Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / basewidget / include / fwl_monthcalendarimp.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _FWL_MONTHCALENDAR_IMP_H\r
8 #define _FWL_MONTHCALENDAR_IMP_H\r
9 class CFWL_WidgetImp;\r
10 class CFWL_WidgetImpProperties;\r
11 class CFWL_WidgetImpDelegate;\r
12 class IFWL_Widget;\r
13 class IFDE_DateTime;\r
14 class CFDE_DateTime;\r
15 extern FX_BYTE FX_DaysInMonth(FX_INT32 iYear, FX_BYTE iMonth);\r
16 class CFWL_MonthCalendarImp;\r
17 class CFWL_MonthCalendarImpDelegate;\r
18 class CFWL_MonthCalendarImp : public CFWL_WidgetImp\r
19 {\r
20 public:\r
21     CFWL_MonthCalendarImp(IFWL_Widget *pOuter = NULL);\r
22     CFWL_MonthCalendarImp(const CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter = NULL);\r
23     ~CFWL_MonthCalendarImp();\r
24     virtual FWL_ERR             GetClassName(CFX_WideString &wsClass) const;\r
25     virtual FX_DWORD    GetClassID() const;\r
26     virtual FWL_ERR             Initialize();\r
27     virtual FWL_ERR             Finalize();\r
28     virtual FWL_ERR             GetWidgetRect(CFX_RectF &rect, FX_BOOL bAutoSize = FALSE);\r
29     virtual     FWL_ERR         Update();\r
30     virtual FWL_ERR             DrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix = NULL);\r
31     virtual FX_INT32    CountSelect();\r
32     virtual     FX_BOOL         GetSelect(FX_INT32 &iYear, FX_INT32 &iMonth, FX_INT32 &iDay, FX_INT32 nIndex = 0);\r
33     virtual     FX_BOOL         SetSelect(FX_INT32 iYear, FX_INT32 iMonth, FX_INT32 iDay);\r
34 protected:\r
35     void                DrawBkground(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
36     void                DrawHeadBK(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
37     void                DrawLButton(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
38     void                DrawRButton(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
39     void                DrawCaption(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
40     void                DrawSeperator(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
41     void                DrawDatesInBK(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
42     void                DrawWeek(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
43     void                DrawWeekNumber(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
44     void                DrawWeekNumberSep(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
45     void                DrawToday(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
46     void                DrawDatesIn(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
47     void                DrawDatesOut(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
48     void                DrawDatesInCircle(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
49     void                DrawTodayCircle(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme, const CFX_Matrix *pMatrix);\r
50     CFX_SizeF   CalcSize(FX_BOOL bAutoSize = FALSE);\r
51     void                LayOut();\r
52     void                CalcHeadSize();\r
53     void                CalcTodaySize();\r
54     void                CalDateItem();\r
55     void                GetCapValue();\r
56     FX_INT32    CalWeekNumber(FX_INT32 iYear, FX_INT32 iMonth, FX_INT32 iDay);\r
57 \r
58     FX_BOOL             GetMinDate(FX_INT32 &iYear, FX_INT32 &iMonth, FX_INT32 &iDay);\r
59     FX_BOOL             SetMinDate(FX_INT32 iYear, FX_INT32 iMonth, FX_INT32 iDay);\r
60     FX_BOOL             GetMaxDate(FX_INT32 &iYear, FX_INT32 &iMonth, FX_INT32 &iDay);\r
61     FX_BOOL             SetMaxDate(FX_INT32 iYear, FX_INT32 iMonth, FX_INT32 iDay);\r
62     FX_BOOL     InitDate();\r
63     void                ClearDateItem();\r
64     void                ReSetDateItem();\r
65     FX_BOOL             NextMonth();\r
66     FX_BOOL             PrevMonth();\r
67     void                ChangeToMonth(FX_INT32 iYear, FX_INT32 iMonth);\r
68     FX_BOOL             RemoveSelDay(FX_INT32 iDay, FX_BOOL bAll = FALSE);\r
69     FX_BOOL             AddSelDay(FX_INT32 iDay);\r
70     FX_BOOL             JumpToToday();\r
71     void                GetHeadText(FX_INT32 iYear, FX_INT32 iMonth, CFX_WideString &wsHead);\r
72     void                GetTodayText(FX_INT32 iYear, FX_INT32 iMonth, FX_INT32 iDay, CFX_WideString &wsToday);\r
73     FX_INT32    GetDayAtPoint(FX_FLOAT x, FX_FLOAT y);\r
74     FX_BOOL             GetDayRect(FX_INT32 iDay, CFX_RectF &rtDay);\r
75     typedef struct _DATE {\r
76         _DATE()\r
77         {\r
78             iYear = 0;\r
79             iMonth = 0;\r
80             iDay = 0;\r
81         }\r
82         _DATE(FX_INT32 year, FX_INT32 month, FX_INT32 day) : iYear(year), iMonth(month), iDay(day) {}\r
83         FX_BOOL operator < (const _DATE &right)\r
84         {\r
85             if (iYear < right.iYear) {\r
86                 return TRUE;\r
87             } else if (iYear == right.iYear) {\r
88                 if (iMonth < right.iMonth) {\r
89                     return TRUE;\r
90                 } else if (iMonth == right.iMonth) {\r
91                     return iDay < right.iDay;\r
92                 }\r
93             }\r
94             return FALSE;\r
95         }\r
96         FX_BOOL operator > (const _DATE &right)\r
97         {\r
98             if (iYear > right.iYear) {\r
99                 return TRUE;\r
100             } else if (iYear == right.iYear) {\r
101                 if (iMonth > right.iMonth) {\r
102                     return TRUE;\r
103                 } else if (iMonth == right.iMonth) {\r
104                     return iDay > right.iDay;\r
105                 }\r
106             }\r
107             return FALSE;\r
108         }\r
109         FX_INT32 iYear;\r
110         FX_INT32 iMonth;\r
111         FX_INT32 iDay;\r
112 \r
113     } DATE, *LPDATE;\r
114     FX_BOOL                             m_bInit;\r
115     CFX_RectF                   m_rtHead;\r
116     CFX_RectF                   m_rtWeek;\r
117     CFX_RectF                   m_rtLBtn;\r
118     CFX_RectF                   m_rtRBtn;\r
119     CFX_RectF                   m_rtDates;\r
120     CFX_RectF                   m_rtHSep;\r
121     CFX_RectF                   m_rtHeadText;\r
122     CFX_RectF                   m_rtToday;\r
123     CFX_RectF                   m_rtTodayFlag;\r
124     CFX_RectF                   m_rtWeekNum;\r
125     CFX_RectF                   m_rtWeekNumSep;\r
126     CFX_RectF                   m_rtTemp;\r
127     CFX_WideString              m_wsHead;\r
128     CFX_WideString              m_wsToday;\r
129     CFX_DateTime                *m_pDateTime;\r
130     CFX_PtrArray                m_arrDates;\r
131     FX_INT32                    m_iCurYear;\r
132     FX_INT32                    m_iCurMonth;\r
133     FX_INT32                    m_iYear;\r
134     FX_INT32                    m_iMonth;\r
135     FX_INT32                    m_iDay;\r
136     FX_INT32                    m_iHovered;\r
137     FX_INT32                    m_iLBtnPartStates;\r
138     FX_INT32                    m_iRBtnPartStates;\r
139     DATE                                m_dtMin;\r
140     DATE                                m_dtMax;\r
141     CFX_SizeF                   m_szHead;\r
142     CFX_SizeF                   m_szCell;\r
143     CFX_SizeF                   m_szToday;\r
144     typedef CFX_ArrayTemplate<FX_INT32> CFWL_Int32Array;\r
145     CFWL_Int32Array             m_arrSelDays;\r
146     FX_INT32                    m_iMaxSel;\r
147     CFX_RectF                   m_rtClient;\r
148     FX_FLOAT m_fHeadWid;\r
149     FX_FLOAT m_fHeadHei;\r
150     FX_FLOAT m_fHeadBtnWid;\r
151     FX_FLOAT m_fHeadBtnHei;\r
152     FX_FLOAT m_fHeadBtnHMargin;\r
153     FX_FLOAT m_fHeadBtnVMargin;\r
154     FX_FLOAT m_fHeadTextWid;\r
155     FX_FLOAT m_fHeadTextHei;\r
156     FX_FLOAT m_fHeadTextHMargin;\r
157     FX_FLOAT m_fHeadTextVMargin;\r
158     FX_FLOAT m_fHSepWid;\r
159     FX_FLOAT m_fHSepHei;\r
160 \r
161     FX_FLOAT m_fWeekNumWid;\r
162     FX_FLOAT m_fSepDOffset;\r
163     FX_FLOAT m_fSepX;\r
164     FX_FLOAT m_fSepY;\r
165 \r
166     FX_FLOAT m_fWeekNumHeigh;\r
167     FX_FLOAT m_fWeekWid;\r
168     FX_FLOAT m_fWeekHei;\r
169     FX_FLOAT m_fDateCellWid;\r
170     FX_FLOAT m_fDateCellHei;\r
171 \r
172     FX_FLOAT m_fTodayWid;\r
173     FX_FLOAT m_fTodayHei;\r
174     FX_FLOAT m_fTodayFlagWid;\r
175 \r
176     FX_FLOAT m_fMCWid;\r
177     FX_FLOAT m_fMCHei;\r
178     friend class CFWL_MonthCalendarImpDelegate;\r
179 };\r
180 typedef struct _DATEINFO {\r
181     _DATEINFO(FX_INT32 day, FX_INT32 dayofweek, FX_DWORD dwSt, CFX_RectF rc, CFX_WideString &wsday) : iDay(day), iDayOfWeek(dayofweek), dwStates(dwSt), rect(rc), wsDay(wsday) {}\r
182     FX_INT32 iDay;\r
183     FX_INT32 iDayOfWeek;\r
184     FX_DWORD dwStates;\r
185     CFX_RectF rect;\r
186     CFX_WideString wsDay;\r
187 } DATEINFO, *LPDATEINFO;\r
188 class CFWL_MonthCalendarImpDelegate : public CFWL_WidgetImpDelegate\r
189 {\r
190 public:\r
191     CFWL_MonthCalendarImpDelegate(CFWL_MonthCalendarImp *pOwner);\r
192     virtual FX_INT32    OnProcessMessage(CFWL_Message *pMessage);\r
193     virtual FWL_ERR             OnDrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix = NULL);\r
194 protected:\r
195     void                OnActivate(CFWL_Message *pMsg);\r
196     void                OnFocusChanged(CFWL_Message *pMsg, FX_BOOL bSet = TRUE);\r
197     void                OnLButtonDown(CFWL_MsgMouse *pMsg);\r
198     void                OnLButtonUp(CFWL_MsgMouse *pMsg);\r
199     void                OnMouseMove(CFWL_MsgMouse *pMsg);\r
200     void                OnMouseLeave(CFWL_MsgMouse *pMsg);\r
201     CFWL_MonthCalendarImp       *m_pOwner;\r
202 };\r
203 #endif\r