Signal
GtkWidget::drag-data-received
Declaration
void
drag_data_received (
GtkWidget* self,
GdkDragContext* context,
gint x,
gint y,
GtkSelectionData* data,
guint info,
guint time,
gpointer user_data
)
Description [src]
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 gdk_drag_status()
and not finish the drag.
If the data was received in response to a GtkWidget::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
gtk_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 gdk_drag_status()
or gtk_drag_finish().
The handler may inspect the selected action with
gdk_drag_context_get_selected_action()
before calling
gtk_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);
}
Default handler: The default handler is called after the handlers added via |
Parameters
context
-
Type:
GdkDragContext
The drag context.
The data is owned by the caller of the function. x
-
Type:
gint
Where the drop happened.
y
-
Type:
gint
Where the drop happened.
data
-
Type:
GtkSelectionData
The received data.
The data is owned by the caller of the function. info
-
Type:
guint
The info that has been registered with the target in the
GtkTargetList
. time
-
Type:
guint
The timestamp at which the data was received.