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