GNOME Bugzilla – Bug 566733
Add GIcon to GtkAction, GtkToolButton
Last modified: 2009-01-08 05:40:37 UTC
Following is a patch to do just that. This was mentioned as necessary in the email thread here: http://mail.gnome.org/archives/gtk-devel-list/2008-January/msg00056.html But it was not picked up for the 2.14 cycle. Incidentally had to add GIcon support to GtkToolButton as necessary for GtkAction.
Created attachment 125831 [details] [review] the patch
There is some aspects here that need to be thought through - This doesn't help for the ActionEntry apis we have. Not much that can be done there, though, and we already hack around this with the icon_name addition to GtkAction. - Something needs to be done about the several alternative ways to specify icons here. What happens if stock_id, icon_name and gicon are all specified ? The current code seems to prefer the stock_id over the icon name...
Created attachment 125897 [details] [review] v2 -) The icon entry code probably complicates things, but otherwise the same strategy should be usable in both cases. -) The GtkToolButton code has this to say on the subject: " if the tool button has an icon_widget, then that widget will be used as the icon. Otherwise, if the tool button has a stock id, the corresponding stock icon will be used. Otherwise, if the tool button has an icon name, the corresponding icon from the theme will be used. Otherwise, the tool button will not have an icon." Discarding the icon_widget part not applicable to GtkAction, similar priority is drawn for us. Stock ID has to have highest priority unless we had something like GtkStockIcon since the stock icons also have automatic labels and actions associated with them. Logically, it seems GIcon should come next, as we have GThemedIcon which provides the same functionality as icon-name but is more generic to include other icon sources.
Okay so apparently I was really asleep when I wrote my last comment last night, and didn't realize that the action (not icon...) entry structs were actually public and had no padding, so there really isn't anything at all to be done there that isn't terribly hackish. (For some reason I was thinking we could just tack on the GIcon and handle it the same way as the icon-name is passed around, not exactly sure how I came to that conclusion...) Pretty ugly situation to be in.
For now I have refrained from adding new api, and just added a GtkAction::gicon property. GtkToolButton is supported via its existing icon_widget api. * gtk/gtkaction.c: Add a ::gicon property to GtkAction and set the icon from it if specified. The stock icon is preferred if a stock id is given. Based on a patch by A. Walton