1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxCalendarCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows license
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(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
69 Constructor for specifying all wxCalendarDateAttr properties.
71 wxCalendarDateAttr(const wxColour
& colText
,
72 const wxColour
& colBack
= wxNullColour
,
73 const wxColour
& colBorder
= wxNullColour
,
74 const wxFont
& font
= wxNullFont
,
75 wxCalendarDateBorder border
= wxCAL_BORDER_NONE
);
78 Constructor using default properties except the given border.
80 wxCalendarDateAttr(wxCalendarDateBorder border
,
81 const wxColour
& colBorder
= wxNullColour
);
84 Returns the background colour set for the calendar date.
86 const wxColour
GetBackgroundColour() const;
89 Returns the border set for the calendar date.
91 wxCalendarDateBorder
GetBorder() const;
94 Returns the border colour set for the calendar date.
96 const wxColour
GetBorderColour() const;
99 Returns the font set for the calendar date.
101 const wxFont
GetFont() const;
104 Returns the text colour set for the calendar date.
106 const wxColour
GetTextColour() const;
109 Returns @true if a non-default text background colour is set.
111 bool HasBackgroundColour() const;
114 Returns @true if a non-default (i.e. any) border is set.
116 bool HasBorder() const;
119 Returns @true if a non-default border colour is set.
121 bool HasBorderColour() const;
124 Returns @true if a non-default font is set.
126 bool HasFont() const;
129 Returns @true if a non-default text foreground colour is set.
131 bool HasTextColour() const;
134 Returns @true if this calendar day is displayed as a holiday.
136 bool IsHoliday() const;
139 Sets the text background colour to use.
141 void SetBackgroundColour(const wxColour
& colBack
);
144 Sets the border to use.
146 void SetBorder(wxCalendarDateBorder border
);
149 Sets the border colour to use.
151 void SetBorderColour(const wxColour
& col
);
154 Sets the font to use.
156 void SetFont(const wxFont
& font
);
159 If @a holiday is @true, this calendar day will be displayed as a
162 void SetHoliday(bool holiday
);
165 Sets the text (foreground) colour to use.
167 void SetTextColour(const wxColour
& colText
);
170 Used (internally) by the generic wxCalendarCtrl::Mark().
172 static const wxCalendarDateAttr
& GetMark();
175 Set the attributes that will be used to Mark() days on the generic
178 static void SetMark(wxCalendarDateAttr
const& m
);
184 Possible return values from wxCalendarCtrl::HitTest().
186 enum wxCalendarHitTestResult
188 wxCAL_HITTEST_NOWHERE
, ///< Hit outside of anything.
189 wxCAL_HITTEST_HEADER
, ///< Hit on the header (weekdays).
190 wxCAL_HITTEST_DAY
///< Hit on a day in the calendar.
194 @class wxCalendarCtrl
196 The calendar control allows the user to pick a date. The user can move the
197 current selection using the keyboard and select the date (generating
198 @c EVT_CALENDAR event) by pressing @c @<Return@> or double clicking it.
200 Generic calendar has advanced possibilities for the customization of its
201 display, described below. If you want to use these possibilities on every
202 platform, use wxGenericCalendarCtrl instead of wxCalendarCtrl.
204 All global settings (such as colours and fonts used) can, of course, be
205 changed. But also, the display style for each day in the month can be set
206 independently using wxCalendarDateAttr class.
208 An item without custom attributes is drawn with the default colours and
209 font and without border, but setting custom attributes with SetAttr()
210 allows to modify its appearance. Just create a custom attribute object and
211 set it for the day you want to be displayed specially (note that the
212 control will take ownership of the pointer, i.e. it will delete it itself).
213 A day may be marked as being a holiday, even if it is not recognized as
214 one by wxDateTime using the wxCalendarDateAttr::SetHoliday() method.
216 As the attributes are specified for each day, they may change when the
217 month is changed, so you will often want to update them in
218 @c EVT_CALENDAR_PAGE_CHANGED event handler.
221 @style{wxCAL_SUNDAY_FIRST}
222 Show Sunday as the first day in the week (not in wxGTK)
223 @style{wxCAL_MONDAY_FIRST}
224 Show Monday as the first day in the week (not in wxGTK)
225 @style{wxCAL_SHOW_HOLIDAYS}
226 Highlight holidays in the calendar (only generic)
227 @style{wxCAL_NO_YEAR_CHANGE}
228 Disable the year changing (deprecated, only generic)
229 @style{wxCAL_NO_MONTH_CHANGE}
230 Disable the month (and, implicitly, the year) changing
231 @style{wxCAL_SHOW_SURROUNDING_WEEKS}
232 Show the neighbouring weeks in the previous and next months
233 (only generic, always on for the native controls)
234 @style{wxCAL_SEQUENTIAL_MONTH_SELECTION}
235 Use alternative, more compact, style for the month and year
236 selection controls. (only generic)
237 @style{wxCAL_SHOW_WEEK_NUMBERS}
238 Show week numbers on the left side of the calendar. (not in generic)
241 @beginEventTable{wxCalendarEvent}
242 @event{EVT_CALENDAR(id, func)}
243 A day was double clicked in the calendar.
244 @event{EVT_CALENDAR_SEL_CHANGED(id, func)}
245 The selected date changed.
246 @event{EVT_CALENDAR_PAGE_CHANGED(id, func)}
247 The selected month (and/or year) changed.
248 @event{EVT_CALENDAR_WEEKDAY_CLICKED(id, func)}
249 User clicked on the week day header (only generic).
252 @note Changing the selected date will trigger an EVT_CALENDAR_DAY, MONTH or
253 YEAR event as well as an EVT_CALENDAR_SEL_CHANGED event.
257 <!-- @appearance{calendarctrl.png} -->
259 @nativeimpl{wxgtk,wxmsw}
261 @see @ref page_samples_calendar, wxCalendarDateAttr, wxCalendarEvent,
264 class wxCalendarCtrl
: public wxControl
273 Does the same as Create() method.
275 wxCalendarCtrl(wxWindow
* parent
, wxWindowID id
,
276 const wxDateTime
& date
= wxDefaultDateTime
,
277 const wxPoint
& pos
= wxDefaultPosition
,
278 const wxSize
& size
= wxDefaultSize
,
279 long style
= wxCAL_SHOW_HOLIDAYS
,
280 const wxString
& name
= wxCalendarNameStr
);
283 Destroys the control.
288 Creates the control. See wxWindow::wxWindow() for the meaning of the
289 parameters and the control overview for the possible styles.
291 bool Create(wxWindow
* parent
, wxWindowID id
,
292 const wxDateTime
& date
= wxDefaultDateTime
,
293 const wxPoint
& pos
= wxDefaultPosition
,
294 const wxSize
& size
= wxDefaultSize
,
295 long style
= wxCAL_SHOW_HOLIDAYS
,
296 const wxString
& name
= wxCalendarNameStr
);
299 This function should be used instead of changing @c wxCAL_SHOW_HOLIDAYS
300 style bit directly. It enables or disables the special highlighting of
303 void EnableHolidayDisplay(bool display
= true);
306 This function should be used instead of changing
307 @c wxCAL_NO_MONTH_CHANGE style bit. It allows or disallows the user to
308 change the month interactively. Note that if the month can not be
309 changed, the year can not be changed neither.
311 @return @true if the value of this option really changed or @false if
312 it was already set to the requested value.
314 bool EnableMonthChange(bool enable
= true);
319 This function should be used instead of changing
320 @c wxCAL_NO_YEAR_CHANGE style bit directly. It allows or disallows the
321 user to change the year interactively. Only in generic wxCalendarCtrl.
323 void EnableYearChange(bool enable
= true);
326 Returns the attribute for the given date (should be in the range
327 1...31). The returned pointer may be @NULL. Only in generic
330 wxCalendarDateAttr
* GetAttr(size_t day
) const;
333 Gets the currently selected date.
335 const wxDateTime
GetDate() const;
338 Gets the background colour of the header part of the calendar window.
340 This method is currently only implemented in generic wxCalendarCtrl and
341 always returns @c wxNullColour in the native versions.
343 @see SetHeaderColours()
345 const wxColour
GetHeaderColourBg() const;
348 Gets the foreground colour of the header part of the calendar window.
350 This method is currently only implemented in generic wxCalendarCtrl and
351 always returns @c wxNullColour in the native versions.
353 @see SetHeaderColours()
355 const wxColour
GetHeaderColourFg() const;
358 Gets the background highlight colour. Only in generic wxCalendarCtrl.
360 This method is currently only implemented in generic wxCalendarCtrl and
361 always returns @c wxNullColour in the native versions.
363 @see SetHighlightColours()
365 const wxColour
GetHighlightColourBg() const;
368 Gets the foreground highlight colour. Only in generic wxCalendarCtrl.
370 This method is currently only implemented in generic wxCalendarCtrl and
371 always returns @c wxNullColour in the native versions.
373 @see SetHighlightColours()
375 const wxColour
GetHighlightColourFg() const;
378 Return the background colour currently used for holiday highlighting.
380 Only useful with generic wxCalendarCtrl as native versions currently
381 don't support holidays display at all and always return
384 @see SetHolidayColours()
386 const wxColour
GetHolidayColourBg() const;
389 Return the foreground colour currently used for holiday highlighting.
391 Only useful with generic wxCalendarCtrl as native versions currently
392 don't support holidays display at all and always return
395 @see SetHolidayColours()
397 const wxColour
GetHolidayColourFg() const;
400 Returns one of wxCalendarHitTestResult constants and fills either
401 @a date or @a wd pointer with the corresponding value depending on the
404 Not implemented in wxGTK currently.
406 wxCalendarHitTestResult
HitTest(const wxPoint
& pos
,
407 wxDateTime
* date
= NULL
,
408 wxDateTime::WeekDay
* wd
= NULL
);
411 Clears any attributes associated with the given day (in the range
412 1...31). Only in generic wxCalendarCtrl.
414 void ResetAttr(size_t day
);
417 Associates the attribute with the specified date (in the range 1...31).
418 If the pointer is @NULL, the items attribute is cleared. Only in
419 generic wxCalendarCtrl.
421 void SetAttr(size_t day
, wxCalendarDateAttr
* attr
);
424 Sets the current date.
426 The @a date parameter must be valid.
428 void SetDate(const wxDateTime
& date
);
431 Set the colours used for painting the weekdays at the top of the
434 This method is currently only implemented in generic wxCalendarCtrl and
435 does nothing in the native versions.
437 void SetHeaderColours(const wxColour
& colFg
,
438 const wxColour
& colBg
);
441 Set the colours to be used for highlighting the currently selected
444 This method is currently only implemented in generic wxCalendarCtrl and
445 does nothing in the native versions.
447 void SetHighlightColours(const wxColour
& colFg
,
448 const wxColour
& colBg
);
451 Marks the specified day as being a holiday in the current month.
453 This method is only implemented in the generic version of the control
454 and does nothing in the native ones.
456 void SetHoliday(size_t day
);
459 Sets the colours to be used for the holidays highlighting.
461 This method is only implemented in the generic version of the control
462 and does nothing in the native ones. It should also only be called if
463 the window style includes @c wxCAL_SHOW_HOLIDAYS flag or
464 EnableHolidayDisplay() had been called.
467 void SetHolidayColours(const wxColour
& colFg
,
468 const wxColour
& colBg
);
471 Mark or unmark the day. This day of month will be marked in every
472 month. In generic wxCalendarCtrl,
474 void Mark(size_t day
, bool mark
);
477 @name Date Range Functions
479 The functions in this section are currently implemented in the generic
480 and MSW versions and do nothing in the native GTK implementation.
485 Restrict the dates shown by the control to the specified range.
487 If either date is set, the corresponding limit will be enforced and
488 @true returned. If none are set, the existing restrictions are removed
489 and @false is returned.
494 The low limit for the dates shown by the control or
495 @c wxDefaultDateTime.
497 The high limit for the dates shown by the control or
498 @c wxDefaultDateTime.
500 @true if either limit is valid, @false otherwise
502 virtual bool SetDateRange(const wxDateTime
& lowerdate
= wxDefaultDateTime
,
503 const wxDateTime
& upperdate
= wxDefaultDateTime
);
506 Returns the limits currently being used.
511 If non-@NULL, the value of the low limit for the dates shown by the
512 control is returned (which may be @c wxDefaultDateTime if no limit
515 If non-@NULL, the value of the upper limit for the dates shown by
516 the control is returned (which may be @c wxDefaultDateTime if no
519 @true if either limit is set, @false otherwise
521 virtual bool GetDateRange(wxDateTime
*lowerdate
,
522 wxDateTime
*upperdate
) const;