This way, we can remove gtk_icon_theme_choose_icon() completely.
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
icon = gtk_icon_theme_lookup_icon (icon_theme,
icon_name,
+ NULL,
48, 1,
gtk_widget_get_direction (GTK_WIDGET (image)),
GTK_ICON_LOOKUP_GENERIC_FALLBACK);
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
icon = gtk_icon_theme_lookup_icon (icon_theme,
"gtk3-demo",
+ NULL,
32, 1,
gtk_widget_get_direction (widget),
GTK_ICON_LOOKUP_GENERIC_FALLBACK);
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
icon = gtk_icon_theme_lookup_icon (icon_theme,
icon_name,
+ NULL,
size, 1,
gtk_widget_get_direction (GTK_WIDGET (image)),
GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
info = gtk_icon_theme_lookup_icon (icon_theme,
name,
+ NULL,
32, 1,
gtk_widget_get_direction (GTK_WIDGET (data)),
0);
gtk_icon_theme_set_custom_theme
gtk_icon_theme_has_icon
gtk_icon_theme_lookup_icon
-gtk_icon_theme_choose_icon
gtk_icon_theme_choose_icon_async
gtk_icon_theme_choose_icon_finish
gtk_icon_theme_lookup_by_gicon
/* FIXME: this should be using the correct display */
theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
- icon = gtk_icon_theme_lookup_icon (theme, "image-missing", 16, 1,
+ icon = gtk_icon_theme_lookup_icon (theme, "image-missing", NULL, 16, 1,
GTK_TEXT_DIR_NONE,
0);
texture = gtk_icon_download_texture (icon, NULL);
theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
icon = gtk_icon_theme_lookup_icon (theme,
"text-x-generic",
+ NULL,
32,
1,
GTK_TEXT_DIR_NONE,
{
icon = gtk_icon_theme_lookup_icon (icon_theme->icon_theme,
icon_theme->name,
+ NULL,
size,
icon_theme->scale,
GTK_TEXT_DIR_NONE,
if (icon == NULL)
icon = gtk_icon_theme_lookup_icon (icon_theme->icon_theme,
"image-missing",
+ NULL,
size, icon_theme->scale,
GTK_TEXT_DIR_NONE,
0 | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
source->paintable = GDK_PAINTABLE(gtk_icon_theme_lookup_icon (theme,
"text-x-generic",
+ NULL,
32,
1,
gtk_widget_get_direction (widget),
if (icon == NULL)
icon = gtk_icon_theme_lookup_icon (icon_theme,
"image-missing",
+ NULL,
width, scale,
dir,
flags | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
* gtk_icon_theme_lookup_icon:
* @self: a #GtkIconTheme
* @icon_name: the name of the icon to lookup
+ * @fallbacks: (nullable) (array zero-terminated=1):
* @size: desired icon size. The resulting icon may not be exactly this size.
* @scale: the window scale this will be displayed on
* @direction: text direction the icon will be displayed in
* passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag, which causes the icon
* to be scaled to the exact size.
*
+ * If the available @icon_name is not available and @fallbacks are provided,
+ * they will be tried in order.
+ *
* Note that you probably want to listen for icon theme changes and
* update the icon. This is usually done by connecting to the
* GtkWidget::style-updated signal.
*
- * Often you want to look up multiple icons at the same time, as fallbacks.
- * For this use the gtk_icon_theme_choose_icon() method is a better option.
- *
* Returns: (nullable) (transfer full): a #GtkIcon object
- * containing information about the icon, or %NULL if the
- * icon wasn’t found.
+ * containing the icon, or %NULL if the icon wasn’t found.
*/
GtkIcon *
gtk_icon_theme_lookup_icon (GtkIconTheme *self,
- const gchar *icon_name,
+ const char *icon_name,
+ const char *fallbacks[],
gint size,
gint scale,
GtkTextDirection direction,
gboolean is_symbolic;
int icon_name_len = strlen (icon_name);
+ g_warn_if_fail (fallbacks == NULL);
+
is_symbolic = icon_name_is_symbolic (icon_name, icon_name_len);
if (is_symbolic)
nonsymbolic_icon_name = g_strndup (icon_name, icon_name_len - strlen ("-symbolic"));
names = nonsymbolic_names;
}
- icon = choose_icon (self, (const gchar **) names, size, scale, direction, flags, FALSE, NULL);
+ icon = choose_icon (self, (const char **) names, size, scale, direction, flags, FALSE, NULL);
g_strfreev (names);
}
+ else if (fallbacks)
+ {
+ gsize n_fallbacks = g_strv_length ((char **) fallbacks);
+ const char **names = g_new (const char *, n_fallbacks + 2);
+
+ names[0] = icon_name;
+ memcpy (&names[1], fallbacks, sizeof (char *) * n_fallbacks);
+ names[n_fallbacks + 1] = NULL;
+
+ icon = choose_icon (self, names, size, scale, direction, flags, FALSE, NULL);
+
+ g_free (names);
+ }
else
{
const gchar *names[2];
return icon;
}
-/**
- * gtk_icon_theme_choose_icon:
- * @self: a #GtkIconTheme
- * @icon_names: (array zero-terminated=1): %NULL-terminated
- * array of icon names to lookup
- * @size: desired icon size. The resulting icon may not be exactly this size.
- * @scale: the window scale this will be displayed on
- * @direction: text direction the icon will be displayed in
- * @flags: flags modifying the behavior of the icon lookup
- *
- * Looks up a named icon for a desired size and window scale, returning a
- * #GtkIcon. The icon can then be rendered by using it as a #GdkPaintable,
- * or you can get information such as the filename and size. The pixels
- * of the texture can be access by using gtk_icon_download_texture().
- *
- * If @icon_names contains more than one name, this function
- * tries them all in the given order before falling back to
- * inherited icon themes.
- *
- * The icon icon size will be based on the requested @size, but may
- * not be exactly this size; an icon theme may have icons that differ
- * slightly from their nominal sizes, and in addition GTK+ will avoid
- * scaling icons that it considers sufficiently close to the requested
- * size or for which the source image would have to be scaled up too
- * far. (This maintains sharpness.). This behaviour can be changed by
- * passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag, which causes the icon
- * to be scaled to the exact size.
- *
- * Note that you probably want to listen for icon theme changes and
- * update the icon. This is usually done by connecting to the
- * GtkWidget::style-updated signal.
- *
- * This function does not support the flag
- * GTK_ICON_LOOKUP_GENERIC_FALLBACK, that only works with the simpler
- * gtk_icon_theme_lookup_icon() method.
- *
- * Returns: (nullable) (transfer full): a #GtkIcon object
- * containing information about the icon, or %NULL if the
- * icon wasn’t found.
- */
-GtkIcon *
-gtk_icon_theme_choose_icon (GtkIconTheme *self,
- const gchar *icon_names[],
- gint size,
- gint scale,
- GtkTextDirection direction,
- GtkIconLookupFlags flags)
-{
- GtkIcon *icon;
-
- g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
- g_return_val_if_fail (icon_names != NULL, NULL);
- g_return_val_if_fail (scale >= 1, NULL);
- g_warn_if_fail ((flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK) == 0);
-
- gtk_icon_theme_lock (self);
-
- icon = choose_icon (self, icon_names, size, scale, direction, flags, FALSE, NULL);
-
- gtk_icon_theme_unlock (self);
-
- return icon;
-}
-
/* Error quark */
GQuark
gtk_icon_theme_error_quark (void)
{
const gchar **names;
- names = (const gchar **)g_themed_icon_get_names (G_THEMED_ICON (gicon));
- icon = gtk_icon_theme_choose_icon (self, names, size, scale, direction, flags);
+ names = (const gchar **) g_themed_icon_get_names (G_THEMED_ICON (gicon));
+ icon = gtk_icon_theme_lookup_icon (self, names[0], &names[1], size, scale, direction, flags);
return icon;
}
const gchar *icon_name);
GDK_AVAILABLE_IN_ALL
GtkIcon * gtk_icon_theme_lookup_icon (GtkIconTheme *self,
- const gchar *icon_name,
- gint size,
- gint scale,
- GtkTextDirection direction,
- GtkIconLookupFlags flags);
-GDK_AVAILABLE_IN_ALL
-GtkIcon * gtk_icon_theme_choose_icon (GtkIconTheme *self,
- const gchar *icon_names[],
+ const char *icon_name,
+ const char *fallbacks[],
gint size,
gint scale,
GtkTextDirection direction,
GTK_CSS_PROPERTY_ICON_THEME));
icon = gtk_icon_theme_lookup_icon (theme,
"application-x-executable",
+ NULL,
24, 1,
gtk_widget_get_direction (GTK_WIDGET (mount_operation->priv->dialog)),
0);
* fixed size of 48.
*/
if (sizes[i] == -1)
- info = gtk_icon_theme_lookup_icon (icon_theme, name,
+ info = gtk_icon_theme_lookup_icon (icon_theme, name, NULL,
48, priv->scale,
gtk_widget_get_direction (GTK_WIDGET (window)),
0);
else
- info = gtk_icon_theme_lookup_icon (icon_theme, name,
+ info = gtk_icon_theme_lookup_icon (icon_theme, name, NULL,
sizes[i], priv->scale,
gtk_widget_get_direction (GTK_WIDGET (window)),
0);
return NULL;
info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (window))),
- name, size, priv->scale,
+ name, NULL, size, priv->scale,
gtk_widget_get_direction (GTK_WIDGET (window)),
GTK_ICON_LOOKUP_FORCE_SIZE);
if (info == NULL)
g_value_init (&value, GDK_TYPE_PIXBUF);
icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gdk_clipboard_get_display (clipboard)),
"utilities-terminal",
+ NULL,
48, 1,
gtk_widget_get_direction (box),
0);
*out_size = width;
icon = gtk_icon_theme_lookup_icon (icon_theme,
icon_name,
+ NULL,
width, 1,
gtk_widget_get_direction (GTK_WIDGET (image)),
GTK_ICON_LOOKUP_GENERIC_FALLBACK);
icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_for_display (gtk_widget_get_display (widget)),
icon_name,
+ NULL,
size, 1,
gtk_widget_get_direction (widget),
0);
if (argc >= 6)
scale = atoi (argv[5]);
- icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, scale, direction, flags);
+ icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], NULL, size, scale, direction, flags);
if (!icon)
{
g_print ("Icon '%s' not found\n", argv[3]);
if (argc >= 6)
scale = atoi (argv[5]);
- icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, scale, direction, flags);
+ icon = gtk_icon_theme_lookup_icon (icon_theme, argv[3], NULL, size, scale, direction, flags);
g_print ("icon for %s at %dx%d@%dx is %s\n", argv[3], size, size, scale,
icon ? gtk_icon_get_filename (icon) : "<none>");
* icon theme.
* The icon size is randomly chosen.
*/
- info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 16, 1, GTK_TEXT_DIR_LTR, 0);
+ info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, NULL, 16, 1, GTK_TEXT_DIR_LTR, 0);
if (info == NULL)
{
g_test_message ("Failed to look up icon for \"%s\"", (char *) icon_name);
{
GtkIcon *info;
- info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, size, 1, direction, flags);
+ info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, NULL, size, 1, direction, flags);
if (info == NULL)
{
g_error ("Could not look up an icon for \"%s\" with flags %s at size %d",
{
GtkIcon *info;
- info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, size, 1, direction, flags);
+ info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, NULL, size, 1, direction, flags);
if (info != NULL)
{
g_assert (lookups == NULL);
- info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, size, 1, direction, flags);
+ info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, NULL, size, 1, direction, flags);
if (info)
g_object_unref (info);