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 557720 - Make GtkButton _set_label and _set_image virtual
Make GtkButton _set_label and _set_image virtual
Status: RESOLVED WONTFIX
Product: gtk+
Classification: Platform
Component: Widget: GtkButton
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2008-10-24 10:00 UTC by Christian Dywan
Modified: 2015-03-07 21:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Implement GtkButton _label and _image virtually (6.14 KB, patch)
2008-10-24 11:33 UTC, Christian Dywan
none Details | Review
Virtual GtkButton _label and _image, option 1 (6.81 KB, patch)
2008-10-28 12:47 UTC, Christian Dywan
none Details | Review
Virtual GtkButton _label and _image, option 1, test (6.75 KB, text/plain)
2008-10-28 12:48 UTC, Christian Dywan
  Details
Virtual GtkButton _label and _image, option 2 (9.18 KB, patch)
2008-10-28 12:51 UTC, Christian Dywan
none Details | Review
Virtual GtkButton _label and _image, option 2, test (6.41 KB, text/plain)
2008-10-28 12:53 UTC, Christian Dywan
  Details

Description Christian Dywan 2008-10-24 10:00:25 UTC
Subclassing GtkButton is a common case, but the way _set_label and _set_image are implemented means that you often end up either breaking those accessors if your subclass has its own packing or your packing breaks as soon as these accessors are used. Consequently you want to be able to verride these functions to refer to your actual implementation.

I propose set_label, get_label, set_image and get_image should be virtual functions in GtkButtonClass.

I will come up with a patch in a bit.
Comment 1 Christian Dywan 2008-10-24 11:33:29 UTC
Created attachment 121261 [details] [review]
Implement GtkButton _label and _image virtually
Comment 2 Christian Persch 2008-10-24 12:11:57 UTC
+ GTK_BUTTON_CLASS (gtk_button_parent_class)->...

Shouldn't these be GTK_BUTTON_GET_CLASS (button)->... instead ?
Comment 3 Matthias Clasen 2008-10-26 02:16:42 UTC
I have to admit that I personally never subclassed GtkButton.
Some examples would be nice...
Comment 4 Emmanuele Bassi (:ebassi) 2008-10-26 11:09:17 UTC
straight from gtk+ itself: GtkColorButton, GtkFontButton and GtkFileChooserButton.
Comment 5 Emmanuele Bassi (:ebassi) 2008-10-26 11:10:28 UTC
well, strike GtkFileChooserButton from the list, as it is a GtkHBox.
Comment 6 Christian Dywan 2008-10-26 21:34:36 UTC
You can also find examples for instance in Hildon widgets, which are used on the Maemo platform.

At this point I'm actually not sure if the virtual _get_label should work with a string, or rather a label widget, which would make it possible to apply a little bit of "magic" regarding mnemonic and stock items. One thing that is currently hard to do in subclasses is imitating the different accessors and it should be nice if (almost) all of them could work out of the box. I'm going to post an improved patch and an alternative implementation soon, together with example code.
Comment 7 Christian Dywan 2008-10-28 12:47:23 UTC
Created attachment 121515 [details] [review]
Virtual GtkButton _label and _image, option 1

This is an improved version of the former patch, that actually works.

This is option 1, as in obtaining a label string from the subclass.
Comment 8 Christian Dywan 2008-10-28 12:48:55 UTC
Created attachment 121516 [details]
Virtual GtkButton _label and _image, option 1, test

A test program for option 1. It helped me verifying that regular buttons, strangely packed buttons and a demo subclass worked as intended.
Comment 9 Christian Dywan 2008-10-28 12:51:50 UTC
Created attachment 121517 [details] [review]
Virtual GtkButton _label and _image, option 2

This is option 2, as in obtaining a label *widget* from the subclass, based on the assumption that subclasses usually create a widget, but just pack it differently. This allows for accesors like _set_use_underline to be implemented in Gtk without the subclass having to imitate it.
Comment 10 Christian Dywan 2008-10-28 12:53:55 UTC
Created attachment 121518 [details]
Virtual GtkButton _label and _image, option 2, test

A test program for option *2*. It helped me verifying that regular buttons,
strangely packed buttons and a demo subclass worked as intended. Basically it's a slightly modified version of the other test program since the API is different.
Comment 11 Alberto Garcia 2009-09-21 10:39:19 UTC
(In reply to comment #6)
> You can also find examples for instance in Hildon widgets, which are
> used on the Maemo platform.

Yes, in Hildon 2.2 we have HildonPickerButton, which is a button with
two labels. Since we create an internal custom layout we can't use
gtk_button_{get,set}_label() and that makes the API a bit uglier.