[gtk/dnd-gestures-2: 100/100] calendar: Use gdk_drag_begin
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/dnd-gestures-2: 100/100] calendar: Use gdk_drag_begin
- Date: Mon, 6 Jan 2020 21:22:30 +0000 (UTC)
commit 7678e5db6365ae45b7036d193a2faad6307122dc
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jan 6 16:12:18 2020 -0500
calendar: Use gdk_drag_begin
gtk/gtkcalendar.c | 37 +++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 9892f99e22..b942573528 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -87,6 +87,10 @@
#include "gtkeventcontrollerscroll.h"
#include "gtkeventcontrollerkey.h"
#include "gtkdragsource.h"
+#include "gtknative.h"
+#include "gtkicontheme.h"
+#include "gtkpicture.h"
+#include "gtkdragicon.h"
#define TIMEOUT_INITIAL 500
#define TIMEOUT_REPEAT 50
@@ -2697,9 +2701,15 @@ gtk_calendar_drag_update (GtkGestureDrag *gesture,
GtkCalendar *calendar = GTK_CALENDAR (widget);
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
gdouble start_x, start_y;
- GtkDragSource *source;
GdkContentProvider *content;
GdkDevice *device;
+ GdkDrag *drag;
+ GtkIconTheme *theme;
+ GdkPaintable *paintable;
+ GdkSurface *surface;
+ GtkWidget *drag_icon;
+ GtkWidget *picture;
+
if (!priv->in_drag)
return;
@@ -2709,13 +2719,28 @@ gtk_calendar_drag_update (GtkGestureDrag *gesture,
gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y);
- source = gtk_drag_source_new ();
+ surface = gtk_native_get_surface (gtk_widget_get_native (widget));
+ device = gtk_gesture_get_device (GTK_GESTURE (gesture));
+
content = get_calendar_content (calendar);
- gtk_drag_source_set_content (source, content);
+
+ drag = gdk_drag_begin (surface, device, content, GDK_ACTION_COPY, start_x, start_y);
+
+ drag_icon = gtk_drag_icon_new_for_drag (drag);
+ gtk_widget_show (drag_icon);
+ g_object_ref_sink (drag_icon);
+ g_object_set_data_full (G_OBJECT (drag), "icon", drag_icon, (GDestroyNotify)gtk_widget_destroy);
+
+ theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
+ paintable = gtk_icon_theme_load_icon (theme, "text-x-generic", 32, 0, NULL);
+
+ picture = gtk_picture_new_for_paintable (paintable);
+ gtk_picture_set_can_shrink (GTK_PICTURE (picture), FALSE);
+ gtk_container_add (GTK_CONTAINER (drag_icon), picture);
+
+ g_clear_object (&paintable);
g_object_unref (content);
- device = gtk_gesture_get_device (GTK_GESTURE (gesture));
- gtk_drag_source_drag_begin (source, widget, device, start_x, start_y);
- g_object_unref (source);
+ g_object_unref (drag);
priv->in_drag = 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]