1 #ifndef _GTKMM_TREEMODELCOLUMN_H
2 #define _GTKMM_TREEMODELCOLUMN_H
5 /* Copyright (c) 2002 The gtkmm Development Team
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or(at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <glib-object.h>
23 #include <glibmm/value.h>
26 #include <gtkmmconfig.h>
28 GLIBMM_USING_STD(vector)
34 class TreeModelColumnBase;
37 /** Typedefed as TreeModel::ColumnRecord.
38 * Keeps a record of @link TreeModelColumn TreeModelColumns@endlink.
40 * ColumnRecord objects are used to setup a new instance of a TreeModel
41 * (or rather, a new instance of an implementation of the model, such as Gtk::ListStore
42 * or Gtk::TreeStore). It is convenient to do that by deriving from
43 * TreeModel::ColumnRecord:
45 * class MyModelColumns : public Gtk::TreeModel::ColumnRecord
48 * Gtk::TreeModelColumn<Glib::ustring> filename;
49 * Gtk::TreeModelColumn<Glib::ustring> description;
50 * Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > thumbnail;
52 * MyModelColumns() { add(filename); add(description); add(thumbnail); }
56 * Whether or not you derive your own ColumnRecord, you need to add the
57 * @link TreeModelColumn TreeModelColumns@endlink to the ColumnRecord with the
60 * A ColumnRecord instance, such as an instance of @c MyModelColumns should then
61 * be passed to ListStore::create() or TreeStore::create().
62 * The @link TreeModelColumn TreeModelColumns@endlink, such as the members
63 * @c filename, @c description and @c thumbnail can then be used with Gtk::TreeRow::operator[]()
64 * to specify the column you're interested in.
66 * Neither TreeModel::ColumnRecord nor the
67 * @link TreeModelColumn TreeModelColumns@endlink contain any real data --
68 * they merely describe what C++ type is stored in which column
69 * of a TreeModel, and save you from having to repeat that type information in several places.
70 * Thus it's absolutely legal to use a statically allocated
71 * TreeModel::ColumnRecord (as long as you make sure it's instantiated after
72 * Gtk::Main), even when creating multiple models from it.
74 class TreeModelColumnRecord
77 TreeModelColumnRecord();
78 virtual ~TreeModelColumnRecord();
80 /** Adds a TreeModelColumn to this record.
81 * add() not only registers the @a column, but also assigns a column
82 * index to it. Once registered, the TreeModelColumn is final, and
83 * you're free to pass it around by value.
85 void add(TreeModelColumnBase& column);
87 unsigned int size() const;
88 const GType* types() const;
91 std::vector<GType> column_types_;
94 TreeModelColumnRecord(const TreeModelColumnRecord&);
95 TreeModelColumnRecord& operator=(const TreeModelColumnRecord&);
99 /** Base class of TreeModelColumn templates.
102 class TreeModelColumnBase
105 GType type() const { return type_; }
106 int index() const { return index_; }
109 explicit TreeModelColumnBase(GType type);
115 friend class Gtk::TreeModelColumnRecord;
118 /** @relates Gtk::TreeModelColumnBase */
119 inline bool operator==(const TreeModelColumnBase& lhs, const TreeModelColumnBase& rhs)
120 { return (lhs.index() == rhs.index()); }
122 /** @relates Gtk::TreeModelColumnBase */
123 inline bool operator!=(const TreeModelColumnBase& lhs, const TreeModelColumnBase& rhs)
124 { return (lhs.index() != rhs.index()); }
127 /** A Gtk::TreeModelColumn describes the C++ type of the data in a model column, and identifies that column in the model.
128 * See @link TreeModelColumnRecord Gtk::TreeModel::Columns@endlink for a usage example.
132 class TreeModelColumn : public TreeModelColumnBase
135 typedef T ElementType;
136 typedef Glib::Value<T> ValueType;
138 TreeModelColumn() : TreeModelColumnBase(ValueType::value_type()) {}
144 #endif /* _GTKMM_TREEMODELCOLUMN_H */