[gtk+] win32: Update color handling to recent GtkWin32Theme changes



commit 3597baf272816a0f2573c4c5b755969399b722e9
Author: Benjamin Otte <otte gnome org>
Date:   Sun Feb 14 16:18:56 2016 +0100

    win32: Update color handling to recent GtkWin32Theme changes

 gtk/gtkcsscolorvalue.c     |   62 ++++++++++++++++++++++++++-----------------
 gtk/gtkwin32theme.c        |   43 ++++++++++++++----------------
 gtk/gtkwin32themeprivate.h |   12 ++++----
 3 files changed, 63 insertions(+), 54 deletions(-)
---
diff --git a/gtk/gtkcsscolorvalue.c b/gtk/gtkcsscolorvalue.c
index 9679fd8..b707946 100644
--- a/gtk/gtkcsscolorvalue.c
+++ b/gtk/gtkcsscolorvalue.c
@@ -62,7 +62,7 @@ struct _GtkCssValue
 
     struct
     {
-      gchar *theme_class;
+      GtkWin32Theme *theme;
       gint id;
     } win32;
   } sym_col;
@@ -90,7 +90,7 @@ gtk_css_value_color_free (GtkCssValue *color)
       _gtk_css_value_unref (color->sym_col.mix.color2);
       break;
     case COLOR_TYPE_WIN32:
-      g_free (color->sym_col.win32.theme_class);
+      gtk_win32_theme_unref (color->sym_col.win32.theme);
       break;
     default:
       break;
