summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/utils.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2015-03-16 14:37:06 +0100
committerRobin Gareus <robin@gareus.org>2015-03-16 14:38:21 +0100
commit4c2ea510e3e69197715ae3f7ca3bea7bc97084c0 (patch)
treef7b9a26996196f15653ceb1ca08ae8d8ec1a59ff /libs/gtkmm2ext/utils.cc
parent26ba494083c5a7417177733fa049ca1830271dc7 (diff)
add API to query Gtk::ComboBoxText entries
..the overly complex C++ style variant. iterate twice.. hell yeah.
Diffstat (limited to 'libs/gtkmm2ext/utils.cc')
-rw-r--r--libs/gtkmm2ext/utils.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc
index f7e96f09c8..03396a4af9 100644
--- a/libs/gtkmm2ext/utils.cc
+++ b/libs/gtkmm2ext/utils.cc
@@ -19,6 +19,7 @@
*/
#include <map>
+#include <algorithm>
#include <gtk/gtkpaned.h>
#include <gtk/gtk.h>
@@ -306,6 +307,39 @@ Gtkmm2ext::set_popdown_strings (Gtk::ComboBoxText& cr, const vector<string>& str
}
}
+void
+Gtkmm2ext::get_popdown_strings (Gtk::ComboBoxText& cr, std::vector<std::string>& strings)
+{
+ strings.clear ();
+ Glib::RefPtr<const Gtk::TreeModel> m = cr.get_model();
+ if (!m) {
+ return;
+ }
+ for(Gtk::TreeModel::iterator i = m->children().begin(); i != m->children().end(); ++i) {
+ Glib::ustring txt;
+ (*i)->get_value(0, txt);
+ strings.push_back (txt);
+ }
+}
+
+bool
+Gtkmm2ext::contains_value (Gtk::ComboBoxText& cr, const std::string text)
+{
+ std::vector<std::string> s;
+ get_popdown_strings (cr, s);
+ return (std::find (s.begin(), s.end(), text) != s.end());
+}
+
+bool
+Gtkmm2ext::set_active_text_if_present (Gtk::ComboBoxText& cr, const std::string text)
+{
+ if (contains_value(cr, text)) {
+ cr.set_active_text (text);
+ return true;
+ }
+ return false;
+}
+
GdkWindow*
Gtkmm2ext::get_paned_handle (Gtk::Paned& paned)
{