[gtk+/wip/cssnode3: 3/46] cssnode: Turn into a GObject



commit 511ec66f3f7e455cac05c09045e6713984d87114
Author: Benjamin Otte <otte redhat com>
Date:   Sat Jan 10 23:49:04 2015 +0100

    cssnode: Turn into a GObject
    
    This will allow us to use subclasses.

 gtk/gtkcssnode.c        |   45 ++++++++++++++++++++++++++-------------------
 gtk/gtkcssnodeprivate.h |   28 +++++++++++++++++++++++++---
 gtk/gtkstylecontext.c   |    4 ++--
 3 files changed, 53 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 5993b3a..a4b5a63 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -19,22 +19,38 @@
 
 #include "gtkcssnodeprivate.h"
 
-struct _GtkCssNode
+G_DEFINE_TYPE (GtkCssNode, gtk_css_node, G_TYPE_OBJECT)
+
+static void
+gtk_css_node_finalize (GObject *object)
 {
-  GtkCssNodeDeclaration *decl;
-  GtkCssNode            *parent;
-  GtkCssStyle           *style;
-};
+  GtkCssNode *cssnode = GTK_CSS_NODE (object);
 
-GtkCssNode *
-gtk_css_node_new (void)
+  if (cssnode->style)
+    g_object_unref (cssnode->style);
+  gtk_css_node_declaration_unref (cssnode->decl);
+
+  G_OBJECT_CLASS (gtk_css_node_parent_class)->finalize (object);
+}
+
+static void
+gtk_css_node_class_init (GtkCssNodeClass *klass)
 {
-  GtkCssNode *cssnode;
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  cssnode = g_slice_new0 (GtkCssNode);
+  object_class->finalize = gtk_css_node_finalize;
+}
+
+static void
+gtk_css_node_init (GtkCssNode *cssnode)
+{
   cssnode->decl = gtk_css_node_declaration_new ();
+}
 
-  return cssnode;
+GtkCssNode *
+gtk_css_node_new (void)
+{
+  return g_object_new (GTK_TYPE_CSS_NODE, NULL);
 }
 
 GtkCssNode *
@@ -50,15 +66,6 @@ gtk_css_node_copy (GtkCssNode *cssnode)
 }
 
 void
-gtk_css_node_free (GtkCssNode *cssnode)
-{
-  if (cssnode->style)
-    g_object_unref (cssnode->style);
-  gtk_css_node_declaration_unref (cssnode->decl);
-  g_slice_free (GtkCssNode, cssnode);
-}
-
-void
 gtk_css_node_set_parent (GtkCssNode *cssnode,
                          GtkCssNode *parent)
 {
diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h
index 0999ab5..7d217d9 100644
--- a/gtk/gtkcssnodeprivate.h
+++ b/gtk/gtkcssnodeprivate.h
@@ -23,13 +23,35 @@
 
 G_BEGIN_DECLS
 
-typedef struct _GtkCssNode GtkCssNode;
+#define GTK_TYPE_CSS_NODE           (gtk_css_node_get_type ())
+#define GTK_CSS_NODE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_NODE, GtkCssNode))
+#define GTK_CSS_NODE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_NODE, GtkCssNodeClass))
+#define GTK_IS_CSS_NODE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_NODE))
+#define GTK_IS_CSS_NODE_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_NODE))
+#define GTK_CSS_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_NODE, GtkCssNodeClass))
+
+typedef struct _GtkCssNode           GtkCssNode;
+typedef struct _GtkCssNodeClass      GtkCssNodeClass;
+
+struct _GtkCssNode
+{
+  GObject object;
+
+  GtkCssNodeDeclaration *decl;
+  GtkCssNode            *parent;
+  GtkCssStyle           *style;
+};
+
+struct _GtkCssNodeClass
+{
+  GObjectClass object_class;
+};
+
+GType                   gtk_css_node_get_type           (void) G_GNUC_CONST;
 
 GtkCssNode *            gtk_css_node_new                (void);
 GtkCssNode *            gtk_css_node_copy               (GtkCssNode            *cssnode);
 
-void                    gtk_css_node_free               (GtkCssNode            *cssnode);
-
 void                    gtk_css_node_set_parent         (GtkCssNode            *cssnode,
                                                          GtkCssNode            *parent);
 GtkCssNode *            gtk_css_node_get_parent         (GtkCssNode            *cssnode);
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index d42e3ad..780401e 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -316,7 +316,7 @@ gtk_style_context_pop_style_node (GtkStyleContext *context)
 
   g_return_if_fail (priv->saved_nodes != NULL);
 
-  gtk_css_node_free (priv->cssnode);
+  g_object_unref (priv->cssnode);
   priv->cssnode = priv->saved_nodes->data;
   priv->saved_nodes = g_slist_remove (priv->saved_nodes, priv->cssnode);
 }
@@ -529,7 +529,7 @@ gtk_style_context_finalize (GObject *object)
 
   while (priv->saved_nodes)
     gtk_style_context_pop_style_node (style_context);
-  gtk_css_node_free (priv->cssnode);
+  g_object_unref (priv->cssnode);
 
   gtk_style_context_clear_property_cache (style_context);
   g_array_free (priv->property_cache, TRUE);


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