dragsource: Replace gtk_drag_source_set_icon_surface()
authorBenjamin Otte <otte@redhat.com>
Thu, 15 Mar 2018 01:53:17 +0000 (02:53 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 16 Mar 2018 05:04:45 +0000 (06:04 +0100)
... with gtk_drag_source_set_icon_paintable().

docs/reference/gtk/gtk4-sections.txt
gtk/gtkdragsource.c
gtk/gtkdragsource.h
gtk/gtkwidget.c
tests/testdnd.c

index ac5712e37c567840f15ac1feb64ee2ae559f7316..4b3f4ead7ea406ddb396f45b9906a722e36f8c0f 100644 (file)
@@ -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
index a50b6826b4047064ffd1f1ec1059716b2274a337..b74c12ee03ea4283867499c4b550f2bf17c03154 100644 (file)
@@ -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);
+}
+
index 80eded5ce332df72d94ec48470188bd575c81ba3..b77f46db741f63f50e7389e72c94d88b9daa94e5 100644 (file)
@@ -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
index cb6899e3cb17ea96a1f3385d3cfe80c52a0cf2a0..7940460bb4fa7c9308f76ac6560bd57cb087031c 100644 (file)
@@ -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
index 165ca76e50e2890639b743de65cb370847b53915..462ef141929dd8c3d9c4137415d1232321a87c0c 100644 (file)
@@ -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);