From a8608618a909e50309a400c9c857aadd2e1afa6d Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 15 Mar 2018 02:53:17 +0100 Subject: [PATCH] dragsource: Replace gtk_drag_source_set_icon_surface() ... with gtk_drag_source_set_icon_paintable(). --- docs/reference/gtk/gtk4-sections.txt | 2 +- gtk/gtkdragsource.c | 48 ++++++++++++++-------------- gtk/gtkdragsource.h | 6 ++-- gtk/gtkwidget.c | 2 +- tests/testdnd.c | 8 ++--- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index ac5712e37c..4b3f4ead7e 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -4999,9 +4999,9 @@ gtk_drag_set_icon_gicon gtk_drag_set_icon_default gtk_drag_check_threshold gtk_drag_source_set -gtk_drag_source_set_icon_surface gtk_drag_source_set_icon_name gtk_drag_source_set_icon_gicon +gtk_drag_source_set_icon_paintable gtk_drag_source_unset gtk_drag_source_set_target_list gtk_drag_source_get_target_list diff --git a/gtk/gtkdragsource.c b/gtk/gtkdragsource.c index a50b6826b4..b74c12ee03 100644 --- a/gtk/gtkdragsource.c +++ b/gtk/gtkdragsource.c @@ -314,30 +314,6 @@ gtk_drag_source_add_uri_targets (GtkWidget *widget) gdk_content_formats_unref (target_list); } -/** - * gtk_drag_source_set_icon_surface: (method) - * @widget: a #GtkWidget - * @surface: the cairo surface for the drag icon - * - * Sets the icon that will be used for drags from a particular widget - * from a cairo surface. GTK+ retains a reference for @surface and will - * release it when it is no longer needed. - */ -void -gtk_drag_source_set_icon_surface (GtkWidget *widget, - cairo_surface_t *surface) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - g_return_if_fail (site != NULL); - - g_clear_pointer (&site->image_def, gtk_image_definition_unref); - site->image_def = gtk_image_definition_new_surface (surface); -} - /** * gtk_drag_source_set_icon_name: (method) * @widget: a #GtkWidget @@ -386,3 +362,27 @@ gtk_drag_source_set_icon_gicon (GtkWidget *widget, site->image_def = gtk_image_definition_new_gicon (icon); } +/** + * gtk_drag_source_set_icon_paintable: (method) + * @widget: a #GtkWidget + * @paintable: A #GdkPaintable + * + * Sets the icon that will be used for drags from a particular source + * to @paintable. + */ +void +gtk_drag_source_set_icon_paintable (GtkWidget *widget, + GdkPaintable *paintable) +{ + GtkDragSourceSite *site; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (GDK_IS_PAINTABLE (paintable)); + + site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); + g_return_if_fail (site != NULL); + + gtk_image_definition_unref (site->image_def); + site->image_def = gtk_image_definition_new_paintable (paintable); +} + diff --git a/gtk/gtkdragsource.h b/gtk/gtkdragsource.h index 80eded5ce3..b77f46db74 100644 --- a/gtk/gtkdragsource.h +++ b/gtk/gtkdragsource.h @@ -58,15 +58,15 @@ void gtk_drag_source_add_image_targets (GtkWidget *widget); GDK_AVAILABLE_IN_ALL void gtk_drag_source_add_uri_targets (GtkWidget *widget); -GDK_AVAILABLE_IN_ALL -void gtk_drag_source_set_icon_surface (GtkWidget *widget, - cairo_surface_t *surface); GDK_AVAILABLE_IN_ALL void gtk_drag_source_set_icon_name (GtkWidget *widget, const gchar *icon_name); GDK_AVAILABLE_IN_ALL void gtk_drag_source_set_icon_gicon (GtkWidget *widget, GIcon *icon); +GDK_AVAILABLE_IN_ALL +void gtk_drag_source_set_icon_paintable (GtkWidget *widget, + GdkPaintable *paintable); G_END_DECLS diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index cb6899e3cb..7940460bb4 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -1911,7 +1911,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) * * The ::drag-begin signal is emitted on the drag source when a drag is * started. A typical reason to connect to this signal is to set up a - * custom drag icon with e.g. gtk_drag_source_set_icon_surface(). + * custom drag icon with e.g. gtk_drag_source_set_icon_paintable(). * * Note that some widgets set up a drag icon in the default handler of * this signal, so you may have to use g_signal_connect_after() to diff --git a/tests/testdnd.c b/tests/testdnd.c index 165ca76e50..462ef14192 100644 --- a/tests/testdnd.c +++ b/tests/testdnd.c @@ -576,7 +576,7 @@ main (int argc, char **argv) GtkWidget *pixmap; GtkWidget *button; GdkPixbuf *drag_icon; - cairo_surface_t *surface; + GdkTexture *texture; GdkContentFormats *targets; test_init (); @@ -592,7 +592,7 @@ main (int argc, char **argv) gtk_container_add (GTK_CONTAINER (window), grid); drag_icon = gdk_pixbuf_new_from_xpm_data (drag_icon_xpm); - surface = gdk_cairo_surface_create_from_pixbuf (drag_icon, 1, NULL); + texture = gdk_texture_new_for_pixbuf (drag_icon); g_object_unref (drag_icon); trashcan_open = gdk_pixbuf_new_from_xpm_data (trashcan_open_xpm); trashcan_closed = gdk_pixbuf_new_from_xpm_data (trashcan_closed_xpm); @@ -655,10 +655,10 @@ main (int argc, char **argv) gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK, targets, GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_drag_source_set_icon_surface (button, surface); + gtk_drag_source_set_icon_paintable (button, GDK_PAINTABLE (texture)); gdk_content_formats_unref (targets); - cairo_surface_destroy (surface); + g_object_unref (texture); gtk_widget_set_hexpand (button, TRUE); gtk_widget_set_vexpand (button, TRUE);