]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkiconfactory.c
new file to build it all ... added to EXTRA_DIST
[~andy/gtk] / gtk / gtkiconfactory.c
index 64c57b33b52c54bf409f3b18cb8d6415b06108f3..55376d177b4cf80c8880180b87a8a15688e19deb 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <pango/pango-utils.h> /* For pango_scan_* */
 #include "gtkiconfactory.h"
 #include "stock-icons/gtkstockpixbufs.h"
+#include "gtkdebug.h"
+#include "gtkicontheme.h"
+#include "gtksettings.h"
 #include "gtkstock.h"
+#include "gtkwidget.h"
 #include "gtkintl.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <ctype.h>
-#include <string.h>
 
 static GSList *all_icon_factories = NULL;
 
+typedef enum {
+  GTK_ICON_SOURCE_EMPTY,
+  GTK_ICON_SOURCE_ICON_NAME,
+  GTK_ICON_SOURCE_FILENAME,
+  GTK_ICON_SOURCE_PIXBUF
+} GtkIconSourceType;
+
 struct _GtkIconSource
 {
-  /* Either filename or pixbuf can be NULL. If both are non-NULL,
-   * the pixbuf is assumed to be the already-loaded contents of the
-   * file.
-   */
-  gchar *filename;
-  GdkPixbuf *pixbuf;
+  GtkIconSourceType type;
+  
+  union {
+    gchar *icon_name;
+    gchar *filename;
+    GdkPixbuf *pixbuf;
+  } source;
+  
+  GdkPixbuf *filename_pixbuf;
 
   GtkTextDirection direction;
   GtkStateType state;
@@ -57,28 +71,35 @@ struct _GtkIconSource
   guint any_size : 1;
 };
 
-/* FIXME use a better icon for this */
-#define MISSING_IMAGE_INLINE dialog_error
-
 static gpointer parent_class = NULL;
 
 static void gtk_icon_factory_init       (GtkIconFactory      *icon_factory);
 static void gtk_icon_factory_class_init (GtkIconFactoryClass *klass);
 static void gtk_icon_factory_finalize   (GObject             *object);
 static void get_default_icons           (GtkIconFactory      *icon_factory);
+static void icon_source_clear           (GtkIconSource       *source);
+
+static GtkIconSize icon_size_register_intern (const gchar *name,
+                                             gint         width,
+                                             gint         height);
+
+#define GTK_ICON_SOURCE_INIT(any_direction, any_state, any_size)       \
+  { GTK_ICON_SOURCE_EMPTY, { NULL }, NULL,                             \
+   0, 0, 0,                                                            \
+   any_direction, any_state, any_size }
 
 GType
 gtk_icon_factory_get_type (void)
 {
-  static GType object_type = 0;
+  static GType icon_factory_type = 0;
 
-  if (!object_type)
+  if (!icon_factory_type)
     {
-      static const GTypeInfo object_info =
+      static const GTypeInfo icon_factory_info =
       {
         sizeof (GtkIconFactoryClass),
-        (GBaseInitFunc) NULL,
-        (GBaseFinalizeFunc) NULL,
+        NULL,          /* base_init */
+        NULL,          /* base_finalize */
         (GClassInitFunc) gtk_icon_factory_class_init,
         NULL,           /* class_finalize */
         NULL,           /* class_data */
@@ -87,12 +108,12 @@ gtk_icon_factory_get_type (void)
         (GInstanceInitFunc) gtk_icon_factory_init,
       };
       
-      object_type = g_type_register_static (G_TYPE_OBJECT,
-                                            "GtkIconFactory",
-                                            &object_info, 0);
+      icon_factory_type =
+       g_type_register_static (G_TYPE_OBJECT, "GtkIconFactory",
+                               &icon_factory_info, 0);
     }
   
-  return object_type;
+  return icon_factory_type;
 }
 
 static void
@@ -137,11 +158,11 @@ gtk_icon_factory_finalize (GObject *object)
  * gtk_icon_factory_new:
  *
  * Creates a new #GtkIconFactory. An icon factory manages a collection
- * of #GtkIconSet; a #GtkIconSet manages a set of variants of a
+ * of #GtkIconSet<!-- -->s; a #GtkIconSet manages a set of variants of a
  * particular icon (i.e. a #GtkIconSet contains variants for different
  * sizes and widget states). Icons in an icon factory are named by a
  * stock ID, which is a simple string identifying the icon. Each
- * #GtkStyle has a list of #GtkIconFactory derived from the current
+ * #GtkStyle has a list of #GtkIconFactory<!-- -->s derived from the current
  * theme; those icon factories are consulted first when searching for
  * an icon. If the theme doesn't set a particular icon, GTK+ looks for
  * the icon in a list of default icon factories, maintained by
@@ -155,7 +176,7 @@ gtk_icon_factory_finalize (GObject *object)
 GtkIconFactory*
 gtk_icon_factory_new (void)
 {
-  return GTK_ICON_FACTORY (g_object_new (GTK_TYPE_ICON_FACTORY, NULL));
+  return g_object_new (GTK_TYPE_ICON_FACTORY, NULL);
 }
 
 /**
@@ -249,7 +270,7 @@ gtk_icon_factory_add_default (GtkIconFactory *factory)
 {
   g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
 
-  g_object_ref (G_OBJECT (factory));
+  g_object_ref (factory);
   
   default_factories = g_slist_prepend (default_factories, factory);
 }
@@ -270,7 +291,7 @@ gtk_icon_factory_remove_default (GtkIconFactory  *factory)
 
   default_factories = g_slist_remove (default_factories, factory);
 
-  g_object_unref (G_OBJECT (factory));
+  g_object_unref (factory);
 }
 
 static void
@@ -322,131 +343,106 @@ gtk_icon_factory_lookup_default (const gchar *stock_id)
   return gtk_icon_factory_lookup (gtk_default_icons, stock_id);
 }
 
-static GtkIconSet *
-sized_icon_set_from_inline (const guchar *inline_data,
-                            GtkIconSize   size)
+static void
+register_stock_icon (GtkIconFactory *factory,
+                    const gchar    *stock_id)
 {
-  GtkIconSet *set;
-
-  GtkIconSource source = { NULL, NULL, 0, 0, 0,
-                           TRUE, TRUE, FALSE };
-
-  source.size = size;
-
-  set = gtk_icon_set_new ();
-
-  source.pixbuf = gdk_pixbuf_new_from_stream (-1, inline_data, FALSE, NULL);
-
-  g_assert (source.pixbuf);
+  GtkIconSet *set = gtk_icon_set_new ();
+  GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
 
+  source.type = GTK_ICON_SOURCE_ICON_NAME;
+  source.source.icon_name = (gchar *)stock_id;
   gtk_icon_set_add_source (set, &source);
-
-  g_object_unref (G_OBJECT (source.pixbuf));
   
-  return set;
+  gtk_icon_factory_add (factory, stock_id, set);
+  gtk_icon_set_unref (set);
 }
 
-
-static GtkIconSet *
-sized_with_fallback_icon_set_from_inline (const guchar *fallback_data,
-                                          const guchar *inline_data,
-                                          GtkIconSize   size)
+static void
+register_bidi_stock_icon (GtkIconFactory *factory,
+                         const gchar    *stock_id,
+                         const gchar    *stock_id_ltr,
+                         const gchar    *stock_id_rtl)
 {
-  GtkIconSet *set;
-
-  GtkIconSource source = { NULL, NULL, 0, 0, 0,
-                           TRUE, TRUE, FALSE };
-
-  source.size = size;
-
-  set = gtk_icon_set_new ();
-
-  source.pixbuf = gdk_pixbuf_new_from_stream (-1, inline_data, FALSE, NULL);
-
-  g_assert (source.pixbuf);
+  GtkIconSet *set = gtk_icon_set_new ();
+  GtkIconSource source = GTK_ICON_SOURCE_INIT (FALSE, TRUE, TRUE);
 
+  source.type = GTK_ICON_SOURCE_ICON_NAME;
+  source.source.icon_name = (gchar *)stock_id_ltr;
+  source.direction = GTK_TEXT_DIR_LTR;
   gtk_icon_set_add_source (set, &source);
-
-  g_object_unref (G_OBJECT (source.pixbuf));
   
-  source.any_size = TRUE;
-
-  source.pixbuf = gdk_pixbuf_new_from_stream (-1, fallback_data, FALSE, NULL);
-
-  g_assert (source.pixbuf);
-
+  source.type = GTK_ICON_SOURCE_ICON_NAME;
+  source.source.icon_name = (gchar *)stock_id_rtl;
+  source.direction = GTK_TEXT_DIR_RTL;
   gtk_icon_set_add_source (set, &source);
-
-  g_object_unref (G_OBJECT (source.pixbuf));  
   
-  return set;
+  gtk_icon_factory_add (factory, stock_id, set);
+  gtk_icon_set_unref (set);
 }
 
-static GtkIconSet *
-unsized_icon_set_from_inline (const guchar *inline_data)
+static void
+add_default_image (const gchar  *stock_id,
+                  gint          size,
+                  const guchar *inline_data)
 {
-  GtkIconSet *set;
+  GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL);
+  g_assert (pixbuf);
 
-  /* This icon can be used for any direction/state/size */
-  GtkIconSource source = { NULL, NULL, 0, 0, 0,
-                           TRUE, TRUE, TRUE };
-
-  set = gtk_icon_set_new ();
-
-  source.pixbuf = gdk_pixbuf_new_from_stream (-1, inline_data, FALSE, NULL);
-
-  g_assert (source.pixbuf);
-
-  gtk_icon_set_add_source (set, &source);
-
-  g_object_unref (G_OBJECT (source.pixbuf));
+  gtk_icon_theme_add_builtin_icon (stock_id, size, pixbuf);
   
