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



commit c60e36df8e84cd647acc167a35a789101b540f5f
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     |   71 ++++++++++++++++++++++++---------------
 2 files changed, 62 insertions(+), 41 deletions(-)
---
diff --git a/app/display/gimpscalecombobox.c b/app/display/gimpscalecombobox.c
index 80989fc..a880101 100644
--- a/app/display/gimpscalecombobox.c
+++ b/app/display/gimpscalecombobox.c
@@ -210,28 +210,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 f670853..d3f1c7e 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -370,33 +370,50 @@ 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->label,
-                                 &child_requisition, NULL);
-  requisition->height = MAX (requisition->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->label)
+    {
+      gtk_widget_get_preferred_size (statusbar->label,
+                                     &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]