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 Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 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
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser 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 <glibmm/vectorutils.h>
29
ListStore::ListStore(const TreeModelColumnRecord& columns)
33
gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
36
void ListStore::set_column_types(const TreeModelColumnRecord& columns)
38
gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
42
TreeModel::iterator ListStore::erase(const iterator& iter)
44
g_assert(iter.get_gobject_if_not_end() != 0);
49
GtkTreeIter tmp = *iter.gobj();
50
gtk_list_store_remove(gobj(), &tmp);
55
TreeModel::iterator ListStore::insert(const iterator& iter)
57
iterator new_pos(this);
59
// get_gobject_if_not_end() returns 0 if iter is an end iterator, which
60
// is in turn interpreted by gtk_list_store_insert_before() as a request to
61
// insert at the end of the list.
63
gtk_list_store_insert_before(
64
gobj(), new_pos.gobj(),
65
const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
67
// GtkTreeIter::stamp should always have a value if it's valid.
68
// For end iterators, we need to remember the iter's parent, and
69
// this is what setup_end_iterator() does.
71
if(new_pos.gobj()->stamp == 0)
72
new_pos.setup_end_iterator(iter);
77
TreeModel::iterator ListStore::insert_after(const iterator& iter)
79
iterator new_pos(this);
81
// get_gobject_if_not_end() returns 0 if iter is an end iterator, which
82
// is in turn interpreted by gtk_list_store_insert_after() as a request to
83
// insert at the beginning of the list.
85
gtk_list_store_insert_after(
86
gobj(), new_pos.gobj(),
87
const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
89
// GtkTreeIter::stamp should always have a value if it's valid.
90
// For end iterators, we need to remember the iter's parent, and
91
// this is what setup_end_iterator() does.
93
if(new_pos.gobj()->stamp == 0)
94
new_pos.setup_end_iterator(iter);
99
TreeModel::iterator ListStore::prepend()
101
iterator new_pos(this);
102
gtk_list_store_prepend(gobj(), new_pos.gobj());
106
TreeModel::iterator ListStore::append()
108
iterator new_pos(this);
109
gtk_list_store_append(gobj(), new_pos.gobj());
113
void ListStore::move(const iterator& source, const iterator& destination)
115
gtk_list_store_move_before(gobj(),
116
const_cast<GtkTreeIter*>(source.get_gobject_if_not_end()),
117
const_cast<GtkTreeIter*>(destination.get_gobject_if_not_end()));
120
void ListStore::reorder(const std::vector<int>& new_order)
122
gtk_list_store_reorder(gobj(), const_cast<int*>(Glib::ArrayHandler<int>::vector_to_array(new_order).data()));
125
void ListStore::set_value_impl(const iterator& row, int column, const Glib::ValueBase& value)
127
gtk_list_store_set_value(
128
gobj(), const_cast<GtkTreeIter*>(row.gobj()),
129
column, const_cast<GValue*>(value.gobj()));