gtkmm 4.14.0
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Gtk::DropTargetAsync Class Reference

Event controller to receive DND drops. More...

#include <gtkmm/droptargetasync.h>

Inheritance diagram for Gtk::DropTargetAsync:
Inheritance graph
[legend]

Public Member Functions

 DropTargetAsync (DropTargetAsync && src) noexcept
 
DropTargetAsyncoperator= (DropTargetAsync && src) noexcept
 
 ~DropTargetAsync () noexcept override
 
GtkDropTargetAsync * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkDropTargetAsync * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkDropTargetAsync * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
void set_formats (const Glib::RefPtr< const Gdk::ContentFormats > & formats)
 Sets the data formats that this drop target will accept. More...
 
Glib::RefPtr< Gdk::ContentFormatsget_formats ()
 Gets the data formats that this drop target accepts. More...
 
Glib::RefPtr< const Gdk::ContentFormatsget_formats () const
 Gets the data formats that this drop target accepts. More...
 
void set_actions (Gdk::DragAction actions)
 Sets the actions that this drop target supports. More...
 
Gdk::DragAction get_actions () const
 Gets the actions that this drop target supports. More...
 
void reject_drop (const Glib::RefPtr< Gdk::Drop > & drop)
 Sets the drop as not accepted on this drag site. More...
 
Glib::PropertyProxy< Gdk::DragActionproperty_actions ()
 The Gdk::DragActions that this drop target supports. More...
 
Glib::PropertyProxy_ReadOnly< Gdk::DragActionproperty_actions () const
 The Gdk::DragActions that this drop target supports. More...
 
Glib::PropertyProxy< Glib::RefPtr< Gdk::ContentFormats > > property_formats ()
 The Gdk::ContentFormats that determines the supported data formats. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::ContentFormats > > property_formats () const
 The Gdk::ContentFormats that determines the supported data formats. More...
 
Glib::SignalProxy< bool(const Glib::RefPtr< Gdk::Drop > &)> signal_accept ()
 Only one signal handler is called. More...
 
Glib::SignalProxy< Gdk::DragAction(const Glib::RefPtr< Gdk::Drop > &, double, double)> signal_drag_enter ()
 Only one signal handler is called. More...
 
Glib::SignalProxy< Gdk::DragAction(const Glib::RefPtr< Gdk::Drop > &, double, double)> signal_drag_motion ()
 Only one signal handler is called. More...
 
Glib::SignalProxy< void(const Glib::RefPtr< Gdk::Drop > &)> signal_drag_leave ()
 
Glib::SignalProxy< bool(const Glib::RefPtr< Gdk::Drop > &, double, double)> signal_drop ()
 Only one signal handler is called. More...
 
- Public Member Functions inherited from Gtk::EventController
 EventController (EventController && src) noexcept
 
EventControlleroperator= (EventController && src) noexcept
 
 ~EventController () noexcept override
 
GtkEventController * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkEventController * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkEventController * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
Widgetget_widget ()
 Returns the Gtk::Widget this controller relates to. More...
 
const Widgetget_widget () const
 Returns the Gtk::Widget this controller relates to. More...
 
void reset ()
 Resets the controller to a clean state. More...
 
PropagationPhase get_propagation_phase () const
 Gets the propagation phase at which controller handles events. More...
 
void set_propagation_phase (PropagationPhase phase)
 Sets the propagation phase at which a controller handles events. More...
 
PropagationLimit get_propagation_limit () const
 Gets the propagation limit of the event controller. More...
 
void set_propagation_limit (PropagationLimit limit)
 Sets the event propagation limit on the event controller. More...
 
Glib::ustring get_name () const
 Gets the name of controller. More...
 
void set_name (const Glib::ustring & name)
 Sets a name on the controller that can be used for debugging. More...
 
Glib::RefPtr< const Gdk::Eventget_current_event () const
 Returns the event that is currently being handled by the controller. More...
 
guint32 get_current_event_time () const
 Returns the timestamp of the event that is currently being handled by the controller. More...
 
Glib::RefPtr< Gdk::Deviceget_current_event_device ()
 Returns the device of the event that is currently being handled by the controller. More...
 
Glib::RefPtr< const Gdk::Deviceget_current_event_device () const
 Returns the event that is currently being handled by the controller. More...
 
Gdk::ModifierType get_current_event_state () const
 Returns the modifier state of the event that is currently being handled by the controller. More...
 
