Class Drag

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
Drag.Drag$Impl

@Generated("org.javagi.JavaGI") public abstract class Drag extends GObject

Represents the source of an ongoing DND operation.

A GdkDrag is created when a drag is started, and stays alive for duration of the DND operation. After a drag has been started with begin(Surface, Device, ContentProvider, Set, double, double), the caller gets informed about the status of the ongoing drag operation with signals on the GdkDrag object.

GTK provides a higher level abstraction based on top of these functions, and so they are not normally needed in GTK applications. See the "Drag and Drop" section of the GTK documentation for more information.

  • Constructor Details

    • Drag

      public Drag(MemorySegment address)
      Create a Drag instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Drag

      public Drag()
      Create a new Drag.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Drag class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Drag asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • begin

      public static @Nullable Drag begin(Surface surface, Device device, ContentProvider content, Set<DragAction> actions, double dx, double dy)

      Starts a drag and creates a new drag context for it.

      This function is called by the drag source. After this call, you probably want to set up the drag icon using the surface returned by getDragSurface().

      This function returns a reference to the Drag object, but GTK keeps its own reference as well, as long as the DND operation is going on.

      Note: if actions include DragAction.MOVE, you need to listen for the Gdk.Drag::dnd-finished signal and delete the data at the source if getSelectedAction() returns DragAction.MOVE.

      Parameters:
      surface - the source surface for this drag
      device - the device that controls this drag
      content - the offered content
      actions - the actions supported by this drag
      dx - the x offset to device's position where the drag nominally started
      dy - the y offset to device's position where the drag nominally started
      Returns:
      a newly created GdkDrag
    • begin

      public static @Nullable Drag begin(Surface surface, Device device, ContentProvider content, DragAction actions, double dx, double dy)

      Starts a drag and creates a new drag context for it.

      This function is called by the drag source. After this call, you probably want to set up the drag icon using the surface returned by getDragSurface().

      This function returns a reference to the Drag object, but GTK keeps its own reference as well, as long as the DND operation is going on.

      Note: if actions include DragAction.MOVE, you need to listen for the Gdk.Drag::dnd-finished signal and delete the data at the source if getSelectedAction() returns DragAction.MOVE.

      Parameters:
      surface - the source surface for this drag
      device - the device that controls this drag
      content - the offered content
      actions - the actions supported by this drag
      dx - the x offset to device's position where the drag nominally started
      dy - the y offset to device's position where the drag nominally started
      Returns:
      a newly created GdkDrag
    • dropDone

      public void dropDone(boolean success)

      Informs GDK that the drop ended.

      Passing false for success may trigger a drag cancellation animation.

      This function is called by the drag source, and should be the last call before dropping the reference to the drag.

      The GdkDrag will only take the first dropDone(boolean) call as effective, if this function is called multiple times, all subsequent calls will be ignored.

      Parameters:
      success - whether the drag was ultimatively successful
    • getActions

      public Set<DragAction> getActions()
      Determines the bitmask of possible actions proposed by the source.
      Returns:
      the GdkDragAction flags
    • getContent

      public ContentProvider getContent()
      Returns the GdkContentProvider associated to the GdkDrag object.
      Returns:
      The GdkContentProvider associated to drag.
    • getDevice

      public Device getDevice()
      Returns the GdkDevice associated to the GdkDrag object.
      Returns:
      The GdkDevice associated to drag.
    • getDisplay

      public Display getDisplay()
      Gets the GdkDisplay that the drag object was created for.
      Returns:
      a GdkDisplay
    • getDragSurface

      public @Nullable Surface getDragSurface()

      Returns the surface on which the drag icon should be rendered during the drag operation.

      Note that the surface may not be available until the drag operation has begun. GDK will move the surface in accordance with the ongoing drag operation. The surface is owned by this Drag and will be destroyed when the drag operation is over.

      Returns:
      the drag surface
    • getFormats

      public ContentFormats getFormats()
      Retrieves the formats supported by this GdkDrag object.
      Returns:
      a GdkContentFormats
    • getSelectedAction

      public Set<DragAction> getSelectedAction()
      Determines the action chosen by the drag destination.
      Returns:
      a GdkDragAction value
    • getSurface

      public Surface getSurface()
      Returns the GdkSurface where the drag originates.
      Returns:
      The GdkSurface where the drag originates
    • setHotspot

      public void setHotspot(int hotX, int hotY)

      Sets the position of the drag surface that will be kept under the cursor hotspot.

      Initially, the hotspot is at the top left corner of the drag surface.

      Parameters:
      hotX - x coordinate of the drag surface hotspot
      hotY - y coordinate of the drag surface hotspot
    • onCancel

      Emitted when the drag operation is cancelled.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitCancel

      public void emitCancel(DragCancelReason reason)
      Emits the "cancel" signal. See onCancel(Drag.CancelCallback).
    • onDndFinished

      Emitted when the destination side has finished reading all data.

      The drag object can now free all miscellaneous data.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitDndFinished

      public void emitDndFinished()
      Emits the "dnd-finished" signal. See onDndFinished(Drag.DndFinishedCallback).
    • onDropPerformed

      Emitted when the drop operation is performed on an accepting client.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitDropPerformed

      public void emitDropPerformed()
      Emits the "drop-performed" signal. See onDropPerformed(Drag.DropPerformedCallback).