From a7293951f75d92a80d4d986ec7dda3fa25ab640b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 7 Apr 2015 04:02:21 -0400 Subject: Wrote up the initial uiButton implementation. It (mostly; just needs text and for that I need to add a uiControlHandle()) works! --- new/button_windows.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 new/button_windows.c (limited to 'new/button_windows.c') diff --git a/new/button_windows.c b/new/button_windows.c new file mode 100644 index 0000000..a66490d --- /dev/null +++ b/new/button_windows.c @@ -0,0 +1,73 @@ +// 7 april 2015 +#include "uipriv_windows.h" + +struct button { + uiControl *c; + void (*onClicked)(uiControl *, void *); + void *onClickedData; +}; + +#define B(x) ((struct button *) (x)) + +static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult) +{ + if (HIWORD(wParam) != BN_CLICKED) + return FALSE; + (*(B(data)->onClicked))(c, B(data)->onClickedData); + *lResult = 0; + return TRUE; +} + +static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult) +{ + return FALSE; +} + +static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height) +{ + // TODO +} + +static void defaultOnClicked(uiControl *c, void *data) +{ + // do nothing +} + +uiControl *uiNewButton(const char *text) +{ + struct button *b; + uiWindowsNewControlParams p; + WCHAR *wtext; + + b = uiNew(struct button); + + p.dwExStyle = 0; + p.lpClassName = L"button"; + p.dwStyle = BS_PUSHBUTTON; + p.hInstance = hInstance; + p.onWM_COMMAND = onWM_COMMAND; + p.onWM_NOTIFY = onWM_NOTIFY; + p.onCommandNotifyData = b; + p.preferredSize = preferredSize; + p.data = b; + b->c = uiWindowsNewControl(&p); + + wtext = toUTF16(text); + // TODO set text + uiFree(wtext); + + b->onClicked = defaultOnClicked; + + return b->c; +} + +// TODO text + +void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data) +{ + struct button *b; + + b = (struct button *) uiWindowsControlData(c); + b->onClicked = f; + b->onClickedData = data; +} -- cgit v1.2.3