]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkiconfactory.c
treeview: remove extra padding handling
[~andy/gtk] / gtk / gtkiconfactory.c
index 5d7cef187124fe605a018cb7f2434f5deda7c1df..b40267335b0a78c0a1ec613de399e2a2422de375 100644 (file)
@@ -1,6 +1,6 @@
 /* GTK - The GIMP Toolkit
  * Copyright (C) 2000 Red Hat, Inc.
- *
+ *               2008 Johan Dahlin
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
  */
 
-#include <pango/pango-utils.h> /* For pango_scan_* */
+#include "config.h"
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
 #include "gtkiconfactory.h"
-#include "stock-icons/gtkstockpixbufs.h"
+#include "gtkiconcache.h"
 #include "gtkdebug.h"
-#include "gtksettings.h"
+#include "gtkicontheme.h"
+#include "gtksettingsprivate.h"
 #include "gtkstock.h"
+#include "gtkwidget.h"
 #include "gtkintl.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
+#include "gtkbuildable.h"
+#include "gtkbuilderprivate.h"
+#include "gtktypebuiltins.h"
+#include "deprecated/gtkstyle.h"
+
+
+/**
+ * SECTION:gtkiconfactory
+ * @Short_description: Manipulating stock icons
+ * @Title: Themeable Stock Images
+ *
+ * Browse the available stock icons in the list of stock IDs found <link
+ * linkend="gtk-Stock-Items">here</link>. You can also use
+ * the <application>gtk-demo</application> application for this purpose.
+ *
+ * An icon factory manages a collection of #GtkIconSet; 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 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 gtk_icon_factory_add_default() and
+ * gtk_icon_factory_remove_default(). Applications with icons should add a default
+ * icon factory with their icons, which will allow themes to override the icons
+ * for the application.
+ *
+ * To display an icon, always use gtk_style_lookup_icon_set() on the widget that
+ * will display the icon, or the convenience function
+ * gtk_widget_render_icon(). These functions take the theme into account when
+ * looking up the icon to use for a given stock ID.
+ *
+ * <refsect2 id="GtkIconFactory-BUILDER-UI">
+ * <title>GtkIconFactory as GtkBuildable</title>
+ * <para>
+ * GtkIconFactory supports a custom &lt;sources&gt; element, which can contain
+ * multiple &lt;source&gt; elements.
+ * The following attributes are allowed:
+ * <variablelist>
+ * <varlistentry>
+ * <term>stock-id</term>
+ * <listitem><para>
+ * The stock id of the source, a string.
+ * This attribute is mandatory
+ * </para></listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>filename</term>
+ * <listitem><para>
+ * The filename of the source, a string.
+ * This attribute is optional
+ * </para></listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>icon-name</term>
+ * <listitem><para>
+ * The icon name for the source, a string.
+ * This attribute is optional.
+ * </para></listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>size</term>
+ * <listitem><para>
+ * Size of the icon, a #GtkIconSize enum value.
+ * This attribute is optional.
+ * </para></listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>direction</term>
+ * <listitem><para>
+ * Direction of the source, a #GtkTextDirection enum value.
+ * This attribute is optional.
+ * </para></listitem>
+ * </varlistentry>
+ * <varlistentry>
+ * <term>state</term>
+ * <listitem><para>
+ * State of the source, a #GtkStateType enum value.
+ * This attribute is optional.
+ * </para></listitem>
+ * </varlistentry>
+ * </variablelist>
+ * <example>
+ * <title>A #GtkIconFactory UI definition fragment.</title>
+ * <programlisting><![CDATA[
+ * <object class="GtkIconFactory" id="iconfactory1">
+ *   <sources>
+ *     <source stock-id="apple-red" filename="apple-red.png"/>
+ *   </sources>
+ * </object>
+ * <object class="GtkWindow" id="window1">
+ *   <child>
+ *     <object class="GtkButton" id="apple_button">
+ *       <property name="label">apple-red</property>
+ *       <property name="use-stock">True</property>
+ *     </object>
+ *   </child>
+ * </object>
+ * ]]>
+ * </programlisting>
+ * </example>
+ * </para>
+ * </refsect2>
+ */
+
 
 static GSList *all_icon_factories = NULL;
 
+struct _GtkIconFactoryPrivate
+{
+  GHashTable *icons;
+};
+
+typedef enum {
+  GTK_ICON_SOURCE_EMPTY,
+  GTK_ICON_SOURCE_ICON_NAME,
+  GTK_ICON_SOURCE_STATIC_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;
@@ -59,49 +182,49 @@ struct _GtkIconSource
   guint any_size : 1;
 };
 
-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_buildable_init  (GtkBuildableIface      *iface);
+
+static gboolean gtk_icon_factory_buildable_custom_tag_start (GtkBuildable     *buildable,
+                                                            GtkBuilder       *builder,
+                                                            GObject          *child,
+                                                            const gchar      *tagname,
+                                                            GMarkupParser    *parser,
+                                                            gpointer         *data);
+static void gtk_icon_factory_buildable_custom_tag_end (GtkBuildable *buildable,
+                                                      GtkBuilder   *builder,
+                                                      GObject      *child,
+                                                      const gchar  *tagname,
+                                                      gpointer     *user_data);
 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);
 
-GType
-gtk_icon_factory_get_type (void)
-{
-  static GType object_type = 0;
+#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 }
 
-  if (!object_type)
-    {
-      static const GTypeInfo object_info =
-      {
-        sizeof (GtkIconFactoryClass),
-        (GBaseInitFunc) NULL,
-        (GBaseFinalizeFunc) NULL,
-        (GClassInitFunc) gtk_icon_factory_class_init,
-        NULL,           /* class_finalize */
-        NULL,           /* class_data */
-        sizeof (GtkIconFactory),
-        0,              /* n_preallocs */
-        (GInstanceInitFunc) gtk_icon_factory_init,
-      };
-      
-      object_type = g_type_register_static (G_TYPE_OBJECT,
-                                            "GtkIconFactory",
-                                            &object_info, 0);
-    }
-  
-  return object_type;
-}
+G_DEFINE_TYPE_WITH_CODE (GtkIconFactory, gtk_icon_factory, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_icon_factory_buildable_init))
 
 static void
 gtk_icon_factory_init (GtkIconFactory *factory)
 {
-  factory->icons = g_hash_table_new (g_str_hash, g_str_equal);
+  GtkIconFactoryPrivate *priv;
+
+  factory->priv = G_TYPE_INSTANCE_GET_PRIVATE (factory,
+                                               GTK_TYPE_ICON_FACTORY,
+                                               GtkIconFactoryPrivate);
+  priv = factory->priv;
+
+  priv->icons = g_hash_table_new (g_str_hash, g_str_equal);
   all_icon_factories = g_slist_prepend (all_icon_factories, factory);
 }
 
@@ -109,10 +232,17 @@ static void
 gtk_icon_factory_class_init (GtkIconFactoryClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
-  parent_class = g_type_class_peek_parent (klass);
 
   object_class->finalize = gtk_icon_factory_finalize;
+
+  g_type_class_add_private (klass, sizeof (GtkIconFactoryPrivate));
+}
+
+static void
+gtk_icon_factory_buildable_init (GtkBuildableIface *iface)
+{
+  iface->custom_tag_start = gtk_icon_factory_buildable_custom_tag_start;
+  iface->custom_tag_end = gtk_icon_factory_buildable_custom_tag_end;
 }
 
 static void
@@ -126,14 +256,15 @@ static void
 gtk_icon_factory_finalize (GObject *object)
 {
   GtkIconFactory *factory = GTK_ICON_FACTORY (object);
+  GtkIconFactoryPrivate *priv = factory->priv;
 
   all_icon_factories = g_slist_remove (all_icon_factories, factory);
-  
-  g_hash_table_foreach (factory->icons, free_icon_set, NULL);
-  
-  g_hash_table_destroy (factory->icons);
-  
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+
+  g_hash_table_foreach (priv->icons, free_icon_set, NULL);
+
+  g_hash_table_destroy (priv->icons);
+
+  G_OBJECT_CLASS (gtk_icon_factory_parent_class)->finalize (object);
 }
 
 /**
@@ -152,13 +283,13 @@ gtk_icon_factory_finalize (GObject *object)
  * gtk_icon_factory_remove_default(). Applications with icons should
  * add a default icon factory with their icons, which will allow
  * themes to override the icons for the application.
- * 
+ *
  * Return value: a new #GtkIconFactory
- **/
+ */
 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);
 }
 
 /**
@@ -177,33 +308,33 @@ gtk_icon_factory_new (void)
  * override your application's default icons. If an icon already
  * existed in @factory for @stock_id, it is unreferenced and replaced
  * with the new @icon_set.
- * 
- **/
+ */
 void
 gtk_icon_factory_add (GtkIconFactory *factory,
                       const gchar    *stock_id,
                       GtkIconSet     *icon_set)
 {
+  GtkIconFactoryPrivate *priv = factory->priv;
   gpointer old_key = NULL;
   gpointer old_value = NULL;
 
   g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
   g_return_if_fail (stock_id != NULL);
-  g_return_if_fail (icon_set != NULL);  
+  g_return_if_fail (icon_set != NULL);
 
-  g_hash_table_lookup_extended (factory->icons, stock_id,
+  g_hash_table_lookup_extended (priv->icons, stock_id,
                                 &old_key, &old_value);
 
   if (old_value == icon_set)
     return;
-  
+
   gtk_icon_set_ref (icon_set);
 
   /* GHashTable key memory management is so fantastically broken. */
   if (old_key)
-    g_hash_table_insert (factory->icons, old_key, icon_set);
+    g_hash_table_insert (priv->icons, old_key, icon_set);
   else
-    g_hash_table_insert (factory->icons, g_strdup (stock_id), icon_set);
+    g_hash_table_insert (priv->icons, g_strdup (stock_id), icon_set);
 
   if (old_value)
     gtk_icon_set_unref (old_value);
@@ -213,47 +344,49 @@ gtk_icon_factory_add (GtkIconFactory *factory,
  * gtk_icon_factory_lookup:
  * @factory: a #GtkIconFactory
  * @stock_id: an icon name
- * 
+ *
  * Looks up @stock_id in the icon factory, returning an icon set
  * if found, otherwise %NULL. For display to the user, you should
  * use gtk_style_lookup_icon_set() on the #GtkStyle for the
  * widget that will display the icon, instead of using this
  * function directly, so that themes are taken into account.
- * 
- * Return value: icon set of @stock_id.
- **/
+ *
+ * Return value: (transfer none): icon set of @stock_id.
+ */
 GtkIconSet *
 gtk_icon_factory_lookup (GtkIconFactory *factory,
                          const gchar    *stock_id)
 {
+  GtkIconFactoryPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_ICON_FACTORY (factory), NULL);
   g_return_val_if_fail (stock_id != NULL, NULL);
-  
-  return g_hash_table_lookup (factory->icons, stock_id);
+
+  priv = factory->priv;
+
+  return g_hash_table_lookup (priv->icons, stock_id);
 }
 
-static GtkIconFactory *gtk_default_icons = NULL;
 static GSList *default_factories = NULL;
 
 /**
  * gtk_icon_factory_add_default:
  * @factory: a #GtkIconFactory
- * 
+ *
  * Adds an icon factory to the list of icon factories searched by
  * gtk_style_lookup_icon_set(). This means that, for example,
  * gtk_image_new_from_stock() will be able to find icons in @factory.
  * There will normally be an icon factory added for each library or
  * application that comes with icons. The default icon factories
  * can be overridden by themes.
- * 
- **/
+ */
 void
 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);
 }
 
@@ -264,8 +397,7 @@ gtk_icon_factory_add_default (GtkIconFactory *factory)
  * Removes an icon factory from the list of default icon
  * factories. Not normally used; you might use it for a library that
  * can be unloaded or shut down.
