• 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_MONTHCALENDAR_H_
8 #define XFA_FWL_CFWL_MONTHCALENDAR_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/cfx_datetime.h"
14 #include "xfa/fwl/cfwl_event.h"
15 #include "xfa/fwl/cfwl_widget.h"
16 #include "xfa/fwl/cfwl_widgetproperties.h"
17 
18 #define FWL_ITEMSTATE_MCD_Flag (1L << 0)
19 #define FWL_ITEMSTATE_MCD_Selected (1L << 1)
20 
21 class CFWL_MessageMouse;
22 
23 class CFWL_MonthCalendar final : public CFWL_Widget {
24  public:
25   CFWL_MonthCalendar(const CFWL_App* app,
26                      std::unique_ptr<CFWL_WidgetProperties> properties,
27                      CFWL_Widget* pOuter);
28   ~CFWL_MonthCalendar() override;
29 
30   // FWL_WidgetImp
31   FWL_Type GetClassID() const override;
32   CFX_RectF GetAutosizedWidgetRect() override;
33   void Update() override;
34   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
35   void OnProcessMessage(CFWL_Message* pMessage) override;
36   void OnDrawWidget(CXFA_Graphics* pGraphics,
37                     const CFX_Matrix& matrix) override;
38 
39   void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay);
40 
41  private:
42   struct DATE {
DATEDATE43     DATE() : iYear(0), iMonth(0), iDay(0) {}
44 
DATEDATE45     DATE(int32_t year, int32_t month, int32_t day)
46         : iYear(year), iMonth(month), iDay(day) {}
47 
48     bool operator<(const DATE& right) {
49       if (iYear < right.iYear)
50         return true;
51       if (iYear == right.iYear) {
52         if (iMonth < right.iMonth)
53           return true;
54         if (iMonth == right.iMonth)
55           return iDay < right.iDay;
56       }
57       return false;
58     }
59 
60     bool operator>(const DATE& right) {
61       if (iYear > right.iYear)
62         return true;
63       if (iYear == right.iYear) {
64         if (iMonth > right.iMonth)
65           return true;
66         if (iMonth == right.iMonth)
67           return iDay > right.iDay;
68       }
69       return false;
70     }
71 
72     int32_t iYear;
73     int32_t iMonth;
74     int32_t iDay;
75   };
76   struct DATEINFO {
77     DATEINFO(int32_t day,
78              int32_t dayofweek,
79              uint32_t dwSt,
80              CFX_RectF rc,
81              const WideString& wsday);
82     ~DATEINFO();
83 
84     int32_t iDay;
85     int32_t iDayOfWeek;
86     uint32_t dwStates;
87     CFX_RectF rect;
88     WideString wsDay;
89   };
90 
91   void DrawBackground(CXFA_Graphics* pGraphics,
92                       IFWL_ThemeProvider* pTheme,
93                       const CFX_Matrix* pMatrix);
94   void DrawHeadBK(CXFA_Graphics* pGraphics,
95                   IFWL_ThemeProvider* pTheme,
96                   const CFX_Matrix* pMatrix);
97   void DrawLButton(CXFA_Graphics* pGraphics,
98                    IFWL_ThemeProvider* pTheme,
99                    const CFX_Matrix* pMatrix);
100   void DrawRButton(CXFA_Graphics* pGraphics,
101                    IFWL_ThemeProvider* pTheme,
102                    const CFX_Matrix* pMatrix);
103   void DrawCaption(CXFA_Graphics* pGraphics,
104                    IFWL_ThemeProvider* pTheme,
105                    const CFX_Matrix* pMatrix);
106   void DrawSeparator(CXFA_Graphics* pGraphics,
107                      IFWL_ThemeProvider* pTheme,
108                      const CFX_Matrix* pMatrix);
109   void DrawDatesInBK(CXFA_Graphics* pGraphics,
110                      IFWL_ThemeProvider* pTheme,
111                      const CFX_Matrix* pMatrix);
112   void DrawWeek(CXFA_Graphics* pGraphics,
113                 IFWL_ThemeProvider* pTheme,
114                 const CFX_Matrix* pMatrix);
115   void DrawToday(CXFA_Graphics* pGraphics,
116                  IFWL_ThemeProvider* pTheme,
117                  const CFX_Matrix* pMatrix);
118   void DrawDatesIn(CXFA_Graphics* pGraphics,
119                    IFWL_ThemeProvider* pTheme,
120                    const CFX_Matrix* pMatrix);
121   void DrawDatesOut(CXFA_Graphics* pGraphics,
122                     IFWL_ThemeProvider* pTheme,
123                     const CFX_Matrix* pMatrix);
124   void DrawDatesInCircle(CXFA_Graphics* pGraphics,
125                          IFWL_ThemeProvider* pTheme,
126                          const CFX_Matrix* pMatrix);
127   CFX_SizeF CalcSize();
128   void Layout();
129   void CalcHeadSize();
130   void CalcTodaySize();
131   void CalDateItem();
132   void GetCapValue();
133   void InitDate();
134   void ClearDateItem();
135   void ResetDateItem();
136   void NextMonth();
137   void PrevMonth();
138   void ChangeToMonth(int32_t iYear, int32_t iMonth);
139   void RemoveSelDay();
140   void AddSelDay(int32_t iDay);
141   void JumpToToday();
142   WideString GetHeadText(int32_t iYear, int32_t iMonth);
143   WideString GetTodayText(int32_t iYear, int32_t iMonth, int32_t iDay);
144   int32_t GetDayAtPoint(const CFX_PointF& point) const;
145   CFX_RectF GetDayRect(int32_t iDay);
146   void OnLButtonDown(CFWL_MessageMouse* pMsg);
147   void OnLButtonUp(CFWL_MessageMouse* pMsg);
148   void OnMouseMove(CFWL_MessageMouse* pMsg);
149   void OnMouseLeave(CFWL_MessageMouse* pMsg);
150 
151   bool m_bInitialized = false;
152   CFX_RectF m_rtHead;
153   CFX_RectF m_rtWeek;
154   CFX_RectF m_rtLBtn;
155   CFX_RectF m_rtRBtn;
156   CFX_RectF m_rtDates;
157   CFX_RectF m_rtHSep;
158   CFX_RectF m_rtHeadText;
159   CFX_RectF m_rtToday;
160   CFX_RectF m_rtTodayFlag;
161   WideString m_wsHead;
162   WideString m_wsToday;
163   std::vector<std::unique_ptr<DATEINFO>> m_arrDates;
164   int32_t m_iCurYear = 2011;
165   int32_t m_iCurMonth = 1;
166   int32_t m_iYear = 2011;
167   int32_t m_iMonth = 1;
168   int32_t m_iDay = 1;
169   int32_t m_iHovered = -1;
170   int32_t m_iLBtnPartStates = CFWL_PartState_Normal;
171   int32_t m_iRBtnPartStates = CFWL_PartState_Normal;
172   DATE m_dtMin;
173   DATE m_dtMax;
174   CFX_SizeF m_szHead;
175   CFX_SizeF m_szCell;
176   CFX_SizeF m_szToday;
177   std::vector<int32_t> m_arrSelDays;
178   CFX_RectF m_rtClient;
179 };
180 
181 #endif  // XFA_FWL_CFWL_MONTHCALENDAR_H_
182