summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ab0e73f)
raw | patch | inline | side by side (parent: ab0e73f)
author | joncruz <joncruz@users.sourceforge.net> | |
Mon, 27 Apr 2009 08:32:58 +0000 (08:32 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Mon, 27 Apr 2009 08:32:58 +0000 (08:32 +0000) |
src/widgets/icon.cpp | patch | blob | history | |
src/widgets/icon.h | patch | blob | history | |
src/widgets/select-toolbar.cpp | patch | blob | history |
diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp
index ad87a3c192f295270665ecef749c9e676f65e488..32b5b868e2bf2b07710f6404128c9740bc93ecf7 100644 (file)
--- a/src/widgets/icon.cpp
+++ b/src/widgets/icon.cpp
GdkPixbuf* _pb;
};
-static Glib::RefPtr<Gtk::IconFactory> inkyIcons;
static std::map<Glib::ustring, std::vector<IconCacheItem> > iconSetCache;
GType
sp_icon_get_type()
{
- //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) {
GTypeInfo info = {
static void sp_icon_theme_changed( 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);
gtk_widget_queue_draw( GTK_WIDGET(icon) );
static void imageMapCB(GtkWidget* widget, gpointer user_data);
static void imageMapNamedCB(GtkWidget* widget, gpointer user_data);
-static void populate_placeholder_icon(gchar const* name, GtkIconSize size);
static bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize);
-static Glib::ustring icon_cache_key(gchar const *name, unsigned lsize, unsigned psize);
+static Glib::ustring icon_cache_key(gchar const *name, unsigned psize);
static GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key);
static void setupLegacyNaming() {
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, mappedSize );
addPreRender( mappedSize, name );
// Add a hook to render if set visible before prerender is done.
// TODO - still need to handle the case of theme changes and resize, especially as we can't re-register a string.
if ( !sizeMapDone )
{
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- bool dump = prefs->getBool( "/debug/icons/dumpDefault");
+ 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;
}
-
- static bool hit = false;
- if ( !hit ) {
- hit = true;
- inkyIcons = Gtk::IconFactory::create();
- inkyIcons->add_default();
- }
}
GtkIconSize Inkscape::getRegisteredIconSize( Inkscape::IconSize size )
if ( !init ) {
sizeDirty = false;
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- bool dump = prefs->getBool("/debug/icons/dumpDefault");
-
+ 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) {
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 std::map<Glib::ustring, svg_doc_cache_t *> doc_cache;
static std::map<Glib::ustring, GdkPixbuf *> pb_cache;
-Glib::ustring icon_cache_key(gchar const *name,
- unsigned lsize, unsigned psize)
+Glib::ustring icon_cache_key(gchar const *name, unsigned psize)
{
Glib::ustring key=name;
key += ":";
- key += lsize;
- key += ":";
key += psize;
return key;
}
return px;
}
-static void populate_placeholder_icon(gchar const* name, GtkIconSize size)
-{
- 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(size) );
- icnset.add_source(src);
- inkyIcons->add(Gtk::StockID(name), icnset);
- }
-}
-
static void addToIconSet(GdkPixbuf* pb, gchar const* name, GtkIconSize lsize, unsigned psize) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
static bool dump = prefs->getBool("/debug/icons/dumpGtk");
@@ -1200,29 +1166,23 @@ static void addToIconSet(GdkPixbuf* pb, gchar const* name, GtkIconSize lsize, un
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 == lsize ) {
- if (dump) {
- g_message(" erasing %s:%d %p", name, it->_lsize, it->_pb);
- }
- iconSetCache[name].erase(it);
- break;
+void Inkscape::queueIconPrerender( Glib::ustring const &name, Inkscape::IconSize lsize )
+{
+ GtkStockItem stock;
+ gboolean stockFound = gtk_stock_lookup( name.c_str(), &stock );
+ if (!stockFound && !gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), name.c_str()) ) {
+ gint trySize = CLAMP( static_cast<gint>(lsize), 0, static_cast<gint>(G_N_ELEMENTS(iconSizeLookup) - 1) );
+ if ( !sizeMapDone ) {
+ injectCustomSize();
}
+ GtkIconSize mappedSize = iconSizeLookup[trySize];
+
+ int psize = sp_icon_get_phys_size(lsize);
+ // TODO place in a queue that is triggered by other map events
+ prerender_icon(name.c_str(), mappedSize, psize);
}
- iconSetCache[name].push_back(IconCacheItem(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
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
static bool dump = prefs->getBool("/debug/icons/dumpGtk");
- Glib::ustring key = icon_cache_key(name, lsize, psize);
+ Glib::ustring key = icon_cache_key(name, psize);
GdkPixbuf *pb = get_cached_pixbuf(key);
if (pb) {
return false;
static GdkPixbuf *sp_icon_image_load_svg(gchar const *name, GtkIconSize lsize, unsigned psize)
{
- Glib::ustring key = icon_cache_key(name, lsize, psize);
+ Glib::ustring key = icon_cache_key(name, psize);
// did we already load this icon at this scale/size?
GdkPixbuf* pb = get_cached_pixbuf(key);
diff --git a/src/widgets/icon.h b/src/widgets/icon.h
index 1e2e04e1071b847511fa46a74a1297961a09db21..f70423702a862fe3d4eac399343a285bfb66d805 100644 (file)
--- a/src/widgets/icon.h
+++ b/src/widgets/icon.h
void sp_icon_fetch_pixbuf( SPIcon *icon );
int sp_icon_get_phys_size(int size);
+namespace Inkscape {
+ void queueIconPrerender( Glib::ustring const &oid, Inkscape::IconSize size = Inkscape::ICON_SIZE_BUTTON );
+}
#endif // SEEN_SP_ICON_H
index 00fd8d2e3649972983f1c29aeb76c27bd45100f6..536819bf44fdee3e5cbdf0e7c9d13b00f970cb5e 100644 (file)
@@ -382,6 +382,8 @@ static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::Vi
g_signal_connect( G_OBJECT(inky), "activate", GTK_SIGNAL_FUNC(trigger_sp_action), targetAction );
+ Inkscape::queueIconPrerender( verb->get_image(), size );
+
return act;
}