add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / liststore.ccg
1 // -*- c++ -*-
2 /* $Id: liststore.ccg,v 1.5 2004/04/03 12:53:49 murrayc Exp $ */
3
4 /* Copyright 1998-2002 The gtkmm Development Team
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include <gtk/gtkliststore.h>
22
23
24 namespace Gtk
25 {
26
27 ListStore::ListStore(const TreeModelColumnRecord& columns)
28 :
29   _CONSTRUCT()
30 {
31   gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
32 }
33
34 void ListStore::set_column_types(const TreeModelColumnRecord& columns)
35 {
36    gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
37 }
38   
39
40 TreeModel::iterator ListStore::erase(const iterator& iter)
41 {
42   g_assert(iter.get_gobject_if_not_end() != 0);
43
44   iterator next(iter);
45   ++next;
46
47   GtkTreeIter tmp = *iter.gobj();
48   gtk_list_store_remove(gobj(), &tmp);
49
50   return next;
51 }
52
53 TreeModel::iterator ListStore::insert(const iterator& iter)
54 {
55   iterator new_pos(this);
56
57   // get_gobject_if_not_end() returns 0 if iter is an end iterator, which
58   // is in turn interpreted by gtk_list_store_insert_before() as a request to
59   // insert at the end of the list.
60
61   gtk_list_store_insert_before(
62       gobj(), new_pos.gobj(),
63       const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
64
65   // GtkTreeIter::stamp should always have a value if it's valid.
66   // For end iterators, we need to remember the iter's parent, and
67   // this is what setup_end_iterator() does.
68
69   if(new_pos.gobj()->stamp == 0)
70     new_pos.setup_end_iterator(iter);
71
72   return new_pos;
73 }
74
75 TreeModel::iterator ListStore::insert_after(const iterator& iter)
76 {
77   iterator new_pos(this);
78
79   // get_gobject_if_not_end() returns 0 if iter is an end iterator, which
80   // is in turn interpreted by gtk_list_store_insert_after() as a request to
81   // insert at the beginning of the list.
82
83   gtk_list_store_insert_after(
84       gobj(), new_pos.gobj(),
85       const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
86
87   // GtkTreeIter::stamp should always have a value if it's valid.
88   // For end iterators, we need to remember the iter's parent, and
89   // this is what setup_end_iterator() does.
90
91   if(new_pos.gobj()->stamp == 0)
92     new_pos.setup_end_iterator(iter);
93
94   return new_pos;
95 }
96
97 TreeModel::iterator ListStore::prepend()
98 {
99   iterator new_pos(this);
100   gtk_list_store_prepend(gobj(), new_pos.gobj());
101   return new_pos;
102 }
103
104 TreeModel::iterator ListStore::append()
105 {
106   iterator new_pos(this);
107   gtk_list_store_append(gobj(), new_pos.gobj());
108   return new_pos;
109 }
110
111 void ListStore::move(const iterator& source, const iterator& destination)
112 {
113   gtk_list_store_move_before(gobj(),
114       const_cast<GtkTreeIter*>(source.get_gobject_if_not_end()),
115       const_cast<GtkTreeIter*>(destination.get_gobject_if_not_end()));
116 }
117
118 void ListStore::reorder(const Glib::ArrayHandle<int>& new_order)
119 {
120   gtk_list_store_reorder(gobj(), const_cast<int*>(new_order.data()));
121 }
122
123 void ListStore::set_value_impl(const iterator& row, int column, const Glib::ValueBase& value)
124 {
125   gtk_list_store_set_value(
126       gobj(), const_cast<GtkTreeIter*>(row.gobj()),
127       column, const_cast<GValue*>(value.gobj()));
128 }
129
130 } // namespace Gtk
131