xref: /aosp_15_r20/external/pdfium/xfa/fwl/cfwl_datetimepicker.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2014 The PDFium Authors
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 <utility>
11 
12 #include "v8/include/cppgc/member.h"
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 
18 #define FWL_STYLEEXT_DTP_ShortDateFormat (1L << 1)
19 #define FWL_STYLEEXT_DTP_EditHAlignMask (3L << 4)
20 #define FWL_STYLEEXT_DTP_EditHNear (0L << 4)
21 #define FWL_STYLEEXT_DTP_EditHCenter (1L << 4)
22 #define FWL_STYLEEXT_DTP_EditHFar (2L << 4)
23 #define FWL_STYLEEXT_DTP_EditVAlignMask (3L << 6)
24 #define FWL_STYLEEXT_DTP_EditVNear (0L << 6)
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 
29 class CFWL_DateTimeEdit;
30 
31 class CFWL_DateTimePicker final : public CFWL_Widget {
32  public:
33   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
34   ~CFWL_DateTimePicker() override;
35 
36   // CFWL_Widget:
37   void PreFinalize() override;
38   void Trace(cppgc::Visitor* visitor) const override;
39   FWL_Type GetClassID() const override;
40   void Update() override;
41   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
42   void DrawWidget(CFGAS_GEGraphics* pGraphics,
43                   const CFX_Matrix& matrix) override;
44   void OnProcessMessage(CFWL_Message* pMessage) override;
45   void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
46                     const CFX_Matrix& matrix) 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 WideString& wsText);
52   size_t GetEditTextLength() const;
53   WideString GetEditText() const;
54   void ClearText();
55 
56   void SelectAll();
57   void ClearSelection();
HasSelection()58   bool HasSelection() const { return m_pEdit->HasSelection(); }
59   // Returns <start, count> of the selection.
GetSelection()60   std::pair<size_t, size_t> GetSelection() const {
61     return m_pEdit->GetSelection();
62   }
63   absl::optional<WideString> Copy();
64   absl::optional<WideString> Cut();
65   bool Paste(const WideString& wsPaste);
66   bool Undo();
67   bool Redo();
68   bool CanUndo();
69   bool CanRedo();
70 
71   CFX_RectF GetBBox() const;
SetEditLimit(int32_t nLimit)72   void SetEditLimit(int32_t nLimit) { m_pEdit->SetLimit(nLimit); }
73   void ModifyEditStyleExts(uint32_t dwStyleExtsAdded,
74                            uint32_t dwStyleExtsRemoved);
75 
76   bool IsMonthCalendarVisible() const;
77   void ShowMonthCalendar();
78   void HideMonthCalendar();
79   void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay);
80 
81  private:
82   explicit CFWL_DateTimePicker(CFWL_App* pApp);
83 
84   void DrawDropDownButton(CFGAS_GEGraphics* pGraphics,
85                           const CFX_Matrix& mtMatrix);
86   WideString FormatDateString(int32_t iYear, int32_t iMonth, int32_t iDay);
87   void ResetEditAlignment();
88   void GetPopupPos(float fMinHeight,
89                    float fMaxHeight,
90                    const CFX_RectF& rtAnchor,
91                    CFX_RectF* pPopupRect);
92   void OnFocusGained(CFWL_Message* pMsg);
93   void OnFocusLost(CFWL_Message* pMsg);
94   void OnLButtonDown(CFWL_MessageMouse* pMsg);
95   void OnLButtonUp(CFWL_MessageMouse* pMsg);
96   void OnMouseMove(CFWL_MessageMouse* pMsg);
97   void OnMouseLeave(CFWL_MessageMouse* pMsg);
98   bool NeedsToShowButton() const;
99   void RepaintInflatedMonthCalRect();
100 
101   bool m_bLBtnDown = false;
102   Mask<CFWL_PartState> m_iBtnState = CFWL_PartState::kChecked;
103   int32_t m_iYear = -1;
104   int32_t m_iMonth = -1;
105   int32_t m_iDay = -1;
106   float m_fBtn = 0.0f;
107   CFX_RectF m_BtnRect;
108   CFX_RectF m_ClientRect;
109   cppgc::Member<CFWL_DateTimeEdit> const m_pEdit;
110   cppgc::Member<CFWL_MonthCalendar> const m_pMonthCal;
111 };
112 
113 #endif  // XFA_FWL_CFWL_DATETIMEPICKER_H_
114