]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcalendar.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcalendar.c
index 1836ef88b6f893bdd0a6b0475b5b0c673d0c2013..cfceb08a1530698aec9c2ca9606e44b1229d2fd8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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
  *
  *
  * 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
+ * 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.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.Free
  */
 
 /*
  * 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/. 
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
 /**
  * @Short_description: Displays a calendar and allows the user to select a date
  * @Title: GtkCalendar
  *
- * #GtkCalendar is a widget that displays a calendar, one month at a time. It
- * can be created with gtk_calendar_new().
+ * #GtkCalendar is a widget that displays a Gregorian calendar, one month
+ * at a time. It can be created with gtk_calendar_new().
  *
  * The month and year currently displayed can be altered with
- * gtk_calendar_select_month(). The exact day can be selected from the displayed
- * month using gtk_calendar_select_day().
+ * gtk_calendar_select_month(). The exact day can be selected from the
+ * displayed month using gtk_calendar_select_day().
  *
- * To place a visual marker on a particular day, use gtk_calendar_mark_day() and
- * to remove the marker, gtk_calendar_unmark_day(). Alternative, all marks can
- * be cleared with gtk_calendar_clear_marks().
+ * To place a visual marker on a particular day, use gtk_calendar_mark_day()
+ * and to remove the marker, gtk_calendar_unmark_day(). Alternative, all
+ * marks can be cleared with gtk_calendar_clear_marks().
  *
  * The way in which the calendar itself is displayed can be altered using
  * gtk_calendar_set_display_options().
  *
  * The selected date can be retrieved from a #GtkCalendar using
  * gtk_calendar_get_date().
+ *
+ * Users should be aware that, although the Gregorian calendar is the legal
+ * calendar in most countries, it was adopted progressively between 1582 and
+ * 1929. Display before these dates is likely to be historically incorrect.
  */
 
 #include "config.h"
 #include "gtkmarshalers.h"
 #include "gtktooltip.h"
 #include "gtkprivate.h"
-#include "gdk/gdkkeysyms.h"
 
 /***************************************************************************/
-/* The following date routines are taken from the lib_date package. 
+/* The following date routines are taken from the lib_date package.
  * They have been minimally edited to avoid conflict with types defined
  * in win32 headers.
  */
@@ -100,20 +102,20 @@ static const guint days_in_months[2][14] =
 static glong  calc_days(guint year, guint mm, guint dd);
 static guint  day_of_week(guint year, guint mm, guint dd);
 static glong  dates_difference(guint year1, guint mm1, guint dd1,
-                              guint year2, guint mm2, guint dd2);
+                               guint year2, guint mm2, guint dd2);
 static guint  weeks_in_year(guint year);
 
-static gboolean 
+static gboolean
 leap (guint year)
 {
   return((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0));
 }
 
-static guint 
+static guint
 day_of_week (guint year, guint mm, guint dd)
 {
   glong  days;
-  
+
   days = calc_days(year, mm, dd);
   if (days > 0L)
     {
@@ -129,7 +131,7 @@ static guint weeks_in_year(guint year)
   return(52 + ((day_of_week(year,1,1)==4) || (day_of_week(year,12,31)==4)));
 }
 
-static gboolean 
+static gboolean
 check_date(guint year, guint mm, guint dd)
 {
   if (year < 1) return FALSE;
@@ -138,55 +140,55 @@ check_date(guint year, guint mm, guint dd)
   return TRUE;
 }
 
-static guint 
+static guint
 week_number(guint year, guint mm, guint dd)
 {
   guint first;
-  
+
   first = day_of_week(year,1,1) - 1;
   return( (guint) ( (dates_difference(year,1,1, year,mm,dd) + first) / 7L ) +
-         (first < 4) );
+          (first < 4) );
 }
 
-static glong 
+static glong
 year_to_days(guint year)
 {
   return( year * 365L + (year / 4) - (year / 100) + (year / 400) );
 }
 
 
-static glong 
+static glong
 calc_days(guint year, guint mm, guint dd)
 {
   gboolean lp;
-  
+
   if (year < 1) return(0L);
   if ((mm < 1) || (mm > 12)) return(0L);
   if ((dd < 1) || (dd > month_length[(lp = leap(year))][mm])) return(0L);
   return( year_to_days(--year) + days_in_months[lp][mm] + dd );
 }
 
-static gboolean 
+static gboolean
 week_of_year(guint *week, guint *year, guint mm, guint dd)
 {
   if (check_date(*year,mm,dd))
     {
       *week = week_number(*year,mm,dd);
-      if (*week == 0) 
-       *week = weeks_in_year(--(*year));
+      if (*week == 0)
+        *week = weeks_in_year(--(*year));
       else if (*week > weeks_in_year(*year))
-       {
-         *week = 1;
-         (*year)++;
-       }
+        {
+          *week = 1;
+          (*year)++;
+        }
       return TRUE;
     }
   return FALSE;
 }
 
-static glong 
+static glong
 dates_difference(guint year1, guint mm1, guint dd1,
-                guint year2, guint mm2, guint dd2)
+                 guint year2, guint mm2, guint dd2)
 {
   return( calc_days(year2, mm2, dd2) - calc_days(year1, mm1, dd1) );
 }
@@ -194,25 +196,13 @@ dates_difference(guint year1, guint mm1, guint dd1,
 /*** END OF lib_date routines ********************************************/
 
 /* Spacing around day/week headers and main area, inside those windows */
-#define CALENDAR_MARGIN                 0
+#define CALENDAR_MARGIN          0
 
-#define DAY_XSEP                0 /* not really good for small calendar */
-#define DAY_YSEP                0 /* not really good for small calendar */
+#define DAY_XSEP                 0 /* not really good for small calendar */
+#define DAY_YSEP                 0 /* not really good for small calendar */
 
 #define SCROLL_DELAY_FACTOR      5
 
-/* Color usage */
-#define HEADER_FG_COLOR(widget)                 (& gtk_widget_get_style (widget)->fg[gtk_widget_get_state (widget)])
-#define HEADER_BG_COLOR(widget)                 (& gtk_widget_get_style (widget)->bg[gtk_widget_get_state (widget)])
-#define SELECTED_BG_COLOR(widget)       (& gtk_widget_get_style (widget)->base[gtk_widget_has_focus (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
-#define SELECTED_FG_COLOR(widget)       (& gtk_widget_get_style (widget)->text[gtk_widget_has_focus (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
-#define NORMAL_DAY_COLOR(widget)        (& gtk_widget_get_style (widget)->text[gtk_widget_get_state (widget)])
-#define PREV_MONTH_COLOR(widget)        (& gtk_widget_get_style (widget)->mid[gtk_widget_get_state (widget)])
-#define NEXT_MONTH_COLOR(widget)        (& gtk_widget_get_style (widget)->mid[gtk_widget_get_state (widget)])
-#define MARKED_COLOR(widget)            (& gtk_widget_get_style (widget)->text[gtk_widget_get_state (widget)])
-#define BACKGROUND_COLOR(widget)        (& gtk_widget_get_style (widget)->base[gtk_widget_get_state (widget)])
-#define HIGHLIGHT_BACK_COLOR(widget)    (& gtk_widget_get_style (widget)->mid[gtk_widget_get_state (widget)])
-
 enum {
   ARROW_YEAR_LEFT,
   ARROW_YEAR_RIGHT,
@@ -257,10 +247,7 @@ static guint gtk_calendar_signals[LAST_SIGNAL] = { 0 };
 struct _GtkCalendarPrivate
 {
   GtkCalendarDisplayOptions display_flags;
-  GtkStyle  *header_style;
-  GtkStyle  *label_style;
 
-  GdkColor marked_date_color[31];
   GdkWindow *main_win;
   GdkWindow *arrow_win[4];
 
@@ -283,10 +270,10 @@ struct _GtkCalendarPrivate
   guint day_name_h;
   guint main_h;
 
-  guint        arrow_state[4];
-  guint        arrow_width;
-  guint        max_month_width;
-  guint        max_year_width;
+  guint arrow_prelight : 4;
+  guint arrow_width;
+  guint max_month_width;
+  guint max_year_width;
 
   guint day_width;
   guint week_width;
@@ -298,7 +285,7 @@ struct _GtkCalendarPrivate
   guint max_label_char_ascent;
   guint max_label_char_descent;
   guint max_week_char_width;
-  
+
   /* flags */
   guint year_before : 1;
 
@@ -331,16 +318,18 @@ struct _GtkCalendarPrivate
 static void gtk_calendar_finalize     (GObject      *calendar);
 static void gtk_calendar_destroy      (GtkWidget    *widget);
 static void gtk_calendar_set_property (GObject      *object,
-                                      guint         prop_id,
-                                      const GValue *value,
-                                      GParamSpec   *pspec);
+                                       guint         prop_id,
+                                       const GValue *value,
+                                       GParamSpec   *pspec);
 static void gtk_calendar_get_property (GObject      *object,
-                                      guint         prop_id,
-                                      GValue       *value,
-                                      GParamSpec   *pspec);
+                                       guint         prop_id,
+                                       GValue       *value,
+                                       GParamSpec   *pspec);
 
 static void     gtk_calendar_realize        (GtkWidget        *widget);
 static void     gtk_calendar_unrealize      (GtkWidget        *widget);
+static void     gtk_calendar_map            (GtkWidget        *widget);
+static void     gtk_calendar_unmap          (GtkWidget        *widget);
 static void     gtk_calendar_get_preferred_width  (GtkWidget   *widget,
                                                    gint        *minimum,
                                                    gint        *natural);
@@ -348,72 +337,73 @@ static void     gtk_calendar_get_preferred_height (GtkWidget   *widget,
                                                    gint        *minimum,
                                                    gint        *natural);
 static void     gtk_calendar_size_allocate  (GtkWidget        *widget,
-                                            GtkAllocation    *allocation);
+                                             GtkAllocation    *allocation);
 static gboolean gtk_calendar_draw           (GtkWidget        *widget,
                                              cairo_t          *cr);
 static gboolean gtk_calendar_button_press   (GtkWidget        *widget,
-                                            GdkEventButton   *event);
+                                             GdkEventButton   *event);
 static gboolean gtk_calendar_button_release (GtkWidget        *widget,
-                                            GdkEventButton   *event);
+                                             GdkEventButton   *event);
 static gboolean gtk_calendar_motion_notify  (GtkWidget        *widget,
-                                            GdkEventMotion   *event);
+                                             GdkEventMotion   *event);
 static gboolean gtk_calendar_enter_notify   (GtkWidget        *widget,
-                                            GdkEventCrossing *event);
+                                             GdkEventCrossing *event);
 static gboolean gtk_calendar_leave_notify   (GtkWidget        *widget,
-                                            GdkEventCrossing *event);
+                                             GdkEventCrossing *event);
 static gboolean gtk_calendar_scroll         (GtkWidget        *widget,
-                                            GdkEventScroll   *event);
+                                             GdkEventScroll   *event);
 static gboolean gtk_calendar_key_press      (GtkWidget        *widget,
-                                            GdkEventKey      *event);
+                                             GdkEventKey      *event);
 static gboolean gtk_calendar_focus_out      (GtkWidget        *widget,
-                                            GdkEventFocus    *event);
+                                             GdkEventFocus    *event);
 static void     gtk_calendar_grab_notify    (GtkWidget        *widget,
-                                            gboolean          was_grabbed);
-static void     gtk_calendar_state_changed  (GtkWidget        *widget,
-                                            GtkStateType      previous_state);
+                                             gboolean          was_grabbed);
+static void     gtk_calendar_state_flags_changed  (GtkWidget     *widget,
+                                                   GtkStateFlags  previous_state);
 static gboolean gtk_calendar_query_tooltip  (GtkWidget        *widget,
-                                            gint              x,
-                                            gint              y,
-                                            gboolean          keyboard_mode,
-                                            GtkTooltip       *tooltip);
+                                             gint              x,
+                                             gint              y,
+                                             gboolean          keyboard_mode,
+                                             GtkTooltip       *tooltip);
 
 static void     gtk_calendar_drag_data_get      (GtkWidget        *widget,
-                                                GdkDragContext   *context,
-                                                GtkSelectionData *selection_data,
-                                                guint             info,
-                                                guint             time);
+                                                 GdkDragContext   *context,
+                                                 GtkSelectionData *selection_data,
+                                                 guint             info,
+                                                 guint             time);
 static void     gtk_calendar_drag_data_received (GtkWidget        *widget,
-                                                GdkDragContext   *context,
-                                                gint              x,
-                                                gint              y,
-                                                GtkSelectionData *selection_data,
-                                                guint             info,
-                                                guint             time);
+                                                 GdkDragContext   *context,
+                                                 gint              x,
+                                                 gint              y,
+                                                 GtkSelectionData *selection_data,
+                                                 guint             info,
+                                                 guint             time);
 static gboolean gtk_calendar_drag_motion        (GtkWidget        *widget,
-                                                GdkDragContext   *context,
-                                                gint              x,
-                                                gint              y,
-                                                guint             time);
+                                                 GdkDragContext   *context,
+                                                 gint              x,
+                                                 gint              y,
+                                                 guint             time);
 static void     gtk_calendar_drag_leave         (GtkWidget        *widget,
-                                                GdkDragContext   *context,
-                                                guint             time);
+                                                 GdkDragContext   *context,
+                                                 guint             time);
 static gboolean gtk_calendar_drag_drop          (GtkWidget        *widget,
-                                                GdkDragContext   *context,
-                                                gint              x,
-                                                gint              y,
-                                                guint             time);
+                                                 GdkDragContext   *context,
+                                                 gint              x,
+                                                 gint              y,
+                                                 guint             time);
+
 
 static void calendar_start_spinning (GtkCalendar *calendar,
-                                    gint         click_child);
+                                     gint         click_child);
 static void calendar_stop_spinning  (GtkCalendar *calendar);
 
 static void calendar_invalidate_day     (GtkCalendar *widget,
-                                        gint       row,
-                                        gint       col);
+                                         gint       row,
+                                         gint       col);
 static void calendar_invalidate_day_num (GtkCalendar *widget,
-                                        gint       day);
+                                         gint       day);
 static void calendar_invalidate_arrow   (GtkCalendar *widget,
-                                        guint      arrow);
+                                         guint      arrow);
 
 static void calendar_compute_days      (GtkCalendar *calendar);
 static gint calendar_get_xsep          (GtkCalendar *calendar);
@@ -433,7 +423,7 @@ gtk_calendar_class_init (GtkCalendarClass *class)
 
   gobject_class = (GObjectClass*)  class;
   widget_class = (GtkWidgetClass*) class;
