1 // Copyright 2014 The PDFium Authors 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/widestring.h" 14 #include "xfa/fwl/cfwl_event.h" 15 #include "xfa/fwl/cfwl_widget.h" 16 17 namespace pdfium { 18 19 class CFWL_MessageMouse; 20 21 class CFWL_MonthCalendar final : public CFWL_Widget { 22 public: 23 CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED; 24 ~CFWL_MonthCalendar() override; 25 26 // CFWL_Widget: 27 FWL_Type GetClassID() const override; 28 CFX_RectF GetAutosizedWidgetRect() override; 29 void Update() override; 30 void DrawWidget(CFGAS_GEGraphics* pGraphics, 31 const CFX_Matrix& matrix) override; 32 void OnProcessMessage(CFWL_Message* pMessage) override; 33 void OnDrawWidget(CFGAS_GEGraphics* pGraphics, 34 const CFX_Matrix& matrix) override; 35 36 void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay); 37 38 private: 39 struct DATE { DATEDATE40 DATE() : iYear(0), iMonth(0), iDay(0) {} 41 DATEDATE42 DATE(int32_t year, int32_t month, int32_t day) 43 : iYear(year), iMonth(month), iDay(day) {} 44 45 bool operator<(const DATE& right) { 46 if (iYear < right.iYear) 47 return true; 48 if (iYear == right.iYear) { 49 if (iMonth < right.iMonth) 50 return true; 51 if (iMonth == right.iMonth) 52 return iDay < right.iDay; 53 } 54 return false; 55 } 56 57 bool operator>(const DATE& right) { 58 if (iYear > right.iYear) 59 return true; 60 if (iYear == right.iYear) { 61 if (iMonth > right.iMonth) 62 return true; 63 if (iMonth == right.iMonth) 64 return iDay > right.iDay; 65 } 66 return false; 67 } 68 69 int32_t iYear; 70 int32_t iMonth; 71 int32_t iDay; 72 }; 73 74 struct DATEINFO { 75 DATEINFO(int32_t day, 76 int32_t dayofweek, 77 bool bFlag, 78 bool bSelect, 79 const WideString& wsday); 80 ~DATEINFO(); 81 82 Mask<CFWL_PartState> AsPartStateMask() const; 83 84 const int32_t iDay; 85 const int32_t iDayOfWeek; 86 bool bFlagged; 87 bool bSelected; 88 CFX_RectF rect; 89 const WideString wsDay; 90 }; 91 92 CFWL_MonthCalendar(CFWL_App* app, 93 const Properties& properties, 94 CFWL_Widget* pOuter); 95 96 void DrawBackground(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 97 void DrawHeadBK(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 98 void DrawLButton(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 99 void DrawRButton(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 100 void DrawCaption(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 101 void DrawSeparator(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 102 void DrawDatesInBK(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 103 void DrawWeek(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 104 void DrawToday(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 105 void DrawDatesIn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 106 void DrawDatesOut(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix); 107 void DrawDatesInCircle(CFGAS_GEGraphics* pGraphics, 108 const CFX_Matrix& mtMatrix); 109 CFX_SizeF CalcSize(); 110 void Layout(); 111 void CalcHeadSize(); 112 void CalcTodaySize(); 113 void CalDateItem(); 114 void InitDate(); 115 void ClearDateItem(); 116 void ResetDateItem(); 117 void NextMonth(); 118 void PrevMonth(); 119 void ChangeToMonth(int32_t iYear, int32_t iMonth); 120 void RemoveSelDay(); 121 void AddSelDay(int32_t iDay); 122 void JumpToToday(); 123 WideString GetHeadText(int32_t iYear, int32_t iMonth); 124 WideString GetTodayText(int32_t iYear, int32_t iMonth, int32_t iDay); 125 int32_t GetDayAtPoint(const CFX_PointF& point) const; 126 CFX_RectF GetDayRect(int32_t iDay); 127 void OnLButtonDown(CFWL_MessageMouse* pMsg); 128 void OnLButtonUp(CFWL_MessageMouse* pMsg); 129 void OnMouseMove(CFWL_MessageMouse* pMsg); 130 void OnMouseLeave(CFWL_MessageMouse* pMsg); 131 132 bool m_bInitialized = false; 133 CFX_RectF m_HeadRect; 134 CFX_RectF m_WeekRect; 135 CFX_RectF m_LBtnRect; 136 CFX_RectF m_RBtnRect; 137 CFX_RectF m_DatesRect; 138 CFX_RectF m_HSepRect; 139 CFX_RectF m_HeadTextRect; 140 CFX_RectF m_TodayRect; 141 CFX_RectF m_TodayFlagRect; 142 WideString m_wsHead; 143 WideString m_wsToday; 144 std::vector<std::unique_ptr<DATEINFO>> m_DateArray; 145 int32_t m_iCurYear = 2011; 146 int32_t m_iCurMonth = 1; 147 int32_t m_iYear = 2011; 148 int32_t m_iMonth = 1; 149 int32_t m_iDay = 1; 150 int32_t m_iHovered = -1; 151 Mask<CFWL_PartState> m_iLBtnPartStates = CFWL_PartState::kNormal; 152 Mask<CFWL_PartState> m_iRBtnPartStates = CFWL_PartState::kNormal; 153 DATE m_dtMin; 154 DATE m_dtMax; 155 CFX_SizeF m_HeadSize; 156 CFX_SizeF m_CellSize; 157 CFX_SizeF m_TodaySize; 158 std::vector<int32_t> m_SelDayArray; 159 CFX_RectF m_ClientRect; 160 }; 161 162 } // namespace pdfium 163 164 // TODO(crbug.com/42271761): Remove. 165 using pdfium::CFWL_MonthCalendar; 166 167 #endif // XFA_FWL_CFWL_MONTHCALENDAR_H_ 168