dragsource: Tweak api, update all callers

Add GdkDrag back to signals, drop ::drag-data-delete,
and replace it with a boolean in ::drag-end.
This commit is contained in:
Matthias Clasen 2020-01-06 13:28:25 -05:00
parent f6f331efe3
commit 38974d7d2b
12 changed files with 109 additions and 91 deletions

View File

@ -120,6 +120,7 @@ get_image_paintable (GtkImage *image)
static void
drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget)
{
GdkPaintable *paintable;

View File

@ -373,6 +373,7 @@ get_image_paintable (GtkImage *image)
static void
drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget)
{
GdkPaintable *paintable;

View File

@ -269,6 +269,7 @@ gtk_color_button_drag_drop (GtkDropTarget *dest,
static void
gtk_color_button_drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkColorButton *button)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);

View File

@ -117,6 +117,7 @@ swatch_snapshot (GtkWidget *widget,
static void
gtk_color_swatch_drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkColorSwatch *swatch)
{
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);

View File

@ -110,7 +110,6 @@ enum {
DRAG_BEGIN,
DRAG_END,
DRAG_FAILED,
DRAG_DATA_DELETE,
NUM_SIGNALS
};
@ -225,12 +224,11 @@ gtk_drag_source_class_init (GtkDragSourceClass *class)
/**
* GtkDragSource::drag-begin:
* @source: the #GtkDragSource
* @drag: the #GtkDrag object
*
* The ::drag-begin signal is emitted on the drag source when a drag
* is started. It can be used to e.g. set a custom drag icon with
* gtk_drag_source_set_icon(). But all of the setup can also be
* done before calling gtk_drag_source_drag_begin(), so this is not
* really necessary.
* gtk_drag_source_set_icon().
*/
signals[DRAG_BEGIN] =
g_signal_new (I_("drag-begin"),
@ -239,11 +237,15 @@ gtk_drag_source_class_init (GtkDragSourceClass *class)
0,
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
G_TYPE_NONE, 1,
GDK_TYPE_DRAG);
/**
* GtkDragSource::drag-end:
* @source: the #GtkDragSource
* @drag: the #GtkDrag object
* @delete_data: %TRUE if the drag was performing %GDK_ACTION_MOVE,
* and the data should be deleted
*
* The ::drag-end signal is emitted on the drag source when a drag is
* finished. A typical reason to connect to this signal is to undo
@ -256,11 +258,14 @@ gtk_drag_source_class_init (GtkDragSourceClass *class)
0,
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
G_TYPE_NONE, 2,
GDK_TYPE_DRAG,
G_TYPE_BOOLEAN);
/**
* GtkDragSource::drag-failed:
* @source: the #GtkDragSource
* @drag: the #GtkDrag object
* @reason: information on why the drag failed
*
* The ::drag-failed signal is emitted on the drag source when a drag has
@ -276,27 +281,10 @@ gtk_drag_source_class_init (GtkDragSourceClass *class)
G_SIGNAL_RUN_LAST,
0,
_gtk_boolean_handled_accumulator, NULL,
_gtk_marshal_BOOLEAN__ENUM,
G_TYPE_BOOLEAN, 1,
_gtk_marshal_BOOLEAN__OBJECT_ENUM,
G_TYPE_BOOLEAN, 2,
GDK_TYPE_DRAG,
GDK_TYPE_DRAG_CANCEL_REASON);
/**
* GtkDragSource::drag-data-delete:
* @source: the #GtkDragSource
*
* The ::drag-data-delete signal is emitted on the drag source when a drag
* with the action %GDK_ACTION_MOVE is successfully completed. The signal
* handler is responsible for deleting the data that has been dropped. What
* "delete" means depends on the context of the drag operation.
*/
signals[DRAG_DATA_DELETE] =
g_signal_new (I_("drag-data-delete"),
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
}
static void gtk_drag_source_dnd_finished_cb (GdkDrag *drag,
@ -311,11 +299,15 @@ static void
drag_end (GtkDragSource *source,
gboolean success)
{
gboolean delete_data;
g_signal_handlers_disconnect_by_func (source->drag, gtk_drag_source_drop_performed_cb, source);
g_signal_handlers_disconnect_by_func (source->drag, gtk_drag_source_dnd_finished_cb, source);
g_signal_handlers_disconnect_by_func (source->drag, gtk_drag_source_cancel_cb, source);
g_signal_emit (source, signals[DRAG_END], 0);
delete_data = success && gdk_drag_get_selected_action (source->drag) == GDK_ACTION_MOVE;
g_signal_emit (source, signals[DRAG_END], 0, source->drag, delete_data);
gdk_drag_drop_done (source->drag, success);
@ -329,8 +321,6 @@ static void
gtk_drag_source_dnd_finished_cb (GdkDrag *drag,
GtkDragSource *source)
{
if (gdk_drag_get_selected_action (drag) == GDK_ACTION_MOVE)
g_signal_emit (source, signals[DRAG_DATA_DELETE], 0);
drag_end (source, TRUE);
}
@ -341,7 +331,7 @@ gtk_drag_source_cancel_cb (GdkDrag *drag,
{
gboolean success = FALSE;
g_signal_emit (source, signals[DRAG_FAILED], 0, reason, &success);
g_signal_emit (source, signals[DRAG_FAILED], 0, source->drag, reason, &success);
drag_end (source, FALSE);
}
@ -415,7 +405,7 @@ gtk_drag_source_drag_begin (GtkDragSource *source,
/* We hold a ref until ::drag-end is emitted */
g_object_ref (source);
g_signal_emit (source, signals[DRAG_BEGIN], 0);
g_signal_emit (source, signals[DRAG_BEGIN], 0, source->drag);
if (!source->paintable)
{
@ -777,7 +767,7 @@ gtk_drag_source_drag_cancel (GtkDragSource *source)
{
gboolean success = FALSE;
g_signal_emit (source, signals[DRAG_FAILED], 0, GDK_DRAG_CANCEL_ERROR, &success);
g_signal_emit (source, signals[DRAG_FAILED], 0, source->drag, GDK_DRAG_CANCEL_ERROR, &success);
gdk_drag_drop_done (source->drag, success);
}

View File

@ -281,12 +281,15 @@ static void update_text_cell (GtkIco
static void update_pixbuf_cell (GtkIconView *icon_view);
/* Source side drag signals */
static void gtk_icon_view_drag_begin (GtkDragSource *source,
GtkWidget *widget);
static GBytes * gtk_icon_view_drag_data_get (const char *mime_type,
gpointer data);
static void gtk_icon_view_drag_data_delete (GtkDragSource *source,
GtkWidget *widget);
static void gtk_icon_view_drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget);
static void gtk_icon_view_drag_end (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
GtkWidget *widget);
static GBytes * gtk_icon_view_drag_data_get (const char *mime_type,
gpointer data);
/* Target side drag signals */
static void gtk_icon_view_drag_leave (GtkDropTarget *dest,
@ -6083,7 +6086,8 @@ gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
/* Source side drag signals */
static void
gtk_icon_view_drag_begin (GtkDragSource *source,
GtkWidget *widget)
GdkDrag *drag,
GtkWidget *widget)
{
GtkIconView *icon_view;
GtkIconViewItem *item;
@ -6162,13 +6166,18 @@ gtk_icon_view_drag_data_get (const char *mime_type,
}
static void
gtk_icon_view_drag_data_delete (GtkDragSource *source,
GtkWidget *widget)
gtk_icon_view_drag_end (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
GtkWidget *widget)
{
GtkTreeModel *model;
GtkIconView *icon_view;
GtkTreePath *source_row;
if (!delete_data)
return;
icon_view = GTK_ICON_VIEW (widget);
model = gtk_icon_view_get_model (icon_view);
@ -6462,8 +6471,8 @@ gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
g_signal_connect (icon_view->priv->source, "drag-begin",
G_CALLBACK (gtk_icon_view_drag_begin), icon_view);
g_signal_connect (icon_view->priv->source, "drag-data-delete",
G_CALLBACK (gtk_icon_view_drag_data_delete), icon_view);
g_signal_connect (icon_view->priv->source, "drag-end",
G_CALLBACK (gtk_icon_view_drag_end), icon_view);
icon_view->priv->start_button_mask = start_button_mask;
icon_view->priv->source_actions = actions;

View File

@ -697,10 +697,14 @@ static gboolean gtk_notebook_focus (GtkWidget *widget,
/*** Drag and drop Methods ***/
static void gtk_notebook_drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget);
static void gtk_notebook_drag_end (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
GtkWidget *widget);
static gboolean gtk_notebook_drag_failed (GtkDragSource *source,
GdkDrag *drag,
GdkDragCancelReason reason,
GtkWidget *widget);
static gboolean gtk_notebook_drag_motion (GtkDropTarget *dest,
@ -3087,6 +3091,7 @@ update_arrow_nodes (GtkNotebook *notebook)
static void
gtk_notebook_drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget)
{
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
@ -3111,6 +3116,8 @@ gtk_notebook_drag_begin (GtkDragSource *source,
static void
gtk_notebook_drag_end (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
GtkWidget *widget)
{
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
@ -3146,9 +3153,10 @@ gtk_notebook_create_window (GtkNotebook *notebook,
}
static gboolean
gtk_notebook_drag_failed (GtkDragSource *source,
GdkDragCancelReason reason,
GtkWidget *widget)
gtk_notebook_drag_failed (GtkDragSource *source,
GdkDrag *drag,
GdkDragCancelReason reason,
GtkWidget *widget)
{
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkNotebookPrivate *priv = notebook->priv;

View File

@ -1728,7 +1728,8 @@ stop_drop_feedback (GtkPlacesSidebar *sidebar)
static void
drag_begin_callback (GtkDragSource *source,
gpointer user_data)
GdkDrag *drag,
gpointer user_data)
{
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
GtkAllocation allocation;
@ -2092,6 +2093,8 @@ out_free:
static void
drag_end_callback (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
gpointer user_data)
{
stop_drop_feedback (GTK_PLACES_SIDEBAR (user_data));

View File

@ -2791,9 +2791,14 @@ gtk_text_motion_controller_motion (GtkEventControllerMotion *controller,
}
static void
drag_end (GtkText *self)
drag_end (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
GtkText *self)
{
g_object_set_data (G_OBJECT (self), "drag-source", NULL);
if (delete_data)
gtk_text_delete_selection (self);
}
static void
@ -2848,10 +2853,7 @@ gtk_text_drag_gesture_update (GtkGestureDrag *gesture,
paintable,
priv->drag_start_x - ranges[0],
priv->drag_start_y);
g_signal_connect_swapped (source, "drag-data-delete",
G_CALLBACK (gtk_text_delete_selection), self);
g_signal_connect_swapped (source, "drag-end",
G_CALLBACK (drag_end), self);
g_signal_connect_swapped (source, "drag-end", G_CALLBACK (drag_end), self);
g_object_set_data_full (G_OBJECT (self), "drag-source", source, g_object_unref);
gtk_drag_source_drag_begin (source,

View File

@ -677,13 +677,14 @@ static void gtk_tree_view_forall (GtkContainer *container,
/* Source side drag signals */
static void gtk_tree_view_drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget);
static void gtk_tree_view_drag_end (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
GtkWidget *widget);
static GBytes *gtk_tree_view_drag_data_get (const char *mimetype,
gpointer data);
static void gtk_tree_view_drag_data_delete (GtkDragSource *source,
GtkWidget *widget);
/* Target side drag signals */
static void gtk_tree_view_drag_leave (GtkDropTarget *dest,
@ -7129,6 +7130,7 @@ gtk_tree_view_maybe_begin_dragging_row (GtkTreeView *tree_view)
static void
gtk_tree_view_drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget)
{
GtkTreeView *tree_view;
@ -7171,13 +7173,43 @@ gtk_tree_view_drag_begin (GtkDragSource *source,
}
static void
gtk_tree_view_drag_end (GtkDragSource *sourc,
gtk_tree_view_drag_end (GtkDragSource *source,
GdkDrag *drag,
gboolean delete_data,
GtkWidget *widget)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
TreeViewDragInfo *di;
GtkTreeModel *model;
GtkTreePath *source_row;
tree_view->event_last_x = -10000;
tree_view->event_last_y = -10000;
if (!delete_data)
return;
tree_view = GTK_TREE_VIEW (widget);
model = gtk_tree_view_get_model (tree_view);
if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
return;
di = get_info (tree_view);
if (di == NULL)
return;
source_row = get_source_row (source);
if (source_row == NULL)
return;
gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model), source_row);
gtk_tree_path_free (source_row);
set_source_row (source, NULL, NULL);
}
/* Default signal implementations for the drag signals */
@ -7232,39 +7264,6 @@ gtk_tree_view_drag_data_get (const char *mime_type,
gtk_selection_data_get_length (&sdata));
}
static void
gtk_tree_view_drag_data_delete (GtkDragSource *source,
GtkWidget *widget)
{
TreeViewDragInfo *di;
GtkTreeModel *model;
GtkTreeView *tree_view;
GtkTreePath *source_row;
tree_view = GTK_TREE_VIEW (widget);
model = gtk_tree_view_get_model (tree_view);
if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
return;
di = get_info (tree_view);
if (di == NULL)
return;
source_row = get_source_row (source);
if (source_row == NULL)
return;
gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model), source_row);
gtk_tree_path_free (source_row);
set_source_row (source, NULL, NULL);
}
static void
gtk_tree_view_drag_leave (GtkDropTarget *dest,
GtkTreeView *tree_view)
@ -12934,7 +12933,6 @@ gtk_tree_view_enable_model_drag_source (GtkTreeView *tree_view,
g_object_unref (content);
g_signal_connect (di->source, "drag-begin", G_CALLBACK (gtk_tree_view_drag_begin), tree_view);
g_signal_connect (di->source, "drag-end", G_CALLBACK (gtk_tree_view_drag_end), tree_view);
g_signal_connect (di->source, "drag-data-delete", G_CALLBACK (gtk_tree_view_drag_data_delete), tree_view);
di->start_button_mask = start_button_mask;
di->source_set = TRUE;

View File

@ -273,7 +273,9 @@ drag_end (GtkDragSource *source)
}
static gboolean
drag_failed (GtkDragSource *source, GdkDragCancelReason reason)
drag_failed (GtkDragSource *source,
GdkDrag *drag,
GdkDragCancelReason reason)
{
g_print ("drag failed: %d\n", reason);
return FALSE;
@ -316,7 +318,8 @@ make_image (const gchar *icon_name, int hotspot)
static void
spinner_drag_begin (GtkDragSource *source,
GtkWidget *widget)
GdkDrag *drag,
GtkWidget *widget)
{
GdkPaintable *paintable;

View File

@ -6,6 +6,7 @@ static const char *entries[] = {
static void
drag_begin (GtkDragSource *source,
GdkDrag *drag,
GtkWidget *widget)
{
GtkWidget *row;