[metacity] libmetacity: remove hack from meta_gtk_state_from_string



commit d206e28d90a1208f5c97281a01ed4ffae5e9af92
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Jan 27 23:26:09 2016 +0200

    libmetacity: remove hack from meta_gtk_state_from_string

 libmetacity/meta-color-spec.c |   37 ++++++++++++++++++++++++-------------
 libmetacity/meta-color-spec.h |    3 ++-
 src/ui/theme-parser.c         |    9 +++------
 3 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/libmetacity/meta-color-spec.c b/libmetacity/meta-color-spec.c
index 5561f71..e8add5a 100644
--- a/libmetacity/meta-color-spec.c
+++ b/libmetacity/meta-color-spec.c
@@ -339,8 +339,7 @@ meta_color_spec_new_from_string (const gchar  *str,
         }
 
       tmp = g_strndup (bracket + 1, end_bracket - bracket - 1);
-      state = meta_gtk_state_from_string (tmp);
-      if (((int) state) == -1)
+      if (!meta_gtk_state_from_string (tmp, &state))
         {
           g_set_error (error, META_THEME_ERROR, META_THEME_ERROR_FAILED,
                        _("Did not understand state '%s' in color specification"),
@@ -609,25 +608,37 @@ meta_color_spec_render (MetaColorSpec   *spec,
     }
 }
 
-GtkStateFlags
-meta_gtk_state_from_string (const gchar *str)
+/**
+ * meta_gtk_state_from_string:
+ * @str: state string
+ * @state: (out): location to store #GtkStateFlags
+ *
+ * Convert string to #GtkStateFlags
+ *
+ * Returns: %TRUE if state string was valid, %FALSE otherwise
+ */
+gboolean
+meta_gtk_state_from_string (const gchar   *str,
+                            GtkStateFlags *state)
 {
   if (g_ascii_strcasecmp ("normal", str) == 0)
-    return GTK_STATE_FLAG_NORMAL;
+    *state = GTK_STATE_FLAG_NORMAL;
   else if (g_ascii_strcasecmp ("prelight", str) == 0)
-    return GTK_STATE_FLAG_PRELIGHT;
+    *state = GTK_STATE_FLAG_PRELIGHT;
   else if (g_ascii_strcasecmp ("active", str) == 0)
-    return GTK_STATE_FLAG_ACTIVE;
+    *state = GTK_STATE_FLAG_ACTIVE;
   else if (g_ascii_strcasecmp ("selected", str) == 0)
-    return GTK_STATE_FLAG_SELECTED;
+    *state = GTK_STATE_FLAG_SELECTED;
   else if (g_ascii_strcasecmp ("insensitive", str) == 0)
-    return GTK_STATE_FLAG_INSENSITIVE;
+    *state = GTK_STATE_FLAG_INSENSITIVE;
   else if (g_ascii_strcasecmp ("inconsistent", str) == 0)
-    return GTK_STATE_FLAG_INCONSISTENT;
+    *state = GTK_STATE_FLAG_INCONSISTENT;
   else if (g_ascii_strcasecmp ("focused", str) == 0)
-    return GTK_STATE_FLAG_FOCUSED;
+    *state = GTK_STATE_FLAG_FOCUSED;
   else if (g_ascii_strcasecmp ("backdrop", str) == 0)
-    return GTK_STATE_FLAG_BACKDROP;
+    *state = GTK_STATE_FLAG_BACKDROP;
   else
-    return -1;
+    return FALSE;
+
+  return TRUE;
 }
diff --git a/libmetacity/meta-color-spec.h b/libmetacity/meta-color-spec.h
index fb4d2e5..f58a1be 100644
--- a/libmetacity/meta-color-spec.h
+++ b/libmetacity/meta-color-spec.h
@@ -41,7 +41,8 @@ void           meta_color_spec_render          (MetaColorSpec          *spec,
                                                 GtkStyleContext        *context,
                                                 GdkRGBA                *color);
 
-GtkStateFlags  meta_gtk_state_from_string      (const gchar            *str);
+gboolean       meta_gtk_state_from_string      (const gchar            *str,
+                                                GtkStateFlags          *state);
 
 G_END_DECLS
 
diff --git a/src/ui/theme-parser.c b/src/ui/theme-parser.c
index 8a47181..ac29178 100644
--- a/src/ui/theme-parser.c
+++ b/src/ui/theme-parser.c
@@ -2296,8 +2296,7 @@ parse_draw_op_element (GMarkupParseContext  *context,
       if (filled && !parse_boolean (filled, &filled_val, context, error))
         return;
 
-      state_val = meta_gtk_state_from_string (state);
-      if (((int) state_val) == -1)
+      if (!meta_gtk_state_from_string (state, &state_val))
         {
           set_error (error, context, G_MARKUP_ERROR,
                      G_MARKUP_ERROR_PARSE,
@@ -2366,8 +2365,7 @@ parse_draw_op_element (GMarkupParseContext  *context,
                               NULL))
         return;
 
-      state_val = meta_gtk_state_from_string (state);
-      if (((int) state_val) == -1)
+      if (!meta_gtk_state_from_string (state, &state_val))
         {
           set_error (error, context, G_MARKUP_ERROR,
                      G_MARKUP_ERROR_PARSE,
@@ -2418,8 +2416,7 @@ parse_draw_op_element (GMarkupParseContext  *context,
                               NULL))
         return;
 
-      state_val = meta_gtk_state_from_string (state);
-      if (((int) state_val) == -1)
+      if (!meta_gtk_state_from_string (state, &state_val))
         {
           set_error (error, context, G_MARKUP_ERROR,
                      G_MARKUP_ERROR_PARSE,


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