From 7668669d56cbd181bc9a240347705f25f1e24999 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 8 Jan 2020 16:06:57 -0500 Subject: [PATCH] dragdest: Add a ::drag-enter signal Mainly for symmetry with ::drag-leave. --- gtk/gtkdragdest.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c index 26ffa3e8e2..3a3c455e55 100644 --- a/gtk/gtkdragdest.c +++ b/gtk/gtkdragdest.c @@ -81,6 +81,7 @@ enum { static GParamSpec *properties[NUM_PROPERTIES]; enum { + DRAG_ENTER, DRAG_LEAVE, DRAG_MOTION, DRAG_DROP, @@ -223,6 +224,24 @@ gtk_drop_target_class_init (GtkDropTargetClass *class) g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); + /** + * GtkDropTarget::drag-enter: + * @dest: the #GtkDropTarget + * @drop: the #GdkDrop + * + * The ::drag-enter signal is emitted on the drop site when the cursor + * enters the widget. + */ + signals[DRAG_ENTER] = + g_signal_new (I_("drag-enter"), + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + GDK_TYPE_DROP); + /** * GtkDropTarget::drag-leave: * @dest: the #GtkDropTarget @@ -231,10 +250,6 @@ gtk_drop_target_class_init (GtkDropTargetClass *class) * The ::drag-leave signal is emitted on the drop site when the cursor * leaves the widget. A typical reason to connect to this signal is to * undo things done in #GtkDropTarget::drag-motion, e.g. undo highlighting. - * - * Likewise, the #GtkWidget::drag-leave signal is also emitted before the - * #GtkDropTarget::drag-drop signal, for instance to allow cleaning up of - * a preview item created in the #GtkDropTarget::drag-motion signal handler. */ signals[DRAG_LEAVE] = g_signal_new (I_("drag-leave"), @@ -537,12 +552,20 @@ set_drop (GtkDropTarget *dest, g_object_add_weak_pointer (G_OBJECT (dest->drop), (gpointer *)&dest->drop); } +static void +gtk_drop_target_emit_drag_enter (GtkDropTarget *dest, + GdkDrop *drop) +{ + set_drop (dest, drop); + g_signal_emit (dest, signals[DRAG_ENTER], 0, drop); +} + static void gtk_drop_target_emit_drag_leave (GtkDropTarget *dest, GdkDrop *drop) { set_drop (dest, drop); - g_signal_emit (dest, signals[DRAG_LEAVE], 0, drop, time); + g_signal_emit (dest, signals[DRAG_LEAVE], 0, drop); set_drop (dest, NULL); } @@ -639,7 +662,6 @@ gtk_drop_set_current_dest (GdkDrop *drop, if (old_dest == dest) return; -g_print ("set current dest %p\n", dest); if (old_dest) { gtk_drop_target_set_contains (old_dest, FALSE); @@ -659,6 +681,8 @@ g_print ("set current dest %p\n", dest); { g_object_weak_ref (G_OBJECT (dest), clear_current_dest, drop); + gtk_drop_target_emit_drag_enter (dest, drop); + widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest)); if (widget) gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_DROP_ACTIVE, FALSE);