-  return set;
+  g_object_unref (pixbuf);
 }
 
 static void
-add_sized (GtkIconFactory *factory,
-           const guchar   *inline_data,
-           GtkIconSize     size,
-           const gchar    *stock_id)
+add_icon (GtkIconFactory *factory,
+         const gchar    *stock_id,
+         gint            size,
+         const guchar   *inline_data)
 {
-  GtkIconSet *set;
-  
-  set = sized_icon_set_from_inline (inline_data, size);
-  
-  gtk_icon_factory_add (factory, stock_id, set);
+  register_stock_icon (factory, stock_id);
 
-  gtk_icon_set_unref (set);
+  add_default_image (stock_id, size, inline_data);
 }
 
 static void
-add_sized_with_fallback (GtkIconFactory *factory,
-                         const guchar   *fallback_data,
-                         const guchar   *inline_data,
-                         GtkIconSize     size,
-                         const gchar    *stock_id)
+add_icon2 (GtkIconFactory *factory,
+          const gchar    *stock_id,
+          gint            size1,
+          const guchar   *inline_data1,
+          gint            size2,
+          const guchar   *inline_data2)
 {
-  GtkIconSet *set;
+  register_stock_icon (factory, stock_id);
   
-  set = sized_with_fallback_icon_set_from_inline (fallback_data, inline_data, size);
-  
-  gtk_icon_factory_add (factory, stock_id, set);
-
-  gtk_icon_set_unref (set);
+  add_default_image (stock_id, size1, inline_data1);
+  add_default_image (stock_id, size2, inline_data2);
 }
 
 static void
-add_unsized (GtkIconFactory *factory,
-             const guchar   *inline_data,
-             const gchar    *stock_id)
+add_icon_bidi2 (GtkIconFactory *factory,
+               const gchar    *stock_id,
+               gint            size1,
+               const guchar   *inline_data_ltr1,
+               const guchar   *inline_data_rtl1,
+               gint            size2,
+               const guchar   *inline_data_ltr2,
+               const guchar   *inline_data_rtl2)
 {
-  GtkIconSet *set;
+  gchar *stock_id_ltr = g_strconcat (stock_id, "-ltr", NULL);
+  gchar *stock_id_rtl = g_strconcat (stock_id, "-rtl", NULL);
   
-  set = unsized_icon_set_from_inline (inline_data);
+  register_bidi_stock_icon (factory, stock_id,
+                           stock_id_ltr, stock_id_rtl);
   
-  gtk_icon_factory_add (factory, stock_id, set);
+  add_default_image (stock_id_ltr, size1, inline_data_ltr1);
+  add_default_image (stock_id_ltr, size2, inline_data_ltr2);
 
-  gtk_icon_set_unref (set);
+  add_default_image (stock_id_rtl, size1, inline_data_rtl1);
+  add_default_image (stock_id_rtl, size2, inline_data_rtl2);
+  
+  g_free (stock_id_ltr);
+  g_free (stock_id_rtl);
 }
 
 static void
