[gtk+/wip/unfocused-fixes: 7/13] calendar: Use the widget state flags as a base for drawing arrows



commit bd84d520d6a44e8c59f2651ce56f73e85b00d52b
Author: Rui Matos <tiagomatos gmail com>
Date:   Thu Dec 15 01:44:46 2011 +0000

    calendar: Use the widget state flags as a base for drawing arrows
    
    This allows drawing calendar arrows in all possible states the main widget may
    be in.
    
    The arrow_state array is converted into a bit field since it only really needs
    to store boolean information about prelight for each arrow.

 gtk/gtkcalendar.c |   36 ++++++++++++++++--------------------
 1 files changed, 16 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 345d7ed..9914809 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -271,7 +271,7 @@ struct _GtkCalendarPrivate
   guint day_name_h;
   guint main_h;
 
-  guint arrow_state[4];
+  guint arrow_prelight : 4;
   guint arrow_width;
   guint max_month_width;
   guint max_year_width;
@@ -1594,11 +1594,9 @@ calendar_realize_arrows (GtkCalendar *calendar)
                                                &attributes,
                                                attributes_mask);
 
-          if (!gtk_widget_is_sensitive (widget))
-            priv->arrow_state[i] = GTK_STATE_FLAG_INSENSITIVE;
-
           gdk_window_set_user_data (priv->arrow_win[i], widget);
         }
+      priv->arrow_prelight = 0x0;
     }
   else
     {
@@ -2777,7 +2775,12 @@ calendar_paint_arrow (GtkCalendar *calendar,
   cairo_save (cr);
 
   context = gtk_widget_get_style_context (widget);
-  state = priv->arrow_state[arrow];
+  state = gtk_widget_get_state_flags (widget);
+
+  if (priv->arrow_prelight & (1 << arrow))
+    state |= GTK_STATE_FLAG_PRELIGHT;
+  else
+    state &= ~(GTK_STATE_FLAG_PRELIGHT);
 
   gtk_style_context_save (context);
   gtk_style_context_set_state (context, state);
@@ -3091,25 +3094,25 @@ gtk_calendar_enter_notify (GtkWidget        *widget,
 
   if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
     {
-      priv->arrow_state[ARROW_MONTH_LEFT] |= GTK_STATE_FLAG_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_FLAG_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_FLAG_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_FLAG_PRELIGHT;
+      priv->arrow_prelight |= (1 << ARROW_YEAR_RIGHT);
       calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
     }
 
@@ -3125,25 +3128,25 @@ gtk_calendar_leave_notify (GtkWidget        *widget,
 
   if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
     {
-      priv->arrow_state[ARROW_MONTH_LEFT] &= ~(GTK_STATE_FLAG_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_FLAG_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_FLAG_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_FLAG_PRELIGHT);
+      priv->arrow_prelight &= ~(1 << ARROW_YEAR_RIGHT);
       calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
     }
 
@@ -3330,19 +3333,12 @@ gtk_calendar_state_flags_changed (GtkWidget     *widget,
 {
   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_FLAG_INSENSITIVE);
-    else
-      priv->arrow_state[i] |= GTK_STATE_FLAG_INSENSITIVE;
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]