| 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 |
/** Thist is a list model for use with a Gtk::TreeView widget. |
| 35 |
* @ingroup TreeView |
| 36 |
* It implements the Gtk::TreeModel interface, and also implements the |
| 37 |
* Gtk::TreeSortable interface so you can sort the list using the view. |
| 38 |
* Finally, it also implements the tree drag and drop interfaces. |
| 39 |
*/ |
| 40 |
class GTKMM_API ListStore : |
| 41 |
public Glib::Object, |
| 42 |
public TreeModel, |
| 43 |
public TreeSortable, |
| 44 |
public TreeDragSource, |
| 45 |
public TreeDragDest, |
| 46 |
public Buildable |
| 47 |
{ |
| 48 |
_CLASS_GOBJECT(ListStore, GtkListStore, GTK_LIST_STORE, Glib::Object, GObject, , , GTKMM_API) |
| 49 |
_IMPLEMENTS_INTERFACE(TreeModel) |
| 50 |
_IMPLEMENTS_INTERFACE(TreeSortable) |
| 51 |
_IMPLEMENTS_INTERFACE(TreeDragSource) |
| 52 |
_IMPLEMENTS_INTERFACE(TreeDragDest) |
| 53 |
_IMPLEMENTS_INTERFACE(Buildable) |
| 54 |
_IGNORE(gtk_list_store_insert_after, |
| 55 |
gtk_list_store_prepend, gtk_list_store_append, gtk_list_store_set_value, |
| 56 |
gtk_list_store_insert, |
| 57 |
gtk_list_store_set, gtk_list_store_set_valist, |
| 58 |
gtk_list_store_reorder, gtk_list_store_move_after, gtk_list_store_move_before) |
| 59 |
|
| 60 |
protected: |
| 61 |
/** When using this constructor, you must use set_column_types() immediately afterwards. |
| 62 |
* This can be useful when deriving from this class, with a fixed TreeModelColumnRecord |
| 63 |
* that is a member of the class. |
| 64 |
* There is no create() method that corresponds to this constructor, because this |
| 65 |
* constructor should only be used by derived classes. |
| 66 |
*/ |
| 67 |
_CTOR_DEFAULT |
| 68 |
|
| 69 |
explicit ListStore(const TreeModelColumnRecord& columns); |
| 70 |
|
| 71 |
public: |
| 72 |
|
| 73 |
/** Instantiate a new ListStore. |
| 74 |
* @param columns The column types for this tree model. |
| 75 |
* @result The new ListStore. |
| 76 |
*/ |
| 77 |
_WRAP_CREATE(const TreeModelColumnRecord& columns) |
| 78 |
|
| 79 |
void set_column_types(const TreeModelColumnRecord& columns); |
| 80 |
_IGNORE(gtk_list_store_set_column_types) |
| 81 |
|
| 82 |
/** Removes the given row from the list store. |
| 83 |
* @param iter The iterator to the row to be removed. |
| 84 |
* @result An iterator to the next row, or end() if there is none. |
| 85 |
*/ |
| 86 |
iterator erase(const iterator& iter); |
| 87 |
_IGNORE(gtk_list_store_remove) |
| 88 |
|
| 89 |
//TODO: Make this documentation similar to documentation for Standard C++ insert methods. |
| 90 |
/** Creates a new row before the position. |
| 91 |
* If iter is end() then a new row will be appended to the list. |
| 92 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 93 |
* See also prepend() and append(). |
| 94 |
* |
| 95 |
* @param iter An iterator to the row before which the new row will be inserted. |
| 96 |
* @result An iterator to the new row. |
| 97 |
*/ |
| 98 |
iterator insert(const iterator& iter); |
| 99 |
_IGNORE(gtk_list_store_insert_before) |
| 100 |
|
| 101 |
//TODO: Docs. This one is apparently faster. |
| 102 |
/** Creates a new row after the position. |
| 103 |
* If iter is end() then a new row will be prepended to the list. |
| 104 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 105 |
* See also insert(), prepend() and append(). |
| 106 |
* |
| 107 |
* @param iter An iterator to the row after which the new row will be inserted. |
| 108 |
* @result An iterator to the new row. |
| 109 |
*/ |
| 110 |
iterator insert_after(const iterator& iter); |
| 111 |
_IGNORE(gtk_list_store_insert_after) |
| 112 |
|
| 113 |
/** Creates a new row at the start. |
| 114 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 115 |
* See also insert() and append(). |
| 116 |
* |
| 117 |
* @result An iterator to the new row. |
| 118 |
*/ |
| 119 |
iterator prepend(); |
| 120 |
|
| 121 |
/** Creates a new row at the end. |
| 122 |
* The row will be empty - to fill in values, you need to dereference the returned iterator and use Row::operator[] or Row::set_value(). |
| 123 |
* See also insert() and prepend(). |
| 124 |
* |
| 125 |
* @result An iterator to the new row. |
| 126 |
*/ |
| 127 |
iterator append(); |
| 128 |
|
| 129 |
_WRAP_METHOD(void iter_swap(const iterator& a, const iterator& b), gtk_list_store_swap) |
| 130 |
|
| 131 |
/** Moves @a source to the position at @a destination. |
| 132 |
* Note that this function only works with unsorted stores. |
| 133 |
* @param source The row that should be moved. |
| 134 |
* @param destination The position to move to. |
| 135 |
*/ |
| 136 |
void move(const iterator& source, const iterator& destination); |
| 137 |
|
| 138 |
/** Reorders the list store to follow the order indicated by @a new_order. |
| 139 |
* Note that this function only works with unsorted stores. |
| 140 |
*/ |
| 141 |
void reorder(const std::vector<int>& new_order); |
| 142 |
|
| 143 |
_WRAP_METHOD(void clear(), gtk_list_store_clear) |
| 144 |
|
| 145 |
_WRAP_METHOD(bool iter_is_valid(const iterator& iter) const, gtk_list_store_iter_is_valid) |
| 146 |
|
| 147 |
protected: |
| 148 |
void set_value_impl(const iterator& row, int column, const Glib::ValueBase& value) override; |
| 149 |
}; |
| 150 |
|
| 151 |
} // namespace Gtk |