Debian Codegraph @

gtk/src/treestore.ccg

raw
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 <glibmm/vectorutils.h>
18
19 #include <gtk/gtk.h>
20
21
22 namespace Gtk
23 {
24
25 TreeStore::TreeStore(const TreeModelColumnRecord& columns)
26 :
27 _CONSTRUCT()
28 {
29 gtk_tree_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
30 }
31
32 void TreeStore::set_column_types(const TreeModelColumnRecord& columns)
33 {
34 gtk_tree_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
35 }
36
37 TreeModel::iterator TreeStore::erase(const iterator& iter)
38 {
39 g_assert(iter.get_gobject_if_not_end() != nullptr);
40
41 iterator next (iter);
42 ++next;
43
44 auto tmp = *iter.gobj();
45 gtk_tree_store_remove(gobj(), &tmp);
46
47 return next;
48 }
49
50 TreeModel::iterator TreeStore::insert(const iterator& iter)
51 {
52 iterator new_pos (this);
53
54 gtk_tree_store_insert_before(
55 gobj(), new_pos.gobj(),
56 const_cast<GtkTreeIter*>(iter.get_parent_gobject_if_end()),
57 const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
58
59 if(new_pos.gobj()->stamp == 0)
60 new_pos.setup_end_iterator(iter);
61
62 return new_pos;
63 }
64
65 TreeModel::iterator TreeStore::insert_after(const iterator& iter)
66 {
67 iterator new_pos (this);
68
69 gtk_tree_store_insert_after(
70 gobj(), new_pos.gobj(),
71 const_cast<GtkTreeIter*>(iter.get_parent_gobject_if_end()),
72 const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
73
74 if(new_pos.gobj()->stamp == 0)
75 new_pos.setup_end_iterator(iter);
76
77 return new_pos;
78 }
79
80 TreeModel::iterator TreeStore::prepend()
81 {
82 iterator new_pos (this);
83 gtk_tree_store_prepend(gobj(), new_pos.gobj(), nullptr);
84 return new_pos;
85 }
86
87 TreeModel::iterator TreeStore::prepend(const TreeNodeChildren& node)
88 {
89 iterator new_pos (this);
90
91 gtk_tree_store_prepend(
92 gobj(), new_pos.gobj(),
93 const_cast<GtkTreeIter*>(node.get_parent_gobject()));
94
95 return new_pos;
96 }
97
98 TreeModel::iterator TreeStore::append()
99 {
100 iterator new_pos (this);
101 gtk_tree_store_append(gobj(), new_pos.gobj(), nullptr);
102 return new_pos;
103 }
104
105 TreeModel::iterator TreeStore::append(const TreeNodeChildren& node)
106 {
107 iterator new_pos (this);
108
109 gtk_tree_store_append(
110 gobj(), new_pos.gobj(),
111 const_cast<GtkTreeIter*>(node.get_parent_gobject()));
112
113 return new_pos;
114 }
115
116 void TreeStore::move(const iterator& source, const iterator& destination)
117 {
118 gtk_tree_store_move_before(gobj(),
119 const_cast<GtkTreeIter*>(source.get_gobject_if_not_end()),
120 const_cast<GtkTreeIter*>(destination.get_gobject_if_not_end()));
121 }
122
123 void TreeStore::reorder(const TreeNodeChildren& node, const std::vector<int>& new_order)
124 {
125 gtk_tree_store_reorder(gobj(),
126 const_cast<GtkTreeIter*>(node.get_parent_gobject()),
127 const_cast<int*>(Glib::ArrayHandler<int>::vector_to_array(new_order).data ()));
128 }
129
130 void TreeStore::set_value_impl(const iterator& row, int column, const Glib::ValueBase& value)
131 {
132 gtk_tree_store_set_value(
133 gobj(), const_cast<GtkTreeIter*>(row.gobj()),
134 column, const_cast<GValue*>(value.gobj()));
135 }
136
137 } // namespace Gtk