Debian Codegraph @

gtk/src/combobox.hg

raw
1 /* Copyright (C) 2003 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 <gtkmm/bin.h>
18 #include <gtkmm/celllayout.h>
19 #include <gtkmm/celleditable.h>
20 #include <gtkmm/treemodel.h>
21 #include <gtkmm/cellarea.h>
22 #include <gtkmm/cellrenderer.h>
23 #include <gtkmm/treeview.h>
24 #include <gtkmm/enums.h> //For SensitivityType.
25
26 _DEFS(gtkmm,gtk)
27 _PINCLUDE(gtkmm/private/bin_p.h)
28
29 namespace Gtk
30 {
31
32 /** A widget used to choose from a list of items.
33 *
34 * A ComboBox is a widget that allows the user to choose from a list of valid choices. The ComboBox displays the
35 * selected choice. When activated, the ComboBox displays a popup which allows the user to make a new choice. The
36 * style in which the selected value is displayed, and the style of the popup is determined by the current theme.
37 * It may be similar to a Windows-style combo box.
38 *
39 * The ComboBox uses the model-view pattern; the list of valid choices is specified in the form of a tree model,
40 * and the display of the choices can be adapted to the data in the model by using cell renderers, as you would in
41 * a tree view. This is possible since ComboBox implements the CellLayout interface. The tree model holding the
42 * valid choices is not restricted to a flat list, it can be a real tree, and the popup will reflect the tree
43 * structure.
44 *
45 * To allow the user to enter values not in the model, the 'has-entry'
46 * property allows the ComboBox to contain a Gtk::Entry. This entry
47 * can be accessed by calling get_entry(), or you can just call get_entry_text()
48 * to get the text from the Entry.
49 *
50 * For a simple list of textual choices, the model-view API of ComboBox
51 * can be a bit overwhelming. In this case, ComboBoxText offers a
52 * simple alternative. Both ComboBox and ComboBoxText can contain
53 * an entry.
54 *
55 * The ComboBox widget looks like this:
56 * @image html combobox1.png
57 *
58 * @ingroup Widgets
59 */
60 class GTKMM_API ComboBox
61 : public Bin,
62 public CellLayout,
63 public CellEditable
64 {
65 _CLASS_GTKOBJECT(ComboBox, GtkComboBox, GTK_COMBO_BOX, Gtk::Bin, GtkBin, , , GTKMM_API)
66 _IMPLEMENTS_INTERFACE(CellLayout)
67 _IMPLEMENTS_INTERFACE(CellEditable)
68 public:
69
70 /** Creates a new empty ComboBox, optionally with an entry.
71 * @param has_entry If this is true then this will have an Entry widget.
72 */
73 explicit ComboBox(bool has_entry = false);
74 _IGNORE(gtk_combo_box_new_with_entry)
75
76 /** Creates a new ComboBox with the model initialized to @a model, optionally with an entry.
77 * @param model The model containing data to display in the ComboBox.
78 * @param has_entry If this is true then this will have an Entry widget.
79 */
80 explicit ComboBox(const Glib::RefPtr<TreeModel>& model, bool has_entry = false);
81 _IGNORE(gtk_combo_box_new_with_model, gtk_combo_box_new_with_model_and_entry)
82
83 /** Creates a new empty ComboBox using @a cell_area to layout cells, optionally with an entry.
84 * @param cell_area The CellArea to use to layout cell renderers.
85 * @param has_entry If this is true then this will have an Entry widget.
86 */
87 explicit ComboBox(const Glib::RefPtr<CellArea>& cell_area, bool has_entry = false);
88 _IGNORE(gtk_combo_box_new_with_area, gtk_combo_box_new_with_area_and_entry)
89 _IGNORE(gtk_combo_box_new)
90
91 _WRAP_METHOD(void set_wrap_width(int width), gtk_combo_box_set_wrap_width)
92 _WRAP_METHOD(int get_wrap_width() const, gtk_combo_box_get_wrap_width)
93
94 _WRAP_METHOD(void set_row_span_column(int row_span), gtk_combo_box_set_row_span_column)
95 _WRAP_METHOD(int get_row_span_column() const, gtk_combo_box_get_row_span_column)
96
97 _WRAP_METHOD(void set_column_span_column(int column_span), gtk_combo_box_set_column_span_column)
98 _WRAP_METHOD(int get_column_span_column() const, gtk_combo_box_get_column_span_column)
99
100 _WRAP_METHOD(bool get_add_tearoffs() const, gtk_combo_box_get_add_tearoffs, deprecated "No replacement available.")
101 _WRAP_METHOD(void set_add_tearoffs(bool add_tearoffs = true), gtk_combo_box_set_add_tearoffs, deprecated "No replacement available.")
102
103 _WRAP_METHOD(Glib::ustring get_title() const, gtk_combo_box_get_title, deprecated "No replacement available.")
104 _WRAP_METHOD(void set_title(const Glib::ustring& title), gtk_combo_box_set_title, deprecated "No replacement available.")
105
106 _WRAP_METHOD(bool get_focus_on_click() const, gtk_combo_box_get_focus_on_click,
107 deprecated "Use Widget::get_focus_on_click() instead.")
108 _WRAP_METHOD(void set_focus_on_click(bool focus_on_click = true), gtk_combo_box_set_focus_on_click,
109 deprecated "Use Widget::set_focus_on_click() instead.")
110
111 /* get/set active item */
112 _WRAP_METHOD(int get_active_row_number() const, gtk_combo_box_get_active)
113
114 /** Gets an iterator that points to the current active item, if it exists.
115 * @result The iterator.
116 */
117 TreeModel::iterator get_active();
118
119 /** Gets an iterator that points to the current active item, if it exists.
120 * @result The iterator.
121 */
122 TreeModel::const_iterator get_active() const;
123 _IGNORE(gtk_combo_box_get_active_iter)
124
125 _WRAP_METHOD(void set_active(int index), gtk_combo_box_set_active)
126 _WRAP_METHOD(void set_active(const TreeModel::iterator& iter), gtk_combo_box_set_active_iter)
127
128 //TODO: See https://bugzilla.gnome.org/show_bug.cgi?id=612396#c30
129 /** Get the text in the entry, if there is an entry.
130 *
131 * @newin{2,24}
132 */
133 Glib::ustring get_entry_text() const;
134
135 /** Causes no item to be active. See also set_active().
136 */
137 void unset_active();
138
139 _WRAP_METHOD(Glib::RefPtr<TreeModel> get_model(), gtk_combo_box_get_model, refreturn)
140 _WRAP_METHOD(Glib::RefPtr<const TreeModel> get_model() const, gtk_combo_box_get_model, refreturn, constversion)
141 _WRAP_METHOD(void set_model(const Glib::RefPtr<TreeModel>& model), gtk_combo_box_set_model)
142
143 /** Remove the model from the ComboBox.
144 *
145 * @see set_model().
146 *
147 * @newin{2,16}
148 */
149 void unset_model();
150
151 typedef TreeView::SlotRowSeparator SlotRowSeparator;
152
153 /** Sets the row separator function, which is used to determine whether a row should be drawn as a separator.
154 * See also unset_row_separator_func().
155 *
156 * @param slot The callback.
157 */
158 void set_row_separator_func(const SlotRowSeparator& slot);
159
160 /** Causes no separators to be drawn.
161 */
162 void unset_row_separator_func();
163 _IGNORE(gtk_combo_box_set_row_separator_func, gtk_combo_box_get_row_separator_func)
164
165 _WRAP_METHOD(void set_button_sensitivity(SensitivityType sensitivity), gtk_combo_box_set_button_sensitivity)
166 _WRAP_METHOD(SensitivityType get_button_sensitivity() const, gtk_combo_box_get_button_sensitivity)
167
168
169 _WRAP_METHOD(bool get_has_entry() const, gtk_combo_box_get_has_entry)
170
171 _WRAP_METHOD(void set_entry_text_column(const TreeModelColumnBase& text_column) const, gtk_combo_box_set_entry_text_column)
172 _WRAP_METHOD(void set_entry_text_column(int text_column), gtk_combo_box_set_entry_text_column)
173
174 _WRAP_METHOD(int get_entry_text_column() const, gtk_combo_box_get_entry_text_column)
175
176 _WRAP_METHOD(void set_popup_fixed_width(bool fixed = true), gtk_combo_box_set_popup_fixed_width )
177 _WRAP_METHOD(bool get_popup_fixed_width() const, gtk_combo_box_get_popup_fixed_width)
178
179 _WRAP_METHOD(void popup(), gtk_combo_box_popup)
180 _WRAP_METHOD(void popup(const Glib::RefPtr<Gdk::Device>& device), gtk_combo_box_popup_for_device)
181 _WRAP_METHOD(void popdown(), gtk_combo_box_popdown)
182
183 _WRAP_METHOD(Glib::RefPtr<Atk::Object> get_popup_accessible(), gtk_combo_box_get_popup_accessible, ifdef GTKMM_ATKMM_ENABLED)
184 _WRAP_METHOD(Glib::RefPtr<const Atk::Object> get_popup_accessible() const, gtk_combo_box_get_popup_accessible, constversion, ifdef GTKMM_ATKMM_ENABLED)
185
186 _WRAP_METHOD(int get_id_column() const, gtk_combo_box_get_id_column)
187 _WRAP_METHOD(void set_id_column(int id_column), gtk_combo_box_set_id_column)
188 _WRAP_METHOD(Glib::ustring get_active_id() const, gtk_combo_box_get_active_id)
189 _WRAP_METHOD(void get_active_id(const Glib::ustring& active_id), gtk_combo_box_set_active_id, deprecated "Use set_active_id(). This method was incorrectly named.")
190
191 /** Changes the active row of the combo box to the one that has an ID equal to
192 * @a active_id.
193 *
194 * If property_id_column() is unset or if no row has the given ID then the function
195 * does nothing and returns false.
196 *
197 * @param active_id The ID of the row that should be set to active.
198 * @returns true if a row with a matching ID was found.
199 *
200 * @newin{3,6}
201 */
202 _WRAP_METHOD(bool set_active_id(const Glib::ustring& active_id), gtk_combo_box_set_active_id)
203
204 /** @see Bin::get_child().
205 * @newin{2,24}
206 */
207 Entry* get_entry();
208
209 /** @see Bin::get_child().
210 * @newin{2,24}
211 */
212 const Entry* get_entry() const;
213
214
215 _WRAP_PROPERTY("model", Glib::RefPtr<TreeModel>)
216 _WRAP_PROPERTY("wrap_width", int)
217 _WRAP_PROPERTY("row_span_column", int)
218 _WRAP_PROPERTY("column_span_column", int)
219 _WRAP_PROPERTY("active", int)
220 _WRAP_PROPERTY("add-tearoffs", bool, deprecated "No replacement available.")
221 _WRAP_PROPERTY("has-frame", bool)
222
223 // GtkComboBox:focus-on-click has been removed from gtk+.
224 // TODO: At ABI-break, remove it from gtkmm.
225 #ifndef GTKMM_DISABLE_DEPRECATED
226 /** Whether the combo box grabs focus when it is clicked with the mouse.
227 * @deprecated Use Widget::property_focus_on_click() instead.
228 *
229 * @return A PropertyProxy that allows you to get or set the value of the property,
230 * or receive notification when the value of the property changes.
231 */
232 Glib::PropertyProxy< bool > property_focus_on_click() ;
233
234 /** Whether the combo box grabs focus when it is clicked with the mouse.
235 * @deprecated Use Widget::property_focus_on_click() instead.
236 *
237 * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
238 * or receive notification when the value of the property changes.
239 */
240 Glib::PropertyProxy_ReadOnly< bool > property_focus_on_click() const;
241 #endif // GTKMM_DISABLE_DEPRECATED
242 //_WRAP_PROPERTY("focus-on-click", bool, deprecated "Use Widget::property_focus_on_click() instead.")
243
244 _WRAP_PROPERTY("tearoff-title", Glib::ustring, deprecated "No replacement available.")
245 _WRAP_PROPERTY("popup-shown", bool)
246 _WRAP_PROPERTY("button-sensitivity", SensitivityType)
247 _WRAP_PROPERTY("popup-fixed-width", bool)
248 _WRAP_PROPERTY("cell-area", Glib::RefPtr<CellArea>)
249 _WRAP_PROPERTY("has-entry", bool)
250 _WRAP_PROPERTY("entry-text-column", int)
251 _WRAP_PROPERTY("id-column", int)
252 _WRAP_PROPERTY("active-id", Glib::ustring)
253
254 _WRAP_SIGNAL(void changed(), "changed")
255
256 //TODO: Remove no_default_handler when we can break ABI
257 #m4 dnl// The ::format_value signal handler should return a newly allocated string.
258 #m4 dnl// (which is obviously not a const gchar*)
259 #m4 _CONVERSION(`Glib::ustring',`const gchar*',`(strlen($3.c_str()) ? g_strdup($3.c_str()) : 0)')
260 #m4 _CONVERSION(`const gchar*',`const TreeModel::Path&',`TreeModel::Path($3)')
261 #m4 _CONVERSION(`const TreeModel::Path&',`const gchar*',`($3).to_string().c_str()')
262 _WRAP_SIGNAL(Glib::ustring format_entry_text(const TreeModel::Path& path), "format-entry-text", no_default_handler)
263
264 //Key-binding signals:
265 _IGNORE_SIGNAL("move-active")
266 _IGNORE_SIGNAL("popup")
267 _IGNORE_SIGNAL("popdown")
268 };
269
270 } // namespace Gtk