[gtk+] css: Add ability to specify icontheme in CSS



commit da6beb994ec25aaa79aae9b43d10b32035c412f1
Author: Benjamin Otte <otte redhat com>
Date:   Wed Dec 2 03:54:41 2015 +0100

    css: Add ability to specify icontheme in CSS
    
    -gtk-icontheme: "oxygen" works now.
    
    This is a very crude implementation. It's meant for testing only.

 gtk/gtkcssiconthemevalue.c        |   61 ++++++++++++++++++++++++++++---------
 gtk/gtkcssiconthemevalueprivate.h |    6 ++-
 gtk/gtkcssstylepropertyimpl.c     |   12 +++----
 3 files changed, 55 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkcssiconthemevalue.c b/gtk/gtkcssiconthemevalue.c
index 84eb02f..e6633c5 100644
--- a/gtk/gtkcssiconthemevalue.c
+++ b/gtk/gtkcssiconthemevalue.c
@@ -76,22 +76,14 @@ gtk_css_value_icon_theme_compute (GtkCssValue             *icon_theme,
                                   GtkCssStyle             *style,
                                   GtkCssStyle             *parent_style)
 {
-  GtkCssValue *result;
   GtkIconTheme *icontheme;
 
-  icontheme = gtk_icon_theme_get_for_screen (_gtk_settings_get_screen 
(_gtk_style_provider_private_get_settings (provider)));
-
-  result = g_object_get_data (G_OBJECT (icontheme), "-gtk-css-value");
-  if (result)
-    return _gtk_css_value_ref (result);
-
-  result = _gtk_css_icon_theme_value_new ();
-  result->icontheme = g_object_ref (icontheme);
-
-  g_object_set_data (G_OBJECT (icontheme), "-gtk-css-value", result);
-  result->changed_id = g_signal_connect (icontheme, "changed", G_CALLBACK 
(gtk_css_value_icon_theme_changed_cb), result);
+  if (icon_theme->icontheme)
+    icontheme = icon_theme->icontheme;
+  else
+    icontheme = gtk_icon_theme_get_for_screen (_gtk_settings_get_screen 
(_gtk_style_provider_private_get_settings (provider)));
 
-  return result;
+  return gtk_css_icon_theme_value_new (icontheme);
 }
 
 static gboolean
@@ -125,10 +117,49 @@ static const GtkCssValueClass GTK_CSS_VALUE_ICON_THEME = {
   gtk_css_value_icon_theme_print
 };
 
+static GtkCssValue default_icon_theme_value = { &GTK_CSS_VALUE_ICON_THEME, 1, NULL, 0 };
+
 GtkCssValue *
-_gtk_css_icon_theme_value_new (void)
+gtk_css_icon_theme_value_new (GtkIconTheme *icontheme)
 {
-  return _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_ICON_THEME);
+  GtkCssValue *result;
+
+  if (icontheme == NULL)
+    return _gtk_css_value_ref (&default_icon_theme_value);
+
+  result = g_object_get_data (G_OBJECT (icontheme), "-gtk-css-value");
+  if (result)
+    return _gtk_css_value_ref (result);
+
+  result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_ICON_THEME);
+  result->icontheme = g_object_ref (icontheme);
+
+  g_object_set_data (G_OBJECT (icontheme), "-gtk-css-value", result);
+  result->changed_id = g_signal_connect (icontheme, "changed", G_CALLBACK 
(gtk_css_value_icon_theme_changed_cb), result);
+
+  return result;
+}
+
+GtkCssValue *
+gtk_css_icon_theme_value_parse (GtkCssParser *parser)
+{
+  GtkIconTheme *icontheme;
+  GtkCssValue *result;
+  char *s;
+
+  s = _gtk_css_parser_read_string (parser);
+  if (s == NULL)
+    return NULL;
+
+  icontheme = gtk_icon_theme_new ();
+  gtk_icon_theme_set_custom_theme (icontheme, s);
+
+  result = gtk_css_icon_theme_value_new (icontheme);
+
+  g_object_unref (icontheme);
+  g_free (s);
+
+  return result;
 }
 
 GtkIconTheme *
diff --git a/gtk/gtkcssiconthemevalueprivate.h b/gtk/gtkcssiconthemevalueprivate.h
index f11df88..420d490 100644
--- a/gtk/gtkcssiconthemevalueprivate.h
+++ b/gtk/gtkcssiconthemevalueprivate.h
@@ -27,9 +27,11 @@
 
 G_BEGIN_DECLS
 
-GtkCssValue *   _gtk_css_icon_theme_value_new           (void);
+GtkCssValue *   gtk_css_icon_theme_value_new            (GtkIconTheme           *icontheme);
 
-GtkIconTheme *  gtk_css_icon_theme_value_get_icon_theme (GtkCssValue    *value);
+GtkCssValue *   gtk_css_icon_theme_value_parse          (GtkCssParser           *parser);
+
+GtkIconTheme *  gtk_css_icon_theme_value_get_icon_theme (GtkCssValue            *value);
 
 G_END_DECLS
 
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index ca4b277..5c48ce8 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -987,9 +987,7 @@ static GtkCssValue *
 icon_theme_value_parse (GtkCssStyleProperty *property,
                        GtkCssParser        *parser)
 {
-  _gtk_css_parser_error (parser, "Only 'inherit', 'initial' or 'unset' are allowed");
-
-  return NULL;
+  return gtk_css_icon_theme_value_parse (parser);
 }
 
 /*** REGISTRATION ***/
@@ -1028,9 +1026,6 @@ _gtk_css_style_property_init_properties (void)
                                           query_length_as_double,
                                           assign_length_from_double,
                                           _gtk_css_font_size_value_new (GTK_CSS_FONT_SIZE_MEDIUM));
-
-  /* properties that aren't referenced when computing values
-   * start here */
   gtk_css_style_property_register        ("-gtk-icon-theme",
                                           GTK_CSS_PROPERTY_ICON_THEME,
                                           G_TYPE_NONE,
@@ -1039,7 +1034,10 @@ _gtk_css_style_property_init_properties (void)
                                           icon_theme_value_parse,
                                           NULL,
                                           NULL,
-                                          _gtk_css_icon_theme_value_new());
+                                          gtk_css_icon_theme_value_new (NULL));
+
+  /* properties that aren't referenced when computing values
+   * start here */
   gtk_css_style_property_register        ("background-color",
                                           GTK_CSS_PROPERTY_BACKGROUND_COLOR,
                                           GDK_TYPE_RGBA,


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