gtkmm: Gtk::DropTargetAsync Class Reference

gtkmm 4.2.0

Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Gtk::DropTargetAsync Class Reference
Event Controllers and Gestures

Event controller to receive DND drops. More...

`#include <gtkmm/droptargetasync.h>`

Inheritance diagram for Gtk::DropTargetAsync:
[legend]

## Public Member Functions
| DropTargetAsync (DropTargetAsync&& src) noexcept
DropTargetAsync& | operator= (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::ContentFormats > | get_formats ()
| Gets the data formats that this drop target accepts. More...
Glib::RefPtr< const Gdk::ContentFormats > | get_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::DragAction > | property_actions ()
| The `GdkDragActions` that this drop target supports. More...
Glib::PropertyProxy_ReadOnly< Gdk::DragAction > | property_actions () const
| The `GdkDragActions` that this drop target supports. More...
Glib::PropertyProxy< Glib::RefPtr< Gdk::ContentFormats > > | property_formats ()
| The `GdkContentFormats` that determines the supported data formats. More...
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::ContentFormats > > | property_formats () const
| The `GdkContentFormats` 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
EventController& | operator= (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...
Widget* | get_widget ()
| Returns the Gtk::Widget this controller relates to. More...
const Widget* | get_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::Event > | get_current_event () const
| Returns the event that is currently being handled by the controller, and `nullptr` at other times. More...
guint32 | get_current_event_time () const
| Returns the timestamp of the event that is currently being handled by the controller, and 0 otherwise. More...
Glib::RefPtr< Gdk::Device > | get_current_event_device ()
| Returns the device of the event that is currently being handled by the controller, and `nullptr` otherwise. More...
Glib::RefPtr< const Gdk::Device > | get_current_event_device () const
| Returns the event that is currently being handled by the controller, and `nullptr` at other times. More...
Gdk::ModifierType | get_current_event_state () const
| Returns the modifier state of the event that is currently being handled by the controller, and 0 otherwise. More...
Glib::PropertyProxy_ReadOnly< Widget* > | property_widget () const
| The widget receiving the `GdkEvents` that the controller will handle. More...
Glib::PropertyProxy< PropagationPhase > | property_propagation_phase ()
| The propagation phase at which this controller will handle events. More...
Glib::PropertyProxy_ReadOnly< PropagationPhase > | property_propagation_phase () const
| The propagation phase at which this controller will handle events. More...
Glib::PropertyProxy< PropagationLimit > | property_propagation_limit ()
| The limit for which events this controller will handle. More...
Glib::PropertyProxy_ReadOnly< PropagationLimit > | property_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...
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const

## 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< DropTargetAsync > | create (const Glib::RefPtr< const Gdk::ContentFormats >& formats, Gdk::DragAction actions=static_cast< Gdk::DragAction >(0))
static Glib::RefPtr< DropTargetAsync > | create (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::DropTargetAsync > | wrap (GtkDropTargetAsync* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Gtk::EventController
Glib::RefPtr< Gtk::EventController > | wrap (GtkEventController* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Additional Inherited Members
Public Types inherited from Glib::Object
typedef void(*)(gpointer data | DestroyNotify)
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...
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## 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 `GdkDragActions` 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 `GdkDragActions` 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 `GdkContentFormats` 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 `GdkContentFormats` 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

  drop | The 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

  actions | The 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

  formats | The 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 [method Gtk.DropTargetAsync.reject_drop] or ultimately by returning `false` from a [signal Gtk.DropTargetAsync::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 [method Gtk.DropTargetAsync.reject_drop].

Parameters

  drop | The 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

  drop | The Gdk::Drop.
  x | The x coordinate of the current pointer position.
  y | The 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 `GtkDropTargetAsync`::drag-enter.

Parameters

  drop | The 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

  drop | The Gdk::Drop.
  x | The x coordinate of the current pointer position.
  y | The 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 [method Gdk.Drop.finish] is called to let the source know that the drop is done. The call to [method 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 [class Gdk.Drop] such as [method Gdk.Drop.read_async] or [method Gdk.Drop.read_value_async].

Parameters

  drop | The Gdk::Drop.
  x | The x coordinate of the current pointer position.
  y | The 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

  object | The C instance.
  take_copy | False 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.