2009-01-12 Alberto Garcia <agarcia@igalia.com>
[hildon] / src / hildon-calendar.c
index 6fd1b22..2a1e8ee 100644 (file)
@@ -12,7 +12,7 @@
  * HldonCalendar modifications
  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
  *
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ * 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
  * standard #GtkCalendar or use #HildonDateEditor for more higher-level date setting
  * operations.
  *
- */    
+ * <note>
+ *   <para>
+ * #HildonCalendar has been deprecated since Hildon 2.2 and should not
+ * be used in newly written code. Use #HildonDateSelector instead.
+ *   </para>
+ * </note>
+ */
+
+#undef                                          HILDON_DISABLE_DEPRECATED
 
 #ifdef                                          HAVE_CONFIG_H
 #include                                        <config.h>
@@ -53,6 +61,8 @@
 
 #define                                         _GNU_SOURCE /* needed for GNU nl_langinfo_l */
 
+#include                                        <locale.h>
+
 #ifdef                                          HAVE_SYS_TIME_H
 #include                                        <sys/time.h>
 #endif
 #include                                        <stdlib.h>
 #include                                        <time.h>
 #include                                        <langinfo.h>
-#include                                        <locale.h>
+
 #include                                        <glib/gprintf.h>
+#include                                        <gdk/gdkkeysyms.h>
+#include                                        <gtk/gtkprivate.h>
 
 #include                                        "hildon-calendar.h"
 #include                                        "hildon-marshalers.h"
-#include                                        <gtk/gtkdnd.h>
-#include                                        <gtk/gtkmain.h>
-#include                                        <gdk/gdkkeysyms.h>
-#include                                        <gtk/gtkprivate.h>
 #include                                        "hildon-calendar-private.h"
 
 /***************************************************************************/
@@ -775,20 +783,6 @@ hildon_calendar_class_init                      (HildonCalendarClass *class)
                 0, 10000, 0,
                 GTK_PARAM_READWRITE));
 
