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/core/ifwl_datetimepicker.h" | 7 #include "xfa/fwl/core/ifwl_datetimepicker.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fwl/core/cfwl_message.h" | 10 #include "xfa/fwl/core/cfwl_message.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 const IFWL_App* app, | 28 const IFWL_App* app, |
29 const CFWL_WidgetImpProperties& properties) | 29 const CFWL_WidgetImpProperties& properties) |
30 : IFWL_Widget(app, properties, nullptr), | 30 : IFWL_Widget(app, properties, nullptr), |
31 m_iBtnState(1), | 31 m_iBtnState(1), |
32 m_iYear(-1), | 32 m_iYear(-1), |
33 m_iMonth(-1), | 33 m_iMonth(-1), |
34 m_iDay(-1), | 34 m_iDay(-1), |
35 m_bLBtnDown(FALSE) { | 35 m_bLBtnDown(FALSE) { |
36 m_rtBtn.Set(0, 0, 0, 0); | 36 m_rtBtn.Set(0, 0, 0, 0); |
37 | 37 |
38 SetDelegate(pdfium::MakeUnique<CFWL_DateTimePickerImpDelegate>(this)); | |
39 | |
40 m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat; | 38 m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat; |
41 CFWL_WidgetImpProperties propMonth; | 39 CFWL_WidgetImpProperties propMonth; |
42 propMonth.m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border; | 40 propMonth.m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border; |
43 propMonth.m_dwStates = FWL_WGTSTATE_Invisible; | 41 propMonth.m_dwStates = FWL_WGTSTATE_Invisible; |
44 propMonth.m_pDataProvider = &m_MonthCalendarDP; | 42 propMonth.m_pDataProvider = &m_MonthCalendarDP; |
45 propMonth.m_pParent = this; | 43 propMonth.m_pParent = this; |
46 propMonth.m_pThemeProvider = m_pProperties->m_pThemeProvider; | 44 propMonth.m_pThemeProvider = m_pProperties->m_pThemeProvider; |
47 | 45 |
48 m_pMonthCal.reset(new IFWL_DateTimeCalendar(m_pOwnerApp, propMonth, this)); | 46 m_pMonthCal.reset(new IFWL_DateTimeCalendar(m_pOwnerApp, propMonth, this)); |
49 CFX_RectF rtMonthCal; | 47 CFX_RectF rtMonthCal; |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0) { | 511 if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0) { |
514 m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay); | 512 m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay); |
515 } | 513 } |
516 m_pMonthCal->Update(); | 514 m_pMonthCal->Update(); |
517 } | 515 } |
518 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate); | 516 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate); |
519 if (bActivate) { | 517 if (bActivate) { |
520 CFWL_MsgSetFocus msg; | 518 CFWL_MsgSetFocus msg; |
521 msg.m_pDstTarget = m_pMonthCal.get(); | 519 msg.m_pDstTarget = m_pMonthCal.get(); |
522 msg.m_pSrcTarget = m_pEdit.get(); | 520 msg.m_pSrcTarget = m_pEdit.get(); |
523 m_pEdit->GetCurrentDelegate()->OnProcessMessage(&msg); | 521 m_pEdit->GetDelegate()->OnProcessMessage(&msg); |
524 } | 522 } |
525 CFX_RectF rtInvalidate, rtCal; | 523 CFX_RectF rtInvalidate, rtCal; |
526 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 524 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
527 m_pProperties->m_rtWidget.height); | 525 m_pProperties->m_rtWidget.height); |
528 m_pMonthCal->GetWidgetRect(rtCal); | 526 m_pMonthCal->GetWidgetRect(rtCal); |
529 rtInvalidate.Union(rtCal); | 527 rtInvalidate.Union(rtCal); |
530 rtInvalidate.Inflate(2, 2); | 528 rtInvalidate.Inflate(2, 2); |
531 Repaint(&rtInvalidate); | 529 Repaint(&rtInvalidate); |
532 } | 530 } |
533 | 531 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 CFX_Matrix mt; | 634 CFX_Matrix mt; |
637 mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top); | 635 mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top); |
638 if (pMatrix) { | 636 if (pMatrix) { |
639 mt.Concat(*pMatrix); | 637 mt.Concat(*pMatrix); |
640 } | 638 } |
641 m_pMonthCal->DrawWidget(pGraphics, &mt); | 639 m_pMonthCal->DrawWidget(pGraphics, &mt); |
642 } | 640 } |
643 return FWL_Error::Succeeded; | 641 return FWL_Error::Succeeded; |
644 } | 642 } |
645 | 643 |
646 CFWL_DateTimePickerImpDelegate::CFWL_DateTimePickerImpDelegate( | 644 void IFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) { |
647 IFWL_DateTimePicker* pOwner) | |
648 : m_pOwner(pOwner) {} | |
649 | |
650 void CFWL_DateTimePickerImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
651 if (!pMessage) | 645 if (!pMessage) |
652 return; | 646 return; |
653 | 647 |
654 switch (pMessage->GetClassID()) { | 648 switch (pMessage->GetClassID()) { |
655 case CFWL_MessageType::SetFocus: { | 649 case CFWL_MessageType::SetFocus: |
656 OnFocusChanged(pMessage, TRUE); | 650 OnFocusChanged(pMessage, TRUE); |
657 break; | 651 break; |
658 } | 652 case CFWL_MessageType::KillFocus: |
659 case CFWL_MessageType::KillFocus: { | |
660 OnFocusChanged(pMessage, FALSE); | 653 OnFocusChanged(pMessage, FALSE); |
661 break; | 654 break; |
662 } | |
663 case CFWL_MessageType::Mouse: { | 655 case CFWL_MessageType::Mouse: { |
664 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); | 656 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); |
665 switch (pMouse->m_dwCmd) { | 657 switch (pMouse->m_dwCmd) { |
666 case FWL_MouseCommand::LeftButtonDown: { | 658 case FWL_MouseCommand::LeftButtonDown: |
667 OnLButtonDown(pMouse); | 659 OnLButtonDown(pMouse); |
668 break; | 660 break; |
669 } | 661 case FWL_MouseCommand::LeftButtonUp: |
670 case FWL_MouseCommand::LeftButtonUp: { | |
671 OnLButtonUp(pMouse); | 662 OnLButtonUp(pMouse); |
672 break; | 663 break; |
673 } | 664 case FWL_MouseCommand::Move: |
674 case FWL_MouseCommand::Move: { | |
675 OnMouseMove(pMouse); | 665 OnMouseMove(pMouse); |
676 break; | 666 break; |
677 } | 667 case FWL_MouseCommand::Leave: |
678 case FWL_MouseCommand::Leave: { | |
679 OnMouseLeave(pMouse); | 668 OnMouseLeave(pMouse); |
680 break; | 669 break; |
681 } | |
682 default: | 670 default: |
683 break; | 671 break; |
684 } | 672 } |
685 break; | 673 break; |
686 } | 674 } |
687 case CFWL_MessageType::Key: { | 675 case CFWL_MessageType::Key: { |
688 if (m_pOwner->m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { | 676 if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { |
689 m_pOwner->m_pEdit->GetCurrentDelegate()->OnProcessMessage(pMessage); | 677 m_pEdit->GetDelegate()->OnProcessMessage(pMessage); |
690 return; | 678 return; |
691 } | 679 } |
692 break; | 680 break; |
693 } | 681 } |
694 default: | 682 default: |
695 break; | 683 break; |
696 } | 684 } |
697 | 685 |
698 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 686 IFWL_Widget::OnProcessMessage(pMessage); |
699 } | 687 } |
700 | 688 |
701 void CFWL_DateTimePickerImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 689 void IFWL_DateTimePicker::OnDrawWidget(CFX_Graphics* pGraphics, |
702 const CFX_Matrix* pMatrix) { | 690 const CFX_Matrix* pMatrix) { |
703 m_pOwner->DrawWidget(pGraphics, pMatrix); | 691 DrawWidget(pGraphics, pMatrix); |
704 } | 692 } |
705 | 693 |
706 void CFWL_DateTimePickerImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | 694 void IFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { |
707 FX_BOOL bSet) { | |
708 if (!pMsg) | 695 if (!pMsg) |
709 return; | 696 return; |
710 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | 697 if (m_pWidgetMgr->IsFormDisabled()) |
711 return DisForm_OnFocusChanged(pMsg, bSet); | 698 return DisForm_OnFocusChanged(pMsg, bSet); |
| 699 |
| 700 if (bSet) { |
| 701 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
| 702 Repaint(&m_rtClient); |
| 703 } else { |
| 704 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
| 705 Repaint(&m_rtClient); |
712 } | 706 } |
713 if (bSet) { | 707 if (pMsg->m_pSrcTarget == m_pMonthCal.get() && IsMonthCalendarShowed()) { |
714 m_pOwner->m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 708 ShowMonthCalendar(FALSE); |
715 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
716 } else { | |
717 m_pOwner->m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | |
718 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
719 } | 709 } |
720 if (pMsg->m_pSrcTarget == m_pOwner->m_pMonthCal.get() && | 710 Repaint(&m_rtClient); |
721 m_pOwner->IsMonthCalendarShowed()) { | |
722 m_pOwner->ShowMonthCalendar(FALSE); | |
723 } | |
724 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
725 } | 711 } |
726 | 712 |
727 void CFWL_DateTimePickerImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 713 void IFWL_DateTimePicker::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
728 if (!pMsg) | 714 if (!pMsg) |
729 return; | 715 return; |
730 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | 716 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
731 m_pOwner->SetFocus(TRUE); | 717 SetFocus(TRUE); |
732 } | 718 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
733 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 719 if (IsMonthCalendarShowed()) { |
734 if (m_pOwner->IsMonthCalendarShowed()) { | 720 ShowMonthCalendar(FALSE); |
735 m_pOwner->ShowMonthCalendar(FALSE); | |
736 CFWL_Event_DtpCloseUp ev; | 721 CFWL_Event_DtpCloseUp ev; |
737 m_pOwner->DispatchEvent(&ev); | 722 DispatchEvent(&ev); |
738 } else { | 723 } else { |
739 if (!(m_pOwner->m_pProperties->m_dwStyleExes & | 724 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat)) { |
740 FWL_STYLEEXT_DTP_TimeFormat)) { | 725 ShowMonthCalendar(TRUE); |
741 m_pOwner->ShowMonthCalendar(TRUE); | |
742 CFWL_Event_DtpDropDown ev; | 726 CFWL_Event_DtpDropDown ev; |
743 m_pOwner->DispatchEvent(&ev); | 727 DispatchEvent(&ev); |
744 } else { | |
745 } | 728 } |
746 m_pOwner->m_bLBtnDown = TRUE; | 729 m_bLBtnDown = TRUE; |
747 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 730 Repaint(&m_rtClient); |
748 } | 731 } |
749 } | 732 } |
750 } | 733 } |
751 | 734 |
752 void CFWL_DateTimePickerImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 735 void IFWL_DateTimePicker::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
753 if (!pMsg) | 736 if (!pMsg) |
754 return; | 737 return; |
755 m_pOwner->m_bLBtnDown = FALSE; | 738 |
756 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 739 m_bLBtnDown = FALSE; |
757 m_pOwner->m_iBtnState = CFWL_PartState_Hovered; | 740 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
758 } else { | 741 m_iBtnState = CFWL_PartState_Hovered; |
759 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | 742 else |
760 } | 743 m_iBtnState = CFWL_PartState_Normal; |
761 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | 744 Repaint(&m_rtBtn); |
762 } | 745 } |
763 | 746 |
764 void CFWL_DateTimePickerImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | 747 void IFWL_DateTimePicker::OnMouseMove(CFWL_MsgMouse* pMsg) { |
765 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 748 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
766 } else { | 749 m_iBtnState = CFWL_PartState_Normal; |
767 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | 750 |
768 } | 751 Repaint(&m_rtBtn); |
769 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | |
770 } | 752 } |
771 | 753 |
772 void CFWL_DateTimePickerImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | 754 void IFWL_DateTimePicker::OnMouseLeave(CFWL_MsgMouse* pMsg) { |
773 if (!pMsg) | 755 if (!pMsg) |
774 return; | 756 return; |
775 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | 757 m_iBtnState = CFWL_PartState_Normal; |
776 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | 758 Repaint(&m_rtBtn); |
777 } | 759 } |
778 | 760 |
779 void CFWL_DateTimePickerImpDelegate::DisForm_OnFocusChanged(CFWL_Message* pMsg, | 761 void IFWL_DateTimePicker::DisForm_OnFocusChanged(CFWL_Message* pMsg, |
780 FX_BOOL bSet) { | 762 FX_BOOL bSet) { |
781 CFX_RectF rtInvalidate(m_pOwner->m_rtBtn); | 763 CFX_RectF rtInvalidate(m_rtBtn); |
782 if (bSet) { | 764 if (bSet) { |
783 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 765 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
784 if (m_pOwner->m_pEdit && | 766 if (m_pEdit && !(m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) { |
785 !(m_pOwner->m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) { | 767 m_rtBtn.Set(m_pProperties->m_rtWidget.width, 0, m_fBtn, |
786 m_pOwner->m_rtBtn.Set(m_pOwner->m_pProperties->m_rtWidget.width, 0, | 768 m_pProperties->m_rtWidget.height - 1); |
787 m_pOwner->m_fBtn, | |
788 m_pOwner->m_pProperties->m_rtWidget.height - 1); | |
789 } | 769 } |
790 rtInvalidate = m_pOwner->m_rtBtn; | 770 rtInvalidate = m_rtBtn; |
791 pMsg->m_pDstTarget = m_pOwner->m_pEdit.get(); | 771 pMsg->m_pDstTarget = m_pEdit.get(); |
792 m_pOwner->m_pEdit->GetCurrentDelegate()->OnProcessMessage(pMsg); | 772 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
793 } else { | 773 } else { |
794 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 774 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
795 m_pOwner->m_rtBtn.Set(0, 0, 0, 0); | 775 m_rtBtn.Set(0, 0, 0, 0); |
796 if (m_pOwner->DisForm_IsMonthCalendarShowed()) { | 776 if (DisForm_IsMonthCalendarShowed()) |
797 m_pOwner->ShowMonthCalendar(FALSE); | 777 ShowMonthCalendar(FALSE); |
798 } | 778 if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { |
799 if (m_pOwner->m_pEdit->GetStates() & FWL_WGTSTATE_Focused) { | 779 pMsg->m_pSrcTarget = m_pEdit.get(); |
800 pMsg->m_pSrcTarget = m_pOwner->m_pEdit.get(); | 780 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
801 m_pOwner->m_pEdit->GetCurrentDelegate()->OnProcessMessage(pMsg); | |
802 } | 781 } |
803 } | 782 } |
804 rtInvalidate.Inflate(2, 2); | 783 rtInvalidate.Inflate(2, 2); |
805 m_pOwner->Repaint(&rtInvalidate); | 784 Repaint(&rtInvalidate); |
806 } | 785 } |
807 | 786 |
808 IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::CFWL_MonthCalendarImpDP() { | 787 IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::CFWL_MonthCalendarImpDP() { |
809 m_iCurYear = 2010; | 788 m_iCurYear = 2010; |
810 m_iCurMonth = 3; | 789 m_iCurMonth = 3; |
811 m_iCurDay = 29; | 790 m_iCurDay = 29; |
812 } | 791 } |
813 | 792 |
814 FWL_Error IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCaption( | 793 FWL_Error IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCaption( |
815 IFWL_Widget* pWidget, | 794 IFWL_Widget* pWidget, |
816 CFX_WideString& wsCaption) { | 795 CFX_WideString& wsCaption) { |
817 return FWL_Error::Succeeded; | 796 return FWL_Error::Succeeded; |
818 } | 797 } |
819 | 798 |
820 int32_t IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCurDay( | 799 int32_t IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCurDay( |
821 IFWL_Widget* pWidget) { | 800 IFWL_Widget* pWidget) { |
822 return m_iCurDay; | 801 return m_iCurDay; |
823 } | 802 } |
824 | 803 |
825 int32_t IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCurMonth( | 804 int32_t IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCurMonth( |
826 IFWL_Widget* pWidget) { | 805 IFWL_Widget* pWidget) { |
827 return m_iCurMonth; | 806 return m_iCurMonth; |
828 } | 807 } |
829 | 808 |
830 int32_t IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCurYear( | 809 int32_t IFWL_DateTimePicker::CFWL_MonthCalendarImpDP::GetCurYear( |
831 IFWL_Widget* pWidget) { | 810 IFWL_Widget* pWidget) { |
832 return m_iCurYear; | 811 return m_iCurYear; |
833 } | 812 } |
OLD | NEW |