diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp
index dd7770ac108aca16f27153c6628d89a08add51d9..e7207d94494ed82316a186efa3fdcf9a83429725 100644 (file)
--- a/src/widgets/icon.cpp
+++ b/src/widgets/icon.cpp
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
*
* Copyright (C) 2002 Lauris Kaplinski
*
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include "path-prefix.h"
-
-
+#include <cstring>
#include <glib/gmem.h>
-#include <gtk/gtkiconfactory.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtkimage.h>
-
-#include <gtkmm/image.h>
+#include <glib/gstdio.h>
+#include <gtk/gtk.h>
+#include <gtkmm.h>
+#include <gdkmm/pixbuf.h>
+#include <glibmm/fileutils.h>
-#include "prefs-utils.h"
+#include "path-prefix.h"
+#include "preferences.h"
#include "inkscape.h"
#include "document.h"
#include "sp-item.h"
#include "icon.h"
-static gboolean icon_prerender_task(gpointer data);
+// Bring in work-around for Glib versions missing GStatBuf
+#if !GLIB_CHECK_VERSION(2,25,0)
+#if defined (_MSC_VER) && !defined(_WIN64)
+typedef struct _stat32 GStatBuf;
+#else //defined (_MSC_VER) && !defined(_WIN64)
+typedef struct stat GStatBuf;
+#endif //defined (_MSC_VER) && !defined(_WIN64)
+#endif //!GLIB_CHECK_VERSION(2,25,0)
+
+struct IconImpl {
+ static void classInit(SPIconClass *klass);
+ static void init(SPIcon *icon);
+
+ static GtkWidget *newFull( Inkscape::IconSize lsize, gchar const *name );
+
+ static void dispose(GObject *object);
-static void addPreRender( Inkscape::IconSize lsize, gchar const *name );
+ static void reset(SPIcon *icon);
+ static void clear(SPIcon *icon);
-static void sp_icon_class_init(SPIconClass *klass);
-static void sp_icon_init(SPIcon *icon);
-static void sp_icon_destroy(GtkObject *object);
+ static void sizeRequest(GtkWidget *widget, GtkRequisition *requisition);
+ static void sizeAllocate(GtkWidget *widget, GtkAllocation *allocation);
+ static int expose(GtkWidget *widget, GdkEventExpose *event);
-static void sp_icon_reset(SPIcon *icon);
-static void sp_icon_clear(SPIcon *icon);
+ static void paint(SPIcon *icon, GdkRectangle const *area);
-static void sp_icon_size_request(GtkWidget *widget, GtkRequisition *requisition);
-static void sp_icon_size_allocate(GtkWidget *widget, GtkAllocation *allocation);
-static int sp_icon_expose(GtkWidget *widget, GdkEventExpose *event);
+ static void screenChanged( GtkWidget *widget, GdkScreen *previous_screen );
+ static void styleSet( GtkWidget *widget, GtkStyle *previous_style );
+ static void themeChanged( SPIcon *icon );
-static void sp_icon_paint(SPIcon *icon, GdkRectangle const *area);
+ static int getPhysSize(int size);
+ static void fetchPixbuf( SPIcon *icon );
-static void sp_icon_screen_changed( GtkWidget *widget, GdkScreen *previous_screen );
-static void sp_icon_style_set( GtkWidget *widget, GtkStyle *previous_style );
-static void sp_icon_theme_changed( SPIcon *icon );
+ static gboolean prerenderTask(gpointer data);
+ static void addPreRender( GtkIconSize lsize, gchar const *name );
+ static GdkPixbuf* renderup( gchar const* name, Inkscape::IconSize lsize, unsigned psize );
-static guchar *sp_icon_image_load_pixmap(gchar const *name, unsigned lsize, unsigned psize);
-static guchar *sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsigned psize);
-static guchar *sp_icon_image_load(SPIcon *icon, gchar const *name);
+ static GdkPixbuf *loadPixmap(gchar const *name, unsigned lsize, unsigned psize);
+ static GdkPixbuf *loadSvg(std::list<Glib::ustring> const &names, GtkIconSize lsize, unsigned psize);
-static int sp_icon_get_phys_size(int size);
+ static void overlayPixels( guchar *px, int width, int height, int stride,
+ unsigned r, unsigned g, unsigned b );
-static void sp_icon_overlay_pixels( guchar *px, int width, int height, int stride,
- unsigned r, unsigned g, unsigned b );
+ static void injectCustomSize();
-static void injectCustomSize();
+ static void imageMapCB(GtkWidget* widget, gpointer user_data);
+ static void imageMapNamedCB(GtkWidget* widget, gpointer user_data);
+ static bool prerenderIcon(gchar const *name, GtkIconSize lsize, unsigned psize);
+
+
+ static std::list<gchar*> &icons_svg_paths();
+ static guchar *load_svg_pixels(std::list<Glib::ustring> const &names,
+ unsigned lsize, unsigned psize);
+
+ static std::string fileEscape( std::string const & str );
+
+ static void validateCache();
+ static void setupLegacyNaming();
+
+private:
+ static const std::string magicNumber;
+ static GtkWidgetClass *parent_class;
+ static std::map<Glib::ustring, Glib::ustring> legacyNames;
+};
+
+const std::string IconImpl::magicNumber = "1.0";
+GtkWidgetClass *IconImpl::parent_class = 0;
+std::map<Glib::ustring, Glib::ustring> IconImpl::legacyNames;
-static GtkWidgetClass *parent_class;
static bool sizeDirty = true;
GTK_ICON_SIZE_MENU, // for Inkscape::ICON_SIZE_DECORATION
};
-GtkType
-sp_icon_get_type()
+class IconCacheItem
{
- static GtkType type = 0;
+public:
+ IconCacheItem( GtkIconSize lsize, GdkPixbuf* pb ) :
+ _lsize( lsize ),
+ _pb( pb )
+ {}
+ GtkIconSize _lsize;
+ GdkPixbuf* _pb;
+};
+
+static std::map<Glib::ustring, std::vector<IconCacheItem> > iconSetCache;
+static std::set<Glib::ustring> internalNames;
+
+GType SPIcon::getType()
+{
+ 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,
+ reinterpret_cast<GClassInitFunc>(IconImpl::classInit),
+ NULL,
+ NULL,
+ sizeof(SPIcon),
+ 0,
+ reinterpret_cast<GInstanceInitFunc>(IconImpl::init),
+ NULL
};
- type = gtk_type_unique(GTK_TYPE_WIDGET, &info);
+ type = g_type_register_static(GTK_TYPE_WIDGET, "SPIcon", &info, (GTypeFlags)0);
}
return type;
}
-static void
-sp_icon_class_init(SPIconClass *klass)
+void IconImpl::classInit(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 = IconImpl::dispose;
- widget_class->size_request = sp_icon_size_request;
- widget_class->size_allocate = sp_icon_size_allocate;
- widget_class->expose_event = sp_icon_expose;
- widget_class->screen_changed = sp_icon_screen_changed;
- widget_class->style_set = sp_icon_style_set;
+ widget_class->size_request = IconImpl::sizeRequest;
+ widget_class->size_allocate = IconImpl::sizeAllocate;
+ widget_class->expose_event = IconImpl::expose;
+ widget_class->screen_changed = IconImpl::screenChanged;
+ widget_class->style_set = IconImpl::styleSet;
}
-
-static void
-sp_icon_init(SPIcon *icon)
+void IconImpl::init(SPIcon *icon)
{
GTK_WIDGET_FLAGS(icon) |= GTK_NO_WINDOW;
icon->lsize = Inkscape::ICON_SIZE_BUTTON;
icon->psize = 0;
icon->name = 0;
icon->pb = 0;
- icon->pb_faded = 0;
}
-static void
-sp_icon_destroy(GtkObject *object)
+void IconImpl::dispose(GObject *object)
{
SPIcon *icon = SP_ICON(object);
- sp_icon_clear(icon);
+ clear(icon);
if ( icon->name ) {
g_free( icon->name );
icon->name = 0;
}
- ((GtkObjectClass *) (parent_class))->destroy(object);
+ ((GObjectClass *) (parent_class))->dispose(object);
}
-static void sp_icon_reset( SPIcon *icon ) {
+void IconImpl::reset( SPIcon *icon )
+{
icon->psize = 0;
- sp_icon_clear(icon);
+ clear(icon);
}
-static void sp_icon_clear( SPIcon *icon ) {
+void IconImpl::clear( SPIcon *icon )
+{
if (icon->pb) {
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
-sp_icon_size_request(GtkWidget *widget, GtkRequisition *requisition)
+void IconImpl::sizeRequest(GtkWidget *widget, GtkRequisition *requisition)
{
SPIcon const *icon = SP_ICON(widget);
int const size = ( icon->psize
? icon->psize
- : sp_icon_get_phys_size(icon->lsize) );
+ : getPhysSize(icon->lsize) );
requisition->width = size;
requisition->height = size;
}
-static void
-sp_icon_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
+void IconImpl::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation)
{
widget->allocation = *allocation;
}
}
-static int sp_icon_expose(GtkWidget *widget, GdkEventExpose *event)
+int IconImpl::expose(GtkWidget *widget, GdkEventExpose *event)
{
if ( GTK_WIDGET_DRAWABLE(widget) ) {
SPIcon *icon = SP_ICON(widget);
if ( !icon->pb ) {
- sp_icon_fetch_pixbuf( icon );
+ fetchPixbuf( icon );
}
- sp_icon_paint(SP_ICON(widget), &event->area);
+ paint(icon, &event->area);
}
return TRUE;
}
+// PUBLIC CALL:
void sp_icon_fetch_pixbuf( SPIcon *icon )
+{
+ return IconImpl::fetchPixbuf(icon);
+}
+
+void IconImpl::fetchPixbuf( SPIcon *icon )
{
if ( icon ) {
if ( !icon->pb ) {
- guchar *pixels = 0;
-
- icon->psize = sp_icon_get_phys_size(icon->lsize);
-
- pixels = sp_icon_image_load( icon, icon->name );
-
- if (pixels) {
- // don't pass the g_free because we're caching the pixel
- // space loaded through ...
- // I just changed this. make sure sp_icon_image_load still does the right thing.
- icon->pb = gdk_pixbuf_new_from_data(pixels, GDK_COLORSPACE_RGB, TRUE, 8,
- icon->psize, icon->psize, icon->psize * 4,
- /*(GdkPixbufDestroyNotify)g_free*/NULL, NULL);
- icon->pb_faded = gdk_pixbuf_copy(icon->pb);
-
- pixels = gdk_pixbuf_get_pixels(icon->pb_faded);
- size_t stride = gdk_pixbuf_get_rowstride(icon->pb_faded);
- pixels += 3; // alpha
- for ( int row = 0 ; row < icon->psize ; row++ ) {
- guchar *row_pixels = pixels;
- for ( int column = 0 ; column < icon->psize ; column++ ) {
- *row_pixels = *row_pixels >> 1;
- row_pixels += 4;
- }
- pixels += stride;
- }
- } else {
- /* TODO: We should do something more useful if we can't load the image. */
- g_warning ("failed to load icon '%s'", icon->name);
+ icon->psize = getPhysSize(icon->lsize);
+ icon->pb = renderup(icon->name, icon->lsize, icon->psize);
+ }
+ }
+}
+
+GdkPixbuf* IconImpl::renderup( gchar const* name, Inkscape::IconSize lsize, unsigned psize ) {
+ GtkIconTheme *theme = gtk_icon_theme_get_default();
+
+ GdkPixbuf *pb = 0;
+ if (gtk_icon_theme_has_icon(theme, name)) {
+ pb = gtk_icon_theme_load_icon(theme, name, psize, (GtkIconLookupFlags) 0, NULL);
+ }
+ if (!pb) {
+ std::list<Glib::ustring> names;
+ names.push_back(name);
+ if ( legacyNames.find(name) != legacyNames.end() ) {
+ if ( Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg") ) {
+ g_message("Checking fallback [%s]->[%s]", name, legacyNames[name].c_str());
}
+ names.push_back(legacyNames[name]);
+ }
+
+ pb = loadSvg( names, Inkscape::getRegisteredIconSize(lsize), psize );
+
+ // if this was loaded from SVG, add it as a builtin icon
+ if (pb) {
+ gtk_icon_theme_add_builtin_icon(name, psize, pb);
}
}
+ if (!pb) {
+ pb = loadPixmap( name, lsize, psize );
+ }
+ if ( !pb ) {
+ // TODO: We should do something more useful if we can't load the image.
+ g_warning ("failed to load icon '%s'", name);
+ }
+ return pb;
}
-static void sp_icon_screen_changed( GtkWidget *widget, GdkScreen *previous_screen )
+void IconImpl::screenChanged( GtkWidget *widget, GdkScreen *previous_screen )
{
if ( GTK_WIDGET_CLASS( parent_class )->screen_changed ) {
GTK_WIDGET_CLASS( parent_class )->screen_changed( widget, previous_screen );
}
SPIcon *icon = SP_ICON(widget);
- sp_icon_theme_changed(icon);
+ themeChanged(icon);
}
-static void sp_icon_style_set( GtkWidget *widget, GtkStyle *previous_style )
+void IconImpl::styleSet( GtkWidget *widget, GtkStyle *previous_style )
{
if ( GTK_WIDGET_CLASS( parent_class )->style_set ) {
GTK_WIDGET_CLASS( parent_class )->style_set( widget, previous_style );
}
SPIcon *icon = SP_ICON(widget);
- sp_icon_theme_changed(icon);
+ themeChanged(icon);
}
-static void sp_icon_theme_changed( SPIcon *icon )
+void IconImpl::themeChanged( SPIcon *icon )
{
- //g_message("Got a change bump for this icon");
+ bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg");
+ if ( dump ) {
+ g_message("Got a change bump for this icon");
+ }
sizeDirty = true;
- sp_icon_reset(icon);
+ reset(icon);
gtk_widget_queue_draw( GTK_WIDGET(icon) );
}
+std::string IconImpl::fileEscape( std::string const & str )
+{
+ std::string result;
+ result.reserve(str.size());
+ for ( size_t i = 0; i < str.size(); ++i ) {
+ char ch = str[i];
+ if ( (0x20 <= ch) && !(0x80 & ch) ) {
+ result += ch;
+ } else {
+ result += "\\x";
+ gchar *tmp = g_strdup_printf("%02X", (0x0ff & ch));
+ result += tmp;
+ g_free(tmp);
+ }
+ }
+ return result;
+}
-static GtkWidget *
-sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name )
+static bool isSizedSubdir( std::string const &name )
{
- static gint dump = prefs_get_int_attribute_limited( "debug.icons", "dumpGtk", 0, 0, 1 );
- static gint fallback = prefs_get_int_attribute_limited( "debug.icons", "checkNames", 0, 0, 1 );
+ bool isSized = false;
+ if ( (name.size() > 2) && (name.size() & 1) ) { // needs to be an odd length 3 or more
+ size_t mid = (name.size() - 1) / 2;
+ if ( (name[mid] == 'x') && (name.substr(0, mid) == name.substr(mid + 1)) ) {
+ isSized = true;
+ for ( size_t i = 0; (i < mid) && isSized; ++i ) {
+ isSized &= g_ascii_isdigit(name[i]);
+ }
+ }
+ }
+ return isSized;
+}
- addPreRender( lsize, name );
+void IconImpl::validateCache()
+{
+ std::list<gchar *> &sources = icons_svg_paths();
+ std::string iconCacheDir = Glib::build_filename(Glib::build_filename(Glib::get_user_cache_dir(), "inkscape"), "icons");
+ std::string iconCacheFile = Glib::build_filename( iconCacheDir, "cache.info" );
- GtkStockItem stock;
- gboolean tryLoad = gtk_stock_lookup( name, &stock );
- if ( !tryLoad && fallback ) {
- tryLoad |= strncmp("gtk-", name, 4 ) == 0;
+ std::vector<std::string> filesFound;
+
+ for (std::list<gchar*>::iterator i = sources.begin(); i != sources.end(); ++i) {
+ gchar const* potentialFile = *i;
+ if ( Glib::file_test(potentialFile, Glib::FILE_TEST_EXISTS) && Glib::file_test(potentialFile, Glib::FILE_TEST_IS_REGULAR) ) {
+ filesFound.push_back(*i);
+ }
+ }
+
+ unsigned long lastSeen = 0;
+ std::ostringstream out;
+ out << "Inkscape cache v" << std::hex << magicNumber << std::dec << std::endl;
+ out << "Sourcefiles: " << filesFound.size() << std::endl;
+ for ( std::vector<std::string>::iterator it = filesFound.begin(); it != filesFound.end(); ++it ) {
+ GStatBuf st;
+ memset(&st, 0, sizeof(st));
+ if ( !g_stat(it->c_str(), &st) ) {
+ unsigned long when = st.st_mtime;
+ lastSeen = std::max(lastSeen, when);
+ out << std::hex << when << std::dec << " " << fileEscape(*it) << std::endl;
+ } else {
+ out << "0 " << fileEscape(*it) << std::endl;
+ }
+ }
+ std::string wanted = out.str();
+
+ std::string present;
+ {
+ gchar *contents = 0;
+ if ( g_file_get_contents(iconCacheFile.c_str(), &contents, 0, 0) ) {
+ if ( contents ) {
+ present = contents;
+ }
+ g_free(contents);
+ contents = 0;
+ }
+ }
+ bool cacheValid = (present == wanted);
+
+ if ( cacheValid ) {
+ // Check if any cached rasters are out of date
+ Glib::Dir dir(iconCacheDir);
+ for ( Glib::DirIterator it = dir.begin(); cacheValid && (it != dir.end()); ++it ) {
+ if ( isSizedSubdir(*it) ) {
+ std::string subdirName = Glib::build_filename( iconCacheDir, *it );
+ if ( Glib::file_test(subdirName, Glib::FILE_TEST_IS_DIR) ) {
+ Glib::Dir subdir(subdirName);
+ for ( Glib::DirIterator subit = subdir.begin(); cacheValid && (subit != subdir.end()); ++subit ) {
+ std::string fullpath = Glib::build_filename( subdirName, *subit );
+ if ( Glib::file_test(fullpath, Glib::FILE_TEST_EXISTS) && !Glib::file_test(fullpath, Glib::FILE_TEST_IS_DIR) ) {
+ GStatBuf st;
+ memset(&st, 0, sizeof(st));
+ if ( !g_stat(fullpath.c_str(), &st) ) {
+ unsigned long when = st.st_mtime;
+ if ( when < lastSeen ) {
+ cacheValid = false;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
- if ( !tryLoad && fallback ) {
- tryLoad |= strncmp("gnome-", name, 6 ) == 0;
+
+ if ( !cacheValid ) {
+ if ( Glib::file_test(iconCacheDir, Glib::FILE_TEST_EXISTS) ) {
+ // Purge existing icons, but not possible future sub-directories.
+ if ( Glib::file_test(iconCacheDir, Glib::FILE_TEST_IS_DIR) ) {
+ Glib::Dir dir(iconCacheDir);
+ for ( Glib::DirIterator it = dir.begin(); it != dir.end(); ++it ) {
+ if ( isSizedSubdir(*it) ) {
+ std::string subdirName = Glib::build_filename( iconCacheDir, *it );
+ if ( Glib::file_test(subdirName, Glib::FILE_TEST_IS_DIR) ) {
+ Glib::Dir subdir(subdirName);
+ for ( Glib::DirIterator subit = subdir.begin(); subit != subdir.end(); ++subit ) {
+ std::string fullpath = Glib::build_filename( subdirName, *subit );
+ if ( Glib::file_test(fullpath, Glib::FILE_TEST_EXISTS) && !Glib::file_test(fullpath, Glib::FILE_TEST_IS_DIR) ) {
+ g_remove(fullpath.c_str());
+ }
+ }
+ g_rmdir( subdirName.c_str() );
+ }
+ }
+ }
+ }
+ } else {
+ g_mkdir_with_parents( iconCacheDir.c_str(), 0x1ED );
+ }
+
+ if ( g_file_set_contents(iconCacheFile.c_str(), wanted.c_str(), wanted.size(), 0) ) {
+ // Caching may proceed
+ } else {
+ g_warning("Unable to write cache info file.");
+ }
}
+}
+
+static Glib::ustring icon_cache_key(Glib::ustring const &name, unsigned psize);
+static GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key);
+
+void IconImpl::setupLegacyNaming() {
+ legacyNames["document-import"] ="file_import";
+ legacyNames["document-export"] ="file_export";
+ legacyNames["document-import-ocal"] ="ocal_import";
+ legacyNames["document-export-ocal"] ="ocal_export";
+ legacyNames["document-metadata"] ="document_metadata";
+ legacyNames["dialog-input-devices"] ="input_devices";
+ legacyNames["edit-duplicate"] ="edit_duplicate";
+ legacyNames["edit-clone"] ="edit_clone";
+ legacyNames["edit-clone-unlink"] ="edit_unlink_clone";
+ legacyNames["edit-select-original"] ="edit_select_original";
+ legacyNames["edit-undo-history"] ="edit_undo_history";
+ legacyNames["edit-paste-in-place"] ="selection_paste_in_place";
+ legacyNames["edit-paste-style"] ="selection_paste_style";
+ legacyNames["selection-make-bitmap-copy"] ="selection_bitmap";
+ legacyNames["edit-select-all"] ="selection_select_all";
+ legacyNames["edit-select-all-layers"] ="selection_select_all_in_all_layers";
+ legacyNames["edit-select-invert"] ="selection_invert";
+ legacyNames["edit-select-none"] ="selection_deselect";
+ legacyNames["dialog-xml-editor"] ="xml_editor";
+ legacyNames["zoom-original"] ="zoom_1_to_1";
+ legacyNames["zoom-half-size"] ="zoom_1_to_2";
+ legacyNames["zoom-double-size"] ="zoom_2_to_1";
+ legacyNames["zoom-fit-selection"] ="zoom_select";
+ legacyNames["zoom-fit-drawing"] ="zoom_draw";
+ legacyNames["zoom-fit-page"] ="zoom_page";
+ legacyNames["zoom-fit-width"] ="zoom_pagewidth";
+ legacyNames["zoom-previous"] ="zoom_previous";
+ legacyNames["zoom-next"] ="zoom_next";
+ legacyNames["zoom-in"] ="zoom_in";
+ legacyNames["zoom-out"] ="zoom_out";
+ legacyNames["show-grid"] ="grid";
+ legacyNames["show-guides"] ="guides";
+ legacyNames["color-management"] ="color_management";
+ legacyNames["show-dialogs"] ="dialog_toggle";
+ legacyNames["dialog-messages"] ="messages";
+ legacyNames["dialog-scripts"] ="scripts";
+ legacyNames["window-previous"] ="window_previous";
+ legacyNames["window-next"] ="window_next";
+ legacyNames["dialog-icon-preview"] ="view_icon_preview";
+ legacyNames["window-new"] ="view_new";
+ legacyNames["view-fullscreen"] ="fullscreen";
+ legacyNames["layer-new"] ="new_layer";
+ legacyNames["layer-rename"] ="rename_layer";
+ legacyNames["layer-previous"] ="switch_to_layer_above";
+ legacyNames["layer-next"] ="switch_to_layer_below";
+ legacyNames["selection-move-to-layer-above"] ="move_selection_above";
+ legacyNames["selection-move-to-layer-below"] ="move_selection_below";
+ legacyNames["layer-raise"] ="raise_layer";
+ legacyNames["layer-lower"] ="lower_layer";
+ legacyNames["layer-top"] ="layer_to_top";
+ legacyNames["layer-bottom"] ="layer_to_bottom";
+ legacyNames["layer-delete"] ="delete_layer";
+ legacyNames["dialog-layers"] ="layers";
+ legacyNames["dialog-fill-and-stroke"] ="fill_and_stroke";
+ legacyNames["dialog-object-properties"] ="dialog_item_properties";
+ legacyNames["object-group"] ="selection_group";
+ legacyNames["object-ungroup"] ="selection_ungroup";
+ legacyNames["selection-raise"] ="selection_up";
+ legacyNames["selection-lower"] ="selection_down";
+ legacyNames["selection-top"] ="selection_top";
+ legacyNames["selection-bottom"] ="selection_bot";
+ legacyNames["object-rotate-left"] ="object_rotate_90_CCW";
+ legacyNames["object-rotate-right"] ="object_rotate_90_CW";
+ legacyNames["object-flip-horizontal"] ="object_flip_hor";
+ legacyNames["object-flip-vertical"] ="object_flip_ver";
+ legacyNames["dialog-transform"] ="object_trans";
+ legacyNames["dialog-align-and-distribute"] ="object_align";
+ legacyNames["dialog-rows-and-columns"] ="grid_arrange";
+ legacyNames["object-to-path"] ="object_tocurve";
+ legacyNames["stroke-to-path"] ="stroke_tocurve";
+ legacyNames["bitmap-trace"] ="selection_trace";
+ legacyNames["path-union"] ="union";
+ legacyNames["path-difference"] ="difference";
+ legacyNames["path-intersection"] ="intersection";
+ legacyNames["path-exclusion"] ="exclusion";
+ legacyNames["path-division"] ="division";
+ legacyNames["path-cut"] ="cut_path";
+ legacyNames["path-combine"] ="selection_combine";
+ legacyNames["path-break-apart"] ="selection_break";
+ legacyNames["path-outset"] ="outset_path";
+ legacyNames["path-inset"] ="inset_path";
+ legacyNames["path-offset-dynamic"] ="dynamic_offset";
+ legacyNames["path-offset-linked"] ="linked_offset";
+ legacyNames["path-simplify"] ="simplify";
+ legacyNames["path-reverse"] ="selection_reverse";
+ legacyNames["dialog-text-and-font"] ="object_font";
+ legacyNames["text-put-on-path"] ="put_on_path";
+ legacyNames["text-remove-from-path"] ="remove_from_path";
+ legacyNames["text-flow-into-frame"] ="flow_into_frame";
+ legacyNames["text-unflow"] ="unflow";
+ legacyNames["text-convert-to-regular"] ="convert_to_text";
+ legacyNames["text-unkern"] ="remove_manual_kerns";
+ legacyNames["help-keyboard-shortcuts"] ="help_keys";
+ legacyNames["help-contents"] ="help_tutorials";
+ legacyNames["inkscape-logo"] ="inkscape_options";
+ legacyNames["dialog-memory"] ="about_memory";
+ legacyNames["tool-pointer"] ="draw_select";
+ legacyNames["tool-node-editor"] ="draw_node";
+ legacyNames["tool-tweak"] ="draw_tweak";
+ legacyNames["zoom"] ="draw_zoom";
+ legacyNames["draw-rectangle"] ="draw_rect";
+ legacyNames["draw-cuboid"] ="draw_3dbox";
+ legacyNames["draw-ellipse"] ="draw_arc";
+ legacyNames["draw-polygon-star"] ="draw_star";
+ legacyNames["draw-spiral"] ="draw_spiral";
+ legacyNames["draw-freehand"] ="draw_freehand";
+ legacyNames["draw-path"] ="draw_pen";
+ legacyNames["draw-calligraphic"] ="draw_calligraphic";
+ legacyNames["draw-eraser"] ="draw_erase";
+ legacyNames["color-fill"] ="draw_paintbucket";
+ legacyNames["draw-text"] ="draw_text";
+ legacyNames["draw-connector"] ="draw_connector";
+ legacyNames["color-gradient"] ="draw_gradient";
+ legacyNames["color-picker"] ="draw_dropper";
+ legacyNames["transform-affect-stroke"] ="transform_stroke";
+ legacyNames["transform-affect-rounded-corners"] ="transform_corners";
+ legacyNames["transform-affect-gradient"] ="transform_gradient";
+ legacyNames["transform-affect-pattern"] ="transform_pattern";
+ legacyNames["node-add"] ="node_insert";
+ legacyNames["node-delete"] ="node_delete";
+ legacyNames["node-join"] ="node_join";
+ legacyNames["node-break"] ="node_break";
+ legacyNames["node-join-segment"] ="node_join_segment";
+ legacyNames["node-delete-segment"] ="node_delete_segment";
+ legacyNames["node-type-cusp"] ="node_cusp";
+ legacyNames["node-type-smooth"] ="node_smooth";
+ legacyNames["node-type-symmetric"] ="node_symmetric";
+ legacyNames["node-type-auto-smooth"] ="node_auto";
+ legacyNames["node-segment-curve"] ="node_curve";
+ legacyNames["node-segment-line"] ="node_line";
+ legacyNames["show-node-handles"] ="nodes_show_handles";
+ legacyNames["path-effect-parameter-next"] ="edit_next_parameter";
+ legacyNames["show-path-outline"] ="nodes_show_helperpath";
+ legacyNames["path-clip-edit"] ="nodeedit-clippath";
+ legacyNames["path-mask-edit"] ="nodeedit-mask";
+ legacyNames["node-type-cusp"] ="node_cusp";
+ legacyNames["object-tweak-push"] ="tweak_move_mode";
+ legacyNames["object-tweak-attract"] ="tweak_move_mode_inout";
+ legacyNames["object-tweak-randomize"] ="tweak_move_mode_jitter";
+ legacyNames["object-tweak-shrink"] ="tweak_scale_mode";
+ legacyNames["object-tweak-rotate"] ="tweak_rotate_mode";
+ legacyNames["object-tweak-duplicate"] ="tweak_moreless_mode";
+ legacyNames["object-tweak-push"] ="tweak_move_mode";
+ legacyNames["path-tweak-push"] ="tweak_push_mode";
+ legacyNames["path-tweak-shrink"] ="tweak_shrink_mode";
+ legacyNames["path-tweak-attract"] ="tweak_attract_mode";
+ legacyNames["path-tweak-roughen"] ="tweak_roughen_mode";
+ legacyNames["object-tweak-paint"] ="tweak_colorpaint_mode";
+ legacyNames["object-tweak-jitter-color"] ="tweak_colorjitter_mode";
+ legacyNames["object-tweak-blur"] ="tweak_blur_mode";
+ legacyNames["rectangle-make-corners-sharp"] ="squared_corner";
+ legacyNames["perspective-parallel"] ="toggle_vp_x";
+ legacyNames["draw-ellipse-whole"] ="reset_circle";
+ legacyNames["draw-ellipse-segment"] ="circle_closed_arc";
+ legacyNames["draw-ellipse-arc"] ="circle_open_arc";
+ legacyNames["draw-polygon"] ="star_flat";
+ legacyNames["draw-star"] ="star_angled";
+ legacyNames["path-mode-bezier"] ="bezier_mode";
+ legacyNames["path-mode-spiro"] ="spiro_splines_mode";
+ legacyNames["path-mode-polyline"] ="polylines_mode";
+ legacyNames["path-mode-polyline-paraxial"] ="paraxial_lines_mode";
+ legacyNames["draw-use-tilt"] ="guse_tilt";
+ legacyNames["draw-use-pressure"] ="guse_pressure";
+ legacyNames["draw-trace-background"] ="trace_background";
+ legacyNames["draw-eraser-delete-objects"] ="delete_object";
+ legacyNames["format-text-direction-vertical"] ="writing_mode_tb";
+ legacyNames["format-text-direction-horizontal"] ="writing_mode_lr";
+ legacyNames["connector-avoid"] ="connector_avoid";
+ legacyNames["connector-ignore"] ="connector_ignore";
+ legacyNames["object-fill"] ="controls_fill";
+ legacyNames["object-stroke"] ="controls_stroke";
+ legacyNames["snap"] ="toggle_snap_global";
+ legacyNames["snap-bounding-box"] ="toggle_snap_bbox";
+ legacyNames["snap-bounding-box-edges"] ="toggle_snap_to_bbox_path";
+ legacyNames["snap-bounding-box-corners"] ="toggle_snap_to_bbox_node";
+ legacyNames["snap-bounding-box-midpoints"] ="toggle_snap_to_bbox_edge_midpoints";
+ legacyNames["snap-bounding-box-center"] ="toggle_snap_to_bbox_midpoints";
+ legacyNames["snap-nodes"] ="toggle_snap_nodes";
+ legacyNames["snap-nodes-path"] ="toggle_snap_to_paths";
+ legacyNames["snap-nodes-cusp"] ="toggle_snap_to_nodes";
+ legacyNames["snap-nodes-smooth"] ="toggle_snap_to_smooth_nodes";
+ legacyNames["snap-nodes-midpoint"] ="toggle_snap_to_midpoints";
+ legacyNames["snap-nodes-intersection"] ="toggle_snap_to_path_intersections";
+ legacyNames["snap-nodes-center"] ="toggle_snap_to_bbox_midpoints-3";
+ legacyNames["snap-nodes-rotation-center"] ="toggle_snap_center";
+ legacyNames["snap-page"] ="toggle_snap_page_border";
+ legacyNames["snap-grid-guide-intersections"] ="toggle_snap_grid_guide_intersections";
+ legacyNames["align-horizontal-right-to-anchor"] ="al_left_out";
+ legacyNames["align-horizontal-left"] ="al_left_in";
+ legacyNames["align-horizontal-center"] ="al_center_hor";
+ legacyNames["align-horizontal-right"] ="al_right_in";
+ legacyNames["align-horizontal-left-to-anchor"] ="al_right_out";
+ legacyNames["align-horizontal-baseline"] ="al_baselines_vert";
+ legacyNames["align-vertical-bottom-to-anchor"] ="al_top_out";
+ legacyNames["align-vertical-top"] ="al_top_in";
+ legacyNames["align-vertical-center"] ="al_center_ver";
+ legacyNames["align-vertical-bottom"] ="al_bottom_in";
+ legacyNames["align-vertical-top-to-anchor"] ="al_bottom_out";
+ legacyNames["align-vertical-baseline"] ="al_baselines_hor";
+ legacyNames["distribute-horizontal-left"] ="distribute_left";
+ legacyNames["distribute-horizontal-center"] ="distribute_hcentre";
+ legacyNames["distribute-horizontal-right"] ="distribute_right";
+ legacyNames["distribute-horizontal-baseline"] ="distribute_baselines_hor";
+ legacyNames["distribute-vertical-bottom"] ="distribute_bottom";
+ legacyNames["distribute-vertical-center"] ="distribute_vcentre";
+ legacyNames["distribute-vertical-top"] ="distribute_top";
+ legacyNames["distribute-vertical-baseline"] ="distribute_baselines_vert";
+ legacyNames["distribute-randomize"] ="distribute_randomize";
+ legacyNames["distribute-unclump"] ="unclump";
+ legacyNames["distribute-graph"] ="graph_layout";
+ legacyNames["distribute-graph-directed"] ="directed_graph";
+ legacyNames["distribute-remove-overlaps"] ="remove_overlaps";
+ legacyNames["align-horizontal-node"] ="node_valign";
+ legacyNames["align-vertical-node"] ="node_halign";
+ legacyNames["distribute-vertical-node"] ="node_vdistribute";
+ legacyNames["distribute-horizontal-node"] ="node_hdistribute";
+ legacyNames["xml-element-new"] ="add_xml_element_node";
+ legacyNames["xml-text-new"] ="add_xml_text_node";
+ legacyNames["xml-node-delete"] ="delete_xml_node";
+ legacyNames["xml-node-duplicate"] ="duplicate_xml_node";
+ legacyNames["xml-attribute-delete"] ="delete_xml_attribute";
+ legacyNames["transform-move-horizontal"] ="arrows_hor";
+ legacyNames["transform-move-vertical"] ="arrows_ver";
+ legacyNames["transform-scale-horizontal"] ="transform_scale_hor";
+ legacyNames["transform-scale-vertical"] ="transform_scale_ver";
+ legacyNames["transform-skew-horizontal"] ="transform_scew_hor";
+ legacyNames["transform-skew-vertical"] ="transform_scew_ver";
+ legacyNames["object-fill"] ="properties_fill";
+ legacyNames["object-stroke"] ="properties_stroke_paint";
+ legacyNames["object-stroke-style"] ="properties_stroke";
+ legacyNames["paint-none"] ="fill_none";
+ legacyNames["paint-solid"] ="fill_solid";
+ legacyNames["paint-gradient-linear"] ="fill_gradient";
+ legacyNames["paint-gradient-radial"] ="fill_radial";
+ legacyNames["paint-pattern"] ="fill_pattern";
+ legacyNames["paint-unknown"] ="fill_unset";
+ legacyNames["fill-rule-even-odd"] ="fillrule_evenodd";
+ legacyNames["fill-rule-nonzero"] ="fillrule_nonzero";
+ legacyNames["stroke-join-miter"] ="join_miter";
+ legacyNames["stroke-join-bevel"] ="join_bevel";
+ legacyNames["stroke-join-round"] ="join_round";
+ legacyNames["stroke-cap-butt"] ="cap_butt";
+ legacyNames["stroke-cap-square"] ="cap_square";
+ legacyNames["stroke-cap-round"] ="cap_round";
+ legacyNames["guides"] ="guide";
+ legacyNames["grid-rectangular"] ="grid_xy";
+ legacyNames["grid-axonometric"] ="grid_axonom";
+ legacyNames["object-visible"] ="visible";
+ legacyNames["object-hidden"] ="hidden";
+ legacyNames["object-unlocked"] ="lock_unlocked";
+ legacyNames["object-locked"] ="width_height_lock";
+ legacyNames["zoom"] ="sticky_zoom";
+}
+
+GtkWidget *IconImpl::newFull( Inkscape::IconSize lsize, gchar const *name )
+{
+ static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
GtkWidget *widget = 0;
- if ( tryLoad ) {
- 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 );
+
+ GtkWidget *img = 0;
+ if ( legacyNames.empty() ) {
+ setupLegacyNaming();
+ }
+
+ if ( stockFound ) {
+ img = gtk_image_new_from_stock( name, mappedSize );
+ } else {
+ 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"));
}
+ }
- GtkWidget *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 ) {
- 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
+ addPreRender( mappedSize, name );
+ // Add a hook to render if set visible before prerender is done.
+ 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)", name, lsize );
+ g_message(" connecting %p for imageMapCB for [%s] %d", img, name, (int)mappedSize);
}
+ }
+ 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.
+ g_signal_connect( G_OBJECT(widget), "map", G_CALLBACK(imageMapNamedCB), GINT_TO_POINTER(0) );
+
+ if ( Inkscape::Preferences::get()->getBool("/options/iconrender/named_nodelay") ) {
+ int psize = getPhysSize(lsize);
+ prerenderIcon(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;
+ 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);
SPIcon *icon = (SPIcon *)g_object_new(SP_TYPE_ICON, NULL);
icon->lsize = lsize;
icon->name = g_strdup(name);
- icon->psize = sp_icon_get_phys_size(lsize);
+ icon->psize = getPhysSize(lsize);
widget = GTK_WIDGET(icon);
}
return widget;
}
-GtkWidget *
-sp_icon_new( Inkscape::IconSize lsize, gchar const *name )
+// PUBLIC CALL:
+GtkWidget *sp_icon_new( Inkscape::IconSize lsize, gchar const *name )
{
- return sp_icon_new_full( lsize, name );
+ return IconImpl::newFull( lsize, name );
}
+// PUBLIC CALL:
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 = IconImpl::newFull( static_cast<Inkscape::IconSize>(Inkscape::getRegisteredIconSize(size)), oid.c_str() );
if ( widget ) {
if ( GTK_IS_IMAGE(widget) ) {
@@ -344,38 +824,12 @@ Gtk::Widget *sp_icon_get_icon( Glib::ustring const &oid, Inkscape::IconSize size
return result;
}
-// Try to load the named svg, falling back to pixmaps
-guchar *
-sp_icon_image_load( SPIcon *icon, gchar const *name )
-{
- guchar *px = sp_icon_image_load_svg( name, icon->lsize, icon->psize );
- if (!px) {
- px = sp_icon_image_load_pixmap(name, icon->lsize, icon->psize);
- }
-
- return px;
-}
-
-GtkIconSize
-sp_icon_get_gtk_size(int size)
-{
- static GtkIconSize map[64] = {(GtkIconSize)0};
- size = CLAMP(size, 4, 63);
- if (!map[size]) {
- static int count = 0;
- char c[64];
- g_snprintf(c, 64, "InkscapeIcon%d", count++);
- map[size] = gtk_icon_size_register(c, size, size);
- }
- return map[size];
-}
-
-static void injectCustomSize()
+void IconImpl::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 );
+ bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpDefault");
gint width = 0;
gint height = 0;
if ( gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height ) ) {
}
sizeMapDone = true;
}
+}
+
+GtkIconSize Inkscape::getRegisteredIconSize( Inkscape::IconSize size )
+{
+ GtkIconSize other = GTK_ICON_SIZE_MENU;
+ IconImpl::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)
+{
+ return IconImpl::getPhysSize(size);
}
-static int sp_icon_get_phys_size(int size)
+int IconImpl::getPhysSize(int size)
{
static bool init = false;
static int lastSys[Inkscape::ICON_SIZE_DECORATION + 1];
static int vals[Inkscape::ICON_SIZE_DECORATION + 1];
- size = CLAMP( size, GTK_ICON_SIZE_MENU, Inkscape::ICON_SIZE_DECORATION );
+ size = CLAMP( size, static_cast<int>(GTK_ICON_SIZE_MENU), static_cast<int>(Inkscape::ICON_SIZE_DECORATION) );
if ( !sizeMapDone ) {
injectCustomSize();
if ( !init ) {
sizeDirty = false;
- gint dump = prefs_get_int_attribute_limited( "debug.icons", "dumpDefault", 0, 0, 1 );
-
+ bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpDefault");
if ( dump ) {
g_message( "Default icon sizes:" );
}
i, gtkSizes[i],
( used ? ' ' : 'X' ), width, height, names[i]);
}
+
+ // The following is needed due to this documented behavior of gtk_icon_size_lookup:
+ // "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."
gchar const *id = GTK_STOCK_OPEN;
GdkPixbuf *pb = gtk_widget_render_icon( icon, id, gtkSizes[i], NULL);
if (pb) {
return vals[size];
}
-static void sp_icon_paint(SPIcon *icon, GdkRectangle const *area)
+void IconImpl::paint(SPIcon *icon, GdkRectangle const */*area*/)
{
GtkWidget &widget = *GTK_WIDGET(icon);
-
- GdkPixbuf *image = GTK_WIDGET_IS_SENSITIVE(&widget) ? icon->pb : icon->pb_faded;
+ GdkPixbuf *image = icon->pb;
+ bool unref_image = false;
+
+ /* 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 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), widget.style->black_gc, image,
+ 0, 0, x, y, width, height,
+ GDK_RGB_DITHER_NORMAL, x, y);
+ }
+ }
- gdk_draw_pixbuf(GDK_DRAWABLE(widget.window), NULL, image,
- x0 - widget.allocation.x - padx,
- y0 - widget.allocation.y - pady,
- x0, y0,
- x1 - x0, y1 - y0,
- GDK_RGB_DITHER_NORMAL, x0, y0);
+ if (unref_image) {
+ g_object_unref(G_OBJECT(image));
}
}
-static guchar *
-sp_icon_image_load_pixmap(gchar const *name, unsigned lsize, unsigned psize)
+GdkPixbuf *IconImpl::loadPixmap(gchar const *name, unsigned /*lsize*/, unsigned psize)
{
- gchar *path;
- guchar *px;
- GdkPixbuf *pb;
-
- path = (gchar *) g_strdup_printf("%s/%s.png", INKSCAPE_PIXMAPDIR, name);
+ gchar *path = (gchar *) g_strdup_printf("%s/%s.png", INKSCAPE_PIXMAPDIR, name);
// TODO: bulia, please look over
gsize bytesRead = 0;
gsize bytesWritten = 0;
&bytesRead,
&bytesWritten,
&error);
- pb = gdk_pixbuf_new_from_file(localFilename, NULL);
+ GdkPixbuf *pb = gdk_pixbuf_new_from_file(localFilename, NULL);
g_free(localFilename);
g_free(path);
if (!pb) {
g_free(localFilename);
g_free(path);
}
+
if (pb) {
- if (!gdk_pixbuf_get_has_alpha(pb))
+ if (!gdk_pixbuf_get_has_alpha(pb)) {
gdk_pixbuf_add_alpha(pb, FALSE, 0, 0, 0);
+ }
+
if ( ( static_cast<unsigned>(gdk_pixbuf_get_width(pb)) != psize )
|| ( static_cast<unsigned>(gdk_pixbuf_get_height(pb)) != psize ) ) {
GdkPixbuf *spb = gdk_pixbuf_scale_simple(pb, psize, psize, GDK_INTERP_HYPER);
g_object_unref(G_OBJECT(pb));
pb = spb;
}
- guchar *spx = gdk_pixbuf_get_pixels(pb);
- int srs = gdk_pixbuf_get_rowstride(pb);
- px = g_new(guchar, 4 * psize * psize);
- for (unsigned y = 0; y < psize; y++) {
- memcpy(px + 4 * y * psize, spx + y * srs, 4 * psize);
- }
- g_object_unref(G_OBJECT(pb));
-
- return px;
}
- return NULL;
+ return pb;
}
// takes doc, root, icon, and icon name to produce pixels
-extern "C" guchar *
-sp_icon_doc_icon( SPDocument *doc, NRArenaItem *root,
- gchar const *name, unsigned psize )
+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 );
+ bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg");
guchar *px = NULL;
if (doc) {
SPObject *object = doc->getObjectById(name);
if (object && SP_IS_ITEM(object)) {
/* Find bbox in document */
- NR::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
- NR::Rect dbox = SP_ITEM(object)->invokeBbox(i2doc);
+ Geom::Matrix const i2doc(SP_ITEM(object)->i2doc_affine());
+ Geom::OptRect dbox = SP_ITEM(object)->getBounds(i2doc);
if ( SP_OBJECT_PARENT(object) == NULL )
{
- dbox = NR::Rect(NR::Point(0, 0),
- NR::Point(sp_document_width(doc), sp_document_height(doc)));
+ dbox = Geom::Rect(Geom::Point(0, 0),
+ Geom::Point(doc->getWidth(), doc->getHeight()));
}
/* This is in document coordinates, i.e. pixels */
- if (dbox.isEmpty() == false) {
+ if ( dbox ) {
NRGC gc(NULL);
/* Update to renderable state */
double sf = 1.0;
- NRMatrix t;
- nr_matrix_set_scale(&t, sf, sf);
- nr_arena_item_set_transform(root, &t);
- nr_matrix_set_identity(&gc.transform);
+ 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 );
/* Item integer bbox in points */
NRRectL ibox;
- ibox.x0 = (int) floor(sf * dbox.min()[NR::X] + 0.5);
- ibox.y0 = (int) floor(sf * dbox.min()[NR::Y] + 0.5);
- ibox.x1 = (int) floor(sf * dbox.max()[NR::X] + 0.5);
- ibox.y1 = (int) floor(sf * dbox.max()[NR::Y] + 0.5);
+ ibox.x0 = (int) floor(sf * dbox->min()[Geom::X] + 0.5);
+ ibox.y0 = (int) floor(sf * dbox->min()[Geom::Y] + 0.5);
+ ibox.x1 = (int) floor(sf * dbox->max()[Geom::X] + 0.5);
+ ibox.y1 = (int) floor(sf * dbox->max()[Geom::Y] + 0.5);
if ( dump ) {
g_message( " box --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 );
}
sf = (double)psize / (double)block;
- nr_matrix_set_scale(&t, sf, sf);
- nr_arena_item_set_transform(root, &t);
- nr_matrix_set_identity(&gc.transform);
+ 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 );
/* Item integer bbox in points */
- ibox.x0 = (int) floor(sf * dbox.min()[NR::X] + 0.5);
- ibox.y0 = (int) floor(sf * dbox.min()[NR::Y] + 0.5);
- ibox.x1 = (int) floor(sf * dbox.max()[NR::X] + 0.5);
- ibox.y1 = (int) floor(sf * dbox.max()[NR::Y] + 0.5);
+ ibox.x0 = (int) floor(sf * dbox->min()[Geom::X] + 0.5);
+ ibox.y0 = (int) floor(sf * dbox->min()[Geom::Y] + 0.5);
+ ibox.x1 = (int) floor(sf * dbox->max()[Geom::X] + 0.5);
+ ibox.y1 = (int) floor(sf * dbox->max()[Geom::Y] + 0.5);
if ( dump ) {
g_message( " box2 --'%s' (%f,%f)-(%f,%f)", name, (double)ibox.x0, (double)ibox.y0, (double)ibox.x1, (double)ibox.y1 );
px + 4 * psize * (ua.y0 - area.y0) +
4 * (ua.x0 - area.x0),
4 * psize, FALSE, FALSE );
- nr_arena_item_invoke_render( root, &ua, &B,
+ nr_arena_item_invoke_render(NULL, root, &ua, &B,
NR_ARENA_ITEM_RENDER_NO_CACHE );
nr_pixblock_release(&B);
- gint useOverlay = prefs_get_int_attribute_limited( "debug.icons", "overlaySvg", 0, 0, 1 );
- if ( useOverlay ) {
- sp_icon_overlay_pixels( px, psize, psize, 4 * psize, 0x00, 0x00, 0xff );
+ if ( Inkscape::Preferences::get()->getBool("/debug/icons/overlaySvg") ) {
+ IconImpl::overlayPixels( px, psize, psize, 4 * psize, 0x00, 0x00, 0xff );
}
}
}
-struct svg_doc_cache_t
+class SVGDocCache
{
+public:
+ SVGDocCache( SPDocument *doc, NRArenaItem *root ) : doc(doc), root(root) {}
SPDocument *doc;
NRArenaItem *root;
};
-static std::map<Glib::ustring, svg_doc_cache_t *> doc_cache;
-static std::map<Glib::ustring, guchar *> px_cache;
+static std::map<Glib::ustring, SVGDocCache *> doc_cache;
+static std::map<Glib::ustring, GdkPixbuf *> pb_cache;
-static Glib::ustring icon_cache_key(gchar const *name,
- unsigned lsize, unsigned psize)
+Glib::ustring icon_cache_key(Glib::ustring const & name, unsigned psize)
{
- Glib::ustring key=name;
- key += ":";
- key += lsize;
+ Glib::ustring key = name;
key += ":";
key += psize;
return key;
}
-static guchar *get_cached_pixels(Glib::ustring const &key) {
- std::map<Glib::ustring, guchar *>::iterator found=px_cache.find(key);
- if ( found != px_cache.end() ) {
- return found->second;
+GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key) {
+ GdkPixbuf* pb = 0;
+ std::map<Glib::ustring, GdkPixbuf *>::iterator found = pb_cache.find(key);
+ if ( found != pb_cache.end() ) {
+ pb = found->second;
}
- return NULL;
+ return pb;
}
-static guchar *load_svg_pixels(gchar const *name,
- unsigned lsize, unsigned psize)
+std::list<gchar*> &IconImpl::icons_svg_paths()
{
- SPDocument *doc = NULL;
- NRArenaItem *root = NULL;
- svg_doc_cache_t *info = NULL;
+ 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;
+}
- // 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));
+// this function renders icons from icons.svg and returns the pixels.
+guchar *IconImpl::load_svg_pixels(std::list<Glib::ustring> const &names,
+ unsigned /*lsize*/, unsigned psize)
+{
+ bool const dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpSvg");
+ 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();
+ guchar *px = NULL;
+ for (std::list<gchar*>::iterator i = sources.begin(); (i != sources.end()) && !px; ++i) {
+ gchar *doc_filename = *i;
+ SVGDocCache *info = 0;
// Did we already load this doc?
Glib::ustring key(doc_filename);
- info = 0;
{
- std::map<Glib::ustring, svg_doc_cache_t *>::iterator i = doc_cache.find(key);
+ std::map<Glib::ustring, SVGDocCache *>::iterator i = doc_cache.find(key);
if ( i != doc_cache.end() ) {
info = i->second;
}
}
- /* Try to load from document. */
- if (!info &&
- Inkscape::IO::file_test( doc_filename, G_FILE_TEST_IS_REGULAR ) &&
- (doc = sp_document_new( doc_filename, FALSE )) ) {
-
- // prep the document
- sp_document_ensure_up_to_date(doc);
- /* Create new arena */
- NRArena *arena = NRArena::create();
- /* Create ArenaItem and set transform */
- unsigned visionkey = sp_item_display_key_new(1);
- /* fixme: Memory manage root if needed (Lauris) */
- root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT(doc)),
- arena, visionkey, SP_ITEM_SHOW_DISPLAY );
+ // Try to load from document.
+ if (!info && Inkscape::IO::file_test( doc_filename, G_FILE_TEST_IS_REGULAR ) ) {
+ SPDocument *doc = SPDocument::createNewDoc( doc_filename, FALSE );
+ if ( doc ) {
+ if ( dump ) {
+ g_message("Loaded icon file %s", doc_filename);
+ }
+ // prep the document
+ doc->ensureUpToDate();
+
+ // Create new arena
+ NRArena *arena = NRArena::create();
+
+ // Create ArenaItem and set transform
+ unsigned visionkey = SPItem::display_key_new(1);
+ // fixme: Memory manage root if needed (Lauris)
+ // This needs to be fixed indeed; this leads to a memory leak of a few megabytes these days
+ // because shapes are being rendered which are not being freed
+ NRArenaItem *root = SP_ITEM(doc->getRoot())->invoke_show( arena, visionkey, SP_ITEM_SHOW_DISPLAY );
+
+ // store into the cache
+ info = new SVGDocCache(doc, root);
+ doc_cache[key] = info;
+ }
+ }
+ if (info) {
+ for (std::list<Glib::ustring>::const_iterator it = names.begin(); !px && (it != names.end()); ++it ) {
+ px = sp_icon_doc_icon( info->doc, info->root, it->c_str(), psize );
+ }
+ }
+ }
- // store into the cache
- info = new svg_doc_cache_t;
- g_assert(info);
+ return px;
+}
- info->doc=doc;
- info->root=root;
- doc_cache[key]=info;
+static void addToIconSet(GdkPixbuf* pb, gchar const* name, GtkIconSize lsize, unsigned psize) {
+ static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
+ GtkStockItem stock;
+ gboolean stockFound = gtk_stock_lookup( name, &stock );
+ if ( !stockFound ) {
+ Gtk::IconTheme::add_builtin_icon( name, psize, Glib::wrap(pb) );
+ if (dump) {
+ g_message(" set in a builtin for %s:%d:%d", name, lsize, psize);
}
- if (info) {
- doc=info->doc;
- root=info->root;
+ }
+}
+
+void Inkscape::queueIconPrerender( Glib::ustring const &name, Inkscape::IconSize lsize )
+{
+ GtkStockItem stock;
+ gboolean stockFound = gtk_stock_lookup( name.c_str(), &stock );
+ gboolean themedFound = gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), name.c_str());
+ if (!stockFound && !themedFound ) {
+ gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
+ if ( !sizeMapDone ) {
+ IconImpl::injectCustomSize();
}
+ GtkIconSize mappedSize = iconSizeLookup[trySize];
- // toss the filename
- g_free(doc_filename);
- sources.pop_front();
+ int psize = IconImpl::getPhysSize(lsize);
+ // TODO place in a queue that is triggered by other map events
+ IconImpl::prerenderIcon(name.c_str(), mappedSize, psize);
+ }
+}
- // move on to the next document if we couldn't get anything
- if (!info && !doc) continue;
+static std::map<unsigned, Glib::ustring> sizePaths;
- px = sp_icon_doc_icon( doc, root, name, psize );
+static std::string getDestDir( unsigned psize )
+{
+ if ( sizePaths.find(psize) == sizePaths.end() ) {
+ gchar *tmp = g_strdup_printf("%dx%d", psize, psize);
+ sizePaths[psize] = tmp;
+ g_free(tmp);
}
- return px;
+ return sizePaths[psize];
}
// returns true if icon needed preloading, false if nothing was done
-static bool prerender_icon(gchar const *name, unsigned lsize, unsigned psize)
+bool IconImpl::prerenderIcon(gchar const *name, GtkIconSize lsize, unsigned psize)
{
- Glib::ustring key = icon_cache_key(name, lsize, psize);
- guchar *px = get_cached_pixels(key);
- if (px) {
- return false;
- } else {
- px = load_svg_pixels(name, lsize, psize);
- if (px) {
- px_cache[key] = px;
+ bool loadNeeded = false;
+ static bool dump = Inkscape::Preferences::get()->getBool("/debug/icons/dumpGtk");
+ static bool useCache = Inkscape::Preferences::get()->getBool("/debug/icons/useCache", true);
+ static bool cacheValidated = false;
+ if (!cacheValidated) {
+ cacheValidated = true;
+ if ( useCache ) {
+ validateCache();
+ }
+ }
+
+ Glib::ustring key = icon_cache_key(name, psize);
+ if ( !get_cached_pixbuf(key) ) {
+ if ((internalNames.find(name) != internalNames.end())
+ || (!gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), name))) {
+ if (dump) {
+ g_message("prerenderIcon [%s] %d:%d", name, lsize, psize);
+ }
+
+ std::string potentialFile;
+ bool dataLoaded = false;
+ if ( useCache ) {
+ // In file encoding:
+ std::string iconCacheDir = Glib::build_filename(Glib::build_filename(Glib::get_user_cache_dir(), "inkscape"), "icons");
+ std::string subpart = getDestDir(psize);
+ std::string subdir = Glib::build_filename( iconCacheDir, subpart );
+ if ( !Glib::file_test(subdir, Glib::FILE_TEST_EXISTS) ) {
+ g_mkdir_with_parents( subdir.c_str(), 0x1ED );
+ }
+ potentialFile = Glib::build_filename( subdir, name );
+ potentialFile += ".png";
+
+ if ( Glib::file_test(potentialFile, Glib::FILE_TEST_EXISTS) && Glib::file_test(potentialFile, Glib::FILE_TEST_IS_REGULAR) ) {
+ bool badFile = false;
+ try {
+ Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_file(potentialFile);
+ if (pb) {
+ dataLoaded = true;
+ GdkPixbuf *obj = pb->gobj();
+ g_object_ref(obj);
+ pb_cache[key] = obj;
+ addToIconSet(obj, name, lsize, psize);
+ loadNeeded = true;
+ if (internalNames.find(name) == internalNames.end()) {
+ internalNames.insert(name);
+ }
+ }
+ } catch ( Glib::FileError &ex ) {
+ //g_warning("FileError [%s]", ex.what().c_str());
+ badFile = true;
+ } catch ( Gdk::PixbufError &ex ) {
+ //g_warning("PixbufError [%s]", ex.what().c_str());
+ // Invalid contents. Remove cached item
+ badFile = true;
+ }
+ if ( badFile ) {
+ g_remove(potentialFile.c_str());
+ }
+ }
+ }
+
+ if (!dataLoaded) {
+ std::list<Glib::ustring> names;
+ names.push_back(name);
+ if ( legacyNames.find(name) != legacyNames.end() ) {
+ names.push_back(legacyNames[name]);
+ if ( dump ) {
+ g_message("load_svg_pixels([%s] = %s, %d, %d)", name, legacyNames[name].c_str(), lsize, psize);
+ }
+ }
+ guchar* px = load_svg_pixels(names, lsize, psize);
+ if (px) {
+ GdkPixbuf* pb = gdk_pixbuf_new_from_data( px, GDK_COLORSPACE_RGB, TRUE, 8,
+ psize, psize, psize * 4,
+ reinterpret_cast<GdkPixbufDestroyNotify>(g_free), NULL );
+ pb_cache[key] = pb;
+ addToIconSet(pb, name, lsize, psize);
+ loadNeeded = true;
+ if (internalNames.find(name) == internalNames.end()) {
+ internalNames.insert(name);
+ }
+ if (useCache) {
+ g_object_ref(pb);
+ Glib::RefPtr<Gdk::Pixbuf> ppp = Glib::wrap(pb);
+ try {
+ ppp->save( potentialFile, "png" );
+ } catch ( Glib::FileError &ex ) {
+ //g_warning("FileError [%s]", ex.what().c_str());
+ } catch ( Gdk::PixbufError &ex ) {
+ //g_warning("PixbufError [%s]", ex.what().c_str());
+ }
+ }
+ } else if (dump) {
+ g_message("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX error!!! pixels not found for '%s'", name);
+ }
+ }
+ }
+ else if (dump) {
+ g_message("prerenderIcon [%s] %d NOT!!!!!!", name, psize);
}
- return true;
}
+ return loadNeeded;
}
-static guchar *
-sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsigned psize)
+GdkPixbuf *IconImpl::loadSvg(std::list<Glib::ustring> const &names, GtkIconSize lsize, unsigned psize)
{
- Glib::ustring key = icon_cache_key(name, lsize, psize);
+ Glib::ustring key = icon_cache_key(*names.begin(), psize);
// did we already load this icon at this scale/size?
- guchar *px = get_cached_pixels(key);
- if (!px) {
- px = load_svg_pixels(name, lsize, psize);
+ GdkPixbuf* pb = get_cached_pixbuf(key);
+ if (!pb) {
+ guchar *px = load_svg_pixels(names, lsize, psize);
if (px) {
- px_cache[key] = 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, names.begin()->c_str(), lsize, psize);
}
}
- return px;
+
+ if ( pb ) {
+ // increase refcount since we're handing out ownership
+ g_object_ref(G_OBJECT(pb));
+ }
+ return pb;
}
-void sp_icon_overlay_pixels(guchar *px, int width, int height, int stride,
+void IconImpl::overlayPixels(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;
class preRenderItem
{
public:
- preRenderItem( Inkscape::IconSize lsize, gchar const *name ) :
+ preRenderItem( GtkIconSize lsize, gchar const *name ) :
_lsize( lsize ),
_name( name )
{}
- Inkscape::IconSize _lsize;
+ GtkIconSize _lsize;
Glib::ustring _name;
};
-#include <queue>
-
-static std::queue<preRenderItem> pendingRenders;
+static std::vector<preRenderItem> pendingRenders;
static bool callbackHooked = false;
-static void addPreRender( Inkscape::IconSize lsize, gchar const *name )
+void IconImpl::addPreRender( GtkIconSize lsize, gchar const *name )
{
-
if ( !callbackHooked )
{
callbackHooked = true;
- g_idle_add_full( G_PRIORITY_LOW, &icon_prerender_task, NULL, NULL );
+ g_idle_add_full( G_PRIORITY_LOW, &prerenderTask, NULL, NULL );
}
- pendingRenders.push(preRenderItem(lsize, name));
+ pendingRenders.push_back(preRenderItem(lsize, name));
}
-gboolean icon_prerender_task(gpointer data) {
- if (!pendingRenders.empty()) {
- preRenderItem single=pendingRenders.front();
- pendingRenders.pop();
- int psize = sp_icon_get_phys_size(single._lsize);
- prerender_icon(single._name.c_str(), single._lsize, psize);
+gboolean IconImpl::prerenderTask(gpointer /*data*/) {
+ if ( inkscapeIsCrashing() ) {
+ // stop
+ } else if (!pendingRenders.empty()) {
+ bool workDone = false;
+ do {
+ preRenderItem single = pendingRenders.front();
+ pendingRenders.erase(pendingRenders.begin());
+ int psize = getPhysSize(single._lsize);
+ workDone = prerenderIcon(single._name.c_str(), single._lsize, psize);
+ } while (!pendingRenders.empty() && !workDone);
}
- if (!pendingRenders.empty()) {
+ if (!inkscapeIsCrashing() && !pendingRenders.empty()) {
return TRUE;
} else {
callbackHooked = false;
}
}
+
+void IconImpl::imageMapCB(GtkWidget* widget, gpointer user_data)
+{
+ gchar* id = 0;
+ GtkIconSize size = GTK_ICON_SIZE_INVALID;
+ gtk_image_get_stock(GTK_IMAGE(widget), &id, &size);
+ GtkIconSize lsize = static_cast<GtkIconSize>(GPOINTER_TO_INT(user_data));
+ if ( id ) {
+ int psize = getPhysSize(lsize);
+ g_message("imageMapCB(%p) for [%s]:%d:%d", widget, id, lsize, psize);
+ for ( std::vector<preRenderItem>::iterator it = pendingRenders.begin(); it != pendingRenders.end(); ++it ) {
+ if ( (it->_name == id) && (it->_lsize == lsize) ) {
+ prerenderIcon(id, lsize, psize);
+ pendingRenders.erase(it);
+ g_message(" prerender for %s:%d:%d", id, lsize, psize);
+ if (lsize != size) {
+ int psize = getPhysSize(size);
+ prerenderIcon(id, size, psize);
+ }
+ break;
+ }
+ }
+ }
+
+ g_signal_handlers_disconnect_by_func(widget, (gpointer)imageMapCB, user_data);
+}
+
+void IconImpl::imageMapNamedCB(GtkWidget* widget, gpointer user_data)
+{
+ GtkImage* img = GTK_IMAGE(widget);
+ gchar const* iconName = 0;
+ GtkIconSize size = GTK_ICON_SIZE_INVALID;
+ gtk_image_get_icon_name(img, &iconName, &size);
+ if ( iconName ) {
+ GtkImageType type = gtk_image_get_storage_type( GTK_IMAGE(img) );
+ if ( type == GTK_IMAGE_ICON_NAME ) {
+
+ gint iconSize = 0;
+ gchar* iconName = 0;
+ {
+ g_object_get(G_OBJECT(widget),
+ "icon-name", &iconName,
+ "icon-size", &iconSize,
+ NULL);
+ }
+
+ for ( std::vector<preRenderItem>::iterator it = pendingRenders.begin(); it != pendingRenders.end(); ++it ) {
+ if ( (it->_name == iconName) && (it->_lsize == size) ) {
+ int psize = getPhysSize(size);
+ prerenderIcon(iconName, size, psize);
+ pendingRenders.erase(it);
+ break;
+ }
+ }
+
+ gtk_image_set_from_icon_name(img, "", (GtkIconSize)iconSize);
+ gtk_image_set_from_icon_name(img, iconName, (GtkIconSize)iconSize);
+ } else {
+ g_warning("UNEXPECTED TYPE of %d", (int)type);
+ }
+ }
+
+ g_signal_handlers_disconnect_by_func(widget, (gpointer)imageMapNamedCB, user_data);
+}
+
+
/*
Local Variables:
mode:c++
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :