Code

Restore base legacy name support
[inkscape.git] / src / widgets / icon.cpp
index b460258edb78d5ee0f9e5912d3691aaf3cf7a78d..ec3af771e4e6ada345c3030eca7162b40243ce6a 100644 (file)
 
 #include <cstring>
 #include <glib/gmem.h>
-#include <gtk/gtkiconfactory.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtkimage.h>
-#include <gtkmm/iconfactory.h>
-#include <gtkmm/iconset.h>
-#include <gtkmm/iconsource.h>
-#include <gtkmm/icontheme.h>
-#include <gtkmm/image.h>
+#include <gtk/gtk.h>
+#include <gtkmm.h>
 
 #include "path-prefix.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "inkscape.h"
 #include "document.h"
 #include "sp-item.h"
 
 #include "icon.h"
 
-static gboolean icon_prerender_task(gpointer data);
-
-static void addPreRender( Inkscape::IconSize lsize, gchar const *name );
-
 static void sp_icon_class_init(SPIconClass *klass);
 static void sp_icon_init(SPIcon *icon);
-static void sp_icon_destroy(GtkObject *object);
+static void sp_icon_dispose(GObject *object);
 
 static void sp_icon_reset(SPIcon *icon);
 static void sp_icon_clear(SPIcon *icon);
@@ -59,7 +49,7 @@ static void sp_icon_style_set( GtkWidget *widget, GtkStyle *previous_style );
 static void sp_icon_theme_changed( SPIcon *icon );
 
 static GdkPixbuf *sp_icon_image_load_pixmap(gchar const *name, unsigned lsize, unsigned psize);
-static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsigned psize);
+static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, GtkIconSize lsize, unsigned psize);
 
 static void sp_icon_overlay_pixels( guchar *px, int width, int height, int stride,
                                     unsigned r, unsigned g, unsigned b );
