1 /* $Id: treeview.hg,v 1.45 2006/06/20 18:46:59 murrayc Exp $ */
3 /* Copyright(C) 2002 The gtkmm Development Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or(at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 // This is for including the config header before any code (such as
21 // the #ifndef GTKMM_DISABLE_DEPRECATED in deprecated classes) is generated:
22 _CONFIGINCLUDE(gtkmmconfig.h)
24 #include <glibmm/listhandle.h>
25 #include <gtkmm/container.h>
26 #include <gtkmm/adjustment.h>
27 #include <gdkmm/pixmap.h>
28 #include <gtkmm/treeviewcolumn.h>
29 #include <gtkmm/treeselection.h>
30 #include <gtkmm/treemodelcolumn.h>
31 #include <gtkmm/cellrenderer.h>
32 #include <gtkmm/targetentry.h>
33 #include <gtkmm/entry.h>
34 #include <gtkmm/tooltip.h>
37 _PINCLUDE(gtkmm/private/container_p.h)
43 _CC_INCLUDE(gtk/gtktypebuiltins.h)
44 _WRAP_ENUM(TreeViewDropPosition, GtkTreeViewDropPosition)
45 _WRAP_ENUM(TreeViewGridLines, GtkTreeViewGridLines)
48 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 namespace TreeView_Private
54 /* This helper function is not a member of TreeView just for the reason that
55 * there are compilers that have problems compiling it otherwise. E.g. in gcc
56 * 2.95.3 a compiler bug prevents member functions from refering to specialized
57 * member function templates and that's what we do here: In function
58 * _connect_auto_store_editable_signal_handler we build a slot from
59 * TreeView::_auto_store_on_cellrenderer_*_edited. (The latter must be member
60 * functions of TreeView since we connect them to signals and we want the
61 * connections to vanish when the TreeView dies, of course.)
63 template <class ColumnType> inline
64 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<ColumnType>& model_column);
66 template<class ColumnType> inline
67 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);
69 template <class ColumnType> inline
70 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);
72 template <class ColumnType> inline
73 void _auto_cell_data_func(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter, int model_column, const Glib::ustring& format);
76 #endif //DOXYGEN_SHOULD_SKIP_THIS
79 //class TreeViewColumn;
82 /** @defgroup TreeView TreeView Classes
83 * These classes are used with the Gtk::TreeView widget.
86 /** The TreeView widget displays the model (Gtk::TreeModel) data and allows the user to interact with it.
87 * The View can show all of the model's columns, or just some, and it can show them in various ways.
88 * You must provide the TreeModel in the constructor, or with set_model().
90 * Add View columns with append_column(), append_column_editable(), insert_column(), or insert_column_editable().
92 * You can manipulate the selection by obtaining the @link Gtk::TreeSelection Gtk::TreeView::Selection@endlink from get_selection().
98 class TreeView : public Container
100 _CLASS_GTKOBJECT(TreeView, GtkTreeView, GTK_TREE_VIEW, Gtk::Container, GtkContainer)
101 _IGNORE(gtk_tree_view_get_path_at_pos, gtk_tree_view_set_destroy_count_func, gtk_tree_view_get_cursor
102 gtk_tree_view_insert_column_with_data_func, gtk_tree_view_get_drag_dest_row, gtk_tree_view_get_dest_row_at_pos)
104 /** A visible column in a Gtk::TreeView widget.
106 typedef TreeViewColumn Column;
108 /** A selection object for Gtk::TreeView.
110 typedef TreeSelection Selection;
116 Constructor that binds to a TreeModel
118 _WRAP_CTOR(TreeView(const Glib::RefPtr<TreeModel>& model), gtk_tree_view_new_with_model)
120 _WRAP_METHOD(Glib::RefPtr<TreeModel> get_model(), gtk_tree_view_get_model, refreturn)
121 _WRAP_METHOD(Glib::RefPtr<const TreeModel> get_model() const, gtk_tree_view_get_model, refreturn)
122 _WRAP_METHOD(void set_model(const Glib::RefPtr<TreeModel>& model), gtk_tree_view_set_model)
124 /** Remove the model from the TreeView.
128 _WRAP_METHOD(Glib::RefPtr<TreeSelection> get_selection(), gtk_tree_view_get_selection, refreturn)
129 _WRAP_METHOD(Glib::RefPtr<const TreeSelection> get_selection() const, gtk_tree_view_get_selection, refreturn, constversion)
130 _WRAP_METHOD(Adjustment* get_hadjustment(), gtk_tree_view_get_hadjustment)
131 _WRAP_METHOD(const Adjustment* get_hadjustment() const, gtk_tree_view_get_hadjustment, constversion)
132 _WRAP_METHOD(void set_hadjustment(Adjustment& adjustment), gtk_tree_view_set_hadjustment)
134 /** This method removes the hadjustment.
135 * @see set_hadjustment().
137 void unset_hadjustment();
139 _WRAP_METHOD(Adjustment* get_vadjustment(), gtk_tree_view_get_vadjustment)
140 _WRAP_METHOD(const Adjustment* get_vadjustment() const, gtk_tree_view_get_vadjustment, constversion)
141 _WRAP_METHOD(void set_vadjustment(Adjustment& adjustment), gtk_tree_view_set_vadjustment)
143 /** This method removes the vadjustment.
144 * @see set_vadjustment().
146 void unset_vadjustment();
148 _WRAP_METHOD(bool get_headers_visible() const, gtk_tree_view_get_headers_visible)
149 _WRAP_METHOD(void set_headers_visible(bool headers_visible), gtk_tree_view_set_headers_visible)
150 _WRAP_METHOD(void columns_autosize(), gtk_tree_view_columns_autosize)
151 _WRAP_METHOD(bool get_headers_clickable() const, gtk_tree_view_get_headers_clickable)
152 _WRAP_METHOD(void set_headers_clickable(bool setting = true), gtk_tree_view_set_headers_clickable)
153 _WRAP_METHOD(void set_rules_hint(bool setting = true), gtk_tree_view_set_rules_hint)
154 _WRAP_METHOD(bool get_rules_hint() const, gtk_tree_view_get_rules_hint)
156 _WRAP_METHOD(int append_column(TreeViewColumn& column), gtk_tree_view_append_column)
158 /** Appends a View column with the appropriate CellRenderer for the Model column.
160 * The CellRenderer can only be created automatically for some basic
161 * column types, such as Glib::ustring, int, double, bool, and Gdk::Pixbuf.
162 * If the type is not supported then the following warning will be shown:
163 * GLib-GObject-WARNING **: unable to set property `text' of type
164 * `gchararray' from value of type `glibmm__CustomBoxed_t'.
166 * If the default formatting is not sufficient, or the numeric type is
167 * not supported, then you could use append_column_numeric(). Or you
168 * could create the TreeView::Column and/or CellRenderer
169 * manually and use TreeViewColumn::set_cell_data_func() to provide a callback
170 * that converts the model value into a string representation with .
172 * @param title The text to be used in the title header of this column.
173 * @param model_column The column in the TreeModel that will be rendered by this View column.
174 * @result The number of columns in the View after appending.
176 template <class ColumnType> inline
177 int append_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column);
179 /** Like append_column(), but only for numeric types, which will be displayed in the specified format.
180 * This convenience template uses TreeView::Column::set_cell_data_func(), so the numeric formatting will
181 * be deactivated if you specify your own cell_data callback by calling set_cell_data_func() again.
183 * @param title The text to be used in the title header of this column.
184 * @param model_column The column in the TreeModel that will be rendered by this View column.
185 * @param format A printf-style format, such as "%d", used to create a text representation of the number.
186 * @result The number of columns in the View after appending.
188 template <class ColumnType> inline
189 int append_column_numeric(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format);
191 //TODO: danielk suggested use of Glib::Value to simplify/improve this.
192 /** Appends a View column with the appropriate CellRenderer for the Model
193 * column. The compiler will attempt to instantiate appropriate template
194 * code to automatically store user changes in the model. To intercept the
195 * user's change and implement non-default logic, or if the compiler can't
196 * instantiate appropriate code for your model type, you could use
197 * append_column() and connect a signal handler to the CellRenderer.
199 * @see append_column_numeric_editable().
201 * @param title The text to be used in the title header of this column.
202 * @param model_column The column in the TreeModel that will be rendered by this View column.
203 * @result The number of columns in the View after appending.
205 template <class ColumnType> inline
206 int append_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column);
208 /** Like append_column_editable(), but only for numeric types, which will be displayed in the specified format.
209 * This convenience template uses TreeView::Column::set_cell_data_func(), so the numeric formatting will
210 * be deactivated if you specify your own cell_data callback by calling set_cell_data_func() again.
212 * Note that the user's input will be interpreted as decimal (base 10), regardless of the @a format.
214 * @param title The text to be used in the title header of this column.
215 * @param model_column The column in the TreeModel that will be rendered by this View column.
216 * @param format A printf-style format, such as "%d", used to create a text representation of the number.
217 * @result The number of columns in the View after appending.
219 template <class ColumnType> inline
220 int append_column_numeric_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format);
223 /// Creates a View column containing the CellRenderer, and appends it.
224 int append_column(const Glib::ustring& title, CellRenderer& cell);
226 _WRAP_METHOD(int remove_column(TreeViewColumn& column), gtk_tree_view_remove_column)
228 /// Removes all View columns.
229 void remove_all_columns();
231 _WRAP_METHOD(int insert_column(TreeViewColumn& column, int position), gtk_tree_view_insert_column)
233 /** Creates a View column containing the CellRenderer, and inserts it.
235 * @param title The text to be used in the title header of this column.
236 * @param cell The CellRenderer.
237 * @param position The position at which the CellRenderer should be inserted.
238 * @result The number of columns in the View after inserting.
240 int insert_column(const Glib::ustring& title, CellRenderer& cell, int position);
242 _IGNORE(gtk_tree_view_insert_column_with_attributes)
244 /** Inserts a View column with the appropriate CellRenderer for the Model column.
246 * @param title The text to be used in the title header of this column.
247 * @param model_column The column in the TreeModel that will be rendered by this View column.
248 * @param position The position at which the CellRenderer should be inserted.
249 * @result The number of columns in the View after inserting.
251 template <class ColumnType> inline
252 int insert_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position);
254 /** Inserts a View column with the appropriate CellRenderer for the Model
255 * column. The compiler will attempt to instantiate appropriate template
256 * code to automatically store user changes in the model. To intercept the
257 * user's change and implement non-default logic, or if the compiler can't
258 * instantiate appropriate code for your model type, you should use
259 * append_column() and connect a signal handler to the CellRenderer.
261 * @param title The text to be used in the title header of this column.
262 * @param model_column The column in the TreeModel that will be rendered by this View column.
263 * @param position The position at which the CellRenderer should be inserted.
264 * @result The number of columns in the View after inserting.
266 template <class ColumnType> inline
267 int insert_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position);
269 typedef TreeViewColumn::SlotCellData SlotCellData;
272 * Inserts a new column into the TreeView with the given cell
273 * renderer and a SlotCellData to set cell renderer attributes
274 * (normally using data from the model).
276 * @param position Position to insert, -1 for append
277 * @param title column title
278 * @param cell cell renderer for column
279 * @param slot function to set attributes of cell renderer
280 * @return number of columns in the TreeView after the insert
282 int insert_column_with_data_func(int position, const Glib::ustring& title, CellRenderer& cell, const SlotCellData& slot);
284 _WRAP_METHOD(TreeViewColumn* get_column(int n), gtk_tree_view_get_column)
285 _WRAP_METHOD(const TreeViewColumn* get_column(int n) const, gtk_tree_view_get_column, constversion)
287 //The column index is of the view, not the model, so we do not need TreeViewColumn* get_column(TreeViewColumn& base_column).
289 /** Gets the CellRenderer for that column.
290 * You should dynamic_cast<> to the expected derived CellRenderer type.
291 * This assumes that the TreeViewColumn contains only one CellRenderer.
293 * @param n The position of the view column.
294 * @result The CellRenderer.
296 CellRenderer* get_column_cell_renderer(int n);
298 //TODO: Add TreeViewColumn* get_column_cell_renderer(TreeViewColumn& base_column); and a const one.
301 /** Gets the CellRenderer for that column.
302 * You should dynamic_cast<> to the expected derived CellRenderer type.
303 * This assumes that the TreeViewColumn contains only one CellRenderer.
305 * @param n The position of the view column.
306 * @result The CellRenderer.
308 const CellRenderer* get_column_cell_renderer(int n) const;
310 _WRAP_METHOD(Glib::ListHandle<TreeViewColumn*> get_columns(), gtk_tree_view_get_columns)
311 _WRAP_METHOD(Glib::ListHandle<const TreeViewColumn*> get_columns() const, gtk_tree_view_get_columns)
313 _WRAP_METHOD(void move_column_after(TreeViewColumn& column, TreeViewColumn& base_column), gtk_tree_view_move_column_after)
315 /** This method moves column to the first position in the view.
317 * @param column The view column that will be moved
319 void move_column_to_start(TreeViewColumn& column);
321 _WRAP_METHOD(void set_expander_column(TreeViewColumn& column), gtk_tree_view_set_expander_column)
323 /** This method resets the expander arrow to the default - the first visible column.
324 * @see set_expander_column().
326 void reset_expander_column();
328 _WRAP_METHOD(TreeViewColumn* get_expander_column(), gtk_tree_view_get_expander_column)
329 _WRAP_METHOD(const TreeViewColumn* get_expander_column() const, gtk_tree_view_get_expander_column, constversion)
332 * bool on_column_drop(TreeView*, tree_view, TreeViewColumn* column, TreeViewColumn* prev_column, TreeViewColumn* next_column)
334 * This function is called on every column pair in turn at the beginning of a column drag to determine where a
335 * drop can take place. The arguments passed to the function are: the tree_view, the view Column being dragged,
336 * and the two view Columns determining the drop spot. If either of the view Column arguments for the drop spot
337 * are 0, then they indicate an edge.
339 typedef sigc::slot<bool, TreeView*, TreeViewColumn*, TreeViewColumn*, TreeViewColumn*> SlotColumnDrop;
341 /** Sets a callback slot for determining where a column may be dropped when dragged.
342 * This function is called on every column pair in turn at the beginning of a column drag to determine where a
343 * drop can take place. The arguments passed to the function are: the tree_view, the view Column being dragged,
344 * and the two view Columns determining the drop spot. If either of the view Column arguments for the drop spot
345 * are 0, then they indicate an edge.
347 * See unset_column_drag_function().
349 * @param slot A callback function to determine which columns are reorderable.
351 void set_column_drag_function(const SlotColumnDrop& slot);
352 _IGNORE(gtk_tree_view_set_column_drag_function)
354 /** See set_column_drag_function(). After this method has been called, the TreeView reverts to the default behavior of
355 * allowing all columns to be dropped everywhere.
357 void unset_column_drag_function();
359 _WRAP_METHOD(void scroll_to_point(int tree_x, int tree_y), gtk_tree_view_scroll_to_point)
361 /** Moves the alignments of tree view to the position specified by @a column and @a path.
362 * @a row_align determines where the row is placed, and @a col_align determines where
363 * column is placed. Both are expected to be between 0.0 and 1.0. 0.0 means left/top
364 * alignment, 1.0 means right/bottom alignment, 0.5 means center.
366 * This function only works if the model is set, and @a path is a valid row on the model.
367 * If the model changes before the tree view is realized, the centered path will be
368 * modified to reflect this change.
370 * @param path The path of the row to move to.
371 * @param column The Gtk::TreeViewColumn to move horizontally to.
372 * @param row_align The vertical alignment of the row specified by @a path.
373 * @param col_align The horizontal alignment of the column specified by @a column.
375 void scroll_to_cell(const TreeModel::Path& path, TreeViewColumn& column, float row_align, float col_align);
376 _IGNORE(gtk_tree_view_scroll_to_cell)
378 /** Moves the alignments of tree view to the position specified by @a column and @a path.
379 * The tree does the minimum amount of work to scroll the cell onto the screen. This means
380 * that the cell will be scrolled to the edge closest to it's current position. If the cell
381 * is currently visible on the screen, nothing is done.
383 * This function only works if the model is set, and @a path is a valid row on the model.
384 * If the model changes before the tree_view is realized, the centered path will be modified
385 * to reflect this change.
387 * @param path The path of the row to move to.
388 * @param column The Gtk::TreeViewColumn to move horizontally to.
390 void scroll_to_cell(const TreeModel::Path& path, TreeViewColumn& column);
392 /** Moves the alignments of tree view to the position specified by @a path.
393 * @a row_align determines where the row is placed, and is expected to be between 0.0
394 * and 1.0. 0.0 means top alignment, 1.0 means bottom alignment, 0.5 means center.
396 * This function only works if the model is set, and @a path is a valid row on the model.
397 * If the model changes before the tree view is realized, the centered path will be
398 * modified to reflect this change.
400 * @param path The path of the row to move to.
401 * @param row_align The vertical alignment of the row specified by @a path.
403 void scroll_to_row(const TreeModel::Path& path, float row_align);
405 /** Moves the alignments of tree view to the position specified by @a path.
406 * The tree does the minimum amount of work to scroll the row onto the screen. This means
407 * that the row will be scrolled to the edge closest to it's current position. If the row
408 * is currently visible on the screen, nothing is done.
410 * This function only works if the model is set, and @a path is a valid row on the model.
411 * If the model changes before the tree view is realized, the centered path will be
412 * modified to reflect this change.
414 * @param path The path of the row to move to.
416 void scroll_to_row(const TreeModel::Path& path);
418 /** Moves the alignments of tree view to the position specified by @a column.
419 * @a col_align determines where the column is placed, and is expected to be between 0.0
420 * and 1.0. 0.0 means left alignment, 1.0 means right alignment, 0.5 means center.
422 * This function only works if the model is set. If the model changes before the tree
423 * view is realized, the centered path will be modified to reflect this change.
425 * @param column The Gtk::TreeViewColumn to move horizontally to.
426 * @param col_align The horizontal alignment of the column specified by @a column.
428 void scroll_to_column(TreeViewColumn& column, float col_align);
430 /** Moves the alignments of tree view to the position specified by @a column.
431 * The tree does the minimum amount of work to scroll the column onto the screen. This means
432 * that the column will be scrolled to the edge closest to it's current position. If the column
433 * is currently visible on the screen, nothing is done.
435 * This function only works if the model is set. If the model changes before the
436 * tree view is realized, the centered path will be modified to reflect this change.
438 * @param column The Gtk::TreeViewColumn to move horizontally to.
440 void scroll_to_column(TreeViewColumn& column);
442 _WRAP_METHOD(void row_activated(const TreeModel::Path& path,TreeViewColumn& column), gtk_tree_view_row_activated)
443 _WRAP_METHOD(void expand_all(), gtk_tree_view_expand_all)
444 _WRAP_METHOD(void collapse_all(), gtk_tree_view_collapse_all)
445 _WRAP_METHOD(void expand_to_path(const TreeModel::Path& path), gtk_tree_view_expand_to_path)
446 _WRAP_METHOD(bool expand_row(const TreeModel::Path& path, bool open_all), gtk_tree_view_expand_row)
447 _WRAP_METHOD(bool collapse_row(const TreeModel::Path& path), gtk_tree_view_collapse_row)
450 * void on_map_expanded_rows(TreeView* tree_view, const TreeModel::Path& path);
452 typedef sigc::slot<void, TreeView*, const TreeModel::Path&> SlotMapping;
454 /** Calls the callback slot on all expanded rows.
455 * @param slot A callback function to be called.
457 void map_expanded_rows(const SlotMapping& slot);
458 _IGNORE(gtk_tree_view_map_expanded_rows)
460 _WRAP_METHOD(bool row_expanded(const TreeModel::Path& path), gtk_tree_view_row_expanded)
461 _WRAP_METHOD(void set_reorderable(bool reorderable = true), gtk_tree_view_set_reorderable)
462 _WRAP_METHOD(bool get_reorderable() const, gtk_tree_view_get_reorderable)
464 //TODO: Add set_cursor(path, ModelColumnBase&, start_editing)?
465 _WRAP_METHOD(void set_cursor(const TreeModel::Path& path, TreeViewColumn& focus_column, bool start_editing = false), gtk_tree_view_set_cursor)
467 _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)
470 /** Sets the current keyboard focus to be at path , and selects it.
471 * This is useful when you want to focus the user's attention on a particular row.
472 * This function is often followed by Gtk::widget::grab_focus(tree_view)
473 * in order to give keyboard focus to the widget.
475 * @param path A reference to cursor path.
477 void set_cursor(const TreeModel::Path& path);
479 /** Fills in path and focus_column with the current path and focus column.
481 * @param path A reference to be filled with the current cursor path
482 * @param focus_column A reference to be filled with the current focus column
484 void get_cursor(TreeModel::Path& path, TreeViewColumn*& focus_column);
486 /* Layout information */
487 _WRAP_METHOD(Glib::RefPtr<Gdk::Window> get_bin_window(), gtk_tree_view_get_bin_window, refreturn)
488 _WRAP_METHOD(Glib::RefPtr<const Gdk::Window> get_bin_window() const, gtk_tree_view_get_bin_window, refreturn, constversion)
490 _DEPRECATE_IFDEF_START
491 /** @deprecated Use the const version.
493 bool get_path_at_pos(int x, int y, TreeModel::Path& path, TreeViewColumn*& column, int& cell_x, int& cell_y);
496 /** Finds the path at the point (x, y), relative to widget
497 * coordinates. It is primarily for things like popup menus.
499 * @param x The x position to be identified
500 * @param y The y position to be identified
501 * @param path A reference to a TreeModel::Path to be filled in
502 * @param column A reference to a TreeViewColumn pointer to be filled in
503 * @param cell_x A reference where the X coordinate relative to the cell
505 * @param cell_y A reference where the Y coordinate relative to the cell
507 * @return true if a row exists at that coordinate.
509 bool get_path_at_pos(int x, int y, TreeModel::Path& path, TreeViewColumn*& column, int& cell_x, int& cell_y) const;
511 _WRAP_METHOD(void get_cell_area(const TreeModel::Path& path, TreeViewColumn& column, Gdk::Rectangle& rect), gtk_tree_view_get_cell_area, deprecated "Use the const version")
512 //We ignore the fact that one of the arguments can be 0 - it does not seem useful.
514 _WRAP_METHOD(void get_cell_area(const TreeModel::Path& path, TreeViewColumn& column, Gdk::Rectangle& rect) const, gtk_tree_view_get_cell_area)
516 _WRAP_METHOD(void get_background_area(const TreeModel::Path& path, TreeViewColumn& column, Gdk::Rectangle& rect), gtk_tree_view_get_background_area, deprecated "Use the const version.")
517 _WRAP_METHOD(void get_background_area(const TreeModel::Path& path, TreeViewColumn& column, Gdk::Rectangle& rect) const, gtk_tree_view_get_background_area)
518 //We ignore the fact that one of the arguments can be 0 - it does not seem useful.
520 _WRAP_METHOD(void get_visible_rect(Gdk::Rectangle& visible_rect), gtk_tree_view_get_visible_rect, deprecated "Use the const version.")
521 _WRAP_METHOD(void get_visible_rect(Gdk::Rectangle& visible_rect) const, gtk_tree_view_get_visible_rect)
523 _WRAP_METHOD(void widget_to_tree_coords(int wx, int wy, int& tx, int& ty), gtk_tree_view_widget_to_tree_coords, deprecated "Use the const version")
524 _WRAP_METHOD(void widget_to_tree_coords(int wx, int wy, int& tx, int& ty) const, gtk_tree_view_widget_to_tree_coords)
526 _WRAP_METHOD(void tree_to_widget_coords(int tx, int ty, int& wx, int& wy), gtk_tree_view_tree_to_widget_coords, deprecated "Use the const version.")
527 _WRAP_METHOD(void tree_to_widget_coords(int tx, int ty, int& wx, int& wy) const, gtk_tree_view_tree_to_widget_coords)
529 bool get_visible_range(TreeModel::Path& start_path, TreeModel::Path& end_path) const;
530 _IGNORE(gtk_tree_view_get_visible_range)
532 /* Drag-and-Drop support */
533 _IGNORE(gtk_tree_view_enable_model_drag_source)
536 * Turns the TreeView into a drag source for automatic DND.
538 * @param targets Standard container of targets that the drag will support.
539 * @param start_button_mask Mask of allowed buttons to start drag.
540 * @param actions The bitmask of possible actions for a drag from this widget.
542 void enable_model_drag_source(const ArrayHandle_TargetEntry& targets,
543 Gdk::ModifierType start_button_mask = Gdk::MODIFIER_MASK,
544 Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
546 // Uses the default "GTK_TREE_MODEL_ROW" target, which the TreeView can handle automatically.
548 /** Turns the TreeView into a drag source for automatic DND.
550 * @param start_button_mask Mask of allowed buttons to start drag.
551 * @param actions The bitmask of possible actions for a drag from this widget.
553 void enable_model_drag_source(Gdk::ModifierType start_button_mask = Gdk::MODIFIER_MASK,
554 Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
556 _IGNORE(gtk_tree_view_enable_model_drag_dest)
558 /** Turns the TreeView into a drop destination for automatic DND.
560 * @param targets The table of targets that the drag will support.
561 * @param actions The bitmask of possible actions for a drag from this widget.
563 void enable_model_drag_dest(const ArrayHandle_TargetEntry& targets, Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
565 /** Turns the TreeView into a drop destination for automatic DND. This uses the default
566 * "GTK_TREE_MODEL_ROW" target, which the TreeView can handle automatically.
568 * @param actions The bitmask of possible actions for a drag from this widget.
570 void enable_model_drag_dest(Gdk::DragAction actions = Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
572 /** Undoes the effect of enable_model_drag_source()
574 _WRAP_METHOD(void unset_rows_drag_source(), gtk_tree_view_unset_rows_drag_source)
576 /** Undoes the effect of enable_model_drag_source()
578 _WRAP_METHOD(void unset_rows_drag_dest(), gtk_tree_view_unset_rows_drag_dest)
581 /* These are useful to implement your own custom stuff. */
583 /** Sets the row that is highlighted for feedback.
585 * @param path The path of the row to highlight
586 * @param pos Specifies whether to drop before, after or into the row
588 _WRAP_METHOD(void set_drag_dest_row(const TreeModel::Path& path, TreeViewDropPosition pos), gtk_tree_view_set_drag_dest_row)
590 /** Gets information about the row that is highlighted for feedback.
592 * @param path Return location for the path of the highlighted row
593 * @param pos Return location for the drop position
595 void get_drag_dest_row(TreeModel::Path& path, TreeViewDropPosition& pos) const;
597 /** Determines the destination row for a given position.
599 * @param drag_x The x position to determine the destination row for
600 * @param drag_y The y position to determine the destination row for
601 * @param path Return location for the path of the highlighted row
602 * @param pos Return location for the drop position
604 bool get_dest_row_at_pos(int drag_x, int drag_y, TreeModel::Path& path, TreeViewDropPosition& pos) const;
606 _WRAP_METHOD(Glib::RefPtr<Gdk::Pixmap> create_row_drag_icon(const TreeModel::Path& path), gtk_tree_view_create_row_drag_icon)
608 /* Interactive search */
609 _WRAP_METHOD(void set_enable_search(bool enable_search = true), gtk_tree_view_set_enable_search)
610 _WRAP_METHOD(bool get_enable_search() const, gtk_tree_view_get_enable_search)
611 _WRAP_METHOD(int get_search_column() const, gtk_tree_view_get_search_column)
612 _WRAP_METHOD(void set_search_column(const TreeModelColumnBase& column), gtk_tree_view_set_search_column)
613 _WRAP_METHOD(void set_search_column(int column), gtk_tree_view_set_search_column)
615 ///void on_search_equal(const Glib::RefPtr<TreeModel>& model, int column, const Glib::ustring& key, const TreeModel::iterator& iter)
616 typedef sigc::slot<bool, const Glib::RefPtr<TreeModel>&, int, const Glib::ustring&, const TreeModel::iterator&> SlotSearchEqual;
617 //SlotSearchEqual get_search_equal_func();
618 _IGNORE(gtk_tree_view_get_search_equal_func)
620 /** Sets the compare function for the interactive search capabilities.
622 * @param slot The compare function to use during the search
624 void set_search_equal_func(const SlotSearchEqual& slot);
625 _IGNORE(gtk_tree_view_set_search_equal_func)
627 _WRAP_METHOD(Entry* get_search_entry(), gtk_tree_view_get_search_entry)
628 _WRAP_METHOD(const Entry* get_search_entry() const, gtk_tree_view_get_search_entry, constversion)
629 _WRAP_METHOD(void set_search_entry(Entry& entry), gtk_tree_view_set_search_entry)
631 ///void on_search_position(Gtk::Widget* search_dialog)
632 typedef sigc::slot<void, Gtk::Widget* /* search_dialog */> SlotSearchPosition;
633 void set_search_position_func(const SlotSearchPosition& slot);
634 _IGNORE(gtk_tree_view_get_search_position_func, gtk_tree_view_set_search_position_func)
636 _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)
637 _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)
638 _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)
639 _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)
640 _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)
641 _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)
644 _WRAP_METHOD(void set_fixed_height_mode(bool enable = true), gtk_tree_view_set_fixed_height_mode)
645 _WRAP_METHOD(bool get_fixed_height_mode() const, gtk_tree_view_get_fixed_height_mode)
646 _WRAP_METHOD(void set_hover_selection(bool hover = true), gtk_tree_view_set_hover_selection)
647 _WRAP_METHOD(bool get_hover_selection() const, gtk_tree_view_get_hover_selection)
648 _WRAP_METHOD(void set_hover_expand(bool expand = true), gtk_tree_view_set_hover_expand)
649 _WRAP_METHOD(bool get_hover_expand() const, gtk_tree_view_get_hover_expand)
650 _WRAP_METHOD(void set_rubber_banding(bool enable = true), gtk_tree_view_set_rubber_banding)
651 _WRAP_METHOD(bool get_rubber_banding() const, gtk_tree_view_get_rubber_banding)
653 //TODO: Rename to get_is?
654 _WRAP_METHOD(bool is_rubber_banding_active() const, gtk_tree_view_is_rubber_banding_active)
657 * void on_row_separator(const Gtk::TreeModel& model, const Gtk::TreeModel::iterator& iter);
659 typedef sigc::slot<bool, const Glib::RefPtr<TreeModel>&, const TreeModel::iterator&> SlotRowSeparator;
661 void set_row_separator_func(const SlotRowSeparator& slot);
662 _IGNORE(gtk_tree_view_set_row_separator_func, gtk_tree_view_get_row_separator_func)
664 _WRAP_METHOD(void set_grid_lines(TreeViewGridLines grid_lines), gtk_tree_view_set_grid_lines)
665 _WRAP_METHOD(TreeViewGridLines get_grid_lines() const, gtk_tree_view_get_grid_lines)
667 _WRAP_METHOD(void set_enable_tree_lines(bool enable = true), gtk_tree_view_set_enable_tree_lines)
668 _WRAP_METHOD(bool get_enable_tree_lines() const, gtk_tree_view_get_enable_tree_lines)
670 _WRAP_METHOD(void set_show_expanders(bool enabled = true), gtk_tree_view_set_show_expanders)
671 _WRAP_METHOD(bool get_show_expanders() const, gtk_tree_view_get_show_expanders)
672 _WRAP_METHOD(void set_level_indentation(int indentation), gtk_tree_view_set_level_indentation)
673 _WRAP_METHOD(int get_level_indentation() const, gtk_tree_view_get_level_indentation)
675 _WRAP_METHOD(void set_tooltip_row(const Glib::RefPtr<Tooltip>& tooltip, const TreePath& path), gtk_tree_view_set_tooltip_row)
677 //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:
678 #m4 _CONVERSION(`const TreeModel::Path*',`GtkTreePath*',`(($3) ? const_cast<GtkTreePath*>(($3)->gobj()) : 0)')
679 _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)
681 _IGNORE(gtk_tree_view_get_tooltip_context)
684 * @param x: the x coordinate (relative to widget coordinates)
685 * @param y: the y coordinate (relative to widget coordinates)
686 * @param keyboard_tip: whether this is a keyboard tooltip or not
687 * @param path: a reference to receive a Gtk::TreePath
689 * This function is supposed to be used in a Gtk::Widget::query-tooltip
690 * signal handler for Gtk::TreeView. The x, y and keyboard_tip values
691 * which are received in the signal handler, should be passed to this
692 * function without modification.
694 * The return value indicates whether there is an tree view row at the given
695 * coordinates (true) or not (false) for mouse tooltips. For keyboard
696 * tooltips the row returned will be the cursor item. When true, then the
697 * path which has been provided will be set to point to
698 * that row and the corresponding model. x and y will always be converted
699 * to be relative to Gtk::TreeView's bin_window if keyboard_tooltip is false.
701 * Return value: whether or not the given tooltip context points to a row.
705 bool get_tooltip_context_path(int& x, int& y,
707 TreeModel::Path& path);
710 * @param x: the x coordinate (relative to widget coordinates)
711 * @param y: the y coordinate (relative to widget coordinates)
712 * @param keyboard_tip: whether this is a keyboard tooltip or not
713 * @param iter: a pointer to receive a Gtk::TreeIter
715 * This function is supposed to be used in a Gtk::Widget::query-tooltip
716 * signal handler for Gtk::TreeView. The x, y and keyboard_tip values
717 * which are received in the signal handler, should be passed to this
718 * function without modification.
720 * The return value indicates whether there is an tree view row at the given
721 * coordinates (true) or not (false) for mouse tooltips. For keyboard
722 * tooltips the row returned will be the cursor item. When true, then the
723 * iter which has been provided will be set to point to
724 * that row and the corresponding model. x and y will always be converted
725 * to be relative to Gtk::TreeView's bin_window if keyboard_tooltip is false.
727 * Return value: whether or not the given tooltip context points to a row.
731 bool get_tooltip_context_iter(int& x, int& y,
733 Gtk::TreeModel::iterator& iter);
735 _WRAP_METHOD(void set_tooltip_column(int column), gtk_tree_view_set_tooltip_column)
736 _WRAP_METHOD(int get_tooltip_column() const, gtk_tree_view_get_tooltip_column)
740 dnl // We need this special conversion here since the C++ Gtk::TreeIter carries
741 dnl // a pointer to the Gtk::TreeModel, whereas the plain GtkTreeIter struct does
742 dnl // not. Fortunately we can use the `self' parameter to get our hands on the
743 dnl // GtkTreeModel*.
744 _CONVERSION(`GtkTreeIter*',`const TreeModel::iterator&',`TreeModel::iterator(gtk_tree_view_get_model(self), $3)')
747 _WRAP_SIGNAL(void set_scroll_adjustments(Adjustment* hadjustment, Adjustment* vadjustment), "set-scroll-adjustments")
748 _WRAP_SIGNAL(void row_activated(const TreeModel::Path& path, TreeViewColumn* column) , "row-activated")
749 _WRAP_SIGNAL(bool test_expand_row(const TreeModel::iterator& iter, const TreeModel::Path& path), "test-expand-row")
750 _WRAP_SIGNAL(bool test_collapse_row(const TreeModel::iterator& iter, const TreeModel::Path& path), "test-collapse-row")
751 _WRAP_SIGNAL(void row_expanded(const TreeModel::iterator& iter, const TreeModel::Path& path), "row-expanded")
752 _WRAP_SIGNAL(void row_collapsed(const TreeModel::iterator& iter, const TreeModel::Path& path), "row-collapsed")
753 _WRAP_SIGNAL(void cursor_changed(), "cursor-changed")
754 _WRAP_SIGNAL(void columns_changed(), "columns-changed")
756 //Don't wrap these. They are keybinding signals, and their API broke for GTK+ 2.2.
757 _IGNORE_SIGNAL("move-cursor")
758 _IGNORE_SIGNAL("select-all")
759 _IGNORE_SIGNAL("unselect-all")
760 _IGNORE_SIGNAL("select-cursor-row")
761 _IGNORE_SIGNAL("toggle-cursor-row")
762 _IGNORE_SIGNAL("expand-collapse-cursor-row")
763 _IGNORE_SIGNAL("select-cursor-parent")
764 _IGNORE_SIGNAL("start-interactive-search")
767 _WRAP_PROPERTY("model", Glib::RefPtr<TreeModel>)
768 _WRAP_PROPERTY("hadjustment", Adjustment*)
769 _WRAP_PROPERTY("vadjustment", Adjustment*)
770 _WRAP_PROPERTY("headers-visible", bool)
771 _WRAP_PROPERTY("headers-clickable", bool)
772 _WRAP_PROPERTY("expander-column", TreeViewColumn*)
773 _WRAP_PROPERTY("reorderable", bool)
774 _WRAP_PROPERTY("rules-hint", bool)
775 _WRAP_PROPERTY("enable-search", bool)
776 _WRAP_PROPERTY("search-column", int)
777 _WRAP_PROPERTY("fixed-height-mode", bool)
778 _WRAP_PROPERTY("hover-selection", bool)
779 _WRAP_PROPERTY("hover-expand", bool)
780 _WRAP_PROPERTY("show-expanders", bool)
781 _WRAP_PROPERTY("level-indentation", bool)
782 _WRAP_PROPERTY("rubber-banding", bool)
783 _WRAP_PROPERTY("enable-grid-lines", bool)
784 _WRAP_PROPERTY("enable-tree-lines", bool)
786 /// Get the treeview's model, but actually get the child model if it's a TreeModelFilter.
787 Glib::RefPtr<Gtk::TreeModel> _get_base_model();
791 #ifndef DOXYGEN_SHOULD_SKIP_THIS
792 template<class ColumnType> friend
793 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);
795 template <class ColumnType> friend
796 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);
798 void _auto_store_on_cellrenderer_toggle_edited_with_model(const Glib::ustring& path_string, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
800 // This is no longer used, but we must keep it to prevent linker errors with already-compiled applications,
801 // For instance, applications that were compiled with the older versions of the templates that did use this method.
802 // TODO: Remove this when we can break API.
803 void _auto_store_on_cellrenderer_toggle_edited(const Glib::ustring& path_string, int model_column);
805 template<class ColumnType> friend
806 void TreeView_Private::_connect_auto_store_editable_signal_handler(TreeView*, CellRenderer*, const TreeModelColumn<ColumnType>&);
808 #endif //DOXYGEN_SHOULD_SKIP_THIS
813 template <class ColumnType> inline
814 int TreeView::append_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column)
816 // compilation will fail if there is no appropriate TreeViewColumn
817 // constructor for this model column type.
818 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
820 return append_column(*pViewColumn);
823 //This is here because sigc::bind once did not work on all platforms, but now it does..
824 #define GTKMM_HAVE_SIGC_BIND 1
826 #ifdef GTKMM_HAVE_SIGC_BIND
828 template <class ColumnType> inline
829 int TreeView::append_column_numeric(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format)
831 TreeViewColumn* const pViewColumn = Gtk::manage( new TreeViewColumn(title) );
833 //Use a CellRendererText:
834 //We don't use TreeView::Column::append_column(model_column) to generate an appropriate CellRenderer,
835 //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.
836 CellRenderer* pCellRenderer = manage( new CellRendererText() );
837 pViewColumn->pack_start(*pCellRenderer);
840 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
841 typedef void (*type_fptr)(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter, int model_column, const Glib::ustring& format);
842 type_fptr fptr = TreeView_Private::_auto_cell_data_func<ColumnType>;
844 //Connect a cell_data callback, to show the number's text representation in the specified format:
845 //We use sigc::bind<-1> twice here, instead of sigc::bind() once, because some compilers need the extra hint.
846 Gtk::TreeViewColumn::SlotCellData slot = sigc::bind<-1>(
847 sigc::bind<-1>( sigc::ptr_fun(fptr), format),
851 pViewColumn->set_cell_data_func(*pCellRenderer, slot);
853 return append_column(*pViewColumn);
856 #endif //GTKMM_HAVE_SIGC_BIND
858 template <class ColumnType> inline
859 int TreeView::append_column_numeric_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, const Glib::ustring& format)
861 int cols_count = append_column_numeric(title, model_column, format);
863 //connect signal handlers for auto-storing of edited cell data
864 //Note: This will only work for base-10 (decimal) formatted numbers:
865 CellRenderer *const cell = get_column_cell_renderer(cols_count - 1);
868 TreeView_Private::_connect_auto_store_editable_signal_handler<ColumnType>(this, cell, model_column);
874 template <class ColumnType> inline
875 int TreeView::append_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column)
877 //Don't use this in a header, because it gives warnings when disabled: g_assert(model_column.type() != 0);
879 // compilation will fail if there is no appropriate TreeViewColumn
880 // constructor for this model column type.
881 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
883 //connect signal handlers for auto-storing of edited cell data
884 CellRenderer* pCellRender = pViewColumn->get_first_cell_renderer();
885 TreeView_Private::_connect_auto_store_editable_signal_handler<ColumnType>(this, pCellRender, model_column);
887 return append_column(*pViewColumn);
890 template <class ColumnType> inline
891 int TreeView::insert_column(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position)
893 // compilation will fail if there is no appropriate TreeViewColumn
894 // constructor for this model column type.
895 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
897 return insert_column(*pViewColumn, position);
900 template <class ColumnType> inline
901 int TreeView::insert_column_editable(const Glib::ustring& title, const TreeModelColumn<ColumnType>& model_column, int position)
903 // compilation will fail if there is no appropriate TreeViewColumn
904 // constructor for this model column type.
905 TreeViewColumn *const pViewColumn = Gtk::manage( new TreeViewColumn(title, model_column) );
907 //connect signal handlers for auto-storing of edited cell data
908 CellRenderer* pCellRender = pViewColumn->get_first_cell_renderer();
909 TreeView_Private::_connect_auto_store_editable_signal_handler(this, pCellRender, model_column);
911 return insert_column(*pViewColumn, position);
915 #ifndef DOXYGEN_SHOULD_SKIP_THIS
916 namespace TreeView_Private
919 //Template specializations, for different model column types:
920 //TODO: Move these specializations into the .ccg file - I tried, but the int specialization was not used by the compiler. murrayc.
922 #ifdef GTKMM_HAVE_SIGC_BIND
924 //bool specialization:
926 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<bool>& model_column)
928 Gtk::CellRendererToggle* pCellToggle = dynamic_cast<Gtk::CellRendererToggle*>(pCellRenderer);
931 //Set the appropriate property,
932 #ifdef GLIBMM_PROPERTIES_ENABLED
933 pCellToggle->property_activatable() = true;
935 pCellToggle->set_property("activatable", true);
938 //Connect to the appropriate signal, sending the model_column too
940 sigc::slot<void, const Glib::ustring&, int> slot_temp =
942 sigc::mem_fun(*this_p, &Gtk::TreeView::_auto_store_on_cellrenderer_toggle_edited_with_model),
943 this_p->_get_base_model()
946 pCellToggle->signal_toggled().connect(
953 //We use bind<1> instead of bind because some compilers need the extra hint.
957 //int specialization:
959 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<int>& model_column)
961 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
964 //Set the appropriate property,
965 #ifdef GLIBMM_PROPERTIES_ENABLED
966 pCellText->property_editable() = true;
968 pCellText->set_property("editable", true);
971 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
972 typedef void (*type_fptr)(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
973 type_fptr fptr = _auto_store_on_cellrenderer_text_edited_numerical<int>;
975 //Connect to the appropriate signal, sending the model_column too,
976 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
977 pCellText->signal_edited().connect(
981 this_p->_get_base_model() ),
989 //unsigned int specialization:
991 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<unsigned int>& model_column)
993 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
996 //Set the appropriate property,
997 #ifdef GLIBMM_PROPERTIES_ENABLED
998 pCellText->property_editable() = true;
1000 pCellText->set_property("editable", true);
1003 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1004 typedef void (*type_fptr)(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
1005 type_fptr fptr = _auto_store_on_cellrenderer_text_edited_numerical<unsigned int>;
1007 //Connect to the appropriate signal, sending the model_column too,
1008 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1009 pCellText->signal_edited().connect(
1012 sigc::ptr_fun(fptr),
1013 this_p->_get_base_model() ),
1014 model_column.index()
1021 //long specialization:
1023 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<long>& model_column)
1025 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
1028 //Set the appropriate property,
1029 #ifdef GLIBMM_PROPERTIES_ENABLED
1030 pCellText->property_editable() = true;
1032 pCellText->set_property("editable", true);
1035 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1036 typedef void (*type_fptr)(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
1037 type_fptr fptr = _auto_store_on_cellrenderer_text_edited_numerical<long>;
1039 //Connect to the appropriate signal, sending the model_column too,
1040 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1041 pCellText->signal_edited().connect(
1044 sigc::ptr_fun(fptr),
1045 this_p->_get_base_model() ),
1046 model_column.index()
1053 //unsigned long specialization:
1055 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<unsigned long>& model_column)
1057 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
1060 //Set the appropriate property,
1061 #ifdef GLIBMM_PROPERTIES_ENABLED
1062 pCellText->property_editable() = true;
1064 pCellText->set_property("editable", true);
1067 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1068 typedef void (*type_fptr)(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
1069 type_fptr fptr = _auto_store_on_cellrenderer_text_edited_numerical<unsigned long>;
1071 //Connect to the appropriate signal, sending the model_column too,
1072 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1073 pCellText->signal_edited().connect(
1076 sigc::ptr_fun(fptr),
1077 this_p->_get_base_model() ),
1078 model_column.index()
1085 //float specialization:
1087 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<float>& model_column)
1089 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
1092 //Set the appropriate property,
1093 #ifdef GLIBMM_PROPERTIES_ENABLED
1094 pCellText->property_editable() = true;
1096 pCellText->set_property("editable", true);
1099 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1100 typedef void (*type_fptr)(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
1101 type_fptr fptr = _auto_store_on_cellrenderer_text_edited_numerical<float>;
1103 //Connect to the appropriate signal, sending the model_column too,
1104 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1105 pCellText->signal_edited().connect(
1108 sigc::ptr_fun(fptr),
1109 this_p->_get_base_model() ),
1110 model_column.index()
1116 //double specialization:
1118 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<double>& model_column)
1120 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
1123 //Set the appropriate property,
1124 #ifdef GLIBMM_PROPERTIES_ENABLED
1125 pCellText->property_editable() = true;
1127 pCellText->set_property("editable", true);
1130 //Some compilers don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1131 typedef void (*type_fptr)(const Glib::ustring& path_string, const Glib::ustring& new_text, int model_column, const Glib::RefPtr<Gtk::TreeModel>& model);
1132 type_fptr fptr = _auto_store_on_cellrenderer_text_edited_numerical<double>;
1134 //Connect to the appropriate signal, sending the model_column too,
1135 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1136 pCellText->signal_edited().connect(
1139 sigc::ptr_fun(fptr),
1140 this_p->_get_base_model() ),
1141 model_column.index()
1147 #endif //GTKMM_HAVE_SIGC_BIND
1149 } // namespace TreeView_Private
1150 #endif //DOXYGEN_SHOULD_SKIP_THIS
1153 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1154 namespace TreeView_Private
1157 #ifdef GTKMM_HAVE_SIGC_BIND
1159 template <class ColumnType> inline
1160 void _connect_auto_store_editable_signal_handler(Gtk::TreeView* this_p, Gtk::CellRenderer* pCellRenderer, const Gtk::TreeModelColumn<ColumnType>& model_column)
1162 //Don't use this in a header, because it gives warnings when disabled: g_assert(model_column.type() != 0);
1164 //The different CellRenderers have different "edited" signals,
1165 //and numerical values need to convert the text value to a number,
1166 //so there are specializations for this tempate.
1168 Gtk::CellRendererText* pCellText = dynamic_cast<Gtk::CellRendererText*>(pCellRenderer);
1170 //Set the appropriate property,
1171 //and connect to the appropriate signal, sending the model_column too,
1174 #ifdef GLIBMM_PROPERTIES_ENABLED
1175 pCellText->property_editable() = true;
1177 pCellText->set_property("editable", true);
1180 //Some compilers (IRIX MipsPro) don't like us to give the pointer to a template function directly to sigc::ptr_fun():
1181 typedef void (*type_func)(const Glib::ustring&, const Glib::ustring&, int, const Glib::RefPtr<Gtk::TreeModel>&);
1182 type_func func = &(_auto_store_on_cellrenderer_text_edited_string<ColumnType>);
1183 sigc::slot<void, const Glib::ustring&, const Glib::ustring&, int, const Glib::RefPtr<Gtk::TreeModel>&> theslot =
1184 sigc::ptr_fun(func);
1186 //We use bind<-1> twice here, instead of using bind() once, because some compilers need the extra hint.
1187 pCellText->signal_edited().connect(
1189 sigc::bind<-1>( theslot, this_p->_get_base_model()),
1190 model_column.index()
1198 #endif //GTKMM_HAVE_SIGC_BIND
1200 template <class ColumnType> inline
1201 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)
1203 Gtk::TreePath path(path_string);
1205 //Get the row from the path:
1208 Gtk::TreeModel::iterator iter = model->get_iter(path);
1211 //Store the user's new text in the model:
1212 Gtk::TreeRow row = *iter;
1213 row.set_value(model_column, (ColumnType)new_text);
1218 template <class ColumnType> inline
1219 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)
1221 //This is used on numerical model columns:
1223 Gtk::TreePath path(path_string);
1225 //Get the row from the path:
1228 Gtk::TreeModel::iterator iter = model->get_iter(path);
1231 //std::istringstream astream(new_text); //Put it in a stream.
1232 //ColumnType new_value = ColumnType();
1233 //new_value << astream; //Get it out of the stream as the numerical type.
1235 //Convert the text to a number, using the same logic used by GtkCellRendererText when it stores numbers.
1237 ColumnType new_value = static_cast<ColumnType>( strtod(new_text.c_str(), &pchEnd) );
1239 //Store the user's new text in the model:
1240 Gtk::TreeRow row = *iter;
1241 row.set_value(model_column, (ColumnType)new_value);
1246 template <class ColumnType> inline
1247 void _auto_cell_data_func(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter, int model_column, const Glib::ustring& format)
1249 Gtk::CellRendererText* pTextRenderer = dynamic_cast<Gtk::CellRendererText*>(cell);
1252 g_warning("gtkmm: TextView: append_column_numeric() was used with a non-numeric type.");
1258 //Get the value from the model.
1259 Gtk::TreeModel::Row row = *iter;
1260 ColumnType value = ColumnType();
1261 row.get_value(model_column, value);
1263 //Convert it to a string representation:
1265 int used = g_snprintf(buff, sizeof(buff), format.c_str(), value); //value must be a numeric type.
1268 //Show the text representation in the view:
1269 #ifdef GLIBMM_PROPERTIES_ENABLED
1270 pTextRenderer->property_text() = buff;
1272 pTextRenderer->set_property("text", (void*)buff);
1279 } // namespace TreeView_Private
1280 #endif //DOXYGEN_SHOULD_SKIP_THIS