[gimp/gtk3-port: 180/218] app: check whether child widgets exist in GtkWidget::style_updated()



commit f6a28b63a81d75fca53b4b56565a92ade41c01d7
Author: Michael Natterer <mitch gimp org>
Date:   Wed Dec 29 15:22:09 2010 +0100

    app: check whether child widgets exist in GtkWidget::style_updated()
    
    because it is emitted repeatedly during widget construction, when not
    everything is in place yet.

 app/display/gimpscalecombobox.c |   32 ++++++++++++---------
 app/display/gimpstatusbar.c     |   59 ++++++++++++++++++++++++--------------
 2 files changed, 55 insertions(+), 36 deletions(-)
---
diff --git a/app/display/gimpscalecombobox.c b/app/display/gimpscalecombobox.c
index ddf3cb2..9f19cd2 100644
--- a/app/display/gimpscalecombobox.c
+++ b/app/display/gimpscalecombobox.c
@@ -209,28 +209,32 @@ gimp_scale_combo_box_finalize (GObject *object)
 static void
 gimp_scale_combo_box_style_updated (GtkWidget *widget)
 {
-  GtkWidget            *entry;
-  PangoContext         *context;
-  PangoFontDescription *font_desc;
-  gint                  font_size;
-  gdouble               scale;
+  GtkWidget *entry;
 
   GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
 
-  gtk_widget_style_get (widget, "label-scale", &scale, NULL);
-
   entry = gtk_bin_get_child (GTK_BIN (widget));
 
-  context = gtk_widget_get_pango_context (entry);
-  font_desc = pango_context_get_font_description (context);
-  font_desc = pango_font_description_copy (font_desc);
+  if (entry)
+    {
+      PangoContext         *context;
+      PangoFontDescription *font_desc;
+      gint                  font_size;
+      gdouble               scale;
+
+      gtk_widget_style_get (widget, "label-scale", &scale, NULL);
 
-  font_size = pango_font_description_get_size (font_desc);
-  pango_font_description_set_size (font_desc, scale * font_size);
+      context = gtk_widget_get_pango_context (entry);
+      font_desc = pango_context_get_font_description (context);
+      font_desc = pango_font_description_copy (font_desc);
 
-  gtk_widget_override_font (entry, font_desc);
+      font_size = pango_font_description_get_size (font_desc);
+      pango_font_description_set_size (font_desc, scale * font_size);
 
-  pango_font_description_free (font_desc);
+      gtk_widget_override_font (entry, font_desc);
+
+      pango_font_description_free (font_desc);
+    }
 }
 
 static void
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index 8c3779b..97f6169 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -309,28 +309,43 @@ gimp_statusbar_hbox_style_updated (GtkWidget     *widget,
 
   /*  also consider the children which can be invisible  */
 
-  gtk_widget_get_preferred_size (statusbar->cursor_label,
-                                 &child_requisition, NULL);
-  width += child_requisition.width;
-  height = MAX (height, child_requisition.height);
-
-  gtk_widget_get_preferred_size (statusbar->unit_combo,
-                                 &child_requisition, NULL);
-  width += child_requisition.width;
-  height = MAX (height, child_requisition.height);
-
-  gtk_widget_get_preferred_size (statusbar->scale_combo,
-                                 &child_requisition, NULL);
-  width += child_requisition.width;
-  height = MAX (height, child_requisition.height);
-
-  gtk_widget_get_preferred_size (statusbar->progressbar,
-                                 &child_requisition, NULL);
-  height = MAX (height, child_requisition.height);
-
-  gtk_widget_get_preferred_size (statusbar->cancel_button,
-                                 &child_requisition, NULL);
-  height = MAX (height, child_requisition.height);
+  if (statusbar->cursor_label)
+    {
+      gtk_widget_get_preferred_size (statusbar->cursor_label,
+                                     &child_requisition, NULL);
+      width += child_requisition.width;
+      height = MAX (height, child_requisition.height);
+    }
+
+  if (statusbar->unit_combo)
+    {
+      gtk_widget_get_preferred_size (statusbar->unit_combo,
+                                     &child_requisition, NULL);
+      width += child_requisition.width;
+      height = MAX (height, child_requisition.height);
+    }
+
+  if (statusbar->scale_combo)
+    {
+      gtk_widget_get_preferred_size (statusbar->scale_combo,
+                                     &child_requisition, NULL);
+      width += child_requisition.width;
+      height = MAX (height, child_requisition.height);
+    }
+
+  if (statusbar->progressbar)
+    {
+      gtk_widget_get_preferred_size (statusbar->progressbar,
+                                     &child_requisition, NULL);
+      height = MAX (height, child_requisition.height);
+    }
+
+  if (statusbar->cancel_button)
+    {
+      gtk_widget_get_preferred_size (statusbar->cancel_button,
+                                     &child_requisition, NULL);
+      height = MAX (height, child_requisition.height);
+    }
 
   width = MAX (requisition.width, width + 32);
 



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