-  
+
   gobject_class->set_property = gtk_calendar_set_property;
   gobject_class->get_property = gtk_calendar_get_property;
   gobject_class->finalize = gtk_calendar_finalize;
@@ -441,6 +431,8 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   widget_class->destroy = gtk_calendar_destroy;
   widget_class->realize = gtk_calendar_realize;
   widget_class->unrealize = gtk_calendar_unrealize;
+  widget_class->map = gtk_calendar_map;
+  widget_class->unmap = gtk_calendar_unmap;
   widget_class->draw = gtk_calendar_draw;
   widget_class->get_preferred_width = gtk_calendar_get_preferred_width;
   widget_class->get_preferred_height = gtk_calendar_get_preferred_height;
@@ -452,7 +444,7 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   widget_class->leave_notify_event = gtk_calendar_leave_notify;
   widget_class->key_press_event = gtk_calendar_key_press;
   widget_class->scroll_event = gtk_calendar_scroll;
-  widget_class->state_changed = gtk_calendar_state_changed;
+  widget_class->state_flags_changed = gtk_calendar_state_flags_changed;
   widget_class->grab_notify = gtk_calendar_grab_notify;
   widget_class->focus_out_event = gtk_calendar_focus_out;
   widget_class->query_tooltip = gtk_calendar_query_tooltip;
@@ -462,49 +454,51 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   widget_class->drag_leave = gtk_calendar_drag_leave;
   widget_class->drag_drop = gtk_calendar_drag_drop;
   widget_class->drag_data_received = gtk_calendar_drag_data_received;
-  
+
+  gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_CALENDAR);
+
   /**
    * GtkCalendar:year:
    *
-   * The selected year. 
+   * The selected year.
    * This property gets initially set to the current year.
-   */  
+   */
   g_object_class_install_property (gobject_class,
                                    PROP_YEAR,
                                    g_param_spec_int ("year",
-                                                    P_("Year"),
-                                                    P_("The selected year"),
-                                                    0, G_MAXINT >> 9, 0,
-                                                    GTK_PARAM_READWRITE));
+                                                     P_("Year"),
+                                                     P_("The selected year"),
+                                                     0, G_MAXINT >> 9, 0,
+                                                     GTK_PARAM_READWRITE));
 
   /**
    * GtkCalendar:month:
    *
-   * The selected month (as a number between 0 and 11). 
+   * The selected month (as a number between 0 and 11).
    * This property gets initially set to the current month.
    */
   g_object_class_install_property (gobject_class,
                                    PROP_MONTH,
                                    g_param_spec_int ("month",
-                                                    P_("Month"),
-                                                    P_("The selected month (as a number between 0 and 11)"),
-                                                    0, 11, 0,
-                                                    GTK_PARAM_READWRITE));
+                                                     P_("Month"),
+                                                     P_("The selected month (as a number between 0 and 11)"),
+                                                     0, 11, 0,
+                                                     GTK_PARAM_READWRITE));
 
   /**
    * GtkCalendar:day:
    *
-   * The selected day (as a number between 1 and 31, or 0 
+   * The selected day (as a number between 1 and 31, or 0
    * to unselect the currently selected day).
    * This property gets initially set to the current day.
    */
   g_object_class_install_property (gobject_class,
                                    PROP_DAY,
                                    g_param_spec_int ("day",
-                                                    P_("Day"),
-                                                    P_("The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day)"),
-                                                    0, 31, 0,
-                                                    GTK_PARAM_READWRITE));
+                                                     P_("Day"),
+                                                     P_("The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day)"),
+                                                     0, 31, 0,
+                                                     GTK_PARAM_READWRITE));
 
 /**
  * GtkCalendar:show-heading:
@@ -516,10 +510,10 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_HEADING,
                                    g_param_spec_boolean ("show-heading",
-                                                        P_("Show Heading"),
-                                                        P_("If TRUE, a heading is displayed"),
-                                                        TRUE,
-                                                        GTK_PARAM_READWRITE));
+                                                         P_("Show Heading"),
+                                                         P_("If TRUE, a heading is displayed"),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE));
 
 /**
  * GtkCalendar:show-day-names:
@@ -531,10 +525,10 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_DAY_NAMES,
                                    g_param_spec_boolean ("show-day-names",
-                                                        P_("Show Day Names"),
-                                                        P_("If TRUE, day names are displayed"),
-                                                        TRUE,
-                                                        GTK_PARAM_READWRITE));
+                                                         P_("Show Day Names"),
+                                                         P_("If TRUE, day names are displayed"),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE));
 /**
  * GtkCalendar:no-month-change:
  *
@@ -545,10 +539,10 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_NO_MONTH_CHANGE,
                                    g_param_spec_boolean ("no-month-change",
-                                                        P_("No Month Change"),
-                                                        P_("If TRUE, the selected month cannot be changed"),
-                                                        FALSE,
-                                                        GTK_PARAM_READWRITE));
+                                                         P_("No Month Change"),
+                                                         P_("If TRUE, the selected month cannot be changed"),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
 
 /**
  * GtkCalendar:show-week-numbers:
@@ -560,10 +554,10 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_WEEK_NUMBERS,
                                    g_param_spec_boolean ("show-week-numbers",
-                                                        P_("Show Week Numbers"),
-                                                        P_("If TRUE, week numbers are displayed"),
-                                                        FALSE,
-                                                        GTK_PARAM_READWRITE));
+                                                         P_("Show Week Numbers"),
+                                                         P_("If TRUE, week numbers are displayed"),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
 
 /**
  * GtkCalendar:detail-width-chars:
@@ -576,10 +570,10 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_DETAIL_WIDTH_CHARS,
                                    g_param_spec_int ("detail-width-chars",
-                                                    P_("Details Width"),
-                                                    P_("Details width in characters"),
-                                                    0, 127, 0,
-                                                    GTK_PARAM_READWRITE));
+                                                     P_("Details Width"),
+                                                     P_("Details width in characters"),
+                                                     0, 127, 0,
+                                                     GTK_PARAM_READWRITE));
 
 /**
  * GtkCalendar:detail-height-rows:
@@ -592,10 +586,10 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_DETAIL_HEIGHT_ROWS,
                                    g_param_spec_int ("detail-height-rows",
-                                                    P_("Details Height"),
-                                                    P_("Details height in rows"),
-                                                    0, 127, 0,
-                                                    GTK_PARAM_READWRITE));
+                                                     P_("Details Height"),
+                                                     P_("Details height in rows"),
+                                                     0, 127, 0,
+                                                     GTK_PARAM_READWRITE));
 
 /**
  * GtkCalendar:show-details:
@@ -609,14 +603,14 @@ gtk_calendar_class_init (GtkCalendarClass *class)
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_DETAILS,
                                    g_param_spec_boolean ("show-details",
-                                                        P_("Show Details"),
-                                                        P_("If TRUE, details are shown"),
-                                                        TRUE,
-                                                        GTK_PARAM_READWRITE));
+                                                         P_("Show Details"),
+                                                         P_("If TRUE, details are shown"),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE));
 
 
   /**
-   * GtkCalendar:inner-border
+   * GtkCalendar:inner-border:
    *
    * The spacing around the day/week headers and main area.
    */
@@ -628,7 +622,7 @@ gtk_calendar_class_init (GtkCalendarClass *class)
                                                              GTK_PARAM_READABLE));
 
   /**
-   * GtkCalndar:vertical-separation
+   * GtkCalndar:vertical-separation:
    *
    * Separation between day headers and main area.
    */
@@ -640,7 +634,7 @@ gtk_calendar_class_init (GtkCalendarClass *class)
                                                              GTK_PARAM_READABLE));
 
   /**
-   * GtkCalendar:horizontal-separation
+   * GtkCalendar:horizontal-separation:
    *
    * Separation between week headers and main area.
    */
@@ -660,12 +654,12 @@ gtk_calendar_class_init (GtkCalendarClass *class)
    */
   gtk_calendar_signals[MONTH_CHANGED_SIGNAL] =
     g_signal_new (I_("month-changed"),
-                 G_OBJECT_CLASS_TYPE (gobject_class),
-                 G_SIGNAL_RUN_FIRST,
-                 G_STRUCT_OFFSET (GtkCalendarClass, month_changed),
-                 NULL, NULL,
-                 _gtk_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0);
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkCalendarClass, month_changed),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 
   /**
    * GtkCalendar::day-selected:
@@ -675,12 +669,12 @@ gtk_calendar_class_init (GtkCalendarClass *class)
    */
   gtk_calendar_signals[DAY_SELECTED_SIGNAL] =
     g_signal_new (I_("day-selected"),
-                 G_OBJECT_CLASS_TYPE (gobject_class),
-                 G_SIGNAL_RUN_FIRST,
-                 G_STRUCT_OFFSET (GtkCalendarClass, day_selected),
-                 NULL, NULL,
-                 _gtk_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0);
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkCalendarClass, day_selected),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 
   /**
    * GtkCalendar::day-selected-double-click:
@@ -690,12 +684,12 @@ gtk_calendar_class_init (GtkCalendarClass *class)
    */
   gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL] =
     g_signal_new (I_("day-selected-double-click"),
-                 G_OBJECT_CLASS_TYPE (gobject_class),
-                 G_SIGNAL_RUN_FIRST,
-                 G_STRUCT_OFFSET (GtkCalendarClass, day_selected_double_click),
-                 NULL, NULL,
-                 _gtk_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0);
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkCalendarClass, day_selected_double_click),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 
   /**
    * GtkCalendar::prev-month:
@@ -705,12 +699,12 @@ gtk_calendar_class_init (GtkCalendarClass *class)
    */
   gtk_calendar_signals[PREV_MONTH_SIGNAL] =
     g_signal_new (I_("prev-month"),
-                 G_OBJECT_CLASS_TYPE (gobject_class),
-                 G_SIGNAL_RUN_FIRST,
-                 G_STRUCT_OFFSET (GtkCalendarClass, prev_month),
-                 NULL, NULL,
-                 _gtk_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0);
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkCalendarClass, prev_month),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 
   /**
    * GtkCalendar::next-month:
@@ -720,12 +714,12 @@ gtk_calendar_class_init (GtkCalendarClass *class)
    */
   gtk_calendar_signals[NEXT_MONTH_SIGNAL] =
     g_signal_new (I_("next-month"),
-                 G_OBJECT_CLASS_TYPE (gobject_class),
-                 G_SIGNAL_RUN_FIRST,
-                 G_STRUCT_OFFSET (GtkCalendarClass, next_month),
-                 NULL, NULL,
-                 _gtk_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0);
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkCalendarClass, next_month),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 
   /**
    * GtkCalendar::prev-year:
@@ -735,12 +729,12 @@ gtk_calendar_class_init (GtkCalendarClass *class)
    */
   gtk_calendar_signals[PREV_YEAR_SIGNAL] =
     g_signal_new (I_("prev-year"),
-                 G_OBJECT_CLASS_TYPE (gobject_class),
-                 G_SIGNAL_RUN_FIRST,
-                 G_STRUCT_OFFSET (GtkCalendarClass, prev_year),
-                 NULL, NULL,
-                 _gtk_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0);
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkCalendarClass, prev_year),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
 
   /**
    * GtkCalendar::next-year:
@@ -750,13 +744,13 @@ gtk_calendar_class_init (GtkCalendarClass *class)
    */
   gtk_calendar_signals[NEXT_YEAR_SIGNAL] =
     g_signal_new (I_("next-year"),
-                 G_OBJECT_CLASS_TYPE (gobject_class),
-                 G_SIGNAL_RUN_FIRST,
-                 G_STRUCT_OFFSET (GtkCalendarClass, next_year),
-                 NULL, NULL,
-                 _gtk_marshal_VOID__VOID,
-                 G_TYPE_NONE, 0);
-  
+                  G_OBJECT_CLASS_TYPE (gobject_class),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GtkCalendarClass, next_year),
+                  NULL, NULL,
+                  _gtk_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
   g_type_class_add_private (gobject_class, sizeof (GtkCalendarPrivate));
 }
 
@@ -785,44 +779,44 @@ gtk_calendar_init (GtkCalendar *calendar)
 #endif
 
   priv = calendar->priv = G_TYPE_INSTANCE_GET_PRIVATE (calendar,
-                                                      GTK_TYPE_CALENDAR,
-                                                      GtkCalendarPrivate);
+                                                       GTK_TYPE_CALENDAR,
+                                                       GtkCalendarPrivate);
 
   gtk_widget_set_can_focus (widget, TRUE);
   gtk_widget_set_has_window (widget, FALSE);
-  
+
   if (!default_abbreviated_dayname[0])
     for (i=0; i<7; i++)
       {
 #ifndef G_OS_WIN32
-       tmp_time= (i+3)*86400;
-       strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
-       default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+        tmp_time= (i+3)*86400;
+        strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
+        default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
 #else
-       if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
-                            wbuffer, G_N_ELEMENTS (wbuffer)))
-         default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
-       else
-         default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+        if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
+                             wbuffer, G_N_ELEMENTS (wbuffer)))
+          default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
+        else
+          default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
 #endif
       }
-  
+
   if (!default_monthname[0])
     for (i=0; i<12; i++)
       {
 #ifndef G_OS_WIN32
-       tmp_time=i*2764800;
-       strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
-       default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+        tmp_time=i*2764800;
+        strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
+        default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
 #else
-       if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
-                            wbuffer, G_N_ELEMENTS (wbuffer)))
-         default_monthname[i] = g_strdup_printf ("(%d)", i);
-       else
-         default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+        if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
+                             wbuffer, G_N_ELEMENTS (wbuffer)))
+          default_monthname[i] = g_strdup_printf ("(%d)", i);
+        else
+          default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
 #endif
       }
-  
+
   /* Set defaults */
   secs = time (NULL);
   tm = localtime (&secs);
@@ -833,11 +827,11 @@ gtk_calendar_init (GtkCalendar *calendar)
     priv->marked_date[i] = FALSE;
   priv->num_marked_dates = 0;
   priv->selected_day = tm->tm_mday;
-  
+
   priv->display_flags = (GTK_CALENDAR_SHOW_HEADING |
-                            GTK_CALENDAR_SHOW_DAY_NAMES |
-                            GTK_CALENDAR_SHOW_DETAILS);
-  
+                             GTK_CALENDAR_SHOW_DAY_NAMES |
+                             GTK_CALENDAR_SHOW_DETAILS);
+
   priv->focus_row = -1;
   priv->focus_col = -1;
 
