gtk.drop_target
Module for [DropTarget] class
Types 3
gtk.drop_target.DropTarget is an event controller to receive Drag-and-Drop operations.
The most basic way to use a gtk.drop_target.DropTarget to receive drops on a widget is to create it via gtk.drop_target.DropTarget.new_, passing in the GType of the data you want to receive and connect to the gtk.drop_target.DropTarget.drop signal to receive the data:
static gboolean
on_drop (GtkDropTarget *target,
const GValue *value,
double x,
double y,
gpointer data)
{
MyWidget *self = data;
// Call the appropriate setter depending on the type of data
// that we received
if (G_VALUE_HOLDS (value, G_TYPE_FILE))
my_widget_set_file (self, g_value_get_object (value));
else if (G_VALUE_HOLDS (value, GDK_TYPE_PIXBUF))
my_widget_set_pixbuf (self, g_value_get_object (value));
else
return FALSE;
return TRUE;
}
static void
my_widget_init (MyWidget *self)
{
GtkDropTarget *target =
gtk_drop_target_new (G_TYPE_INVALID, GDK_ACTION_COPY);
// This widget accepts two types of drop types: GFile objects
// and GdkPixbuf objects
gtk_drop_target_set_gtypes (target, (GType [2]) {
G_TYPE_FILE,
GDK_TYPE_PIXBUF,
}, 2);
g_signal_connect (target, "drop", G_CALLBACK (on_drop), self);
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (target));
}gtk.drop_target.DropTarget supports more options, such as:
- rejecting potential drops via the gtk.drop_target.DropTarget.accept signal and the gtk.drop_target.DropTarget.reject function to let other drop targets handle the drop
- tracking an ongoing drag operation before the drop via the gtk.drop_target.DropTarget.enter, gtk.drop_target.DropTarget.motion and gtk.drop_target.DropTarget.leave signals
- configuring how to receive data by setting the gtk.drop_target.DropTarget.preload property and listening for its availability via the gtk.drop_target.DropTarget.value property
However, gtk.drop_target.DropTarget is ultimately modeled in a synchronous way and only supports data transferred via GType. If you want full control over an ongoing drop, the gtk.drop_target_async.DropTargetAsync object gives you this ability.
While a pointer is dragged over the drop target's widget and the drop has not been rejected, that widget will receive the gtk.types.StateFlags.DropActive state, which can be used to style the widget.
If you are not interested in receiving the drop, but just want to update UI state during a Drag-and-Drop operation (e.g. switching tabs), you can use gtk.drop_controller_motion.DropControllerMotion.
DropTargetGidBuilder builder() static nothrowGet builder for [gtk.drop_target.DropTarget] Returns: New builder objectgdk.types.DragAction actions() @property nothrowGet `actions` property. Returns: The `GdkDragActions` that this drop target supports.void actions(gdk.types.DragAction propval) @property nothrowSet `actions` property. Params: propval = The `GdkDragActions` that this drop target supports.gdk.drop.Drop currentDrop() @property nothrowGet `currentDrop` property. Returns: The [gdk.drop.Drop] that is currently being performed.gdk.content_formats.ContentFormats formats() @property nothrowGet `formats` property. Returns: The [gdk.content_formats.ContentFormats] that determine the supported data formats.bool preload() @property nothrowGet `preload` property. Returns: Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.void preload(bool propval) @property nothrowSet `preload` property. Params: propval = Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.gobject.value.Value value() @property nothrowGet `value` property. Returns: The value for this drop operation.gdk.types.DragAction getActions() nothrowGets the actions that this drop target supports. Returns: the actions that this drop target supportsgdk.content_formats.ContentFormats getFormats() nothrowGets the data formats that this drop target accepts.gobject.types.GType[] getGtypes() nothrowGets the list of supported `GType`s that can be dropped on the target.bool getPreload() nothrowGets whether data should be preloaded on hover. Returns: true if drop data should be preloadedgobject.value.Value getValue() nothrowGets the current drop data, as a [gobject.value.Value]. Returns: The current drop datavoid setActions(gdk.types.DragAction actions) nothrowSets the actions that this drop target supports.void setGtypes(gobject.types.GType[] types = null) nothrowSets the supported `GType`s for this drop target.gulong connectAccept(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == bool)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gdk.drop.Drop)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.drop_target.DropTarget)))
&& Parameters!T.length < 3) nothrowConnect to `Accept` signal.gulong connectDrop(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == bool)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gobject.value.Value)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == double)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] == double)))
&& (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] : gtk.drop_target.DropTarget)))
&& Parameters!T.length < 5) nothrowConnect to `Drop` signal.gulong connectEnter(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == gdk.types.DragAction)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == double)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == double)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.drop_target.DropTarget)))
&& Parameters!T.length < 4) nothrowConnect to `Enter` signal.gulong connectLeave(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.drop_target.DropTarget)))
&& Parameters!T.length < 2) nothrowConnect to `Leave` signal.gulong connectMotion(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == gdk.types.DragAction)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == double)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == double)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtk.drop_target.DropTarget)))
&& Parameters!T.length < 4) nothrowConnect to `Motion` signal.this(gobject.types.GType type, gdk.types.DragAction actions)Creates a new [gtk.drop_target.DropTarget] object.Fluent builder implementation template for gtk.drop_target.DropTarget
T actions(gdk.types.DragAction propval) nothrowSet `actions` property. Params: propval = The `GdkDragActions` that this drop target supports. Returns: Builder instance for fluent chainingT formats(gdk.content_formats.ContentFormats propval) nothrowSet `formats` property. Params: propval = The [gdk.content_formats.ContentFormats] that determine the supported data formats. Returns: Builder instance for fluent chainingT preload(bool propval) nothrowSet `preload` property. Params: propval = Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.Fluent builder for gtk.drop_target.DropTarget