libui/windows/combobox.c

74 lines
1.9 KiB
C
Raw Normal View History

2015-05-20 16:09:58 -05:00
// 20 may 2015
#include "uipriv_windows.h"
2015-06-02 11:55:12 -05:00
// we as Common Controls 6 users don't need to worry about the height of comboboxes; see http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx
2015-05-22 08:43:45 -05:00
2015-05-20 16:09:58 -05:00
struct combobox {
uiCombobox c;
HWND hwnd;
};
uiDefineControlType(uiCombobox, uiTypeCombobox, struct combobox)
2015-05-20 16:09:58 -05:00
static uintptr_t comboboxHandle(uiControl *cc)
{
struct combobox *c = (struct combobox *) cc;
return (uintptr_t) (c->hwnd);
}
2015-05-20 16:09:58 -05:00
// 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);
}
static uiCombobox *finishNewCombobox(DWORD style)
2015-05-20 16:09:58 -05:00
{
struct combobox *c;
c = (struct combobox *) uiWindowsNewSingleHWNDControl(uiTypeCombobox());
2015-05-20 16:09:58 -05:00
c->hwnd = uiWindowsUtilCreateControlHWND(WS_EX_CLIENTEDGE,
L"combobox", L"",
style | WS_TABSTOP,
hInstance, NULL,
TRUE);
2015-05-20 16:09:58 -05:00
uiControl(c)->Handle = comboboxHandle;
2015-05-20 16:09:58 -05:00
uiControl(c)->PreferredSize = comboboxPreferredSize;
uiCombobox(c)->Append = comboboxAppend;
return uiCombobox(c);
}
uiCombobox *uiNewCombobox(void)
{
return finishNewCombobox(CBS_DROPDOWNLIST);
}
uiCombobox *uiNewEditableCombobox(void)
{
return finishNewCombobox(CBS_DROPDOWN);
}