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 #ifndef XFA_FWL_CFWL_DATETIMEPICKER_H_ 8 #define XFA_FWL_CFWL_DATETIMEPICKER_H_ 9 10 #include <memory> 11 #include <utility> 12 13 #include "xfa/fwl/cfwl_datetimeedit.h" 14 #include "xfa/fwl/cfwl_event.h" 15 #include "xfa/fwl/cfwl_monthcalendar.h" 16 #include "xfa/fwl/cfwl_widget.h" 17 #include "xfa/fwl/cfwl_widgetproperties.h" 18 19 #define FWL_STYLEEXT_DTP_LongDateFormat 0 20 #define FWL_STYLEEXT_DTP_ShortDateFormat (1L << 1) 21 #define FWL_STYLEEXT_DTP_EditHNear 0 22 #define FWL_STYLEEXT_DTP_EditHCenter (1L << 4) 23 #define FWL_STYLEEXT_DTP_EditHFar (2L << 4) 24 #define FWL_STYLEEXT_DTP_EditVNear 0 25 #define FWL_STYLEEXT_DTP_EditVCenter (1L << 6) 26 #define FWL_STYLEEXT_DTP_EditVFar (2L << 6) 27 #define FWL_STYLEEXT_DTP_EditJustified (1L << 8) 28 #define FWL_STYLEEXT_DTP_EditHAlignMask (3L << 4) 29 #define FWL_STYLEEXT_DTP_EditVAlignMask (3L << 6) 30 31 class CFWL_DateTimeEdit; 32 class CFWL_FormProxy; 33 34 class CFWL_DateTimePicker : public CFWL_Widget { 35 public: 36 explicit CFWL_DateTimePicker(const CFWL_App* pApp); 37 ~CFWL_DateTimePicker() override; 38 39 // CFWL_Widget 40 FWL_Type GetClassID() const override; 41 void Update() override; 42 FWL_WidgetHit HitTest(const CFX_PointF& point) override; 43 void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override; 44 void SetThemeProvider(IFWL_ThemeProvider* pTP) override; 45 void OnProcessMessage(CFWL_Message* pMessage) override; 46 void OnDrawWidget(CXFA_Graphics* pGraphics, 47 const CFX_Matrix& matrix) override; 48 49 void GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay); 50 void SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay); 51 52 void SetEditText(const WideString& wsText); 53 WideString GetEditText() const; 54 HasSelection()55 bool HasSelection() const { return m_pEdit->HasSelection(); } 56 // Returns <start, count> of the selection. GetSelection()57 std::pair<size_t, size_t> GetSelection() const { 58 return m_pEdit->GetSelection(); 59 } 60 61 CFX_RectF GetBBox() const; SetEditLimit(int32_t nLimit)62 void SetEditLimit(int32_t nLimit) { m_pEdit->SetLimit(nLimit); } 63 void ModifyEditStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); 64 65 bool IsMonthCalendarVisible() const; 66 void ShowMonthCalendar(bool bActivate); 67 void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay); 68 GetFormProxy()69 CFWL_FormProxy* GetFormProxy() const { return m_pForm.get(); } 70 71 private: 72 void DrawDropDownButton(CXFA_Graphics* pGraphics, 73 IFWL_ThemeProvider* pTheme, 74 const CFX_Matrix* pMatrix); 75 WideString FormatDateString(int32_t iYear, int32_t iMonth, int32_t iDay); 76 void ResetEditAlignment(); 77 void InitProxyForm(); 78 void OnFocusChanged(CFWL_Message* pMsg, bool bSet); 79 void OnLButtonDown(CFWL_MessageMouse* pMsg); 80 void OnLButtonUp(CFWL_MessageMouse* pMsg); 81 void OnMouseMove(CFWL_MessageMouse* pMsg); 82 void OnMouseLeave(CFWL_MessageMouse* pMsg); 83 84 bool DisForm_IsMonthCalendarVisible() const; 85 void DisForm_ShowMonthCalendar(bool bActivate); 86 FWL_WidgetHit DisForm_HitTest(const CFX_PointF& point) const; 87 bool DisForm_IsNeedShowButton() const; 88 void DisForm_Update(); 89 CFX_RectF DisForm_GetBBox() const; 90 void DisForm_DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix* pMatrix); 91 void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet); 92 93 CFX_RectF m_rtBtn; 94 CFX_RectF m_rtClient; 95 int32_t m_iBtnState; 96 int32_t m_iYear; 97 int32_t m_iMonth; 98 int32_t m_iDay; 99 bool m_bLBtnDown; 100 std::unique_ptr<CFWL_DateTimeEdit> m_pEdit; 101 std::unique_ptr<CFWL_MonthCalendar> m_pMonthCal; 102 std::unique_ptr<CFWL_FormProxy> m_pForm; 103 float m_fBtn; 104 }; 105 106 #endif // XFA_FWL_CFWL_DATETIMEPICKER_H_ 107