From 4a966d50150f7a654a4cddf36f259f9fd15e4de3 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 19 Nov 2024 04:28:59 +0100 Subject: [PATCH] DndVBox: implement drag-refuse and drag move action --- libs/gtkmm2ext/gtkmm2ext/dndvbox.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/libs/gtkmm2ext/gtkmm2ext/dndvbox.h b/libs/gtkmm2ext/gtkmm2ext/dndvbox.h index 27c10b79b6..a30e94ca24 100644 --- a/libs/gtkmm2ext/gtkmm2ext/dndvbox.h +++ b/libs/gtkmm2ext/gtkmm2ext/dndvbox.h @@ -62,8 +62,9 @@ template class /*LIBGTKMM2EXT_API*/ DnDVBox : public Gtk::EventBox { public: - DnDVBox (std::list targets) + DnDVBox (std::list targets, Gdk::DragAction actions = Gdk::ACTION_COPY) : _targets (targets) + , _actions (actions) , _active (0) , _drag_icon (0) , _expecting_unwanted_button_event (false) @@ -85,7 +86,7 @@ public: _internal_vbox.show (); - drag_dest_set (_targets); + drag_dest_set (_targets, Gtk::DEST_DEFAULT_ALL, _actions); signal_drag_data_received().connect (mem_fun (*this, &DnDVBox::drag_data_received)); } @@ -100,9 +101,9 @@ public: void add_child (T* child, std::list targets = std::list()) { if (targets.empty ()) { - child->action_widget().drag_source_set (_targets); + child->action_widget().drag_source_set (_targets, Gdk::MODIFIER_MASK, _actions); } else { - child->action_widget().drag_source_set (targets); + child->action_widget().drag_source_set (targets, Gdk::MODIFIER_MASK, _actions); } child->action_widget().signal_drag_begin().connect (sigc::bind (mem_fun (*this, &DnDVBox::drag_begin), child)); child->action_widget().signal_drag_data_get().connect (sigc::bind (mem_fun (*this, &DnDVBox::drag_data_get), child)); @@ -255,6 +256,8 @@ public: sigc::signal SelectionChanged; sigc::signal SelectionAdded; + sigc::signal DragRefuse; + private: /** @return the bottom y position of a child, pretending any placeholder @@ -478,6 +481,13 @@ private: bool top_half = (c - int (c)) < .5; bool bottom_half = !top_half; + if (_drag_source != this) { + if (DragRefuse (_drag_source, at)) { + ctx->drag_refuse (tme); + return true; + } + } + if (_drag_source != this /* re-order */ && _drag_source && at && _drag_source->_drag_child @@ -512,7 +522,7 @@ private: if (_drag_source == this /* re-order */) { ctx->drag_status (Gdk::ACTION_MOVE, tme); } else { - ctx->drag_status (Gdk::ACTION_COPY, tme); + ctx->drag_status (ctx->get_suggested_action (), tme); } } else { ctx->drag_status (Gdk::ACTION_LINK, tme); @@ -664,6 +674,7 @@ private: Gtk::VBox _internal_vbox; std::list _targets; + Gdk::DragAction _actions; std::list _children; std::list _selection; T* _active;