gtkmm 4.14.0
Public Member Functions | Static Public 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_gtypes (const std::vector< GType > & types)
 Sets the supported Types for this drop target. More...
 
std::vector< GType > get_gtypes () const
 Gets a vector of supported Types. 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 set_preload (bool preload=true)
 Sets whether data should be preloaded on hover. More...
 
bool get_preload () const
 Gets whether data should be preloaded on hover. More...
 
Glib::RefPtr< Gdk::Dropget_drop ()
 Gets the currently handled drop operation. More...
 
Glib::RefPtr< const Gdk::Dropget_drop () const
 Gets the currently handled drop operation. More...
 
Glib::RefPtr< Gdk::Dropget_current_drop ()
 Gets the currently handled drop operation. More...
 
Glib::RefPtr< const Gdk::Dropget_current_drop () const
 Gets the currently handled drop operation. More...
 
Glib::ValueBase get_value () const
 Gets the current drop data, as a Glib::Value. More...
 
void reject ()
 Rejects the ongoing drop operation. 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< Glib::RefPtr< Gdk::Drop > > property_drop () const
 The Gdk::Drop that is currently being performed. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::Drop > > property_current_drop () const
 The Gdk::Drop that is currently being performed. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::ContentFormats > > property_formats () const
 The Gdk::ContentFormats that determine the supported data formats. More...
 
Glib::PropertyProxy< bool > property_preload ()
 Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released. More...
 
Glib::PropertyProxy_ReadOnly< bool > property_preload () const
 Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released. More...
 
Glib::PropertyProxy_ReadOnly< GValue * > property_value () const
 The value for this drop operation. More...
 
Glib::SignalProxy< bool(const Glib::RefPtr< Gdk::Drop > &)> signal_accept ()
 Only one signal handler is called. More...
 
Glib::SignalProxy< Gdk::DragAction(double, double)> signal_enter ()
 Only one signal handler is called. More...
 
Glib::SignalProxy< Gdk::DragAction(double, double)> signal_motion ()
 Only one signal handler is called. More...
 
Glib::SignalProxy< void()> signal_leave ()
 
