After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 682291 - GtkMenuButton .ui issues
GtkMenuButton .ui issues
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2012-08-20 19:08 UTC by David Zeuthen (not reading bugmail)
Modified: 2012-09-01 03:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Minimal test program (4.59 KB, text/plain)
2012-08-20 19:08 UTC, David Zeuthen (not reading bugmail)
  Details
Proposed patch (2.77 KB, patch)
2012-08-21 16:51 UTC, David Zeuthen (not reading bugmail)
none Details | Review
untested patch (1.79 KB, patch)
2012-08-25 03:34 UTC, Matthias Clasen
none Details | Review
better patch, still untested (1.75 KB, patch)
2012-08-25 14:38 UTC, Matthias Clasen
none Details | Review
GtkMenuButton: Override add (1.79 KB, patch)
2012-09-01 03:02 UTC, Matthias Clasen
committed Details | Review
menubutton: make it work with custom content in .ui file (2.76 KB, patch)
2012-09-01 03:02 UTC, Matthias Clasen
committed Details | Review

Description David Zeuthen (not reading bugmail) 2012-08-20 19:08:59 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.
Comment 1 David Zeuthen (not reading bugmail) 2012-08-20 19:10:24 UTC
Bastien: IIRC you wrote this - any insights? Thanks!
Comment 2 David Zeuthen (not reading bugmail) 2012-08-20 20:49:14 UTC
(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>)
Comment 3 David Zeuthen (not reading bugmail) 2012-08-21 16:51:31 UTC
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!
Comment 4 David Zeuthen (not reading bugmail) 2012-08-22 18:27:08 UTC
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.
Comment 5 Matthias Clasen 2012-08-22 23:15:46 UTC
 (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.
Comment 6 Matthias Clasen 2012-08-25 03:34:23 UTC
Created attachment 222374 [details] [review]
untested patch
Comment 7 Matthias Clasen 2012-08-25 14:38:48 UTC
Created attachment 222398 [details] [review]
better patch, still untested
Comment 8 Matthias Clasen 2012-09-01 03:02:41 UTC
The following fixes have been pushed:
9e4b550 GtkMenuButton: Override add
6e6487b menubutton: make it work with custom content in .ui file
Comment 9 Matthias Clasen 2012-09-01 03:02:44 UTC
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.
Comment 10 Matthias Clasen 2012-09-01 03:02:47 UTC
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>