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,
53 // show week numbers on the left side of the calendar.
54 wxCAL_SHOW_WEEK_NUMBERS
= 0x0040
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // return values for the HitTest() method
62 enum wxCalendarHitTestResult
64 wxCAL_HITTEST_NOWHERE
, // outside of anything
65 wxCAL_HITTEST_HEADER
, // on the header (weekdays)
66 wxCAL_HITTEST_DAY
, // on a day in the calendar
67 wxCAL_HITTEST_INCMONTH
,
68 wxCAL_HITTEST_DECMONTH
,
69 wxCAL_HITTEST_SURROUNDING_WEEK
72 // border types for a date
73 enum wxCalendarDateBorder
75 wxCAL_BORDER_NONE
, // no border (default)
76 wxCAL_BORDER_SQUARE
, // a rectangular border
77 wxCAL_BORDER_ROUND
// a round border
80 // ----------------------------------------------------------------------------
81 // wxCalendarDateAttr: custom attributes for a calendar date
82 // ----------------------------------------------------------------------------
84 class WXDLLIMPEXP_ADV wxCalendarDateAttr
88 wxCalendarDateAttr(const wxColour
& colText
= wxNullColour
,
89 const wxColour
& colBack
= wxNullColour
,
90 const wxColour
& colBorder
= wxNullColour
,
91 const wxFont
& font
= wxNullFont
,
92 wxCalendarDateBorder border
= wxCAL_BORDER_NONE
)
93 : m_colText(colText
), m_colBack(colBack
),
94 m_colBorder(colBorder
), m_font(font
)
98 wxCalendarDateAttr(wxCalendarDateBorder border
,
99 const wxColour
& colBorder
= wxNullColour
)
100 : m_colBorder(colBorder
)
106 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
107 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
108 void SetBorderColour(const wxColour
& col
) { m_colBorder
= col
; }
109 void SetFont(const wxFont
& font
) { m_font
= font
; }
110 void SetBorder(wxCalendarDateBorder border
) { m_border
= border
; }
111 void SetHoliday(bool holiday
) { m_holiday
= holiday
; }
114 bool HasTextColour() const { return m_colText
.Ok(); }
115 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
116 bool HasBorderColour() const { return m_colBorder
.Ok(); }
117 bool HasFont() const { return m_font
.Ok(); }
118 bool HasBorder() const { return m_border
!= wxCAL_BORDER_NONE
; }
120 bool IsHoliday() const { return m_holiday
; }
122 const wxColour
& GetTextColour() const { return m_colText
; }
123 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
124 const wxColour
& GetBorderColour() const { return m_colBorder
; }
125 const wxFont
& GetFont() const { return m_font
; }
126 wxCalendarDateBorder
GetBorder() const { return m_border
; }
128 // get or change the "mark" attribute, i.e. the one used for the items
129 // marked with wxCalendarCtrl::Mark()
130 static const wxCalendarDateAttr
& GetMark() { return m_mark
; }
131 static void SetMark(wxCalendarDateAttr
const& m
) { m_mark
= m
; }
134 void Init(wxCalendarDateBorder border
= wxCAL_BORDER_NONE
)
141 static wxCalendarDateAttr m_mark
;
147 wxCalendarDateBorder m_border
;
151 // ----------------------------------------------------------------------------
152 // wxCalendarCtrl events
153 // ----------------------------------------------------------------------------
155 class WXDLLIMPEXP_FWD_ADV wxCalendarCtrl
;
157 class WXDLLIMPEXP_ADV wxCalendarEvent
: public wxDateEvent
160 wxCalendarEvent() : m_wday(wxDateTime::Inv_WeekDay
) { }
161 wxCalendarEvent(wxWindow
*win
, const wxDateTime
& dt
, wxEventType type
)
162 : wxDateEvent(win
, dt
, type
),
163 m_wday(wxDateTime::Inv_WeekDay
)
167 void SetWeekDay(const wxDateTime::WeekDay wd
) { m_wday
= wd
; }
168 wxDateTime::WeekDay
GetWeekDay() const { return m_wday
; }
171 wxDateTime::WeekDay m_wday
;
173 DECLARE_DYNAMIC_CLASS_NO_COPY(wxCalendarEvent
)
176 // ----------------------------------------------------------------------------
177 // wxCalendarCtrlBase
178 // ----------------------------------------------------------------------------
180 class WXDLLIMPEXP_ADV wxCalendarCtrlBase
: public wxControl
183 // do we allow changing the month/year?
184 bool AllowMonthChange() const { return !HasFlag(wxCAL_NO_MONTH_CHANGE
); }
186 // get/set the current date
187 virtual wxDateTime
GetDate() const = 0;
188 virtual bool SetDate(const wxDateTime
& date
) = 0;
191 // restricting the dates shown by the control to the specified range: only
192 // implemented in the generic and MSW versions for now
194 // if either date is set, the corresponding limit will be enforced and true
195 // returned; if none are set, the existing restrictions are removed and
198 SetDateRange(const wxDateTime
& WXUNUSED(lowerdate
) = wxDefaultDateTime
,
199 const wxDateTime
& WXUNUSED(upperdate
) = wxDefaultDateTime
)
204 // retrieves the limits currently in use (wxDefaultDateTime if none) in the
205 // provided pointers (which may be NULL) and returns true if there are any
206 // limits or false if none
208 GetDateRange(wxDateTime
*lowerdate
, wxDateTime
*upperdate
) const
211 *lowerdate
= wxDefaultDateTime
;
213 *upperdate
= wxDefaultDateTime
;
217 // returns one of wxCAL_HITTEST_XXX constants and fills either date or wd
218 // with the corresponding value (none for NOWHERE, the date for DAY and wd
221 // notice that this is not implemented in all versions
222 virtual wxCalendarHitTestResult
223 HitTest(const wxPoint
& WXUNUSED(pos
),
224 wxDateTime
* WXUNUSED(date
) = NULL
,
225 wxDateTime::WeekDay
* WXUNUSED(wd
) = NULL
)
227 return wxCAL_HITTEST_NOWHERE
;
230 // allow or disable changing the current month (and year), return true if
231 // the value of this option really changed or false if it was already set
232 // to the required value
234 // NB: we provide implementation for this pure virtual function, derived
235 // classes should call it
236 virtual bool EnableMonthChange(bool enable
) = 0;
239 // an item without custom attributes is drawn with the default colours and
240 // font and without border, setting custom attributes allows to modify this
242 // the day parameter should be in 1..31 range, for days 29, 30, 31 the
243 // corresponding attribute is just unused if there is no such day in the
246 // notice that currently arbitrary attributes are supported only in the
247 // generic version, the native controls only support Mark() which assigns
248 // some special appearance (which can be customized using SetMark() for the
249 // generic version) to the given day
251 virtual void Mark(size_t day
, bool mark
) = 0;
253 virtual wxCalendarDateAttr
*GetAttr(size_t WXUNUSED(day
)) const
255 virtual void SetAttr(size_t WXUNUSED(day
), wxCalendarDateAttr
*attr
)
257 virtual void ResetAttr(size_t WXUNUSED(day
)) { }
262 // currently all functions in this section are implemented in the generic
263 // version of the control only and are simply ignored by native ones
265 // equivalent to changing wxCAL_SHOW_HOLIDAYS flag but should be called
266 // instead of just changing it
267 virtual void EnableHolidayDisplay(bool WXUNUSED(display
) = true) { }
269 // set/get the colours to use for holidays (if they're enabled)
270 virtual void SetHolidayColours(const wxColour
& WXUNUSED(colFg
),
271 const wxColour
& WXUNUSED(colBg
)) { }
273 virtual const wxColour
& GetHolidayColourFg() const { return wxNullColour
; }
274 virtual const wxColour
& GetHolidayColourBg() const { return wxNullColour
; }
276 // mark the given day of the current month as being a holiday
277 virtual void SetHoliday(size_t WXUNUSED(day
)) { }
280 // customizing the colours of the controls
282 // most of the methods in this section are only implemented by the native
283 // version of the control and do nothing in the native ones
285 // set/get the colours to use for the display of the week day names at the
286 // top of the controls
287 virtual void SetHeaderColours(const wxColour
& WXUNUSED(colFg
),
288 const wxColour
& WXUNUSED(colBg
)) { }
290 virtual const wxColour
& GetHeaderColourFg() const { return wxNullColour
; }
291 virtual const wxColour
& GetHeaderColourBg() const { return wxNullColour
; }
293 // set/get the colours used for the currently selected date
294 virtual void SetHighlightColours(const wxColour
& WXUNUSED(colFg
),
295 const wxColour
& WXUNUSED(colBg
)) { }
297 virtual const wxColour
& GetHighlightColourFg() const { return wxNullColour
; }
298 virtual const wxColour
& GetHighlightColourBg() const { return wxNullColour
; }
301 // implementation only from now on
303 // generate the given calendar event, return true if it was processed
305 // NB: this is public because it's used from GTK+ callbacks
306 bool GenerateEvent(wxEventType type
)
308 wxCalendarEvent
event(this, GetDate(), type
);
309 return HandleWindowEvent(event
);
313 // generate all the events for the selection change from dateOld to current
314 // date: SEL_CHANGED, PAGE_CHANGED if necessary and also one of (deprecated)
315 // YEAR/MONTH/DAY_CHANGED ones
316 void GenerateAllChangeEvents(const wxDateTime
& dateOld
);
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 #define wxCalendarNameStr "CalendarCtrl"
325 #ifndef __WXUNIVERSAL__
326 #if defined(__WXGTK20__)
327 #define wxHAS_NATIVE_CALENDARCTRL
328 #include "wx/gtk/calctrl.h"
329 #define wxCalendarCtrl wxGtkCalendarCtrl
330 #elif defined(__WXMSW__)
331 #define wxHAS_NATIVE_CALENDARCTRL
332 #include "wx/msw/calctrl.h"
334 #endif // !__WXUNIVERSAL__
336 #ifndef wxHAS_NATIVE_CALENDARCTRL
337 #include "wx/generic/calctrlg.h"
338 #define wxCalendarCtrl wxGenericCalendarCtrl
341 // ----------------------------------------------------------------------------
342 // calendar event types and macros for handling them
343 // ----------------------------------------------------------------------------
345 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_SEL_CHANGED
;
346 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_PAGE_CHANGED
;
347 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_DOUBLECLICKED
;
348 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED
;
351 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_DAY_CHANGED
;
352 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_MONTH_CHANGED
;
353 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_CALENDAR_YEAR_CHANGED
;
355 typedef void (wxEvtHandler::*wxCalendarEventFunction
)(wxCalendarEvent
&);
357 #define wxCalendarEventHandler(func) \
358 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCalendarEventFunction, &func)
360 #define wx__DECLARE_CALEVT(evt, id, fn) \
361 wx__DECLARE_EVT1(wxEVT_CALENDAR_ ## evt, id, wxCalendarEventHandler(fn))
363 #define EVT_CALENDAR(id, fn) wx__DECLARE_CALEVT(DOUBLECLICKED, id, fn)
364 #define EVT_CALENDAR_SEL_CHANGED(id, fn) wx__DECLARE_CALEVT(SEL_CHANGED, id, fn)
365 #define EVT_CALENDAR_PAGE_CHANGED(id, fn) wx__DECLARE_CALEVT(PAGE_CHANGED, id, fn)
366 #define EVT_CALENDAR_WEEKDAY_CLICKED(id, fn) wx__DECLARE_CALEVT(WEEKDAY_CLICKED, id, fn)
369 #define EVT_CALENDAR_DAY(id, fn) wx__DECLARE_CALEVT(DAY_CHANGED, id, fn)
370 #define EVT_CALENDAR_MONTH(id, fn) wx__DECLARE_CALEVT(MONTH_CHANGED, id, fn)
371 #define EVT_CALENDAR_YEAR(id, fn) wx__DECLARE_CALEVT(YEAR_CHANGED, id, fn)
373 #endif // wxUSE_CALENDARCTRL
375 #endif // _WX_CALCTRL_H_