Gtk::TreeView
already implments simple drag-and-drop when used with the Gtk::ListStore
or Gtk::TreeStore
models. If necessary, it also allows you to implement more complex behaviour when items are dragged and dropped, using the normal Drag and Drop API.
If you call Gtk::TreeView::set_reorderable()
then your TreeView's items can be moved within the treeview itself. This is demonstrated in the TreeStore
example.
However, this does not allow you any control of which items can be dragged, and where they can be dropped. If you need that extra control then you might create a derived Gtk::TreeModel
from Gtk::TreeStore
or Gtk::ListStore
and override the Gtk::TreeDragSource::row_draggable()
and Gdk::TreeDragDest::row_drop_possible()
virtual methods. You can examine the Gtk::TreeModel::Path
s provided and allow or disallow dragging or dropping by return true
or false
.
This is demonstrated in the drag_and_drop example.