Loading an icon might fail.
icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
if (icon_info == NULL)
return NULL;
- return GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info));
+ return GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info, NULL));
default:
g_warning ("Image storage type %d not handled",
gtk_image_get_storage_type (image));
g_assert (icon_info != NULL);
symbolic = gtk_icon_info_is_symbolic (icon_info);
- texture = gtk_icon_info_load_texture (icon_info);
+ texture = gtk_icon_info_load_texture (icon_info, NULL);
g_clear_object (&icon_theme->cached_texture);
flags | GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
*symbolic = gtk_icon_info_is_symbolic (info);
- paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (info));
+ paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (info, NULL));
g_object_unref (info);
if (paintable && scale != 1)
#include "gtkstylecontextprivate.h"
#include "gtkprivate.h"
#include "gdkpixbufutilsprivate.h"
+#include "gdk/gdktextureprivate.h"
/* this is in case round() is not provided by the compiler,
* such as in the case of C89 compilers, like MSVC
/**
* gtk_icon_info_load_texture:
* @icon_info: a #GtkIconInfo
+ * @error: (nullable): location to store error information on failure,
+ * or %NULL.
*
* Returns a texture object that can be used to render the icon
* with GSK.
*
- * Returns: (transfer full): the icon texture; this may be a newly
+ * Returns: (transfer full) (nullable): the icon texture; this may be a newly
* created texture or a new reference to an exiting texture. Use
* g_object_unref() to release your reference.
+ * In case of failure, %NULL is returned and @error is set
*/
GdkTexture *
-gtk_icon_info_load_texture (GtkIconInfo *icon_info)
+gtk_icon_info_load_texture (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->texture)
{
GdkPixbuf *pixbuf;
pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
- icon_info->texture = gdk_texture_new_for_pixbuf (pixbuf);
- g_object_unref (pixbuf);
+
+ if (!pixbuf)
+ {
+ 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"));
+ }
+
+ return NULL;
+ }
+ else
+ {
+ icon_info->texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+ }
g_object_add_weak_pointer (G_OBJECT (icon_info->texture), (void **)&icon_info->texture);
}
* text direction
* @GTK_ICON_LOOKUP_DIR_RTL: Try to load a variant of the icon for right-to-left
* text direction
- *
+ *
* Used to specify options for gtk_icon_theme_lookup_icon()
*/
typedef enum
* GtkIconThemeError:
* @GTK_ICON_THEME_NOT_FOUND: The icon specified does not exist in the theme
* @GTK_ICON_THEME_FAILED: An unspecified error occurred.
- *
+ *
* Error codes for GtkIconTheme operations.
**/
typedef enum {
GdkPixbuf * gtk_icon_info_load_icon (GtkIconInfo *icon_info,
GError **error);
GDK_AVAILABLE_IN_ALL
-GdkTexture * gtk_icon_info_load_texture (GtkIconInfo *icon_info);
+GdkTexture * gtk_icon_info_load_texture (GtkIconInfo *icon_info,
+ GError **error);
GDK_AVAILABLE_IN_ALL
void gtk_icon_info_load_icon_async (GtkIconInfo *icon_info,
(_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (mount_operation->priv->dialog)),
GTK_CSS_PROPERTY_ICON_THEME));
info = gtk_icon_theme_lookup_icon (theme, "application-x-executable", 24, 0);
- texture = gtk_icon_info_load_texture (info);
+ texture = gtk_icon_info_load_texture (info, NULL);
g_object_unref (info);
}
0);
if (info)
{
- list = g_list_insert_sorted (list, gtk_icon_info_load_texture (info), (GCompareFunc) icon_size_compare);
+ list = g_list_insert_sorted (list, gtk_icon_info_load_texture (info, NULL), (GCompareFunc) icon_size_compare);
g_object_unref (info);
}
}
if (info == NULL)
return NULL;
- texture = gtk_icon_info_load_texture (info);
+ texture = gtk_icon_info_load_texture (info, NULL);
g_object_unref (info);
return texture;
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
*out_size = width;
icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, width, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
- paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info));
+ paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info, NULL));
g_object_unref (icon_info);
return paintable;
default:
theme = gtk_icon_theme_get_default ();
icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, icon_name, 48, gtk_widget_get_scale_factor (window), GTK_ICON_LOOKUP_GENERIC_FALLBACK);
- texture = gtk_icon_info_load_texture (icon_info);
+ texture = gtk_icon_info_load_texture (icon_info, NULL);
g_object_unref (icon_info);
image = gtk_image_new_from_paintable (GDK_PAINTABLE (texture));
g_object_unref (texture);