diff options
Diffstat (limited to 'hildon/hildon-calendar.c')
-rw-r--r-- | hildon/hildon-calendar.c | 4303 |
1 files changed, 0 insertions, 4303 deletions
diff --git a/hildon/hildon-calendar.c b/hildon/hildon-calendar.c deleted file mode 100644 index b460e50..0000000 --- a/hildon/hildon-calendar.c +++ /dev/null @@ -1,4303 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * GTK Calendar Widget - * Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson and Mattias Groenlund - * - * lib_date routines - * Copyright (C) 1995, 1996, 1997, 1998 by Steffen Beyer - * - * HldonCalendar modifications - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -/** - * SECTION:hildon-calendar - * @short_description: A calendar widget - * - * #HildonCalendar is a slightly modified #GtkCalendar. It has an almost same API - * but a slightly different look and behaviour. Use this widget instead of - * standard #GtkCalendar or use #HildonDateEditor for more higher-level date setting - * operations. - * - * <note> - * <para> - * #HildonCalendar has been deprecated since Hildon 2.2 - * See <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#define _GNU_SOURCE /* needed for GNU nl_langinfo_l */ - -#include <locale.h> - -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#include <string.h> -#include <stdlib.h> -#include <time.h> -#include <langinfo.h> - -#include <glib/gprintf.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtkprivate.h> - -#include "hildon-calendar.h" -#include "hildon-marshalers.h" -#include "hildon-calendar-private.h" - -/***************************************************************************/ -/* The following date routines are taken from the lib_date package. Keep - * them separate in case we want to update them if a newer lib_date comes - * out with fixes. */ - -typedef unsigned int N_int; - -typedef unsigned long N_long; - -typedef signed long Z_long; - -typedef enum { false = FALSE , true = TRUE } boolean; - -#define and && /* logical (boolean) operators: lower case */ - -#define or || - -static const N_int month_length [2][13] = -{ - { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } -}; - -static const N_int days_in_months[2][14] = -{ - { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, - { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } -}; - -static Z_long calc_days (N_int year, N_int mm, N_int dd); - -static N_int day_of_week (N_int year, N_int mm, N_int dd); - -static Z_long dates_difference (N_int year1, N_int mm1, N_int dd1, - N_int year2, N_int mm2, N_int dd2); - -static N_int weeks_in_year (N_int year); - -static boolean -leap (N_int year) -{ - return ((((year % 4) == 0) and ((year % 100) != 0)) or ((year % 400) == 0)); -} - -static N_int -day_of_week (N_int year, - N_int mm, - N_int dd) -{ - Z_long days; - - days = calc_days (year, mm, dd); - if (days > 0L) - { - days--; - days %= 7L; - days++; - } - return( (N_int) days ); -} - -static N_int -weeks_in_year (N_int year) -{ - return (52 + ((day_of_week(year,1,1)==4) or (day_of_week(year,12,31)==4))); -} - -static boolean -check_date (N_int year, - N_int mm, - N_int dd) -{ - if (year < 1) return(false); - if ((mm < 1) or (mm > 12)) return(false); - if ((dd < 1) or (dd > month_length[leap(year)][mm])) return(false); - return(true); -} - -static N_int -week_number (N_int year, - N_int mm, - N_int dd) -{ - N_int first; - - first = day_of_week (year,1,1) - 1; - return( (N_int) ( (dates_difference(year,1,1, year,mm,dd) + first) / 7L ) + - (first < 4) ); -} - -static Z_long -year_to_days (N_int year) -{ - return ( year * 365L + (year / 4) - (year / 100) + (year / 400) ); -} - -static Z_long -calc_days (N_int year, - N_int mm, - N_int dd) -{ - boolean lp; - - if (year < 1) return(0L); - if ((mm < 1) or (mm > 12)) return(0L); - if ((dd < 1) or (dd > month_length[(lp = leap(year))][mm])) return(0L); - return( year_to_days(--year) + days_in_months[lp][mm] + dd ); -} - -static boolean -week_of_year (N_int *week, - N_int *year, - N_int mm, - N_int dd) -{ - if (check_date(*year,mm,dd)) - { - *week = week_number(*year,mm,dd); - if (*week == 0) - *week = weeks_in_year(--(*year)); - else if (*week > weeks_in_year(*year)) - { - *week = 1; - (*year)++; - } - return(true); - } - return(false); -} - -static Z_long -dates_difference (N_int year1, - N_int mm1, - N_int dd1, - N_int year2, - N_int mm2, - N_int dd2) -{ - return (calc_days (year2, mm2, dd2) - calc_days (year1, mm1, dd1)); -} - -/*** END OF lib_date routines ********************************************/ - -/* HILDON: Spacings modified */ -#define HILDON_ARROW_SEP 5 /* Space between arrows and data */ - -#define HILDON_DAY_WIDTH 26 - -#define HILDON_DAY_HEIGHT 25 - -/* additional widths given to week number and day windows */ - -#define HILDON_WEEKS_EXTRA_WIDTH 8 - -#define HILDON_DAYS_EXTRA_WIDTH 8 - -/* Spacing around day/week headers and main area, inside those windows */ - -#define CALENDAR_MARGIN 0 - -/* Spacing around day/week headers and main area, outside those windows */ - -#define INNER_BORDER 0 /* 4 */ - -/* Separation between day headers and main area */ - -#define CALENDAR_YSEP 3 /* 4 */ - -/* Separation between week headers and main area */ - -#define CALENDAR_XSEP 6 /* 4 */ - -#define DAY_XSEP 0 /* not really good for small calendar */ - -#define DAY_YSEP 0 /* not really good for small calendar */ - -/* Color usage */ -#define HEADER_FG_COLOR(widget) \ - (& (widget)->style->fg[GTK_WIDGET_STATE (widget)]) - -#define HEADER_BG_COLOR(widget) \ - (& (widget)->style->bg[GTK_WIDGET_STATE (widget)]) - -#define SELECTED_BG_COLOR(widget) \ - (& (widget)->style->base[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]) - -#define SELECTED_FG_COLOR(widget) \ - (& (widget)->style->text[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]) - -#define NORMAL_DAY_COLOR(widget) \ - (& (widget)->style->fg[GTK_WIDGET_STATE (widget)]) - -#define PREV_MONTH_COLOR(widget) \ - (& (widget)->style->mid[GTK_WIDGET_STATE (widget)]) - -#define NEXT_MONTH_COLOR(widget) \ - (& (widget)->style->mid[GTK_WIDGET_STATE (widget)]) - -#define MARKED_COLOR(widget) \ - (& (widget)->style->fg[GTK_WIDGET_STATE (widget)]) - -#define BACKGROUND_COLOR(widget) \ - (& (widget)->style->base[GTK_WIDGET_STATE (widget)]) - -#define HIGHLIGHT_BACK_COLOR(widget) \ - (& (widget)->style->mid[GTK_WIDGET_STATE (widget)]) - -#define CALENDAR_INITIAL_TIMER_DELAY 200 - -#define CALENDAR_TIMER_DELAY 20 - -enum { - ARROW_YEAR_LEFT, - ARROW_YEAR_RIGHT, - ARROW_MONTH_LEFT, - ARROW_MONTH_RIGHT -}; - -enum { - MONTH_PREV, - MONTH_CURRENT, - MONTH_NEXT -}; - -enum { - MONTH_CHANGED_SIGNAL, - DAY_SELECTED_SIGNAL, - DAY_SELECTED_DOUBLE_CLICK_SIGNAL, - PREV_MONTH_SIGNAL, - NEXT_MONTH_SIGNAL, - PREV_YEAR_SIGNAL, - NEXT_YEAR_SIGNAL, - ERRONEOUS_DATE_SIGNAL, - SELECTED_DATE_SIGNAL, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_YEAR, - PROP_MONTH, - PROP_DAY, - PROP_SHOW_HEADING, - PROP_SHOW_DAY_NAMES, - PROP_NO_MONTH_CHANGE, - PROP_SHOW_WEEK_NUMBERS, - PROP_WEEK_START, - PROP_MIN_YEAR, - PROP_MAX_YEAR, - PROP_LAST -}; - -static gint hildon_calendar_signals [LAST_SIGNAL] = { 0 }; - -static GtkWidgetClass* parent_class = NULL; - -typedef void (*HildonCalendarSignalDate) (GtkObject *object, guint arg1, guint arg2, guint arg3, gpointer data); - -static void -hildon_calendar_class_init (HildonCalendarClass *class); - -static void -hildon_calendar_init (HildonCalendar *calendar); - -static void -hildon_calendar_finalize (GObject *calendar); - -static void -hildon_calendar_destroy (GtkObject *calendar); - -static void -hildon_calendar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_calendar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_calendar_realize (GtkWidget *widget); - -static void -hildon_calendar_unrealize (GtkWidget *widget); - -static void -hildon_calendar_size_request (GtkWidget *widget, - GtkRequisition *requisition); - -static void -hildon_calendar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static gint -hildon_calendar_expose (GtkWidget *widget, - GdkEventExpose *event); - -static gint -hildon_calendar_button_press (GtkWidget *widget, - GdkEventButton *event); - -static gint -hildon_calendar_button_release (GtkWidget *widget, - GdkEventButton *event); - -static void -hildon_calendar_main_button (GtkWidget *widget, - GdkEventButton *event); - -static gint -hildon_calendar_motion_notify (GtkWidget *widget, - GdkEventMotion *event); - -static gint -hildon_calendar_enter_notify (GtkWidget *widget, - GdkEventCrossing *event); - -static gint -hildon_calendar_leave_notify (GtkWidget *widget, - GdkEventCrossing *event); - -static gint -hildon_calendar_key_press (GtkWidget *widget, - GdkEventKey *event); - -static gint -hildon_calendar_scroll (GtkWidget *widget, - GdkEventScroll *event); - -static void -hildon_calendar_grab_notify (GtkWidget *widget, - gboolean was_grabbed); - -static gboolean -hildon_calendar_focus_out (GtkWidget *widget, - GdkEventFocus *event); - -static void -hildon_calendar_state_changed (GtkWidget *widget, - GtkStateType previous_state); - -static void -hildon_calendar_style_set (GtkWidget *widget, - GtkStyle *previous_style); - -static void -hildon_calendar_paint_header (GtkWidget *widget); - -static void -hildon_calendar_paint_footer (GtkWidget *widget); - -static void -hildon_calendar_paint_day_names (GtkWidget *widget); - -static void -hildon_calendar_paint_week_numbers (GtkWidget *widget); - -static void -hildon_calendar_paint_main (GtkWidget *widget); - -static void -hildon_calendar_select_and_focus_day (HildonCalendar *calendar, - guint day); - -static void -hildon_calendar_paint_arrow (GtkWidget *widget, - guint arrow); - -static void -hildon_calendar_paint_day_num (GtkWidget *widget, - gint day); - -static void -hildon_calendar_paint_day (GtkWidget *widget, - gint row, - gint col); - -static void -hildon_calendar_compute_days (HildonCalendar *calendar); - -static gint -left_x_for_column (HildonCalendar *calendar, - gint column); - -static gint -top_y_for_row (HildonCalendar *calendar, - gint row); - -static void -hildon_calendar_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time); - -static void -hildon_calendar_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time); - -static gboolean -hildon_calendar_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time); - -static void -hildon_calendar_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time); - -static gboolean -hildon_calendar_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time); - -/* This function was added because we need to mark current day according to - * specifications - */ - -static void -hildon_calendar_check_current_date (HildonCalendar *calendar, - gint x, - gint y); - -GType G_GNUC_CONST -hildon_calendar_get_type (void) -{ - static GType calendar_type = 0; - - if (!calendar_type) - { - static const GTypeInfo calendar_info = - { - sizeof (HildonCalendarClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_calendar_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonCalendar), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_calendar_init, - }; - - calendar_type = g_type_register_static (GTK_TYPE_WIDGET, "HildonCalendar", - &calendar_info, 0); - } - - return calendar_type; -} - -static void -locales_init (HildonCalendarPrivate *priv) -{ - /* Hildon: This is not exactly portable, see - * http://bugzilla.gnome.org/show_bug.cgi?id=343415 - * The labels need to be instance variables as the startup wizard changes - * locale on runtime. - */ - locale_t l; - - l = newlocale (LC_TIME_MASK, setlocale (LC_MESSAGES, NULL), NULL); - - priv->abbreviated_dayname[0] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_1, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[1] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_2, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[2] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_3, l), - -1, NULL, NULL, NULL) ; - priv->abbreviated_dayname[3] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_4, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[4] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_5, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[5] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_6, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[6] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_7, l), - -1, NULL, NULL, NULL); - priv->monthname[0] = g_locale_to_utf8 (nl_langinfo_l(MON_1, l), - -1, NULL, NULL, NULL); - priv->monthname[1] = g_locale_to_utf8 (nl_langinfo_l(MON_2, l), - -1, NULL, NULL, NULL); - priv->monthname[2] = g_locale_to_utf8 (nl_langinfo_l(MON_3, l), - -1, NULL, NULL, NULL); - priv->monthname[3] = g_locale_to_utf8 (nl_langinfo_l(MON_4, l), - -1, NULL, NULL, NULL); - priv->monthname[4] = g_locale_to_utf8 (nl_langinfo_l(MON_5, l), - -1, NULL, NULL, NULL); - priv->monthname[5] = g_locale_to_utf8 (nl_langinfo_l(MON_6, l), - -1, NULL, NULL, NULL); - priv->monthname[6] = g_locale_to_utf8 (nl_langinfo_l(MON_7, l), - -1, NULL, NULL, NULL); - priv->monthname[7] = g_locale_to_utf8 (nl_langinfo_l(MON_8, l), - -1, NULL, NULL, NULL); - priv->monthname[8] = g_locale_to_utf8 (nl_langinfo_l(MON_9, l), - -1, NULL, NULL, NULL); - priv->monthname[9] = g_locale_to_utf8 (nl_langinfo_l(MON_10, l), - -1, NULL, NULL, NULL); - priv->monthname[10] = g_locale_to_utf8 (nl_langinfo_l(MON_11, l), - -1, NULL, NULL, NULL); - priv->monthname[11] = g_locale_to_utf8 (nl_langinfo_l(MON_12, l), - -1, NULL, NULL, NULL); - - freelocale (l); -} - -static void -hildon_calendar_class_init (HildonCalendarClass *class) -{ - GObjectClass *gobject_class; - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - gobject_class = (GObjectClass*) class; - object_class = (GtkObjectClass*) class; - widget_class = (GtkWidgetClass*) class; - - parent_class = g_type_class_peek_parent (class); - - gobject_class->set_property = hildon_calendar_set_property; - gobject_class->get_property = hildon_calendar_get_property; - gobject_class->finalize = hildon_calendar_finalize; - - object_class->destroy = hildon_calendar_destroy; - - widget_class->realize = hildon_calendar_realize; - widget_class->unrealize = hildon_calendar_unrealize; - widget_class->expose_event = hildon_calendar_expose; - widget_class->size_request = hildon_calendar_size_request; - widget_class->size_allocate = hildon_calendar_size_allocate; - widget_class->button_press_event = hildon_calendar_button_press; - widget_class->button_release_event = hildon_calendar_button_release; - widget_class->motion_notify_event = hildon_calendar_motion_notify; - widget_class->enter_notify_event = hildon_calendar_enter_notify; - widget_class->leave_notify_event = hildon_calendar_leave_notify; - widget_class->key_press_event = hildon_calendar_key_press; - widget_class->scroll_event = hildon_calendar_scroll; - widget_class->style_set = hildon_calendar_style_set; - widget_class->state_changed = hildon_calendar_state_changed; - widget_class->grab_notify = hildon_calendar_grab_notify; - widget_class->focus_out_event = hildon_calendar_focus_out; - - widget_class->drag_data_get = hildon_calendar_drag_data_get; - widget_class->drag_motion = hildon_calendar_drag_motion; - widget_class->drag_leave = hildon_calendar_drag_leave; - widget_class->drag_drop = hildon_calendar_drag_drop; - widget_class->drag_data_received = hildon_calendar_drag_data_received; - - class->month_changed = NULL; - class->day_selected = NULL; - class->day_selected_double_click = NULL; - class->prev_month = NULL; - class->next_month = NULL; - class->prev_year = NULL; - class->next_year = NULL; - - /** - * HildonCalendar:year: - * - * The selected year. - */ - g_object_class_install_property (gobject_class, - PROP_YEAR, - g_param_spec_int ("year", - "Year", - "The selected year", - 0, G_MAXINT, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:month: - * - * The selected month as number between 0 and 11. - */ - g_object_class_install_property (gobject_class, - PROP_MONTH, - g_param_spec_int ("month", - "Month", - "The selected month (as a number between 0 and 11)", - 0, 11, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:day: - * - * The selected day as number between 1 and 31 or 0 to unselect the currently selected day. - */ - g_object_class_install_property (gobject_class, - PROP_DAY, - g_param_spec_int ("day", - "Day", - "The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day)", - 0, 31, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:show-heading: - * - * Determines whether a heading is displayed. - * - */ - g_object_class_install_property (gobject_class, - PROP_SHOW_HEADING, - g_param_spec_boolean ("show-heading", - "Show Heading", - "If TRUE, a heading is displayed", - TRUE, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:show-day-names: - * - * Determines whether day names are displayed. - * - */ - g_object_class_install_property (gobject_class, - PROP_SHOW_DAY_NAMES, - g_param_spec_boolean ("show-day-names", - "Show Day Names", - "If TRUE, day names are displayed", - TRUE, - GTK_PARAM_READWRITE)); - /** - * HildonCalendar:no-month-change: - * - * Determines whether the selected month can be changed. - * - */ - g_object_class_install_property (gobject_class, - PROP_NO_MONTH_CHANGE, - g_param_spec_boolean ("no-month-change", - "No Month Change", - "If TRUE, the selected month cannot be changed", - FALSE, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:show-week-numbers: - * - * Determines whether week numbers are displayed. - * - */ - g_object_class_install_property (gobject_class, - PROP_SHOW_WEEK_NUMBERS, - g_param_spec_boolean ("show-week-numbers", - "Show Week Numbers", - "If TRUE, week numbers are displayed", - FALSE, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:week-start: - * - * Determines the start day of the week (0 for Sunday, 1 for Monday etc.) - * - */ - g_object_class_install_property (gobject_class, - PROP_WEEK_START, - g_param_spec_int ("week-start", - "Week start day", - "First day of the week; 0 for Sunday, 1 for Monday etc.", - 0, 6, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:min-year: - * - * Minimum valid year (0 if no limit). - * - */ - g_object_class_install_property (gobject_class, - PROP_MIN_YEAR, - g_param_spec_int ("min-year", - "Minimum valid year", - "Minimum valid year (0 if no limit)", - 0, 10000, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:max-year: - * - * Maximum valid year (0 if no limit). - * - */ - g_object_class_install_property (gobject_class, - PROP_MAX_YEAR, - g_param_spec_int ("max-year", - "Maximum valid year", - "Maximum valid year (0 if no limit)", - 0, 10000, 0, - GTK_PARAM_READWRITE)); - - hildon_calendar_signals[MONTH_CHANGED_SIGNAL] = - g_signal_new ("month_changed", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, month_changed), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[DAY_SELECTED_SIGNAL] = - g_signal_new ("day_selected", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, day_selected), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL] = - g_signal_new ("day_selected_double_click", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, day_selected_double_click), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[PREV_MONTH_SIGNAL] = - g_signal_new ("prev_month", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, prev_month), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[NEXT_MONTH_SIGNAL] = - g_signal_new ("next_month", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, next_month), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[PREV_YEAR_SIGNAL] = - g_signal_new ("prev_year", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, prev_year), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[NEXT_YEAR_SIGNAL] = - g_signal_new ("next_year", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, next_year), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - /** - * HildonCalendar::erroneous-date: - * - * Emitted when the user tries to set a date which is outside the boundaries - * set by min-year and max-year properties. - * - */ - hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL] = - g_signal_new ("erroneous_date", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - /** - * HildonCalendar::selected-date: - * - * Emitted on button-release when the user has selected a date. - * - */ - hildon_calendar_signals[SELECTED_DATE_SIGNAL] = - g_signal_new ("selected_date", - G_OBJECT_CLASS_TYPE(gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -hildon_calendar_init (HildonCalendar *calendar) -{ - time_t secs; - struct tm *tm; - gint i; - /* char buffer[255];*/ - /* time_t tmp_time;*/ - GtkWidget *widget; - HildonCalendarPrivate *private_data; - /* gchar *year_before;*/ - /* gint row; - gint col; */ - gchar *langinfo; - GDateWeekday week_1stday; - gint first_weekday; - guint week_origin; - - widget = GTK_WIDGET (calendar); - GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); - - calendar->private_data = g_malloc (sizeof (HildonCalendarPrivate)); - private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - - /* Set defaults */ - secs = time (NULL); - tm = localtime (&secs); - calendar->month = tm->tm_mon; - calendar->year = 1900 + tm->tm_year; - - for (i=0;i<31;i++) - calendar->marked_date[i] = FALSE; - calendar->num_marked_dates = 0; - calendar->selected_day = tm->tm_mday; - - calendar->display_flags = ( HILDON_CALENDAR_SHOW_HEADING | - HILDON_CALENDAR_SHOW_DAY_NAMES ); - - /* Hildon: we should mark current day and we need to store current date */ - private_data->current_day = tm->tm_mday; - private_data->current_month = tm->tm_mon; - private_data->current_year = tm->tm_year + 1900; - - /* Hildon: following lines are for stylus sliding */ - private_data->slide_stylus = FALSE; - private_data->prev_row = -1; - private_data->prev_col = -1; - - /* Hildon: is_bad_day indicate if day was selected out of legal range */ - private_data->is_bad_day = FALSE; - - calendar->highlight_row = -1; - calendar->highlight_col = -1; - - calendar->focus_row = -1; - calendar->focus_col = -1; - calendar->xor_gc = NULL; - - private_data->max_year_width = 0; - private_data->max_month_width = 0; - private_data->max_day_char_width = 0; - private_data->max_week_char_width = 0; - - private_data->max_day_char_ascent = 0; - private_data->max_day_char_descent = 0; - private_data->max_label_char_ascent = 0; - private_data->max_label_char_descent = 0; - - /* private_data->arrow_width = 10;*/ - - private_data->freeze_count = 0; - - private_data->dirty_header = 0; - private_data->dirty_day_names = 0; - private_data->dirty_week = 0; - private_data->dirty_main = 0; - - private_data->need_timer = 0; - private_data->timer = 0; - private_data->click_child = -1; - - private_data->in_drag = 0; - private_data->drag_highlight = 0; - - private_data->min_year = 0; - private_data->max_year = 0; - - gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_COPY); - gtk_drag_dest_add_text_targets (widget); - -#if 0 - private_data->year_before = 0; - - /* Translate to calendar:YM if you want years to be displayed - * before months; otherwise translate to calendar:MY. - * Do *not* translate it to anything else, if it - * it isn't calendar:YM or calendar:MY it will not work. - * - * Note that this flipping is in top the text direction flipping, - * so if you have a default text direction of RTL and YM, then - * the year will appear on the right. - */ - year_before = _("calendar:MY"); - if (strcmp (year_before, "calendar:YM") == 0) - private_data->year_before = 1; - else if (strcmp (year_before, "calendar:MY") != 0) - g_warning ("Whoever translated calendar:MY did so wrongly.\n"); -#endif - langinfo = nl_langinfo (_NL_TIME_FIRST_WEEKDAY); - first_weekday = langinfo[0]; - langinfo = nl_langinfo (_NL_TIME_WEEK_1STDAY); - week_origin = GPOINTER_TO_UINT (langinfo); - if (week_origin == 19971130) - week_1stday = G_DATE_SUNDAY; - else if (week_origin == 19971201) - week_1stday = G_DATE_MONDAY; - else if (g_date_valid_dmy ((week_origin % 100), - (week_origin / 100) % 100, - (week_origin / 10000))) - { - GDate *date; - date = g_date_new_dmy ((week_origin % 100), - (week_origin / 100) % 100, - (week_origin / 10000)); - week_1stday = g_date_get_weekday (date); - g_date_free (date); - } - else - { - g_warning ("Invalid value set for _NL_TIME_WEEK_1STDAY"); - week_1stday = G_DATE_SUNDAY; - } - - private_data->week_star |