[gtk+] stylecontext: Add setter for widget



commit 1aa4a196dc6b3b43ba693b844f5b9dd8a9e3f9d0
Author: Benjamin Otte <otte redhat com>
Date:   Sun Mar 18 23:02:33 2012 +0100

    stylecontext: Add setter for widget
    
    ... and actually set the widget on the style context. Note that this
    function does not take a reference on the widget, which is a very good
    reason to keep it private.

 gtk/gtkstylecontext.c        |   14 +++++++++++++-
 gtk/gtkstylecontextprivate.h |    4 +++-
 gtk/gtkwidget.c              |    6 +++++-
 3 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 415b186..9d6608e 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -361,6 +361,7 @@ struct _GtkStyleContextPrivate
   GtkStyleCascade *cascade;
 
   GtkStyleContext *parent;
+  GtkWidget *widget;            
   GtkWidgetPath *widget_path;
   GHashTable *style_data;
   GSList *info_stack;
@@ -1021,6 +1022,16 @@ gtk_style_context_new (void)
   return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
 }
 
+void
+_gtk_style_context_set_widget (GtkStyleContext *context,
+                               GtkWidget       *widget)
+{
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
+
+  context->priv->widget = widget;
+}
+
 /**
  * gtk_style_context_add_provider:
  * @context: a #GtkStyleContext
@@ -1492,6 +1503,7 @@ gtk_style_context_set_path (GtkStyleContext *context,
   g_return_if_fail (path != NULL);
 
   priv = context->priv;
+  g_return_if_fail (priv->widget == NULL);
 
   if (priv->widget_path)
     {
@@ -2214,7 +2226,7 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
   g_param_spec_ref (pcache->pspec);
   g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
 
-  if (priv->widget_path)
+  if (priv->widget || priv->widget_path)
     {
       if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
                                                  priv->widget_path, state,
diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h
index dbec998..b35a3aa 100644
--- a/gtk/gtkstylecontextprivate.h
+++ b/gtk/gtkstylecontextprivate.h
@@ -24,7 +24,9 @@
 
 G_BEGIN_DECLS
 
-GtkCssValue   * _gtk_style_context_peek_property              (GtkStyleContext *context,
+void            _gtk_style_context_set_widget                (GtkStyleContext *context,
+                                                              GtkWidget       *widget);
+GtkCssValue   * _gtk_style_context_peek_property             (GtkStyleContext *context,
                                                               const char      *property_name);
 double         _gtk_style_context_get_number                 (GtkStyleContext *context,
                                                               const char      *property_name,
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index aea3574..43da8ab 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -10402,7 +10402,10 @@ gtk_widget_finalize (GObject *object)
     gtk_widget_path_free (priv->path);
 
   if (priv->context)
-    g_object_unref (priv->context);
+    {
+      _gtk_style_context_set_widget (priv->context, NULL);
+      g_object_unref (priv->context);
+    }
 
   _gtk_widget_free_cached_sizes (widget);
 
@@ -14128,6 +14131,7 @@ gtk_widget_get_style_context (GtkWidget *widget)
         gtk_style_context_set_parent (priv->context,
                                       gtk_widget_get_style_context (priv->parent));
 
+      _gtk_style_context_set_widget (priv->context, widget);
       g_signal_connect (widget->priv->context, "changed",
                         G_CALLBACK (style_context_changed), widget);
     }



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