aboutsummaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-10-01 13:38:35 +0100
committerSimon Tatham <anakin@pobox.com>2017-10-01 16:34:41 +0100
commitde67801b0fd3dfa11777c1ef86cd617baf376b7b (patch)
treef632daee458c8fefcfc90ff809c44672adeedaa4 /gtk.c
parenteeb2db283de9115f7256fa4cc49597d63e06b0ab (diff)
downloadpuzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.zip
puzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.tar.gz
puzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.tar.bz2
puzzles-de67801b0fd3dfa11777c1ef86cd617baf376b7b.tar.xz
Use a proper union in struct config_item.
This allows me to use different types for the mutable, dynamically allocated string value in a C_STRING control and the fixed constant list of option names in a C_CHOICES.
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/gtk.c b/gtk.c
index b1175ef..c1e5a66 100644
--- a/gtk.c
+++ b/gtk.c
@@ -1641,22 +1641,25 @@ static void editbox_changed(GtkEditable *ed, gpointer data)
{
config_item *i = (config_item *)data;
- sfree(i->sval);
- i->sval = dupstr(gtk_entry_get_text(GTK_ENTRY(ed)));
+ assert(i->type == C_STRING);
+ sfree(i->u.string.sval);
+ i->u.string.sval = dupstr(gtk_entry_get_text(GTK_ENTRY(ed)));
}
static void button_toggled(GtkToggleButton *tb, gpointer data)
{
config_item *i = (config_item *)data;
- i->ival = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tb));
+ assert(i->type == C_BOOLEAN);
+ i->u.boolean.bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tb));
}
static void droplist_sel(GtkComboBox *combo, gpointer data)
{
config_item *i = (config_item *)data;
- i->ival = gtk_combo_box_get_active(combo);
+ assert(i->type == C_CHOICES);
+ i->u.choices.selected = gtk_combo_box_get_active(combo);
}
static int get_config(frontend *fe, int which)
@@ -1751,7 +1754,7 @@ static int get_config(frontend *fe, int which)
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
3, 3);
#endif
- gtk_entry_set_text(GTK_ENTRY(w), i->sval);
+ gtk_entry_set_text(GTK_ENTRY(w), i->u.string.sval);
g_signal_connect(G_OBJECT(w), "changed",
G_CALLBACK(editbox_changed), i);
g_signal_connect(G_OBJECT(w), "key_press_event",
@@ -1776,7 +1779,8 @@ static int get_config(frontend *fe, int which)
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
3, 3);
#endif
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), i->ival);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
+ i->u.boolean.bval);
gtk_widget_show(w);
break;
@@ -1799,15 +1803,16 @@ static int get_config(frontend *fe, int which)
{
int c;
- char *p, *q, *name;
+ const char *p, *q;
+ char *name;
GtkListStore *model;
GtkCellRenderer *cr;
GtkTreeIter iter;
model = gtk_list_store_new(1, G_TYPE_STRING);
- c = *i->sval;
- p = i->sval+1;
+ c = *i->u.choices.choicenames;
+ p = i->u.choices.choicenames+1;
while (*p) {
q = p;
@@ -1828,7 +1833,8 @@ static int get_config(frontend *fe, int which)
w = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
- gtk_combo_box_set_active(GTK_COMBO_BOX(w), i->ival);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(w),
+ i->u.choices.selected);
cr = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(w), cr, TRUE);