@@ -886,9 +880,9 @@ gtk_calendar_init (GtkCalendar *calendar)
   week_start = NULL;
 
   if (GetLocaleInfoW (GetThreadLocale (), LOCALE_IFIRSTDAYOFWEEK,
-                     wbuffer, G_N_ELEMENTS (wbuffer)))
+                      wbuffer, G_N_ELEMENTS (wbuffer)))
     week_start = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
-      
+
   if (week_start != NULL)
     {
       priv->week_start = (week_start[0] - '0' + 1) % 7;
@@ -912,14 +906,14 @@ gtk_calendar_init (GtkCalendar *calendar)
   /* Translate to calendar:week_start:0 if you want Sunday to be the
    * first day of the week to calendar:week_start:1 if you want Monday
    * to be the first day of the week, and so on.
-   */  
+   */
   week_start = _("calendar:week_start:0");
 
   if (strncmp (week_start, "calendar:week_start:", 20) == 0)
     priv->week_start = *(week_start + 20) - '0';
-  else 
+  else
     priv->week_start = -1;
-  
+
   if (priv->week_start < 0 || priv->week_start > 6)
     {
       g_warning ("Whoever translated calendar:week_start:0 did so wrongly.\n");
@@ -968,11 +962,11 @@ calendar_set_month_next (GtkCalendar *calendar)
 
   calendar_compute_days (calendar);
   g_signal_emit (calendar,
-                gtk_calendar_signals[NEXT_MONTH_SIGNAL],
-                0);
+                 gtk_calendar_signals[NEXT_MONTH_SIGNAL],
+                 0);
   g_signal_emit (calendar,
-                gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
-                0);
+                 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+                 0);
 
   month_len = month_length[leap (priv->year)][priv->month + 1];
 
@@ -996,11 +990,11 @@ calendar_set_year_prev (GtkCalendar *calendar)
   priv->year--;
   calendar_compute_days (calendar);
   g_signal_emit (calendar,
-                gtk_calendar_signals[PREV_YEAR_SIGNAL],
-                0);
+                 gtk_calendar_signals[PREV_YEAR_SIGNAL],
+                 0);
   g_signal_emit (calendar,
-                gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
-                0);
+                 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+                 0);
 
   month_len = month_length[leap (priv->year)][priv->month + 1];
 
@@ -1024,11 +1018,11 @@ calendar_set_year_next (GtkCalendar *calendar)
   priv->year++;
   calendar_compute_days (calendar);
   g_signal_emit (calendar,
-                gtk_calendar_signals[NEXT_YEAR_SIGNAL],
-                0);
+                 gtk_calendar_signals[NEXT_YEAR_SIGNAL],
+                 0);
   g_signal_emit (calendar,
-                gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
-                0);
+                 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+                 0);
 
   month_len = month_length[leap (priv->year)][priv->month + 1];
 
@@ -1070,18 +1064,18 @@ calendar_compute_days (GtkCalendar *calendar)
   else
     ndays_in_prev_month = month_length[leap (year)][12];
   day = ndays_in_prev_month - first_day + 1;
-  
+
   row = 0;
   if (first_day > 0)
     {
       for (col = 0; col < first_day; col++)
-       {
-         priv->day[row][col] = day;
-         priv->day_month[row][col] = MONTH_PREV;
-         day++;
-       }
+        {
+          priv->day[row][col] = day;
+          priv->day_month[row][col] = MONTH_PREV;
+          day++;
+        }
     }
-  
+
   /* Compute days of current month */
   col = first_day;
   for (day = 1; day <= ndays_in_month; day++)
@@ -1091,50 +1085,50 @@ calendar_compute_days (GtkCalendar *calendar)
 
       col++;
       if (col == 7)
-       {
-         row++;
-         col = 0;
-       }
+        {
+          row++;
+          col = 0;
+        }
     }
-  
+
   /* Compute days of next month */
   day = 1;
   for (; row <= 5; row++)
     {
       for (; col <= 6; col++)
-       {
-         priv->day[row][col] = day;
-         priv->day_month[row][col] = MONTH_NEXT;
-         day++;
-       }
+        {
+          priv->day[row][col] = day;
+          priv->day_month[row][col] = MONTH_NEXT;
+          day++;
+        }
       col = 0;
     }
 }
 
 static void
 calendar_select_and_focus_day (GtkCalendar *calendar,
-                              guint        day)
+                               guint        day)
 {
   GtkCalendarPrivate *priv = calendar->priv;
   gint old_focus_row = priv->focus_row;
   gint old_focus_col = priv->focus_col;
   gint row;
   gint col;
-  
+
   for (row = 0; row < 6; row ++)
     for (col = 0; col < 7; col++)
       {
-       if (priv->day_month[row][col] == MONTH_CURRENT
-           && priv->day[row][col] == day)
-         {
-           priv->focus_row = row;
-           priv->focus_col = col;
-         }
+        if (priv->day_month[row][col] == MONTH_CURRENT
+            && priv->day[row][col] == day)
+          {
+            priv->focus_row = row;
+            priv->focus_col = col;
+          }
       }
 
   if (old_focus_row != -1 && old_focus_col != -1)
     calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
-  
+
   gtk_calendar_select_day (calendar, day);
 }
 
@@ -1149,8 +1143,8 @@ calendar_row_height (GtkCalendar *calendar)
   GtkCalendarPrivate *priv = calendar->priv;
 
   return (GTK_CALENDAR_GET_PRIVATE (calendar)->main_h - CALENDAR_MARGIN
-         - ((priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
-            ? calendar_get_ysep (calendar) : CALENDAR_MARGIN)) / 6;
+          - ((priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
+             ? calendar_get_ysep (calendar) : CALENDAR_MARGIN)) / 6;
 }
 
 
