• 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 _FWL_DATETIMEPICKER_IMP_H
8 #define _FWL_DATETIMEPICKER_IMP_H
9 
10 #include <memory>
11 
12 class CFWL_WidgetImp;
13 class CFWL_WidgetImpProperties;
14 class CFWL_WidgetImpDelegate;
15 class CFWL_EditImp;
16 class CFWL_EditImpDelegate;
17 class CFWL_MonthCalendarImp;
18 class CFWL_MonthCalendarImpDelegate;
19 class CFWL_FormProxyImp;
20 class CFWL_DateTimeEdit;
21 class CFWL_DateTimeEditImpDelegate;
22 class CFWL_DateTimeCalendar;
23 class CFWL_DateTimeCalendarImpDelegate;
24 class CFWL_DateTimePickerImp;
25 class CFWL_DateTimePickerImpDelegate;
26 
27 class IFWL_DateTimeForm : public IFWL_Form {
28  public:
29   static IFWL_DateTimeForm* Create(const CFWL_WidgetImpProperties& properties,
30                                    IFWL_Widget* pOuter);
31 
32  protected:
IFWL_DateTimeForm()33   IFWL_DateTimeForm() {}
34 };
35 
36 class IFWL_DateTimeCalender : public IFWL_MonthCalendar {
37  public:
38   static IFWL_DateTimeCalender* Create(
39       const CFWL_WidgetImpProperties& properties,
40       IFWL_Widget* pOuter);
41 
42  protected:
IFWL_DateTimeCalender()43   IFWL_DateTimeCalender() {}
44 };
45 
46 class IFWL_DateTimeEdit : public IFWL_Edit {
47  public:
48   static IFWL_DateTimeEdit* Create(const CFWL_WidgetImpProperties& properties,
49                                    IFWL_Widget* pOuter);
50 
51  protected:
IFWL_DateTimeEdit()52   IFWL_DateTimeEdit() {}
53 };
54 
55 class CFWL_DateTimeEdit : public CFWL_EditImp {
56  public:
57   CFWL_DateTimeEdit(const CFWL_WidgetImpProperties& properties,
58                     IFWL_Widget* pOuter);
59   virtual FWL_ERR Initialize();
60   virtual FWL_ERR Finalize();
61 
62  protected:
63   friend class CFWL_DateTimeEditImpDelegate;
64 };
65 class CFWL_DateTimeEditImpDelegate : public CFWL_EditImpDelegate {
66  public:
67   CFWL_DateTimeEditImpDelegate(CFWL_DateTimeEdit* pOwner);
68   int32_t OnProcessMessage(CFWL_Message* pMessage) override;
69 
70  private:
71   int32_t DisForm_OnProcessMessage(CFWL_Message* pMessage);
72 
73  protected:
74   CFWL_DateTimeEdit* m_pOwner;
75 };
76 class CFWL_DateTimeCalendar : public CFWL_MonthCalendarImp {
77  public:
78   CFWL_DateTimeCalendar(const CFWL_WidgetImpProperties& properties,
79                         IFWL_Widget* pOuter);
80   virtual FWL_ERR Initialize();
81   virtual FWL_ERR Finalize();
82 
83  protected:
84   friend class CFWL_DateTimeCalendarImpDelegate;
85 };
86 class CFWL_DateTimeCalendarImpDelegate : public CFWL_MonthCalendarImpDelegate {
87  public:
88   CFWL_DateTimeCalendarImpDelegate(CFWL_DateTimeCalendar* pOwner);
89   int32_t OnProcessMessage(CFWL_Message* pMessage) override;
90 
91   void OnLButtonDownEx(CFWL_MsgMouse* pMsg);
92   void OnLButtonUpEx(CFWL_MsgMouse* pMsg);
93   void OnMouseMoveEx(CFWL_MsgMouse* pMsg);
94 
95  private:
96   int32_t DisForm_OnProcessMessage(CFWL_Message* pMessage);
97   void DisForm_OnLButtonUpEx(CFWL_MsgMouse* pMsg);
98 
99  protected:
100   CFWL_DateTimeCalendar* m_pOwner;
101   FX_BOOL m_bFlag;
102 };
103 class CFWL_DateTimePickerImp : public CFWL_WidgetImp {
104  public:
105   CFWL_DateTimePickerImp(const CFWL_WidgetImpProperties& properties,
106                          IFWL_Widget* pOuter);
107   virtual ~CFWL_DateTimePickerImp();
108   virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const;
109   virtual FX_DWORD GetClassID() const;
110   virtual FWL_ERR Initialize();
111   virtual FWL_ERR Finalize();
112   virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE);
113   virtual FWL_ERR Update();
114   virtual FX_DWORD HitTest(FX_FLOAT fx, FX_FLOAT fy);
115   virtual FWL_ERR DrawWidget(CFX_Graphics* pGraphics,
116                              const CFX_Matrix* pMatrix = NULL);
117   virtual FWL_ERR SetThemeProvider(IFWL_ThemeProvider* pTP);
118   virtual FWL_ERR GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay);
119   virtual FWL_ERR SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay);
120   virtual FWL_ERR SetEditText(const CFX_WideString& wsText);
121   virtual FWL_ERR GetEditText(CFX_WideString& wsText,
122                               int32_t nStart = 0,
123                               int32_t nCount = -1) const;
124 
125  public:
126   virtual FX_BOOL CanUndo();
127   virtual FX_BOOL CanRedo();
128   virtual FX_BOOL Undo();
129   virtual FX_BOOL Redo();
130   virtual FX_BOOL CanCopy();
131   virtual FX_BOOL CanCut();
132   virtual FX_BOOL CanSelectAll();
133   virtual FX_BOOL Copy(CFX_WideString& wsCopy);
134   virtual FX_BOOL Cut(CFX_WideString& wsCut);
135   virtual FX_BOOL Paste(const CFX_WideString& wsPaste);
136   virtual FX_BOOL SelectAll();
137   virtual FX_BOOL Delete();
138   virtual FX_BOOL DeSelect();
139   virtual FWL_ERR GetBBox(CFX_RectF& rect);
140   virtual FWL_ERR SetEditLimit(int32_t nLimit);
141   virtual FWL_ERR ModifyEditStylesEx(FX_DWORD dwStylesExAdded,
142                                      FX_DWORD dwStylesExRemoved);
143 
144  public:
145   IFWL_DateTimeEdit* GetDataTimeEdit();
146 
147  protected:
148   void DrawDropDownButton(CFX_Graphics* pGraphics,
149                           IFWL_ThemeProvider* pTheme,
150                           const CFX_Matrix* pMatrix);
151   void FormatDateString(int32_t iYear,
152                         int32_t iMonth,
153                         int32_t iDay,
154                         CFX_WideString& wsText);
155   void ShowMonthCalendar(FX_BOOL bActivate);
156   FX_BOOL IsMonthCalendarShowed();
157   void ReSetEditAlignment();
158   void InitProxyForm();
159   void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay);
160 
161  private:
162   FWL_ERR DisForm_Initialize();
163   void DisForm_InitDateTimeCalendar();
164   void DisForm_InitDateTimeEdit();
165   FX_BOOL DisForm_IsMonthCalendarShowed();
166   void DisForm_ShowMonthCalendar(FX_BOOL bActivate);
167   FX_DWORD DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy);
168   FX_BOOL DisForm_IsNeedShowButton();
169   FWL_ERR DisForm_Update();
170   FWL_ERR DisForm_GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE);
171   FWL_ERR DisForm_GetBBox(CFX_RectF& rect);
172   FWL_ERR DisForm_DrawWidget(CFX_Graphics* pGraphics,
173                              const CFX_Matrix* pMatrix = NULL);
174 
175  protected:
176   CFX_RectF m_rtBtn;
177   CFX_RectF m_rtClient;
178   int32_t m_iBtnState;
179   int32_t m_iYear;
180   int32_t m_iMonth;
181   int32_t m_iDay;
182   FX_BOOL m_bLBtnDown;
183   std::unique_ptr<IFWL_DateTimeEdit> m_pEdit;
184   std::unique_ptr<IFWL_DateTimeCalender> m_pMonthCal;
185   std::unique_ptr<IFWL_DateTimeForm> m_pForm;
186   FX_FLOAT m_fBtn;
187   class CFWL_MonthCalendarImpDP : public IFWL_MonthCalendarDP {
188    public:
CFWL_MonthCalendarImpDP()189     CFWL_MonthCalendarImpDP() {
190       m_iCurYear = 2010;
191       m_iCurMonth = 3;
192       m_iCurDay = 29;
193     }
GetCaption(IFWL_Widget * pWidget,CFX_WideString & wsCaption)194     virtual FWL_ERR GetCaption(IFWL_Widget* pWidget,
195                                CFX_WideString& wsCaption) {
196       return FWL_ERR_Succeeded;
197     }
GetCurDay(IFWL_Widget * pWidget)198     virtual int32_t GetCurDay(IFWL_Widget* pWidget) { return m_iCurDay; }
GetCurMonth(IFWL_Widget * pWidget)199     virtual int32_t GetCurMonth(IFWL_Widget* pWidget) { return m_iCurMonth; }
GetCurYear(IFWL_Widget * pWidget)200     virtual int32_t GetCurYear(IFWL_Widget* pWidget) { return m_iCurYear; }
201     int32_t m_iCurDay;
202     int32_t m_iCurYear;
203     int32_t m_iCurMonth;
204   };
205 
206   CFWL_MonthCalendarImpDP m_MonthCalendarDP;
207   friend class CFWL_DateTimeEditImpDelegate;
208   friend class CFWL_DateTimeCalendar;
209   friend class CFWL_DateTimeCalendarImpDelegate;
210   friend class CFWL_DateTimePickerImpDelegate;
211 };
212 class CFWL_DateTimePickerImpDelegate : public CFWL_WidgetImpDelegate {
213  public:
214   CFWL_DateTimePickerImpDelegate(CFWL_DateTimePickerImp* pOwner);
215   int32_t OnProcessMessage(CFWL_Message* pMessage) override;
216   FWL_ERR OnDrawWidget(CFX_Graphics* pGraphics,
217                        const CFX_Matrix* pMatrix = NULL) override;
218 
219  protected:
220   void OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE);
221   void OnLButtonDown(CFWL_MsgMouse* pMsg);
222   void OnLButtonUp(CFWL_MsgMouse* pMsg);
223   void OnMouseMove(CFWL_MsgMouse* pMsg);
224   void OnMouseLeave(CFWL_MsgMouse* pMsg);
225 
226   CFWL_DateTimePickerImp* m_pOwner;
227 
228  private:
229   void DisForm_OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE);
230 };
231 #endif
232