Glib::PropertyProxy_ReadOnly< Widget * > property_widget () const
 The widget receiving the Gdk::Events that the controller will handle. More...
 
Glib::PropertyProxy< PropagationPhaseproperty_propagation_phase ()
 The propagation phase at which this controller will handle events. More...
 
Glib::PropertyProxy_ReadOnly< PropagationPhaseproperty_propagation_phase () const
 The propagation phase at which this controller will handle events. More...
 
Glib::PropertyProxy< PropagationLimitproperty_propagation_limit ()
 The limit for which events this controller will handle. More...
 
Glib::PropertyProxy_ReadOnly< PropagationLimitproperty_propagation_limit () const
 The limit for which events this controller will handle. More...
 
Glib::PropertyProxy< Glib::ustring > property_name ()
 The name for this controller, typically used for debugging purposes. More...
 
Glib::PropertyProxy_ReadOnly< Glib::ustring > property_name () const
 The name for this controller, typically used for debugging purposes. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< DropTargetAsynccreate (const Glib::RefPtr< const Gdk::ContentFormats > & formats, Gdk::DragAction actions=static_cast< Gdk::DragAction >(0))
 
static Glib::RefPtr< DropTargetAsynccreate (Gdk::DragAction actions=static_cast< Gdk::DragAction >(0))
 
