| 1 |
/* Copyright (C) 1998-2002 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or(at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <vector> |
| 18 |
|
| 19 |
#include <gtkmm/treeiter.h> |
| 20 |
#include <gtkmm/treemodel.h> |
| 21 |
#include <gtkmm/treesortable.h> |
| 22 |
#include <gtkmm/treedragdest.h> |
| 23 |
#include <gtkmm/treedragsource.h> |
| 24 |
#include <gtkmm/buildable.h> |
| 25 |
// We couldn't include it in treemodel.h, but doing it here makes it easier for people. |
| 26 |
#include <gtkmm/treepath.h> |
| 27 |
|
| 28 |
_DEFS(gtkmm,gtk) |
| 29 |
_PINCLUDE(glibmm/private/object_p.h) |
| 30 |
|
| 31 |
namespace Gtk |
| 32 |
{ |
| 33 |
|
| 34 |
/** |
| 35 |
* @ingroup TreeView |
| 36 |
*/ |
| 37 |
class GTKMM_API TreeStore : |
| 38 |
public Glib::Object, |
| 39 |
public Gtk::TreeModel, |
| 40 |
public TreeSortable, |
| 41 |
public TreeDragSource, |
| 42 |
public TreeDragDest, |
| 43 |
public Buildable |
| 44 |
{ |
| 45 |
_CLASS_GOBJECT(TreeStore, GtkTreeStore, GTK_TREE_STORE, Glib::Object, GObject, , , GTKMM_API) |
| 46 |
_IMPLEMENTS_INTERFACE(TreeModel) |
| 47 |
_IMPLEMENTS_INTERFACE(TreeSortable) |
| 48 |
_IMPLEMENTS_INTERFACE(TreeDragSource) |
| 49 |
_IMPLEMENTS_INTERFACE(TreeDragDest) |
| 50 |
_IMPLEMENTS_INTERFACE(Buildable) |
| 51 |
_IGNORE(gtk_tree_store_set, gtk_tree_store_set_valist, |
| 52 |
gtk_tree_store_insert, gtk_tree_store_append, gtk_tree_store_prepend, |
| 53 |
gtk_tree_store_reorder, gtk_tree_store_move_after, gtk_tree_store_move_before) |
| 54 |
|
| 55 |
protected: |
| 56 |
/** When using this constructor, you must use set_column_types() immediately afterwards. |
| 57 |
* This can be useful when deriving from this class, with a fixed TreeModelColumnRecord |
| 58 |
* that is a member of the class. |
| 59 |
* There is no create() method that corresponds to this constructor, because this |
| 60 |
* constructor should only be used by derived classes. |
| 61 |
*/ |
| 62 |
_CTOR_DEFAULT |
| 63 |
|
| 64 |
explicit TreeStore(const TreeModelColumnRecord& columns); |
| 65 |
|
| 66 |
public: |
| 67 |
/** Instantiate a new TreeStore. |
| 68 |
* @param columns The column types for this tree model. |
| 69 |
* @result The new TreeStore. |
| 70 |
*/ |
| 71 |
_WRAP_CREATE(const TreeModelColumnRecord& columns) |
| 72 |
|
| 73 |
void set_column_types(const TreeModelColumnRecord& columns); |
| 74 |
_IGNORE(gtk_tree_store_set_column_types) |
| 75 |
|
| 76 |
/** Removes the given row from the list store. |
| 77 |
* @param iter The iterator to the row to be removed. |
| 78 |
* @result An iterator to the next row, or end() if there is none. |
| 79 |
*/ |
| 80 |
iterator erase(const iterator& iter); |
| 81 |
_IGNORE(gtk_tree_store_remove) |
| 82 |
|
| 83 |
//TODO: Make this documentation similar to documentation for Standard C++ insert methods. |
| 84 |
/** Creates a new row before the position. |
| 85 |
* If iter is end() then a new row will be appended to the list. |
| 86 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 87 |
* See also prepend() and append(). |
| 88 |
* |
| 89 |
* @param iter An iterator to the row before which the new row will be inserted. |
| 90 |
* @result An iterator to the new row. |
| 91 |
*/ |
| 92 |
iterator insert(const iterator& iter); |
| 93 |
_IGNORE(gtk_tree_store_insert_before) |
| 94 |
|
| 95 |
/** Creates a new row after the position. |
| 96 |
* If iter is end() then a new row will be prepended to the list. |
| 97 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 98 |
* See also prepend() and append(). |
| 99 |
* |
| 100 |
* @param iter An iterator to the row after which the new row will be inserted. |
| 101 |
* @result An iterator to the new row. |
| 102 |
*/ |
| 103 |
iterator insert_after(const iterator& iter); |
| 104 |
_IGNORE(gtk_tree_store_insert_after) |
| 105 |
|
| 106 |
/** Creates a new row at the start of the top-level. |
| 107 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 108 |
* See also insert() and append(). |
| 109 |
* |
| 110 |
* @result An iterator to the new row. |
| 111 |
*/ |
| 112 |
iterator prepend(); |
| 113 |
|
| 114 |
/** Creates a new row at the start of the row's children. |
| 115 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 116 |
* See also insert() and append(). |
| 117 |
* |
| 118 |
* @param node The list of the parent row's children, as returned by Gtk::TreeModel::iterator::children(). |
| 119 |
* @result An iterator to the new row. |
| 120 |
*/ |
| 121 |
iterator prepend(const TreeNodeChildren& node); |
| 122 |
|
| 123 |
|
| 124 |
/** Creates a new row at the end of the top-level. |
| 125 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 126 |
* See also insert() and prepend(). |
| 127 |
* |
| 128 |
* @result An iterator to the new row. |
| 129 |
*/ |
| 130 |
iterator append(); |
| 131 |
|
| 132 |
/** Creates a new row at the end of the row's children. |
| 133 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 134 |
* See also insert() and prepend(). |
| 135 |
* |
| 136 |
* @param node The list of the parent row's children, as returned by Gtk::TreeModel::iterator::children(). |
| 137 |
* @result An iterator to the new row. |
| 138 |
*/ |
| 139 |
iterator append(const TreeNodeChildren& node); |
| 140 |
|
| 141 |
_WRAP_METHOD(void iter_swap(const iterator& a, const iterator& b), gtk_tree_store_swap) |
| 142 |
|
| 143 |
/** Moves @a source to the position at @a destination. |
| 144 |
* @a source and @a destination should be at the same level. |
| 145 |
* Note that this function only works with unsorted stores. |
| 146 |
* @param source The row that should be moved. |
| 147 |
* @param destination The position to move to. |
| 148 |
*/ |
| 149 |
void move(const iterator& source, const iterator& destination); |
| 150 |
|
| 151 |
/** Reorders the children of @a node to follow the order indicated by @a new_order. |
| 152 |
* Note that this function only works with unsorted stores. |
| 153 |
*/ |
| 154 |
void reorder(const TreeNodeChildren& node, const std::vector<int>& new_order); |
| 155 |
|
| 156 |
_WRAP_METHOD(void clear(), gtk_tree_store_clear) |
| 157 |
_WRAP_METHOD(bool is_ancestor(const iterator& iter, const iterator& descendant) const, gtk_tree_store_is_ancestor) |
| 158 |
_WRAP_METHOD(int iter_depth(const iterator& iter) const, gtk_tree_store_iter_depth) |
| 159 |
|
| 160 |
_WRAP_METHOD(bool iter_is_valid(const iterator& iter) const, gtk_tree_store_iter_is_valid) |
| 161 |
|
| 162 |
protected: |
| 163 |
void set_value_impl(const iterator& row, int column, const Glib::ValueBase& value) override; |
| 164 |
_IGNORE(gtk_tree_store_set_value) |
| 165 |
}; |
| 166 |
|
| 167 |
} // namespace Gtk |