Commit 571021cb authored by Benjamin Otte's avatar Benjamin Otte Committed by Alexander Larsson
Browse files

icontheme: Pass fallbacks as optional argument to lookup_icon()

This way, we can remove gtk_icon_theme_choose_icon() completely.
parent f7a5dd7b
......@@ -109,6 +109,7 @@ get_image_paintable (GtkImage *image)
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);
......
......@@ -137,6 +137,7 @@ insert_text (GtkTextView *view)
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);
......
......@@ -369,6 +369,7 @@ get_image_paintable (GtkImage *image)
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);
......@@ -425,6 +426,7 @@ get_file (GValue *value,
info = gtk_icon_theme_lookup_icon (icon_theme,
name,
NULL,
32, 1,
gtk_widget_get_direction (GTK_WIDGET (data)),
0);
......
......@@ -5005,7 +5005,6 @@ gtk_icon_theme_add_resource_path
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
......
......@@ -2171,7 +2171,7 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
/* 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);
......
......@@ -2606,6 +2606,7 @@ gtk_calendar_drag_update (GtkGestureDrag *gesture,
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,
......
......@@ -63,6 +63,7 @@ gtk_css_image_icon_theme_snapshot (GtkCssImage *image,
{
icon = gtk_icon_theme_lookup_icon (icon_theme->icon_theme,
icon_theme->name,
NULL,
size,
icon_theme->scale,
GTK_TEXT_DIR_NONE,
......@@ -70,6 +71,7 @@ gtk_css_image_icon_theme_snapshot (GtkCssImage *image,
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);
......
......@@ -488,6 +488,7 @@ gtk_drag_source_drag_begin (GtkDragSource *source)
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),
......
......@@ -112,6 +112,7 @@ ensure_paintable_for_gicon (GtkIconHelper *self,
if (icon == NULL)
icon = gtk_icon_theme_lookup_icon (icon_theme,
"image-missing",
NULL,
width, scale,
dir,
flags | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
......
......@@ -2148,6 +2148,7 @@ choose_icon (GtkIconTheme *self,
* 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
......@@ -2167,20 +2168,20 @@ choose_icon (GtkIconTheme *self,
* 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,
......@@ -2205,6 +2206,8 @@ gtk_icon_theme_lookup_icon (GtkIconTheme *self,
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"));
......@@ -2244,10 +2247,23 @@ gtk_icon_theme_lookup_icon (GtkIconTheme *self,
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];
......@@ -2263,70 +2279,6 @@ gtk_icon_theme_lookup_icon (GtkIconTheme *self,
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)
......@@ -3972,8 +3924,8 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme *self,
{
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;
}
......
......@@ -125,14 +125,8 @@ gint *gtk_icon_theme_get_icon_sizes (GtkIconTheme
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,
......
......@@ -1176,6 +1176,7 @@ add_pid_to_process_list_store (GtkMountOperation *mount_operation,
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);
......
......@@ -4027,12 +4027,12 @@ icon_list_from_theme (GtkWindow *window,
* 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);
......@@ -4114,7 +4114,7 @@ gtk_window_get_icon_for_size (GtkWindow *window,
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)
......
......@@ -288,6 +288,7 @@ get_button_list (GdkClipboard *clipboard,
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);
......
......@@ -27,6 +27,7 @@ get_image_texture (GtkImage *image,
*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);
......@@ -234,6 +235,7 @@ update_source_icon (GtkDragSource *source,
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);
......
......@@ -85,7 +85,7 @@ main (int argc, char *argv[])
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]);
......@@ -127,7 +127,7 @@ main (int argc, char *argv[])
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>");
......
......@@ -80,7 +80,7 @@ test_icon_existence (gconstpointer icon_name)
* 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);
......
......@@ -58,7 +58,7 @@ assert_icon_lookup_size (const 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",
......@@ -113,7 +113,7 @@ assert_icon_lookup_fails (const 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)
{
......@@ -177,7 +177,7 @@ assert_lookup_order (const char *icon_name,
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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment