[gtk: 15/40] icon-theme: Drop all load() calls from GtkIconInfo
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 15/40] icon-theme: Drop all load() calls from GtkIconInfo
- Date: Thu, 30 Jan 2020 17:32:24 +0000 (UTC)
commit 6af4b6a644bb8ad29088cf5dc37dbe426a005937
Author: Alexander Larsson <alexl redhat com>
Date: Tue Jan 28 14:54:18 2020 +0100
icon-theme: Drop all load() calls from GtkIconInfo
All users now either use it directly as a paintable or download
the texture to use the pixels.
gtk/gtkicontheme.c | 1019 ++--------------------------------------------------
gtk/gtkicontheme.h | 65 ----
2 files changed, 27 insertions(+), 1057 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index ff9f307ab7..1d88e81e26 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -2517,115 +2517,40 @@ gtk_icon_theme_error_quark (void)
return g_quark_from_static_string ("gtk-icon-theme-error-quark");
}
-/**
- * gtk_icon_theme_load_icon:
- * @self: a #GtkIconTheme
- * @icon_name: the name of the icon to lookup
- * @size: the desired icon size. The resulting icon may not be
- * exactly this size; see gtk_icon_info_load_icon().
- * @flags: flags modifying the behavior of the icon lookup
- * @error: (allow-none): Location to store error information on failure,
- * or %NULL.
- *
- * Looks up an icon in an icon theme, scales it to the given size
- * and renders it into a pixbuf. This is a convenience function;
- * if more details about the icon are needed, use
- * gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
- *
- * 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-set signal. If for some reason you do not want to
- * update the icon when the icon theme changes, you should consider
- * using gdk_pixbuf_copy() to make a private copy of the pixbuf
- * returned by this function. Otherwise GTK+ may need to keep the old
- * icon theme loaded, which would be a waste of memory.
- *
- * Returns: (nullable) (transfer full): the rendered icon; this may be
- * a newly created icon or a new reference to an internal icon, so
- * you must not modify the icon. Use g_object_unref() to release
- * your reference to the icon. %NULL if the icon isn’t found.
- */
-GdkPaintable *
-gtk_icon_theme_load_icon (GtkIconTheme *self,
- const gchar *icon_name,
- gint size,
- GtkIconLookupFlags flags,
- GError **error)
-{
- g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
- g_return_val_if_fail (icon_name != NULL, NULL);
- g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
- (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- return gtk_icon_theme_load_icon_for_scale (self, icon_name,
- size, 1, flags, error);
-}
-
-/**
- * gtk_icon_theme_load_icon_for_scale:
- * @self: a #GtkIconTheme
- * @icon_name: the name of the icon to lookup
- * @size: the desired icon size. The resulting icon may not be
- * exactly this size; see gtk_icon_info_load_icon().
- * @scale: desired scale
- * @flags: flags modifying the behavior of the icon lookup
- * @error: (allow-none): Location to store error information on failure,
- * or %NULL.
- *
- * Looks up an icon in an icon theme for a particular window scale,
- * scales it to the given size and renders it into a pixbuf. This is a
- * convenience function; if more details about the icon are needed,
- * use gtk_icon_theme_lookup_icon() followed by
- * gtk_icon_info_load_icon().
- *
- * 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-set signal. If for some reason you do not want to
- * update the icon when the icon theme changes, you should consider
- * using gdk_pixbuf_copy() to make a private copy of the pixbuf
- * returned by this function. Otherwise GTK+ may need to keep the old
- * icon theme loaded, which would be a waste of memory.
- *
- * Returns: (nullable) (transfer full): the rendered icon; this may be
- * a newly created icon or a new reference to an internal icon, so
- * you must not modify the icon. Use g_object_unref() to release
- * your reference to the icon. %NULL if the icon isn’t found.
- */
-GdkPaintable *
-gtk_icon_theme_load_icon_for_scale (GtkIconTheme *self,
- const gchar *icon_name,
- gint size,
- gint scale,
- GtkIconLookupFlags flags,
- GError **error)
+void
+gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
+ GdkRGBA *color_out,
+ GdkRGBA *success_out,
+ GdkRGBA *warning_out,
+ GdkRGBA *error_out)
{
- GtkIconInfo *icon_info;
- GdkPaintable *paintable = NULL;
+ GtkCssValue *palette, *color;
+ const GdkRGBA *lookup;
- g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
- g_return_val_if_fail (icon_name != NULL, NULL);
- g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
- (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- g_return_val_if_fail (scale >= 1, NULL);
+ color = style->core->color;
+ palette = style->core->icon_palette;
+ *color_out = *gtk_css_color_value_get_rgba (color);
- icon_info = gtk_icon_theme_lookup_icon_for_scale (self, icon_name, size, scale,
- flags | GTK_ICON_LOOKUP_USE_BUILTIN);
- if (!icon_info)
- {
- g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND,
- _("Icon “%s” not present in theme %s"), icon_name, self->current_theme);
- return NULL;
- }
+ lookup = gtk_css_palette_value_get_color (palette, "success");
+ if (lookup)
+ *success_out = *lookup;
+ else
+ *success_out = *color_out;
- paintable = gtk_icon_info_load_icon (icon_info, error);
- g_prefix_error (error, "Failed to load %s: ", icon_info->filename);
- g_object_unref (icon_info);
+ lookup = gtk_css_palette_value_get_color (palette, "warning");
+ if (lookup)
+ *warning_out = *lookup;
+ else
+ *warning_out = *color_out;
- return paintable;
+ lookup = gtk_css_palette_value_get_color (palette, "error");
+ if (lookup)
+ *error_out = *lookup;
+ else
+ *error_out = *color_out;
}
+
/**
* gtk_icon_theme_has_icon:
* @self: a #GtkIconTheme
@@ -3601,48 +3526,6 @@ icon_info_compute_rendered_size (GtkIconInfo *icon_info)
icon_info->rendered_size = rendered_size;
}
-/* This only copies whatever is needed to load the pixbuf,
- * so that we can do a load in a thread without affecting
- * the original IconInfo from the thread.
- */
-static GtkIconInfo *
-icon_info_dup (GtkIconInfo *icon_info)
-{
- GtkIconInfo *dup;
-
- dup = icon_info_new (icon_info->dir_type, icon_info->dir_size, icon_info->dir_scale);
-
- dup->filename = g_strdup (icon_info->filename);
- dup->is_svg = icon_info->is_svg;
-
- if (icon_info->loadable)
- dup->loadable = g_object_ref (icon_info->loadable);
-
- if (icon_info->cache_pixbuf)
- dup->cache_pixbuf = g_object_ref (icon_info->cache_pixbuf);
-
- dup->unscaled_scale = icon_info->unscaled_scale;
- dup->desired_size = icon_info->desired_size;
- dup->desired_scale = icon_info->desired_scale;
- dup->forced_size = icon_info->forced_size;
- dup->rendered_size = icon_info->rendered_size;
- dup->is_resource = icon_info->is_resource;
- dup->min_size = icon_info->min_size;
- dup->max_size = icon_info->max_size;
-
- g_mutex_lock (&icon_info->cache_lock);
-
- if (icon_info->texture)
- dup->texture = g_object_ref (icon_info->texture);
- dup->scale = icon_info->scale;
- dup->symbolic_width = icon_info->symbolic_width;
- dup->symbolic_height = icon_info->symbolic_height;
-
- g_mutex_unlock (&icon_info->cache_lock);
-
- return dup;
-}
-
static void
gtk_icon_info_finalize (GObject *object)
{
@@ -3762,29 +3645,6 @@ gtk_icon_info_is_symbolic (GtkIconInfo *icon_info)
icon_uri_is_symbolic (icon_info->filename, -1);
}
-/* If this returns TRUE, its safe to call icon_info_ensure_scale_and_texture__locked
- * without blocking. Call with cache_lock held.
- */
-static gboolean
-icon_info_get_pixbuf_ready__locked (GtkIconInfo *icon_info)
-{
- return icon_info->texture != NULL || icon_info->load_error != NULL;
-}
-
-static gboolean
-icon_info_get_pixbuf_ready__unlocked (GtkIconInfo *icon_info)
-{
- gboolean res;
-
- g_mutex_lock (&icon_info->cache_lock);
-
- res = icon_info_get_pixbuf_ready__locked (icon_info);
-
- g_mutex_unlock (&icon_info->cache_lock);
-
- return res;
-}
-
static void
icon_info_add_to_lru_cache__locked (GtkIconInfo *info)
{
@@ -4239,831 +4099,6 @@ icon_info_paintable_init (GdkPaintableInterface *iface)
iface->get_intrinsic_height = icon_info_paintable_get_intrinsic_height;
}
-
-/**
- * gtk_icon_info_load_icon:
- * @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
- * @error: (allow-none): location to store error information on failure,
- * or %NULL.
- *
- * Renders an icon previously looked up in an icon theme using
- * gtk_icon_theme_lookup_icon(); the size will be based on the size
- * passed to gtk_icon_theme_lookup_icon(). Note that the resulting
- * pixbuf 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 when obtaining
- * the #GtkIconInfo. If this flag has been specified, the pixbuf
- * returned by this function will be scaled to the exact size.
- *
- * Returns: (transfer full) (nullable): the rendered icon.
- * Use g_object_unref() to release your reference to the icon.
- */
-GdkPaintable *
-gtk_icon_info_load_icon (GtkIconInfo *icon_info,
- GError **error)
-{
- g_return_val_if_fail (icon_info != NULL, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- GdkPaintable *paintable = NULL;
-
- g_mutex_lock (&icon_info->cache_lock);
-
- if (!icon_info->texture)
- {
- icon_info_ensure_scale_and_texture__locked (icon_info);
-
- /* Still no texture -> error */
- if (!icon_info->texture)
- {
- if (icon_info->load_error)
- {
- if (error)
- *error = g_error_copy (icon_info->load_error);
- }
- else
- {
- g_set_error_literal (error,
- GTK_ICON_THEME_ERROR,
- GTK_ICON_THEME_NOT_FOUND,
- _("Failed to load icon"));
- }
-
- goto out;
- }
- }
-
- paintable = GDK_PAINTABLE (g_object_ref (icon_info->texture));
-
- out:
- g_mutex_unlock (&icon_info->cache_lock);
-
- return paintable;
-}
-
-/**
- * gtk_icon_info_load_icon_async:
- * @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
- * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
- * @callback: (scope async): a #GAsyncReadyCallback to call when the
- * request is satisfied
- * @user_data: (closure): the data to pass to callback function
- *
- * Asynchronously load, render and scale an icon previously looked up
- * from the icon theme using gtk_icon_theme_lookup_icon().
- *
- * For more details, see gtk_icon_info_load_icon() which is the synchronous
- * version of this call.
- */
-void
-gtk_icon_info_load_icon_async (GtkIconInfo *icon_info,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GTask *task;
-
- task = g_task_new (icon_info, cancellable, callback, user_data);
-
- if (icon_info_get_pixbuf_ready__unlocked (icon_info))
- {
- GError *error = NULL;
- GdkPaintable *paintable = gtk_icon_info_load_icon (icon_info, &error);
-
- if (paintable == NULL)
- g_task_return_error (task, error);
- else
- g_task_return_pointer (task, paintable, g_object_unref);
- }
- else
- {
- GtkIconInfo *dup = icon_info_dup (icon_info);
- g_task_set_task_data (task, dup, g_object_unref);
- g_task_run_in_thread (task, load_icon_thread);
- }
-
- g_object_unref (task);
-}
-
-/**
- * gtk_icon_info_load_icon_finish:
- * @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
- * @res: a #GAsyncResult
- * @error: (allow-none): location to store error information on failure,
- * or %NULL.
- *
- * Finishes an async icon load, see gtk_icon_info_load_icon_async().
- *
- * Returns: (transfer full): the rendered icon; this may be a newly
- * created icon or a new reference to an internal icon, so you must
- * not modify the icon. Use g_object_unref() to release your reference
- * to the icon.
- */
-GdkPaintable *
-gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info,
- GAsyncResult *result,
- GError **error)
-{
- GTask *task = G_TASK (result);
- GtkIconInfo *dup;
-
- g_return_val_if_fail (g_task_is_valid (result, icon_info), NULL);
-
- dup = g_task_get_task_data (task);
- if (dup == NULL || g_task_had_error (task))
- return g_task_propagate_pointer (task, error);
-
- /* We ran the thread and it was not cancelled */
-
- /* Check if someone else updated the icon_info in between */
- g_mutex_lock (&icon_info->cache_lock);
- if (!icon_info_get_pixbuf_ready__locked (icon_info))
- {
- /* If not, copy results from dup back to icon_info */
- icon_info->scale = dup->scale;
- g_clear_object (&icon_info->texture);
- if (dup->texture)
- icon_info->texture = g_object_ref (dup->texture);
- g_clear_error (&icon_info->load_error);
- if (dup->load_error)
- icon_info->load_error = g_error_copy (dup->load_error);
- }
-
- g_assert (icon_info_get_pixbuf_ready__locked (icon_info));
-
- g_mutex_unlock (&icon_info->cache_lock);
-
- /* This is now guaranteed to not block */
- return gtk_icon_info_load_icon (icon_info, error);
-}
-
-static GdkPixbuf *
-gtk_icon_info_load_symbolic_png (GtkIconInfo *icon_info,
- const GdkRGBA *fg,
- const GdkRGBA *success_color,
- const GdkRGBA *warning_color,
- const GdkRGBA *error_color,
- GError **error)
-{
- GdkRGBA fg_default = { 0.7450980392156863, 0.7450980392156863, 0.7450980392156863, 1.0};
- GdkRGBA success_default = { 0.3046921492332342,0.6015716792553597, 0.023437857633325704, 1.0};
- GdkRGBA warning_default = {0.9570458533607996, 0.47266346227206835, 0.2421911955443656, 1.0 };
- GdkRGBA error_default = { 0.796887159533074, 0 ,0, 1.0 };
- GdkPixbuf *pixbuf;
- GdkPixbuf *colored;
-
- g_mutex_lock (&icon_info->cache_lock);
-
- if (!icon_info_ensure_scale_and_texture__locked (icon_info))
- {
- if (icon_info->load_error)
- {
- if (error)
- *error = g_error_copy (icon_info->load_error);
- }
- else
- {
- g_set_error_literal (error,
- GTK_ICON_THEME_ERROR,
- GTK_ICON_THEME_NOT_FOUND,
- _("Failed to load icon"));
- }
- g_mutex_unlock (&icon_info->cache_lock);
-
- return NULL;
- }
-
- pixbuf = gdk_pixbuf_get_from_texture (icon_info->texture);
- g_mutex_unlock (&icon_info->cache_lock);
-
- colored = gtk_color_symbolic_pixbuf (pixbuf,
- fg ? fg : &fg_default,
- success_color ? success_color : &success_default,
- warning_color ? warning_color : &warning_default,
- error_color ? error_color : &error_default);
- g_object_unref (pixbuf);
- return colored;
-}
-
-#define MAX_RGB_STRING_LENGTH (3 + 1 + ((3 + 1) * 3) + 1 + 1)
-static inline void
-rgba_to_string_noalpha (const GdkRGBA *rgba,
- char *buff)
-{
- /* gdk_rgba_to_string inlined in here for the alpha == 1 case,
- * and g_strdup_printf replaced with g_snprintf */
- g_snprintf (buff,
- MAX_RGB_STRING_LENGTH,
- "rgb(%d,%d,%d)",
- (int)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.),
- (int)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.),
- (int)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.));
-}
-
-static GdkPixbuf *
-gtk_icon_info_load_symbolic_svg (GtkIconInfo *icon_info,
- const GdkRGBA *fg,
- const GdkRGBA *success_color,
- const GdkRGBA *warning_color,
- const GdkRGBA *error_color,
- GError **error)
-{
- GInputStream *stream;
- GdkPixbuf *pixbuf;
- char css_fg[MAX_RGB_STRING_LENGTH];
- char css_warning[MAX_RGB_STRING_LENGTH] = "rgb(245,121,62)";
- char css_success[MAX_RGB_STRING_LENGTH] = "rgb(78,154,6)";
- char css_error[MAX_RGB_STRING_LENGTH] = "rgb(204,0,0)";
- gchar *svg_data;
- gchar *width;
- gchar *height;
- guint texture_width, texture_height;
- char *escaped_file_data;
- double alpha;
- gchar alphastr[G_ASCII_DTOSTR_BUF_SIZE];
-
- alpha = fg->alpha;
-
- rgba_to_string_noalpha (fg, css_fg);
-
- if (warning_color)
- rgba_to_string_noalpha (warning_color, css_warning);
-
- if (error_color)
- rgba_to_string_noalpha (error_color, css_error);
-
- if (success_color)
- rgba_to_string_noalpha (success_color, css_success);
-
- if (icon_info->is_resource)
- {
- GBytes *bytes;
- const char *data;
- gsize file_len;
-
- bytes = g_resources_lookup_data (icon_info->filename, G_RESOURCE_LOOKUP_FLAGS_NONE, error);
- if (bytes == NULL)
- return NULL;
- data = g_bytes_get_data (bytes, &file_len);
- escaped_file_data = g_base64_encode ((guchar *) data, file_len);
- g_bytes_unref (bytes);
- }
- else
- {
- char *file_data;
- gsize file_len;
-
- if (!g_file_get_contents (icon_info->filename, &file_data, &file_len, error))
- return NULL;
- escaped_file_data = g_base64_encode ((guchar *) file_data, file_len);
- g_free (file_data);
- }
-
- g_mutex_lock (&icon_info->cache_lock);
- if (!icon_info_ensure_scale_and_texture__locked (icon_info))
- {
- g_propagate_error (error, icon_info->load_error);
- icon_info->load_error = NULL;
- g_mutex_unlock (&icon_info->cache_lock);
- g_free (escaped_file_data);
- return NULL;
- }
-
- if (icon_info->symbolic_width == 0 ||
- icon_info->symbolic_height == 0)
- {
- /* Fetch size from the original icon */
- if (icon_info->is_resource)
- pixbuf = gdk_pixbuf_new_from_resource (icon_info->filename, error);
- else
- pixbuf = gdk_pixbuf_new_from_file (icon_info->filename, error);
-
- if (!pixbuf)
- {
- g_free (escaped_file_data);
- g_mutex_unlock (&icon_info->cache_lock);
- return NULL;
- }
-
- icon_info->symbolic_width = gdk_pixbuf_get_width (pixbuf);
- icon_info->symbolic_height = gdk_pixbuf_get_height (pixbuf);
- g_object_unref (pixbuf);
- }
-
- GTK_NOTE (ICONTHEME, {
- int symbolic_size = MAX (icon_info->symbolic_width, icon_info->symbolic_height);
- if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
- g_message ("Symbolic icon %s is not in an icon theme directory",
- icon_info->key.icon_names ? icon_info->key.icon_names[0] : icon_info->filename);
- else if (icon_info->dir_size * icon_info->dir_scale != symbolic_size)
- g_message ("Symbolic icon %s of size %d is in an icon theme directory of size %d",
- icon_info->key.icon_names ? icon_info->key.icon_names[0] : icon_info->filename,
- symbolic_size,
- icon_info->dir_size * icon_info->dir_scale);
- });
-
- width = g_strdup_printf ("%d", icon_info->symbolic_width);
- height = g_strdup_printf ("%d", icon_info->symbolic_height);
-
- texture_width = gdk_texture_get_width (icon_info->texture);
- texture_height = gdk_texture_get_height (icon_info->texture);
-
- g_mutex_unlock (&icon_info->cache_lock);
-
- g_ascii_dtostr (alphastr, G_ASCII_DTOSTR_BUF_SIZE, CLAMP (alpha, 0, 1));
-
- svg_data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
- "<svg version=\"1.1\"\n"
- " xmlns=\"http://www.w3.org/2000/svg\"\n"
- " xmlns:xi=\"http://www.w3.org/2001/XInclude\"\n"
- " width=\"", width, "\"\n"
- " height=\"", height, "\">\n"
- " <style type=\"text/css\">\n"
- " rect,path,ellipse,circle,polygon {\n"
- " fill: ", css_fg," !important;\n"
- " }\n"
- " .warning {\n"
- " fill: ", css_warning, " !important;\n"
- " }\n"
- " .error {\n"
- " fill: ", css_error ," !important;\n"
- " }\n"
- " .success {\n"
- " fill: ", css_success, " !important;\n"
- " }\n"
- " </style>\n"
- " <g opacity=\"", alphastr, "\" ><xi:include href=\"data:text/xml;base64,",
escaped_file_data, "\"/></g>\n"
- "</svg>",
- NULL);
- g_free (escaped_file_data);
- g_free (width);
- g_free (height);
-
- stream = g_memory_input_stream_new_from_data (svg_data, -1, g_free);
- pixbuf = _gdk_pixbuf_new_from_stream_at_scale (stream,
- "svg",
- texture_width,
- texture_height,
- TRUE,
- NULL,
- error);
- g_object_unref (stream);
-
- return pixbuf;
-}
-
-
-static GdkPixbuf *
-gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
- const GdkRGBA *fg,
- const GdkRGBA *success_color,
- const GdkRGBA *warning_color,
- const GdkRGBA *error_color,
- GError **error)
-{
- GdkPixbuf *pixbuf;
-
- if (g_str_has_suffix (icon_info->filename, ".symbolic.png"))
- pixbuf = gtk_icon_info_load_symbolic_png (icon_info, fg, success_color, warning_color, error_color,
error);
- else
- pixbuf = gtk_icon_info_load_symbolic_svg (icon_info, fg, success_color, warning_color, error_color,
error);
-
- return pixbuf;
-}
-
-/**
- * gtk_icon_info_load_symbolic:
- * @self: a #GtkIconInfo
- * @fg: a #GdkRGBA representing the foreground color of the icon
- * @success_color: (allow-none): a #GdkRGBA representing the warning color
- * of the icon or %NULL to use the default color
- * @warning_color: (allow-none): a #GdkRGBA representing the warning color
- * of the icon or %NULL to use the default color
- * @error_color: (allow-none): a #GdkRGBA representing the error color
- * of the icon or %NULL to use the default color (allow-none)
- * @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
- * loaded icon was a symbolic one and whether the @fg color was
- * applied to it.
- * @error: (allow-none): location to store error information on failure,
- * or %NULL.
- *
- * Loads an icon, modifying it to match the system colours for the foreground,
- * success, warning and error colors provided. If the icon is not a symbolic
- * one, the function will return the result from gtk_icon_info_load_icon().
- *
- * This allows loading symbolic icons that will match the system theme.
- *
- * Unless you are implementing a widget, you will want to use
- * g_themed_icon_new_with_default_fallbacks() to load the icon.
- *
- * As implementation details, the icon loaded needs to be of SVG type,
- * contain the “symbolic” term as the last component of the icon name,
- * and use the “fg”, “success”, “warning” and “error” CSS styles in the
- * SVG file itself.
- *
- * See the [Symbolic Icons Specification](http://www.freedesktop.org/wiki/SymbolicIcons)
- * for more information about symbolic icons.
- *
- * Returns: (transfer full): a #GdkPixbuf representing the loaded icon
- */
-GdkPaintable *
-gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
- const GdkRGBA *fg,
- const GdkRGBA *success_color,
- const GdkRGBA *warning_color,
- const GdkRGBA *error_color,
- gboolean *was_symbolic,
- GError **error)
-{
- GdkPixbuf *pixbuf;
- gboolean is_symbolic;
-
- g_return_val_if_fail (icon_info != NULL, NULL);
- g_return_val_if_fail (fg != NULL, NULL);
-
- is_symbolic = gtk_icon_info_is_symbolic (icon_info);
-
- if (was_symbolic)
- *was_symbolic = is_symbolic;
-
- if (!is_symbolic)
- return gtk_icon_info_load_icon (icon_info, error);
-
- pixbuf = gtk_icon_info_load_symbolic_internal (icon_info,
- fg, success_color,
- warning_color, error_color,
- error);
- if (pixbuf)
- {
- GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf);
- g_object_unref (pixbuf);
-
- return GDK_PAINTABLE (texture);
- }
-
- return NULL;
-}
-
-void
-gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
- GdkRGBA *color_out,
- GdkRGBA *success_out,
- GdkRGBA *warning_out,
- GdkRGBA *error_out)
-{
- GtkCssValue *palette, *color;
- const GdkRGBA *lookup;
-
- color = style->core->color;
- palette = style->core->icon_palette;
- *color_out = *gtk_css_color_value_get_rgba (color);
-
- lookup = gtk_css_palette_value_get_color (palette, "success");
- if (lookup)
- *success_out = *lookup;
- else
- *success_out = *color_out;
-
- lookup = gtk_css_palette_value_get_color (palette, "warning");
- if (lookup)
- *warning_out = *lookup;
- else
- *warning_out = *color_out;
-
- lookup = gtk_css_palette_value_get_color (palette, "error");
- if (lookup)
- *error_out = *lookup;
- else
- *error_out = *color_out;
-}
-
-/**
- * gtk_icon_info_load_symbolic_for_context:
- * @self: a #GtkIconInfo
- * @context: a #GtkStyleContext
- * @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
- * loaded icon was a symbolic one and whether the foreground color was
- * applied to it.
- * @error: (allow-none): location to store error information on failure,
- * or %NULL.
- *
- * Loads an icon, modifying it to match the system colors for the foreground,
- * success, warning and error colors provided. If the icon is not a symbolic
- * one, the function will return the result from gtk_icon_info_load_icon().
- * This function uses the regular foreground color and the symbolic colors
- * with the names “success_color”, “warning_color” and “error_color” from
- * the context.
- *
- * This allows loading symbolic icons that will match the system theme.
- *
- * See gtk_icon_info_load_symbolic() for more details.
- *
- * Returns: (transfer full) (nullable): a #GdkPixbuf representing the loaded icon
- * or %NULL If the icon could not be loaded
- */
-GdkPaintable *
-gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
- GtkStyleContext *context,
- gboolean *was_symbolic,
- GError **error)
-{
- GdkRGBA fg;
- GdkRGBA success_color;
- GdkRGBA warning_color;
- GdkRGBA error_color;
- gboolean is_symbolic;
- GdkPixbuf *pixbuf;
-
- g_return_val_if_fail (icon_info != NULL, NULL);
- g_return_val_if_fail (context != NULL, NULL);
-
- is_symbolic = gtk_icon_info_is_symbolic (icon_info);
-
- if (was_symbolic)
- *was_symbolic = is_symbolic;
-
- if (!is_symbolic)
- return gtk_icon_info_load_icon (icon_info, error);
-
- gtk_icon_theme_lookup_symbolic_colors (gtk_style_context_lookup_style (context),
- &fg, &success_color,
- &warning_color, &error_color);
-
- pixbuf = gtk_icon_info_load_symbolic_internal (icon_info,
- &fg, &success_color,
- &warning_color, &error_color,
- error);
-
- if (pixbuf)
- {
- GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf);
- g_object_unref (pixbuf);
-
- return GDK_PAINTABLE (texture);
- }
-
- return NULL;
-}
-
-typedef struct {
- guint is_symbolic : 1;
- guint success_color_set : 1;
- guint warning_color_set : 1;
- guint error_color_set : 1;
- guint fg_set : 1;
- GtkIconInfo *dup;
- GdkRGBA fg;
- GdkRGBA success_color;
- GdkRGBA warning_color;
- GdkRGBA error_color;
-} AsyncSymbolicData;
-
-static void
-async_symbolic_data_free (AsyncSymbolicData *data)
-{
- if (data->dup)
- g_object_unref (data->dup);
- g_slice_free (AsyncSymbolicData, data);
-}
-
-static void
-async_load_no_symbolic_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GtkIconInfo *icon_info = GTK_ICON_INFO (source_object);
- GTask *task = user_data;
- GError *error = NULL;
- GdkPaintable *paintable;
-
- paintable = gtk_icon_info_load_icon_finish (icon_info, res, &error);
- if (paintable == NULL)
- g_task_return_error (task, error);
- else
- g_task_return_pointer (task, paintable, g_object_unref);
- g_object_unref (task);
-}
-
-static void
-load_symbolic_icon_thread (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- AsyncSymbolicData *data = task_data;
- GError *error;
- GdkPixbuf *pixbuf;
-
- error = NULL;
- pixbuf = gtk_icon_info_load_symbolic_internal (data->dup,
- data->fg_set ? &data->fg : NULL,
- data->success_color_set ? &data->success_color : NULL,
- data->warning_color_set ? &data->warning_color : NULL,
- data->error_color_set ? &data->error_color : NULL,
- &error);
- if (pixbuf == NULL)
- g_task_return_error (task, error);
- else
- g_task_return_pointer (task, pixbuf, g_object_unref);
-}
-
-/**
- * gtk_icon_info_load_symbolic_async:
- * @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
- * @fg: a #GdkRGBA representing the foreground color of the icon
- * @success_color: (allow-none): a #GdkRGBA representing the warning color
- * of the icon or %NULL to use the default color
- * @warning_color: (allow-none): a #GdkRGBA representing the warning color
- * of the icon or %NULL to use the default color
- * @error_color: (allow-none): a #GdkRGBA representing the error color
- * of the icon or %NULL to use the default color (allow-none)
- * @cancellable: (allow-none): optional #GCancellable object,
- * %NULL to ignore
- * @callback: (scope async): a #GAsyncReadyCallback to call when the
- * request is satisfied
- * @user_data: (closure): the data to pass to callback function
- *
- * Asynchronously load, render and scale a symbolic icon previously looked up
- * from the icon theme using gtk_icon_theme_lookup_icon().
- *
- * For more details, see gtk_icon_info_load_symbolic() which is the synchronous
- * version of this call.
- */
-void
-gtk_icon_info_load_symbolic_async (GtkIconInfo *icon_info,
- const GdkRGBA *fg,
- const GdkRGBA *success_color,
- const GdkRGBA *warning_color,
- const GdkRGBA *error_color,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GTask *task;
- AsyncSymbolicData *data;
-
- g_return_if_fail (icon_info != NULL);
- g_return_if_fail (fg != NULL);
-
- task = g_task_new (icon_info, cancellable, callback, user_data);
-
- data = g_slice_new0 (AsyncSymbolicData);
- g_task_set_task_data (task, data, (GDestroyNotify) async_symbolic_data_free);
-
- data->is_symbolic = gtk_icon_info_is_symbolic (icon_info);
-
- if (!data->is_symbolic)
- {
- gtk_icon_info_load_icon_async (icon_info, cancellable, async_load_no_symbolic_cb, g_object_ref (task));
- }
- else
- {
- if (fg)
- {
- data->fg = *fg;
- data->fg_set = TRUE;
- }
-
- if (success_color)
- {
- data->success_color = *success_color;
- data->success_color_set = TRUE;
- }
-
- if (warning_color)
- {
- data->warning_color = *warning_color;
- data->warning_color_set = TRUE;
- }
-
- if (error_color)
- {
- data->error_color = *error_color;
- data->error_color_set = TRUE;
- }
-
- data->dup = icon_info_dup (icon_info);
- g_task_run_in_thread (task, load_symbolic_icon_thread);
- }
- g_object_unref (task);
-}
-
-/**
- * gtk_icon_info_load_symbolic_finish:
- * @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
- * @res: a #GAsyncResult
- * @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
- * loaded icon was a symbolic one and whether the @fg color was
- * applied to it.
- * @error: (allow-none): location to store error information on failure,
- * or %NULL.
- *
- * Finishes an async icon load, see gtk_icon_info_load_symbolic_async().
- *
- * Returns: (transfer full): the rendered icon;
- * Use g_object_unref() to release your reference
- * to the icon.
- */
-GdkPaintable *
-gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info,
- GAsyncResult *result,
- gboolean *was_symbolic,
- GError **error)
-{
- GTask *task = G_TASK (result);
- AsyncSymbolicData *data = g_task_get_task_data (task);
- GdkPixbuf *pixbuf;
- GdkTexture *texture;
-
- if (was_symbolic)
- *was_symbolic = data->is_symbolic;
-
- if (data->dup && !g_task_had_error (task))
- {
- pixbuf = g_task_propagate_pointer (task, NULL);
-
- g_assert (pixbuf != NULL); /* we checked for !had_error above */
- }
- else
- {
- pixbuf = g_task_propagate_pointer (task, error);
- }
-
- texture = gdk_texture_new_for_pixbuf (pixbuf);
- g_object_unref (pixbuf);
-
- return GDK_PAINTABLE (texture);
-}
-
-/**
- * gtk_icon_info_load_symbolic_for_context_async:
- * @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
- * @context: a #GtkStyleContext
- * @cancellable: (allow-none): optional #GCancellable object,
- * %NULL to ignore
- * @callback: (scope async): a #GAsyncReadyCallback to call when the
- * request is satisfied
- * @user_data: (closure): the data to pass to callback function
- *
- * Asynchronously load, render and scale a symbolic icon previously
- * looked up from the icon theme using gtk_icon_theme_lookup_icon().
- *
- * For more details, see gtk_icon_info_load_symbolic_for_context()
- * which is the synchronous version of this call.
- */
-void
-gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info,
- GtkStyleContext *context,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GdkRGBA fg;
- GdkRGBA success_color;
- GdkRGBA warning_color;
- GdkRGBA error_color;
-
- g_return_if_fail (icon_info != NULL);
- g_return_if_fail (context != NULL);
-
- gtk_icon_theme_lookup_symbolic_colors (gtk_style_context_lookup_style (context),
- &fg, &success_color,
- &warning_color, &error_color);
-
- gtk_icon_info_load_symbolic_async (icon_info,
- &fg, &success_color,
- &warning_color, &error_color,
- cancellable, callback, user_data);
-}
-
-/**
- * gtk_icon_info_load_symbolic_for_context_finish:
- * @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
- * @res: a #GAsyncResult
- * @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
- * loaded icon was a symbolic one and whether the @fg color was
- * applied to it.
- * @error: (allow-none): location to store error information on failure,
- * or %NULL.
- *
- * Finishes an async icon load, see gtk_icon_info_load_symbolic_for_context_async().
- *
- * Returns: (transfer full): the rendered icon; this may be a newly
- * created icon or a new reference to an internal icon, so you must
- * not modify the icon. Use g_object_unref() to release your reference
- * to the icon.
- */
-GdkPaintable *
-gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info,
- GAsyncResult *result,
- gboolean *was_symbolic,
- GError **error)
-{
- return gtk_icon_info_load_symbolic_finish (icon_info, result, was_symbolic, error);
-}
-
/**
* gtk_icon_theme_lookup_by_gicon:
* @self: a #GtkIconTheme
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index 6ec132b272..c1f60303be 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -182,20 +182,6 @@ GtkIconInfo * gtk_icon_theme_choose_icon_finish (GtkIconTheme
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_ALL
-GdkPaintable *gtk_icon_theme_load_icon (GtkIconTheme *self,
- const char *icon_name,
- int size,
- GtkIconLookupFlags flags,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-GdkPaintable *gtk_icon_theme_load_icon_for_scale (GtkIconTheme *self,
- const gchar *icon_name,
- gint size,
- gint scale,
- GtkIconLookupFlags flags,
- GError **error);
-
-GDK_AVAILABLE_IN_ALL
GtkIconInfo * gtk_icon_theme_lookup_by_gicon (GtkIconTheme *self,
GIcon *icon,
gint size,
@@ -246,57 +232,6 @@ void gtk_icon_info_snapshot_with_colors (GtkIconInfo *icon_info
const GdkRGBA *success_color,
const GdkRGBA *warning_color,
const GdkRGBA *error_color);
-GDK_AVAILABLE_IN_ALL
-GdkPaintable * gtk_icon_info_load_icon (GtkIconInfo *self,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-void gtk_icon_info_load_icon_async (GtkIconInfo *self,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-GDK_AVAILABLE_IN_ALL
-GdkPaintable * gtk_icon_info_load_icon_finish (GtkIconInfo *self,
- GAsyncResult *res,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-GdkPaintable * gtk_icon_info_load_symbolic (GtkIconInfo *self,
- const GdkRGBA *fg,
- const GdkRGBA *success_color,
- const GdkRGBA *warning_color,
- const GdkRGBA *error_color,
- gboolean *was_symbolic,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-void gtk_icon_info_load_symbolic_async (GtkIconInfo *self,
- const GdkRGBA *fg,
- const GdkRGBA *success_color,
- const GdkRGBA *warning_color,
- const GdkRGBA *error_color,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-GDK_AVAILABLE_IN_ALL
-GdkPaintable * gtk_icon_info_load_symbolic_finish (GtkIconInfo *self,
- GAsyncResult *res,
- gboolean *was_symbolic,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-GdkPaintable * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *self,
- GtkStyleContext *context,
- gboolean *was_symbolic,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-void gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *self,
- GtkStyleContext *context,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-GDK_AVAILABLE_IN_ALL
-GdkPaintable * gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *self,
- GAsyncResult *res,
- gboolean *was_symbolic,
- GError **error);
-
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]