Glib::SignalProxy< bool(const Glib::ValueBase &, 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< DropTargetcreate (GType type, Gdk::DragAction actions)
 Creates a new Gtk::DropTarget object. More...
 
- 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::DropTargetwrap (GtkDropTarget * 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::DropTarget is an event controller implementing a simple way to receive Drag-and-Drop operations.

The most basic way to use a Gtk::DropTarget to receive drops on a widget is to create it via create() passing in the GType of the data you want to receive and connect to signal_drop() to receive the data.

Gtk::DropTarget supports more options, such as:

However, Gtk::DropTarget is ultimately modeled in a synchronous way and only supports data transferred via GType.
If you want full control over an ongoing drop, the Gtk::DropTargetAsync object gives you this ability.

While a pointer is dragged over the drop target's widget and the drop has not been rejected, that widget will receive the Gtk::StateFlags::DROP_ACTIVE state, which can be used to style the widget.

Since gtkmm 3.96:

Constructor & Destructor Documentation

◆ DropTarget()

Gtk::DropTarget::DropTarget ( DropTarget &&  src)
noexcept

◆ ~DropTarget()

Gtk::DropTarget::~DropTarget ( )
overridenoexcept

Member Function Documentation

◆ create()

static Glib::RefPtr< DropTarget > Gtk::DropTarget::create ( GType  type,
Gdk::DragAction  actions 
)
static

Creates a new Gtk::DropTarget object.

If the drop target should support more than 1 type, pass G_TYPE_INVALID for type and then call set_gtypes().

Parameters
typeThe supported type or G_TYPE_INVALID.
actionsThe supported actions.
Returns
The new Gtk::DropTarget.

◆ get_actions()

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

Gets the actions that this drop target supports.

Returns
The actions that this drop target supports.

◆ get_current_drop() [1/2]

Glib::RefPtr< Gdk::Drop > Gtk::DropTarget::get_current_drop ( )

Gets the currently handled drop operation.

If no drop operation is going on, nullptr is returned.

Since gtkmm 4.4:
Returns
The current drop.

◆ get_current_drop() [2/2]

Glib::RefPtr< const Gdk::Drop > Gtk::DropTarget::get_current_drop ( ) const

Gets the currently handled drop operation.

If no drop operation is going on, nullptr is returned.

Since gtkmm 4.4:
Returns
The current drop.

◆ get_drop() [1/2]

Glib::RefPtr< Gdk::Drop > Gtk::DropTarget::get_drop ( )

Gets the currently handled drop operation.

If no drop operation is going on, nullptr is returned.

Deprecated: 4.4: Use get_current_drop() instead

Deprecated:
Use get_current_drop() instead.
Returns
The current drop.

◆ get_drop() [2/2]

Glib::RefPtr< const Gdk::Drop > Gtk::DropTarget::get_drop ( ) const

Gets the currently handled drop operation.

If no drop operation is going on, nullptr is returned.

Deprecated: 4.4: Use get_current_drop() instead

Deprecated:
Use get_current_drop() instead.
Returns
The current drop.

◆ get_formats() [1/2]

Glib::RefPtr< Gdk::ContentFormats > Gtk::DropTarget::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::DropTarget::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_gtypes()

std::vector< GType > Gtk::DropTarget::get_gtypes ( ) const

Gets a vector of supported Types.

If no type have been set, an empty vector will be returned.

Returns
Vector of types.

◆ get_preload()

bool Gtk::DropTarget::get_preload ( ) const

Gets whether data should be preloaded on hover.

Returns
true if drop data should be preloaded.

◆ get_type()

static GType Gtk::DropTarget::get_type ( )
static

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

◆ get_value()

Glib::ValueBase Gtk::DropTarget::get_value ( ) const

Gets the current drop data, as a Glib::Value.

Returns
The current drop data.

◆ gobj() [1/2]

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

Provides access to the underlying C GObject.

◆ gobj() [2/2]

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

Provides access to the underlying C GObject.

◆ gobj_copy()

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.

◆ operator=()

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

◆ property_actions() [1/2]

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.

◆ property_actions() [2/2]

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.

◆ property_current_drop()

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::Drop > > Gtk::DropTarget::property_current_drop ( ) const

The Gdk::Drop that is currently being performed.

Since gtkmm 4.4:
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_drop()

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::Drop > > Gtk::DropTarget::property_drop ( ) const

The Gdk::Drop that is currently being performed.

Deprecated: 4.4: Use property_current_drop() instead

Deprecated:
Use property_current_drop() instead.
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()

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

The Gdk::ContentFormats that determine 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.

◆ property_preload() [1/2]

Glib::PropertyProxy< bool > Gtk::DropTarget::property_preload ( )

Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.

Setting this property allows finer grained reaction to an ongoing drop at the cost of loading more data.

The default value for this property is false to avoid downloading huge amounts of data by accident.

For example, if somebody drags a full document of gigabytes of text from a text editor across a widget with a preloading drop target, this data will be downloaded, even if the data is ultimately dropped elsewhere.

For a lot of data formats, the amount of data is very small (like GDK_TYPE_RGBA), so enabling this property does not hurt at all. And for local-only Drag-and-Drop operations, no data transfer is done, so enabling it there is free.

Default value: false

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_preload() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gtk::DropTarget::property_preload ( ) const

Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.

Setting this property allows finer grained reaction to an ongoing drop at the cost of loading more data.

The default value for this property is false to avoid downloading huge amounts of data by accident.

For example, if somebody drags a full document of gigabytes of text from a text editor across a widget with a preloading drop target, this data will be downloaded, even if the data is ultimately dropped elsewhere.

For a lot of data formats, the amount of data is very small (like GDK_TYPE_RGBA), so enabling this property does not hurt at all. And for local-only Drag-and-Drop operations, no data transfer is done, so enabling it there is free.

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.

◆ property_value()

Glib::PropertyProxy_ReadOnly< GValue * > Gtk::DropTarget::property_value ( ) const

The value for this drop operation.

This is nullptr if the data has not been loaded yet or no drop operation is going on.

Data may be available before the signal_drop() signal gets emitted - for example when the property_preload() property is set. You can use the signal_notify() signal to be notified of available data.

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()

void Gtk::DropTarget::reject ( )

Rejects the ongoing drop operation.

If no drop operation is ongoing, i.e when property_current_drop() is nullptr, this function does nothing.

This function should be used when delaying the decision on whether to accept a drag or not until after reading the data.

◆ set_actions()

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

Sets the actions that this drop target supports.

Parameters
actionsThe supported actions.

◆ set_gtypes()

void Gtk::DropTarget::set_gtypes ( const std::vector< GType > &  types)

Sets the supported Types for this drop target.

Parameters
typesAll supported Types that can be dropped.

◆ set_preload()

void Gtk::DropTarget::set_preload ( bool  preload = true)

Sets whether data should be preloaded on hover.

Parameters
preloadtrue to preload drop data.

◆ signal_accept()

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

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::DropTarget::reject() 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 depends on the data, this function should return true, the property_preload() property should be set and the value should be inspected via the ::notify:value signal, calling Gtk::DropTarget::reject() if required.

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

◆ signal_drop()

Glib::SignalProxy< bool(const Glib::ValueBase &, double, double)> Gtk::DropTarget::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::ValueBase& value, 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 is responsible for using the given value and performing the drop operation.

Parameters
valueThe Glib::Value being dropped.
xThe x coordinate of the current pointer position.
yThe y coordinate of the current pointer position.
Returns
Whether the drop was accepted at the given pointer position.

◆ signal_enter()

Glib::SignalProxy< Gdk::DragAction(double, double)> Gtk::DropTarget::signal_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_enter(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
xThe x coordinate of the current pointer position.
yThe y coordinate of the current pointer position.
Returns
Preferred action for this drag operation or 0 if dropping is not supported at the current x, y location.

◆ signal_leave()

Glib::SignalProxy< void()> Gtk::DropTarget::signal_leave ( )
Slot Prototype:
void on_my_leave()

Flags: Run Last

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

Its main purpose it to undo things done in signal_enter().

◆ signal_motion()

Glib::SignalProxy< Gdk::DragAction(double, double)> Gtk::DropTarget::signal_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_motion(double x, double y)

Flags: Run Last

Emitted while the pointer is moving over the drop target.

Parameters
xThe x coordinate of the current pointer position.
yThe y coordinate of the current pointer position.
Returns
Preferred action for this drag operation or 0 if dropping is not supported at the current x, y location.

Friends And Related Function Documentation

◆ wrap()

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.