• 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 #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_ShortDateFormat (1L << 1)
20 #define FWL_STYLEEXT_DTP_EditHAlignMask (3L << 4)
21 #define FWL_STYLEEXT_DTP_EditHNear (0L << 4)
22 #define FWL_STYLEEXT_DTP_EditHCenter (1L << 4)
23 #define FWL_STYLEEXT_DTP_EditHFar (2L << 4)
24 #define FWL_STYLEEXT_DTP_EditVAlignMask (3L << 6)
25 #define FWL_STYLEEXT_DTP_EditVNear (0L << 6)
26 #define FWL_STYLEEXT_DTP_EditVCenter (1L << 6)
27 #define FWL_STYLEEXT_DTP_EditVFar (2L << 6)
28 #define FWL_STYLEEXT_DTP_EditJustified (1L << 8)
29 
30 class CFWL_DateTimeEdit;
31 
32 class CFWL_DateTimePicker final : public CFWL_Widget {
33  public:
34   explicit CFWL_DateTimePicker(const CFWL_App* pApp);
35   ~CFWL_DateTimePicker() override;
36 
37   // CFWL_Widget
38   FWL_Type GetClassID() const override;
39   void Update() override;
40   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
41   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
42   void SetThemeProvider(IFWL_ThemeProvider* pTP) override;
43   void OnProcessMessage(CFWL_Message* pMessage) override;
44   void OnDrawWidget(CXFA_Graphics* pGraphics,
45                     const CFX_Matrix& matrix) override;
46 
47   void GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay);
48   void SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay);
49 
50   void SetEditText(const WideString& wsText);
51   int32_t GetEditTextLength() const;
52   WideString GetEditText() const;
53   void ClearText();
54 
55   void SelectAll();
56   void ClearSelection();
HasSelection()57   bool HasSelection() const { return m_pEdit->HasSelection(); }
58   // Returns <start, count> of the selection.
GetSelection()59   std::pair<size_t, size_t> GetSelection() const {
60     return m_pEdit->GetSelection();
61   }
62   Optional<WideString> Copy();
63   Optional<WideString> Cut();
64   bool Paste(const WideString& wsPaste);
65   bool Undo();
66   bool Redo();
67   bool CanUndo();
68   bool CanRedo();
69 
70   CFX_RectF GetBBox() const;
SetEditLimit(int32_t nLimit)71   void SetEditLimit(int32_t nLimit) { m_pEdit->SetLimit(nLimit); }
72   void ModifyEditStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved);
73 
74   bool IsMonthCalendarVisible() const;
75   void ShowMonthCalendar(bool bActivate);
76   void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay);
77 
78  private:
79   void DrawDropDownButton(CXFA_Graphics* pGraphics,
80                           IFWL_ThemeProvider* pTheme,
81                           const CFX_Matrix* pMatrix);
82   WideString FormatDateString(int32_t iYear, int32_t iMonth, int32_t iDay);
83   void ResetEditAlignment();
84   void GetPopupPos(float fMinHeight,
85                    float fMaxHeight,
86                    const CFX_RectF& rtAnchor,
87                    CFX_RectF* pPopupRect);
88   void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
89   void OnLButtonDown(CFWL_MessageMouse* pMsg);
90   void OnLButtonUp(CFWL_MessageMouse* pMsg);
91   void OnMouseMove(CFWL_MessageMouse* pMsg);
92   void OnMouseLeave(CFWL_MessageMouse* pMsg);
93 
94   bool NeedsToShowButton() const;
95 
96   bool m_bLBtnDown = false;
97   int32_t m_iBtnState = 1;
98   int32_t m_iYear = -1;
99   int32_t m_iMonth = -1;
100   int32_t m_iDay = -1;
101   float m_fBtn = 0.0f;
102   CFX_RectF m_rtBtn;
103   CFX_RectF m_rtClient;
104   std::unique_ptr<CFWL_DateTimeEdit> m_pEdit;
105   std::unique_ptr<CFWL_MonthCalendar> m_pMonthCal;
106 };
107 
108 #endif  // XFA_FWL_CFWL_DATETIMEPICKER_H_
109