@@ -1158,19 +1152,23 @@ calendar_row_height (GtkCalendar *calendar)
  * for the left of the column */
 static gint
 calendar_left_x_for_column (GtkCalendar *calendar,
-                           gint         column)
+                            gint         column)
 {
   GtkCalendarPrivate *priv = calendar->priv;
   gint width;
   gint x_left;
   gint week_width;
   gint calendar_xsep = calendar_get_xsep (calendar);
-  GtkStyle *style;
+  GtkStyleContext *context;
+  GtkStateFlags state;
   gint inner_border = calendar_get_inner_border (calendar);
+  GtkBorder padding;
 
-  style = gtk_widget_get_style (GTK_WIDGET (calendar));
+  context = gtk_widget_get_style_context (GTK_WIDGET (calendar));
+  state = gtk_widget_get_state_flags (GTK_WIDGET (calendar));
+  gtk_style_context_get_padding (context, state, &padding);
 
-  week_width = priv->week_width + style->xthickness + inner_border;
+  week_width = priv->week_width + padding.left + inner_border;
 
   if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
     {
@@ -1183,7 +1181,7 @@ calendar_left_x_for_column (GtkCalendar *calendar,
     x_left = week_width + calendar_xsep + (width + DAY_XSEP) * column;
   else
     x_left = week_width + CALENDAR_MARGIN + (width + DAY_XSEP) * column;
-  
+
   return x_left;
 }
 
@@ -1191,25 +1189,25 @@ calendar_left_x_for_column (GtkCalendar *calendar,
  * x pixel of the xwindow is in */
 static gint
 calendar_column_from_x (GtkCalendar *calendar,
-                       gint         event_x)
+                        gint         event_x)
 {
   gint c, column;
   gint x_left, x_right;
-  
+
   column = -1;
-  
+
   for (c = 0; c < 7; c++)
     {
       x_left = calendar_left_x_for_column (calendar, c);
       x_right = x_left + GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
-      
+
       if (event_x >= x_left && event_x < x_right)
-       {
-         column = c;
-         break;
-       }
+        {
+          column = c;
+          break;
+        }
     }
-  
+
   return column;
 }
 
@@ -1217,19 +1215,24 @@ calendar_column_from_x (GtkCalendar *calendar,
  * for the top of the row */
 static gint
 calendar_top_y_for_row (GtkCalendar *calendar,
-                       gint         row)
+                        gint         row)
 {
-  GtkStyle *style;
+  GtkStyleContext *context;
   GtkAllocation allocation;
   gint inner_border = calendar_get_inner_border (calendar);
+  GtkStateFlags state;
+  GtkBorder padding;
 
   gtk_widget_get_allocation (GTK_WIDGET (calendar), &allocation);
-  style = gtk_widget_get_style (GTK_WIDGET (calendar));
-  
+  context = gtk_widget_get_style_context (GTK_WIDGET (calendar));
+  state = gtk_widget_get_state_flags (GTK_WIDGET (calendar));
+
+  gtk_style_context_get_padding (context, state, &padding);
+
   return  allocation.height
-          - style->ythickness - inner_border
-         - (CALENDAR_MARGIN + (6 - row)
-            * calendar_row_height (calendar));
+          - padding.top - inner_border
+          - (CALENDAR_MARGIN + (6 - row)
+             * calendar_row_height (calendar));
 }
 
 /* row_from_y: returns the row 0-5 that the
@@ -1241,38 +1244,43 @@ calendar_row_from_y (GtkCalendar *calendar,
   gint r, row;
   gint height;
   gint y_top, y_bottom;
-  
+
   height = calendar_row_height (calendar);
   row = -1;
-  
+
   for (r = 0; r < 6; r++)
     {
       y_top = calendar_top_y_for_row (calendar, r);
       y_bottom = y_top + height;
-      
+
       if (event_y >= y_top && event_y < y_bottom)
-       {
-         row = r;
-         break;
-       }
+        {
+          row = r;
+          break;
+        }
     }
-  
+
   return row;
 }
 
 static void
 calendar_arrow_rectangle (GtkCalendar  *calendar,
-                         guint         arrow,
-                         GdkRectangle *rect)
+                          guint         arrow,
+                          GdkRectangle *rect)
 {
   GtkWidget *widget = GTK_WIDGET (calendar);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   GtkAllocation allocation;
-  GtkStyle *style;
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder padding;
   gboolean year_left;
 
   gtk_widget_get_allocation (widget, &allocation);
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+
+  gtk_style_context_get_padding (context, state, &padding);
 
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
     year_left = priv->year_before;
@@ -1287,43 +1295,43 @@ calendar_arrow_rectangle (GtkCalendar  *calendar,
     {
     case ARROW_MONTH_LEFT:
       if (year_left)
-        rect->x = (allocation.width - 2 * style->xthickness
+        rect->x = (allocation.width - padding.left - padding.right
                    - (3 + 2 * priv->arrow_width + priv->max_month_width));
       else
-       rect->x = 3;
+        rect->x = 3;
       break;
     case ARROW_MONTH_RIGHT:
       if (year_left)
-        rect->x = (allocation.width - 2 * style->xthickness
-                  - 3 - priv->arrow_width);
+        rect->x = (allocation.width - padding.left - padding.right
+                   - 3 - priv->arrow_width);
       else
-       rect->x = (priv->arrow_width + priv->max_month_width);
+        rect->x = (priv->arrow_width + priv->max_month_width);
       break;
     case ARROW_YEAR_LEFT:
       if (year_left)
-       rect->x = 3;
+        rect->x = 3;
       else
-        rect->x = (allocation.width - 2 * style->xthickness
+        rect->x = (allocation.width - padding.left - padding.right
                    - (3 + 2 * priv->arrow_width + priv->max_year_width));
       break;
     case ARROW_YEAR_RIGHT:
       if (year_left)
         rect->x = (priv->arrow_width + priv->max_year_width);
       else
-        rect->x = (allocation.width - 2 * style->xthickness
-                  - 3 - priv->arrow_width);
+        rect->x = (allocation.width - padding.left - padding.right
+                   - 3 - priv->arrow_width);
       break;
     }
 
-  rect->x += style->xthickness;
-  rect->y += style->ythickness;
+  rect->x += padding.left;
+  rect->y += padding.top;
 }
 
 static void
 calendar_day_rectangle (GtkCalendar  *calendar,
-                       gint          row,
-                       gint          col,
-                       GdkRectangle *rect)
+                        gint          row,
+                        gint          col,
+                        GdkRectangle *rect)
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
 
@@ -1338,7 +1346,7 @@ calendar_set_month_prev (GtkCalendar *calendar)
 {
   GtkCalendarPrivate *priv = calendar->priv;
   gint month_len;
-  
+
   if (priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
     return;
 
@@ -1353,13 +1361,13 @@ calendar_set_month_prev (GtkCalendar *calendar)
   month_len = month_length[leap (priv->year)][priv->month + 1];
 
   calendar_compute_days (calendar);
-  
+
   g_signal_emit (calendar,
-                gtk_calendar_signals[PREV_MONTH_SIGNAL],
-                0);
+                 gtk_calendar_signals[PREV_MONTH_SIGNAL],
+                 0);
   g_signal_emit (calendar,
-                gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
-                0);
+                 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+                 0);
 
   if (month_len < priv->selected_day)
     {
@@ -1369,7 +1377,7 @@ calendar_set_month_prev (GtkCalendar *calendar)
   else
     {
       if (priv->selected_day < 0)
-       priv->selected_day = priv->selected_day + 1 + month_length[leap (priv->year)][priv->month + 1];
+        priv->selected_day = priv->selected_day + 1 + month_length[leap (priv->year)][priv->month + 1];
       gtk_calendar_select_day (calendar, priv->selected_day);
     }
 
@@ -1408,8 +1416,8 @@ gtk_calendar_destroy (GtkWidget *widget)
 
 static void
 calendar_set_display_option (GtkCalendar              *calendar,
-                            GtkCalendarDisplayOptions flag,
-                            gboolean                  setting)
+                             GtkCalendarDisplayOptions flag,
+                             gboolean                  setting)
 {
   GtkCalendarPrivate *priv = calendar->priv;
   GtkCalendarDisplayOptions flags;
@@ -1423,62 +1431,62 @@ calendar_set_display_option (GtkCalendar              *calendar,
 
 static gboolean
 calendar_get_display_option (GtkCalendar              *calendar,
-                            GtkCalendarDisplayOptions flag)
+                             GtkCalendarDisplayOptions flag)
 {
   GtkCalendarPrivate *priv = calendar->priv;
 
   return (priv->display_flags & flag) != 0;
 }
 
-static void 
+static void
 gtk_calendar_set_property (GObject      *object,
-                          guint         prop_id,
-                          const GValue *value,
-                          GParamSpec   *pspec)
+                           guint         prop_id,
+                           const GValue *value,
+                           GParamSpec   *pspec)
 {
   GtkCalendar *calendar = GTK_CALENDAR (object);
   GtkCalendarPrivate *priv = calendar->priv;
 
-  switch (prop_id) 
+  switch (prop_id)
     {
     case PROP_YEAR:
       gtk_calendar_select_month (calendar,
-                                priv->month,
-                                g_value_get_int (value));
+                                 priv->month,
+                                 g_value_get_int (value));
       break;
     case PROP_MONTH:
       gtk_calendar_select_month (calendar,
-                                g_value_get_int (value),
-                                priv->year);
+                                 g_value_get_int (value),
+                                 priv->year);
       break;
     case PROP_DAY:
       gtk_calendar_select_day (calendar,
-                              g_value_get_int (value));
+                               g_value_get_int (value));
       break;
     case PROP_SHOW_HEADING:
       calendar_set_display_option (calendar,
-                                  GTK_CALENDAR_SHOW_HEADING,
-                                  g_value_get_boolean (value));
+                                   GTK_CALENDAR_SHOW_HEADING,
+                                   g_value_get_boolean (value));
       break;
     case PROP_SHOW_DAY_NAMES:
       calendar_set_display_option (calendar,
-                                  GTK_CALENDAR_SHOW_DAY_NAMES,
-                                  g_value_get_boolean (value));
+                                   GTK_CALENDAR_SHOW_DAY_NAMES,
+                                   g_value_get_boolean (value));
       break;
     case PROP_NO_MONTH_CHANGE:
       calendar_set_display_option (calendar,
-                                  GTK_CALENDAR_NO_MONTH_CHANGE,
-                                  g_value_get_boolean (value));
+                                   GTK_CALENDAR_NO_MONTH_CHANGE,
+                                   g_value_get_boolean (value));
       break;
     case PROP_SHOW_WEEK_NUMBERS:
       calendar_set_display_option (calendar,
-                                  GTK_CALENDAR_SHOW_WEEK_NUMBERS,
-                                  g_value_get_boolean (value));
+                                   GTK_CALENDAR_SHOW_WEEK_NUMBERS,
+                                   g_value_get_boolean (value));
       break;
     case PROP_SHOW_DETAILS:
       calendar_set_display_option (calendar,
-                                  GTK_CALENDAR_SHOW_DETAILS,
-                                  g_value_get_boolean (value));
+                                   GTK_CALENDAR_SHOW_DETAILS,
+                                   g_value_get_boolean (value));
       break;
     case PROP_DETAIL_WIDTH_CHARS:
       gtk_calendar_set_detail_width_chars (calendar,
@@ -1494,16 +1502,16 @@ gtk_calendar_set_property (GObject      *object,
     }
 }
 
-static void 
+static void
 gtk_calendar_get_property (GObject      *object,
-                          guint         prop_id,
-                          GValue       *value,
-                          GParamSpec   *pspec)
+                           guint         prop_id,
+                           GValue       *value,
+                           GParamSpec   *pspec)
 {
   GtkCalendar *calendar = GTK_CALENDAR (object);
   GtkCalendarPrivate *priv = calendar->priv;
 
-  switch (prop_id) 
+  switch (prop_id)
     {
     case PROP_YEAR:
       g_value_set_int (value, priv->year);
@@ -1516,23 +1524,23 @@ gtk_calendar_get_property (GObject      *object,
       break;
     case PROP_SHOW_HEADING:
       g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                              GTK_CALENDAR_SHOW_HEADING));
+                                                               GTK_CALENDAR_SHOW_HEADING));
       break;
     case PROP_SHOW_DAY_NAMES:
       g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                              GTK_CALENDAR_SHOW_DAY_NAMES));
+                                                               GTK_CALENDAR_SHOW_DAY_NAMES));
       break;
     case PROP_NO_MONTH_CHANGE:
       g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                              GTK_CALENDAR_NO_MONTH_CHANGE));
+                                                               GTK_CALENDAR_NO_MONTH_CHANGE));
       break;
     case PROP_SHOW_WEEK_NUMBERS:
       g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                              GTK_CALENDAR_SHOW_WEEK_NUMBERS));
+                                                               GTK_CALENDAR_SHOW_WEEK_NUMBERS));
       break;
     case PROP_SHOW_DETAILS:
       g_value_set_boolean (value, calendar_get_display_option (calendar,
-                                                              GTK_CALENDAR_SHOW_DETAILS));
+                                                               GTK_CALENDAR_SHOW_DETAILS));
       break;
     case PROP_DETAIL_WIDTH_CHARS:
       g_value_set_int (value, priv->detail_width_chars);
@@ -1573,29 +1581,26 @@ calendar_realize_arrows (GtkCalendar *calendar)
                                | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
       attributes_mask = GDK_WA_X | GDK_WA_Y;
       for (i = 0; i < 4; i++)
-       {
-         GdkRectangle rect;
-         calendar_arrow_rectangle (calendar, i, &rect);
-         
-         attributes.x = allocation.x + rect.x;
-         attributes.y = allocation.y + rect.y;
-         attributes.width = rect.width;
-         attributes.height = rect.height;
-         priv->arrow_win[i] = gdk_window_new (gtk_widget_get_window (widget),
-                                              &attributes, 
-                                              attributes_mask);
-         if (gtk_widget_is_sensitive (widget))
-           priv->arrow_state[i] = GTK_STATE_NORMAL;
-         else 
-           priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
-         gdk_window_show (priv->arrow_win[i]);
-         gdk_window_set_user_data (priv->arrow_win[i], widget);
-       }
+        {
+          GdkRectangle rect;
+          calendar_arrow_rectangle (calendar, i, &rect);
+
+          attributes.x = allocation.x + rect.x;
+          attributes.y = allocation.y + rect.y;
+          attributes.width = rect.width;
+          attributes.height = rect.height;
+          priv->arrow_win[i] = gdk_window_new (gtk_widget_get_window (widget),
+                                               &attributes,
+                                               attributes_mask);
+
+          gtk_widget_register_window (widget, priv->arrow_win[i]);
+        }
+      priv->arrow_prelight = 0x0;
     }
   else
     {
       for (i = 0; i < 4; i++)
-       priv->arrow_win[i] = NULL;
+        priv->arrow_win[i] = NULL;
     }
 }
 
@@ -1609,7 +1614,7 @@ calendar_unrealize_arrows (GtkCalendar *calendar)
     {
       if (priv->arrow_win[i])
         {
-          gdk_window_set_user_data (priv->arrow_win[i], NULL);
+          gtk_widget_unregister_window (GTK_WIDGET (calendar), priv->arrow_win[i]);
           gdk_window_destroy (priv->arrow_win[i]);
           priv->arrow_win[i] = NULL;
         }
@@ -1660,10 +1665,15 @@ gtk_calendar_realize (GtkWidget *widget)
   GdkWindowAttr attributes;
   gint attributes_mask;
   gint inner_border = calendar_get_inner_border (GTK_CALENDAR (widget));
-  GtkStyle *style;
+  GtkStyleContext *context;
   GtkAllocation allocation;
+  GtkStateFlags state = 0;
+  GtkBorder padding;
+
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+  gtk_style_context_get_padding (context, state, &padding);
 
-  style = gtk_widget_get_style (widget);
   gtk_widget_get_allocation (widget, &allocation);
 
   GTK_WIDGET_CLASS (gtk_calendar_parent_class)->realize (widget);
@@ -1671,16 +1681,17 @@ gtk_calendar_realize (GtkWidget *widget)
   attributes.wclass = GDK_INPUT_ONLY;
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
+                           | GDK_SCROLL_MASK
                            | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
                            | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
 
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
-    attributes.x = priv->week_width + style->ythickness + inner_border;
+    attributes.x = priv->week_width + padding.left + inner_border;
   else
-    attributes.x = style->ythickness + inner_border;
+    attributes.x = padding.left + inner_border;
 
-  attributes.y = priv->header_h + priv->day_name_h + style->ythickness + inner_border;
-  attributes.width = allocation.width - attributes.x - (style->xthickness + inner_border);
+  attributes.y = priv->header_h + priv->day_name_h + padding.top + inner_border;
+  attributes.width = allocation.width - attributes.x - (padding.right + inner_border);
 
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
     attributes.width -= priv->week_width;
@@ -1693,8 +1704,7 @@ gtk_calendar_realize (GtkWidget *widget)
 
   priv->main_win = gdk_window_new (gtk_widget_get_window (widget),
                                    &attributes, attributes_mask);
-  gdk_window_show (priv->main_win);
-  gdk_window_set_user_data (priv->main_win, widget);
+  gtk_widget_register_window (widget, priv->main_win);
 
   calendar_realize_arrows (GTK_CALENDAR (widget));
 }
@@ -1708,7 +1718,7 @@ gtk_calendar_unrealize (GtkWidget *widget)
 
   if (priv->main_win)
     {
-      gdk_window_set_user_data (priv->main_win, NULL);
+      gtk_widget_unregister_window (widget, priv->main_win);
       gdk_window_destroy (priv->main_win);
       priv->main_win = NULL;
     }
@@ -1716,6 +1726,56 @@ gtk_calendar_unrealize (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize (widget);
 }
 
+static void
+calendar_map_arrows (GtkCalendar *calendar)
+{
+  GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
+  gint i;
+
+  for (i = 0; i < 4; i++)
+    {
+      if (priv->arrow_win[i])
+        gdk_window_show (priv->arrow_win[i]);
+    }
+}
+
+static void
+calendar_unmap_arrows (GtkCalendar *calendar)
+{
+  GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
+  gint i;
+
+  for (i = 0; i < 4; i++)
+    {
+      if (priv->arrow_win[i])
+        gdk_window_hide (priv->arrow_win[i]);
+    }
+}
+
+static void
+gtk_calendar_map (GtkWidget *widget)
+{
+  GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
+
+  GTK_WIDGET_CLASS (gtk_calendar_parent_class)->map (widget);
+
+  gdk_window_show (priv->main_win);
+
+  calendar_map_arrows (GTK_CALENDAR (widget));
+}
+
+static void
+gtk_calendar_unmap (GtkWidget *widget)
+{
+  GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
+
+  calendar_unmap_arrows (GTK_CALENDAR (widget));
+
+  gdk_window_hide (priv->main_win);
+
+  GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unmap (widget);
+}
+
 static gchar*
 gtk_calendar_get_detail (GtkCalendar *calendar,
                          gint         row,
@@ -1793,12 +1853,14 @@ gtk_calendar_query_tooltip (GtkWidget  *widget,
  ****************************************/
 
 static void
-gtk_calendar_size_request (GtkWidget     *widget,
-                          GtkRequisition *requisition)
+gtk_calendar_size_request (GtkWidget      *widget,
+                           GtkRequisition *requisition)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
-  GtkStyle *style;
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder padding;
   PangoLayout *layout;
   PangoRectangle logical_rect;
 
@@ -1815,29 +1877,29 @@ gtk_calendar_size_request (GtkWidget      *widget,
   gint calendar_xsep = calendar_get_xsep (calendar);
 
   gtk_widget_style_get (GTK_WIDGET (widget),
-                       "focus-line-width", &focus_width,
-                       "focus-padding", &focus_padding,
-                       NULL);
+                        "focus-line-width", &focus_width,
+                        "focus-padding", &focus_padding,
+                        NULL);
 
   layout = gtk_widget_create_pango_layout (widget, NULL);
-  
+
   /*
-   * Calculate the requisition width for the widget.
+   * Calculate the requisition  width for the widget.
    */
-  
+
   /* Header width */
-  
+
   if (priv->display_flags & GTK_CALENDAR_SHOW_HEADING)
     {
       priv->max_month_width = 0;
       for (i = 0; i < 12; i++)
-       {
-         pango_layout_set_text (layout, default_monthname[i], -1);
-         pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-         priv->max_month_width = MAX (priv->max_month_width,
-                                              logical_rect.width + 8);
-         max_header_height = MAX (max_header_height, logical_rect.height); 
-       }
+        {
+          pango_layout_set_text (layout, default_monthname[i], -1);
+          pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+          priv->max_month_width = MAX (priv->max_month_width,
+                                               logical_rect.width + 8);
+          max_header_height = MAX (max_header_height, logical_rect.height);
+        }
 
       priv->max_year_width = 0;
       /* Translators:  This is a text measurement template.
@@ -1845,29 +1907,29 @@ gtk_calendar_size_request (GtkWidget      *widget,
        *
        * If you don't understand this, leave it as "2000"
        */
-      pango_layout_set_text (layout, C_("year measurement template", "2000"), -1);       
+      pango_layout_set_text (layout, C_("year measurement template", "2000"), -1);
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
       priv->max_year_width = MAX (priv->max_year_width,
-                                 logical_rect.width + 8);
-      max_header_height = MAX (max_header_height, logical_rect.height); 
-    } 
-  else 
+                                  logical_rect.width + 8);
+      max_header_height = MAX (max_header_height, logical_rect.height);
+    }
+  else
     {
       priv->max_month_width = 0;
       priv->max_year_width = 0;
     }
-  
+
   if (priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
-    header_width = (priv->max_month_width 
-                   + priv->max_year_width
-                   + 3 * 3);
+    header_width = (priv->max_month_width
+                    + priv->max_year_width
+                    + 3 * 3);
   else
-    header_width = (priv->max_month_width 
-                   + priv->max_year_width
-                   + 4 * priv->arrow_width + 3 * 3);
+    header_width = (priv->max_month_width
+                    + priv->max_year_width
+                    + 4 * priv->arrow_width + 3 * 3);
 
   /* Mainwindow labels width */
-  
+
   priv->max_day_char_width = 0;
   priv->max_day_char_ascent = 0;
   priv->max_day_char_descent = 0;
@@ -1877,44 +1939,44 @@ gtk_calendar_size_request (GtkWidget      *widget,
     {
       gchar buffer[32];
       g_snprintf (buffer, sizeof (buffer), C_("calendar:day:digits", "%d"), i * 11);
-      pango_layout_set_text (layout, buffer, -1);        
+      pango_layout_set_text (layout, buffer, -1);
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
       priv->min_day_width = MAX (priv->min_day_width,
-                                        logical_rect.width);
+                                         logical_rect.width);
 
       priv->max_day_char_ascent = MAX (priv->max_day_char_ascent,
-                                              PANGO_ASCENT (logical_rect));
-      priv->max_day_char_descent = MAX (priv->max_day_char_descent, 
-                                               PANGO_DESCENT (logical_rect));
+                                               PANGO_ASCENT (logical_rect));
+      priv->max_day_char_descent = MAX (priv->max_day_char_descent,
+                                                PANGO_DESCENT (logical_rect));
     }
