Added basic uiComboboxes.

This commit is contained in:
Pietro Gagliardi 2015-05-20 17:09:58 -04:00
parent 0c061e3bd2
commit 237cdffee6
4 changed files with 101 additions and 0 deletions

View File

@ -28,6 +28,8 @@ SETTOO(Spinbox, High, 80)
SETTOO(Slider, Low, -80)
SETTOO(Slider, High, 80)
uiCombobox *cbox;
uiBox *makePage4(void)
{
uiBox *page4;
@ -73,5 +75,13 @@ uiBox *makePage4(void)
uiBoxAppend(hbox, uiControl(b), 0);
uiBoxAppend(page4, uiControl(hbox), 0);
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
cbox = uiNewCombobox();
uiComboboxAppend(cbox, "Item 1");
uiComboboxAppend(cbox, "Item 2");
uiComboboxAppend(cbox, "Item 3");
uiBoxAppend(page4, uiControl(cbox), 0);
return page4;
}

View File

@ -170,6 +170,11 @@ interface Separator from Control {
};
func NewHorizontalSeparator(void) *Separator;
interface Combobox from Control {
func Append(text *const char);
};
func NewCombobox(void) *Combobox;
interface Menu {
func AppendItem(name *const char) *MenuItem;
func AppendCheckItem(name *const char) *MenuItem;

View File

@ -4,6 +4,7 @@ osCFILES = \
windows/alloc.c \
windows/button.c \
windows/checkbox.c \
windows/combobox.c \
windows/container.c \
windows/control.c \
windows/debug.c \

85
redo/windows/combobox.c Normal file
View File

@ -0,0 +1,85 @@
// 20 may 2015
#include "uipriv_windows.h"
struct combobox {
uiCombobox c;
HWND hwnd;
};
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
{
return FALSE;
}
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
{
return FALSE;
}
static BOOL onWM_HSCROLL(uiControl *c, WORD code, LRESULT *lResult)
{
return FALSE;
}
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);
}
uiCombobox *uiNewCombobox(void)
{
struct combobox *c;
uiWindowsMakeControlParams p;
c = uiNew(struct combobox);
uiTyped(c)->Type = uiTypeCombobox();
p.dwExStyle = WS_EX_CLIENTEDGE;
p.lpClassName = L"combobox";
p.lpWindowName = L"";
p.dwStyle = CBS_DROPDOWNLIST | WS_TABSTOP;
p.hInstance = hInstance;
p.lpParam = NULL;
p.useStandardControlFont = TRUE;
p.onWM_COMMAND = onWM_COMMAND;
p.onWM_NOTIFY = onWM_NOTIFY;
p.onWM_HSCROLL = onWM_HSCROLL;
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);
}