Get rid of GtkDragDestInfo

We can just attach the GtkDropTarget directly to
the GdkDrop.
This commit is contained in:
Matthias Clasen 2020-01-05 23:09:26 -05:00
parent dfb2cbdfdb
commit 6a7f39e6d2
3 changed files with 41 additions and 66 deletions

View File

@ -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)
{
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);
}
static void
gtk_drag_dest_info_destroy (gpointer data)
clear_current_dest (gpointer data, GObject *former_object)
{
GtkDragDestInfo *info = (GtkDragDestInfo *)data;
gtk_drag_dest_set_target (info, NULL);
g_slice_free (GtkDragDestInfo, data);
g_object_set_data (G_OBJECT (data), "current-dest", NULL);
}
GtkDragDestInfo *
gtk_drag_get_dest_info (GdkDrop *drop,
gboolean create)
void
gtk_drop_set_current_dest (GdkDrop *drop,
GtkDropTarget *dest)
{
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);
}
GtkDropTarget *old_dest;
return info;
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);
g_object_set_data (G_OBJECT (drop), "current-dest", dest);
if (dest)
g_object_weak_ref (G_OBJECT (dest), clear_current_dest, drop);
}
GtkDropTarget *
gtk_drop_get_current_dest (GdkDrop *drop)
{
return g_object_get_data (G_OBJECT (drop), "current-dest");
}

View File

@ -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

View File

@ -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;