-  
+
   priv->max_label_char_ascent = 0;
   priv->max_label_char_descent = 0;
   if (priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
     for (i = 0; i < 7; i++)
       {
-       pango_layout_set_text (layout, default_abbreviated_dayname[i], -1);
-       pango_layout_line_get_pixel_extents (pango_layout_get_lines_readonly (layout)->data, NULL, &logical_rect);
-
-       priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
-       priv->max_label_char_ascent = MAX (priv->max_label_char_ascent,
-                                                  PANGO_ASCENT (logical_rect));
-       priv->max_label_char_descent = MAX (priv->max_label_char_descent, 
-                                                   PANGO_DESCENT (logical_rect));
+        pango_layout_set_text (layout, default_abbreviated_dayname[i], -1);
+        pango_layout_line_get_pixel_extents (pango_layout_get_lines_readonly (layout)->data, NULL, &logical_rect);
+
+        priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
+        priv->max_label_char_ascent = MAX (priv->max_label_char_ascent,
+                                                   PANGO_ASCENT (logical_rect));
+        priv->max_label_char_descent = MAX (priv->max_label_char_descent,
+                                                    PANGO_DESCENT (logical_rect));
       }
-  
+
   priv->max_week_char_width = 0;
   if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
     for (i = 0; i < 9; i++)
       {
-       gchar buffer[32];
-       g_snprintf (buffer, sizeof (buffer), C_("calendar:week:digits", "%d"), i * 11);
-       pango_layout_set_text (layout, buffer, -1);       
-       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-       priv->max_week_char_width = MAX (priv->max_week_char_width,
-                                          logical_rect.width / 2);
+        gchar buffer[32];
+        g_snprintf (buffer, sizeof (buffer), C_("calendar:week:digits", "%d"), i * 11);
+        pango_layout_set_text (layout, buffer, -1);
+        pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+        priv->max_week_char_width = MAX (priv->max_week_char_width,
+                                           logical_rect.width / 2);
       }
-  
+
   /* Calculate detail extents. Do this as late as possible since
    * pango_layout_set_markup is called which alters font settings. */
   max_detail_height = 0;
@@ -1987,18 +2049,20 @@ gtk_calendar_size_request (GtkWidget      *widget,
   priv->max_day_char_width = priv->min_day_width / 2 + 1;
 
   main_width = (7 * (priv->min_day_width + (focus_padding + focus_width) * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
-               + (priv->max_week_char_width
-                  ? priv->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + calendar_xsep * 2
-                  : 0));
+                + (priv->max_week_char_width
+                   ? priv->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + calendar_xsep * 2
+                   : 0));
 
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+  gtk_style_context_get_padding (context, state, &padding);
 
-  requisition->width = MAX (header_width, main_width + inner_border * 2) + style->xthickness * 2;
+  requisition->width = MAX (header_width, main_width + inner_border * 2) + padding.left + padding.right;
 
   /*
    * Calculate the requisition height for the widget.
    */
-  
+
   if (priv->display_flags & GTK_CALENDAR_SHOW_HEADING)
     {
       priv->header_h = (max_header_height + calendar_ysep * 2);
@@ -2007,29 +2071,29 @@ gtk_calendar_size_request (GtkWidget      *widget,
     {
       priv->header_h = 0;
     }
-  
+
   if (priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
     {
       priv->day_name_h = (priv->max_label_char_ascent
-                                 + priv->max_label_char_descent
-                                 + 2 * (focus_padding + focus_width) + calendar_margin);
+                                  + priv->max_label_char_descent
+                                  + 2 * (focus_padding + focus_width) + calendar_margin);
       calendar_margin = calendar_ysep;
-    } 
+    }
   else
     {
       priv->day_name_h = 0;
     }
 
   priv->main_h = (CALENDAR_MARGIN + calendar_margin
-                         + 6 * (priv->max_day_char_ascent
-                                + priv->max_day_char_descent
+                          + 6 * (priv->max_day_char_ascent
+                                 + priv->max_day_char_descent
                                  + max_detail_height
-                                + 2 * (focus_padding + focus_width))
-                         + DAY_YSEP * 5);
+                                 + 2 * (focus_padding + focus_width))
+                          + DAY_YSEP * 5);
 
   height = priv->header_h + priv->day_name_h + priv->main_h;
 
-  requisition->height = height + (style->ythickness + inner_border) * 2;
+  requisition->height = height + padding.top + padding.bottom + (inner_border * 2);
 
   g_object_unref (layout);
 }
@@ -2059,59 +2123,65 @@ gtk_calendar_get_preferred_height (GtkWidget *widget,
 }
 
 static void
-gtk_calendar_size_allocate (GtkWidget    *widget,
-                           GtkAllocation *allocation)
+gtk_calendar_size_allocate (GtkWidget     *widget,
+                            GtkAllocation *allocation)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
-  GtkStyle *style;
-  gint xthickness, ythickness;
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder padding;
   guint i;
   gint inner_border = calendar_get_inner_border (calendar);
   gint calendar_xsep = calendar_get_xsep (calendar);
 
-  style = gtk_widget_get_style (widget);
-  xthickness = style->xthickness;
-  ythickness = style->xthickness;
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+  gtk_style_context_get_padding (context, state, &padding);
 
   gtk_widget_set_allocation (widget, allocation);
 
   if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
     {
       priv->day_width = (priv->min_day_width
-                        * ((allocation->width - (xthickness + inner_border) * 2
-                            - (CALENDAR_MARGIN * 2) -  (DAY_XSEP * 6) - calendar_xsep * 2))
-                        / (7 * priv->min_day_width + priv->max_week_char_width * 2));
-      priv->week_width = ((allocation->width - (xthickness + inner_border) * 2
-                          - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - calendar_xsep * 2 )
-                         - priv->day_width * 7 + CALENDAR_MARGIN + calendar_xsep);
-    } 
-  else 
+                         * ((allocation->width - (inner_border * 2) - padding.left - padding.right
+                             - (CALENDAR_MARGIN * 2) -  (DAY_XSEP * 6) - calendar_xsep * 2))
+                         / (7 * priv->min_day_width + priv->max_week_char_width * 2));
+      priv->week_width = ((allocation->width - (inner_border * 2) - padding.left - padding.right
+                           - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - calendar_xsep * 2 )
+                          - priv->day_width * 7 + CALENDAR_MARGIN + calendar_xsep);
+    }
+  else
     {
       priv->day_width = (allocation->width
-                        - (xthickness + inner_border) * 2
-                        - (CALENDAR_MARGIN * 2)
-                        - (DAY_XSEP * 6))/7;
+                         - (inner_border * 2)
+                         - padding.left - padding.right
+                         - (CALENDAR_MARGIN * 2)
+                         - (DAY_XSEP * 6))/7;
       priv->week_width = 0;
     }
-  
+
   if (gtk_widget_get_realized (widget))
     {
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
         gdk_window_move_resize (priv->main_win,
-                                priv->week_width + xthickness + inner_border,
-                                priv->header_h + priv->day_name_h
-                                 + (style->ythickness + inner_border),
+                                allocation->x
+                                 + priv->week_width + padding.left + inner_border,
+                                allocation->y
+                                 + priv->header_h + priv->day_name_h
+                                 + (padding.top + inner_border),
                                 allocation->width - priv->week_width
-                                 - (xthickness + inner_border) * 2,
+                                - (inner_border * 2) - padding.left - padding.right,
                                 priv->main_h);
       else
         gdk_window_move_resize (priv->main_win,
-                                xthickness + inner_border,
-                                priv->header_h + priv->day_name_h
-                                 + style->ythickness + inner_border,
+                                allocation->x
+                                 + padding.left + inner_border,
+                                allocation->y
+                                 + priv->header_h + priv->day_name_h
+                                 + padding.top + inner_border,
                                 allocation->width - priv->week_width
-                                 - (xthickness + inner_border) * 2,
+                                - (inner_border * 2) - padding.left - padding.right,
                                 priv->main_h);
 
       for (i = 0 ; i < 4 ; i++)
@@ -2141,7 +2211,9 @@ calendar_paint_header (GtkCalendar *calendar, cairo_t *cr)
   GtkWidget *widget = GTK_WIDGET (calendar);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   GtkAllocation allocation;
-  GtkStyle *style;
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder padding;
   char buffer[255];
   gint x, y;
   gint header_width;
@@ -2154,10 +2226,12 @@ calendar_paint_header (GtkCalendar *calendar, cairo_t *cr)
   struct tm *tm;
   gchar *str;
 
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+  gtk_style_context_get_padding (context, state, &padding);
 
   cairo_save (cr);
-  cairo_translate (cr, style->xthickness, style->ythickness);
+  cairo_translate (cr, padding.left, padding.top);
 
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
     year_left = priv->year_before;
@@ -2166,19 +2240,16 @@ calendar_paint_header (GtkCalendar *calendar, cairo_t *cr)
 
   gtk_widget_get_allocation (widget, &allocation);
 
-  header_width = allocation.width - 2 * style->xthickness;
+  header_width = allocation.width - padding.left - padding.right;
 
   max_month_width = priv->max_month_width;
   max_year_width = priv->max_year_width;
 
-  gdk_cairo_set_source_color (cr, HEADER_BG_COLOR (widget));
-  cairo_rectangle (cr, 0, 0, header_width, priv->header_h);
-  cairo_fill (cr);
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_HEADER);
 
-  gtk_paint_shadow (style, cr,
-                    GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-                    widget, "calendar",
-                    0, 0, header_width, priv->header_h);
+  gtk_render_background (context, cr, 0, 0, header_width, priv->header_h);
+  gtk_render_frame (context, cr, 0, 0, header_width, priv->header_h);
 
   tmp_time = 1;  /* Jan 1 1970, 00:00:01 UTC */
   tm = gmtime (&tmp_time);
@@ -2198,32 +2269,29 @@ calendar_paint_header (GtkCalendar *calendar, cairo_t *cr)
   str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
   layout = gtk_widget_create_pango_layout (widget, str);
   g_free (str);
-  
+
   pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-  
+
   /* Draw title */
   y = (priv->header_h - logical_rect.height) / 2;
-  
+
   /* Draw year and its arrows */
-  
+
   if (priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
     if (year_left)
       x = 3 + (max_year_width - logical_rect.width)/2;
     else
       x = header_width - (3 + max_year_width
-                         - (max_year_width - logical_rect.width)/2);
+                          - (max_year_width - logical_rect.width)/2);
   else
     if (year_left)
       x = 3 + priv->arrow_width + (max_year_width - logical_rect.width)/2;
     else
       x = header_width - (3 + priv->arrow_width + max_year_width
-                         - (max_year_width - logical_rect.width)/2);
-  
+                          - (max_year_width - logical_rect.width)/2);
+
+  gtk_render_layout (context, cr, x, y, layout);
 
-  gdk_cairo_set_source_color (cr, HEADER_FG_COLOR (GTK_WIDGET (calendar)));
-  cairo_move_to (cr, x, y);
-  pango_cairo_show_layout (cr, layout);
-  
   /* Draw month */
   g_snprintf (buffer, sizeof (buffer), "%s", default_monthname[priv->month]);
   pango_layout_set_text (layout, buffer, -1);
@@ -2232,21 +2300,20 @@ calendar_paint_header (GtkCalendar *calendar, cairo_t *cr)
   if (priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
     if (year_left)
       x = header_width - (3 + max_month_width
-                         - (max_month_width - logical_rect.width)/2);      
+                          - (max_month_width - logical_rect.width)/2);
     else
     x = 3 + (max_month_width - logical_rect.width) / 2;
   else
     if (year_left)
       x = header_width - (3 + priv->arrow_width + max_month_width
-                         - (max_month_width - logical_rect.width)/2);
+                          - (max_month_width - logical_rect.width)/2);
     else
     x = 3 + priv->arrow_width + (max_month_width - logical_rect.width)/2;
 
-  cairo_move_to (cr, x, y);
-  pango_cairo_show_layout (cr, layout);
-
+  gtk_render_layout (context, cr, x, y, layout);
   g_object_unref (layout);
 
+  gtk_style_context_restore (context);
   cairo_restore (cr);
 }
 
@@ -2256,7 +2323,9 @@ calendar_paint_day_names (GtkCalendar *calendar,
 {
   GtkWidget *widget = GTK_WIDGET (calendar);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
-  GtkStyle *style;
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder padding;
   GtkAllocation allocation;
   char buffer[255];
   int day,i;
@@ -2270,78 +2339,77 @@ calendar_paint_day_names (GtkCalendar *calendar,
   gint calendar_xsep = calendar_get_xsep (calendar);
   gint inner_border = calendar_get_inner_border (calendar);
 
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+  gtk_style_context_get_padding (context, state, &padding);
 
   cairo_save (cr);
 
   cairo_translate (cr,
-                   style->xthickness + inner_border,
-                   priv->header_h + style->ythickness + inner_border);
+                   padding.left + inner_border,
+                   priv->header_h + padding.top + inner_border);
 
   gtk_widget_style_get (GTK_WIDGET (widget),
-                       "focus-line-width", &focus_width,
-                       "focus-padding", &focus_padding,
-                       NULL);
+                        "focus-line-width", &focus_width,
+                        "focus-padding", &focus_padding,
+                        NULL);
 
   gtk_widget_get_allocation (widget, &allocation);
 
   day_width = priv->day_width;
-  cal_width = allocation.width - (style->xthickness + inner_border) * 2;
+  cal_width = allocation.width - (inner_border * 2) - padding.left - padding.right;
   day_wid_sep = day_width + DAY_XSEP;
-  
+
   /*
    * Draw rectangles as inverted background for the labels.
    */
 
-  gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
-  cairo_rectangle (cr,
-                   CALENDAR_MARGIN, CALENDAR_MARGIN,
-                   cal_width - CALENDAR_MARGIN * 2,
-                   priv->day_name_h - CALENDAR_MARGIN);
-  cairo_fill (cr);
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
+
+  gtk_render_background (context, cr,
+                         CALENDAR_MARGIN, CALENDAR_MARGIN,
+                         cal_width - CALENDAR_MARGIN * 2,
+                         priv->day_name_h - CALENDAR_MARGIN);
 
   if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
-    {
-      cairo_rectangle (cr,
-                      CALENDAR_MARGIN,
-                      priv->day_name_h - calendar_ysep,
-                      priv->week_width - calendar_ysep - CALENDAR_MARGIN,
-                      calendar_ysep);
-      cairo_fill (cr);
-    }
+    gtk_render_background (context, cr,
+                           CALENDAR_MARGIN,
+                           priv->day_name_h - calendar_ysep,
+                           priv->week_width - calendar_ysep - CALENDAR_MARGIN,
+                           calendar_ysep);
 
   /*
    * Write the labels
    */
-
   layout = gtk_widget_create_pango_layout (widget, NULL);
 
-  gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
   for (i = 0; i < 7; i++)
     {
       if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
-       day = 6 - i;
+        day = 6 - i;
       else
-       day = i;
+        day = i;
       day = (day + priv->week_start) % 7;
       g_snprintf (buffer, sizeof (buffer), "%s", default_abbreviated_dayname[day]);
 
       pango_layout_set_text (layout, buffer, -1);
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
 
-      cairo_move_to (cr, 
-                    (CALENDAR_MARGIN +
-                     + (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
-                        (priv->week_width + (priv->week_width ? calendar_xsep : 0))
-                        : 0)
-                     + day_wid_sep * i
-                     + (day_width - logical_rect.width)/2),
-                    CALENDAR_MARGIN + focus_width + focus_padding + logical_rect.y);
-      pango_cairo_show_layout (cr, layout);
+      gtk_render_layout (context, cr,
+                         (CALENDAR_MARGIN +
+                          + (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
+                             (priv->week_width + (priv->week_width ? calendar_xsep : 0))
+                             : 0)
+                          + day_wid_sep * i
+                          + (day_width - logical_rect.width)/2),
+                         CALENDAR_MARGIN + focus_width + focus_padding + logical_rect.y,
+                         layout);
     }
 
   g_object_unref (layout);
 
+  gtk_style_context_restore (context);
   cairo_restore (cr);
 }
 
