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