1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxCalendarCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxCalendarEvent
12 The wxCalendarEvent class is used together with wxCalendarCtrl.
19 class wxCalendarEvent
: public wxDateEvent
23 Returns the week day on which the user clicked in
24 @c EVT_CALENDAR_WEEKDAY_CLICKED handler. It doesn't make sense to call
25 this function in other handlers.
27 wxDateTime::WeekDay
GetWeekDay() const;
30 Sets the week day carried by the event, normally only used by the
33 void SetWeekDay(const wxDateTime::WeekDay day
);
39 Possible kinds of borders which may be used to decorate a date using
42 enum wxCalendarDateBorder
44 wxCAL_BORDER_NONE
, ///< No Border (Default)
45 wxCAL_BORDER_SQUARE
, ///< Rectangular Border
46 wxCAL_BORDER_ROUND
///< Round Border
50 @class wxCalendarDateAttr
52 wxCalendarDateAttr is a custom attributes for a calendar date. The objects
53 of this class are used with wxCalendarCtrl.
60 class wxCalendarDateAttr
64 Constructor for specifying all wxCalendarDateAttr properties.
66 wxCalendarDateAttr(const wxColour
& colText
= wxNullColour
,
67 const wxColour
& colBack
= wxNullColour
,
68 const wxColour
& colBorder
= wxNullColour
,
69 const wxFont
& font
= wxNullFont
,
70 wxCalendarDateBorder border
= wxCAL_BORDER_NONE
);
73 Constructor using default properties except the given border.
75 wxCalendarDateAttr(wxCalendarDateBorder border
,
76 const wxColour
& colBorder
= wxNullColour
);
79 Returns the background colour set for the calendar date.
81 const wxColour
& GetBackgroundColour() const;
84 Returns the border set for the calendar date.
86 wxCalendarDateBorder
GetBorder() const;
89 Returns the border colour set for the calendar date.
91 const wxColour
& GetBorderColour() const;
94 Returns the font set for the calendar date.
96 const wxFont
& GetFont() const;
99 Returns the text colour set for the calendar date.
101 const wxColour
& GetTextColour() const;
104 Returns @true if a non-default text background colour is set.
106 bool HasBackgroundColour() const;
109 Returns @true if a non-default (i.e. any) border is set.
111 bool HasBorder() const;
114 Returns @true if a non-default border colour is set.
116 bool HasBorderColour() const;
119 Returns @true if a non-default font is set.
121 bool HasFont() const;
124 Returns @true if a non-default text foreground colour is set.
126 bool HasTextColour() const;
129 Returns @true if this calendar day is displayed as a holiday.
131 bool IsHoliday() const;
134 Sets the text background colour to use.
136 void SetBackgroundColour(const wxColour
& colBack
);
139 Sets the border to use.
141 void SetBorder(wxCalendarDateBorder border
);
144 Sets the border colour to use.
146 void SetBorderColour(const wxColour
& col
);
149 Sets the font to use.
151 void SetFont(const wxFont
& font
);
154 If @a holiday is @true, this calendar day will be displayed as a
157 void SetHoliday(bool holiday
);
160 Sets the text (foreground) colour to use.
162 void SetTextColour(const wxColour
& colText
);
165 Used (internally) by the generic wxCalendarCtrl::Mark().
167 static const wxCalendarDateAttr
& GetMark();
170 Set the attributes that will be used to Mark() days on the generic
173 static void SetMark(wxCalendarDateAttr
const& m
);
179 Possible return values from wxCalendarCtrl::HitTest().
181 enum wxCalendarHitTestResult
183 wxCAL_HITTEST_NOWHERE
, ///< Hit outside of anything.
184 wxCAL_HITTEST_HEADER
, ///< Hit on the header (weekdays).
185 wxCAL_HITTEST_DAY
, ///< Hit on a day in the calendar.
186 wxCAL_HITTEST_INCMONTH
, ///< Hit on next month arrow (in alternate month selector mode).
187 wxCAL_HITTEST_DECMONTH
, ///< Hit on previous month arrow (in alternate month selector mode).
188 wxCAL_HITTEST_SURROUNDING_WEEK
, ///< Hit on surrounding week of previous/next month (if shown).
189 wxCAL_HITTEST_WEEK
///< Hit on week of the year number (if shown).
193 @class wxCalendarCtrl
195 The calendar control allows the user to pick a date. The user can move the
196 current selection using the keyboard and select the date (generating
197 @c EVT_CALENDAR event) by pressing @c @<Return@> or double clicking it.
199 Generic calendar has advanced possibilities for the customization of its
200 display, described below. If you want to use these possibilities on every
201 platform, use wxGenericCalendarCtrl instead of wxCalendarCtrl.
203 All global settings (such as colours and fonts used) can, of course, be
204 changed. But also, the display style for each day in the month can be set
205 independently using wxCalendarDateAttr class.
207 An item without custom attributes is drawn with the default colours and
208 font and without border, but setting custom attributes with SetAttr()
209 allows to modify its appearance. Just create a custom attribute object and
210 set it for the day you want to be displayed specially (note that the
211 control will take ownership of the pointer, i.e. it will delete it itself).
212 A day may be marked as being a holiday, even if it is not recognized as
213 one by wxDateTime using the wxCalendarDateAttr::SetHoliday() method.
215 As the attributes are specified for each day, they may change when the
216 month is changed, so you will often want to update them in
217 @c EVT_CALENDAR_PAGE_CHANGED event handler.
220 @style{wxCAL_SUNDAY_FIRST}
221 Show Sunday as the first day in the week (not in wxGTK)
222 @style{wxCAL_MONDAY_FIRST}
223 Show Monday as the first day in the week (not in wxGTK)
224 @style{wxCAL_SHOW_HOLIDAYS}
225 Highlight holidays in the calendar (only generic)
226 @style{wxCAL_NO_YEAR_CHANGE}
227 Disable the year changing (deprecated, only generic)
228 @style{wxCAL_NO_MONTH_CHANGE}
229 Disable the month (and, implicitly, the year) changing
230 @style{wxCAL_SHOW_SURROUNDING_WEEKS}
231 Show the neighbouring weeks in the previous and next months
232 (only generic, always on for the native controls)
233 @style{wxCAL_SEQUENTIAL_MONTH_SELECTION}
234 Use alternative, more compact, style for the month and year
235 selection controls. (only generic)
236 @style{wxCAL_SHOW_WEEK_NUMBERS}
237 Show week numbers on the left side of the calendar. (not in generic)
240 @beginEventEmissionTable{wxCalendarEvent}
241 @event{EVT_CALENDAR(id, func)}
242 A day was double clicked in the calendar.
243 @event{EVT_CALENDAR_SEL_CHANGED(id, func)}
244 The selected date changed.
245 @event{EVT_CALENDAR_PAGE_CHANGED(id, func)}
246 The selected month (and/or year) changed.
247 @event{EVT_CALENDAR_WEEKDAY_CLICKED(id, func)}
248 User clicked on the week day header (only generic).
249 @event{EVT_CALENDAR_WEEK_CLICKED(id, func)}
250 User clicked on the week of the year number (only generic).
253 @note Changing the selected date will trigger an EVT_CALENDAR_DAY, MONTH or
254 YEAR event as well as an EVT_CALENDAR_SEL_CHANGED event.
258 @appearance{calendarctrl.png}
260 @nativeimpl{wxgtk,wxmsw}
262 @see @ref page_samples_calendar, wxCalendarDateAttr, wxCalendarEvent,
265 class wxCalendarCtrl
: public wxControl
274 Does the same as Create() method.
276 wxCalendarCtrl(wxWindow
* parent
, wxWindowID id
,
277 const wxDateTime
& date
= wxDefaultDateTime
,
278 const wxPoint
& pos
= wxDefaultPosition
,
279 const wxSize
& size
= wxDefaultSize
,
280 long style
= wxCAL_SHOW_HOLIDAYS
,
281 const wxString
& name
= wxCalendarNameStr
);
284 Destroys the control.
289 Creates the control. See wxWindow::wxWindow() for the meaning of the
290 parameters and the control overview for the possible styles.
292 bool Create(wxWindow
* parent
, wxWindowID id
,
293 const wxDateTime
& date
= wxDefaultDateTime
,
294 const wxPoint
& pos
= wxDefaultPosition
,
295 const wxSize
& size
= wxDefaultSize
,
296 long style
= wxCAL_SHOW_HOLIDAYS
,
297 const wxString
& name
= wxCalendarNameStr
);
300 This function should be used instead of changing @c wxCAL_SHOW_HOLIDAYS
301 style bit directly. It enables or disables the special highlighting of
304 virtual void EnableHolidayDisplay(bool display
= true);
307 This function should be used instead of changing
308 @c wxCAL_NO_MONTH_CHANGE style bit. It allows or disallows the user to
309 change the month interactively. Note that if the month cannot be
310 changed, the year cannot be changed neither.
312 @return @true if the value of this option really changed or @false if
313 it was already set to the requested value.
315 virtual bool EnableMonthChange(bool enable
= true);
320 This function should be used instead of changing
321 @c wxCAL_NO_YEAR_CHANGE style bit directly. It allows or disallows the
322 user to change the year interactively. Only in generic wxCalendarCtrl.
324 virtual void EnableYearChange(bool enable
= true);
327 Returns the attribute for the given date (should be in the range
328 1...31). The returned pointer may be @NULL. Only in generic
331 virtual wxCalendarDateAttr
* GetAttr(size_t day
) const;
334 Gets the currently selected date.
336 virtual wxDateTime
GetDate() const;
339 Gets the background colour of the header part of the calendar window.
341 This method is currently only implemented in generic wxCalendarCtrl and
342 always returns @c wxNullColour in the native versions.
344 @see SetHeaderColours()
346 virtual const wxColour
& GetHeaderColourBg() const;
349 Gets the foreground colour of the header part of the calendar window.
351 This method is currently only implemented in generic wxCalendarCtrl and
352 always returns @c wxNullColour in the native versions.
354 @see SetHeaderColours()
356 virtual const wxColour
& GetHeaderColourFg() const;
359 Gets the background highlight colour. Only in generic wxCalendarCtrl.
361 This method is currently only implemented in generic wxCalendarCtrl and
362 always returns @c wxNullColour in the native versions.
364 @see SetHighlightColours()
366 virtual const wxColour
& GetHighlightColourBg() const;
369 Gets the foreground highlight colour. Only in generic wxCalendarCtrl.
371 This method is currently only implemented in generic wxCalendarCtrl and
372 always returns @c wxNullColour in the native versions.
374 @see SetHighlightColours()
376 virtual const wxColour
& GetHighlightColourFg() const;
379 Return the background colour currently used for holiday highlighting.
381 Only useful with generic wxCalendarCtrl as native versions currently
382 don't support holidays display at all and always return
385 @see SetHolidayColours()
387 virtual const wxColour
& GetHolidayColourBg() const;
390 Return the foreground colour currently used for holiday highlighting.
392 Only useful with generic wxCalendarCtrl as native versions currently
393 don't support holidays display at all and always return
396 @see SetHolidayColours()
398 virtual const wxColour
& GetHolidayColourFg() const;
401 Returns one of wxCalendarHitTestResult constants and fills either
402 @a date or @a wd pointer with the corresponding value depending on the
405 Not implemented in wxGTK currently.
407 virtual wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
408 wxDateTime
* date
= NULL
,
409 wxDateTime::WeekDay
* wd
= NULL
);
412 Clears any attributes associated with the given day (in the range
413 1...31). Only in generic wxCalendarCtrl.
415 virtual void ResetAttr(size_t day
);
418 Associates the attribute with the specified date (in the range 1...31).
419 If the pointer is @NULL, the items attribute is cleared. Only in
420 generic wxCalendarCtrl.
422 virtual void SetAttr(size_t day
, wxCalendarDateAttr
* attr
);
425 Sets the current date.
427 The @a date parameter must be valid.
429 virtual bool SetDate(const wxDateTime
& date
);
432 Set the colours used for painting the weekdays at the top of the
435 This method is currently only implemented in generic wxCalendarCtrl and
436 does nothing in the native versions.
438 virtual void SetHeaderColours(const wxColour
& colFg
,
439 const wxColour
& colBg
);
442 Set the colours to be used for highlighting the currently selected
445 This method is currently only implemented in generic wxCalendarCtrl and
446 does nothing in the native versions.
448 virtual void SetHighlightColours(const wxColour
& colFg
,
449 const wxColour
& colBg
);
452 Marks the specified day as being a holiday in the current month.
454 This method is only implemented in the generic version of the control
455 and does nothing in the native ones.
457 virtual void SetHoliday(size_t day
);
460 Sets the colours to be used for the holidays highlighting.
462 This method is only implemented in the generic version of the control
463 and does nothing in the native ones. It should also only be called if
464 the window style includes @c wxCAL_SHOW_HOLIDAYS flag or
465 EnableHolidayDisplay() had been called.
468 virtual void SetHolidayColours(const wxColour
& colFg
,
469 const wxColour
& colBg
);
472 Mark or unmark the day. This day of month will be marked in every
473 month. In generic wxCalendarCtrl,
475 virtual void Mark(size_t day
, bool mark
);
478 @name Date Range Functions
480 The functions in this section are currently implemented in the generic
481 and MSW versions and do nothing in the native GTK implementation.
486 Restrict the dates shown by the control to the specified range.
488 If either date is set, the corresponding limit will be enforced and
489 @true returned. If none are set, the existing restrictions are removed
490 and @false is returned.
495 The low limit for the dates shown by the control or
498 The high limit for the dates shown by the control or
501 @true if either limit is valid, @false otherwise
503 virtual bool SetDateRange(const wxDateTime
& lowerdate
= wxDefaultDateTime
,
504 const wxDateTime
& upperdate
= wxDefaultDateTime
);
507 Returns the limits currently being used.
512 If non-@NULL, the value of the low limit for the dates shown by the
513 control is returned (which may be ::wxDefaultDateTime if no limit
516 If non-@NULL, the value of the upper limit for the dates shown by
517 the control is returned (which may be ::wxDefaultDateTime if no
520 @true if either limit is set, @false otherwise
522 virtual bool GetDateRange(wxDateTime
*lowerdate
,
523 wxDateTime
*upperdate
) const;