@@ -2351,7 +2419,9 @@ calendar_paint_week_numbers (GtkCalendar *calendar,
 {
   GtkWidget *widget = GTK_WIDGET (calendar);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
-  GtkStyle *style;
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder padding;
   guint week = 0, year;
   gint row, x_loc, y_loc;
   gint day_height;
@@ -2364,59 +2434,56 @@ calendar_paint_week_numbers (GtkCalendar *calendar,
   gint inner_border = calendar_get_inner_border (calendar);
   gint x, y;
 
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+  gtk_style_context_get_padding (context, state, &padding);
 
   cairo_save (cr);
 
-  y = priv->header_h + priv->day_name_h + (style->ythickness + inner_border);
+  y = priv->header_h + priv->day_name_h + (padding.top + inner_border);
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
-    x = style->xthickness + inner_border;
+    x = padding.left + inner_border;
   else
-    x = gtk_widget_get_allocated_width (widget) - priv->week_width - (style->xthickness + inner_border);
+    x = gtk_widget_get_allocated_width (widget) - priv->week_width - (padding.right + inner_border);
 
   gtk_widget_style_get (GTK_WIDGET (widget),
-                       "focus-line-width", &focus_width,
-                       "focus-padding", &focus_padding,
-                       NULL);
+                        "focus-line-width", &focus_width,
+                        "focus-padding", &focus_padding,
+                        NULL);
 
-  /*
-   * Draw a rectangle as inverted background for the labels.
-   */
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
 
-  gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
   if (priv->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
-    cairo_rectangle (cr,
-                    x + CALENDAR_MARGIN,
-                    y,
-                    priv->week_width - CALENDAR_MARGIN,
-                    priv->main_h - CALENDAR_MARGIN);
+    gtk_render_background (context, cr,
+                           x + CALENDAR_MARGIN, y,
+                           priv->week_width - CALENDAR_MARGIN,
+                           priv->main_h - CALENDAR_MARGIN);
   else
-    cairo_rectangle (cr,
-                    x + CALENDAR_MARGIN,
-                    y + CALENDAR_MARGIN,
-                    priv->week_width - CALENDAR_MARGIN,
-                    priv->main_h - 2 * CALENDAR_MARGIN);
-  cairo_fill (cr);
+    gtk_render_background (context, cr,
+                           x + CALENDAR_MARGIN,
+                           y + CALENDAR_MARGIN,
+                           priv->week_width - CALENDAR_MARGIN,
+                           priv->main_h - 2 * CALENDAR_MARGIN);
 
   /*
    * Write the labels
    */
 
   layout = gtk_widget_create_pango_layout (widget, NULL);
-
-  gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
   day_height = calendar_row_height (calendar);
+
   for (row = 0; row < 6; row++)
     {
       gboolean result;
 
       year = priv->year;
       if (priv->day[row][6] < 15 && row > 3 && priv->month == 11)
-       year++;
+        year++;
 
       result = week_of_year (&week, &year,
-                            ((priv->day[row][6] < 15 && row > 3 ? 1 : 0)
-                             + priv->month) % 12 + 1, priv->day[row][6]);
+                             ((priv->day[row][6] < 15 && row > 3 ? 1 : 0)
+                              + priv->month) % 12 + 1, priv->day[row][6]);
       g_return_if_fail (result);
 
       /* Translators: this defines whether the week numbers should use
@@ -2436,46 +2503,46 @@ calendar_paint_week_numbers (GtkCalendar *calendar,
       y_loc = calendar_top_y_for_row (calendar, row) + (day_height - logical_rect.height) / 2;
 
       x_loc = x + (priv->week_width
-                  - logical_rect.width
-                  - calendar_xsep - focus_padding - focus_width);
+                   - logical_rect.width
+                   - calendar_xsep - focus_padding - focus_width);
 
-      cairo_move_to (cr, x_loc, y_loc);
-      pango_cairo_show_layout (cr, layout);
+      gtk_render_layout (context, cr, x_loc, y_loc, layout);
     }
-  
+
   g_object_unref (layout);
 
+  gtk_style_context_restore (context);
   cairo_restore (cr);
 }
 
 static void
 calendar_invalidate_day_num (GtkCalendar *calendar,
-                            gint         day)
+                             gint         day)
 {
   GtkCalendarPrivate *priv = calendar->priv;
   gint r, c, row, col;
-  
+
   row = -1;
   col = -1;
   for (r = 0; r < 6; r++)
     for (c = 0; c < 7; c++)
       if (priv->day_month[r][c] == MONTH_CURRENT &&
-         priv->day[r][c] == day)
-       {
-         row = r;
-         col = c;
-       }
-  
+          priv->day[r][c] == day)
+        {
+          row = r;
+          col = c;
+        }
+
   g_return_if_fail (row != -1);
   g_return_if_fail (col != -1);
-  
+
   calendar_invalidate_day (calendar, row, col);
 }
 
 static void
 calendar_invalidate_day (GtkCalendar *calendar,
-                        gint         row,
-                        gint         col)
+                         gint         row,
+                         gint         col)
 {
   GdkRectangle day_rect;
   GtkAllocation allocation;
@@ -2499,13 +2566,13 @@ is_color_attribute (PangoAttribute *attribute,
 static void
 calendar_paint_day (GtkCalendar *calendar,
                     cairo_t     *cr,
-                   gint         row,
-                   gint         col)
+                    gint         row,
+                    gint         col)
 {
   GtkWidget *widget = GTK_WIDGET (calendar);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
-  GtkStyle *style;
-  GdkColor *text_color;
+  GtkStyleContext *context;
+  GtkStateFlags state = 0;
   gchar *detail;
   gchar buffer[32];
   gint day;
@@ -2520,37 +2587,39 @@ calendar_paint_day (GtkCalendar *calendar,
   g_return_if_fail (row < 6);
   g_return_if_fail (col < 7);
 
-  style = gtk_widget_get_style (widget);
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
 
   day = priv->day[row][col];
   show_details = (priv->display_flags & GTK_CALENDAR_SHOW_DETAILS);
 
   calendar_day_rectangle (calendar, row, col, &day_rect);
-  
-  if (priv->day_month[row][col] == MONTH_PREV)
-    {
-      text_color = PREV_MONTH_COLOR (widget);
-    } 
-  else if (priv->day_month[row][col] == MONTH_NEXT)
-    {
-      text_color =  NEXT_MONTH_COLOR (widget);
-    } 
-  else 
+
+  gtk_style_context_save (context);
+
+  state &= ~(GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_SELECTED);
+
+  if (priv->day_month[row][col] == MONTH_PREV ||
+      priv->day_month[row][col] == MONTH_NEXT)
+    state |= GTK_STATE_FLAG_INCONSISTENT;
+  else
     {
+      if (priv->marked_date[day-1])
+        state |= GTK_STATE_FLAG_ACTIVE;
+
       if (priv->selected_day == day)
-       {
-         gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
-         gdk_cairo_rectangle (cr, &day_rect);
-         cairo_fill (cr);
-       }
-      if (priv->selected_day == day)
-       text_color = SELECTED_FG_COLOR (widget);
-      else if (priv->marked_date[day-1])
-       text_color = MARKED_COLOR (widget);
-      else
-       text_color = NORMAL_DAY_COLOR (widget);
+        {
+          state |= GTK_STATE_FLAG_SELECTED;
+
+          gtk_style_context_set_state (context, state);
+          gtk_render_background (context, cr,
+                                 day_rect.x, day_rect.y,
+                                 day_rect.width, day_rect.height);
+        }
     }
 
+  gtk_style_context_set_state (context, state);
+
   /* Translators: this defines whether the day numbers should use
    * localized digits or the ones used in English (0123...).
    *
@@ -2570,33 +2639,26 @@ calendar_paint_day (GtkCalendar *calendar,
   layout = gtk_widget_create_pango_layout (widget, buffer);
   pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
   pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-  
+
   x_loc = day_rect.x + (day_rect.width - logical_rect.width) / 2;
   y_loc = day_rect.y;
 
-  gdk_cairo_set_source_color (cr, text_color);
-  cairo_move_to (cr, x_loc, y_loc);
-  pango_cairo_show_layout (cr, layout);
+  gtk_render_layout (context, cr, x_loc, y_loc, layout);
 
   if (priv->day_month[row][col] == MONTH_CURRENT &&
      (priv->marked_date[day-1] || (detail && !show_details)))
-    {
-      cairo_move_to (cr, x_loc - 1, y_loc);
-      pango_cairo_show_layout (cr, layout);
-    }
+    gtk_render_layout (context, cr, x_loc - 1, y_loc, layout);
 
   y_loc += priv->max_day_char_descent;
 
   if (priv->detail_func && show_details)
     {
+      GdkRGBA color;
+
       cairo_save (cr);
 
-      if (priv->selected_day == day)
-        gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_ACTIVE]);
-      else if (priv->day_month[row][col] == MONTH_CURRENT)
-        gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_ACTIVE]);
-      else
-        gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_INSENSITIVE]);
+      gtk_style_context_get_color (context, state, &color);
+      gdk_cairo_set_source_rgba (cr, &color);
 
       cairo_set_line_width (cr, 1);
       cairo_move_to (cr, day_rect.x + 2, y_loc + 0.5);
@@ -2641,27 +2703,18 @@ calendar_paint_day (GtkCalendar *calendar,
       pango_cairo_show_layout (cr, layout);
     }
 
-  if (gtk_widget_has_focus (widget)
-      && priv->focus_row == row && priv->focus_col == col)
-    {
-      GtkStateType state;
-
-      if (priv->selected_day == day)
-       state = gtk_widget_has_focus (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
-      else
-       state = GTK_STATE_NORMAL;
-
-      gtk_paint_focus (style, cr,
-                      state, widget, "calendar-day",
-                      day_rect.x,     day_rect.y, 
-                      day_rect.width, day_rect.height);
-    }
+  if (gtk_widget_has_visible_focus (widget) &&
+      priv->focus_row == row && priv->focus_col == col)
+    gtk_render_focus (context, cr,
+                      day_rect.x, day_rect.y,
+                      day_rect.width, day_rect.height);
 
   if (overflow)
     priv->detail_overflow[row] |= (1 << col);
   else
     priv->detail_overflow[row] &= ~(1 << col);
 
+  gtk_style_context_restore (context);
   g_object_unref (layout);
   g_free (detail);
 }
@@ -2671,7 +2724,7 @@ calendar_paint_main (GtkCalendar *calendar,
                      cairo_t     *cr)
 {
   gint row, col;
-  
+
   cairo_save (cr);
 
   for (col = 0; col < 7; col++)
@@ -2683,7 +2736,7 @@ calendar_paint_main (GtkCalendar *calendar,
 
 static void
 calendar_invalidate_arrow (GtkCalendar *calendar,
-                          guint        arrow)
+                           guint        arrow)
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
 
@@ -2709,9 +2762,10 @@ calendar_paint_arrow (GtkCalendar *calendar,
 {
   GtkWidget *widget = GTK_WIDGET (calendar);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
-  GtkStyle *style;
-  gint state;
+  GtkStyleContext *context;
+  GtkStateFlags state;
   GdkRectangle rect;
+  gdouble angle;
 
   if (!priv->arrow_win[arrow])
     return;
@@ -2720,28 +2774,33 @@ calendar_paint_arrow (GtkCalendar *calendar,
 
   cairo_save (cr);
 
-  style = gtk_widget_get_style (widget);
-  state = priv->arrow_state[arrow];
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_widget_get_state_flags (widget);
+
+  if (priv->arrow_prelight & (1 << arrow))
+    state |= GTK_STATE_FLAG_PRELIGHT;
+  else
+    state &= ~(GTK_STATE_FLAG_PRELIGHT);
 
-  cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
-  gdk_cairo_set_source_color (cr, &style->bg[state]);
-  cairo_fill (cr);
+  gtk_style_context_save (context);
+  gtk_style_context_set_state (context, state);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
+
+  gtk_render_background (context, cr,
+                         rect.x, rect.y,
+                         rect.width, rect.height);
 
   if (arrow == ARROW_MONTH_LEFT || arrow == ARROW_YEAR_LEFT)
-    gtk_paint_arrow (style, cr, state,
-                     GTK_SHADOW_OUT, widget, "calendar",
-                     GTK_ARROW_LEFT, TRUE,
-                     rect.x + (rect.width - 8) / 2,
-                     rect.y + (rect.height - 8) / 2,
-                     8, 8);
+    angle = 3 * (G_PI / 2);
   else
-    gtk_paint_arrow (style, cr, state,
-                     GTK_SHADOW_OUT, widget, "calendar",
-                     GTK_ARROW_RIGHT, TRUE,
-                     rect.x + (rect.width - 8) / 2,
-                     rect.y + (rect.height - 8) / 2,
-                     8, 8);
+    angle = G_PI / 2;
+
+  gtk_render_arrow (context, cr, angle,
+                    rect.x + (rect.width - 8) / 2,
+                    rect.y + (rect.height - 8) / 2,
+                    8);
 
+  gtk_style_context_restore (context);
   cairo_restore (cr);
 }
 
@@ -2755,18 +2814,21 @@ gtk_calendar_draw (GtkWidget *widget,
 
   if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
     {
-      gdk_cairo_set_source_color (cr, BACKGROUND_COLOR (widget));
-      cairo_rectangle (cr,
-                       0, 0,
-                       gtk_widget_get_allocated_width (widget),
-                       gtk_widget_get_allocated_height (widget));
-      cairo_fill (cr);
-      gtk_paint_shadow (gtk_widget_get_style (widget), cr,
-                        gtk_widget_get_state (widget), GTK_SHADOW_IN,
-                        widget, "calendar",
-                        0, 0,
+      GtkStyleContext *context;
+
+      context = gtk_widget_get_style_context (widget);
+
+      gtk_style_context_save (context);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
+
+      gtk_render_background (context, cr, 0, 0,
+                             gtk_widget_get_allocated_width (widget),
+                             gtk_widget_get_allocated_height (widget));
+      gtk_render_frame (context, cr, 0, 0,
                         gtk_widget_get_allocated_width (widget),
                         gtk_widget_get_allocated_height (widget));
+
+      gtk_style_context_restore (context);
     }
 
   calendar_paint_main (calendar, cr);
@@ -2794,7 +2856,7 @@ gtk_calendar_draw (GtkWidget *widget,
 
 static void
 calendar_arrow_action (GtkCalendar *calendar,
-                      guint        arrow)
+                       guint        arrow)
 {
   switch (arrow)
     {
@@ -2821,27 +2883,27 @@ calendar_timer (gpointer data)
   GtkCalendar *calendar = data;
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   gboolean retval = FALSE;
-  
+
   if (priv->timer)
     {
       calendar_arrow_action (calendar, priv->click_child);
 
       if (priv->need_timer)
-       {
+        {
           GtkSettings *settings;
           guint        timeout;
 
           settings = gtk_widget_get_settings (GTK_WIDGET (calendar));
           g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
 
-         priv->need_timer = FALSE;
-         priv->timer = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
-                                           timeout * SCROLL_DELAY_FACTOR,
-                                           (GSourceFunc) calendar_timer,
-                                           (gpointer) calendar, NULL);
-       }
-      else 
-       retval = TRUE;
+          priv->need_timer = FALSE;
+          priv->timer = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
+                                            timeout * SCROLL_DELAY_FACTOR,
+                                            (GSourceFunc) calendar_timer,
+                                            (gpointer) calendar, NULL);
+        }
+      else
+        retval = TRUE;
     }
 
   return retval;
@@ -2849,12 +2911,12 @@ calendar_timer (gpointer data)
 
 static void
 calendar_start_spinning (GtkCalendar *calendar,
-                        gint         click_child)
+                         gint         click_child)
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
 
   priv->click_child = click_child;
-  
+
   if (!priv->timer)
     {
       GtkSettings *settings;
@@ -2865,9 +2927,9 @@ calendar_start_spinning (GtkCalendar *calendar,
 
       priv->need_timer = TRUE;
       priv->timer = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
-                                       timeout,
-                                       (GSourceFunc) calendar_timer,
-                                       (gpointer) calendar, NULL);
+                                        timeout,
+                                        (GSourceFunc) calendar_timer,
+                                        (gpointer) calendar, NULL);
     }
 }
 
@@ -2924,7 +2986,7 @@ calendar_main_button_press (GtkCalendar    *calendar,
       if (!gtk_widget_has_focus (widget))
         gtk_widget_grab_focus (widget);
 
-      if (event->button == 1)
+      if (event->button == GDK_BUTTON_PRIMARY)
         {
           priv->in_drag = 1;
           priv->drag_start_x = x;
@@ -2960,51 +3022,47 @@ gtk_calendar_button_press (GtkWidget      *widget,
   for (arrow = ARROW_YEAR_LEFT; arrow <= ARROW_MONTH_RIGHT; arrow++)
     {
       if (event->window == priv->arrow_win[arrow])
-       {
+        {
 
-         /* only call the action on single click, not double */
-         if (event->type == GDK_BUTTON_PRESS)
-           {
-             if (event->button == 1)
-               calendar_start_spinning (calendar, arrow);
+          /* only call the action on single click, not double */
+          if (event->type == GDK_BUTTON_PRESS)
+            {
+              if (event->button == GDK_BUTTON_PRIMARY)
+                calendar_start_spinning (calendar, arrow);
 
-             calendar_arrow_action (calendar, arrow);
-           }
+              calendar_arrow_action (calendar, arrow);
+            }
 
-         return TRUE;
-       }
+          return TRUE;
+        }
     }
 
   return FALSE;
 }
 
 static gboolean
