Top | ![]() |
![]() |
![]() |
![]() |
GtkDropTargetAsync is an auxiliary object that can be used to receive Drag-and-Drop operations. It is the more complete but also more complex method of handling drop operations compared to GtkDropTarget and you should only use it if GtkDropTarget doesn't provide all the features you need.
To use a GtkDropTargetAsync to receive drops on a widget, you create
a GtkDropTargetAsync object, configure which data formats and actions
you support, connect to its signals, and then attach
it to the widget with gtk_widget_add_controller()
.
During a drag operation, the first signal that a GtkDropTargetAsync emits is “accept”, which is meant to determine whether the target is a possible drop site for the ongoing drop. The default handler for the ::accept signal accepts the drop if it finds a compatible data format and an action that is supported on both sides.
If it is, and the widget becomes a target, you will receive a “drag-enter” signal, followed by “drag-motion” signals as the pointer moves, optionally a “drop” signal when a drop happens, and finally a “drag-leave” signal when the pointer moves off the widget.
The ::drag-enter and ::drag-motion handler return a GdkDragAction
to update the status of the ongoing operation. The ::drop handler
should decide if it ultimately accepts the drop and if it does, it
should initiate the data transfer and finish the operation by calling
gdk_drop_finish()
.
Between the ::drag-enter and ::drag-leave signals the widget is a
current drop target, and will receive the GTK_STATE_FLAG_DROP_ACTIVE
state, which can be used by themes to style the widget as a drop target.
GtkDropTargetAsync * gtk_drop_target_async_new (GdkContentFormats *formats
,GdkDragAction actions
);
Creates a new GtkDropTargetAsync object.
void gtk_drop_target_async_set_formats (GtkDropTargetAsync *self
,GdkContentFormats *formats
);
Sets the data formats that this drop target will accept.
GdkContentFormats *
gtk_drop_target_async_get_formats (GtkDropTargetAsync *self
);
Gets the data formats that this drop target accepts.
If the result is NULL
, all formats are expected to be supported.
void gtk_drop_target_async_set_actions (GtkDropTargetAsync *self
,GdkDragAction actions
);
Sets the actions that this drop target supports.
GdkDragAction
gtk_drop_target_async_get_actions (GtkDropTargetAsync *self
);
Gets the actions that this drop target supports.
void gtk_drop_target_async_reject_drop (GtkDropTargetAsync *self
,GdkDrop *drop
);
Sets the drop
as not accepted on this drag site.
This function should be used when delaying the decision on whether to accept a drag or not until after reading the data.