summaryrefslogtreecommitdiff
path: root/xfa/fwl/core/ifwl_monthcalendar.h
blob: b9376b82c37e3306db3141c49e8cde379610c874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FWL_CORE_IFWL_MONTHCALENDAR_H_
#define XFA_FWL_CORE_IFWL_MONTHCALENDAR_H_

#include "xfa/fgas/localization/fgas_datetime.h"
#include "xfa/fwl/core/cfwl_event.h"
#include "xfa/fwl/core/cfwl_widgetimpproperties.h"
#include "xfa/fwl/core/ifwl_dataprovider.h"
#include "xfa/fwl/core/ifwl_widget.h"

#define FWL_STYLEEXT_MCD_MultiSelect (1L << 0)
#define FWL_STYLEEXT_MCD_NoToday (1L << 1)
#define FWL_STYLEEXT_MCD_NoTodayCircle (1L << 2)
#define FWL_STYLEEXT_MCD_WeekNumbers (1L << 3)
#define FWL_ITEMSTATE_MCD_Nomal (0L << 0)
#define FWL_ITEMSTATE_MCD_Flag (1L << 0)
#define FWL_ITEMSTATE_MCD_Selected (1L << 1)
#define FWL_ITEMSTATE_MCD_Focused (1L << 2)

FWL_EVENT_DEF(CFWL_Event_McdDateSelected,
              CFWL_EventType::DataSelected,
              int32_t m_iStartDay;
              int32_t m_iEndDay;)

FWL_EVENT_DEF(CFWL_EventMcdDateChanged,
              CFWL_EventType::DateChanged,
              int32_t m_iOldYear;
              int32_t m_iOldMonth;
              int32_t m_iStartDay;
              int32_t m_iEndDay;)

class CFWL_MonthCalendarImpDelegate;
class CFWL_MsgMouse;
class CFWL_WidgetImpProperties;
class IFWL_Widget;

struct FWL_DATEINFO;

extern uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth);

class IFWL_MonthCalendarDP : public IFWL_DataProvider {
 public:
  virtual int32_t GetCurDay(IFWL_Widget* pWidget) = 0;
  virtual int32_t GetCurMonth(IFWL_Widget* pWidget) = 0;
  virtual int32_t GetCurYear(IFWL_Widget* pWidget) = 0;
};

class IFWL_MonthCalendar : public IFWL_Widget {
 public:
  IFWL_MonthCalendar(const CFWL_WidgetImpProperties& properties,
                     IFWL_Widget* pOuter);
  ~IFWL_MonthCalendar() override;

