From: joncruz Date: Sun, 21 Sep 2008 09:59:34 +0000 (+0000) Subject: Fixes for missing icons and icon size issues. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=26c69a6606992e9945766e6efca44ddaee5e3321;p=inkscape.git Fixes for missing icons and icon size issues. --- diff --git a/src/icon-size.h b/src/icon-size.h index 772c79943..da2b3854d 100644 --- a/src/icon-size.h +++ b/src/icon-size.h @@ -20,15 +20,16 @@ namespace Inkscape { enum IconSize { ICON_SIZE_INVALID = ::GTK_ICON_SIZE_INVALID, - ICON_SIZE_MENU = ::GTK_ICON_SIZE_MENU, - ICON_SIZE_SMALL_TOOLBAR = ::GTK_ICON_SIZE_SMALL_TOOLBAR, - ICON_SIZE_LARGE_TOOLBAR = ::GTK_ICON_SIZE_LARGE_TOOLBAR, - ICON_SIZE_BUTTON = ::GTK_ICON_SIZE_BUTTON, - ICON_SIZE_DND = ::GTK_ICON_SIZE_DND, - ICON_SIZE_DIALOG = ::GTK_ICON_SIZE_DIALOG, + ICON_SIZE_MENU = ::GTK_ICON_SIZE_MENU, + ICON_SIZE_SMALL_TOOLBAR = ::GTK_ICON_SIZE_SMALL_TOOLBAR, + ICON_SIZE_LARGE_TOOLBAR = ::GTK_ICON_SIZE_LARGE_TOOLBAR, + ICON_SIZE_BUTTON = ::GTK_ICON_SIZE_BUTTON, + ICON_SIZE_DND = ::GTK_ICON_SIZE_DND, + ICON_SIZE_DIALOG = ::GTK_ICON_SIZE_DIALOG, ICON_SIZE_DECORATION }; + GtkIconSize getRegisteredIconSize( IconSize size ); } // namespace Inkscape #endif // SEEN_ICON_SIZE_H diff --git a/src/ink-action.cpp b/src/ink-action.cpp index c09cade05..acb65d131 100644 --- a/src/ink-action.cpp +++ b/src/ink-action.cpp @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -325,7 +326,7 @@ static void ink_toggle_action_class_init( InkToggleActionClass* klass ) "Icon Size", "The size the icon", (int)Inkscape::ICON_SIZE_MENU, - (int)Inkscape::ICON_SIZE_DECORATION, + (int)99, (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR, (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); @@ -360,7 +361,7 @@ InkToggleAction* ink_toggle_action_new( const gchar *name, "label", label, "tooltip", tooltip, "iconId", inkId, - "iconSize", size, + "iconSize", Inkscape::getRegisteredIconSize(size), NULL ); InkToggleAction* action = INK_TOGGLE_ACTION( obj ); @@ -434,7 +435,9 @@ static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action ) GtkToolButton* button = GTK_TOOL_BUTTON(item); if ( act->private_data->iconId ) { GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); - gtk_tool_button_set_icon_widget( button, child ); + GtkWidget* align = gtk_alignment_new( 0.5, 0.5, 0.0, 0.0 ); + gtk_container_add( GTK_CONTAINER(align), child ); + gtk_tool_button_set_icon_widget( button, align ); } else { gchar *label; g_object_get (G_OBJECT(action), "short_label", &label, NULL); @@ -585,7 +588,7 @@ InkRadioAction* ink_radio_action_new( const gchar *name, "label", label, "tooltip", tooltip, "iconId", inkId, - "iconSize", size, + "iconSize", Inkscape::getRegisteredIconSize(size), NULL ); InkRadioAction* action = INK_RADIO_ACTION( obj ); diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index fa33dca78..9333ffc35 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -44,7 +44,7 @@ static const int PANEL_SETTING_NEXTFREE = 4; void Panel::prep() { GtkIconSize sizes[] = { - static_cast(Inkscape::ICON_SIZE_DECORATION), + Inkscape::getRegisteredIconSize(Inkscape::ICON_SIZE_DECORATION), GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR, GTK_ICON_SIZE_BUTTON, @@ -122,13 +122,13 @@ void Panel::_init() Glib::ustring two_label(_("Grid")); Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, one_label)); Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, two_label)); - + if (panel_mode == 0) { one->set_active(true); } else if (panel_mode == 1) { two->set_active(true); } - + _menu->append(*one); _non_horizontal.push_back(one); _menu->append(*two); @@ -139,10 +139,10 @@ void Panel::_init() one->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_MODE, 0)); two->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_MODE, 1)); } - + { Glib::ustring heightItemLabel(Q_("swatches|Size")); - + //TRANSLATORS: Indicates size of colour swatches const gchar *heightLabels[] = { N_("tiny"), @@ -152,11 +152,11 @@ void Panel::_init() N_("large"), N_("huge") }; - + Gtk::MenuItem *sizeItem = manage(new Gtk::MenuItem(heightItemLabel)); Gtk::Menu *sizeMenu = manage(new Gtk::Menu()); sizeItem->set_submenu(*sizeMenu); - + Gtk::RadioMenuItem::Group heightGroup; for (unsigned int i = 0; i < G_N_ELEMENTS(heightLabels); i++) { Glib::ustring _label(Q_(heightLabels[i])); @@ -167,13 +167,13 @@ void Panel::_init() } _item->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_SIZE, i)); } - - _menu->append(*sizeItem); + + _menu->append(*sizeItem); } - + { Glib::ustring widthItemLabel(Q_("swatches|Width")); - + //TRANSLATORS: Indicates width of colour swatches const gchar *widthLabels[] = { N_("narrower"), @@ -220,7 +220,7 @@ void Panel::_init() check->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &Panel::_wrapToggled), check)); } - + Gtk::SeparatorMenuItem *sep; sep = manage(new Gtk::SeparatorMenuItem()); _menu->append(*sep); @@ -245,7 +245,7 @@ void Panel::_init() gint width = 0; gint height = 0; - if ( gtk_icon_size_lookup( static_cast(Inkscape::ICON_SIZE_DECORATION), &width, &height ) ) { + if ( gtk_icon_size_lookup( Inkscape::getRegisteredIconSize(Inkscape::ICON_SIZE_DECORATION), &width, &height ) ) { _temp_arrow.set_size_request(width, height); } diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index f9e4bf941..183481cf6 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -39,7 +39,7 @@ static gboolean icon_prerender_task(gpointer data); -static void addPreRender( Inkscape::IconSize lsize, gchar const *name ); +static void addPreRender( GtkIconSize lsize, gchar const *name ); static void sp_icon_class_init(SPIconClass *klass); static void sp_icon_init(SPIcon *icon); @@ -59,7 +59,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,11 +85,11 @@ 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; }; @@ -218,7 +218,7 @@ void sp_icon_fetch_pixbuf( SPIcon *icon ) if ( !icon->pb ) { icon->psize = sp_icon_get_phys_size(icon->lsize); - GdkPixbuf *pb = sp_icon_image_load_svg( icon->name, icon->lsize, icon->psize ); + GdkPixbuf *pb = sp_icon_image_load_svg( icon->name, Inkscape::getRegisteredIconSize(icon->lsize), icon->psize ); if (!pb) { pb = sp_icon_image_load_pixmap( icon->name, icon->lsize, icon->psize ); } @@ -264,8 +264,8 @@ static void sp_icon_theme_changed( SPIcon *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, unsigned lsize); -static bool prerender_icon(gchar const *name, unsigned lsize, unsigned psize); +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 GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key); @@ -284,10 +284,10 @@ sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name ) GtkWidget *widget = 0; gint trySize = CLAMP( static_cast(lsize), 0, static_cast(G_N_ELEMENTS(iconSizeLookup) - 1) ); - if ( !sizeMapDone ) { injectCustomSize(); } + GtkIconSize mappedSize = iconSizeLookup[trySize]; GtkStockItem stock; gboolean stockFound = gtk_stock_lookup( name, &stock ); @@ -299,15 +299,15 @@ sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name ) bool flagMe = false; if ( legacyNames.find(name) != legacyNames.end() ) { - img = gtk_image_new_from_icon_name( name, iconSizeLookup[trySize] ); + img = gtk_image_new_from_icon_name( name, mappedSize ); flagMe = true; if ( dump ) { - g_message("gtk_image_new_from_icon_name( '%s', %d ) = %p", name, iconSizeLookup[trySize], img); + 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")); } } else { - img = gtk_image_new_from_stock( name, iconSizeLookup[trySize] ); + img = gtk_image_new_from_stock( name, mappedSize ); } if ( img ) { @@ -315,19 +315,19 @@ sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name ) 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 ); + populate_placeholder_icon( name, mappedSize ); + 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(lsize)) ); + g_signal_connect( G_OBJECT(img), "map", G_CALLBACK(imageMapCB), GINT_TO_POINTER(static_cast(mappedSize)) ); if ( dump ) { - g_message(" connecting %p for imageMapCB for [%s] %d", img, name, (int)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, lsize, (stockFound ? "STOCK" : "local"), widget ); + 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); @@ -338,9 +338,9 @@ sp_icon_new_full( Inkscape::IconSize lsize, gchar const *name ) if ( prefs_get_int_attribute_limited( "options.iconrender", "named_nodelay", 0, 0, 1 ) ) { int psize = sp_icon_get_phys_size(lsize); - prerender_icon(name, lsize, psize); + prerender_icon(name, mappedSize, psize); } else { - addPreRender( lsize, name ); + addPreRender( mappedSize, name ); } } else { if ( dump ) { @@ -374,7 +374,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::getRegisteredIconSize(size)), oid.c_str() ); if ( widget ) { if ( GTK_IS_IMAGE(widget) ) { @@ -402,6 +402,7 @@ 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. @@ -437,6 +438,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(size); + } + + return other; +} + + // PUBLIC CALL: int sp_icon_get_phys_size(int size) { @@ -864,20 +880,20 @@ static guchar *load_svg_pixels(gchar const *name, return px; } -static void populate_placeholder_icon(gchar const* name, unsigned lsize) +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(lsize) ); + src.set_size( Gtk::IconSize(size) ); icnset.add_source(src); inkyIcons->add(Gtk::StockID(name), icnset); } } -static void addToIconSet(GdkPixbuf* pb, gchar const* name, unsigned lsize, unsigned psize) { +static void addToIconSet(GdkPixbuf* pb, gchar const* name, GtkIconSize lsize, unsigned psize) { static gint dump = prefs_get_int_attribute_limited( "debug.icons", "dumpGtk", 0, 0, 1 ); GtkStockItem stock; gboolean stockFound = gtk_stock_lookup( name, &stock ); @@ -889,12 +905,12 @@ static void addToIconSet(GdkPixbuf* pb, gchar const* name, unsigned lsize, unsig } for ( std::vector::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) { - if ( it->_lsize == Inkscape::IconSize(lsize) ) { + if ( it->_lsize == lsize ) { iconSetCache[name].erase(it); break; } } - iconSetCache[name].push_back(IconCacheItem(Inkscape::IconSize(lsize), pb)); + iconSetCache[name].push_back(IconCacheItem(lsize, pb)); Gtk::IconSet icnset; for ( std::vector::iterator it = iconSetCache[name].begin(); it != iconSetCache[name].end(); ++it ) { @@ -910,7 +926,7 @@ static void addToIconSet(GdkPixbuf* pb, gchar const* name, unsigned lsize, unsig } // returns true if icon needed preloading, false if nothing was done -bool prerender_icon(gchar const *name, unsigned lsize, unsigned psize) +bool prerender_icon(gchar const *name, GtkIconSize lsize, unsigned psize) { static gint dump = prefs_get_int_attribute_limited( "debug.icons", "dumpGtk", 0, 0, 1 ); Glib::ustring key = icon_cache_key(name, lsize, psize); @@ -942,7 +958,7 @@ bool prerender_icon(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) { Glib::ustring key = icon_cache_key(name, lsize, psize); @@ -1024,11 +1040,11 @@ void sp_icon_overlay_pixels(guchar *px, int width, int height, int stride, 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; }; @@ -1036,7 +1052,7 @@ public: static std::vector pendingRenders; static bool callbackHooked = false; -static void addPreRender( Inkscape::IconSize lsize, gchar const *name ) +static void addPreRender( GtkIconSize lsize, gchar const *name ) { if ( !callbackHooked ) { @@ -1071,15 +1087,19 @@ 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); - int lsize = GPOINTER_TO_INT(user_data); + GtkIconSize lsize = static_cast(GPOINTER_TO_INT(user_data)); if ( id ) { int psize = sp_icon_get_phys_size(lsize); //g_message("imageMapCB(%p) for %s:%d:%d", widget, id, lsize, psize); for ( std::vector::iterator it = pendingRenders.begin(); it != pendingRenders.end(); ++it ) { - if ( (it->_name == id) && (it->_lsize == static_cast(lsize)) ) { + if ( (it->_name == id) && (it->_lsize == lsize) ) { prerender_icon(id, lsize, psize); pendingRenders.erase(it); //g_message(" prerender for %s:%d:%d", id, lsize, psize); + if (lsize != size) { + int psize = sp_icon_get_phys_size(size); + prerender_icon(id, size, psize); + } break; } } @@ -1097,7 +1117,7 @@ static void imageMapNamedCB(GtkWidget* widget, gpointer user_data) { GtkImageType type = gtk_image_get_storage_type( GTK_IMAGE(img) ); if ( type == GTK_IMAGE_ICON_NAME ) { for ( std::vector::iterator it = pendingRenders.begin(); it != pendingRenders.end(); ++it ) { - if ( (it->_name == iconName) && (it->_lsize == static_cast(size)) ) { + if ( (it->_name == iconName) && (it->_lsize == size) ) { int psize = sp_icon_get_phys_size(size); prerender_icon(iconName, size, psize); pendingRenders.erase(it);