Class DropTargetAsync
- All Implemented Interfaces:
Proxy
It is the more complete but also more complex method of handling drop
operations compared to DropTarget, 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 Widget.addController(org.gnome.gtk.EventController).
During a drag operation, the first signal that a GtkDropTargetAsync
emits is Gtk.DropTargetAsync::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
Gtk.DropTargetAsync::drag-enter signal, followed by
Gtk.DropTargetAsync::drag-motion signals as the pointer moves,
optionally a Gtk.DropTargetAsync::drop signal when a drop happens,
and finally a Gtk.DropTargetAsync::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
Drop.finish(java.util.Set<org.gnome.gdk.DragAction>).
Between the ::drag-enter and ::drag-leave signals the widget is a
current drop target, and will receive the StateFlags.DROP_ACTIVE
state, which can be used by themes to style the widget as a drop target.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theAcceptCallbackcallback.static classDropTargetAsync.Builder<B extends DropTargetAsync.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theDragEnterCallbackcallback.static interfaceFunctional interface declaration of theDragLeaveCallbackcallback.static interfaceFunctional interface declaration of theDragMotionCallbackcallback.static interfaceFunctional interface declaration of theDropCallbackcallback.static classNested classes/interfaces inherited from class org.gnome.gtk.EventController
EventController.EventController$Impl, EventController.EventControllerClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DropTargetAsync.DropTargetAsync(MemorySegment address) Create a DropTargetAsync proxy instance for the provided memory address.DropTargetAsync(@Nullable ContentFormats formats, Set<DragAction> actions) Creates a newGtkDropTargetAsyncobject.DropTargetAsync(@Nullable ContentFormats formats, DragAction... actions) Creates a newGtkDropTargetAsyncobject. -
Method Summary
Modifier and TypeMethodDescriptionprotected DropTargetAsyncasParent()Returns this instance as if it were its parent type.static DropTargetAsync.Builder<? extends DropTargetAsync.Builder> builder()ADropTargetAsync.Builderobject constructs aDropTargetAsyncwith the specified properties.booleanemitAccept(@Nullable Drop drop) Emits the "accept" signal.emitDragEnter(@Nullable Drop drop, double x, double y) Emits the "drag-enter" signal.voidemitDragLeave(@Nullable Drop drop) Emits the "drag-leave" signal.emitDragMotion(@Nullable Drop drop, double x, double y) Emits the "drag-motion" signal.booleanEmits the "drop" signal.Gets the actions that this drop target supports.@Nullable ContentFormatsGets the data formats that this drop target accepts.static @Nullable TypegetType()Get the GType of the DropTargetAsync classonAccept(DropTargetAsync.AcceptCallback handler) Emitted on the drop site when a drop operation is about to begin.Emitted on the drop site when the pointer enters the widget.Emitted on the drop site when the pointer leaves the widget.Emitted while the pointer is moving over the drop target.onDrop(DropTargetAsync.DropCallback handler) Emitted on the drop site when the user drops the data onto the widget.voidrejectDrop(Drop drop) Sets thedropas not accepted on this drag site.voidsetActions(Set<DragAction> actions) Sets the actions that this drop target supports.voidsetActions(DragAction... actions) Sets the actions that this drop target supports.voidsetFormats(@Nullable ContentFormats formats) Sets the data formats that this drop target will accept.Methods inherited from class org.gnome.gtk.EventController
getCurrentEvent, getCurrentEventDevice, getCurrentEventState, getCurrentEventTime, getName, getPropagationLimit, getPropagationPhase, getWidget, reset, setName, setPropagationLimit, setPropagationPhase, setStaticNameMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
DropTargetAsync
Create a DropTargetAsync proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
DropTargetAsync
Creates a newGtkDropTargetAsyncobject.- Parameters:
formats- the supported data formatsactions- the supported actions
-
DropTargetAsync
Creates a newGtkDropTargetAsyncobject.- Parameters:
formats- the supported data formatsactions- the supported actions
-
DropTargetAsync
public DropTargetAsync()Creates a new DropTargetAsync.
-
-
Method Details
-
getType
Get the GType of the DropTargetAsync class- Returns:
- the GType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type.- Overrides:
asParentin classEventController
-
getActions
Gets the actions that this drop target supports.- Returns:
- the actions that this drop target supports
-
getFormats
Gets the data formats that this drop target accepts.If the result is
null, all formats are expected to be supported.- Returns:
- the supported data formats
-
rejectDrop
Sets thedropas 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.
- Parameters:
drop- theGdkDropof an ongoing drag operation
-
setActions
Sets the actions that this drop target supports.- Parameters:
actions- the supported actions
-
setActions
Sets the actions that this drop target supports.- Parameters:
actions- the supported actions
-
setFormats
Sets the data formats that this drop target will accept.- Parameters:
formats- the supported data formats ornullfor any format
-
onAccept
public SignalConnection<DropTargetAsync.AcceptCallback> onAccept(DropTargetAsync.AcceptCallback handler) Emitted on the drop site when a drop operation is about to begin.If the drop is not accepted,
falsewill be returned and the drop target will ignore the drop. Iftrueis returned, the drop is accepted for now but may be rejected later via a call torejectDrop(org.gnome.gdk.Drop)or ultimately by returningfalsefrom aGtk.DropTargetAsync::drophandler.The default handler for this signal decides whether to accept the drop based on the formats provided by the
drop.If the decision whether the drop will be accepted or rejected needs further processing, such as inspecting the data, this function should return
trueand proceed as isdropwas accepted and if it decides to reject the drop later, it should callrejectDrop(org.gnome.gdk.Drop).- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitAccept
Emits the "accept" signal. SeeonAccept(org.gnome.gtk.DropTargetAsync.AcceptCallback). -
onDragEnter
public SignalConnection<DropTargetAsync.DragEnterCallback> onDragEnter(DropTargetAsync.DragEnterCallback handler) Emitted on the drop site when the pointer enters the widget.It can be used to set up custom highlighting.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDragEnter
Emits the "drag-enter" signal. SeeonDragEnter(org.gnome.gtk.DropTargetAsync.DragEnterCallback). -
onDragLeave
public SignalConnection<DropTargetAsync.DragLeaveCallback> onDragLeave(DropTargetAsync.DragLeaveCallback handler) Emitted on the drop site when the pointer leaves the widget.Its main purpose it to undo things done in
GtkDropTargetAsync::drag-enter.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDragLeave
Emits the "drag-leave" signal. SeeonDragLeave(org.gnome.gtk.DropTargetAsync.DragLeaveCallback). -
onDragMotion
public SignalConnection<DropTargetAsync.DragMotionCallback> onDragMotion(DropTargetAsync.DragMotionCallback handler) Emitted while the pointer is moving over the drop target.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDragMotion
Emits the "drag-motion" signal. SeeonDragMotion(org.gnome.gtk.DropTargetAsync.DragMotionCallback). -
onDrop
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
falseand no further processing is necessary.Otherwise, the handler returns
true. In this case, this handler will accept the drop. The handler must ensure thatDrop.finish(java.util.Set<org.gnome.gdk.DragAction>)is called to let the source know that the drop is done. The call toDrop.finish(java.util.Set<org.gnome.gdk.DragAction>)must only be done when all data has been received.To receive the data, use one of the read functions provided by
Dropsuch asDrop.readAsync(java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)orDrop.readValueAsync(org.gnome.glib.Type, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback).- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDrop
Emits the "drop" signal. SeeonDrop(org.gnome.gtk.DropTargetAsync.DropCallback). -
builder
ADropTargetAsync.Builderobject constructs aDropTargetAsyncwith the specified properties. Use the variousset...()methods to set properties, and finish construction withDropTargetAsync.Builder.build().- Returns:
- the builder object
-