home *** CD-ROM | disk | FTP | other *** search
/ Computer Buyer 1998 October / dpcb1098.iso / Business / Maxim / MAX5 / data.z / CalendarCtrl.h < prev    next >
C/C++ Source or Header  |  1998-05-15  |  5KB  |  261 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // NAME.......: CalendarCtrl.H                                               
  3. // PURPOSE....: Group of day, month and year controls
  4. // WRITTEN....: 96/09/27 by Darko Juvan
  5. // DESCRIPTION: 
  6. //
  7. // This code and information is provided "as is" without warranty of any
  8. // kind, either expressed or implied, including but not limited to the
  9. // implied warranties of merchantability and/or fitness for a particular
  10. // purpose..
  11. //
  12. // Copyright (c) 1998  Multiactive Software Inc.  All Rights Reserved.
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15.  
  16. #ifndef __CALENDARCTRL_H 
  17. #define __CALENDARCTRL_H 
  18.  
  19. #define UM_DATE_CHANGED        WM_USER    + 5
  20.  
  21. class CCalendarCtrl;
  22.  
  23. enum eDayType {eCurrentMonth, eCurrentDay, eOtherMonth};
  24.  
  25. class CDayButton : public CButton
  26. {
  27. // Constructors
  28. public:
  29.     CDayButton();
  30.  
  31. protected:
  32.  
  33. // Attributes
  34. public:
  35.     CCalendarCtrl* m_pCalendarGroup; // date control group
  36.  
  37.     int m_iYear; // current selected year [m_iLowYear..m_iHighYear]
  38.     int m_iMonth; // current selected month [1..12]
  39.     int m_iDay; // current selected day [1..31]
  40.  
  41.     int m_iDaysInMonth; // number of days in current month
  42.     int m_iFirstWeekDay; // weekday for the 1st of this month [0..6]
  43.  
  44.     int m_iButtonWidth; // control width 
  45.     int m_iButtonHeight; // control height
  46.     int m_iBoxWidth; // width of a single day space on screen 
  47.     int m_iBoxHeight; // height of a single day space on screen
  48.  
  49.     
  50.     int m_iCurrentIndex; // index in array [1..42] of day spaces on screen
  51.  
  52.     BOOL m_bInitialized; // set when control is drawn the first time
  53.  
  54.     int m_iLowYear; // lower limit for year
  55.     int m_iHighYear; // upper limit for year
  56.  
  57.     CComboBox*       m_pMonthControl; // month control connected to this control
  58.     CSpinButtonCtrl* m_pYearControl; // year control connected to this control
  59.  
  60. protected:
  61.  
  62.  
  63. // Operations
  64. public:
  65.     void DrawItem(LPDRAWITEMSTRUCT lpDIS);
  66.     void DrawBorder(CRect rcItem);
  67.  
  68.     void DrawAll(CDC* pDC);
  69.  
  70.     void WeekBack();
  71.     void WeekForward();
  72.     void DayBack();
  73.     void DayForward();
  74.     void FirstDay();
  75.     void LastDay();
  76.     BOOL MonthBack();
  77.     BOOL MonthForward();
  78.  
  79.     // ClassWizard generated virtual function overrides
  80.     //{{AFX_VIRTUAL(CDayButton)
  81.     //}}AFX_VIRTUAL
  82.  
  83. protected:
  84.  
  85. private:
  86.  
  87. // Implementation
  88. public:
  89.     virtual ~CDayButton();
  90.  
  91. protected:
  92.     void DrawDays(CDC* pDC);
  93.     void DrawDayNames(CDC* pDC);
  94.     void DrawDayName(CDC* pDC, int iIndex, int iHorOr, int iVerOr);
  95.  
  96.     void DrawChanged(CDC* pDC, int iOld, int iNew);
  97.     void DrawDay(CDC* pDC, int iIndex, const CString& szDay, eDayType eDay);
  98.  
  99.     void  RecalculateData();
  100.     int   GetDaysInMonth(int iYear, int iMonth);
  101.     int   GetFirstWeekDay(int iYear, int iMonth, int iDay);
  102.  
  103.     int ProcessMouseClick(int& iOld, int& iNew);
  104.  
  105.     //{{AFX_MSG(CDayButton)
  106.     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  107.     //}}AFX_MSG
  108.  
  109. private:
  110.     DECLARE_MESSAGE_MAP()
  111.     DECLARE_DYNAMIC(CDayButton)
  112.  
  113. };
  114.  
  115.  
  116. class CMonthComboBox : public CComboBox
  117. {
  118. // Constructors
  119. public:
  120.     CMonthComboBox();
  121.  
  122. protected:
  123.  
  124. private:
  125.  
  126. // Attributes
  127. public:
  128.     CCalendarCtrl* m_pCalendarGroup; // date control group
  129.  
  130. protected:
  131.  
  132. private:
  133.  
  134. // Operations
  135. public:
  136.     // ClassWizard generated virtual function overrides
  137.     //{{AFX_VIRTUAL(CMonthComboBox)
  138.     //}}AFX_VIRTUAL
  139.  
  140. protected:
  141.  
  142. private:
  143.  
  144. // Implementation
  145. public:
  146.     virtual ~CMonthComboBox();
  147.  
  148. protected:
  149.     //{{AFX_MSG(CMonthComboBox)
  150.     afx_msg void OnSelchange();
  151.     //}}AFX_MSG
  152.  
  153. private:
  154.     DECLARE_MESSAGE_MAP()
  155. };
  156.  
  157. class CYearSpin : public CSpinButtonCtrl
  158. {
  159. // Constructors
  160. public:
  161.     CYearSpin();
  162.  
  163. protected:
  164.  
  165. private:
  166.  
  167. // Attributes
  168. public:
  169.     CCalendarCtrl* m_pCalendarGroup; // date control group
  170.  
  171. protected:
  172.  
  173. private:
  174.  
  175. // Operations
  176. public:
  177.     // ClassWizard generated virtual function overrides
  178.     //{{AFX_VIRTUAL(CYearSpin)
  179.     //}}AFX_VIRTUAL
  180.  
  181. protected:
  182.  
  183. private:
  184.  
  185. // Implementation
  186. public:
  187.     virtual ~CYearSpin();
  188.  
  189. protected:
  190.     //{{AFX_MSG(CYearSpin)
  191.     afx_msg void OnDeltapos(NMHDR* pNMHDR, LRESULT* pResult);
  192.     //}}AFX_MSG
  193.  
  194. private:
  195.     DECLARE_MESSAGE_MAP()
  196. };
  197.  
  198. class CCalendarCtrl : public CObject
  199. {
  200. // Constructors
  201. public:
  202.     CCalendarCtrl();
  203.     void Create(CWnd* parent,
  204.                 UINT iDayControl,
  205.                 UINT iMonthControl,
  206.                 UINT iYearControl,
  207.                 CString date);
  208.     void Create(CWnd* parent,
  209.                 UINT iDayControl,
  210.                 UINT iMonthControl,
  211.                 UINT iYearControl,
  212.                 int iYear=0, int iMonth=0, int iDay=0);
  213.     
  214.     void SetDate(int iYear=0, int iMonth=0, int iDay=0);
  215.     void SetDate(LPCTSTR date);
  216.     int GetMonth(LPCTSTR sMonth);
  217.  
  218. protected:
  219.  
  220. private:
  221.  
  222. // Attributes
  223. public:
  224.     CDayButton        m_DayControl; // day control
  225.     CMonthComboBox    m_MonthControl; // month control
  226.     CYearSpin        m_YearControl; // year control
  227.     CWnd*            m_pParent;
  228.     BOOL            m_bClose;
  229.  
  230.     int m_iYear; // year
  231.     int m_iMonth; // month
  232.     int m_iDay; // day
  233.  
  234. protected:
  235.  
  236. private:
  237.  
  238. // Operations
  239. public:
  240.     void ForwardMsg(MSG* pMsg);
  241.     void RefreshDate();
  242.     void UpdateMonth();
  243.     void UpdateYear(NMHDR* pNMHDR);
  244.     void DateChanged();
  245.  
  246. protected:
  247.  
  248. private:
  249.  
  250. // Implementation
  251. public:
  252.  
  253. protected:
  254.  
  255. private:
  256.     DECLARE_DYNAMIC(CCalendarCtrl)
  257.  
  258. };
  259.  
  260. #endif //__CALENDARCTRL_H 
  261.