[gtk+] widget: Reshuffle code for style context getter



commit 963c0905f2f0e71c7d30f8e9f2b95455ab01ae5a
Author: Benjamin Otte <otte redhat com>
Date:   Sat Mar 26 16:07:54 2011 +0100

    widget: Reshuffle code for style context getter
    
    The intention of this patch is to make the code clearer, shorter and
    most of all to avoid recreating the widget path and setting it path
    twice on the style context when the style context was recreated.

 gtk/gtkwidget.c |   29 ++++++++++++++---------------
 1 files changed, 14 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f52ac29..03fde15 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -14330,15 +14330,23 @@ style_context_changed (GtkStyleContext *context,
 GtkStyleContext *
 gtk_widget_get_style_context (GtkWidget *widget)
 {
+  GtkWidgetPrivate *priv;
+  GtkWidgetPath *path;
+
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  if (G_UNLIKELY (!widget->priv->context))
+  priv = widget->priv;
+  
+  /* updates style context if it exists already */
+  path = gtk_widget_get_path (widget);
+
+  if (G_UNLIKELY (priv->context == NULL))
     {
       GdkScreen *screen;
 
-      widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
-                                            "direction", gtk_widget_get_direction (widget),
-                                            NULL);
+      priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
+                                    "direction", gtk_widget_get_direction (widget),
+                                    NULL);
 
       g_signal_connect (widget->priv->context, "changed",
                         G_CALLBACK (style_context_changed), widget);
@@ -14346,18 +14354,9 @@ gtk_widget_get_style_context (GtkWidget *widget)
       screen = gtk_widget_get_screen (widget);
 
       if (screen)
-        gtk_style_context_set_screen (widget->priv->context, screen);
+        gtk_style_context_set_screen (priv->context, screen);
 
-      _gtk_widget_update_path (widget);
-      gtk_style_context_set_path (widget->priv->context,
-                                  widget->priv->path);
-    }
-  else
-    {
-      /* Force widget path regeneration if needed, the
-       * context will be updated within this function.
-       */
-      gtk_widget_get_path (widget);
+      gtk_style_context_set_path (priv->context, path);
     }
 
   return widget->priv->context;



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