## wxCalendarCtrl

The calendar control allows the user to pick a date. For this, it displays a window containing several parts: a control at the top to pick the month and the year (either or both of them may be disabled), and a month area below them which shows all the days in the month. The user can move the current selection using the keyboard and select the date (generating `EVT_CALENDAR` event) by pressing `<Return>` or double clicking it.

It has advanced possibilities for the customization of its display. All global settings (such as colours and fonts used) can, of course, be changed. But also, the display style for each day in the month can be set independently using wxCalendarDateAttr class.

An item without custom attributes is drawn with the default colours and font and without border, but setting custom attributes with SetAttr allows to modify its appearance. Just create a custom attribute object and set it for the day you want to be displayed specially (note that the control will take ownership of the pointer, i.e. it will delete it itself). A day may be marked as being a holiday, even if it is not recognized as one by wxDateTime using SetHoliday method.

As the attributes are specified for each day, they may change when the month is changed, so you will often want to update them in `EVT_CALENDAR_MONTH` event handler.

Derived from

wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/calctrl.h>

Window styles

wxCAL_SUNDAY_FIRST | Show Sunday as the first day in the week
wxCAL_MONDAY_FIRST | Show Monday as the first day in the week
wxCAL_SHOW_HOLIDAYS | Highlight holidays in the calendar
wxCAL_NO_YEAR_CHANGE | Disable the year changing
wxCAL_NO_MONTH_CHANGE | Disable the month (and, implicitly, the year) changing
wxCAL_SHOW_SURROUNDING_WEEKS | Show the neighbouring weeks in the previous and next months
wxCAL_SEQUENTIAL_MONTH_SELECTION | Use alternative, more compact, style for the month and year selection controls.

The default calendar style is `wxCAL_SHOW_HOLIDAYS`.

Event table macros

To process input from a calendar control, use these event handler macros to direct input to member functions that take a wxCalendarEvent argument.

EVT_CALENDAR(id, func) | A day was double clicked in the calendar.
EVT_CALENDAR_SEL_CHANGED(id, func) | The selected date changed.
EVT_CALENDAR_DAY(id, func) | The selected day changed.
EVT_CALENDAR_MONTH(id, func) | The selected month changed.
EVT_CALENDAR_YEAR(id, func) | The selected year changed.
EVT_CALENDAR_WEEKDAY_CLICKED(id, func) | User clicked on the week day header

Note that changing the selected date will result in either of `EVT_CALENDAR_DAY`, `MONTH` or `YEAR` events and `EVT_CALENDAR_SEL_CHANGED` one.

Constants

The following are the possible return values for HitTest method:

    enum wxCalendarHitTestResult
    {
        wxCAL_HITTEST_NOWHERE,      // outside of anything
        wxCAL_HITTEST_HEADER,       // on the header (weekdays)
        wxCAL_HITTEST_DAY           // on a day in the calendar
    }

See also

Calendar sample
wxCalendarDateAttr
wxCalendarEvent

Members

wxCalendarCtrl::wxCalendarCtrl
wxCalendarCtrl::Create
wxCalendarCtrl::~wxCalendarCtrl
wxCalendarCtrl::SetDate
wxCalendarCtrl::GetDate
wxCalendarCtrl::EnableYearChange
wxCalendarCtrl::EnableMonthChange
wxCalendarCtrl::EnableHolidayDisplay
wxCalendarCtrl::SetHeaderColours
wxCalendarCtrl::GetHeaderColourFg
wxCalendarCtrl::GetHeaderColourBg
wxCalendarCtrl::SetHighlightColours
wxCalendarCtrl::GetHighlightColourFg
wxCalendarCtrl::GetHighlightColourBg
wxCalendarCtrl::SetHolidayColours
wxCalendarCtrl::GetHolidayColourFg
wxCalendarCtrl::GetHolidayColourBg
wxCalendarCtrl::GetAttr
wxCalendarCtrl::SetAttr
wxCalendarCtrl::SetHoliday
wxCalendarCtrl::ResetAttr
wxCalendarCtrl::HitTest

### wxCalendarCtrl::wxCalendarCtrl

wxCalendarCtrl()

Default constructor, use Create after it.

wxCalendarCtrl(wxWindow* parent, wxWindowID id, const wxDateTime& date = wxDefaultDateTime, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAL_SHOW_HOLIDAYS, const wxString& name = wxCalendarNameStr)