@@ -85,32 +75,38 @@ static GtkIconSize iconSizeLookup[] = {
 class IconCacheItem
 {
 public:
-    IconCacheItem( Inkscape::IconSize lsize, GdkPixbuf* pb ) :
+    IconCacheItem( GtkIconSize lsize, GdkPixbuf* pb ) :
         _lsize( lsize ),
         _pb( pb )
     {}
-    Inkscape::IconSize _lsize;
+    GtkIconSize _lsize;
     GdkPixbuf* _pb;
 };
 
 static Glib::RefPtr<Gtk::IconFactory> inkyIcons;
-static std::map<Glib::ustring, std::vector<IconCacheItem> > iconSetCache;
-static std::map<gpointer, gulong> mapHandlerMap;
 
-GtkType
+GType
 sp_icon_get_type()
 {
-    static GtkType type = 0;
+    //TODO: switch to GObject
+    // GtkType and such calls were deprecated a while back with the
+    // introduction of GObject as a separate layer, with GType instead. --JonCruz
+
+    static GType type = 0;
     if (!type) {
-        GtkTypeInfo info = {
-            "SPIcon",
-            sizeof(SPIcon),
+        GTypeInfo info = {
             sizeof(SPIconClass),
-            (GtkClassInitFunc) sp_icon_class_init,
-            (GtkObjectInitFunc) sp_icon_init,
-            NULL, NULL, NULL
+            NULL,
+            NULL,
+            (GClassInitFunc) sp_icon_class_init,
+            NULL,
+            NULL,
+            sizeof(SPIcon),
+            0,
+            (GInstanceInitFunc) sp_icon_init,
+            NULL
         };
-        type = gtk_type_unique(GTK_TYPE_WIDGET, &info);
+        type = g_type_register_static(GTK_TYPE_WIDGET, "SPIcon", &info, (GTypeFlags)0);
     }
     return type;
 }
@@ -118,15 +114,15 @@ sp_icon_get_type()
 static void
 sp_icon_class_init(SPIconClass *klass)
 {
-    GtkObjectClass *object_class;
+    GObjectClass *object_class;
     GtkWidgetClass *widget_class;
 
-    object_class = (GtkObjectClass *) klass;
+    object_class = (GObjectClass *) klass;
     widget_class = (GtkWidgetClass *) klass;
 
     parent_class = (GtkWidgetClass*)g_type_class_peek_parent(klass);
 
-    object_class->destroy = sp_icon_destroy;
+    object_class->dispose = sp_icon_dispose;
 
     widget_class->size_request = sp_icon_size_request;
     widget_class->size_allocate = sp_icon_size_allocate;
@@ -144,11 +140,10 @@ sp_icon_init(SPIcon *icon)
     icon->psize = 0;
     icon->name = 0;
     icon->pb = 0;
-    icon->pb_faded = 0;
 }
 
 static void
-sp_icon_destroy(GtkObject *object)
+sp_icon_dispose(GObject *object)
 {
     SPIcon *icon = SP_ICON(object);
     sp_icon_clear(icon);
@@ -157,7 +152,7 @@ sp_icon_destroy(GtkObject *object)
         icon->name = 0;
     }
 
-    ((GtkObjectClass *) (parent_class))->destroy(object);
+    ((GObjectClass *) (parent_class))->dispose(object);
 }
 
 static void sp_icon_reset( SPIcon *icon ) {
@@ -170,10 +165,6 @@ static void sp_icon_clear( SPIcon *icon ) {
         g_object_unref(G_OBJECT(icon->pb));
         icon->pb = NULL;
     }
-    if (icon->pb_faded) {
-        g_object_unref(G_OBJECT(icon->pb_faded));
-        icon->pb_faded = NULL;
-    }
 }
 
 static void
@@ -218,16 +209,24 @@ void sp_icon_fetch_pixbuf( SPIcon *icon )
     if ( icon ) {
         if ( !icon->pb ) {
             icon->psize = sp_icon_get_phys_size(icon->lsize);
+            GtkIconTheme *theme = gtk_icon_theme_get_default();
 
-            GdkPixbuf *pb = sp_icon_image_load_svg( icon->name, icon->lsize, icon->psize );
+            GdkPixbuf *pb = 0;
+            if (gtk_icon_theme_has_icon(theme, icon->name)) {
+                pb = gtk_icon_theme_load_icon(theme, icon->name, icon->psize, (GtkIconLookupFlags) 0, NULL);
+            }
+            if (!pb) {
+                pb = sp_icon_image_load_svg( icon->name, Inkscape::getRegisteredIconSize(icon->lsize), icon->psize );
+                // if this was loaded from SVG, add it as a builtin icon
+                if (pb) {
+                    gtk_icon_theme_add_builtin_icon(icon->name, icon->psize, pb);
+                }
+            }
             if (!pb) {
                 pb = sp_icon_image_load_pixmap( icon->name, icon->lsize, icon->psize );
             }
-
             if ( pb ) {
                 icon->pb = pb;
-                icon->pb_faded = gdk_pixbuf_copy(icon->pb);
-                gdk_pixbuf_saturate_and_pixelate(icon->pb, icon->pb_faded, 0.5, TRUE);
             } else {
                 /* TODO: We should do something more useful if we can't load the image. */
                 g_warning ("failed to load icon '%s'", icon->name);
@@ -263,9 +262,6 @@ static void sp_icon_theme_changed( SPIcon *icon )
 }
 
 
-static void imageMapCB(GtkWidget* widget, gpointer user_data);
-static void populate_placeholder_icon(gchar const* name, unsigned lsize);
-static bool prerender_icon(gchar const *name, unsigned lsize, unsigned psize);
 static Glib::ustring icon_cache_key(gchar const *name, unsigned lsize, unsigned psize);
 static GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key);
 
@@ -280,57 +276,76 @@ static void setupLegacyNaming() {
 static GtkWidget *
 sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
 {
-    static gint dump = prefs_get_int_attribute_limited( "debug.icons", "dumpGtk", 0, 0, 1 );
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    static bool dump = prefs->getBool( "/debug/icons/dumpGtk");
 
     GtkWidget *widget = 0;
-        gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
+    gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
+    if ( !sizeMapDone ) {
+        injectCustomSize();
+    }
+    GtkIconSize mappedSize = iconSizeLookup[trySize];
 
-        if ( !sizeMapDone ) {
-            injectCustomSize();
-        }
+    GtkStockItem stock;
+    gboolean stockFound = gtk_stock_lookup( name, &stock );
 
-        GtkStockItem stock;
-        gboolean stockFound = gtk_stock_lookup( name, &stock );
+    GtkWidget *img = 0;
+    if ( legacyNames.empty() ) {
+        setupLegacyNaming();
+    }
 
-        GtkWidget *img = 0;
-        if ( legacyNames.empty() ) {
-            setupLegacyNaming();
+    if ( stockFound ) {
+        img = gtk_image_new_from_stock( name, mappedSize );
+    }
+    else if ( legacyNames.find(name) != legacyNames.end() ) {
+        img = gtk_image_new_from_icon_name( name, mappedSize );
+        if ( dump ) {
+            g_message("gtk_image_new_from_icon_name( '%s', %d ) = %p", name, mappedSize, img);
+            GtkImageType thing = gtk_image_get_storage_type(GTK_IMAGE(img));
+            g_message("      Type is %d  %s", (int)thing, (thing == GTK_IMAGE_EMPTY ? "Empty" : "ok"));
         }
+    }
 
-        if ( legacyNames.find(name) != legacyNames.end() ) {
-            img = gtk_image_new_from_icon_name( name, iconSizeLookup[trySize] );
-        } else {
-            img = gtk_image_new_from_stock( name, iconSizeLookup[trySize] );
-        }
-        if ( img ) {
-            GtkImageType type = gtk_image_get_storage_type( GTK_IMAGE(img) );
-            if ( type == GTK_IMAGE_STOCK ) {
-                if ( !stockFound ) {
-                    // It's not showing as a stock ID, so assume it will be present internally
-                    populate_placeholder_icon( name, lsize );
-                    addPreRender( lsize, name );
-
-                    // Add a hook to render if set visible before prerender is done.
-                    gulong handlerId = g_signal_connect( G_OBJECT(img), "map", G_CALLBACK(imageMapCB), GINT_TO_POINTER(0) );
-                    mapHandlerMap[img] = handlerId;
-                }
-                widget = GTK_WIDGET(img);
-                img = 0;
+    if ( img ) {
+        GtkImageType type = gtk_image_get_storage_type( GTK_IMAGE(img) );
+        if ( type == GTK_IMAGE_STOCK ) {
+            if ( !stockFound ) {
+                // It's not showing as a stock ID, so assume it will be present internally
+                // TODO restore: populate_placeholder_icon( name, mappedSize );
+                // TODO restore: addPreRender( mappedSize, name );
+
+                // Add a hook to render if set visible before prerender is done.
+                // TODO restore g_signal_connect( G_OBJECT(img), "map", G_CALLBACK(imageMapCB), GINT_TO_POINTER(static_cast<int>(mappedSize)) );
                 if ( dump ) {
-                    g_message( "loaded gtk  '%s' %d  (GTK_IMAGE_STOCK) %s", name, lsize, (stockFound ? "STOCK" : "local") );
+                    g_message("      connecting %p for imageMapCB for [%s] %d", img, name, (int)mappedSize);
                 }
-            } else if ( type == GTK_IMAGE_ICON_NAME ) {
-                widget = GTK_WIDGET(img);
-                img = 0;
-                addPreRender( lsize, name );
+            }
+            widget = GTK_WIDGET(img);
+            img = 0;
+            if ( dump ) {
+                g_message( "loaded gtk  '%s' %d  (GTK_IMAGE_STOCK) %s  on %p", name, mappedSize, (stockFound ? "STOCK" : "local"), widget );
+            }
+        } else if ( type == GTK_IMAGE_ICON_NAME ) {
+            widget = GTK_WIDGET(img);
+            img = 0;
+
+            // Add a hook to render if set visible before prerender is done.
+            // TODO restore g_signal_connect( G_OBJECT(widget), "map", G_CALLBACK(imageMapNamedCB), GINT_TO_POINTER(0) );
+
+            if ( prefs->getBool("/options/iconrender/named_nodelay") ) {
+                // TODO restore int psize = sp_icon_get_phys_size(lsize);
+                // TODO restore prerender_icon(name, mappedSize, psize);
             } else {
-                if ( dump ) {
-                    g_message( "skipped gtk '%s' %d  (not GTK_IMAGE_STOCK)", name, lsize );
-                }
-                //g_object_unref( (GObject *)img );
-                img = 0;
+                // TODO restore addPreRender( mappedSize, name );
+            }
+        } else {
+            if ( dump ) {
+                g_message( "skipped gtk '%s' %d  (not GTK_IMAGE_STOCK)", name, lsize );
             }
+            //g_object_unref( (GObject *)img );
+            img = 0;
         }
+    }
 
     if ( !widget ) {
         //g_message("Creating an SPIcon instance for %s:%d", name, (int)lsize);
@@ -355,7 +370,7 @@ sp_icon_new( Inkscape::IconSize lsize, gchar const *name )
 Gtk::Widget *sp_icon_get_icon( Glib::ustring const &oid, Inkscape::IconSize size )
 {
     Gtk::Widget *result = 0;
-    GtkWidget *widget = sp_icon_new_full( size, oid.c_str() );
+    GtkWidget *widget = sp_icon_new_full( static_cast<Inkscape::IconSize>(Inkscape::getRegisteredIconSize(size)), oid.c_str() );
 
     if ( widget ) {
         if ( GTK_IS_IMAGE(widget) ) {
@@ -383,12 +398,14 @@ sp_icon_get_gtk_size(int size)
     return sizemap[size];
 }
 
+
 static void injectCustomSize()
 {
     // TODO - still need to handle the case of theme changes and resize, especially as we can't re-register a string.
     if ( !sizeMapDone )
     {
-        gint dump = prefs_get_int_attribute_limited( "debug.icons", "dumpDefault", 0, 0, 1 );
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        bool dump = prefs->getBool( "/debug/icons/dumpDefault");
         gint width = 0;
         gint height = 0;
         if ( gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height ) ) {
@@ -418,6 +435,21 @@ static void injectCustomSize()
     }
 }
 
+GtkIconSize Inkscape::getRegisteredIconSize( Inkscape::IconSize size )
+{
+    GtkIconSize other = GTK_ICON_SIZE_MENU;
+    injectCustomSize();
+    size = CLAMP( size, Inkscape::ICON_SIZE_MENU, Inkscape::ICON_SIZE_DECORATION );
+    if ( size == Inkscape::ICON_SIZE_DECORATION ) {
+        other = gtk_icon_size_from_name("inkscape-decoration");
+    } else {
+        other = static_cast<GtkIconSize>(size);
+    }
+
+    return other;
+}
+
+
 // PUBLIC CALL:
 int sp_icon_get_phys_size(int size)
 {
@@ -458,7 +490,8 @@ int sp_icon_get_phys_size(int size)
 
     if ( !init ) {
         sizeDirty = false;
-        gint dump = prefs_get_int_attribute_limited( "debug.icons", "dumpDefault", 0, 0, 1 );
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+        bool dump = prefs->getBool("/debug/icons/dumpDefault");
 
         if ( dump ) {
             g_message( "Default icon sizes:" );
@@ -527,40 +560,52 @@ int sp_icon_get_phys_size(int size)
         init = true;
     }
 
+    // Fixup workaround
+    if ((size == GTK_ICON_SIZE_MENU) || (size == GTK_ICON_SIZE_SMALL_TOOLBAR) || (size == GTK_ICON_SIZE_LARGE_TOOLBAR)) {
+        gint width = 0;
+        gint height = 0;
+        if ( gtk_icon_size_lookup( static_cast<GtkIconSize>(size), &width, &height ) ) {
+            vals[size] = std::max( width, height );
+        }
+    }
+
     return vals[size];
 }
 
-static void sp_icon_paint(SPIcon *icon, GdkRectangle const *area)
+static void sp_icon_paint(SPIcon *icon, GdkRectangle const */*area*/)
 {
     GtkWidget &widget = *GTK_WIDGET(icon);
+    GdkPixbuf *image = icon->pb;
+    bool unref_image = false;
 
-    GdkPixbuf *image = GTK_WIDGET_IS_SENSITIVE(&widget) ? icon->pb : icon->pb_faded;
+    /* copied from the expose function of GtkImage */
+    if (GTK_WIDGET_STATE (icon) != GTK_STATE_NORMAL && image) {
+        GtkIconSource *source = gtk_icon_source_new();
+        gtk_icon_source_set_pixbuf(source, icon->pb);
+        gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used
+        gtk_icon_source_set_size_wildcarded(source, FALSE);
+        image = gtk_style_render_icon (widget.style, source, gtk_widget_get_direction(&widget),
+            (GtkStateType) GTK_WIDGET_STATE(&widget), (GtkIconSize)-1, &widget, "gtk-image");
+        gtk_icon_source_free(source);
+        unref_image = true;
+    }
 
     if (image) {
-        int const padx = ( ( widget.allocation.width > icon->psize )
-                           ? ( widget.allocation.width - icon->psize ) / 2
-                           : 0 );
-        int const pady = ( ( widget.allocation.height > icon->psize )
-                           ? ( widget.allocation.height - icon->psize ) / 2
-                           : 0 );
-
-        int const x0 = std::max(area->x, widget.allocation.x + padx);
-        int const y0 = std::max(area->y, widget.allocation.y + pady);
-        int const x1 = std::min(area->x + area->width,  widget.allocation.x + padx + static_cast<int>(icon->psize) );
-        int const y1 = std::min(area->y + area->height, widget.allocation.y + pady + static_cast<int>(icon->psize) );
-
-        int width = x1 - x0;
-        int height = y1 - y0;
+        int x = floor(widget.allocation.x + ((widget.allocation.width - widget.requisition.width) * 0.5));
+        int y = floor(widget.allocation.y + ((widget.allocation.height - widget.requisition.height) * 0.5));
+        int width = gdk_pixbuf_get_width(image);
+        int height = gdk_pixbuf_get_height(image);
         // Limit drawing to when we actually have something. Avoids some crashes.
         if ( (width > 0) && (height > 0) ) {
-            gdk_draw_pixbuf(GDK_DRAWABLE(widget.window), NULL, image,
-                            x0 - widget.allocation.x - padx,
-                            y0 - widget.allocation.y - pady,
-                            x0, y0,
-                            width, height,
-                            GDK_RGB_DITHER_NORMAL, x0, y0);
+            gdk_draw_pixbuf(GDK_DRAWABLE(widget.window), widget.style->black_gc, image,
+                            0, 0, x, y, width, height,
+                            GDK_RGB_DITHER_NORMAL, x, y);
         }
     }
+
+    if (unref_image) {
+        g_object_unref(G_OBJECT(image));
+    }
 }
 
 GdkPixbuf *sp_icon_image_load_pixmap(gchar const *name, unsigned /*lsize*/, unsigned psize)
@@ -615,7 +660,8 @@ extern "C" guchar *
 sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                   gchar const *name, unsigned psize )
 {
-    gint const dump = prefs_get_int_attribute_limited( "debug.icons", "dumpSvg", 0, 0, 1 );
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    bool const dump = prefs->getBool("/debug/icons/dumpSvg");
     guchar *px = NULL;
 
     if (doc) {
@@ -623,7 +669,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
         if (object && SP_IS_ITEM(object)) {
             /* Find bbox in document */
             Geom::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
-            boost::optional<Geom::Rect> dbox = SP_ITEM(object)->getBounds(i2doc);
+            Geom::OptRect dbox = SP_ITEM(object)->getBounds(i2doc);
 
             if ( SP_OBJECT_PARENT(object) == NULL )
             {
@@ -632,12 +678,12 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
             }
 
             /* This is in document coordinates, i.e. pixels */
-            if ( dbox && !dbox->isEmpty() ) {
+            if ( dbox ) {
                 NRGC gc(NULL);
                 /* Update to renderable state */
                 double sf = 1.0;
-                nr_arena_item_set_transform(root, from_2geom(Geom::Scale(sf, sf)));
-                gc.transform.set_identity();
+                nr_arena_item_set_transform(root, (Geom::Matrix)Geom::Scale(sf, sf));
+                gc.transform.setIdentity();
                 nr_arena_item_invoke_update( root, NULL, &gc,
                                              NR_ARENA_ITEM_STATE_ALL,
                                              NR_ARENA_ITEM_STATE_NONE );
@@ -668,8 +714,8 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                         }
                         sf = (double)psize / (double)block;
 
-                        nr_arena_item_set_transform(root, from_2geom(Geom::Scale(sf, sf)));
-                        gc.transform.set_identity();
+                        nr_arena_item_set_transform(root, (Geom::Matrix)Geom::Scale(sf, sf));
+                        gc.transform.setIdentity();
                         nr_arena_item_invoke_update( root, NULL, &gc,
                                                      NR_ARENA_ITEM_STATE_ALL,
                                                      NR_ARENA_ITEM_STATE_NONE );
@@ -728,7 +774,7 @@ sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
                                              NR_ARENA_ITEM_RENDER_NO_CACHE );
                 nr_pixblock_release(&B);
 
-                gint useOverlay = prefs_get_int_attribute_limited( "debug.icons", "overlaySvg", 0, 0, 1 );
+                bool useOverlay = prefs->getBool("/debug/icons/overlaySvg");
                 if ( useOverlay ) {
                     sp_icon_overlay_pixels( px, psize, psize, 4 * psize, 0x00, 0x00, 0xff );
                 }
@@ -769,6 +815,22 @@ GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key) {
     return NULL;
 }
 
+static std::list<gchar*> &icons_svg_paths()
+{
+    static std::list<gchar *> sources;
+    static bool initialized = false;
+    if (!initialized) {
+        // Fall back from user prefs dir into system locations.
+        gchar *userdir = profile_path("icons");
+        sources.push_back(g_build_filename(userdir,"icons.svg", NULL));
+        sources.push_back(g_build_filename(INKSCAPE_PIXMAPDIR, "icons.svg", NULL));
+        g_free(userdir);
+        initialized = true;
+    }
+    return sources;
+}
+
+// this function renders icons from icons.svg and returns the pixels.
 static guchar *load_svg_pixels(gchar const *name,
                                unsigned /*lsize*/, unsigned psize)
 {
@@ -776,19 +838,12 @@ static guchar *load_svg_pixels(gchar const *name,
     NRArenaItem *root = NULL;
     svg_doc_cache_t *info = NULL;
 
-    // Fall back from user prefs dir into system locations.
-    Glib::ustring iconsvg = name;
-    iconsvg += ".svg";
-    std::list<gchar *> sources;
-    sources.push_back(g_build_filename(profile_path("icons"),iconsvg.c_str(), NULL));
-    sources.push_back(g_build_filename(profile_path("icons"),"icons.svg", NULL));
-    sources.push_back(g_build_filename(INKSCAPE_PIXMAPDIR, iconsvg.c_str(), NULL));
-    sources.push_back(g_build_filename(INKSCAPE_PIXMAPDIR, "icons.svg", NULL));
+    std::list<gchar *> &sources = icons_svg_paths();
 
     // Try each document in turn until we successfully load the icon from one
     guchar *px=NULL;
-    while ( !sources.empty() && !px ) {
-        gchar *doc_filename = sources.front();
+    for (std::list<gchar*>::iterator i = sources.begin(); i != sources.end() && !px; ++i) {
+        gchar *doc_filename = *i;
 
         // Did we already load this doc?
         Glib::ustring key(doc_filename);
@@ -805,6 +860,7 @@ static guchar *load_svg_pixels(gchar const *name,
             Inkscape::IO::file_test( doc_filename, G_FILE_TEST_IS_REGULAR ) &&
             (doc = sp_document_new( doc_filename, FALSE )) ) {
 
+            //g_message("Loaded icon file %s", doc_filename);
             // prep the document
             sp_document_ensure_up_to_date(doc);
             /* Create new arena */
@@ -828,89 +884,24 @@ static guchar *load_svg_pixels(gchar const *name,
             root=info->root;
         }
 
-        // toss the filename
-        g_free(doc_filename);
-        sources.pop_front();
-
         // move on to the next document if we couldn't get anything
-        if (!info && !doc) continue;
+        if (!info && !doc) {
+            continue;
+        }
 
         px = sp_icon_doc_icon( doc, root, name, psize );
+//         if (px) {
+//             g_message("Found icon %s in %s", name, doc_filename);
+//         }
     }
 
+//     if (!px) {
+//         g_message("Not found icon %s", name);
+//     }
     return px;
 }
 
-static void populate_placeholder_icon(gchar const* name, unsigned lsize)
-{
-    if ( iconSetCache.find(name) == iconSetCache.end() ) {
-        // only add a placeholder if nothing is already set
-        Gtk::IconSet icnset;
-        Gtk::IconSource src;
-        src.set_icon_name( GTK_STOCK_MISSING_IMAGE );
-        src.set_size( Gtk::IconSize(lsize) );
-        icnset.add_source(src);
-        inkyIcons->add(Gtk::StockID(name), icnset);
-    }
-}
-
-static void addToIconSet(GdkPixbuf* pb, gchar const* name, unsigned lsize, unsigned psize) {
-    GtkStockItem stock;
-    gboolean stockFound = gtk_stock_lookup( name, &stock );
-    if ( !stockFound ) {
-        Gtk::IconTheme::add_builtin_icon( name, psize, Glib::wrap(pb) );
-        //g_message("    set in a builtin for %s:%d:%d", name, lsize, psize);
-    }
-
-    for ( std::vector<IconCacheItem>::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) {
-        if ( it->_lsize == Inkscape::IconSize(lsize) ) {
-            iconSetCache[name].erase(it);
-            break;
-        }
-    }
-    iconSetCache[name].push_back(IconCacheItem(Inkscape::IconSize(lsize), pb));
-
-    Gtk::IconSet icnset;
-    for ( std::vector<IconCacheItem>::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) {
-        Gtk::IconSource src;
-        g_object_ref( G_OBJECT(it->_pb) );
-        src.set_pixbuf( Glib::wrap(it->_pb) );
-        src.set_size( Gtk::IconSize(it->_lsize) );
-        src.set_size_wildcarded( (it->_lsize != 1) || (iconSetCache[name].size() == 1) );
-        src.set_state_wildcarded( true );
-        icnset.add_source(src);
-    }
-    inkyIcons->add(Gtk::StockID(name), icnset);
-}
-
-// returns true if icon needed preloading, false if nothing was done
-bool prerender_icon(gchar const *name, unsigned lsize, unsigned psize)
-{
-    Glib::ustring key = icon_cache_key(name, lsize, psize);
-    GdkPixbuf *pb = get_cached_pixbuf(key);
-    if (pb) {
-        return false;
-    } else {
-        guchar* px = load_svg_pixels(name, lsize, psize);
-        if ( !px ) {
-            // check for a fallback name
-            if ( legacyNames.find(name) != legacyNames.end() ) {
-                px = load_svg_pixels(legacyNames[name].c_str(), lsize, psize);
-            }
-        }
-
-        if (px) {
-            pb = gdk_pixbuf_new_from_data(px, GDK_COLORSPACE_RGB, TRUE, 8,
-                                          psize, psize, psize * 4,
-                                          (GdkPixbufDestroyNotify)g_free, NULL);
-            pb_cache[key] = pb;
-            addToIconSet(pb, name, lsize, psize);
-        }
-        return true;
-    }
-}
-
-static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsigned psize)
+static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, GtkIconSize lsize, unsigned psize)
 {
     Glib::ustring key = icon_cache_key(name, lsize, psize);
 
@@ -923,7 +914,6 @@ static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsi
                                           psize, psize, psize * 4,
                                           (GdkPixbufDestroyNotify)g_free, NULL);
             pb_cache[key] = pb;
-            addToIconSet(pb, name, lsize, psize);
         }
     }
 
@@ -937,21 +927,23 @@ static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsi
 void sp_icon_overlay_pixels(guchar *px, int width, int height, int stride,
                             unsigned r, unsigned g, unsigned b)
 {
-    for ( int y = 0; y < height; y += 4 ) {
+    int bytesPerPixel = 4;
+    int spacing = 4;
+    for ( int y = 0; y < height; y += spacing ) {
         guchar *ptr = px + y * stride;
-        for ( int x = 0; x < width; x += 4 ) {
+        for ( int x = 0; x < width; x += spacing ) {
             *(ptr++) = r;
             *(ptr++) = g;
             *(ptr++) = b;
             *(ptr++) = 0xff;
 
-            ptr += 4 * 3;
+            ptr += bytesPerPixel * (spacing - 1);
         }
     }
 
     if ( width > 1 && height > 1 ) {
         // point at the last pixel
-        guchar *ptr = px + ((height-1) * stride) + ((width - 1) * 4);
+        guchar *ptr = px + ((height-1) * stride) + ((width - 1) * bytesPerPixel);
 
         if ( width > 2 ) {
             px[4] = r;
@@ -989,81 +981,6 @@ void sp_icon_overlay_pixels(guchar *px, int width, int height, int stride,
     }
 }
 
-class preRenderItem
-{
-public:
-    preRenderItem( Inkscape::IconSize lsize, gchar const *name ) :
-        _lsize( lsize ),
-        _name( name )
-    {}
-    Inkscape::IconSize _lsize;
-    Glib::ustring _name;
-};
-
-
-#include <queue>
-
-static std::queue<preRenderItem> pendingRenders;
-static bool callbackHooked = false;
-
-static void addPreRender( Inkscape::IconSize lsize, gchar const *name )
-{
-    if ( !callbackHooked )
-    {
-        callbackHooked = true;
-        g_idle_add_full( G_PRIORITY_LOW, &icon_prerender_task, NULL, NULL );
-    }
-
-    pendingRenders.push(preRenderItem(lsize, name));
-}
-
-gboolean icon_prerender_task(gpointer /*data*/) {
-    if (!pendingRenders.empty()) {
-        bool workDone = false;
-        do {
-            preRenderItem single = pendingRenders.front();
-            pendingRenders.pop();
-            int psize = sp_icon_get_phys_size(single._lsize);
-            workDone = prerender_icon(single._name.c_str(), single._lsize, psize);
-        } while (!pendingRenders.empty() && !workDone);
-    }
-
-    if (!pendingRenders.empty()) {
-        return TRUE;
-    } else {
-        callbackHooked = false;
-        return FALSE;
-    }
-}
-
-void imageMapCB(GtkWidget* widget, gpointer /*user_data*/) {
-    gchar* id = 0;
-    GtkIconSize size = GTK_ICON_SIZE_INVALID;
-    gtk_image_get_stock(GTK_IMAGE(widget), &id, &size);
-    if ( id ) {
-        int psize = sp_icon_get_phys_size(size);
-        prerender_icon(id, size, psize);
-
-        std::vector<IconCacheItem>& iconSet = iconSetCache[id];
-        for ( std::vector<IconCacheItem>::iterator it = iconSet.begin(); it != iconSet.end(); ++it ) {
-            GObject* obj = G_OBJECT(it->_pb);
-            if ( obj ) {
-            }
-        }
-    }
-
-
-    std::map<gpointer, gulong>::iterator it =  mapHandlerMap.find(widget);
-
-    if ( it != mapHandlerMap.end() ) {
-        gulong handlerId = it->second;
-        if ( g_signal_handler_is_connected(widget, handlerId) ) {
-            g_signal_handler_disconnect(widget, handlerId);
-        }
-        mapHandlerMap.erase(it);
-    }
-}
-
 
 /*
   Local Variables: