X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fgtkmm2ext%2Fdndtreeview.cc;h=2c2e69f6b68e8b712ed1be9f50fdb57def0c1554;hb=c6c9bfda4910e4b1c80161e2b3af622e8b23283f;hp=83955861cfec9e1364a66e64a0bd743e9f31b274;hpb=ea6de825fae8083176a718939546cb4e2b2b508e;p=ardour.git diff --git a/libs/gtkmm2ext/dndtreeview.cc b/libs/gtkmm2ext/dndtreeview.cc index 83955861cf..2c2e69f6b6 100644 --- a/libs/gtkmm2ext/dndtreeview.cc +++ b/libs/gtkmm2ext/dndtreeview.cc @@ -1,3 +1,22 @@ +/* + Copyright (C) 2000-2007 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #include #include @@ -10,7 +29,7 @@ using namespace Gtk; using namespace Glib; using namespace Gtkmm2ext; -DnDTreeView::DnDTreeView () +DnDTreeViewBase::DnDTreeViewBase () : TreeView () { draggable.push_back (TargetEntry ("GTK_TREE_MODEL_ROW", TARGET_SAME_WIDGET)); @@ -23,7 +42,7 @@ DnDTreeView::DnDTreeView () } void -DnDTreeView::add_drop_targets (list& targets) +DnDTreeViewBase::add_drop_targets (list& targets) { for (list::iterator i = targets.begin(); i != targets.end(); ++i) { draggable.push_back (*i); @@ -33,7 +52,7 @@ DnDTreeView::add_drop_targets (list& targets) } void -DnDTreeView::add_object_drag (int column, string type_name) +DnDTreeViewBase::add_object_drag (int column, string type_name) { draggable.push_back (TargetEntry (type_name, TargetFlags(0))); data_column = column; @@ -42,86 +61,11 @@ DnDTreeView::add_object_drag (int column, string type_name) enable_model_drag_dest (draggable); } -DnDTreeView::SerializedObjectPointers* -DnDTreeView::serialize_pointers (RefPtr model, TreeSelection::ListHandle_Path* selection, ustring type) -{ - uint32_t cnt = selection->size(); - uint32_t sz = (sizeof (void*) * cnt) + sizeof (SerializedObjectPointers); - - cerr << "lets plan to serialize " << cnt << " from selection\n"; - - char* buf = new char[sz]; - SerializedObjectPointers* sr = new (buf) SerializedObjectPointers; - - sr->cnt = cnt; - sr->size = sz; - - snprintf (sr->type, sizeof (sr->type), "%s", type.c_str()); - - cnt = 0; - - for (TreeSelection::ListHandle_Path::iterator x = selection->begin(); x != selection->end(); ++x, ++cnt) { - cerr << "getting next item\n"; - TreeModel::Row row = *(model->get_iter (*x)); - row.get_value (data_column, sr->ptr[cnt]); - } - - cerr << "returning an SR with size = " << sr->size << endl; - return sr; -} - -void -DnDTreeView::on_drag_data_get(const RefPtr& context, 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 (data_column >= 0) { - - Gtk::TreeSelection::ListHandle_Path selection = get_selection()->get_selected_rows (); - SerializedObjectPointers* sr = serialize_pointers (get_model(), &selection, selection_data.get_target()); - selection_data.set (8, (guchar*)sr, sr->size); - - cerr << "selection data set to contain " << sr->size << endl; - } -} - -void -DnDTreeView::on_drag_data_received(const RefPtr& context, int x, int y, const 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 if (data_column >= 0) { - - /* object D-n-D */ - - const SerializedObjectPointers* sr = reinterpret_cast(selection_data.get_data()); - - if (sr) { - signal_object_drop (sr->type, sr->cnt, const_cast(sr->ptr)); - } - - } else { - /* some kind of target type added by the app, which will be handled by a signal handler */ - } -} - bool -DnDTreeView::on_drag_drop(const Glib::RefPtr& context, int x, int y, guint time) +DnDTreeViewBase::on_drag_drop(const Glib::RefPtr& context, int x, int y, guint time) { suggested_action = Gdk::DragAction (0); return TreeView::on_drag_drop (context, x, y, time); } +