@@ -454,111 +450,249 @@ get_default_icons (GtkIconFactory *factory)
 {
   /* KEEP IN SYNC with gtkstock.c */
 
-  add_unsized (factory, MISSING_IMAGE_INLINE, GTK_STOCK_MISSING_IMAGE);
-  
-  add_sized (factory, dialog_error, GTK_ICON_SIZE_DIALOG, GTK_STOCK_DIALOG_ERROR);
-  add_sized (factory, dialog_info, GTK_ICON_SIZE_DIALOG, GTK_STOCK_DIALOG_INFO);
-  add_sized (factory, dialog_question, GTK_ICON_SIZE_DIALOG, GTK_STOCK_DIALOG_QUESTION);
-  add_sized (factory, dialog_warning, GTK_ICON_SIZE_DIALOG, GTK_STOCK_DIALOG_WARNING);
+  /* Have dialog size */
+  add_icon (factory, GTK_STOCK_DIALOG_AUTHENTICATION, 48, stock_dialog_authentication_48);
+  add_icon (factory, GTK_STOCK_DIALOG_ERROR, 48, stock_dialog_error_48);
+  add_icon (factory, GTK_STOCK_DIALOG_INFO, 48, stock_dialog_info_48);
+  add_icon (factory, GTK_STOCK_DIALOG_QUESTION, 48, stock_dialog_question_48);
+  add_icon (factory, GTK_STOCK_DIALOG_WARNING, 48, stock_dialog_warning_48);
   
-  /* dnd size only */
-  add_sized (factory, stock_new, GTK_ICON_SIZE_DND, GTK_STOCK_DND);
-  add_sized (factory, stock_dnd_multiple, GTK_ICON_SIZE_DND, GTK_STOCK_DND_MULTIPLE);
+  /* Have dnd size */
+  add_icon (factory, GTK_STOCK_DND, 32, stock_dnd_32);
+  add_icon (factory, GTK_STOCK_DND_MULTIPLE, 32, stock_dnd_multiple_32);
   
-  /* Only have button sizes */
-  add_sized (factory, stock_button_apply, GTK_ICON_SIZE_BUTTON, GTK_STOCK_APPLY);
-  add_sized (factory, stock_button_cancel, GTK_ICON_SIZE_BUTTON, GTK_STOCK_CANCEL);
-  add_sized (factory, stock_button_no, GTK_ICON_SIZE_BUTTON, GTK_STOCK_NO);
-  add_sized (factory, stock_button_ok, GTK_ICON_SIZE_BUTTON, GTK_STOCK_OK);
-  add_sized (factory, stock_button_yes, GTK_ICON_SIZE_BUTTON, GTK_STOCK_YES);
+  /* Have button sizes */
+  add_icon (factory, GTK_STOCK_APPLY, 20, stock_apply_20);
+  add_icon (factory, GTK_STOCK_CANCEL, 20, stock_cancel_20);
+  add_icon (factory, GTK_STOCK_NO, 20, stock_no_20);
+  add_icon (factory, GTK_STOCK_OK, 20, stock_ok_20);
+  add_icon (factory, GTK_STOCK_YES, 20, stock_yes_20);
 
   /* Generic + button sizes */
-  add_sized_with_fallback (factory,
-                           stock_close,
-                           stock_button_close,
-                           GTK_ICON_SIZE_BUTTON,
-                           GTK_STOCK_CLOSE);
+  add_icon2 (factory, GTK_STOCK_CLOSE,
+            20, stock_close_20,
+            24, stock_close_24);
 
   /* Generic + menu sizes */  
+  add_icon2 (factory, GTK_STOCK_ADD,
+            16, stock_add_16,
+            24, stock_add_24);
+
+  add_icon2 (factory, GTK_STOCK_JUSTIFY_CENTER,
+            16, stock_align_center_16,
+            24, stock_align_center_24);
+
+  add_icon2 (factory, GTK_STOCK_JUSTIFY_FILL,
+            16, stock_align_justify_16,
+            24, stock_align_justify_24);
+
+  add_icon2 (factory, GTK_STOCK_JUSTIFY_LEFT,
+            16, stock_align_left_16,
+            24, stock_align_left_24);
+            
+  add_icon2 (factory, GTK_STOCK_JUSTIFY_RIGHT,
+            16, stock_align_right_16,
+            24, stock_align_right_24);
+
+  add_icon2 (factory, GTK_STOCK_GOTO_BOTTOM,
+            16, stock_bottom_16,
+            24, stock_bottom_24);
+            
+  add_icon2 (factory, GTK_STOCK_CDROM,
+            16, stock_cdrom_16,
+            24, stock_cdrom_24);
+
+  add_icon2 (factory, GTK_STOCK_CONVERT,
+            16, stock_convert_16,
+            24, stock_convert_24);
+
+  add_icon2 (factory, GTK_STOCK_COPY,
+            16, stock_copy_16,
+            24, stock_copy_24);
+
+  add_icon2 (factory, GTK_STOCK_CUT,
+            16, stock_cut_16,
+            24, stock_cut_24);
+
+  add_icon2 (factory, GTK_STOCK_GO_DOWN,
+            16, stock_down_arrow_16,
+            24, stock_down_arrow_24);
+
+  add_icon2 (factory, GTK_STOCK_EXECUTE,
+            16, stock_exec_16,
+            24, stock_exec_24);
+
+  add_icon2 (factory, GTK_STOCK_QUIT,
+            16, stock_exit_16,
+            24, stock_exit_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_GOTO_FIRST,
+                 16, stock_first_16, stock_last_16,
+                 24, stock_first_24, stock_last_24);
+
+  add_icon2 (factory, GTK_STOCK_SELECT_FONT,
+            16, stock_font_16,
+            24, stock_font_24);
+
+  add_icon2 (factory, GTK_STOCK_HELP,
+            16, stock_help_16,
+            24, stock_help_24);
+
+  add_icon2 (factory, GTK_STOCK_HOME,
+            16, stock_home_16,
+            24, stock_home_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_JUMP_TO,
+                 16, stock_jump_to_16, stock_jump_to_rtl_16,
+                 24, stock_jump_to_24, stock_jump_to_rtl_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_GOTO_LAST,
+                 16, stock_last_16, stock_first_16,
+                 24, stock_last_24, stock_first_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_GO_BACK,
+                 16, stock_left_arrow_16, stock_right_arrow_16,
+                 24, stock_left_arrow_24, stock_right_arrow_24);
+
+  add_icon2 (factory, GTK_STOCK_MISSING_IMAGE,
+            16, stock_missing_image_16,
+            24, stock_missing_image_24);
+
+  add_icon2 (factory, GTK_STOCK_NEW,
+            16, stock_new_16,
+            24, stock_new_24);
+
+  add_icon2 (factory, GTK_STOCK_OPEN,
+            16, stock_open_16,
+            24, stock_open_24);
+
+  add_icon2 (factory, GTK_STOCK_PASTE,
+            16, stock_paste_16,
+            24, stock_paste_24);
+
+  add_icon2 (factory, GTK_STOCK_PREFERENCES,
+            16, stock_preferences_16,
+            24, stock_preferences_24);
+
+  add_icon2 (factory, GTK_STOCK_PRINT,
+            16, stock_print_16,
+            24, stock_print_24);
+
+  add_icon2 (factory, GTK_STOCK_PRINT_PREVIEW,
+            16, stock_print_preview_16,
+            24, stock_print_preview_24);
+
+  add_icon2 (factory, GTK_STOCK_PROPERTIES,
+            16, stock_properties_16,
+            24, stock_properties_24);
+  
+  add_icon_bidi2 (factory, GTK_STOCK_REDO,
+                 16, stock_redo_16, stock_redo_rtl_16,
+                 24, stock_redo_24, stock_redo_rtl_24);
+
+  add_icon2 (factory, GTK_STOCK_REMOVE,
+            16, stock_remove_16,
+            24, stock_remove_24);
+
+  add_icon2 (factory, GTK_STOCK_REFRESH,
+            16, stock_refresh_16,
+            24, stock_refresh_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_REVERT_TO_SAVED,
+                 16, stock_revert_16, stock_revert_rtl_16,
+                 24, stock_revert_24, stock_revert_rtl_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_GO_FORWARD,
+                 16, stock_right_arrow_16, stock_left_arrow_16,
+                 24, stock_right_arrow_24, stock_left_arrow_24);
+
+  add_icon2 (factory, GTK_STOCK_SAVE,
+            16, stock_save_16,
+            24, stock_save_24);
+
+  add_icon2 (factory, GTK_STOCK_FLOPPY,
+            16, stock_save_16,
+            24, stock_save_24);
+
+  add_icon2 (factory, GTK_STOCK_SAVE_AS,
+            16, stock_save_as_16,
+            24, stock_save_as_24);
+
+  add_icon2 (factory, GTK_STOCK_FIND,
+            16, stock_search_16,
+            24, stock_search_24);
+
+  add_icon2 (factory, GTK_STOCK_FIND_AND_REPLACE,
+            16, stock_search_replace_16,
+            24, stock_search_replace_24);
+
+  add_icon2 (factory, GTK_STOCK_SORT_DESCENDING,
+            16, stock_sort_descending_16,
+            24, stock_sort_descending_24);
+
+  add_icon2 (factory, GTK_STOCK_SORT_ASCENDING,
+            16, stock_sort_ascending_16,
+            24, stock_sort_ascending_24);
+
+  add_icon2 (factory, GTK_STOCK_SPELL_CHECK,
+            16, stock_spellcheck_16,
+            24, stock_spellcheck_24);
 
-  add_sized_with_fallback (factory,
-                           stock_print_preview,
-                           stock_menu_print_preview,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_PRINT_PREVIEW);
-
-  add_sized_with_fallback (factory,
-                           stock_sort_descending,
-                           stock_menu_sort_descending,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_SORT_DESCENDING);
-  
-
-  add_sized_with_fallback (factory,
-                           stock_sort_ascending,
-                           stock_menu_sort_ascending,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_SORT_ASCENDING);
-  
-/* Generic size only */
-
-  add_unsized (factory, stock_add, GTK_STOCK_ADD);
-  add_unsized (factory, stock_align_center, GTK_STOCK_JUSTIFY_CENTER);
-  add_unsized (factory, stock_align_justify, GTK_STOCK_JUSTIFY_FILL);
-  add_unsized (factory, stock_align_left, GTK_STOCK_JUSTIFY_LEFT);
-  add_unsized (factory, stock_align_right, GTK_STOCK_JUSTIFY_RIGHT);
-  add_unsized (factory, stock_bottom, GTK_STOCK_GOTO_BOTTOM);  
-  add_unsized (factory, stock_cdrom, GTK_STOCK_CDROM);
-  add_unsized (factory, stock_clear, GTK_STOCK_CLEAR);
-  add_unsized (factory, stock_colorselector, GTK_STOCK_SELECT_COLOR);
-  add_unsized (factory, stock_convert, GTK_STOCK_CONVERT);
-  add_unsized (factory, stock_copy, GTK_STOCK_COPY);
-  add_unsized (factory, stock_cut, GTK_STOCK_CUT);
-  add_unsized (factory, stock_down_arrow, GTK_STOCK_GO_DOWN);
-  add_unsized (factory, stock_exec, GTK_STOCK_EXECUTE);
-  add_unsized (factory, stock_exit, GTK_STOCK_QUIT);
-  add_unsized (factory, stock_first, GTK_STOCK_GOTO_FIRST);
-  add_unsized (factory, stock_font, GTK_STOCK_SELECT_FONT);
-  add_unsized (factory, stock_help, GTK_STOCK_HELP);
-  add_unsized (factory, stock_home, GTK_STOCK_HOME);
-  add_unsized (factory, stock_index, GTK_STOCK_INDEX);
-  add_unsized (factory, stock_jump_to, GTK_STOCK_JUMP_TO);
-  add_unsized (factory, stock_last, GTK_STOCK_GOTO_LAST);
-  add_unsized (factory, stock_left_arrow, GTK_STOCK_GO_BACK);
-  add_unsized (factory, stock_new, GTK_STOCK_NEW);
-  add_unsized (factory, stock_open, GTK_STOCK_OPEN);
-  add_unsized (factory, stock_paste, GTK_STOCK_PASTE);
-  add_unsized (factory, stock_preferences, GTK_STOCK_PREFERENCES);
-  add_unsized (factory, stock_print, GTK_STOCK_PRINT);
-  add_unsized (factory, stock_properties, GTK_STOCK_PROPERTIES);
-  add_unsized (factory, stock_redo, GTK_STOCK_REDO);
-  add_unsized (factory, stock_refresh, GTK_STOCK_REFRESH);
-  add_unsized (factory, stock_remove, GTK_STOCK_REMOVE);
-  add_unsized (factory, stock_revert, GTK_STOCK_REVERT_TO_SAVED);
-  add_unsized (factory, stock_right_arrow, GTK_STOCK_GO_FORWARD);
-  add_unsized (factory, stock_save, GTK_STOCK_FLOPPY);
-  add_unsized (factory, stock_save, GTK_STOCK_SAVE);
-  add_unsized (factory, stock_save_as, GTK_STOCK_SAVE_AS);
-  add_unsized (factory, stock_search, GTK_STOCK_FIND);
-  add_unsized (factory, stock_search_replace, GTK_STOCK_FIND_AND_REPLACE);
-  add_unsized (factory, stock_spellcheck, GTK_STOCK_SPELL_CHECK);
-  add_unsized (factory, stock_stop, GTK_STOCK_STOP);
-  add_unsized (factory, stock_text_bold, GTK_STOCK_BOLD);
-  add_unsized (factory, stock_text_italic, GTK_STOCK_ITALIC);
-  add_unsized (factory, stock_text_strikeout, GTK_STOCK_STRIKETHROUGH);
-  add_unsized (factory, stock_text_underline, GTK_STOCK_UNDERLINE);
-  add_unsized (factory, stock_top, GTK_STOCK_GOTO_TOP);
-  add_unsized (factory, stock_trash, GTK_STOCK_DELETE);
-  add_unsized (factory, stock_undelete, GTK_STOCK_UNDELETE);
-  add_unsized (factory, stock_undo, GTK_STOCK_UNDO);
-  add_unsized (factory, stock_up_arrow, GTK_STOCK_GO_UP);
-  add_unsized (factory, stock_zoom_1, GTK_STOCK_ZOOM_100);
-  add_unsized (factory, stock_zoom_fit, GTK_STOCK_ZOOM_FIT);
-  add_unsized (factory, stock_zoom_in, GTK_STOCK_ZOOM_IN);
-  add_unsized (factory, stock_zoom_out, GTK_STOCK_ZOOM_OUT);
-}
-
-/* Sizes */
+  add_icon2 (factory, GTK_STOCK_STOP,
+            16, stock_stop_16,
+            24, stock_stop_24);
+
+  add_icon2 (factory, GTK_STOCK_BOLD,
+            16, stock_text_bold_16,
+            24, stock_text_bold_24);
+
+  add_icon2 (factory, GTK_STOCK_ITALIC,
+            16, stock_text_italic_16,
+            24, stock_text_italic_24);
+
+  add_icon2 (factory, GTK_STOCK_STRIKETHROUGH,
+            16, stock_text_strikethrough_16,
+            24, stock_text_strikethrough_24);
+
+  add_icon2 (factory, GTK_STOCK_UNDERLINE,
+            16, stock_text_underline_16,
+            24, stock_text_underline_24);
+
+  add_icon2 (factory, GTK_STOCK_GOTO_TOP,
+            16, stock_top_16,
+            24, stock_top_24);
+
+  add_icon2 (factory, GTK_STOCK_DELETE,
+            16, stock_trash_16,
+            24, stock_trash_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_UNDELETE,
+                 16, stock_undelete_16, stock_undelete_rtl_16,
+                 24, stock_undelete_24, stock_undelete_rtl_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_UNDO,
+                 16, stock_undo_16, stock_undo_rtl_16,
+                 24, stock_undo_24, stock_undo_rtl_24);
+
+  add_icon2 (factory, GTK_STOCK_GO_UP,
+            16, stock_up_arrow_16,
+            24, stock_up_arrow_24);
+
+  /* Generic size only */
+
+  add_icon (factory, GTK_STOCK_CLEAR, 24, stock_clear_24);
+  add_icon (factory, GTK_STOCK_SELECT_COLOR, 24, stock_colorselector_24);
+  add_icon (factory, GTK_STOCK_COLOR_PICKER, 25, stock_color_picker_25);
+  add_icon (factory, GTK_STOCK_INDEX, 24, stock_index_24);
+  add_icon (factory, GTK_STOCK_ZOOM_100, 24, stock_zoom_1_24);
+  add_icon (factory, GTK_STOCK_ZOOM_FIT, 24, stock_zoom_fit_24);
+  add_icon (factory, GTK_STOCK_ZOOM_IN, 24, stock_zoom_in_24);
+  add_icon (factory, GTK_STOCK_ZOOM_OUT, 24, stock_zoom_out_24);
+}
+
+/************************************************************
+ *                    Icon size handling                    *
+ ************************************************************/
 
 typedef struct _IconSize IconSize;
 
