3 #include <gtkmm2ext/dndtreeview.h>
10 using namespace Gtkmm2ext;
12 DnDTreeView::DnDTreeView ()
15 draggable.push_back (TargetEntry ("GTK_TREE_MODEL_ROW", TARGET_SAME_WIDGET));
17 enable_model_drag_source (draggable);
18 enable_model_drag_dest (draggable);
20 suggested_action = Gdk::DragAction (0);
24 DnDTreeView::add_object_drag (int column, string type_name)
26 draggable.push_back (TargetEntry (type_name, TargetFlags(0)));
29 enable_model_drag_source (draggable);
30 enable_model_drag_dest (draggable);
33 DnDTreeView::SerializedObjectPointers*
34 DnDTreeView::serialize_pointers (RefPtr<TreeModel> model, TreeSelection::ListHandle_Path* selection, ustring type)
36 uint32_t cnt = selection->size();
37 uint32_t sz = (sizeof (void*) * cnt) + sizeof (SerializedObjectPointers);
39 char* buf = new char[sz];
40 SerializedObjectPointers* sr = new (buf) SerializedObjectPointers;
45 snprintf (sr->type, sizeof (sr->type), "%s", type.c_str());
49 for (TreeSelection::ListHandle_Path::iterator x = selection->begin(); x != selection->end(); ++x, ++cnt) {
50 TreeModel::Row row = *(model->get_iter (*x));
51 row.get_value (data_column, sr->ptr[cnt]);
58 DnDTreeView::on_drag_data_get(const RefPtr<DragContext>& context, SelectionData& selection_data, guint info, guint time)
60 if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
62 TreeView::on_drag_data_get (context, selection_data, info, time);
66 Gtk::TreeSelection::ListHandle_Path selection = get_selection()->get_selected_rows ();
67 SerializedObjectPointers* sr = serialize_pointers (get_model(), &selection, selection_data.get_target());
68 selection_data.set (8, (guchar*)sr, sr->size);
74 DnDTreeView::on_drag_data_received(const RefPtr<DragContext>& context, int x, int y, const SelectionData& selection_data, guint info, guint time)
76 if (suggested_action) {
77 /* this is a drag motion callback. just update the status to
78 say that we are still dragging, and that's it.
80 suggested_action = Gdk::DragAction (0);
81 TreeView::on_drag_data_received (context, x, y, selection_data, info, time);
85 if (selection_data.get_target() == "GTK_TREE_MODEL_ROW") {
87 TreeView::on_drag_data_received (context, x, y, selection_data, info, time);
92 const SerializedObjectPointers* sr = reinterpret_cast<const SerializedObjectPointers *>(selection_data.get_data());
95 signal_object_drop (sr->type, sr->cnt, const_cast<void**>(sr->ptr));
98 context->drag_finish (true, false, time);