Implemented the new uiCombobox stuff on GTK+.
This commit is contained in:
parent
26e90f0b51
commit
06f17aa4de
|
@ -97,14 +97,14 @@ uiBox *makePage4(void)
|
||||||
uiComboboxAppend(cbox, "Item 1");
|
uiComboboxAppend(cbox, "Item 1");
|
||||||
uiComboboxAppend(cbox, "Item 2");
|
uiComboboxAppend(cbox, "Item 2");
|
||||||
uiComboboxAppend(cbox, "Item 3");
|
uiComboboxAppend(cbox, "Item 3");
|
||||||
uiComboboxOnChanged(cbox, onCBChanged, "noneditable");
|
uiComboboxOnSelected(cbox, onCBChanged, "noneditable");
|
||||||
uiBoxAppend(page4, uiControl(cbox), 0);
|
uiBoxAppend(page4, uiControl(cbox), 0);
|
||||||
|
|
||||||
editable = uiNewEditableCombobox();
|
editable = uiNewEditableCombobox();
|
||||||
uiComboboxAppend(editable, "Editable Item 1");
|
uiComboboxAppend(editable, "Editable Item 1");
|
||||||
uiComboboxAppend(editable, "Editable Item 2");
|
uiComboboxAppend(editable, "Editable Item 2");
|
||||||
uiComboboxAppend(editable, "Editable Item 3");
|
uiComboboxAppend(editable, "Editable Item 3");
|
||||||
uiComboboxOnChanged(cbox, onCBChanged, "editable");
|
uiComboboxOnSelected(editable, onCBChanged, "editable");
|
||||||
uiBoxAppend(page4, uiControl(editable), 0);
|
uiBoxAppend(page4, uiControl(editable), 0);
|
||||||
|
|
||||||
rb = uiNewRadioButtons();
|
rb = uiNewRadioButtons();
|
||||||
|
|
|
@ -6,6 +6,8 @@ struct uiCombobox {
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
GtkComboBox *combobox;
|
GtkComboBox *combobox;
|
||||||
GtkComboBoxText *comboboxText;
|
GtkComboBoxText *comboboxText;
|
||||||
|
void (*onSelected)(uiCombobox *, void *);
|
||||||
|
void *onSelectedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiUnixDefineControl(
|
uiUnixDefineControl(
|
||||||
|
@ -13,11 +15,35 @@ uiUnixDefineControl(
|
||||||
uiComboboxType // type function
|
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)
|
void uiComboboxAppend(uiCombobox *c, const char *text)
|
||||||
{
|
{
|
||||||
gtk_combo_box_text_append(c->comboboxText, NULL, 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))
|
static uiCombobox *finishNewCombobox(GtkWidget *(*newfunc)(void))
|
||||||
{
|
{
|
||||||
uiCombobox *c;
|
uiCombobox *c;
|
||||||
|
@ -28,6 +54,9 @@ static uiCombobox *finishNewCombobox(GtkWidget *(*newfunc)(void))
|
||||||
c->combobox = GTK_COMBO_BOX(c->widget);
|
c->combobox = GTK_COMBO_BOX(c->widget);
|
||||||
c->comboboxText = GTK_COMBO_BOX_TEXT(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);
|
uiUnixFinishNewControl(c, uiCombobox);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
|
Loading…
Reference in New Issue