@@ -243,10 +243,9 @@ _gtk_css_color_value_resolve (GtkCssValue             *color,
       {
        GdkRGBA res;
 
-       if (!_gtk_win32_theme_color_resolve (color->sym_col.win32.theme_class,
-                                            color->sym_col.win32.id,
-                                            &res))
-         return NULL;
+        gtk_win32_theme_get_color (color->sym_col.win32.theme,
+                                  color->sym_col.win32.id,
+                                  &res);
 
        value = _gtk_css_rgba_value_new_from_rgba (&res);
       }
@@ -350,7 +349,7 @@ gtk_css_value_color_equal (const GtkCssValue *value1,
              _gtk_css_value_equal (value1->sym_col.mix.color2,
                                    value2->sym_col.mix.color2);
     case COLOR_TYPE_WIN32:
-      return g_str_equal (value1->sym_col.win32.theme_class, value2->sym_col.win32.theme_class) &&
+      return gtk_win32_theme_equal (value1->sym_col.win32.theme, value2->sym_col.win32.theme) &&
              value1->sym_col.win32.id == value2->sym_col.win32.id;
     case COLOR_TYPE_CURRENT_COLOR:
       return TRUE;
@@ -422,8 +421,9 @@ gtk_css_value_color_print (const GtkCssValue *value,
       break;
     case COLOR_TYPE_WIN32:
       {
-        g_string_append_printf (string, GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME"(%s, %d)", 
-                               value->sym_col.win32.theme_class, value->sym_col.win32.id);
+        g_string_append (string, GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME"(");
+        gtk_win32_theme_print (value->sym_col.win32.theme, string);
+        g_string_append_printf (string, "%d)", value->sym_col.win32.id);
       }
       break;
     case COLOR_TYPE_CURRENT_COLOR:
@@ -532,18 +532,34 @@ _gtk_css_color_value_new_mix (GtkCssValue *color1,
   return value;
 }
 
+static GtkCssValue *
+gtk_css_color_value_new_win32_for_theme (GtkWin32Theme *theme,
+                                         gint           id)
+{
+  GtkCssValue *value;
+
+  gtk_internal_return_val_if_fail (theme != NULL, NULL);
+
+  value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_COLOR);
+  value->type = COLOR_TYPE_WIN32;
+  value->sym_col.win32.theme = gtk_win32_theme_ref (theme);
+  value->sym_col.win32.id = id;
+
+  return value;
+}
+
 GtkCssValue *
 _gtk_css_color_value_new_win32 (const gchar *theme_class,
                                 gint         id)
 {
+  GtkWin32Theme *theme;
   GtkCssValue *value;
 
   gtk_internal_return_val_if_fail (theme_class != NULL, NULL);
 
-  value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_COLOR);
-  value->type = COLOR_TYPE_WIN32;
-  value->sym_col.win32.theme_class = g_strdup (theme_class);
-  value->sym_col.win32.id = id;
+  theme = gtk_win32_theme_lookup (theme_class);
+  value = gtk_css_color_value_new_win32_for_theme (theme, id);
+  gtk_win32_theme_unref (theme);
 
   return value;
 }
@@ -571,20 +587,16 @@ static GtkCssValue *
 gtk_css_color_parse_win32 (GtkCssParser *parser)
 {
   GtkCssValue *color;
-  char *class;
+  GtkWin32Theme *theme;
   int id;
 
-  class = _gtk_css_parser_try_name (parser, TRUE);
-  if (class == NULL)
-    {
-      _gtk_css_parser_error (parser,
-                            "Expected name as first argument to  '-gtk-win32-color'");
-      return NULL;
-    }
+  theme = gtk_win32_theme_parse (parser);
+  if (theme == NULL)
+    return NULL;
 
   if (! _gtk_css_parser_try (parser, ",", TRUE))
     {
-      g_free (class);
+      gtk_win32_theme_unref (theme);
       _gtk_css_parser_error (parser,
                             "Expected ','");
       return NULL;
@@ -592,13 +604,13 @@ gtk_css_color_parse_win32 (GtkCssParser *parser)
 
   if (!_gtk_css_parser_try_int (parser, &id))
     {
-      g_free (class);
+      gtk_win32_theme_unref (theme);
       _gtk_css_parser_error (parser, "Expected a valid integer value");
       return NULL;
     }
 
-  color = _gtk_css_color_value_new_win32 (class, id);
-  g_free (class);
+  color = gtk_css_color_value_new_win32_for_theme (theme, id);
+  gtk_win32_theme_unref (theme);
   return color;
 }
 
diff --git a/gtk/gtkwin32theme.c b/gtk/gtkwin32theme.c
index 352e20a..e1de2c9 100644
--- a/gtk/gtkwin32theme.c
+++ b/gtk/gtkwin32theme.c
@@ -64,7 +64,7 @@ typedef HRESULT (FAR PASCAL *GetThemePartSizeFunc)          (HTHEME hTheme,
                                                             SIZE *psz);
 
 static GetThemeSysFontFunc get_theme_sys_font = NULL;
-static GetThemeSysColorFunc get_theme_sys_color = NULL;
+static GetThemeSysColorFunc GetThemeSysColor = NULL;
 static GetThemeSysSizeFunc get_theme_sys_metric = NULL;
 static OpenThemeDataFunc OpenThemeData = NULL;
 static CloseThemeDataFunc CloseThemeData = NULL;
@@ -205,7 +205,7 @@ gtk_win32_theme_init (void)
       draw_theme_background = (DrawThemeBackgroundFunc) GetProcAddress (uxtheme_dll, "DrawThemeBackground");
       enable_theme_dialog_texture = (EnableThemeDialogTextureFunc) GetProcAddress (uxtheme_dll, 
"EnableThemeDialogTexture");
       get_theme_sys_font = (GetThemeSysFontFunc) GetProcAddress (uxtheme_dll, "GetThemeSysFont");
-      get_theme_sys_color = (GetThemeSysColorFunc) GetProcAddress (uxtheme_dll, "GetThemeSysColor");
+      GetThemeSysColor = (GetThemeSysColorFunc) GetProcAddress (uxtheme_dll, "GetThemeSysColor");
       get_theme_sys_metric = (GetThemeSysSizeFunc) GetProcAddress (uxtheme_dll, "GetThemeSysSize");
       is_theme_partially_transparent = (IsThemeBackgroundPartiallyTransparentFunc) GetProcAddress 
(uxtheme_dll, "IsThemeBackgroundPartiallyTransparent");
       draw_theme_parent_background = (DrawThemeParentBackgroundFunc) GetProcAddress (uxtheme_dll, 
"DrawThemeParentBackground");
@@ -251,22 +251,27 @@ canonicalize_class_name (const char *classname)
   return g_ascii_strdown (classname, -1);
 }
 
-static GtkWin32Theme *
+GtkWin32Theme *
 gtk_win32_theme_lookup (const char *classname)
 {
   GtkWin32Theme *theme;
+  char *canonical_classname;
 
   if (G_UNLIKELY (themes_by_class == NULL))
     themes_by_class = g_hash_table_new (g_str_hash, g_str_equal);
 
-  theme = g_hash_table_lookup (themes_by_class, classname);
+  canonical_classname = canonicalize_class_name (classname);
+  theme = g_hash_table_lookup (themes_by_class, canonical_classname);
 
   if (theme != NULL)
-    return gtk_win32_theme_ref (theme);
+    {
+      g_free (canonical_classname);
+      return gtk_win32_theme_ref (theme);
+    }
 
   theme = g_slice_new0 (GtkWin32Theme);
   theme->ref_count = 1;
-  theme->class_name = g_strdup (classname);
+  theme->class_name = canonical_classname;
 
   g_hash_table_insert (themes_by_class, theme->class_name, theme);
 
@@ -277,7 +282,7 @@ GtkWin32Theme *
 gtk_win32_theme_parse (GtkCssParser *parser)
 {
   GtkWin32Theme *theme;
-  char *canonical_class_name, *class_name;
+  char *class_name;
 
   class_name = _gtk_css_parser_try_name (parser, TRUE);
   if (class_name == NULL)
@@ -285,10 +290,8 @@ gtk_win32_theme_parse (GtkCssParser *parser)
       _gtk_css_parser_error (parser, "Expected valid win32 theme name");
       return NULL;
     }
-  canonical_class_name = canonicalize_class_name (class_name);
 
-  theme = gtk_win32_theme_lookup (canonical_class_name);
-  g_free (canonical_class_name);
+  theme = gtk_win32_theme_lookup (class_name);
   g_free (class_name);
 
   return theme;
@@ -405,30 +408,25 @@ gtk_win32_theme_get_size (GtkWin32Theme *theme,
 #endif
 }
 
-gboolean
-_gtk_win32_theme_color_resolve (const char *theme_class,
-                               gint id,
-                               GdkRGBA *color)
+void
+gtk_win32_theme_get_color (GtkWin32Theme *theme,
+                           gint           id,
+                           GdkRGBA       *color)
 {
 #ifdef G_OS_WIN32
-  GtkWin32Theme *theme;
   HTHEME htheme;
   DWORD dcolor;
 
-  theme = gtk_win32_theme_lookup (theme_class);
-  if (use_xp_theme && get_theme_sys_color != NULL)
+  if (use_xp_theme && GetThemeSysColor != NULL)
     {
       htheme = gtk_win32_theme_get_htheme (theme);
 
-      /* if htheme is NULL, it will just return the GetSystemColor()
-         value */
-      dcolor = get_theme_sys_color (htheme, id);
+      /* if htheme is NULL, it will just return the GetSysColor() value */
+      dcolor = GetThemeSysColor (htheme, id);
     }
   else
     dcolor = GetSysColor (id);
 
-  gtk_win32_theme_unref (theme);
-
   color->alpha = 1.0;
   color->red = GetRValue (dcolor) / 255.0;
   color->green = GetGValue (dcolor) / 255.0;
@@ -436,7 +434,6 @@ _gtk_win32_theme_color_resolve (const char *theme_class,
 #else
   gdk_rgba_parse (color, "pink");
 #endif
-  return TRUE;
 }
 
 void
diff --git a/gtk/gtkwin32themeprivate.h b/gtk/gtkwin32themeprivate.h
index 0c749ac..c05311d 100644
--- a/gtk/gtkwin32themeprivate.h
+++ b/gtk/gtkwin32themeprivate.h
@@ -28,6 +28,7 @@ typedef struct _GtkWin32Theme GtkWin32Theme;
 
 #define GTK_WIN32_THEME_SYMBOLIC_COLOR_NAME "-gtk-win32-color"
 
+GtkWin32Theme *         gtk_win32_theme_lookup          (const char     *class_name);
 GtkWin32Theme *         gtk_win32_theme_parse           (GtkCssParser   *parser);
 
 GtkWin32Theme *         gtk_win32_theme_ref             (GtkWin32Theme  *theme);
@@ -47,12 +48,11 @@ cairo_surface_t *       gtk_win32_theme_create_surface  (GtkWin32Theme *theme,
                                                          int            height,
                                                         int           *x_offs_out,
                                                         int           *y_offs_out);
-int                     gtk_win32_theme_get_size        (GtkWin32Theme *theme,
-                                                        int            id);
-
-gboolean           _gtk_win32_theme_color_resolve (const char        *theme_class,
-                                                  gint               id,
-                                                  GdkRGBA           *color);
+int                     gtk_win32_theme_get_size        (GtkWin32Theme  *theme,
+                                                        int             id);
+void                    gtk_win32_theme_get_color       (GtkWin32Theme  *theme,
+                                                         gint            id,
+                                                         GdkRGBA        *color);
 
 G_END_DECLS
 


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