GNOME Bugzilla – Bug 169870
gtk_image_new_from_stock with an invalid stock id doesn't yield documented behavior
Last modified: 2005-04-11 04:31:22 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.
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)
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.
I can confirm that for example gaim and rhythmbox show a lot of "broken image" images with gtk+ 2.6.5. Please reopen bug.
Created attachment 39871 [details] [review] proposed patch It seems that we should use gtk_style_lookup_icon_set instead of gtk_stock_lookup.
Gnumeric is shot too.
Does using gtk_style_lookup_icon_set fix the problem for you ?
Ivan's patch fixes the problem for me, at least in GIMP.
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)
Works for me.