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

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@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2013-01-06 16:34:25 +02:00 committed by Dirk Hohndel
parent 6d10aab049
commit c607f09f40

View file

@ -1475,19 +1475,15 @@ GtkWidget *entry_depth[MAX_WAYPOINTS], *entry_duration[MAX_WAYPOINTS], *entry_ga
int nr_waypoints = 0; int nr_waypoints = 0;
static GtkListStore *gas_model = NULL; 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; char *gastext;
int o2, he; int o2, he;
GtkWidget *entry;
if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Tab) { gastext = strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
entry = gtk_bin_get_child(GTK_BIN(combo)); if (validate_gas(gastext, &o2, &he))
gastext = strdup(gtk_entry_get_text(GTK_ENTRY(entry))); add_string_list_entry(gastext, gas_model);
if (validate_gas(gastext, &o2, &he)) free(gastext);
add_string_list_entry(gastext, gas_model);
free(gastext);
}
return FALSE; 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); combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(gas_model), 0);
gtk_widget_add_events(combo, GDK_FOCUS_CHANGE_MASK); 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) { if (label) {
frame = gtk_frame_new(label); frame = gtk_frame_new(label);