  // FWL_WidgetImp
  FWL_Type GetClassID() const override;
  FWL_Error Initialize() override;
  void Finalize() override;
  FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE) override;
  FWL_Error Update() override;
  FWL_Error DrawWidget(CFX_Graphics* pGraphics,
                       const CFX_Matrix* pMatrix = nullptr) override;
  int32_t CountSelect();
  FX_BOOL GetSelect(int32_t& iYear,
                    int32_t& iMonth,
                    int32_t& iDay,
                    int32_t nIndex = 0);
  FX_BOOL SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay);

 protected:
  struct DATE {
    DATE() : iYear(0), iMonth(0), iDay(0) {}
    DATE(int32_t year, int32_t month, int32_t day)
        : iYear(year), iMonth(month), iDay(day) {}
    FX_BOOL operator<(const DATE& right) {
      if (iYear < right.iYear) {
        return TRUE;
      } else if (iYear == right.iYear) {
        if (iMonth < right.iMonth) {
          return TRUE;
        } else if (iMonth == right.iMonth) {
          return iDay < right.iDay;
        }
      }
      return FALSE;
    }
    FX_BOOL operator>(const DATE& right) {
      if (iYear > right.iYear) {
        return TRUE;
      } else if (iYear == right.iYear) {
        if (iMonth > right.iMonth) {
          return TRUE;
        } else if (iMonth == right.iMonth) {
          return iDay > right.iDay;
        }
      }
      return FALSE;
    }
    int32_t iYear;
    int32_t iMonth;
    int32_t iDay;
  };

  void DrawBkground(CFX_Graphics* pGraphics,
                    IFWL_ThemeProvider* pTheme,
                    const CFX_Matrix* pMatrix);
  void DrawHeadBK(CFX_Graphics* pGraphics,
                  IFWL_ThemeProvider* pTheme,
                  const CFX_Matrix* pMatrix);
  void DrawLButton(CFX_Graphics* pGraphics,
                   IFWL_ThemeProvider* pTheme,
                   const CFX_Matrix* pMatrix);
  void DrawRButton(CFX_Graphics* pGraphics,
                   IFWL_ThemeProvider* pTheme,
                   const CFX_Matrix* pMatrix);
  void DrawCaption(CFX_Graphics* pGraphics,
                   IFWL_ThemeProvider* pTheme,
                   const CFX_Matrix* pMatrix);
  void DrawSeperator(CFX_Graphics* pGraphics,
                     IFWL_ThemeProvider* pTheme,
                     const CFX_Matrix* pMatrix);
  void DrawDatesInBK(CFX_Graphics* pGraphics,
                     IFWL_ThemeProvider* pTheme,
                     const CFX_Matrix* pMatrix);
  void DrawWeek(CFX_Graphics* pGraphics,
                IFWL_ThemeProvider* pTheme,
                const CFX_Matrix* pMatrix);
  void DrawWeekNumber(CFX_Graphics* pGraphics,
                      IFWL_ThemeProvider* pTheme,
                      const CFX_Matrix* pMatrix);
  void DrawWeekNumberSep(CFX_Graphics* pGraphics,
                         IFWL_ThemeProvider* pTheme,
                         const CFX_Matrix* pMatrix);
  void DrawToday(CFX_Graphics* pGraphics,
                 IFWL_ThemeProvider* pTheme,
                 const CFX_Matrix* pMatrix);
  void DrawDatesIn(CFX_Graphics* pGraphics,
                   IFWL_ThemeProvider* pTheme,
                   const CFX_Matrix* pMatrix);
  void DrawDatesOut(CFX_Graphics* pGraphics,
                    IFWL_ThemeProvider* pTheme,
                    const CFX_Matrix* pMatrix);
  void DrawDatesInCircle(CFX_Graphics* pGraphics,
                         IFWL_ThemeProvider* pTheme,
                         const CFX_Matrix* pMatrix);
  void DrawTodayCircle(CFX_Graphics* pGraphics,
                       IFWL_ThemeProvider* pTheme,
                       const CFX_Matrix* pMatrix);
  CFX_SizeF CalcSize(FX_BOOL bAutoSize = FALSE);
  void LayOut();
  void CalcHeadSize();
  void CalcTodaySize();
  void CalDateItem();
  void GetCapValue();
  int32_t CalWeekNumber(int32_t iYear, int32_t iMonth, int32_t iDay);
  FX_BOOL GetMinDate(int32_t& iYear, int32_t& iMonth, int32_t& iDay);
  FX_BOOL SetMinDate(int32_t iYear, int32_t iMonth, int32_t iDay);
  FX_BOOL GetMaxDate(int32_t& iYear, int32_t& iMonth, int32_t& iDay);
  FX_BOOL SetMaxDate(int32_t iYear, int32_t iMonth, int32_t iDay);
  FX_BOOL InitDate();
  void ClearDateItem();
  void ReSetDateItem();
  FX_BOOL NextMonth();
  FX_BOOL PrevMonth();
  void ChangeToMonth(int32_t iYear, int32_t iMonth);
  FX_BOOL RemoveSelDay(int32_t iDay, FX_BOOL bAll = FALSE);
  FX_BOOL AddSelDay(int32_t iDay);
  FX_BOOL JumpToToday();
  void GetHeadText(int32_t iYear, int32_t iMonth, CFX_WideString& wsHead);
  void GetTodayText(int32_t iYear,
                    int32_t iMonth,
                    int32_t iDay,
                    CFX_WideString& wsToday);
  int32_t GetDayAtPoint(FX_FLOAT x, FX_FLOAT y);
  FX_BOOL GetDayRect(int32_t iDay, CFX_RectF& rtDay);

  FX_BOOL m_bInit;
  CFX_RectF m_rtHead;
  CFX_RectF m_rtWeek;
  CFX_RectF m_rtLBtn;
  CFX_RectF m_rtRBtn;
  CFX_RectF m_rtDates;
  CFX_RectF m_rtHSep;
  CFX_RectF m_rtHeadText;
  CFX_RectF m_rtToday;
  CFX_RectF m_rtTodayFlag;
  CFX_RectF m_rtWeekNum;
  CFX_RectF m_rtWeekNumSep;
  CFX_RectF m_rtTemp;
  CFX_WideString m_wsHead;
  CFX_WideString m_wsToday;
  std::unique_ptr<CFX_DateTime> m_pDateTime;
  CFX_ArrayTemplate<FWL_DATEINFO*> m_arrDates;
  int32_t m_iCurYear;
  int32_t m_iCurMonth;
  int32_t m_iYear;
  int32_t m_iMonth;
  int32_t m_iDay;
  int32_t m_iHovered;
  int32_t m_iLBtnPartStates;
  int32_t m_iRBtnPartStates;
  DATE m_dtMin;
  DATE m_dtMax;
  CFX_SizeF m_szHead;
  CFX_SizeF m_szCell;
  CFX_SizeF m_szToday;
  CFX_ArrayTemplate<int32_t> m_arrSelDays;
  int32_t m_iMaxSel;
  CFX_RectF m_rtClient;
  FX_FLOAT m_fHeadWid;
  FX_FLOAT m_fHeadHei;
  FX_FLOAT m_fHeadBtnWid;
  FX_FLOAT m_fHeadBtnHei;
  FX_FLOAT m_fHeadBtnHMargin;
  FX_FLOAT m_fHeadBtnVMargin;
  FX_FLOAT m_fHeadTextWid;
  FX_FLOAT m_fHeadTextHei;
  FX_FLOAT m_fHeadTextHMargin;
  FX_FLOAT m_fHeadTextVMargin;
  FX_FLOAT m_fHSepWid;
  FX_FLOAT m_fHSepHei;
  FX_FLOAT m_fWeekNumWid;
  FX_FLOAT m_fSepDOffset;
  FX_FLOAT m_fSepX;
  FX_FLOAT m_fSepY;
  FX_FLOAT m_fWeekNumHeigh;
  FX_FLOAT m_fWeekWid;
  FX_FLOAT m_fWeekHei;
  FX_FLOAT m_fDateCellWid;
  FX_FLOAT m_fDateCellHei;
  FX_FLOAT m_fTodayWid;
  FX_FLOAT m_fTodayHei;
  FX_FLOAT m_fTodayFlagWid;
  FX_FLOAT m_fMCWid;
  FX_FLOAT m_fMCHei;
  friend class CFWL_MonthCalendarImpDelegate;
};

