GNOME Bugzilla – Bug 682291
GtkMenuButton .ui issues
Last modified: 2012-09-01 03:02:47 UTC
Created attachment 221880 [details] Minimal test program The following .ui file XML <object class="GtkMenuButton" id="button1"> <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_action_appearance">False</property> <property name="menu">menu1</property> <child> <object class="GtkImage" id="image1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="stock">gtk-cdrom</property> </object> </child> </object> does not seem to have the desired effect - in fact, the following warning is printed (gtkmenubutton-test:753): Gtk-WARNING **: Attempting to add a widget with type GtkImage to a GtkMenuButton, but as a GtkBin subclass a GtkMenuButton can only contain one widget at a time; it already contains a widget of type GtkArrow This bug makes it hard to use GtkMenuButton without adding a hack in your application code. I've attached a minimal test program exhibiting the problem. I've seen this with 3.5.10 (specifically gtk3-3.5.10-1.fc18.x86_64), haven't tried master.
Bastien: IIRC you wrote this - any insights? Thanks!
(In reply to comment #0) > <object class="GtkMenuButton" id="button1"> > <property name="use_action_appearance">False</property> > <property name="visible">True</property> > <property name="can_focus">True</property> > <property name="receives_default">True</property> > <property name="use_action_appearance">False</property> > <property name="menu">menu1</property> > <child> > <object class="GtkImage" id="image1"> > <property name="visible">True</property> > <property name="can_focus">False</property> > <property name="stock">gtk-cdrom</property> > </object> > </child> > </object> Btw, this XML was obtained by using glade to create a button with GtkImage content, then s/GtkButton/GtkMenuButton/ and then adding the :menu property to point to the menu1 object. (Also, it would be great if glade was part of gtk+ and updated with new widgets as they are added here... </dreaming>)
Created attachment 222050 [details] [review] Proposed patch This patch fixes the problem for me if I also include this property in the .ui file <property name=\"direction\">GTK_ARROW_NONE</property> (I don't think there's any way to avoid that). Please review. Thanks!
Ping? Also: one thing I mentioned on IRC yesterday is that it's kinda broken the way things work now: for example, it's not unimaginable that a user wants his own custom icon and wants direction to be GTK_ARROW_UP - right now this is not possible to do without custom code (e.g. calling gtk_menu_button_set_direction() after loading the .ui file). How about adding a :show-arrow property for this? With this property, you'd do <object class="GtkMenuButton" id="button1"> <property name="use_action_appearance">False</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_action_appearance">False</property> <property name="menu">menu1</property> <property name="show-arrow">False</property> <property name="direction">GTK_ARROW_UP</property> <child> <object class="GtkImage" id="image1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="stock">gtk-cdrom</property> </object> </child> </object> and life would be good.
(gtkmenubutton-test:753): Gtk-WARNING **: Attempting to add a widget with type GtkImage to a GtkMenuButton, but as a GtkBin subclass a GtkMenuButton can only contain one widget at a time; it already contains a widget of type GtkArrow That error message comes out of the gtk_bin_add implementation. I think we can simply fix this by giving gtkmenubutton a custom add implementation that first checks if the current child is the arrow, and if it is, removes it, before chaining up.
Created attachment 222374 [details] [review] untested patch
Created attachment 222398 [details] [review] better patch, still untested
The following fixes have been pushed: 9e4b550 GtkMenuButton: Override add 6e6487b menubutton: make it work with custom content in .ui file
Created attachment 223119 [details] [review] GtkMenuButton: Override add By removing an existing child in add, if it is our own arrow, we can make things work better in GtkBuilder.
Created attachment 223120 [details] [review] menubutton: make it work with custom content in .ui file This was reported in bug 682291. https://bugzilla.gnome.org/show_bug.cgi?id=682291 Signed-off-by: David Zeuthen <zeuthen@gmail.com>