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 169870 - gtk_image_new_from_stock with an invalid stock id doesn't yield documented behavior
gtk_image_new_from_stock with an invalid stock id doesn't yield documented be...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.6.x
Other All
: Normal blocker
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2005-03-10 19:15 UTC by Steven Walter
Modified: 2005-04-11 04:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (1.43 KB, patch)
2005-04-09 15:58 UTC, Ivan Wong
none Details | Review

Description Steven Walter 2005-03-10 19:15:46 UTC
Please describe the problem:
According to the documentation, when gtk_image_new_from_stock is passed a stock
id that doesn't exist, a "broken image" icon is shown in its place.  What
actually happens is that nothing appears where the GtkImage should be.  Either
the documentation is out of date and should be corrected, or the described
functionality should be implemented.

Steps to reproduce:
#include <gtk/gtk.h>
 
int main (int argc, char **argv) {
    GtkWidget *window;
    GtkWidget *image;
    GtkWidget *hbox;
 
    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    hbox = gtk_hbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), hbox);
     
    image = gtk_image_new_from_stock("gtk-yes", GTK_ICON_SIZE_DIALOG);
    gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
     
    image = gtk_image_new_from_stock("yes", GTK_ICON_SIZE_DIALOG);
    gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
 
    gtk_widget_show_all(window);
    gtk_main();
}


Actual results:
Only one image is shown, the GTK_STOCK_YES icon

Expected results:
Two images should be shown, the GTK_STOCK_YES and a broken icon indicator

Does this happen every time?
Yes

Other information:
This behavior is somewhat harmless in C, as the GTK_STOCK_YES, etc, macros will
cause a compile-time failure if they don't exist.  The Gtk2-Perl bindings,
however, where I initially discovered the problem, will silently fail at
run-time, which is most confusing.  If nothing else, gtk_image_new_from_stock
should return some indicator of failure if the stock ID doesn't exist.
Comment 1 Matthias Clasen 2005-04-09 02:52:00 UTC
2005-04-08  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkimage.c (gtk_image_expose, gtk_image_calc_size): 
	If a stock_id is unknown, display the missing image. (#169870,
	Steven Walter)

Comment 2 Roman Kagan 2005-04-09 14:49:54 UTC
The fix in the comment #1, which unfortunately sneaked in 2.6.5, breaks a lot of
apps.  The problem is that it checks if the image->data.stock.stock_id is found
by gtk_stock_lookup(), but there are stock icons other than those known to
gtk/gtkstock.c.

Please reconsider the resolution of this bug.
Comment 3 Jürg Billeter 2005-04-09 15:26:23 UTC
I can confirm that for example gaim and rhythmbox show a lot of "broken image"
images with gtk+ 2.6.5. Please reopen bug.
Comment 4 Ivan Wong 2005-04-09 15:58:40 UTC
Created attachment 39871 [details] [review]
proposed patch

It seems that we should use gtk_style_lookup_icon_set instead of
gtk_stock_lookup.
Comment 5 Morten Welinder 2005-04-09 19:14:22 UTC
Gnumeric is shot too.
Comment 6 Matthias Clasen 2005-04-09 21:28:15 UTC
Does using gtk_style_lookup_icon_set fix the problem for you ?
Comment 7 Manish Singh 2005-04-09 21:30:00 UTC
Ivan's patch fixes the problem for me, at least in GIMP.
Comment 8 Matthias Clasen 2005-04-09 21:53:58 UTC
2005-04-09  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtkimage.c (gtk_image_calc_size, gtk_image_expose): 
	Don't display too many broken images.  (#169870, Roman
	Kagan, patch by Ivan Wong)
Comment 9 Roman Kagan 2005-04-11 04:31:22 UTC
Works for me.