About all my projects
Gnome::Gtk4::DropTargetAsync

Gnome::Gtk4::DropTargetAsync

Description

Gnome::Gtk4::DropTargetAsync is an event controller to receive Drag-and-Drop operations, asynchronously.

It is the more complete but also more complex method of handling drop operations compared to Gnome::Gtk4::DropTarget, and you should only use it if Gnome::Gtk4::DropTarget doesn't provide all the features you need.

To use a Gnome::Gtk4::DropTargetAsync to receive drops on a widget, you create a Gnome::Gtk4::DropTargetAsync object, configure which data formats and actions you support, connect to its signals, and then attach it to the widget with .add-controller() in class Gnome::Gtk4::Widget.

During a drag operation, the first signal that a Gnome::Gtk4::DropTargetAsync emits is 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 drag-enter signal, followed by drag-motion signals as the pointer moves, optionally a drop signal when a drop happens, and finally a drag-leave signal when the pointer moves off the widget.

The drag-enter and drag-motion handler return a bit field GdkDragAction defined in Gnome::Gdk4::T-enums 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 .finish() in class Gnome::Gdk4::Drop.

Between the drag-enter and drag-leave signals the widget is a current drop target, and will receive the GTK_STATE_FLAG_DROP_ACTIVE state, which can be used by themes to style the widget as a drop target.

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

new-droptargetasync

Creates a new Gnome::Gtk4::DropTargetAsync object.

method new-droptargetasync ( N-Object $formats, UInt $actions --> Gnome::Gtk4::DropTargetAsync \)
  • $formats; (transfer ownership: full) the supported data formats

  • $actions; the supported actions.

Methods

get-actions

Gets the actions that this drop target supports.

method get-actions (--> UInt )

Return value; the actions that this drop target supports.

get-formats

Gets the data formats that this drop target accepts.

If the result is undefined, all formats are expected to be supported.

method get-formats (--> N-Object )

Return value; the supported data formats.

reject-drop

Sets the $drop as 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.

method reject-drop ( N-Object() $drop )
  • $drop; the Gnome::Gdk4::Drop of an ongoing drag operation.

set-actions

Sets the actions that this drop target supports.

method set-actions ( UInt $actions )
  • $actions; the supported actions.

set-formats

Sets the data formats that this drop target will accept.

method set-formats ( N-Object $formats )
  • $formats; the supported data formats or undefined for any format

Signals

accept

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 .reject-drop() or ultimately by returning False from a drop handler.

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 True and proceed as is $drop was accepted and if it decides to reject the drop later, it should call .reject-drop().

method handler (
   $drop,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::DropTargetAsync :$_widget,
  *C<user>-options
  --> gboolean
)
  • $drop; the Gnome::Gdk4::Drop.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::DropTargetAsync object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

Return value; True if $drop is accepted

drag-enter

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

It can be used to set up custom highlighting.

method handler (
   $drop,
  gdouble $x,
  gdouble $y,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::DropTargetAsync :$_widget,
  *C<user>-options
)
  • $drop; the Gnome::Gdk4::Drop.

  • $x; the x coordinate of the current pointer position.

  • $y; the y coordinate of the current pointer position.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::DropTargetAsync object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

drag-leave

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

Its main purpose it to undo things done in Gnome::Gtk4::DropTargetAsync::drag-enter.

method handler (
   $drop,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::DropTargetAsync :$_widget,
  *C<user>-options
)
  • $drop; the Gnome::Gdk4::Drop.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::DropTargetAsync object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

drag-motion

Emitted while the pointer is moving over the drop target.

method handler (
   $drop,
  gdouble $x,
  gdouble $y,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::DropTargetAsync :$_widget,
  *C<user>-options
)
  • $drop; the Gnome::Gdk4::Drop.

  • $x; the x coordinate of the current pointer position.

  • $y; the y coordinate of the current pointer position.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::DropTargetAsync object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

drop

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 must ensure that .finish() in class Gnome::Gdk4::Drop is called to let the source know that the drop is done. The call to .finish() in class Gnome::Gdk4::Drop must only be done when all data has been received.

To receive the data, use one of the read functions provided by Gnome::Gdk4::Drop such as .read-async() in class Gnome::Gdk4::Drop or .read-value-async() in class Gnome::Gdk4::Drop.

method handler (
   $drop,
  gdouble $x,
  gdouble $y,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::DropTargetAsync :$_widget,
  *C<user>-options
  --> gboolean
)
  • $drop; the Gnome::Gdk4::Drop.

  • $x; the x coordinate of the current pointer position.

  • $y; the y coordinate of the current pointer position.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::DropTargetAsync object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

Return value; whether the drop is accepted at the given pointer position