2015-04-09 11:32:59 -05:00
|
|
|
// 7 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
|
|
|
struct checkbox {
|
|
|
|
void (*onToggled)(uiControl *, void *);
|
|
|
|
void *onToggledData;
|
|
|
|
};
|
|
|
|
|
2015-04-09 17:54:14 -05:00
|
|
|
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
|
2015-04-09 11:32:59 -05:00
|
|
|
{
|
2015-04-09 16:46:26 -05:00
|
|
|
struct checkbox *cc = (struct checkbox *) (c->data);
|
2015-04-09 11:32:59 -05:00
|
|
|
HWND hwnd;
|
|
|
|
WPARAM check;
|
|
|
|
|
2015-04-09 17:54:14 -05:00
|
|
|
if (code != BN_CLICKED)
|
2015-04-09 11:32:59 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// we didn't use BS_AUTOCHECKBOX (see controls_windows.go) so we have to manage the check state ourselves
|
|
|
|
hwnd = (HWND) uiControlHandle(c);
|
|
|
|
check = BST_CHECKED;
|
|
|
|
if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
|
|
|
check = BST_UNCHECKED;
|
|
|
|
SendMessage(hwnd, BM_SETCHECK, check, 0);
|
|
|
|
|
2015-04-09 16:46:26 -05:00
|
|
|
(*(cc->onToggled))(c, cc->onToggledData);
|
2015-04-09 11:32:59 -05:00
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-09 18:07:41 -05:00
|
|
|
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
|
2015-04-09 11:32:59 -05:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-04-09 16:46:26 -05:00
|
|
|
static void onWM_DESTROY(uiControl *c)
|
2015-04-09 11:32:59 -05:00
|
|
|
{
|
2015-04-09 16:46:26 -05:00
|
|
|
struct checkbox *cc = (struct checkbox *) (c->data);
|
2015-04-09 11:32:59 -05:00
|
|
|
|
|
|
|
uiFree(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
|
|
#define checkboxHeight 10
|
|
|
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx
|
|
|
|
#define checkboxXFromLeftOfBoxToLeftOfLabel 12
|
|
|
|
|
2015-04-09 16:46:26 -05:00
|
|
|
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
2015-04-09 11:32:59 -05:00
|
|
|
{
|
2015-04-09 17:45:58 -05:00
|
|
|
*width = uiDlgUnitsToX(checkboxXFromLeftOfBoxToLeftOfLabel, d->sys->baseX) + uiWindowsWindowTextWidth((HWND) uiControlHandle(c));
|
|
|
|
*height = uiDlgUnitsToY(checkboxHeight, d->sys->baseY);
|
2015-04-09 11:32:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnToggled(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
uiControl *uiNewCheckbox(const char *text)
|
|
|
|
{
|
2015-04-09 16:46:26 -05:00
|
|
|
uiControl *c;
|
|
|
|
struct checkbox *cc;
|
2015-04-09 11:32:59 -05:00
|
|
|
uiWindowsNewControlParams p;
|
|
|
|
WCHAR *wtext;
|
|
|
|
|
|
|
|
p.dwExStyle = 0;
|
|
|
|
p.lpClassName = L"button";
|
|
|
|
wtext = toUTF16(text);
|
|
|
|
p.lpWindowName = wtext;
|
|
|
|
p.dwStyle = BS_CHECKBOX | WS_TABSTOP;
|
|
|
|
p.hInstance = hInstance;
|
2015-04-10 16:53:59 -05:00
|
|
|
p.useStandardControlFont = TRUE;
|
2015-04-09 11:32:59 -05:00
|
|
|
p.onWM_COMMAND = onWM_COMMAND;
|
|
|
|
p.onWM_NOTIFY = onWM_NOTIFY;
|
|
|
|
p.onWM_DESTROY = onWM_DESTROY;
|
2015-04-09 16:46:26 -05:00
|
|
|
c = uiWindowsNewControl(&p);
|
2015-04-09 11:32:59 -05:00
|
|
|
uiFree(wtext);
|
|
|
|
|
2015-04-09 16:46:26 -05:00
|
|
|
c->preferredSize = preferredSize;
|
|
|
|
|
|
|
|
cc = uiNew(struct checkbox);
|
|
|
|
cc->onToggled = defaultOnToggled;
|
|
|
|
c->data = cc;
|
2015-04-09 11:32:59 -05:00
|
|
|
|
2015-04-09 16:46:26 -05:00
|
|
|
return c;
|
2015-04-09 11:32:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
char *uiCheckboxText(uiControl *c)
|
|
|
|
{
|
|
|
|
return uiWindowsControlText(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiCheckboxSetText(uiControl *c, const char *text)
|
|
|
|
{
|
|
|
|
uiWindowsControlSetText(c, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiCheckboxOnToggled(uiControl *c, void (*f)(uiControl *, void *), void *data)
|
|
|
|
{
|
2015-04-09 16:46:26 -05:00
|
|
|
struct checkbox *cc = (struct checkbox *) (c->data);
|
2015-04-09 11:32:59 -05:00
|
|
|
|
|
|
|
cc->onToggled = f;
|
|
|
|
cc->onToggledData = data;
|
|
|
|
}
|
2015-04-09 12:10:32 -05:00
|
|
|
|
|
|
|
int uiCheckboxChecked(uiControl *c)
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
|
|
|
|
hwnd = (HWND) uiControlHandle(c);
|
|
|
|
return SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiCheckboxSetChecked(uiControl *c, int checked)
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
WPARAM check;
|
|
|
|
|
|
|
|
hwnd = (HWND) uiControlHandle(c);
|
|
|
|
check = BST_CHECKED;
|
|
|
|
if (!checked)
|
|
|
|
check = BST_UNCHECKED;
|
|
|
|
SendMessage(hwnd, BM_SETCHECK, check, 0);
|
|
|
|
}
|