-    /**
-     * HildonCalendar:hildonlike:
-     *
-     * Changes the appearance and behaviour of HildonCalendar to be consistent with
-     * Hildon library.
-     * 
-     */
-    gtk_widget_class_install_style_property (widget_class,
-            g_param_spec_boolean ("hildonlike",
-                "Size request",
-                "Size allocate",
-                FALSE,
-                GTK_PARAM_READABLE));
-
     hildon_calendar_signals[MONTH_CHANGED_SIGNAL] =
         g_signal_new ("month_changed",
                 G_OBJECT_CLASS_TYPE (gobject_class),
@@ -1297,7 +1291,6 @@ hildon_calendar_main_button                     (GtkWidget *widget,
     gint row, col;
     gint day_month;
     gint day;
-    gboolean hildonlike;
 
     calendar = HILDON_CALENDAR (widget);
     private_data = HILDON_CALENDAR_GET_PRIVATE (widget);
@@ -1312,23 +1305,19 @@ hildon_calendar_main_button                     (GtkWidget *widget,
     if (row == -1 || col == -1)
         return;
 
-    gtk_widget_style_get (GTK_WIDGET (calendar), "hildonlike", &hildonlike, NULL);
     day_month = calendar->day_month[row][col];
 
-    if (hildonlike) 
+    if ((calendar->year == private_data->min_year &&
+                calendar->month == 0 && day_month == MONTH_PREV) ||
+            (calendar->year == private_data->max_year &&
+             calendar->month == 11 && day_month == MONTH_NEXT)) 
     {
-        if ((calendar->year == private_data->min_year &&
-                    calendar->month == 0 && day_month == MONTH_PREV) ||
-                (calendar->year == private_data->max_year &&
-                 calendar->month == 11 && day_month == MONTH_NEXT)) 
-        {
-            private_data->is_bad_day = TRUE;
-            g_signal_emit (calendar, hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL], 0);
-            return;
-        }
+        private_data->is_bad_day = TRUE;
+        g_signal_emit (calendar, hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL], 0);
+        return;
     }
 
-    if (event->type == (hildonlike ? GDK_BUTTON_RELEASE : GDK_BUTTON_PRESS))
+    if (event->type == GDK_BUTTON_RELEASE)
     {
         day = calendar->day[row][col];
 
@@ -2118,6 +2107,14 @@ hildon_calendar_expose                          (GtkWidget *widget,
             hildon_calendar_paint_week_numbers (widget);
     }
 
+    /* FIXME This appeared after 2.6 -> 2.10 migration. Without this the 
+     * arrows disappear when spinning through the calendar. Apparently, something 
+     * overdraws them somehow or the expose events go into blackhole. This is 
+     * a dirty fix... but kinda works */
+
+    hildon_calendar_paint_header (widget);
+    hildon_calendar_paint_footer (widget);
+
     return FALSE;
 }
 
@@ -2236,7 +2233,6 @@ hildon_calendar_paint_day_names                 (GtkWidget *widget)
     HildonCalendarPrivate *private_data;
     gint focus_padding;
     gint focus_width;
-    gboolean hildonlike;
 
     g_return_if_fail (HILDON_IS_CALENDAR (widget));
     calendar = HILDON_CALENDAR (widget);
@@ -2246,7 +2242,6 @@ hildon_calendar_paint_day_names                 (GtkWidget *widget)
     gtk_widget_style_get (GTK_WIDGET (widget),
             "focus-line-width", &focus_width,
             "focus-padding", &focus_padding,
-            "hildonlike", &hildonlike,
             NULL);
     /*
      * Handle freeze/thaw functionality
@@ -2274,23 +2269,6 @@ hildon_calendar_paint_day_names                 (GtkWidget *widget)
      * Draw rectangles as inverted background for the labels.
      */
 
-    /* Hildon: don't paint dayname window */
-    if (!hildonlike)
-    {
-        gdk_gc_set_foreground (gc, SELECTED_BG_COLOR (widget));
-        gdk_draw_rectangle (private_data->day_name_win, gc, TRUE,
-                CALENDAR_MARGIN, CALENDAR_MARGIN,
-                cal_width-CALENDAR_MARGIN * 2,
-                private_data->day_name_h - CALENDAR_MARGIN);
-
-        if (calendar->display_flags & HILDON_CALENDAR_SHOW_WEEK_NUMBERS)
-            gdk_draw_rectangle (private_data->day_name_win, gc, TRUE,
-                    CALENDAR_MARGIN,
-                    private_data->day_name_h - CALENDAR_YSEP,
-                    private_data->week_width - CALENDAR_YSEP - CALENDAR_MARGIN,
-                    CALENDAR_YSEP);
-    }
-
     /*
      * Write the labels
      */
@@ -2313,7 +2291,7 @@ hildon_calendar_paint_day_names                 (GtkWidget *widget)
         pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
 
         /* Hildon: draw passive focus for day name */
-        if (hildonlike && calendar->focus_col == i)
+        if (calendar->focus_col == i)
             gtk_paint_box(GTK_WIDGET (calendar)->style,
                     private_data->day_name_win,
                     GTK_STATE_NORMAL,
@@ -2337,7 +2315,7 @@ hildon_calendar_paint_week_numbers              (GtkWidget *widget)
 {
     HildonCalendar *calendar;
     GdkGC *gc; 
-    gint row, week = 0, year;
+    guint row, week = 0, year;
     gint x_loc;
     char buffer[10];
     gint y_loc;
@@ -2346,7 +2324,6 @@ hildon_calendar_paint_week_numbers              (GtkWidget *widget)
     PangoRectangle logical_rect;
     gint focus_padding;
     gint focus_width;
-    gboolean hildonlike;
 
     g_return_if_fail (HILDON_IS_CALENDAR (widget));
     g_return_if_fail (widget->window != NULL);
@@ -2368,7 +2345,6 @@ hildon_calendar_paint_week_numbers              (GtkWidget *widget)
     gtk_widget_style_get (GTK_WIDGET (widget),
             "focus-line-width", &focus_width,
             "focus-padding", &focus_padding,
-            "hildonlike", &hildonlike,
             NULL);
 
     /*
@@ -2384,21 +2360,6 @@ hildon_calendar_paint_week_numbers              (GtkWidget *widget)
     gdk_gc_set_foreground (gc, SELECTED_BG_COLOR (widget));
 
     /* Hildon: don't paint background for weekday window */
-    if (!hildonlike)
-    {
-        if (private_data->day_name_win)
-            gdk_draw_rectangle (private_data->week_win, gc, TRUE,
-                    CALENDAR_MARGIN,
-                    0,
-                    private_data->week_width - CALENDAR_MARGIN,
-                    private_data->main_h + private_data->day_name_h - CALENDAR_MARGIN);
-        else
-            gdk_draw_rectangle (private_data->week_win, gc, TRUE,
-                    CALENDAR_MARGIN,
-                    CALENDAR_MARGIN,
-                    private_data->week_width - CALENDAR_MARGIN,
-                    private_data->main_h - 2 * CALENDAR_MARGIN);
-    }
 
     /*
      * Write the labels
@@ -2428,7 +2389,7 @@ hildon_calendar_paint_week_numbers              (GtkWidget *widget)
         pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
 
         /* Hildon: draw passive focus for week */
-        if (hildonlike && calendar->focus_row == row) 
+        if (calendar->focus_row == row) 
         {
             guint y = top_y_for_row (calendar, calendar->focus_row + 1);
 
@@ -2495,7 +2456,6 @@ hildon_calendar_paint_day                       (GtkWidget *widget,
     gint y_top;
     gint y_loc;
     gint focus_width;
-    gboolean hildonlike;
 
     HildonCalendarPrivate *private_data;
     PangoLayout *layout;
@@ -2519,8 +2479,7 @@ hildon_calendar_paint_day                       (GtkWidget *widget,
         return;
     }
 
-    gtk_widget_style_get (widget, "focus-line-width", &focus_width,
-            "hildonlike", &hildonlike, NULL);
+    gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
 
     day = calendar->day[row][col];
     x_left = left_x_for_column (calendar, col);
@@ -2544,23 +2503,14 @@ hildon_calendar_paint_day                       (GtkWidget *widget,
         if (calendar->selected_day == day)
         {
             /* Hildon: use custom graphics */
-            if (hildonlike)
-            {
-                gtk_paint_box(GTK_WIDGET (calendar)->style,
-                        private_data->main_win,
-                        GTK_STATE_NORMAL,
-                        GTK_SHADOW_NONE, NULL,
-                        GTK_WIDGET (calendar), "active-day",
-                        x_left, y_top,
-                        HILDON_DAY_WIDTH,
-                        HILDON_DAY_HEIGHT);
-            }
-            else
-            {
-                gdk_gc_set_foreground (gc, SELECTED_BG_COLOR (GTK_WIDGET (calendar)));
-                gdk_draw_rectangle (private_data->main_win, gc, TRUE, x_left, y_top,
-                        HILDON_DAY_WIDTH, HILDON_DAY_HEIGHT);
-            }
+            gtk_paint_box(GTK_WIDGET (calendar)->style,
+                    private_data->main_win,
+                    GTK_STATE_NORMAL,
+                    GTK_SHADOW_NONE, NULL,
+                    GTK_WIDGET (calendar), "active-day",
+                    x_left, y_top,
+                    HILDON_DAY_WIDTH,
+                    HILDON_DAY_HEIGHT);
         } 
         if (calendar->marked_date[day-1])
             gdk_gc_set_foreground (gc, MARKED_COLOR    (GTK_WIDGET (calendar)));
@@ -2594,7 +2544,7 @@ hildon_calendar_paint_day                       (GtkWidget *widget,
     }
 
     /* Hildon: paint green indicator for current day */
-    if (hildonlike && (day == private_data->current_day && calendar->selected_day !=
+    if ((day == private_data->current_day && calendar->selected_day !=
                 private_data->current_day) && (calendar->day_month[row][col] == MONTH_CURRENT))
         hildon_calendar_check_current_date (calendar, x_left, y_top);
 
@@ -3090,8 +3040,11 @@ calendar_timer                                  (gpointer data)
     GtkSettings *settings;
     guint timeout;
 
+    gdk_window_process_updates (((GtkWidget *) calendar)->window, TRUE);
+
     settings = gtk_settings_get_default ();
     g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
+    timeout *= 8;
 
     GDK_THREADS_ENTER ();
 
@@ -3125,6 +3078,7 @@ start_spinning                                  (GtkWidget *widget,
 
     settings = gtk_settings_get_default ();
     g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
+    timeout *= 8;
 
     private_data->click_child = click_child;
 
@@ -3190,19 +3144,17 @@ hildon_calendar_button_press                    (GtkWidget *widget,
     HildonCalendar *calendar;
     HildonCalendarPrivate *private_data;
     gint arrow = -1;
-    gboolean hildonlike;
 
     calendar = HILDON_CALENDAR (widget);
     private_data = HILDON_CALENDAR_GET_PRIVATE (widget);
 
-    gtk_widget_style_get (widget, "hildonlike", &hildonlike, NULL);
 
-    if (!hildonlike || event->type == GDK_2BUTTON_PRESS)
+    if (event->type == GDK_2BUTTON_PRESS)
     {
         if (event->window == private_data->main_win)
             hildon_calendar_main_button (widget, event);
     }
-    else if (hildonlike && (event->window == private_data->main_win))
+    else if (event->window == private_data->main_win)
     {
         gint x = (gint) (event->x);
         gint y = (gint) (event->y);
@@ -3255,15 +3207,11 @@ hildon_calendar_button_release                  (GtkWidget *widget,
 {
     HildonCalendar *calendar;
     HildonCalendarPrivate *private_data;
-    gboolean hildonlike;
 
     calendar = HILDON_CALENDAR (widget);
     private_data = HILDON_CALENDAR_GET_PRIVATE (widget);
 
-    gtk_widget_style_get(widget, "hildonlike", &hildonlike,
-            NULL);
-
-    if (hildonlike && (event->window == private_data->main_win))
+    if (event->window == private_data->main_win)
     {
         hildon_calendar_main_button (widget, event);
         gint x = (gint) (event->x);
@@ -3308,41 +3256,34 @@ hildon_calendar_motion_notify                   (GtkWidget *widget,
     gint event_x, event_y;
     gint row, col;
     gint old_row, old_col;
-    gboolean hildonlike;
 
     calendar = HILDON_CALENDAR (widget);
     private_data = HILDON_CALENDAR_GET_PRIVATE (widget);
     event_x = (gint) (event->x);
     event_y = (gint) (event->y);
 
-    gtk_widget_style_get(widget, "hildonlike", &hildonlike,
-            NULL);
-
     if (event->window == private_data->main_win)
     {
-        if (hildonlike)
+        /* Hildon: make active day to move, when stylus is slided */
+        if (private_data->slide_stylus)
         {
-            /* Hildon: make active day to move, when stylus is slided */
-            if (private_data->slide_stylus)
+            gint c_row = row_from_y (calendar, event_y);
+            gint c_col = column_from_x (calendar, event_x);
+
+            if (calendar->day_month[c_row][c_col] == MONTH_PREV ||
+                    calendar->day_month[c_row][c_col] == MONTH_NEXT)
+            { }
+            else if ((private_data->prev_row != c_row || private_data->prev_col != c_col) &&
+                    (calendar->highlight_row != -1 && calendar->highlight_col != -1))
             {
-                gint c_row = row_from_y (calendar, event_y);
-                gint c_col = column_from_x (calendar, event_x);
-
-                if (calendar->day_month[c_row][c_col] == MONTH_PREV ||
-                        calendar->day_month[c_row][c_col] == MONTH_NEXT)
-                { }
-                else if ((private_data->prev_row != c_row || private_data->prev_col != c_col) &&
-                        (calendar->highlight_row != -1 && calendar->highlight_col != -1))
-                {
-                    hildon_calendar_select_and_focus_day (calendar, 
-                            calendar->day[c_row][c_col]);
-                    /* Update passive focus indicators work weekday number and name */
-                    hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar));
-                    hildon_calendar_paint_day_names (GTK_WIDGET (calendar));
-                }
-                private_data->prev_col = c_col;
-                private_data->prev_row = c_row;    
+                hildon_calendar_select_and_focus_day (calendar, 
+                        calendar->day[c_row][c_col]);
+                /* Update passive focus indicators work weekday number and name */
+                hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar));
+                hildon_calendar_paint_day_names (GTK_WIDGET (calendar));
             }
+            private_data->prev_col = c_col;
+            private_data->prev_row = c_row;    
         }
         if (private_data->in_drag) 
         {
@@ -3486,7 +3427,6 @@ hildon_calendar_paint_arrow                     (GtkWidget *widget,
     GdkGC *gc;
     HildonCalendar *calendar;
     gint state;
-    gboolean hildonlike;
     guint arrow_hlength, arrow_vlength;
     /*  gint width, height;*/
 
@@ -3495,7 +3435,6 @@ hildon_calendar_paint_arrow                     (GtkWidget *widget,
     gtk_widget_style_get (widget,
             "scroll-arrow-hlength", &arrow_hlength,
             "scroll-arrow-vlength", &arrow_vlength,
-            "hildonlike", &hildonlike,
             NULL);
 
     if (private_data->freeze_count)
@@ -3519,9 +3458,8 @@ hildon_calendar_paint_arrow                     (GtkWidget *widget,
         gdk_window_clear(window);
 
         /* Hildon: added support for dimmed arrows */
-        if (hildonlike &&
-                ((private_data->min_year && calendar->year <= private_data->min_year) ||
-                 (private_data->max_year && calendar->year >= private_data->max_year)))
+        if (((private_data->min_year && calendar->year <= private_data->min_year) ||
+             (private_data->max_year && calendar->year >= private_data->max_year)))
         {
             if (private_data->min_year &&
                     calendar->year <= private_data->min_year)
@@ -4297,7 +4235,7 @@ hildon_calendar_drag_data_received              (GtkWidget *widget,
          * supposed to call drag_status, not actually paste in the
          * data.
          */
-        str = gtk_selection_data_get_text (selection_data);
+        str = (gchar *) gtk_selection_data_get_text (selection_data);
         if (str) 
         {
             date = g_date_new ();
@@ -4316,7 +4254,7 @@ hildon_calendar_drag_data_received              (GtkWidget *widget,
     }
 
     date = g_date_new ();
-    str = gtk_selection_data_get_text (selection_data);
+    str = (gchar *) gtk_selection_data_get_text (selection_data);
     if (str) 
     {
         g_date_set_parse (date, str);