- * 
- **/
+ */
 void
 gtk_icon_factory_remove_default (GtkIconFactory  *factory)
 {
@@ -273,18 +405,35 @@ 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
-ensure_default_icons (void)
+static GtkIconFactory *
+_gtk_icon_factory_get_default_icons (void)
 {
-  if (gtk_default_icons == NULL)
-    {
-      gtk_default_icons = gtk_icon_factory_new ();
+  static GtkIconFactory *default_icons = NULL;
+  GtkIconFactory *icons = NULL;
+  GdkScreen *screen = gdk_screen_get_default ();
+
+  if (screen)
+    icons = g_object_get_data (G_OBJECT (screen), "gtk-default-icons");
 
-      get_default_icons (gtk_default_icons);
+  if (icons == NULL)
+    {
+      if (default_icons == NULL)
+        {
+          default_icons = gtk_icon_factory_new ();
+          get_default_icons (default_icons);
+        }
+      if (screen)
+        g_object_set_data_full (G_OBJECT (screen),
+                                I_("gtk-default-icons"),
+                                default_icons,
+                                g_object_unref);
+      icons = default_icons;
     }
+
+  return icons;
 }
 
 /**
@@ -296,17 +445,17 @@ ensure_default_icons (void)
  * the #GtkStyle for the widget that will display the icon, instead of
  * using this function directly, so that themes are taken into
  * account.
- * 
- * 
- * Return value: a #GtkIconSet, or %NULL
- **/
+ *
+ * Return value: (transfer none): a #GtkIconSet, or %NULL
+ */
 GtkIconSet *
 gtk_icon_factory_lookup_default (const gchar *stock_id)
 {
   GSList *tmp_list;
+  GtkIconFactory *default_icons;
 
   g_return_val_if_fail (stock_id != NULL, NULL);
-  
+
   tmp_list = default_factories;
   while (tmp_list != NULL)
     {
@@ -316,166 +465,53 @@ gtk_icon_factory_lookup_default (const gchar *stock_id)
 
       if (icon_set)
         return icon_set;
-      
+
       tmp_list = g_slist_next (tmp_list);
     }
 
-  ensure_default_icons ();
-  
-  return gtk_icon_factory_lookup (gtk_default_icons, stock_id);
+  default_icons = _gtk_icon_factory_get_default_icons ();
+  if (default_icons)
+    return gtk_icon_factory_lookup (default_icons, stock_id);
+  else
+    return NULL;
 }
 
 static void
-add_source (GtkIconSet    *set,
-           GtkIconSource *source,
-           const gchar   *inline_data)
-{
-  source->pixbuf = gdk_pixbuf_new_from_inline (-1, inline_data, FALSE, NULL);
-  g_assert (source->pixbuf);
-
-  gtk_icon_set_add_source (set, source);
-
-  g_object_unref (G_OBJECT (source->pixbuf));
-}
-
-#if 0
-static GtkIconSet *
-sized_icon_set_from_inline (const guchar *inline_data,
-                            GtkIconSize   size)
-{
-  GtkIconSet *set;
-
-  GtkIconSource source = { NULL, NULL, 0, 0, 0,
-                           TRUE, TRUE, FALSE };
-
-  source.size = size;
-
-  set = gtk_icon_set_new ();
-
-  add_source (set, source, inline_data);
-  
-  return set;
-}
-#endif
-
-static GtkIconSet *
-sized_with_fallback_icon_set_from_inline (const guchar *fallback_data_ltr,
-                                          const guchar *fallback_data_rtl,
-                                          const guchar *inline_data_ltr,
-                                          const guchar *inline_data_rtl,
-                                          GtkIconSize   size)
-{
-  GtkIconSet *set;
-
-  GtkIconSource source = { NULL, NULL, 0, 0, 0,
-                           TRUE, TRUE, FALSE };
-
-  set = gtk_icon_set_new ();
-
-  source.size = size;
-  source.any_direction = inline_data_rtl == NULL;
-  
-  source.direction = GTK_TEXT_DIR_LTR;
-  add_source (set, &source, inline_data_ltr);
-  
-  if (inline_data_rtl != NULL)
-    {
-      source.direction = GTK_TEXT_DIR_RTL;
-      add_source (set, &source, inline_data_rtl);
-    }
-  
-  source.any_size = TRUE;
-  source.any_direction = fallback_data_rtl == NULL;
-
-  source.direction = GTK_TEXT_DIR_LTR;
-  add_source (set, &source, fallback_data_ltr);
-    
-  if (fallback_data_rtl != NULL)
-    {
-      source.direction = GTK_TEXT_DIR_RTL;
-      add_source (set, &source, fallback_data_rtl);
-    }
-  
-  return set;
-}
-
-static GtkIconSet *
-unsized_icon_set_from_inline (const guchar *inline_data)
+register_stock_icon (GtkIconFactory *factory,
+                    const gchar    *stock_id,
+                     const gchar    *icon_name)
 {
-  GtkIconSet *set;
-
-  /* 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 ();
+  GtkIconSet *set = gtk_icon_set_new ();
+  GtkIconSource source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
 
-  add_source (set, &source, inline_data);
-  
-  return set;
-}
+  source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
+  source.source.icon_name = (gchar *)icon_name;
+  source.direction = GTK_TEXT_DIR_NONE;
+  gtk_icon_set_add_source (set, &source);
 
-#if 0
-static void
-add_sized (GtkIconFactory *factory,
-           const guchar   *inline_data,
-           GtkIconSize     size,
-           const gchar    *stock_id)
-{
-  GtkIconSet *set;
-  
-  set = sized_icon_set_from_inline (inline_data, size);
-  
   gtk_icon_factory_add (factory, stock_id, set);
-
   gtk_icon_set_unref (set);
 }
-#endif
 
 static void
-add_sized_with_fallback_and_rtl (GtkIconFactory *factory,
-                                const guchar   *fallback_data_ltr,
-                                const guchar   *fallback_data_rtl,
-                                const guchar   *inline_data_ltr,
-                                const guchar   *inline_data_rtl,
-                                GtkIconSize     size,
-                                const gchar    *stock_id)
+register_bidi_stock_icon (GtkIconFactory *factory,
+                         const gchar    *stock_id,
+                          const gchar    *icon_name)
 {
-  GtkIconSet *set;
-
-  set = sized_with_fallback_icon_set_from_inline (fallback_data_ltr, fallback_data_rtl,
-                                                 inline_data_ltr, inline_data_rtl,
-                                                 size);
-  
-  gtk_icon_factory_add (factory, stock_id, set);
+  GtkIconSet *set = gtk_icon_set_new ();
+  GtkIconSource source = GTK_ICON_SOURCE_INIT (FALSE, TRUE, TRUE);
 
-  gtk_icon_set_unref (set);
-}
+  source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
+  source.source.icon_name = (gchar *)icon_name;
+  source.direction = GTK_TEXT_DIR_LTR;
+  gtk_icon_set_add_source (set, &source);
 
-static void
-add_sized_with_fallback (GtkIconFactory *factory,
-                        const guchar   *fallback_data,
-                        const guchar   *inline_data,
-                        GtkIconSize     size,
-                        const gchar     *stock_id)
-{
-  add_sized_with_fallback_and_rtl (factory,
-                                  fallback_data, NULL,
-                                  inline_data, NULL,
-                                  size, stock_id);
-}
+  source.type = GTK_ICON_SOURCE_STATIC_ICON_NAME;
+  source.source.icon_name = (gchar *)icon_name;
+  source.direction = GTK_TEXT_DIR_RTL;
+  gtk_icon_set_add_source (set, &source);
 
-static void
-add_unsized (GtkIconFactory *factory,
-             const guchar   *inline_data,
-             const gchar    *stock_id)
-{
-  GtkIconSet *set;
-  
-  set = unsized_icon_set_from_inline (inline_data);
-  
   gtk_icon_factory_add (factory, stock_id, set);
-
   gtk_icon_set_unref (set);
 }
 
@@ -484,355 +520,110 @@ get_default_icons (GtkIconFactory *factory)
 {
   /* KEEP IN SYNC with gtkstock.c */
 
-  /* We add all stock icons unsized, since it's confusing if icons only
-   * can be loaded at certain sizes.
-   */
-
-  /* Have dialog size */
-  add_unsized (factory, stock_dialog_error_48, GTK_STOCK_DIALOG_ERROR);
-  add_unsized (factory, stock_dialog_info_48, GTK_STOCK_DIALOG_INFO);
-  add_unsized (factory, stock_dialog_question_48, GTK_STOCK_DIALOG_QUESTION);
-  add_unsized (factory, stock_dialog_warning_48,GTK_STOCK_DIALOG_WARNING);
-  
-  /* Have dnd size */
-  add_unsized (factory, stock_dnd_32, GTK_STOCK_DND);
-  add_unsized (factory, stock_dnd_multiple_32, GTK_STOCK_DND_MULTIPLE);
-  
-  /* Have button sizes */
-  add_unsized (factory, stock_apply_20, GTK_STOCK_APPLY);
-  add_unsized (factory, stock_cancel_20, GTK_STOCK_CANCEL);
-  add_unsized (factory, stock_no_20, GTK_STOCK_NO);
-  add_unsized (factory, stock_ok_20, GTK_STOCK_OK);
-  add_unsized (factory, stock_yes_20, GTK_STOCK_YES);
-
-  /* Generic + button sizes */
-  add_sized_with_fallback (factory,
-                           stock_close_24,
-                           stock_close_20,
-                           GTK_ICON_SIZE_BUTTON,
-                           GTK_STOCK_CLOSE);
-
-  /* Generic + menu sizes */  
-  add_sized_with_fallback (factory,
-                          stock_add_24,
-                          stock_add_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_ADD);
-
-  add_sized_with_fallback (factory,
-                          stock_align_center_24,
-                          stock_align_center_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_JUSTIFY_CENTER);
-
-  add_sized_with_fallback (factory,
-                          stock_align_justify_24,
-                          stock_align_justify_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_JUSTIFY_FILL);
-
-  add_sized_with_fallback (factory,
-                          stock_align_left_24,
-                          stock_align_left_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_JUSTIFY_LEFT);
-
-  add_sized_with_fallback (factory,
-                          stock_align_right_24,
-                          stock_align_right_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_JUSTIFY_RIGHT);
-
-  add_sized_with_fallback (factory,
-                          stock_bottom_24,
-                          stock_bottom_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_GOTO_BOTTOM);
-
-  add_sized_with_fallback (factory,
-                           stock_cdrom_24,
-                           stock_cdrom_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_CDROM);
-
-  add_sized_with_fallback (factory,
-                           stock_convert_24,
-                           stock_convert_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_CONVERT);
-
-  add_sized_with_fallback (factory,
-                          stock_copy_24,
-                          stock_copy_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_COPY);
-
-  add_sized_with_fallback (factory,
-                          stock_cut_24,
-                          stock_cut_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_CUT);
-
-  add_sized_with_fallback (factory,
-                           stock_down_arrow_24,
-                           stock_down_arrow_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_GO_DOWN);
-
-  add_sized_with_fallback (factory,
-                          stock_exec_24,
-                          stock_exec_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_EXECUTE);
-
-  add_sized_with_fallback (factory,
-                          stock_exit_24,
-                          stock_exit_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_QUIT);
-
-  add_sized_with_fallback (factory,
-                          stock_first_24,
-                          stock_first_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_GOTO_FIRST);
-
-  add_sized_with_fallback (factory,
-                          stock_font_24,
-                           stock_font_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_SELECT_FONT);
-
-  add_sized_with_fallback (factory,
-                           stock_help_24,
-                           stock_help_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_HELP);
-
-  add_sized_with_fallback (factory,
-                           stock_home_24,
-                           stock_home_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_HOME);
-
-  add_sized_with_fallback (factory,
-                          stock_jump_to_24,
-                          stock_jump_to_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_JUMP_TO);
-
-  add_sized_with_fallback (factory,
-                           stock_last_24,
-                           stock_last_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_GOTO_LAST);
-
-  add_sized_with_fallback_and_rtl (factory,
-                                  stock_left_arrow_24,
-                                  stock_right_arrow_24,
-                                  stock_left_arrow_16,
-                                  stock_right_arrow_16,
-                                  GTK_ICON_SIZE_MENU,
-                                  GTK_STOCK_GO_BACK);
-
-  add_sized_with_fallback (factory,
-                          stock_missing_image_24,
-                          stock_missing_image_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_MISSING_IMAGE);
-
-  add_sized_with_fallback (factory,
-                          stock_new_24,
-                          stock_new_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_NEW);
-
-  add_sized_with_fallback (factory,
-                          stock_open_24,
-                          stock_open_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_OPEN);
-
-  add_sized_with_fallback (factory,
-                           stock_paste_24,
-                           stock_paste_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_PASTE);
-
-  add_sized_with_fallback (factory,
-                           stock_preferences_24,
-                           stock_preferences_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_PREFERENCES);
-
-  add_sized_with_fallback (factory,
-                           stock_print_24,
-                           stock_print_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_PRINT);
-
-  add_sized_with_fallback (factory,
-                           stock_print_preview_24,
-                           stock_print_preview_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_PRINT_PREVIEW);
-
-  add_sized_with_fallback (factory,
-                          stock_properties_24,
-                          stock_properties_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_PROPERTIES);
-  
-  add_sized_with_fallback (factory,
-                           stock_redo_24,
-                           stock_redo_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_REDO);
-
-  add_sized_with_fallback (factory,
-                          stock_remove_24,
-                          stock_remove_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_REMOVE);
-
-  add_sized_with_fallback (factory,
-                          stock_refresh_24,
-                          stock_refresh_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_REFRESH);
-
-  add_sized_with_fallback (factory,
-                          stock_revert_24,
-                          stock_revert_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_REVERT_TO_SAVED);
-
-  add_sized_with_fallback_and_rtl (factory,
-                                  stock_right_arrow_24,
-                                  stock_left_arrow_24,
-                                  stock_right_arrow_16,
-                                  stock_left_arrow_16,
-                                  GTK_ICON_SIZE_MENU,
-                                  GTK_STOCK_GO_FORWARD);
-
-  add_sized_with_fallback (factory,
-                          stock_save_24,
-                          stock_save_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_SAVE);
-
-  add_sized_with_fallback (factory,
-                          stock_save_24,
-                          stock_save_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_FLOPPY);
-
-  add_sized_with_fallback (factory,
-                          stock_save_as_24,
-                          stock_save_as_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_SAVE_AS);
-
-  add_sized_with_fallback (factory,
-                          stock_search_24,
-                          stock_search_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_FIND);
-
-  add_sized_with_fallback (factory,
-                          stock_search_replace_24,
-                          stock_search_replace_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_FIND_AND_REPLACE);
-
-  add_sized_with_fallback (factory,
-                           stock_sort_descending_24,
-                           stock_sort_descending_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_SORT_DESCENDING);
-
-  add_sized_with_fallback (factory,
-                           stock_sort_ascending_24,
-                           stock_sort_ascending_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_SORT_ASCENDING);
-
-  add_sized_with_fallback (factory,
-                          stock_spellcheck_24,
-                          stock_spellcheck_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_SPELL_CHECK);
-
-  add_sized_with_fallback (factory,
-                          stock_stop_24,
-                          stock_stop_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_STOP);
-
-  add_sized_with_fallback (factory,
-                           stock_text_bold_24,
-                           stock_text_bold_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_BOLD);
-
-  add_sized_with_fallback (factory,
-                           stock_text_italic_24,
-                           stock_text_italic_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_ITALIC);
-
-  add_sized_with_fallback (factory,
-                           stock_text_strikethrough_24,
-                           stock_text_strikethrough_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_STRIKETHROUGH);
-
-  add_sized_with_fallback (factory,
-                           stock_text_underline_24,
-                           stock_text_underline_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_UNDERLINE);
-
-  add_sized_with_fallback (factory,
-                          stock_top_24,
-                          stock_top_16,
-                          GTK_ICON_SIZE_MENU,
-                          GTK_STOCK_GOTO_TOP);
-
-  add_sized_with_fallback (factory,
-                           stock_trash_24,
-                           stock_trash_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_DELETE);
-
-  add_sized_with_fallback (factory,
-                           stock_undelete_24,
-                           stock_undelete_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_UNDELETE);
-
-  add_sized_with_fallback (factory,
-                           stock_undo_24,
-                           stock_undo_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_UNDO);
-
-  add_sized_with_fallback (factory,
-                           stock_up_arrow_24,
-                           stock_up_arrow_16,
-                           GTK_ICON_SIZE_MENU,
-                           GTK_STOCK_GO_UP);
-
-/* Generic size only */
-
-  add_unsized (factory, stock_clear_24, GTK_STOCK_CLEAR);
-  add_unsized (factory, stock_colorselector_24, GTK_STOCK_SELECT_COLOR);
-  add_unsized (factory, stock_color_picker_25, GTK_STOCK_COLOR_PICKER);
-  add_unsized (factory, stock_index_24, GTK_STOCK_INDEX);
-  add_unsized (factory, stock_zoom_1_24, GTK_STOCK_ZOOM_100);
-  add_unsized (factory, stock_zoom_fit_24, GTK_STOCK_ZOOM_FIT);
-  add_unsized (factory, stock_zoom_in_24, GTK_STOCK_ZOOM_IN);
-  add_unsized (factory, stock_zoom_out_24, GTK_STOCK_ZOOM_OUT);
+  register_stock_icon (factory, GTK_STOCK_DIALOG_AUTHENTICATION, "dialog-password");
+  register_stock_icon (factory, GTK_STOCK_DIALOG_ERROR, "dialog-error");
+  register_stock_icon (factory, GTK_STOCK_DIALOG_INFO, "dialog-information");
+  register_stock_icon (factory, GTK_STOCK_DIALOG_QUESTION, "dialog-question");
+  register_stock_icon (factory, GTK_STOCK_DIALOG_WARNING, "dialog-warning");
+  register_stock_icon (factory, GTK_STOCK_DND, GTK_STOCK_DND);
+  register_stock_icon (factory, GTK_STOCK_DND_MULTIPLE, GTK_STOCK_DND_MULTIPLE);
+  register_stock_icon (factory, GTK_STOCK_APPLY, GTK_STOCK_APPLY);
+  register_stock_icon (factory, GTK_STOCK_CANCEL, GTK_STOCK_CANCEL);
+  register_stock_icon (factory, GTK_STOCK_NO, GTK_STOCK_NO);
+  register_stock_icon (factory, GTK_STOCK_OK, GTK_STOCK_OK);
+  register_stock_icon (factory, GTK_STOCK_YES, GTK_STOCK_YES);
+  register_stock_icon (factory, GTK_STOCK_CLOSE, "window-close");
+  register_stock_icon (factory, GTK_STOCK_ADD, "list-add");
+  register_stock_icon (factory, GTK_STOCK_JUSTIFY_CENTER, "format-justify-center");
+  register_stock_icon (factory, GTK_STOCK_JUSTIFY_FILL, "format-justify-fill");
+  register_stock_icon (factory, GTK_STOCK_JUSTIFY_LEFT, "format-justify-left");
+  register_stock_icon (factory, GTK_STOCK_JUSTIFY_RIGHT, "format-justify-right");
+  register_stock_icon (factory, GTK_STOCK_GOTO_BOTTOM, "go-bottom");
+  register_stock_icon (factory, GTK_STOCK_CDROM, "media-optical");
+  register_stock_icon (factory, GTK_STOCK_CONVERT, GTK_STOCK_CONVERT);
+  register_stock_icon (factory, GTK_STOCK_COPY, "edit-copy");
+  register_stock_icon (factory, GTK_STOCK_CUT, "edit-cut");
+  register_stock_icon (factory, GTK_STOCK_GO_DOWN, "go-down");
+  register_stock_icon (factory, GTK_STOCK_EXECUTE, "system-run");
+  register_stock_icon (factory, GTK_STOCK_QUIT, "application-exit");
+  register_bidi_stock_icon (factory, GTK_STOCK_GOTO_FIRST, "go-first");
+  register_stock_icon (factory, GTK_STOCK_SELECT_FONT, GTK_STOCK_SELECT_FONT);
+  register_stock_icon (factory, GTK_STOCK_FULLSCREEN, "view-fullscreen");
+  register_stock_icon (factory, GTK_STOCK_LEAVE_FULLSCREEN, "view-restore");
+  register_stock_icon (factory, GTK_STOCK_HARDDISK, "drive-harddisk");
+  register_stock_icon (factory, GTK_STOCK_HELP, "help-contents");
+  register_stock_icon (factory, GTK_STOCK_HOME, "go-home");
+  register_stock_icon (factory, GTK_STOCK_INFO, "dialog-information");
+  register_bidi_stock_icon (factory, GTK_STOCK_JUMP_TO, "go-jump");
+  register_bidi_stock_icon (factory, GTK_STOCK_GOTO_LAST, "go-last");
+  register_bidi_stock_icon (factory, GTK_STOCK_GO_BACK, "go-previous");
+  register_stock_icon (factory, GTK_STOCK_MISSING_IMAGE, "image-missing");
+  register_stock_icon (factory, GTK_STOCK_NETWORK, "network-idle");
+  register_stock_icon (factory, GTK_STOCK_NEW, "document-new");
+  register_stock_icon (factory, GTK_STOCK_OPEN, "document-open");
+  register_stock_icon (factory, GTK_STOCK_ORIENTATION_PORTRAIT, GTK_STOCK_ORIENTATION_PORTRAIT);
+  register_stock_icon (factory, GTK_STOCK_ORIENTATION_LANDSCAPE, GTK_STOCK_ORIENTATION_LANDSCAPE);
+  register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT, GTK_STOCK_ORIENTATION_REVERSE_PORTRAIT);
+  register_stock_icon (factory, GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE, GTK_STOCK_ORIENTATION_REVERSE_LANDSCAPE);
+  register_stock_icon (factory, GTK_STOCK_PAGE_SETUP, GTK_STOCK_PAGE_SETUP);
+  register_stock_icon (factory, GTK_STOCK_PASTE, "edit-paste");
+  register_stock_icon (factory, GTK_STOCK_PREFERENCES, GTK_STOCK_PREFERENCES);
+  register_stock_icon (factory, GTK_STOCK_PRINT, "document-print");
+  register_stock_icon (factory, GTK_STOCK_PRINT_ERROR, "printer-error");
+  register_stock_icon (factory, GTK_STOCK_PRINT_PAUSED, "printer-paused");
+  register_stock_icon (factory, GTK_STOCK_PRINT_PREVIEW, "document-print-preview");
+  register_stock_icon (factory, GTK_STOCK_PRINT_REPORT, "printer-info");
+  register_stock_icon (factory, GTK_STOCK_PRINT_WARNING, "printer-warning");
+  register_stock_icon (factory, GTK_STOCK_PROPERTIES, "document-properties");
+  register_bidi_stock_icon (factory, GTK_STOCK_REDO, "edit-redo");
+  register_stock_icon (factory, GTK_STOCK_REMOVE, "list-remove");
+  register_stock_icon (factory, GTK_STOCK_REFRESH, "view-refresh");
+  register_bidi_stock_icon (factory, GTK_STOCK_REVERT_TO_SAVED, "document-revert");
+  register_bidi_stock_icon (factory, GTK_STOCK_GO_FORWARD, "go-next");
+  register_stock_icon (factory, GTK_STOCK_SAVE, "document-save");
+  register_stock_icon (factory, GTK_STOCK_FLOPPY, "media-floppy");
+  register_stock_icon (factory, GTK_STOCK_SAVE_AS, "document-save-as");
+  register_stock_icon (factory, GTK_STOCK_FIND, "edit-find");
+  register_stock_icon (factory, GTK_STOCK_FIND_AND_REPLACE, "edit-find-replace");
+  register_stock_icon (factory, GTK_STOCK_SORT_DESCENDING, "view-sort-descending");
+  register_stock_icon (factory, GTK_STOCK_SORT_ASCENDING, "view-sort-ascending");
+  register_stock_icon (factory, GTK_STOCK_SPELL_CHECK, "tools-check-spelling");
+  register_stock_icon (factory, GTK_STOCK_STOP, "process-stop");
+  register_stock_icon (factory, GTK_STOCK_BOLD, "format-text-bold");
+  register_stock_icon (factory, GTK_STOCK_ITALIC, "format-text-italic");
+  register_stock_icon (factory, GTK_STOCK_STRIKETHROUGH, "format-text-strikethrough");
+  register_stock_icon (factory, GTK_STOCK_UNDERLINE, "format-text-underline");
+  register_bidi_stock_icon (factory, GTK_STOCK_INDENT, "format-indent-more");
+  register_bidi_stock_icon (factory, GTK_STOCK_UNINDENT, "format-indent-less");
+  register_stock_icon (factory, GTK_STOCK_GOTO_TOP, "go-top");
+  register_stock_icon (factory, GTK_STOCK_DELETE, "edit-delete");
+  register_bidi_stock_icon (factory, GTK_STOCK_UNDELETE, GTK_STOCK_UNDELETE);
+  register_bidi_stock_icon (factory, GTK_STOCK_UNDO, "edit-undo");
+  register_stock_icon (factory, GTK_STOCK_GO_UP, "go-up");
+  register_stock_icon (factory, GTK_STOCK_FILE, "text-x-generic");
+  register_stock_icon (factory, GTK_STOCK_DIRECTORY, "folder");
+  register_stock_icon (factory, GTK_STOCK_ABOUT, "help-about");
+  register_stock_icon (factory, GTK_STOCK_CONNECT, GTK_STOCK_CONNECT);
+  register_stock_icon (factory, GTK_STOCK_DISCONNECT, GTK_STOCK_DISCONNECT);
+  register_stock_icon (factory, GTK_STOCK_EDIT, GTK_STOCK_EDIT);
+  register_stock_icon (factory, GTK_STOCK_CAPS_LOCK_WARNING, GTK_STOCK_CAPS_LOCK_WARNING);
+  register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_FORWARD, "media-seek-forward");
+  register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_NEXT, "media-skip-forward");
+  register_stock_icon (factory, GTK_STOCK_MEDIA_PAUSE, "media-playback-pause");
+  register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_PLAY, "media-playback-start");
+  register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_PREVIOUS, "media-skip-backward");
+  register_stock_icon (factory, GTK_STOCK_MEDIA_RECORD, "media-record");
+  register_bidi_stock_icon (factory, GTK_STOCK_MEDIA_REWIND, "media-seek-backward");
+  register_stock_icon (factory, GTK_STOCK_MEDIA_STOP, "media-playback-stop");
+  register_stock_icon (factory, GTK_STOCK_INDEX, GTK_STOCK_INDEX);
+  register_stock_icon (factory, GTK_STOCK_ZOOM_100, "zoom-original");
+  register_stock_icon (factory, GTK_STOCK_ZOOM_IN, "zoom-in");
+  register_stock_icon (factory, GTK_STOCK_ZOOM_OUT, "zoom-out");
+  register_stock_icon (factory, GTK_STOCK_ZOOM_FIT, "zoom-fit-best");
+  register_stock_icon (factory, GTK_STOCK_SELECT_ALL, "edit-select-all");
+  register_stock_icon (factory, GTK_STOCK_CLEAR, "edit-clear");
+  register_stock_icon (factory, GTK_STOCK_SELECT_COLOR, GTK_STOCK_SELECT_COLOR);
+  register_stock_icon (factory, GTK_STOCK_COLOR_PICKER, GTK_STOCK_COLOR_PICKER);
 }
 
 /************************************************************
@@ -845,7 +636,7 @@ struct _IconSize
 {
   gint size;
   gchar *name;
-  
+
   gint width;
   gint height;
 };
@@ -880,7 +671,7 @@ init_icon_sizes (void)
       gint i;
 
       icon_aliases = g_hash_table_new (g_str_hash, g_str_equal);
-      
+
       icon_sizes = g_new (IconSize, NUM_BUILTIN_SIZES);
       icon_sizes_allocated = NUM_BUILTIN_SIZES;
       icon_sizes_used = NUM_BUILTIN_SIZES;
@@ -895,7 +686,7 @@ init_icon_sizes (void)
        * Even if we did I suppose removing the builtin sizes would be
        * disallowed.
        */
