~ubuntu-branches/ubuntu/precise/gtkmm3.0/precise

« back to all changes in this revision

Viewing changes to gtk/src/liststore.ccg

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-06-17 00:12:44 UTC
  • Revision ID: james.westby@ubuntu.com-20110617001244-9hl5an15hiaaahi6
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 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.
 
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
 * Lesser General Public License for more details.
 
15
 *
 
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.
 
19
 */
 
20
 
 
21
#include <glibmm/vectorutils.h>
 
22
 
 
23
#include <gtk/gtk.h>
 
24
 
 
25
 
 
26
namespace Gtk
 
27
{
 
28
 
 
29
ListStore::ListStore(const TreeModelColumnRecord& columns)
 
30
:
 
31
  _CONSTRUCT()
 
32
{
 
33
  gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
 
34
}
 
35
 
 
36
void ListStore::set_column_types(const TreeModelColumnRecord& columns)
 
37
{
 
38
   gtk_list_store_set_column_types(gobj(), columns.size(), const_cast<GType*>(columns.types()));
 
39
}
 
40
  
 
41
 
 
42
TreeModel::iterator ListStore::erase(const iterator& iter)
 
43
{
 
44
  g_assert(iter.get_gobject_if_not_end() != 0);
 
45
 
 
46
  iterator next(iter);
 
47
  ++next;
 
48
 
 
49
  GtkTreeIter tmp = *iter.gobj();
 
50
  gtk_list_store_remove(gobj(), &tmp);
 
51
 
 
52
  return next;
 
53
}
 
54
 
 
55
TreeModel::iterator ListStore::insert(const iterator& iter)
 
56
{
 
57
  iterator new_pos(this);
 
58
 
 
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.
 
62
 
 
63
  gtk_list_store_insert_before(
 
64
      gobj(), new_pos.gobj(),
 
65
      const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
 
66
 
 
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.
 
70
 
 
71
  if(new_pos.gobj()->stamp == 0)
 
72
    new_pos.setup_end_iterator(iter);
 
73
 
 
74
  return new_pos;
 
75
}
 
76
 
 
77
TreeModel::iterator ListStore::insert_after(const iterator& iter)
 
78
{
 
79
  iterator new_pos(this);
 
80
 
 
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.
 
84
 
 
85
  gtk_list_store_insert_after(
 
86
      gobj(), new_pos.gobj(),
 
87
      const_cast<GtkTreeIter*>(iter.get_gobject_if_not_end()));
 
88
 
 
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.
 
92
 
 
93
  if(new_pos.gobj()->stamp == 0)
 
94
    new_pos.setup_end_iterator(iter);
 
95
 
 
96
  return new_pos;
 
97
}
 
98
 
 
99
TreeModel::iterator ListStore::prepend()
 
100
{
 
101
  iterator new_pos(this);
 
102
  gtk_list_store_prepend(gobj(), new_pos.gobj());
 
103
  return new_pos;
 
104
}
 
105
 
 
106
TreeModel::iterator ListStore::append()
 
107
{
 
108
  iterator new_pos(this);
 
109
  gtk_list_store_append(gobj(), new_pos.gobj());
 
110
  return new_pos;
 
111
}
 
112
 
 
113
void ListStore::move(const iterator& source, const iterator& destination)
 
114
{
 
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()));
 
118
}
 
119
 
 
120
void ListStore::reorder(const std::vector<int>& new_order)
 
121
{
 
122
  gtk_list_store_reorder(gobj(), const_cast<int*>(Glib::ArrayHandler<int>::vector_to_array(new_order).data()));
 
123
}
 
124
 
 
125
void ListStore::set_value_impl(const iterator& row, int column, const Glib::ValueBase& value)
 
126
{
 
127
  gtk_list_store_set_value(
 
128
      gobj(), const_cast<GtkTreeIter*>(row.gobj()),
 
129
      column, const_cast<GValue*>(value.gobj()));
 
130
}
 
131
 
 
132
} // namespace Gtk
 
133