Debian Codegraph @

gtk/src/treeviewcolumn.hg

raw
1 /* Copyright (C) 2002 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or(at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 // This is for including the config header before any code (such as
18 // the #ifndef GTKMM_DISABLE_DEPRECATED in deprecated classes) is generated:
19 _CONFIGINCLUDE(gtkmmconfig.h)
20
21 #include <gtkmm/treeiter.h>
22 #include <gtkmm/button.h>
23 #include <gdkmm/window.h>
24 #include <gtkmm/treemodel.h>
25 #include <gtkmm/celllayout.h>
26 #include <gtkmm/cellrenderer_generation.h>
27 _DEFS(gtkmm,gtk)
28 _PINCLUDE(gtkmm/private/object_p.h)
29
30 namespace Gtk
31 {
32
33 _CC_INCLUDE(gtk/gtk.h)
34 _WRAP_ENUM(TreeViewColumnSizing, GtkTreeViewColumnSizing, decl_prefix GTKMM_API)
35
36 // We use GTKMM_API here because gcc needs the extra help on win32 , even
37 // when using --export-all and auto-import.
38 // See http://bugzilla.gnome.org/show_bug.cgi?id=309030.
39
40 class GTKMM_API TreeView;
41
42 //TODO: Deal with the GtkObject->GObject change?
43 /** Typedefed as Gtk::TreeView::Column.
44 * This is a visible column in a Gtk::TreeView widget. It determines the geometry, type.
45 *
46 * @ingroup TreeView
47 */
48 class GTKMM_API TreeViewColumn
49 : public Object,
50 public CellLayout
51 {
52 _CLASS_GTKOBJECT(TreeViewColumn, GtkTreeViewColumn, GTK_TREE_VIEW_COLUMN, Object, GObject, , , GTKMM_API)
53 _IMPLEMENTS_INTERFACE(CellLayout)
54 _IGNORE(gtk_tree_view_column_set_cell_data_func)
55 public:
56 typedef TreeViewColumn Column;
57
58 _CTOR_DEFAULT()
59
60 explicit TreeViewColumn(const Glib::ustring& title);
61 TreeViewColumn(const Glib::ustring& title, CellRenderer& cell);
62
63 /** Create a default view column for the given model column type.
64 */
65 template<class T_ModelColumnType>
66 TreeViewColumn(const Glib::ustring& title, const TreeModelColumn<T_ModelColumnType>& column);
67
68 _WRAP_METHOD(void pack_start(CellRenderer& cell, bool expand = true), gtk_tree_view_column_pack_start)
69 _WRAP_METHOD(void pack_end(CellRenderer& cell, bool expand = true), gtk_tree_view_column_pack_end)
70
71 /** Creates an appropriate CellRenderer for the @a column, and packs that cell into the beginning of the column.
72 * If @a expand is <tt>false</tt>, then
73 * the cell is allocated no more space than it needs. Any unused space is divided
74 * evenly between cells for which @a expand is <tt>true</tt>.
75 *
76 * You can use get_first_cell() or get_cells() to access the generated CellRenderer.
77 *
78 * @param column The model column that will be rendered by the view cell.
79 * @param expand <tt>true</tt> if the cell is to be given extra space allocated to the view column.
80 */
81 template<class T_ModelColumnType>
82 void pack_start(const TreeModelColumn<T_ModelColumnType>& column, bool expand = true);
83
84 /** Creates an appropriate CellRenderer for the @a column, and packs that cell at the end of the column.
85 * If @a expand is <tt>false</tt>, then
86 * the cell is allocated no more space than it needs. Any unused space is divided
87 * evenly between cells for which @a expand is <tt>true</tt>.
88 *
89 * You can use get_first_cell() or get_cells() to access the generated CellRenderer.
90 *
91 * @param column The model column that will be rendered by the view cell.
92 * @param expand <tt>true</tt> if the cell is to be given extra space allocated to the view column.
93 */
94 template<class T_ModelColumnType>
95 void pack_end(const TreeModelColumn<T_ModelColumnType>& column, bool expand = true);
96
97 _WRAP_METHOD(void clear(), gtk_tree_view_column_clear)
98
99 _WRAP_METHOD(void add_attribute(CellRenderer& cell_renderer, const Glib::ustring& attribute, int column),
100 gtk_tree_view_column_add_attribute)
101
102 void add_attribute(const Glib::PropertyProxy_Base& property, const TreeModelColumnBase& column);
103
104 void add_attribute(Gtk::CellRenderer& cell, const Glib::ustring& property_name, const TreeModelColumnBase& column);
105 _IGNORE(gtk_tree_view_column_set_attributes)
106
107 /** Associate a view CellRenderer with a model column, so that the CellRenderer renders the data in the model column.
108 *
109 * @param renderer The view cell renderer which will render the model column.
110 * @param column The model column to be renderered by this view.
111 */
112 void set_renderer(Gtk::CellRenderer& renderer, const TreeModelColumnBase& column);
113
114 // _WRAP_METHOD(void set_attributes(CellRenderer& cell_renderer, ...), )
115
116 _DEPRECATE_IFDEF_START
117 /** For instance,
118 * void on_cell_data(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
119 *
120 * This function is used instead of the standard attributes mapping for setting the column value, and should set the
121 * value of the column's cell renderer as appropriate.
122 *
123 * @deprecated Use SlotTreeCellData instead.
124 */
125 typedef sigc::slot<void, CellRenderer*, const Gtk::TreeModel::iterator&> SlotCellData;
126 _DEPRECATE_IFDEF_END
127
128 /** For instance,
129 * void on_cell_data(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter);
130 *
131 * This function is used instead of the standard attributes mapping for setting the column value, and should set the
132 * value of the column's cell renderer as appropriate.
133 */
134 typedef sigc::slot<void, CellRenderer*, const Gtk::TreeModel::iterator&> SlotTreeCellData;
135
136 /** Sets the slot callback to use for the column.
137 * This callback function is used instead of the standard attributes mapping for setting the column value, and should set the
138 * value of the column's cell renderer as appropriate.
139 *
140 * See also unset_cell_data_func().
141 *
142 * @param cell_renderer A Gtk::CellRenderer
143 * @param slot The callback slot to use. Create this with sigc::mem_fun(), or sigc::ptr_fun().
144 */
145 void set_cell_data_func(CellRenderer& cell_renderer, const SlotTreeCellData& slot);
146
147 /** Removes a previously set callback slot. See set_cell_data_func().
148 */
149 void unset_cell_data_func(CellRenderer& cell_renderer);
150
151 _WRAP_METHOD(void clear_attributes(CellRenderer& cell_renderer), gtk_tree_view_column_clear_attributes)
152 _WRAP_METHOD(void set_spacing(int spacing), gtk_tree_view_column_set_spacing)
153 _WRAP_METHOD(int get_spacing() const, gtk_tree_view_column_get_spacing)
154 _WRAP_METHOD(void set_visible(bool visible = true), gtk_tree_view_column_set_visible)
155 _WRAP_METHOD(bool get_visible() const, gtk_tree_view_column_get_visible)
156 _WRAP_METHOD(void set_resizable(bool resizable = true), gtk_tree_view_column_set_resizable)
157 _WRAP_METHOD(bool get_resizable() const, gtk_tree_view_column_get_resizable)
158 _WRAP_METHOD(void set_sizing(TreeViewColumnSizing type), gtk_tree_view_column_set_sizing)
159 _WRAP_METHOD(TreeViewColumnSizing get_sizing(), gtk_tree_view_column_get_sizing)
160 _WRAP_METHOD(int get_x_offset() const, gtk_tree_view_column_get_x_offset)
161 _WRAP_METHOD(int get_width() const, gtk_tree_view_column_get_width)
162 _WRAP_METHOD(int get_fixed_width() const, gtk_tree_view_column_get_fixed_width)
163 _WRAP_METHOD(void set_fixed_width(int fixed_width), gtk_tree_view_column_set_fixed_width)
164 _WRAP_METHOD(void set_min_width(int min_width), gtk_tree_view_column_set_min_width)
165 _WRAP_METHOD(int get_min_width() const, gtk_tree_view_column_get_min_width)
166 _WRAP_METHOD(void set_max_width(int max_width), gtk_tree_view_column_set_max_width)
167 _WRAP_METHOD(int get_max_width() const, gtk_tree_view_column_get_max_width)
168 _WRAP_METHOD(void clicked(), gtk_tree_view_column_clicked)
169
170 _WRAP_METHOD(void set_title(const Glib::ustring& title), gtk_tree_view_column_set_title)
171 _WRAP_METHOD(Glib::ustring get_title() const, gtk_tree_view_column_get_title)
172
173 _WRAP_METHOD(void set_expand(bool expand = true), gtk_tree_view_column_set_expand)
174 _WRAP_METHOD(bool get_expand() const, gtk_tree_view_column_get_expand)
175
176 _WRAP_METHOD(void set_clickable(bool clickable = true), gtk_tree_view_column_set_clickable)
177 _WRAP_METHOD(bool get_clickable() const, gtk_tree_view_column_get_clickable)
178 _WRAP_METHOD(void set_widget(Gtk::Widget& widget), gtk_tree_view_column_set_widget)
179 _WRAP_METHOD(Widget* get_widget(), gtk_tree_view_column_get_widget)
180 _WRAP_METHOD(const Widget* get_widget() const, gtk_tree_view_column_get_widget)
181
182 _WRAP_METHOD(void set_alignment(float xalign), gtk_tree_view_column_set_alignment)
183 _WRAP_METHOD(void set_alignment(Align xalign), gtk_tree_view_column_set_alignment)
184
185 _WRAP_METHOD(float get_alignment() const, gtk_tree_view_column_get_alignment)
186 _WRAP_METHOD(void set_reorderable(bool reorderable = true), gtk_tree_view_column_set_reorderable)
187 _WRAP_METHOD(bool get_reorderable() const, gtk_tree_view_column_get_reorderable)
188
189 _WRAP_METHOD(void set_sort_column(const TreeModelColumnBase& sort_column_id), gtk_tree_view_column_set_sort_column_id)
190 _WRAP_METHOD(void set_sort_column(int sort_column_id), gtk_tree_view_column_set_sort_column_id)
191
192 _WRAP_METHOD(int get_sort_column_id() const, gtk_tree_view_column_get_sort_column_id)
193 _WRAP_METHOD(void set_sort_indicator(bool setting), gtk_tree_view_column_set_sort_indicator)
194 _WRAP_METHOD(bool get_sort_indicator() const, gtk_tree_view_column_get_sort_indicator)
195 _WRAP_METHOD(void set_sort_order(SortType order), gtk_tree_view_column_set_sort_order)
196 _WRAP_METHOD(SortType get_sort_order() const, gtk_tree_view_column_get_sort_order)
197
198
199 _WRAP_METHOD(void cell_set_cell_data(const Glib::RefPtr<TreeModel>& tree_model, const TreeModel::iterator& iter, bool is_expander, bool is_expanded), gtk_tree_view_column_cell_set_cell_data)
200
201 //TODO: cell_area can be NULL. Add a method overload.
202 //But see http://bugzilla.gnome.org/show_bug.cgi?id=542329 about the lack of C documentation.
203 _WRAP_METHOD(void cell_get_size(const Gdk::Rectangle& cell_area, int& x_offset, int& y_offset, int& width, int& height) const, gtk_tree_view_column_cell_get_size)
204
205 _WRAP_METHOD(bool cell_is_visible() const, gtk_tree_view_column_cell_is_visible)
206 _WRAP_METHOD(void focus_cell(CellRenderer& cell), gtk_tree_view_column_focus_cell)
207
208 _WRAP_METHOD(bool get_cell_position(const CellRenderer& cell_renderer, int& start_pos, int& width) const, gtk_tree_view_column_cell_get_position)
209 _WRAP_METHOD(void queue_resize(), gtk_tree_view_column_queue_resize)
210
211 _WRAP_METHOD(TreeView* get_tree_view(), gtk_tree_view_column_get_tree_view, refreturn)
212 _WRAP_METHOD(const TreeView* get_tree_view() const, gtk_tree_view_column_get_tree_view, refreturn, constversion)
213
214 _WRAP_METHOD(Button* get_button(), gtk_tree_view_column_get_button, refreturn)
215 _WRAP_METHOD(const Button* get_button() const, gtk_tree_view_column_get_button, refreturn, constversion)
216
217 _WRAP_SIGNAL(void clicked(), "clicked")
218
219 _WRAP_PROPERTY("visible", bool)
220 _WRAP_PROPERTY("resizable", bool)
221 _WRAP_PROPERTY("x-offset", int)
222 _WRAP_PROPERTY("width", int)
223 _WRAP_PROPERTY("spacing", int)
224 _WRAP_PROPERTY("sizing", TreeViewColumnSizing)
225 _WRAP_PROPERTY("fixed-width", int)
226 _WRAP_PROPERTY("min-width", int)
227 _WRAP_PROPERTY("max-width", int)
228 _WRAP_PROPERTY("title", Glib::ustring)
229 _WRAP_PROPERTY("expand", bool)
230 _WRAP_PROPERTY("clickable", bool)
231 _WRAP_PROPERTY("widget", Widget*)
232 _WRAP_PROPERTY("alignment", float)
233 _WRAP_PROPERTY("reorderable", bool)
234 _WRAP_PROPERTY("sort-indicator", bool)
235 _WRAP_PROPERTY("sort-order", SortType)
236 _WRAP_PROPERTY("sort-column-id", int)
237 _WRAP_PROPERTY("cell-area", Glib::RefPtr<CellArea>)
238
239 #ifndef DOXYGEN_SHOULD_SKIP_THIS
240 private:
241 // Only necessary because of the templated ctor, see below.
242 static const Glib::Class& class_init_();
243 #endif //DOXYGEN_SHOULD_SKIP_THIS
244 };
245
246 #ifndef DOXYGEN_SHOULD_SKIP_THIS
247
248 template<class T_ModelColumnType> inline
249 void TreeViewColumn::pack_start(const TreeModelColumn<T_ModelColumnType>& column, bool expand)
250 {
251 //Generate appropriate Renderer for the column:
252 CellRenderer* pCellRenderer = manage( CellRenderer_Generation::generate_cellrenderer<T_ModelColumnType>() );
253
254 //Use the renderer:
255 pack_start(*pCellRenderer, expand);
256 set_renderer(*pCellRenderer, column);
257 }
258
259 template<class T_ModelColumnType> inline
260 void TreeViewColumn::pack_end(const TreeModelColumn<T_ModelColumnType>& column, bool expand)
261 {
262 //Generate appropriate Renderer for the column:
263 CellRenderer* pCellRenderer= manage( CellRenderer_Generation::generate_cellrenderer<T_ModelColumnType>() );
264
265 //Use the renderer:
266 pack_end(*pCellRenderer, expand);
267 set_renderer(*pCellRenderer, column);
268 }
269
270 template <class T_ModelColumnType> inline
271 TreeViewColumn::TreeViewColumn(const Glib::ustring& title,
272 const TreeModelColumn<T_ModelColumnType>& column)
273 :
274 Glib::ObjectBase(nullptr), // not (yet) a custom class
275 Gtk::Object(Glib::ConstructParams(class_init_(), "title", title.c_str(), nullptr))
276 {
277 pack_start(column, true /* expand */);
278 }
279
280 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
281
282 } // namespace Gtk