-      
+
       icon_sizes[GTK_ICON_SIZE_MENU].size = GTK_ICON_SIZE_MENU;
       icon_sizes[GTK_ICON_SIZE_MENU].name = "gtk-menu";
       icon_sizes[GTK_ICON_SIZE_MENU].width = 16;
@@ -910,7 +701,7 @@ init_icon_sizes (void)
       icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].name = "gtk-small-toolbar";
       icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].width = 18;
       icon_sizes[GTK_ICON_SIZE_SMALL_TOOLBAR].height = 18;
-      
+
       icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].size = GTK_ICON_SIZE_LARGE_TOOLBAR;
       icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].name = "gtk-large-toolbar";
       icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].width = 24;
@@ -933,10 +724,10 @@ init_icon_sizes (void)
       while (i < NUM_BUILTIN_SIZES)
         {
           gtk_icon_size_register_alias (icon_sizes[i].name, icon_sizes[i].size);
-          
+
           ++i;
         }
-      
+
 #undef NUM_BUILTIN_SIZES
     }
 }
@@ -986,7 +777,7 @@ icon_size_set_for_settings (GtkSettings *settings,
   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)
     {
@@ -998,7 +789,7 @@ icon_size_set_for_settings (GtkSettings *settings,
     }
 
   settings_size = &g_array_index (settings_sizes, SettingsIconSize, size);
-  
+
   settings_size->width = width;
   settings_size->height = height;
 }
