2 /* $Id: liststore.ccg,v 1.5 2004/04/03 12:53:49 murrayc Exp $ */
4 /* Copyright 1998-2002 The gtkmm Development Team
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.
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.
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.
21 #include <gtk/gtkliststore.h>
27 ListStore::ListStore(const TreeModelColumnRecord& columns)
31 gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
34 void ListStore::set_column_types(const TreeModelColumnRecord& columns)
36 gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
40 TreeModel::iterator ListStore::erase(const iterator& iter)
42 g_assert(iter.get_gobject_if_not_end() != 0);
47 GtkTreeIter tmp = *iter.gobj();
48 gtk_list_store_remove(gobj(), &tmp);
53 TreeModel::iterator ListStore::insert(const iterator& iter)
55 iterator new_pos(this);
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.
61 gtk_list_store_insert_before(
62 gobj(), new_pos.gobj(),
63 const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
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.
69 if(new_pos.gobj()->stamp == 0)
70 new_pos.setup_end_iterator(iter);
75 TreeModel::iterator ListStore::insert_after(const iterator& iter)
77 iterator new_pos(this);
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.
83 gtk_list_store_insert_after(
84 gobj(), new_pos.gobj(),
85 const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
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.
91 if(new_pos.gobj()->stamp == 0)
92 new_pos.setup_end_iterator(iter);
97 TreeModel::iterator ListStore::prepend()
99 iterator new_pos(this);
100 gtk_list_store_prepend(gobj(), new_pos.gobj());
104 TreeModel::iterator ListStore::append()
106 iterator new_pos(this);
107 gtk_list_store_append(gobj(), new_pos.gobj());
111 void ListStore::move(const iterator& source, const iterator& destination)
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()));
118 void ListStore::reorder(const Glib::ArrayHandle<int>& new_order)
120 gtk_list_store_reorder(gobj(), const_cast<int*>(new_order.data()));
123 void ListStore::set_value_impl(const iterator& row, int column, const Glib::ValueBase& value)
125 gtk_list_store_set_value(
126 gobj(), const_cast<GtkTreeIter*>(row.gobj()),
127 column, const_cast<GValue*>(value.gobj()));