Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: xfa/src/fwl/basewidget/fwl_datetimepickerimp.cpp

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

Powered by Google App Engine
This is Rietveld 408576698