1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/calctrl.h
3 // Purpose: generic implementation of date-picker control
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma interface "calctrl.h"
16 #ifndef _WX_GENERIC_CALCTRL_H
17 #define _WX_GENERIC_CALCTRL_H
19 #include "wx/control.h" // the base class
21 #include "wx/datetime.h" // for m_date
22 #include "wx/combobox.h" // for m_comboMonth
23 #include "wx/spinctrl.h" // for m_spinYear
25 #define wxCalendarNameStr _T("CalendarCtrl")
27 // ----------------------------------------------------------------------------
28 // wxCalendarCtrl: a control allowing the user to pick a date interactively
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxCalendarCtrl
: public wxControl
33 friend class wxMonthComboBox
;
34 friend class wxYearSpinCtrl
;
38 wxCalendarCtrl() { Init(); }
39 wxCalendarCtrl(wxWindow
*parent
,
41 const wxDateTime
& date
= wxDefaultDateTime
,
42 const wxPoint
& pos
= wxDefaultPosition
,
43 const wxSize
& size
= wxDefaultSize
,
45 const wxString
& name
= wxCalendarNameStr
)
46 : wxControl(parent
, id
, pos
, size
,
47 style
| wxWANTS_CHARS
, wxDefaultValidator
, name
)
51 (void)Create(parent
, id
, date
, pos
, size
, style
, name
);
54 bool Create(wxWindow
*parent
,
56 const wxDateTime
& date
= wxDefaultDateTime
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
60 const wxString
& name
= wxCalendarNameStr
);
62 virtual ~wxCalendarCtrl();
64 // set/get the current date
65 void SetDate(const wxDateTime
& date
);
66 const wxDateTime
& GetDate() const { return m_date
; }
68 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
69 // with the corresponding value (none for NOWHERE, the date for DAY and wd
71 wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
72 wxDateTime
*date
= NULL
,
73 wxDateTime::WeekDay
*wd
= NULL
);
75 // implementation only from now on
76 // -------------------------------
78 // forward these functions to all subcontrols
79 virtual bool Enable(bool enable
= TRUE
);
80 virtual bool Show(bool show
= TRUE
);
83 // common part of all ctors
87 void OnPaint(wxPaintEvent
& event
);
88 void OnClick(wxMouseEvent
& event
);
89 void OnDClick(wxMouseEvent
& event
);
90 void OnChar(wxKeyEvent
& event
);
91 void OnMonthChange(wxCommandEvent
& event
);
92 void OnYearChange(wxSpinEvent
& event
);
94 // override some base class virtuals
95 virtual wxSize
DoGetBestSize() const;
96 virtual void DoGetPosition(int *x
, int *y
) const;
97 virtual void DoGetSize(int *width
, int *height
) const;
98 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
99 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
101 // (re)calc m_widthCol and m_heightRow
102 void RecalcGeometry();
104 // set the date and send the notification
105 void SetDateAndNotify(const wxDateTime
& date
);
107 // get the week (row, in range 1..6) for the given date
108 size_t GetWeek(const wxDateTime
& date
) const;
110 // get the date from which we start drawing days
111 wxDateTime
GetStartDate() const;
113 // is this date shown?
114 bool IsDateShown(const wxDateTime
& date
) const;
116 // redraw the given date
117 void RefreshDate(const wxDateTime
& date
);
119 // change the date inside the same month/year
120 void ChangeDay(const wxDateTime
& date
);
122 // generate the given calendar event and a "selection changed" one if
123 // selChanged is TRUE
124 void GenerateEvent(wxEventType type
, bool selChanged
= TRUE
);
127 wxComboBox
*m_comboMonth
;
128 wxSpinCtrl
*m_spinYear
;
132 // the width and height of one column/row in the calendar
136 // the week day names
137 wxString m_weekdays
[7];
139 DECLARE_DYNAMIC_CLASS(wxCalendarCtrl
)
140 DECLARE_EVENT_TABLE()
143 #endif // _WX_GENERIC_CALCTRL_H