Implemented the new uiCombobox stuff on GTK+.

This commit is contained in:
Pietro Gagliardi 2015-10-08 14:55:18 -04:00
parent 26e90f0b51
commit 06f17aa4de
2 changed files with 31 additions and 2 deletions

View File

@ -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();

View File

@ -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;