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