struct FWL_DATEINFO {
  FWL_DATEINFO(int32_t day,
               int32_t dayofweek,
               uint32_t dwSt,
               CFX_RectF rc,
               CFX_WideString& wsday);
  ~FWL_DATEINFO();

  int32_t iDay;
  int32_t iDayOfWeek;
  uint32_t dwStates;
  CFX_RectF rect;
  CFX_WideString wsDay;
};

class CFWL_MonthCalendarImpDelegate : public CFWL_WidgetImpDelegate {
 public:
  CFWL_MonthCalendarImpDelegate(IFWL_MonthCalendar* pOwner);
  void OnProcessMessage(CFWL_Message* pMessage) override;
  void OnDrawWidget(CFX_Graphics* pGraphics,
                    const CFX_Matrix* pMatrix = nullptr) override;

 protected:
  void OnActivate(CFWL_Message* pMsg);
  void OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE);
  void OnLButtonDown(CFWL_MsgMouse* pMsg);
  void OnLButtonUp(CFWL_MsgMouse* pMsg);
  void OnMouseMove(CFWL_MsgMouse* pMsg);
  void OnMouseLeave(CFWL_MsgMouse* pMsg);
  IFWL_MonthCalendar* m_pOwner;
};

#endif  // XFA_FWL_CORE_IFWL_MONTHCALENDAR_H_