GtkCalendar

GtkCalendar — Displays a calendar and allows the user to select a date

Properties

gint day Read / Write
gint month Read / Write
gboolean show-day-names Read / Write
gboolean show-heading Read / Write
gboolean show-week-numbers Read / Write
gint year Read / Write

Signals

void day-selected Run First
void next-month Run First
void next-year Run First
void prev-month Run First
void prev-year Run First

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkCalendar

Implemented Interfaces

GtkCalendar implements AtkImplementorIface, GtkBuildable and GtkConstraintTarget.

Includes

#include <gtk/gtk.h>

Description

GtkCalendar is a widget that displays a Gregorian calendar, one month at a time. It can be created with gtk_calendar_new().

The date that is currently displayed can be altered with gtk_calendar_select_day().

To place a visual marker on a particular day, use gtk_calendar_mark_day() and to remove the marker, gtk_calendar_unmark_day(). Alternative, all marks can be cleared with gtk_calendar_clear_marks().

The selected date can be retrieved from a GtkCalendar using gtk_calendar_get_date().

Users should be aware that, although the Gregorian calendar is the legal calendar in most countries, it was adopted progressively between 1582 and 1929. Display before these dates is likely to be historically incorrect.

CSS nodes

1
2
3
4
5
6
7
8
9
10
calendar.view
├── header
   ├── button
   ├── stack.month
   ├── button
   ├── button
   ├── label.year
   ╰── button
╰── grid
    ╰── label[.day-name][.week-number][.day-number][.other-month][.today]

GtkCalendar has a main node with name calendar. It contains a subnode called header containing the widgets for switching between years and months.

The grid subnode contains all day labels, including week numbers on the left (marked with the .week-number css class) and day names on top (marked with the .day-name css class).

Day labels that belong to the previous or next month get the .other-month style class. The label of the current day get the .today style class.

Marked day labels get the :selected state assigned.

Functions

gtk_calendar_new ()

GtkWidget *
gtk_calendar_new (void);

Creates a new calendar, with the current date being selected.

Returns

a newly GtkCalendar widget


gtk_calendar_select_day ()

void
gtk_calendar_select_day (GtkCalendar *self,
                         GDateTime *date);

Will switch to date 's year and month and select its day.

Parameters

self

a GtkCalendar.

 

date

a GDateTime representing the day to select.

[transfer none]

gtk_calendar_mark_day ()

void
gtk_calendar_mark_day (GtkCalendar *calendar,
                       guint day);

Places a visual marker on a particular day.

Parameters

calendar

a GtkCalendar

 

day

the day number to mark between 1 and 31.

 

gtk_calendar_unmark_day ()

void
gtk_calendar_unmark_day (GtkCalendar *calendar,
                         guint day);

Removes the visual marker from a particular day.

Parameters

calendar

a GtkCalendar.

 

day

the day number to unmark between 1 and 31.

 

gtk_calendar_get_day_is_marked ()

gboolean
gtk_calendar_get_day_is_marked (GtkCalendar *calendar,
                                guint day);

Returns if the day of the calendar is already marked.

Parameters

calendar

a GtkCalendar

 

day

the day number between 1 and 31.

 

Returns

whether the day is marked.


gtk_calendar_clear_marks ()

void
gtk_calendar_clear_marks (GtkCalendar *calendar);

Remove all visual markers.

Parameters

calendar

a GtkCalendar

 

gtk_calendar_get_show_day_names ()

gboolean
gtk_calendar_get_show_day_names (GtkCalendar *self);

Returns whether self is currently showing the names of the week days above the day numbers, i.e. the value of the “show-day-names” property.

Parameters

self

a GtkCalendar

 

Returns

Whether the calendar shows day names.


gtk_calendar_set_show_day_names ()

void
gtk_calendar_set_show_day_names (GtkCalendar *self,
                                 gboolean value);

Sets whether the calendar shows day names.

Parameters

self

a GtkCalendar

 

value

Whether to show day names above the day numbers

 

gtk_calendar_get_show_heading ()

gboolean
gtk_calendar_get_show_heading (GtkCalendar *self);

Returns whether self is currently showing the heading, i.e. the value of the “show-heading” property.

Return: Whether the calendar is showing a heading.

Parameters

self

a GtkCalendar

 

gtk_calendar_set_show_heading ()

void
gtk_calendar_set_show_heading (GtkCalendar *self,
                               gboolean value);

Sets whether the calendar should show a heading containing the current year and month as well as buttons for changing both.

Parameters

self

a GtkCalendar

 

value

Whether to show the heading in the calendar

 

gtk_calendar_get_show_week_numbers ()

gboolean
gtk_calendar_get_show_week_numbers (GtkCalendar *self);

Returns whether self is showing week numbers right now, i.e. the value of the “show-week-numbers” property.

Return: Whether the calendar is showing week numbers.

Parameters

self

a GtkCalendar

 

gtk_calendar_set_show_week_numbers ()

void
gtk_calendar_set_show_week_numbers (GtkCalendar *self,
                                    gboolean value);

Sets whether week numbers are shown in the calendar.

Parameters

self

a GtkCalendar

 

value

whether to show week numbers on the left of the days

 

gtk_calendar_get_date ()

GDateTime *
gtk_calendar_get_date (GtkCalendar *self);

Returns a GDateTime representing the shown year, month and the selected day, in the local time zone.

Parameters

self

a GtkCalendar

 

Returns

the GDate representing the shown date.

[transfer full]

Types and Values

GtkCalendar

typedef struct _GtkCalendar GtkCalendar;

Property Details

The “day” property

  “day”                      gint

The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day). This property gets initially set to the current day.

Owner: GtkCalendar

Flags: Read / Write

Allowed values: [0,31]

Default value: 0


The “month” property

  “month”                    gint

The selected month (as a number between 0 and 11). This property gets initially set to the current month.

Owner: GtkCalendar

Flags: Read / Write

Allowed values: [0,11]

Default value: 0


The “show-day-names” property

  “show-day-names”           gboolean

Determines whether day names are displayed.

Owner: GtkCalendar

Flags: Read / Write

Default value: TRUE


The “show-heading” property

  “show-heading”             gboolean

Determines whether a heading is displayed.

Owner: GtkCalendar

Flags: Read / Write

Default value: TRUE


The “show-week-numbers” property

  “show-week-numbers”        gboolean

Determines whether week numbers are displayed.

Owner: GtkCalendar

Flags: Read / Write

Default value: FALSE


The “year” property

  “year”                     gint

The selected year. This property gets initially set to the current year.

Owner: GtkCalendar

Flags: Read / Write

Allowed values: [1,9999]

Default value: 1

Signal Details

The “day-selected” signal

void
user_function (GtkCalendar *calendar,
               gpointer     user_data)

Emitted when the user selects a day.

Parameters

calendar

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “next-month” signal

void
user_function (GtkCalendar *calendar,
               gpointer     user_data)

Emitted when the user switched to the next month.

Parameters

calendar

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “next-year” signal

void
user_function (GtkCalendar *calendar,
               gpointer     user_data)

Emitted when user switched to the next year.

Parameters

calendar

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “prev-month” signal

void
user_function (GtkCalendar *calendar,
               gpointer     user_data)

Emitted when the user switched to the previous month.

Parameters

calendar

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “prev-year” signal

void
user_function (GtkCalendar *calendar,
               gpointer     user_data)

Emitted when user switched to the previous year.

Parameters

calendar

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First