Debian Codegraph @

gtk/src/treeview.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 <vector>
22
23 #include <gtkmm/container.h>
24 #include <gtkmm/treeviewcolumn.h>
25 #include <gtkmm/treeselection.h>
26 #include <gtkmm/treemodelcolumn.h>
27 #include <gtkmm/cellrenderer.h>
28 #include <gtkmm/scrollable.h>
29 #include <gtkmm/targetentry.h>
30 #include <gtkmm/entry.h>
31 #include <gtkmm/tooltip.h>
32
33 _DEFS(gtkmm,gtk)
34 _PINCLUDE(gtkmm/private/container_p.h)
35
36 namespace Gtk
37 {
38
39 _CC_INCLUDE(gtk/gtk.h)
40 _WRAP_ENUM(TreeViewDropPosition, GtkTreeViewDropPosition, decl_prefix GTKMM_API)
41 _WRAP_ENUM(TreeViewGridLines, GtkTreeViewGridLines, decl_prefix GTKMM_API)
42
43
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45
46 class GTKMM_API TreeView;
47
48 namespace TreeView_Private
49 {
50 /* This helper function is not a member of TreeView just for the reason that
51 * there are compilers that have problems compiling it otherwise. E.g. in gcc
52 * 2.95.3 a compiler bug prevents member functions from refering to specialized
53 * member function templates and that's what we do here: In function
54 * _connect_auto_store_editable_signal_handler we build a slot from
55 * TreeView::_auto_store_on_cellrenderer_*_edited. (The latter must be member
56 * functions of TreeView since we connect them to signals and we want the
57 * connections to vanish when the TreeView dies, of course.)
58 */
59 template <class ColumnType> inline
60 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<ColumnType>& model_column);
61
62 template <class ColumnType> inline
63 void _connect_auto_store_numeric_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<ColumnType>& model_column);
64
65 template<class ColumnType> inline
66 void _auto_store_on_cellrenderer_text_edited_string(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
67
68 template <class ColumnType> inline
69 void _auto_store_on_cellrenderer_text_edited_numerical(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
70
71 template <class ColumnType> inline
72 void _auto_cell_data_func(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter, int model_column, const Glib::ustring& format);
73 }
74
75 #endif //DOXYGEN_SHOULD_SKIP_THIS
76
77
78 //class GTKMM_API TreeViewColumn;
79 class GTKMM_API TreeModel;
80
81 /** @defgroup TreeView TreeView Classes
82 * These classes are used with the Gtk::TreeView widget.
83 */
84
85 /** The TreeView widget displays the model (Gtk::TreeModel) data and allows the user to interact with it.
86 * The View can show all of the model's columns, or just some, and it can show them in various ways.
87 * You must provide the TreeModel in the constructor, or with set_model().
88 *
89 * Add View columns with append_column(), append_column_editable(), append_column_numeric(),
90 * append_column_numeric_editable(), insert_column(), or insert_column_editable().
91 *
92 * You can manipulate the selection by obtaining the @link Gtk::TreeSelection Gtk::TreeView::Selection@endlink from get_selection().
93 *
94 * @ingroup Widgets
95 * @ingroup Containers
96 * @ingroup TreeView
97 */
98 class GTKMM_API TreeView
99 : public Container,
100 public Scrollable
101 {
102 _CLASS_GTKOBJECT(TreeView, GtkTreeView, GTK_TREE_VIEW, Gtk::Container, GtkContainer, , , GTKMM_API)
103 _IMPLEMENTS_INTERFACE(Scrollable)
104 _IGNORE(gtk_tree_view_get_path_at_pos, gtk_tree_view_set_destroy_count_func, gtk_tree_view_get_cursor
105 gtk_tree_view_insert_column_with_data_func, gtk_tree_view_get_drag_dest_row, gtk_tree_view_get_dest_row_at_pos)
106 public:
107 /** A visible column in a Gtk::TreeView widget.
108 */
109 typedef TreeViewColumn Column;
110
111 /** A selection object for Gtk::TreeView.
112 */
113 typedef TreeSelection Selection;
114
115 /** Default constructor.
116 */
117 _CTOR_DEFAULT()
118
119 /**
120 Constructor that binds to a TreeModel.
121 */
122 _WRAP_CTOR(TreeView(const Glib::RefPtr<TreeModel>& model), gtk_tree_view_new_with_model)
123
124 _WRAP_METHOD(Glib::RefPtr<TreeModel> get_model(), gtk_tree_view_get_model, refreturn)
125 _WRAP_METHOD(Glib::RefPtr<const TreeModel> get_model() const, gtk_tree_view_get_model, refreturn)
126 _WRAP_METHOD(void set_model(const Glib::RefPtr<TreeModel>& model), gtk_tree_view_set_model)
127
128 /** Remove the model from the TreeView.
129 *
130 * @see set_model().
131 *
132 * @newin{2,8}
133 */
134 void unset_model();
135
136 _WRAP_METHOD(Glib::RefPtr<TreeSelection> get_selection(), gtk_tree_view_get_selection, refreturn)
137 _WRAP_METHOD(Glib::RefPtr<const TreeSelection> get_selection() const, gtk_tree_view_get_selection, refreturn, constversion)
138 _IGNORE(gtk_tree_view_get_hadjustment, gtk_tree_view_get_vadjustment,
139 gtk_tree_view_set_hadjustment, gtk_tree_view_set_vadjustment) //deprecated
140
141 _WRAP_METHOD(bool get_headers_visible() const, gtk_tree_view_get_headers_visible)
142 _WRAP_METHOD(void set_headers_visible(bool headers_visible = true), gtk_tree_view_set_headers_visible)
143 _WRAP_METHOD(void columns_autosize(), gtk_tree_view_columns_autosize)
144 _WRAP_METHOD(bool get_headers_clickable() const, gtk_tree_view_get_headers_clickable)
145 _WRAP_METHOD(void set_headers_clickable(bool setting = true), gtk_tree_view_set_headers_clickable)
146 _WRAP_METHOD(void set_rules_hint(bool setting = true), gtk_tree_view_set_rules_hint, deprecated "Don't use this API. There is no replacement.")
147 _WRAP_METHOD(bool get_rules_hint() const, gtk_tree_view_get_rules_hint, deprecated "Don't use this API. There is no replacement.")
148
149 _WRAP_METHOD(void set_activate_on_single_click(bool single = true), gtk_tree_view_set_activate_on_single_click)
150 _WRAP_METHOD(bool get_activate_on_single_click() const, gtk_tree_view_get_activate_on_single_click)
151
152 _WRAP_METHOD(int append_column(TreeViewColumn& column), gtk_tree_view_append_column)
153
154 /** Appends a View column with the appropriate CellRenderer for the Model column.
155 *
156 * The CellRenderer can only be created automatically for some basic
157 * column types, such as Glib::ustring, int, double, bool, and Gdk::Pixbuf.
158 * If the type is not supported then the following warning will be shown:
159 * GLib-GObject-WARNING **: unable to set property `text' of type
160 * `gchararray' from value of type `glibmm__CustomBoxed_t'.
161 *
162 * If the default formatting is not sufficient, or the numeric type is
163 * not supported, then you could use append_column_numeric(). Or you
164 * could create the TreeView::Column and/or CellRenderer
165 * manually and use TreeViewColumn::set_cell_data_func() to provide a callback
166 * that converts the model value into a string representation with .
167 *
168 * The returned value is useful, for example, for connecting the column renderer signal to
169 * a slot:
170 * @code
171 * int Ncolumns = mTreeView.append_column("Column Title", mColumns.mName);
172 * auto renderer =
173 * dynamic_cast<Gtk::CellRendererText*>(mTreeView.get_column_cell_renderer(Ncolumns-1));
174 * renderer->signal_edited().connect(sigc::mem_fun(*this, &MyWindow::on_name_edited));
175 * @endcode
176 *
177 * @param title The text to be used in the title header of this column.
178 * @param model_column The column in the TreeModel that will be rendered by this View column.
179 * @result The number of columns in the View after appending.
180 */
181 template <class ColumnType> inline
182 int append_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column);
183
184 /** Like append_column(), but only for numeric types, which will be displayed in the specified format.
185 * This convenience template uses TreeView::Column::set_cell_data_func(), so the numeric formatting will
186 * be deactivated if you specify your own cell_data callback by calling set_cell_data_func() again.
187 *
188 * @param title The text to be used in the title header of this column.
189 * @param model_column The column in the TreeModel that will be rendered by this View column.
190 * @param format A printf-style format, such as "%d", used to create a text representation of the number.
191 * @result The number of columns in the View after appending.
192 */
193 template <class ColumnType> inline
194 int append_column_numeric(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format);
195
196 //TODO: danielk suggested use of Glib::Value to simplify/improve this.
197 /** Appends a View column with the appropriate CellRenderer for the Model
198 * column. The compiler will attempt to instantiate appropriate template
199 * code to automatically store user changes in the model. To intercept the
200 * user's change and implement non-default logic, or if the compiler can't
201 * instantiate appropriate code for your model type, you could use
202 * append_column() and connect a signal handler to the CellRenderer.
203 *
204 * @see append_column_numeric_editable().
205 *
206 * @param title The text to be used in the title header of this column.
207 * @param model_column The column in the TreeModel that will be rendered by this View column.
208 * @result The number of columns in the View after appending.
209 */
210 template <class ColumnType> inline
211 int append_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column);
212
213 /** Like append_column_editable(), but only for numeric types, which will be displayed in the specified format.
214 * This convenience template uses TreeView::Column::set_cell_data_func(), so the numeric formatting will
215 * be deactivated if you specify your own cell_data callback by calling set_cell_data_func() again.
216 *
217 * Note that the user's input will be interpreted as decimal (base 10), regardless of the @a format.
218 *
219 * @param title The text to be used in the title header of this column.
220 * @param model_column The column in the TreeModel that will be rendered by this View column.
221 * @param format A printf-style format, such as "%d", used to create a text representation of the number.
222 * @result The number of columns in the View after appending.
223 */
224 template <class ColumnType> inline
225 int append_column_numeric_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format);
226
227
228 /// Creates a View column containing the CellRenderer, and appends it.
229 int append_column(const Glib::ustring& title, CellRenderer& cell);
230
231 _WRAP_METHOD(int remove_column(TreeViewColumn& column), gtk_tree_view_remove_column)
232
233 /// Removes all View columns.
234 void remove_all_columns();
235
236 _WRAP_METHOD(int insert_column(TreeViewColumn& column, int position), gtk_tree_view_insert_column)
237
238 /** Creates a View column containing the CellRenderer, and inserts it.
239 *
240 * @param title The text to be used in the title header of this column.
241 * @param cell The CellRenderer.
242 * @param position The position at which the CellRenderer should be inserted.
243 * @result The number of columns in the View after inserting.
244 */
245 int insert_column(const Glib::ustring& title, CellRenderer& cell, int position);
246
247 _IGNORE(gtk_tree_view_insert_column_with_attributes)
248
249 /** Inserts a View column with the appropriate CellRenderer for the Model column.
250 *
251 * @param title The text to be used in the title header of this column.
252 * @param model_column The column in the TreeModel that will be rendered by this View column.
253 * @param position The position at which the CellRenderer should be inserted.
254 * @result The number of columns in the View after inserting.
255 */
256 template <class ColumnType> inline
257 int insert_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position);
258
259 /** Inserts a View column with the appropriate CellRenderer for the Model
260 * column. The compiler will attempt to instantiate appropriate template
261 * code to automatically store user changes in the model. To intercept the
262 * user's change and implement non-default logic, or if the compiler can't
263 * instantiate appropriate code for your model type, you should use
264 * insert_column() and connect a signal handler to the CellRenderer.
265 *
266 * @param title The text to be used in the title header of this column.
267 * @param model_column The column in the TreeModel that will be rendered by this View column.
268 * @param position The position at which the CellRenderer should be inserted.
269 * @result The number of columns in the View after inserting.
270 */
271 template <class ColumnType> inline
272 int insert_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position);
273
274 _DEPRECATE_IFDEF_START
275 /** @deprecated Use SlotTreeCellData instead.
276 */
277 typedef TreeViewColumn::SlotCellData SlotCellData;
278 _DEPRECATE_IFDEF_END
279
280 typedef TreeViewColumn::SlotTreeCellData SlotTreeCellData;
281
282 /**
283 * Inserts a new column into the TreeView with the given cell
284 * renderer and a SlotTreeCellData to set cell renderer attributes
285 * (normally using data from the model).
286 *
287 * @param position Position to insert, -1 for append
288 * @param title column title
289 * @param cell cell renderer for column
290 * @param slot function to set attributes of cell renderer
291 * @return number of columns in the TreeView after the insert
292 */
293 int insert_column_with_data_func(int position, const Glib::ustring& title, CellRenderer& cell, const SlotTreeCellData& slot);
294
295 _WRAP_METHOD(guint get_n_columns() const, gtk_tree_view_get_n_columns)
296
297 _WRAP_METHOD(TreeViewColumn* get_column(int n), gtk_tree_view_get_column)
298 _WRAP_METHOD(const TreeViewColumn* get_column(int n) const, gtk_tree_view_get_column, constversion)
299
300 //The column index is of the view, not the model, so we do not need TreeViewColumn* get_column(TreeViewColumn& base_column).
301
302 /** Gets the CellRenderer for that column.
303 * You should dynamic_cast<> to the expected derived CellRenderer type.
304 * This assumes that the TreeViewColumn contains only one CellRenderer.
305 *
306 * @param n The position of the view column.
307 * @result The CellRenderer.
308 */
309 CellRenderer* get_column_cell_renderer(int n);
310
311 //TODO: Add TreeViewColumn* get_column_cell_renderer(TreeViewColumn& base_column); and a const one.
312
313
314 /** Gets the CellRenderer for that column.
315 * You should dynamic_cast<> to the expected derived CellRenderer type.
316 * This assumes that the TreeViewColumn contains only one CellRenderer.
317 *
318 * @param n The position of the view column.
319 * @result The CellRenderer.
320 */
321 const CellRenderer* get_column_cell_renderer(int n) const;
322
323 #m4 _CONVERSION(`GList*',`std::vector<TreeViewColumn*>',`Glib::ListHandler<TreeViewColumn*>::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
324 _WRAP_METHOD(std::vector<TreeViewColumn*> get_columns(), gtk_tree_view_get_columns)
325 #m4 _CONVERSION(`GList*',`std::vector<const TreeViewColumn*>',`Glib::ListHandler<const TreeViewColumn*>::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
326 _WRAP_METHOD(std::vector<const TreeViewColumn*> get_columns() const, gtk_tree_view_get_columns)
327
328 _WRAP_METHOD(void move_column_after(TreeViewColumn& column, TreeViewColumn& base_column), gtk_tree_view_move_column_after)
329
330 /** This method moves column to the first position in the view.
331 *
332 * @param column The view column that will be moved
333 */
334 void move_column_to_start(TreeViewColumn& column);
335
336 _WRAP_METHOD(void set_expander_column(TreeViewColumn& column), gtk_tree_view_set_expander_column)
337
338 /** This method resets the expander arrow to the default - the first visible column.
339 * @see set_expander_column().
340 */
341 void reset_expander_column();
342
343 _WRAP_METHOD(TreeViewColumn* get_expander_column(), gtk_tree_view_get_expander_column)
344 _WRAP_METHOD(const TreeViewColumn* get_expander_column() const, gtk_tree_view_get_expander_column, constversion)
345
346 /** For instance,
347 * bool on_column_drop(TreeView*, tree_view, TreeViewColumn* column, TreeViewColumn* prev_column, TreeViewColumn* next_column)
348 *
349 * This function is called on every column pair in turn at the beginning of a column drag to determine where a
350 * drop can take place. The arguments passed to the function are: the tree_view, the view Column being dragged,
351 * and the two view Columns determining the drop spot. If either of the view Column arguments for the drop spot
352 * are 0, then they indicate an edge.
353 */
354 typedef sigc::slot<bool, TreeView*, TreeViewColumn*, TreeViewColumn*, TreeViewColumn*> SlotColumnDrop;
355
356 /** Sets a callback slot for determining where a column may be dropped when dragged.
357 * This function is called on every column pair in turn at the beginning of a column drag to determine where a
358 * drop can take place. The arguments passed to the function are: the tree_view, the view Column being dragged,
359 * and the two view Columns determining the drop spot. If either of the view Column arguments for the drop spot
360 * are 0, then they indicate an edge.
361 *
362 * See unset_column_drag_function().
363 *
364 * @param slot A callback function to determine which columns are reorderable.
365 */
366 void set_column_drag_function(const SlotColumnDrop& slot);
367 _IGNORE(gtk_tree_view_set_column_drag_function)
368
369 /** See set_column_drag_function(). After this method has been called, the TreeView reverts to the default behavior of
370 * allowing all columns to be dropped everywhere.
371 */
372 void unset_column_drag_function();
373
374 _WRAP_METHOD(void scroll_to_point(int tree_x, int tree_y), gtk_tree_view_scroll_to_point)
375
376 /** Moves the alignments of tree view to the position specified by @a column and @a path.
377 * @a row_align determines where the row is placed, and @a col_align determines where
378 * column is placed. Both are expected to be between 0.0 and 1.0. 0.0 means left/top
379 * alignment, 1.0 means right/bottom alignment, 0.5 means center.
380 *
381 * This function only works if the model is set, and @a path is a valid row on the model.
382 * If the model changes before the tree view is realized, the centered path will be
383 * modified to reflect this change.
384 *
385 * @param path The path of the row to move to.
386 * @param column The Gtk::TreeViewColumn to move horizontally to.
387 * @param row_align The vertical alignment of the row specified by @a path.
388 * @param col_align The horizontal alignment of the column specified by @a column.
389 */
390 void scroll_to_cell(const TreeModel::Path& path, TreeViewColumn& column, float row_align, float col_align);
391 _IGNORE(gtk_tree_view_scroll_to_cell)
392
393 /** Moves the alignments of tree view to the position specified by @a column and @a path.
394 * The tree does the minimum amount of work to scroll the cell onto the screen. This means
395 * that the cell will be scrolled to the edge closest to it's current position. If the cell
396 * is currently visible on the screen, nothing is done.
397 *
398 * This function only works if the model is set, and @a path is a valid row on the model.
399 * If the model changes before the tree_view is realized, the centered path will be modified
400 * to reflect this change.
401 *
402 * @param path The path of the row to move to.
403 * @param column The Gtk::TreeViewColumn to move horizontally to.
404 */
405 void scroll_to_cell(const TreeModel::Path& path, TreeViewColumn& column);
406
407 /** Moves the alignments of tree view to the position specified by @a path.
408 * @a row_align determines where the row is placed, and is expected to be between 0.0
409 * and 1.0. 0.0 means top alignment, 1.0 means bottom alignment, 0.5 means center.
410 *
411 * This function only works if the model is set, and @a path is a valid row on the model.
412 * If the model changes before the tree view is realized, the centered path will be
413 * modified to reflect this change.
414 *
415 * @param path The path of the row to move to.
416 * @param row_align The vertical alignment of the row specified by @a path.
417 */
418 void scroll_to_row(const TreeModel::Path& path, float row_align);
419
420 /** Moves the alignments of tree view to the position specified by @a path.
421 * The tree does the minimum amount of work to scroll the row onto the screen. This means
422 * that the row will be scrolled to the edge closest to it's current position. If the row
423 * is currently visible on the screen, nothing is done.
424 *
425 * This function only works if the model is set, and @a path is a valid row on the model.
426 * If the model changes before the tree view is realized, the centered path will be
427 * modified to reflect this change.
428 *
429 * @param path The path of the row to move to.
430 */
431 void scroll_to_row(const TreeModel::Path& path);
432
433 /** Moves the alignments of tree view to the position specified by @a column.
434 * @a col_align determines where the column is placed, and is expected to be between 0.0
435 * and 1.0. 0.0 means left alignment, 1.0 means right alignment, 0.5 means center.
436 *
437 * This function only works if the model is set. If the model changes before the tree
438 * view is realized, the centered path will be modified to reflect this change.
439 *
440 * @param column The Gtk::TreeViewColumn to move horizontally to.
441 * @param col_align The horizontal alignment of the column specified by @a column.
442 */
443 void scroll_to_column(TreeViewColumn& column, float col_align);
444
445 /** Moves the alignments of tree view to the position specified by @a column.
446 * The tree does the minimum amount of work to scroll the column onto the screen. This means
447 * that the column will be scrolled to the edge closest to it's current position. If the column
448 * is currently visible on the screen, nothing is done.
449 *
450 * This function only works if the model is set. If the model changes before the
451 * tree view is realized, the centered path will be modified to reflect this change.
452 *
453 * @param column The Gtk::TreeViewColumn to move horizontally to.
454 */
455 void scroll_to_column(TreeViewColumn& column);
456
457 _WRAP_METHOD(void row_activated(const TreeModel::Path& path,TreeViewColumn& column), gtk_tree_view_row_activated)
458 _WRAP_METHOD(void expand_all(), gtk_tree_view_expand_all)
459 _WRAP_METHOD(void collapse_all(), gtk_tree_view_collapse_all)
460 _WRAP_METHOD(void expand_to_path(const TreeModel::Path& path), gtk_tree_view_expand_to_path)
461 _WRAP_METHOD(bool expand_row(const TreeModel::Path& path, bool open_all), gtk_tree_view_expand_row)
462 _WRAP_METHOD(bool collapse_row(const TreeModel::Path& path), gtk_tree_view_collapse_row)
463
464 /** For example,
465 * void on_map_expanded_rows(TreeView* tree_view, const TreeModel::Path& path);
466 */
467 typedef sigc::slot<void, TreeView*, const TreeModel::Path&> SlotMapping;
468
469 /** Calls the callback slot on all expanded rows.
470 * @param slot A callback function to be called.
471 */
472 void map_expanded_rows(const SlotMapping& slot);
473 _IGNORE(gtk_tree_view_map_expanded_rows)
474
475 _WRAP_METHOD(bool row_expanded(const TreeModel::Path& path), gtk_tree_view_row_expanded)
476 _WRAP_METHOD(void set_reorderable(bool reorderable = true), gtk_tree_view_set_reorderable)
477 _WRAP_METHOD(bool get_reorderable() const, gtk_tree_view_get_reorderable)
478
479 //TODO: Add set_cursor(path, ModelColumnBase&, start_editing)?
480 _WRAP_METHOD(void set_cursor(const TreeModel::Path& path, TreeViewColumn& focus_column, bool start_editing = false), gtk_tree_view_set_cursor)
481
482 _WRAP_METHOD(void set_cursor(const TreeModel::Path& path, TreeViewColumn& focus_column, CellRenderer& focus_cell, bool start_editing = false), gtk_tree_view_set_cursor_on_cell)
483
484
485 /** Sets the current keyboard focus to be at path , and selects it.
486 * This is useful when you want to focus the user's attention on a particular row.
487 * This function is often followed by Gtk::widget::grab_focus(tree_view)
488 * in order to give keyboard focus to the widget.
489 *
490 * @param path A reference to cursor path.
491 */
492 void set_cursor(const TreeModel::Path& path);
493
494 /** Fills in path and focus_column with the current path and focus column.
495 *
496 * @param path A reference to be filled with the current cursor path
497 * @param focus_column A reference to be filled with the current focus column
498 */
499 void get_cursor(TreeModel::Path& path, TreeViewColumn*& focus_column);
500
501 /* Layout information */
502 _WRAP_METHOD(Glib::RefPtr<Gdk::Window> get_bin_window(), gtk_tree_view_get_bin_window, refreturn)
503 _WRAP_METHOD(Glib::RefPtr<const Gdk::Window> get_bin_window() const, gtk_tree_view_get_bin_window, refreturn, constversion)
504
505 /** Finds the path at the point (@a x, @a y), relative to bin_window coordinates
506 * (please see get_bin_window()).
507 * That is, @a x and @a y are relative to an events coordinates. @a x and @a y must
508 * come from an event on the TreeView only where event->window ==
509 * get_bin_window(). It is primarily for
510 * things like popup menus. @a path will be filled
511 * with the TreeModel::Path at that point. @a column will be filled
512 * with the column at that point. @a cell_x and @a cell_y return the coordinates
513 * relative to the cell background (i.e. the background_area passed to
514 * Gtk::CellRenderer::render()). This method is only meaningful if
515 * the TreeView is realized.
516 *
517 * For converting widget coordinates (eg. the ones you get from
518 * Widget::property_query_tooltip()), please see
519 * convert_widget_to_bin_window_coords().
520 *
521 * @param x The x position to be identified (relative to bin_window).
522 * @param y The y position to be identified (relative to bin_window).
523 * @param path A reference to a TreeModel::Path to be filled in
524 * @param column A reference to a TreeViewColumn pointer to be filled in
525 * @param cell_x A reference where the X coordinate relative to the cell
526 * can be placed
527 * @param cell_y A reference where the Y coordinate relative to the cell
528 * can be placed
529 * @return true if a row exists at that coordinate.
530 *
531 * @newin{2,8}
532 */
533 bool get_path_at_pos(int x, int y, TreeModel::Path& path, TreeViewColumn*& column, int& cell_x, int& cell_y) const;
534
535 /** Finds the path at the point (@a x, @a y), relative to bin_window coordinates
536 * (please see get_bin_window()).
537 * That is, @a x and @a y are relative to an events coordinates. @a x and @a y must
538 * come from an event on the TreeView only where event->window ==
539 * get_bin_window(). It is primarily for
540 * things like popup menus. @a path will be filled
541 * with the TreeModel::Path at that point.
542 * This method is only meaningful if the TreeView is realized.
543 *
544 * For converting widget coordinates (eg. the ones you get from
545 * Widget::property_query_tooltip()), please see
546 * convert_widget_to_bin_window_coords().
547 *
548 * @param x The x position to be identified (relative to bin_window).
549 * @param y The y position to be identified (relative to bin_window).
550 * @param path A reference to a TreeModel::Path to be filled in
551 * @return true if a row exists at that coordinate.
552 *
553 * newin{2,16}
554 */
555 bool get_path_at_pos(int x, int y, TreeModel::Path& path) const;
556
557 //We ignore the fact that one of the arguments can be 0 - it does not seem useful.
558 _WRAP_METHOD(void get_cell_area(const TreeModel::Path& path, TreeViewColumn& column, Gdk::Rectangle& rect) const, gtk_tree_view_get_cell_area)
559
560 _WRAP_METHOD(void get_background_area(const TreeModel::Path& path, TreeViewColumn& column, Gdk::Rectangle& rect) const, gtk_tree_view_get_background_area)
561 //We ignore the fact that one of the arguments can be 0 - it does not seem useful.
562
563 _WRAP_METHOD(void get_visible_rect(Gdk::Rectangle& visible_rect) const, gtk_tree_view_get_visible_rect)
564
565 bool get_visible_range(TreeModel::Path& start_path, TreeModel::Path& end_path) const;
566 _IGNORE(gtk_tree_view_get_visible_range)
567
568 //TODO: Documentation
569 bool is_blank_at_pos(int x, int y, TreePath& path, TreeViewColumn*& column, int& cell_x, int& cell_y) const;
570 _IGNORE(gtk_tree_view_is_blank_at_pos)
571
572 //TODO: Documentation
573 bool is_blank_at_pos(int x, int y) const;
574
575
576 /* Drag-and-Drop support */
577 _IGNORE(gtk_tree_view_enable_model_drag_source)
578
579 /**
580 * Turns the TreeView into a drag source for automatic DND.
581 *
582 * @param targets Standard container of targets that the drag will support.
583 * @param start_button_mask Mask of allowed buttons to start drag.
584 * @param actions The bitmask of possible actions for a drag from this widget.
585 */
586 void enable_model_drag_source(const std::vector<TargetEntry>& targets,
587 Gdk::ModifierType start_button_mask = Gdk::MODIFIER_MASK,
588 Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
589
590 // Uses the default "GTK_TREE_MODEL_ROW" target, which the TreeView can handle automatically.
591
592 /** Turns the TreeView into a drag source for automatic DND.
593 *
594 * @param start_button_mask Mask of allowed buttons to start drag.
595 * @param actions The bitmask of possible actions for a drag from this widget.
596 */
597 void enable_model_drag_source(Gdk::ModifierType start_button_mask = Gdk::MODIFIER_MASK,
598 Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
599
600 _IGNORE(gtk_tree_view_enable_model_drag_dest)
601
602 /** Turns the TreeView into a drop destination for automatic DND.
603 *
604 * @param targets The table of targets that the drag will support.
605 * @param actions The bitmask of possible actions for a drag from this widget.
606 */
607 void enable_model_drag_dest(const std::vector<TargetEntry>& targets, Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
608
609 /** Turns the TreeView into a drop destination for automatic DND. This uses the default
610 * "GTK_TREE_MODEL_ROW" target, which the TreeView can handle automatically.
611 *
612 * @param actions The bitmask of possible actions for a drag from this widget.
613 */
614 void enable_model_drag_dest(Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
615
616 /** Undoes the effect of enable_model_drag_source()
617 */
618 _WRAP_METHOD(void unset_rows_drag_source(), gtk_tree_view_unset_rows_drag_source)
619
620 /** Undoes the effect of enable_model_drag_dest()
621 */
622 _WRAP_METHOD(void unset_rows_drag_dest(), gtk_tree_view_unset_rows_drag_dest)
623
624
625 /* These are useful to implement your own custom stuff. */
626
627 /** Sets the row that is highlighted for feedback.
628 * See also unset_drag_dest_row().
629 *
630 * @param path The path of the row to highlight
631 * @param pos Specifies whether to drop before, after or into the row
632 */
633 _WRAP_METHOD(void set_drag_dest_row(const TreeModel::Path& path, TreeViewDropPosition pos), gtk_tree_view_set_drag_dest_row)
634
635 /** Remove an existing highlight.
636 * See set_drag_dest_row().
637 *
638 * @newin{3,2}
639 */
640 void unset_drag_dest_row();
641
642 /** Gets information about the row that is highlighted for feedback.
643 *
644 * @param path Return location for the path of the highlighted row
645 * @param pos Return location for the drop position
646 */
647 void get_drag_dest_row(TreeModel::Path& path, TreeViewDropPosition& pos) const;
648
649 /** Determines the destination row for a given position.
650 *
651 * @param drag_x The x position to determine the destination row for
652 * @param drag_y The y position to determine the destination row for
653 * @param path Return location for the path of the highlighted row
654 * @param pos Return location for the drop position
655 */
656 bool get_dest_row_at_pos(int drag_x, int drag_y, TreeModel::Path& path, TreeViewDropPosition& pos) const;
657
658 #m4 _CONVERSION(`cairo_surface_t*',`Cairo::RefPtr<Cairo::Surface>',`Cairo::RefPtr<Cairo::Surface>(new Cairo::Surface($3, true /* take reference */))')
659 _WRAP_METHOD(Cairo::RefPtr<Cairo::Surface> create_row_drag_icon(const TreeModel::Path& path) const, gtk_tree_view_create_row_drag_icon)
660
661 /* Interactive search */
662 _WRAP_METHOD(void set_enable_search(bool enable_search = true), gtk_tree_view_set_enable_search)
663 _WRAP_METHOD(bool get_enable_search() const, gtk_tree_view_get_enable_search)
664 _WRAP_METHOD(int get_search_column() const, gtk_tree_view_get_search_column)
665 _WRAP_METHOD(void set_search_column(const TreeModelColumnBase& column), gtk_tree_view_set_search_column)
666 _WRAP_METHOD(void set_search_column(int column), gtk_tree_view_set_search_column)
667
668 ///void on_search_equal(const Glib::RefPtr<TreeModel>& model, int column, const Glib::ustring& key, const TreeModel::iterator& iter)
669 typedef sigc::slot<bool, const Glib::RefPtr<TreeModel>&, int, const Glib::ustring&, const TreeModel::iterator&> SlotSearchEqual;
670 //SlotSearchEqual get_search_equal_func();
671 _IGNORE(gtk_tree_view_get_search_equal_func)
672
673 /** Sets the compare function for the interactive search capabilities.
674 *
675 * @param slot The compare function to use during the search
676 */
677 void set_search_equal_func(const SlotSearchEqual& slot);
678 _IGNORE(gtk_tree_view_set_search_equal_func)
679
680 _WRAP_METHOD(Entry* get_search_entry(), gtk_tree_view_get_search_entry)
681 _WRAP_METHOD(const Entry* get_search_entry() const, gtk_tree_view_get_search_entry, constversion)
682 _WRAP_METHOD(void set_search_entry(Entry& entry), gtk_tree_view_set_search_entry)
683
684 ///void on_search_position(Gtk::Widget* search_dialog)
685 typedef sigc::slot<void, Gtk::Widget* /* search_dialog */> SlotSearchPosition;
686 void set_search_position_func(const SlotSearchPosition& slot);
687 _IGNORE(gtk_tree_view_get_search_position_func, gtk_tree_view_set_search_position_func)
688
689 _WRAP_METHOD(void convert_widget_to_tree_coords(int wx, int wy, int& tx, int& ty) const, gtk_tree_view_convert_widget_to_tree_coords)
690 _WRAP_METHOD(void convert_tree_to_widget_coords(int tx, int ty, int& wx, int& wy) const, gtk_tree_view_convert_tree_to_widget_coords)
691 _WRAP_METHOD(void convert_widget_to_bin_window_coords(int wx, int wy, int& bx, int& by) const, gtk_tree_view_convert_widget_to_bin_window_coords)
692 _WRAP_METHOD(void convert_bin_window_to_widget_coords(int bx, int by, int& wx, int& wy) const, gtk_tree_view_convert_bin_window_to_widget_coords)
693 _WRAP_METHOD(void convert_tree_to_bin_window_coords(int tx, int ty, int& bx, int& by) const, gtk_tree_view_convert_tree_to_bin_window_coords)
694 _WRAP_METHOD(void convert_bin_window_to_tree_coords(int bx, int by, int& tx, int& ty) const, gtk_tree_view_convert_bin_window_to_tree_coords)
695
696
697 _WRAP_METHOD(void set_fixed_height_mode(bool enable = true), gtk_tree_view_set_fixed_height_mode)
698 _WRAP_METHOD(bool get_fixed_height_mode() const, gtk_tree_view_get_fixed_height_mode)
699 _WRAP_METHOD(void set_hover_selection(bool hover = true), gtk_tree_view_set_hover_selection)
700 _WRAP_METHOD(bool get_hover_selection() const, gtk_tree_view_get_hover_selection)
701 _WRAP_METHOD(void set_hover_expand(bool expand = true), gtk_tree_view_set_hover_expand)
702 _WRAP_METHOD(bool get_hover_expand() const, gtk_tree_view_get_hover_expand)
703 _WRAP_METHOD(void set_rubber_banding(bool enable = true), gtk_tree_view_set_rubber_banding)
704 _WRAP_METHOD(bool get_rubber_banding() const, gtk_tree_view_get_rubber_banding)
705
706 //TODO: Rename to get_is?
707 _WRAP_METHOD(bool is_rubber_banding_active() const, gtk_tree_view_is_rubber_banding_active)
708
709 /** The slot type for determining whether the row pointed to by the iterator should be rendered as a separator.
710 * Return true if the row is a separator.
711 * A common way to implement this is to have a boolean column in the model, whose values the slot returns.
712 *
713 * For instance,
714 * bool on_row_separator(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::iterator& iter);
715 */
716 typedef sigc::slot<bool, const Glib::RefPtr<TreeModel>&, const TreeModel::iterator&> SlotRowSeparator;
717
718 /** Sets the row separator function, which is used to determine whether a row should be drawn as a separator.
719 */
720 void set_row_separator_func(const SlotRowSeparator& slot);
721 _IGNORE(gtk_tree_view_set_row_separator_func, gtk_tree_view_get_row_separator_func)
722
723 /** Removes the row separator function, so no separators are drawn.
724 * See set_row_separator_func().
725 *
726 * @newin{3,2}
727 */
728 void unset_row_separator_func();
729
730 _WRAP_METHOD(void set_grid_lines(TreeViewGridLines grid_lines), gtk_tree_view_set_grid_lines)
731 _WRAP_METHOD(TreeViewGridLines get_grid_lines() const, gtk_tree_view_get_grid_lines)
732
733 _WRAP_METHOD(void set_enable_tree_lines(bool enable = true), gtk_tree_view_set_enable_tree_lines)
734 _WRAP_METHOD(bool get_enable_tree_lines() const, gtk_tree_view_get_enable_tree_lines)
735
736 _WRAP_METHOD(void set_show_expanders(bool enabled = true), gtk_tree_view_set_show_expanders)
737 _WRAP_METHOD(bool get_show_expanders() const, gtk_tree_view_get_show_expanders)
738 _WRAP_METHOD(void set_level_indentation(int indentation), gtk_tree_view_set_level_indentation)
739 _WRAP_METHOD(int get_level_indentation() const, gtk_tree_view_get_level_indentation)
740
741 _WRAP_METHOD(void set_tooltip_row(const Glib::RefPtr<Tooltip>& tooltip, const TreePath& path), gtk_tree_view_set_tooltip_row)
742
743 //Note that we use pointers instead of references because any one of the 3 arguments may be NULL, and we don't want that many method overloads:
744 #m4 _CONVERSION(`const TreeModel::Path*',`GtkTreePath*',`(($3) ? const_cast<GtkTreePath*>(($3)->gobj()) : nullptr)')
745 _WRAP_METHOD(void set_tooltip_cell(const Glib::RefPtr<Tooltip>& tooltip, const TreeModel::Path* path, TreeViewColumn* column, CellRenderer* cell), gtk_tree_view_set_tooltip_cell)
746
747 _IGNORE(gtk_tree_view_get_tooltip_context)
748
749 /**
750 * @param x: the x coordinate (relative to widget coordinates)
751 * @param y: the y coordinate (relative to widget coordinates)
752 * @param keyboard_tip: whether this is a keyboard tooltip or not
753 * @param path: a reference to receive a Gtk::TreePath
754 *
755 * This function is supposed to be used in a Gtk::Widget::query-tooltip
756 * signal handler for Gtk::TreeView. The x, y and keyboard_tip values
757 * which are received in the signal handler, should be passed to this
758 * function without modification.
759 *
760 * The return value indicates whether there is an tree view row at the given
761 * coordinates (true) or not (false) for mouse tooltips. For keyboard
762 * tooltips the row returned will be the cursor item. When true, then the
763 * path which has been provided will be set to point to
764 * that row and the corresponding model. x and y will always be converted
765 * to be relative to Gtk::TreeView's bin_window if keyboard_tooltip is false.
766 *
767 * Return value: whether or not the given tooltip context points to a row.
768 *
769 * @newin{2,12}
770 */
771 bool get_tooltip_context_path(int& x, int& y,
772 bool keyboard_tip,
773 TreeModel::Path& path);
774
775 /**
776 * @param x: the x coordinate (relative to widget coordinates)
777 * @param y: the y coordinate (relative to widget coordinates)
778 * @param keyboard_tip: whether this is a keyboard tooltip or not
779 * @param iter: a pointer to receive a Gtk::TreeIter
780 *
781 * This function is supposed to be used in a Gtk::Widget::query-tooltip
782 * signal handler for Gtk::TreeView. The x, y and keyboard_tip values
783 * which are received in the signal handler, should be passed to this
784 * function without modification.
785 *
786 * The return value indicates whether there is an tree view row at the given
787 * coordinates (true) or not (false) for mouse tooltips. For keyboard
788 * tooltips the row returned will be the cursor item. When true, then the
789 * iter which has been provided will be set to point to
790 * that row and the corresponding model. x and y will always be converted
791 * to be relative to Gtk::TreeView's bin_window if keyboard_tooltip is false.
792 *
793 * Return value: whether or not the given tooltip context points to a row.
794 *
795 * @newin{2,12}
796 */
797 bool get_tooltip_context_iter(int& x, int& y,
798 bool keyboard_tip,
799 Gtk::TreeModel::iterator& iter);
800
801 _WRAP_METHOD(void set_tooltip_column(int column), gtk_tree_view_set_tooltip_column)
802 _WRAP_METHOD(int get_tooltip_column() const, gtk_tree_view_get_tooltip_column)
803
804 #m4begin
805 dnl // We need this special conversion here since the C++ Gtk::TreeIter carries
806 dnl // a pointer to the Gtk::TreeModel, whereas the plain GtkTreeIter struct does
807 dnl // not. Fortunately we can use the `self' parameter to get our hands on the
808 dnl // GtkTreeModel*.
809 _CONVERSION(`GtkTreeIter*',`const TreeModel::iterator&',`TreeModel::iterator(gtk_tree_view_get_model(self), $3)')
810 #m4end
811
812 _WRAP_SIGNAL(void row_activated(const TreeModel::Path& path, TreeViewColumn* column) , "row-activated")
813 _WRAP_SIGNAL(bool test_expand_row(const TreeModel::iterator& iter, const TreeModel::Path& path), "test-expand-row")
814 _WRAP_SIGNAL(bool test_collapse_row(const TreeModel::iterator& iter, const TreeModel::Path& path), "test-collapse-row")
815 _WRAP_SIGNAL(void row_expanded(const TreeModel::iterator& iter, const TreeModel::Path& path), "row-expanded")
816 _WRAP_SIGNAL(void row_collapsed(const TreeModel::iterator& iter, const TreeModel::Path& path), "row-collapsed")
817 _WRAP_SIGNAL(void cursor_changed(), "cursor-changed")
818 _WRAP_SIGNAL(void columns_changed(), "columns-changed")
819
820 //Don't wrap these. They are keybinding signals, and their API broke for GTK+ 2.2.
821 _IGNORE_SIGNAL("move-cursor")
822 _IGNORE_SIGNAL("select-all")
823 _IGNORE_SIGNAL("unselect-all")
824 _IGNORE_SIGNAL("select-cursor-row")
825 _IGNORE_SIGNAL("toggle-cursor-row")
826 _IGNORE_SIGNAL("expand-collapse-cursor-row")
827 _IGNORE_SIGNAL("select-cursor-parent")
828 _IGNORE_SIGNAL("start-interactive-search")
829
830
831 _WRAP_PROPERTY("model", Glib::RefPtr<TreeModel>)
832 _WRAP_PROPERTY("headers-visible", bool)
833 _WRAP_PROPERTY("headers-clickable", bool)
834 _WRAP_PROPERTY("expander-column", TreeViewColumn*)
835 _WRAP_PROPERTY("reorderable", bool)
836 _WRAP_PROPERTY("rules-hint", bool, deprecated "Don't use this API. There is no replacement.")
837 _WRAP_PROPERTY("enable-search", bool)
838 _WRAP_PROPERTY("search-column", int)
839 _WRAP_PROPERTY("fixed-height-mode", bool)
840 _WRAP_PROPERTY("hover-selection", bool)
841 _WRAP_PROPERTY("hover-expand", bool)
842 _WRAP_PROPERTY("show-expanders", bool)
843 _WRAP_PROPERTY("level-indentation", bool)
844 _WRAP_PROPERTY("rubber-banding", bool)
845 _WRAP_PROPERTY("enable-grid-lines", bool)
846 _WRAP_PROPERTY("enable-tree-lines", bool)
847 _WRAP_PROPERTY("tooltip-column", int)
848 _WRAP_PROPERTY("activate-on-single-click", bool)
849
850 protected:
851
852 #ifndef DOXYGEN_SHOULD_SKIP_THIS
853 template<class ColumnType> friend
854 void _auto_store_on_cellrenderer_text_edited_string(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
855
856 template <class ColumnType> friend
857 void _auto_store_on_cellrenderer_text_edited_numerical(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
858
859 void _auto_store_on_cellrenderer_toggle_edited_with_model(const Glib::ustring& path_string, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
860
861 // This is no longer used, but we must keep it to prevent linker errors with already-compiled applications,
862 // For instance, applications that were compiled with the older versions of the templates that did use this method.
863 // TODO: Remove this when we can break API.
864 void _auto_store_on_cellrenderer_toggle_edited(const Glib::ustring& path_string, int model_column);
865
866 template<class ColumnType> friend
867 void TreeView_Private::_connect_auto_store_editable_signal_handler(TreeView*, CellRenderer*, const TreeModelColumn<ColumnType>&);
868
869 #endif //DOXYGEN_SHOULD_SKIP_THIS
870 };
871
872
873
874 template <class ColumnType> inline
875 int TreeView::append_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column)
876 {
877 // compilation will fail if there is no appropriate TreeViewColumn
878 // constructor for this model column type.
879 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
880
881 return append_column(*pViewColumn);
882 }
883
884 //This is here because sigc::bind once did not work on all platforms, but now it does..
885 #define GTKMM_HAVE_SIGC_BIND 1
886
887 #ifdef GTKMM_HAVE_SIGC_BIND
888
889 template <class ColumnType> inline
890 int TreeView::append_column_numeric(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format)
891 {
892 TreeViewColumn* const pViewColumn = Gtk::manage( new TreeViewColumn(title) );
893
894 //Use a CellRendererText:
895 //We don't use TreeView::Column::append_column(model_column) to generate an appropriate CellRenderer,
896 //because that uses set_renderer(), which renders the model value using the automatic glib "transformations" (number-string conversions). As well as being unnecessary here, those automatic conversions can't handle all numeric types.
897 CellRenderer* pCellRenderer = manage( new CellRendererText() );
898 pViewColumn->pack_start(*pCellRenderer);
899
900
901 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
902 typedef void (*type_fptr)(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter, int model_column, const Glib::ustring& format);
903 type_fptr fptr = TreeView_Private::_auto_cell_data_func<ColumnType>;
904
905 //Connect a cell_data callback, to show the number's text representation in the specified format:
906 //We use sigc::bind<-1> twice here, instead of sigc::bind() once, because some compilers need the extra hint.
907 Gtk::TreeViewColumn::SlotTreeCellData slot = sigc::bind<-1>(
908 sigc::bind<-1>( sigc::ptr_fun(fptr), format),
909 model_column.index()
910 );
911
912 pViewColumn->set_cell_data_func(*pCellRenderer, slot);
913
914 return append_column(*pViewColumn);
915 }
916
917 #endif //GTKMM_HAVE_SIGC_BIND
918
919 template <class ColumnType> inline
920 int TreeView::append_column_numeric_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format)
921 {
922 int cols_count = append_column_numeric(title, model_column, format);
923
924 //connect signal handlers for auto-storing of edited cell data
925 //Note: This will only work for base-10 (decimal) formatted numbers:
926 CellRenderer *const cell = get_column_cell_renderer(cols_count - 1);
927 if(cell)
928 {
929 TreeView_Private::_connect_auto_store_numeric_editable_signal_handler<ColumnType>(this, cell, model_column);
930 }
931
932 return cols_count;
933 }
934
935 template <class ColumnType> inline
936 int TreeView::append_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column)
937 {
938 //Don't use this in a header, because it gives warnings when disabled: g_assert(model_column.type() != 0);
939
940 // compilation will fail if there is no appropriate TreeViewColumn
941 // constructor for this model column type.
942 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
943
944 //connect signal handlers for auto-storing of edited cell data
945 CellRenderer* pCellRender = pViewColumn->get_first_cell();
946 TreeView_Private::_connect_auto_store_editable_signal_handler<ColumnType>(this, pCellRender, model_column);
947
948 return append_column(*pViewColumn);
949 }
950
951 template <class ColumnType> inline
952 int TreeView::insert_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position)
953 {
954 // compilation will fail if there is no appropriate TreeViewColumn
955 // constructor for this model column type.
956 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
957
958 return insert_column(*pViewColumn, position);
959 }
960
961 template <class ColumnType> inline
962 int TreeView::insert_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position)
963 {
964 // compilation will fail if there is no appropriate TreeViewColumn
965 // constructor for this model column type.
966 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
967
968 //connect signal handlers for auto-storing of edited cell data
969 CellRenderer* pCellRender = pViewColumn->get_first_cell();
970 TreeView_Private::_connect_auto_store_editable_signal_handler(this, pCellRender, model_column);
971
972 return insert_column(*pViewColumn, position);
973 }
974
975
976 #ifndef DOXYGEN_SHOULD_SKIP_THIS
977 namespace TreeView_Private
978 {
979
980 //Template specializations, for different model column types:
981 //TODO: Move these specializations into the .ccg file - I tried, but the int specialization was not used by the compiler. murrayc.
982
983 // append_column_editable<>() and insert_column_editable<>() call template function
984 // _connect_auto_store_editable_signal_handler<ColumnType>().
985 // There are 3 versions of _connect_auto_store_editable_signal_handler<>():
986 //
987 // 1. The default version for string data. It connects
988 // CellRendererText::signal_edited() to template function
989 // _auto_store_on_cellrenderer_text_edited_string<ColumnType>().
990 //
991 // 2. A bool specialization. It connects CellRendererToggle::signal_toggled()
992 // to function _auto_store_on_cellrenderer_toggle_edited_with_model().
993 //
994 // 3. Several identical (except for the type name) specializations for numeric data.
995 // They call _connect_auto_store_numeric_editable_signal_handler<ColumnType>(),
996 // which connects CellRendererText::signal_edited() to template function
997 // _auto_store_on_cellrenderer_text_edited_numerical<ColumnType>().
998 //
999 // We need all those specializations with identical implementations, because we
1000 // chose to avoid multiple specializations for the string types by dealing with
1001 // string types in the default implementation.
1002 //
1003 // With these numeric specializations append_column_editable<>() and
1004 // insert_column_editable<>() can be used for the same numeric types as
1005 // append_column<>() and insert_column<>(). Those are fundamental types in the
1006 // GType system, and Glib registers conversion functions from those types to
1007 // gchararray with g_value_register_transform_func().
1008 // 'short' is not one of those types. It can be handled only by
1009 // append_column_numeric<>() and append_column_numeric_editable<>().
1010
1011 #ifdef GTKMM_HAVE_SIGC_BIND
1012
1013 //bool specialization:
1014 template<> inline
1015 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<bool>& model_column)
1016 {
1017 Gtk::CellRendererToggle* pCellToggle = dynamic_cast<Gtk::CellRendererToggle*>(pCellRenderer);
1018 if(pCellToggle)
1019 {
1020 //Set the appropriate property,
1021 pCellToggle->property_activatable() = true;
1022
1023 //Connect to the appropriate signal, sending the model_column too
1024
1025 sigc::slot<void, const Glib::ustring&, int> slot_temp =
1026 sigc::bind<-1>(
1027 sigc::mem_fun(*this_p, &Gtk::TreeView::_auto_store_on_cellrenderer_toggle_edited_with_model),
1028 this_p->get_model()
1029 );
1030
1031 pCellToggle->signal_toggled().connect(
1032 sigc::bind<-1>(
1033 slot_temp,
1034 model_column.index()
1035 )
1036 );
1037
1038 //We use bind<1> instead of bind because some compilers need the extra hint.
1039 }
1040 }
1041
1042 //int specialization:
1043 template<> inline
1044 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<int>& model_column)
1045 {
1046 _connect_auto_store_numeric_editable_signal_handler<int>(this_p, pCellRenderer, model_column);
1047 }
1048
1049 //unsigned int specialization:
1050 template<> inline
1051 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<unsigned int>& model_column)
1052 {
1053 _connect_auto_store_numeric_editable_signal_handler<unsigned int>(this_p, pCellRenderer, model_column);
1054 }
1055
1056 //long specialization:
1057 template<> inline
1058 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<long>& model_column)
1059 {
1060 _connect_auto_store_numeric_editable_signal_handler<long>(this_p, pCellRenderer, model_column);
1061 }
1062
1063 //unsigned long specialization:
1064 template<> inline
1065 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<unsigned long>& model_column)
1066 {
1067 _connect_auto_store_numeric_editable_signal_handler<unsigned long>(this_p, pCellRenderer, model_column);
1068 }
1069
1070 //float specialization:
1071 template<> inline
1072 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<float>& model_column)
1073 {
1074 _connect_auto_store_numeric_editable_signal_handler<float>(this_p, pCellRenderer, model_column);
1075 }
1076
1077 //double specialization:
1078 template<> inline
1079 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<double>& model_column)
1080 {
1081 _connect_auto_store_numeric_editable_signal_handler<double>(this_p, pCellRenderer, model_column);
1082 }
1083
1084 #endif //GTKMM_HAVE_SIGC_BIND
1085
1086 } // namespace TreeView_Private
1087 #endif //DOXYGEN_SHOULD_SKIP_THIS
1088
1089
1090 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1091 namespace TreeView_Private
1092 {
1093
1094 #ifdef GTKMM_HAVE_SIGC_BIND
1095
1096 template <class ColumnType> inline
1097 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<ColumnType>& model_column)
1098 {
1099 //Don't use this in a header, because it gives warnings when disabled: g_assert(model_column.type() != 0);
1100
1101 //The different CellRenderers have different "edited" signals,
1102 //and numerical values need to convert the text value to a number,
1103 //so there are specializations for this template.
1104
1105 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
1106
1107 //Set the appropriate property,
1108 //and connect to the appropriate signal, sending the model_column too,
1109 if(pCellText)
1110 {
1111 pCellText->property_editable() = true;
1112
1113 //Some compilers (IRIX MipsPro) don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1114 typedef void (*type_func)(const Glib::ustring&, const Glib::ustring&, int, const Glib::RefPtr<Gtk::TreeModel>&);
1115 type_func func = &(Gtk::TreeView_Private::_auto_store_on_cellrenderer_text_edited_string<ColumnType>);
1116 sigc::slot<void, const Glib::ustring&, const Glib::ustring&, int, const Glib::RefPtr<Gtk::TreeModel>&> theslot =
1117 sigc::ptr_fun(func);
1118
1119 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1120 pCellText->signal_edited().connect(
1121 sigc::bind<-1>(
1122 sigc::bind<-1>( theslot, this_p->get_model()),
1123 model_column.index()
1124 )
1125 );
1126 }
1127 }
1128
1129 template<class ColumnType> inline
1130 void _connect_auto_store_numeric_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<ColumnType>& model_column)
1131 {
1132 //The different CellRenderers have different "edited" signals,
1133 //and numerical values need to convert the text value to a number.
1134
1135 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
1136 if(pCellText)
1137 {
1138 //Set the appropriate property.
1139 pCellText->property_editable() = true;
1140
1141 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1142 typedef void (*type_fptr)(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
1143 type_fptr fptr = _auto_store_on_cellrenderer_text_edited_numerical<ColumnType>;
1144
1145 //Connect to the appropriate signal, sending the model_column too.
1146 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1147 pCellText->signal_edited().connect(
1148 sigc::bind<-1>(
1149 sigc::bind<-1>(
1150 sigc::ptr_fun(fptr),
1151 this_p->get_model() ),
1152 model_column.index()
1153 )
1154 );
1155 }
1156 }
1157
1158 #endif //GTKMM_HAVE_SIGC_BIND
1159
1160 template <class ColumnType> inline
1161 void _auto_store_on_cellrenderer_text_edited_string(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model)
1162 {
1163 Gtk::TreePath path(path_string);
1164
1165 //Get the row from the path:
1166 if(model)
1167 {
1168 Gtk::TreeModel::iterator iter = model->get_iter(path);
1169 if(iter)
1170 {
1171 //Store the user's new text in the model:
1172 Gtk::TreeRow row = *iter;
1173 row.set_value(model_column, (ColumnType)new_text);
1174 }
1175 }
1176 }
1177
1178 template <class ColumnType> inline
1179 void _auto_store_on_cellrenderer_text_edited_numerical(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model)
1180 {
1181 //This is used on numerical model columns:
1182
1183 Gtk::TreePath path(path_string);
1184
1185 //Get the row from the path:
1186 if(model)
1187 {
1188 Gtk::TreeModel::iterator iter = model->get_iter(path);
1189 if(iter)
1190 {
1191 //std::istringstream astream(new_text); //Put it in a stream.
1192 //ColumnType new_value = ColumnType();
1193 //new_value << astream; //Get it out of the stream as the numerical type.
1194
1195 //Convert the text to a number, using the same logic used by GtkCellRendererText when it stores numbers.
1196 ColumnType new_value = ColumnType();
1197 try
1198 {
1199 new_value = static_cast<ColumnType>( std::stod(new_text.raw()) );
1200 }
1201 catch(const std::invalid_argument&)
1202 {
1203 //Intentionally ignored.
1204 //Applications can use their own logic if they want to handle invalid input differently.
1205 }
1206
1207 //Store the user's new text in the model:
1208 Gtk::TreeRow row = *iter;
1209 row.set_value(model_column, (ColumnType)new_value);
1210 }
1211 }
1212 }
1213
1214 template <class ColumnType> inline
1215 void _auto_cell_data_func(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter, int model_column, const Glib::ustring& format)
1216 {
1217 Gtk::CellRendererText* pTextRenderer = dynamic_cast<Gtk::CellRendererText*>(cell);
1218 if(!pTextRenderer)
1219 {
1220 g_warning("gtkmm: TextView: append_column_numeric() was used with a non-numeric type.");
1221 }
1222 else
1223 {
1224 if(iter)
1225 {
1226 //Get the value from the model.
1227 Gtk::TreeModel::Row row = *iter;
1228 ColumnType value = ColumnType();
1229 row.get_value(model_column, value);
1230
1231 //Convert it to a string representation:
1232 char buff[20];
1233 int used = g_snprintf(buff, sizeof(buff), format.c_str(), value); //value must be a numeric type.
1234 if(used > 0)
1235 {
1236 //Show the text representation in the view:
1237 pTextRenderer->property_text() = buff;
1238 }
1239 }
1240 }
1241 }
1242
1243 } // namespace TreeView_Private
1244 #endif //DOXYGEN_SHOULD_SKIP_THIS
1245
1246 } // namespace Gtk