mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 10:50:10 +00:00
dnd: Add gdk_event_get_drop()
And remove gdk_event_get_drag_context(). All GTK code now only uses GdkDrop for dropping.
This commit is contained in:
parent
6048b69145
commit
d02b185a87
@ -652,7 +652,7 @@ gdk_event_get_scancode
|
||||
gdk_event_get_pointer_emulated
|
||||
gdk_event_get_crossing_detail
|
||||
gdk_event_get_crossing_mode
|
||||
gdk_event_get_drag_context
|
||||
gdk_event_get_drop
|
||||
gdk_event_get_focus_in
|
||||
gdk_event_get_grab_surface
|
||||
gdk_event_get_motion_history
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "gdkinternals.h"
|
||||
#include "gdkdisplayprivate.h"
|
||||
#include "gdkdndprivate.h"
|
||||
#include "gdkdropprivate.h"
|
||||
#include "gdk-private.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -2058,17 +2059,15 @@ gdk_event_is_sent (const GdkEvent *event)
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_event_get_drag_context:
|
||||
* gdk_event_get_drop:
|
||||
* @event: a #GdkEvent
|
||||
* @context: (out) (transfer none): return location for the drag context
|
||||
*
|
||||
* Gets the drag context from a DND event.
|
||||
* Gets the #GdkDrop from a DND event.
|
||||
*
|
||||
* Returns: %TRUE on success, otherwise %FALSE
|
||||
* Returns: (transfer none) (nullable): the drop
|
||||
**/
|
||||
gboolean
|
||||
gdk_event_get_drag_context (const GdkEvent *event,
|
||||
GdkDragContext **context)
|
||||
GdkDrop *
|
||||
gdk_event_get_drop (const GdkEvent *event)
|
||||
{
|
||||
if (!event)
|
||||
return FALSE;
|
||||
@ -2078,11 +2077,10 @@ gdk_event_get_drag_context (const GdkEvent *event,
|
||||
event->any.type == GDK_DRAG_MOTION ||
|
||||
event->any.type == GDK_DROP_START)
|
||||
{
|
||||
*context = event->dnd.context;
|
||||
return TRUE;
|
||||
return GDK_DROP (event->dnd.context);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -513,8 +513,7 @@ GDK_AVAILABLE_IN_ALL
|
||||
gboolean gdk_event_is_sent (const GdkEvent *event);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gdk_event_get_drag_context (const GdkEvent *event,
|
||||
GdkDragContext **context);
|
||||
GdkDrop * gdk_event_get_drop (const GdkEvent *event);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gdk_event_get_crossing_mode (const GdkEvent *event,
|
||||
|
117
gtk/gtkdnd.c
117
gtk/gtkdnd.c
@ -79,42 +79,42 @@ struct _GtkDragSourceInfo
|
||||
struct _GtkDragDestInfo
|
||||
{
|
||||
GtkWidget *widget; /* Widget in which drag is in */
|
||||
GdkDragContext *context; /* Drag context */
|
||||
GdkDrop *drop; /* drop */
|
||||
};
|
||||
|
||||
#define DROP_ABORT_TIME 300000
|
||||
|
||||
typedef gboolean (* GtkDragDestCallback) (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
GdkDrop *drop,
|
||||
gint x,
|
||||
gint y,
|
||||
guint32 time);
|
||||
|
||||
/* Forward declarations */
|
||||
static gboolean gtk_drag_find_widget (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
static gboolean gtk_drop_find_widget (GtkWidget *widget,
|
||||
GdkDrop *drop,
|
||||
GtkDragDestInfo *info,
|
||||
gint x,
|
||||
gint y,
|
||||
guint32 time,
|
||||
GtkDragDestCallback callback);
|
||||
static void gtk_drag_dest_leave (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
GdkDrop *drop,
|
||||
guint time);
|
||||
static gboolean gtk_drag_dest_motion (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
GdkDrop *drop,
|
||||
gint x,
|
||||
gint y,
|
||||
guint time);
|
||||
static gboolean gtk_drag_dest_drop (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
GdkDrop *drop,
|
||||
gint x,
|
||||
gint y,
|
||||
guint time);
|
||||
static void gtk_drag_dest_set_widget (GtkDragDestInfo *info,
|
||||
GtkWidget *widget);
|
||||
|
||||
static GtkDragDestInfo * gtk_drag_get_dest_info (GdkDragContext *context,
|
||||
static GtkDragDestInfo * gtk_drag_get_dest_info (GdkDrop *drop,
|
||||
gboolean create);
|
||||
static GtkDragSourceInfo *gtk_drag_get_source_info (GdkDragContext *context,
|
||||
gboolean create);
|
||||
@ -385,7 +385,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
||||
GdkEvent *event)
|
||||
{
|
||||
GtkDragDestInfo *info;
|
||||
GdkDragContext *context;
|
||||
GdkDrop *drop;
|
||||
guint32 time;
|
||||
GdkEventType event_type;
|
||||
|
||||
@ -393,10 +393,10 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
||||
g_return_if_fail (event != NULL);
|
||||
|
||||
event_type = gdk_event_get_event_type (event);
|
||||
gdk_event_get_drag_context (event, &context);
|
||||
drop = gdk_event_get_drop (event);
|
||||
time = gdk_event_get_time (event);
|
||||
|
||||
info = gtk_drag_get_dest_info (context, TRUE);
|
||||
info = gtk_drag_get_dest_info (drop, TRUE);
|
||||
|
||||
/* Find the widget for the event */
|
||||
switch ((guint) event_type)
|
||||
@ -407,7 +407,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
||||
case GDK_DRAG_LEAVE:
|
||||
if (info->widget)
|
||||
{
|
||||
gtk_drag_dest_leave (info->widget, context, time);
|
||||
gtk_drag_dest_leave (info->widget, drop, time);
|
||||
gtk_drag_dest_set_widget (info, NULL);
|
||||
}
|
||||
break;
|
||||
@ -427,7 +427,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
||||
*/
|
||||
if (info->widget)
|
||||
{
|
||||
gtk_drag_dest_leave (info->widget, context, time);
|
||||
gtk_drag_dest_leave (info->widget, drop, time);
|
||||
gtk_drag_dest_set_widget (info, NULL);
|
||||
}
|
||||
}
|
||||
@ -437,8 +437,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
||||
gdk_surface_get_position (surface, &tx, &ty);
|
||||
gdk_event_get_root_coords (event, &x_root, &y_root);
|
||||
|
||||
found = gtk_drag_find_widget (toplevel,
|
||||
context,
|
||||
found = gtk_drop_find_widget (toplevel,
|
||||
drop,
|
||||
info,
|
||||
x_root - tx,
|
||||
y_root - ty,
|
||||
@ -449,14 +449,14 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
||||
|
||||
if (info->widget && !found)
|
||||
{
|
||||
gtk_drag_dest_leave (info->widget, context, time);
|
||||
gtk_drag_dest_leave (info->widget, drop, time);
|
||||
gtk_drag_dest_set_widget (info, NULL);
|
||||
}
|
||||
|
||||
/* Send a reply.
|
||||
*/
|
||||
if (!found)
|
||||
gdk_drag_status (context, 0, time);
|
||||
gdk_drop_status (drop, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -466,8 +466,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_drag_find_widget (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gtk_drop_find_widget (GtkWidget *widget,
|
||||
GdkDrop *drop,
|
||||
GtkDragDestInfo *info,
|
||||
gint x,
|
||||
gint y,
|
||||
@ -517,13 +517,13 @@ gtk_drag_find_widget (GtkWidget *widget,
|
||||
*/
|
||||
if (g_object_get_data (G_OBJECT (widget), "gtk-drag-dest"))
|
||||
{
|
||||
found = callback (widget, context, x, y, time);
|
||||
found = callback (widget, drop, x, y, time);
|
||||
|
||||
/* If so, send a "drag-leave" to the last widget */
|
||||
if (found && info->widget != widget)
|
||||
{
|
||||
if (info->widget)
|
||||
gtk_drag_dest_leave (info->widget, context, time);
|
||||
gtk_drag_dest_leave (info->widget, drop, time);
|
||||
|
||||
gtk_drag_dest_set_widget (info, widget);
|
||||
}
|
||||
@ -586,20 +586,20 @@ gtk_drag_dest_info_destroy (gpointer data)
|
||||
}
|
||||
|
||||
static GtkDragDestInfo *
|
||||
gtk_drag_get_dest_info (GdkDragContext *context,
|
||||
gboolean create)
|
||||
gtk_drag_get_dest_info (GdkDrop *drop,
|
||||
gboolean create)
|
||||
{
|
||||
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 (context), info_quark);
|
||||
info = g_object_get_qdata (G_OBJECT (drop), info_quark);
|
||||
if (!info && create)
|
||||
{
|
||||
info = g_slice_new0 (GtkDragDestInfo);
|
||||
info->context = context;
|
||||
g_object_set_qdata_full (G_OBJECT (context), info_quark,
|
||||
info->drop = drop;
|
||||
g_object_set_qdata_full (G_OBJECT (drop), info_quark,
|
||||
info, gtk_drag_dest_info_destroy);
|
||||
}
|
||||
|
||||
@ -638,7 +638,7 @@ gtk_drag_clear_source_info (GdkDragContext *context)
|
||||
*/
|
||||
static void
|
||||
gtk_drag_dest_leave (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
GdkDrop *drop,
|
||||
guint time)
|
||||
{
|
||||
GtkDragDestSite *site;
|
||||
@ -651,20 +651,19 @@ gtk_drag_dest_leave (GtkWidget *widget,
|
||||
|
||||
if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag ||
|
||||
site->track_motion)
|
||||
g_signal_emit_by_name (widget, "drag-leave", context, time);
|
||||
g_signal_emit_by_name (widget, "drag-leave", drop, time);
|
||||
|
||||
site->have_drag = FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_drag_dest_motion (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gint x,
|
||||
gint y,
|
||||
guint time)
|
||||
gtk_drag_dest_motion (GtkWidget *widget,
|
||||
GdkDrop *drop,
|
||||
gint x,
|
||||
gint y,
|
||||
guint time)
|
||||
{
|
||||
GtkDragDestSite *site;
|
||||
GdkDragAction action = 0;
|
||||
gboolean retval;
|
||||
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
||||
@ -672,24 +671,14 @@ gtk_drag_dest_motion (GtkWidget *widget,
|
||||
|
||||
if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
|
||||
{
|
||||
if (gdk_drag_context_get_suggested_action (context) & site->actions)
|
||||
action = gdk_drag_context_get_suggested_action (context);
|
||||
else
|
||||
{
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
if ((site->actions & (1 << i)) &&
|
||||
(gdk_drag_context_get_actions (context) & (1 << i)))
|
||||
{
|
||||
action = (1 << i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
GdkDragAction actions;
|
||||
|
||||
actions = gdk_drop_get_actions (drop);
|
||||
|
||||
if (action && gtk_drag_dest_find_target (widget, GDK_DROP (context), NULL))
|
||||
if ((actions & site->actions) == 0)
|
||||
actions = 0;
|
||||
|
||||
if (actions && gtk_drag_dest_find_target (widget, drop, NULL))
|
||||
{
|
||||
if (!site->have_drag)
|
||||
{
|
||||
@ -698,28 +687,28 @@ gtk_drag_dest_motion (GtkWidget *widget,
|
||||
gtk_drag_highlight (widget);
|
||||
}
|
||||
|
||||
gdk_drag_status (context, action, time);
|
||||
gdk_drop_status (drop, site->actions);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_drag_status (context, 0, time);
|
||||
gdk_drop_status (drop, 0);
|
||||
if (!site->track_motion)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
g_signal_emit_by_name (widget, "drag-motion",
|
||||
context, x, y, &retval);
|
||||
drop, x, y, &retval);
|
||||
|
||||
return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_drag_dest_drop (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gint x,
|
||||
gint y,
|
||||
guint time)
|
||||
gtk_drag_dest_drop (GtkWidget *widget,
|
||||
GdkDrop *drop,
|
||||
gint x,
|
||||
gint y,
|
||||
guint time)
|
||||
{
|
||||
GtkDragDestSite *site;
|
||||
GtkDragDestInfo *info;
|
||||
@ -728,24 +717,24 @@ gtk_drag_dest_drop (GtkWidget *widget,
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
||||
g_return_val_if_fail (site != NULL, FALSE);
|
||||
|
||||
info = gtk_drag_get_dest_info (context, FALSE);
|
||||
info = gtk_drag_get_dest_info (drop, FALSE);
|
||||
g_return_val_if_fail (info != NULL, FALSE);
|
||||
|
||||
if (site->flags & GTK_DEST_DEFAULT_DROP)
|
||||
{
|
||||
GdkAtom target = gtk_drag_dest_find_target (widget, GDK_DROP (context), NULL);
|
||||
GdkAtom target = gtk_drag_dest_find_target (widget, drop, NULL);
|
||||
|
||||
if (target == NULL)
|
||||
{
|
||||
gdk_drag_finish (context, FALSE, time);
|
||||
gdk_drop_finish (drop, 0);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
gtk_drag_get_data (widget, GDK_DROP (context), target);
|
||||
gtk_drag_get_data (widget, drop, target);
|
||||
}
|
||||
|
||||
g_signal_emit_by_name (widget, "drag-drop",
|
||||
context, x, y, &retval);
|
||||
drop, x, y, &retval);
|
||||
|
||||
return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user