2015-05-20 16:09:58 -05:00
|
|
|
// 20 may 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
2015-05-22 08:43:45 -05:00
|
|
|
// TODO point to where it says size is autocomputed on comctl6
|
|
|
|
|
2015-05-20 16:09:58 -05:00
|
|
|
struct combobox {
|
|
|
|
uiCombobox c;
|
|
|
|
HWND hwnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void onDestroy(void *data)
|
|
|
|
{
|
|
|
|
struct combobox *c = (struct combobox *) data;
|
|
|
|
|
|
|
|
uiFree(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 comboboxHeight 14
|
|
|
|
|
|
|
|
static void comboboxPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
|
|
|
{
|
|
|
|
*width = uiWindowsDlgUnitsToX(comboboxWidth, d->Sys->BaseX);
|
|
|
|
*height = uiWindowsDlgUnitsToY(comboboxHeight, d->Sys->BaseY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void comboboxAppend(uiCombobox *cc, const char *text)
|
|
|
|
{
|
|
|
|
struct combobox *c = (struct combobox *) cc;
|
|
|
|
WCHAR *wtext;
|
|
|
|
LRESULT res;
|
|
|
|
|
|
|
|
wtext = toUTF16(text);
|
|
|
|
res = SendMessageW(c->hwnd, CB_ADDSTRING, 0, (LPARAM) wtext);
|
|
|
|
if (res == (LRESULT) CB_ERR)
|
|
|
|
logLastError("error appending item to uiCombobox");
|
|
|
|
else if (res == (LRESULT) CB_ERRSPACE)
|
|
|
|
logLastError("memory exhausted appending item to uiCombobox");
|
|
|
|
uiFree(wtext);
|
|
|
|
}
|
|
|
|
|
2015-05-21 20:45:31 -05:00
|
|
|
static uiCombobox *finishNewCombobox(DWORD style)
|
2015-05-20 16:09:58 -05:00
|
|
|
{
|
|
|
|
struct combobox *c;
|
|
|
|
uiWindowsMakeControlParams p;
|
|
|
|
|
|
|
|
c = uiNew(struct combobox);
|
|
|
|
uiTyped(c)->Type = uiTypeCombobox();
|
|
|
|
|
2015-05-22 09:36:24 -05:00
|
|
|
// TODO client edge?
|
2015-05-20 16:09:58 -05:00
|
|
|
p.dwExStyle = WS_EX_CLIENTEDGE;
|
|
|
|
p.lpClassName = L"combobox";
|
|
|
|
p.lpWindowName = L"";
|
2015-05-21 20:45:31 -05:00
|
|
|
p.dwStyle = style | WS_TABSTOP;
|
2015-05-20 16:09:58 -05:00
|
|
|
p.hInstance = hInstance;
|
|
|
|
p.lpParam = NULL;
|
|
|
|
p.useStandardControlFont = TRUE;
|
|
|
|
p.onDestroy = onDestroy;
|
|
|
|
p.onDestroyData = c;
|
|
|
|
uiWindowsMakeControl(uiControl(c), &p);
|
|
|
|
|
|
|
|
c->hwnd = (HWND) uiControlHandle(uiControl(c));
|
|
|
|
|
|
|
|
uiControl(c)->PreferredSize = comboboxPreferredSize;
|
|
|
|
|
|
|
|
uiCombobox(c)->Append = comboboxAppend;
|
|
|
|
|
|
|
|
return uiCombobox(c);
|
|
|
|
}
|
2015-05-21 20:45:31 -05:00
|
|
|
|
|
|
|
uiCombobox *uiNewCombobox(void)
|
|
|
|
{
|
|
|
|
return finishNewCombobox(CBS_DROPDOWNLIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiCombobox *uiNewEditableCombobox(void)
|
|
|
|
{
|
|
|
|
return finishNewCombobox(CBS_DROPDOWN);
|
|
|
|
}
|