[gtk+/gtk-3-0] widget: Create the widget's style lazily



commit f285dd49b533c589e5d878e7978e353da4c57625
Author: Benjamin Otte <otte redhat com>
Date:   Sat Mar 26 23:33:39 2011 +0100

    widget: Create the widget's style lazily
    
    That way we don't have to update the style's colors all the time on
    theme changes when the widget is not actually using GtkStyle.

 gtk/gtkwidget.c |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 1f9c76d..a4fe908 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -7875,21 +7875,13 @@ gtk_widget_ensure_style (GtkWidget *widget)
 
   if (priv->style == gtk_widget_get_default_style ())
     {
-      GtkStyle *style;
-
       g_object_unref (priv->style);
 
-      style = g_object_new (GTK_TYPE_STYLE,
-                            "context", gtk_widget_get_style_context (widget),
-                            NULL);
-
-      priv->style = g_object_ref (style);
+      priv->style = NULL;
 
       g_signal_emit (widget,
                      widget_signals[STYLE_SET],
                      0, NULL);
-
-      g_object_unref (style);
     }
 }
 
@@ -7906,9 +7898,21 @@ gtk_widget_ensure_style (GtkWidget *widget)
 GtkStyle*
 gtk_widget_get_style (GtkWidget *widget)
 {
+  GtkWidgetPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
-  return widget->priv->style;
+  priv = widget->priv;
+
+  if (priv->style == NULL)
+    {
+      priv->style = g_object_new (GTK_TYPE_STYLE,
+                                  "context", gtk_widget_get_style_context (widget),
+                                  NULL);
+
+    }
+
+  return priv->style;
 }
 
 /**



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