gtkmm
3.97.1
|
Event controller to receive DND drops. More...
#include <gtkmm/droptarget.h>
Public Member Functions | |
DropTarget (DropTarget&& src) noexcept | |
DropTarget& | operator= (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::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... | |
Glib::RefPtr< Gdk::Drop > | get_drop () |
Returns the underlying Gtk::Drop object for an ongoing drag. More... | |
Glib::RefPtr< const Gdk::Drop > | get_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::DragAction > | property_actions () |
The Gdk::DragActions that this drop target supports. More... | |
Glib::PropertyProxy_ReadOnly< Gdk::DragAction > | property_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 () |
![]() | |
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... | |
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< 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 () |
Name for this controller. More... | |
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_name () const |
Name for this controller. More... | |
![]() | |
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) |
![]() | |
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< DropTarget > | create (const Glib::RefPtr< const Gdk::ContentFormats >& formats, Gdk::DragAction actions=static_cast< Gdk::DragAction >(0)) |
static Glib::RefPtr< DropTarget > | create (Gdk::DragAction actions=static_cast< Gdk::DragAction >(0)) |
![]() | |
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) | |
![]() | |
EventController () | |
There is no create() method that corresponds to this constructor, because only derived classes shall be created. More... | |
![]() | |
Object () | |
Object (const Glib::ConstructParams &construct_params) | |
Object (GObject *castitem) | |
~Object () noexcept override | |
![]() | |
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) |
Related Functions | |
(Note that these are not member functions.) | |
Glib::RefPtr< Gtk::DropTarget > | wrap (GtkDropTarget* object, bool take_copy=false) |
A Glib::wrap() method for this object. More... | |
![]() | |
Glib::RefPtr< Gtk::EventController > | wrap (GtkEventController* object, bool take_copy=false) |
A Glib::wrap() method for this object. More... | |
Additional Inherited Members | |
![]() | |
typedef void(*)(gpointer data | DestroyNotify) |
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.
|
noexcept |
|
overridenoexcept |
|
explicitprotected |
|
static |
|
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.
drop | The 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.
nullptr
. Gdk::DragAction Gtk::DropTarget::get_actions | ( | ) | const |
Gets 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.
nullptr
. Glib::RefPtr<const Gdk::Drop> Gtk::DropTarget::get_drop | ( | ) | const |
Returns the underlying Gtk::Drop object for an ongoing drag.
nullptr
. Glib::RefPtr<Gdk::ContentFormats> Gtk::DropTarget::get_formats | ( | ) |
Gets the data formats that this drop target accepts.
Glib::RefPtr<const Gdk::ContentFormats> Gtk::DropTarget::get_formats | ( | ) | const |
Gets the data formats that this drop target accepts.
|
static |
Get the GType for this class, for use with the underlying GObject type system.
|
inline |
Provides access to the underlying C GObject.
|
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.
|
noexcept |
Glib::PropertyProxy< Gdk::DragAction > Gtk::DropTarget::property_actions | ( | ) |
The Gdk::DragActions that this drop target supports.
Default value: 0
Glib::PropertyProxy_ReadOnly< Gdk::DragAction > Gtk::DropTarget::property_actions | ( | ) | const |
The Gdk::DragActions that this drop target supports.
Default value: 0
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
Glib::PropertyProxy< Glib::RefPtr<Gdk::ContentFormats> > Gtk::DropTarget::property_formats | ( | ) |
The Gdk::ContentFormats that determines the supported data formats.
Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Gdk::ContentFormats> > Gtk::DropTarget::property_formats | ( | ) | const |
The Gdk::ContentFormats that determines the supported data formats.
void Gtk::DropTarget::read_selection_async | ( | const std::string & | target, |
const Gio::SlotAsyncReady & | slot | ||
) |
A read_selection_async() convenience overload.
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.
target | The data format to read. |
cancellable | A cancellable. |
slot | Callback to call on completion. |
SelectionData Gtk::DropTarget::read_selection_finish | ( | const Glib::RefPtr< Gio::AsyncResult > & | result | ) |
Finishes an async drop read operation, see read_selection().
result | A Gio::AsyncResult. |
nullptr
.Glib::Error |
void Gtk::DropTarget::set_actions | ( | Gdk::DragAction | actions | ) |
Sets the actions that this drop target supports.
actions | The supported actions. |
void Gtk::DropTarget::set_formats | ( | const Glib::RefPtr< const Gdk::ContentFormats >& | formats | ) |
Sets the data formats that this drop target will accept.
formats | The 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
.
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.
drop | The Gdk::Drop. |
Glib::SignalProxy<bool(const Glib::RefPtr<Gdk::Drop>&, int, int)> Gtk::DropTarget::signal_drag_drop | ( | ) |
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.
drop | The Gdk::Drop. |
x | The x coordinate of the current cursor position. |
y | The y coordinate of the current cursor position. |
Glib::SignalProxy<void(const Glib::RefPtr<Gdk::Drop>&)> Gtk::DropTarget::signal_drag_enter | ( | ) |
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.
drop | The Gdk::Drop. |
Glib::SignalProxy<void(const Glib::RefPtr<Gdk::Drop>&)> Gtk::DropTarget::signal_drag_leave | ( | ) |
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().
drop | The Gdk::Drop. |
Glib::SignalProxy<void(const Glib::RefPtr<Gdk::Drop>&, int, int)> Gtk::DropTarget::signal_drag_motion | ( | ) |
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.
drop | The Gdk::Drop. |
x | The x coordinate of the current cursor position. |
y | The y coordinate of the current cursor position. |
|
related |
A Glib::wrap() method for this object.
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. |