Debian Codegraph @

gtk/src/combobox.ccg

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/liststore.h>
18 #include <gtkmm/cellrenderertext.h>
19 #include <gtkmm/treeview_private.h> //For SignalProxy_RowSeparator.
20 #include <gtk/gtk.h>
21
22 namespace Gtk
23 {
24
25 ComboBox::ComboBox(bool has_entry)
26 :
27 _CONSTRUCT("has-entry", gboolean(has_entry))
28 {}
29
30 ComboBox::ComboBox(const Glib::RefPtr<TreeModel>& model, bool has_entry)
31 :
32 _CONSTRUCT("model", Glib::unwrap(model), "has-entry", gboolean(has_entry))
33 {}
34
35 ComboBox::ComboBox(const Glib::RefPtr<CellArea>& cell_area, bool has_entry)
36 :
37 _CONSTRUCT("cell-area", Glib::unwrap(cell_area), "has-entry", gboolean(has_entry))
38 {}
39
40 void ComboBox::unset_active()
41 {
42 gtk_combo_box_set_active(gobj(), -1 /* see GTK+ docs */);
43 }
44
45 TreeModel::iterator ComboBox::get_active()
46 {
47 Gtk::TreeModel::iterator iter;
48
49 auto model = get_model();
50 if(model)
51 {
52 gtk_combo_box_get_active_iter(gobj(), iter.gobj());
53
54 //It must be given the model, because the C++ wrapper has extra information.
55 iter.set_model_gobject(model->gobj());
56 }
57
58 return iter;
59 }
60
61 TreeModel::const_iterator ComboBox::get_active() const
62 {
63 Gtk::TreeModel::iterator iter;
64
65 const auto model = get_model();
66 if(model)
67 {
68 gtk_combo_box_get_active_iter(const_cast<GtkComboBox*>(gobj()), iter.gobj());
69
70 //It must be given the model, because the C++ wrapper has extra information.
71 iter.set_model_gobject(const_cast<GtkTreeModel*>(model->gobj()));
72 }
73
74 return iter;
75 }
76
77
78 void ComboBox::unset_model()
79 {
80 gtk_combo_box_set_model(gobj(), nullptr);
81 }
82
83
84 void ComboBox::set_row_separator_func(const SlotRowSeparator& slot)
85 {
86 //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
87 //It will be deleted when SignalProxy_RowSeparator_gtk_callback_destroy() is called.
88 auto slot_copy = new SlotRowSeparator(slot);
89
90 gtk_combo_box_set_row_separator_func(gobj(),
91 &TreeView_Private::SignalProxy_RowSeparator_gtk_callback, slot_copy,
92 &TreeView_Private::SignalProxy_RowSeparator_gtk_callback_destroy);
93 }
94
95 void ComboBox::unset_row_separator_func()
96 {
97 gtk_combo_box_set_row_separator_func(gobj(), nullptr, nullptr, nullptr /* See C docs. */);
98 }
99
100 Entry* ComboBox::get_entry()
101 {
102 auto widget = Glib::wrap(gtk_bin_get_child(GTK_BIN(gobj())));
103 return dynamic_cast<Gtk::Entry*>(widget);
104 }
105
106 const Entry* ComboBox::get_entry() const
107 {
108 const auto widget = Glib::wrap(gtk_bin_get_child(GTK_BIN(gobj())));
109 return dynamic_cast<const Gtk::Entry*>(widget);
110 }
111
112 Glib::ustring ComboBox::get_entry_text() const
113 {
114 const auto entry = get_entry();
115 if(!entry)
116 return Glib::ustring();
117 else
118 return entry->get_text();
119 }
120
121 // GtkComboBox:focus-on-click has been removed from gtk+.
122 // TODO: At ABI-break, remove it from gtkmm.
123 #ifndef GTKMM_DISABLE_DEPRECATED
124 Glib::PropertyProxy< bool > ComboBox::property_focus_on_click()
125 {
126 return Glib::PropertyProxy< bool >(this, "focus-on-click");
127 }
128
129 Glib::PropertyProxy_ReadOnly< bool > ComboBox::property_focus_on_click() const
130 {
131 return Glib::PropertyProxy_ReadOnly< bool >(this, "focus-on-click");
132 }
133 #endif // GTKMM_DISABLE_DEPRECATED
134
135 } // namespace Gtk