@@ -1012,7 +803,7 @@ scan_icon_size_name (const char **pos, GString *out)
 
   while (g_ascii_isspace (*p))
     p++;
-  
+
   if (!((*p >= 'A' && *p <= 'Z') ||
        (*p >= 'a' && *p <= 'z') ||
        *p == '_' || *p == '-'))
@@ -1046,7 +837,7 @@ icon_size_setting_parse (GtkSettings *settings,
   while (pango_skip_space (&p))
     {
       gint width, height;
-      
+
       if (!scan_icon_size_name (&p, name_buf))
        goto err;
 
@@ -1126,7 +917,7 @@ icon_size_settings_changed (GtkSettings  *settings,
 {
   icon_size_set_all_from_settings (settings);
 
-  _gtk_rc_reset_styles (settings);
+  gtk_style_context_reset_widgets (_gtk_settings_get_screen (settings));
 }
 
 static void
@@ -1136,11 +927,11 @@ icon_sizes_init_for_settings (GtkSettings *settings)
                    "notify::gtk-icon-sizes",
                    G_CALLBACK (icon_size_settings_changed),
                    NULL);
-  
+
   icon_size_set_all_from_settings (settings);
 }
-     
-gboolean
+
+static gboolean
 icon_size_lookup_intern (GtkSettings *settings,
                         GtkIconSize  size,
                         gint        *widthp,
@@ -1149,10 +940,13 @@ icon_size_lookup_intern (GtkSettings *settings,
   GArray *settings_sizes;
   gint width_for_settings = -1;
   gint height_for_settings = -1;
-  
+
   init_icon_sizes ();
 
-  if (size >= icon_sizes_used || icon_sizes[size].width < 0)
+  if (size == (GtkIconSize)-1)
+    return FALSE;
+
+  if (size >= icon_sizes_used)
     return FALSE;
 
   if (size == GTK_ICON_SIZE_INVALID)
@@ -1161,17 +955,18 @@ icon_size_lookup_intern (GtkSettings *settings,
   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;
        }
@@ -1188,56 +983,58 @@ icon_size_lookup_intern (GtkSettings *settings,
 
 /**
  * gtk_icon_size_lookup_for_settings:
- * @GtkSettings: a #GtkSettings object, used to determine
+ * @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
+ * @size: (type int): an icon size
+ * @width: (out): location to store icon width
+ * @height: (out): 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
+ * 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
+ * isn't normally needed, gtk_widget_render_icon_pixbuf() 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        *widthp,
-                                  gint        *heightp)
+                                  gint        *width,
+                                  gint        *height)
 {
   g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
 
-  return icon_size_lookup_intern (settings, size, widthp, heightp);
+  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
+ * @size: (type int): an icon size
+ * @width: (out): location to store icon width
+ * @height: (out): location to store icon height
  *
  * 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
+ * isn't normally needed, gtk_widget_render_icon_pixbuf() 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
- **/
+ */
 gboolean
 gtk_icon_size_lookup (GtkIconSize  size,
                       gint        *widthp,
@@ -1257,7 +1054,7 @@ icon_size_register_intern (const gchar *name,
 {
   IconAlias *old_alias;
   GtkIconSize size;
-  
+
   init_icon_sizes ();
 
   old_alias = g_hash_table_lookup (icon_aliases, name);
@@ -1303,9 +1100,8 @@ icon_size_register_intern (const gchar *name,
  * Registers a new icon size, along the same lines as #GTK_ICON_SIZE_MENU,
  * etc. Returns the integer value for the size.
  *
- * Returns: integer value representing the size
- * 
- **/
+ * Returns: (type int): integer value representing the size
+ */
 GtkIconSize
 gtk_icon_size_register (const gchar *name,
                         gint         width,
@@ -1314,32 +1110,31 @@ gtk_icon_size_register (const gchar *name,
   g_return_val_if_fail (name != NULL, 0);
   g_return_val_if_fail (width > 0, 0);
   g_return_val_if_fail (height > 0, 0);
-  
+
   return icon_size_register_intern (name, width, height);
 }
 
 /**
  * gtk_icon_size_register_alias:
  * @alias: an alias for @target
- * @target: an existing icon size
+ * @target: (type int): an existing icon size
  *
  * Registers @alias as another name for @target.
  * So calling gtk_icon_size_from_name() with @alias as argument
  * will return @target.
- *
- **/
+ */
 void
 gtk_icon_size_register_alias (const gchar *alias,
                               GtkIconSize  target)
 {
   IconAlias *ia;
-  
+
   g_return_if_fail (alias != NULL);
 
   init_icon_sizes ();
 
   if (!icon_size_lookup_intern (NULL, target, NULL, NULL))
-    g_warning ("gtk_icon_size_register_alias: Icon size %d does not exist", target);
+    g_warning ("gtk_icon_size_register_alias: Icon size %u does not exist", target);
 
   ia = g_hash_table_lookup (icon_aliases, alias);
   if (ia)
@@ -1363,20 +1158,21 @@ gtk_icon_size_register_alias (const gchar *alias,
     }
 }
 
-/** 
+/**
  * 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.
- **/
+ *
+ * Return value: (type int): the icon size
+ */
 GtkIconSize
 gtk_icon_size_from_name (const gchar *name)
 {
   IconAlias *ia;
 
   init_icon_sizes ();
-  
+
   ia = g_hash_table_lookup (icon_aliases, name);
 
   if (ia && icon_sizes[ia->target].width > 0)
@@ -1387,13 +1183,14 @@ gtk_icon_size_from_name (const gchar *name)
 
 /**
  * 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 
+ * @size: (type int): a #GtkIconSize.
+ *
+ * Gets the canonical name of the given icon size. The returned string
  * is statically allocated and should not be freed.
- **/
-G_CONST_RETURN gchar*
+ *
+ * Returns: the name of the given icon size.
+ */
+const gchar*
 gtk_icon_size_get_name (GtkIconSize  size)
 {
   if (size >= icon_sizes_used)
@@ -1407,29 +1204,29 @@ gtk_icon_size_get_name (GtkIconSize  size)
 /* 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,
+                                     GtkStyleContext  *style_context,
                                      GtkTextDirection  direction,
                                      GtkStateType      state,
                                      GtkIconSize       size);
 static void       add_to_cache      (GtkIconSet       *icon_set,
-                                     GtkStyle         *style,
+                                     GtkStyleContext  *style_context,
                                      GtkTextDirection  direction,
                                      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,
                                      GtkIconSet       *copy_recipient);
 static void       attach_to_style   (GtkIconSet       *icon_set,
-                                     GtkStyle         *style);
+                                     GtkStyleContext  *style_context);
 static void       detach_from_style (GtkIconSet       *icon_set,
-                                     GtkStyle         *style);
+                                     GtkStyleContext  *style_context);
 static void       style_dnotify     (gpointer          data);
 
 struct _GtkIconSet
@@ -1450,19 +1247,19 @@ static guint cache_serial = 0;
 
 /**
  * gtk_icon_set_new:
- * 
+ *
  * Creates a new #GtkIconSet. A #GtkIconSet represents a single icon
  * in various sizes and widget states. It can provide a #GdkPixbuf
  * for a given size and state on request, and automatically caches
  * some of the rendered #GdkPixbuf objects.
  *
- * Normally you would use gtk_widget_render_icon() instead of
+ * Normally you would use gtk_widget_render_icon_pixbuf() instead of
  * using #GtkIconSet directly. The one case where you'd use
  * #GtkIconSet is to create application-specific icon sets to place in
  * a #GtkIconFactory.
- * 
+ *
  * Return value: a new #GtkIconSet
- **/
+ */
 GtkIconSet*
 gtk_icon_set_new (void)
 {
@@ -1475,38 +1272,37 @@ gtk_icon_set_new (void)
   icon_set->cache = NULL;
   icon_set->cache_size = 0;
   icon_set->cache_serial = cache_serial;
-  
+
   return icon_set;
 }
 
 /**
  * gtk_icon_set_new_from_pixbuf:
  * @pixbuf: a #GdkPixbuf
- * 
+ *
  * Creates a new #GtkIconSet with @pixbuf as the default/fallback
  * source image. If you don't add any additional #GtkIconSource to the
  * icon set, all variants of the icon will be created from @pixbuf,
  * using scaling, pixelation, etc. as required to adjust the icon size
  * or make the icon look insensitive/prelighted.
- * 
+ *
  * Return value: a new #GtkIconSet
- **/
+ */
 GtkIconSet *
 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;
 }
 
@@ -1514,11 +1310,11 @@ gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf)
 /**
  * gtk_icon_set_ref:
  * @icon_set: a #GtkIconSet.
- * 
+ *
  * Increments the reference count on @icon_set.
- * 
+ *
  * Return value: @icon_set.
- **/
+ */
 GtkIconSet*
 gtk_icon_set_ref (GtkIconSet *icon_set)
 {
@@ -1533,10 +1329,10 @@ gtk_icon_set_ref (GtkIconSet *icon_set)
 /**
  * gtk_icon_set_unref:
  * @icon_set: a #GtkIconSet
- * 
+ *
  * Decrements the reference count on @icon_set, and frees memory
  * if the reference count reaches 0.
- **/
+ */
 void
 gtk_icon_set_unref (GtkIconSet *icon_set)
 {
@@ -1554,6 +1350,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);
 
@@ -1561,25 +1358,16 @@ 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;
-}
+G_DEFINE_BOXED_TYPE (GtkIconSet, gtk_icon_set,
+                     gtk_icon_set_ref,
+                     gtk_icon_set_unref)
 
 /**
  * gtk_icon_set_copy:
  * @icon_set: a #GtkIconSet
- * 
- * Copies @icon_set by value. 
- * 
+ *
+ * Copies @icon_set by value.
+ *
  * Return value: a new #GtkIconSet identical to the first.
  **/
 GtkIconSet*
@@ -1587,7 +1375,7 @@ gtk_icon_set_copy (GtkIconSet *icon_set)
 {
   GtkIconSet *copy;
   GSList *tmp_list;
-  
+
   copy = gtk_icon_set_new ();
 
   tmp_list = icon_set->sources;
@@ -1604,7 +1392,7 @@ gtk_icon_set_copy (GtkIconSet *icon_set)
   copy->cache = copy_cache (icon_set, copy);
   copy->cache_size = icon_set->cache_size;
   copy->cache_serial = icon_set->cache_serial;
-  
+
   return copy;
 }
 
@@ -1620,8 +1408,8 @@ sizes_equivalent (GtkIconSize lhs,
    */
 #if 1
   return lhs == rhs;
-#else  
-  
+#else
+
   gint r_w, r_h, l_w, l_h;
 
   icon_size_lookup_intern (NULL, rhs, &r_w, &r_h);
@@ -1631,16 +1419,16 @@ sizes_equivalent (GtkIconSize lhs,
 #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
@@ -1648,102 +1436,352 @@ find_and_prep_icon_source (GtkIconSet       *icon_set,
    * multiple matches for a given "wildness" then the RC file contained
    * dumb stuff, and we end up with an arbitrary matching source)
    */
-  
+
   source = NULL;
   tmp_list = icon_set->sources;
   while (tmp_list != NULL)
     {
       GtkIconSource *s = tmp_list->data;
-      
+
       if ((s->any_direction || (s->direction == direction)) &&
           (s->any_state || (s->state == state)) &&
-          (s->any_size || (sizes_equivalent (size, s->size))))
+          (s->any_size || size == (GtkIconSize)-1 || (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;
-  
-  if (source->pixbuf == NULL)
+  return source;
+}
+
+static gboolean
+ensure_filename_pixbuf (GtkIconSet    *icon_set,
+                       GtkIconSource *source)
+{
+  if (source->filename_pixbuf == NULL)
     {
       GError *error = NULL;
-      
-      g_assert (source->filename);
-      source->pixbuf = gdk_pixbuf_new_from_file (source->filename, &error);
 
-      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;
-        }
-    }
+      source->filename_pixbuf = gdk_pixbuf_new_from_file (source->source.filename, &error);
 
-  return source;
-}
+      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);
 
-static GdkPixbuf*
-render_fallback_image (GtkStyle          *style,
-                       GtkTextDirection   direction,
-                       GtkStateType       state,
-                       GtkIconSize        size,
-                       GtkWidget         *widget,
-                       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 };
+         icon_set->sources = g_slist_remove (icon_set->sources, source);
+
+         gtk_icon_source_free (source);
+
+         return FALSE;
+       }
+    }
 
-  if (fallback_source.pixbuf == NULL)
-    fallback_source.pixbuf = gdk_pixbuf_new_from_inline (-1, stock_missing_image_24, FALSE, NULL);
-  
-  return gtk_style_render_icon (style,
-                                &fallback_source,
-                                direction,
-                                state,
-                                size,
-                                widget,
-                                detail);
+  return TRUE;
 }
 
-/**
- * gtk_icon_set_render_icon:
- * @icon_set: a #GtkIconSet
- * @style: a #GtkStyle associated with @widget, or %NULL
- * @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
- * 
- * Renders an icon using gtk_style_render_icon(). In most cases,
+static GdkPixbuf *
+render_icon_name_pixbuf (GtkIconSource    *icon_source,
+                        GtkStyleContext  *context,
+                        GtkIconSize       size)
+{
+  GdkPixbuf *pixbuf;
+  GdkPixbuf *tmp_pixbuf;
+  GtkIconSource tmp_source;
+  GdkScreen *screen;
+  GtkIconTheme *icon_theme;
+  GtkSettings *settings;
+  gint width, height, pixel_size;
+  gint *sizes, *s, dist;
+  GError *error = NULL;
+
+  screen = gtk_style_context_get_screen (context);
+  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))
+    {
+      if (size == (GtkIconSize)-1)
+       {
+         /* Find an available size close to 48 */
+         sizes = gtk_icon_theme_get_icon_sizes (icon_theme, icon_source->source.icon_name);
+         dist = 1000;
+         width = height = 48;
+         for (s = sizes; *s; s++)
+           {
+             if (*s == -1)
+               {
+                 width = height = 48;
+                 break;
+               }
+             if (*s < 48)
+               {
+                 if (48 - *s < dist)
+                   {
+                     width = height = *s;
+                     dist = 48 - *s;
+                   }
+               }
+             else
+               {
+                 if (*s - 48 < dist)
+                   {
+                     width = height = *s;
+                     dist = *s - 48;
+                   }
+               }
+           }
+
+         g_free (sizes);
+       }
+      else
+       {
+         g_warning ("Invalid icon size %u\n", size);
+         width = height = 24;
+       }
+    }
+
+  pixel_size = MIN (width, height);
+
+  if (icon_source->direction != GTK_TEXT_DIR_NONE)
+    {
+      gchar *suffix[3] = { NULL, "-ltr", "-rtl" };
+      gchar *names[3];
+      GtkIconInfo *info;
+
+      names[0] = g_strconcat (icon_source->source.icon_name, suffix[icon_source->direction], NULL);
+      names[1] = icon_source->source.icon_name;
+      names[2] = NULL;
+
+      info = gtk_icon_theme_choose_icon (icon_theme,
+                                         (const char **) names,
+                                         pixel_size, GTK_ICON_LOOKUP_USE_BUILTIN);
+      g_free (names[0]);
+      if (info)
+        {
+          tmp_pixbuf = gtk_icon_info_load_icon (info, &error);
+          g_object_unref (info);
+        }
+      else
+        tmp_pixbuf = NULL;
+    }
+  else
+    {
+      tmp_pixbuf = gtk_icon_theme_load_icon (icon_theme,
+                                             icon_source->source.icon_name,
+                                             pixel_size, 0,
+                                             &error);
+    }
+
+  if (!tmp_pixbuf)
+    {
+      g_warning ("Error loading theme icon '%s' for stock: %s",
+                 icon_source->source.icon_name, error ? error->message : "");
+      if (error)
+        g_error_free (error);
+      return NULL;
+    }
+
+  tmp_source = *icon_source;
+  tmp_source.type = GTK_ICON_SOURCE_PIXBUF;
+  tmp_source.source.pixbuf = tmp_pixbuf;
+
+  pixbuf = gtk_render_icon_pixbuf (context, &tmp_source, -1);
+
+  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,
+                            GtkStyleContext  *context,
+                            GtkTextDirection  direction,
+                            GtkStateType      state,
+                            GtkIconSize       size)
+{
+  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 == 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_render_icon_pixbuf (context, source, size);
+         if (!pixbuf)
+           {
+             g_warning ("Failed to render icon");
+             failed = g_slist_prepend (failed, source);
+           }
+         break;
+       case GTK_ICON_SOURCE_ICON_NAME:
+       case GTK_ICON_SOURCE_STATIC_ICON_NAME:
+          pixbuf = render_icon_name_pixbuf (source, context, size);
+         if (!pixbuf)
+           failed = g_slist_prepend (failed, source);
+         break;
+       case GTK_ICON_SOURCE_EMPTY:
+         g_assert_not_reached ();
+       }
+    }
+
+  g_slist_free (failed);
+
+  return pixbuf;
+}
+
+extern GtkIconCache *_builtin_cache;
+
+static GdkPixbuf*
+render_fallback_image (GtkStyleContext   *context,
+                       GtkTextDirection   direction,
+                       GtkStateType       state,
+                       GtkIconSize        size)
+{
+  /* This icon can be used for any direction/state/size */
+  static GtkIconSource fallback_source = GTK_ICON_SOURCE_INIT (TRUE, TRUE, TRUE);
+
+  if (fallback_source.type == GTK_ICON_SOURCE_EMPTY)
+    {
+      gint index;
+      GdkPixbuf *pixbuf;
+
+      _gtk_icon_theme_ensure_builtin_cache ();
+
+      index = _gtk_icon_cache_get_directory_index (_builtin_cache, "24");
+      pixbuf = _gtk_icon_cache_get_icon (_builtin_cache, "image-missing", index);
+
+      g_return_val_if_fail(pixbuf != NULL, NULL);
+
+      gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
+      g_object_unref (pixbuf);
+    }
+
+  return gtk_render_icon_pixbuf (context, &fallback_source, size);
+}
+
+/**
+ * gtk_icon_set_render_icon_pixbuf:
+ * @icon_set: a #GtkIconSet
+ * @context: a #GtkStyleContext
+ * @size: (type int): icon size. A size of (GtkIconSize)-1
+ *        means render at the size of the source and don't scale.
+ *
+ * Renders an icon using gtk_render_icon_pixbuf(). In most cases,
+ * gtk_widget_render_icon_pixbuf() is better, since it automatically provides
+ * most of the arguments from the current widget settings.  This
+ * function never returns %NULL; if the icon can't be rendered
+ * (perhaps because an image file fails to load), a default "missing
+ * image" icon will be returned instead.
+ *
+ * Return value: (transfer full): a #GdkPixbuf to be displayed
+ *
+ * Since: 3.0
+ */
+GdkPixbuf *
+gtk_icon_set_render_icon_pixbuf (GtkIconSet        *icon_set,
+                                 GtkStyleContext   *context,
+                                 GtkIconSize        size)
+{
+  GdkPixbuf *icon = NULL;
+  GtkStateFlags flags = 0;
+  GtkStateType state;
+  GtkTextDirection direction;
+
+  g_return_val_if_fail (icon_set != NULL, NULL);
+  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
+
+  flags = gtk_style_context_get_state (context);
+  if (flags & GTK_STATE_FLAG_INSENSITIVE)
+    state = GTK_STATE_INSENSITIVE;
+  else if (flags & GTK_STATE_FLAG_PRELIGHT)
+    state = GTK_STATE_PRELIGHT;
+  else
+    state = GTK_STATE_NORMAL;
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+  direction = gtk_style_context_get_direction (context);
+G_GNUC_END_IGNORE_DEPRECATIONS;
+
+  if (icon_set->sources)
+    {
+      icon = find_in_cache (icon_set, context, direction, state, size);
+      if (icon)
+        {
+          g_object_ref (icon);
+          return icon;
+        }
+    }
+
+  if (icon_set->sources)
+    icon = find_and_render_icon_source (icon_set, context, direction, state, size);
+
+  if (icon == NULL)
+    icon = render_fallback_image (context, direction, state, size);
+
+  add_to_cache (icon_set, context, direction, state, size, icon);
+
+  return icon;
+}
+
+/**
+ * gtk_icon_set_render_icon:
+ * @icon_set: a #GtkIconSet
+ * @style: (allow-none): a #GtkStyle associated with @widget, or %NULL
+ * @direction: text direction
+ * @state: widget state
+ * @size: (type int): icon size. A size of (GtkIconSize)-1
+ *        means render at the size of the source and don't scale.
+ * @widget: (allow-none): widget that will display the icon, or %NULL.
+ *          The only use that is typically made of this
+ *          is to determine the appropriate #GdkScreen.
+ * @detail: (allow-none): 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
  * most of the arguments from the current widget settings.  This
  * function never returns %NULL; if the icon can't be rendered
  * (perhaps because an image file fails to load), a default "missing
  * image" icon will be returned instead.
- * 
- * Return value: a #GdkPixbuf to be displayed
- **/
+ *
+ * Return value: (transfer full): a #GdkPixbuf to be displayed
+ *
+ * Deprecated: 3.0: Use gtk_icon_set_render_icon_pixbuf() instead
+ */
 GdkPixbuf*
 gtk_icon_set_render_icon (GtkIconSet        *icon_set,
                           GtkStyle          *style,
@@ -1754,47 +1792,50 @@ 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);
+  GtkStyleContext *context = NULL;
+  GtkStateFlags flags = 0;
 
-  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);
+  g_return_val_if_fail (icon_set != NULL, NULL);
+  g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
 
-  if (icon)
+  if (style && gtk_style_has_context (style))
     {
-      g_object_ref (G_OBJECT (icon));
-      return icon;
+      g_object_get (style, "context", &context, NULL);
+      /* g_object_get returns a refed object */
+      if (context)
+        g_object_unref (context);
+    }
+  else if (widget)
+    {
+      context = gtk_widget_get_style_context (widget);
     }
 
-  
-  source = find_and_prep_icon_source (icon_set, direction, state, size);
-
-  if (source == NULL)
-    return render_fallback_image (style, direction, state, size, widget, detail);
+  if (!context)
+    return render_fallback_image (context, direction, state, size);
 
-  g_assert (source->pixbuf != NULL);
-  
-  icon = gtk_style_render_icon (style,
-                                source,
-                                direction,
-                                state,
-                                size,
-                                widget,
-                                detail);
+  gtk_style_context_save (context);
 
-  if (icon == NULL)
+  switch (state)
     {
-      g_warning ("Theme engine failed to render icon");
-      return NULL;
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
     }
-  
-  add_to_cache (icon_set, style, direction, state, size, icon);
-  
+
+  gtk_style_context_set_state (context, flags);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+  gtk_style_context_set_direction (context, direction);
+G_GNUC_END_IGNORE_DEPRECATIONS;
+
+  icon = gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
+
+  gtk_style_context_restore (context);
+
   return icon;
 }
 
@@ -1836,7 +1877,7 @@ icon_source_compare (gconstpointer ap, gconstpointer bp)
  * gtk_icon_set_render_icon(), but #GtkIconSet needs base images to
  * work with. The base images and when to use them are described by
  * a #GtkIconSource.
- * 
+ *
  * This function copies @source, so you can reuse the same source immediately
  * without affecting the icon set.
  *
@@ -1855,22 +1896,20 @@ icon_source_compare (gconstpointer ap, gconstpointer bp)
  *
  * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
  * default icon source based on the given pixbuf.
- * 
- **/
+ */
 void
-gtk_icon_set_add_source (GtkIconSet *icon_set,
+gtk_icon_set_add_source (GtkIconSet          *icon_set,
                          const GtkIconSource *source)
 {
   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;
     }
-  
+
   icon_set->sources = g_slist_insert_sorted (icon_set->sources,
                                              gtk_icon_source_copy (source),
                                              icon_source_compare);
@@ -1879,13 +1918,13 @@ gtk_icon_set_add_source (GtkIconSet *icon_set,
 /**
  * gtk_icon_set_get_sizes:
  * @icon_set: a #GtkIconSet
- * @sizes: return location for array of sizes
+ * @sizes: (array length=n_sizes) (out) (type int): return location
+ *     for array of sizes
  * @n_sizes: location to store number of elements in returned array
  *
  * Obtains a list of icon sizes this icon set can render. The returned
  * array must be freed with g_free().
- * 
- **/
+ */
 void
 gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
                         GtkIconSize **sizes,
@@ -1894,11 +1933,11 @@ gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
   GSList *tmp_list;
   gboolean all_sizes = FALSE;
   GSList *specifics = NULL;
-  
+
   g_return_if_fail (icon_set != NULL);
   g_return_if_fail (sizes != NULL);
   g_return_if_fail (n_sizes != NULL);
-  
+
   tmp_list = icon_set->sources;
   while (tmp_list != NULL)
     {
@@ -1913,7 +1952,7 @@ gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
         }
       else
         specifics = g_slist_prepend (specifics, GINT_TO_POINTER (source->size));
-      
+
       tmp_list = g_slist_next (tmp_list);
     }
 
@@ -1923,11 +1962,11 @@ gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
       gint i;
 
       init_icon_sizes ();
-      
+
       *sizes = g_new (GtkIconSize, icon_sizes_used);
       *n_sizes = icon_sizes_used - 1;
-      
-      i = 1;      
+
+      i = 1;
       while (i < icon_sizes_used)
         {
           (*sizes)[i - 1] = icon_sizes[i].size;
@@ -1937,7 +1976,7 @@ gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
   else
     {
       gint i;
-      
+
       *n_sizes = g_slist_length (specifics);
       *sizes = g_new (GtkIconSize, *n_sizes);
 
@@ -1958,21 +1997,21 @@ gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
 
 /**
  * gtk_icon_source_new:
- * 
+ *
  * Creates a new #GtkIconSource. A #GtkIconSource contains a #GdkPixbuf (or
  * image filename) that serves as the base image for one or more of the
  * icons in a #GtkIconSet, along with a specification for which icons in the
  * icon set will be based on that pixbuf or image file. An icon set contains
  * a set of icons that represent "the same" logical concept in different states,
  * different global text directions, and different sizes.
- * 
+ *
  * So for example a web browser's "Back to Previous Page" icon might
  * point in a different direction in Hebrew and in English; it might
  * look different when insensitive; and it might change size depending
  * on toolbar mode (small/large icons). So a single icon set would
  * contain all those variants of the icon. #GtkIconSet contains a list
  * of #GtkIconSource from which it can derive specific icon variants in
- * the set. 
+ * the set.
  *
  * In the simplest case, #GtkIconSet contains one source pixbuf from
  * which it derives all variants. The convenience function
@@ -1987,50 +2026,65 @@ gtk_icon_set_get_sizes (GtkIconSet   *icon_set,
  * By default, the icon source has all parameters wildcarded. That is,
  * the icon source will be used as the base icon for any desired text
  * direction, widget state, or icon size.
- * 
+ *
  * Return value: a new #GtkIconSource
- **/
+ */
 GtkIconSource*
 gtk_icon_source_new (void)
 {
   GtkIconSource *src;
-  
+
   src = g_new0 (GtkIconSource, 1);
 
   src->direction = GTK_TEXT_DIR_NONE;
   src->size = GTK_ICON_SIZE_INVALID;
   src->state = GTK_STATE_NORMAL;
-  
+
   src->any_direction = TRUE;
   src->any_state = TRUE;
   src->any_size = TRUE;
-  
+
   return src;
 }
 
 /**
  * gtk_icon_source_copy:
  * @source: a #GtkIconSource
- * 
+ *
  * Creates a copy of @source; mostly useful for language bindings.
- * 
+ *
  * Return value: a new #GtkIconSource
- **/
+ */
 GtkIconSource*
 gtk_icon_source_copy (const GtkIconSource *source)
 {
   GtkIconSource *copy;
-  
+
   g_return_val_if_fail (source != NULL, NULL);
 
   copy = g_new (GtkIconSource, 1);
 
   *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:
+    case GTK_ICON_SOURCE_STATIC_ICON_NAME:
+      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;
 }
@@ -2038,43 +2092,62 @@ gtk_icon_source_copy (const GtkIconSource *source)
 /**
  * gtk_icon_source_free:
  * @source: a #GtkIconSource
- * 
+ *
  * Frees a dynamically-allocated icon source, along with its
  * filename, size, and pixbuf fields if those are not %NULL.
- **/
+ */
 void
 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)
+G_DEFINE_BOXED_TYPE (GtkIconSource, gtk_icon_source,
+                     gtk_icon_source_copy,
+                     gtk_icon_source_free)
+
+static void
+icon_source_clear (GtkIconSource *source)
 {
-  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);
+  switch (source->type)
+    {
+    case GTK_ICON_SOURCE_EMPTY:
+      break;
+    case GTK_ICON_SOURCE_ICON_NAME:
+      g_free (source->source.icon_name);
+      /* fall thru */
+    case GTK_ICON_SOURCE_STATIC_ICON_NAME:
+      source->source.icon_name = NULL;
+      break;
+    case GTK_ICON_SOURCE_FILENAME:
+      g_free (source->source.filename);
+      source->source.filename = NULL;
+      if (source->filename_pixbuf) 
+       g_object_unref (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();
+    }
 
-  return our_type;
+  source->type = GTK_ICON_SOURCE_EMPTY;
 }
 
 /**
  * gtk_icon_source_set_filename:
  * @source: a #GtkIconSource
- * @filename: image file to use
+ * @filename: (type filename): image file to use
  *
  * Sets the name of an image file to use as a base image when creating
- * icon variants for #GtkIconSet. The filename must be absolute. 
- **/
+ * icon variants for #GtkIconSet. The filename must be absolute.
+ */
 void
 gtk_icon_source_set_filename (GtkIconSource *source,
                              const gchar   *filename)
@@ -2082,13 +2155,44 @@ gtk_icon_source_set_filename (GtkIconSource *source,
   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;
+
+  icon_source_clear (source);
+
+  if (filename != NULL)
+    {
+      source->type = GTK_ICON_SOURCE_FILENAME;
+      source->source.filename = g_strdup (filename);
+    }
+}
+
+/**
+ * gtk_icon_source_set_icon_name:
+ * @source: a #GtkIconSource
+ * @icon_name: (allow-none): 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;
-  
-  if (source->filename)
-    g_free (source->filename);
 
-  source->filename = g_strdup (filename);  
+  icon_source_clear (source);
+
+  if (icon_name != NULL)
+    {
+      source->type = GTK_ICON_SOURCE_ICON_NAME;
+      source->source.icon_name = g_strdup (icon_name);
+    }
 }
 
 /**
@@ -2097,59 +2201,97 @@ 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 (pixbuf)
-    g_object_ref (G_OBJECT (pixbuf));
+  if (source->type == GTK_ICON_SOURCE_PIXBUF &&
+      source->source.pixbuf == pixbuf)
+    return;
 
-  if (source->pixbuf)
-    g_object_unref (G_OBJECT (source->pixbuf));
+  icon_source_clear (source);
 
-  source->pixbuf = pixbuf;
+  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
  * 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. This string must not be modified
- * or freed.
- **/
-G_CONST_RETURN gchar*
+ *
+ * Return value: (type filename): image filename. This string must not
+ * be modified or freed.
+ */
+const 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.
+ */
+const 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 ||
+     source->type == GTK_ICON_SOURCE_STATIC_ICON_NAME)
+    return source->source.icon_name;
+  else
+    return NULL;
 }
 
 /**
  * gtk_icon_source_get_pixbuf:
  * @source: a #GtkIconSource
- * 
+ *
  * Retrieves the source pixbuf, or %NULL if none is set.
- * The reference count on the pixbuf is not incremented.
- * 
- * Return value: source pixbuf
- **/
+ * 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: (transfer none): source pixbuf
+ */
 GdkPixbuf*
 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;
 }
 
 /**
@@ -2166,8 +2308,7 @@ gtk_icon_source_get_pixbuf (const GtkIconSource *source)
  *
  * #GtkIconSet prefers non-wildcarded sources (exact matches) over
  * wildcarded sources, and will use an exact match when possible.
- * 
- **/
+ */
 void
 gtk_icon_source_set_direction_wildcarded (GtkIconSource *source,
                                           gboolean       setting)
