Home | History | Annotate | Download | only in include
      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 _FWL_MONTHCALENDAR_IMP_H
      8 #define _FWL_MONTHCALENDAR_IMP_H
      9 class CFWL_WidgetImp;
     10 class CFWL_WidgetImpProperties;
     11 class CFWL_WidgetImpDelegate;
     12 class IFWL_Widget;
     13 class IFDE_DateTime;
     14 class CFDE_DateTime;
     15 extern uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth);
     16 class CFWL_MonthCalendarImp;
     17 class CFWL_MonthCalendarImpDelegate;
     18 class CFWL_MonthCalendarImp : public CFWL_WidgetImp {
     19  public:
     20   CFWL_MonthCalendarImp(const CFWL_WidgetImpProperties& properties,
     21                         IFWL_Widget* pOuter);
     22   ~CFWL_MonthCalendarImp();
     23   virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const;
     24   virtual FX_DWORD GetClassID() const;
     25   virtual FWL_ERR Initialize();
     26   virtual FWL_ERR Finalize();
     27   virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE);
     28   virtual FWL_ERR Update();
     29   virtual FWL_ERR DrawWidget(CFX_Graphics* pGraphics,
     30                              const CFX_Matrix* pMatrix = NULL);
     31   virtual int32_t CountSelect();
     32   virtual FX_BOOL GetSelect(int32_t& iYear,
     33                             int32_t& iMonth,
     34                             int32_t& iDay,
     35                             int32_t nIndex = 0);
     36   virtual FX_BOOL SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay);
     37 
     38  protected:
     39   void DrawBkground(CFX_Graphics* pGraphics,
     40                     IFWL_ThemeProvider* pTheme,
     41                     const CFX_Matrix* pMatrix);
     42   void DrawHeadBK(CFX_Graphics* pGraphics,
     43                   IFWL_ThemeProvider* pTheme,
     44                   const CFX_Matrix* pMatrix);
     45   void DrawLButton(CFX_Graphics* pGraphics,
     46                    IFWL_ThemeProvider* pTheme,
     47                    const CFX_Matrix* pMatrix);
     48   void DrawRButton(CFX_Graphics* pGraphics,
     49                    IFWL_ThemeProvider* pTheme,
     50                    const CFX_Matrix* pMatrix);
     51   void DrawCaption(CFX_Graphics* pGraphics,
     52                    IFWL_ThemeProvider* pTheme,
     53                    const CFX_Matrix* pMatrix);
     54   void DrawSeperator(CFX_Graphics* pGraphics,
     55                      IFWL_ThemeProvider* pTheme,
     56                      const CFX_Matrix* pMatrix);
     57   void DrawDatesInBK(CFX_Graphics* pGraphics,
     58                      IFWL_ThemeProvider* pTheme,
     59                      const CFX_Matrix* pMatrix);
     60   void DrawWeek(CFX_Graphics* pGraphics,
     61                 IFWL_ThemeProvider* pTheme,
     62                 const CFX_Matrix* pMatrix);
     63   void DrawWeekNumber(CFX_Graphics* pGraphics,
     64                       IFWL_ThemeProvider* pTheme,
     65                       const CFX_Matrix* pMatrix);
     66   void DrawWeekNumberSep(CFX_Graphics* pGraphics,
     67                          IFWL_ThemeProvider* pTheme,
     68                          const CFX_Matrix* pMatrix);
     69   void DrawToday(CFX_Graphics* pGraphics,
     70                  IFWL_ThemeProvider* pTheme,
     71                  const CFX_Matrix* pMatrix);
     72   void DrawDatesIn(CFX_Graphics* pGraphics,
     73                    IFWL_ThemeProvider* pTheme,
     74                    const CFX_Matrix* pMatrix);
     75   void DrawDatesOut(CFX_Graphics* pGraphics,
     76                     IFWL_ThemeProvider* pTheme,
     77                     const CFX_Matrix* pMatrix);
     78   void DrawDatesInCircle(CFX_Graphics* pGraphics,
     79                          IFWL_ThemeProvider* pTheme,
     80                          const CFX_Matrix* pMatrix);
     81   void DrawTodayCircle(CFX_Graphics* pGraphics,
     82                        IFWL_ThemeProvider* pTheme,
     83                        const CFX_Matrix* pMatrix);
     84   CFX_SizeF CalcSize(FX_BOOL bAutoSize = FALSE);
     85   void LayOut();
     86   void CalcHeadSize();
     87   void CalcTodaySize();
     88   void CalDateItem();
     89   void GetCapValue();
     90   int32_t CalWeekNumber(int32_t iYear, int32_t iMonth, int32_t iDay);
     91 
     92   FX_BOOL GetMinDate(int32_t& iYear, int32_t& iMonth, int32_t& iDay);
     93   FX_BOOL SetMinDate(int32_t iYear, int32_t iMonth, int32_t iDay);
     94   FX_BOOL GetMaxDate(int32_t& iYear, int32_t& iMonth, int32_t& iDay);
     95   FX_BOOL SetMaxDate(int32_t iYear, int32_t iMonth, int32_t iDay);
     96   FX_BOOL InitDate();
     97   void ClearDateItem();
     98   void ReSetDateItem();
     99   FX_BOOL NextMonth();
    100   FX_BOOL PrevMonth();
    101   void ChangeToMonth(int32_t iYear, int32_t iMonth);
    102   FX_BOOL RemoveSelDay(int32_t iDay, FX_BOOL bAll = FALSE);
    103   FX_BOOL AddSelDay(int32_t iDay);
    104   FX_BOOL JumpToToday();
    105   void GetHeadText(int32_t iYear, int32_t iMonth, CFX_WideString& wsHead);
    106   void GetTodayText(int32_t iYear,
    107                     int32_t iMonth,
    108                     int32_t iDay,
    109                     CFX_WideString& wsToday);
    110   int32_t GetDayAtPoint(FX_FLOAT x, FX_FLOAT y);
    111   FX_BOOL GetDayRect(int32_t iDay, CFX_RectF& rtDay);
    112   typedef struct _DATE {
    113     _DATE() {
    114       iYear = 0;
    115       iMonth = 0;
    116       iDay = 0;
    117     }
    118     _DATE(int32_t year, int32_t month, int32_t day)
    119         : iYear(year), iMonth(month), iDay(day) {}
    120     FX_BOOL operator<(const _DATE& right) {
    121       if (iYear < right.iYear) {
    122         return TRUE;
    123       } else if (iYear == right.iYear) {
    124         if (iMonth < right.iMonth) {
    125           return TRUE;
    126         } else if (iMonth == right.iMonth) {
    127           return iDay < right.iDay;
    128         }
    129       }
    130       return FALSE;
    131     }
    132     FX_BOOL operator>(const _DATE& right) {
    133       if (iYear > right.iYear) {
    134         return TRUE;
    135       } else if (iYear == right.iYear) {
    136         if (iMonth > right.iMonth) {
    137           return TRUE;
    138         } else if (iMonth == right.iMonth) {
    139           return iDay > right.iDay;
    140         }
    141       }
    142       return FALSE;
    143     }
    144     int32_t iYear;
    145     int32_t iMonth;
    146     int32_t iDay;
    147 
    148   } DATE, *LPDATE;
    149   FX_BOOL m_bInit;
    150   CFX_RectF m_rtHead;
    151   CFX_RectF m_rtWeek;
    152   CFX_RectF m_rtLBtn;
    153   CFX_RectF m_rtRBtn;
    154   CFX_RectF m_rtDates;
    155   CFX_RectF m_rtHSep;
    156   CFX_RectF m_rtHeadText;
    157   CFX_RectF m_rtToday;
    158   CFX_RectF m_rtTodayFlag;
    159   CFX_RectF m_rtWeekNum;
    160   CFX_RectF m_rtWeekNumSep;
    161   CFX_RectF m_rtTemp;
    162   CFX_WideString m_wsHead;
    163   CFX_WideString m_wsToday;
    164   CFX_DateTime* m_pDateTime;
    165   CFX_PtrArray m_arrDates;
    166   int32_t m_iCurYear;
    167   int32_t m_iCurMonth;
    168   int32_t m_iYear;
    169   int32_t m_iMonth;
    170   int32_t m_iDay;
    171   int32_t m_iHovered;
    172   int32_t m_iLBtnPartStates;
    173   int32_t m_iRBtnPartStates;
    174   DATE m_dtMin;
    175   DATE m_dtMax;
    176   CFX_SizeF m_szHead;
    177   CFX_SizeF m_szCell;
    178   CFX_SizeF m_szToday;
    179   typedef CFX_ArrayTemplate<int32_t> CFWL_Int32Array;
    180   CFWL_Int32Array m_arrSelDays;
    181   int32_t m_iMaxSel;
    182   CFX_RectF m_rtClient;
    183   FX_FLOAT m_fHeadWid;
    184   FX_FLOAT m_fHeadHei;
    185   FX_FLOAT m_fHeadBtnWid;
    186   FX_FLOAT m_fHeadBtnHei;
    187   FX_FLOAT m_fHeadBtnHMargin;
    188   FX_FLOAT m_fHeadBtnVMargin;
    189   FX_FLOAT m_fHeadTextWid;
    190   FX_FLOAT m_fHeadTextHei;
    191   FX_FLOAT m_fHeadTextHMargin;
    192   FX_FLOAT m_fHeadTextVMargin;
    193   FX_FLOAT m_fHSepWid;
    194   FX_FLOAT m_fHSepHei;
    195 
    196   FX_FLOAT m_fWeekNumWid;
    197   FX_FLOAT m_fSepDOffset;
    198   FX_FLOAT m_fSepX;
    199   FX_FLOAT m_fSepY;
    200 
    201   FX_FLOAT m_fWeekNumHeigh;
    202   FX_FLOAT m_fWeekWid;
    203   FX_FLOAT m_fWeekHei;
    204   FX_FLOAT m_fDateCellWid;
    205   FX_FLOAT m_fDateCellHei;
    206 
    207   FX_FLOAT m_fTodayWid;
    208   FX_FLOAT m_fTodayHei;
    209   FX_FLOAT m_fTodayFlagWid;
    210 
    211   FX_FLOAT m_fMCWid;
    212   FX_FLOAT m_fMCHei;
    213   friend class CFWL_MonthCalendarImpDelegate;
    214 };
    215 typedef struct _DATEINFO {
    216   _DATEINFO(int32_t day,
    217             int32_t dayofweek,
    218             FX_DWORD dwSt,
    219             CFX_RectF rc,
    220             CFX_WideString& wsday)
    221       : iDay(day),
    222         iDayOfWeek(dayofweek),
    223         dwStates(dwSt),
    224         rect(rc),
    225         wsDay(wsday) {}
    226   int32_t iDay;
    227   int32_t iDayOfWeek;
    228   FX_DWORD dwStates;
    229   CFX_RectF rect;
    230   CFX_WideString wsDay;
    231 } DATEINFO, *LPDATEINFO;
    232 class CFWL_MonthCalendarImpDelegate : public CFWL_WidgetImpDelegate {
    233  public:
    234   CFWL_MonthCalendarImpDelegate(CFWL_MonthCalendarImp* pOwner);
    235   int32_t OnProcessMessage(CFWL_Message* pMessage) override;
    236   FWL_ERR OnDrawWidget(CFX_Graphics* pGraphics,
    237                        const CFX_Matrix* pMatrix = NULL) override;
    238 
    239  protected:
    240   void OnActivate(CFWL_Message* pMsg);
    241   void OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE);
    242   void OnLButtonDown(CFWL_MsgMouse* pMsg);
    243   void OnLButtonUp(CFWL_MsgMouse* pMsg);
    244   void OnMouseMove(CFWL_MsgMouse* pMsg);
    245   void OnMouseLeave(CFWL_MsgMouse* pMsg);
    246   CFWL_MonthCalendarImp* m_pOwner;
    247 };
    248 #endif
    249