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

Side by Side Diff: xfa/fwl/core/cfwl_datetimepicker.cpp

Issue 2559173002: Move xfa/fwl/core to xfa/fwl. (Closed)
Patch Set: Created 4 years 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/fwl/core/cfwl_datetimepicker.h ('k') | xfa/fwl/core/cfwl_edit.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/fwl/core/cfwl_datetimepicker.h"
8
9 #include <memory>
10 #include <utility>
11
12 #include "third_party/base/ptr_util.h"
13 #include "xfa/fwl/core/cfwl_event.h"
14 #include "xfa/fwl/core/cfwl_evtselectchanged.h"
15 #include "xfa/fwl/core/cfwl_formproxy.h"
16 #include "xfa/fwl/core/cfwl_msgmouse.h"
17 #include "xfa/fwl/core/cfwl_msgsetfocus.h"
18 #include "xfa/fwl/core/cfwl_notedriver.h"
19 #include "xfa/fwl/core/cfwl_spinbutton.h"
20 #include "xfa/fwl/core/cfwl_themebackground.h"
21 #include "xfa/fwl/core/cfwl_widgetmgr.h"
22 #include "xfa/fwl/core/ifwl_themeprovider.h"
23
24 namespace {
25
26 const int kDateTimePickerHeight = 20;
27
28 } // namespace
29 CFWL_DateTimePicker::CFWL_DateTimePicker(const CFWL_App* app)
30 : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr),
31 m_iBtnState(1),
32 m_iYear(-1),
33 m_iMonth(-1),
34 m_iDay(-1),
35 m_bLBtnDown(false) {
36 m_rtBtn.Set(0, 0, 0, 0);
37
38 m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat;
39
40 auto monthProp = pdfium::MakeUnique<CFWL_WidgetProperties>();
41 monthProp->m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border;
42 monthProp->m_dwStates = FWL_WGTSTATE_Invisible;
43 monthProp->m_pParent = this;
44 monthProp->m_pThemeProvider = m_pProperties->m_pThemeProvider;
45 m_pMonthCal.reset(
46 new CFWL_MonthCalendar(m_pOwnerApp, std::move(monthProp), this));
47
48 CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
49 rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height);
50 m_pMonthCal->SetWidgetRect(rtMonthCal);
51
52 auto editProp = pdfium::MakeUnique<CFWL_WidgetProperties>();
53 editProp->m_pParent = this;
54 editProp->m_pThemeProvider = m_pProperties->m_pThemeProvider;
55
56 m_pEdit.reset(new CFWL_DateTimeEdit(m_pOwnerApp, std::move(editProp), this));
57 RegisterEventTarget(m_pMonthCal.get());
58 RegisterEventTarget(m_pEdit.get());
59 }
60
61 CFWL_DateTimePicker::~CFWL_DateTimePicker() {
62 UnregisterEventTarget();
63 }
64
65 FWL_Type CFWL_DateTimePicker::GetClassID() const {
66 return FWL_Type::DateTimePicker;
67 }
68
69 void CFWL_DateTimePicker::Update() {
70 if (m_pWidgetMgr->IsFormDisabled()) {
71 DisForm_Update();
72 return;
73 }
74 if (m_iLock)
75 return;
76 if (!m_pProperties->m_pThemeProvider)
77 m_pProperties->m_pThemeProvider = GetAvailableTheme();
78
79 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider);
80 GetClientRect(m_rtClient);
81 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>(
82 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
83 if (!pFWidth)
84 return;
85
86 FX_FLOAT fBtn = *pFWidth;
87 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1,
88 m_rtClient.height - 1);
89
90 CFX_RectF rtEdit;
91 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn,
92 m_rtClient.height);
93 m_pEdit->SetWidgetRect(rtEdit);
94 ResetEditAlignment();
95 m_pEdit->Update();
96 if (!(m_pMonthCal->GetThemeProvider()))
97 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider);
98
99 CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
100 CFX_RectF rtPopUp;
101 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight,
102 rtMonthCal.width, rtMonthCal.height);
103 m_pMonthCal->SetWidgetRect(rtPopUp);
104 m_pMonthCal->Update();
105 return;
106 }
107
108 FWL_WidgetHit CFWL_DateTimePicker::HitTest(FX_FLOAT fx, FX_FLOAT fy) {
109 if (m_pWidgetMgr->IsFormDisabled())
110 return DisForm_HitTest(fx, fy);
111 if (m_rtClient.Contains(fx, fy))
112 return FWL_WidgetHit::Client;
113 if (IsMonthCalendarVisible()) {
114 CFX_RectF rect = m_pMonthCal->GetWidgetRect();
115 if (rect.Contains(fx, fy))
116 return FWL_WidgetHit::Client;
117 }
118 return FWL_WidgetHit::Unknown;
119 }
120
121 void CFWL_DateTimePicker::DrawWidget(CFX_Graphics* pGraphics,
122 const CFX_Matrix* pMatrix) {
123 if (!pGraphics)
124 return;
125 if (!m_pProperties->m_pThemeProvider)
126 return;
127
128 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
129 if (HasBorder())
130 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix);
131 if (HasEdge())
132 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix);
133 if (!m_rtBtn.IsEmpty())
134 DrawDropDownButton(pGraphics, pTheme, pMatrix);
135 if (m_pWidgetMgr->IsFormDisabled()) {
136 DisForm_DrawWidget(pGraphics, pMatrix);
137 return;
138 }
139 }
140
141 void CFWL_DateTimePicker::SetThemeProvider(IFWL_ThemeProvider* pTP) {
142 m_pProperties->m_pThemeProvider = pTP;
143 m_pMonthCal->SetThemeProvider(pTP);
144 }
145
146 void CFWL_DateTimePicker::GetCurSel(int32_t& iYear,
147 int32_t& iMonth,
148 int32_t& iDay) {
149 iYear = m_iYear;
150 iMonth = m_iMonth;
151 iDay = m_iDay;
152 }
153
154 void CFWL_DateTimePicker::SetCurSel(int32_t iYear,
155 int32_t iMonth,
156 int32_t iDay) {
157 if (iYear <= 0 || iYear >= 3000)
158 return;
159 if (iMonth <= 0 || iMonth >= 13)
160 return;
161 if (iDay <= 0 || iDay >= 32)
162 return;
163
164 m_iYear = iYear;
165 m_iMonth = iMonth;
166 m_iDay = iDay;
167 m_pMonthCal->SetSelect(iYear, iMonth, iDay);
168 }
169
170 void CFWL_DateTimePicker::SetEditText(const CFX_WideString& wsText) {
171 if (!m_pEdit)
172 return;
173
174 m_pEdit->SetText(wsText);
175 Repaint(&m_rtClient);
176
177 CFWL_Event ev(CFWL_Event::Type::EditChanged);
178 DispatchEvent(&ev);
179 }
180
181 CFX_WideString CFWL_DateTimePicker::GetEditText() const {
182 return m_pEdit ? m_pEdit->GetText() : L"";
183 }
184
185 void CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) const {
186 if (m_pWidgetMgr->IsFormDisabled()) {
187 DisForm_GetBBox(rect);
188 return;
189 }
190
191 rect = m_pProperties->m_rtWidget;
192 if (IsMonthCalendarVisible()) {
193 CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect();
194 rtMonth.Offset(m_pProperties->m_rtWidget.left,
195 m_pProperties->m_rtWidget.top);
196 rect.Union(rtMonth);
197 }
198 }
199
200 void CFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded,
201 uint32_t dwStylesExRemoved) {
202 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
203 }
204
205 void CFWL_DateTimePicker::DrawDropDownButton(CFX_Graphics* pGraphics,
206 IFWL_ThemeProvider* pTheme,
207 const CFX_Matrix* pMatrix) {
208 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_Spin) ==
209 FWL_STYLEEXT_DTP_Spin) {
210 return;
211 }
212
213 CFWL_ThemeBackground param;
214 param.m_pWidget = this;
215 param.m_iPart = CFWL_Part::DropDownButton;
216 param.m_dwStates = m_iBtnState;
217 param.m_pGraphics = pGraphics;
218 param.m_rtPart = m_rtBtn;
219 if (pMatrix)
220 param.m_matrix.Concat(*pMatrix);
221 pTheme->DrawBackground(&param);
222 }
223
224 void CFWL_DateTimePicker::FormatDateString(int32_t iYear,
225 int32_t iMonth,
226 int32_t iDay,
227 CFX_WideString& wsText) {
228 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat) ==
229 FWL_STYLEEXT_DTP_ShortDateFormat) {
230 wsText.Format(L"%d-%d-%d", iYear, iMonth, iDay);
231 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_LongDateFormat) ==
232 FWL_STYLEEXT_DTP_LongDateFormat) {
233 wsText.Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay);
234 }
235 }
236
237 void CFWL_DateTimePicker::ShowMonthCalendar(bool bActivate) {
238 if (m_pWidgetMgr->IsFormDisabled())
239 return DisForm_ShowMonthCalendar(bActivate);
240 if (IsMonthCalendarVisible() == bActivate)
241 return;
242 if (!m_pForm)
243 InitProxyForm();
244
245 if (!bActivate) {
246 m_pForm->EndDoModal();
247 return;
248 }
249
250 CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect();
251
252 CFX_RectF rtAnchor;
253 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width,
254 m_pProperties->m_rtWidget.height);
255 GetPopupPos(0, rtMonth.height, rtAnchor, rtMonth);
256 m_pForm->SetWidgetRect(rtMonth);
257
258 rtMonth.left = rtMonth.top = 0;
259 if (bActivate)
260 m_pMonthCal->RemoveStates(FWL_WGTSTATE_Invisible);
261 else
262 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible);
263 m_pMonthCal->SetWidgetRect(rtMonth);
264 m_pMonthCal->Update();
265 m_pForm->DoModal();
266 }
267
268 bool CFWL_DateTimePicker::IsMonthCalendarVisible() const {
269 if (m_pWidgetMgr->IsFormDisabled())
270 return DisForm_IsMonthCalendarVisible();
271 if (!m_pForm)
272 return false;
273 return !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible);
274 }
275
276 void CFWL_DateTimePicker::ResetEditAlignment() {
277 if (!m_pEdit)
278 return;
279
280 uint32_t dwAdd = 0;
281 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditHAlignMask) {
282 case FWL_STYLEEXT_DTP_EditHCenter: {
283 dwAdd |= FWL_STYLEEXT_EDT_HCenter;
284 break;
285 }
286 case FWL_STYLEEXT_DTP_EditHFar: {
287 dwAdd |= FWL_STYLEEXT_EDT_HFar;
288 break;
289 }
290 default: {
291 dwAdd |= FWL_STYLEEXT_EDT_HNear;
292 break;
293 }
294 }
295 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditVAlignMask) {
296 case FWL_STYLEEXT_DTP_EditVCenter: {
297 dwAdd |= FWL_STYLEEXT_EDT_VCenter;
298 break;
299 }
300 case FWL_STYLEEXT_DTP_EditVFar: {
301 dwAdd |= FWL_STYLEEXT_EDT_VFar;
302 break;
303 }
304 default: {
305 dwAdd |= FWL_STYLEEXT_EDT_VNear;
306 break;
307 }
308 }
309 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditJustified)
310 dwAdd |= FWL_STYLEEXT_EDT_Justified;
311 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditDistributed)
312 dwAdd |= FWL_STYLEEXT_EDT_Distributed;
313
314 m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask |
315 FWL_STYLEEXT_EDT_HAlignModeMask |
316 FWL_STYLEEXT_EDT_VAlignMask);
317 }
318
319 void CFWL_DateTimePicker::ProcessSelChanged(int32_t iYear,
320 int32_t iMonth,
321 int32_t iDay) {
322 m_iYear = iYear;
323 m_iMonth = iMonth;
324 m_iDay = iDay;
325
326 CFX_WideString wsText;
327 FormatDateString(m_iYear, m_iMonth, m_iDay, wsText);
328 m_pEdit->SetText(wsText);
329 m_pEdit->Update();
330 Repaint(&m_rtClient);
331
332 CFWL_EvtSelectChanged ev(this);
333 ev.iYear = m_iYear;
334 ev.iMonth = m_iMonth;
335 ev.iDay = m_iDay;
336 DispatchEvent(&ev);
337 }
338
339 void CFWL_DateTimePicker::InitProxyForm() {
340 if (m_pForm)
341 return;
342 if (!m_pMonthCal)
343 return;
344
345 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
346 prop->m_dwStyles = FWL_WGTSTYLE_Popup;
347 prop->m_dwStates = FWL_WGTSTATE_Invisible;
348 prop->m_pOwner = this;
349
350 m_pForm = pdfium::MakeUnique<CFWL_FormProxy>(m_pOwnerApp, std::move(prop),
351 m_pMonthCal.get());
352 m_pMonthCal->SetParent(m_pForm.get());
353 }
354
355 bool CFWL_DateTimePicker::DisForm_IsMonthCalendarVisible() const {
356 if (!m_pMonthCal)
357 return false;
358 return !(m_pMonthCal->GetStates() & FWL_WGTSTATE_Invisible);
359 }
360
361 void CFWL_DateTimePicker::DisForm_ShowMonthCalendar(bool bActivate) {
362 if (IsMonthCalendarVisible() == bActivate)
363 return;
364
365 if (bActivate) {
366 CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
367 FX_FLOAT fPopupMin = rtMonthCal.height;
368 FX_FLOAT fPopupMax = rtMonthCal.height;
369 CFX_RectF rtAnchor(m_pProperties->m_rtWidget);
370 rtAnchor.width = rtMonthCal.width;
371 rtMonthCal.left = m_rtClient.left;
372 rtMonthCal.top = rtAnchor.Height();
373 GetPopupPos(fPopupMin, fPopupMax, rtAnchor, rtMonthCal);
374 m_pMonthCal->SetWidgetRect(rtMonthCal);
375 if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0)
376 m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay);
377 m_pMonthCal->Update();
378 }
379 if (bActivate)
380 m_pMonthCal->RemoveStates(FWL_WGTSTATE_Invisible);
381 else
382 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible);
383
384 if (bActivate) {
385 CFWL_MsgSetFocus msg(m_pEdit.get(), m_pMonthCal.get());
386 m_pEdit->GetDelegate()->OnProcessMessage(&msg);
387 }
388
389 CFX_RectF rtInvalidate;
390 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width,
391 m_pProperties->m_rtWidget.height);
392
393 CFX_RectF rtCal = m_pMonthCal->GetWidgetRect();
394 rtInvalidate.Union(rtCal);
395 rtInvalidate.Inflate(2, 2);
396 Repaint(&rtInvalidate);
397 }
398
399 FWL_WidgetHit CFWL_DateTimePicker::DisForm_HitTest(FX_FLOAT fx,
400 FX_FLOAT fy) const {
401 CFX_RectF rect;
402 rect.Set(0, 0, m_pProperties->m_rtWidget.width,
403 m_pProperties->m_rtWidget.height);
404 if (rect.Contains(fx, fy))
405 return FWL_WidgetHit::Edit;
406 if (DisForm_IsNeedShowButton())
407 rect.width += m_fBtn;
408 if (rect.Contains(fx, fy))
409 return FWL_WidgetHit::Client;
410 if (IsMonthCalendarVisible()) {
411 if (m_pMonthCal->GetWidgetRect().Contains(fx, fy))
412 return FWL_WidgetHit::Client;
413 }
414 return FWL_WidgetHit::Unknown;
415 }
416
417 bool CFWL_DateTimePicker::DisForm_IsNeedShowButton() const {
418 return m_pProperties->m_dwStates & FWL_WGTSTATE_Focused ||
419 m_pMonthCal->GetStates() & FWL_WGTSTATE_Focused ||
420 m_pEdit->GetStates() & FWL_WGTSTATE_Focused;
421 }
422
423 void CFWL_DateTimePicker::DisForm_Update() {
424 if (m_iLock)
425 return;
426 if (!m_pProperties->m_pThemeProvider)
427 m_pProperties->m_pThemeProvider = GetAvailableTheme();
428
429 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider);
430 GetClientRect(m_rtClient);
431 m_pEdit->SetWidgetRect(m_rtClient);
432 ResetEditAlignment();
433 m_pEdit->Update();
434
435 if (!m_pMonthCal->GetThemeProvider())
436 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider);
437
438 FX_FLOAT* pWidth = static_cast<FX_FLOAT*>(
439 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
440 if (!pWidth)
441 return;
442
443 m_fBtn = *pWidth;
444 CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
445 CFX_RectF rtPopUp;
446 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight,
447 rtMonthCal.width, rtMonthCal.height);
448 m_pMonthCal->SetWidgetRect(rtPopUp);
449 m_pMonthCal->Update();
450 }
451
452 void CFWL_DateTimePicker::DisForm_GetBBox(CFX_RectF& rect) const {
453 rect = m_pProperties->m_rtWidget;
454 if (DisForm_IsNeedShowButton())
455 rect.width += m_fBtn;
456 if (!IsMonthCalendarVisible())
457 return;
458
459 CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect();
460 rtMonth.Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top);
461 rect.Union(rtMonth);
462 }
463
464 void CFWL_DateTimePicker::DisForm_DrawWidget(CFX_Graphics* pGraphics,
465 const CFX_Matrix* pMatrix) {
466 if (!pGraphics)
467 return;
468 if (m_pEdit) {
469 CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
470
471 CFX_Matrix mt;
472 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top);
473 if (pMatrix)
474 mt.Concat(*pMatrix);
475 m_pEdit->DrawWidget(pGraphics, &mt);
476 }
477 if (!IsMonthCalendarVisible())
478 return;
479
480 CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect();
481 CFX_Matrix mt;
482 mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top);
483 if (pMatrix)
484 mt.Concat(*pMatrix);
485 m_pMonthCal->DrawWidget(pGraphics, &mt);
486 }
487
488 void CFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) {
489 if (!pMessage)
490 return;
491
492 switch (pMessage->GetType()) {
493 case CFWL_Message::Type::SetFocus:
494 OnFocusChanged(pMessage, true);
495 break;
496 case CFWL_Message::Type::KillFocus:
497 OnFocusChanged(pMessage, false);
498 break;
499 case CFWL_Message::Type::Mouse: {
500 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage);
501 switch (pMouse->m_dwCmd) {
502 case FWL_MouseCommand::LeftButtonDown:
503 OnLButtonDown(pMouse);
504 break;
505 case FWL_MouseCommand::LeftButtonUp:
506 OnLButtonUp(pMouse);
507 break;
508 case FWL_MouseCommand::Move:
509 OnMouseMove(pMouse);
510 break;
511 case FWL_MouseCommand::Leave:
512 OnMouseLeave(pMouse);
513 break;
514 default:
515 break;
516 }
517 break;
518 }
519 case CFWL_Message::Type::Key: {
520 if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) {
521 m_pEdit->GetDelegate()->OnProcessMessage(pMessage);
522 return;
523 }
524 break;
525 }
526 default:
527 break;
528 }
529
530 CFWL_Widget::OnProcessMessage(pMessage);
531 }
532
533 void CFWL_DateTimePicker::OnDrawWidget(CFX_Graphics* pGraphics,
534 const CFX_Matrix* pMatrix) {
535 DrawWidget(pGraphics, pMatrix);
536 }
537
538 void CFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
539 if (!pMsg)
540 return;
541 if (m_pWidgetMgr->IsFormDisabled())
542 return DisForm_OnFocusChanged(pMsg, bSet);
543
544 if (bSet) {
545 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused);
546 Repaint(&m_rtClient);
547 } else {
548 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused);
549 Repaint(&m_rtClient);
550 }
551 if (pMsg->m_pSrcTarget == m_pMonthCal.get() && IsMonthCalendarVisible()) {
552 ShowMonthCalendar(false);
553 }
554 Repaint(&m_rtClient);
555 }
556
557 void CFWL_DateTimePicker::OnLButtonDown(CFWL_MsgMouse* pMsg) {
558 if (!pMsg)
559 return;
560 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)
561 SetFocus(true);
562 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
563 return;
564
565 if (IsMonthCalendarVisible()) {
566 ShowMonthCalendar(false);
567 return;
568 }
569 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat))
570 ShowMonthCalendar(true);
571
572 m_bLBtnDown = true;
573 Repaint(&m_rtClient);
574 }
575
576 void CFWL_DateTimePicker::OnLButtonUp(CFWL_MsgMouse* pMsg) {
577 if (!pMsg)
578 return;
579
580 m_bLBtnDown = false;
581 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
582 m_iBtnState = CFWL_PartState_Hovered;
583 else
584 m_iBtnState = CFWL_PartState_Normal;
585 Repaint(&m_rtBtn);
586 }
587
588 void CFWL_DateTimePicker::OnMouseMove(CFWL_MsgMouse* pMsg) {
589 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
590 m_iBtnState = CFWL_PartState_Normal;
591 Repaint(&m_rtBtn);
592 }
593
594 void CFWL_DateTimePicker::OnMouseLeave(CFWL_MsgMouse* pMsg) {
595 if (!pMsg)
596 return;
597 m_iBtnState = CFWL_PartState_Normal;
598 Repaint(&m_rtBtn);
599 }
600
601 void CFWL_DateTimePicker::DisForm_OnFocusChanged(CFWL_Message* pMsg,
602 bool bSet) {
603 CFX_RectF rtInvalidate(m_rtBtn);
604 if (bSet) {
605 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
606 if (m_pEdit && !(m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) {
607 m_rtBtn.Set(m_pProperties->m_rtWidget.width, 0, m_fBtn,
608 m_pProperties->m_rtWidget.height - 1);
609 }
610 rtInvalidate = m_rtBtn;
611 pMsg->m_pDstTarget = m_pEdit.get();
612 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
613 } else {
614 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
615 m_rtBtn.Set(0, 0, 0, 0);
616 if (DisForm_IsMonthCalendarVisible())
617 ShowMonthCalendar(false);
618 if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) {
619 pMsg->m_pSrcTarget = m_pEdit.get();
620 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
621 }
622 }
623 rtInvalidate.Inflate(2, 2);
624 Repaint(&rtInvalidate);
625 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/cfwl_datetimepicker.h ('k') | xfa/fwl/core/cfwl_edit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698