[gtk+] cssnode: Add a style-changed signal



commit 10d39171d929366a6fdfd1903c7424c86aa4ef38
Author: Benjamin Otte <otte redhat com>
Date:   Thu Mar 5 17:35:57 2015 +0100

    cssnode: Add a style-changed signal
    
    The signal gets emitted whenever the style needs to be changed.

 gtk/gtkcssnode.c        |   31 +++++++++++++++++++++++--------
 gtk/gtkcssnodeprivate.h |    3 +++
 2 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index e31690a..cda2ab8 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -34,6 +34,7 @@ G_DEFINE_TYPE (GtkCssNode, gtk_css_node, G_TYPE_OBJECT)
 enum {
   NODE_ADDED,
   NODE_REMOVED,
+  STYLE_CHANGED,
   LAST_SIGNAL
 };
 
@@ -388,6 +389,17 @@ gtk_css_node_real_node_added (GtkCssNode *parent,
 }
 
 static void
+gtk_css_node_real_style_changed (GtkCssNode  *cssnode,
+                                 GtkCssStyle *old_style,
+                                 GtkCssStyle *new_style)
+{
+  g_object_ref (new_style);
+  g_object_unref (old_style);
+
+  cssnode->style = new_style;
+}
+
+static void
 gtk_css_node_class_init (GtkCssNodeClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -408,6 +420,7 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
 
   klass->node_added = gtk_css_node_real_node_added;
   klass->node_removed = gtk_css_node_real_node_removed;
+  klass->style_changed = gtk_css_node_real_style_changed;
 
   cssnode_signals[NODE_ADDED] =
     g_signal_new (I_("node-added"),
@@ -427,6 +440,15 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
                  _gtk_marshal_VOID__OBJECT_OBJECT,
                  G_TYPE_NONE, 2,
                  GTK_TYPE_CSS_NODE, GTK_TYPE_CSS_NODE);
+  cssnode_signals[STYLE_CHANGED] =
+    g_signal_new (I_("style-changed"),
+                 G_TYPE_FROM_CLASS (object_class),
+                 G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GtkCssNodeClass, style_changed),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__OBJECT_OBJECT,
+                 G_TYPE_NONE, 2,
+                 GTK_TYPE_CSS_STYLE, GTK_TYPE_CSS_STYLE);
 }
 
 static void
@@ -640,14 +662,7 @@ gtk_css_node_set_style (GtkCssNode  *cssnode,
   if (cssnode->style == style)
     return FALSE;
 
-  if (style)
-    g_object_ref (style);
-
-  if (cssnode->style)
-    g_object_unref (cssnode->style);
-
-  cssnode->style = style;
-
+  g_signal_emit (cssnode, cssnode_signals[STYLE_CHANGED], 0, cssnode->style, style);
   return TRUE;
 }
 
diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h
index 6cc9f72..21b92ca 100644
--- a/gtk/gtkcssnodeprivate.h
+++ b/gtk/gtkcssnodeprivate.h
@@ -71,6 +71,9 @@ struct _GtkCssNodeClass
   void                  (* node_removed)                (GtkCssNode            *cssnode,
                                                          GtkCssNode            *child,
                                                          GtkCssNode            *previous);
+  void                  (* style_changed)               (GtkCssNode            *cssnode,
+                                                         GtkCssStyle           *old_style,
+                                                         GtkCssStyle           *new_style);
 
   gboolean              (* init_matcher)                (GtkCssNode            *cssnode,
                                                          GtkCssMatcher         *matcher);


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