Implemented the new combobox stuff on Windows.
This commit is contained in:
parent
06f17aa4de
commit
eb96d5edb0
|
@ -6,13 +6,28 @@
|
||||||
struct uiCombobox {
|
struct uiCombobox {
|
||||||
uiWindowsControl c;
|
uiWindowsControl c;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
|
void (*onSelected)(uiCombobox *, void *);
|
||||||
|
void *onSelectedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiWindowsDefineControl(
|
uiWindowsDefineControlWithOnDestroy(
|
||||||
uiCombobox, // type name
|
uiCombobox, // type name
|
||||||
uiComboboxType // type function
|
uiComboboxType, // type function
|
||||||
|
uiWindowsUnregisterWM_COMMANDHandler(this->hwnd); // on destroy
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// note: NOT triggered on entering text
|
||||||
|
static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult)
|
||||||
|
{
|
||||||
|
uiCombobox *c = uiCombobox(cc);
|
||||||
|
|
||||||
|
if (code != CBN_SELCHANGE)
|
||||||
|
return FALSE;
|
||||||
|
(*(c->onSelected))(c, c->onSelectedData);
|
||||||
|
*lResult = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */
|
#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */
|
||||||
#define comboboxHeight 14
|
#define comboboxHeight 14
|
||||||
|
@ -23,6 +38,11 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width
|
||||||
*height = uiWindowsDlgUnitsToY(comboboxHeight, d->BaseY);
|
*height = uiWindowsDlgUnitsToY(comboboxHeight, d->BaseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void defaultOnSelected(uiCombobox *c, void *data)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
void uiComboboxAppend(uiCombobox *c, const char *text)
|
void uiComboboxAppend(uiCombobox *c, const char *text)
|
||||||
{
|
{
|
||||||
WCHAR *wtext;
|
WCHAR *wtext;
|
||||||
|
@ -37,6 +57,22 @@ void uiComboboxAppend(uiCombobox *c, const char *text)
|
||||||
uiFree(wtext);
|
uiFree(wtext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intmax_t uiComboboxSelected(uiCombobox *c)
|
||||||
|
{
|
||||||
|
LRESULT n;
|
||||||
|
|
||||||
|
n = SendMessage(c->hwnd, CB_GETCURSEL, 0, 0);
|
||||||
|
if (n == (LRESULT) CB_ERR)
|
||||||
|
return -1;
|
||||||
|
return (intmax_t) n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data)
|
||||||
|
{
|
||||||
|
c->onSelected = f;
|
||||||
|
c->onSelectedData = data;
|
||||||
|
}
|
||||||
|
|
||||||
static uiCombobox *finishNewCombobox(DWORD style)
|
static uiCombobox *finishNewCombobox(DWORD style)
|
||||||
{
|
{
|
||||||
uiCombobox *c;
|
uiCombobox *c;
|
||||||
|
@ -49,6 +85,9 @@ static uiCombobox *finishNewCombobox(DWORD style)
|
||||||
hInstance, NULL,
|
hInstance, NULL,
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
|
uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c));
|
||||||
|
uiComboboxOnSelected(c, defaultOnSelected, NULL);
|
||||||
|
|
||||||
uiWindowsFinishNewControl(c, uiCombobox);
|
uiWindowsFinishNewControl(c, uiCombobox);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
|
Loading…
Reference in New Issue