Debian Codegraph @

gtk/src/comboboxtext.ccg

raw
1 /* Copyright (C) 2010 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 <gtk/gtk.h>
18
19 namespace Gtk
20 {
21
22 ComboBoxText::ComboBoxText(bool has_entry)
23 :
24 //The entry-text-column and id-column values are copied from gtk_combo_box_text_new():
25 _CONSTRUCT("has-entry", gboolean(has_entry))
26 {}
27
28 void ComboBoxText::set_active_text(const Glib::ustring& text)
29 {
30 //Look for the row with this text, and activate it:
31 auto model = get_model();
32 if(model)
33 {
34 for(const auto& row : model->children())
35 {
36 Glib::ustring this_text;
37 row.get_value(0, this_text);
38
39 if(this_text == text)
40 {
41 set_active(row);
42 return; //success
43 }
44 }
45 }
46
47 //Not found, so mark it as blank:
48 unset_active();
49 }
50
51 } // namespace Gtk