The drag_data_received signal is emitted on the drop site when the dragged data has been received.
If the data was received in order to determine whether the drop will be accepted, the handler is expected to call
drag_status and not finish the drag. If the data was received in response to a
drag_drop signal (and this is the last target to be received), the handler for this
signal is expected to process the received data and then call drag_finish, setting the
success
parameter depending on whether the data was processed successfully.
Applications must create some means to determine why the signal was emitted and therefore whether to call drag_status or drag_finish.
The handler may inspect the selected action with get_selected_action before calling drag_finish, e.g. to implement gdk_action_ask as shown in the following example:
void
drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint info,
guint time)
{
if ((data->length >= 0) && (data->format == 8))
{
GdkDragAction action;
// handle data here
action = gdk_drag_context_get_selected_action (context);
if (action == GDK_ACTION_ASK)
{
GtkWidget *dialog;
gint response;
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_YES_NO,
"Move the data ?\n");
response = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
if (response == GTK_RESPONSE_YES)
action = GDK_ACTION_MOVE;
else
action = GDK_ACTION_COPY;
}
gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
}
else
gtk_drag_finish (context, FALSE, FALSE, time);
}
context |
the drag context |
x |
where the drop happened |
y |
where the drop happened |
info |
the info that has been registered with the target in the TargetList |
data |
the received data |
time |
the timestamp at which the data was received |