icontheme: Return textures from load_icon{,_for_scale}

This commit is contained in:
Timm Bäder 2019-08-30 20:54:16 +02:00
parent 37f8e6aabd
commit f3099afcc5
6 changed files with 28 additions and 29 deletions

View File

@ -128,18 +128,16 @@ insert_text (GtkTextBuffer *buffer)
{ {
GtkTextIter iter; GtkTextIter iter;
GtkTextIter start, end; GtkTextIter start, end;
GdkPixbuf *pixbuf;
GdkTexture *texture; GdkTexture *texture;
GtkIconTheme *icon_theme; GtkIconTheme *icon_theme;
icon_theme = gtk_icon_theme_get_default (); icon_theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (icon_theme, texture = GDK_TEXTURE (gtk_icon_theme_load_icon (icon_theme,
"gtk3-demo", "gtk3-demo",
32, 32,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, GTK_ICON_LOOKUP_GENERIC_FALLBACK,
NULL); NULL));
g_assert (pixbuf); g_assert (texture);
texture = gdk_texture_new_for_pixbuf (pixbuf);
/* get start of buffer; each insertion will revalidate the /* get start of buffer; each insertion will revalidate the
* iterator to point to just after the inserted text. * iterator to point to just after the inserted text.
@ -379,7 +377,6 @@ insert_text (GtkTextBuffer *buffer)
gtk_text_buffer_get_bounds (buffer, &start, &end); gtk_text_buffer_get_bounds (buffer, &start, &end);
gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end); gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
g_object_unref (pixbuf);
g_object_unref (texture); g_object_unref (texture);
} }

View File

@ -333,7 +333,6 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
* gdk_pixbuf_get_rowstride (pixbuf), * gdk_pixbuf_get_rowstride (pixbuf),
g_object_unref, g_object_unref,
g_object_ref (pixbuf)); g_object_ref (pixbuf));
texture = gdk_memory_texture_new (gdk_pixbuf_get_width (pixbuf), texture = gdk_memory_texture_new (gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf), gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_has_alpha (pixbuf) gdk_pixbuf_get_has_alpha (pixbuf)

View File

@ -2156,6 +2156,7 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
if (pixbuf == NULL) if (pixbuf == NULL)
{ {
GtkIconTheme *theme; GtkIconTheme *theme;
GdkPaintable *texture;
g_warning ("Could not load image '%s': %s", g_warning ("Could not load image '%s': %s",
string, tmp_error->message); string, tmp_error->message);
@ -2163,11 +2164,13 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
/* fall back to a missing image */ /* fall back to a missing image */
theme = gtk_icon_theme_get_default (); theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, texture = gtk_icon_theme_load_icon (theme,
"image-missing", "image-missing",
16, 16,
GTK_ICON_LOOKUP_USE_BUILTIN, GTK_ICON_LOOKUP_USE_BUILTIN,
NULL); NULL);
pixbuf = gdk_pixbuf_get_from_texture (GDK_TEXTURE (texture));
g_object_unref (texture);
} }
if (pixbuf) if (pixbuf)

View File

@ -2264,7 +2264,7 @@ gtk_icon_theme_error_quark (void)
* you must not modify the icon. Use g_object_unref() to release * you must not modify the icon. Use g_object_unref() to release
* your reference to the icon. %NULL if the icon isnt found. * your reference to the icon. %NULL if the icon isnt found.
*/ */
GdkPixbuf * GdkPaintable *
gtk_icon_theme_load_icon (GtkIconTheme *icon_theme, gtk_icon_theme_load_icon (GtkIconTheme *icon_theme,
const gchar *icon_name, const gchar *icon_name,
gint size, gint size,
@ -2311,7 +2311,7 @@ gtk_icon_theme_load_icon (GtkIconTheme *icon_theme,
* you must not modify the icon. Use g_object_unref() to release * you must not modify the icon. Use g_object_unref() to release
* your reference to the icon. %NULL if the icon isnt found. * your reference to the icon. %NULL if the icon isnt found.
*/ */
GdkPixbuf * GdkPaintable *
gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme, gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
const gchar *icon_name, const gchar *icon_name,
gint size, gint size,
@ -2320,7 +2320,7 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
GError **error) GError **error)
{ {
GtkIconInfo *icon_info; GtkIconInfo *icon_info;
GdkPixbuf *pixbuf = NULL; GdkTexture *texture = NULL;
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
g_return_val_if_fail (icon_name != NULL, NULL); g_return_val_if_fail (icon_name != NULL, NULL);
@ -2338,11 +2338,11 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
return NULL; return NULL;
} }
pixbuf = gtk_icon_info_load_icon (icon_info, error); texture = gtk_icon_info_load_texture (icon_info, error);
g_prefix_error (error, "Failed to load %s: ", icon_info->filename); g_prefix_error (error, "Failed to load %s: ", icon_info->filename);
g_object_unref (icon_info); g_object_unref (icon_info);
return pixbuf; return GDK_PAINTABLE (texture);
} }
/** /**

View File

@ -169,13 +169,13 @@ GtkIconInfo * gtk_icon_theme_choose_icon_for_scale (GtkIconTheme
gint scale, gint scale,
GtkIconLookupFlags flags); GtkIconLookupFlags flags);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_theme_load_icon (GtkIconTheme *icon_theme, GdkPaintable *gtk_icon_theme_load_icon (GtkIconTheme *icon_theme,
const gchar *icon_name, const char *icon_name,
gint size, int size,
GtkIconLookupFlags flags, GtkIconLookupFlags flags,
GError **error); GError **error);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme, GdkPaintable *gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
const gchar *icon_name, const gchar *icon_name,
gint size, gint size,
gint scale, gint scale,

View File

@ -93,7 +93,7 @@ main (int argc, char *argv[])
if (strcmp (argv[1], "display") == 0) if (strcmp (argv[1], "display") == 0)
{ {
GError *error; GError *error;
GdkPixbuf *pixbuf; GdkPaintable *paintable;
GtkWidget *window, *image; GtkWidget *window, *image;
if (argc < 4) if (argc < 4)
@ -110,8 +110,8 @@ main (int argc, char *argv[])
scale = atoi (argv[5]); scale = atoi (argv[5]);
error = NULL; error = NULL;
pixbuf = gtk_icon_theme_load_icon_for_scale (icon_theme, argv[3], size, scale, flags, &error); paintable = gtk_icon_theme_load_icon_for_scale (icon_theme, argv[3], size, scale, flags, &error);
if (!pixbuf) if (!paintable)
{ {
g_print ("%s\n", error->message); g_print ("%s\n", error->message);
return 1; return 1;
@ -119,8 +119,8 @@ main (int argc, char *argv[])
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
image = gtk_image_new (); image = gtk_image_new ();
gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); gtk_image_set_from_paintable (GTK_IMAGE (image), paintable);
g_object_unref (pixbuf); g_object_unref (paintable);
gtk_container_add (GTK_CONTAINER (window), image); gtk_container_add (GTK_CONTAINER (window), image);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window); gtk_widget_show (window);