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

==(other : self) ==, current_event : Gdk::Event | Nil current_event, current_event_device : Gdk::Device | Nil current_event_device, current_event_state : Gdk::ModifierType current_event_state, current_event_time : UInt32 current_event_time, hash(hasher) hash, name : String | Nil name, name=(value : String) : String
name=(value : Nil) : Nil
name=(name : String | Nil) : Nil
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, widget : Gtk::Widget widget

Constructor methods inherited from class Gtk::EventController

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

Class methods inherited from class Gtk::EventController

g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

==(other : self) ==, 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) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, 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) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil 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, 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

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : 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

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

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

Creates a new Gtk::DropTargetAsync object.


[View source]
def self.new #

Initialize a new DropTargetAsync.


[View source]
def self.new(*, actions : Gdk::DragAction | Nil = nil, formats : Gdk::ContentFormats | Nil = nil, name : String | Nil = nil, propagation_limit : Gtk::PropagationLimit | Nil = nil, propagation_phase : Gtk::PropagationPhase | Nil = nil, widget : Gtk::Widget | Nil = nil) #

[View source]

Class Method Detail

def self.g_type : UInt64 #

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


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def accept_signal #

[View source]
def actions : Gdk::DragAction #

Gets the actions that this drop target supports.


[View source]
def actions=(actions : Gdk::DragAction) : Nil #

Sets the actions that this drop target supports.


[View source]
def drag_enter_signal #

[View source]
def drag_leave_signal #

[View source]
def drag_motion_signal #

[View source]
def drop_signal #

[View source]
def formats : Gdk::ContentFormats | Nil #

Gets the data formats that this drop target accepts.

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


[View source]
def formats=(formats : Gdk::ContentFormats | Nil) : Nil #

Sets the data formats that this drop target will accept.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


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.


[View source]