summaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-01-27 16:40:01 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-28 13:17:44 -0800
commit77ece3fccb1a08ef8eea10a9f548bc6a4a3c889e (patch)
tree71dd23e661b88cf690779193a8579a3c6aaa944b /gtk-gui.c
parent32e497b5744ef690e91b4a9f22a63109dde4c7df (diff)
downloadsubsurface-77ece3fccb1a08ef8eea10a9f548bc6a4a3c889e.tar.gz
Clean up gtk combo box handling
This cleans up our handling of combo boxes and all the duplicated completion logic, and simplifies the code. In particular, we get rid of the deprecated GtkComboBoxEntry. While it made some things easier, it made other things harder. Just using GtkComboBox and setting that up correctly ends up being simpler, and also makes the logic work with gtk-3. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'gtk-gui.c')
-rw-r--r--gtk-gui.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index 9f76d31cd..15743f37d 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -415,6 +415,42 @@ GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char
return col;
}
+/* Helper functions for gtk combo boxes */
+GtkEntry *get_entry(GtkComboBox *combo_box)
+{
+ return GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
+}
+
+const char *get_active_text(GtkComboBox *combo_box)
+{
+ return gtk_entry_get_text(get_entry(combo_box));
+}
+
+void set_active_text(GtkComboBox *combo_box, const char *text)
+{
+ gtk_entry_set_text(get_entry(combo_box), text);
+}
+
+GtkWidget *combo_box_with_model_and_entry(GtkListStore *model)
+{
+ GtkWidget *widget;
+ GtkEntryCompletion *completion;
+
+ widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(model));
+ gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(widget), 0);
+
+ completion = gtk_entry_completion_new();
+ gtk_entry_completion_set_text_column(completion, 0);
+ gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
+ gtk_entry_completion_set_inline_completion(completion, TRUE);
+ gtk_entry_completion_set_inline_selection(completion, TRUE);
+ gtk_entry_completion_set_popup_single_match(completion, FALSE);
+ gtk_entry_set_completion(get_entry(GTK_COMBO_BOX(widget)), completion);
+ g_object_unref(completion);
+
+ return widget;
+}
+
static void create_radio(GtkWidget *vbox, const char *w_name, ...)
{
va_list args;