Commit 590e70d4 authored by Timm Bäder's avatar Timm Bäder 👎

icontheme: Return a paintable from gtk_icon_info_load_icon

parent fd16ac4d
......@@ -3740,37 +3740,10 @@ proxy_pixbuf_destroy (guchar *pixels, gpointer data)
g_object_unref (icon_info);
}
/**
* gtk_icon_info_load_icon:
* @icon_info: 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; 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.
* If the icon could not be loaded, %NULL is returned and @error is set.
*/
GdkPixbuf *
gtk_icon_info_load_icon (GtkIconInfo *icon_info,
GError **error)
static GdkPixbuf *
icon_info_load_pixbuf (GtkIconInfo *icon_info,
GError **error)
{
g_return_val_if_fail (icon_info != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (!icon_info_ensure_scale_and_pixbuf (icon_info))
{
if (icon_info->load_error)
......@@ -3812,6 +3785,40 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
return icon_info->proxy_pixbuf;
}
/**
* gtk_icon_info_load_icon:
* @icon_info: 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; 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.
* If the icon could not be loaded, %NULL is returned and @error is set.
*/
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);
return (GdkPaintable *)gtk_icon_info_load_texture (icon_info, error);
}
/**
* gtk_icon_info_load_texture:
* @icon_info: a #GtkIconInfo
......@@ -3837,7 +3844,7 @@ gtk_icon_info_load_texture (GtkIconInfo *icon_info,
{
GdkPixbuf *pixbuf;
pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
pixbuf = icon_info_load_pixbuf (icon_info, NULL);
if (!pixbuf)
{
......@@ -3904,7 +3911,6 @@ gtk_icon_info_load_icon_async (GtkIconInfo *icon_info,
gpointer user_data)
{
GTask *task;
GdkPixbuf *pixbuf;
GtkIconInfo *dup;
GError *error = NULL;
......@@ -3912,11 +3918,12 @@ gtk_icon_info_load_icon_async (GtkIconInfo *icon_info,
if (icon_info_get_pixbuf_ready (icon_info))
{
pixbuf = gtk_icon_info_load_icon (icon_info, &error);
if (pixbuf == 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, pixbuf, g_object_unref);
g_task_return_pointer (task, paintable, g_object_unref);
g_object_unref (task);
}
else
......
......@@ -222,8 +222,8 @@ const gchar * gtk_icon_info_get_filename (GtkIconInfo *icon_info
GDK_AVAILABLE_IN_ALL
gboolean gtk_icon_info_is_symbolic (GtkIconInfo *icon_info);
GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_info_load_icon (GtkIconInfo *icon_info,
GError **error);
GdkPaintable * gtk_icon_info_load_icon (GtkIconInfo *icon_info,
GError **error);
GDK_AVAILABLE_IN_ALL
GdkTexture * gtk_icon_info_load_texture (GtkIconInfo *icon_info,
GError **error);
......
......@@ -211,15 +211,15 @@ main (int argc, char *argv[])
if (icon_info)
{
GdkPixbuf *pixbuf;
GdkTexture *texture;
g_print ("Base size: %d, Scale: %d\n", gtk_icon_info_get_base_size (icon_info), gtk_icon_info_get_base_scale (icon_info));
pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
if (pixbuf != NULL)
texture = GDK_TEXTURE (gtk_icon_info_load_icon (icon_info, NULL));
if (texture != NULL)
{
g_print ("Pixbuf size: %dx%d\n", gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
g_object_unref (pixbuf);
g_print ("texture size: %dx%d\n", gdk_texture_get_width (texture), gdk_texture_get_height (texture));
g_object_unref (texture);
}
g_object_unref (icon_info);
......
......@@ -82,13 +82,13 @@ assert_icon_lookup_size (const char *icon_name,
if (pixbuf_size > 0)
{
GdkPixbuf *pixbuf;
GdkTexture *texture;
GError *error = NULL;
pixbuf = gtk_icon_info_load_icon (info, &error);
texture = GDK_TEXTURE (gtk_icon_info_load_icon (info, &error));
g_assert_no_error (error);
g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, pixbuf_size);
g_object_unref (pixbuf);
g_assert_cmpint (gdk_texture_get_width (texture), ==, pixbuf_size);
g_object_unref (texture);
}
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