@@ -579,6 +713,14 @@ struct _IconAlias
   gint   target;
 };
 
+typedef struct _SettingsIconSize SettingsIconSize;
+
+struct _SettingsIconSize
+{
+  gint width;
+  gint height;
+};
+
 static GHashTable *icon_aliases = NULL;
 static IconSize *icon_sizes = NULL;
 static gint      icon_sizes_allocated = 0;
@@ -616,8 +758,8 @@ init_icon_sizes (void)
 
       icon_sizes[GTK_ICON_SIZE_BUTTON].size = GTK_ICON_SIZE_BUTTON;
       icon_sizes[GTK_ICON_SIZE_BUTTON].name = "gtk-button";
-      icon_sizes[GTK_ICON_SIZE_BUTTON].width = 24;
-      icon_sizes[GTK_ICON_SIZE_BUTTON].height = 24;
+      icon_sizes[GTK_ICON_SIZE_BUTTON].width = 20;
+      icon_sizes[GTK_ICON_SIZE_BUTTON].height = 20;
 
       icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].size = GTK_ICON_SIZE_SMALL_TOOLBAR;
       icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].name = "gtk-small-toolbar";
@@ -654,13 +796,295 @@ init_icon_sizes (void)
     }
 }
 
+static void
+free_settings_sizes (gpointer data)
+{
+  g_array_free (data, TRUE);
+}
+
+static GArray *
+get_settings_sizes (GtkSettings *settings,
+                   gboolean    *created)
+{
+  GArray *settings_sizes;
+  static GQuark sizes_quark = 0;
+
+  if (!sizes_quark)
+    sizes_quark = g_quark_from_static_string ("gtk-icon-sizes");
+
+  settings_sizes = g_object_get_qdata (G_OBJECT (settings), sizes_quark);
+  if (!settings_sizes)
+    {
+      settings_sizes = g_array_new (FALSE, FALSE, sizeof (SettingsIconSize));
+      g_object_set_qdata_full (G_OBJECT (settings), sizes_quark,
+                              settings_sizes, free_settings_sizes);
+      if (created)
+       *created = TRUE;
+    }
+
+  return settings_sizes;
+}
+
+static void
+icon_size_set_for_settings (GtkSettings *settings,
+                           const gchar *size_name,
+                           gint         width,
+                           gint         height)
+{
+  GtkIconSize size;
+  GArray *settings_sizes;
+  SettingsIconSize *settings_size;
+
+  g_return_if_fail (size_name != NULL);
+
+  size = gtk_icon_size_from_name (size_name);
+  if (size == GTK_ICON_SIZE_INVALID)
+    /* Reserve a place */
+    size = icon_size_register_intern (size_name, -1, -1);
+  
+  settings_sizes = get_settings_sizes (settings, NULL);
+  if (size >= settings_sizes->len)
+    {
+      SettingsIconSize unset = { -1, -1 };
+      gint i;
+
+      for (i = settings_sizes->len; i <= size; i++)
+       g_array_append_val (settings_sizes, unset);
+    }
+
+  settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
+  
+  settings_size->width = width;
+  settings_size->height = height;
+}
+
+/* Like pango_parse_word, but accept - as well
+ */
+static gboolean
+scan_icon_size_name (const char **pos, GString *out)
+{
+  const char *p = *pos;
+
+  while (g_ascii_isspace (*p))
+    p++;
+  
+  if (!((*p >= 'A' && *p <= 'Z') ||
+       (*p >= 'a' && *p <= 'z') ||
+       *p == '_' || *p == '-'))
+    return FALSE;
+
+  g_string_truncate (out, 0);
+  g_string_append_c (out, *p);
+  p++;
+
+  while ((*p >= 'A' && *p <= 'Z') ||
+        (*p >= 'a' && *p <= 'z') ||
+        (*p >= '0' && *p <= '9') ||
+        *p == '_' || *p == '-')
+    {
+      g_string_append_c (out, *p);
+      p++;
+    }
+
+  *pos = p;
+
+  return TRUE;
+}
+
+static void
+icon_size_setting_parse (GtkSettings *settings,
+                        const gchar *icon_size_string)
+{
+  GString *name_buf = g_string_new (NULL);
+  const gchar *p = icon_size_string;
+
+  while (pango_skip_space (&p))
+    {
+      gint width, height;
+      
+      if (!scan_icon_size_name (&p, name_buf))
+       goto err;
+
+      if (!pango_skip_space (&p))
+       goto err;
+
+      if (*p != '=')
+       goto err;
+
+      p++;
+
+      if (!pango_scan_int (&p, &width))
+       goto err;
+
+      if (!pango_skip_space (&p))
+       goto err;
+
+      if (*p != ',')
+       goto err;
+
+      p++;
+
+      if (!pango_scan_int (&p, &height))
+       goto err;
+
+      if (width > 0 && height > 0)
+       {
+         icon_size_set_for_settings (settings, name_buf->str,
+                                     width, height);
+       }
+      else
+       {
+         g_warning ("Invalid size in gtk-icon-sizes: %d,%d\n", width, height);
+       }
+
+      pango_skip_space (&p);
+      if (*p == '\0')
+       break;
+      if (*p == ':')
+       p++;
+      else
+       goto err;
+    }
+
+  g_string_free (name_buf, TRUE);
+  return;
+
+ err:
+  g_warning ("Error parsing gtk-icon-sizes string:\n\t'%s'", icon_size_string);
+  g_string_free (name_buf, TRUE);
+}
+
+static void
+icon_size_set_all_from_settings (GtkSettings *settings)
+{
+  GArray *settings_sizes;
+  gchar *icon_size_string;
+
+  /* Reset old settings */
+  settings_sizes = get_settings_sizes (settings, NULL);
+  g_array_set_size (settings_sizes, 0);
+
+  g_object_get (settings,
+               "gtk-icon-sizes", &icon_size_string,
+               NULL);
+
+  if (icon_size_string)
+    {
+      icon_size_setting_parse (settings, icon_size_string);
+      g_free (icon_size_string);
+    }
+}
+
+static void
+icon_size_settings_changed (GtkSettings  *settings,
+                           GParamSpec   *pspec)
+{
+  icon_size_set_all_from_settings (settings);
+
+  _gtk_rc_reset_styles (settings);
+}
+
+static void
+icon_sizes_init_for_settings (GtkSettings *settings)
+{
+  g_signal_connect (settings,
+                   "notify::gtk-icon-sizes",
+                   G_CALLBACK (icon_size_settings_changed),
+                   NULL);
+  
+  icon_size_set_all_from_settings (settings);
+}
+     
+static gboolean
+icon_size_lookup_intern (GtkSettings *settings,
+                        GtkIconSize  size,
+                        gint        *widthp,
+                        gint        *heightp)
+{
+  GArray *settings_sizes;
+  gint width_for_settings = -1;
+  gint height_for_settings = -1;
+  
+  init_icon_sizes ();
+
+  if (size >= icon_sizes_used)
+    return FALSE;
+
+  if (size == GTK_ICON_SIZE_INVALID)
+    return FALSE;
+
+  if (settings)
+    {
+      gboolean initial = FALSE;
+      
+      settings_sizes = get_settings_sizes (settings, &initial);
+      if (initial)
+       icon_sizes_init_for_settings (settings);
+  
+      if (size < settings_sizes->len)
+       {
+         SettingsIconSize *settings_size;
+         
+         settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
+         
+         width_for_settings = settings_size->width;
+         height_for_settings = settings_size->height;
+       }
+    }
+
+  if (widthp)
+    *widthp = width_for_settings >= 0 ? width_for_settings : icon_sizes[size].width;
+
+  if (heightp)
+    *heightp = height_for_settings >= 0 ? height_for_settings : icon_sizes[size].height;
+
+  return TRUE;
+}
+
+/**
+ * gtk_icon_size_lookup_for_settings:
+ * @settings: a #GtkSettings object, used to determine
+ *   which set of user preferences to used.
+ * @size: an icon size
+ * @width: location to store icon width
+ * @height: location to store icon height
+ *
+ * Obtains the pixel size of a semantic icon size, possibly
+ * modified by user preferences for a particular 
+ * #GtkSettings. Normally @size would be
+ * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc.  This function
+ * isn't normally needed, gtk_widget_render_icon() is the usual
+ * way to get an icon for rendering, then just look at the size of
+ * the rendered pixbuf. The rendered pixbuf may not even correspond to
+ * the width/height returned by gtk_icon_size_lookup(), because themes
+ * are free to render the pixbuf however they like, including changing
+ * the usual size.
+ * 
+ * Return value: %TRUE if @size was a valid size
+ *
+ * Since: 2.2
+ **/
+gboolean
+gtk_icon_size_lookup_for_settings (GtkSettings *settings,
+                                  GtkIconSize  size,
+                                  gint        *width,
+                                  gint        *height)
+{
+  g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
+
+  return icon_size_lookup_intern (settings, size, width, height);
+}
+
 /**
  * gtk_icon_size_lookup:
  * @size: an icon size
  * @width: location to store icon width
  * @height: location to store icon height
  *
- * Obtains the pixel size of a semantic icon size, normally @size would be
+ * Obtains the pixel size of a semantic icon size, possibly
+ * modified by user preferences for the default #GtkSettings.
+ * (See gtk_icon_size_lookup_for_settings().)
+ * Normally @size would be
  * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_BUTTON, etc.  This function
  * isn't normally needed, gtk_widget_render_icon() is the usual
  * way to get an icon for rendering, then just look at the size of
@@ -676,21 +1100,55 @@ gtk_icon_size_lookup (GtkIconSize  size,
                       gint        *widthp,
                       gint        *heightp)
 {
-  init_icon_sizes ();
+  GTK_NOTE (MULTIHEAD,
+           g_warning ("gtk_icon_size_lookup ()) is not multihead safe"));
 
-  if (size >= icon_sizes_used)
-    return FALSE;
+  return gtk_icon_size_lookup_for_settings (gtk_settings_get_default (),
+                                           size, widthp, heightp);
+}
 
-  if (size == GTK_ICON_SIZE_INVALID)
-    return FALSE;
+static GtkIconSize
+icon_size_register_intern (const gchar *name,
+                          gint         width,
+                          gint         height)
+{
+  IconAlias *old_alias;
+  GtkIconSize size;
   
-  if (widthp)
-    *widthp = icon_sizes[size].width;
+  init_icon_sizes ();
 
-  if (heightp)
-    *heightp = icon_sizes[size].height;
+  old_alias = g_hash_table_lookup (icon_aliases, name);
+  if (old_alias && icon_sizes[old_alias->target].width > 0)
+    {
+      g_warning ("Icon size name '%s' already exists", name);
+      return GTK_ICON_SIZE_INVALID;
+    }
 
-  return TRUE;
+  if (old_alias)
+    {
+      size = old_alias->target;
+    }
+  else
+    {
+      if (icon_sizes_used == icon_sizes_allocated)
+       {
+         icon_sizes_allocated *= 2;
+         icon_sizes = g_renew (IconSize, icon_sizes, icon_sizes_allocated);
+       }
+
+      size = icon_sizes_used++;
+
+      /* alias to self. */
+      gtk_icon_size_register_alias (name, size);
+
+      icon_sizes[size].size = size;
+      icon_sizes[size].name = g_strdup (name);
+    }
+
+  icon_sizes[size].width = width;
+  icon_sizes[size].height = height;
+
+  return size;
 }
 
 /**
@@ -714,26 +1172,7 @@ gtk_icon_size_register (const gchar *name,
   g_return_val_if_fail (width > 0, 0);
   g_return_val_if_fail (height > 0, 0);
   
-  init_icon_sizes ();
-
-  if (icon_sizes_used == icon_sizes_allocated)
-    {
-      icon_sizes_allocated *= 2;
-      icon_sizes = g_renew (IconSize, icon_sizes, icon_sizes_allocated);
-    }
-  
-  icon_sizes[icon_sizes_used].size = icon_sizes_used;
-  icon_sizes[icon_sizes_used].name = g_strdup (name);
-  icon_sizes[icon_sizes_used].width = width;
-  icon_sizes[icon_sizes_used].height = height;
-
-  /* alias to self. */
-  gtk_icon_size_register_alias (icon_sizes[icon_sizes_used].name,
-                                icon_sizes[icon_sizes_used].size);
-  
-  ++icon_sizes_used;
-
-  return icon_sizes_used - 1;
+  return icon_size_register_intern (name, width, height);
 }
 
 /**
@@ -756,19 +1195,38 @@ gtk_icon_size_register_alias (const gchar *alias,
 
   init_icon_sizes ();
 
-  if (g_hash_table_lookup (icon_aliases, alias))
-    g_warning ("gtk_icon_size_register_alias: Icon size name '%s' already exists", alias);
-
-  if (!gtk_icon_size_lookup (target, NULL, NULL))
+  if (!icon_size_lookup_intern (NULL, target, NULL, NULL))
     g_warning ("gtk_icon_size_register_alias: Icon size %d does not exist", target);
-  
-  ia = g_new (IconAlias, 1);
-  ia->name = g_strdup (alias);
-  ia->target = target;
 
-  g_hash_table_insert (icon_aliases, ia->name, ia);
+  ia = g_hash_table_lookup (icon_aliases, alias);
+  if (ia)
+    {
+      if (icon_sizes[ia->target].width > 0)
+       {
+         g_warning ("gtk_icon_size_register_alias: Icon size name '%s' already exists", alias);
+         return;
+       }
+
+      ia->target = target;
+    }
+
+  if (!ia)
+    {
+      ia = g_new (IconAlias, 1);
+      ia->name = g_strdup (alias);
+      ia->target = target;
+
+      g_hash_table_insert (icon_aliases, ia->name, ia);
+    }
 }
 
+/** 
+ * gtk_icon_size_from_name:
+ * @name: the name to look up.
+ * @returns: the icon size with the given name.
+ * 
+ * Looks up the icon size associated with @name.
+ **/
 GtkIconSize
 gtk_icon_size_from_name (const gchar *name)
 {
@@ -778,12 +1236,20 @@ gtk_icon_size_from_name (const gchar *name)
   
   ia = g_hash_table_lookup (icon_aliases, name);
 
-  if (ia)
+  if (ia && icon_sizes[ia->target].width > 0)
     return ia->target;
   else
     return GTK_ICON_SIZE_INVALID;
 }
 