Does the same as Create method.

### wxCalendarCtrl::Create

bool Create(wxWindow* parent, wxWindowID id, const wxDateTime& date = wxDefaultDateTime, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAL_SHOW_HOLIDAYS, const wxString& name = wxCalendarNameStr)

Creates the control. See wxWindow for the meaning of the parameters and the control overview for the possible styles.

### wxCalendarCtrl::~wxCalendarCtrl

~wxCalendarCtrl()

Destroys the control.

### wxCalendarCtrl::SetDate

void SetDate(const wxDateTime& date)

Sets the current date.

### wxCalendarCtrl::GetDate

const wxDateTime& GetDate() const

Gets the currently selected date.

### wxCalendarCtrl::EnableYearChange

void EnableYearChange(bool enable = true)

This function should be used instead of changing `wxCAL_NO_YEAR_CHANGE` style bit directly. It allows or disallows the user to change the year interactively.

### wxCalendarCtrl::EnableMonthChange

void EnableMonthChange(bool enable = true)

This function should be used instead of changing `wxCAL_NO_MONTH_CHANGE` style bit. It allows or disallows the user to change the month interactively. Note that if the month can not be changed, the year can not be changed neither.

### wxCalendarCtrl::EnableHolidayDisplay

void EnableHolidayDisplay(bool display = true)

This function should be used instead of changing `wxCAL_SHOW_HOLIDAYS` style bit directly. It enables or disables the special highlighting of the holidays.

### wxCalendarCtrl::SetHeaderColours

void SetHeaderColours(const wxColour& colFg, const wxColour& colBg)

Set the colours used for painting the weekdays at the top of the control.

### wxCalendarCtrl::GetHeaderColourFg

const wxColour& GetHeaderColourFg() const

Gets the foreground colour of the header part of the calendar window.

See also

SetHeaderColours

### wxCalendarCtrl::GetHeaderColourBg

const wxColour& GetHeaderColourBg() const

Gets the background colour of the header part of the calendar window.

See also

SetHeaderColours

### wxCalendarCtrl::SetHighlightColours

void SetHighlightColours(const wxColour& colFg, const wxColour& colBg)

Set the colours to be used for highlighting the currently selected date.

### wxCalendarCtrl::GetHighlightColourFg

const wxColour& GetHighlightColourFg() const

Gets the foreground highlight colour.

See also

SetHighlightColours

### wxCalendarCtrl::GetHighlightColourBg

const wxColour& GetHighlightColourBg() const

Gets the background highlight colour.

See also

SetHighlightColours

### wxCalendarCtrl::SetHolidayColours

void SetHolidayColours(const wxColour& colFg, const wxColour& colBg)

Sets the colours to be used for the holidays highlighting (only used if the window style includes `wxCAL_SHOW_HOLIDAYS` flag).

### wxCalendarCtrl::GetHolidayColourFg

const wxColour& GetHolidayColourFg() const

Return the foreground colour currently used for holiday highlighting.

See also

SetHolidayColours

### wxCalendarCtrl::GetHolidayColourBg

const wxColour& GetHolidayColourBg() const

Return the background colour currently used for holiday highlighting.

See also

SetHolidayColours

### wxCalendarCtrl::GetAttr

wxCalendarDateAttr * GetAttr(size_t day) const

Returns the attribute for the given date (should be in the range 1...31).

The returned pointer may be `NULL`.

### wxCalendarCtrl::SetAttr

void SetAttr(size_t day, wxCalendarDateAttr* attr)

Associates the attribute with the specified date (in the range 1...31).

If the pointer is `NULL`, the items attribute is cleared.

### wxCalendarCtrl::SetHoliday

void SetHoliday(size_t day)

Marks the specified day as being a holiday in the current month.

### wxCalendarCtrl::ResetAttr

void ResetAttr(size_t day)

Clears any attributes associated with the given day (in the range 1...31).

### wxCalendarCtrl::HitTest

wxCalendarHitTestResult HitTest(const wxPoint& pos, wxDateTime* date = NULL, wxDateTime::WeekDay* wd = NULL)

Returns one of `wxCAL_HITTEST_XXX` constants and fills either date or wd pointer with the corresponding value depending on the hit test code.