DropTarget

open class DropTarget(pointer: <Error class: unknown class><<Error class: unknown class>>) : EventController

GtkDropTarget is an event controller to receive Drag-and-Drop operations.

The most basic way to use a GtkDropTarget to receive drops on a widget is to create it via ctor@Gtk.DropTarget.new, passing in the GType of the data you want to receive and connect to the signal@Gtk.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));
}

GtkDropTarget supports more options, such as:

  • rejecting potential drops via the signal@Gtk.DropTarget::accept signal and the method@Gtk.DropTarget.reject function to let other drop targets handle the drop

  • tracking an ongoing drag operation before the drop via the signal@Gtk.DropTarget::enter, signal@Gtk.DropTarget::motion and signal@Gtk.DropTarget::leave signals

  • configuring how to receive data by setting the property@Gtk.DropTarget:preload property and listening for its availability via the property@Gtk.DropTarget:value property

However, GtkDropTarget is ultimately modeled in a synchronous way and only supports data transferred via GType. If you want full control over an ongoing drop, the class@Gtk.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_STATE_FLAG_DROP_ACTIVE 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 class@Gtk.DropControllerMotion.

Skipped during bindings generation

  • parameter n_types: n_types: Out parameter is not supported

  • parameter types: Array parameter of type GType is not supported

Constructors

Link copied to clipboard
constructor(type: <Error class: unknown class>, actions: <Error class: unknown class>)

Creates a new GtkDropTarget object.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open var actions: <Error class: unknown class>

The GdkDragActions that this drop target supports.

Link copied to clipboard
open val currentDrop: <Error class: unknown class>?

The GdkDrop that is currently being performed.

Link copied to clipboard
open val drop: <Error class: unknown class>?

The GdkDrop that is currently being performed.

Link copied to clipboard
open val formats: <Error class: unknown class>?

The GdkContentFormats that determine the supported data formats.

Link copied to clipboard
val gtkDropTargetPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
val gtkEventControllerPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open var name: String?

The name for this controller, typically used for debugging purposes.

Link copied to clipboard
open var preload: Boolean

Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.

Link copied to clipboard

The limit for which events this controller will handle.

Link copied to clipboard

The propagation phase at which this controller will handle events.

Link copied to clipboard
open val value: <Error class: unknown class>?

The value for this drop operation.

Link copied to clipboard
open val widget: Widget?

The widget receiving the GdkEvents that the controller will handle.

Functions

Link copied to clipboard
fun connectAccept(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (<Error class: unknown class>) -> Boolean): <Error class: unknown class>

Emitted on the drop site when a drop operation is about to begin.

Link copied to clipboard
fun connectDrop(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (<Error class: unknown class>, x: Double, y: Double) -> Boolean): <Error class: unknown class>

Emitted on the drop site when the user drops the data onto the widget.

Link copied to clipboard
fun connectEnter(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (x: Double, y: Double) -> <Error class: unknown class>): <Error class: unknown class>

Emitted on the drop site when the pointer enters the widget.

Link copied to clipboard
fun connectLeave(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: () -> Unit): <Error class: unknown class>

Emitted on the drop site when the pointer leaves the widget.

Link copied to clipboard
fun connectMotion(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (x: Double, y: Double) -> <Error class: unknown class>): <Error class: unknown class>

Emitted while the pointer is moving over the drop target.

Link copied to clipboard
open fun getActions(): <Error class: unknown class>

Gets the actions that this drop target supports.

Link copied to clipboard
open fun getCurrentDrop(): <Error class: unknown class>?

Gets the currently handled drop operation.

Link copied to clipboard
open fun getCurrentEvent(): <Error class: unknown class>?

Returns the event that is currently being handled by the controller.

Link copied to clipboard
open fun getCurrentEventDevice(): <Error class: unknown class>?

Returns the device of the event that is currently being handled by the controller.

Link copied to clipboard
open fun getCurrentEventState(): <Error class: unknown class>

Returns the modifier state of the event that is currently being handled by the controller.

Link copied to clipboard
open fun getCurrentEventTime(): <Error class: unknown class>

Returns the timestamp of the event that is currently being handled by the controller.

Link copied to clipboard
open fun getDrop(): <Error class: unknown class>?

Gets the currently handled drop operation.

Link copied to clipboard
open fun getFormats(): <Error class: unknown class>?

Gets the data formats that this drop target accepts.

Link copied to clipboard
open fun getName(): String?

Gets the name of @controller.

Link copied to clipboard
open fun getPreload(): Boolean

Gets whether data should be preloaded on hover.

Link copied to clipboard

Gets the propagation limit of the event controller.

Link copied to clipboard

Gets the propagation phase at which @controller handles events.

Link copied to clipboard
open fun getValue(): <Error class: unknown class>?

Gets the current drop data, as a GValue.

Link copied to clipboard
open fun getWidget(): Widget?

Returns the GtkWidget this controller relates to.

Link copied to clipboard
open fun reject()

Rejects the ongoing drop operation.

Link copied to clipboard
open fun reset()

Resets the @controller to a clean state.

Link copied to clipboard
open fun setActions(actions: <Error class: unknown class>)

Sets the actions that this drop target supports.

Link copied to clipboard
open fun setName(name: String? = null)

Sets a name on the controller that can be used for debugging.

Link copied to clipboard
open fun setPreload(preload: Boolean)

Sets whether data should be preloaded on hover.

Link copied to clipboard

Sets the event propagation limit on the event controller.

Link copied to clipboard

Sets the propagation phase at which a controller handles events.

Link copied to clipboard
open fun setStaticName(name: String? = null)

Sets a name on the controller that can be used for debugging.