+/**
+ * gtk_icon_size_get_name:
+ * @size: a #GtkIconSize.
+ * @returns: the name of the given icon size.
+ * 
+ * Gets the canonical name of the given icon size. The returned string 
+ * is statically allocated and should not be freed.
+ **/
 G_CONST_RETURN gchar*
 gtk_icon_size_get_name (GtkIconSize  size)
 {
@@ -793,13 +1259,11 @@ gtk_icon_size_get_name (GtkIconSize  size)
     return icon_sizes[size].name;
 }
 
+/************************************************************/
+
 /* Icon Set */
 
 
-/* Clear icon set contents, drop references to all contained
- * GdkPixbuf objects and forget all GtkIconSources. Used to
- * recycle an icon set.
- */
 static GdkPixbuf *find_in_cache     (GtkIconSet       *icon_set,
                                      GtkStyle         *style,
                                      GtkTextDirection  direction,
@@ -811,6 +1275,10 @@ static void       add_to_cache      (GtkIconSet       *icon_set,
                                      GtkStateType      state,
                                      GtkIconSize       size,
                                      GdkPixbuf        *pixbuf);
+/* Clear icon set contents, drop references to all contained
+ * GdkPixbuf objects and forget all GtkIconSources. Used to
+ * recycle an icon set.
+ */
 static void       clear_cache       (GtkIconSet       *icon_set,
                                      gboolean          style_detach);
 static GSList*    copy_cache        (GtkIconSet       *icon_set,
@@ -885,16 +1353,15 @@ gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf)
 {
   GtkIconSet *set;
 
-  GtkIconSource source = { NULL, NULL, 0, 0, 0,
-                           TRUE, TRUE, TRUE };
+  GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
 
   g_return_val_if_fail (pixbuf != NULL, NULL);
 
   set = gtk_icon_set_new ();
 
-  source.pixbuf = pixbuf;
-
+  gtk_icon_source_set_pixbuf (&source, pixbuf);
   gtk_icon_set_add_source (set, &source);
+  gtk_icon_source_set_pixbuf (&source, NULL);
   
   return set;
 }
@@ -902,11 +1369,11 @@ gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf)
 
 /**
  * gtk_icon_set_ref:
- * @icon_set: a #GtkIconSet
+ * @icon_set: a #GtkIconSet.
  * 
- * Increments the reference count on @icon_set
+ * Increments the reference count on @icon_set.
  * 
- * Return value: @icon_set is returned
+ * Return value: @icon_set.
  **/
 GtkIconSet*
 gtk_icon_set_ref (GtkIconSet *icon_set)
