1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: date-picker control
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CALCTRL_H_
13 #define _WX_CALCTRL_H_
17 #if wxUSE_CALENDARCTRL
19 #include "wx/dateevt.h"
20 #include "wx/colour.h"
22 #include "wx/control.h"
24 // ----------------------------------------------------------------------------
25 // wxCalendarCtrl flags
26 // ----------------------------------------------------------------------------
30 // show Sunday as the first day of the week (default)
31 wxCAL_SUNDAY_FIRST
= 0x0000,
33 // show Monder as the first day of the week
34 wxCAL_MONDAY_FIRST
= 0x0001,
37 wxCAL_SHOW_HOLIDAYS
= 0x0002,
39 // disable the year change control, show only the month change one
41 wxCAL_NO_YEAR_CHANGE
= 0x0004,
43 // don't allow changing neither month nor year (implies
44 // wxCAL_NO_YEAR_CHANGE)
45 wxCAL_NO_MONTH_CHANGE
= 0x000c,
47 // use MS-style month-selection instead of combo-spin combination
48 wxCAL_SEQUENTIAL_MONTH_SELECTION
= 0x0010,
50 // show the neighbouring weeks in the previous and next month
51 wxCAL_SHOW_SURROUNDING_WEEKS
= 0x0020
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // return values for the HitTest() method
59 enum wxCalendarHitTestResult
61 wxCAL_HITTEST_NOWHERE
, // outside of anything
62 wxCAL_HITTEST_HEADER
, // on the header (weekdays)
63 wxCAL_HITTEST_DAY
, // on a day in the calendar
64 wxCAL_HITTEST_INCMONTH
,
65 wxCAL_HITTEST_DECMONTH
,
66 wxCAL_HITTEST_SURROUNDING_WEEK
69 // border types for a date
70 enum wxCalendarDateBorder
72 wxCAL_BORDER_NONE
, // no border (default)
73 wxCAL_BORDER_SQUARE
, // a rectangular border
74 wxCAL_BORDER_ROUND
// a round border
77 // ----------------------------------------------------------------------------
78 // wxCalendarDateAttr: custom attributes for a calendar date
79 // ----------------------------------------------------------------------------
81 class WXDLLIMPEXP_ADV wxCalendarDateAttr
85 wxCalendarDateAttr(const wxColour
& colText
= wxNullColour
,
86 const wxColour
& colBack
= wxNullColour
,
87 const wxColour
& colBorder
= wxNullColour
,
88 const wxFont
& font
= wxNullFont
,
89 wxCalendarDateBorder border
= wxCAL_BORDER_NONE
)
90 : m_colText(colText
), m_colBack(colBack
),
91 m_colBorder(colBorder
), m_font(font
)
95 wxCalendarDateAttr(wxCalendarDateBorder border
,
96 const wxColour
& colBorder
= wxNullColour
)
97 : m_colBorder(colBorder
)
103 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
104 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
105 void SetBorderColour(const wxColour
& col
) { m_colBorder
= col
; }
106 void SetFont(const wxFont
& font
) { m_font
= font
; }
107 void SetBorder(wxCalendarDateBorder border
) { m_border
= border
; }
108 void SetHoliday(bool holiday
) { m_holiday
= holiday
; }
111 bool HasTextColour() const { return m_colText
.Ok(); }
112 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
113 bool HasBorderColour() const { return m_colBorder
.Ok(); }
114 bool HasFont() const { return m_font
.Ok(); }
115 bool HasBorder() const { return m_border
!= wxCAL_BORDER_NONE
; }
117 bool IsHoliday() const { return m_holiday
; }
119 const wxColour
& GetTextColour() const { return m_colText
; }
120 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
121 const wxColour
& GetBorderColour() const { return m_colBorder
; }
122 const wxFont
& GetFont() const { return m_font
; }
123 wxCalendarDateBorder
GetBorder() const { return m_border
; }
125 // get or change the "mark" attribute, i.e. the one used for the items
126 // marked with wxCalendarCtrl::Mark()
127 static const wxCalendarDateAttr
& GetMark() { return m_mark
; }
128 static void SetMark(wxCalendarDateAttr
const& m
) { m_mark
= m
; }
131 void Init(wxCalendarDateBorder border
= wxCAL_BORDER_NONE
)
138 static wxCalendarDateAttr m_mark
;
144 wxCalendarDateBorder m_border
;
148 // ----------------------------------------------------------------------------
149 // wxCalendarCtrl events
150 // ----------------------------------------------------------------------------
152 class WXDLLIMPEXP_FWD_ADV wxCalendarCtrl
;
154 class WXDLLIMPEXP_ADV wxCalendarEvent
: public wxDateEvent
157 wxCalendarEvent() : m_wday(wxDateTime::Inv_WeekDay
) { }
158 wxCalendarEvent(wxWindow
*win
, const wxDateTime
& dt
, wxEventType type
)
159 : wxDateEvent(win
, dt
, type
),
160 m_wday(wxDateTime::Inv_WeekDay
)
164 void SetWeekDay(const wxDateTime::WeekDay wd
) { m_wday
= wd
; }
165 wxDateTime::WeekDay
GetWeekDay() const { return m_wday
; }
168 wxDateTime::WeekDay m_wday
;
170 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCalendarEvent
)
173 // ----------------------------------------------------------------------------
174 // wxCalendarCtrlBase
175 // ----------------------------------------------------------------------------
177 class WXDLLIMPEXP_ADV wxCalendarCtrlBase
: public wxControl
180 // do we allow changing the month/year?
181 bool AllowMonthChange() const { return !HasFlag(wxCAL_NO_MONTH_CHANGE
); }
183 // get/set the current date
184 virtual wxDateTime
GetDate() const = 0;
185 virtual bool SetDate(const wxDateTime
& date
) = 0;
188 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
189 // with the corresponding value (none for NOWHERE, the date for DAY and wd
192 // notice that this is not implemented in all versions
193 virtual wxCalendarHitTestResult
194 HitTest(const wxPoint
& WXUNUSED(pos
),
195 wxDateTime
* WXUNUSED(date
) = NULL
,
196 wxDateTime::WeekDay
* WXUNUSED(wd
) = NULL
)
198 return wxCAL_HITTEST_NOWHERE
;
201 // allow or disable changing the current month (and year), return true if
202 // the value of this option really changed or false if it was already set
203 // to the required value
205 // NB: we provide implementation for this pure virtual function, derived
206 // classes should call it
207 virtual bool EnableMonthChange(bool enable
) = 0;
210 // an item without custom attributes is drawn with the default colours and
211 // font and without border, setting custom attributes allows to modify this
213 // the day parameter should be in 1..31 range, for days 29, 30, 31 the
214 // corresponding attribute is just unused if there is no such day in the
217 // notice that currently arbitrary attributes are supported only in the
218 // generic version, the native controls only support Mark() which assigns
219 // some special appearance (which can be customized using SetMark() for the
220 // generic version) to the given day
222 virtual void Mark(size_t day
, bool mark
) = 0;
224 virtual wxCalendarDateAttr
*GetAttr(size_t WXUNUSED(day
)) const
226 virtual void SetAttr(size_t WXUNUSED(day
), wxCalendarDateAttr
*attr
)
228 virtual void ResetAttr(size_t WXUNUSED(day
)) { }
233 // currently all functions in this section are implemented in the generic
234 // version of the control only and are simply ignored by native ones
236 // equivalent to changing wxCAL_SHOW_HOLIDAYS flag but should be called
237 // instead of just changing it
238 virtual void EnableHolidayDisplay(bool WXUNUSED(display
) = true) { }
240 // set/get the colours to use for holidays (if they're enabled)
241 virtual void SetHolidayColours(const wxColour
& WXUNUSED(colFg
),
242 const wxColour
& WXUNUSED(colBg
)) { }
244 virtual const wxColour
& GetHolidayColourFg() const { return wxNullColour
; }
245 virtual const wxColour
& GetHolidayColourBg() const { return wxNullColour
; }
247 // mark the given day of the current month as being a holiday
248 virtual void SetHoliday(size_t WXUNUSED(day
)) { }
251 // customizing the colours of the controls
253 // most of the methods in this section are only implemented by the native
254 // version of the control and do nothing in the native ones
256 // set/get the colours to use for the display of the week day names at the
257 // top of the controls
258 virtual void SetHeaderColours(const wxColour
& WXUNUSED(colFg
),
259 const wxColour
& WXUNUSED(colBg
)) { }
261 virtual const wxColour
& GetHeaderColourFg() const { return wxNullColour
; }
262 virtual const wxColour
& GetHeaderColourBg() const { return wxNullColour
; }
264 // set/get the colours used for the currently selected date
265 virtual void SetHighlightColours(const wxColour
& WXUNUSED(colFg
),
266 const wxColour
& WXUNUSED(colBg
)) { }
268 virtual const wxColour
& GetHighlightColourFg() const { return wxNullColour
; }
269 virtual const wxColour
& GetHighlightColourBg() const { return wxNullColour
; }
272 // implementation only from now on
274 // generate the given calendar event(s)
275 void GenerateEvent(wxEventType type
)
277 wxCalendarEvent
event(this, GetDate(), type
);
278 HandleWindowEvent(event
);
282 // ----------------------------------------------------------------------------
284 // ----------------------------------------------------------------------------
286 #define wxCalendarNameStr "CalendarCtrl"
288 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
289 #define wxHAS_NATIVE_CALENDARCTRL
290 #include "wx/gtk/calctrl.h"
291 #define wxCalendarCtrl wxGtkCalendarCtrl
293 #include "wx/generic/calctrlg.h"
294 #define wxCalendarCtrl wxGenericCalendarCtrl
298 // ----------------------------------------------------------------------------
299 // calendar event types and macros for handling them
300 // ----------------------------------------------------------------------------
302 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_SEL_CHANGED
;
303 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_PAGE_CHANGED
;
304 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_DOUBLECLICKED
;
305 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED
;
308 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_DAY_CHANGED
;
309 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_MONTH_CHANGED
;
310 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_YEAR_CHANGED
;
312 typedef void (wxEvtHandler::*wxCalendarEventFunction
)(wxCalendarEvent
&);
314 #define wxCalendarEventHandler(func) \
315 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCalendarEventFunction, &func)
317 #define wx__DECLARE_CALEVT(evt, id, fn) \
318 wx__DECLARE_EVT1(wxEVT_CALENDAR_ ## evt, id, wxCalendarEventHandler(fn))
320 #define EVT_CALENDAR(id, fn) wx__DECLARE_CALEVT(DOUBLECLICKED, id, fn)
321 #define EVT_CALENDAR_SEL_CHANGED(id, fn) wx__DECLARE_CALEVT(SEL_CHANGED, id, fn)
322 #define EVT_CALENDAR_PAGE_CHANGED(id, fn) wx__DECLARE_CALEVT(PAGE_CHANGED, id, fn)
323 #define EVT_CALENDAR_WEEKDAY_CLICKED(id, fn) wx__DECLARE_CALEVT(WEEKDAY_CLICKED, id, fn)
326 #define EVT_CALENDAR_DAY(id, fn) wx__DECLARE_CALEVT(DAY_CHANGED, id, fn)
327 #define EVT_CALENDAR_MONTH(id, fn) wx__DECLARE_CALEVT(MONTH_CHANGED, id, fn)
328 #define EVT_CALENDAR_YEAR(id, fn) wx__DECLARE_CALEVT(YEAR_CHANGED, id, fn)
330 #endif // wxUSE_CALENDARCTRL
332 #endif // _WX_CALCTRL_H_