1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
5 * Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson and Mattias Groenlund
8 * Copyright (c) 1995, 1996, 1997, 1998 by Steffen Beyer
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #ifdef HAVE_SYS_TIME_H
37 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
50 #undef GTK_DISABLE_DEPRECATED
51 #include "gtkcalendar.h"
56 #include "gtkmarshalers.h"
57 #include "gtkprivate.h"
58 #include "gdk/gdkkeysyms.h"
61 /***************************************************************************/
62 /* The following date routines are taken from the lib_date package.
63 * They have been minimally edited to avoid conflict with types defined
67 static const guint month_length[2][13] =
69 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
70 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
73 static const guint days_in_months[2][14] =
75 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
76 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
79 static glong calc_days(guint year, guint mm, guint dd);
80 static guint day_of_week(guint year, guint mm, guint dd);
81 static glong dates_difference(guint year1, guint mm1, guint dd1,
82 guint year2, guint mm2, guint dd2);
83 static guint weeks_in_year(guint year);
88 return((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0));
92 day_of_week (guint year, guint mm, guint dd)
96 days = calc_days(year, mm, dd);
103 return( (guint) days );
106 static guint weeks_in_year(guint year)
108 return(52 + ((day_of_week(year,1,1)==4) || (day_of_week(year,12,31)==4)));
112 check_date(guint year, guint mm, guint dd)
114 if (year < 1) return FALSE;
115 if ((mm < 1) || (mm > 12)) return FALSE;
116 if ((dd < 1) || (dd > month_length[leap(year)][mm])) return FALSE;
121 week_number(guint year, guint mm, guint dd)
125 first = day_of_week(year,1,1) - 1;
126 return( (guint) ( (dates_difference(year,1,1, year,mm,dd) + first) / 7L ) +
131 year_to_days(guint year)
133 return( year * 365L + (year / 4) - (year / 100) + (year / 400) );
138 calc_days(guint year, guint mm, guint dd)
142 if (year < 1) return(0L);
143 if ((mm < 1) || (mm > 12)) return(0L);
144 if ((dd < 1) || (dd > month_length[(lp = leap(year))][mm])) return(0L);
145 return( year_to_days(--year) + days_in_months[lp][mm] + dd );
149 week_of_year(guint *week, guint *year, guint mm, guint dd)
151 if (check_date(*year,mm,dd))
153 *week = week_number(*year,mm,dd);
155 *week = weeks_in_year(--(*year));
156 else if (*week > weeks_in_year(*year))
167 dates_difference(guint year1, guint mm1, guint dd1,
168 guint year2, guint mm2, guint dd2)
170 return( calc_days(year2, mm2, dd2) - calc_days(year1, mm1, dd1) );
173 /*** END OF lib_date routines ********************************************/
175 /* Spacing around day/week headers and main area, inside those windows */
176 #define CALENDAR_MARGIN 0
177 /* Spacing around day/week headers and main area, outside those windows */
178 #define INNER_BORDER 4
179 /* Separation between day headers and main area */
180 #define CALENDAR_YSEP 4
181 /* Separation between week headers and main area */
182 #define CALENDAR_XSEP 4
184 #define DAY_XSEP 0 /* not really good for small calendar */
185 #define DAY_YSEP 0 /* not really good for small calendar */
187 #define SCROLL_DELAY_FACTOR 5
190 #define HEADER_FG_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
191 #define HEADER_BG_COLOR(widget) (& (widget)->style->bg[GTK_WIDGET_STATE (widget)])
192 #define SELECTED_BG_COLOR(widget) (& (widget)->style->base[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
193 #define SELECTED_FG_COLOR(widget) (& (widget)->style->text[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
194 #define NORMAL_DAY_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
195 #define PREV_MONTH_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
196 #define NEXT_MONTH_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
197 #define MARKED_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
198 #define BACKGROUND_COLOR(widget) (& (widget)->style->base[GTK_WIDGET_STATE (widget)])
199 #define HIGHLIGHT_BACK_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
215 MONTH_CHANGED_SIGNAL,
217 DAY_SELECTED_DOUBLE_CLICK_SIGNAL,
233 PROP_NO_MONTH_CHANGE,
234 PROP_SHOW_WEEK_NUMBERS,
238 static guint gtk_calendar_signals[LAST_SIGNAL] = { 0 };
240 struct _GtkCalendarPrivate
242 GdkWindow *header_win;
243 GdkWindow *day_name_win;
246 GdkWindow *arrow_win[4];
252 guint arrow_state[4];
254 guint max_month_width;
255 guint max_year_width;
261 guint max_day_char_width;
262 guint max_day_char_ascent;
263 guint max_day_char_descent;
264 guint max_label_char_ascent;
265 guint max_label_char_descent;
266 guint max_week_char_width;
269 guint year_before : 1;
271 guint need_timer : 1;
274 guint drag_highlight : 1;
285 #define GTK_CALENDAR_GET_PRIVATE(widget) (GTK_CALENDAR (widget)->priv)
287 static void gtk_calendar_finalize (GObject *calendar);
288 static void gtk_calendar_destroy (GtkObject *calendar);
289 static void gtk_calendar_set_property (GObject *object,
293 static void gtk_calendar_get_property (GObject *object,
298 static void gtk_calendar_realize (GtkWidget *widget);
299 static void gtk_calendar_unrealize (GtkWidget *widget);
300 static void gtk_calendar_size_request (GtkWidget *widget,
301 GtkRequisition *requisition);
302 static void gtk_calendar_size_allocate (GtkWidget *widget,
303 GtkAllocation *allocation);
304 static gboolean gtk_calendar_expose (GtkWidget *widget,
305 GdkEventExpose *event);
306 static gboolean gtk_calendar_button_press (GtkWidget *widget,
307 GdkEventButton *event);
308 static gboolean gtk_calendar_button_release (GtkWidget *widget,
309 GdkEventButton *event);
310 static gboolean gtk_calendar_motion_notify (GtkWidget *widget,
311 GdkEventMotion *event);
312 static gboolean gtk_calendar_enter_notify (GtkWidget *widget,
313 GdkEventCrossing *event);
314 static gboolean gtk_calendar_leave_notify (GtkWidget *widget,
315 GdkEventCrossing *event);
316 static gboolean gtk_calendar_scroll (GtkWidget *widget,
317 GdkEventScroll *event);
318 static gboolean gtk_calendar_key_press (GtkWidget *widget,
320 static gboolean gtk_calendar_focus_out (GtkWidget *widget,
321 GdkEventFocus *event);
322 static void gtk_calendar_grab_notify (GtkWidget *widget,
323 gboolean was_grabbed);
324 static void gtk_calendar_state_changed (GtkWidget *widget,
325 GtkStateType previous_state);
326 static void gtk_calendar_style_set (GtkWidget *widget,
327 GtkStyle *previous_style);
329 static void gtk_calendar_drag_data_get (GtkWidget *widget,
330 GdkDragContext *context,
331 GtkSelectionData *selection_data,
334 static void gtk_calendar_drag_data_received (GtkWidget *widget,
335 GdkDragContext *context,
338 GtkSelectionData *selection_data,
341 static gboolean gtk_calendar_drag_motion (GtkWidget *widget,
342 GdkDragContext *context,
346 static void gtk_calendar_drag_leave (GtkWidget *widget,
347 GdkDragContext *context,
349 static gboolean gtk_calendar_drag_drop (GtkWidget *widget,
350 GdkDragContext *context,
355 static void calendar_start_spinning (GtkCalendar *calendar,
357 static void calendar_stop_spinning (GtkCalendar *calendar);
359 static void calendar_invalidate_day (GtkCalendar *widget,
362 static void calendar_invalidate_day_num (GtkCalendar *widget,
364 static void calendar_invalidate_arrow (GtkCalendar *widget,
367 static void calendar_compute_days (GtkCalendar *calendar);
369 static char *default_abbreviated_dayname[7];
370 static char *default_monthname[12];
372 G_DEFINE_TYPE (GtkCalendar, gtk_calendar, GTK_TYPE_WIDGET)
375 gtk_calendar_class_init (GtkCalendarClass *class)
377 GObjectClass *gobject_class;
378 GtkObjectClass *object_class;
379 GtkWidgetClass *widget_class;
381 gobject_class = (GObjectClass*) class;
382 object_class = (GtkObjectClass*) class;
383 widget_class = (GtkWidgetClass*) class;
385 gobject_class->set_property = gtk_calendar_set_property;
386 gobject_class->get_property = gtk_calendar_get_property;
387 gobject_class->finalize = gtk_calendar_finalize;
389 object_class->destroy = gtk_calendar_destroy;
391 widget_class->realize = gtk_calendar_realize;
392 widget_class->unrealize = gtk_calendar_unrealize;
393 widget_class->expose_event = gtk_calendar_expose;
394 widget_class->size_request = gtk_calendar_size_request;
395 widget_class->size_allocate = gtk_calendar_size_allocate;
396 widget_class->button_press_event = gtk_calendar_button_press;
397 widget_class->button_release_event = gtk_calendar_button_release;
398 widget_class->motion_notify_event = gtk_calendar_motion_notify;
399 widget_class->enter_notify_event = gtk_calendar_enter_notify;
400 widget_class->leave_notify_event = gtk_calendar_leave_notify;
401 widget_class->key_press_event = gtk_calendar_key_press;
402 widget_class->scroll_event = gtk_calendar_scroll;
403 widget_class->style_set = gtk_calendar_style_set;
404 widget_class->state_changed = gtk_calendar_state_changed;
405 widget_class->grab_notify = gtk_calendar_grab_notify;
406 widget_class->focus_out_event = gtk_calendar_focus_out;
408 widget_class->drag_data_get = gtk_calendar_drag_data_get;
409 widget_class->drag_motion = gtk_calendar_drag_motion;
410 widget_class->drag_leave = gtk_calendar_drag_leave;
411 widget_class->drag_drop = gtk_calendar_drag_drop;
412 widget_class->drag_data_received = gtk_calendar_drag_data_received;
414 g_object_class_install_property (gobject_class,
416 g_param_spec_int ("year",
418 P_("The selected year"),
420 GTK_PARAM_READWRITE));
421 g_object_class_install_property (gobject_class,
423 g_param_spec_int ("month",
425 P_("The selected month (as a number between 0 and 11)"),
427 GTK_PARAM_READWRITE));
428 g_object_class_install_property (gobject_class,
430 g_param_spec_int ("day",
432 P_("The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day)"),
434 GTK_PARAM_READWRITE));
437 * GtkCalendar:show-heading:
439 * Determines whether a heading is displayed.
443 g_object_class_install_property (gobject_class,
445 g_param_spec_boolean ("show-heading",
447 P_("If TRUE, a heading is displayed"),
449 GTK_PARAM_READWRITE));
452 * GtkCalendar:show-day-names:
454 * Determines whether day names are displayed.
458 g_object_class_install_property (gobject_class,
460 g_param_spec_boolean ("show-day-names",
461 P_("Show Day Names"),
462 P_("If TRUE, day names are displayed"),
464 GTK_PARAM_READWRITE));
466 * GtkCalendar:no-month-change:
468 * Determines whether the selected month can be changed.
472 g_object_class_install_property (gobject_class,
473 PROP_NO_MONTH_CHANGE,
474 g_param_spec_boolean ("no-month-change",
475 P_("No Month Change"),
476 P_("If TRUE, the selected month cannot be changed"),
478 GTK_PARAM_READWRITE));
481 * GtkCalendar:show-week-numbers:
483 * Determines whether week numbers are displayed.
487 g_object_class_install_property (gobject_class,
488 PROP_SHOW_WEEK_NUMBERS,
489 g_param_spec_boolean ("show-week-numbers",
490 P_("Show Week Numbers"),
491 P_("If TRUE, week numbers are displayed"),
493 GTK_PARAM_READWRITE));
495 gtk_calendar_signals[MONTH_CHANGED_SIGNAL] =
496 g_signal_new (I_("month_changed"),
497 G_OBJECT_CLASS_TYPE (gobject_class),
499 G_STRUCT_OFFSET (GtkCalendarClass, month_changed),
501 _gtk_marshal_VOID__VOID,
503 gtk_calendar_signals[DAY_SELECTED_SIGNAL] =
504 g_signal_new (I_("day_selected"),
505 G_OBJECT_CLASS_TYPE (gobject_class),
507 G_STRUCT_OFFSET (GtkCalendarClass, day_selected),
509 _gtk_marshal_VOID__VOID,
511 gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL] =
512 g_signal_new (I_("day_selected_double_click"),
513 G_OBJECT_CLASS_TYPE (gobject_class),
515 G_STRUCT_OFFSET (GtkCalendarClass, day_selected_double_click),
517 _gtk_marshal_VOID__VOID,
519 gtk_calendar_signals[PREV_MONTH_SIGNAL] =
520 g_signal_new (I_("prev_month"),
521 G_OBJECT_CLASS_TYPE (gobject_class),
523 G_STRUCT_OFFSET (GtkCalendarClass, prev_month),
525 _gtk_marshal_VOID__VOID,
527 gtk_calendar_signals[NEXT_MONTH_SIGNAL] =
528 g_signal_new (I_("next_month"),
529 G_OBJECT_CLASS_TYPE (gobject_class),
531 G_STRUCT_OFFSET (GtkCalendarClass, next_month),
533 _gtk_marshal_VOID__VOID,
535 gtk_calendar_signals[PREV_YEAR_SIGNAL] =
536 g_signal_new (I_("prev_year"),
537 G_OBJECT_CLASS_TYPE (gobject_class),
539 G_STRUCT_OFFSET (GtkCalendarClass, prev_year),
541 _gtk_marshal_VOID__VOID,
543 gtk_calendar_signals[NEXT_YEAR_SIGNAL] =
544 g_signal_new (I_("next_year"),
545 G_OBJECT_CLASS_TYPE (gobject_class),
547 G_STRUCT_OFFSET (GtkCalendarClass, next_year),
549 _gtk_marshal_VOID__VOID,
552 g_type_class_add_private (gobject_class, sizeof (GtkCalendarPrivate));
556 gtk_calendar_init (GtkCalendar *calendar)
558 GtkWidget *widget = GTK_WIDGET (calendar);
563 wchar_t wbuffer[100];
568 GtkCalendarPrivate *priv;
570 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
572 gint week_1stday = 0;
573 gint first_weekday = 1;
579 priv = calendar->priv = G_TYPE_INSTANCE_GET_PRIVATE (calendar,
583 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
585 if (!default_abbreviated_dayname[0])
589 tmp_time= (i+3)*86400;
590 strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
591 default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
593 if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
594 wbuffer, G_N_ELEMENTS (wbuffer)))
595 default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
597 default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
601 if (!default_monthname[0])
606 strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
607 default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
609 if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
610 wbuffer, G_N_ELEMENTS (wbuffer)))
611 default_monthname[i] = g_strdup_printf ("(%d)", i);
613 default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
619 tm = localtime (&secs);
620 calendar->month = tm->tm_mon;
621 calendar->year = 1900 + tm->tm_year;
624 calendar->marked_date[i] = FALSE;
625 calendar->num_marked_dates = 0;
626 calendar->selected_day = tm->tm_mday;
628 calendar->display_flags = ( GTK_CALENDAR_SHOW_HEADING |
629 GTK_CALENDAR_SHOW_DAY_NAMES );
631 calendar->highlight_row = -1;
632 calendar->highlight_col = -1;
634 calendar->focus_row = -1;
635 calendar->focus_col = -1;
637 priv->max_year_width = 0;
638 priv->max_month_width = 0;
639 priv->max_day_char_width = 0;
640 priv->max_week_char_width = 0;
642 priv->max_day_char_ascent = 0;
643 priv->max_day_char_descent = 0;
644 priv->max_label_char_ascent = 0;
645 priv->max_label_char_descent = 0;
647 priv->arrow_width = 10;
649 priv->need_timer = 0;
651 priv->click_child = -1;
654 priv->drag_highlight = 0;
656 gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_COPY);
657 gtk_drag_dest_add_text_targets (widget);
659 priv->year_before = 0;
661 /* Translate to calendar:YM if you want years to be displayed
662 * before months; otherwise translate to calendar:MY.
663 * Do *not* translate it to anything else, if it
664 * it isn't calendar:YM or calendar:MY it will not work.
666 * Note that this flipping is in top of the text direction flipping,
667 * so if you have a default text direction of RTL and YM, then
668 * the year will appear on the right.
670 year_before = _("calendar:MY");
671 if (strcmp (year_before, "calendar:YM") == 0)
672 priv->year_before = 1;
673 else if (strcmp (year_before, "calendar:MY") != 0)
674 g_warning ("Whoever translated calendar:MY did so wrongly.\n");
677 /* Check if any of those environment variables that affect the
678 * behaviour of gettext are set. If not, we use the thread's
679 * locale's week start day.
681 if (getenv ("LANGUAGE") == NULL &&
682 getenv ("LC_ALL") == NULL &&
683 getenv ("LC_MESSAGES") == NULL &&
684 getenv ("LANG") == NULL)
686 priv->week_start = 0;
689 if (GetLocaleInfoW (GetThreadLocale (), LOCALE_IFIRSTDAYOFWEEK,
690 wbuffer, G_N_ELEMENTS (wbuffer)))
691 week_start = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
693 if (week_start != NULL)
695 priv->week_start = (week_start[0] - '0' + 1) % 7;
702 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
703 langinfo = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
704 first_weekday = langinfo[0];
705 langinfo = nl_langinfo (_NL_TIME_WEEK_1STDAY);
706 week_origin = GPOINTER_TO_INT (langinfo);
707 if (week_origin == 19971130) /* Sunday */
709 else if (week_origin == 19971201) /* Monday */
712 g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");
714 priv->week_start = (week_1stday + first_weekday - 1) % 7;
716 /* Translate to calendar:week_start:0 if you want Sunday to be the
717 * first day of the week to calendar:week_start:1 if you want Monday
718 * to be the first day of the week, and so on.
720 week_start = _("calendar:week_start:0");
722 if (strncmp (week_start, "calendar:week_start:", 20) == 0)
723 priv->week_start = *(week_start + 20) - '0';
725 priv->week_start = -1;
727 if (priv->week_start < 0 || priv->week_start > 6)
729 g_warning ("Whoever translated calendar:week_start:0 did so wrongly.\n");
730 priv->week_start = 0;
737 calendar_compute_days (calendar);
741 /****************************************
742 * Utility Functions *
743 ****************************************/
746 calendar_set_month_next (GtkCalendar *calendar)
750 g_return_if_fail (GTK_IS_WIDGET (calendar));
752 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
756 if (calendar->month == 11)
764 calendar_compute_days (calendar);
765 g_signal_emit (calendar,
766 gtk_calendar_signals[NEXT_MONTH_SIGNAL],
768 g_signal_emit (calendar,
769 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
772 month_len = month_length[leap (calendar->year)][calendar->month + 1];
774 if (month_len < calendar->selected_day)
776 calendar->selected_day = 0;
777 gtk_calendar_select_day (calendar, month_len);
780 gtk_calendar_select_day (calendar, calendar->selected_day);
782 gtk_widget_queue_draw (GTK_WIDGET (calendar));
786 calendar_set_year_prev (GtkCalendar *calendar)
790 g_return_if_fail (GTK_IS_WIDGET (calendar));
793 calendar_compute_days (calendar);
794 g_signal_emit (calendar,
795 gtk_calendar_signals[PREV_YEAR_SIGNAL],
797 g_signal_emit (calendar,
798 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
801 month_len = month_length[leap (calendar->year)][calendar->month + 1];
803 if (month_len < calendar->selected_day)
805 calendar->selected_day = 0;
806 gtk_calendar_select_day (calendar, month_len);
809 gtk_calendar_select_day (calendar, calendar->selected_day);
811 gtk_widget_queue_draw (GTK_WIDGET (calendar));
815 calendar_set_year_next (GtkCalendar *calendar)
819 g_return_if_fail (GTK_IS_WIDGET (calendar));
822 calendar_compute_days (calendar);
823 g_signal_emit (calendar,
824 gtk_calendar_signals[NEXT_YEAR_SIGNAL],
826 g_signal_emit (calendar,
827 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
830 month_len = month_length[leap (calendar->year)][calendar->month + 1];
832 if (month_len < calendar->selected_day)
834 calendar->selected_day = 0;
835 gtk_calendar_select_day (calendar, month_len);
838 gtk_calendar_select_day (calendar, calendar->selected_day);
840 gtk_widget_queue_draw (GTK_WIDGET (calendar));
844 calendar_compute_days (GtkCalendar *calendar)
846 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (GTK_WIDGET (calendar));
850 gint ndays_in_prev_month;
856 g_return_if_fail (GTK_IS_CALENDAR (calendar));
858 year = calendar->year;
859 month = calendar->month + 1;
861 ndays_in_month = month_length[leap (year)][month];
863 first_day = day_of_week (year, month, 1);
864 first_day = (first_day + 7 - priv->week_start) % 7;
866 /* Compute days of previous month */
868 ndays_in_prev_month = month_length[leap (year)][month-1];
870 ndays_in_prev_month = month_length[leap (year)][12];
871 day = ndays_in_prev_month - first_day + 1;
876 for (col = 0; col < first_day; col++)
878 calendar->day[row][col] = day;
879 calendar->day_month[row][col] = MONTH_PREV;
884 /* Compute days of current month */
886 for (day = 1; day <= ndays_in_month; day++)
888 calendar->day[row][col] = day;
889 calendar->day_month[row][col] = MONTH_CURRENT;
899 /* Compute days of next month */
901 for (; row <= 5; row++)
903 for (; col <= 6; col++)
905 calendar->day[row][col] = day;
906 calendar->day_month[row][col] = MONTH_NEXT;
914 calendar_select_and_focus_day (GtkCalendar *calendar,
917 gint old_focus_row = calendar->focus_row;
918 gint old_focus_col = calendar->focus_col;
922 for (row = 0; row < 6; row ++)
923 for (col = 0; col < 7; col++)
925 if (calendar->day_month[row][col] == MONTH_CURRENT
926 && calendar->day[row][col] == day)
928 calendar->focus_row = row;
929 calendar->focus_col = col;
933 if (old_focus_row != -1 && old_focus_col != -1)
934 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
936 gtk_calendar_select_day (calendar, day);
940 /****************************************
941 * Layout computation utilities *
942 ****************************************/
945 calendar_row_height (GtkCalendar *calendar)
947 return (GTK_CALENDAR_GET_PRIVATE (calendar)->main_h - CALENDAR_MARGIN
948 - ((calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
949 ? CALENDAR_YSEP : CALENDAR_MARGIN)) / 6;
953 /* calendar_left_x_for_column: returns the x coordinate
954 * for the left of the column */
956 calendar_left_x_for_column (GtkCalendar *calendar,
962 if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
965 width = GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
966 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
967 x_left = CALENDAR_XSEP + (width + DAY_XSEP) * column;
969 x_left = CALENDAR_MARGIN + (width + DAY_XSEP) * column;
974 /* column_from_x: returns the column 0-6 that the
975 * x pixel of the xwindow is in */
977 calendar_column_from_x (GtkCalendar *calendar,
981 gint x_left, x_right;
985 for (c = 0; c < 7; c++)
987 x_left = calendar_left_x_for_column (calendar, c);
988 x_right = x_left + GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
990 if (event_x >= x_left && event_x < x_right)
1000 /* calendar_top_y_for_row: returns the y coordinate
1001 * for the top of the row */
1003 calendar_top_y_for_row (GtkCalendar *calendar,
1007 return (GTK_CALENDAR_GET_PRIVATE (calendar)->main_h
1008 - (CALENDAR_MARGIN + (6 - row)
1009 * calendar_row_height (calendar)));
1012 /* row_from_y: returns the row 0-5 that the
1013 * y pixel of the xwindow is in */
1015 calendar_row_from_y (GtkCalendar *calendar,
1020 gint y_top, y_bottom;
1022 height = calendar_row_height (calendar);
1025 for (r = 0; r < 6; r++)
1027 y_top = calendar_top_y_for_row (calendar, r);
1028 y_bottom = y_top + height;
1030 if (event_y >= y_top && event_y < y_bottom)
1041 calendar_arrow_rectangle (GtkCalendar *calendar,
1045 GtkWidget *widget = GTK_WIDGET (calendar);
1046 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1049 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1050 year_left = priv->year_before;
1052 year_left = !priv->year_before;
1055 rect->width = priv->arrow_width;
1056 rect->height = priv->header_h - 7;
1060 case ARROW_MONTH_LEFT:
1062 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1063 - (3 + 2*priv->arrow_width
1064 + priv->max_month_width));
1068 case ARROW_MONTH_RIGHT:
1070 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1071 - 3 - priv->arrow_width);
1073 rect->x = (priv->arrow_width
1074 + priv->max_month_width);
1076 case ARROW_YEAR_LEFT:
1080 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1081 - (3 + 2*priv->arrow_width
1082 + priv->max_year_width));
1084 case ARROW_YEAR_RIGHT:
1086 rect->x = (priv->arrow_width
1087 + priv->max_year_width);
1089 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1090 - 3 - priv->arrow_width);
1096 calendar_day_rectangle (GtkCalendar *calendar,
1101 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1103 rect->x = calendar_left_x_for_column (calendar, col);
1104 rect->y = calendar_top_y_for_row (calendar, row);
1105 rect->height = calendar_row_height (calendar);
1106 rect->width = priv->day_width;
1110 calendar_set_month_prev (GtkCalendar *calendar)
1114 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1117 if (calendar->month == 0)
1119 calendar->month = 11;
1125 month_len = month_length[leap (calendar->year)][calendar->month + 1];
1127 calendar_compute_days (calendar);
1129 g_signal_emit (calendar,
1130 gtk_calendar_signals[PREV_MONTH_SIGNAL],
1132 g_signal_emit (calendar,
1133 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
1136 if (month_len < calendar->selected_day)
1138 calendar->selected_day = 0;
1139 gtk_calendar_select_day (calendar, month_len);
1143 if (calendar->selected_day < 0)
1144 calendar->selected_day = calendar->selected_day + 1 + month_length[leap (calendar->year)][calendar->month + 1];
1145 gtk_calendar_select_day (calendar, calendar->selected_day);
1148 gtk_widget_queue_draw (GTK_WIDGET (calendar));
1152 /****************************************
1153 * Basic object methods *
1154 ****************************************/
1157 gtk_calendar_finalize (GObject *object)
1159 (* G_OBJECT_CLASS (gtk_calendar_parent_class)->finalize) (object);
1163 gtk_calendar_destroy (GtkObject *object)
1165 calendar_stop_spinning (GTK_CALENDAR (object));
1167 GTK_OBJECT_CLASS (gtk_calendar_parent_class)->destroy (object);
1172 calendar_set_display_option (GtkCalendar *calendar,
1173 GtkCalendarDisplayOptions flag,
1176 GtkCalendarDisplayOptions flags;
1178 flags = calendar->display_flags | flag;
1180 flags = calendar->display_flags & ~flag;
1181 gtk_calendar_display_options (calendar, flags);
1185 calendar_get_display_option (GtkCalendar *calendar,
1186 GtkCalendarDisplayOptions flag)
1188 return (calendar->display_flags & flag) != 0;
1192 gtk_calendar_set_property (GObject *object,
1194 const GValue *value,
1197 GtkCalendar *calendar;
1199 calendar = GTK_CALENDAR (object);
1204 gtk_calendar_select_month (calendar,
1206 g_value_get_int (value));
1209 gtk_calendar_select_month (calendar,
1210 g_value_get_int (value),
1214 gtk_calendar_select_day (calendar,
1215 g_value_get_int (value));
1217 case PROP_SHOW_HEADING:
1218 calendar_set_display_option (calendar,
1219 GTK_CALENDAR_SHOW_HEADING,
1220 g_value_get_boolean (value));
1222 case PROP_SHOW_DAY_NAMES:
1223 calendar_set_display_option (calendar,
1224 GTK_CALENDAR_SHOW_DAY_NAMES,
1225 g_value_get_boolean (value));
1227 case PROP_NO_MONTH_CHANGE:
1228 calendar_set_display_option (calendar,
1229 GTK_CALENDAR_NO_MONTH_CHANGE,
1230 g_value_get_boolean (value));
1232 case PROP_SHOW_WEEK_NUMBERS:
1233 calendar_set_display_option (calendar,
1234 GTK_CALENDAR_SHOW_WEEK_NUMBERS,
1235 g_value_get_boolean (value));
1238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1244 gtk_calendar_get_property (GObject *object,
1249 GtkCalendar *calendar;
1251 calendar = GTK_CALENDAR (object);
1256 g_value_set_int (value, calendar->year);
1259 g_value_set_int (value, calendar->month);
1262 g_value_set_int (value, calendar->selected_day);
1264 case PROP_SHOW_HEADING:
1265 g_value_set_boolean (value, calendar_get_display_option (calendar,
1266 GTK_CALENDAR_SHOW_HEADING));
1268 case PROP_SHOW_DAY_NAMES:
1269 g_value_set_boolean (value, calendar_get_display_option (calendar,
1270 GTK_CALENDAR_SHOW_DAY_NAMES));
1272 case PROP_NO_MONTH_CHANGE:
1273 g_value_set_boolean (value, calendar_get_display_option (calendar,
1274 GTK_CALENDAR_NO_MONTH_CHANGE));
1276 case PROP_SHOW_WEEK_NUMBERS:
1277 g_value_set_boolean (value, calendar_get_display_option (calendar,
1278 GTK_CALENDAR_SHOW_WEEK_NUMBERS));
1281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1287 /****************************************
1289 ****************************************/
1292 calendar_realize_arrows (GtkCalendar *calendar)
1294 GtkWidget *widget = GTK_WIDGET (calendar);
1295 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1296 GdkWindowAttr attributes;
1297 gint attributes_mask;
1300 /* Arrow windows ------------------------------------- */
1301 if (! (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1302 && (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING))
1304 attributes.wclass = GDK_INPUT_OUTPUT;
1305 attributes.window_type = GDK_WINDOW_CHILD;
1306 attributes.visual = gtk_widget_get_visual (widget);
1307 attributes.colormap = gtk_widget_get_colormap (widget);
1308 attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
1309 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
1310 | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
1311 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1312 for (i = 0; i < 4; i++)
1315 calendar_arrow_rectangle (calendar, i, &rect);
1317 attributes.x = rect.x;
1318 attributes.y = rect.y;
1319 attributes.width = rect.width;
1320 attributes.height = rect.height;
1321 priv->arrow_win[i] = gdk_window_new (priv->header_win,
1324 if (GTK_WIDGET_IS_SENSITIVE (widget))
1325 priv->arrow_state[i] = GTK_STATE_NORMAL;
1327 priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
1328 gdk_window_set_background (priv->arrow_win[i],
1329 HEADER_BG_COLOR (GTK_WIDGET (calendar)));
1330 gdk_window_show (priv->arrow_win[i]);
1331 gdk_window_set_user_data (priv->arrow_win[i], widget);
1336 for (i = 0; i < 4; i++)
1337 priv->arrow_win[i] = NULL;
1342 calendar_realize_header (GtkCalendar *calendar)
1344 GtkWidget *widget = GTK_WIDGET (calendar);
1345 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1346 GdkWindowAttr attributes;
1347 gint attributes_mask;
1349 /* Header window ------------------------------------- */
1350 if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
1352 attributes.wclass = GDK_INPUT_OUTPUT;
1353 attributes.window_type = GDK_WINDOW_CHILD;
1354 attributes.visual = gtk_widget_get_visual (widget);
1355 attributes.colormap = gtk_widget_get_colormap (widget);
1356 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1357 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1358 attributes.x = widget->style->xthickness;
1359 attributes.y = widget->style->ythickness;
1360 attributes.width = widget->allocation.width - 2 * attributes.x;
1361 attributes.height = priv->header_h - 2 * attributes.y;
1362 priv->header_win = gdk_window_new (widget->window,
1363 &attributes, attributes_mask);
1365 gdk_window_set_background (priv->header_win,
1366 HEADER_BG_COLOR (GTK_WIDGET (calendar)));
1367 gdk_window_show (priv->header_win);
1368 gdk_window_set_user_data (priv->header_win, widget);
1373 priv->header_win = NULL;
1375 calendar_realize_arrows (calendar);
1379 calendar_realize_day_names (GtkCalendar *calendar)
1381 GtkWidget *widget = GTK_WIDGET (calendar);
1382 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1383 GdkWindowAttr attributes;
1384 gint attributes_mask;
1386 /* Day names window --------------------------------- */
1387 if ( calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
1389 attributes.wclass = GDK_INPUT_OUTPUT;
1390 attributes.window_type = GDK_WINDOW_CHILD;
1391 attributes.visual = gtk_widget_get_visual (widget);
1392 attributes.colormap = gtk_widget_get_colormap (widget);
1393 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1394 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1395 attributes.x = (widget->style->xthickness + INNER_BORDER);
1396 attributes.y = priv->header_h + (widget->style->ythickness
1398 attributes.width = (widget->allocation.width
1399 - (widget->style->xthickness + INNER_BORDER)
1401 attributes.height = priv->day_name_h;
1402 priv->day_name_win = gdk_window_new (widget->window,
1405 gdk_window_set_background (priv->day_name_win,
1406 BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
1407 gdk_window_show (priv->day_name_win);
1408 gdk_window_set_user_data (priv->day_name_win, widget);
1412 priv->day_name_win = NULL;
1417 calendar_realize_week_numbers (GtkCalendar *calendar)
1419 GtkWidget *widget = GTK_WIDGET (calendar);
1420 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1421 GdkWindowAttr attributes;
1422 gint attributes_mask;
1424 /* Week number window -------------------------------- */
1425 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1427 attributes.wclass = GDK_INPUT_OUTPUT;
1428 attributes.window_type = GDK_WINDOW_CHILD;
1429 attributes.visual = gtk_widget_get_visual (widget);
1430 attributes.colormap = gtk_widget_get_colormap (widget);
1431 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1433 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1434 attributes.x = widget->style->xthickness + INNER_BORDER;
1435 attributes.y = (priv->header_h + priv->day_name_h
1436 + (widget->style->ythickness + INNER_BORDER));
1437 attributes.width = priv->week_width;
1438 attributes.height = priv->main_h;
1439 priv->week_win = gdk_window_new (widget->window,
1440 &attributes, attributes_mask);
1441 gdk_window_set_background (priv->week_win,
1442 BACKGROUND_COLOR (GTK_WIDGET (calendar)));
1443 gdk_window_show (priv->week_win);
1444 gdk_window_set_user_data (priv->week_win, widget);
1448 priv->week_win = NULL;
1453 gtk_calendar_realize (GtkWidget *widget)
1455 GtkCalendar *calendar = GTK_CALENDAR (widget);
1456 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1457 GdkWindowAttr attributes;
1458 gint attributes_mask;
1460 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1462 attributes.x = widget->allocation.x;
1463 attributes.y = widget->allocation.y;
1464 attributes.width = widget->allocation.width;
1465 attributes.height = widget->allocation.height;
1466 attributes.wclass = GDK_INPUT_OUTPUT;
1467 attributes.window_type = GDK_WINDOW_CHILD;
1468 attributes.event_mask = (gtk_widget_get_events (widget)
1469 | GDK_EXPOSURE_MASK |GDK_KEY_PRESS_MASK | GDK_SCROLL_MASK);
1470 attributes.visual = gtk_widget_get_visual (widget);
1471 attributes.colormap = gtk_widget_get_colormap (widget);
1473 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1474 widget->window = gdk_window_new (widget->parent->window,
1475 &attributes, attributes_mask);
1477 widget->style = gtk_style_attach (widget->style, widget->window);
1479 /* Header window ------------------------------------- */
1480 calendar_realize_header (calendar);
1481 /* Day names window --------------------------------- */
1482 calendar_realize_day_names (calendar);
1483 /* Week number window -------------------------------- */
1484 calendar_realize_week_numbers (calendar);
1485 /* Main Window -------------------------------------- */
1486 attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
1487 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
1488 | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
1490 attributes.x = priv->week_width + (widget->style->ythickness + INNER_BORDER);
1491 attributes.y = (priv->header_h + priv->day_name_h
1492 + (widget->style->ythickness + INNER_BORDER));
1493 attributes.width = (widget->allocation.width - attributes.x
1494 - (widget->style->xthickness + INNER_BORDER));
1495 attributes.height = priv->main_h;
1496 priv->main_win = gdk_window_new (widget->window,
1497 &attributes, attributes_mask);
1498 gdk_window_set_background (priv->main_win,
1499 BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
1500 gdk_window_show (priv->main_win);
1501 gdk_window_set_user_data (priv->main_win, widget);
1502 gdk_window_set_background (widget->window, BACKGROUND_COLOR (widget));
1503 gdk_window_show (widget->window);
1504 gdk_window_set_user_data (widget->window, widget);
1508 gtk_calendar_unrealize (GtkWidget *widget)
1510 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1513 if (priv->header_win)
1515 for (i = 0; i < 4; i++)
1517 if (priv->arrow_win[i])
1519 gdk_window_set_user_data (priv->arrow_win[i], NULL);
1520 gdk_window_destroy (priv->arrow_win[i]);
1521 priv->arrow_win[i] = NULL;
1524 gdk_window_set_user_data (priv->header_win, NULL);
1525 gdk_window_destroy (priv->header_win);
1526 priv->header_win = NULL;
1531 gdk_window_set_user_data (priv->week_win, NULL);
1532 gdk_window_destroy (priv->week_win);
1533 priv->week_win = NULL;
1538 gdk_window_set_user_data (priv->main_win, NULL);
1539 gdk_window_destroy (priv->main_win);
1540 priv->main_win = NULL;
1542 if (priv->day_name_win)
1544 gdk_window_set_user_data (priv->day_name_win, NULL);
1545 gdk_window_destroy (priv->day_name_win);
1546 priv->day_name_win = NULL;
1549 if (GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize)
1550 (* GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize) (widget);
1554 /****************************************
1555 * Size Request and Allocate *
1556 ****************************************/
1559 gtk_calendar_size_request (GtkWidget *widget,
1560 GtkRequisition *requisition)
1562 GtkCalendar *calendar = GTK_CALENDAR (widget);
1563 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1564 PangoLayout *layout;
1565 PangoRectangle logical_rect;
1569 gint calendar_margin = CALENDAR_MARGIN;
1570 gint header_width, main_width;
1571 gint max_header_height = 0;
1575 gtk_widget_style_get (GTK_WIDGET (widget),
1576 "focus-line-width", &focus_width,
1577 "focus-padding", &focus_padding,
1580 layout = gtk_widget_create_pango_layout (widget, NULL);
1583 * Calculate the requisition width for the widget.
1588 if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
1590 priv->max_month_width = 0;
1591 for (i = 0; i < 12; i++)
1593 pango_layout_set_text (layout, default_monthname[i], -1);
1594 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1595 priv->max_month_width = MAX (priv->max_month_width,
1596 logical_rect.width + 8);
1597 max_header_height = MAX (max_header_height, logical_rect.height);
1600 priv->max_year_width = 0;
1601 /* Translators: This is a text measurement template.
1602 * Translate it to the widest year text.
1604 * Don't include the prefix "year measurement template|"
1605 * in the translation.
1607 * If you don't understand this, leave it as "2000"
1609 pango_layout_set_text (layout, Q_("year measurement template|2000"), -1);
1610 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1611 priv->max_year_width = MAX (priv->max_year_width,
1612 logical_rect.width + 8);
1613 max_header_height = MAX (max_header_height, logical_rect.height);
1617 priv->max_month_width = 0;
1618 priv->max_year_width = 0;
1621 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1622 header_width = (priv->max_month_width
1623 + priv->max_year_width
1626 header_width = (priv->max_month_width
1627 + priv->max_year_width
1628 + 4 * priv->arrow_width + 3 * 3);
1630 /* Mainwindow labels width */
1632 priv->max_day_char_width = 0;
1633 priv->max_day_char_ascent = 0;
1634 priv->max_day_char_descent = 0;
1635 priv->min_day_width = 0;
1637 for (i = 0; i < 9; i++)
1640 g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), i * 11);
1641 pango_layout_set_text (layout, buffer, -1);
1642 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1643 priv->min_day_width = MAX (priv->min_day_width,
1644 logical_rect.width);
1646 priv->max_day_char_ascent = MAX (priv->max_day_char_ascent,
1647 PANGO_ASCENT (logical_rect));
1648 priv->max_day_char_descent = MAX (priv->max_day_char_descent,
1649 PANGO_DESCENT (logical_rect));
1651 /* We add one to max_day_char_width to be able to make the marked day "bold" */
1652 priv->max_day_char_width = priv->min_day_width / 2 + 1;
1654 priv->max_label_char_ascent = 0;
1655 priv->max_label_char_descent = 0;
1656 if (calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
1657 for (i = 0; i < 7; i++)
1659 pango_layout_set_text (layout, default_abbreviated_dayname[i], -1);
1660 pango_layout_line_get_pixel_extents (pango_layout_get_lines (layout)->data, NULL, &logical_rect);
1662 priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
1663 priv->max_label_char_ascent = MAX (priv->max_label_char_ascent,
1664 PANGO_ASCENT (logical_rect));
1665 priv->max_label_char_descent = MAX (priv->max_label_char_descent,
1666 PANGO_DESCENT (logical_rect));
1669 priv->max_week_char_width = 0;
1670 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1671 for (i = 0; i < 9; i++)
1674 g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), i * 11);
1675 pango_layout_set_text (layout, buffer, -1);
1676 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1677 priv->max_week_char_width = MAX (priv->max_week_char_width,
1678 logical_rect.width / 2);
1681 main_width = (7 * (priv->min_day_width + (focus_padding + focus_width) * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
1682 + (priv->max_week_char_width
1683 ? priv->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + CALENDAR_XSEP * 2
1687 requisition->width = MAX (header_width, main_width + INNER_BORDER * 2) + widget->style->xthickness * 2;
1690 * Calculate the requisition height for the widget.
1693 if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
1695 priv->header_h = (max_header_height + CALENDAR_YSEP * 2);
1702 if (calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
1704 priv->day_name_h = (priv->max_label_char_ascent
1705 + priv->max_label_char_descent
1706 + 2 * (focus_padding + focus_width) + calendar_margin);
1707 calendar_margin = CALENDAR_YSEP;
1711 priv->day_name_h = 0;
1714 priv->main_h = (CALENDAR_MARGIN + calendar_margin
1715 + 6 * (priv->max_day_char_ascent
1716 + priv->max_day_char_descent
1717 + 2 * (focus_padding + focus_width))
1720 height = (priv->header_h + priv->day_name_h
1723 requisition->height = height + (widget->style->ythickness + INNER_BORDER) * 2;
1725 g_object_unref (layout);
1729 gtk_calendar_size_allocate (GtkWidget *widget,
1730 GtkAllocation *allocation)
1732 GtkCalendar *calendar = GTK_CALENDAR (widget);
1733 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1734 gint xthickness = widget->style->xthickness;
1735 gint ythickness = widget->style->xthickness;
1738 widget->allocation = *allocation;
1740 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1742 priv->day_width = (priv->min_day_width
1743 * ((allocation->width - (xthickness + INNER_BORDER) * 2
1744 - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2))
1745 / (7 * priv->min_day_width + priv->max_week_char_width * 2));
1746 priv->week_width = ((allocation->width - (xthickness + INNER_BORDER) * 2
1747 - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2 )
1748 - priv->day_width * 7 + CALENDAR_MARGIN + CALENDAR_XSEP);
1752 priv->day_width = (allocation->width
1753 - (xthickness + INNER_BORDER) * 2
1754 - (CALENDAR_MARGIN * 2)
1755 - (DAY_XSEP * 6))/7;
1756 priv->week_width = 0;
1759 if (GTK_WIDGET_REALIZED (widget))
1761 gdk_window_move_resize (widget->window,
1762 allocation->x, allocation->y,
1763 allocation->width, allocation->height);
1764 if (priv->header_win)
1765 gdk_window_move_resize (priv->header_win,
1766 xthickness, ythickness,
1767 allocation->width - 2 * xthickness, priv->header_h);
1769 for (i = 0 ; i < 4 ; i++)
1771 if (priv->arrow_win[i])
1774 calendar_arrow_rectangle (calendar, i, &rect);
1776 gdk_window_move_resize (priv->arrow_win[i],
1777 rect.x, rect.y, rect.width, rect.height);
1781 if (priv->day_name_win)
1782 gdk_window_move_resize (priv->day_name_win,
1783 xthickness + INNER_BORDER,
1784 priv->header_h + (widget->style->ythickness + INNER_BORDER),
1785 allocation->width - (xthickness + INNER_BORDER) * 2,
1787 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1790 gdk_window_move_resize (priv->week_win,
1791 (xthickness + INNER_BORDER),
1792 priv->header_h + priv->day_name_h
1793 + (widget->style->ythickness + INNER_BORDER),
1796 gdk_window_move_resize (priv->main_win,
1797 priv->week_width + (xthickness + INNER_BORDER),
1798 priv->header_h + priv->day_name_h
1799 + (widget->style->ythickness + INNER_BORDER),
1802 - (xthickness + INNER_BORDER) * 2,
1807 gdk_window_move_resize (priv->main_win,
1808 (xthickness + INNER_BORDER),
1809 priv->header_h + priv->day_name_h
1810 + (widget->style->ythickness + INNER_BORDER),
1813 - (xthickness + INNER_BORDER) * 2,
1816 gdk_window_move_resize (priv->week_win,
1819 - (xthickness + INNER_BORDER),
1820 priv->header_h + priv->day_name_h
1821 + (widget->style->ythickness + INNER_BORDER),
1829 /****************************************
1831 ****************************************/
1834 calendar_paint_header (GtkCalendar *calendar)
1836 GtkWidget *widget = GTK_WIDGET (calendar);
1837 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1842 gint max_month_width;
1843 gint max_year_width;
1844 PangoLayout *layout;
1845 PangoRectangle logical_rect;
1851 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1852 year_left = priv->year_before;
1854 year_left = !priv->year_before;
1856 cr = gdk_cairo_create (priv->header_win);
1858 header_width = widget->allocation.width - 2 * widget->style->xthickness;
1860 max_month_width = priv->max_month_width;
1861 max_year_width = priv->max_year_width;
1863 gtk_paint_shadow (widget->style, priv->header_win,
1864 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
1865 NULL, widget, "calendar",
1866 0, 0, header_width, priv->header_h);
1868 tmp_time = 1; /* Jan 1 1970, 00:00:01 UTC */
1869 tm = gmtime (&tmp_time);
1870 tm->tm_year = calendar->year - 1900;
1872 /* Translators: This dictates how the year is displayed in
1873 * gtkcalendar widget. See strftime() manual for the format.
1874 * Use only ASCII in the translation.
1876 * Also look for the msgid "year measurement template|2000".
1877 * Translate that entry to a year with the widest output of this
1880 * Don't include the prefix "calendar year format|" in the
1881 * translation. "%Y" is appropriate for most locales.
1883 strftime (buffer, sizeof (buffer), Q_("calendar year format|%Y"), tm);
1884 str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
1885 layout = gtk_widget_create_pango_layout (widget, str);
1888 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1891 y = (priv->header_h - logical_rect.height) / 2;
1893 /* Draw year and its arrows */
1895 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1897 x = 3 + (max_year_width - logical_rect.width)/2;
1899 x = header_width - (3 + max_year_width
1900 - (max_year_width - logical_rect.width)/2);
1903 x = 3 + priv->arrow_width + (max_year_width - logical_rect.width)/2;
1905 x = header_width - (3 + priv->arrow_width + max_year_width
1906 - (max_year_width - logical_rect.width)/2);
1909 gdk_cairo_set_source_color (cr, HEADER_FG_COLOR (GTK_WIDGET (calendar)));
1910 cairo_move_to (cr, x, y);
1911 pango_cairo_show_layout (cr, layout);
1914 g_snprintf (buffer, sizeof (buffer), "%s", default_monthname[calendar->month]);
1915 pango_layout_set_text (layout, buffer, -1);
1916 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1918 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1920 x = header_width - (3 + max_month_width
1921 - (max_month_width - logical_rect.width)/2);
1923 x = 3 + (max_month_width - logical_rect.width) / 2;
1926 x = header_width - (3 + priv->arrow_width + max_month_width
1927 - (max_month_width - logical_rect.width)/2);
1929 x = 3 + priv->arrow_width + (max_month_width - logical_rect.width)/2;
1931 cairo_move_to (cr, x, y);
1932 pango_cairo_show_layout (cr, layout);
1934 g_object_unref (layout);
1939 calendar_paint_day_names (GtkCalendar *calendar)
1941 GtkWidget *widget = GTK_WIDGET (calendar);
1942 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1946 int day_width, cal_width;
1948 PangoLayout *layout;
1949 PangoRectangle logical_rect;
1953 cr = gdk_cairo_create (priv->day_name_win);
1955 gtk_widget_style_get (GTK_WIDGET (widget),
1956 "focus-line-width", &focus_width,
1957 "focus-padding", &focus_padding,
1960 day_width = priv->day_width;
1961 cal_width = widget->allocation.width;
1962 day_wid_sep = day_width + DAY_XSEP;
1965 * Draw rectangles as inverted background for the labels.
1968 gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
1969 cairo_rectangle (cr,
1970 CALENDAR_MARGIN, CALENDAR_MARGIN,
1971 cal_width-CALENDAR_MARGIN * 2,
1972 priv->day_name_h - CALENDAR_MARGIN);
1975 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1977 cairo_rectangle (cr,
1979 priv->day_name_h - CALENDAR_YSEP,
1980 priv->week_width - CALENDAR_YSEP - CALENDAR_MARGIN,
1989 layout = gtk_widget_create_pango_layout (widget, NULL);
1991 gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
1992 for (i = 0; i < 7; i++)
1994 if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
1998 day = (day + priv->week_start) % 7;
1999 g_snprintf (buffer, sizeof (buffer), "%s", default_abbreviated_dayname[day]);
2001 pango_layout_set_text (layout, buffer, -1);
2002 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
2006 + (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
2007 (priv->week_width + (priv->week_width ? CALENDAR_XSEP : 0))
2010 + (day_width - logical_rect.width)/2),
2011 CALENDAR_MARGIN + focus_width + focus_padding + logical_rect.y);
2012 pango_cairo_show_layout (cr, layout);
2015 g_object_unref (layout);
2020 calendar_paint_week_numbers (GtkCalendar *calendar)
2022 GtkWidget *widget = GTK_WIDGET (calendar);
2023 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2025 gint row, week = 0, year;
2028 gint y_loc, day_height;
2029 PangoLayout *layout;
2030 PangoRectangle logical_rect;
2034 cr = gdk_cairo_create (priv->week_win);
2036 gtk_widget_style_get (GTK_WIDGET (widget),
2037 "focus-line-width", &focus_width,
2038 "focus-padding", &focus_padding,
2042 * Draw a rectangle as inverted background for the labels.
2045 gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
2046 if (priv->day_name_win)
2047 cairo_rectangle (cr,
2050 priv->week_width - CALENDAR_MARGIN,
2051 priv->main_h - CALENDAR_MARGIN);
2053 cairo_rectangle (cr,
2056 priv->week_width - CALENDAR_MARGIN,
2057 priv->main_h - 2 * CALENDAR_MARGIN);
2064 layout = gtk_widget_create_pango_layout (widget, NULL);
2066 gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
2067 day_height = calendar_row_height (calendar);
2068 for (row = 0; row < 6; row++)
2072 year = calendar->year;
2073 if (calendar->day[row][6] < 15 && row > 3 && calendar->month == 11)
2076 result = week_of_year (&week, &year,
2077 ((calendar->day[row][6] < 15 && row > 3 ? 1 : 0)
2078 + calendar->month) % 12 + 1, calendar->day[row][6]);
2079 g_return_if_fail (result);
2081 /* Translators: this defines whether the week numbers should use
2082 * localized digits or the ones used in English (0123...).
2084 * Translate to "%Id" if you want to use localized digits, or
2085 * translate to "%d" otherwise. Don't include the
2086 * "calendar:week:digits|" part in the translation.
2088 * Note that translating this doesn't guarantee that you get localized
2089 * digits. That needs support from your system and locale definition
2092 g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), week);
2093 pango_layout_set_text (layout, buffer, -1);
2094 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
2096 y_loc = calendar_top_y_for_row (calendar, row) + (day_height - logical_rect.height) / 2;
2098 x_loc = (priv->week_width
2099 - logical_rect.width
2100 - CALENDAR_XSEP - focus_padding - focus_width);
2102 cairo_move_to (cr, x_loc, y_loc);
2103 pango_cairo_show_layout (cr, layout);
2106 g_object_unref (layout);
2111 calendar_invalidate_day_num (GtkCalendar *calendar,
2114 gint r, c, row, col;
2118 for (r = 0; r < 6; r++)
2119 for (c = 0; c < 7; c++)
2120 if (calendar->day_month[r][c] == MONTH_CURRENT &&
2121 calendar->day[r][c] == day)
2127 g_return_if_fail (row != -1);
2128 g_return_if_fail (col != -1);
2130 calendar_invalidate_day (calendar, row, col);
2134 calendar_invalidate_day (GtkCalendar *calendar,
2138 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2142 GdkRectangle day_rect;
2144 calendar_day_rectangle (calendar, row, col, &day_rect);
2145 gdk_window_invalidate_rect (priv->main_win, &day_rect, FALSE);
2150 calendar_paint_day (GtkCalendar *calendar,
2154 GtkWidget *widget = GTK_WIDGET (calendar);
2155 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2157 GdkColor *text_color;
2161 GdkRectangle day_rect;
2163 PangoLayout *layout;
2164 PangoRectangle logical_rect;
2166 g_return_if_fail (row < 6);
2167 g_return_if_fail (col < 7);
2169 cr = gdk_cairo_create (priv->main_win);
2171 day = calendar->day[row][col];
2173 calendar_day_rectangle (calendar, row, col, &day_rect);
2175 if (calendar->day_month[row][col] == MONTH_PREV)
2177 text_color = PREV_MONTH_COLOR (widget);
2179 else if (calendar->day_month[row][col] == MONTH_NEXT)
2181 text_color = NEXT_MONTH_COLOR (widget);
2186 if (calendar->highlight_row == row && calendar->highlight_col == col)
2188 cairo_set_source_color (cr, HIGHLIGHT_BG_COLOR (widget));
2189 gdk_cairo_rectangle (cr, &day_rect);
2193 if (calendar->selected_day == day)
2195 gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
2196 gdk_cairo_rectangle (cr, &day_rect);
2199 if (calendar->selected_day == day)
2200 text_color = SELECTED_FG_COLOR (widget);
2201 else if (calendar->marked_date[day-1])
2202 text_color = MARKED_COLOR (widget);
2204 text_color = NORMAL_DAY_COLOR (widget);
2207 /* Translators: this defines whether the day numbers should use
2208 * localized digits or the ones used in English (0123...).
2210 * Translate to "%Id" if you want to use localized digits, or
2211 * translate to "%d" otherwise. Don't include the "calendar:day:digits|"
2212 * part in the translation.
2214 * Note that translating this doesn't guarantee that you get localized
2215 * digits. That needs support from your system and locale definition
2218 g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), day);
2219 layout = gtk_widget_create_pango_layout (widget, buffer);
2220 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
2222 x_loc = day_rect.x + day_rect.width / 2 + priv->max_day_char_width;
2223 x_loc -= logical_rect.width;
2224 y_loc = day_rect.y + (day_rect.height - logical_rect.height) / 2;
2226 gdk_cairo_set_source_color (cr, text_color);
2227 cairo_move_to (cr, x_loc, y_loc);
2228 pango_cairo_show_layout (cr, layout);
2230 if (calendar->marked_date[day-1]
2231 && calendar->day_month[row][col] == MONTH_CURRENT)
2233 cairo_move_to (cr, x_loc - 1, y_loc);
2234 pango_cairo_show_layout (cr, layout);
2237 if (GTK_WIDGET_HAS_FOCUS (calendar)
2238 && calendar->focus_row == row && calendar->focus_col == col)
2242 if (calendar->selected_day == day)
2243 state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
2245 state = GTK_STATE_NORMAL;
2247 gtk_paint_focus (widget->style,
2251 (calendar->selected_day == day)
2252 ? GTK_STATE_SELECTED : GTK_STATE_NORMAL,
2254 NULL, widget, "calendar-day",
2255 day_rect.x, day_rect.y,
2256 day_rect.width, day_rect.height);
2259 g_object_unref (layout);
2264 calendar_paint_main (GtkCalendar *calendar)
2268 for (col = 0; col < 7; col++)
2269 for (row = 0; row < 6; row++)
2270 calendar_paint_day (calendar, row, col);
2274 calendar_invalidate_arrow (GtkCalendar *calendar,
2277 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2280 window = priv->arrow_win[arrow];
2282 gdk_window_invalidate_rect (window, NULL, FALSE);
2286 calendar_paint_arrow (GtkCalendar *calendar,
2289 GtkWidget *widget = GTK_WIDGET (calendar);
2290 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2293 window = priv->arrow_win[arrow];
2296 cairo_t *cr = gdk_cairo_create (window);
2300 state = priv->arrow_state[arrow];
2302 gdk_cairo_set_source_color (cr, &widget->style->bg[state]);
2306 gdk_drawable_get_size (window, &width, &height);
2307 if (arrow == ARROW_MONTH_LEFT || arrow == ARROW_YEAR_LEFT)
2308 gtk_paint_arrow (widget->style, window, state,
2309 GTK_SHADOW_OUT, NULL, widget, "calendar",
2310 GTK_ARROW_LEFT, TRUE,
2311 width/2 - 3, height/2 - 4, 8, 8);
2313 gtk_paint_arrow (widget->style, window, state,
2314 GTK_SHADOW_OUT, NULL, widget, "calendar",
2315 GTK_ARROW_RIGHT, TRUE,
2316 width/2 - 2, height/2 - 4, 8, 8);
2321 gtk_calendar_expose (GtkWidget *widget,
2322 GdkEventExpose *event)
2324 GtkCalendar *calendar = GTK_CALENDAR (widget);
2325 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2328 if (GTK_WIDGET_DRAWABLE (widget))
2330 if (event->window == priv->main_win)
2331 calendar_paint_main (calendar);
2333 if (event->window == priv->header_win)
2334 calendar_paint_header (calendar);
2336 for (i = 0; i < 4; i++)
2337 if (event->window == priv->arrow_win[i])
2338 calendar_paint_arrow (calendar, i);
2340 if (event->window == priv->day_name_win)
2341 calendar_paint_day_names (calendar);
2343 if (event->window == priv->week_win)
2344 calendar_paint_week_numbers (calendar);
2345 if (event->window == widget->window)
2347 gtk_paint_shadow (widget->style, widget->window, GTK_WIDGET_STATE (widget),
2348 GTK_SHADOW_IN, NULL, widget, "calendar",
2349 0, 0, widget->allocation.width, widget->allocation.height);
2357 /****************************************
2359 ****************************************/
2362 calendar_arrow_action (GtkCalendar *calendar,
2367 case ARROW_YEAR_LEFT:
2368 calendar_set_year_prev (calendar);
2370 case ARROW_YEAR_RIGHT:
2371 calendar_set_year_next (calendar);
2373 case ARROW_MONTH_LEFT:
2374 calendar_set_month_prev (calendar);
2376 case ARROW_MONTH_RIGHT:
2377 calendar_set_month_next (calendar);
2385 calendar_timer (gpointer data)
2387 GtkCalendar *calendar = data;
2388 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2389 gboolean retval = FALSE;
2391 GDK_THREADS_ENTER ();
2395 calendar_arrow_action (calendar, priv->click_child);
2397 if (priv->need_timer)
2399 GtkSettings *settings;
2402 settings = gtk_widget_get_settings (GTK_WIDGET (calendar));
2403 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
2405 priv->need_timer = FALSE;
2406 priv->timer = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
2407 timeout * SCROLL_DELAY_FACTOR,
2408 (GSourceFunc) calendar_timer,
2409 (gpointer) calendar, NULL);
2415 GDK_THREADS_LEAVE ();
2421 calendar_start_spinning (GtkCalendar *calendar,
2424 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2426 priv->click_child = click_child;
2430 GtkSettings *settings;
2433 settings = gtk_widget_get_settings (GTK_WIDGET (calendar));
2434 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
2436 priv->need_timer = TRUE;
2437 priv->timer = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
2439 (GSourceFunc) calendar_timer,
2440 (gpointer) calendar, NULL);
2445 calendar_stop_spinning (GtkCalendar *calendar)
2447 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2451 g_source_remove (priv->timer);
2453 priv->need_timer = FALSE;
2458 calendar_main_button_press (GtkCalendar *calendar,
2459 GdkEventButton *event)
2461 GtkWidget *widget = GTK_WIDGET (calendar);
2462 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2468 x = (gint) (event->x);
2469 y = (gint) (event->y);
2471 row = calendar_row_from_y (calendar, y);
2472 col = calendar_column_from_x (calendar, x);
2474 /* If row or column isn't found, just return. */
2475 if (row == -1 || col == -1)
2478 day_month = calendar->day_month[row][col];
2480 if (event->type == GDK_BUTTON_PRESS)
2482 day = calendar->day[row][col];
2484 if (day_month == MONTH_PREV)
2485 calendar_set_month_prev (calendar);
2486 else if (day_month == MONTH_NEXT)
2487 calendar_set_month_next (calendar);
2489 if (!GTK_WIDGET_HAS_FOCUS (widget))
2490 gtk_widget_grab_focus (widget);
2492 if (event->button == 1)
2495 priv->drag_start_x = x;
2496 priv->drag_start_y = y;
2499 calendar_select_and_focus_day (calendar, day);
2501 else if (event->type == GDK_2BUTTON_PRESS)
2504 if (day_month == MONTH_CURRENT)
2505 g_signal_emit (calendar,
2506 gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL],
2512 gtk_calendar_button_press (GtkWidget *widget,
2513 GdkEventButton *event)
2515 GtkCalendar *calendar = GTK_CALENDAR (widget);
2516 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2519 if (event->window == priv->main_win)
2520 calendar_main_button_press (calendar, event);
2522 if (!GTK_WIDGET_HAS_FOCUS (widget))
2523 gtk_widget_grab_focus (widget);
2525 for (arrow = ARROW_YEAR_LEFT; arrow <= ARROW_MONTH_RIGHT; arrow++)
2527 if (event->window == priv->arrow_win[arrow])
2530 /* only call the action on single click, not double */
2531 if (event->type == GDK_BUTTON_PRESS)
2533 if (event->button == 1)
2534 calendar_start_spinning (calendar, arrow);
2536 calendar_arrow_action (calendar, arrow);
2547 gtk_calendar_button_release (GtkWidget *widget,
2548 GdkEventButton *event)
2550 GtkCalendar *calendar = GTK_CALENDAR (widget);
2551 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2553 if (event->button == 1)
2555 calendar_stop_spinning (calendar);
2565 gtk_calendar_motion_notify (GtkWidget *widget,
2566 GdkEventMotion *event)
2568 GtkCalendar *calendar = GTK_CALENDAR (widget);
2569 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2570 gint event_x, event_y;
2572 gint old_row, old_col;
2574 event_x = (gint) (event->x);
2575 event_y = (gint) (event->y);
2577 if (event->window == priv->main_win)
2582 if (gtk_drag_check_threshold (widget,
2583 priv->drag_start_x, priv->drag_start_y,
2584 event->x, event->y))
2586 GdkDragContext *context;
2587 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
2588 gtk_target_list_add_text_targets (target_list, 0);
2589 context = gtk_drag_begin (widget, target_list, GDK_ACTION_COPY,
2590 1, (GdkEvent *)event);
2595 gtk_target_list_unref (target_list);
2596 gtk_drag_set_icon_default (context);
2601 row = calendar_row_from_y (calendar, event_y);
2602 col = calendar_column_from_x (calendar, event_x);
2604 if (row != calendar->highlight_row || calendar->highlight_col != col)
2606 old_row = calendar->highlight_row;
2607 old_col = calendar->highlight_col;
2608 if (old_row > -1 && old_col > -1)
2610 calendar->highlight_row = -1;
2611 calendar->highlight_col = -1;
2612 calendar_invalidate_day (calendar, old_row, old_col);
2615 calendar->highlight_row = row;
2616 calendar->highlight_col = col;
2618 if (row > -1 && col > -1)
2619 calendar_invalidate_day (calendar, row, col);
2627 gtk_calendar_enter_notify (GtkWidget *widget,
2628 GdkEventCrossing *event)
2630 GtkCalendar *calendar = GTK_CALENDAR (widget);
2631 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2633 if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
2635 priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_PRELIGHT;
2636 calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
2639 if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
2641 priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_PRELIGHT;
2642 calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
2645 if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
2647 priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_PRELIGHT;
2648 calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
2651 if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
2653 priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_PRELIGHT;
2654 calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
2661 gtk_calendar_leave_notify (GtkWidget *widget,
2662 GdkEventCrossing *event)
2664 GtkCalendar *calendar = GTK_CALENDAR (widget);
2665 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2669 if (event->window == priv->main_win)
2671 row = calendar->highlight_row;
2672 col = calendar->highlight_col;
2673 calendar->highlight_row = -1;
2674 calendar->highlight_col = -1;
2675 if (row > -1 && col > -1)
2676 calendar_invalidate_day (calendar, row, col);
2679 if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
2681 priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_NORMAL;
2682 calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
2685 if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
2687 priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_NORMAL;
2688 calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
2691 if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
2693 priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_NORMAL;
2694 calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
2697 if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
2699 priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_NORMAL;
2700 calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
2707 gtk_calendar_scroll (GtkWidget *widget,
2708 GdkEventScroll *event)
2710 GtkCalendar *calendar = GTK_CALENDAR (widget);
2712 if (event->direction == GDK_SCROLL_UP)
2714 if (!GTK_WIDGET_HAS_FOCUS (widget))
2715 gtk_widget_grab_focus (widget);
2716 calendar_set_month_prev (calendar);
2718 else if (event->direction == GDK_SCROLL_DOWN)
2720 if (!GTK_WIDGET_HAS_FOCUS (widget))
2721 gtk_widget_grab_focus (widget);
2722 calendar_set_month_next (calendar);
2731 /****************************************
2733 ****************************************/
2736 move_focus (GtkCalendar *calendar,
2739 GtkTextDirection text_dir = gtk_widget_get_direction (GTK_WIDGET (calendar));
2741 if ((text_dir == GTK_TEXT_DIR_LTR && direction == -1) ||
2742 (text_dir == GTK_TEXT_DIR_RTL && direction == 1))
2744 if (calendar->focus_col > 0)
2745 calendar->focus_col--;
2746 else if (calendar->focus_row > 0)
2748 calendar->focus_col = 6;
2749 calendar->focus_row--;
2754 if (calendar->focus_col < 6)
2755 calendar->focus_col++;
2756 else if (calendar->focus_row < 5)
2758 calendar->focus_col = 0;
2759 calendar->focus_row++;
2765 gtk_calendar_key_press (GtkWidget *widget,
2768 GtkCalendar *calendar;
2774 calendar = GTK_CALENDAR (widget);
2777 old_focus_row = calendar->focus_row;
2778 old_focus_col = calendar->focus_col;
2780 switch (event->keyval)
2785 if (event->state & GDK_CONTROL_MASK)
2786 calendar_set_month_prev (calendar);
2789 move_focus (calendar, -1);
2790 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2791 calendar_invalidate_day (calendar, calendar->focus_row,
2792 calendar->focus_col);
2798 if (event->state & GDK_CONTROL_MASK)
2799 calendar_set_month_next (calendar);
2802 move_focus (calendar, 1);
2803 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2804 calendar_invalidate_day (calendar, calendar->focus_row,
2805 calendar->focus_col);
2811 if (event->state & GDK_CONTROL_MASK)
2812 calendar_set_year_prev (calendar);
2815 if (calendar->focus_row > 0)
2816 calendar->focus_row--;
2817 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2818 calendar_invalidate_day (calendar, calendar->focus_row,
2819 calendar->focus_col);
2825 if (event->state & GDK_CONTROL_MASK)
2826 calendar_set_year_next (calendar);
2829 if (calendar->focus_row < 5)
2830 calendar->focus_row++;
2831 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2832 calendar_invalidate_day (calendar, calendar->focus_row,
2833 calendar->focus_col);
2838 row = calendar->focus_row;
2839 col = calendar->focus_col;
2841 if (row > -1 && col > -1)
2845 day = calendar->day[row][col];
2846 if (calendar->day_month[row][col] == MONTH_PREV)
2847 calendar_set_month_prev (calendar);
2848 else if (calendar->day_month[row][col] == MONTH_NEXT)
2849 calendar_set_month_next (calendar);
2851 calendar_select_and_focus_day (calendar, day);
2859 /****************************************
2860 * Misc widget methods *
2861 ****************************************/
2864 calendar_set_background (GtkWidget *widget)
2866 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2869 if (GTK_WIDGET_REALIZED (widget))
2871 for (i = 0; i < 4; i++)
2873 if (priv->arrow_win[i])
2874 gdk_window_set_background (priv->arrow_win[i],
2875 HEADER_BG_COLOR (widget));
2877 if (priv->header_win)
2878 gdk_window_set_background (priv->header_win,
2879 HEADER_BG_COLOR (widget));
2880 if (priv->day_name_win)
2881 gdk_window_set_background (priv->day_name_win,
2882 BACKGROUND_COLOR (widget));
2884 gdk_window_set_background (priv->week_win,
2885 BACKGROUND_COLOR (widget));
2887 gdk_window_set_background (priv->main_win,
2888 BACKGROUND_COLOR (widget));
2890 gdk_window_set_background (widget->window,
2891 BACKGROUND_COLOR (widget));
2896 gtk_calendar_style_set (GtkWidget *widget,
2897 GtkStyle *previous_style)
2899 if (previous_style && GTK_WIDGET_REALIZED (widget))
2900 calendar_set_background (widget);
2904 gtk_calendar_state_changed (GtkWidget *widget,
2905 GtkStateType previous_state)
2907 GtkCalendar *calendar = GTK_CALENDAR (widget);
2908 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2911 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2914 calendar_stop_spinning (calendar);
2917 for (i = 0; i < 4; i++)
2918 if (GTK_WIDGET_IS_SENSITIVE (widget))
2919 priv->arrow_state[i] = GTK_STATE_NORMAL;
2921 priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
2923 calendar_set_background (widget);
2927 gtk_calendar_grab_notify (GtkWidget *widget,
2928 gboolean was_grabbed)
2931 calendar_stop_spinning (GTK_CALENDAR (widget));
2935 gtk_calendar_focus_out (GtkWidget *widget,
2936 GdkEventFocus *event)
2938 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2940 gtk_widget_queue_draw (widget);
2942 calendar_stop_spinning (GTK_CALENDAR (widget));
2950 /****************************************
2952 ****************************************/
2955 gtk_calendar_drag_data_get (GtkWidget *widget,
2956 GdkDragContext *context,
2957 GtkSelectionData *selection_data,
2961 GtkCalendar *calendar = GTK_CALENDAR (widget);
2966 date = g_date_new_dmy (calendar->selected_day, calendar->month + 1, calendar->year);
2967 len = g_date_strftime (str, 127, "%x", date);
2968 gtk_selection_data_set_text (selection_data, str, len);
2973 /* Get/set whether drag_motion requested the drag data and
2974 * drag_data_received should thus not actually insert the data,
2975 * since the data doesn't result from a drop.
2978 set_status_pending (GdkDragContext *context,
2979 GdkDragAction suggested_action)
2981 g_object_set_data (G_OBJECT (context),
2982 I_("gtk-calendar-status-pending"),
2983 GINT_TO_POINTER (suggested_action));
2986 static GdkDragAction
2987 get_status_pending (GdkDragContext *context)
2989 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
2990 "gtk-calendar-status-pending"));
2994 gtk_calendar_drag_leave (GtkWidget *widget,
2995 GdkDragContext *context,
2998 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
3000 priv->drag_highlight = 0;
3001 gtk_drag_unhighlight (widget);
3006 gtk_calendar_drag_motion (GtkWidget *widget,
3007 GdkDragContext *context,
3012 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
3015 if (!priv->drag_highlight)
3017 priv->drag_highlight = 1;
3018 gtk_drag_highlight (widget);
3021 target = gtk_drag_dest_find_target (widget, context, NULL);
3022 if (target == GDK_NONE || context->suggested_action == 0)
3023 gdk_drag_status (context, 0, time);
3026 set_status_pending (context, context->suggested_action);
3027 gtk_drag_get_data (widget, context, target, time);
3034 gtk_calendar_drag_drop (GtkWidget *widget,
3035 GdkDragContext *context,
3042 target = gtk_drag_dest_find_target (widget, context, NULL);
3043 if (target != GDK_NONE)
3045 gtk_drag_get_data (widget, context,
3055 gtk_calendar_drag_data_received (GtkWidget *widget,
3056 GdkDragContext *context,
3059 GtkSelectionData *selection_data,
3063 GtkCalendar *calendar = GTK_CALENDAR (widget);
3064 guint day, month, year;
3067 GdkDragAction suggested_action;
3069 suggested_action = get_status_pending (context);
3071 if (suggested_action)
3073 set_status_pending (context, 0);
3075 /* We are getting this data due to a request in drag_motion,
3076 * rather than due to a request in drag_drop, so we are just
3077 * supposed to call drag_status, not actually paste in the
3080 str = gtk_selection_data_get_text (selection_data);
3083 date = g_date_new ();
3084 g_date_set_parse (date, str);
3085 if (!g_date_valid (date))
3086 suggested_action = 0;
3091 suggested_action = 0;
3093 gdk_drag_status (context, suggested_action, time);
3098 date = g_date_new ();
3099 str = gtk_selection_data_get_text (selection_data);
3102 g_date_set_parse (date, str);
3106 if (!g_date_valid (date))
3108 g_warning ("Received invalid date data\n");
3110 gtk_drag_finish (context, FALSE, FALSE, time);
3114 day = g_date_get_day (date);
3115 month = g_date_get_month (date);
3116 year = g_date_get_year (date);
3119 gtk_drag_finish (context, TRUE, FALSE, time);
3122 g_object_freeze_notify (G_OBJECT (calendar));
3123 if (!(calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
3124 && (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING))
3125 gtk_calendar_select_month (calendar, month - 1, year);
3126 gtk_calendar_select_day (calendar, day);
3127 g_object_thaw_notify (G_OBJECT (calendar));
3131 /****************************************
3133 ****************************************/
3138 * Creates a new calendar, with the current date being selected.
3140 * Return value: a newly #GtkCalendar widget
3143 gtk_calendar_new (void)
3145 return g_object_new (GTK_TYPE_CALENDAR, NULL);
3149 * gtk_calendar_display_options:
3150 * @calendar: a #GtkCalendar.
3151 * @flags: the display options to set.
3153 * Sets display options (whether to display the heading and the month headings).
3155 * Deprecated: 2.4: Use gtk_calendar_set_display_options() instead
3158 gtk_calendar_display_options (GtkCalendar *calendar,
3159 GtkCalendarDisplayOptions flags)
3161 gtk_calendar_set_display_options (calendar, flags);
3165 * gtk_calendar_get_display_options:
3166 * @calendar: a #GtkCalendar
3168 * Returns the current display options of @calendar.
3170 * Return value: the display options.
3174 GtkCalendarDisplayOptions
3175 gtk_calendar_get_display_options (GtkCalendar *calendar)
3177 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
3179 return calendar->display_flags;
3183 * gtk_calendar_set_display_options:
3184 * @calendar: a #GtkCalendar
3185 * @flags: the display options to set
3187 * Sets display options (whether to display the heading and the month
3193 gtk_calendar_set_display_options (GtkCalendar *calendar,
3194 GtkCalendarDisplayOptions flags)
3196 GtkWidget *widget = GTK_WIDGET (calendar);
3197 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
3200 GtkCalendarDisplayOptions old_flags;
3202 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3204 old_flags = calendar->display_flags;
3206 if (GTK_WIDGET_REALIZED (widget))
3208 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
3211 if (! (flags & GTK_CALENDAR_NO_MONTH_CHANGE)
3212 && (priv->header_win))
3214 calendar->display_flags &= ~GTK_CALENDAR_NO_MONTH_CHANGE;
3215 calendar_realize_arrows (calendar);
3219 for (i = 0; i < 4; i++)
3221 if (priv->arrow_win[i])
3223 gdk_window_set_user_data (priv->arrow_win[i],
3225 gdk_window_destroy (priv->arrow_win[i]);
3226 priv->arrow_win[i] = NULL;
3232 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_HEADING)
3236 if (flags & GTK_CALENDAR_SHOW_HEADING)
3238 calendar->display_flags |= GTK_CALENDAR_SHOW_HEADING;
3239 calendar_realize_header (calendar);
3243 for (i = 0; i < 4; i++)
3245 if (priv->arrow_win[i])
3247 gdk_window_set_user_data (priv->arrow_win[i],
3249 gdk_window_destroy (priv->arrow_win[i]);
3250 priv->arrow_win[i] = NULL;
3253 gdk_window_set_user_data (priv->header_win, NULL);
3254 gdk_window_destroy (priv->header_win);
3255 priv->header_win = NULL;
3260 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
3264 if (flags & GTK_CALENDAR_SHOW_DAY_NAMES)
3266 calendar->display_flags |= GTK_CALENDAR_SHOW_DAY_NAMES;
3267 calendar_realize_day_names (calendar);
3271 gdk_window_set_user_data (priv->day_name_win, NULL);
3272 gdk_window_destroy (priv->day_name_win);
3273 priv->day_name_win = NULL;
3277 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
3281 if (flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
3283 calendar->display_flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS;
3284 calendar_realize_week_numbers (calendar);
3288 gdk_window_set_user_data (priv->week_win, NULL);
3289 gdk_window_destroy (priv->week_win);
3290 priv->week_win = NULL;
3294 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_WEEK_START_MONDAY)
3295 g_warning ("GTK_CALENDAR_WEEK_START_MONDAY is ignored; the first day of the week is determined from the locale");
3297 calendar->display_flags = flags;
3299 gtk_widget_queue_resize (GTK_WIDGET (calendar));
3303 calendar->display_flags = flags;
3305 g_object_freeze_notify (G_OBJECT (calendar));
3306 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_HEADING)
3307 g_object_notify (G_OBJECT (calendar), "show-heading");
3308 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
3309 g_object_notify (G_OBJECT (calendar), "show-day-names");
3310 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
3311 g_object_notify (G_OBJECT (calendar), "no-month-change");
3312 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
3313 g_object_notify (G_OBJECT (calendar), "show-week-numbers");
3314 g_object_thaw_notify (G_OBJECT (calendar));
3318 * gtk_calendar_select_month:
3319 * @calendar: a #GtkCalendar
3320 * @month: a month number between 0 and 11.
3321 * @year: the year the month is in.
3323 * Shifts the calendar to a different month.
3325 * Return value: %TRUE, always
3328 gtk_calendar_select_month (GtkCalendar *calendar,
3332 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
3333 g_return_val_if_fail (month <= 11, FALSE);
3335 calendar->month = month;
3336 calendar->year = year;
3338 calendar_compute_days (calendar);
3340 gtk_widget_queue_draw (GTK_WIDGET (calendar));
3342 g_object_freeze_notify (G_OBJECT (calendar));
3343 g_object_notify (G_OBJECT (calendar), "month");
3344 g_object_notify (G_OBJECT (calendar), "year");
3345 g_object_thaw_notify (G_OBJECT (calendar));
3347 g_signal_emit (calendar,
3348 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
3354 * gtk_calendar_select_day:
3355 * @calendar: a #GtkCalendar.
3356 * @day: the day number between 1 and 31, or 0 to unselect
3357 * the currently selected day.
3359 * Selects a day from the current month.
3362 gtk_calendar_select_day (GtkCalendar *calendar,
3365 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3366 g_return_if_fail (day <= 31);
3368 /* Deselect the old day */
3369 if (calendar->selected_day > 0)
3373 selected_day = calendar->selected_day;
3374 calendar->selected_day = 0;
3375 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
3376 calendar_invalidate_day_num (calendar, selected_day);
3379 calendar->selected_day = day;
3381 /* Select the new day */
3384 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
3385 calendar_invalidate_day_num (calendar, day);
3388 g_object_notify (G_OBJECT (calendar), "day");
3390 g_signal_emit (calendar,
3391 gtk_calendar_signals[DAY_SELECTED_SIGNAL],
3396 * gtk_calendar_clear_marks:
3397 * @calendar: a #GtkCalendar
3399 * Remove all visual markers.
3402 gtk_calendar_clear_marks (GtkCalendar *calendar)
3406 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3408 for (day = 0; day < 31; day++)
3410 calendar->marked_date[day] = FALSE;
3413 calendar->num_marked_dates = 0;
3415 gtk_widget_queue_draw (GTK_WIDGET (calendar));
3419 * gtk_calendar_mark_day:
3420 * @calendar: a #GtkCalendar
3421 * @day: the day number to mark between 1 and 31.
3423 * Places a visual marker on a particular day.
3425 * Return value: %TRUE, always
3428 gtk_calendar_mark_day (GtkCalendar *calendar,
3431 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
3433 if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == FALSE)
3435 calendar->marked_date[day - 1] = TRUE;
3436 calendar->num_marked_dates++;
3437 calendar_invalidate_day_num (calendar, day);
3444 * gtk_calendar_unmark_day:
3445 * @calendar: a #GtkCalendar.
3446 * @day: the day number to unmark between 1 and 31.
3448 * Removes the visual marker from a particular day.
3450 * Return value: %TRUE, always
3453 gtk_calendar_unmark_day (GtkCalendar *calendar,
3456 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
3458 if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == TRUE)
3460 calendar->marked_date[day - 1] = FALSE;
3461 calendar->num_marked_dates--;
3462 calendar_invalidate_day_num (calendar, day);
3469 * gtk_calendar_get_date:
3470 * @calendar: a #GtkCalendar
3471 * @year: location to store the year number, or %NULL
3472 * @month: location to store the month number (between 0 and 11), or %NULL
3473 * @day: location to store the day number (between 1 and 31), or %NULL
3475 * Obtains the selected date from a #GtkCalendar.
3478 gtk_calendar_get_date (GtkCalendar *calendar,
3483 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3486 *year = calendar->year;
3489 *month = calendar->month;
3492 *day = calendar->selected_day;
3496 * gtk_calendar_freeze:
3497 * @calendar: a #GtkCalendar
3499 * Does nothing. Previously locked the display of the calendar until
3500 * it was thawed with gtk_calendar_thaw().
3505 gtk_calendar_freeze (GtkCalendar *calendar)
3507 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3511 * gtk_calendar_thaw:
3512 * @calendar: a #GtkCalendar
3514 * Does nothing. Previously defrosted a calendar; all the changes made
3515 * since the last gtk_calendar_freeze() were displayed.
3520 gtk_calendar_thaw (GtkCalendar *calendar)
3522 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3525 #define __GTK_CALENDAR_C__
3526 #include "gtkaliasdef.c"