OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/cfwl_datetimepicker.h" | 7 #include "xfa/fwl/cfwl_datetimepicker.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 if (m_pWidgetMgr->IsFormDisabled()) { | 70 if (m_pWidgetMgr->IsFormDisabled()) { |
71 DisForm_Update(); | 71 DisForm_Update(); |
72 return; | 72 return; |
73 } | 73 } |
74 if (m_iLock) | 74 if (m_iLock) |
75 return; | 75 return; |
76 if (!m_pProperties->m_pThemeProvider) | 76 if (!m_pProperties->m_pThemeProvider) |
77 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 77 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
78 | 78 |
79 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); | 79 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); |
80 GetClientRect(m_rtClient); | 80 m_rtClient = GetClientRect(); |
81 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | 81 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( |
82 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 82 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
83 if (!pFWidth) | 83 if (!pFWidth) |
84 return; | 84 return; |
85 | 85 |
86 FX_FLOAT fBtn = *pFWidth; | 86 FX_FLOAT fBtn = *pFWidth; |
87 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1, | 87 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1, |
88 m_rtClient.height - 1); | 88 m_rtClient.height - 1); |
89 | 89 |
90 CFX_RectF rtEdit; | 90 CFX_RectF rtEdit; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 m_iMonth = iMonth; | 165 m_iMonth = iMonth; |
166 m_iDay = iDay; | 166 m_iDay = iDay; |
167 m_pMonthCal->SetSelect(iYear, iMonth, iDay); | 167 m_pMonthCal->SetSelect(iYear, iMonth, iDay); |
168 } | 168 } |
169 | 169 |
170 void CFWL_DateTimePicker::SetEditText(const CFX_WideString& wsText) { | 170 void CFWL_DateTimePicker::SetEditText(const CFX_WideString& wsText) { |
171 if (!m_pEdit) | 171 if (!m_pEdit) |
172 return; | 172 return; |
173 | 173 |
174 m_pEdit->SetText(wsText); | 174 m_pEdit->SetText(wsText); |
175 Repaint(&m_rtClient); | 175 RepaintRect(m_rtClient); |
176 | 176 |
177 CFWL_Event ev(CFWL_Event::Type::EditChanged); | 177 CFWL_Event ev(CFWL_Event::Type::EditChanged); |
178 DispatchEvent(&ev); | 178 DispatchEvent(&ev); |
179 } | 179 } |
180 | 180 |
181 CFX_WideString CFWL_DateTimePicker::GetEditText() const { | 181 CFX_WideString CFWL_DateTimePicker::GetEditText() const { |
182 return m_pEdit ? m_pEdit->GetText() : L""; | 182 return m_pEdit ? m_pEdit->GetText() : L""; |
183 } | 183 } |
184 | 184 |
185 void CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) const { | 185 void CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) const { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 int32_t iMonth, | 320 int32_t iMonth, |
321 int32_t iDay) { | 321 int32_t iDay) { |
322 m_iYear = iYear; | 322 m_iYear = iYear; |
323 m_iMonth = iMonth; | 323 m_iMonth = iMonth; |
324 m_iDay = iDay; | 324 m_iDay = iDay; |
325 | 325 |
326 CFX_WideString wsText; | 326 CFX_WideString wsText; |
327 FormatDateString(m_iYear, m_iMonth, m_iDay, wsText); | 327 FormatDateString(m_iYear, m_iMonth, m_iDay, wsText); |
328 m_pEdit->SetText(wsText); | 328 m_pEdit->SetText(wsText); |
329 m_pEdit->Update(); | 329 m_pEdit->Update(); |
330 Repaint(&m_rtClient); | 330 RepaintRect(m_rtClient); |
331 | 331 |
332 CFWL_EventSelectChanged ev(this); | 332 CFWL_EventSelectChanged ev(this); |
333 ev.iYear = m_iYear; | 333 ev.iYear = m_iYear; |
334 ev.iMonth = m_iMonth; | 334 ev.iMonth = m_iMonth; |
335 ev.iDay = m_iDay; | 335 ev.iDay = m_iDay; |
336 DispatchEvent(&ev); | 336 DispatchEvent(&ev); |
337 } | 337 } |
338 | 338 |
339 void CFWL_DateTimePicker::InitProxyForm() { | 339 void CFWL_DateTimePicker::InitProxyForm() { |
340 if (m_pForm) | 340 if (m_pForm) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 m_pEdit->GetDelegate()->OnProcessMessage(&msg); | 386 m_pEdit->GetDelegate()->OnProcessMessage(&msg); |
387 } | 387 } |
388 | 388 |
389 CFX_RectF rtInvalidate; | 389 CFX_RectF rtInvalidate; |
390 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 390 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
391 m_pProperties->m_rtWidget.height); | 391 m_pProperties->m_rtWidget.height); |
392 | 392 |
393 CFX_RectF rtCal = m_pMonthCal->GetWidgetRect(); | 393 CFX_RectF rtCal = m_pMonthCal->GetWidgetRect(); |
394 rtInvalidate.Union(rtCal); | 394 rtInvalidate.Union(rtCal); |
395 rtInvalidate.Inflate(2, 2); | 395 rtInvalidate.Inflate(2, 2); |
396 Repaint(&rtInvalidate); | 396 RepaintRect(rtInvalidate); |
397 } | 397 } |
398 | 398 |
399 FWL_WidgetHit CFWL_DateTimePicker::DisForm_HitTest(FX_FLOAT fx, | 399 FWL_WidgetHit CFWL_DateTimePicker::DisForm_HitTest(FX_FLOAT fx, |
400 FX_FLOAT fy) const { | 400 FX_FLOAT fy) const { |
401 CFX_RectF rect; | 401 CFX_RectF rect; |
402 rect.Set(0, 0, m_pProperties->m_rtWidget.width, | 402 rect.Set(0, 0, m_pProperties->m_rtWidget.width, |
403 m_pProperties->m_rtWidget.height); | 403 m_pProperties->m_rtWidget.height); |
404 if (rect.Contains(fx, fy)) | 404 if (rect.Contains(fx, fy)) |
405 return FWL_WidgetHit::Edit; | 405 return FWL_WidgetHit::Edit; |
406 if (DisForm_IsNeedShowButton()) | 406 if (DisForm_IsNeedShowButton()) |
(...skipping 13 matching lines...) Expand all Loading... |
420 m_pEdit->GetStates() & FWL_WGTSTATE_Focused; | 420 m_pEdit->GetStates() & FWL_WGTSTATE_Focused; |
421 } | 421 } |
422 | 422 |
423 void CFWL_DateTimePicker::DisForm_Update() { | 423 void CFWL_DateTimePicker::DisForm_Update() { |
424 if (m_iLock) | 424 if (m_iLock) |
425 return; | 425 return; |
426 if (!m_pProperties->m_pThemeProvider) | 426 if (!m_pProperties->m_pThemeProvider) |
427 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 427 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
428 | 428 |
429 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); | 429 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); |
430 GetClientRect(m_rtClient); | 430 m_rtClient = GetClientRect(); |
431 m_pEdit->SetWidgetRect(m_rtClient); | 431 m_pEdit->SetWidgetRect(m_rtClient); |
432 ResetEditAlignment(); | 432 ResetEditAlignment(); |
433 m_pEdit->Update(); | 433 m_pEdit->Update(); |
434 | 434 |
435 if (!m_pMonthCal->GetThemeProvider()) | 435 if (!m_pMonthCal->GetThemeProvider()) |
436 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); | 436 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); |
437 | 437 |
438 FX_FLOAT* pWidth = static_cast<FX_FLOAT*>( | 438 FX_FLOAT* pWidth = static_cast<FX_FLOAT*>( |
439 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 439 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
440 if (!pWidth) | 440 if (!pWidth) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 536 } |
537 | 537 |
538 void CFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { | 538 void CFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
539 if (!pMsg) | 539 if (!pMsg) |
540 return; | 540 return; |
541 if (m_pWidgetMgr->IsFormDisabled()) | 541 if (m_pWidgetMgr->IsFormDisabled()) |
542 return DisForm_OnFocusChanged(pMsg, bSet); | 542 return DisForm_OnFocusChanged(pMsg, bSet); |
543 | 543 |
544 if (bSet) { | 544 if (bSet) { |
545 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 545 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
546 Repaint(&m_rtClient); | 546 RepaintRect(m_rtClient); |
547 } else { | 547 } else { |
548 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | 548 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
549 Repaint(&m_rtClient); | 549 RepaintRect(m_rtClient); |
550 } | 550 } |
551 if (pMsg->m_pSrcTarget == m_pMonthCal.get() && IsMonthCalendarVisible()) { | 551 if (pMsg->m_pSrcTarget == m_pMonthCal.get() && IsMonthCalendarVisible()) { |
552 ShowMonthCalendar(false); | 552 ShowMonthCalendar(false); |
553 } | 553 } |
554 Repaint(&m_rtClient); | 554 RepaintRect(m_rtClient); |
555 } | 555 } |
556 | 556 |
557 void CFWL_DateTimePicker::OnLButtonDown(CFWL_MessageMouse* pMsg) { | 557 void CFWL_DateTimePicker::OnLButtonDown(CFWL_MessageMouse* pMsg) { |
558 if (!pMsg) | 558 if (!pMsg) |
559 return; | 559 return; |
560 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 560 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
561 SetFocus(true); | 561 SetFocus(true); |
562 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) | 562 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
563 return; | 563 return; |
564 | 564 |
565 if (IsMonthCalendarVisible()) { | 565 if (IsMonthCalendarVisible()) { |
566 ShowMonthCalendar(false); | 566 ShowMonthCalendar(false); |
567 return; | 567 return; |
568 } | 568 } |
569 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat)) | 569 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat)) |
570 ShowMonthCalendar(true); | 570 ShowMonthCalendar(true); |
571 | 571 |
572 m_bLBtnDown = true; | 572 m_bLBtnDown = true; |
573 Repaint(&m_rtClient); | 573 RepaintRect(m_rtClient); |
574 } | 574 } |
575 | 575 |
576 void CFWL_DateTimePicker::OnLButtonUp(CFWL_MessageMouse* pMsg) { | 576 void CFWL_DateTimePicker::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
577 if (!pMsg) | 577 if (!pMsg) |
578 return; | 578 return; |
579 | 579 |
580 m_bLBtnDown = false; | 580 m_bLBtnDown = false; |
581 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) | 581 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
582 m_iBtnState = CFWL_PartState_Hovered; | 582 m_iBtnState = CFWL_PartState_Hovered; |
583 else | 583 else |
584 m_iBtnState = CFWL_PartState_Normal; | 584 m_iBtnState = CFWL_PartState_Normal; |
585 Repaint(&m_rtBtn); | 585 RepaintRect(m_rtBtn); |
586 } | 586 } |
587 | 587 |
588 void CFWL_DateTimePicker::OnMouseMove(CFWL_MessageMouse* pMsg) { | 588 void CFWL_DateTimePicker::OnMouseMove(CFWL_MessageMouse* pMsg) { |
589 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) | 589 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
590 m_iBtnState = CFWL_PartState_Normal; | 590 m_iBtnState = CFWL_PartState_Normal; |
591 Repaint(&m_rtBtn); | 591 RepaintRect(m_rtBtn); |
592 } | 592 } |
593 | 593 |
594 void CFWL_DateTimePicker::OnMouseLeave(CFWL_MessageMouse* pMsg) { | 594 void CFWL_DateTimePicker::OnMouseLeave(CFWL_MessageMouse* pMsg) { |
595 if (!pMsg) | 595 if (!pMsg) |
596 return; | 596 return; |
597 m_iBtnState = CFWL_PartState_Normal; | 597 m_iBtnState = CFWL_PartState_Normal; |
598 Repaint(&m_rtBtn); | 598 RepaintRect(m_rtBtn); |
599 } | 599 } |
600 | 600 |
601 void CFWL_DateTimePicker::DisForm_OnFocusChanged(CFWL_Message* pMsg, | 601 void CFWL_DateTimePicker::DisForm_OnFocusChanged(CFWL_Message* pMsg, |
602 bool bSet) { | 602 bool bSet) { |
603 CFX_RectF rtInvalidate(m_rtBtn); | 603 CFX_RectF rtInvalidate(m_rtBtn); |
604 if (bSet) { | 604 if (bSet) { |
605 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 605 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
606 if (m_pEdit && !(m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) { | 606 if (m_pEdit && !(m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) { |
607 m_rtBtn.Set(m_pProperties->m_rtWidget.width, 0, m_fBtn, | 607 m_rtBtn.Set(m_pProperties->m_rtWidget.width, 0, m_fBtn, |
608 m_pProperties->m_rtWidget.height - 1); | 608 m_pProperties->m_rtWidget.height - 1); |
609 } | 609 } |
610 rtInvalidate = m_rtBtn; | 610 rtInvalidate = m_rtBtn; |
611 pMsg->m_pDstTarget = m_pEdit.get(); | 611 pMsg->m_pDstTarget = m_pEdit.get(); |
612 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 612 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
613 } else { | 613 } else { |
614 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 614 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
615 m_rtBtn.Set(0, 0, 0, 0); | 615 m_rtBtn.Set(0, 0, 0, 0); |
616 if (DisForm_IsMonthCalendarVisible()) | 616 if (DisForm_IsMonthCalendarVisible()) |
617 ShowMonthCalendar(false); | 617 ShowMonthCalendar(false); |
618 if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { | 618 if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { |
619 pMsg->m_pSrcTarget = m_pEdit.get(); | 619 pMsg->m_pSrcTarget = m_pEdit.get(); |
620 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 620 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
621 } | 621 } |
622 } | 622 } |
623 rtInvalidate.Inflate(2, 2); | 623 rtInvalidate.Inflate(2, 2); |
624 Repaint(&rtInvalidate); | 624 RepaintRect(rtInvalidate); |
625 } | 625 } |
OLD | NEW |