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