diff options
-rw-r--r-- | demos/gtk-demo/clipboard.c | 2 | ||||
-rw-r--r-- | gtk/gtkcssimageicontheme.c | 2 | ||||
-rw-r--r-- | gtk/gtkiconhelper.c | 2 | ||||
-rw-r--r-- | gtk/gtkicontheme.c | 37 | ||||
-rw-r--r-- | gtk/gtkicontheme.h | 7 | ||||
-rw-r--r-- | gtk/gtkmountoperation.c | 2 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 4 | ||||
-rw-r--r-- | tests/testdnd2.c | 2 | ||||
-rw-r--r-- | tests/testimage.c | 2 |
9 files changed, 45 insertions, 15 deletions
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c index 36569d8d07..9d6b281d7c 100644 --- a/demos/gtk-demo/clipboard.c +++ b/demos/gtk-demo/clipboard.c @@ -110,7 +110,7 @@ get_image_paintable (GtkImage *image) 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)); diff --git a/gtk/gtkcssimageicontheme.c b/gtk/gtkcssimageicontheme.c index 582dbfec30..093b9e9012 100644 --- a/gtk/gtkcssimageicontheme.c +++ b/gtk/gtkcssimageicontheme.c @@ -79,7 +79,7 @@ gtk_css_image_icon_theme_snapshot (GtkCssImage *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); diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c index 5e96bb8e64..e6976b3a29 100644 --- a/gtk/gtkiconhelper.c +++ b/gtk/gtkiconhelper.c @@ -122,7 +122,7 @@ ensure_paintable_for_gicon (GtkIconHelper *self, 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) diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 8389e4acce..48e3968343 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -49,6 +49,7 @@ #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 @@ -3813,24 +3814,52 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info, /** * 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); } diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index de0cd2308d..5a98d149a1 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -65,7 +65,7 @@ typedef struct _GtkIconTheme GtkIconTheme; * 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 @@ -92,7 +92,7 @@ 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 { @@ -225,7 +225,8 @@ GDK_AVAILABLE_IN_ALL 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, diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c index 4ad02628ab..f5fab79029 100644 --- a/gtk/gtkmountoperation.c +++ b/gtk/gtkmountoperation.c @@ -1171,7 +1171,7 @@ add_pid_to_process_list_store (GtkMountOperation *mount_operation, (_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); } diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 5748b278e5..513232c309 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -4048,7 +4048,7 @@ icon_list_from_theme (GtkWindow *window, 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); } } @@ -4126,7 +4126,7 @@ gtk_window_get_icon_for_size (GtkWindow *window, 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; diff --git a/tests/testdnd2.c b/tests/testdnd2.c index b94362e57c..7df9bb3a90 100644 --- a/tests/testdnd2.c +++ b/tests/testdnd2.c @@ -21,7 +21,7 @@ get_image_paintable (GtkImage *image, 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: diff --git a/tests/testimage.c b/tests/testimage.c index 2e2d5da50b..b595cd8f4d 100644 --- a/tests/testimage.c +++ b/tests/testimage.c @@ -110,7 +110,7 @@ main (int argc, char **argv) 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); |