+ std::string object_type;
+
+ double press_start_x;
+ double press_start_y;
+ int _drag_column;
+
+ struct DragData {
+ DragData () : source (0) {}
+
+ Gtk::TreeView* source;
+ int data_column;
+ std::string object_type;
+ };
+
+ static DragData drag_data;
+
+ void start_object_drag () {
+ drag_data.source = this;
+ drag_data.data_column = data_column;
+ drag_data.object_type = object_type;
+ }
+
+ void end_object_drag () {
+ drag_data.source = 0;
+ drag_data.data_column = -1;
+ drag_data.object_type = "";
+ }
+};
+
+template<class DataType>
+class /*LIBGTKMM2EXT_API*/ DnDTreeView : public DnDTreeViewBase
+{
+ public:
+ DnDTreeView() {}
+ ~DnDTreeView() {}
+
+ sigc::signal<void, const Glib::RefPtr<Gdk::DragContext>&, const Gtk::SelectionData&> signal_drop;
+
+ void on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time) {
+ if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
+
+ TreeView::on_drag_data_get (context, selection_data, info, time);
+
+ } else if (selection_data.get_target() == object_type) {
+
+ /* return a pointer to this object, which allows
+ * the receiver to call on_drag_data_received()
+ */
+ void *c = this;
+ selection_data.set (8, (guchar*)&c, sizeof(void*));
+ }
+ }
+
+ void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& selection_data, guint info, guint time) {
+ if (suggested_action) {
+ /* this is a drag motion callback. just update the status to
+ say that we are still dragging, and that's it.
+ */
+ suggested_action = Gdk::DragAction (0);
+ TreeView::on_drag_data_received (context, x, y, selection_data, info, time);
+ return;
+ }
+
+ if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
+ TreeView::on_drag_data_received (context, x, y, selection_data, info, time);
+ } else {
+ /* some kind of target type, usually 'object_type' added by the app,
+ * which will be handled by a signal handler */
+ for (std::list<Gtk::TargetEntry>::const_iterator i = draggable.begin(); i != draggable.end (); ++i) {
+ if (selection_data.get_target() == (*i).get_target()) {
+ signal_drop (context, selection_data);
+ context->drag_finish (true, false, time);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * This can be called by the Treeview itself or by some other
+ * object that wants to get the list of dragged items.
+ */
+
+ void get_object_drag_data (std::list<DataType>& l, Gtk::TreeView** source) const {
+
+ if (drag_data.source == 0) {
+ return;
+ }
+
+ Glib::RefPtr<Gtk::TreeModel> model = drag_data.source->get_model();
+ DataType v;
+ Gtk::TreeSelection::ListHandle_Path selection = drag_data.source->get_selection()->get_selected_rows ();
+
+ for (Gtk::TreeSelection::ListHandle_Path::iterator x = selection.begin(); x != selection.end(); ++x) {
+ model->get_iter (*x)->get_value (drag_data.data_column, v);
+ l.push_back (v);
+ }
+
+ *source = drag_data.source;
+ }