From 06f17aa4de33bff755d76fd1f98bc88dc8aa0d00 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 8 Oct 2015 14:55:18 -0400 Subject: [PATCH] Implemented the new uiCombobox stuff on GTK+. --- test/page4.c | 4 ++-- unix/combobox.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/test/page4.c b/test/page4.c index f03ad28e..27c68880 100644 --- a/test/page4.c +++ b/test/page4.c @@ -97,14 +97,14 @@ uiBox *makePage4(void) uiComboboxAppend(cbox, "Item 1"); uiComboboxAppend(cbox, "Item 2"); uiComboboxAppend(cbox, "Item 3"); - uiComboboxOnChanged(cbox, onCBChanged, "noneditable"); + uiComboboxOnSelected(cbox, onCBChanged, "noneditable"); uiBoxAppend(page4, uiControl(cbox), 0); editable = uiNewEditableCombobox(); uiComboboxAppend(editable, "Editable Item 1"); uiComboboxAppend(editable, "Editable Item 2"); uiComboboxAppend(editable, "Editable Item 3"); - uiComboboxOnChanged(cbox, onCBChanged, "editable"); + uiComboboxOnSelected(editable, onCBChanged, "editable"); uiBoxAppend(page4, uiControl(editable), 0); rb = uiNewRadioButtons(); diff --git a/unix/combobox.c b/unix/combobox.c index 7dc7e0cf..b4ef2598 100644 --- a/unix/combobox.c +++ b/unix/combobox.c @@ -6,6 +6,8 @@ struct uiCombobox { GtkWidget *widget; GtkComboBox *combobox; GtkComboBoxText *comboboxText; + void (*onSelected)(uiCombobox *, void *); + void *onSelectedData; }; uiUnixDefineControl( @@ -13,11 +15,35 @@ uiUnixDefineControl( uiComboboxType // type function ) +// TODO this is triggered when editing an editable combobox's text +static void onChanged(GtkComboBox *cbox, gpointer data) +{ + uiCombobox *c = uiCombobox(data); + + (*(c->onSelected))(c, c->onSelectedData); +} + +static void defaultOnSelected(uiCombobox *c, void *data) +{ + // do nothing +} + void uiComboboxAppend(uiCombobox *c, const char *text) { gtk_combo_box_text_append(c->comboboxText, NULL, text); } +intmax_t uiComboboxSelected(uiCombobox *c) +{ + return gtk_combo_box_get_active(c->combobox); +} + +void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data) +{ + c->onSelected = f; + c->onSelectedData = data; +} + static uiCombobox *finishNewCombobox(GtkWidget *(*newfunc)(void)) { uiCombobox *c; @@ -28,6 +54,9 @@ static uiCombobox *finishNewCombobox(GtkWidget *(*newfunc)(void)) c->combobox = GTK_COMBO_BOX(c->widget); c->comboboxText = GTK_COMBO_BOX_TEXT(c->widget); + g_signal_connect(c->widget, "changed", G_CALLBACK(onChanged), c); + uiComboboxOnSelected(c, defaultOnSelected, NULL); + uiUnixFinishNewControl(c, uiCombobox); return c;