2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GTKMM_TREEPATH_H
4 #define _GTKMM_TREEPATH_H
10 /* Copyright(C) 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.
28 #include <gtkmm/treemodel.h>
29 #include <gtkmm/selectiondata.h>
30 #include <gtkmmconfig.h>
32 GLIBMM_USING_STD(random_access_iterator_tag)
33 GLIBMM_USING_STD(reverse_iterator)
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 extern "C" { typedef struct _GtkTreePath GtkTreePath; }
43 /** A path is essentially a potential node. It is a location on a model that may
44 * or may not actually correspond to a node on a specific model.
46 * A Path can be converted into either an array of unsigned integers or a string. The string
47 * form is a list of numbers separated by a colon. Each number refers to the
48 * offset at that level. Thus, the path "0" refers to the root node and the
49 * path "2:4" refers to the fifth child of the third node.
51 * Typedefed as Gtk::TreeModel::Path.
57 #ifndef DOXYGEN_SHOULD_SKIP_THIS
58 typedef TreePath CppObjectType;
59 typedef GtkTreePath BaseObjectType;
61 static GType get_type() G_GNUC_CONST;
62 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
66 explicit TreePath(GtkTreePath* gobject, bool make_a_copy = true);
68 TreePath(const TreePath& other);
69 TreePath& operator=(const TreePath& other);
73 void swap(TreePath& other);
75 ///Provides access to the underlying C instance.
76 GtkTreePath* gobj() { return gobject_; }
78 ///Provides access to the underlying C instance.
79 const GtkTreePath* gobj() const { return gobject_; }
81 ///Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.
82 GtkTreePath* gobj_copy() const;
85 GtkTreePath* gobject_;
91 typedef unsigned int size_type;
92 typedef int difference_type;
94 typedef int value_type;
95 typedef int& reference;
96 typedef const int& const_reference;
98 // Use plain pointers for simplicity.
99 typedef int* iterator;
100 typedef const int* const_iterator;
102 #ifndef GLIBMM_HAVE_SUN_REVERSE_ITERATOR
104 typedef std::reverse_iterator<iterator> reverse_iterator;
105 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
109 typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
110 int, int&, int*, ptrdiff_t> reverse_iterator;
112 typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
113 int, const int&, const int*, ptrdiff_t> const_reverse_iterator;
115 #endif /* GLIBMM_HAVE_SUN_REVERSE_ITERATOR */
117 explicit TreePath(size_type n, value_type value = 0);
118 explicit TreePath(const Glib::ustring& path);
119 explicit TreePath(const TreeModel::iterator& iter);
121 template <class In> inline TreePath(In pbegin, In pend);
125 // I think it's OK for this assignment to be implicit. It's very useful.
126 TreePath& operator=(const TreeModel::iterator& iter);
128 template <class In> inline void assign(In pbegin, In pend);
129 template <class In> void append(In pbegin, In pend);
132 /** Appends a new index to a path. As a result, the depth of the path is
134 * @param index The index.
136 void push_back(int index);
138 /** Prepends a new index to a path. As a result, the depth of the path is
140 * @param index The index.
142 void push_front(int index);
144 size_type size() const;
147 reference operator[](size_type i);
148 const_reference operator[](size_type i) const;
152 const_iterator begin() const;
153 const_iterator end() const;
155 // Note: there is no advantage in not inlining these methods.
156 // We can't change them without breaking ABI anyway.
157 reverse_iterator rbegin() { return reverse_iterator(end()); }
158 reverse_iterator rend() { return reverse_iterator(begin()); }
159 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
160 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
162 reference front() { return *begin(); }
163 const_reference front() const { return *begin(); }
164 reference back() { return *rbegin(); }
165 const_reference back() const { return *rbegin(); }
168 /** Moves the @a path to point to the next node at the current depth.
172 /** Moves the @a path to point to the previous node at the current depth, if it exists.
173 * @return <tt>true</tt> if @a path has a previous node, and the move was made.
177 /** Moves the @a path to point to its parent node, if it has a parent.
178 * @return <tt>true</tt> if @a path has a parent, and the move was made.
182 /** Moves @a path to point to the first child of the current path.
187 /** Returns <tt>true</tt> if @a descendant is a descendant of @a path .
188 * @param descendant Another Gtk::TreePath.
189 * @return <tt>true</tt> if @a descendant is contained inside @a path .
191 bool is_ancestor(const TreePath& descendant) const;
193 /** Returns <tt>true</tt> if @a path is a descendant of @a ancestor .
194 * @param ancestor Another Gtk::TreePath.
195 * @return <tt>true</tt> if @a ancestor contains @a path somewhere below it.
197 bool is_descendant(const TreePath& ancestor) const;
200 /** Generates a string representation of the path. This string is a ':'
201 * separated list of numbers. For example, "4:10:0:3" would be an acceptable return value for this string.
202 * @return The string.
204 Glib::ustring to_string() const;
207 #ifndef GTKMM_DISABLE_DEPRECATED
208 /// @deprecated replaced by push_back():
210 /** Appends a new index to a path. As a result, the depth of the path is
212 * @param index The index.
214 void append_index(int index);
215 /// @deprecated replaced by push_front():
217 /** Prepends a new index to a path. As a result, the depth of the path is
219 * @param index The index.
221 void prepend_index(int index);
222 /// @deprecated replaced by size():
224 /** Returns the current depth of @a path .
225 * @return The depth of @a path .
227 int get_depth() const;
229 /// @deprecated replaced by begin(), end(), and operator[]
230 Glib::ArrayHandle<int> get_indices() const;
235 * Obtains a Gtk::TreeModel and Gtk::TreeModel::Path from selection data of target type
236 * "GTK_TREE_MODEL_ROW". Normally called from a drag_data_received handler.
237 * This function can only be used if @a selection_data originates from the same
238 * process that's calling this function, because a pointer to the tree model
239 * is being passed around. If you aren't in the same process, then you'll
240 * get memory corruption. In the Gtk::TreeDragDest drag_data_received signal handler,
241 * you can assume that selection data of type "GTK_TREE_MODEL_ROW" is
242 * from the current process.
244 * @param selection_data a #SelectionData
245 * @param model a Gtk::TreeModel
246 * @param path a row in model
248 * @return true if the selection_data had target type "GTK_TREE_MODEL_ROW" and
251 static bool get_from_selection_data(const SelectionData& selection_data, Glib::RefPtr<TreeModel>& model, TreePath& path);
252 //TODO: Add an override that takes a const TreeModel (and deprecate the current version).
254 /// See description in the other overload.
255 static bool get_from_selection_data(const SelectionData& selection_data, TreePath& path);
258 * Sets selection data of target type "GTK_TREE_MODEL_ROW". Normally used
259 * in a drag_data_get signal handler.
261 * @param selection_data some #SelectionData
262 * @param model: a Gtk::TreeModel
264 * @return true if the selection_data had the proper target type to allow us to set a tree row
266 bool set_in_selection_data(SelectionData& selection_data, const Glib::RefPtr<const TreeModel>& model) const;
271 #ifndef DOXYGEN_SHOULD_SKIP_THIS
274 void TreePath::append(In pbegin, In pend)
276 // push_back() can't throw -- if it could, this code wouldn't be strongly exception-safe.
277 for(; pbegin != pend; ++pbegin)
278 this->push_back(*pbegin);
281 template <class In> inline
282 TreePath::TreePath(In pbegin, In pend)
284 this->append(pbegin, pend);
287 template <class In> inline
288 void TreePath::assign(In pbegin, In pend)
290 TreePath temp (pbegin, pend);
295 /* Traits for use of TreePath in a Glib::ListHandle<>.
297 struct TreePath_Traits
299 typedef TreePath CppType;
300 typedef const GtkTreePath* CType;
301 typedef GtkTreePath* CTypeNonConst;
303 static CType to_c_type(const CppType& item)
304 { return item.gobj(); }
306 static CType to_c_type(CType item)
309 static CppType to_cpp_type(CType item)
310 { return CppType(const_cast<CTypeNonConst>(item)); }
312 static void release_c_type(CType item)
313 { gtk_tree_path_free(const_cast<CTypeNonConst>(item)); }
316 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
325 /** @relates Gtk::TreePath
326 * @param lhs The left-hand side
327 * @param rhs The right-hand side
330 bool operator==(const TreePath& lhs, const TreePath& rhs);
332 /** @relates Gtk::TreePath
333 * @param lhs The left-hand side
334 * @param rhs The right-hand side
337 bool operator!=(const TreePath& lhs, const TreePath& rhs);
339 /** @relates Gtk::TreePath
340 * @param lhs The left-hand side
341 * @param rhs The right-hand side
344 bool operator<(const TreePath& lhs, const TreePath& rhs);
346 /** @relates Gtk::TreePath
347 * @param lhs The left-hand side
348 * @param rhs The right-hand side
351 bool operator>(const TreePath& lhs, const TreePath& rhs);
353 /** @relates Gtk::TreePath
354 * @param lhs The left-hand side
355 * @param rhs The right-hand side
358 bool operator<=(const TreePath& lhs, const TreePath& rhs);
360 /** @relates Gtk::TreePath
361 * @param lhs The left-hand side
362 * @param rhs The right-hand side
365 bool operator>=(const TreePath& lhs, const TreePath& rhs);
374 /** @relates Gtk::TreePath
375 * @param lhs The left-hand side
376 * @param rhs The right-hand side
378 inline void swap(TreePath& lhs, TreePath& rhs)
386 /** @relates Gtk::TreePath
387 * @param object The C instance
388 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
389 * @result A C++ instance that wraps this C instance.
391 Gtk::TreePath wrap(GtkTreePath* object, bool take_copy = false);
393 #ifndef DOXYGEN_SHOULD_SKIP_THIS
395 class Value<Gtk::TreePath> : public Glib::Value_Boxed<Gtk::TreePath>
397 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
401 #endif /* _GTKMM_TREEPATH_H */