- Static Public Member Functions inherited from Gtk::EventController
static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::DropTargetAsyncwrap (GtkDropTargetAsync * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Gtk::EventController
 EventController ()
 There is no create() method that corresponds to this constructor, because only derived classes shall be created. More...
 

Detailed Description

Event controller to receive DND drops.

Gtk::DropTargetAsync is an auxiliary object that can be used to receive Drag-and-Drop operations.
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 signal_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_drag_enter(), followed by signal_drag_motion() as the pointer moves, optionally a signal_drop() when a drop happens, and finally a signal_drag_leave() 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::StateFlags::DROP_ACTIVE state, which can be used by themes to style the widget as a drop target.

Since gtkmm 3.98:

Constructor & Destructor Documentation

◆ DropTargetAsync()

Gtk::DropTargetAsync::DropTargetAsync ( DropTargetAsync &&  src)
noexcept

◆ ~DropTargetAsync()

Gtk::DropTargetAsync::~DropTargetAsync ( )
overridenoexcept

Member Function Documentation

◆ create() [1/2]

static Glib::RefPtr< DropTargetAsync > Gtk::DropTargetAsync::create ( const Glib::RefPtr< const Gdk::ContentFormats > &  formats,
Gdk::DragAction  actions = static_cast< Gdk::DragAction >(0) 
)
static

◆ create() [2/2]

static Glib::RefPtr< DropTargetAsync > Gtk::DropTargetAsync::create ( Gdk::DragAction  actions = static_cast< Gdk::DragAction >(0))
static

◆ get_actions()

Gdk::DragAction Gtk::DropTargetAsync::get_actions ( ) const

Gets the actions that this drop target supports.

Returns
The actions that this drop target supports.

◆ get_formats() [1/2]

Glib::RefPtr< Gdk::ContentFormats > Gtk::DropTargetAsync::get_formats ( )

Gets the data formats that this drop target accepts.

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

Returns
The supported data formats.

◆ get_formats() [2/2]

Glib::RefPtr< const Gdk::ContentFormats > Gtk::DropTargetAsync::get_formats ( ) const

Gets the data formats that this drop target accepts.

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

Returns
The supported data formats.

◆ get_type()

static GType Gtk::DropTargetAsync::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GtkDropTargetAsync * Gtk::DropTargetAsync::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkDropTargetAsync * Gtk::DropTargetAsync::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkDropTargetAsync * Gtk::DropTargetAsync::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ operator=()

DropTargetAsync & Gtk::DropTargetAsync::operator= ( DropTargetAsync &&  src)
noexcept

◆ property_actions() [1/2]

Glib::PropertyProxy< Gdk::DragAction > Gtk::DropTargetAsync::property_actions ( )

The Gdk::DragActions that this drop target supports.

Default value: 0

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_actions() [2/2]

Glib::PropertyProxy_ReadOnly< Gdk::DragAction > Gtk::DropTargetAsync::property_actions ( ) const

The Gdk::DragActions that this drop target supports.

Default value: 0

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_formats() [1/2]

Glib::PropertyProxy< Glib::RefPtr< Gdk::ContentFormats > > Gtk::DropTargetAsync::property_formats ( )

The Gdk::ContentFormats that determines the supported data formats.

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_formats() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::ContentFormats > > Gtk::DropTargetAsync::property_formats ( ) const

The Gdk::ContentFormats that determines the supported data formats.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ reject_drop()

void Gtk::DropTargetAsync::reject_drop ( const Glib::RefPtr< Gdk::Drop > &  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.

Parameters
dropThe Gdk::Drop of an ongoing drag operation.

◆ set_actions()

void Gtk::DropTargetAsync::set_actions ( Gdk::DragAction  actions)

Sets the actions that this drop target supports.

Parameters
actionsThe supported actions.

◆ set_formats()

void Gtk::DropTargetAsync::set_formats ( const Glib::RefPtr< const Gdk::ContentFormats > &  formats)

Sets the data formats that this drop target will accept.

Parameters
formatsThe supported data formats or nullptr for any format.

◆ signal_accept()

Glib::SignalProxy< bool(const Glib::RefPtr< Gdk::Drop > &)> Gtk::DropTargetAsync::signal_accept ( )

Only one signal handler is called.

If you connect a handler, it must be called before (instead of) the default handler, otherwise it won't be called. Set the after parameter in connect() to false.

Slot Prototype:
bool on_my_accept(const Glib::RefPtr<Gdk::Drop>& drop)

Flags: Run Last

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 Gtk::DropTargetAsync::reject_drop() or ultimately by returning false from a signal_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 Gtk::DropTargetAsync::reject_drop().

Parameters
dropThe Gdk::Drop.
Returns
true if drop is accepted.

◆ signal_drag_enter()

Glib::SignalProxy< Gdk::DragAction(const Glib::RefPtr< Gdk::Drop > &, double, double)> Gtk::DropTargetAsync::signal_drag_enter ( )

Only one signal handler is called.

If you connect a handler, it must be called before (instead of) the default handler, otherwise it won't be called. Set the after parameter in connect() to false.

Slot Prototype:
Gdk::DragAction on_my_drag_enter(const Glib::RefPtr<Gdk::Drop>& drop, double x, double y)

Flags: Run Last

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

It can be used to set up custom highlighting.

Parameters
dropThe Gdk::Drop.
xThe x coordinate of the current pointer position.
yThe y coordinate of the current pointer position.
Returns
Preferred action for this drag operation.

◆ signal_drag_leave()

Glib::SignalProxy< void(const Glib::RefPtr< Gdk::Drop > &)> Gtk::DropTargetAsync::signal_drag_leave ( )
Slot Prototype:
void on_my_drag_leave(const Glib::RefPtr<Gdk::Drop>& drop)

Flags: Run Last

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

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

Parameters
dropThe Gdk::Drop.

◆ signal_drag_motion()

Glib::SignalProxy< Gdk::DragAction(const Glib::RefPtr< Gdk::Drop > &, double, double)> Gtk::DropTargetAsync::signal_drag_motion ( )

Only one signal handler is called.

If you connect a handler, it must be called before (instead of) the default handler, otherwise it won't be called. Set the after parameter in connect() to false.

Slot Prototype:
Gdk::DragAction on_my_drag_motion(const Glib::RefPtr<Gdk::Drop>& drop, double x, double y)

Flags: Run Last

Emitted while the pointer is moving over the drop target.

Parameters
dropThe Gdk::Drop.
xThe x coordinate of the current pointer position.
yThe y coordinate of the current pointer position.
Returns
Preferred action for this drag operation.

◆ signal_drop()

Glib::SignalProxy< bool(const Glib::RefPtr< Gdk::Drop > &, double, double)> Gtk::DropTargetAsync::signal_drop ( )

Only one signal handler is called.

If you connect a handler, it must be called before (instead of) the default handler, otherwise it won't be called. Set the after parameter in connect() to false.

Slot Prototype:
bool on_my_drop(const Glib::RefPtr<Gdk::Drop>& drop, double x, double y)

Flags: Run Last

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

To receive the data, use one of the read functions provided by Gdk::Drop such as Gdk::Drop::read_async() or Gdk::Drop::read_value_async().

Parameters
dropThe Gdk::Drop.
xThe x coordinate of the current pointer position.
yThe y coordinate of the current pointer position.
Returns
Whether the drop is accepted at the given pointer position.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gtk::DropTargetAsync > wrap ( GtkDropTargetAsync *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.