1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxCalendarCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
11 // show Sunday as the first day of the week (default)
12 wxCAL_SUNDAY_FIRST
= 0x0000,
14 // show Monday as the first day of the week
15 wxCAL_MONDAY_FIRST
= 0x0001,
18 wxCAL_SHOW_HOLIDAYS
= 0x0002,
20 // disable the year change control, show only the month change one
22 wxCAL_NO_YEAR_CHANGE
= 0x0004,
24 // don't allow changing neither month nor year (implies
25 // wxCAL_NO_YEAR_CHANGE)
26 wxCAL_NO_MONTH_CHANGE
= 0x000c,
28 // use MS-style month-selection instead of combo-spin combination
29 wxCAL_SEQUENTIAL_MONTH_SELECTION
= 0x0010,
31 // show the neighbouring weeks in the previous and next month
32 wxCAL_SHOW_SURROUNDING_WEEKS
= 0x0020,
34 // show week numbers on the left side of the calendar.
35 wxCAL_SHOW_WEEK_NUMBERS
= 0x0040
40 @class wxCalendarEvent
42 The wxCalendarEvent class is used together with wxCalendarCtrl.
49 class wxCalendarEvent
: public wxDateEvent
53 wxCalendarEvent(wxWindow
*win
, const wxDateTime
& dt
, wxEventType type
);
56 Returns the week day on which the user clicked in
57 @c EVT_CALENDAR_WEEKDAY_CLICKED handler. It doesn't make sense to call
58 this function in other handlers.
60 wxDateTime::WeekDay
GetWeekDay() const;
63 Sets the week day carried by the event, normally only used by the
66 void SetWeekDay(const wxDateTime::WeekDay day
);
69 wxEventType wxEVT_CALENDAR_SEL_CHANGED
;
70 wxEventType wxEVT_CALENDAR_PAGE_CHANGED
;
71 wxEventType wxEVT_CALENDAR_DOUBLECLICKED
;
72 wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED
;
73 wxEventType wxEVT_CALENDAR_WEEK_CLICKED
;
78 Possible kinds of borders which may be used to decorate a date using
81 enum wxCalendarDateBorder
83 wxCAL_BORDER_NONE
, ///< No Border (Default)
84 wxCAL_BORDER_SQUARE
, ///< Rectangular Border
85 wxCAL_BORDER_ROUND
///< Round Border
89 @class wxCalendarDateAttr
91 wxCalendarDateAttr is a custom attributes for a calendar date. The objects
92 of this class are used with wxCalendarCtrl.
99 class wxCalendarDateAttr
103 Constructor for specifying all wxCalendarDateAttr properties.
105 wxCalendarDateAttr(const wxColour
& colText
= wxNullColour
,
106 const wxColour
& colBack
= wxNullColour
,
107 const wxColour
& colBorder
= wxNullColour
,
108 const wxFont
& font
= wxNullFont
,
109 wxCalendarDateBorder border
= wxCAL_BORDER_NONE
);
112 Constructor using default properties except the given border.
114 wxCalendarDateAttr(wxCalendarDateBorder border
,
115 const wxColour
& colBorder
= wxNullColour
);
118 Returns the background colour set for the calendar date.
120 const wxColour
& GetBackgroundColour() const;
123 Returns the border set for the calendar date.
125 wxCalendarDateBorder
GetBorder() const;
128 Returns the border colour set for the calendar date.
130 const wxColour
& GetBorderColour() const;
133 Returns the font set for the calendar date.
135 const wxFont
& GetFont() const;
138 Returns the text colour set for the calendar date.
140 const wxColour
& GetTextColour() const;
143 Returns @true if a non-default text background colour is set.
145 bool HasBackgroundColour() const;
148 Returns @true if a non-default (i.e.\ any) border is set.
150 bool HasBorder() const;
153 Returns @true if a non-default border colour is set.
155 bool HasBorderColour() const;
158 Returns @true if a non-default font is set.
160 bool HasFont() const;
163 Returns @true if a non-default text foreground colour is set.
165 bool HasTextColour() const;
168 Returns @true if this calendar day is displayed as a holiday.
170 bool IsHoliday() const;
173 Sets the text background colour to use.
175 void SetBackgroundColour(const wxColour
& colBack
);
178 Sets the border to use.
180 void SetBorder(wxCalendarDateBorder border
);
183 Sets the border colour to use.
185 void SetBorderColour(const wxColour
& col
);
188 Sets the font to use.
190 void SetFont(const wxFont
& font
);
193 If @a holiday is @true, this calendar day will be displayed as a
196 void SetHoliday(bool holiday
);
199 Sets the text (foreground) colour to use.
201 void SetTextColour(const wxColour
& colText
);
204 Used (internally) by the generic wxCalendarCtrl::Mark().
206 static const wxCalendarDateAttr
& GetMark();
209 Set the attributes that will be used to Mark() days on the generic
212 static void SetMark(const wxCalendarDateAttr
& m
);
218 Possible return values from wxCalendarCtrl::HitTest().
220 enum wxCalendarHitTestResult
222 wxCAL_HITTEST_NOWHERE
, ///< Hit outside of anything.
223 wxCAL_HITTEST_HEADER
, ///< Hit on the header (weekdays).
224 wxCAL_HITTEST_DAY
, ///< Hit on a day in the calendar.
225 wxCAL_HITTEST_INCMONTH
, ///< Hit on next month arrow (in alternate month selector mode).
226 wxCAL_HITTEST_DECMONTH
, ///< Hit on previous month arrow (in alternate month selector mode).
227 wxCAL_HITTEST_SURROUNDING_WEEK
, ///< Hit on surrounding week of previous/next month (if shown).
228 wxCAL_HITTEST_WEEK
///< Hit on week of the year number (if shown).
232 @class wxCalendarCtrl
234 The calendar control allows the user to pick a date. The user can move the
235 current selection using the keyboard and select the date (generating
236 @c EVT_CALENDAR event) by pressing @c @<Return@> or double clicking it.
238 Generic calendar has advanced possibilities for the customization of its
239 display, described below. If you want to use these possibilities on every
240 platform, use wxGenericCalendarCtrl instead of wxCalendarCtrl.
242 All global settings (such as colours and fonts used) can, of course, be
243 changed. But also, the display style for each day in the month can be set
244 independently using wxCalendarDateAttr class.
246 An item without custom attributes is drawn with the default colours and
247 font and without border, but setting custom attributes with SetAttr()
248 allows to modify its appearance. Just create a custom attribute object and
249 set it for the day you want to be displayed specially (note that the
250 control will take ownership of the pointer, i.e. it will delete it itself).
251 A day may be marked as being a holiday, even if it is not recognized as
252 one by wxDateTime using the wxCalendarDateAttr::SetHoliday() method.
254 As the attributes are specified for each day, they may change when the
255 month is changed, so you will often want to update them in
256 @c EVT_CALENDAR_PAGE_CHANGED event handler.
259 @style{wxCAL_SUNDAY_FIRST}
260 Show Sunday as the first day in the week (not in wxGTK)
261 @style{wxCAL_MONDAY_FIRST}
262 Show Monday as the first day in the week (not in wxGTK)
263 @style{wxCAL_SHOW_HOLIDAYS}
264 Highlight holidays in the calendar (only generic)
265 @style{wxCAL_NO_YEAR_CHANGE}
266 Disable the year changing (deprecated, only generic)
267 @style{wxCAL_NO_MONTH_CHANGE}
268 Disable the month (and, implicitly, the year) changing
269 @style{wxCAL_SHOW_SURROUNDING_WEEKS}
270 Show the neighbouring weeks in the previous and next months
271 (only generic, always on for the native controls)
272 @style{wxCAL_SEQUENTIAL_MONTH_SELECTION}
273 Use alternative, more compact, style for the month and year
274 selection controls. (only generic)
275 @style{wxCAL_SHOW_WEEK_NUMBERS}
276 Show week numbers on the left side of the calendar. (not in generic)
279 @beginEventEmissionTable{wxCalendarEvent}
280 @event{EVT_CALENDAR(id, func)}
281 A day was double clicked in the calendar.
282 @event{EVT_CALENDAR_SEL_CHANGED(id, func)}
283 The selected date changed.
284 @event{EVT_CALENDAR_PAGE_CHANGED(id, func)}
285 The selected month (and/or year) changed.
286 @event{EVT_CALENDAR_WEEKDAY_CLICKED(id, func)}
287 User clicked on the week day header (only generic).
288 @event{EVT_CALENDAR_WEEK_CLICKED(id, func)}
289 User clicked on the week of the year number (only generic).
292 @note Changing the selected date will trigger an EVT_CALENDAR_DAY, MONTH or
293 YEAR event as well as an EVT_CALENDAR_SEL_CHANGED event.
297 @appearance{calendarctrl}
299 @nativeimpl{wxgtk,wxmsw}
301 @see @ref page_samples_calendar, wxCalendarDateAttr, wxCalendarEvent,
304 class wxCalendarCtrl
: public wxControl
313 Does the same as Create() method.
315 wxCalendarCtrl(wxWindow
* parent
, wxWindowID id
,
316 const wxDateTime
& date
= wxDefaultDateTime
,
317 const wxPoint
& pos
= wxDefaultPosition
,
318 const wxSize
& size
= wxDefaultSize
,
319 long style
= wxCAL_SHOW_HOLIDAYS
,
320 const wxString
& name
= wxCalendarNameStr
);
323 Destroys the control.
328 Creates the control. See wxWindow::wxWindow() for the meaning of the
329 parameters and the control overview for the possible styles.
331 bool Create(wxWindow
* parent
, wxWindowID id
,
332 const wxDateTime
& date
= wxDefaultDateTime
,
333 const wxPoint
& pos
= wxDefaultPosition
,
334 const wxSize
& size
= wxDefaultSize
,
335 long style
= wxCAL_SHOW_HOLIDAYS
,
336 const wxString
& name
= wxCalendarNameStr
);
339 This function should be used instead of changing @c wxCAL_SHOW_HOLIDAYS
340 style bit directly. It enables or disables the special highlighting of
343 virtual void EnableHolidayDisplay(bool display
= true);
346 This function should be used instead of changing
347 @c wxCAL_NO_MONTH_CHANGE style bit. It allows or disallows the user to
348 change the month interactively. Note that if the month cannot be
349 changed, the year cannot be changed neither.
351 @return @true if the value of this option really changed or @false if
352 it was already set to the requested value.
354 virtual bool EnableMonthChange(bool enable
= true);
359 This function should be used instead of changing
360 @c wxCAL_NO_YEAR_CHANGE style bit directly. It allows or disallows the
361 user to change the year interactively. Only in generic wxCalendarCtrl.
363 virtual void EnableYearChange(bool enable
= true);
366 Returns the attribute for the given date (should be in the range
367 1...31). The returned pointer may be @NULL. Only in generic
370 virtual wxCalendarDateAttr
* GetAttr(size_t day
) const;
373 Gets the currently selected date.
375 virtual wxDateTime
GetDate() const;
378 Gets the background colour of the header part of the calendar window.
380 This method is currently only implemented in generic wxCalendarCtrl and
381 always returns @c wxNullColour in the native versions.
383 @see SetHeaderColours()
385 virtual const wxColour
& GetHeaderColourBg() const;
388 Gets the foreground colour of the header part of the calendar window.
390 This method is currently only implemented in generic wxCalendarCtrl and
391 always returns @c wxNullColour in the native versions.
393 @see SetHeaderColours()
395 virtual const wxColour
& GetHeaderColourFg() const;
398 Gets the background highlight colour. Only in generic wxCalendarCtrl.
400 This method is currently only implemented in generic wxCalendarCtrl and
401 always returns @c wxNullColour in the native versions.
403 @see SetHighlightColours()
405 virtual const wxColour
& GetHighlightColourBg() const;
408 Gets the foreground highlight colour. Only in generic wxCalendarCtrl.
410 This method is currently only implemented in generic wxCalendarCtrl and
411 always returns @c wxNullColour in the native versions.
413 @see SetHighlightColours()
415 virtual const wxColour
& GetHighlightColourFg() const;
418 Return the background colour currently used for holiday highlighting.
420 Only useful with generic wxCalendarCtrl as native versions currently
421 don't support holidays display at all and always return
424 @see SetHolidayColours()
426 virtual const wxColour
& GetHolidayColourBg() const;
429 Return the foreground colour currently used for holiday highlighting.
431 Only useful with generic wxCalendarCtrl as native versions currently
432 don't support holidays display at all and always return
435 @see SetHolidayColours()
437 virtual const wxColour
& GetHolidayColourFg() const;
440 Returns one of wxCalendarHitTestResult constants and fills either
441 @a date or @a wd pointer with the corresponding value depending on the
444 Not implemented in wxGTK currently.
446 virtual wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
447 wxDateTime
* date
= NULL
,
448 wxDateTime::WeekDay
* wd
= NULL
);
451 Clears any attributes associated with the given day (in the range
452 1...31). Only in generic wxCalendarCtrl.
454 virtual void ResetAttr(size_t day
);
457 Associates the attribute with the specified date (in the range 1...31).
458 If the pointer is @NULL, the items attribute is cleared. Only in
459 generic wxCalendarCtrl.
461 virtual void SetAttr(size_t day
, wxCalendarDateAttr
* attr
);
464 Sets the current date.
466 The @a date parameter must be valid and in the currently valid range as
467 set by SetDateRange(), otherwise the current date is not changed and
468 the function returns @false.
470 virtual bool SetDate(const wxDateTime
& date
);
473 Set the colours used for painting the weekdays at the top of the
476 This method is currently only implemented in generic wxCalendarCtrl and
477 does nothing in the native versions.
479 virtual void SetHeaderColours(const wxColour
& colFg
,
480 const wxColour
& colBg
);
483 Set the colours to be used for highlighting the currently selected
486 This method is currently only implemented in generic wxCalendarCtrl and
487 does nothing in the native versions.
489 virtual void SetHighlightColours(const wxColour
& colFg
,
490 const wxColour
& colBg
);
493 Marks the specified day as being a holiday in the current month.
495 This method is only implemented in the generic version of the control
496 and does nothing in the native ones.
498 virtual void SetHoliday(size_t day
);
501 Sets the colours to be used for the holidays highlighting.
503 This method is only implemented in the generic version of the control
504 and does nothing in the native ones. It should also only be called if
505 the window style includes @c wxCAL_SHOW_HOLIDAYS flag or
506 EnableHolidayDisplay() had been called.
509 virtual void SetHolidayColours(const wxColour
& colFg
,
510 const wxColour
& colBg
);
513 Mark or unmark the day. This day of month will be marked in every
514 month. In generic wxCalendarCtrl,
516 virtual void Mark(size_t day
, bool mark
);
519 @name Date Range Functions
524 Restrict the dates that can be selected in the control to the specified
527 If either date is set, the corresponding limit will be enforced and
528 @true returned. If none are set, the existing restrictions are removed
529 and @false is returned.
534 The low limit for the dates shown by the control or
537 The high limit for the dates shown by the control or
540 @true if either limit is valid, @false otherwise
542 virtual bool SetDateRange(const wxDateTime
& lowerdate
= wxDefaultDateTime
,
543 const wxDateTime
& upperdate
= wxDefaultDateTime
);
546 Returns the limits currently being used.
551 If non-@NULL, the value of the low limit for the dates shown by the
552 control is returned (which may be ::wxDefaultDateTime if no limit
555 If non-@NULL, the value of the upper limit for the dates shown by
556 the control is returned (which may be ::wxDefaultDateTime if no
559 @true if either limit is set, @false otherwise
561 virtual bool GetDateRange(wxDateTime
*lowerdate
,
562 wxDateTime
*upperdate
) const;