@@ -943,6 +1410,7 @@ gtk_icon_set_unref (GtkIconSet *icon_set)
 
           tmp_list = g_slist_next (tmp_list);
         }
+      g_slist_free (icon_set->sources);
 
       clear_cache (icon_set, TRUE);
 
@@ -950,6 +1418,19 @@ gtk_icon_set_unref (GtkIconSet *icon_set)
     }
 }
 
+GType
+gtk_icon_set_get_type (void)
+{
+  static GType our_type = 0;
+  
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static ("GtkIconSet",
+                                            (GBoxedCopyFunc) gtk_icon_set_ref,
+                                            (GBoxedFreeFunc) gtk_icon_set_unref);
+
+  return our_type;
+}
+
 /**
  * gtk_icon_set_copy:
  * @icon_set: a #GtkIconSet
@@ -984,29 +1465,39 @@ gtk_icon_set_copy (GtkIconSet *icon_set)
   return copy;
 }
 
-
 static gboolean
 sizes_equivalent (GtkIconSize lhs,
                   GtkIconSize rhs)
 {
+  /* We used to consider sizes equivalent if they were
+   * the same pixel size, but we don't have the GtkSettings
+   * here, so we can't do that. Plus, it's not clear that
+   * it is right... it was just a workaround for the fact
+   * that we register icons by logical size, not pixel size.
+   */
+#if 1
+  return lhs == rhs;
+#else  
+  
   gint r_w, r_h, l_w, l_h;
 
-  gtk_icon_size_lookup (rhs, &r_w, &r_h);
-  gtk_icon_size_lookup (lhs, &l_w, &l_h);
+  icon_size_lookup_intern (NULL, rhs, &r_w, &r_h);
+  icon_size_lookup_intern (NULL, lhs, &l_w, &l_h);
 
   return r_w == l_w && r_h == l_h;
+#endif
 }
 
