mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-03 17:21:11 +00:00
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.
This commit is contained in:
parent
109fcb987b
commit
9619b8cff4
@ -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:
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user