gtkmm  3.97.1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::DropTarget Class Reference

Event controller to receive DND drops. More...

#include <gtkmm/droptarget.h>

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

Public Member Functions

 DropTarget (DropTarget&& src) noexcept
 
DropTargetoperator= (DropTarget&& src) noexcept
 
 ~DropTarget () noexcept override
 
GtkDropTarget* gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkDropTarget* gobj () const
 Provides access to the underlying C GObject. More...
 
GtkDropTarget* 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...
 
Glib::RefPtr< Gdk::Dropget_drop ()
 Returns the underlying Gtk::Drop object for an ongoing drag. More...
 
Glib::RefPtr< const Gdk::Dropget_drop () const
 Returns the underlying Gtk::Drop object for an ongoing drag. More...
 
Glib::ustring find_mimetype () const
 Returns a mimetype that is supported both by dest and the ongoing drag. More...
 
void read_selection_async (const std::string& target, const Gio::SlotAsyncReady& slot, const Glib::RefPtr< Gio::Cancellable >& cancellable)
 Asynchronously reads the dropped data from an ongoing drag on a Gtk::DropTarget, and returns the data in a Gtk::SelectionData object. More...
 
void read_selection_async (const std::string& target, const Gio::SlotAsyncReady& slot)
 A read_selection_async() convenience overload. More...
 
SelectionData read_selection_finish (const Glib::RefPtr< Gio::AsyncResult >& result)
 Finishes an async drop read operation, see read_selection(). More...
 
void deny_drop (const Glib::RefPtr< Gdk::Drop >& drop)
 Sets the drop as not accepted on this drag site. 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::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_ReadOnly< bool > property_contains () const
 Whether the drop target is currently the targed of an ongoing drag operation, and highlighted. More...
 
Glib::SignalProxy< bool(const Glib::RefPtr< Gdk::Drop >&)> signal_accept ()
 Only one signal handler is called. More...
 
Glib::SignalProxy< void(const Glib::RefPtr< Gdk::Drop >&)> signal_drag_enter ()
 
Glib::SignalProxy< void(const Glib::RefPtr< Gdk::Drop >&, int, int)> signal_drag_motion ()
 
Glib::SignalProxy< void(const Glib::RefPtr< Gdk::Drop >&)> signal_drag_leave ()
 
Glib::SignalProxy< bool(const Glib::RefPtr< Gdk::Drop >&, int, int)> signal_drag_drop ()
 
- 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...
 
bool handle_event (const Glib::RefPtr< const Gdk::Event >& event)
 Feeds an event into controller, so it can be interpreted and the controller actions triggered. 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
 
void set_propagation_limit (PropagationLimit limit)
 
Glib::ustring get_name () const
 
void set_name (const Glib::ustring& name)
 
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::ustringproperty_name ()
 Name for this controller. More...
 
Glib::PropertyProxy_ReadOnly< Glib::ustringproperty_name () const
 Name for this controller. More...
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&src) noexcept
 