-gtk_calendar_button_release (GtkWidget   *widget,
-                            GdkEventButton *event)
+gtk_calendar_button_release (GtkWidget    *widget,
+                             GdkEventButton *event)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
 
-  if (event->button == 1)
+  if (event->button == GDK_BUTTON_PRIMARY)
     {
       calendar_stop_spinning (calendar);
 
       if (priv->in_drag)
-       priv->in_drag = 0;
+        priv->in_drag = 0;
     }
 
   return TRUE;
 }
 
 static gboolean
-gtk_calendar_motion_notify (GtkWidget     *widget,
-                           GdkEventMotion *event)
+gtk_calendar_motion_notify (GtkWidget      *widget,
+                            GdkEventMotion *event)
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
-  gint event_x, event_y;
-
-  event_x = (gint) (event->x);
-  event_y = (gint) (event->y);
 
   if (priv->in_drag)
     {
@@ -3028,89 +3086,89 @@ gtk_calendar_motion_notify (GtkWidget      *widget,
 }
 
 static gboolean
-gtk_calendar_enter_notify (GtkWidget       *widget,
-                          GdkEventCrossing *event)
+gtk_calendar_enter_notify (GtkWidget        *widget,
+                           GdkEventCrossing *event)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
-  
+
   if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
     {
-      priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_PRELIGHT;
+      priv->arrow_prelight |= (1 << ARROW_MONTH_LEFT);
       calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
     }
-  
+
   if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
     {
-      priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_PRELIGHT;
+      priv->arrow_prelight |= (1 << ARROW_MONTH_RIGHT);
       calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
     }
-  
+
   if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
     {
-      priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_PRELIGHT;
+      priv->arrow_prelight |= (1 << ARROW_YEAR_LEFT);
       calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
     }
-  
+
   if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
     {
-      priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_PRELIGHT;
+      priv->arrow_prelight |= (1 << ARROW_YEAR_RIGHT);
       calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
     }
-  
+
   return TRUE;
 }
 
 static gboolean
 gtk_calendar_leave_notify (GtkWidget        *widget,
-                          GdkEventCrossing *event)
+                           GdkEventCrossing *event)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
 
   if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
     {
-      priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_NORMAL;
+      priv->arrow_prelight &= ~(1 << ARROW_MONTH_LEFT);
       calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
     }
-  
+
   if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
     {
-      priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_NORMAL;
+      priv->arrow_prelight &= ~(1 << ARROW_MONTH_RIGHT);
       calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
     }
-  
+
   if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
     {
-      priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_NORMAL;
+      priv->arrow_prelight &= ~(1 << ARROW_YEAR_LEFT);
       calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
     }
-  
+
   if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
     {
-      priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_NORMAL;
+      priv->arrow_prelight &= ~(1 << ARROW_YEAR_RIGHT);
       calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
     }
-  
+
   return TRUE;
 }
 
 static gboolean
 gtk_calendar_scroll (GtkWidget      *widget,
-                    GdkEventScroll *event)
+                     GdkEventScroll *event)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
 
-  if (event->direction == GDK_SCROLL_UP) 
+  if (event->direction == GDK_SCROLL_UP)
     {
       if (!gtk_widget_has_focus (widget))
-       gtk_widget_grab_focus (widget);
+        gtk_widget_grab_focus (widget);
       calendar_set_month_prev (calendar);
     }
-  else if (event->direction == GDK_SCROLL_DOWN) 
+  else if (event->direction == GDK_SCROLL_DOWN)
     {
       if (!gtk_widget_has_focus (widget))
-       gtk_widget_grab_focus (widget);
+        gtk_widget_grab_focus (widget);
       calendar_set_month_next (calendar);
     }
   else
@@ -3124,38 +3182,38 @@ gtk_calendar_scroll (GtkWidget      *widget,
  *             Key handling              *
  ****************************************/
 
-static void 
-move_focus (GtkCalendar *calendar, 
-           gint         direction)
+static void
+move_focus (GtkCalendar *calendar,
+            gint         direction)
 {
   GtkCalendarPrivate *priv = calendar->priv;
   GtkTextDirection text_dir = gtk_widget_get_direction (GTK_WIDGET (calendar));
+
   if ((text_dir == GTK_TEXT_DIR_LTR && direction == -1) ||
-      (text_dir == GTK_TEXT_DIR_RTL && direction == 1)) 
+      (text_dir == GTK_TEXT_DIR_RTL && direction == 1))
     {
       if (priv->focus_col > 0)
-         priv->focus_col--;
+          priv->focus_col--;
       else if (priv->focus_row > 0)
-       {
-         priv->focus_col = 6;
-         priv->focus_row--;
-       }
+        {
+          priv->focus_col = 6;
+          priv->focus_row--;
+        }
 
       if (priv->focus_col < 0)
         priv->focus_col = 6;
       if (priv->focus_row < 0)
         priv->focus_row = 5;
     }
-  else 
+  else
     {
       if (priv->focus_col < 6)
-       priv->focus_col++;
+        priv->focus_col++;
       else if (priv->focus_row < 5)
-       {
-         priv->focus_col = 0;
-         priv->focus_row++;
-       }
+        {
+          priv->focus_col = 0;
+          priv->focus_row++;
+        }
 
       if (priv->focus_col < 0)
         priv->focus_col = 0;
@@ -3166,7 +3224,7 @@ move_focus (GtkCalendar *calendar,
 
 static gboolean
 gtk_calendar_key_press (GtkWidget   *widget,
-                       GdkEventKey *event)
+                        GdkEventKey *event)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = calendar->priv;
@@ -3186,81 +3244,81 @@ gtk_calendar_key_press (GtkWidget   *widget,
     case GDK_KEY_Left:
       return_val = TRUE;
       if (event->state & GDK_CONTROL_MASK)
-       calendar_set_month_prev (calendar);
+        calendar_set_month_prev (calendar);
       else
-       {
-         move_focus (calendar, -1);
-         calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
-         calendar_invalidate_day (calendar, priv->focus_row,
-                                  priv->focus_col);
-       }
+        {
+          move_focus (calendar, -1);
+          calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+          calendar_invalidate_day (calendar, priv->focus_row,
+                                   priv->focus_col);
+        }
       break;
     case GDK_KEY_KP_Right:
     case GDK_KEY_Right:
       return_val = TRUE;
       if (event->state & GDK_CONTROL_MASK)
-       calendar_set_month_next (calendar);
+        calendar_set_month_next (calendar);
       else
-       {
-         move_focus (calendar, 1);
-         calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
-         calendar_invalidate_day (calendar, priv->focus_row,
-                                  priv->focus_col);
-       }
+        {
+          move_focus (calendar, 1);
+          calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+          calendar_invalidate_day (calendar, priv->focus_row,
+                                   priv->focus_col);
+        }
       break;
     case GDK_KEY_KP_Up:
     case GDK_KEY_Up:
       return_val = TRUE;
       if (event->state & GDK_CONTROL_MASK)
-       calendar_set_year_prev (calendar);
+        calendar_set_year_prev (calendar);
       else
-       {
-         if (priv->focus_row > 0)
-           priv->focus_row--;
+        {
+          if (priv->focus_row > 0)
+            priv->focus_row--;
           if (priv->focus_row < 0)
             priv->focus_row = 5;
           if (priv->focus_col < 0)
             priv->focus_col = 6;
-         calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
-         calendar_invalidate_day (calendar, priv->focus_row,
-                                  priv->focus_col);
-       }
+          calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+          calendar_invalidate_day (calendar, priv->focus_row,
+                                   priv->focus_col);
+        }
       break;
     case GDK_KEY_KP_Down:
     case GDK_KEY_Down:
       return_val = TRUE;
       if (event->state & GDK_CONTROL_MASK)
-       calendar_set_year_next (calendar);
+        calendar_set_year_next (calendar);
       else
-       {
-         if (priv->focus_row < 5)
-           priv->focus_row++;
+        {
+          if (priv->focus_row < 5)
+            priv->focus_row++;
           if (priv->focus_col < 0)
             priv->focus_col = 0;
-         calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
-         calendar_invalidate_day (calendar, priv->focus_row,
-                                  priv->focus_col);
-       }
+          calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+          calendar_invalidate_day (calendar, priv->focus_row,
+                                   priv->focus_col);
+        }
       break;
     case GDK_KEY_KP_Space:
     case GDK_KEY_space:
       row = priv->focus_row;
       col = priv->focus_col;
-      
+
       if (row > -1 && col > -1)
-       {
-         return_val = TRUE;
+        {
+          return_val = TRUE;
 
           day = priv->day[row][col];
-         if (priv->day_month[row][col] == MONTH_PREV)
-           calendar_set_month_prev (calendar);
-         else if (priv->day_month[row][col] == MONTH_NEXT)
-           calendar_set_month_next (calendar);
-
-         calendar_select_and_focus_day (calendar, day);
-       }
-    }  
-  
+          if (priv->day_month[row][col] == MONTH_PREV)
+            calendar_set_month_prev (calendar);
+          else if (priv->day_month[row][col] == MONTH_NEXT)
+            calendar_set_month_next (calendar);
+
+          calendar_select_and_focus_day (calendar, day);
+        }
+    }
+
   return return_val;
 }
 
