2 /* $Id: treepath.ccg,v 1.5 2005/11/29 16:38:10 murrayc Exp $ */
4 /* Copyright 1998-2002 The gtkmm Development Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gtkmm/treemodel.h>
22 #include <glibmm/utility.h>
23 #include <gtk/gtktreemodel.h>
24 #include <gtk/gtktreednd.h>
30 TreePath::TreePath(TreePath::size_type n, TreePath::value_type value)
32 gobject_ (gtk_tree_path_new())
35 gtk_tree_path_append_index(gobject_, value);
38 TreePath::TreePath(const Glib::ustring& path)
40 gobject_ (gtk_tree_path_new_from_string(path.c_str()))
43 TreePath::TreePath(const TreeModel::iterator& iter)
45 // The GtkTreePath* is always newly created.
46 gobject_ (gtk_tree_model_get_path(iter.get_model_gobject(), const_cast<GtkTreeIter*>(iter.gobj())))
49 TreePath& TreePath::operator=(const TreeModel::iterator& iter)
56 void TreePath::clear()
62 TreePath::size_type TreePath::size() const
64 return gtk_tree_path_get_depth(gobject_);
67 bool TreePath::empty() const
69 return (gtk_tree_path_get_depth(gobject_) == 0);
72 TreePath::reference TreePath::operator[](TreePath::size_type i)
74 int *const indices = gtk_tree_path_get_indices(gobject_);
78 TreePath::const_reference TreePath::operator[](TreePath::size_type i) const
80 const int *const indices = gtk_tree_path_get_indices(gobject_);
84 TreePath::iterator TreePath::begin()
86 return gtk_tree_path_get_indices(gobject_);
89 TreePath::iterator TreePath::end()
91 return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
94 TreePath::const_iterator TreePath::begin() const
96 return gtk_tree_path_get_indices(gobject_);
99 TreePath::const_iterator TreePath::end() const
101 return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
104 bool TreePath::get_from_selection_data(const SelectionData& selection_data, Glib::RefPtr<TreeModel>& model, TreePath& path) //static
106 GtkTreeModel* src_model = 0;
107 GtkTreePath* src_path = 0;
108 gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), &src_model, &src_path);
110 model = Glib::wrap(src_model, true /* take_copy=true */);
112 //gtk_tree_get_row_drag_data gives us ownership of src_path.
113 path = Glib::wrap(src_path, false /* take_copy=false */);
118 bool TreePath::get_from_selection_data(const SelectionData& selection_data, TreePath& path) //static
120 GtkTreePath* src_path = 0;
121 gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), 0, &src_path);
123 //gtk_tree_get_row_drag_data gives us ownership of src_path.
124 path = Glib::wrap(src_path, false /* take_copy=false */);
130 bool TreePath::set_in_selection_data(SelectionData& selection_data, const Glib::RefPtr<const TreeModel>& model) const
132 return gtk_tree_set_row_drag_data(selection_data.gobj(), const_cast<GtkTreeModel*>(model->gobj()), const_cast<GtkTreePath*>(gobj()));
135 _DEPRECATE_IFDEF_START
136 Glib::ArrayHandle<int> TreePath::get_indices() const
138 // gtk_tree_path_get_indices() returns a pointer to an internal array,
139 // similar to std::string::data(). Thus the OWNERSHIP_NONE flag.
141 return Glib::ArrayHandle<int>(gtk_tree_path_get_indices(gobject_),
142 gtk_tree_path_get_depth(gobject_),
143 Glib::OWNERSHIP_NONE);