[glade/css: 5/8] Set style classes on runtime objects



commit 9cfe5d199b50111be78b7b56bc3793c4e2677195
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Wed Jul 24 17:06:26 2013 -0300

    Set style classes on runtime objects

 plugins/gtk+/glade-gtk-widget.c |   29 ++++++++++++++++++++++++++++-
 plugins/gtk+/gtk+.xml.in        |    2 +-
 2 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-widget.c b/plugins/gtk+/glade-gtk-widget.c
index 75b0a8f..7267697 100644
--- a/plugins/gtk+/glade-gtk-widget.c
+++ b/plugins/gtk+/glade-gtk-widget.c
@@ -733,7 +733,34 @@ glade_gtk_widget_set_property (GladeWidgetAdaptor * adaptor,
   if (!strcmp (id, "can-focus"))
     return;
 
-  GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value);
+  if (!strcmp (id, "glade-style-classes"))
+    {
+      GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (object));
+      GList *l, *styles;
+
+      /* NOTE: we can not use gtk_style_context_list_classes() because we only
+       * want to remove the classes we added not the ones added by the widget
+       */
+      styles = g_object_get_data (object, "glade-style-classes");
+      for (l = styles; l; l = g_list_next (l))
+       {
+         GladeString *style = l->data;
+          gtk_style_context_remove_class (context, style->string);
+       }
+
+      for (l = g_value_get_boxed (value); l; l = g_list_next (l))
+       {
+         GladeString *style = l->data;
+         gtk_style_context_add_class (context, style->string);
+       }
+
+      /* Save the list here so we can use it later on to remove them from the style context */
+      g_object_set_data_full (object, "glade-style-classes",
+                              glade_string_list_copy (g_value_get_boxed (value)),
+                              (GDestroyNotify) glade_string_list_free);
+    }
+  else
+      GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor, object, id, value);
 }
 
 void
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 1580308..4ec5ad8 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -91,7 +91,7 @@
           </property>
           
           <property id="glade-style-classes" _name="Style Classes" weight="4.25" custom-layout="True"
-                 save="False" ignore="True" since="3.0">
+                 save="False" since="3.0">
             <parameter-spec>
               <type>GParamBoxed</type>
               <value-type>GladeStringList</value-type>


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