The
gtk:drop-target object is an event controller implementing a
simple way to receive Drag-and-Drop operations. The most basic way to use a
gtk:drop-target object to receive drops on a widget is to create it via the
gtk:drop-target-new function passing in the
GType of the data you want to receive and connect to the
"current-drop" signal to receive the data.
The
gtk:drop-target object supports more options, such as:
- rejecting potential drops via the "accept" signal and the gtk:drop-target-reject function to let other drop targets handle the drop
- tracking an ongoing drag operation before the drop via the "enter", "motion" and "leave" signals
- configuring how to receive data by setting the preload property and listening for its availability via the value property
However, the
gtk:drop-target object 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
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
:drop-active state,
which can be used to style the widget.
Signal Details
The "accept" signal
lambda (target drop) :run-last
- target
- The gtk:drag-target object.
- drop
- The gdk:drop object.
- Returns
- True if drop is accepted.
The signal is emitted on the drop site when a drop operation is about to begin. If the drop is not accepted,
false will be returned and the drop target will ignore the drop. If
true is returned, the drop is
accepted for now but may be rejected later via a call to the
gtk:drop-target-reject function or ultimately by returning
false from the
"drop" signal.
The default handler for this signal decides whether to accept the drop based on the formats provided by
drop.
If the decision whether the drop will be accepted or rejected needs inspecting the data, this function should return
true, the
preload property should be set and the value should be inspected via the
"notify::value" signal and then call the
gtk:drop-target-reject function.
The "drop" signal
lambda (target value x y) :run-last
- target
- The gtk:drag-target object.
- value
- The g:value instance being dropped.
- x
- The double float with the x coordinate of the current pointer position.
- y
- The double float with the x coordinate of the current pointer position.
- Returns
- Whether the drop was accepted at the given pointer position.
The signal is emitted on the drop site when the user drops the data onto
the widget. The signal handler must determine whether the pointer position
is in a drop zone or not. If it is not in a drop zone, it returns
false and no further processing is necessary. Otherwise, the handler returns
true. In this case, this handler will accept the drop. The handler is responsible for reading the given
value and performing
the drop operation.
The "enter" signal
lambda (target x y) :run-last
- target
- The gtk:drag-target object.
- x
- A double float with the x coordinate of the current pointer position.
- y
- A double float with the x coordinate of the current pointer position.
- Returns
- A gdk:drag-action value with the preferred
action for this drag operation or 0 if dropping is not supported at the current x,y location.
The signal is emitted on the drop site when the pointer enters the widget.
It can be used to set up custom highlighting.
The "leave" signal
lambda (target) :run-last
- target
- The gtk:drag-target object.
The signal is emitted on the drop site when the pointer leaves the widget. Its main purpose is to undo things done in the
"enter" signal
handler.
The "motion" signal
lambda (target x y) :run-last
- target
- The gtk:drag-target object.
- x
- The double float with the x coordinate of the current pointer position.
- y
- The double float with the x coordinate of the current pointer position.
- Returns
- The gdk:drag-action value with the preferred
action for this drag operation or 0 if dropping is not supported at the current x,y location.
The signal is emitted while the pointer is moving over the drop target.