wxCalendarCtrl — wx v2.4.3

Search documentation of wx

# View Source wxCalendarCtrl (wx v2.4.3)

The calendar control allows the user to pick a date.

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.

Generic calendar has advanced possibilities for the customization of its display, described below. If you want to use these possibilities on every platform, use wxGenericCalendarCtrl instead of `wxCalendarCtrl`.

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/3` allows modifying 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 `wx_datetime()` using the `wxCalendarDateAttr:setHoliday/2` 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_PAGE_CHANGED` event handler.

If neither the `wxCAL_SUNDAY_FIRST` or `wxCAL_MONDAY_FIRST` style is given, the first day of the week is determined from operating system's settings, if possible. The native wxGTK calendar chooses the first weekday based on locale, and these styles have no effect on it.

## Styles

This class supports the following styles:

- wxCAL_SUNDAY_FIRST: Show Sunday as the first day in the week (not in wxGTK)

- wxCAL_MONDAY_FIRST: Show Monday as the first day in the week (not in wxGTK)

- wxCAL_SHOW_HOLIDAYS: Highlight holidays in the calendar (only generic)

- wxCAL_NO_YEAR_CHANGE: Disable the year changing (deprecated, only generic)

- 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 (only generic, always on for the native controls)

- wxCAL_SEQUENTIAL_MONTH_SELECTION: Use alternative, more compact, style for the month and year selection controls. (only generic)

- wxCAL_SHOW_WEEK_NUMBERS: Show week numbers on the left side of the calendar. (not in generic)

See:

- Examples

- `wxCalendarDateAttr`

- `wxCalendarEvent`

- `wxDatePickerCtrl`

This class is derived, and can use functions, from:

- `wxControl`

- `wxWindow`

- `wxEvtHandler`

wxWidgets docs: wxCalendarCtrl

## Events

Event types emitted from this class:

- `calendar_sel_changed`

- `calendar_weekday_clicked`

# Summary

## Types

wxCalendarCtrl()

## Functions

create(This, Parent, Id)

Equivalent to `create(This, Parent, Id, [])`.

create/4

Creates the control.

destroy(This)

Destroys the object

enableHolidayDisplay(This)

Equivalent to `enableHolidayDisplay(This, [])`.

enableHolidayDisplay/2

This function should be used instead of changing `wxCAL\_SHOW\_HOLIDAYS` style bit directly.

enableMonthChange(This)

Equivalent to `enableMonthChange(This, [])`.

enableMonthChange/2

This function should be used instead of changing `wxCAL\_NO\_MONTH\_CHANGE` style bit.

enableYearChange(This) deprecated

Equivalent to `enableYearChange(This, [])`.

enableYearChange/2 deprecated

Deprecated

getAttr(This, Day)

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

getDate(This)

Gets the currently selected date.

getHeaderColourBg(This)

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

getHeaderColourFg(This)

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

getHighlightColourBg(This)

Gets the background highlight colour.

getHighlightColourFg(This)

Gets the foreground highlight colour.

getHolidayColourBg(This)

Return the background colour currently used for holiday highlighting.

getHolidayColourFg(This)

Return the foreground colour currently used for holiday highlighting.

hitTest(This, Pos)

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

new()

Default constructor.

new(Parent, Id)

Equivalent to `new(Parent, Id, [])`.

new/3

Does the same as `create/4` method.

resetAttr(This, Day)

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

setAttr(This, Day, Attr)

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

setDate(This, Date)

Sets the current date.

setHeaderColours(This, ColFg, ColBg)

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

setHighlightColours(This, ColFg, ColBg)

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

setHoliday(This, Day)

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

setHolidayColours(This, ColFg, ColBg)

Sets the colours to be used for the holidays highlighting.

# Types

Link to this type

# wxCalendarCtrl()

View Source

    -type wxCalendarCtrl() :: wx:wx_object().

# Functions

Link to this function

# create(This, Parent, Id)

View Source

    -spec create(This, Parent, Id) -> boolean()
                    when This :: wxCalendarCtrl(), Parent :: wxWindow:wxWindow(), Id :: integer().

Equivalent to `create(This, Parent, Id, [])`.

Link to this function

# create/4