-static GtkIconSource*
-find_and_prep_icon_source (GtkIconSet       *icon_set,
-                           GtkTextDirection  direction,
-                           GtkStateType      state,
-                           GtkIconSize       size)
+static GtkIconSource *
+find_best_matching_source (GtkIconSet       *icon_set,
+                          GtkTextDirection  direction,
+                          GtkStateType      state,
+                          GtkIconSize       size,
+                          GSList           *failed)
 {
   GtkIconSource *source;
   GSList *tmp_list;
-
-
+  
   /* We need to find the best icon source.  Direction matters more
    * than state, state matters more than size. icon_set->sources
    * is sorted according to wildness, so if we take the first
@@ -1025,57 +1516,175 @@ find_and_prep_icon_source (GtkIconSet       *icon_set,
           (s->any_state || (s->state == state)) &&
           (s->any_size || (sizes_equivalent (size, s->size))))
         {
-          source = s;
-          break;
-        }
-      
+         if (!g_slist_find (failed, s))
+           {
+             source = s;
+             break;
+           }
+       }
+         
       tmp_list = g_slist_next (tmp_list);
     }
 
-  if (source == NULL)
-    return NULL;
+  return source;
+}
   
-  if (source->pixbuf == NULL)
+static gboolean
+ensure_filename_pixbuf (GtkIconSet    *icon_set,
+                       GtkIconSource *source)
+{
+  if (source->filename_pixbuf == NULL)
     {
-      GError *error;
-      gchar *full;
+      GError *error = NULL;
       
-      g_assert (source->filename);
+      source->filename_pixbuf = gdk_pixbuf_new_from_file (source->source.filename, &error);
+      
+      if (source->filename_pixbuf == NULL)
+       {
+         /* Remove this icon source so we don't keep trying to
+          * load it.
+          */
+         g_warning (_("Error loading icon: %s"), error->message);
+         g_error_free (error);
+         
+         icon_set->sources = g_slist_remove (icon_set->sources, source);
+         
+         gtk_icon_source_free (source);
+
+         return FALSE;
+       }
+    }
+  
+  return TRUE;
+}
+static GdkPixbuf *
+render_icon_name_pixbuf (GtkIconSource    *icon_source,
+                        GtkStyle         *style,
+                        GtkTextDirection  direction,
+                        GtkStateType      state,
+                        GtkIconSize       size,
+                        GtkWidget         *widget,
+                        const char        *detail)
+{
+  GdkPixbuf *pixbuf;
+  GdkPixbuf *tmp_pixbuf;
+  GtkIconSource tmp_source;
+  GdkScreen *screen;
+  GtkIconTheme *icon_theme;
+  GtkSettings *settings;
+  gint width, height, pixel_size;
+  GError *error = NULL;
+  
+  if (widget && gtk_widget_has_screen (widget))
+    screen = gtk_widget_get_screen (widget);
+  else if (style->colormap)
+    screen = gdk_colormap_get_screen (style->colormap);
+  else
+    {
+      screen = gdk_screen_get_default ();
+      GTK_NOTE (MULTIHEAD,
+               g_warning ("Using the default screen for gtk_icon_source_render_icon()"));
+    }
 
-      if (g_path_is_absolute (source->filename))
-        full = g_strdup (source->filename);
-      else
-        full = gtk_rc_find_pixmap_in_path (NULL, source->filename);
+  icon_theme = gtk_icon_theme_get_for_screen (screen);
+  settings = gtk_settings_get_for_screen (screen);
+
+  if (!gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
+    {
+      g_warning ("Invalid icon size %d\n", size);
+      width = height = 24;
+    }
+
+  pixel_size = MIN (width, height);
 
-      error = NULL;
-      source->pixbuf = gdk_pixbuf_new_from_file (full, &error);
+  tmp_pixbuf = gtk_icon_theme_load_icon (icon_theme,
+                                        icon_source->source.icon_name,
+                                        pixel_size, 0,
+                                        &error);
 
-      g_free (full);
+  if (!tmp_pixbuf)
+    {
+      g_warning ("Error loading theme icon for stock: %s", error->message);
+      return NULL;
+    }
+  
+  tmp_source = *icon_source;
+  tmp_source.type = GTK_ICON_SOURCE_PIXBUF;
+  tmp_source.source.pixbuf = tmp_pixbuf;
+
+  pixbuf = gtk_style_render_icon (style, &tmp_source,
+                                 direction, state, -1,
+                                 widget, detail);
+
+  if (!pixbuf)
+    g_warning ("Failed to render icon");
+
+  g_object_unref (tmp_pixbuf);
+
+  return pixbuf;
+}
+
+static GdkPixbuf *
+find_and_render_icon_source (GtkIconSet       *icon_set,
+                            GtkStyle         *style,
+                            GtkTextDirection  direction,
+                            GtkStateType      state,
+                            GtkIconSize       size,
+                            GtkWidget         *widget,
+                            const char        *detail)
+{
+  GSList *failed = NULL;
+  GdkPixbuf *pixbuf = NULL;
+
+  /* We treat failure in two different ways:
+   *
+   *  A) If loading a source that specifies a filename fails,
+   *     we treat that as permanent, and remove the source
+   *     from the GtkIconSet. (in ensure_filename_pixbuf ()
+   *  B) If loading a themed icon fails, or scaling an icon
+   *     fails, we treat that as transient and will try
+   *     again next time the icon falls out of the cache
+   *     and we need to recreate it.
+   */
+  while (pixbuf == NULL)
+    {
+      GtkIconSource *source = find_best_matching_source (icon_set, direction, state, size, failed);
       
-      if (source->pixbuf == NULL)
-        {
-          /* Remove this icon source so we don't keep trying to
-           * load it.
-           */
-          g_warning (_("Error loading icon: %s"), error->message);
-          g_error_free (error);
-          
-          icon_set->sources = g_slist_remove (icon_set->sources, source);
-
-          gtk_icon_source_free (source);
-
-          /* Try to fall back to other sources */
-          if (icon_set->sources != NULL)
-            return find_and_prep_icon_source (icon_set,
-                                              direction,
-                                              state,
-                                              size);
-          else
-            return NULL;
-        }
+      if (source == NULL)
+       break;
+
+      switch (source->type)
+       {
+       case GTK_ICON_SOURCE_FILENAME:
+         if (!ensure_filename_pixbuf (icon_set, source))
+           break;
+         /* Fall through */
+       case GTK_ICON_SOURCE_PIXBUF:
+         pixbuf = gtk_style_render_icon (style, source,
+                                         direction, state, size,
+                                         widget, detail);
+         if (!pixbuf)
+           {
+             g_warning ("Failed to render icon");
+             failed = g_slist_prepend (failed, source);
+           }
+         break;
+       case GTK_ICON_SOURCE_ICON_NAME:
+         pixbuf = render_icon_name_pixbuf (source, style,
+                                           direction, state, size,
+                                           widget, detail);
+         if (!pixbuf)
+           failed = g_slist_prepend (failed, source);
+         break;
+       case GTK_ICON_SOURCE_EMPTY:
+         g_assert_not_reached ();
+       }
     }
 
-  return source;
+  g_slist_free (failed);
+
+  return pixbuf;
 }
 
 static GdkPixbuf*
@@ -1087,10 +1696,14 @@ render_fallback_image (GtkStyle          *style,
                        const char        *detail)
 {
   /* This icon can be used for any direction/state/size */
-  static GtkIconSource fallback_source = { NULL, NULL, 0, 0, 0, TRUE, TRUE, TRUE };
+  static GtkIconSource fallback_source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
 
-  if (fallback_source.pixbuf == NULL)
-    fallback_source.pixbuf = gdk_pixbuf_new_from_stream (-1, MISSING_IMAGE_INLINE, FALSE, NULL);
+  if (fallback_source.type == GTK_ICON_SOURCE_EMPTY)
+    {
+      GdkPixbuf *pixbuf = gdk_pixbuf_new_from_inline (-1, stock_missing_image_24, FALSE, NULL);
+      gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
+      g_object_unref (pixbuf);
+    }
   
   return gtk_style_render_icon (style,
                                 &fallback_source,
@@ -1108,8 +1721,12 @@ render_fallback_image (GtkStyle          *style,
  * @direction: text direction
  * @state: widget state
  * @size: icon size
- * @widget: widget that will display the icon, or %NULL
- * @detail: detail to pass to the theme engine, or %NULL
+ * @widget: widget that will display the icon, or %NULL.
+ *          The only use that is typically made of this
+ *          is to determine the appropriate #GdkScreen.
+ * @detail: detail to pass to the theme engine, or %NULL.
+ *          Note that passing a detail of anything but %NULL
+ *          will disable caching.
  * 
  * Renders an icon using gtk_style_render_icon(). In most cases,
  * gtk_widget_render_icon() is better, since it automatically provides
@@ -1130,46 +1747,34 @@ gtk_icon_set_render_icon (GtkIconSet        *icon_set,
                           const char        *detail)
 {
   GdkPixbuf *icon;
-  GtkIconSource *source;
   
   g_return_val_if_fail (icon_set != NULL, NULL);
   g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
 
   if (icon_set->sources == NULL)
     return render_fallback_image (style, direction, state, size, widget, detail);
-  
-  icon = find_in_cache (icon_set, style, direction,
-                        state, size);
 
-  if (icon)
+  if (detail == NULL)
     {
-      g_object_ref (G_OBJECT (icon));
-      return icon;
+      icon = find_in_cache (icon_set, style, direction,
+                        state, size);
+      
+      if (icon)
+       {
+         g_object_ref (icon);
+         return icon;
+       }
     }
 
-  
-  source = find_and_prep_icon_source (icon_set, direction, state, size);
 
-  if (source == NULL)
-    return render_fallback_image (style, direction, state, size, widget, detail);
-
-  g_assert (source->pixbuf != NULL);
-  
-  icon = gtk_style_render_icon (style,
-                                source,
-                                direction,
-                                state,
-                                size,
-                                widget,
-                                detail);
+  icon = find_and_render_icon_source (icon_set, style, direction, state, size,
+                                     widget, detail);
 
   if (icon == NULL)
-    {
-      g_warning ("Theme engine failed to render icon");
-      return NULL;
-    }
-  
-  add_to_cache (icon_set, style, direction, state, size, icon);
+    icon = render_fallback_image (style, direction, state, size, widget, detail);
+
+  if (detail == NULL)
+    add_to_cache (icon_set, style, direction, state, size, icon);
   
   return icon;
 }
@@ -1240,10 +1845,9 @@ gtk_icon_set_add_source (GtkIconSet *icon_set,
   g_return_if_fail (icon_set != NULL);
   g_return_if_fail (source != NULL);
 
-  if (source->pixbuf == NULL &&
-      source->filename == NULL)
+  if (source->type == GTK_ICON_SOURCE_EMPTY)
     {
-      g_warning ("Useless GtkIconSource contains NULL filename and pixbuf");
+      g_warning ("Useless empty GtkIconSource");
       return;
     }
   
@@ -1301,12 +1905,12 @@ gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
       init_icon_sizes ();
       
       *sizes = g_new (GtkIconSize, icon_sizes_used);
-      *n_sizes = icon_sizes_used;
+      *n_sizes = icon_sizes_used - 1;
       
-      i = 0;      
+      i = 1;      
       while (i < icon_sizes_used)
         {
-          (*sizes)[i] = icon_sizes[i].size;
+          (*sizes)[i - 1] = icon_sizes[i].size;
           ++i;
         }
     }
@@ -1403,10 +2007,24 @@ gtk_icon_source_copy (const GtkIconSource *source)
 
   *copy = *source;
   
-  copy->filename = g_strdup (source->filename);
-  copy->size = source->size;
-  if (copy->pixbuf)
-    g_object_ref (G_OBJECT (copy->pixbuf));
+  switch (copy->type)
+    {
+    case GTK_ICON_SOURCE_EMPTY:
+      break;
+    case GTK_ICON_SOURCE_ICON_NAME:
+      copy->source.icon_name = g_strdup (copy->source.icon_name);
+      break;
+    case GTK_ICON_SOURCE_FILENAME:
+      copy->source.filename = g_strdup (copy->source.filename);
+      if (copy->filename_pixbuf)
+       g_object_ref (copy->filename_pixbuf);
+      break;
+    case GTK_ICON_SOURCE_PIXBUF:
+      g_object_ref (copy->source.pixbuf);
+      break;
+    default:
+      g_assert_not_reached();
+    }
 
   return copy;
 }
@@ -1423,39 +2041,104 @@ gtk_icon_source_free (GtkIconSource *source)
 {
   g_return_if_fail (source != NULL);
 
-  g_free ((char*) source->filename);
-  if (source->pixbuf)
-    g_object_unref (G_OBJECT (source->pixbuf));
-
+  icon_source_clear (source);
   g_free (source);
 }
 
+GType
+gtk_icon_source_get_type (void)
+{
+  static GType our_type = 0;
+  
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static ("GtkIconSource",
+                                            (GBoxedCopyFunc) gtk_icon_source_copy,
+                                            (GBoxedFreeFunc) gtk_icon_source_free);
+
+  return our_type;
+}
+
+static void
+icon_source_clear (GtkIconSource *source)
+{
+  switch (source->type)
+    {
+    case GTK_ICON_SOURCE_EMPTY:
+      break;
+    case GTK_ICON_SOURCE_ICON_NAME:
+      g_free (source->source.icon_name);
+      source->source.icon_name = NULL;
+      break;
+    case GTK_ICON_SOURCE_FILENAME:
+      g_free (source->source.filename);
+      source->source.filename = NULL;
+      g_free (source->filename_pixbuf);
+      source->filename_pixbuf = NULL;
+      break;
+    case GTK_ICON_SOURCE_PIXBUF:
+      g_object_unref (source->source.pixbuf);
+      source->source.pixbuf = NULL;
+      break;
+    default:
+      g_assert_not_reached();
+    }
+
+  source->type = GTK_ICON_SOURCE_EMPTY;
+}
+
 /**
  * gtk_icon_source_set_filename:
  * @source: a #GtkIconSource
  * @filename: image file to use
  *
- * Sets the name of an image file to use as a base image when creating icon
- * variants for #GtkIconSet. If the filename is absolute, GTK+ will
- * attempt to open the exact file given. If the filename is relative,
- * GTK+ will search for it in the "pixmap path" which can be configured
- * by users in their gtkrc files or specified as part of a theme's gtkrc
- * file. See #GtkRcStyle for information on gtkrc files.
- * 
+ * Sets the name of an image file to use as a base image when creating
+ * icon variants for #GtkIconSet. The filename must be absolute. 
  **/
 void
-gtk_icon_source_set_filename             (GtkIconSource *source,
-                                          const gchar   *filename)
+gtk_icon_source_set_filename (GtkIconSource *source,
+                             const gchar   *filename)
 {
   g_return_if_fail (source != NULL);
+  g_return_if_fail (filename == NULL || g_path_is_absolute (filename));
 
-  if (source->filename == filename)
+  if (source->type == GTK_ICON_SOURCE_FILENAME &&
+      source->source.filename == filename)
     return;
   
-  if (source->filename)
-    g_free (source->filename);
+  icon_source_clear (source);
+  
+  if (filename != NULL)
+    {
+      source->type = GTK_ICON_SOURCE_FILENAME;
+      source->source.filename = g_strdup (filename);
+    }
+}
 
-  source->filename = g_strdup (filename);  
+/**
+ * gtk_icon_source_set_icon_name
+ * @source: a #GtkIconSource
+ * @icon_name: name of icon to use
+ *
+ * Sets the name of an icon to look up in the current icon theme
+ * to use as a base image when creating icon variants for #GtkIconSet.
+ **/
+void
+gtk_icon_source_set_icon_name (GtkIconSource *source,
+                              const gchar   *icon_name)
+{
+  g_return_if_fail (source != NULL);
+
+  if (source->type == GTK_ICON_SOURCE_ICON_NAME &&
+      source->source.icon_name == icon_name)
+    return;
+
+  icon_source_clear (source);
+  
+  if (icon_name != NULL)
+    {
+      source->type = GTK_ICON_SOURCE_ICON_NAME;
+      source->source.icon_name = g_strdup (icon_name);
+    }
 }
 
 /**
@@ -1464,41 +2147,69 @@ gtk_icon_source_set_filename             (GtkIconSource *source,
  * @pixbuf: pixbuf to use as a source
  *
  * Sets a pixbuf to use as a base image when creating icon variants
- * for #GtkIconSet. If an icon source has both a filename and a pixbuf
- * set, the pixbuf will take priority.
- * 
+ * for #GtkIconSet.
  **/
 void
 gtk_icon_source_set_pixbuf (GtkIconSource *source,
                             GdkPixbuf     *pixbuf)
 {
   g_return_if_fail (source != NULL);
+  g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
+  
+  if (source->type == GTK_ICON_SOURCE_PIXBUF &&
+      source->source.pixbuf == pixbuf)
+    return;
 
-  if (pixbuf)
-    g_object_ref (G_OBJECT (pixbuf));
-
-  if (source->pixbuf)
-    g_object_unref (G_OBJECT (source->pixbuf));
-
-  source->pixbuf = pixbuf;
+  icon_source_clear (source);
+  
+  if (pixbuf != NULL)
+    {
+      source->type = GTK_ICON_SOURCE_PIXBUF;
+      source->source.pixbuf = g_object_ref (pixbuf);
+    }
 }
 
 /**
  * gtk_icon_source_get_filename:
  * @source: a #GtkIconSource
  * 
- * Retrieves the source filename, or %NULL if none is set.  The
+ * Retrieves the source filename, or %NULL if none is set. The
  * filename is not a copy, and should not be modified or expected to
  * persist beyond the lifetime of the icon source.
  * 
- * Return value: image filename
+ * Return value: image filename. This string must not be modified
+ * or freed.
  **/
 G_CONST_RETURN gchar*
 gtk_icon_source_get_filename (const GtkIconSource *source)
 {
   g_return_val_if_fail (source != NULL, NULL);
-  
-  return source->filename;
+
+  if (source->type == GTK_ICON_SOURCE_FILENAME)
+    return source->source.filename;
+  else
+    return NULL;
+}
+
+/**
+ * gtk_icon_source_get_icon_name:
+ * @source: a #GtkIconSource
+ * 
+ * Retrieves the source icon name, or %NULL if none is set. The
+ * icon_name is not a copy, and should not be modified or expected to
+ * persist beyond the lifetime of the icon source.
+ * 
+ * Return value: icon name. This string must not be modified or freed.
+ **/
+G_CONST_RETURN gchar*
+gtk_icon_source_get_icon_name (const GtkIconSource *source)
+{
+  g_return_val_if_fail (source != NULL, NULL);
+
+  if (source->type == GTK_ICON_SOURCE_ICON_NAME)
+    return source->source.icon_name;
+  else
+    return NULL;
 }
 
 /**
@@ -1506,7 +2217,12 @@ gtk_icon_source_get_filename (const GtkIconSource *source)
  * @source: a #GtkIconSource
  * 
  * Retrieves the source pixbuf, or %NULL if none is set.
- * The reference count on the pixbuf is not incremented.
+ * In addition, if a filename source is in use, this
+ * function in some cases will return the pixbuf from
+ * loaded from the filename. This is, for example, true
+ * for the GtkIconSource passed to the GtkStyle::render_icon()
+ * virtual function. The reference count on the pixbuf is
+ * not incremented.
  * 
  * Return value: source pixbuf
  **/
@@ -1515,7 +2231,12 @@ gtk_icon_source_get_pixbuf (const GtkIconSource *source)
 {
   g_return_val_if_fail (source != NULL, NULL);
   
-  return source->pixbuf;
+  if (source->type == GTK_ICON_SOURCE_PIXBUF)
+    return source->source.pixbuf;
+  else if (source->type == GTK_ICON_SOURCE_FILENAME)
+    return source->filename_pixbuf;
+  else
+    return NULL;
 }
 
 /**
@@ -1721,7 +2442,7 @@ gtk_icon_source_set_size (GtkIconSource *source,
  * @source: a #GtkIconSource
  * 
  * Obtains the text direction this icon source applies to. The return
- * value is only useful/meaningful if the text direction is NOT
+ * value is only useful/meaningful if the text direction is <emphasis>not</emphasis> 
  * wildcarded.
  * 
  * Return value: text direction this source matches
@@ -1739,7 +2460,7 @@ gtk_icon_source_get_direction (const GtkIconSource *source)
  * @source: a #GtkIconSource
  * 
  * Obtains the widget state this icon source applies to. The return
- * value is only useful/meaningful if the widget state is NOT
+ * value is only useful/meaningful if the widget state is <emphasis>not</emphasis>
  * wildcarded.
  * 
  * Return value: widget state this source matches
@@ -1757,7 +2478,7 @@ gtk_icon_source_get_state (const GtkIconSource *source)
  * @source: a #GtkIconSource
  * 
  * Obtains the icon size this source applies to. The return value
- * is only useful/meaningful if the icon size is NOT wildcarded.
+ * is only useful/meaningful if the icon size is <emphasis>not</emphasis> wildcarded.
  * 
  * Return value: icon size this source matches.
  **/
@@ -1769,9 +2490,6 @@ gtk_icon_source_get_size (const GtkIconSource *source)
   return source->size;
 }
 
-/* Note that the logical maximum is 20 per GtkTextDirection, so we could
- * eventually set this to >20 to never throw anything out.
- */
 #define NUM_CACHED_ICONS 8
 
 typedef struct _CachedIcon CachedIcon;
@@ -1793,13 +2511,16 @@ static void
 ensure_cache_up_to_date (GtkIconSet *icon_set)
 {
   if (icon_set->cache_serial != cache_serial)
-    clear_cache (icon_set, TRUE);
+    {
+      clear_cache (icon_set, TRUE);
+      icon_set->cache_serial = cache_serial;
+    }
 }
 
 static void
 cached_icon_free (CachedIcon *icon)
 {
-  g_object_unref (G_OBJECT (icon->pixbuf));
+  g_object_unref (icon->pixbuf);
 
   g_free (icon);
 }
@@ -1857,7 +2578,7 @@ add_to_cache (GtkIconSet      *icon_set,
 
   ensure_cache_up_to_date (icon_set);
   
-  g_object_ref (G_OBJECT (pixbuf));
+  g_object_ref (pixbuf);
 
   /* We have to ref the style, since if the style was finalized
    * its address could be reused by another style, creating a
@@ -1865,7 +2586,7 @@ add_to_cache (GtkIconSet      *icon_set,
    */
   
   if (style)
-    g_object_ref (G_OBJECT (style));
+    g_object_ref (style);
   
 
   icon = g_new (CachedIcon, 1);
@@ -1963,7 +2684,7 @@ copy_cache (GtkIconSet *icon_set,
       if (icon_copy->style)
         attach_to_style (copy_recipient, icon_copy->style);
         
-      g_object_ref (G_OBJECT (icon_copy->pixbuf));
+      g_object_ref (icon_copy->pixbuf);
 
       icon_copy->size = icon->size;