diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-15 18:49:45 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-15 18:49:45 -0400 |
| commit | 518a5ddbf15d50a254c732a80d5907ef8878abe0 (patch) | |
| tree | 48cf259f98994e4570e65c389fcd9824272884ad /new/button_windows.c | |
| parent | 50ae3ca045e7f5f5744043df0a4506e2f6930bb1 (diff) | |
Split all OS backends into their own folders.
Diffstat (limited to 'new/button_windows.c')
| -rw-r--r-- | new/button_windows.c | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/new/button_windows.c b/new/button_windows.c deleted file mode 100644 index f89a197..0000000 --- a/new/button_windows.c +++ /dev/null @@ -1,108 +0,0 @@ -// 7 april 2015 -#include "uipriv_windows.h" - -struct button { - void (*onClicked)(uiControl *, void *); - void *onClickedData; -}; - -static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult) -{ - struct button *b = (struct button *) (c->data); - - if (code != BN_CLICKED) - return FALSE; - (*(b->onClicked))(c, b->onClickedData); - *lResult = 0; - return TRUE; -} - -static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult) -{ - return FALSE; -} - -static void onWM_DESTROY(uiControl *c) -{ - struct button *b = (struct button *) (c->data); - - uiFree(b); -} - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define buttonHeight 14 - -static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) -{ - HWND hwnd; - SIZE size; - - hwnd = uiControlHWND(c); - - // try the comctl32 version 6 way - size.cx = 0; // explicitly ask for ideal size - size.cy = 0; - if (SendMessageW(hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) { - *width = size.cx; - *height = size.cy; - return; - } - - // that didn't work; fall back to using Microsoft's metrics - // Microsoft says to use a fixed width for all buttons; this isn't good enough - // use the text width instead, with some edge padding - *width = uiWindowsWindowTextWidth(hwnd) + (2 * GetSystemMetrics(SM_CXEDGE)); - *height = uiDlgUnitsToY(buttonHeight, d->sys->baseY); -} - -static void defaultOnClicked(uiControl *c, void *data) -{ - // do nothing -} - -uiControl *uiNewButton(const char *text) -{ - uiControl *c; - struct button *b; - uiWindowsNewControlParams p; - WCHAR *wtext; - - p.dwExStyle = 0; - p.lpClassName = L"button"; - wtext = toUTF16(text); - p.lpWindowName = wtext; - p.dwStyle = BS_PUSHBUTTON | WS_TABSTOP; - p.hInstance = hInstance; - p.useStandardControlFont = TRUE; - p.onWM_COMMAND = onWM_COMMAND; - p.onWM_NOTIFY = onWM_NOTIFY; - p.onWM_DESTROY = onWM_DESTROY; - c = uiWindowsNewControl(&p); - uiFree(wtext); - - c->preferredSize = preferredSize; - - b = uiNew(struct button); - b->onClicked = defaultOnClicked; - c->data = b; - - return c; -} - -char *uiButtonText(uiControl *c) -{ - return uiWindowsControlText(c); -} - -void uiButtonSetText(uiControl *c, const char *text) -{ - uiWindowsControlSetText(c, text); -} - -void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data) -{ - struct button *b = (struct button *) (c->data); - - b->onClicked = f; - b->onClickedData = data; -} |
