[gtk/clipboard-emo] gtk-demo: Fix up image handling in the clipboard demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/clipboard-emo] gtk-demo: Fix up image handling in the clipboard demo
- Date: Thu, 15 Oct 2020 13:19:49 +0000 (UTC)
commit 8cf955731fd6c5ac36c8b590dad0fb1de9482af3
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Oct 15 09:16:17 2020 -0400
gtk-demo: Fix up image handling in the clipboard demo
Using GtkIconPaintable+GtkPicture is not good for symbolic
icons - they don't get properly colored that way. So change
things around to use the icon name if we have it.
Fixes: #3252
demos/gtk-demo/demoimage.c | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/demos/gtk-demo/demoimage.c b/demos/gtk-demo/demoimage.c
index 40acbd2dce..a7ecb6e213 100644
--- a/demos/gtk-demo/demoimage.c
+++ b/demos/gtk-demo/demoimage.c
@@ -47,6 +47,38 @@ get_image_paintable (GtkImage *image)
}
}
+static void
+update_drag_icon (DemoImage *demo,
+ GtkDragIcon *icon)
+{
+ const char *icon_name;
+ GdkPaintable *paintable;
+ GtkWidget *image;
+
+ switch (gtk_image_get_storage_type (GTK_IMAGE (demo->image)))
+ {
+ case GTK_IMAGE_PAINTABLE:
+ paintable = gtk_image_get_paintable (GTK_IMAGE (demo->image));
+ image = gtk_image_new_from_paintable (paintable);
+ break;
+ case GTK_IMAGE_ICON_NAME:
+ icon_name = gtk_image_get_icon_name (GTK_IMAGE (demo->image));
+ image = gtk_image_new_from_icon_name (icon_name);
+ break;
+ case GTK_IMAGE_EMPTY:
+ case GTK_IMAGE_GICON:
+ default:
+ g_warning ("Image storage type %d not handled",
+ gtk_image_get_storage_type (GTK_IMAGE (demo->image)));
+ return;
+ }
+
+ gtk_image_set_pixel_size (GTK_IMAGE (image),
+ gtk_image_get_pixel_size (GTK_IMAGE (demo->image)));
+
+ gtk_drag_icon_set_child (icon, image);
+}
+
static void
drag_begin (GtkDragSource *source,
GdkDrag *drag,
@@ -54,14 +86,8 @@ drag_begin (GtkDragSource *source,
{
GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
DemoImage *demo = DEMO_IMAGE (widget);
- GdkPaintable *paintable;
- paintable = get_image_paintable (GTK_IMAGE (demo->image));
- if (paintable)
- {
- gtk_drag_icon_set_from_paintable (drag, paintable, -2, -2);
- g_object_unref (paintable);
- }
+ update_drag_icon (demo, GTK_DRAG_ICON (gtk_drag_icon_get_for_drag (drag)));
}
static GdkContentProvider *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]