[gtk+] win32: Add gtk_win32_theme_parse()



commit d584e22e021b15446e60ef451160211ae3347bb7
Author: Benjamin Otte <otte gnome org>
Date:   Sun Feb 14 01:11:57 2016 +0100

    win32: Add gtk_win32_theme_parse()
    
    So all places can use this function instead of parsing things themselves.

 gtk/gtkcssimagewin32.c     |   13 +++----------
 gtk/gtkcsswin32sizevalue.c |   19 ++++++-------------
 gtk/gtkwin32theme.c        |   21 ++++++++++++++++++++-
 gtk/gtkwin32themeprivate.h |    2 +-
 4 files changed, 30 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkcssimagewin32.c b/gtk/gtkcssimagewin32.c
index 342178e..2ec110e 100644
--- a/gtk/gtkcssimagewin32.c
+++ b/gtk/gtkcssimagewin32.c
@@ -70,7 +70,6 @@ gtk_css_image_win32_parse (GtkCssImage  *image,
                            GtkCssParser *parser)
 {
   GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
-  char *class;
 
   if (!_gtk_css_parser_try (parser, "-gtk-win32-theme-part", TRUE))
     {
@@ -85,15 +84,9 @@ gtk_css_image_win32_parse (GtkCssImage  *image,
       return FALSE;
     }
   
-  class = _gtk_css_parser_try_name (parser, TRUE);
-  if (class == NULL)
-    {
-      _gtk_css_parser_error (parser,
-                             "Expected name as first argument to  '-gtk-win32-theme-part'");
-      return FALSE;
-    }
-  wimage->theme = gtk_win32_theme_lookup (class);
-  g_free (class);
+  wimage->theme = gtk_win32_theme_parse (parser);
+  if (wimage->theme == NULL)
+    return FALSE;
 
   if (! _gtk_css_parser_try (parser, ",", TRUE))
     {
diff --git a/gtk/gtkcsswin32sizevalue.c b/gtk/gtkcsswin32sizevalue.c
index c2b8b08..9856a20 100644
--- a/gtk/gtkcsswin32sizevalue.c
+++ b/gtk/gtkcsswin32sizevalue.c
@@ -148,7 +148,6 @@ gtk_css_win32_size_value_parse (GtkCssParser           *parser,
                                 GtkCssNumberParseFlags  flags)
 {
   GtkWin32Theme *theme;
-  char *theme_class;
   GtkCssValue *result;
   int id;
 
@@ -158,37 +157,31 @@ gtk_css_win32_size_value_parse (GtkCssParser           *parser,
       return NULL;
     }
 
-  theme_class = _gtk_css_parser_try_name (parser, TRUE);
-  if (theme_class == NULL)
-    {
-      _gtk_css_parser_error (parser, "Expected name as first argument to  '-gtk-win32-size'");
-      return NULL;
-    }
+  theme = gtk_win32_theme_parse (parser);
+  if (theme == NULL)
+    return NULL;
 
   if (! _gtk_css_parser_try (parser, ",", TRUE))
     {
-      g_free (theme_class);
+      gtk_win32_theme_unref (theme);
       _gtk_css_parser_error (parser, "Expected ','");
       return NULL;
     }
 
   if (!_gtk_css_parser_try_int (parser, &id))
     {
-      g_free (theme_class);
+      gtk_win32_theme_unref (theme);
       _gtk_css_parser_error (parser, "Expected an integer ID");
       return 0;
     }
 
   if (!_gtk_css_parser_try (parser, ")", TRUE))
     {
-      g_free (theme_class);
+      gtk_win32_theme_unref (theme);
       _gtk_css_parser_error (parser, "Expected ')'");
       return NULL;
     }
 
-  theme = gtk_win32_theme_lookup (theme_class);
-  g_free (theme_class);
-
   result = gtk_css_win32_size_value_new (1.0, theme, id);
   gtk_win32_theme_unref (theme);
 
diff --git a/gtk/gtkwin32theme.c b/gtk/gtkwin32theme.c
index c55a66a..4f9452d 100644
--- a/gtk/gtkwin32theme.c
+++ b/gtk/gtkwin32theme.c
@@ -247,7 +247,7 @@ gtk_win32_theme_get_htheme (GtkWin32Theme *theme)
 
 #endif /* G_OS_WIN32 */
 
-GtkWin32Theme *
+static GtkWin32Theme *
 gtk_win32_theme_lookup (const char *classname)
 {
   GtkWin32Theme *theme;
@@ -269,6 +269,25 @@ gtk_win32_theme_lookup (const char *classname)
   return theme;
 }
 
+GtkWin32Theme *
+gtk_win32_theme_parse (GtkCssParser *parser)
+{
+  GtkWin32Theme *theme;
+  char *class_name;
+
+  class_name = _gtk_css_parser_try_name (parser, TRUE);
+  if (class_name == NULL)
+    {
+      _gtk_css_parser_error (parser, "Expected valid win32 theme name");
+      return NULL;
+    }
+
+  theme = gtk_win32_theme_lookup (class_name);
+  g_free (class_name);
+
+  return theme;
+}
+
 cairo_surface_t *
 gtk_win32_theme_create_surface (GtkWin32Theme *theme,
                                 int            xp_part,
diff --git a/gtk/gtkwin32themeprivate.h b/gtk/gtkwin32themeprivate.h
index 964eb8a..0c749ac 100644
--- a/gtk/gtkwin32themeprivate.h
+++ b/gtk/gtkwin32themeprivate.h
@@ -28,7 +28,7 @@ typedef struct _GtkWin32Theme GtkWin32Theme;
 
 #define GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME "-gtk-win32-color"
 
-GtkWin32Theme *         gtk_win32_theme_lookup          (const char     *classname);
+GtkWin32Theme *         gtk_win32_theme_parse           (GtkCssParser   *parser);
 
 GtkWin32Theme *         gtk_win32_theme_ref             (GtkWin32Theme  *theme);
 void                    gtk_win32_theme_unref           (GtkWin32Theme  *theme);


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