1 // Generated by gtkmmproc -- DO NOT MODIFY!
4 #include <gtkmm/treepath.h>
5 #include <gtkmm/private/treepath_p.h>
10 /* Copyright 1998-2002 The gtkmm Development Team
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <gtkmm/treemodel.h>
28 #include <glibmm/utility.h>
29 #include <gtk/gtktreemodel.h>
30 #include <gtk/gtktreednd.h>
36 TreePath::TreePath(TreePath::size_type n, TreePath::value_type value)
38 gobject_ (gtk_tree_path_new())
41 gtk_tree_path_append_index(gobject_, value);
44 TreePath::TreePath(const Glib::ustring& path)
46 gobject_ (gtk_tree_path_new_from_string(path.c_str()))
49 TreePath::TreePath(const TreeModel::iterator& iter)
51 // The GtkTreePath* is always newly created.
52 gobject_ (gtk_tree_model_get_path(iter.get_model_gobject(), const_cast<GtkTreeIter*>(iter.gobj())))
55 TreePath& TreePath::operator=(const TreeModel::iterator& iter)
62 void TreePath::clear()
68 TreePath::size_type TreePath::size() const
70 return gtk_tree_path_get_depth(gobject_);
73 bool TreePath::empty() const
75 return (gtk_tree_path_get_depth(gobject_) == 0);
78 TreePath::reference TreePath::operator[](TreePath::size_type i)
80 int *const indices = gtk_tree_path_get_indices(gobject_);
84 TreePath::const_reference TreePath::operator[](TreePath::size_type i) const
86 const int *const indices = gtk_tree_path_get_indices(gobject_);
90 TreePath::iterator TreePath::begin()
92 return gtk_tree_path_get_indices(gobject_);
95 TreePath::iterator TreePath::end()
97 return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
100 TreePath::const_iterator TreePath::begin() const
102 return gtk_tree_path_get_indices(gobject_);
105 TreePath::const_iterator TreePath::end() const
107 return gtk_tree_path_get_indices(gobject_) + gtk_tree_path_get_depth(gobject_);
110 bool TreePath::get_from_selection_data(const SelectionData& selection_data, Glib::RefPtr<TreeModel>& model, TreePath& path) //static
112 GtkTreeModel* src_model = 0;
113 GtkTreePath* src_path = 0;
114 gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), &src_model, &src_path);
116 model = Glib::wrap(src_model, true /* take_copy=true */);
118 //gtk_tree_get_row_drag_data gives us ownership of src_path.
119 path = Glib::wrap(src_path, false /* take_copy=false */);
124 bool TreePath::get_from_selection_data(const SelectionData& selection_data, TreePath& path) //static
126 GtkTreePath* src_path = 0;
127 gboolean result = gtk_tree_get_row_drag_data(const_cast<GtkSelectionData*>(selection_data.gobj()), 0, &src_path);
129 //gtk_tree_get_row_drag_data gives us ownership of src_path.
130 path = Glib::wrap(src_path, false /* take_copy=false */);
136 bool TreePath::set_in_selection_data(SelectionData& selection_data, const Glib::RefPtr<const TreeModel>& model) const
138 return gtk_tree_set_row_drag_data(selection_data.gobj(), const_cast<GtkTreeModel*>(model->gobj()), const_cast<GtkTreePath*>(gobj()));
141 #ifndef GTKMM_DISABLE_DEPRECATED
143 Glib::ArrayHandle<int> TreePath::get_indices() const
145 // gtk_tree_path_get_indices() returns a pointer to an internal array,
146 // similar to std::string::data(). Thus the OWNERSHIP_NONE flag.
148 return Glib::ArrayHandle<int>(gtk_tree_path_get_indices(gobject_),
149 gtk_tree_path_get_depth(gobject_),
150 Glib::OWNERSHIP_NONE);
152 #endif // GTKMM_DISABLE_DEPRECATED
160 } // anonymous namespace
166 Gtk::TreePath wrap(GtkTreePath* object, bool take_copy)
168 return Gtk::TreePath(object, take_copy);
179 GType TreePath::get_type()
181 return gtk_tree_path_get_type();
186 gobject_ (gtk_tree_path_new())
189 TreePath::TreePath(const TreePath& other)
191 gobject_ ((other.gobject_) ? gtk_tree_path_copy(other.gobject_) : 0)
194 TreePath::TreePath(GtkTreePath* gobject, bool make_a_copy)
196 // For BoxedType wrappers, make_a_copy is true by default. The static
197 // BoxedType wrappers must always take a copy, thus make_a_copy = true
198 // ensures identical behaviour if the default argument is used.
199 gobject_ ((make_a_copy && gobject) ? gtk_tree_path_copy(gobject) : gobject)
202 TreePath& TreePath::operator=(const TreePath& other)
204 TreePath temp (other);
209 TreePath::~TreePath()
212 gtk_tree_path_free(gobject_);
215 void TreePath::swap(TreePath& other)
217 GtkTreePath *const temp = gobject_;
218 gobject_ = other.gobject_;
219 other.gobject_ = temp;
222 GtkTreePath* TreePath::gobj_copy() const
224 return gtk_tree_path_copy(gobject_);
228 void TreePath::push_back(int index)
230 gtk_tree_path_append_index(gobj(), index);
233 void TreePath::push_front(int index)
235 gtk_tree_path_prepend_index(gobj(), index);
238 void TreePath::next()
240 gtk_tree_path_next(gobj());
243 bool TreePath::prev()
245 return gtk_tree_path_prev(gobj());
250 return gtk_tree_path_up(gobj());
253 void TreePath::down()
255 gtk_tree_path_down(gobj());
258 bool TreePath::is_ancestor(const TreePath& descendant) const
260 return gtk_tree_path_is_ancestor(const_cast<GtkTreePath*>(gobj()), const_cast<GtkTreePath*>((descendant).gobj()));
263 bool TreePath::is_descendant(const TreePath& ancestor) const
265 return gtk_tree_path_is_descendant(const_cast<GtkTreePath*>(gobj()), const_cast<GtkTreePath*>((ancestor).gobj()));
268 Glib::ustring TreePath::to_string() const
270 return Glib::convert_return_gchar_ptr_to_ustring(gtk_tree_path_to_string(const_cast<GtkTreePath*>(gobj())));
274 bool operator==(const TreePath& lhs, const TreePath& rhs)
276 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) == 0);
279 bool operator!=(const TreePath& lhs, const TreePath& rhs)
281 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) != 0);
284 bool operator<(const TreePath& lhs, const TreePath& rhs)
286 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) < 0);
289 bool operator>(const TreePath& lhs, const TreePath& rhs)
291 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) > 0);
294 bool operator<=(const TreePath& lhs, const TreePath& rhs)
296 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) <= 0);
299 bool operator>=(const TreePath& lhs, const TreePath& rhs)
301 return (gtk_tree_path_compare(lhs.gobj(), rhs.gobj()) >= 0);
305 #ifndef GTKMM_DISABLE_DEPRECATED
307 void TreePath::append_index(int index)
309 gtk_tree_path_append_index(gobj(), index);
312 #endif // GTKMM_DISABLE_DEPRECATED
314 #ifndef GTKMM_DISABLE_DEPRECATED
316 void TreePath::prepend_index(int index)
318 gtk_tree_path_prepend_index(gobj(), index);
321 #endif // GTKMM_DISABLE_DEPRECATED
323 #ifndef GTKMM_DISABLE_DEPRECATED
325 int TreePath::get_depth() const
327 return gtk_tree_path_get_depth(const_cast<GtkTreePath*>(gobj()));
330 #endif // GTKMM_DISABLE_DEPRECATED