Debian Codegraph @

gtk/src/treeselection.hg

raw
1 /* Copyright (C) 1998-1999 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 #include <vector>
18
19 #include <gtkmm/enums.h>
20 #include <gtkmm/treemodel.h>
21 #include <gtkmm/treeiter.h>
22 #include <gtkmm/treepath.h>
23
24 _DEFS(gtkmm,gtk)
25 _PINCLUDE(glibmm/private/object_p.h)
26
27 namespace Gtk
28 {
29
30 class GTKMM_API TreeView;
31 class GTKMM_API TreeModel;
32 class GTKMM_API TreePath;
33
34 /** Typedefed as Gtk::TreeView::Selection.
35 * This is a helper object to manage the selection for a Gtk::TreeView widget.
36 *
37 * It is automatically created when a new Gtk::TreeView widget is created, and
38 * cannot exist independently of this widget. The primary reason this class
39 * exists is for cleanliness of code and API. That is, there is no conceptual
40 * reason all these methods could not be methods on the Gtk::TreeView widget
41 * instead of a separate class.
42 *
43 * The Gtk::TreeSelection object can be obtained from a Gtk::TreeView by
44 * calling Gtk::TreeView::get_selection(). It can be manipulated to check the
45 * selection status of the tree, as well as to select and deselect individual
46 * rows. Selection is done completely view-side. As a result, multiple views
47 * of the same model can have completely different selections. Additionally,
48 * you cannot change the selection of a row on the model that is not currently
49 * displayed by the view without expanding its parents first.
50 *
51 * When monitoring the selection of a view, it's important to remember that the
52 * "changed" signal is mostly a hint. That is, it may only emit one signal when
53 * a range of rows is selected. Additionally, it may on occasion emit a
54 * "changed" signal when nothing has happened.
55 *
56 * @ingroup TreeView
57 */
58 class GTKMM_API TreeSelection : public Glib::Object
59 {
60 _CLASS_GOBJECT(TreeSelection, GtkTreeSelection, GTK_TREE_SELECTION, Glib::Object, GObject, , , GTKMM_API)
61 _IGNORE(gtk_tree_selection_get_selected,
62 gtk_tree_selection_get_selected_rows, gtk_tree_selection_count_selected_rows)
63 protected:
64
65
66 public:
67 _WRAP_METHOD(void set_mode(SelectionMode type), gtk_tree_selection_set_mode)
68 _WRAP_METHOD(SelectionMode get_mode() const, gtk_tree_selection_get_mode)
69
70 /** For instance, bool on_select_function(const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool path_currently_selected)
71 * The select function should return true if the state of the node may be toggled,
72 * and false if the state of the node should be left unchanged.
73 */
74 typedef sigc::slot<bool, const Glib::RefPtr<TreeModel>&, const TreeModel::Path&, bool> SlotSelect;
75
76 /** Sets the selection callback slot. If set, this function is called before any node is selected or unselected,
77 * giving some control over which nodes are selected.
78 *
79 * The select function should return true if the state of the node may be toggled, and FALSE if the state of the node
80 * should be left unchanged.
81 *
82 * @param slot The selection function.
83 */
84 void set_select_function(const SlotSelect& slot);
85 _IGNORE(gtk_tree_selection_set_select_function, gtk_tree_selection_get_select_function)
86
87 _IGNORE(gtk_tree_selection_get_user_data) // This would be our SignalProxy_Select* data.
88
89 _WRAP_METHOD(TreeView* get_tree_view(), gtk_tree_selection_get_tree_view)
90 _WRAP_METHOD(const TreeView* get_tree_view() const, gtk_tree_selection_get_tree_view, constversion)
91
92 /** Shortcut for get_tree_view()->get_model().
93 * @return The TreeModel associated with this TreeSelection.
94 */
95 Glib::RefPtr<TreeModel> get_model(); // convenience function, not in GTK+
96 Glib::RefPtr<const TreeModel> get_model() const; // convenience function, not in GTK+
97
98 //TODO: Add TreeModel::const_iterator get_selected() const, when we have a real const_iterator.
99
100 /** Get the currently selected row.
101 * @return The currently selected row.
102 * @note
103 * This method won't work if the selection mode is <tt>Gtk::SELECTION_MULTIPLE</tt>.
104 * Use get_selected_rows() for multiple selections.
105 */
106 TreeModel::iterator get_selected();
107
108 /** Get the currently selected row.
109 * @return The currently selected row. Or end() if no rows were selected.
110 * @retval model The current TreeModel.
111 * @note
112 * This method won't work if the selection mode is <tt>Gtk::SELECTION_MULTIPLE</tt>.
113 * Use get_selected_rows() for multiple selections.
114 */
115 TreeModel::iterator get_selected(Glib::RefPtr<TreeModel>& model);
116
117 /** Creates a list of paths of all selected rows.
118 * Additionally, if you are planning on modifying the model after calling this function,
119 * you may want to convert the returned list into a list of GtkTreeRowReferences.
120 *
121 * @returns a standard container containing a Gtk::Model::Path for each selected row.
122 */
123 std::vector<TreeModel::Path> get_selected_rows() const;
124
125 /** Creates a list of paths of all selected rows.
126 * Additionally, if you are planning on modifying the model after calling this function,
127 * you may want to convert the returned list into a list of GtkTreeRowReferences.
128 *
129 * @retval model The current TreeModel.
130 * @returns a standard container containing a Gtk::Model::Path for each selected row.
131 */
132 std::vector<TreeModel::Path> get_selected_rows(Glib::RefPtr<TreeModel>& model);
133
134 _WRAP_METHOD(int count_selected_rows() const, gtk_tree_selection_count_selected_rows)
135
136 //TODO: Consider deprecating these selected_foreach() methods, because get_selected_rows() should be enough.
137
138 //TODO: SlotForEachIter should take a const_iterator, when we have a real const iterator.
139 /** For example,
140 * void on_foreach(const Gtk::TreeModel::iterator& iter);
141 *
142 * Note that you cannot modify the tree or selection from within the callback function.
143 * As a result, get_selected_rows() might be more useful.
144 */
145 typedef sigc::slot<void, const TreeModel::iterator&> SlotForeachIter;
146
147 /** Calls a callback slot for each selected node.
148 * Note that you cannot modify the tree or selection from within the callback function.
149 * As a result, get_selected_rows() might be more useful.
150 *
151 * @param slot The function to call for each selected node.
152 */
153 void selected_foreach_iter(const SlotForeachIter& slot) const;
154
155 /** For example,
156 * void on_foreach(const Gtk::TreeModel::Path& path);
157 *
158 * Note that you cannot modify the tree or selection from within the callback function.
159 * As a result, get_selected_rows() might be more useful.
160 */
161 typedef sigc::slot<void, const TreeModel::Path&> SlotForeachPath;
162
163 /** Calls a callback slot for each selected node.
164 * Note that you cannot modify the tree or selection from within the callback function.
165 * As a result, get_selected_rows() might be more useful.
166 *
167 * @param slot The function to call for each selected node.
168 */
169 void selected_foreach_path(const SlotForeachPath& slot) const;
170 _IGNORE(gtk_tree_selection_selected_foreach)
171
172 /** For example,
173 * void on_foreach(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter);
174 *
175 * Note that you cannot modify the tree or selection from within the callback function.
176 * As a result, get_selected_rows() might be more useful.
177 */
178 typedef sigc::slot<void, const TreeModel::Path&, const TreeModel::iterator&> SlotForeachPathAndIter;
179
180 /** Calls a callback slot for each selected node.
181 * Note that you cannot modify the tree or selection from within the callback function.
182 * As a result, get_selected_rows() might be more useful.
183 *
184 * @param slot The function to call for each selected node.
185 */
186 void selected_foreach(const SlotForeachPathAndIter& slot) const;
187
188 _WRAP_METHOD(void select(const TreeModel::Path& path), gtk_tree_selection_select_path)
189 _WRAP_METHOD(void select(const TreeModel::iterator& iter), gtk_tree_selection_select_iter)
190 _WRAP_METHOD(void select(const TreeModel::Row& row), gtk_tree_selection_select_iter)
191 _WRAP_METHOD(void select(const TreeModel::Path& start_path, const TreeModel::Path& end_path), gtk_tree_selection_select_range)
192
193 _WRAP_METHOD(void unselect(const TreeModel::Path& path), gtk_tree_selection_unselect_path)
194 _WRAP_METHOD(void unselect(const TreeModel::Path& start_path, const TreeModel::Path& end_path), gtk_tree_selection_unselect_range)
195 _WRAP_METHOD(void unselect(const TreeModel::iterator& iter), gtk_tree_selection_unselect_iter)
196
197 _WRAP_METHOD(bool is_selected(const TreeModel::Path& path) const, gtk_tree_selection_path_is_selected)
198 _WRAP_METHOD(bool is_selected(const TreeModel::iterator& iter) const, gtk_tree_selection_iter_is_selected)
199
200 _WRAP_METHOD(void select_all(), gtk_tree_selection_select_all)
201 _WRAP_METHOD(void unselect_all(), gtk_tree_selection_unselect_all)
202
203 _WRAP_PROPERTY("mode", SelectionMode)
204
205 _WRAP_SIGNAL(void changed(), "changed")
206 };
207
208 } // namespace Gtk