[gtk/dnd-gestures-2: 86/100] Get rid of GtkDragDestInfo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/dnd-gestures-2: 86/100] Get rid of GtkDragDestInfo
- Date: Mon, 6 Jan 2020 21:21:19 +0000 (UTC)
commit 46748c478e60b471bdffa27ec601088401909b88
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 5 23:09:26 2020 -0500
Get rid of GtkDragDestInfo
We can just attach the GtkDropTarget directly to
the GdkDrop.
gtk/gtkdnd.c | 64 ++++++++++++++++++++---------------------------------
gtk/gtkdndprivate.h | 19 +++++-----------
gtk/gtkdragdest.c | 18 +++++++--------
3 files changed, 38 insertions(+), 63 deletions(-)
---
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index eff878ed03..1ebbf9666a 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -80,7 +80,7 @@ void
_gtk_drag_dest_handle_event (GtkWidget *toplevel,
GdkEvent *event)
{
- GtkDragDestInfo *info;
+ GtkDropTarget *dest;
GdkDrop *drop;
GdkEventType event_type;
@@ -90,8 +90,6 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
event_type = gdk_event_get_event_type (event);
drop = gdk_event_get_drop (event);
- info = gtk_drag_get_dest_info (drop, TRUE);
-
/* Find the widget for the event */
switch ((guint) event_type)
{
@@ -99,13 +97,14 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
break;
case GDK_DRAG_LEAVE:
- if (info->dest)
+ dest = gtk_drop_get_current_dest (drop);
+ if (dest)
{
- gtk_drop_target_emit_drag_leave (info->dest, drop);
- gtk_drag_dest_set_target (info, NULL);
+ gtk_drop_target_emit_drag_leave (dest, drop);
+ gtk_drop_set_current_dest (drop, NULL);
}
break;
-
+
case GDK_DRAG_MOTION:
case GDK_DROP_START:
{
@@ -202,46 +201,31 @@ gtk_drop_find_widget (GtkWidget *event_widget,
return FALSE;
}
-void
-gtk_drag_dest_set_target (GtkDragDestInfo *info,
- GtkDropTarget *dest)
+static void
+clear_current_dest (gpointer data, GObject *former_object)
{
- if (info->dest)
- g_object_remove_weak_pointer (G_OBJECT (info->dest), (gpointer *) &info->dest);
-
- info->dest = dest;
-
- if (info->dest)
- g_object_add_weak_pointer (G_OBJECT (info->dest), (gpointer *) &info->dest);
+ g_object_set_data (G_OBJECT (data), "current-dest", NULL);
}
-static void
-gtk_drag_dest_info_destroy (gpointer data)
+void
+gtk_drop_set_current_dest (GdkDrop *drop,
+ GtkDropTarget *dest)
{
- GtkDragDestInfo *info = (GtkDragDestInfo *)data;
+ GtkDropTarget *old_dest;
+
+ old_dest = g_object_get_data (G_OBJECT (drop), "current-dest");
+
+ if (old_dest)
+ g_object_weak_unref (G_OBJECT (old_dest), clear_current_dest, drop);
- gtk_drag_dest_set_target (info, NULL);
+ g_object_set_data (G_OBJECT (drop), "current-dest", dest);
- g_slice_free (GtkDragDestInfo, data);
+ if (dest)
+ g_object_weak_ref (G_OBJECT (dest), clear_current_dest, drop);
}
-GtkDragDestInfo *
-gtk_drag_get_dest_info (GdkDrop *drop,
- gboolean create)
+GtkDropTarget *
+gtk_drop_get_current_dest (GdkDrop *drop)
{
- GtkDragDestInfo *info;
- static GQuark info_quark = 0;
- if (!info_quark)
- info_quark = g_quark_from_static_string ("gtk-dest-info");
-
- info = g_object_get_qdata (G_OBJECT (drop), info_quark);
- if (!info && create)
- {
- info = g_slice_new0 (GtkDragDestInfo);
- info->drop = drop;
- g_object_set_qdata_full (G_OBJECT (drop), info_quark,
- info, gtk_drag_dest_info_destroy);
- }
-
- return info;
+ return g_object_get_data (G_OBJECT (drop), "current-dest");
}
diff --git a/gtk/gtkdndprivate.h b/gtk/gtkdndprivate.h
index b316a9fded..a520b1cf08 100644
--- a/gtk/gtkdndprivate.h
+++ b/gtk/gtkdndprivate.h
@@ -25,21 +25,12 @@
G_BEGIN_DECLS
-void _gtk_drag_dest_handle_event (GtkWidget *toplevel,
- GdkEvent *event);
+void _gtk_drag_dest_handle_event (GtkWidget *toplevel,
+ GdkEvent *event);
-typedef struct _GtkDragDestInfo GtkDragDestInfo;
-
-struct _GtkDragDestInfo
-{
- GtkDropTarget *dest;
- GdkDrop *drop; /* drop */
-};
-
-GtkDragDestInfo * gtk_drag_get_dest_info (GdkDrop *drop,
- gboolean create);
-void gtk_drag_dest_set_target (GtkDragDestInfo *info,
- GtkDropTarget *dest);
+void gtk_drop_set_current_dest (GdkDrop *drop,
+ GtkDropTarget *dest);
+GtkDropTarget *gtk_drop_get_current_dest (GdkDrop *drop);
G_END_DECLS
diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c
index cd12f995ed..0dc2c27761 100644
--- a/gtk/gtkdragdest.c
+++ b/gtk/gtkdragdest.c
@@ -691,14 +691,14 @@ gtk_drop_target_handle_event (GtkEventController *controller,
{
GtkDropTarget *dest = GTK_DROP_TARGET (controller);
GdkDrop *drop;
- GtkDragDestInfo *info;
+ GtkDropTarget *old_dest;
double x, y;
gboolean found = FALSE;
gdk_event_get_coords (event, &x, &y);
drop = gdk_event_get_drop (event);
- info = gtk_drag_get_dest_info (drop, TRUE);
+ old_dest = gtk_drop_get_current_dest (drop);
switch ((int)gdk_event_get_event_type (event))
{
@@ -710,10 +710,10 @@ gtk_drop_target_handle_event (GtkEventController *controller,
/* We send a leave before the drop so that the widget unhighlights
* properly.
*/
- if (info->dest)
+ if (old_dest)
{
- gtk_drop_target_emit_drag_leave (info->dest, drop);
- gtk_drag_dest_set_target (info, NULL);
+ gtk_drop_target_emit_drag_leave (old_dest, drop);
+ gtk_drop_set_current_dest (drop, NULL);
}
found = gtk_drop_target_emit_drag_drop (dest, drop, x, y);
@@ -725,13 +725,13 @@ gtk_drop_target_handle_event (GtkEventController *controller,
if (found)
{
- if (info->dest && info->dest != dest)
+ if (old_dest && old_dest != dest)
{
- gtk_drop_target_emit_drag_leave (info->dest, drop);
- gtk_drag_dest_set_target (info, NULL);
+ gtk_drop_target_emit_drag_leave (old_dest, drop);
+ gtk_drop_set_current_dest (drop, NULL);
}
- gtk_drag_dest_set_target (info, dest);
+ gtk_drop_set_current_dest (drop, dest);
}
return found;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]