diff --git a/ChangeLog b/ChangeLog index 1bcb9fecad..c35da9a24e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-04-19 Matthias Clasen + + * gtk/gtkicontheme.h: + * gtk/gtkicontheme.c: Add GTK_ICON_LOOKUP_GENERIC_FALLBACK + icon lookup flag and implement it. (#396901, Luca Ferreti) + 2007-04-18 Richard Hult * gdk/quartz/gdkwindow-quartz.c: diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 3f07e61829..6eb4aa01ab 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -1256,6 +1256,7 @@ gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme, UnthemedIcon *unthemed_icon; gboolean allow_svg; gboolean use_builtin; + gboolean generic_fallback; g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); g_return_val_if_fail (icon_name != NULL, NULL); @@ -1273,15 +1274,33 @@ gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme, else allow_svg = priv->pixbuf_supports_svg; - use_builtin = (flags & GTK_ICON_LOOKUP_USE_BUILTIN); - + use_builtin = flags & GTK_ICON_LOOKUP_USE_BUILTIN; + generic_fallback = flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK; + ensure_valid_themes (icon_theme); for (l = priv->themes; l; l = l->next) { IconTheme *theme = l->data; - icon_info = theme_lookup_icon (theme, icon_name, size, allow_svg, use_builtin); + gchar *name = g_strdup (icon_name); + gchar *s; + + while (TRUE) + { + icon_info = theme_lookup_icon (theme, name, size, allow_svg, use_builtin); + if (icon_info || !generic_fallback) + break; + + s = strrchr (name, '-'); + if (!s) + break; + + *s = '\0'; + } + + g_free (name); + if (icon_info) goto out; } diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index 8a0ae125ab..cef75e7121 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -66,6 +66,8 @@ struct _GtkIconThemeClass * gtk_icon_theme_lookup_icon() includes builtin icons * as well as files. For a builtin icon, gtk_icon_info_get_filename() * returns %NULL and you need to call gtk_icon_info_get_builtin_pixbuf(). + * @GTK_ICON_LOOKUP_GENERIC_FALLBACK: Try to shorten icon name at '-' + * characters before looking at inherited themes. * * Used to specify options for gtk_icon_theme_lookup_icon() **/ @@ -73,7 +75,8 @@ typedef enum { GTK_ICON_LOOKUP_NO_SVG = 1 << 0, GTK_ICON_LOOKUP_FORCE_SVG = 1 << 1, - GTK_ICON_LOOKUP_USE_BUILTIN = 1 << 2 + GTK_ICON_LOOKUP_USE_BUILTIN = 1 << 2, + GTK_ICON_LOOKUP_GENERIC_FALLBACK = 1 << 3 } GtkIconLookupFlags; #define GTK_ICON_THEME_ERROR gtk_icon_theme_error_quark ()