| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/fwl/basewidget/fwl_datetimepickerimp.h" | |
| 8 | |
| 9 #include "xfa/fwl/basewidget/fwl_editimp.h" | |
| 10 #include "xfa/fwl/basewidget/fwl_formproxyimp.h" | |
| 11 #include "xfa/fwl/basewidget/fwl_monthcalendarimp.h" | |
| 12 #include "xfa/fwl/basewidget/ifwl_spinbutton.h" | |
| 13 #include "xfa/fwl/core/cfwl_message.h" | |
| 14 #include "xfa/fwl/core/cfwl_themebackground.h" | |
| 15 #include "xfa/fwl/core/cfwl_widgetmgr.h" | |
| 16 #include "xfa/fwl/core/fwl_formimp.h" | |
| 17 #include "xfa/fwl/core/fwl_noteimp.h" | |
| 18 #include "xfa/fwl/core/fwl_widgetimp.h" | |
| 19 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const int kDateTimePickerWidth = 100; | |
| 24 const int kDateTimePickerHeight = 20; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 // static | |
| 29 IFWL_DateTimePicker* IFWL_DateTimePicker::Create( | |
| 30 const CFWL_WidgetImpProperties& properties, | |
| 31 IFWL_Widget* pOuter) { | |
| 32 IFWL_DateTimePicker* pDateTimePicker = new IFWL_DateTimePicker; | |
| 33 CFWL_DateTimePickerImp* pDateTimePickerImpl = | |
| 34 new CFWL_DateTimePickerImp(properties, pOuter); | |
| 35 pDateTimePicker->SetImpl(pDateTimePickerImpl); | |
| 36 pDateTimePickerImpl->SetInterface(pDateTimePicker); | |
| 37 return pDateTimePicker; | |
| 38 } | |
| 39 | |
| 40 // Static | |
| 41 IFWL_DateTimeForm* IFWL_DateTimeForm::Create( | |
| 42 const CFWL_WidgetImpProperties& properties, | |
| 43 IFWL_Widget* pOuter) { | |
| 44 IFWL_DateTimeForm* pDateTimeForm = new IFWL_DateTimeForm; | |
| 45 CFWL_FormProxyImp* pFormProxyImpl = new CFWL_FormProxyImp(properties, pOuter); | |
| 46 pDateTimeForm->SetImpl(pFormProxyImpl); | |
| 47 pFormProxyImpl->SetInterface(pDateTimeForm); | |
| 48 return pDateTimeForm; | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 IFWL_DateTimeCalender* IFWL_DateTimeCalender::Create( | |
| 53 const CFWL_WidgetImpProperties& properties, | |
| 54 IFWL_Widget* pOuter) { | |
| 55 IFWL_DateTimeCalender* pDateTimeCalendar = new IFWL_DateTimeCalender; | |
| 56 CFWL_DateTimeCalendar* pDateTimeCalendarImpl = | |
| 57 new CFWL_DateTimeCalendar(properties, pOuter); | |
| 58 pDateTimeCalendar->SetImpl(pDateTimeCalendarImpl); | |
| 59 pDateTimeCalendarImpl->SetInterface(pDateTimeCalendar); | |
| 60 return pDateTimeCalendar; | |
| 61 } | |
| 62 | |
| 63 // static | |
| 64 IFWL_DateTimeEdit* IFWL_DateTimeEdit::Create( | |
| 65 const CFWL_WidgetImpProperties& properties, | |
| 66 IFWL_Widget* pOuter) { | |
| 67 IFWL_DateTimeEdit* pDateTimeEdit = new IFWL_DateTimeEdit; | |
| 68 CFWL_DateTimeEdit* pDateTimeEditImpl = | |
| 69 new CFWL_DateTimeEdit(properties, pOuter); | |
| 70 pDateTimeEdit->SetImpl(pDateTimeEditImpl); | |
| 71 pDateTimeEditImpl->SetInterface(pDateTimeEdit); | |
| 72 return pDateTimeEdit; | |
| 73 } | |
| 74 | |
| 75 IFWL_DateTimePicker::IFWL_DateTimePicker() {} | |
| 76 int32_t IFWL_DateTimePicker::CountSelRanges() { | |
| 77 return static_cast<CFWL_DateTimePickerImp*>(GetImpl()) | |
| 78 ->GetDataTimeEdit() | |
| 79 ->CountSelRanges(); | |
| 80 } | |
| 81 int32_t IFWL_DateTimePicker::GetSelRange(int32_t nIndex, int32_t& nStart) { | |
| 82 return static_cast<CFWL_DateTimePickerImp*>(GetImpl()) | |
| 83 ->GetDataTimeEdit() | |
| 84 ->GetSelRange(nIndex, nStart); | |
| 85 } | |
| 86 FWL_Error IFWL_DateTimePicker::GetCurSel(int32_t& iYear, | |
| 87 int32_t& iMonth, | |
| 88 int32_t& iDay) { | |
| 89 return static_cast<CFWL_DateTimePickerImp*>(GetImpl()) | |
| 90 ->GetCurSel(iYear, iMonth, iDay); | |
| 91 } | |
| 92 FWL_Error IFWL_DateTimePicker::SetCurSel(int32_t iYear, | |
| 93 int32_t iMonth, | |
| 94 int32_t iDay) { | |
| 95 return static_cast<CFWL_DateTimePickerImp*>(GetImpl()) | |
| 96 ->SetCurSel(iYear, iMonth, iDay); | |
| 97 } | |
| 98 FWL_Error IFWL_DateTimePicker::SetEditText(const CFX_WideString& wsText) { | |
| 99 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->SetEditText(wsText); | |
| 100 } | |
| 101 FWL_Error IFWL_DateTimePicker::GetEditText(CFX_WideString& wsText, | |
| 102 int32_t nStart, | |
| 103 int32_t nCount) const { | |
| 104 return static_cast<CFWL_DateTimePickerImp*>(GetImpl()) | |
| 105 ->GetEditText(wsText, nStart, nCount); | |
| 106 } | |
| 107 FX_BOOL IFWL_DateTimePicker::CanUndo() { | |
| 108 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->CanUndo(); | |
| 109 } | |
| 110 FX_BOOL IFWL_DateTimePicker::CanRedo() { | |
| 111 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->CanRedo(); | |
| 112 } | |
| 113 FX_BOOL IFWL_DateTimePicker::Undo() { | |
| 114 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->Undo(); | |
| 115 } | |
| 116 FX_BOOL IFWL_DateTimePicker::Redo() { | |
| 117 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->Redo(); | |
| 118 } | |
| 119 FX_BOOL IFWL_DateTimePicker::CanCopy() { | |
| 120 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->CanCopy(); | |
| 121 } | |
| 122 FX_BOOL IFWL_DateTimePicker::CanCut() { | |
| 123 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->CanCut(); | |
| 124 } | |
| 125 FX_BOOL IFWL_DateTimePicker::CanSelectAll() { | |
| 126 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->CanSelectAll(); | |
| 127 } | |
| 128 FX_BOOL IFWL_DateTimePicker::Copy(CFX_WideString& wsCopy) { | |
| 129 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->Copy(wsCopy); | |
| 130 } | |
| 131 FX_BOOL IFWL_DateTimePicker::Cut(CFX_WideString& wsCut) { | |
| 132 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->Cut(wsCut); | |
| 133 } | |
| 134 FX_BOOL IFWL_DateTimePicker::Paste(const CFX_WideString& wsPaste) { | |
| 135 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->Paste(wsPaste); | |
| 136 } | |
| 137 FX_BOOL IFWL_DateTimePicker::SelectAll() { | |
| 138 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->SelectAll(); | |
| 139 } | |
| 140 FX_BOOL IFWL_DateTimePicker::Delete() { | |
| 141 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->Delete(); | |
| 142 } | |
| 143 FX_BOOL IFWL_DateTimePicker::DeSelect() { | |
| 144 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->DeSelect(); | |
| 145 } | |
| 146 FWL_Error IFWL_DateTimePicker::GetBBox(CFX_RectF& rect) { | |
| 147 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->GetBBox(rect); | |
| 148 } | |
| 149 FWL_Error IFWL_DateTimePicker::SetEditLimit(int32_t nLimit) { | |
| 150 return static_cast<CFWL_DateTimePickerImp*>(GetImpl())->SetEditLimit(nLimit); | |
| 151 } | |
| 152 FWL_Error IFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded, | |
| 153 uint32_t dwStylesExRemoved) { | |
| 154 return static_cast<CFWL_DateTimePickerImp*>(GetImpl()) | |
| 155 ->ModifyEditStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 156 } | |
| 157 CFWL_DateTimeEdit::CFWL_DateTimeEdit(const CFWL_WidgetImpProperties& properties, | |
| 158 IFWL_Widget* pOuter) | |
| 159 : CFWL_EditImp(properties, pOuter) {} | |
| 160 FWL_Error CFWL_DateTimeEdit::Initialize() { | |
| 161 m_pDelegate = new CFWL_DateTimeEditImpDelegate(this); | |
| 162 if (CFWL_EditImp::Initialize() != FWL_Error::Succeeded) | |
| 163 return FWL_Error::Indefinite; | |
| 164 return FWL_Error::Succeeded; | |
| 165 } | |
| 166 FWL_Error CFWL_DateTimeEdit::Finalize() { | |
| 167 delete m_pDelegate; | |
| 168 m_pDelegate = nullptr; | |
| 169 return CFWL_EditImp::Finalize(); | |
| 170 } | |
| 171 | |
| 172 CFWL_DateTimeEditImpDelegate::CFWL_DateTimeEditImpDelegate( | |
| 173 CFWL_DateTimeEdit* pOwner) | |
| 174 : CFWL_EditImpDelegate(pOwner), m_pOwner(pOwner) {} | |
| 175 | |
| 176 void CFWL_DateTimeEditImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 177 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | |
| 178 DisForm_OnProcessMessage(pMessage); | |
| 179 return; | |
| 180 } | |
| 181 | |
| 182 CFWL_MessageType dwHashCode = pMessage->GetClassID(); | |
| 183 if (dwHashCode == CFWL_MessageType::SetFocus || | |
| 184 dwHashCode == CFWL_MessageType::KillFocus) { | |
| 185 IFWL_Widget* pOuter = m_pOwner->GetOuter(); | |
| 186 IFWL_WidgetDelegate* pDelegate = pOuter->SetDelegate(nullptr); | |
| 187 pDelegate->OnProcessMessage(pMessage); | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 void CFWL_DateTimeEditImpDelegate::DisForm_OnProcessMessage( | |
| 192 CFWL_Message* pMessage) { | |
| 193 CFWL_MessageType dwHashCode = pMessage->GetClassID(); | |
| 194 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | |
| 195 if (dwHashCode == CFWL_MessageType::Mouse) { | |
| 196 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 197 if (pMouse->m_dwCmd == FWL_MouseCommand::LeftButtonDown || | |
| 198 pMouse->m_dwCmd == FWL_MouseCommand::RightButtonDown) { | |
| 199 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | |
| 200 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 201 } | |
| 202 CFWL_DateTimePickerImp* pDateTime = | |
| 203 static_cast<CFWL_DateTimePickerImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 204 if (pDateTime->IsMonthCalendarShowed()) { | |
| 205 CFX_RectF rtInvalidate; | |
| 206 pDateTime->GetWidgetRect(rtInvalidate); | |
| 207 pDateTime->ShowMonthCalendar(FALSE); | |
| 208 rtInvalidate.Offset(-rtInvalidate.left, -rtInvalidate.top); | |
| 209 pDateTime->Repaint(&rtInvalidate); | |
| 210 } | |
| 211 } | |
| 212 } | |
| 213 } | |
| 214 CFWL_EditImpDelegate::OnProcessMessage(pMessage); | |
| 215 } | |
| 216 | |
| 217 CFWL_DateTimeCalendar::CFWL_DateTimeCalendar( | |
| 218 const CFWL_WidgetImpProperties& properties, | |
| 219 IFWL_Widget* pOuter) | |
| 220 : CFWL_MonthCalendarImp(properties, pOuter) {} | |
| 221 FWL_Error CFWL_DateTimeCalendar::Initialize() { | |
| 222 if (CFWL_MonthCalendarImp::Initialize() != FWL_Error::Succeeded) | |
| 223 return FWL_Error::Indefinite; | |
| 224 delete m_pDelegate; | |
| 225 m_pDelegate = new CFWL_DateTimeCalendarImpDelegate(this); | |
| 226 return FWL_Error::Succeeded; | |
| 227 } | |
| 228 FWL_Error CFWL_DateTimeCalendar::Finalize() { | |
| 229 delete m_pDelegate; | |
| 230 m_pDelegate = nullptr; | |
| 231 return CFWL_MonthCalendarImp::Finalize(); | |
| 232 } | |
| 233 | |
| 234 CFWL_DateTimeCalendarImpDelegate::CFWL_DateTimeCalendarImpDelegate( | |
| 235 CFWL_DateTimeCalendar* pOwner) | |
| 236 : CFWL_MonthCalendarImpDelegate(pOwner), m_pOwner(pOwner) { | |
| 237 m_bFlag = FALSE; | |
| 238 } | |
| 239 | |
| 240 void CFWL_DateTimeCalendarImpDelegate::OnProcessMessage( | |
| 241 CFWL_Message* pMessage) { | |
| 242 CFWL_MessageType dwCode = pMessage->GetClassID(); | |
| 243 if (dwCode == CFWL_MessageType::SetFocus || | |
| 244 dwCode == CFWL_MessageType::KillFocus) { | |
| 245 IFWL_Widget* pOuter = m_pOwner->GetOuter(); | |
| 246 IFWL_WidgetDelegate* pDelegate = pOuter->SetDelegate(nullptr); | |
| 247 pDelegate->OnProcessMessage(pMessage); | |
| 248 return; | |
| 249 } | |
| 250 if (dwCode == CFWL_MessageType::Mouse) { | |
| 251 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 252 if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) | |
| 253 OnLButtonDownEx(pMsg); | |
| 254 else if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonUp) | |
| 255 OnLButtonUpEx(pMsg); | |
| 256 return; | |
| 257 } | |
| 258 CFWL_MonthCalendarImpDelegate::OnProcessMessage(pMessage); | |
| 259 } | |
| 260 | |
| 261 void CFWL_DateTimeCalendarImpDelegate::OnLButtonDownEx(CFWL_MsgMouse* pMsg) { | |
| 262 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 263 m_pOwner->m_iLBtnPartStates = CFWL_PartState_Pressed; | |
| 264 m_pOwner->PrevMonth(); | |
| 265 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 266 } else if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 267 m_pOwner->m_iRBtnPartStates |= CFWL_PartState_Pressed; | |
| 268 m_pOwner->NextMonth(); | |
| 269 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 270 } else if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 271 if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == | |
| 272 0) { | |
| 273 m_pOwner->JumpToToday(); | |
| 274 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 275 } | |
| 276 } else { | |
| 277 IFWL_DateTimePicker* pIPicker = | |
| 278 static_cast<IFWL_DateTimePicker*>(m_pOwner->m_pOuter); | |
| 279 CFWL_DateTimePickerImp* pPicker = | |
| 280 static_cast<CFWL_DateTimePickerImp*>(pIPicker->GetImpl()); | |
| 281 if (pPicker->IsMonthCalendarShowed()) { | |
| 282 m_bFlag = 1; | |
| 283 } | |
| 284 } | |
| 285 } | |
| 286 void CFWL_DateTimeCalendarImpDelegate::OnLButtonUpEx(CFWL_MsgMouse* pMsg) { | |
| 287 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | |
| 288 return DisForm_OnLButtonUpEx(pMsg); | |
| 289 } | |
| 290 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 291 m_pOwner->m_iLBtnPartStates = 0; | |
| 292 m_pOwner->Repaint(&m_pOwner->m_rtLBtn); | |
| 293 return; | |
| 294 } | |
| 295 if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 296 m_pOwner->m_iRBtnPartStates = 0; | |
| 297 m_pOwner->Repaint(&m_pOwner->m_rtRBtn); | |
| 298 return; | |
| 299 } | |
| 300 if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 301 return; | |
| 302 } | |
| 303 int32_t iOldSel = 0; | |
| 304 if (m_pOwner->m_arrSelDays.GetSize() > 0) { | |
| 305 iOldSel = m_pOwner->m_arrSelDays[0]; | |
| 306 } | |
| 307 int32_t iCurSel = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 308 CFX_RectF rt; | |
| 309 IFWL_DateTimePicker* pIPicker = | |
| 310 static_cast<IFWL_DateTimePicker*>(m_pOwner->m_pOuter); | |
| 311 CFWL_DateTimePickerImp* pPicker = | |
| 312 static_cast<CFWL_DateTimePickerImp*>(pIPicker->GetImpl()); | |
| 313 pPicker->m_pForm->GetWidgetRect(rt); | |
| 314 rt.Set(0, 0, rt.width, rt.height); | |
| 315 if (iCurSel > 0) { | |
| 316 FWL_DATEINFO* lpDatesInfo = m_pOwner->m_arrDates.GetAt(iCurSel - 1); | |
| 317 CFX_RectF rtInvalidate(lpDatesInfo->rect); | |
| 318 if (iOldSel > 0 && iOldSel <= m_pOwner->m_arrDates.GetSize()) { | |
| 319 lpDatesInfo = m_pOwner->m_arrDates.GetAt(iOldSel - 1); | |
| 320 rtInvalidate.Union(lpDatesInfo->rect); | |
| 321 } | |
| 322 m_pOwner->AddSelDay(iCurSel); | |
| 323 if (!m_pOwner->m_pOuter) | |
| 324 return; | |
| 325 pPicker->ProcessSelChanged(m_pOwner->m_iCurYear, m_pOwner->m_iCurMonth, | |
| 326 iCurSel); | |
| 327 pPicker->ShowMonthCalendar(FALSE); | |
| 328 } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { | |
| 329 pPicker->ShowMonthCalendar(FALSE); | |
| 330 } | |
| 331 m_bFlag = 0; | |
| 332 } | |
| 333 void CFWL_DateTimeCalendarImpDelegate::OnMouseMoveEx(CFWL_MsgMouse* pMsg) { | |
| 334 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) { | |
| 335 return; | |
| 336 } | |
| 337 FX_BOOL bRepaint = FALSE; | |
| 338 CFX_RectF rtInvalidate; | |
| 339 rtInvalidate.Set(0, 0, 0, 0); | |
| 340 if (m_pOwner->m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 341 int32_t iHover = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 342 bRepaint = m_pOwner->m_iHovered != iHover; | |
| 343 if (bRepaint) { | |
| 344 if (m_pOwner->m_iHovered > 0) { | |
| 345 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate); | |
| 346 } | |
| 347 if (iHover > 0) { | |
| 348 CFX_RectF rtDay; | |
| 349 m_pOwner->GetDayRect(iHover, rtDay); | |
| 350 if (rtInvalidate.IsEmpty()) { | |
| 351 rtInvalidate = rtDay; | |
| 352 } else { | |
| 353 rtInvalidate.Union(rtDay); | |
| 354 } | |
| 355 } | |
| 356 } | |
| 357 m_pOwner->m_iHovered = iHover; | |
| 358 CFWL_Event_DtpHoverChanged ev; | |
| 359 ev.hoverday = iHover; | |
| 360 m_pOwner->DispatchEvent(&ev); | |
| 361 } else { | |
| 362 bRepaint = m_pOwner->m_iHovered > 0; | |
| 363 if (bRepaint) { | |
| 364 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate); | |
| 365 } | |
| 366 m_pOwner->m_iHovered = -1; | |
| 367 } | |
| 368 if (bRepaint && !rtInvalidate.IsEmpty()) { | |
| 369 m_pOwner->Repaint(&rtInvalidate); | |
| 370 } | |
| 371 } | |
| 372 | |
| 373 void CFWL_DateTimeCalendarImpDelegate::DisForm_OnProcessMessage( | |
| 374 CFWL_Message* pMessage) { | |
| 375 if (pMessage->GetClassID() == CFWL_MessageType::Mouse) { | |
| 376 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 377 if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonUp) { | |
| 378 DisForm_OnLButtonUpEx(pMsg); | |
| 379 return; | |
| 380 } | |
| 381 } | |
| 382 CFWL_MonthCalendarImpDelegate::OnProcessMessage(pMessage); | |
| 383 } | |
| 384 | |
| 385 void CFWL_DateTimeCalendarImpDelegate::DisForm_OnLButtonUpEx( | |
| 386 CFWL_MsgMouse* pMsg) { | |
| 387 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 388 m_pOwner->m_iLBtnPartStates = 0; | |
| 389 m_pOwner->Repaint(&(m_pOwner->m_rtLBtn)); | |
| 390 return; | |
| 391 } | |
| 392 if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 393 m_pOwner->m_iRBtnPartStates = 0; | |
| 394 m_pOwner->Repaint(&(m_pOwner->m_rtRBtn)); | |
| 395 return; | |
| 396 } | |
| 397 if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 398 return; | |
| 399 } | |
| 400 int32_t iOldSel = 0; | |
| 401 if (m_pOwner->m_arrSelDays.GetSize() > 0) { | |
| 402 iOldSel = m_pOwner->m_arrSelDays[0]; | |
| 403 } | |
| 404 int32_t iCurSel = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 405 if (iCurSel > 0) { | |
| 406 FWL_DATEINFO* lpDatesInfo = m_pOwner->m_arrDates.GetAt(iCurSel - 1); | |
| 407 CFX_RectF rtInvalidate(lpDatesInfo->rect); | |
| 408 if (iOldSel > 0 && iOldSel <= m_pOwner->m_arrDates.GetSize()) { | |
| 409 lpDatesInfo = m_pOwner->m_arrDates.GetAt(iOldSel - 1); | |
| 410 rtInvalidate.Union(lpDatesInfo->rect); | |
| 411 } | |
| 412 m_pOwner->AddSelDay(iCurSel); | |
| 413 CFWL_DateTimePickerImp* pDateTime = | |
| 414 static_cast<CFWL_DateTimePickerImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 415 pDateTime->ProcessSelChanged(m_pOwner->m_iCurYear, m_pOwner->m_iCurMonth, | |
| 416 iCurSel); | |
| 417 pDateTime->ShowMonthCalendar(FALSE); | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 CFWL_DateTimePickerImp::CFWL_DateTimePickerImp( | |
| 422 const CFWL_WidgetImpProperties& properties, | |
| 423 IFWL_Widget* pOuter) | |
| 424 : CFWL_WidgetImp(properties, pOuter), | |
| 425 m_iBtnState(1), | |
| 426 m_iYear(-1), | |
| 427 m_iMonth(-1), | |
| 428 m_iDay(-1), | |
| 429 m_bLBtnDown(FALSE) { | |
| 430 m_rtBtn.Set(0, 0, 0, 0); | |
| 431 } | |
| 432 | |
| 433 CFWL_DateTimePickerImp::~CFWL_DateTimePickerImp() {} | |
| 434 | |
| 435 FWL_Error CFWL_DateTimePickerImp::GetClassName(CFX_WideString& wsClass) const { | |
| 436 wsClass = FWL_CLASS_DateTimePicker; | |
| 437 return FWL_Error::Succeeded; | |
| 438 } | |
| 439 | |
| 440 FWL_Type CFWL_DateTimePickerImp::GetClassID() const { | |
| 441 return FWL_Type::DateTimePicker; | |
| 442 } | |
| 443 | |
| 444 FWL_Error CFWL_DateTimePickerImp::Initialize() { | |
| 445 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
| 446 return FWL_Error::Indefinite; | |
| 447 | |
| 448 m_pDelegate = new CFWL_DateTimePickerImpDelegate(this); | |
| 449 m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat; | |
| 450 CFWL_WidgetImpProperties propMonth; | |
| 451 propMonth.m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border; | |
| 452 propMonth.m_dwStates = FWL_WGTSTATE_Invisible; | |
| 453 propMonth.m_pDataProvider = &m_MonthCalendarDP; | |
| 454 propMonth.m_pParent = m_pInterface; | |
| 455 propMonth.m_pThemeProvider = m_pProperties->m_pThemeProvider; | |
| 456 m_pMonthCal.reset(IFWL_DateTimeCalender::Create(propMonth, m_pInterface)); | |
| 457 m_pMonthCal->Initialize(); | |
| 458 CFX_RectF rtMonthCal; | |
| 459 m_pMonthCal->GetWidgetRect(rtMonthCal, TRUE); | |
| 460 rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height); | |
| 461 m_pMonthCal->SetWidgetRect(rtMonthCal); | |
| 462 CFWL_WidgetImpProperties propEdit; | |
| 463 propEdit.m_pParent = m_pInterface; | |
| 464 propEdit.m_pThemeProvider = m_pProperties->m_pThemeProvider; | |
| 465 m_pEdit.reset(IFWL_DateTimeEdit::Create(propEdit, m_pInterface)); | |
| 466 m_pEdit->Initialize(); | |
| 467 RegisterEventTarget(m_pMonthCal.get()); | |
| 468 RegisterEventTarget(m_pEdit.get()); | |
| 469 return FWL_Error::Succeeded; | |
| 470 } | |
| 471 | |
| 472 FWL_Error CFWL_DateTimePickerImp::Finalize() { | |
| 473 if (m_pEdit) { | |
| 474 m_pEdit->Finalize(); | |
| 475 } | |
| 476 if (m_pMonthCal) { | |
| 477 m_pMonthCal->Finalize(); | |
| 478 } | |
| 479 if (m_pForm) { | |
| 480 m_pForm->Finalize(); | |
| 481 } | |
| 482 UnregisterEventTarget(); | |
| 483 delete m_pDelegate; | |
| 484 m_pDelegate = nullptr; | |
| 485 return CFWL_WidgetImp::Finalize(); | |
| 486 } | |
| 487 FWL_Error CFWL_DateTimePickerImp::GetWidgetRect(CFX_RectF& rect, | |
| 488 FX_BOOL bAutoSize) { | |
| 489 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 490 return DisForm_GetWidgetRect(rect, bAutoSize); | |
| 491 } | |
| 492 if (bAutoSize) { | |
| 493 rect.Set(0, 0, kDateTimePickerWidth, kDateTimePickerHeight); | |
| 494 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | |
| 495 } else { | |
| 496 rect = m_pProperties->m_rtWidget; | |
| 497 } | |
| 498 return FWL_Error::Succeeded; | |
| 499 } | |
| 500 FWL_Error CFWL_DateTimePickerImp::Update() { | |
| 501 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 502 return DisForm_Update(); | |
| 503 } | |
| 504 if (m_iLock) { | |
| 505 return FWL_Error::Indefinite; | |
| 506 } | |
| 507 if (!m_pProperties->m_pThemeProvider) { | |
| 508 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 509 } | |
| 510 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); | |
| 511 GetClientRect(m_rtClient); | |
| 512 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | |
| 513 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 514 if (!pFWidth) | |
| 515 return FWL_Error::Indefinite; | |
| 516 FX_FLOAT fBtn = *pFWidth; | |
| 517 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1, | |
| 518 m_rtClient.height - 1); | |
| 519 CFX_RectF rtEdit; | |
| 520 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, | |
| 521 m_rtClient.height); | |
| 522 m_pEdit->SetWidgetRect(rtEdit); | |
| 523 ReSetEditAlignment(); | |
| 524 m_pEdit->Update(); | |
| 525 if (!(m_pMonthCal->GetThemeProvider())) { | |
| 526 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); | |
| 527 } | |
| 528 if (m_pProperties->m_pDataProvider) { | |
| 529 IFWL_DateTimePickerDP* pData = | |
| 530 static_cast<IFWL_DateTimePickerDP*>(m_pProperties->m_pDataProvider); | |
| 531 pData->GetToday(m_pInterface, m_MonthCalendarDP.m_iCurYear, | |
| 532 m_MonthCalendarDP.m_iCurMonth, m_MonthCalendarDP.m_iCurDay); | |
| 533 } | |
| 534 CFX_RectF rtMonthCal; | |
| 535 m_pMonthCal->GetWidgetRect(rtMonthCal, TRUE); | |
| 536 CFX_RectF rtPopUp; | |
| 537 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, | |
| 538 rtMonthCal.width, rtMonthCal.height); | |
| 539 m_pMonthCal->SetWidgetRect(rtPopUp); | |
| 540 m_pMonthCal->Update(); | |
| 541 return FWL_Error::Succeeded; | |
| 542 } | |
| 543 FWL_WidgetHit CFWL_DateTimePickerImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
| 544 if (m_pWidgetMgr->IsFormDisabled()) | |
| 545 return DisForm_HitTest(fx, fy); | |
| 546 if (m_rtClient.Contains(fx, fy)) | |
| 547 return FWL_WidgetHit::Client; | |
| 548 if (IsMonthCalendarShowed()) { | |
| 549 CFX_RectF rect; | |
| 550 m_pMonthCal->GetWidgetRect(rect); | |
| 551 if (rect.Contains(fx, fy)) | |
| 552 return FWL_WidgetHit::Client; | |
| 553 } | |
| 554 return FWL_WidgetHit::Unknown; | |
| 555 } | |
| 556 FWL_Error CFWL_DateTimePickerImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 557 const CFX_Matrix* pMatrix) { | |
| 558 if (!pGraphics) | |
| 559 return FWL_Error::Indefinite; | |
| 560 if (!m_pProperties->m_pThemeProvider) | |
| 561 return FWL_Error::Indefinite; | |
| 562 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 563 if (HasBorder()) { | |
| 564 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | |
| 565 } | |
| 566 if (HasEdge()) { | |
| 567 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | |
| 568 } | |
| 569 if (!m_rtBtn.IsEmpty()) { | |
| 570 DrawDropDownButton(pGraphics, pTheme, pMatrix); | |
| 571 } | |
| 572 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 573 return DisForm_DrawWidget(pGraphics, pMatrix); | |
| 574 } | |
| 575 return FWL_Error::Succeeded; | |
| 576 } | |
| 577 FWL_Error CFWL_DateTimePickerImp::SetThemeProvider(IFWL_ThemeProvider* pTP) { | |
| 578 m_pProperties->m_pThemeProvider = pTP; | |
| 579 m_pMonthCal->SetThemeProvider(pTP); | |
| 580 return FWL_Error::Succeeded; | |
| 581 } | |
| 582 FWL_Error CFWL_DateTimePickerImp::GetCurSel(int32_t& iYear, | |
| 583 int32_t& iMonth, | |
| 584 int32_t& iDay) { | |
| 585 iYear = m_iYear; | |
| 586 iMonth = m_iMonth; | |
| 587 iDay = m_iDay; | |
| 588 return FWL_Error::Succeeded; | |
| 589 } | |
| 590 FWL_Error CFWL_DateTimePickerImp::SetCurSel(int32_t iYear, | |
| 591 int32_t iMonth, | |
| 592 int32_t iDay) { | |
| 593 if (iYear <= 0 || iYear >= 3000) | |
| 594 return FWL_Error::Indefinite; | |
| 595 if (iMonth <= 0 || iMonth >= 13) | |
| 596 return FWL_Error::Indefinite; | |
| 597 if (iDay <= 0 || iDay >= 32) | |
| 598 return FWL_Error::Indefinite; | |
| 599 m_iYear = iYear; | |
| 600 m_iMonth = iMonth; | |
| 601 m_iDay = iDay; | |
| 602 m_pMonthCal->SetSelect(iYear, iMonth, iDay); | |
| 603 return FWL_Error::Succeeded; | |
| 604 } | |
| 605 | |
| 606 FWL_Error CFWL_DateTimePickerImp::SetEditText(const CFX_WideString& wsText) { | |
| 607 if (!m_pEdit) | |
| 608 return FWL_Error::Indefinite; | |
| 609 | |
| 610 FWL_Error iRet = m_pEdit->SetText(wsText); | |
| 611 Repaint(&m_rtClient); | |
| 612 CFWL_Event_DtpEditChanged ev; | |
| 613 ev.m_wsText = wsText; | |
| 614 DispatchEvent(&ev); | |
| 615 return iRet; | |
| 616 } | |
| 617 | |
| 618 FWL_Error CFWL_DateTimePickerImp::GetEditText(CFX_WideString& wsText, | |
| 619 int32_t nStart, | |
| 620 int32_t nCount) const { | |
| 621 if (m_pEdit) { | |
| 622 return m_pEdit->GetText(wsText, nStart, nCount); | |
| 623 } | |
| 624 return FWL_Error::Indefinite; | |
| 625 } | |
| 626 FX_BOOL CFWL_DateTimePickerImp::CanUndo() { | |
| 627 return m_pEdit->CanUndo(); | |
| 628 } | |
| 629 FX_BOOL CFWL_DateTimePickerImp::CanRedo() { | |
| 630 return m_pEdit->CanRedo(); | |
| 631 } | |
| 632 FX_BOOL CFWL_DateTimePickerImp::Undo() { | |
| 633 return m_pEdit->Undo(); | |
| 634 } | |
| 635 FX_BOOL CFWL_DateTimePickerImp::Redo() { | |
| 636 return m_pEdit->Redo(); | |
| 637 } | |
| 638 FX_BOOL CFWL_DateTimePickerImp::CanCopy() { | |
| 639 int32_t nCount = m_pEdit->CountSelRanges(); | |
| 640 return nCount > 0; | |
| 641 } | |
| 642 FX_BOOL CFWL_DateTimePickerImp::CanCut() { | |
| 643 if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) { | |
| 644 return FALSE; | |
| 645 } | |
| 646 int32_t nCount = m_pEdit->CountSelRanges(); | |
| 647 return nCount > 0; | |
| 648 } | |
| 649 FX_BOOL CFWL_DateTimePickerImp::CanSelectAll() { | |
| 650 return m_pEdit->GetTextLength() > 0; | |
| 651 } | |
| 652 FX_BOOL CFWL_DateTimePickerImp::Copy(CFX_WideString& wsCopy) { | |
| 653 return m_pEdit->Copy(wsCopy); | |
| 654 } | |
| 655 FX_BOOL CFWL_DateTimePickerImp::Cut(CFX_WideString& wsCut) { | |
| 656 return m_pEdit->Cut(wsCut); | |
| 657 } | |
| 658 FX_BOOL CFWL_DateTimePickerImp::Paste(const CFX_WideString& wsPaste) { | |
| 659 return m_pEdit->Paste(wsPaste); | |
| 660 } | |
| 661 FX_BOOL CFWL_DateTimePickerImp::SelectAll() { | |
| 662 return m_pEdit->AddSelRange(0) == FWL_Error::Succeeded; | |
| 663 } | |
| 664 FX_BOOL CFWL_DateTimePickerImp::Delete() { | |
| 665 return m_pEdit->ClearText() == FWL_Error::Succeeded; | |
| 666 } | |
| 667 FX_BOOL CFWL_DateTimePickerImp::DeSelect() { | |
| 668 return m_pEdit->ClearSelections() == FWL_Error::Succeeded; | |
| 669 } | |
| 670 FWL_Error CFWL_DateTimePickerImp::GetBBox(CFX_RectF& rect) { | |
| 671 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 672 return DisForm_GetBBox(rect); | |
| 673 } | |
| 674 rect = m_pProperties->m_rtWidget; | |
| 675 if (IsMonthCalendarShowed()) { | |
| 676 CFX_RectF rtMonth; | |
| 677 m_pMonthCal->GetWidgetRect(rtMonth); | |
| 678 rtMonth.Offset(m_pProperties->m_rtWidget.left, | |
| 679 m_pProperties->m_rtWidget.top); | |
| 680 rect.Union(rtMonth); | |
| 681 } | |
| 682 return FWL_Error::Succeeded; | |
| 683 } | |
| 684 FWL_Error CFWL_DateTimePickerImp::SetEditLimit(int32_t nLimit) { | |
| 685 return m_pEdit->SetLimit(nLimit); | |
| 686 } | |
| 687 FWL_Error CFWL_DateTimePickerImp::ModifyEditStylesEx( | |
| 688 uint32_t dwStylesExAdded, | |
| 689 uint32_t dwStylesExRemoved) { | |
| 690 return m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 691 } | |
| 692 void CFWL_DateTimePickerImp::DrawDropDownButton(CFX_Graphics* pGraphics, | |
| 693 IFWL_ThemeProvider* pTheme, | |
| 694 const CFX_Matrix* pMatrix) { | |
| 695 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_Spin) == | |
| 696 FWL_STYLEEXT_DTP_Spin) { | |
| 697 CFWL_WidgetImpProperties prop; | |
| 698 prop.m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; | |
| 699 prop.m_pParent = m_pInterface; | |
| 700 prop.m_rtWidget = m_rtBtn; | |
| 701 IFWL_SpinButton* pSpin = IFWL_SpinButton::Create(prop, m_pInterface); | |
| 702 pSpin->Initialize(); | |
| 703 } else { | |
| 704 CFWL_ThemeBackground param; | |
| 705 param.m_pWidget = m_pInterface; | |
| 706 param.m_iPart = CFWL_Part::DropDownButton; | |
| 707 param.m_dwStates = m_iBtnState; | |
| 708 param.m_pGraphics = pGraphics; | |
| 709 param.m_rtPart = m_rtBtn; | |
| 710 if (pMatrix) { | |
| 711 param.m_matrix.Concat(*pMatrix); | |
| 712 } | |
| 713 pTheme->DrawBackground(¶m); | |
| 714 } | |
| 715 } | |
| 716 void CFWL_DateTimePickerImp::FormatDateString(int32_t iYear, | |
| 717 int32_t iMonth, | |
| 718 int32_t iDay, | |
| 719 CFX_WideString& wsText) { | |
| 720 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat) == | |
| 721 FWL_STYLEEXT_DTP_ShortDateFormat) { | |
| 722 wsText.Format(L"%d-%d-%d", iYear, iMonth, iDay); | |
| 723 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_LongDateFormat) == | |
| 724 FWL_STYLEEXT_DTP_LongDateFormat) { | |
| 725 wsText.Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay); | |
| 726 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat) == | |
| 727 FWL_STYLEEXT_DTP_TimeFormat) { | |
| 728 } | |
| 729 } | |
| 730 void CFWL_DateTimePickerImp::ShowMonthCalendar(FX_BOOL bActivate) { | |
| 731 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 732 return DisForm_ShowMonthCalendar(bActivate); | |
| 733 } | |
| 734 if (IsMonthCalendarShowed() == bActivate) { | |
| 735 return; | |
| 736 } | |
| 737 if (!m_pForm) { | |
| 738 InitProxyForm(); | |
| 739 } | |
| 740 if (bActivate) { | |
| 741 CFX_RectF rtMonth; | |
| 742 m_pMonthCal->GetWidgetRect(rtMonth); | |
| 743 CFX_RectF rtAnchor; | |
| 744 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 745 m_pProperties->m_rtWidget.height); | |
| 746 GetPopupPos(0, rtMonth.height, rtAnchor, rtMonth); | |
| 747 m_pForm->SetWidgetRect(rtMonth); | |
| 748 rtMonth.left = rtMonth.top = 0; | |
| 749 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate); | |
| 750 m_pMonthCal->SetWidgetRect(rtMonth); | |
| 751 m_pMonthCal->Update(); | |
| 752 m_pForm->DoModal(); | |
| 753 } else { | |
| 754 m_pForm->EndDoModal(); | |
| 755 } | |
| 756 } | |
| 757 FX_BOOL CFWL_DateTimePickerImp::IsMonthCalendarShowed() { | |
| 758 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 759 return DisForm_IsMonthCalendarShowed(); | |
| 760 } | |
| 761 if (!m_pForm) | |
| 762 return FALSE; | |
| 763 return !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible); | |
| 764 } | |
| 765 void CFWL_DateTimePickerImp::ReSetEditAlignment() { | |
| 766 if (!m_pEdit) | |
| 767 return; | |
| 768 uint32_t dwStylExes = m_pProperties->m_dwStyleExes; | |
| 769 uint32_t dwAdd = 0; | |
| 770 switch (dwStylExes & FWL_STYLEEXT_DTP_EditHAlignMask) { | |
| 771 case FWL_STYLEEXT_DTP_EditHCenter: { | |
| 772 dwAdd |= FWL_STYLEEXT_EDT_HCenter; | |
| 773 break; | |
| 774 } | |
| 775 case FWL_STYLEEXT_DTP_EditHFar: { | |
| 776 dwAdd |= FWL_STYLEEXT_EDT_HFar; | |
| 777 break; | |
| 778 } | |
| 779 default: { dwAdd |= FWL_STYLEEXT_EDT_HNear; } | |
| 780 } | |
| 781 switch (dwStylExes & FWL_STYLEEXT_DTP_EditVAlignMask) { | |
| 782 case FWL_STYLEEXT_DTP_EditVCenter: { | |
| 783 dwAdd |= FWL_STYLEEXT_EDT_VCenter; | |
| 784 break; | |
| 785 } | |
| 786 case FWL_STYLEEXT_DTP_EditVFar: { | |
| 787 dwAdd |= FWL_STYLEEXT_EDT_VFar; | |
| 788 break; | |
| 789 } | |
| 790 default: { dwAdd |= FWL_STYLEEXT_EDT_VNear; } | |
| 791 } | |
| 792 if (dwStylExes & FWL_STYLEEXT_DTP_EditJustified) { | |
| 793 dwAdd |= FWL_STYLEEXT_EDT_Justified; | |
| 794 } | |
| 795 if (dwStylExes & FWL_STYLEEXT_DTP_EditDistributed) { | |
| 796 dwAdd |= FWL_STYLEEXT_EDT_Distributed; | |
| 797 } | |
| 798 m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | | |
| 799 FWL_STYLEEXT_EDT_HAlignModeMask | | |
| 800 FWL_STYLEEXT_EDT_VAlignMask); | |
| 801 } | |
| 802 void CFWL_DateTimePickerImp::ProcessSelChanged(int32_t iYear, | |
| 803 int32_t iMonth, | |
| 804 int32_t iDay) { | |
| 805 m_iYear = iYear; | |
| 806 m_iMonth = iMonth; | |
| 807 m_iDay = iDay; | |
| 808 CFX_WideString wsText; | |
| 809 FormatDateString(m_iYear, m_iMonth, m_iDay, wsText); | |
| 810 m_pEdit->SetText(wsText); | |
| 811 m_pEdit->Update(); | |
| 812 Repaint(&m_rtClient); | |
| 813 CFWL_Event_DtpSelectChanged ev; | |
| 814 ev.m_pSrcTarget = m_pInterface; | |
| 815 ev.iYear = m_iYear; | |
| 816 ev.iMonth = m_iMonth; | |
| 817 ev.iDay = m_iDay; | |
| 818 DispatchEvent(&ev); | |
| 819 } | |
| 820 void CFWL_DateTimePickerImp::InitProxyForm() { | |
| 821 if (m_pForm) | |
| 822 return; | |
| 823 if (!m_pMonthCal) | |
| 824 return; | |
| 825 CFWL_WidgetImpProperties propForm; | |
| 826 propForm.m_dwStyles = FWL_WGTSTYLE_Popup; | |
| 827 propForm.m_dwStates = FWL_WGTSTATE_Invisible; | |
| 828 propForm.m_pOwner = m_pInterface; | |
| 829 m_pForm.reset(IFWL_DateTimeForm::Create(propForm, m_pMonthCal.get())); | |
| 830 m_pForm->Initialize(); | |
| 831 m_pMonthCal->SetParent(m_pForm.get()); | |
| 832 } | |
| 833 IFWL_DateTimeEdit* CFWL_DateTimePickerImp::GetDataTimeEdit() { | |
| 834 return m_pEdit.get(); | |
| 835 } | |
| 836 FWL_Error CFWL_DateTimePickerImp::DisForm_Initialize() { | |
| 837 m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat; | |
| 838 DisForm_InitDateTimeCalendar(); | |
| 839 DisForm_InitDateTimeEdit(); | |
| 840 RegisterEventTarget(m_pMonthCal.get()); | |
| 841 RegisterEventTarget(m_pEdit.get()); | |
| 842 return FWL_Error::Succeeded; | |
| 843 } | |
| 844 void CFWL_DateTimePickerImp::DisForm_InitDateTimeCalendar() { | |
| 845 if (m_pMonthCal) { | |
| 846 return; | |
| 847 } | |
| 848 CFWL_WidgetImpProperties propMonth; | |
| 849 propMonth.m_dwStyles = | |
| 850 FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border | FWL_WGTSTYLE_EdgeSunken; | |
| 851 propMonth.m_dwStates = FWL_WGTSTATE_Invisible; | |
| 852 propMonth.m_pParent = m_pInterface; | |
| 853 propMonth.m_pDataProvider = &m_MonthCalendarDP; | |
| 854 propMonth.m_pThemeProvider = m_pProperties->m_pThemeProvider; | |
| 855 m_pMonthCal.reset(IFWL_DateTimeCalender::Create(propMonth, m_pInterface)); | |
| 856 m_pMonthCal->Initialize(); | |
| 857 CFX_RectF rtMonthCal; | |
| 858 m_pMonthCal->GetWidgetRect(rtMonthCal, TRUE); | |
| 859 rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height); | |
| 860 m_pMonthCal->SetWidgetRect(rtMonthCal); | |
| 861 } | |
| 862 void CFWL_DateTimePickerImp::DisForm_InitDateTimeEdit() { | |
| 863 if (m_pEdit) { | |
| 864 return; | |
| 865 } | |
| 866 CFWL_WidgetImpProperties propEdit; | |
| 867 propEdit.m_pParent = m_pInterface; | |
| 868 propEdit.m_pThemeProvider = m_pProperties->m_pThemeProvider; | |
| 869 m_pEdit.reset(IFWL_DateTimeEdit::Create(propEdit, m_pInterface)); | |
| 870 m_pEdit->Initialize(); | |
| 871 } | |
| 872 FX_BOOL CFWL_DateTimePickerImp::DisForm_IsMonthCalendarShowed() { | |
| 873 if (!m_pMonthCal) | |
| 874 return FALSE; | |
| 875 return !(m_pMonthCal->GetStates() & FWL_WGTSTATE_Invisible); | |
| 876 } | |
| 877 void CFWL_DateTimePickerImp::DisForm_ShowMonthCalendar(FX_BOOL bActivate) { | |
| 878 FX_BOOL bShowed = IsMonthCalendarShowed(); | |
| 879 if (bShowed == bActivate) { | |
| 880 return; | |
| 881 } | |
| 882 if (bActivate) { | |
| 883 CFX_RectF rtMonthCal; | |
| 884 m_pMonthCal->GetWidgetRect(rtMonthCal, TRUE); | |
| 885 FX_FLOAT fPopupMin = rtMonthCal.height; | |
| 886 FX_FLOAT fPopupMax = rtMonthCal.height; | |
| 887 CFX_RectF rtAnchor(m_pProperties->m_rtWidget); | |
| 888 rtAnchor.width = rtMonthCal.width; | |
| 889 rtMonthCal.left = m_rtClient.left; | |
| 890 rtMonthCal.top = rtAnchor.Height(); | |
| 891 GetPopupPos(fPopupMin, fPopupMax, rtAnchor, rtMonthCal); | |
| 892 m_pMonthCal->SetWidgetRect(rtMonthCal); | |
| 893 if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0) { | |
| 894 m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay); | |
| 895 } | |
| 896 m_pMonthCal->Update(); | |
| 897 } | |
| 898 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate); | |
| 899 if (bActivate) { | |
| 900 CFWL_MsgSetFocus msg; | |
| 901 msg.m_pDstTarget = m_pMonthCal.get(); | |
| 902 msg.m_pSrcTarget = m_pEdit.get(); | |
| 903 IFWL_WidgetDelegate* pDelegate = m_pEdit->SetDelegate(nullptr); | |
| 904 pDelegate->OnProcessMessage(&msg); | |
| 905 } | |
| 906 CFX_RectF rtInvalidate, rtCal; | |
| 907 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 908 m_pProperties->m_rtWidget.height); | |
| 909 m_pMonthCal->GetWidgetRect(rtCal); | |
| 910 rtInvalidate.Union(rtCal); | |
| 911 rtInvalidate.Inflate(2, 2); | |
| 912 Repaint(&rtInvalidate); | |
| 913 } | |
| 914 FWL_WidgetHit CFWL_DateTimePickerImp::DisForm_HitTest(FX_FLOAT fx, | |
| 915 FX_FLOAT fy) { | |
| 916 CFX_RectF rect; | |
| 917 rect.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 918 m_pProperties->m_rtWidget.height); | |
| 919 if (rect.Contains(fx, fy)) | |
| 920 return FWL_WidgetHit::Edit; | |
| 921 if (DisForm_IsNeedShowButton()) | |
| 922 rect.width += m_fBtn; | |
| 923 if (rect.Contains(fx, fy)) | |
| 924 return FWL_WidgetHit::Client; | |
| 925 if (IsMonthCalendarShowed()) { | |
| 926 m_pMonthCal->GetWidgetRect(rect); | |
| 927 if (rect.Contains(fx, fy)) | |
| 928 return FWL_WidgetHit::Client; | |
| 929 } | |
| 930 return FWL_WidgetHit::Unknown; | |
| 931 } | |
| 932 FX_BOOL CFWL_DateTimePickerImp::DisForm_IsNeedShowButton() { | |
| 933 FX_BOOL bFocus = m_pProperties->m_dwStates & FWL_WGTSTATE_Focused || | |
| 934 m_pMonthCal->GetStates() & FWL_WGTSTATE_Focused || | |
| 935 m_pEdit->GetStates() & FWL_WGTSTATE_Focused; | |
| 936 return bFocus; | |
| 937 } | |
| 938 | |
| 939 FWL_Error CFWL_DateTimePickerImp::DisForm_Update() { | |
| 940 if (m_iLock) | |
| 941 return FWL_Error::Indefinite; | |
| 942 if (!m_pProperties->m_pThemeProvider) | |
| 943 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 944 | |
| 945 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); | |
| 946 GetClientRect(m_rtClient); | |
| 947 m_pEdit->SetWidgetRect(m_rtClient); | |
| 948 ReSetEditAlignment(); | |
| 949 m_pEdit->Update(); | |
| 950 if (!m_pMonthCal->GetThemeProvider()) | |
| 951 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); | |
| 952 | |
| 953 if (m_pProperties->m_pDataProvider) { | |
| 954 IFWL_DateTimePickerDP* pData = | |
| 955 static_cast<IFWL_DateTimePickerDP*>(m_pProperties->m_pDataProvider); | |
| 956 pData->GetToday(m_pInterface, m_MonthCalendarDP.m_iCurYear, | |
| 957 m_MonthCalendarDP.m_iCurMonth, m_MonthCalendarDP.m_iCurDay); | |
| 958 } | |
| 959 FX_FLOAT* pWidth = static_cast<FX_FLOAT*>( | |
| 960 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 961 if (!pWidth) | |
| 962 return FWL_Error::Succeeded; | |
| 963 | |
| 964 m_fBtn = *pWidth; | |
| 965 CFX_RectF rtMonthCal; | |
| 966 m_pMonthCal->GetWidgetRect(rtMonthCal, TRUE); | |
| 967 CFX_RectF rtPopUp; | |
| 968 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, | |
| 969 rtMonthCal.width, rtMonthCal.height); | |
| 970 m_pMonthCal->SetWidgetRect(rtPopUp); | |
| 971 m_pMonthCal->Update(); | |
| 972 return FWL_Error::Succeeded; | |
| 973 } | |
| 974 | |
| 975 FWL_Error CFWL_DateTimePickerImp::DisForm_GetWidgetRect(CFX_RectF& rect, | |
| 976 FX_BOOL bAutoSize) { | |
| 977 rect = m_pProperties->m_rtWidget; | |
| 978 if (DisForm_IsNeedShowButton()) { | |
| 979 rect.width += m_fBtn; | |
| 980 } | |
| 981 return FWL_Error::Succeeded; | |
| 982 } | |
| 983 FWL_Error CFWL_DateTimePickerImp::DisForm_GetBBox(CFX_RectF& rect) { | |
| 984 rect = m_pProperties->m_rtWidget; | |
| 985 if (DisForm_IsNeedShowButton()) { | |
| 986 rect.width += m_fBtn; | |
| 987 } | |
| 988 if (IsMonthCalendarShowed()) { | |
| 989 CFX_RectF rtMonth; | |
| 990 m_pMonthCal->GetWidgetRect(rtMonth); | |
| 991 rtMonth.Offset(m_pProperties->m_rtWidget.left, | |
| 992 m_pProperties->m_rtWidget.top); | |
| 993 rect.Union(rtMonth); | |
| 994 } | |
| 995 return FWL_Error::Succeeded; | |
| 996 } | |
| 997 FWL_Error CFWL_DateTimePickerImp::DisForm_DrawWidget( | |
| 998 CFX_Graphics* pGraphics, | |
| 999 const CFX_Matrix* pMatrix) { | |
| 1000 if (!pGraphics) | |
| 1001 return FWL_Error::Indefinite; | |
| 1002 if (m_pEdit) { | |
| 1003 CFX_RectF rtEdit; | |
| 1004 m_pEdit->GetWidgetRect(rtEdit); | |
| 1005 CFX_Matrix mt; | |
| 1006 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); | |
| 1007 if (pMatrix) { | |
| 1008 mt.Concat(*pMatrix); | |
| 1009 } | |
| 1010 m_pEdit->DrawWidget(pGraphics, &mt); | |
| 1011 } | |
| 1012 if (IsMonthCalendarShowed()) { | |
| 1013 CFX_RectF rtMonth; | |
| 1014 m_pMonthCal->GetWidgetRect(rtMonth); | |
| 1015 CFX_Matrix mt; | |
| 1016 mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top); | |
| 1017 if (pMatrix) { | |
| 1018 mt.Concat(*pMatrix); | |
| 1019 } | |
| 1020 m_pMonthCal->DrawWidget(pGraphics, &mt); | |
| 1021 } | |
| 1022 return FWL_Error::Succeeded; | |
| 1023 } | |
| 1024 | |
| 1025 CFWL_DateTimePickerImpDelegate::CFWL_DateTimePickerImpDelegate( | |
| 1026 CFWL_DateTimePickerImp* pOwner) | |
| 1027 : m_pOwner(pOwner) {} | |
| 1028 | |
| 1029 void CFWL_DateTimePickerImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 1030 if (!pMessage) | |
| 1031 return; | |
| 1032 | |
| 1033 switch (pMessage->GetClassID()) { | |
| 1034 case CFWL_MessageType::SetFocus: { | |
| 1035 OnFocusChanged(pMessage, TRUE); | |
| 1036 break; | |
| 1037 } | |
| 1038 case CFWL_MessageType::KillFocus: { | |
| 1039 OnFocusChanged(pMessage, FALSE); | |
| 1040 break; | |
| 1041 } | |
| 1042 case CFWL_MessageType::Mouse: { | |
| 1043 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 1044 switch (pMouse->m_dwCmd) { | |
| 1045 case FWL_MouseCommand::LeftButtonDown: { | |
| 1046 OnLButtonDown(pMouse); | |
| 1047 break; | |
| 1048 } | |
| 1049 case FWL_MouseCommand::LeftButtonUp: { | |
| 1050 OnLButtonUp(pMouse); | |
| 1051 break; | |
| 1052 } | |
| 1053 case FWL_MouseCommand::Move: { | |
| 1054 OnMouseMove(pMouse); | |
| 1055 break; | |
| 1056 } | |
| 1057 case FWL_MouseCommand::Leave: { | |
| 1058 OnMouseLeave(pMouse); | |
| 1059 break; | |
| 1060 } | |
| 1061 default: | |
| 1062 break; | |
| 1063 } | |
| 1064 break; | |
| 1065 } | |
| 1066 case CFWL_MessageType::Key: { | |
| 1067 if (m_pOwner->m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { | |
| 1068 IFWL_WidgetDelegate* pDelegate = | |
| 1069 m_pOwner->m_pEdit->SetDelegate(nullptr); | |
| 1070 pDelegate->OnProcessMessage(pMessage); | |
| 1071 return; | |
| 1072 } | |
| 1073 break; | |
| 1074 } | |
| 1075 default: | |
| 1076 break; | |
| 1077 } | |
| 1078 | |
| 1079 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | |
| 1080 } | |
| 1081 | |
| 1082 void CFWL_DateTimePickerImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 1083 const CFX_Matrix* pMatrix) { | |
| 1084 m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 1085 } | |
| 1086 | |
| 1087 void CFWL_DateTimePickerImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | |
| 1088 FX_BOOL bSet) { | |
| 1089 if (!pMsg) | |
| 1090 return; | |
| 1091 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | |
| 1092 return DisForm_OnFocusChanged(pMsg, bSet); | |
| 1093 } | |
| 1094 if (bSet) { | |
| 1095 m_pOwner->m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | |
| 1096 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1097 } else { | |
| 1098 m_pOwner->m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | |
| 1099 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1100 } | |
| 1101 if (pMsg->m_pSrcTarget == m_pOwner->m_pMonthCal.get() && | |
| 1102 m_pOwner->IsMonthCalendarShowed()) { | |
| 1103 m_pOwner->ShowMonthCalendar(FALSE); | |
| 1104 } | |
| 1105 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1106 } | |
| 1107 void CFWL_DateTimePickerImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
| 1108 if (!pMsg) | |
| 1109 return; | |
| 1110 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | |
| 1111 m_pOwner->SetFocus(TRUE); | |
| 1112 } | |
| 1113 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1114 if (m_pOwner->IsMonthCalendarShowed()) { | |
| 1115 m_pOwner->ShowMonthCalendar(FALSE); | |
| 1116 CFWL_Event_DtpCloseUp ev; | |
| 1117 m_pOwner->DispatchEvent(&ev); | |
| 1118 } else { | |
| 1119 if (!(m_pOwner->m_pProperties->m_dwStyleExes & | |
| 1120 FWL_STYLEEXT_DTP_TimeFormat)) { | |
| 1121 m_pOwner->ShowMonthCalendar(TRUE); | |
| 1122 CFWL_Event_DtpDropDown ev; | |
| 1123 m_pOwner->DispatchEvent(&ev); | |
| 1124 } else { | |
| 1125 } | |
| 1126 m_pOwner->m_bLBtnDown = TRUE; | |
| 1127 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1128 } | |
| 1129 } | |
| 1130 } | |
| 1131 void CFWL_DateTimePickerImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
| 1132 if (!pMsg) | |
| 1133 return; | |
| 1134 m_pOwner->m_bLBtnDown = FALSE; | |
| 1135 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1136 m_pOwner->m_iBtnState = CFWL_PartState_Hovered; | |
| 1137 } else { | |
| 1138 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
| 1139 } | |
| 1140 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | |
| 1141 } | |
| 1142 void CFWL_DateTimePickerImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
| 1143 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1144 } else { | |
| 1145 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
| 1146 } | |
| 1147 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | |
| 1148 } | |
| 1149 void CFWL_DateTimePickerImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | |
| 1150 if (!pMsg) | |
| 1151 return; | |
| 1152 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
| 1153 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | |
| 1154 } | |
| 1155 void CFWL_DateTimePickerImpDelegate::DisForm_OnFocusChanged(CFWL_Message* pMsg, | |
| 1156 FX_BOOL bSet) { | |
| 1157 CFX_RectF rtInvalidate(m_pOwner->m_rtBtn); | |
| 1158 if (bSet) { | |
| 1159 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 1160 if (m_pOwner->m_pEdit && | |
| 1161 !(m_pOwner->m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) { | |
| 1162 m_pOwner->m_rtBtn.Set(m_pOwner->m_pProperties->m_rtWidget.width, 0, | |
| 1163 m_pOwner->m_fBtn, | |
| 1164 m_pOwner->m_pProperties->m_rtWidget.height - 1); | |
| 1165 } | |
| 1166 rtInvalidate = m_pOwner->m_rtBtn; | |
| 1167 pMsg->m_pDstTarget = m_pOwner->m_pEdit.get(); | |
| 1168 IFWL_WidgetDelegate* pDelegate = m_pOwner->m_pEdit->SetDelegate(nullptr); | |
| 1169 pDelegate->OnProcessMessage(pMsg); | |
| 1170 } else { | |
| 1171 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 1172 m_pOwner->m_rtBtn.Set(0, 0, 0, 0); | |
| 1173 if (m_pOwner->DisForm_IsMonthCalendarShowed()) { | |
| 1174 m_pOwner->ShowMonthCalendar(FALSE); | |
| 1175 } | |
| 1176 if (m_pOwner->m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { | |
| 1177 pMsg->m_pSrcTarget = m_pOwner->m_pEdit.get(); | |
| 1178 IFWL_WidgetDelegate* pDelegate = m_pOwner->m_pEdit->SetDelegate(nullptr); | |
| 1179 pDelegate->OnProcessMessage(pMsg); | |
| 1180 } | |
| 1181 } | |
| 1182 rtInvalidate.Inflate(2, 2); | |
| 1183 m_pOwner->Repaint(&rtInvalidate); | |
| 1184 } | |
| 1185 | |
| 1186 CFWL_DateTimePickerImp::CFWL_MonthCalendarImpDP::CFWL_MonthCalendarImpDP() { | |
| 1187 m_iCurYear = 2010; | |
| 1188 m_iCurMonth = 3; | |
| 1189 m_iCurDay = 29; | |
| 1190 } | |
| 1191 | |
| 1192 FWL_Error CFWL_DateTimePickerImp::CFWL_MonthCalendarImpDP::GetCaption( | |
| 1193 IFWL_Widget* pWidget, | |
| 1194 CFX_WideString& wsCaption) { | |
| 1195 return FWL_Error::Succeeded; | |
| 1196 } | |
| 1197 | |
| 1198 int32_t CFWL_DateTimePickerImp::CFWL_MonthCalendarImpDP::GetCurDay( | |
| 1199 IFWL_Widget* pWidget) { | |
| 1200 return m_iCurDay; | |
| 1201 } | |
| 1202 | |
| 1203 int32_t CFWL_DateTimePickerImp::CFWL_MonthCalendarImpDP::GetCurMonth( | |
| 1204 IFWL_Widget* pWidget) { | |
| 1205 return m_iCurMonth; | |
| 1206 } | |
| 1207 | |
| 1208 int32_t CFWL_DateTimePickerImp::CFWL_MonthCalendarImpDP::GetCurYear( | |
| 1209 IFWL_Widget* pWidget) { | |
| 1210 return m_iCurYear; | |
| 1211 } | |
| OLD | NEW |