2015-11-26 17:27:23 -06:00
|
|
|
// 26 november 2015
|
|
|
|
#include "uipriv_wpf.hpp"
|
|
|
|
|
|
|
|
struct uiCombobox {
|
|
|
|
uiWindowsControl c;
|
2015-11-26 18:11:55 -06:00
|
|
|
gcroot<ComboBox ^> *combobox;
|
|
|
|
void (*onSelected)(uiCombobox *, void *);
|
|
|
|
void *onSelectedData;
|
2015-11-26 17:27:23 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
uiWindowsDefineControl(
|
|
|
|
uiCombobox, // type name
|
|
|
|
uiComboboxType, // type function
|
2015-11-26 18:11:55 -06:00
|
|
|
combobox // handle
|
2015-11-26 17:27:23 -06:00
|
|
|
)
|
|
|
|
|
2015-11-26 18:11:55 -06:00
|
|
|
static void defaultOnSelected(uiCombobox *c, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-11-26 17:27:23 -06:00
|
|
|
void uiComboboxAppend(uiCombobox *c, const char *text)
|
|
|
|
{
|
2015-11-26 18:11:55 -06:00
|
|
|
(*(c->combobox))->Items->Add(fromUTF8(text));
|
2015-11-26 17:27:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
intmax_t uiComboboxSelected(uiCombobox *c)
|
|
|
|
{
|
2015-11-26 18:11:55 -06:00
|
|
|
// TODO what happens on an editable combobox?
|
|
|
|
return (*(c->combobox))->SelectedIndex;
|
2015-11-26 17:27:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiComboboxSetSelected(uiCombobox *c, intmax_t n)
|
|
|
|
{
|
2015-11-26 18:11:55 -06:00
|
|
|
(*(c->combobox))->SelectedIndex = n;
|
2015-11-26 17:27:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data)
|
|
|
|
{
|
2015-11-26 18:11:55 -06:00
|
|
|
c->onSelected = f;
|
|
|
|
c->onSelectedData = data;
|
2015-11-26 17:27:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static uiCombobox *finishNewCombobox(bool editable)
|
|
|
|
{
|
|
|
|
uiCombobox *c;
|
|
|
|
|
|
|
|
c = (uiCombobox *) uiNewControl(uiComboboxType());
|
|
|
|
|
2015-11-26 18:11:55 -06:00
|
|
|
c->combobox = new gcroot<ComboBox ^>();
|
|
|
|
*(c->combobox) = gcnew ComboBox();
|
2015-11-26 19:34:21 -06:00
|
|
|
(*(c->combobox))->IsEditable = editable;
|
2015-11-26 17:27:23 -06:00
|
|
|
|
2015-11-26 18:11:55 -06:00
|
|
|
uiComboboxOnSelected(c, defaultOnSelected, NULL);
|
2015-11-26 17:27:23 -06:00
|
|
|
|
2015-11-26 18:11:55 -06:00
|
|
|
uiWindowsFinishNewControl(c, uiCombobox, combobox);
|
2015-11-26 17:27:23 -06:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiCombobox *uiNewCombobox(void)
|
|
|
|
{
|
2015-11-26 19:34:21 -06:00
|
|
|
return finishNewCombobox(false);
|
2015-11-26 17:27:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
uiCombobox *uiNewEditableCombobox(void)
|
|
|
|
{
|
2015-11-26 19:34:21 -06:00
|
|
|
return finishNewCombobox(true);
|
2015-11-26 17:27:23 -06:00
|
|
|
}
|