[mutter] theme: Port from GtkStateType to GtkStateFlags



commit d95da2dfbe493e0718644e53789f0f110cc48ed5
Author: Florian MÃllner <fmuellner gnome org>
Date:   Wed May 18 23:32:44 2011 +0200

    theme: Port from GtkStateType to GtkStateFlags
    
    We now use GtkStyleContext exclusively, so it's a bit weird to store
    widget state as GtkStateType and translate it always to GtkStateFlags.
    Just use GtkStateFlags instead of GtkStateType.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=650586

 src/ui/theme-parser.c  |    6 +-
 src/ui/theme-private.h |   14 +++---
 src/ui/theme.c         |  103 +++++++++++++----------------------------------
 3 files changed, 39 insertions(+), 84 deletions(-)
---
diff --git a/src/ui/theme-parser.c b/src/ui/theme-parser.c
index 8b1c83b..36056ac 100644
--- a/src/ui/theme-parser.c
+++ b/src/ui/theme-parser.c
@@ -2320,7 +2320,7 @@ parse_draw_op_element (GMarkupParseContext  *context,
       const char *height;
       const char *filled;
       gboolean filled_val;
-      GtkStateType state_val;
+      GtkStateFlags state_val;
       GtkShadowType shadow_val;
       GtkArrowType arrow_val;
       
@@ -2410,7 +2410,7 @@ parse_draw_op_element (GMarkupParseContext  *context,
       const char *y;
       const char *width;
       const char *height;
-      GtkStateType state_val;
+      GtkStateFlags state_val;
       GtkShadowType shadow_val;
       
       if (!locate_attributes (context, element_name, attribute_names, attribute_values,
@@ -2478,7 +2478,7 @@ parse_draw_op_element (GMarkupParseContext  *context,
       const char *x;
       const char *y1;
       const char *y2;
-      GtkStateType state_val;
+      GtkStateFlags state_val;
       
       if (!locate_attributes (context, element_name, attribute_names, attribute_values,
                               error,
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index b2e7bb4..015a889 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -308,7 +308,7 @@ struct _MetaColorSpec
     } basic;
     struct {
       MetaGtkColorComponent component;
-      GtkStateType state;
+      GtkStateFlags state;
     } gtk;
     struct {
       MetaColorSpec *foreground;
@@ -553,7 +553,7 @@ struct _MetaDrawOp
     } image;
     
     struct {
-      GtkStateType state;
+      GtkStateFlags state;
       GtkShadowType shadow;
       GtkArrowType arrow;
       gboolean filled;
@@ -565,7 +565,7 @@ struct _MetaDrawOp
     } gtk_arrow;
 
     struct {
-      GtkStateType state;
+      GtkStateFlags state;
       GtkShadowType shadow;
       MetaDrawSpec *x;
       MetaDrawSpec *y;
@@ -574,7 +574,7 @@ struct _MetaDrawOp
     } gtk_box;
 
     struct {
-      GtkStateType state;
+      GtkStateFlags state;
       MetaDrawSpec *x;
       MetaDrawSpec *y1;
       MetaDrawSpec *y2;  
@@ -958,7 +958,7 @@ MetaColorSpec* meta_color_spec_new             (MetaColorSpecType  type);
 MetaColorSpec* meta_color_spec_new_from_string (const char        *str,
                                                 GError           **err);
 MetaColorSpec* meta_color_spec_new_gtk         (MetaGtkColorComponent component,
-                                                GtkStateType          state);
+                                                GtkStateFlags         state);
 void           meta_color_spec_free            (MetaColorSpec     *spec);
 void           meta_color_spec_render          (MetaColorSpec     *spec,
                                                 GtkStyleContext   *style_gtk,
@@ -1208,8 +1208,8 @@ const char*           meta_frame_focus_to_string       (MetaFrameFocus         f
 MetaFrameType         meta_frame_type_from_string      (const char            *str);
 MetaGradientType      meta_gradient_type_from_string   (const char            *str);
 const char*           meta_gradient_type_to_string     (MetaGradientType       type);
-GtkStateType          meta_gtk_state_from_string       (const char            *str);
-const char*           meta_gtk_state_to_string         (GtkStateType           state);
+GtkStateFlags         meta_gtk_state_from_string       (const char            *str);
+const char*           meta_gtk_state_to_string         (GtkStateFlags          state);
 GtkShadowType         meta_gtk_shadow_from_string      (const char            *str);
 const char*           meta_gtk_shadow_to_string        (GtkShadowType          shadow);
 GtkArrowType          meta_gtk_arrow_from_string       (const char            *str);
diff --git a/src/ui/theme.c b/src/ui/theme.c
index e9f6883..1088998 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -1185,7 +1185,7 @@ meta_color_spec_new_from_string (const char *str,
       const char *bracket;
       const char *end_bracket;
       char *tmp;
-      GtkStateType state;
+      GtkStateFlags state;
       MetaGtkColorComponent component;
       
       bracket = str;
@@ -1400,7 +1400,7 @@ meta_color_spec_new_from_string (const char *str,
  */
 MetaColorSpec*
 meta_color_spec_new_gtk (MetaGtkColorComponent component,
-                         GtkStateType          state)
+                         GtkStateFlags         state)
 {
   MetaColorSpec *spec;
 
@@ -1436,42 +1436,23 @@ meta_gtk_style_get_dark_color (GtkStyleContext *style,
 static void
 meta_set_color_from_style (GdkRGBA               *color,
                            GtkStyleContext       *context,
-                           GtkStateType           state,
+                           GtkStateFlags          state,
                            MetaGtkColorComponent  component)
 {
   GdkRGBA other;
-  GtkStateFlags flags;
-
-  switch (state)
-    {
-    case GTK_STATE_ACTIVE:
-      flags = GTK_STATE_FLAG_ACTIVE;
-      break;
-    case GTK_STATE_PRELIGHT:
-      flags = GTK_STATE_FLAG_PRELIGHT;
-      break;
-    case GTK_STATE_SELECTED:
-      flags = GTK_STATE_FLAG_SELECTED;
-      break;
-    case GTK_STATE_INSENSITIVE:
-      flags = GTK_STATE_FLAG_INSENSITIVE;
-      break;
-    default:
-      flags = 0;
-    }
 
   switch (component)
     {
     case META_GTK_COLOR_BG:
     case META_GTK_COLOR_BASE:
-      gtk_style_context_get_background_color (context, flags, color);
+      gtk_style_context_get_background_color (context, state, color);
       break;
     case META_GTK_COLOR_FG:
     case META_GTK_COLOR_TEXT:
-      gtk_style_context_get_color (context, flags, color);
+      gtk_style_context_get_color (context, state, color);
       break;
     case META_GTK_COLOR_TEXT_AA:
-      gtk_style_context_get_color (context, flags, color);
+      gtk_style_context_get_color (context, state, color);
       meta_set_color_from_style (&other, context, state, META_GTK_COLOR_BASE);
 
       color->red = (color->red + other.red) / 2;
@@ -1479,18 +1460,18 @@ meta_set_color_from_style (GdkRGBA               *color,
       color->blue = (color->blue + other.blue) / 2;
       break;
     case META_GTK_COLOR_MID:
-      meta_gtk_style_get_light_color (context, flags, color);
-      meta_gtk_style_get_dark_color (context, flags, &other);
+      meta_gtk_style_get_light_color (context, state, color);
+      meta_gtk_style_get_dark_color (context, state, &other);
 
       color->red = (color->red + other.red) / 2;
       color->green = (color->green + other.green) / 2;
       color->blue = (color->blue + other.blue) / 2;
       break;
     case META_GTK_COLOR_LIGHT:
-      meta_gtk_style_get_light_color (context, flags, color);
+      meta_gtk_style_get_light_color (context, state, color);
       break;
     case META_GTK_COLOR_DARK:
-      meta_gtk_style_get_dark_color (context, flags, color);
+      meta_gtk_style_get_dark_color (context, state, color);
       break;
     case META_GTK_COLOR_LAST:
       g_assert_not_reached ();
@@ -3526,29 +3507,6 @@ fill_env (MetaPositionExprEnv *env,
   env->theme = meta_current_theme;
 }
 
-static GtkStateFlags
-state_flags_from_gtk_state (GtkStateType state)
-{
-  switch (state)
-    {
-    case GTK_STATE_NORMAL:
-      return 0;
-    case GTK_STATE_PRELIGHT:
-      return GTK_STATE_FLAG_PRELIGHT;
-    case GTK_STATE_ACTIVE:
-      return GTK_STATE_FLAG_ACTIVE;
-    case GTK_STATE_SELECTED:
-      return GTK_STATE_FLAG_SELECTED;
-    case GTK_STATE_INSENSITIVE:
-      return GTK_STATE_FLAG_INSENSITIVE;
-    case GTK_STATE_INCONSISTENT:
-      return GTK_STATE_FLAG_INCONSISTENT;
-    case GTK_STATE_FOCUSED:
-      return GTK_STATE_FLAG_FOCUSED;
-    }
-  return 0;
-}
-
 
 /* This code was originally rendering anti-aliased using X primitives, and
  * now has been switched to draw anti-aliased using cairo. In general, the
@@ -3852,8 +3810,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp    *op,
             return;
           }
 
-        gtk_style_context_set_state (style_gtk,
-                                     state_flags_from_gtk_state (op->data.gtk_arrow.state));
+        gtk_style_context_set_state (style_gtk, op->data.gtk_arrow.state);
         gtk_render_arrow (style_gtk, cr, angle, rx, ry, size);
       }
       break;
@@ -3867,8 +3824,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp    *op,
         rwidth = parse_size_unchecked (op->data.gtk_box.width, env);
         rheight = parse_size_unchecked (op->data.gtk_box.height, env);
 
-        gtk_style_context_set_state (style_gtk,
-                                     state_flags_from_gtk_state (op->data.gtk_box.state));
+        gtk_style_context_set_state (style_gtk, op->data.gtk_box.state);
         gtk_render_background (style_gtk, cr, rx, ry, rwidth, rheight);
         gtk_render_frame (style_gtk, cr, rx, ry, rwidth, rheight);
       }
@@ -3882,8 +3838,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp    *op,
         ry1 = parse_y_position_unchecked (op->data.gtk_vline.y1, env);
         ry2 = parse_y_position_unchecked (op->data.gtk_vline.y2, env);
         
-        gtk_style_context_set_state (style_gtk,
-                                     state_flags_from_gtk_state (op->data.gtk_vline.state));
+        gtk_style_context_set_state (style_gtk, op->data.gtk_vline.state);
         gtk_render_line (style_gtk, cr, rx, ry1, rx, ry2);
       }
       break;
@@ -6369,45 +6324,45 @@ meta_gradient_type_to_string (MetaGradientType type)
   return "<unknown>";
 }
 
-GtkStateType
+GtkStateFlags
 meta_gtk_state_from_string (const char *str)
 {
   if (g_ascii_strcasecmp ("normal", str) == 0)
-    return GTK_STATE_NORMAL;
+    return GTK_STATE_FLAG_NORMAL;
   else if (g_ascii_strcasecmp ("prelight", str) == 0)
-    return GTK_STATE_PRELIGHT;
+    return GTK_STATE_FLAG_PRELIGHT;
   else if (g_ascii_strcasecmp ("active", str) == 0)
-    return GTK_STATE_ACTIVE;
+    return GTK_STATE_FLAG_ACTIVE;
   else if (g_ascii_strcasecmp ("selected", str) == 0)
-    return GTK_STATE_SELECTED;
+    return GTK_STATE_FLAG_SELECTED;
   else if (g_ascii_strcasecmp ("insensitive", str) == 0)
-    return GTK_STATE_INSENSITIVE;
+    return GTK_STATE_FLAG_INSENSITIVE;
   else if (g_ascii_strcasecmp ("inconsistent", str) == 0)
-    return GTK_STATE_INCONSISTENT;
+    return GTK_STATE_FLAG_INCONSISTENT;
   else if (g_ascii_strcasecmp ("focused", str) == 0)
-    return GTK_STATE_FOCUSED;
+    return GTK_STATE_FLAG_FOCUSED;
   else
     return -1; /* hack */
 }
 
 const char*
-meta_gtk_state_to_string (GtkStateType state)
+meta_gtk_state_to_string (GtkStateFlags state)
 {
   switch (state)
     {
-    case GTK_STATE_NORMAL:
+    case GTK_STATE_FLAG_NORMAL:
       return "NORMAL";
-    case GTK_STATE_PRELIGHT:
+    case GTK_STATE_FLAG_PRELIGHT:
       return "PRELIGHT";
-    case GTK_STATE_ACTIVE:
+    case GTK_STATE_FLAG_ACTIVE:
       return "ACTIVE";
-    case GTK_STATE_SELECTED:
+    case GTK_STATE_FLAG_SELECTED:
       return "SELECTED";
-    case GTK_STATE_INSENSITIVE:
+    case GTK_STATE_FLAG_INSENSITIVE:
       return "INSENSITIVE";
-    case GTK_STATE_INCONSISTENT:
+    case GTK_STATE_FLAG_INCONSISTENT:
       return "INCONSISTENT";
-    case GTK_STATE_FOCUSED:
+    case GTK_STATE_FLAG_FOCUSED:
       return "FOCUSED";
     }
 



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