[gtk+] Ensure GtkWidget::style-updated is emitted before first size negociation



commit b7f772eb93e8615ebf14f5bdde33bc59dd0b11bf
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 25 00:31:46 2011 +0100

    Ensure GtkWidget::style-updated is emitted before first size negociation
    
    Fixes Bug 639584 - initial emission of GtkWidget:style-set is
    not happening.
    
    GtkWidget was filtering out ::style-updated (and ::style-set)
    emissions until the widget was realized in order to avoid often
    useless updates during widget construction and placing.
    
    This is now done instead until the widget has a parent/screen,
    which ensures the initial emission happen prior to the first
    size negociation, while still filtering out all early emissions
    during construction.

 gtk/gtkwidget.c |   57 ++++++++++++++++++++++++++++---------------------------
 1 files changed, 29 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 5ec6f44..427b3b7 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4389,7 +4389,10 @@ gtk_widget_realize (GtkWidget *widget)
       gtk_widget_ensure_style (widget);
 
       if (priv->style_update_pending)
-        g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
+        {
+          g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
+          priv->style_update_pending = FALSE;
+        }
 
       g_signal_emit (widget, widget_signals[REALIZE], 0);
 
@@ -6468,16 +6471,13 @@ gtk_widget_real_query_tooltip (GtkWidget  *widget,
 static void
 gtk_widget_real_style_updated (GtkWidget *widget)
 {
-  if (gtk_widget_get_realized (widget))
-    {
-      /* Trigger ::style-set for old
-       * widgets not listening to this
-       */
-      g_signal_emit (widget,
-                     widget_signals[STYLE_SET],
-                     0,
-                     widget->priv->style);
-    }
+  /* Trigger ::style-set for old
+   * widgets not listening to this
+   */
+  g_signal_emit (widget,
+                 widget_signals[STYLE_SET],
+                 0,
+                 widget->priv->style);
 
   if (widget->priv->context)
     {
@@ -7702,6 +7702,12 @@ gtk_widget_set_parent (GtkWidget *widget,
 
   gtk_widget_push_verify_invariants (widget);
 
+  if (!widget->priv->context)
+    {
+      /* Ensure the style context is there */
+      gtk_widget_get_style_context (widget);
+    }
+
   priv->parent = parent;
 
   parent_flags = gtk_widget_get_state_flags (parent);
@@ -7717,7 +7723,7 @@ gtk_widget_set_parent (GtkWidget *widget,
   data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
   gtk_widget_propagate_state (widget, &data);
 
-  gtk_widget_reset_rc_styles (widget);
+  gtk_widget_reset_style (widget);
 
   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
   if (priv->parent->priv->anchored)
@@ -7757,19 +7763,6 @@ gtk_widget_set_parent (GtkWidget *widget,
       gtk_widget_queue_compute_expand (parent);
     }
 
-  if (widget->priv->context)
-    {
-      GdkScreen *screen;
-
-      _gtk_widget_update_path (widget);
-      gtk_style_context_set_path (widget->priv->context, widget->priv->path);
-
-      screen = gtk_widget_get_screen (widget);
-
-      if (screen)
-        gtk_style_context_set_screen (widget->priv->context, screen);
-    }
-
   gtk_widget_pop_verify_invariants (widget);
 }
 
@@ -8720,9 +8713,16 @@ reset_style_recurse (GtkWidget *widget, gpointer data)
 {
   if (widget->priv->context)
     {
+      GdkScreen *screen;
+
       _gtk_widget_update_path (widget);
       gtk_style_context_set_path (widget->priv->context,
                                   widget->priv->path);
+
+      screen = gtk_widget_get_screen_unchecked (widget);
+
+      if (screen)
+        gtk_style_context_set_screen (widget->priv->context, screen);
     }
 
   if (GTK_IS_CONTAINER (widget))
@@ -14312,12 +14312,13 @@ style_context_changed (GtkStyleContext *context,
 
   gtk_widget_update_pango_context (widget);
 
-  if (gtk_widget_get_realized (widget))
+  if (widget->priv->parent &&
+      gtk_widget_get_screen_unchecked (widget))
     g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
-  else
+  else if (!gtk_widget_get_realized (widget))
     {
       /* Compress all style updates so it
-       * is only emitted once pre-realize.
+       * is emitted at least once pre-realize
        */
       widget->priv->style_update_pending = TRUE;
     }



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