diff options
author | Benjamin Otte <otte@redhat.com> | 2014-05-10 15:35:12 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2014-05-11 04:02:59 +0200 |
commit | c91cb5ebc0c3064c260257b79740524d5da9aede (patch) | |
tree | 802fbbe0b8123beaeb075328bf71a941cf4b71ae | |
parent | ffedaa71cdd4386344d9b1a85c5bc397333ac9a4 (diff) | |
download | gtk+-c91cb5ebc0c3064c260257b79740524d5da9aede.tar.gz |
API: icontheme: Add 2 new GtkIconLookupFlags
GTK_ICON_LOOKUP_FORCE_REGULAR and GTK_ICON_LOOKUP_FORCE_SYMBOLIC can be
used to force a regular or symbolic icon to be loaded, even if the icon
names specify a different version.
This is intended to support the CSS property -gtk-icon-style.
-rw-r--r-- | gtk/gtkicontheme.c | 69 | ||||
-rw-r--r-- | gtk/gtkicontheme.h | 8 |
2 files changed, 71 insertions, 6 deletions
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 2d40287d7e..b381cde52c 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -1592,11 +1592,11 @@ symbolic_pixbuf_cache_free (SymbolicPixbufCache *cache) } static GtkIconInfo * -choose_icon (GtkIconTheme *icon_theme, - const gchar *icon_names[], - gint size, - gint scale, - GtkIconLookupFlags flags) +real_choose_icon (GtkIconTheme *icon_theme, + const gchar *icon_names[], + gint size, + gint scale, + GtkIconLookupFlags flags) { GtkIconThemePrivate *priv; GList *l; @@ -1794,6 +1794,65 @@ choose_icon (GtkIconTheme *icon_theme, return icon_info; } +static GtkIconInfo * +choose_icon (GtkIconTheme *icon_theme, + const gchar *icon_names[], + gint size, + gint scale, + GtkIconLookupFlags flags) +{ + gboolean has_regular = FALSE, has_symbolic = FALSE; + GtkIconInfo *icon_info; + gchar **new_names; + guint i; + + for (i = 0; icon_names[i]; i++) + { + if (g_str_has_suffix (icon_names[i], "-symbolic")) + has_symbolic = TRUE; + else + has_regular = TRUE; + } + + if ((flags & GTK_ICON_LOOKUP_FORCE_REGULAR) && has_symbolic) + { + new_names = g_new0 (gchar *, i + 1); + for (i = 0; icon_names[i]; i++) + { + if (g_str_has_suffix (icon_names[i], "-symbolic")) + new_names[i] = g_strndup (icon_names[i], strlen (icon_names[i]) - strlen ("-symbolic")); + else + new_names[i] = g_strdup (icon_names[i]); + } + } + else if ((flags & GTK_ICON_LOOKUP_FORCE_SYMBOLIC) && has_regular) + { + new_names = g_new0 (gchar *, i + 1); + for (i = 0; icon_names[i]; i++) + { + if (!g_str_has_suffix (icon_names[i], "-symbolic")) + new_names[i] = g_strconcat (icon_names[i], "-symbolic", NULL); + else + new_names[i] = g_strdup (icon_names[i]); + } + } + else + { + new_names = NULL; + } + + icon_info = real_choose_icon (icon_theme, + new_names ? (const gchar **) new_names : icon_names, + size, + scale, + flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC)); + + if (new_names) + g_strfreev (new_names); + + return icon_info; +} + /** * gtk_icon_theme_lookup_icon: diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index 84bb0b6322..bdbaafe317 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -113,6 +113,10 @@ struct _GtkIconThemeClass * fallback, see gtk_icon_theme_choose_icon(). Since 2.12. * @GTK_ICON_LOOKUP_FORCE_SIZE: Always get the icon scaled to the * requested size. Since 2.14. + * @GTK_ICON_LOOKUP_FORCE_REGULAR: Always load regular icons, even when + * symbolic icon names are given. Since 3.14. + * @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Always load symbolic icons, even when + * regular icon names are given. Since 3.14. * * Used to specify options for gtk_icon_theme_lookup_icon() */ @@ -122,7 +126,9 @@ typedef enum GTK_ICON_LOOKUP_FORCE_SVG = 1 << 1, GTK_ICON_LOOKUP_USE_BUILTIN = 1 << 2, GTK_ICON_LOOKUP_GENERIC_FALLBACK = 1 << 3, - GTK_ICON_LOOKUP_FORCE_SIZE = 1 << 4 + GTK_ICON_LOOKUP_FORCE_SIZE = 1 << 4, + GTK_ICON_LOOKUP_FORCE_REGULAR = 1 << 5, + GTK_ICON_LOOKUP_FORCE_SYMBOLIC = 1 << 6 } GtkIconLookupFlags; /** |