class Gtk::DropTargetAsync

Overview

Gtk::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 Gtk::DropTarget, and you should only use it if Gtk::DropTarget doesn't provide all the features you need.

To use a Gtk::DropTargetAsync to receive drops on a widget, you create a Gtk::DropTargetAsync object, configure which data formats and actions you support, connect to its signals, and then attach it to the widget with Gtk::Widget#add_controller.

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

The ::drag-enter and ::drag-motion handler return a Gdk::DragAction 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 Gdk::Drop#finish.

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.

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/drop_target_async.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Gtk::EventController

current_event : Gdk::Event? current_event, current_event_device : Gdk::Device? current_event_device, current_event_state : Gdk::ModifierType current_event_state, current_event_time : UInt32 current_event_time, name : String? name, name=(value : String) : String
name=(name : String?) : Nil
name=
, propagation_limit : Gtk::PropagationLimit propagation_limit, propagation_limit=(limit : Gtk::PropagationLimit) : Nil propagation_limit=, propagation_phase : Gtk::PropagationPhase propagation_phase, propagation_phase=(phase : Gtk::PropagationPhase) : Nil propagation_phase=, reset : Nil reset, static_name=(name : String?) : Nil static_name=, widget : Gtk::Widget widget

Constructor methods inherited from class Gtk::EventController

new
new(*, name : String? = nil, propagation_limit : Gtk::PropagationLimit? = nil, propagation_phase : Gtk::PropagationPhase? = nil, widget : Gtk::Widget? = nil)
new

Class methods inherited from class Gtk::EventController

g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new(formats : Gdk::ContentFormats?, actions : Gdk::DragAction) : self #

Creates a new Gtk::DropTargetAsync object.


def self.new #

Initialize a new DropTargetAsync.


def self.new(*, actions : Gdk::DragAction? = nil, formats : Gdk::ContentFormats? = nil, name : String? = nil, propagation_limit : Gtk::PropagationLimit? = nil, propagation_phase : Gtk::PropagationPhase? = nil, widget : Gtk::Widget? = nil) #

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def accept_signal #

def actions : Gdk::DragAction #

Gets the actions that this drop target supports.


def actions=(actions : Gdk::DragAction) : Nil #

Sets the actions that this drop target supports.


def drag_enter_signal #

def drag_leave_signal #

def drag_motion_signal #

def drop_signal #

def formats : Gdk::ContentFormats? #

Gets the data formats that this drop target accepts.

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


def formats=(formats : Gdk::ContentFormats?) : Nil #

Sets the data formats that this drop target will accept.


def reject_drop(drop : Gdk::Drop) : Nil #

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.