Debian Codegraph @

gtk/src/liststore.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 ListStore::ListStore(const TreeModelColumnRecord& columns)
26 :
27 _CONSTRUCT()
28 {
29 gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
30 }
31
32 void ListStore::set_column_types(const TreeModelColumnRecord& columns)
33 {
34 gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
35 }
36
37
38 TreeModel::iterator ListStore::erase(const iterator& iter)
39 {
40 g_assert(iter.get_gobject_if_not_end() != nullptr);
41
42 iterator next(iter);
43 ++next;
44
45 auto tmp = *iter.gobj();
46 gtk_list_store_remove(gobj(), &tmp);
47
48 return next;
49 }
50
51 TreeModel::iterator ListStore::insert(const iterator& iter)
52 {
53 iterator new_pos(this);
54
55 // get_gobject_if_not_end() returns 0 if iter is an end iterator, which
56 // is in turn interpreted by gtk_list_store_insert_before() as a request to
57 // insert at the end of the list.
58
59 gtk_list_store_insert_before(
60 gobj(), new_pos.gobj(),
61 const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
62
63 // GtkTreeIter::stamp should always have a value if it's valid.
64 // For end iterators, we need to remember the iter's parent, and
65 // this is what setup_end_iterator() does.
66
67 if(new_pos.gobj()->stamp == 0)
68 new_pos.setup_end_iterator(iter);
69
70 return new_pos;
71 }
72
73 TreeModel::iterator ListStore::insert_after(const iterator& iter)
74 {
75 iterator new_pos(this);
76
77 // get_gobject_if_not_end() returns 0 if iter is an end iterator, which
78 // is in turn interpreted by gtk_list_store_insert_after() as a request to
79 // insert at the beginning of the list.
80
81 gtk_list_store_insert_after(
82 gobj(), new_pos.gobj(),
83 const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
84
85 // GtkTreeIter::stamp should always have a value if it's valid.
86 // For end iterators, we need to remember the iter's parent, and
87 // this is what setup_end_iterator() does.
88
89 if(new_pos.gobj()->stamp == 0)
90 new_pos.setup_end_iterator(iter);
91
92 return new_pos;
93 }
94
95 TreeModel::iterator ListStore::prepend()
96 {
97 iterator new_pos(this);
98 gtk_list_store_prepend(gobj(), new_pos.gobj());
99 return new_pos;
100 }
101
102 TreeModel::iterator ListStore::append()
103 {
104 iterator new_pos(this);
105 gtk_list_store_append(gobj(), new_pos.gobj());
106 return new_pos;
107 }
108
109 void ListStore::move(const iterator& source, const iterator& destination)
110 {
111 gtk_list_store_move_before(gobj(),
112 const_cast<GtkTreeIter*>(source.get_gobject_if_not_end()),
113 const_cast<GtkTreeIter*>(destination.get_gobject_if_not_end()));
114 }
115
116 void ListStore::reorder(const std::vector<int>& new_order)
117 {
118 gtk_list_store_reorder(gobj(), const_cast<int*>(Glib::ArrayHandler<int>::vector_to_array(new_order).data()));
119 }
120
121 void ListStore::set_value_impl(const iterator& row, int column, const Glib::ValueBase& value)
122 {
123 gtk_list_store_set_value(
124 gobj(), const_cast<GtkTreeIter*>(row.gobj()),
125 column, const_cast<GValue*>(value.gobj()));
126 }
127
128 } // namespace Gtk