[gtk+] stylecontext: Add style_info_set_data()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] stylecontext: Add style_info_set_data()
- Date: Tue, 17 Apr 2012 07:21:49 +0000 (UTC)
commit 42d243049855f554eb63da0ff86b051de0a3841b
Author: Benjamin Otte <otte redhat com>
Date: Wed Apr 11 12:22:07 2012 +0200
stylecontext: Add style_info_set_data()
.. to take care of the refcounting properly.
gtk/gtkstylecontext.c | 65 ++++++++++++++++++++++++++----------------------
1 files changed, 35 insertions(+), 30 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 8d72af0..73db284 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -533,10 +533,25 @@ style_info_new (void)
}
static void
-style_info_free (GtkStyleInfo *info)
+style_info_set_data (GtkStyleInfo *info,
+ StyleData *data)
{
+ if (info->data == data)
+ return;
+
+ if (data)
+ style_data_ref (data);
+
if (info->data)
style_data_unref (info->data);
+
+ info->data = data;
+}
+
+static void
+style_info_free (GtkStyleInfo *info)
+{
+ style_info_set_data (info, NULL);
g_array_free (info->style_classes, TRUE);
g_array_free (info->regions, TRUE);
g_slice_free (GtkStyleInfo, info);
@@ -569,8 +584,7 @@ style_info_copy (GtkStyleInfo *info)
copy->next = info;
copy->junction_sides = info->junction_sides;
copy->state_flags = info->state_flags;
- if (info->data)
- copy->data = style_data_ref (info->data);
+ style_info_set_data (copy, info->data);
return copy;
}
@@ -938,7 +952,9 @@ static StyleData *
style_data_lookup (GtkStyleContext *context)
{
GtkStyleContextPrivate *priv;
+ GtkWidgetPath *path;
GtkStyleInfo *info;
+ StyleData *data;
priv = context->priv;
info = priv->info;
@@ -949,29 +965,26 @@ style_data_lookup (GtkStyleContext *context)
g_assert (priv->widget != NULL || priv->widget_path != NULL);
- info->data = g_hash_table_lookup (priv->style_data, info);
-
- if (info->data)
+ data = g_hash_table_lookup (priv->style_data, info);
+ if (data)
{
- style_data_ref (info->data);
+ style_info_set_data (info, data);
+ return data;
}
- else
- {
- GtkWidgetPath *path;
- path = create_query_path (context);
+ path = create_query_path (context);
- info->data = style_data_new ();
- g_hash_table_insert (priv->style_data,
- style_info_copy (info),
- style_data_ref (info->data));
+ data = style_data_new ();
+ style_info_set_data (info, data);
+ g_hash_table_insert (priv->style_data,
+ style_info_copy (info),
+ data);
- build_properties (context, info->data, path, info->state_flags);
+ build_properties (context, data, path, info->state_flags);
- gtk_widget_path_free (path);
- }
+ gtk_widget_path_free (path);
- return info->data;
+ return data;
}
static void
@@ -1016,11 +1029,7 @@ gtk_style_context_queue_invalidate_internal (GtkStyleContext *context,
if (gtk_style_context_is_saved (context))
{
- if (info->data)
- {
- style_data_unref (info->data);
- info->data = NULL;
- }
+ style_info_set_data (info, NULL);
}
else
{
@@ -2888,11 +2897,7 @@ gtk_style_context_clear_cache (GtkStyleContext *context)
for (info = priv->info; info; info = info->next)
{
- if (info->data)
- {
- style_data_unref (info->data);
- info->data = NULL;
- }
+ style_info_set_data (info, NULL);
}
g_hash_table_remove_all (priv->style_data);
}
@@ -2981,7 +2986,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
if ((priv->relevant_changes & change) & ~GTK_STYLE_CONTEXT_CACHED_CHANGE)
gtk_style_context_clear_cache (context);
else
- info->data = NULL;
+ style_info_set_data (info, NULL);
if (old)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]