From 726d8abb7d890ec696f933da6c1c8687ca640fa5 Mon Sep 17 00:00:00 2001 From: Benjamin Otte <otte@redhat.com> Date: Sat, 10 Jan 2015 23:49:04 +0100 Subject: [PATCH] cssnode: Turn into a GObject This will allow us to use subclasses. --- gtk/gtkcssnode.c | 47 +++++++++++++++++++++++------------------ gtk/gtkcssnodeprivate.h | 28 +++++++++++++++++++++--- gtk/gtkstylecontext.c | 4 ++-- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c index 5993b3a83b..a4b5a6308a 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); + + 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) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = gtk_css_node_finalize; +} + +static void +gtk_css_node_init (GtkCssNode *cssnode) +{ + cssnode->decl = gtk_css_node_declaration_new (); +} GtkCssNode * gtk_css_node_new (void) { - GtkCssNode *cssnode; - - cssnode = g_slice_new0 (GtkCssNode); - cssnode->decl = gtk_css_node_declaration_new (); - - return cssnode; + return g_object_new (GTK_TYPE_CSS_NODE, NULL); } GtkCssNode * @@ -49,15 +65,6 @@ gtk_css_node_copy (GtkCssNode *cssnode) return copy; } -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 0999ab5c89..7d217d9a56 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 9c15207e33..ef6dcaac0a 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);