@@ -3270,29 +3328,22 @@ gtk_calendar_key_press (GtkWidget   *widget,
  ****************************************/
 
 static void
-gtk_calendar_state_changed (GtkWidget     *widget,
-                           GtkStateType    previous_state)
+gtk_calendar_state_flags_changed (GtkWidget     *widget,
+                                  GtkStateFlags  previous_state)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
-  int i;
 
   if (!gtk_widget_is_sensitive (widget))
     {
       priv->in_drag = 0;
       calendar_stop_spinning (calendar);
     }
-
-  for (i = 0; i < 4; i++)
-    if (gtk_widget_is_sensitive (widget))
-      priv->arrow_state[i] = GTK_STATE_NORMAL;
-    else
-      priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
 }
 
 static void
 gtk_calendar_grab_notify (GtkWidget *widget,
-                         gboolean   was_grabbed)
+                          gboolean   was_grabbed)
 {
   if (!was_grabbed)
     calendar_stop_spinning (GTK_CALENDAR (widget));
@@ -3300,7 +3351,7 @@ gtk_calendar_grab_notify (GtkWidget *widget,
 
 static gboolean
 gtk_calendar_focus_out (GtkWidget     *widget,
-                       GdkEventFocus *event)
+                        GdkEventFocus *event)
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
   GtkCalendar *calendar = GTK_CALENDAR (widget);
@@ -3320,10 +3371,10 @@ gtk_calendar_focus_out (GtkWidget     *widget,
 
 static void
 gtk_calendar_drag_data_get (GtkWidget        *widget,
-                           GdkDragContext   *context,
-                           GtkSelectionData *selection_data,
-                           guint             info,
-                           guint             time)
+                            GdkDragContext   *context,
+                            GtkSelectionData *selection_data,
+                            guint             info,
+                            guint             time)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = calendar->priv;
@@ -3334,7 +3385,7 @@ gtk_calendar_drag_data_get (GtkWidget        *widget,
   date = g_date_new_dmy (priv->selected_day, priv->month + 1, priv->year);
   len = g_date_strftime (str, 127, "%x", date);
   gtk_selection_data_set_text (selection_data, str, len);
-  
+
   g_free (date);
 }
 
@@ -3360,22 +3411,22 @@ get_status_pending (GdkDragContext *context)
 
 static void
 gtk_calendar_drag_leave (GtkWidget      *widget,
-                        GdkDragContext *context,
-                        guint           time)
+                         GdkDragContext *context,
+                         guint           time)
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
 
   priv->drag_highlight = 0;
   gtk_drag_unhighlight (widget);
-  
+
 }
 
 static gboolean
 gtk_calendar_drag_motion (GtkWidget      *widget,
-                         GdkDragContext *context,
-                         gint            x,
-                         gint            y,
-                         guint           time)
+                          GdkDragContext *context,
+                          gint            x,
+                          gint            y,
+                          guint           time)
 {
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
   GdkAtom target;
@@ -3394,25 +3445,25 @@ gtk_calendar_drag_motion (GtkWidget      *widget,
       set_status_pending (context, gdk_drag_context_get_suggested_action (context));
       gtk_drag_get_data (widget, context, target, time);
     }
-  
+
   return TRUE;
 }
 
 static gboolean
 gtk_calendar_drag_drop (GtkWidget      *widget,
-                       GdkDragContext *context,
-                       gint            x,
-                       gint            y,
-                       guint           time)
+                        GdkDragContext *context,
+                        gint            x,
+                        gint            y,
+                        guint           time)
 {
   GdkAtom target;
 
-  target = gtk_drag_dest_find_target (widget, context, NULL);  
+  target = gtk_drag_dest_find_target (widget, context, NULL);
   if (target != GDK_NONE)
     {
-      gtk_drag_get_data (widget, context, 
-                        target, 
-                        time);
+      gtk_drag_get_data (widget, context,
+                         target,
+                         time);
       return TRUE;
     }
 
@@ -3421,12 +3472,12 @@ gtk_calendar_drag_drop (GtkWidget      *widget,
 
 static void
 gtk_calendar_drag_data_received (GtkWidget        *widget,
-                                GdkDragContext   *context,
-                                gint              x,
-                                gint              y,
-                                GtkSelectionData *selection_data,
-                                guint             info,
-                                guint             time)
+                                 GdkDragContext   *context,
+                                 gint              x,
+                                 gint              y,
+                                 GtkSelectionData *selection_data,
+                                 guint             info,
+                                 guint             time)
 {
   GtkCalendar *calendar = GTK_CALENDAR (widget);
   GtkCalendarPrivate *priv = calendar->priv;
@@ -3437,10 +3488,10 @@ gtk_calendar_drag_data_received (GtkWidget        *widget,
 
   suggested_action = get_status_pending (context);
 
-  if (suggested_action) 
+  if (suggested_action)
     {
       set_status_pending (context, 0);
-     
+
       /* We are getting this data due to a request in drag_motion,
        * rather than due to a request in drag_drop, so we are just
        * supposed to call drag_status, not actually paste in the
@@ -3448,17 +3499,17 @@ gtk_calendar_drag_data_received (GtkWidget        *widget,
        */
       str = (gchar*) gtk_selection_data_get_text (selection_data);
 
-      if (str) 
-       {
-         date = g_date_new ();
-         g_date_set_parse (date, str);
-         if (!g_date_valid (date)) 
-             suggested_action = 0;
-         g_date_free (date);
-         g_free (str);
-       }
+      if (str)
+        {
+          date = g_date_new ();
+          g_date_set_parse (date, str);
+          if (!g_date_valid (date))
+              suggested_action = 0;
+          g_date_free (date);
+          g_free (str);
+        }
       else
-       suggested_action = 0;
+        suggested_action = 0;
 
       gdk_drag_status (context, suggested_action, time);
 
@@ -3467,16 +3518,16 @@ gtk_calendar_drag_data_received (GtkWidget        *widget,
 
   date = g_date_new ();
   str = (gchar*) gtk_selection_data_get_text (selection_data);
-  if (str) 
+  if (str)
     {
       g_date_set_parse (date, str);
       g_free (str);
     }
-  
-  if (!g_date_valid (date)) 
+
+  if (!g_date_valid (date))
     {
       g_warning ("Received invalid date data\n");
-      g_date_free (date);      
+      g_date_free (date);
       gtk_drag_finish (context, FALSE, FALSE, time);
       return;
     }
@@ -3484,17 +3535,17 @@ gtk_calendar_drag_data_received (GtkWidget        *widget,
   day = g_date_get_day (date);
   month = g_date_get_month (date);
   year = g_date_get_year (date);
-  g_date_free (date);  
+  g_date_free (date);
 
   gtk_drag_finish (context, TRUE, FALSE, time);
 
-  
+
   g_object_freeze_notify (G_OBJECT (calendar));
   if (!(priv->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
       && (priv->display_flags & GTK_CALENDAR_SHOW_HEADING))
     gtk_calendar_select_month (calendar, month - 1, year);
   gtk_calendar_select_day (calendar, day);
-  g_object_thaw_notify (G_OBJECT (calendar));  
+  g_object_thaw_notify (G_OBJECT (calendar));
 }
 
 \f
@@ -3504,9 +3555,9 @@ gtk_calendar_drag_data_received (GtkWidget        *widget,
 
 /**
  * gtk_calendar_new:
- * 
- * Creates a new calendar, with the current date being selected. 
- * 
+ *
+ * Creates a new calendar, with the current date being selected.
+ *
  * Return value: a newly #GtkCalendar widget
  **/
 GtkWidget*
@@ -3518,14 +3569,14 @@ gtk_calendar_new (void)
 /**
  * gtk_calendar_get_display_options:
  * @calendar: a #GtkCalendar
- * 
- * Returns the current display options of @calendar. 
- * 
+ *
+ * Returns the current display options of @calendar.
+ *
  * Return value: the display options.
  *
  * Since: 2.4
  **/
-GtkCalendarDisplayOptions 
+GtkCalendarDisplayOptions
 gtk_calendar_get_display_options (GtkCalendar         *calendar)
 {
   g_return_val_if_fail (GTK_IS_CALENDAR (calendar), 0);
@@ -3537,66 +3588,69 @@ gtk_calendar_get_display_options (GtkCalendar         *calendar)
  * gtk_calendar_set_display_options:
  * @calendar: a #GtkCalendar
  * @flags: the display options to set
- * 
- * Sets display options (whether to display the heading and the month  
+ *
+ * Sets display options (whether to display the heading and the month
  * headings).
  *
  * Since: 2.4
  **/
 void
-gtk_calendar_set_display_options (GtkCalendar         *calendar,
-                                 GtkCalendarDisplayOptions flags)
+gtk_calendar_set_display_options (GtkCalendar          *calendar,
+                                  GtkCalendarDisplayOptions flags)
 {
   GtkWidget *widget = GTK_WIDGET (calendar);
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   gint resize = 0;
   GtkCalendarDisplayOptions old_flags;
-  
+
   g_return_if_fail (GTK_IS_CALENDAR (calendar));
-  
+
   old_flags = priv->display_flags;
-  
+
   if (gtk_widget_get_realized (widget))
     {
       if ((flags ^ priv->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
-       {
-         resize ++;
-         if (! (flags & GTK_CALENDAR_NO_MONTH_CHANGE)
+        {
+          resize ++;
+          if (! (flags & GTK_CALENDAR_NO_MONTH_CHANGE)
               && (priv->display_flags & GTK_CALENDAR_SHOW_HEADING))
-           {
-             priv->display_flags &= ~GTK_CALENDAR_NO_MONTH_CHANGE;
-             calendar_realize_arrows (calendar);
-           }
-         else
-           {
-             calendar_unrealize_arrows (calendar);
-           }
-       }
-      
+            {
+              priv->display_flags &= ~GTK_CALENDAR_NO_MONTH_CHANGE;
+              calendar_realize_arrows (calendar);
+              if (gtk_widget_get_mapped (widget))
+                calendar_map_arrows (calendar);
+            }
+          else
+            {
+              calendar_unrealize_arrows (calendar);
+            }
+        }
+
       if ((flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_HEADING)
-       {
-         resize++;
-         
-         if (flags & GTK_CALENDAR_SHOW_HEADING)
+        {
+          resize++;
+
+          if (flags & GTK_CALENDAR_SHOW_HEADING)
+            {
+              priv->display_flags |= GTK_CALENDAR_SHOW_HEADING;
+              calendar_realize_arrows (calendar);
+              if (gtk_widget_get_mapped (widget))
+                calendar_map_arrows (calendar);
+            }
+          else
             {
-             priv->display_flags |= GTK_CALENDAR_SHOW_HEADING;
-             calendar_realize_arrows (calendar);
+              calendar_unrealize_arrows (calendar);
             }
-         else
-           {
-             calendar_unrealize_arrows (calendar);
-           }
-       }
-      
-      
+        }
+
       if ((flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
-       {
-         resize++;
-         
-         if (flags & GTK_CALENDAR_SHOW_DAY_NAMES)
-           priv->display_flags |= GTK_CALENDAR_SHOW_DAY_NAMES;
-       }
-      
+        {
+          resize++;
+
+          if (flags & GTK_CALENDAR_SHOW_DAY_NAMES)
+            priv->display_flags |= GTK_CALENDAR_SHOW_DAY_NAMES;
+        }
+
       if ((flags ^ priv->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
         {
           resize++;
@@ -3610,7 +3664,7 @@ gtk_calendar_set_display_options (GtkCalendar            *calendar,
 
       priv->display_flags = flags;
       if (resize)
-       gtk_widget_queue_resize (GTK_WIDGET (calendar));
+        gtk_widget_queue_resize (GTK_WIDGET (calendar));
     }
   else
     priv->display_flags = flags;
@@ -3637,8 +3691,8 @@ gtk_calendar_set_display_options (GtkCalendar            *calendar,
  **/
 void
 gtk_calendar_select_month (GtkCalendar *calendar,
-                          guint        month,
-                          guint        year)
+                           guint        month,
+                           guint        year)
 {
   GtkCalendarPrivate *priv;
 
@@ -3659,21 +3713,21 @@ gtk_calendar_select_month (GtkCalendar *calendar,
   g_object_thaw_notify (G_OBJECT (calendar));
 
   g_signal_emit (calendar,
-                gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
-                0);
+                 gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+                 0);
 }
 
 /**
  * gtk_calendar_select_day:
  * @calendar: a #GtkCalendar.
- * @day: the day number between 1 and 31, or 0 to unselect 
+ * @day: the day number between 1 and 31, or 0 to unselect
  *   the currently selected day.
- * 
+ *
  * Selects a day from the current month.
  **/
 void
 gtk_calendar_select_day (GtkCalendar *calendar,
-                        guint        day)
+                         guint        day)
 {
   GtkCalendarPrivate *priv;
 
@@ -3686,33 +3740,33 @@ gtk_calendar_select_day (GtkCalendar *calendar,
   if (priv->selected_day > 0)
     {
       gint selected_day;
-      
+
       selected_day = priv->selected_day;
       priv->selected_day = 0;
       if (gtk_widget_is_drawable (GTK_WIDGET (calendar)))
-       calendar_invalidate_day_num (calendar, selected_day);
+        calendar_invalidate_day_num (calendar, selected_day);
     }
-  
+
   priv->selected_day = day;
-  
+
   /* Select the new day */
   if (day != 0)
     {
       if (gtk_widget_is_drawable (GTK_WIDGET (calendar)))
-       calendar_invalidate_day_num (calendar, day);
+        calendar_invalidate_day_num (calendar, day);
     }
-  
+
   g_object_notify (G_OBJECT (calendar), "day");
 
   g_signal_emit (calendar,
-                gtk_calendar_signals[DAY_SELECTED_SIGNAL],
-                0);
+                 gtk_calendar_signals[DAY_SELECTED_SIGNAL],
+                 0);
 }
 
 /**
  * gtk_calendar_clear_marks:
  * @calendar: a #GtkCalendar
- * 
+ *
  * Remove all visual markers.
  **/
 void
@@ -3743,7 +3797,7 @@ gtk_calendar_clear_marks (GtkCalendar *calendar)
  */
 void
 gtk_calendar_mark_day (GtkCalendar *calendar,
-                      guint        day)
+                       guint        day)
 {
   GtkCalendarPrivate *priv;
 
@@ -3795,7 +3849,7 @@ gtk_calendar_get_day_is_marked (GtkCalendar *calendar,
  */
 void
 gtk_calendar_unmark_day (GtkCalendar *calendar,
-                        guint        day)
+                         guint        day)
 {
   GtkCalendarPrivate *priv;
 
@@ -3814,17 +3868,20 @@ gtk_calendar_unmark_day (GtkCalendar *calendar,
 /**
  * gtk_calendar_get_date:
  * @calendar: a #GtkCalendar
- * @year: (allow-none): location to store the year number, or %NULL
- * @month: (allow-none): location to store the month number (between 0 and 11), or %NULL
- * @day: (allow-none): location to store the day number (between 1 and 31), or %NULL
- * 
+ * @year: (out) (allow-none): location to store the year as a decimal
+ *     number (e.g. 2011), or %NULL
+ * @month: (out) (allow-none): location to store the month number
+ *     (between 0 and 11), or %NULL
+ * @day: (out) (allow-none): location to store the day number (between
+ *     1 and 31), or %NULL
+ *
  * Obtains the selected date from a #GtkCalendar.
- **/
+ */
 void
 gtk_calendar_get_date (GtkCalendar *calendar,
-                      guint       *year,
-                      guint       *month,
-                      guint       *day)
+                       guint       *year,
+                       guint       *month,
+                       guint       *day)
 {
   GtkCalendarPrivate *priv;