Objectoperator= (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::Objectwrap (GObject *object, bool take_copy=false)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
 
ObjectBaseoperator= (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
 
- Public Member Functions inherited from sigc::trackable
 trackable () noexcept
 
 trackable (const trackable &src) noexcept
 
 trackable (trackable &&src) noexcept
 
 ~trackable ()
 
void add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
 
void notify_callbacks ()
 
trackableoperator= (const trackable &src)
 
trackableoperator= (trackable &&src) noexcept
 
void remove_destroy_notify_callback (notifiable *data) 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< DropTargetcreate (const Glib::RefPtr< const Gdk::ContentFormats >& formats, Gdk::DragAction actions=static_cast< Gdk::DragAction >(0))
 
static Glib::RefPtr< DropTargetcreate (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...
 

Protected Member Functions

 DropTarget (const Glib::RefPtr< const Gdk::ContentFormats >& formats, Gdk::DragAction actions)
 
- 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
 
ObjectBaseoperator= (ObjectBase &&src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject *castitem)
 
void initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::DropTargetwrap (GtkDropTarget* 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)
 
- Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify func_destroy_notify
 
- Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify func_destroy_notify
 

Detailed Description

Event controller to receive DND drops.

Gtk::DropTarget is an auxiliary object that is used to receive Drag-and-Drop operations.

To use a Gtk::DropTarget to receive drops on a widget, you create a Gtk::DropTarget 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::DropTarget emits is signal_accept(), which is meant to determine whether the target is a possible drop site for the ongoing drag. The default handler for the accept signal accepts the drag if it finds a compatible data format and an action that is supported on both sides.

If it is, and the widget becomes the current target, you will receive a signal_drag_enter(), followed by signal_drag_motion() signals as the pointer moves, and finally either a signal_drag_leave() when the pointer moves off the widget, or a signal_drag_drop() when a drop happens.

The signal_drag_enter() and signal_drag_motion() handler can call Gdk::Drop::status() to update the status of the ongoing operation. The signal_drag_drop() handler 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 the current drop target, and will receive the Gtk::StateFlags::DROP_ACTIVE state, which can be used to style the widget as a drop target.

Since gtkmm 3.96:

Constructor & Destructor Documentation

Gtk::DropTarget::DropTarget ( DropTarget&&  src)
noexcept
Gtk::DropTarget::~DropTarget ( )
overridenoexcept
Gtk::DropTarget::DropTarget ( const Glib::RefPtr< const Gdk::ContentFormats >&  formats,
Gdk::DragAction  actions 
)
explicitprotected

Member Function Documentation

static Glib::RefPtr<DropTarget> Gtk::DropTarget::create ( const Glib::RefPtr< const Gdk::ContentFormats >&  formats,
Gdk::DragAction  actions = static_cast< Gdk::DragAction >(0) 
)
static
static Glib::RefPtr<DropTarget> Gtk::DropTarget::create ( Gdk::DragAction  actions = static_cast< Gdk::DragAction >(0))
static
void Gtk::DropTarget::deny_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.
Glib::ustring Gtk::DropTarget::find_mimetype ( ) const

Returns a mimetype that is supported both by dest and the ongoing drag.

For more detailed control, you can use gdk_drop_get_formats() to obtain the content formats that are supported by the source.

Returns
A matching mimetype for the ongoing drag, or nullptr.
Gdk::DragAction Gtk::DropTarget::get_actions ( ) const

Gets the actions that this drop target supports.

Returns
The actions that this drop target supports.
Glib::RefPtr<Gdk::Drop> Gtk::DropTarget::get_drop ( )

Returns the underlying Gtk::Drop object for an ongoing drag.

Returns
The Gtk::Drop of the current drag operation, or nullptr.
Glib::RefPtr<const Gdk::Drop> Gtk::DropTarget::get_drop ( ) const

Returns the underlying Gtk::Drop object for an ongoing drag.

Returns
The Gtk::Drop of the current drag operation, or nullptr.
Glib::RefPtr<Gdk::ContentFormats> Gtk::DropTarget::get_formats ( )

Gets the data formats that this drop target accepts.

Returns
The supported data formats.
Glib::RefPtr<const Gdk::ContentFormats> Gtk::DropTarget::get_formats ( ) const

Gets the data formats that this drop target accepts.

Returns
The supported data formats.
static GType Gtk::DropTarget::get_type ( )
static

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

GtkDropTarget* Gtk::DropTarget::gobj ( )
inline

Provides access to the underlying C GObject.

const GtkDropTarget* Gtk::DropTarget::gobj ( ) const
inline

Provides access to the underlying C GObject.

GtkDropTarget* Gtk::DropTarget::gobj_copy ( )

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

DropTarget& Gtk::DropTarget::operator= ( DropTarget&&  src)
noexcept
Glib::PropertyProxy< Gdk::DragAction > Gtk::DropTarget::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.
Glib::PropertyProxy_ReadOnly< Gdk::DragAction > Gtk::DropTarget::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.
Glib::PropertyProxy_ReadOnly< bool > Gtk::DropTarget::property_contains ( ) const

Whether the drop target is currently the targed of an ongoing drag operation, and highlighted.

Default value: false

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.
Glib::PropertyProxy< Glib::RefPtr<Gdk::ContentFormats> > Gtk::DropTarget::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.
Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Gdk::ContentFormats> > Gtk::DropTarget::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.
void Gtk::DropTarget::read_selection_async ( const std::string target,
const Gio::SlotAsyncReady &  slot,
const Glib::RefPtr< Gio::Cancellable > &  cancellable 
)

Asynchronously reads the dropped data from an ongoing drag on a Gtk::DropTarget, and returns the data in a Gtk::SelectionData object.

This function is meant for cases where a Gtk::SelectionData object is needed, such as when using the Gtk::TreeModel DND support. In most other cases, the Gdk::Drop async read APIs that return in input stream or Value are more convenient and should be preferred.

Parameters
targetThe data format to read.
cancellableA cancellable.
slotCallback to call on completion.
void Gtk::DropTarget::read_selection_async ( const std::string target,
const Gio::SlotAsyncReady &  slot 
)

A read_selection_async() convenience overload.

SelectionData Gtk::DropTarget::read_selection_finish ( const Glib::RefPtr< Gio::AsyncResult > &  result)

Finishes an async drop read operation, see read_selection().

Parameters
resultA Gio::AsyncResult.
Returns
The Gtk::SelectionData, or nullptr.
Exceptions
Glib::Error
void Gtk::DropTarget::set_actions ( Gdk::DragAction  actions)

Sets the actions that this drop target supports.

Parameters
actionsThe supported actions.
void Gtk::DropTarget::set_formats ( const Glib::RefPtr< const Gdk::ContentFormats >&  formats)

Sets the data formats that this drop target will accept.

Parameters
formatsThe supported data formats.
Glib::SignalProxy<bool(const Glib::RefPtr<Gdk::Drop>&)> Gtk::DropTarget::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

The signal_accept() signal is emitted on the drop site when the user moves the cursor over the widget during a drag. The signal handler must determine whether the cursor 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, the handler is responsible for providing the necessary information for displaying feedback to the user, by calling gdk_drag_status().

The default handler for this signal decides whether to accept the drop based on the type of the data.

If the decision whether the drop will be accepted or rejected can't be made based solely the data format, handler may inspect the dragged data by calling one of the Gdk::Drop read functions and return true to tentatively accept the drop. When the data arrives and is found to not be acceptable, a call to Gtk::DropTarget::deny_drop() should be made to reject the drop.

Parameters
dropThe Gdk::Drop.
Returns
Whether the cursor position is in a drop zone.
Glib::SignalProxy<bool(const Glib::RefPtr<Gdk::Drop>&, int, int)> Gtk::DropTarget::signal_drag_drop ( )
Slot Prototype:
bool on_my_drag_drop(const Glib::RefPtr<Gdk::Drop>& drop, int x, int y)

Flags: Run Last

The signal_drag_drop() signal is emitted on the drop site when the user drops the data onto the widget. The signal handler must determine whether the cursor 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, the handler must ensure that gdk_drop_finish() is called to let the source know that the drop is done. The call to gtk_drag_finish() can be done either directly or after receiving the data.

To receive the data, use one of the read functions provides by Gtk::Drop and Gtk::DragDest: gdk_drop_read_async(), gdk_drop_read_value_async(), gdk_drop_read_text_async(), Gtk::DropTarget::read_selection().

You can use Gtk::DropTarget::get_drop() to obtain the Gtk::Drop object for the ongoing operation in your signal handler. If you call one of the read functions in your handler, GTK will ensure that the Gtk::Drop object stays alive until the read is completed. If you delay obtaining the data (e.g. to handle Gdk::DragAction::ASK by showing a Gtk::Popover), you need to hold a reference on the Gtk::Drop.

Parameters
dropThe Gdk::Drop.
xThe x coordinate of the current cursor position.
yThe y coordinate of the current cursor position.
Returns
Whether the cursor position is in a drop zone.
Glib::SignalProxy<void(const Glib::RefPtr<Gdk::Drop>&)> Gtk::DropTarget::signal_drag_enter ( )
Slot Prototype:
void on_my_drag_enter(const Glib::RefPtr<Gdk::Drop>& drop)

Flags: Run Last

The signal_drag_enter() signal is emitted on the drop site when the cursor enters the widget. It can be used to set up custom highlighting.

Parameters
dropThe Gdk::Drop.
Glib::SignalProxy<void(const Glib::RefPtr<Gdk::Drop>&)> Gtk::DropTarget::signal_drag_leave ( )
Slot Prototype:
void on_my_drag_leave(const Glib::RefPtr<Gdk::Drop>& drop)

Flags: Run Last

The signal_drag_leave() signal is emitted on the drop site when the cursor leaves the widget. Its main purpose it to undo things done in Gtk::DropTarget::signal_drag_enter().

Parameters
dropThe Gdk::Drop.
Glib::SignalProxy<void(const Glib::RefPtr<Gdk::Drop>&, int, int)> Gtk::DropTarget::signal_drag_motion ( )
Slot Prototype:
void on_my_drag_motion(const Glib::RefPtr<Gdk::Drop>& drop, int x, int y)

Flags: Run Last

The signal_drag() motion signal is emitted while the pointer is moving over the drop target.

Parameters
dropThe Gdk::Drop.
xThe x coordinate of the current cursor position.
yThe y coordinate of the current cursor position.

Friends And Related Function Documentation

Glib::RefPtr< Gtk::DropTarget > wrap ( GtkDropTarget *  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.