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->text[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->text[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
571 union { unsigned int word; char *string; } langinfo;
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 priv->week_start = 0;
680 if (GetLocaleInfoW (GetThreadLocale (), LOCALE_IFIRSTDAYOFWEEK,
681 wbuffer, G_N_ELEMENTS (wbuffer)))
682 week_start = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
684 if (week_start != NULL)
686 priv->week_start = (week_start[0] - '0' + 1) % 7;
690 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
691 langinfo.string = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
692 first_weekday = langinfo.string[0];
693 langinfo.string = nl_langinfo (_NL_TIME_WEEK_1STDAY);
694 week_origin = langinfo.word;
695 if (week_origin == 19971130) /* Sunday */
697 else if (week_origin == 19971201) /* Monday */
700 g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");
702 priv->week_start = (week_1stday + first_weekday - 1) % 7;
704 /* Translate to calendar:week_start:0 if you want Sunday to be the
705 * first day of the week to calendar:week_start:1 if you want Monday
706 * to be the first day of the week, and so on.
708 week_start = _("calendar:week_start:0");
710 if (strncmp (week_start, "calendar:week_start:", 20) == 0)
711 priv->week_start = *(week_start + 20) - '0';
713 priv->week_start = -1;
715 if (priv->week_start < 0 || priv->week_start > 6)
717 g_warning ("Whoever translated calendar:week_start:0 did so wrongly.\n");
718 priv->week_start = 0;
723 calendar_compute_days (calendar);
727 /****************************************
728 * Utility Functions *
729 ****************************************/
732 calendar_set_month_next (GtkCalendar *calendar)
736 g_return_if_fail (GTK_IS_WIDGET (calendar));
738 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
742 if (calendar->month == 11)
750 calendar_compute_days (calendar);
751 g_signal_emit (calendar,
752 gtk_calendar_signals[NEXT_MONTH_SIGNAL],
754 g_signal_emit (calendar,
755 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
758 month_len = month_length[leap (calendar->year)][calendar->month + 1];
760 if (month_len < calendar->selected_day)
762 calendar->selected_day = 0;
763 gtk_calendar_select_day (calendar, month_len);
766 gtk_calendar_select_day (calendar, calendar->selected_day);
768 gtk_widget_queue_draw (GTK_WIDGET (calendar));
772 calendar_set_year_prev (GtkCalendar *calendar)
776 g_return_if_fail (GTK_IS_WIDGET (calendar));
779 calendar_compute_days (calendar);
780 g_signal_emit (calendar,
781 gtk_calendar_signals[PREV_YEAR_SIGNAL],
783 g_signal_emit (calendar,
784 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
787 month_len = month_length[leap (calendar->year)][calendar->month + 1];
789 if (month_len < calendar->selected_day)
791 calendar->selected_day = 0;
792 gtk_calendar_select_day (calendar, month_len);
795 gtk_calendar_select_day (calendar, calendar->selected_day);
797 gtk_widget_queue_draw (GTK_WIDGET (calendar));
801 calendar_set_year_next (GtkCalendar *calendar)
805 g_return_if_fail (GTK_IS_WIDGET (calendar));
808 calendar_compute_days (calendar);
809 g_signal_emit (calendar,
810 gtk_calendar_signals[NEXT_YEAR_SIGNAL],
812 g_signal_emit (calendar,
813 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
816 month_len = month_length[leap (calendar->year)][calendar->month + 1];
818 if (month_len < calendar->selected_day)
820 calendar->selected_day = 0;
821 gtk_calendar_select_day (calendar, month_len);
824 gtk_calendar_select_day (calendar, calendar->selected_day);
826 gtk_widget_queue_draw (GTK_WIDGET (calendar));
830 calendar_compute_days (GtkCalendar *calendar)
832 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (GTK_WIDGET (calendar));
836 gint ndays_in_prev_month;
842 g_return_if_fail (GTK_IS_CALENDAR (calendar));
844 year = calendar->year;
845 month = calendar->month + 1;
847 ndays_in_month = month_length[leap (year)][month];
849 first_day = day_of_week (year, month, 1);
850 first_day = (first_day + 7 - priv->week_start) % 7;
852 /* Compute days of previous month */
854 ndays_in_prev_month = month_length[leap (year)][month-1];
856 ndays_in_prev_month = month_length[leap (year)][12];
857 day = ndays_in_prev_month - first_day + 1;
862 for (col = 0; col < first_day; col++)
864 calendar->day[row][col] = day;
865 calendar->day_month[row][col] = MONTH_PREV;
870 /* Compute days of current month */
872 for (day = 1; day <= ndays_in_month; day++)
874 calendar->day[row][col] = day;
875 calendar->day_month[row][col] = MONTH_CURRENT;
885 /* Compute days of next month */
887 for (; row <= 5; row++)
889 for (; col <= 6; col++)
891 calendar->day[row][col] = day;
892 calendar->day_month[row][col] = MONTH_NEXT;
900 calendar_select_and_focus_day (GtkCalendar *calendar,
903 gint old_focus_row = calendar->focus_row;
904 gint old_focus_col = calendar->focus_col;
908 for (row = 0; row < 6; row ++)
909 for (col = 0; col < 7; col++)
911 if (calendar->day_month[row][col] == MONTH_CURRENT
912 && calendar->day[row][col] == day)
914 calendar->focus_row = row;
915 calendar->focus_col = col;
919 if (old_focus_row != -1 && old_focus_col != -1)
920 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
922 gtk_calendar_select_day (calendar, day);
926 /****************************************
927 * Layout computation utilities *
928 ****************************************/
931 calendar_row_height (GtkCalendar *calendar)
933 return (GTK_CALENDAR_GET_PRIVATE (calendar)->main_h - CALENDAR_MARGIN
934 - ((calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
935 ? CALENDAR_YSEP : CALENDAR_MARGIN)) / 6;
939 /* calendar_left_x_for_column: returns the x coordinate
940 * for the left of the column */
942 calendar_left_x_for_column (GtkCalendar *calendar,
948 if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
951 width = GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
952 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
953 x_left = CALENDAR_XSEP + (width + DAY_XSEP) * column;
955 x_left = CALENDAR_MARGIN + (width + DAY_XSEP) * column;
960 /* column_from_x: returns the column 0-6 that the
961 * x pixel of the xwindow is in */
963 calendar_column_from_x (GtkCalendar *calendar,
967 gint x_left, x_right;
971 for (c = 0; c < 7; c++)
973 x_left = calendar_left_x_for_column (calendar, c);
974 x_right = x_left + GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
976 if (event_x >= x_left && event_x < x_right)
986 /* calendar_top_y_for_row: returns the y coordinate
987 * for the top of the row */
989 calendar_top_y_for_row (GtkCalendar *calendar,
993 return (GTK_CALENDAR_GET_PRIVATE (calendar)->main_h
994 - (CALENDAR_MARGIN + (6 - row)
995 * calendar_row_height (calendar)));
998 /* row_from_y: returns the row 0-5 that the
999 * y pixel of the xwindow is in */
1001 calendar_row_from_y (GtkCalendar *calendar,
1006 gint y_top, y_bottom;
1008 height = calendar_row_height (calendar);
1011 for (r = 0; r < 6; r++)
1013 y_top = calendar_top_y_for_row (calendar, r);
1014 y_bottom = y_top + height;
1016 if (event_y >= y_top && event_y < y_bottom)
1027 calendar_arrow_rectangle (GtkCalendar *calendar,
1031 GtkWidget *widget = GTK_WIDGET (calendar);
1032 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1035 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1036 year_left = priv->year_before;
1038 year_left = !priv->year_before;
1041 rect->width = priv->arrow_width;
1042 rect->height = priv->header_h - 7;
1046 case ARROW_MONTH_LEFT:
1048 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1049 - (3 + 2*priv->arrow_width
1050 + priv->max_month_width));
1054 case ARROW_MONTH_RIGHT:
1056 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1057 - 3 - priv->arrow_width);
1059 rect->x = (priv->arrow_width
1060 + priv->max_month_width);
1062 case ARROW_YEAR_LEFT:
1066 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1067 - (3 + 2*priv->arrow_width
1068 + priv->max_year_width));
1070 case ARROW_YEAR_RIGHT:
1072 rect->x = (priv->arrow_width
1073 + priv->max_year_width);
1075 rect->x = (widget->allocation.width - 2 * widget->style->xthickness
1076 - 3 - priv->arrow_width);
1082 calendar_day_rectangle (GtkCalendar *calendar,
1087 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1089 rect->x = calendar_left_x_for_column (calendar, col);
1090 rect->y = calendar_top_y_for_row (calendar, row);
1091 rect->height = calendar_row_height (calendar);
1092 rect->width = priv->day_width;
1096 calendar_set_month_prev (GtkCalendar *calendar)
1100 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1103 if (calendar->month == 0)
1105 calendar->month = 11;
1111 month_len = month_length[leap (calendar->year)][calendar->month + 1];
1113 calendar_compute_days (calendar);
1115 g_signal_emit (calendar,
1116 gtk_calendar_signals[PREV_MONTH_SIGNAL],
1118 g_signal_emit (calendar,
1119 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
1122 if (month_len < calendar->selected_day)
1124 calendar->selected_day = 0;
1125 gtk_calendar_select_day (calendar, month_len);
1129 if (calendar->selected_day < 0)
1130 calendar->selected_day = calendar->selected_day + 1 + month_length[leap (calendar->year)][calendar->month + 1];
1131 gtk_calendar_select_day (calendar, calendar->selected_day);
1134 gtk_widget_queue_draw (GTK_WIDGET (calendar));
1138 /****************************************
1139 * Basic object methods *
1140 ****************************************/
1143 gtk_calendar_finalize (GObject *object)
1145 (* G_OBJECT_CLASS (gtk_calendar_parent_class)->finalize) (object);
1149 gtk_calendar_destroy (GtkObject *object)
1151 calendar_stop_spinning (GTK_CALENDAR (object));
1153 GTK_OBJECT_CLASS (gtk_calendar_parent_class)->destroy (object);
1158 calendar_set_display_option (GtkCalendar *calendar,
1159 GtkCalendarDisplayOptions flag,
1162 GtkCalendarDisplayOptions flags;
1164 flags = calendar->display_flags | flag;
1166 flags = calendar->display_flags & ~flag;
1167 gtk_calendar_display_options (calendar, flags);
1171 calendar_get_display_option (GtkCalendar *calendar,
1172 GtkCalendarDisplayOptions flag)
1174 return (calendar->display_flags & flag) != 0;
1178 gtk_calendar_set_property (GObject *object,
1180 const GValue *value,
1183 GtkCalendar *calendar;
1185 calendar = GTK_CALENDAR (object);
1190 gtk_calendar_select_month (calendar,
1192 g_value_get_int (value));
1195 gtk_calendar_select_month (calendar,
1196 g_value_get_int (value),
1200 gtk_calendar_select_day (calendar,
1201 g_value_get_int (value));
1203 case PROP_SHOW_HEADING:
1204 calendar_set_display_option (calendar,
1205 GTK_CALENDAR_SHOW_HEADING,
1206 g_value_get_boolean (value));
1208 case PROP_SHOW_DAY_NAMES:
1209 calendar_set_display_option (calendar,
1210 GTK_CALENDAR_SHOW_DAY_NAMES,
1211 g_value_get_boolean (value));
1213 case PROP_NO_MONTH_CHANGE:
1214 calendar_set_display_option (calendar,
1215 GTK_CALENDAR_NO_MONTH_CHANGE,
1216 g_value_get_boolean (value));
1218 case PROP_SHOW_WEEK_NUMBERS:
1219 calendar_set_display_option (calendar,
1220 GTK_CALENDAR_SHOW_WEEK_NUMBERS,
1221 g_value_get_boolean (value));
1224 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1230 gtk_calendar_get_property (GObject *object,
1235 GtkCalendar *calendar;
1237 calendar = GTK_CALENDAR (object);
1242 g_value_set_int (value, calendar->year);
1245 g_value_set_int (value, calendar->month);
1248 g_value_set_int (value, calendar->selected_day);
1250 case PROP_SHOW_HEADING:
1251 g_value_set_boolean (value, calendar_get_display_option (calendar,
1252 GTK_CALENDAR_SHOW_HEADING));
1254 case PROP_SHOW_DAY_NAMES:
1255 g_value_set_boolean (value, calendar_get_display_option (calendar,
1256 GTK_CALENDAR_SHOW_DAY_NAMES));
1258 case PROP_NO_MONTH_CHANGE:
1259 g_value_set_boolean (value, calendar_get_display_option (calendar,
1260 GTK_CALENDAR_NO_MONTH_CHANGE));
1262 case PROP_SHOW_WEEK_NUMBERS:
1263 g_value_set_boolean (value, calendar_get_display_option (calendar,
1264 GTK_CALENDAR_SHOW_WEEK_NUMBERS));
1267 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1273 /****************************************
1275 ****************************************/
1278 calendar_realize_arrows (GtkCalendar *calendar)
1280 GtkWidget *widget = GTK_WIDGET (calendar);
1281 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1282 GdkWindowAttr attributes;
1283 gint attributes_mask;
1286 /* Arrow windows ------------------------------------- */
1287 if (! (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1288 && (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING))
1290 attributes.wclass = GDK_INPUT_OUTPUT;
1291 attributes.window_type = GDK_WINDOW_CHILD;
1292 attributes.visual = gtk_widget_get_visual (widget);
1293 attributes.colormap = gtk_widget_get_colormap (widget);
1294 attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
1295 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
1296 | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
1297 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1298 for (i = 0; i < 4; i++)
1301 calendar_arrow_rectangle (calendar, i, &rect);
1303 attributes.x = rect.x;
1304 attributes.y = rect.y;
1305 attributes.width = rect.width;
1306 attributes.height = rect.height;
1307 priv->arrow_win[i] = gdk_window_new (priv->header_win,
1310 if (GTK_WIDGET_IS_SENSITIVE (widget))
1311 priv->arrow_state[i] = GTK_STATE_NORMAL;
1313 priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
1314 gdk_window_set_background (priv->arrow_win[i],
1315 HEADER_BG_COLOR (GTK_WIDGET (calendar)));
1316 gdk_window_show (priv->arrow_win[i]);
1317 gdk_window_set_user_data (priv->arrow_win[i], widget);
1322 for (i = 0; i < 4; i++)
1323 priv->arrow_win[i] = NULL;
1328 calendar_realize_header (GtkCalendar *calendar)
1330 GtkWidget *widget = GTK_WIDGET (calendar);
1331 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1332 GdkWindowAttr attributes;
1333 gint attributes_mask;
1335 /* Header window ------------------------------------- */
1336 if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
1338 attributes.wclass = GDK_INPUT_OUTPUT;
1339 attributes.window_type = GDK_WINDOW_CHILD;
1340 attributes.visual = gtk_widget_get_visual (widget);
1341 attributes.colormap = gtk_widget_get_colormap (widget);
1342 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1343 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1344 attributes.x = widget->style->xthickness;
1345 attributes.y = widget->style->ythickness;
1346 attributes.width = widget->allocation.width - 2 * attributes.x;
1347 attributes.height = priv->header_h - 2 * attributes.y;
1348 priv->header_win = gdk_window_new (widget->window,
1349 &attributes, attributes_mask);
1351 gdk_window_set_background (priv->header_win,
1352 HEADER_BG_COLOR (GTK_WIDGET (calendar)));
1353 gdk_window_show (priv->header_win);
1354 gdk_window_set_user_data (priv->header_win, widget);
1359 priv->header_win = NULL;
1361 calendar_realize_arrows (calendar);
1365 calendar_realize_day_names (GtkCalendar *calendar)
1367 GtkWidget *widget = GTK_WIDGET (calendar);
1368 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1369 GdkWindowAttr attributes;
1370 gint attributes_mask;
1372 /* Day names window --------------------------------- */
1373 if ( calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
1375 attributes.wclass = GDK_INPUT_OUTPUT;
1376 attributes.window_type = GDK_WINDOW_CHILD;
1377 attributes.visual = gtk_widget_get_visual (widget);
1378 attributes.colormap = gtk_widget_get_colormap (widget);
1379 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1380 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1381 attributes.x = (widget->style->xthickness + INNER_BORDER);
1382 attributes.y = priv->header_h + (widget->style->ythickness
1384 attributes.width = (widget->allocation.width
1385 - (widget->style->xthickness + INNER_BORDER)
1387 attributes.height = priv->day_name_h;
1388 priv->day_name_win = gdk_window_new (widget->window,
1391 gdk_window_set_background (priv->day_name_win,
1392 BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
1393 gdk_window_show (priv->day_name_win);
1394 gdk_window_set_user_data (priv->day_name_win, widget);
1398 priv->day_name_win = NULL;
1403 calendar_realize_week_numbers (GtkCalendar *calendar)
1405 GtkWidget *widget = GTK_WIDGET (calendar);
1406 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1407 GdkWindowAttr attributes;
1408 gint attributes_mask;
1410 /* Week number window -------------------------------- */
1411 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1413 attributes.wclass = GDK_INPUT_OUTPUT;
1414 attributes.window_type = GDK_WINDOW_CHILD;
1415 attributes.visual = gtk_widget_get_visual (widget);
1416 attributes.colormap = gtk_widget_get_colormap (widget);
1417 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
1419 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1420 attributes.x = widget->style->xthickness + INNER_BORDER;
1421 attributes.y = (priv->header_h + priv->day_name_h
1422 + (widget->style->ythickness + INNER_BORDER));
1423 attributes.width = priv->week_width;
1424 attributes.height = priv->main_h;
1425 priv->week_win = gdk_window_new (widget->window,
1426 &attributes, attributes_mask);
1427 gdk_window_set_background (priv->week_win,
1428 BACKGROUND_COLOR (GTK_WIDGET (calendar)));
1429 gdk_window_show (priv->week_win);
1430 gdk_window_set_user_data (priv->week_win, widget);
1434 priv->week_win = NULL;
1439 gtk_calendar_realize (GtkWidget *widget)
1441 GtkCalendar *calendar = GTK_CALENDAR (widget);
1442 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1443 GdkWindowAttr attributes;
1444 gint attributes_mask;
1446 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1448 attributes.x = widget->allocation.x;
1449 attributes.y = widget->allocation.y;
1450 attributes.width = widget->allocation.width;
1451 attributes.height = widget->allocation.height;
1452 attributes.wclass = GDK_INPUT_OUTPUT;
1453 attributes.window_type = GDK_WINDOW_CHILD;
1454 attributes.event_mask = (gtk_widget_get_events (widget)
1455 | GDK_EXPOSURE_MASK |GDK_KEY_PRESS_MASK | GDK_SCROLL_MASK);
1456 attributes.visual = gtk_widget_get_visual (widget);
1457 attributes.colormap = gtk_widget_get_colormap (widget);
1459 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1460 widget->window = gdk_window_new (widget->parent->window,
1461 &attributes, attributes_mask);
1463 widget->style = gtk_style_attach (widget->style, widget->window);
1465 /* Header window ------------------------------------- */
1466 calendar_realize_header (calendar);
1467 /* Day names window --------------------------------- */
1468 calendar_realize_day_names (calendar);
1469 /* Week number window -------------------------------- */
1470 calendar_realize_week_numbers (calendar);
1471 /* Main Window -------------------------------------- */
1472 attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
1473 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
1474 | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
1476 attributes.x = priv->week_width + (widget->style->ythickness + INNER_BORDER);
1477 attributes.y = (priv->header_h + priv->day_name_h
1478 + (widget->style->ythickness + INNER_BORDER));
1479 attributes.width = (widget->allocation.width - attributes.x
1480 - (widget->style->xthickness + INNER_BORDER));
1481 attributes.height = priv->main_h;
1482 priv->main_win = gdk_window_new (widget->window,
1483 &attributes, attributes_mask);
1484 gdk_window_set_background (priv->main_win,
1485 BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
1486 gdk_window_show (priv->main_win);
1487 gdk_window_set_user_data (priv->main_win, widget);
1488 gdk_window_set_background (widget->window, BACKGROUND_COLOR (widget));
1489 gdk_window_show (widget->window);
1490 gdk_window_set_user_data (widget->window, widget);
1494 gtk_calendar_unrealize (GtkWidget *widget)
1496 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1499 if (priv->header_win)
1501 for (i = 0; i < 4; i++)
1503 if (priv->arrow_win[i])
1505 gdk_window_set_user_data (priv->arrow_win[i], NULL);
1506 gdk_window_destroy (priv->arrow_win[i]);
1507 priv->arrow_win[i] = NULL;
1510 gdk_window_set_user_data (priv->header_win, NULL);
1511 gdk_window_destroy (priv->header_win);
1512 priv->header_win = NULL;
1517 gdk_window_set_user_data (priv->week_win, NULL);
1518 gdk_window_destroy (priv->week_win);
1519 priv->week_win = NULL;
1524 gdk_window_set_user_data (priv->main_win, NULL);
1525 gdk_window_destroy (priv->main_win);
1526 priv->main_win = NULL;
1528 if (priv->day_name_win)
1530 gdk_window_set_user_data (priv->day_name_win, NULL);
1531 gdk_window_destroy (priv->day_name_win);
1532 priv->day_name_win = NULL;
1535 if (GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize)
1536 (* GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize) (widget);
1540 /****************************************
1541 * Size Request and Allocate *
1542 ****************************************/
1545 gtk_calendar_size_request (GtkWidget *widget,
1546 GtkRequisition *requisition)
1548 GtkCalendar *calendar = GTK_CALENDAR (widget);
1549 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1550 PangoLayout *layout;
1551 PangoRectangle logical_rect;
1555 gint calendar_margin = CALENDAR_MARGIN;
1556 gint header_width, main_width;
1557 gint max_header_height = 0;
1561 gtk_widget_style_get (GTK_WIDGET (widget),
1562 "focus-line-width", &focus_width,
1563 "focus-padding", &focus_padding,
1566 layout = gtk_widget_create_pango_layout (widget, NULL);
1569 * Calculate the requisition width for the widget.
1574 if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
1576 priv->max_month_width = 0;
1577 for (i = 0; i < 12; i++)
1579 pango_layout_set_text (layout, default_monthname[i], -1);
1580 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1581 priv->max_month_width = MAX (priv->max_month_width,
1582 logical_rect.width + 8);
1583 max_header_height = MAX (max_header_height, logical_rect.height);
1586 priv->max_year_width = 0;
1587 /* Translators: This is a text measurement template.
1588 * Translate it to the widest year text.
1590 * Don't include the prefix "year measurement template|"
1591 * in the translation.
1593 * If you don't understand this, leave it as "2000"
1595 pango_layout_set_text (layout, Q_("year measurement template|2000"), -1);
1596 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1597 priv->max_year_width = MAX (priv->max_year_width,
1598 logical_rect.width + 8);
1599 max_header_height = MAX (max_header_height, logical_rect.height);
1603 priv->max_month_width = 0;
1604 priv->max_year_width = 0;
1607 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1608 header_width = (priv->max_month_width
1609 + priv->max_year_width
1612 header_width = (priv->max_month_width
1613 + priv->max_year_width
1614 + 4 * priv->arrow_width + 3 * 3);
1616 /* Mainwindow labels width */
1618 priv->max_day_char_width = 0;
1619 priv->max_day_char_ascent = 0;
1620 priv->max_day_char_descent = 0;
1621 priv->min_day_width = 0;
1623 for (i = 0; i < 9; i++)
1626 g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), i * 11);
1627 pango_layout_set_text (layout, buffer, -1);
1628 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1629 priv->min_day_width = MAX (priv->min_day_width,
1630 logical_rect.width);
1632 priv->max_day_char_ascent = MAX (priv->max_day_char_ascent,
1633 PANGO_ASCENT (logical_rect));
1634 priv->max_day_char_descent = MAX (priv->max_day_char_descent,
1635 PANGO_DESCENT (logical_rect));
1637 /* We add one to max_day_char_width to be able to make the marked day "bold" */
1638 priv->max_day_char_width = priv->min_day_width / 2 + 1;
1640 priv->max_label_char_ascent = 0;
1641 priv->max_label_char_descent = 0;
1642 if (calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
1643 for (i = 0; i < 7; i++)
1645 pango_layout_set_text (layout, default_abbreviated_dayname[i], -1);
1646 pango_layout_line_get_pixel_extents (pango_layout_get_lines_readonly (layout)->data, NULL, &logical_rect);
1648 priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
1649 priv->max_label_char_ascent = MAX (priv->max_label_char_ascent,
1650 PANGO_ASCENT (logical_rect));
1651 priv->max_label_char_descent = MAX (priv->max_label_char_descent,
1652 PANGO_DESCENT (logical_rect));
1655 priv->max_week_char_width = 0;
1656 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1657 for (i = 0; i < 9; i++)
1660 g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), i * 11);
1661 pango_layout_set_text (layout, buffer, -1);
1662 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1663 priv->max_week_char_width = MAX (priv->max_week_char_width,
1664 logical_rect.width / 2);
1667 main_width = (7 * (priv->min_day_width + (focus_padding + focus_width) * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
1668 + (priv->max_week_char_width
1669 ? priv->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + CALENDAR_XSEP * 2
1673 requisition->width = MAX (header_width, main_width + INNER_BORDER * 2) + widget->style->xthickness * 2;
1676 * Calculate the requisition height for the widget.
1679 if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
1681 priv->header_h = (max_header_height + CALENDAR_YSEP * 2);
1688 if (calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
1690 priv->day_name_h = (priv->max_label_char_ascent
1691 + priv->max_label_char_descent
1692 + 2 * (focus_padding + focus_width) + calendar_margin);
1693 calendar_margin = CALENDAR_YSEP;
1697 priv->day_name_h = 0;
1700 priv->main_h = (CALENDAR_MARGIN + calendar_margin
1701 + 6 * (priv->max_day_char_ascent
1702 + priv->max_day_char_descent
1703 + 2 * (focus_padding + focus_width))
1706 height = (priv->header_h + priv->day_name_h
1709 requisition->height = height + (widget->style->ythickness + INNER_BORDER) * 2;
1711 g_object_unref (layout);
1715 gtk_calendar_size_allocate (GtkWidget *widget,
1716 GtkAllocation *allocation)
1718 GtkCalendar *calendar = GTK_CALENDAR (widget);
1719 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
1720 gint xthickness = widget->style->xthickness;
1721 gint ythickness = widget->style->xthickness;
1724 widget->allocation = *allocation;
1726 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1728 priv->day_width = (priv->min_day_width
1729 * ((allocation->width - (xthickness + INNER_BORDER) * 2
1730 - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2))
1731 / (7 * priv->min_day_width + priv->max_week_char_width * 2));
1732 priv->week_width = ((allocation->width - (xthickness + INNER_BORDER) * 2
1733 - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2 )
1734 - priv->day_width * 7 + CALENDAR_MARGIN + CALENDAR_XSEP);
1738 priv->day_width = (allocation->width
1739 - (xthickness + INNER_BORDER) * 2
1740 - (CALENDAR_MARGIN * 2)
1741 - (DAY_XSEP * 6))/7;
1742 priv->week_width = 0;
1745 if (GTK_WIDGET_REALIZED (widget))
1747 gdk_window_move_resize (widget->window,
1748 allocation->x, allocation->y,
1749 allocation->width, allocation->height);
1750 if (priv->header_win)
1751 gdk_window_move_resize (priv->header_win,
1752 xthickness, ythickness,
1753 allocation->width - 2 * xthickness, priv->header_h);
1755 for (i = 0 ; i < 4 ; i++)
1757 if (priv->arrow_win[i])
1760 calendar_arrow_rectangle (calendar, i, &rect);
1762 gdk_window_move_resize (priv->arrow_win[i],
1763 rect.x, rect.y, rect.width, rect.height);
1767 if (priv->day_name_win)
1768 gdk_window_move_resize (priv->day_name_win,
1769 xthickness + INNER_BORDER,
1770 priv->header_h + (widget->style->ythickness + INNER_BORDER),
1771 allocation->width - (xthickness + INNER_BORDER) * 2,
1773 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1776 gdk_window_move_resize (priv->week_win,
1777 (xthickness + INNER_BORDER),
1778 priv->header_h + priv->day_name_h
1779 + (widget->style->ythickness + INNER_BORDER),
1782 gdk_window_move_resize (priv->main_win,
1783 priv->week_width + (xthickness + INNER_BORDER),
1784 priv->header_h + priv->day_name_h
1785 + (widget->style->ythickness + INNER_BORDER),
1788 - (xthickness + INNER_BORDER) * 2,
1793 gdk_window_move_resize (priv->main_win,
1794 (xthickness + INNER_BORDER),
1795 priv->header_h + priv->day_name_h
1796 + (widget->style->ythickness + INNER_BORDER),
1799 - (xthickness + INNER_BORDER) * 2,
1802 gdk_window_move_resize (priv->week_win,
1805 - (xthickness + INNER_BORDER),
1806 priv->header_h + priv->day_name_h
1807 + (widget->style->ythickness + INNER_BORDER),
1815 /****************************************
1817 ****************************************/
1820 calendar_paint_header (GtkCalendar *calendar)
1822 GtkWidget *widget = GTK_WIDGET (calendar);
1823 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1828 gint max_month_width;
1829 gint max_year_width;
1830 PangoLayout *layout;
1831 PangoRectangle logical_rect;
1837 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
1838 year_left = priv->year_before;
1840 year_left = !priv->year_before;
1842 cr = gdk_cairo_create (priv->header_win);
1844 header_width = widget->allocation.width - 2 * widget->style->xthickness;
1846 max_month_width = priv->max_month_width;
1847 max_year_width = priv->max_year_width;
1849 gtk_paint_shadow (widget->style, priv->header_win,
1850 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
1851 NULL, widget, "calendar",
1852 0, 0, header_width, priv->header_h);
1854 tmp_time = 1; /* Jan 1 1970, 00:00:01 UTC */
1855 tm = gmtime (&tmp_time);
1856 tm->tm_year = calendar->year - 1900;
1858 /* Translators: This dictates how the year is displayed in
1859 * gtkcalendar widget. See strftime() manual for the format.
1860 * Use only ASCII in the translation.
1862 * Also look for the msgid "year measurement template|2000".
1863 * Translate that entry to a year with the widest output of this
1866 * Don't include the prefix "calendar year format|" in the
1867 * translation. "%Y" is appropriate for most locales.
1869 strftime (buffer, sizeof (buffer), Q_("calendar year format|%Y"), tm);
1870 str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
1871 layout = gtk_widget_create_pango_layout (widget, str);
1874 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1877 y = (priv->header_h - logical_rect.height) / 2;
1879 /* Draw year and its arrows */
1881 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1883 x = 3 + (max_year_width - logical_rect.width)/2;
1885 x = header_width - (3 + max_year_width
1886 - (max_year_width - logical_rect.width)/2);
1889 x = 3 + priv->arrow_width + (max_year_width - logical_rect.width)/2;
1891 x = header_width - (3 + priv->arrow_width + max_year_width
1892 - (max_year_width - logical_rect.width)/2);
1895 gdk_cairo_set_source_color (cr, HEADER_FG_COLOR (GTK_WIDGET (calendar)));
1896 cairo_move_to (cr, x, y);
1897 pango_cairo_show_layout (cr, layout);
1900 g_snprintf (buffer, sizeof (buffer), "%s", default_monthname[calendar->month]);
1901 pango_layout_set_text (layout, buffer, -1);
1902 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1904 if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
1906 x = header_width - (3 + max_month_width
1907 - (max_month_width - logical_rect.width)/2);
1909 x = 3 + (max_month_width - logical_rect.width) / 2;
1912 x = header_width - (3 + priv->arrow_width + max_month_width
1913 - (max_month_width - logical_rect.width)/2);
1915 x = 3 + priv->arrow_width + (max_month_width - logical_rect.width)/2;
1917 cairo_move_to (cr, x, y);
1918 pango_cairo_show_layout (cr, layout);
1920 g_object_unref (layout);
1925 calendar_paint_day_names (GtkCalendar *calendar)
1927 GtkWidget *widget = GTK_WIDGET (calendar);
1928 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
1932 int day_width, cal_width;
1934 PangoLayout *layout;
1935 PangoRectangle logical_rect;
1939 cr = gdk_cairo_create (priv->day_name_win);
1941 gtk_widget_style_get (GTK_WIDGET (widget),
1942 "focus-line-width", &focus_width,
1943 "focus-padding", &focus_padding,
1946 day_width = priv->day_width;
1947 cal_width = widget->allocation.width;
1948 day_wid_sep = day_width + DAY_XSEP;
1951 * Draw rectangles as inverted background for the labels.
1954 gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
1955 cairo_rectangle (cr,
1956 CALENDAR_MARGIN, CALENDAR_MARGIN,
1957 cal_width-CALENDAR_MARGIN * 2,
1958 priv->day_name_h - CALENDAR_MARGIN);
1961 if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
1963 cairo_rectangle (cr,
1965 priv->day_name_h - CALENDAR_YSEP,
1966 priv->week_width - CALENDAR_YSEP - CALENDAR_MARGIN,
1975 layout = gtk_widget_create_pango_layout (widget, NULL);
1977 gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
1978 for (i = 0; i < 7; i++)
1980 if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
1984 day = (day + priv->week_start) % 7;
1985 g_snprintf (buffer, sizeof (buffer), "%s", default_abbreviated_dayname[day]);
1987 pango_layout_set_text (layout, buffer, -1);
1988 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1992 + (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
1993 (priv->week_width + (priv->week_width ? CALENDAR_XSEP : 0))
1996 + (day_width - logical_rect.width)/2),
1997 CALENDAR_MARGIN + focus_width + focus_padding + logical_rect.y);
1998 pango_cairo_show_layout (cr, layout);
2001 g_object_unref (layout);
2006 calendar_paint_week_numbers (GtkCalendar *calendar)
2008 GtkWidget *widget = GTK_WIDGET (calendar);
2009 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2012 guint week = 0, year;
2013 gint row, x_loc, y_loc;
2016 PangoLayout *layout;
2017 PangoRectangle logical_rect;
2021 cr = gdk_cairo_create (priv->week_win);
2023 gtk_widget_style_get (GTK_WIDGET (widget),
2024 "focus-line-width", &focus_width,
2025 "focus-padding", &focus_padding,
2029 * Draw a rectangle as inverted background for the labels.
2032 gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
2033 if (priv->day_name_win)
2034 cairo_rectangle (cr,
2037 priv->week_width - CALENDAR_MARGIN,
2038 priv->main_h - CALENDAR_MARGIN);
2040 cairo_rectangle (cr,
2043 priv->week_width - CALENDAR_MARGIN,
2044 priv->main_h - 2 * CALENDAR_MARGIN);
2051 layout = gtk_widget_create_pango_layout (widget, NULL);
2053 gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
2054 day_height = calendar_row_height (calendar);
2055 for (row = 0; row < 6; row++)
2059 year = calendar->year;
2060 if (calendar->day[row][6] < 15 && row > 3 && calendar->month == 11)
2063 result = week_of_year (&week, &year,
2064 ((calendar->day[row][6] < 15 && row > 3 ? 1 : 0)
2065 + calendar->month) % 12 + 1, calendar->day[row][6]);
2066 g_return_if_fail (result);
2068 /* Translators: this defines whether the week numbers should use
2069 * localized digits or the ones used in English (0123...).
2071 * Translate to "%Id" if you want to use localized digits, or
2072 * translate to "%d" otherwise. Don't include the
2073 * "calendar:week:digits|" part in the translation.
2075 * Note that translating this doesn't guarantee that you get localized
2076 * digits. That needs support from your system and locale definition
2079 g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), week);
2080 pango_layout_set_text (layout, buffer, -1);
2081 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
2083 y_loc = calendar_top_y_for_row (calendar, row) + (day_height - logical_rect.height) / 2;
2085 x_loc = (priv->week_width
2086 - logical_rect.width
2087 - CALENDAR_XSEP - focus_padding - focus_width);
2089 cairo_move_to (cr, x_loc, y_loc);
2090 pango_cairo_show_layout (cr, layout);
2093 g_object_unref (layout);
2098 calendar_invalidate_day_num (GtkCalendar *calendar,
2101 gint r, c, row, col;
2105 for (r = 0; r < 6; r++)
2106 for (c = 0; c < 7; c++)
2107 if (calendar->day_month[r][c] == MONTH_CURRENT &&
2108 calendar->day[r][c] == day)
2114 g_return_if_fail (row != -1);
2115 g_return_if_fail (col != -1);
2117 calendar_invalidate_day (calendar, row, col);
2121 calendar_invalidate_day (GtkCalendar *calendar,
2125 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2129 GdkRectangle day_rect;
2131 calendar_day_rectangle (calendar, row, col, &day_rect);
2132 gdk_window_invalidate_rect (priv->main_win, &day_rect, FALSE);
2137 calendar_paint_day (GtkCalendar *calendar,
2141 GtkWidget *widget = GTK_WIDGET (calendar);
2142 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2144 GdkColor *text_color;
2148 GdkRectangle day_rect;
2150 PangoLayout *layout;
2151 PangoRectangle logical_rect;
2153 g_return_if_fail (row < 6);
2154 g_return_if_fail (col < 7);
2156 cr = gdk_cairo_create (priv->main_win);
2158 day = calendar->day[row][col];
2160 calendar_day_rectangle (calendar, row, col, &day_rect);
2162 if (calendar->day_month[row][col] == MONTH_PREV)
2164 text_color = PREV_MONTH_COLOR (widget);
2166 else if (calendar->day_month[row][col] == MONTH_NEXT)
2168 text_color = NEXT_MONTH_COLOR (widget);
2173 if (calendar->highlight_row == row && calendar->highlight_col == col)
2175 cairo_set_source_color (cr, HIGHLIGHT_BG_COLOR (widget));
2176 gdk_cairo_rectangle (cr, &day_rect);
2180 if (calendar->selected_day == day)
2182 gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
2183 gdk_cairo_rectangle (cr, &day_rect);
2186 if (calendar->selected_day == day)
2187 text_color = SELECTED_FG_COLOR (widget);
2188 else if (calendar->marked_date[day-1])
2189 text_color = MARKED_COLOR (widget);
2191 text_color = NORMAL_DAY_COLOR (widget);
2194 /* Translators: this defines whether the day numbers should use
2195 * localized digits or the ones used in English (0123...).
2197 * Translate to "%Id" if you want to use localized digits, or
2198 * translate to "%d" otherwise. Don't include the "calendar:day:digits|"
2199 * part in the translation.
2201 * Note that translating this doesn't guarantee that you get localized
2202 * digits. That needs support from your system and locale definition
2205 g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), day);
2206 layout = gtk_widget_create_pango_layout (widget, buffer);
2207 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
2209 x_loc = day_rect.x + day_rect.width / 2 + priv->max_day_char_width;
2210 x_loc -= logical_rect.width;
2211 y_loc = day_rect.y + (day_rect.height - logical_rect.height) / 2;
2213 gdk_cairo_set_source_color (cr, text_color);
2214 cairo_move_to (cr, x_loc, y_loc);
2215 pango_cairo_show_layout (cr, layout);
2217 if (calendar->marked_date[day-1]
2218 && calendar->day_month[row][col] == MONTH_CURRENT)
2220 cairo_move_to (cr, x_loc - 1, y_loc);
2221 pango_cairo_show_layout (cr, layout);
2224 if (GTK_WIDGET_HAS_FOCUS (calendar)
2225 && calendar->focus_row == row && calendar->focus_col == col)
2229 if (calendar->selected_day == day)
2230 state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
2232 state = GTK_STATE_NORMAL;
2234 gtk_paint_focus (widget->style,
2237 NULL, widget, "calendar-day",
2238 day_rect.x, day_rect.y,
2239 day_rect.width, day_rect.height);
2242 g_object_unref (layout);
2247 calendar_paint_main (GtkCalendar *calendar)
2251 for (col = 0; col < 7; col++)
2252 for (row = 0; row < 6; row++)
2253 calendar_paint_day (calendar, row, col);
2257 calendar_invalidate_arrow (GtkCalendar *calendar,
2260 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2263 window = priv->arrow_win[arrow];
2265 gdk_window_invalidate_rect (window, NULL, FALSE);
2269 calendar_paint_arrow (GtkCalendar *calendar,
2272 GtkWidget *widget = GTK_WIDGET (calendar);
2273 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2276 window = priv->arrow_win[arrow];
2279 cairo_t *cr = gdk_cairo_create (window);
2283 state = priv->arrow_state[arrow];
2285 gdk_cairo_set_source_color (cr, &widget->style->bg[state]);
2289 gdk_drawable_get_size (window, &width, &height);
2290 if (arrow == ARROW_MONTH_LEFT || arrow == ARROW_YEAR_LEFT)
2291 gtk_paint_arrow (widget->style, window, state,
2292 GTK_SHADOW_OUT, NULL, widget, "calendar",
2293 GTK_ARROW_LEFT, TRUE,
2294 width/2 - 3, height/2 - 4, 8, 8);
2296 gtk_paint_arrow (widget->style, window, state,
2297 GTK_SHADOW_OUT, NULL, widget, "calendar",
2298 GTK_ARROW_RIGHT, TRUE,
2299 width/2 - 4, height/2 - 4, 8, 8);
2304 gtk_calendar_expose (GtkWidget *widget,
2305 GdkEventExpose *event)
2307 GtkCalendar *calendar = GTK_CALENDAR (widget);
2308 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2311 if (GTK_WIDGET_DRAWABLE (widget))
2313 if (event->window == priv->main_win)
2314 calendar_paint_main (calendar);
2316 if (event->window == priv->header_win)
2317 calendar_paint_header (calendar);
2319 for (i = 0; i < 4; i++)
2320 if (event->window == priv->arrow_win[i])
2321 calendar_paint_arrow (calendar, i);
2323 if (event->window == priv->day_name_win)
2324 calendar_paint_day_names (calendar);
2326 if (event->window == priv->week_win)
2327 calendar_paint_week_numbers (calendar);
2328 if (event->window == widget->window)
2330 gtk_paint_shadow (widget->style, widget->window, GTK_WIDGET_STATE (widget),
2331 GTK_SHADOW_IN, NULL, widget, "calendar",
2332 0, 0, widget->allocation.width, widget->allocation.height);
2340 /****************************************
2342 ****************************************/
2345 calendar_arrow_action (GtkCalendar *calendar,
2350 case ARROW_YEAR_LEFT:
2351 calendar_set_year_prev (calendar);
2353 case ARROW_YEAR_RIGHT:
2354 calendar_set_year_next (calendar);
2356 case ARROW_MONTH_LEFT:
2357 calendar_set_month_prev (calendar);
2359 case ARROW_MONTH_RIGHT:
2360 calendar_set_month_next (calendar);
2368 calendar_timer (gpointer data)
2370 GtkCalendar *calendar = data;
2371 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2372 gboolean retval = FALSE;
2376 calendar_arrow_action (calendar, priv->click_child);
2378 if (priv->need_timer)
2380 GtkSettings *settings;
2383 settings = gtk_widget_get_settings (GTK_WIDGET (calendar));
2384 g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
2386 priv->need_timer = FALSE;
2387 priv->timer = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
2388 timeout * SCROLL_DELAY_FACTOR,
2389 (GSourceFunc) calendar_timer,
2390 (gpointer) calendar, NULL);
2400 calendar_start_spinning (GtkCalendar *calendar,
2403 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2405 priv->click_child = click_child;
2409 GtkSettings *settings;
2412 settings = gtk_widget_get_settings (GTK_WIDGET (calendar));
2413 g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
2415 priv->need_timer = TRUE;
2416 priv->timer = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
2418 (GSourceFunc) calendar_timer,
2419 (gpointer) calendar, NULL);
2424 calendar_stop_spinning (GtkCalendar *calendar)
2426 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2430 g_source_remove (priv->timer);
2432 priv->need_timer = FALSE;
2437 calendar_main_button_press (GtkCalendar *calendar,
2438 GdkEventButton *event)
2440 GtkWidget *widget = GTK_WIDGET (calendar);
2441 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
2447 x = (gint) (event->x);
2448 y = (gint) (event->y);
2450 row = calendar_row_from_y (calendar, y);
2451 col = calendar_column_from_x (calendar, x);
2453 /* If row or column isn't found, just return. */
2454 if (row == -1 || col == -1)
2457 day_month = calendar->day_month[row][col];
2459 if (event->type == GDK_BUTTON_PRESS)
2461 day = calendar->day[row][col];
2463 if (day_month == MONTH_PREV)
2464 calendar_set_month_prev (calendar);
2465 else if (day_month == MONTH_NEXT)
2466 calendar_set_month_next (calendar);
2468 if (!GTK_WIDGET_HAS_FOCUS (widget))
2469 gtk_widget_grab_focus (widget);
2471 if (event->button == 1)
2474 priv->drag_start_x = x;
2475 priv->drag_start_y = y;
2478 calendar_select_and_focus_day (calendar, day);
2480 else if (event->type == GDK_2BUTTON_PRESS)
2483 if (day_month == MONTH_CURRENT)
2484 g_signal_emit (calendar,
2485 gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL],
2491 gtk_calendar_button_press (GtkWidget *widget,
2492 GdkEventButton *event)
2494 GtkCalendar *calendar = GTK_CALENDAR (widget);
2495 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2498 if (event->window == priv->main_win)
2499 calendar_main_button_press (calendar, event);
2501 if (!GTK_WIDGET_HAS_FOCUS (widget))
2502 gtk_widget_grab_focus (widget);
2504 for (arrow = ARROW_YEAR_LEFT; arrow <= ARROW_MONTH_RIGHT; arrow++)
2506 if (event->window == priv->arrow_win[arrow])
2509 /* only call the action on single click, not double */
2510 if (event->type == GDK_BUTTON_PRESS)
2512 if (event->button == 1)
2513 calendar_start_spinning (calendar, arrow);
2515 calendar_arrow_action (calendar, arrow);
2526 gtk_calendar_button_release (GtkWidget *widget,
2527 GdkEventButton *event)
2529 GtkCalendar *calendar = GTK_CALENDAR (widget);
2530 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2532 if (event->button == 1)
2534 calendar_stop_spinning (calendar);
2544 gtk_calendar_motion_notify (GtkWidget *widget,
2545 GdkEventMotion *event)
2547 GtkCalendar *calendar = GTK_CALENDAR (widget);
2548 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2549 gint event_x, event_y;
2551 gint old_row, old_col;
2553 event_x = (gint) (event->x);
2554 event_y = (gint) (event->y);
2556 if (event->window == priv->main_win)
2561 if (gtk_drag_check_threshold (widget,
2562 priv->drag_start_x, priv->drag_start_y,
2563 event->x, event->y))
2565 GdkDragContext *context;
2566 GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
2567 gtk_target_list_add_text_targets (target_list, 0);
2568 context = gtk_drag_begin (widget, target_list, GDK_ACTION_COPY,
2569 1, (GdkEvent *)event);
2574 gtk_target_list_unref (target_list);
2575 gtk_drag_set_icon_default (context);
2580 row = calendar_row_from_y (calendar, event_y);
2581 col = calendar_column_from_x (calendar, event_x);
2583 if (row != calendar->highlight_row || calendar->highlight_col != col)
2585 old_row = calendar->highlight_row;
2586 old_col = calendar->highlight_col;
2587 if (old_row > -1 && old_col > -1)
2589 calendar->highlight_row = -1;
2590 calendar->highlight_col = -1;
2591 calendar_invalidate_day (calendar, old_row, old_col);
2594 calendar->highlight_row = row;
2595 calendar->highlight_col = col;
2597 if (row > -1 && col > -1)
2598 calendar_invalidate_day (calendar, row, col);
2606 gtk_calendar_enter_notify (GtkWidget *widget,
2607 GdkEventCrossing *event)
2609 GtkCalendar *calendar = GTK_CALENDAR (widget);
2610 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2612 if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
2614 priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_PRELIGHT;
2615 calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
2618 if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
2620 priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_PRELIGHT;
2621 calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
2624 if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
2626 priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_PRELIGHT;
2627 calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
2630 if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
2632 priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_PRELIGHT;
2633 calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
2640 gtk_calendar_leave_notify (GtkWidget *widget,
2641 GdkEventCrossing *event)
2643 GtkCalendar *calendar = GTK_CALENDAR (widget);
2644 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2648 if (event->window == priv->main_win)
2650 row = calendar->highlight_row;
2651 col = calendar->highlight_col;
2652 calendar->highlight_row = -1;
2653 calendar->highlight_col = -1;
2654 if (row > -1 && col > -1)
2655 calendar_invalidate_day (calendar, row, col);
2658 if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
2660 priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_NORMAL;
2661 calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
2664 if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
2666 priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_NORMAL;
2667 calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
2670 if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
2672 priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_NORMAL;
2673 calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
2676 if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
2678 priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_NORMAL;
2679 calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
2686 gtk_calendar_scroll (GtkWidget *widget,
2687 GdkEventScroll *event)
2689 GtkCalendar *calendar = GTK_CALENDAR (widget);
2691 if (event->direction == GDK_SCROLL_UP)
2693 if (!GTK_WIDGET_HAS_FOCUS (widget))
2694 gtk_widget_grab_focus (widget);
2695 calendar_set_month_prev (calendar);
2697 else if (event->direction == GDK_SCROLL_DOWN)
2699 if (!GTK_WIDGET_HAS_FOCUS (widget))
2700 gtk_widget_grab_focus (widget);
2701 calendar_set_month_next (calendar);
2710 /****************************************
2712 ****************************************/
2715 move_focus (GtkCalendar *calendar,
2718 GtkTextDirection text_dir = gtk_widget_get_direction (GTK_WIDGET (calendar));
2720 if ((text_dir == GTK_TEXT_DIR_LTR && direction == -1) ||
2721 (text_dir == GTK_TEXT_DIR_RTL && direction == 1))
2723 if (calendar->focus_col > 0)
2724 calendar->focus_col--;
2725 else if (calendar->focus_row > 0)
2727 calendar->focus_col = 6;
2728 calendar->focus_row--;
2731 if (calendar->focus_col < 0)
2732 calendar->focus_col = 6;
2733 if (calendar->focus_row < 0)
2734 calendar->focus_row = 5;
2738 if (calendar->focus_col < 6)
2739 calendar->focus_col++;
2740 else if (calendar->focus_row < 5)
2742 calendar->focus_col = 0;
2743 calendar->focus_row++;
2746 if (calendar->focus_col < 0)
2747 calendar->focus_col = 0;
2748 if (calendar->focus_row < 0)
2749 calendar->focus_row = 0;
2754 gtk_calendar_key_press (GtkWidget *widget,
2757 GtkCalendar *calendar;
2763 calendar = GTK_CALENDAR (widget);
2766 old_focus_row = calendar->focus_row;
2767 old_focus_col = calendar->focus_col;
2769 switch (event->keyval)
2774 if (event->state & GDK_CONTROL_MASK)
2775 calendar_set_month_prev (calendar);
2778 move_focus (calendar, -1);
2779 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2780 calendar_invalidate_day (calendar, calendar->focus_row,
2781 calendar->focus_col);
2787 if (event->state & GDK_CONTROL_MASK)
2788 calendar_set_month_next (calendar);
2791 move_focus (calendar, 1);
2792 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2793 calendar_invalidate_day (calendar, calendar->focus_row,
2794 calendar->focus_col);
2800 if (event->state & GDK_CONTROL_MASK)
2801 calendar_set_year_prev (calendar);
2804 if (calendar->focus_row > 0)
2805 calendar->focus_row--;
2806 if (calendar->focus_row < 0)
2807 calendar->focus_row = 5;
2808 if (calendar->focus_col < 0)
2809 calendar->focus_col = 6;
2810 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2811 calendar_invalidate_day (calendar, calendar->focus_row,
2812 calendar->focus_col);
2818 if (event->state & GDK_CONTROL_MASK)
2819 calendar_set_year_next (calendar);
2822 if (calendar->focus_row < 5)
2823 calendar->focus_row++;
2824 if (calendar->focus_col < 0)
2825 calendar->focus_col = 0;
2826 calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
2827 calendar_invalidate_day (calendar, calendar->focus_row,
2828 calendar->focus_col);
2833 row = calendar->focus_row;
2834 col = calendar->focus_col;
2836 if (row > -1 && col > -1)
2840 day = calendar->day[row][col];
2841 if (calendar->day_month[row][col] == MONTH_PREV)
2842 calendar_set_month_prev (calendar);
2843 else if (calendar->day_month[row][col] == MONTH_NEXT)
2844 calendar_set_month_next (calendar);
2846 calendar_select_and_focus_day (calendar, day);
2854 /****************************************
2855 * Misc widget methods *
2856 ****************************************/
2859 calendar_set_background (GtkWidget *widget)
2861 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2864 if (GTK_WIDGET_REALIZED (widget))
2866 for (i = 0; i < 4; i++)
2868 if (priv->arrow_win[i])
2869 gdk_window_set_background (priv->arrow_win[i],
2870 HEADER_BG_COLOR (widget));
2872 if (priv->header_win)
2873 gdk_window_set_background (priv->header_win,
2874 HEADER_BG_COLOR (widget));
2875 if (priv->day_name_win)
2876 gdk_window_set_background (priv->day_name_win,
2877 BACKGROUND_COLOR (widget));
2879 gdk_window_set_background (priv->week_win,
2880 BACKGROUND_COLOR (widget));
2882 gdk_window_set_background (priv->main_win,
2883 BACKGROUND_COLOR (widget));
2885 gdk_window_set_background (widget->window,
2886 BACKGROUND_COLOR (widget));
2891 gtk_calendar_style_set (GtkWidget *widget,
2892 GtkStyle *previous_style)
2894 if (previous_style && GTK_WIDGET_REALIZED (widget))
2895 calendar_set_background (widget);
2899 gtk_calendar_state_changed (GtkWidget *widget,
2900 GtkStateType previous_state)
2902 GtkCalendar *calendar = GTK_CALENDAR (widget);
2903 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2906 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2909 calendar_stop_spinning (calendar);
2912 for (i = 0; i < 4; i++)
2913 if (GTK_WIDGET_IS_SENSITIVE (widget))
2914 priv->arrow_state[i] = GTK_STATE_NORMAL;
2916 priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
2918 calendar_set_background (widget);
2922 gtk_calendar_grab_notify (GtkWidget *widget,
2923 gboolean was_grabbed)
2926 calendar_stop_spinning (GTK_CALENDAR (widget));
2930 gtk_calendar_focus_out (GtkWidget *widget,
2931 GdkEventFocus *event)
2933 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2935 gtk_widget_queue_draw (widget);
2937 calendar_stop_spinning (GTK_CALENDAR (widget));
2945 /****************************************
2947 ****************************************/
2950 gtk_calendar_drag_data_get (GtkWidget *widget,
2951 GdkDragContext *context,
2952 GtkSelectionData *selection_data,
2956 GtkCalendar *calendar = GTK_CALENDAR (widget);
2961 date = g_date_new_dmy (calendar->selected_day, calendar->month + 1, calendar->year);
2962 len = g_date_strftime (str, 127, "%x", date);
2963 gtk_selection_data_set_text (selection_data, str, len);
2968 /* Get/set whether drag_motion requested the drag data and
2969 * drag_data_received should thus not actually insert the data,
2970 * since the data doesn't result from a drop.
2973 set_status_pending (GdkDragContext *context,
2974 GdkDragAction suggested_action)
2976 g_object_set_data (G_OBJECT (context),
2977 I_("gtk-calendar-status-pending"),
2978 GINT_TO_POINTER (suggested_action));
2981 static GdkDragAction
2982 get_status_pending (GdkDragContext *context)
2984 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
2985 "gtk-calendar-status-pending"));
2989 gtk_calendar_drag_leave (GtkWidget *widget,
2990 GdkDragContext *context,
2993 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
2995 priv->drag_highlight = 0;
2996 gtk_drag_unhighlight (widget);
3001 gtk_calendar_drag_motion (GtkWidget *widget,
3002 GdkDragContext *context,
3007 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
3010 if (!priv->drag_highlight)
3012 priv->drag_highlight = 1;
3013 gtk_drag_highlight (widget);
3016 target = gtk_drag_dest_find_target (widget, context, NULL);
3017 if (target == GDK_NONE || context->suggested_action == 0)
3018 gdk_drag_status (context, 0, time);
3021 set_status_pending (context, context->suggested_action);
3022 gtk_drag_get_data (widget, context, target, time);
3029 gtk_calendar_drag_drop (GtkWidget *widget,
3030 GdkDragContext *context,
3037 target = gtk_drag_dest_find_target (widget, context, NULL);
3038 if (target != GDK_NONE)
3040 gtk_drag_get_data (widget, context,
3050 gtk_calendar_drag_data_received (GtkWidget *widget,
3051 GdkDragContext *context,
3054 GtkSelectionData *selection_data,
3058 GtkCalendar *calendar = GTK_CALENDAR (widget);
3059 guint day, month, year;
3062 GdkDragAction suggested_action;
3064 suggested_action = get_status_pending (context);
3066 if (suggested_action)
3068 set_status_pending (context, 0);
3070 /* We are getting this data due to a request in drag_motion,
3071 * rather than due to a request in drag_drop, so we are just
3072 * supposed to call drag_status, not actually paste in the
3075 str = (gchar*) gtk_selection_data_get_text (selection_data);
3079 date = g_date_new ();
3080 g_date_set_parse (date, str);
3081 if (!g_date_valid (date))
3082 suggested_action = 0;
3087 suggested_action = 0;
3089 gdk_drag_status (context, suggested_action, time);
3094 date = g_date_new ();
3095 str = (gchar*) gtk_selection_data_get_text (selection_data);
3098 g_date_set_parse (date, str);
3102 if (!g_date_valid (date))
3104 g_warning ("Received invalid date data\n");
3106 gtk_drag_finish (context, FALSE, FALSE, time);
3110 day = g_date_get_day (date);
3111 month = g_date_get_month (date);
3112 year = g_date_get_year (date);
3115 gtk_drag_finish (context, TRUE, FALSE, time);
3118 g_object_freeze_notify (G_OBJECT (calendar));
3119 if (!(calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
3120 && (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING))
3121 gtk_calendar_select_month (calendar, month - 1, year);
3122 gtk_calendar_select_day (calendar, day);
3123 g_object_thaw_notify (G_OBJECT (calendar));
3127 /****************************************
3129 ****************************************/
3134 * Creates a new calendar, with the current date being selected.
3136 * Return value: a newly #GtkCalendar widget
3139 gtk_calendar_new (void)
3141 return g_object_new (GTK_TYPE_CALENDAR, NULL);
3145 * gtk_calendar_display_options:
3146 * @calendar: a #GtkCalendar.
3147 * @flags: the display options to set.
3149 * Sets display options (whether to display the heading and the month headings).
3151 * Deprecated: 2.4: Use gtk_calendar_set_display_options() instead
3154 gtk_calendar_display_options (GtkCalendar *calendar,
3155 GtkCalendarDisplayOptions flags)
3157 gtk_calendar_set_display_options (calendar, flags);
3161 * gtk_calendar_get_display_options:
3162 * @calendar: a #GtkCalendar
3164 * Returns the current display options of @calendar.
3166 * Return value: the display options.
3170 GtkCalendarDisplayOptions
3171 gtk_calendar_get_display_options (GtkCalendar *calendar)
3173 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
3175 return calendar->display_flags;
3179 * gtk_calendar_set_display_options:
3180 * @calendar: a #GtkCalendar
3181 * @flags: the display options to set
3183 * Sets display options (whether to display the heading and the month
3189 gtk_calendar_set_display_options (GtkCalendar *calendar,
3190 GtkCalendarDisplayOptions flags)
3192 GtkWidget *widget = GTK_WIDGET (calendar);
3193 GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
3196 GtkCalendarDisplayOptions old_flags;
3198 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3200 old_flags = calendar->display_flags;
3202 if (GTK_WIDGET_REALIZED (widget))
3204 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
3207 if (! (flags & GTK_CALENDAR_NO_MONTH_CHANGE)
3208 && (priv->header_win))
3210 calendar->display_flags &= ~GTK_CALENDAR_NO_MONTH_CHANGE;
3211 calendar_realize_arrows (calendar);
3215 for (i = 0; i < 4; i++)
3217 if (priv->arrow_win[i])
3219 gdk_window_set_user_data (priv->arrow_win[i],
3221 gdk_window_destroy (priv->arrow_win[i]);
3222 priv->arrow_win[i] = NULL;
3228 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_HEADING)
3232 if (flags & GTK_CALENDAR_SHOW_HEADING)
3234 calendar->display_flags |= GTK_CALENDAR_SHOW_HEADING;
3235 calendar_realize_header (calendar);
3239 for (i = 0; i < 4; i++)
3241 if (priv->arrow_win[i])
3243 gdk_window_set_user_data (priv->arrow_win[i],
3245 gdk_window_destroy (priv->arrow_win[i]);
3246 priv->arrow_win[i] = NULL;
3249 gdk_window_set_user_data (priv->header_win, NULL);
3250 gdk_window_destroy (priv->header_win);
3251 priv->header_win = NULL;
3256 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
3260 if (flags & GTK_CALENDAR_SHOW_DAY_NAMES)
3262 calendar->display_flags |= GTK_CALENDAR_SHOW_DAY_NAMES;
3263 calendar_realize_day_names (calendar);
3267 gdk_window_set_user_data (priv->day_name_win, NULL);
3268 gdk_window_destroy (priv->day_name_win);
3269 priv->day_name_win = NULL;
3273 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
3277 if (flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
3279 calendar->display_flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS;
3280 calendar_realize_week_numbers (calendar);
3284 gdk_window_set_user_data (priv->week_win, NULL);
3285 gdk_window_destroy (priv->week_win);
3286 priv->week_win = NULL;
3290 if ((flags ^ calendar->display_flags) & GTK_CALENDAR_WEEK_START_MONDAY)
3291 g_warning ("GTK_CALENDAR_WEEK_START_MONDAY is ignored; the first day of the week is determined from the locale");
3293 calendar->display_flags = flags;
3295 gtk_widget_queue_resize (GTK_WIDGET (calendar));
3299 calendar->display_flags = flags;
3301 g_object_freeze_notify (G_OBJECT (calendar));
3302 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_HEADING)
3303 g_object_notify (G_OBJECT (calendar), "show-heading");
3304 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
3305 g_object_notify (G_OBJECT (calendar), "show-day-names");
3306 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
3307 g_object_notify (G_OBJECT (calendar), "no-month-change");
3308 if ((old_flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
3309 g_object_notify (G_OBJECT (calendar), "show-week-numbers");
3310 g_object_thaw_notify (G_OBJECT (calendar));
3314 * gtk_calendar_select_month:
3315 * @calendar: a #GtkCalendar
3316 * @month: a month number between 0 and 11.
3317 * @year: the year the month is in.
3319 * Shifts the calendar to a different month.
3321 * Return value: %TRUE, always
3324 gtk_calendar_select_month (GtkCalendar *calendar,
3328 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
3329 g_return_val_if_fail (month <= 11, FALSE);
3331 calendar->month = month;
3332 calendar->year = year;
3334 calendar_compute_days (calendar);
3336 gtk_widget_queue_draw (GTK_WIDGET (calendar));
3338 g_object_freeze_notify (G_OBJECT (calendar));
3339 g_object_notify (G_OBJECT (calendar), "month");
3340 g_object_notify (G_OBJECT (calendar), "year");
3341 g_object_thaw_notify (G_OBJECT (calendar));
3343 g_signal_emit (calendar,
3344 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
3350 * gtk_calendar_select_day:
3351 * @calendar: a #GtkCalendar.
3352 * @day: the day number between 1 and 31, or 0 to unselect
3353 * the currently selected day.
3355 * Selects a day from the current month.
3358 gtk_calendar_select_day (GtkCalendar *calendar,
3361 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3362 g_return_if_fail (day <= 31);
3364 /* Deselect the old day */
3365 if (calendar->selected_day > 0)
3369 selected_day = calendar->selected_day;
3370 calendar->selected_day = 0;
3371 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
3372 calendar_invalidate_day_num (calendar, selected_day);
3375 calendar->selected_day = day;
3377 /* Select the new day */
3380 if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
3381 calendar_invalidate_day_num (calendar, day);
3384 g_object_notify (G_OBJECT (calendar), "day");
3386 g_signal_emit (calendar,
3387 gtk_calendar_signals[DAY_SELECTED_SIGNAL],
3392 * gtk_calendar_clear_marks:
3393 * @calendar: a #GtkCalendar
3395 * Remove all visual markers.
3398 gtk_calendar_clear_marks (GtkCalendar *calendar)
3402 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3404 for (day = 0; day < 31; day++)
3406 calendar->marked_date[day] = FALSE;
3409 calendar->num_marked_dates = 0;
3411 gtk_widget_queue_draw (GTK_WIDGET (calendar));
3415 * gtk_calendar_mark_day:
3416 * @calendar: a #GtkCalendar
3417 * @day: the day number to mark between 1 and 31.
3419 * Places a visual marker on a particular day.
3421 * Return value: %TRUE, always
3424 gtk_calendar_mark_day (GtkCalendar *calendar,
3427 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
3429 if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == FALSE)
3431 calendar->marked_date[day - 1] = TRUE;
3432 calendar->num_marked_dates++;
3433 calendar_invalidate_day_num (calendar, day);
3440 * gtk_calendar_unmark_day:
3441 * @calendar: a #GtkCalendar.
3442 * @day: the day number to unmark between 1 and 31.
3444 * Removes the visual marker from a particular day.
3446 * Return value: %TRUE, always
3449 gtk_calendar_unmark_day (GtkCalendar *calendar,
3452 g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
3454 if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == TRUE)
3456 calendar->marked_date[day - 1] = FALSE;
3457 calendar->num_marked_dates--;
3458 calendar_invalidate_day_num (calendar, day);
3465 * gtk_calendar_get_date:
3466 * @calendar: a #GtkCalendar
3467 * @year: location to store the year number, or %NULL
3468 * @month: location to store the month number (between 0 and 11), or %NULL
3469 * @day: location to store the day number (between 1 and 31), or %NULL
3471 * Obtains the selected date from a #GtkCalendar.
3474 gtk_calendar_get_date (GtkCalendar *calendar,
3479 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3482 *year = calendar->year;
3485 *month = calendar->month;
3488 *day = calendar->selected_day;
3492 * gtk_calendar_freeze:
3493 * @calendar: a #GtkCalendar
3495 * Does nothing. Previously locked the display of the calendar until
3496 * it was thawed with gtk_calendar_thaw().
3501 gtk_calendar_freeze (GtkCalendar *calendar)
3503 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3507 * gtk_calendar_thaw:
3508 * @calendar: a #GtkCalendar
3510 * Does nothing. Previously defrosted a calendar; all the changes made
3511 * since the last gtk_calendar_freeze() were displayed.
3516 gtk_calendar_thaw (GtkCalendar *calendar)
3518 g_return_if_fail (GTK_IS_CALENDAR (calendar));
3521 #define __GTK_CALENDAR_C__
3522 #include "gtkaliasdef.c"