View Source

    -spec create(This, Parent, Id, [Option]) -> boolean()
                    when
                        This :: wxCalendarCtrl(),
                        Parent :: wxWindow:wxWindow(),
                        Id :: integer(),
                        Option ::
                            {date, wx:wx_datetime()} |
                            {pos, {X :: integer(), Y :: integer()}} |
                            {size, {W :: integer(), H :: integer()}} |
                            {style, integer()}.

Creates the control.

See `wxWindow:new/3` for the meaning of the parameters and the control overview for the possible styles.

Link to this function

# destroy(This)

View Source

    -spec destroy(This :: wxCalendarCtrl()) -> ok.

Destroys the object

Link to this function

# enableHolidayDisplay(This)

View Source

    -spec enableHolidayDisplay(This) -> ok when This :: wxCalendarCtrl().

Equivalent to `enableHolidayDisplay(This, [])`.

Link to this function

# enableHolidayDisplay/2

View Source

    -spec enableHolidayDisplay(This, [Option]) -> ok
                                  when This :: wxCalendarCtrl(), Option :: {display, boolean()}.

This function should be used instead of changing `wxCAL\_SHOW\_HOLIDAYS` style bit directly.

It enables or disables the special highlighting of the holidays.

Link to this function

# enableMonthChange(This)

View Source

    -spec enableMonthChange(This) -> boolean() when This :: wxCalendarCtrl().

Equivalent to `enableMonthChange(This, [])`.

Link to this function

# enableMonthChange/2

View Source

    -spec enableMonthChange(This, [Option]) -> boolean()
                               when This :: wxCalendarCtrl(), Option :: {enable, boolean()}.

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 cannot be changed, the year cannot be changed neither.

Return: true if the value of this option really changed or false if it was already set to the requested value.

Link to this function

# enableYearChange(This)

View Source
This function is deprecated. wxCalendarCtrl:enableYearChange/1 is deprecated; not available in wxWidgets-2.9 and later.

    -spec enableYearChange(This) -> ok when This :: wxCalendarCtrl().

Equivalent to `enableYearChange(This, [])`.

Link to this function

# enableYearChange/2

View Source
This function is deprecated. wxCalendarCtrl:enableYearChange/2 is deprecated; not available in wxWidgets-2.9 and later.

    -spec enableYearChange(This, [Option]) -> ok
                              when This :: wxCalendarCtrl(), Option :: {enable, boolean()}.

Deprecated:

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. Only in generic `wxCalendarCtrl`.

Link to this function

# getAttr(This, Day)

View Source

    -spec getAttr(This, Day) -> wxCalendarDateAttr:wxCalendarDateAttr()
                     when This :: wxCalendarCtrl(), Day :: integer().

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

The returned pointer may be NULL. Only in generic `wxCalendarCtrl`.

Link to this function

# getDate(This)

View Source

    -spec getDate(This) -> wx:wx_datetime() when This :: wxCalendarCtrl().

Gets the currently selected date.

Link to this function

# getHeaderColourBg(This)

View Source

    -spec getHeaderColourBg(This) -> wx:wx_colour4() when This :: wxCalendarCtrl().

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

This method is currently only implemented in generic `wxCalendarCtrl` and always returns `wxNullColour` in the native versions.

See: `setHeaderColours/3`

Link to this function

# getHeaderColourFg(This)

View Source

    -spec getHeaderColourFg(This) -> wx:wx_colour4() when This :: wxCalendarCtrl().

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

This method is currently only implemented in generic `wxCalendarCtrl` and always returns `wxNullColour` in the native versions.

See: `setHeaderColours/3`

Link to this function

# getHighlightColourBg(This)

View Source

    -spec getHighlightColourBg(This) -> wx:wx_colour4() when This :: wxCalendarCtrl().

Gets the background highlight colour.

Only in generic `wxCalendarCtrl`.

This method is currently only implemented in generic `wxCalendarCtrl` and always returns `wxNullColour` in the native versions.

See: `setHighlightColours/3`

Link to this function

# getHighlightColourFg(This)

View Source

    -spec getHighlightColourFg(This) -> wx:wx_colour4() when This :: wxCalendarCtrl().

Gets the foreground highlight colour.

Only in generic `wxCalendarCtrl`.

This method is currently only implemented in generic `wxCalendarCtrl` and always returns `wxNullColour` in the native versions.

See: `setHighlightColours/3`

Link to this function

# getHolidayColourBg(This)

View Source

    -spec getHolidayColourBg(This) -> wx:wx_colour4() when This :: wxCalendarCtrl().

