Re: a bug in the GtkOptionMenu widget (GTK-1.2.6)




Eugene Osintsev <osgene@omskelecom.ru> writes:

> Hi, folks,
> 
> There is a bug in the GtkOptionMenu widget. I've found it in GTK-1.2.6
> but I think it's older.
> 
> When _first_ activated the GtkOptionMenu displays its popup GtkMenu not
> always properly. Maybe you noticed when the GtkOptionMenu was at the
> bottom of the screen its popup menu fell beneath the screen after the
> first click. After the second click it was already positioned correctly.
> 
> The problem is because of using allocation.width and allocation.height
> of the menu for its positioning. So before the first displaying the menu
> those fields are equal to their initial values (i.e. 1 and 1). I've
> patched the bug by getting requisitions (NOT allocations!) via
> gtk_widget_size_request (widget, &requisition). Please, look at diff
> attached.

Yes, this is approximately the right thing to do. I made the
equivalent fix for some of the other menu position functions in GTK+,
but missed the one for option menus.

> But, nevertheless, help me, friends, to understand why in
> gtk_option_menu_position() (and not only there) for getting sizes of
> widgets allocation.width and allocation.height are used.
> And what is more preferable in gtk_option_menu_position(): to use
> requisition fields directly or via gtk_widget_size_request()?

gtk_widget_size_request() actually causes the size of the menu
to be recalculated; you don't need to do this here, because
gtk_menu_position() is guaranteed to call gtk_widget_size_request()
before calling the menu position function.

So, you could just access the requisiton of the menu and the
menu items directly.

However, if you access the fields correctly, then you won't
correctly account for any calls to gtk_widget_set_usize(),
so the most correct thing to do is to call
gtk_widget_get_child_requisition(), which properly accounts
for the effect of set_usize(), but does not cause the size
to be recomputed.

I'm applying the following patch.

Thanks a lot for looking into the bug.

                                        Owen

Index: gtkoptionmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.c,v
retrieving revision 1.26.2.1
diff -u -r1.26.2.1 gtkoptionmenu.c
--- gtkoptionmenu.c	2000/01/21 23:22:50	1.26.2.1
+++ gtkoptionmenu.c	2000/01/26 02:23:40
@@ -616,6 +616,7 @@
   GtkOptionMenu *option_menu;
   GtkWidget *active;
   GtkWidget *child;
+  GtkRequisition requisition;
   GList *children;
   gint shift_menu;
   gint screen_width;
@@ -630,8 +631,9 @@
 
   option_menu = GTK_OPTION_MENU (user_data);
 
-  width = GTK_WIDGET (menu)->allocation.width;
-  height = GTK_WIDGET (menu)->allocation.height;
+  gtk_widget_get_child_requisition (GTK_WIDGET (menu), &requisition);
+  width = requisition.width;
+  height = requisition.height;
 
   active = gtk_menu_get_active (GTK_MENU (option_menu->menu));
   children = GTK_MENU_SHELL (option_menu->menu)->children;
@@ -640,7 +642,10 @@
   menu_ypos += GTK_WIDGET (option_menu)->allocation.height / 2 - 2;
 
   if (active != NULL)
-    menu_ypos -= active->requisition.height / 2;
+    {
+      gtk_widget_get_child_requisition (active, &requisition);
+      menu_ypos -= requisition.height / 2;
+    }
 
   while (children)
     {
@@ -650,7 +655,10 @@
 	break;
 
       if (GTK_WIDGET_VISIBLE (child))
-	menu_ypos -= child->allocation.height;
+	{
+	  gtk_widget_get_child_requisition (child, &requisition);
+	  menu_ypos -= requisition.height;
+	}
 
       children = children->next;
     }



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