@@ -2195,7 +2336,7 @@ gtk_icon_source_set_direction_wildcarded (GtkIconSource *source,
  * produce an appropriate icon for a given state, for example
  * lightening an image on prelight, but will not modify source images
  * that match exactly.
- **/
+ */
 void
 gtk_icon_source_set_state_wildcarded (GtkIconSource *source,
                                       gboolean       setting)
@@ -2223,40 +2364,40 @@ gtk_icon_source_set_state_wildcarded (GtkIconSource *source,
  * #GtkIconSet will normally scale wildcarded source images to produce
  * an appropriate icon at a given size, but will not change the size
  * of source images that match exactly.
- **/
+ */
 void
 gtk_icon_source_set_size_wildcarded (GtkIconSource *source,
                                      gboolean       setting)
 {
   g_return_if_fail (source != NULL);
 
-  source->any_size = setting != FALSE;  
+  source->any_size = setting != FALSE;
 }
 
 /**
  * gtk_icon_source_get_size_wildcarded:
  * @source: a #GtkIconSource
- * 
+ *
  * Gets the value set by gtk_icon_source_set_size_wildcarded().
- * 
+ *
  * Return value: %TRUE if this icon source is a base for any icon size variant
- **/
+ */
 gboolean
 gtk_icon_source_get_size_wildcarded (const GtkIconSource *source)
 {
   g_return_val_if_fail (source != NULL, TRUE);
-  
+
   return source->any_size;
 }
 
 /**
  * gtk_icon_source_get_state_wildcarded:
  * @source: a #GtkIconSource
- * 
+ *
  * Gets the value set by gtk_icon_source_set_state_wildcarded().
- * 
+ *
  * Return value: %TRUE if this icon source is a base for any widget state variant
- **/
+ */
 gboolean
 gtk_icon_source_get_state_wildcarded (const GtkIconSource *source)
 {
@@ -2268,11 +2409,11 @@ gtk_icon_source_get_state_wildcarded (const GtkIconSource *source)
 /**
  * gtk_icon_source_get_direction_wildcarded:
  * @source: a #GtkIconSource
- * 
+ *
  * Gets the value set by gtk_icon_source_set_direction_wildcarded().
- * 
+ *
  * Return value: %TRUE if this icon source is a base for any text direction variant
- **/
+ */
 gboolean
 gtk_icon_source_get_direction_wildcarded (const GtkIconSource *source)
 {
@@ -2288,13 +2429,12 @@ gtk_icon_source_get_direction_wildcarded (const GtkIconSource *source)
  *
  * Sets the text direction this icon source is intended to be used
  * with.
- * 
+ *
  * Setting the text direction on an icon source makes no difference
  * if the text direction is wildcarded. Therefore, you should usually
  * call gtk_icon_source_set_direction_wildcarded() to un-wildcard it
  * in addition to calling this function.
- * 
- **/
+ */
 void
 gtk_icon_source_set_direction (GtkIconSource   *source,
                                GtkTextDirection direction)
@@ -2311,13 +2451,12 @@ gtk_icon_source_set_direction (GtkIconSource   *source,
  *
  * Sets the widget state this icon source is intended to be used
  * with.
- * 
+ *
  * Setting the widget state on an icon source makes no difference
  * if the state is wildcarded. Therefore, you should usually
  * call gtk_icon_source_set_state_wildcarded() to un-wildcard it
  * in addition to calling this function.
- * 
- **/
+ */
 void
 gtk_icon_source_set_state (GtkIconSource *source,
                            GtkStateType   state)
@@ -2330,17 +2469,16 @@ gtk_icon_source_set_state (GtkIconSource *source,
 /**
  * gtk_icon_source_set_size:
  * @source: a #GtkIconSource
- * @size: icon size this source applies to
+ * @size: (type int): icon size this source applies to
  *
  * Sets the icon size this icon source is intended to be used
  * with.
- * 
+ *
  * Setting the icon size on an icon source makes no difference
  * if the size is wildcarded. Therefore, you should usually
  * call gtk_icon_source_set_size_wildcarded() to un-wildcard it
  * in addition to calling this function.
- * 
- **/
+ */
 void
 gtk_icon_source_set_size (GtkIconSource *source,
                           GtkIconSize    size)
@@ -2353,13 +2491,13 @@ gtk_icon_source_set_size (GtkIconSource *source,
 /**
  * gtk_icon_source_get_direction:
  * @source: a #GtkIconSource
- * 
+ *
  * Obtains the text direction this icon source applies to. The return
- * value is only useful/meaningful if the text direction is <emphasis>not</emphasis> 
+ * value is only useful/meaningful if the text direction is <emphasis>not</emphasis>
  * wildcarded.
- * 
+ *
  * Return value: text direction this source matches
- **/
+ */
 GtkTextDirection
 gtk_icon_source_get_direction (const GtkIconSource *source)
 {
@@ -2371,13 +2509,13 @@ gtk_icon_source_get_direction (const GtkIconSource *source)
 /**
  * gtk_icon_source_get_state:
  * @source: a #GtkIconSource
- * 
+ *
  * Obtains the widget state this icon source applies to. The return
  * value is only useful/meaningful if the widget state is <emphasis>not</emphasis>
  * wildcarded.
- * 
+ *
  * Return value: widget state this source matches
- **/
+ */
 GtkStateType
 gtk_icon_source_get_state (const GtkIconSource *source)
 {
@@ -2389,12 +2527,12 @@ gtk_icon_source_get_state (const GtkIconSource *source)
 /**
  * gtk_icon_source_get_size:
  * @source: a #GtkIconSource
- * 
+ *
  * Obtains the icon size this source applies to. The return value
  * is only useful/meaningful if the icon size is <emphasis>not</emphasis> wildcarded.
- * 
- * Return value: icon size this source matches.
- **/
+ *
+ * Return value: (type int): icon size this source matches.
+ */
 GtkIconSize
 gtk_icon_source_get_size (const GtkIconSource *source)
 {
@@ -2403,9 +2541,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;
@@ -2415,7 +2550,7 @@ struct _CachedIcon
   /* These must all match to use the cached pixbuf.
    * If any don't match, we must re-render the pixbuf.
    */
-  GtkStyle *style;
+  GtkStyleContext *style;
   GtkTextDirection direction;
   GtkStateType state;
   GtkIconSize size;
@@ -2427,20 +2562,24 @@ 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_object_unref (icon->style);
 
   g_free (icon);
 }
 
 static GdkPixbuf *
 find_in_cache (GtkIconSet      *icon_set,
-               GtkStyle        *style,
+               GtkStyleContext *style_context,
                GtkTextDirection direction,
                GtkStateType     state,
                GtkIconSize      size)
@@ -2449,17 +2588,17 @@ find_in_cache (GtkIconSet      *icon_set,
   GSList *prev;
 
   ensure_cache_up_to_date (icon_set);
-  
+
   prev = NULL;
   tmp_list = icon_set->cache;
   while (tmp_list != NULL)
     {
       CachedIcon *icon = tmp_list->data;
 
-      if (icon->style == style &&
+      if (icon->style == style_context &&
           icon->direction == direction &&
           icon->state == state &&
-          icon->size == size)
+          (size == (GtkIconSize)-1 || icon->size == size))
         {
           if (prev)
             {
@@ -2468,10 +2607,10 @@ find_in_cache (GtkIconSet      *icon_set,
               tmp_list->next = icon_set->cache;
               icon_set->cache = tmp_list;
             }
-          
+
           return icon->pixbuf;
         }
-          
+
       prev = tmp_list;
       tmp_list = g_slist_next (tmp_list);
     }
@@ -2481,7 +2620,7 @@ find_in_cache (GtkIconSet      *icon_set,
 
 static void
 add_to_cache (GtkIconSet      *icon_set,
-              GtkStyle        *style,
+              GtkStyleContext *style_context,
               GtkTextDirection direction,
               GtkStateType     state,
               GtkIconSize      size,
@@ -2490,36 +2629,25 @@ add_to_cache (GtkIconSet      *icon_set,
   CachedIcon *icon;
 
   ensure_cache_up_to_date (icon_set);
-  
-  g_object_ref (G_OBJECT (pixbuf));
 
-  /* We have to ref the style, since if the style was finalized
-   * its address could be reused by another style, creating a
-   * really weird bug
-   */
-  
-  if (style)
-    g_object_ref (G_OBJECT (style));
-  
+  g_object_ref (pixbuf);
 
   icon = g_new (CachedIcon, 1);
   icon_set->cache = g_slist_prepend (icon_set->cache, icon);
+  icon_set->cache_size++;
 
-  icon->style = style;
+  icon->style = g_object_ref (style_context);
   icon->direction = direction;
   icon->state = state;
   icon->size = size;
   icon->pixbuf = pixbuf;
+  attach_to_style (icon_set, icon->style);
 
-  if (icon->style)
-    attach_to_style (icon_set, icon->style);
-  
   if (icon_set->cache_size >= NUM_CACHED_ICONS)
     {
       /* Remove oldest item in the cache */
-      
       GSList *tmp_list;
-      
+
       tmp_list = icon_set->cache;
 
       /* Find next-to-last link */
@@ -2545,10 +2673,13 @@ static void
 clear_cache (GtkIconSet *icon_set,
              gboolean    style_detach)
 {
-  GSList *tmp_list;
-  GtkStyle *last_style = NULL;
+  GSList *cache, *tmp_list;
+  GtkStyleContext *last_style = NULL;
 
-  tmp_list = icon_set->cache;
+  cache = icon_set->cache;
+  icon_set->cache = NULL;
+  icon_set->cache_size = 0;
+  tmp_list = cache;
   while (tmp_list != NULL)
     {
       CachedIcon *icon = tmp_list->data;
@@ -2566,15 +2697,13 @@ clear_cache (GtkIconSet *icon_set,
               last_style = icon->style;
             }
         }
-      
-      cached_icon_free (icon);      
-      
+
+      cached_icon_free (icon);
+
       tmp_list = g_slist_next (tmp_list);
     }
 
-  g_slist_free (icon_set->cache);
-  icon_set->cache = NULL;
-  icon_set->cache_size = 0;
+  g_slist_free (cache);
 }
 
 static GSList*
@@ -2585,7 +2714,7 @@ copy_cache (GtkIconSet *icon_set,
   GSList *copy = NULL;
 
   ensure_cache_up_to_date (icon_set);
-  
+
   tmp_list = icon_set->cache;
   while (tmp_list != NULL)
     {
@@ -2594,15 +2723,15 @@ copy_cache (GtkIconSet *icon_set,
 
       *icon_copy = *icon;
 
-      if (icon_copy->style)
-        attach_to_style (copy_recipient, icon_copy->style);
-        
-      g_object_ref (G_OBJECT (icon_copy->pixbuf));
+      attach_to_style (copy_recipient, icon_copy->style);
+      g_object_ref (icon_copy->style);
+
+      g_object_ref (icon_copy->pixbuf);
 
       icon_copy->size = icon->size;
-      
-      copy = g_slist_prepend (copy, icon_copy);      
-      
+
+      copy = g_slist_prepend (copy, icon_copy);
+
       tmp_list = g_slist_next (tmp_list);
     }
 
@@ -2610,18 +2739,18 @@ copy_cache (GtkIconSet *icon_set,
 }
 
 static void
-attach_to_style (GtkIconSet *icon_set,
-                 GtkStyle   *style)
+attach_to_style (GtkIconSet      *icon_set,
+                 GtkStyleContext *style_context)
 {
   GHashTable *table;
 
-  table = g_object_get_qdata (G_OBJECT (style),
+  table = g_object_get_qdata (G_OBJECT (style_context),
                               g_quark_try_string ("gtk-style-icon-sets"));
 
   if (table == NULL)
     {
       table = g_hash_table_new (NULL, NULL);
-      g_object_set_qdata_full (G_OBJECT (style),
+      g_object_set_qdata_full (G_OBJECT (style_context),
                                g_quark_from_static_string ("gtk-style-icon-sets"),
                                table,
                                style_dnotify);
@@ -2631,12 +2760,12 @@ attach_to_style (GtkIconSet *icon_set,
 }
 
 static void
-detach_from_style (GtkIconSet *icon_set,
-                   GtkStyle   *style)
+detach_from_style (GtkIconSet       *icon_set,
+                   GtkStyleContext  *style_context)
 {
   GHashTable *table;
 
-  table = g_object_get_qdata (G_OBJECT (style),
+  table = g_object_get_qdata (G_OBJECT (style_context),
                               g_quark_try_string ("gtk-style-icon-sets"));
 
   if (table != NULL)
@@ -2656,7 +2785,7 @@ iconsets_foreach (gpointer key,
    * time all cache entries will have the same style,
    * so this is faster anyway.
    */
-  
+
   clear_cache (icon_set, FALSE);
 }
 
@@ -2664,7 +2793,7 @@ static void
 style_dnotify (gpointer data)
 {
   GHashTable *table = data;
-  
+
   g_hash_table_foreach (table, iconsets_foreach, NULL);
 
   g_hash_table_destroy (table);
@@ -2677,56 +2806,280 @@ _gtk_icon_set_invalidate_caches (void)
   ++cache_serial;
 }
 
-static void
-listify_foreach (gpointer key, gpointer value, gpointer data)
-{
-  GSList **list = data;
-
-  *list = g_slist_prepend (*list, key);
-}
-
-static GSList *
-g_hash_table_get_keys (GHashTable *table)
-{
-  GSList *list = NULL;
-
-  g_hash_table_foreach (table, listify_foreach, &list);
-
-  return list;
-}
-
 /**
  * _gtk_icon_factory_list_ids:
- * 
+ *
  * Gets all known IDs stored in an existing icon factory.
  * The strings in the returned list aren't copied.
  * The list itself should be freed.
- * 
+ *
  * Return value: List of ids in icon factories
- **/
-GSList*
+ */
+GList*
 _gtk_icon_factory_list_ids (void)
 {
   GSList *tmp_list;
-  GSList *ids;
+  GList *ids;
 
   ids = NULL;
 
-  ensure_default_icons ();
-  
+  _gtk_icon_factory_get_default_icons ();
+
   tmp_list = all_icon_factories;
   while (tmp_list != NULL)
     {
-      GSList *these_ids;
-      
+      GList *these_ids;
       GtkIconFactory *factory = GTK_ICON_FACTORY (tmp_list->data);
+      GtkIconFactoryPrivate *priv = factory->priv;
+
+      these_ids = g_hash_table_get_keys (priv->icons);
+
+      ids = g_list_concat (ids, these_ids);
 
-      these_ids = g_hash_table_get_keys (factory->icons);
-      
-      ids = g_slist_concat (ids, these_ids);
-      
       tmp_list = g_slist_next (tmp_list);
     }
 
   return ids;
 }
+
+typedef struct {
+  GSList *sources;
+  gboolean in_source;
+
+} IconFactoryParserData;
+
+typedef struct {
+  gchar            *stock_id;
+  gchar            *filename;
+  gchar            *icon_name;
+  GtkTextDirection  direction;
+  GtkIconSize       size;
+  GtkStateType      state;
+} IconSourceParserData;
+
+static void
+icon_source_start_element (GMarkupParseContext  *context,
+                           const gchar          *element_name,
+                           const gchar         **names,
+                           const gchar         **values,
+                           gpointer              user_data,
+                           GError              **error)
+{
+  gint i;
+  gchar *stock_id = NULL;
+  gchar *filename = NULL;
+  gchar *icon_name = NULL;
+  gint size = -1;
+  gint direction = -1;
+  gint state = -1;
+  IconFactoryParserData *parser_data;
+  IconSourceParserData *source_data;
+  gchar *error_msg;
+  GQuark error_domain;
+
+  parser_data = (IconFactoryParserData*)user_data;
+
+  if (!parser_data->in_source)
+    {
+      if (strcmp (element_name, "sources") != 0)
+        {
+          error_msg = g_strdup_printf ("Unexpected element %s, expected <sources>", element_name);
+          error_domain = GTK_BUILDER_ERROR_INVALID_TAG;
+          goto error;
+        }
+      parser_data->in_source = TRUE;
+      return;
+    }
+  else
+    {
+      if (strcmp (element_name, "source") != 0)
+        {
+          error_msg = g_strdup_printf ("Unexpected element %s, expected <source>", element_name);
+          error_domain = GTK_BUILDER_ERROR_INVALID_TAG;
+          goto error;
+        }
+    }
+
+  for (i = 0; names[i]; i++)
+    {
+      if (strcmp (names[i], "stock-id") == 0)
+        stock_id = g_strdup (values[i]);
+      else if (strcmp (names[i], "filename") == 0)
+        filename = g_strdup (values[i]);
+      else if (strcmp (names[i], "icon-name") == 0)
+        icon_name = g_strdup (values[i]);
+      else if (strcmp (names[i], "size") == 0)
+        {
+          if (!_gtk_builder_enum_from_string (GTK_TYPE_ICON_SIZE,
+                                              values[i],
+                                              &size,
+                                              error))
+            return;
+        }
+      else if (strcmp (names[i], "direction") == 0)
+        {
+          if (!_gtk_builder_enum_from_string (GTK_TYPE_TEXT_DIRECTION,
+                                              values[i],
+                                              &direction,
+                                              error))
+            return;
+        }
+      else if (strcmp (names[i], "state") == 0)
+        {
+          if (!_gtk_builder_enum_from_string (GTK_TYPE_STATE_TYPE,
+                                              values[i],
+                                              &state,
+                                              error))
+            return;
+        }
+      else
+        {
+          error_msg = g_strdup_printf ("'%s' is not a valid attribute of <%s>",
+                                       names[i], "source");
+          error_domain = GTK_BUILDER_ERROR_INVALID_ATTRIBUTE;
+          goto error;
+        }
+    }
+
+  if (!stock_id)
+    {
+      error_msg = g_strdup_printf ("<source> requires a stock_id");
+      error_domain = GTK_BUILDER_ERROR_MISSING_ATTRIBUTE;
+      goto error;
+    }
+
+  source_data = g_slice_new (IconSourceParserData);
+  source_data->stock_id = stock_id;
+  source_data->filename = filename;
+  source_data->icon_name = icon_name;
+  source_data->size = size;
+  source_data->direction = direction;
+  source_data->state = state;
+
+  parser_data->sources = g_slist_prepend (parser_data->sources, source_data);
+  return;
+
+ error:
+  {
+    gchar *tmp;
+    gint line_number, char_number;
+
+    g_markup_parse_context_get_position (context, &line_number, &char_number);
+
+    tmp = g_strdup_printf ("%s:%d:%d %s", "input",
+                           line_number, char_number, error_msg);
+    g_set_error_literal (error, GTK_BUILDER_ERROR, error_domain, tmp);
+    g_free (tmp);
+    g_free (stock_id);
+    g_free (filename);
+    g_free (icon_name);
+    return;
+  }
+}
+
+static const GMarkupParser icon_source_parser =
+  {
+    icon_source_start_element,
+  };
+
+static gboolean
+gtk_icon_factory_buildable_custom_tag_start (GtkBuildable     *buildable,
+                                            GtkBuilder       *builder,
+                                            GObject          *child,
+                                            const gchar      *tagname,
+                                            GMarkupParser    *parser,
+                                            gpointer         *data)
+{
+  g_assert (buildable);
+
+  if (strcmp (tagname, "sources") == 0)
+    {
+      IconFactoryParserData *parser_data;
+
+      parser_data = g_slice_new0 (IconFactoryParserData);
+      *parser = icon_source_parser;
+      *data = parser_data;
+      return TRUE;
+    }
+  return FALSE;
+}
+
+static void
+gtk_icon_factory_buildable_custom_tag_end (GtkBuildable *buildable,
+                                          GtkBuilder   *builder,
+                                          GObject      *child,
+                                          const gchar  *tagname,
+                                          gpointer     *user_data)
+{
+  GtkIconFactory *icon_factory;
+
+  icon_factory = GTK_ICON_FACTORY (buildable);
+
+  if (strcmp (tagname, "sources") == 0)
+    {
+      IconFactoryParserData *parser_data;
+      GtkIconSource *icon_source;
+      GtkIconSet *icon_set;
+      GSList *l;
+
+      parser_data = (IconFactoryParserData*)user_data;
+
+      for (l = parser_data->sources; l; l = l->next)
+       {
+         IconSourceParserData *source_data = l->data;
+
+         icon_set = gtk_icon_factory_lookup (icon_factory, source_data->stock_id);
+         if (!icon_set)
+           {
+             icon_set = gtk_icon_set_new ();
+             gtk_icon_factory_add (icon_factory, source_data->stock_id, icon_set);
+              gtk_icon_set_unref (icon_set);
+           }
+
+         icon_source = gtk_icon_source_new ();
+
+         if (source_data->filename)
+           {
+             gchar *filename;
+             filename = _gtk_builder_get_absolute_filename (builder, source_data->filename);
+             gtk_icon_source_set_filename (icon_source, filename);
+             g_free (filename);
+           }
+         if (source_data->icon_name)
+           gtk_icon_source_set_icon_name (icon_source, source_data->icon_name);
+         if (source_data->size != -1)
+            {
+              gtk_icon_source_set_size (icon_source, source_data->size);
+              gtk_icon_source_set_size_wildcarded (icon_source, FALSE);
+            }
+         if (source_data->direction != -1)
+            {
+              gtk_icon_source_set_direction (icon_source, source_data->direction);
+              gtk_icon_source_set_direction_wildcarded (icon_source, FALSE);
+            }
+         if (source_data->state != -1)
+            {
+              gtk_icon_source_set_state (icon_source, source_data->state);
+              gtk_icon_source_set_state_wildcarded (icon_source, FALSE);
+            }
+
+         /* Inline source_add() to avoid creating a copy */
+         g_assert (icon_source->type != GTK_ICON_SOURCE_EMPTY);
+         icon_set->sources = g_slist_insert_sorted (icon_set->sources,
+                                                    icon_source,
+                                                    icon_source_compare);
+
+         g_free (source_data->stock_id);
+         g_free (source_data->filename);
+         g_free (source_data->icon_name);
+         g_slice_free (IconSourceParserData, source_data);
+       }
+      g_slist_free (parser_data->sources);
+      g_slice_free (IconFactoryParserData, parser_data);
+
+      /* TODO: Add an attribute/tag to prevent this.
+       * Usually it's the right thing to do though.
+       */
+      gtk_icon_factory_add_default (icon_factory);
+    }
+}