1 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #include <gtkmm/treepath.h>
4 #include <gtkmm/private/treepath_p.h>
9 /* Copyright 1998-2002 The gtkmm Development Team
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <gtkmm/treemodel.h>
27 #include <glibmm/utility.h>
28 #include <gtk/gtktreemodel.h>
29 #include <gtk/gtktreednd.h>
35 TreePath::TreePath(TreePath::size_type n, TreePath::value_type value)
37 gobject_ (gtk_tree_path_new())
40 gtk_tree_path_append_index(gobject_, value);
43 TreePath::TreePath(const Glib::ustring& path)
45 gobject_ (gtk_tree_path_new_from_string(path.c_str()))
48 TreePath::TreePath(const TreeModel::iterator& iter)
50 // The GtkTreePath* is always newly created.
51 gobject_ (gtk_tree_model_get_path(iter.get_model_gobject(), const_cast<GtkTreeIter*>(iter.gobj())))
54 TreePath& TreePath::operator=(const TreeModel::iterator& iter)
61 void TreePath::clear()
67 TreePath::size_type TreePath::size() const
69 return gtk_tree_path_get_depth(gobject_);
72 bool TreePath::empty() const
74 return (gtk_tree_path_get_depth(gobject_) == 0);
77 TreePath::reference TreePath::operator[](TreePath::size_type i)
79 int *const indices = gtk_tree_path_get_indices(gobject_);
83 TreePath::const_reference TreePath::operator[](TreePath::size_type i) const
85 const int *const indices = gtk_tree_path_get_indices(gobject_);
89 TreePath::iterator TreePath::begin()
91 return gtk_tree_path_get_indices(gobject_);
94 TreePath::iterator TreePath::end()
96 return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
99 TreePath::const_iterator TreePath::begin() const
101 return gtk_tree_path_get_indices(gobject_);
104 TreePath::const_iterator TreePath::end() const
106 return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
109 bool TreePath::get_from_selection_data(const SelectionData& selection_data, Glib::RefPtr<TreeModel>& model, TreePath& path) //static
111 GtkTreeModel* src_model = 0;
112 GtkTreePath* src_path = 0;
113 gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), &src_model, &src_path);
115 model = Glib::wrap(src_model, true /* take_copy=true */);
117 //gtk_tree_get_row_drag_data gives us ownership of src_path.
118 path = Glib::wrap(src_path, false /* take_copy=false */);
123 bool TreePath::get_from_selection_data(const SelectionData& selection_data, TreePath& path) //static
125 GtkTreePath* src_path = 0;
126 gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), 0, &src_path);
128 //gtk_tree_get_row_drag_data gives us ownership of src_path.
129 path = Glib::wrap(src_path, false /* take_copy=false */);
135 bool TreePath::set_in_selection_data(SelectionData& selection_data, const Glib::RefPtr<const TreeModel>& model) const
137 return gtk_tree_set_row_drag_data(selection_data.gobj(), const_cast<GtkTreeModel*>(model->gobj()), const_cast<GtkTreePath*>(gobj()));
141 Glib::ArrayHandle<int> TreePath::get_indices() const
143 // gtk_tree_path_get_indices() returns a pointer to an internal array,
144 // similar to std::string::data(). Thus the OWNERSHIP_NONE flag.
146 return Glib::ArrayHandle<int>(gtk_tree_path_get_indices(gobject_),
147 gtk_tree_path_get_depth(gobject_),
148 Glib::OWNERSHIP_NONE);
156 } // anonymous namespace
162 Gtk::TreePath wrap(GtkTreePath* object, bool take_copy)
164 return Gtk::TreePath(object, take_copy);
175 GType TreePath::get_type()
177 return gtk_tree_path_get_type();
182 gobject_ (gtk_tree_path_new())
185 TreePath::TreePath(const TreePath& other)
187 gobject_ ((other.gobject_) ? gtk_tree_path_copy(other.gobject_) : 0)
190 TreePath::TreePath(GtkTreePath* gobject, bool make_a_copy)
192 // For BoxedType wrappers, make_a_copy is true by default. The static
193 // BoxedType wrappers must always take a copy, thus make_a_copy = true
194 // ensures identical behaviour if the default argument is used.
195 gobject_ ((make_a_copy && gobject) ? gtk_tree_path_copy(gobject) : gobject)
198 TreePath& TreePath::operator=(const TreePath& other)
200 TreePath temp (other);
205 TreePath::~TreePath()
208 gtk_tree_path_free(gobject_);
211 void TreePath::swap(TreePath& other)
213 GtkTreePath *const temp = gobject_;
214 gobject_ = other.gobject_;
215 other.gobject_ = temp;
218 GtkTreePath* TreePath::gobj_copy() const
220 return gtk_tree_path_copy(gobject_);
224 void TreePath::push_back(int index)
226 gtk_tree_path_append_index(gobj(), index);
229 void TreePath::push_front(int index)
231 gtk_tree_path_prepend_index(gobj(), index);
234 void TreePath::next()
236 gtk_tree_path_next(gobj());
239 bool TreePath::prev()
241 return gtk_tree_path_prev(gobj());
246 return gtk_tree_path_up(gobj());
249 void TreePath::down()
251 gtk_tree_path_down(gobj());
254 bool TreePath::is_ancestor(const TreePath& descendant) const
256 return gtk_tree_path_is_ancestor(const_cast<GtkTreePath*>(gobj()), const_cast<GtkTreePath*>((descendant).gobj()));
259 bool TreePath::is_descendant(const TreePath& ancestor) const
261 return gtk_tree_path_is_descendant(const_cast<GtkTreePath*>(gobj()), const_cast<GtkTreePath*>((ancestor).gobj()));
264 Glib::ustring TreePath::to_string() const
266 return Glib::convert_return_gchar_ptr_to_ustring(gtk_tree_path_to_string(const_cast<GtkTreePath*>(gobj())));
270 bool operator==(const TreePath& lhs, const TreePath& rhs)
272 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) == 0);
275 bool operator!=(const TreePath& lhs, const TreePath& rhs)
277 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) != 0);
280 bool operator<(const TreePath& lhs, const TreePath& rhs)
282 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) < 0);
285 bool operator>(const TreePath& lhs, const TreePath& rhs)
287 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) > 0);
290 bool operator<=(const TreePath& lhs, const TreePath& rhs)
292 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) <= 0);
295 bool operator>=(const TreePath& lhs, const TreePath& rhs)
297 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) >= 0);
301 void TreePath::append_index(int index)
303 gtk_tree_path_append_index(gobj(), index);
306 void TreePath::prepend_index(int index)
308 gtk_tree_path_prepend_index(gobj(), index);
311 int TreePath::get_depth() const
313 return gtk_tree_path_get_depth(const_cast<GtkTreePath*>(gobj()));