]> Pileus Git - ~andy/gtk/commitdiff
overlay: do not to set uninitialized values in the main allocation
authorCosimo Cecchi <cosimoc@gnome.org>
Wed, 29 Feb 2012 17:21:59 +0000 (12:21 -0500)
committerCosimo Cecchi <cosimoc@gnome.org>
Wed, 29 Feb 2012 17:26:02 +0000 (12:26 -0500)
gtk_widget_translate_coordinates() can fail in case the widget is not
realized or there's no common ancestor. Don't use the x/y values
returned by that method in that case, since their value is undefined.

gtk/gtkoverlay.c

index 331d9ee60063587edd45d55868947a4a94befbfd..e27384916d6680a318c33e3c00eb9ef8368abd87 100644 (file)
@@ -127,12 +127,22 @@ gtk_overlay_get_main_widget_allocation (GtkOverlay *overlay,
     {
       GtkWidget *grandchild;
       gint x, y;
+      gboolean res;
 
       grandchild = gtk_bin_get_child (GTK_BIN (main_widget));
       res = gtk_widget_translate_coordinates (grandchild, main_widget, 0, 0, &x, &y);
 
-      main_alloc.x = x;
-      main_alloc.y = y;
+      if (res)
+        {
+          main_alloc.x = x;
+          main_alloc.y = y;
+        }
+      else
+        {
+          main_alloc.x = 0;
+          main_alloc.y = 0;
+        }
+
       main_alloc.width = gtk_widget_get_allocated_width (grandchild);
       main_alloc.height = gtk_widget_get_allocated_height (grandchild);
     }