xref: /aosp_15_r20/external/pdfium/xfa/fwl/cfwl_monthcalendar.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_MONTHCALENDAR_H_
8 #define XFA_FWL_CFWL_MONTHCALENDAR_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/widestring.h"
14 #include "xfa/fwl/cfwl_event.h"
15 #include "xfa/fwl/cfwl_widget.h"
16 
17 class CFWL_MessageMouse;
18 
19 class CFWL_MonthCalendar final : public CFWL_Widget {
20  public:
21   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
22   ~CFWL_MonthCalendar() override;
23 
24   // CFWL_Widget:
25   FWL_Type GetClassID() const override;
26   CFX_RectF GetAutosizedWidgetRect() override;
27   void Update() override;
28   void DrawWidget(CFGAS_GEGraphics* pGraphics,
29                   const CFX_Matrix& matrix) override;
30   void OnProcessMessage(CFWL_Message* pMessage) override;
31   void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
32                     const CFX_Matrix& matrix) override;
33 
34   void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay);
35 
36  private:
37   struct DATE {
DATEDATE38     DATE() : iYear(0), iMonth(0), iDay(0) {}
39 
DATEDATE40     DATE(int32_t year, int32_t month, int32_t day)
41         : iYear(year), iMonth(month), iDay(day) {}
42 
43     bool operator<(const DATE& right) {
44       if (iYear < right.iYear)
45         return true;
46       if (iYear == right.iYear) {
47         if (iMonth < right.iMonth)
48           return true;
49         if (iMonth == right.iMonth)
50           return iDay < right.iDay;
51       }
52       return false;
53     }
54 
55     bool operator>(const DATE& right) {
56       if (iYear > right.iYear)
57         return true;
58       if (iYear == right.iYear) {
59         if (iMonth > right.iMonth)
60           return true;
61         if (iMonth == right.iMonth)
62           return iDay > right.iDay;
63       }
64       return false;
65     }
66 
67     int32_t iYear;
68     int32_t iMonth;
69     int32_t iDay;
70   };
71 
72   struct DATEINFO {
73     DATEINFO(int32_t day,
74              int32_t dayofweek,
75              bool bFlag,
76              bool bSelect,
77              const WideString& wsday);
78     ~DATEINFO();
79 
80     Mask<CFWL_PartState> AsPartStateMask() const;
81 
82     const int32_t iDay;
83     const int32_t iDayOfWeek;
84     bool bFlagged;
85     bool bSelected;
86     CFX_RectF rect;
87     const WideString wsDay;
88   };
89 
90   CFWL_MonthCalendar(CFWL_App* app,
91                      const Properties& properties,
92                      CFWL_Widget* pOuter);
93 
94   void DrawBackground(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
95   void DrawHeadBK(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
96   void DrawLButton(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
97   void DrawRButton(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
98   void DrawCaption(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
99   void DrawSeparator(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
100   void DrawDatesInBK(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
101   void DrawWeek(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
102   void DrawToday(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
103   void DrawDatesIn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
104   void DrawDatesOut(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
105   void DrawDatesInCircle(CFGAS_GEGraphics* pGraphics,
106                          const CFX_Matrix& mtMatrix);
107   CFX_SizeF CalcSize();
108   void Layout();
109   void CalcHeadSize();
110   void CalcTodaySize();
111   void CalDateItem();
112   void InitDate();
113   void ClearDateItem();
114   void ResetDateItem();
115   void NextMonth();
116   void PrevMonth();
117   void ChangeToMonth(int32_t iYear, int32_t iMonth);
118   void RemoveSelDay();
119   void AddSelDay(int32_t iDay);
120   void JumpToToday();
121   WideString GetHeadText(int32_t iYear, int32_t iMonth);
122   WideString GetTodayText(int32_t iYear, int32_t iMonth, int32_t iDay);
123   int32_t GetDayAtPoint(const CFX_PointF& point) const;
124   CFX_RectF GetDayRect(int32_t iDay);
125   void OnLButtonDown(CFWL_MessageMouse* pMsg);
126   void OnLButtonUp(CFWL_MessageMouse* pMsg);
127   void OnMouseMove(CFWL_MessageMouse* pMsg);
128   void OnMouseLeave(CFWL_MessageMouse* pMsg);
129 
130   bool m_bInitialized = false;
131   CFX_RectF m_HeadRect;
132   CFX_RectF m_WeekRect;
133   CFX_RectF m_LBtnRect;
134   CFX_RectF m_RBtnRect;
135   CFX_RectF m_DatesRect;
136   CFX_RectF m_HSepRect;
137   CFX_RectF m_HeadTextRect;
138   CFX_RectF m_TodayRect;
139   CFX_RectF m_TodayFlagRect;
140   WideString m_wsHead;
141   WideString m_wsToday;
142   std::vector<std::unique_ptr<DATEINFO>> m_DateArray;
143   int32_t m_iCurYear = 2011;
144   int32_t m_iCurMonth = 1;
145   int32_t m_iYear = 2011;
146   int32_t m_iMonth = 1;
147   int32_t m_iDay = 1;
148   int32_t m_iHovered = -1;
149   Mask<CFWL_PartState> m_iLBtnPartStates = CFWL_PartState::kNormal;
150   Mask<CFWL_PartState> m_iRBtnPartStates = CFWL_PartState::kNormal;
151   DATE m_dtMin;
152   DATE m_dtMax;
153   CFX_SizeF m_HeadSize;
154   CFX_SizeF m_CellSize;
155   CFX_SizeF m_TodaySize;
156   std::vector<int32_t> m_SelDayArray;
157   CFX_RectF m_ClientRect;
158 };
159 
160 #endif  // XFA_FWL_CFWL_MONTHCALENDAR_H_
161