cssnode: Turn into a GObject

This will allow us to use subclasses.
This commit is contained in:
Benjamin Otte 2015-01-10 23:49:04 +01:00
parent cf6d9edc12
commit 726d8abb7d
3 changed files with 54 additions and 25 deletions

View File

@ -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)

View File

@ -23,13 +23,35 @@
G_BEGIN_DECLS
#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);

View File

@ -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);