Class Drop

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

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

Represents the target of an ongoing DND operation.

Possible drop sites get informed about the status of the ongoing drag operation with events of type GDK_DRAG_ENTER, GDK_DRAG_LEAVE, GDK_DRAG_MOTION and GDK_DROP_START. The GdkDrop object can be obtained from these Event types using DNDEvent.getDrop().

The actual data transfer is initiated from the target side via an async read, using one of the GdkDrop methods for this purpose: readAsync(String[], int, Cancellable, AsyncReadyCallback) or readValueAsync(Type, int, Cancellable, AsyncReadyCallback).

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

    • Drop

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

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

    • getType

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

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

      protected Drop 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
    • finish

      public void finish(Set<DragAction> action)

      Ends the drag operation after a drop.

      The action must be a single action selected from the actions available via getActions().

      Parameters:
      action - the action performed by the destination or GDK_ACTION_NONE if the drop failed
    • finish

      public void finish(DragAction... action)

      Ends the drag operation after a drop.

      The action must be a single action selected from the actions available via getActions().

      Parameters:
      action - the action performed by the destination or GDK_ACTION_NONE if the drop failed
    • getActions

      public Set<DragAction> getActions()

      Returns the possible actions for this GdkDrop.

      If this value contains multiple actions - i.e. DragAction.isUnique() returns false for the result - finish(Set) must choose the action to use when accepting the drop. This will only happen if you passed GDK_ACTION_ASK as one of the possible actions in status(Set, Set). GDK_ACTION_ASK itself will not be included in the actions returned by this function.

      This value may change over the lifetime of the Drop both as a response to source side actions as well as to calls to status(Set, Set) or finish(Set). The source side will not change this value anymore once a drop has started.

      Returns:
      The possible GdkDragActions
    • getDevice

      public Device getDevice()
      Returns the GdkDevice performing the drop.
      Returns:
      The GdkDevice performing the drop.
    • getDisplay

      public Display getDisplay()
      Gets the GdkDisplay that this Drop was created for.
      Returns:
      a GdkDisplay
    • getDrag

      public @Nullable Drag getDrag()

      If this is an in-app drag-and-drop operation, returns the GdkDrag that corresponds to this drop.

      If it is not, NULL is returned.

      Returns:
      the corresponding GdkDrag
    • getFormats

      public ContentFormats getFormats()
      Returns the GdkContentFormats that the drop offers the data to be read in.
      Returns:
      The possible GdkContentFormats
    • getSurface

      public Surface getSurface()
      Returns the GdkSurface performing the drop.
      Returns:
      The GdkSurface performing the drop.
    • readAsync

      public void readAsync(@Nullable String @Nullable [] mimeTypes, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Asynchronously read the dropped data from a GdkDrop in a format that complies with one of the mime types.
      Parameters:
      mimeTypes - pointer to an array of mime types
      ioPriority - the I/O priority for the read operation
      cancellable - optional GCancellable object
      callback - a GAsyncReadyCallback to call when the request is satisfied
    • readFinish

      public @Nullable InputStream readFinish(AsyncResult result, Out<String> outMimeType) throws GErrorException

      Finishes an async drop read operation.

      Note that you must not use blocking read calls on the returned stream in the GTK thread, since some platforms might require communication with GTK to complete the data transfer. You can use async APIs such as g_input_stream_read_bytes_async().

      See readAsync(String[], int, Cancellable, AsyncReadyCallback).

      Parameters:
      result - a GAsyncResult
      outMimeType - return location for the used mime type
      Returns:
      the GInputStream
      Throws:
      GErrorException - see GError
    • readValueAsync

      public void readValueAsync(Type type, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously request the drag operation's contents converted to the given type.

      For local drag-and-drop operations that are available in the given GType, the value will be copied directly. Otherwise, GDK will try to use Gdk.contentDeserializeAsync(InputStream, String, Type, int, Cancellable, AsyncReadyCallback) to convert the data.

      Parameters:
      type - a GType to read
      ioPriority - the I/O priority of the request.
      cancellable - optional GCancellable object, null to ignore.
      callback - callback to call when the request is satisfied
    • readValueFinish

      public Value readValueFinish(AsyncResult result) throws GErrorException
      Parameters:
      result - a GAsyncResult
      Returns:
      a GValue containing the result.
      Throws:
      GErrorException - see GError
    • status

      public void status(Set<DragAction> actions, Set<DragAction> preferred)

      Selects all actions that are potentially supported by the destination.

      When calling this function, do not restrict the passed in actions to the ones provided by getActions(). Those actions may change in the future, even depending on the actions you provide here.

      The preferred action is a hint to the drag-and-drop mechanism about which action to use when multiple actions are possible.

      This function should be called by drag destinations in response to GDK_DRAG_ENTER or GDK_DRAG_MOTION events. If the destination does not yet know the exact actions it supports, it should set any possible actions first and then later call this function again.

      Parameters:
      actions - Supported actions of the destination, or GDK_ACTION_NONE to indicate that a drop will not be accepted
      preferred - A unique action that's a member of actions indicating the preferred action
    • status

      public void status(DragAction actions, DragAction... preferred)

      Selects all actions that are potentially supported by the destination.

      When calling this function, do not restrict the passed in actions to the ones provided by getActions(). Those actions may change in the future, even depending on the actions you provide here.

      The preferred action is a hint to the drag-and-drop mechanism about which action to use when multiple actions are possible.

      This function should be called by drag destinations in response to GDK_DRAG_ENTER or GDK_DRAG_MOTION events. If the destination does not yet know the exact actions it supports, it should set any possible actions first and then later call this function again.

      Parameters:
      actions - Supported actions of the destination, or GDK_ACTION_NONE to indicate that a drop will not be accepted
      preferred - A unique action that's a member of actions indicating the preferred action