Return the background colour currently used for holiday highlighting.

Only useful with generic `wxCalendarCtrl` as native versions currently don't support holidays display at all and always return `wxNullColour`.

See: `setHolidayColours/3`

Link to this function

# getHolidayColourFg(This)

View Source

    -spec getHolidayColourFg(This) -> wx:wx_colour4() when This :: wxCalendarCtrl().

Return the foreground colour currently used for holiday highlighting.

Only useful with generic `wxCalendarCtrl` as native versions currently don't support holidays display at all and always return `wxNullColour`.

See: `setHolidayColours/3`

Link to this function

# hitTest(This, Pos)

View Source

    -spec hitTest(This, Pos) -> Result
                     when
                         Result :: {Res :: wx:wx_enum(), Date :: wx:wx_datetime(), Wd :: wx:wx_enum()},
                         This :: wxCalendarCtrl(),
                         Pos :: {X :: integer(), Y :: integer()}.

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

Not implemented in wxGTK currently.

Link to this function

# new()

View Source

    -spec new() -> wxCalendarCtrl().

Default constructor.

Link to this function

# new(Parent, Id)

View Source

    -spec new(Parent, Id) -> wxCalendarCtrl() when Parent :: wxWindow:wxWindow(), Id :: integer().

Equivalent to `new(Parent, Id, [])`.

Link to this function

# new/3

View Source

    -spec new(Parent, Id, [Option]) -> wxCalendarCtrl()
                 when
                     Parent :: wxWindow:wxWindow(),
                     Id :: integer(),
                     Option ::
                         {date, wx:wx_datetime()} |
                         {pos, {X :: integer(), Y :: integer()}} |
                         {size, {W :: integer(), H :: integer()}} |
                         {style, integer()}.

Does the same as `create/4` method.

Link to this function

# resetAttr(This, Day)

View Source

    -spec resetAttr(This, Day) -> ok when This :: wxCalendarCtrl(), Day :: integer().

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

Only in generic `wxCalendarCtrl`.

Link to this function

# setAttr(This, Day, Attr)

View Source

    -spec setAttr(This, Day, Attr) -> ok
                     when
                         This :: wxCalendarCtrl(),
                         Day :: integer(),
                         Attr :: wxCalendarDateAttr:wxCalendarDateAttr().

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

If the pointer is NULL, the items attribute is cleared. Only in generic `wxCalendarCtrl`.

Link to this function

# setDate(This, Date)

View Source

    -spec setDate(This, Date) -> boolean() when This :: wxCalendarCtrl(), Date :: wx:wx_datetime().

Sets the current date.

The `date` parameter must be valid and in the currently valid range as set by `SetDateRange()` (not implemented in wx), otherwise the current date is not changed and the function returns false and, additionally, triggers an assertion failure if the date is invalid.

Link to this function

# setHeaderColours(This, ColFg, ColBg)

View Source

    -spec setHeaderColours(This, ColFg, ColBg) -> ok
                              when
                                  This :: wxCalendarCtrl(), ColFg :: wx:wx_colour(), ColBg :: wx:wx_colour().

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

This method is currently only implemented in generic `wxCalendarCtrl` and does nothing in the native versions.

Link to this function

# setHighlightColours(This, ColFg, ColBg)

View Source

    -spec setHighlightColours(This, ColFg, ColBg) -> ok
                                 when
                                     This :: wxCalendarCtrl(),
                                     ColFg :: wx:wx_colour(),
                                     ColBg :: wx:wx_colour().

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

This method is currently only implemented in generic `wxCalendarCtrl` and does nothing in the native versions.

Link to this function

# setHoliday(This, Day)

View Source

    -spec setHoliday(This, Day) -> ok when This :: wxCalendarCtrl(), Day :: integer().

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

This method is only implemented in the generic version of the control and does nothing in the native ones.

Link to this function

# setHolidayColours(This, ColFg, ColBg)

View Source

    -spec setHolidayColours(This, ColFg, ColBg) -> ok
                               when
                                   This :: wxCalendarCtrl(),
                                   ColFg :: wx:wx_colour(),
                                   ColBg :: wx:wx_colour().

Sets the colours to be used for the holidays highlighting.

This method is only implemented in the generic version of the control and does nothing in the native ones. It should also only be called if the window style includes `wxCAL_SHOW_HOLIDAYS` flag or `enableHolidayDisplay/2` had been called.