13
0

extend Drag/Drop mechanism

DnDVbox: un-hardcode TargetEntry list, add callback for secondary targets
DvDTreeview: return pointer to self
This commit is contained in:
Robin Gareus 2015-12-22 04:14:12 +01:00
parent b67892833b
commit 2a55e8b9b3
2 changed files with 18 additions and 8 deletions

View File

@ -104,12 +104,11 @@ class /*LIBGTKMM2EXT_API*/ DnDTreeView : public DnDTreeViewBase
} else if (selection_data.get_target() == object_type) {
/* we don't care about the data passed around by DnD, but
we have to provide something otherwise it will stop.
/* return a pointer to this object, which allows
* the receiver to call on_drag_data_received()
*/
guchar c;
selection_data.set (8, (guchar*)&c, 1);
void *c = this;
selection_data.set (8, (guchar*)&c, sizeof(void*));
}
}
@ -142,7 +141,7 @@ class /*LIBGTKMM2EXT_API*/ DnDTreeView : public DnDTreeViewBase
* object that wants to get the list of dragged items.
*/
void get_object_drag_data (std::list<DataType>& l, Gtk::TreeView** source) {
void get_object_drag_data (std::list<DataType>& l, Gtk::TreeView** source) const {
if (drag_data.source == 0) {
return;

View File

@ -51,9 +51,13 @@ template <class T>
class /*LIBGTKMM2EXT_API*/ DnDVBox : public Gtk::EventBox
{
public:
DnDVBox () : _active (0), _drag_icon (0), _expecting_unwanted_button_event (false), _placeholder (0)
DnDVBox (std::list<Gtk::TargetEntry> targets)
: _targets (targets)
, _active (0)
, _drag_icon (0)
, _expecting_unwanted_button_event (false)
, _placeholder (0)
{
_targets.push_back (Gtk::TargetEntry ("processor"));
add (_internal_vbox);
add_events (
@ -220,6 +224,7 @@ public:
* Parameters are the source DnDVBox, our child which the other one was dropped on (or 0) and the DragContext.
*/
sigc::signal<void, DnDVBox*, T*, Glib::RefPtr<Gdk::DragContext> const & > DropFromAnotherBox;
sigc::signal<void, Gtk::SelectionData const &, T*, Glib::RefPtr<Gdk::DragContext> const & > DropFromExternal;
sigc::signal<void> SelectionChanged;
private:
@ -352,6 +357,12 @@ private:
/* work out where it was dropped */
std::pair<T*, double> const drop = get_child_at_position (y);
if (selection_data.get_target () != _targets.front ().get_target ()) {
DropFromExternal (selection_data, drop.first, context);
context->drag_finish (false, false, time);
return;
}
if (_drag_source == this) {
/* dropped from ourselves onto ourselves */