[PATCH] Planner: hook the gas combo box to a "focus-out" event handler

Lubomir I. Ivanov neolit123 at gmail.com
Sun Jan 6 06:34:25 PST 2013

From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

GTK's logic might be a bit flawed (or complicated) in terms of
"focus-out-event" and GtkComboBoxEntry objects as it does not work
by attaching said signal type directly to the GtkComboBoxEntry.
Perhaps it only makes sense for text input.

Since "focus-out-event" works for GtkEntry, we can retrieve the child
GtkEntry from the combo using gtk_bin_get_child(GTK_BIN(combo)
and attach the event handler to that.

This change should make it possible to update gas_model (GtkListStore)
when changing the widget focus with both the keyboard and mouse clicks.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
 gtk-gui.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/gtk-gui.c b/gtk-gui.c
index 5f58812..172e4ab 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1475,19 +1475,15 @@ GtkWidget *entry_depth[MAX_WAYPOINTS], *entry_duration[MAX_WAYPOINTS], *entry_ga
 int nr_waypoints = 0;
 static GtkListStore *gas_model = NULL;
-static gboolean gas_changed_cb(GtkComboBox *combo, GdkEventKey *event, gpointer data)
+static gboolean gas_focus_out_cb(GtkWidget *entry, gpointer data)
 	char *gastext;
 	int o2, he;
-	GtkWidget *entry;
-	if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Tab) {
-		entry = gtk_bin_get_child(GTK_BIN(combo));
-		gastext = strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
-		if (validate_gas(gastext, &o2, &he))
-			add_string_list_entry(gastext, gas_model);
-		free(gastext);
-	}
+	gastext = strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
+	if (validate_gas(gastext, &o2, &he))
+		add_string_list_entry(gastext, gas_model);
+	free(gastext);
 	return FALSE;
@@ -1505,7 +1501,7 @@ static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label)
 	combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(gas_model), 0);
 	gtk_widget_add_events(combo, GDK_FOCUS_CHANGE_MASK);
-	g_signal_connect(G_OBJECT(combo), "event", G_CALLBACK(gas_changed_cb), NULL);
+	g_signal_connect(gtk_bin_get_child(GTK_BIN(combo)), "focus-out-event", G_CALLBACK(gas_focus_out_cb), NULL);
 	if (label) {
 		frame = gtk_frame_new(label);

More information about the subsurface mailing list