2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GTKMM_TREEMODEL_H
4 #define _GTKMM_TREEMODEL_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.
27 #include <gtk/gtktreemodel.h>
28 #include <glibmm/interface.h>
29 #include <gtkmm/treeiter.h>
30 #include <gtkmm/treemodelcolumn.h>
33 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 typedef struct _GtkTreeModel GtkTreeModel;
35 typedef struct _GtkTreeModelClass GtkTreeModelClass;
36 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
40 { class TreeModel_Class; } // namespace Gtk
46 class TreeRowReference;
49 /** @addtogroup gtkmmEnums Enums and Flags */
53 * @par Bitwise operators:
54 * <tt>%TreeModelFlags operator|(TreeModelFlags, TreeModelFlags)</tt><br>
55 * <tt>%TreeModelFlags operator&(TreeModelFlags, TreeModelFlags)</tt><br>
56 * <tt>%TreeModelFlags operator^(TreeModelFlags, TreeModelFlags)</tt><br>
57 * <tt>%TreeModelFlags operator~(TreeModelFlags)</tt><br>
58 * <tt>%TreeModelFlags& operator|=(TreeModelFlags&, TreeModelFlags)</tt><br>
59 * <tt>%TreeModelFlags& operator&=(TreeModelFlags&, TreeModelFlags)</tt><br>
60 * <tt>%TreeModelFlags& operator^=(TreeModelFlags&, TreeModelFlags)</tt><br>
64 TREE_MODEL_ITERS_PERSIST = 1 << 0,
65 TREE_MODEL_LIST_ONLY = 1 << 1
68 /** @ingroup gtkmmEnums */
69 inline TreeModelFlags operator|(TreeModelFlags lhs, TreeModelFlags rhs)
70 { return static_cast<TreeModelFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
72 /** @ingroup gtkmmEnums */
73 inline TreeModelFlags operator&(TreeModelFlags lhs, TreeModelFlags rhs)
74 { return static_cast<TreeModelFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
76 /** @ingroup gtkmmEnums */
77 inline TreeModelFlags operator^(TreeModelFlags lhs, TreeModelFlags rhs)
78 { return static_cast<TreeModelFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
80 /** @ingroup gtkmmEnums */
81 inline TreeModelFlags operator~(TreeModelFlags flags)
82 { return static_cast<TreeModelFlags>(~static_cast<unsigned>(flags)); }
84 /** @ingroup gtkmmEnums */
85 inline TreeModelFlags& operator|=(TreeModelFlags& lhs, TreeModelFlags rhs)
86 { return (lhs = static_cast<TreeModelFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
88 /** @ingroup gtkmmEnums */
89 inline TreeModelFlags& operator&=(TreeModelFlags& lhs, TreeModelFlags rhs)
90 { return (lhs = static_cast<TreeModelFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
92 /** @ingroup gtkmmEnums */
93 inline TreeModelFlags& operator^=(TreeModelFlags& lhs, TreeModelFlags rhs)
94 { return (lhs = static_cast<TreeModelFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
99 #ifndef DOXYGEN_SHOULD_SKIP_THIS
104 class Value<Gtk::TreeModelFlags> : public Glib::Value_Flags<Gtk::TreeModelFlags>
107 static GType value_type() G_GNUC_CONST;
111 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
118 //TODO: Remove any mention of null arguments from the method documentation, by adding overrides in gtk_docs_override.xml.
119 /** This class defines a generic tree interface for use by the Gtk::TreeView widget.
122 * It is is designed to be usable with any appropriate data structure. The
123 * programmer just has to implement this interface on their own data type for
124 * it to be viewable by a Gtk::TreeView widget.
126 * The model is represented as a hierarchical tree of strongly-typed, columned
127 * data. In other words, the model can be seen as a tree where every node has
128 * different values depending on which column is being queried. The type of
129 * data found in a column is determined by TreeModel::Column<> templates.
130 * The types are homogeneous per column across all nodes. It is important to note that this
131 * interface only provides a way of examining a model and observing changes.
132 * The implementation of each individual model decides how and if changes are
135 * In order to make life simpler for programmers who do not need to write their
136 * own specialized model, two generic models are provided - the Gtk::TreeStore
137 * and the Gtk::ListStore. To use these, the developer simply pushes data into
138 * these models as necessary. These models provide the data structure as well
139 * as all appropriate tree interfaces. As a result, implementing drag and drop,
140 * sorting, and storing data is trivial. For the vast majority of trees and
141 * lists, these two models are sufficient.
143 * Models are accessed on a node/column level of granularity. One can query for
144 * the value of a model at a certain node and a certain column on that node.
145 * There are two structures used to reference a particular node in a model.
146 * They are the @link Gtk::TreePath Path@endlink and the iterator. Most of the interface consists of
147 * operations on an @link Gtk::TreeIter iterator@endlink.
149 * A @link Gtk::TreePath Gtk::TreeModel::Path@endlink is essentially a potential node. It is a location on a model that may
150 * or may not actually correspond to a node on a specific model.
152 * By contrast, an @link Gtk::TreeIter Gtk::TreeModel::iterator@endlink is a reference to a specific node on a specific
153 * model. One can convert a path to an @link Gtk::TreeIter iterator@endlink by calling Gtk::TreeModel::get_iter().
154 * These iterators are the primary way of accessing a model and are similar to the iterators
155 * used by Gtk::TextBuffer. The model interface defines a set of operations
156 * using them for navigating the model.
158 * The @link Gtk::TreeRowReference RowReference@endlink is also useful, because it remains
159 * valid as long as there is an existing row pointed to by it's path. You can convert between RowReferences and iterators and @link Gtk::TreePath Path@endlink s.
162 class TreeModel : public Glib::Interface
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS
168 typedef TreeModel CppObjectType;
169 typedef TreeModel_Class CppClassType;
170 typedef GtkTreeModel BaseObjectType;
171 typedef GtkTreeModelIface BaseClassType;
174 friend class TreeModel_Class;
175 static CppClassType treemodel_class_;
178 TreeModel(const TreeModel&);
179 TreeModel& operator=(const TreeModel&);
182 TreeModel(); // you must derive from this class
183 explicit TreeModel(GtkTreeModel* castitem);
185 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
188 virtual ~TreeModel();
190 static void add_interface(GType gtype_implementer);
192 #ifndef DOXYGEN_SHOULD_SKIP_THIS
193 static GType get_type() G_GNUC_CONST;
194 static GType get_base_type() G_GNUC_CONST;
197 ///Provides access to the underlying C GObject.
198 GtkTreeModel* gobj() { return reinterpret_cast<GtkTreeModel*>(gobject_); }
200 ///Provides access to the underlying C GObject.
201 const GtkTreeModel* gobj() const { return reinterpret_cast<GtkTreeModel*>(gobject_); }
207 typedef TreeModelColumnRecord ColumnRecord;
209 typedef TreeNodeChildren Children;
210 typedef Children::iterator iterator;
211 typedef Children::reverse_iterator reverse_iterator;
212 typedef Children::const_iterator const_iterator;
213 typedef Children::const_reverse_iterator const_reverse_iterator;
216 typedef TreePath Path;
217 typedef TreeRowReference RowReference;
220 //These are part of GtkTreeModelFilter or GtkTreeModelSort, not GtkTreeModel:
223 /** Returns a valid iterator pointing to @a path.
225 * @param path The @link Gtk::TreePath Gtk::TreeModel::Path@endlink.
226 * @result A valid iterator pointing to the path, or an invalid iterator if that is not possible.
228 iterator get_iter(const Path& path);
229 //TODO: Add const_iterator get_iter(const Path& path) const;
230 //Implement a const_iterator?
232 /** Returns a valid iterator pointing to @a path_string.
234 * @param path_string The path, as a string representation.
235 * @result A valid iterator pointing to the path, or an invalid iterator if that is not possible.
237 iterator get_iter(const Glib::ustring& path_string);
238 //TODO: Implement a const_iterator? const_iterator get_iter(const Glib::ustring& path_string) const;
240 ///This returns an STL-like container API, for iterating over the rows.
243 //TODO: Return a real TreeNodeChildren (a container of const_iterators), when we have a real const_iterator.
244 ///This returns an STL-like container API, for iterating over the rows.
245 Children children() const;
249 * void on_foreach(const Gtk::TreeModel::iterator& iter);
251 * If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
253 typedef sigc::slot<bool, const TreeModel::iterator&> SlotForeachIter;
255 /** Calls a callback slot on each node in the model in a depth-first fashion.
256 * If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
258 * @param slot The function to call for each selected node.
260 void foreach_iter(const SlotForeachIter& slot);
263 * void on_foreach(const Gtk::TreeModel::Path& path);
265 * If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
267 typedef sigc::slot<bool, const TreeModel::Path&> SlotForeachPath;
269 /** Calls a callback slot on each node in the model in a depth-first fashion.
270 * If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
272 * @param slot The function to call for each selected node.
274 void foreach_path(const SlotForeachPath& slot);
277 * void on_foreach(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter);
279 * If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
281 typedef sigc::slot<bool, const TreeModel::Path&, const TreeModel::iterator&> SlotForeachPathAndIter;
283 /** Calls a callback slot on each node in the model in a depth-first fashion.
284 * If the callback function returns true, then the tree ceases to be walked, and foreach() returns.
286 * @param slot The function to call for each selected node.
288 void foreach(const SlotForeachPathAndIter& slot);
291 /** Returns a set of flags supported by this interface. The flags are a bitwise
292 * combination of Gtk::TreeModelFlags. The flags supported should not change
293 * during the lifecycle of the tree_model.
294 * @return The flags supported by this interface.
296 TreeModelFlags get_flags() const;
298 /** Returns the number of columns supported by @a tree_model .
299 * @return The number of columns.
301 int get_n_columns() const;
303 /** Returns the type of the column.
304 * @param index The column index.
305 * @return The type of the column.
307 GType get_column_type(int index) const;
308 //TODO: A C++-type version of get_column_type()?
311 /** Returns a Gtk::TreePath referenced by @a iter .
312 * @param iter The Gtk::TreeIter.
313 * @return A Gtk::TreePath.
315 TreeModel::Path get_path(const iterator& iter) const;
318 /** Emits the "row_changed" signal on @a tree_model .
319 * @param path A Gtk::TreePath pointing to the changed row.
320 * @param iter A valid Gtk::TreeIter pointing to the changed row.
322 void row_changed(const Path& path, const iterator& iter);
324 /** Emits the "row_inserted" signal on @a tree_model
325 * @param path A Gtk::TreePath pointing to the inserted row.
326 * @param iter A valid Gtk::TreeIter pointing to the inserted row.
328 void row_inserted(const Path& path, const iterator& iter);
330 /** Emits the "row_has_child_toggled" signal on @a tree_model . This should be
331 * called by models after the child state of a node changes.
332 * @param path A Gtk::TreePath pointing to the changed row.
333 * @param iter A valid Gtk::TreeIter pointing to the changed row.
335 void row_has_child_toggled(const Path& path, const iterator& iter);
337 /** Emits the "row_deleted" signal on @a tree_model . This should be called by
338 * models after a row has been removed. The location pointed to by @a path should
339 * be the location that the row previously was at. It may not be a valid
341 * @param path A Gtk::TreePath pointing to the previous location of the deleted row.
343 void row_deleted(const Path& path);
345 void rows_reordered(const Path& path, const iterator& iter, const Glib::ArrayHandle<int>& new_order);
348 /** Emits the "rows_reordered" signal on @a tree_model . This should be called by
349 * models when their rows have been reordered.
350 * @param path A Gtk::TreePath pointing to the tree node whose children have been reordered.
351 * @param iter A valid Gtk::TreeIter pointing to the node whose children have been reordered.
352 * @param new_order An array of integers mapping the current position of each child
353 * to its old position before the re-ordering,
354 * i.e. @a new_order <tt>[newpos] = oldpos</tt>.
356 void rows_reordered(const Path& path, const iterator& iter, int* new_order);
359 /** Generates a string representation of the iter. This string is a ':'
360 * separated list of numbers. For example, "4:10:0:3" would be an
361 * acceptable return value for this string.
362 * @param iter An Gtk::TreeIter.
363 * @return The string.
367 Glib::ustring get_string(const iterator& iter) const;
370 Glib::SignalProxy2< void,const TreeModel::Path&,const TreeModel::iterator& > signal_row_changed();
373 Glib::SignalProxy2< void,const TreeModel::Path&,const TreeModel::iterator& > signal_row_inserted();
376 Glib::SignalProxy2< void,const TreeModel::Path&,const TreeModel::iterator& > signal_row_has_child_toggled();
379 Glib::SignalProxy1< void,const TreeModel::Path& > signal_row_deleted();
382 Glib::SignalProxy3< void,const TreeModel::Path&,const TreeModel::iterator&,int* > signal_rows_reordered();
386 virtual TreeModelFlags get_flags_vfunc() const;
387 virtual int get_n_columns_vfunc() const;
388 virtual GType get_column_type_vfunc(int index) const;
390 //These are only for deriving new TreeModels, which isn't very common or easy:
392 /** Override and implement this in a derived TreeModel class.
393 * Sets @a iter_next to refer to the node following @a iter it at the current level.
394 * If there is no next iter, false is returned and iter_next is set to be invalid.
396 * @param iter An iterator.
397 * @param iter_next An iterator that will be set to refer to the next node, or will be set as invalid.
398 * @result true if the operation was possible.
400 virtual bool iter_next_vfunc(const iterator& iter, iterator& iter_next) const;
402 /** Override and implement this in a derived TreeModel class.
403 * Sets @a iter to a valid iterator pointing to @a path
405 * @param path An path to a node.
406 * @param iter An iterator that will be set to refer to a node to the path, or will be set as invalid.
407 * @result true if the operation was possible.
409 virtual bool get_iter_vfunc(const Path& path, iterator& iter) const;
411 /** Override and implement this in a derived TreeModel class.
412 * Sets @a iter to refer to the first child of @a parent. If @a parent has no children,
413 * false is returned and @a iter is set to be invalid.
415 * @param parent An iterator.
416 * @param iter An iterator that will be set to refer to the firt child node, or will be set as invalid.
417 * @result true if the operation was possible.
419 virtual bool iter_children_vfunc(const iterator& parent, iterator& iter) const;
421 /** Override and implement this in a derived TreeModel class.
422 * Sets @a iter to be the parent of @a child. If @a child is at the toplevel, and
423 * doesn't have a parent, then @a iter is set to an invalid iterator and false
426 * @param child An iterator.
427 * @param iter An iterator that will be set to refer to the parent node, or will be set as invalid.
428 * @result true if the operation was possible.
430 virtual bool iter_parent_vfunc(const iterator& child, iterator& iter) const;
432 /** Override and implement this in a derived TreeModel class.
433 * Sets @a iter to be the child of @a parent using the given index. The first
434 * index is 0. If @a n is too big, or @a parent has no children, @a iter is set
435 * to an invalid iterator and false is returned.
436 * See also iter_nth_root_child_vfunc()
438 * @param parent An iterator.
439 * @param n The index of the child node to which @a iter should be set.
440 * @param iter An iterator that will be set to refer to the nth node, or will be set as invalid.
441 * @result true if the operation was possible.
443 virtual bool iter_nth_child_vfunc(const iterator& parent, int n, iterator& iter) const;
445 /** Override and implement this in a derived TreeModel class.
446 * Sets @a iter to be the child of at the root level using the given index. The first
447 * index is 0. If @a n is too big, or if there are no children, @a iter is set
448 * to an invalid iterator and false is returned.
449 * See also iter_nth_child_vfunc().
451 * @param n The index of the child node to which @a iter should be set.
452 * @param iter An iterator that will be set to refer to the nth node, or will be set as invalid.
453 * @result true if the operation was possible.
455 virtual bool iter_nth_root_child_vfunc(int n, iterator& iter) const;
458 /** Override and implement this in a derived TreeModel class.
459 * Returns true if @a iter has children, false otherwise.
461 * @param iter The iterator to test for children.
462 * @result true if @a iter has children.
464 virtual bool iter_has_child_vfunc(const iterator& iter) const;
466 /** Override and implement this in a derived TreeModel class.
467 * Returns the number of children that @a iter has.
468 * See also iter_n_root_children_vfunc().
470 * @param iter The iterator to test for children.
471 * @result The number of children of @a iter.
473 virtual int iter_n_children_vfunc(const iterator& iter) const;
475 /** Override and implement this in a derived TreeModel class.
476 * Returns the number of toplevel nodes.
477 * See also iter_n_children().
479 * @result The number of children at the root level.
481 virtual int iter_n_root_children_vfunc() const;
483 /** Override and implement this in a derived TreeModel class.
484 * Lets the tree ref the node. This is an optional method for models to
485 * implement. To be more specific, models may ignore this call as it exists
486 * primarily for performance reasons.
488 * This function is primarily meant as a way for views to let caching model know
489 * when nodes are being displayed (and hence, whether or not to cache that
490 * node.) For example, a file-system based model would not want to keep the
491 * entire file-hierarchy in memory, just the sections that are currently being
492 * displayed by every current view.
494 * A model should be expected to be able to get an iter independent of its
497 * @param iter the iterator.
499 virtual void ref_node_vfunc(const iterator& iter) const;
501 /** Override and implement this in a derived TreeModel class.
502 * Lets the tree unref the node. This is an optional method for models to
503 * implement. To be more specific, models may ignore this call as it exists
504 * primarily for performance reasons.
506 * For more information on what this means, see unref_node_vfunc().
507 * Please note that nodes that are deleted are not unreffed.
509 * @param iter the iterator.
511 virtual void unref_node_vfunc(const iterator& iter) const;
513 /** Override and implement this in a derived TreeModel class.
514 * Returns a Path referenced by @a iter.
516 * @param iter The iterator.
521 virtual TreeModel::Path get_path_vfunc(const iterator& iter) const;
523 /** Override and implement this in a derived TreeModel class.
524 * Initializes and sets @a value to that at @a column.
526 * @param iter The iterator.
527 * @param column The column to lookup the value at.
528 * @param value An empty Glib:Value to set.
530 virtual void get_value_vfunc(const iterator& iter, int column, Glib::ValueBase& value) const;
532 /** Override and implement this in a derived TreeModel class.
533 * @note This virtual method is <em>deprecated</em>. If you want to check
534 * whether an iterator is valid, call TreeStore::iter_is_valid(),
535 * ListStore::iter_is_valid() or TreeModelSort::iter_is_valid() directly
536 * instead. Because these methods are intended to be used only for debugging
537 * and/or testing purposes, it doesn't make sense to provide an abstract
540 * @result true if the iterator is valid.
542 * @deprecated Use iter_is_valid() in the derived class.
544 virtual bool iter_is_valid(const iterator& iter) const;
546 //Called by TreeRow, which is a friend class:
547 //The comment about set_row_changed() in the documentation is based on my reading of the source of
548 //gtk_list_store_set_value() and gtk_tree_store_set_value().
549 /** Override and implement this in a derived TreeModel class, so that Row::operator() and
550 * Row::set_value() work.
551 * You can probably just implement this by calling set_value_vfunc().
552 * Your implementation of set_value_impl() should also call set_row_changed() after changing the value.
554 virtual void set_value_impl(const iterator& row, int column, const Glib::ValueBase& value);
556 //This might not need to be virtual, but it's not a big deal. murrayc.
557 virtual void get_value_impl(const iterator& row, int column, Glib::ValueBase& value) const;
559 friend class Gtk::TreeModelSort;
560 friend class Gtk::TreeRow;
561 friend class Gtk::TreeIter;
567 //C++ methods used to invoke GTK+ virtual functions:
570 //GTK+ Virtual Functions (override these to change behaviour):
572 //Default Signal Handlers::
573 virtual void on_row_changed(const TreeModel::Path& path, const TreeModel::iterator& iter);
574 virtual void on_row_inserted(const TreeModel::Path& path, const TreeModel::iterator& iter);
575 virtual void on_row_has_child_toggled(const TreeModel::Path& path, const TreeModel::iterator& iter);
576 virtual void on_row_deleted(const TreeModel::Path& path);
577 virtual void on_rows_reordered(const TreeModel::Path& path, const TreeModel::iterator& iter, int* new_order);
587 /** @relates Gtk::TreeModel
588 * @param object The C instance
589 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
590 * @result A C++ instance that wraps this C instance.
592 Glib::RefPtr<Gtk::TreeModel> wrap(GtkTreeModel* object, bool take_copy = false);
596 #endif /* _GTKMM_TREEMODEL_H */