2015-05-20 16:52:21 -05:00
|
|
|
// 20 may 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
|
|
|
struct radiobuttons {
|
|
|
|
uiRadioButtons r;
|
|
|
|
struct ptrArray *hwnds;
|
2015-05-21 14:48:16 -05:00
|
|
|
uiControl *parent;
|
2015-05-20 16:52:21 -05:00
|
|
|
};
|
2015-05-21 14:48:16 -05:00
|
|
|
|
2015-05-30 01:14:13 -05:00
|
|
|
uiDefineControlType(uiRadioButtons, uiTypeRadioButtons, struct radiobuttons)
|
|
|
|
|
2015-05-21 14:52:59 -05:00
|
|
|
static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult)
|
2015-05-21 14:48:16 -05:00
|
|
|
{
|
|
|
|
struct radiobuttons *r = (struct radiobuttons *) c;
|
2015-05-21 14:52:59 -05:00
|
|
|
WPARAM check;
|
|
|
|
uintmax_t i;
|
|
|
|
HWND hwnd;
|
2015-05-21 14:48:16 -05:00
|
|
|
|
|
|
|
if (code != BN_CLICKED)
|
|
|
|
return FALSE;
|
2015-05-21 14:52:59 -05:00
|
|
|
for (i = 0; i < r->hwnds->len; i++) {
|
|
|
|
hwnd = ptrArrayIndex(r->hwnds, HWND, i);
|
|
|
|
check = BST_UNCHECKED;
|
|
|
|
if (clicked == hwnd)
|
|
|
|
check = BST_CHECKED;
|
|
|
|
SendMessage(hwnd, BM_SETCHECK, check, 0);
|
|
|
|
}
|
2015-05-21 14:48:16 -05:00
|
|
|
*lResult = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:28:00 -05:00
|
|
|
static void radiobuttonsCommitDestroy(uiControl *c)
|
2015-05-21 14:48:16 -05:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
// radio buttons have more than one handle
|
|
|
|
// if we allow deletion, the handles are not permanent
|
|
|
|
static uintptr_t radiobuttonsHandle(uiControl *c)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:28:00 -05:00
|
|
|
static void radiobuttonsCommitSetParent(uiControl *c, uiControl *parent)
|
2015-05-21 14:48:16 -05:00
|
|
|
{
|
|
|
|
struct radiobuttons *r = (struct radiobuttons *) c;
|
|
|
|
HWND newParentHWND;
|
|
|
|
HWND hwnd;
|
|
|
|
uintmax_t i;
|
|
|
|
|
2015-05-29 21:28:00 -05:00
|
|
|
// TODO store the hwnd instead
|
2015-05-21 14:48:16 -05:00
|
|
|
r->parent = parent;
|
|
|
|
newParentHWND = utilWindow;
|
|
|
|
if (r->parent != NULL)
|
|
|
|
newParentHWND = (HWND) uiControlHandle(r->parent);
|
|
|
|
for (i = 0; i < r->hwnds->len; i++) {
|
|
|
|
hwnd = ptrArrayIndex(r->hwnds, HWND, i);
|
|
|
|
if (SetParent(hwnd, newParentHWND) == NULL)
|
|
|
|
logLastError("error setting radio button parent in radiobuttonsSetParent()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
2015-05-21 16:26:25 -05:00
|
|
|
#define radiobuttonHeight 10
|
2015-05-21 14:48:16 -05:00
|
|
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx
|
2015-05-21 16:26:25 -05:00
|
|
|
#define radiobuttonXFromLeftOfBoxToLeftOfLabel 12
|
|
|
|
|
|
|
|
// TODO vertical space between controls
|
2015-05-21 14:48:16 -05:00
|
|
|
|
|
|
|
static void radiobuttonsPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
|
|
|
{
|
|
|
|
struct radiobuttons *r = (struct radiobuttons *) c;
|
|
|
|
uintmax_t i;
|
|
|
|
intmax_t wid, maxwid;
|
|
|
|
|
|
|
|
maxwid = 0;
|
|
|
|
for (i = 0; i < r->hwnds->len; i++) {
|
|
|
|
wid = uiWindowsWindowTextWidth(ptrArrayIndex(r->hwnds, HWND, i));
|
|
|
|
if (maxwid < wid)
|
|
|
|
maxwid = wid;
|
|
|
|
}
|
2015-05-21 16:26:25 -05:00
|
|
|
*width = uiWindowsDlgUnitsToX(radiobuttonXFromLeftOfBoxToLeftOfLabel, d->Sys->BaseX) + maxwid;
|
|
|
|
*height = uiWindowsDlgUnitsToY(radiobuttonHeight, d->Sys->BaseY) * r->hwnds->len;
|
2015-05-21 14:48:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO clip to height
|
|
|
|
static void radiobuttonsResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
|
|
{
|
|
|
|
struct radiobuttons *r = (struct radiobuttons *) c;
|
|
|
|
intmax_t height1;
|
|
|
|
uintmax_t i;
|
|
|
|
HWND hwnd;
|
|
|
|
|
2015-05-21 16:26:25 -05:00
|
|
|
height1 = uiWindowsDlgUnitsToY(radiobuttonHeight, d->Sys->BaseY);
|
2015-05-21 14:48:16 -05:00
|
|
|
for (i = 0; i < r->hwnds->len; i++) {
|
|
|
|
hwnd = ptrArrayIndex(r->hwnds, HWND, i);
|
|
|
|
moveWindow(hwnd, x, y, width, height1, d);
|
|
|
|
y += height1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uiSizing *radiobuttonsSizing(uiControl *c)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void radiobuttonsSHED(uiControl *c)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
static void radiobuttonsSysFunc(uiControl *c, uiControlSysFuncParams *p)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
static int radiobuttonsStartZOrder(uiControl *c, uiControlSysFuncParams *p)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
|
|
|
|
{
|
|
|
|
struct radiobuttons *r = (struct radiobuttons *) rr;
|
|
|
|
HWND hwnd, parent;
|
|
|
|
WCHAR *wtext;
|
|
|
|
|
|
|
|
wtext = toUTF16(text);
|
|
|
|
parent = utilWindow;
|
|
|
|
if (r->parent != NULL)
|
|
|
|
parent = (HWND) uiControlHandle(r->parent);
|
|
|
|
hwnd = CreateWindowExW(0,
|
|
|
|
L"button", wtext,
|
|
|
|
BS_RADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE,
|
|
|
|
0, 0,
|
|
|
|
100, 100,
|
|
|
|
parent, NULL, hInstance, NULL);
|
|
|
|
if (hwnd == NULL)
|
|
|
|
logLastError("error creating radio button in radiobuttonsAppend()");
|
2015-05-21 14:52:59 -05:00
|
|
|
uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r));
|
2015-05-21 14:48:16 -05:00
|
|
|
ptrArrayAppend(r->hwnds, hwnd);
|
|
|
|
uiControlQueueResize(uiControl(r));
|
|
|
|
}
|
|
|
|
|
|
|
|
uiRadioButtons *uiNewRadioButtons(void)
|
|
|
|
{
|
|
|
|
struct radiobuttons *r;
|
|
|
|
|
|
|
|
r = uiNew(struct radiobuttons);
|
|
|
|
uiTyped(r)->Type = uiTypeRadioButtons();
|
|
|
|
|
|
|
|
r->hwnds = newPtrArray();
|
|
|
|
|
2015-05-29 21:28:00 -05:00
|
|
|
uiControl(r)->CommitDestroy = radiobuttonsCommitDestroy;
|
2015-05-21 14:48:16 -05:00
|
|
|
uiControl(r)->Handle = radiobuttonsHandle;
|
2015-05-29 21:28:00 -05:00
|
|
|
uiControl(r)->CommitSetParent = radiobuttonsCommitSetParent;
|
2015-05-21 14:48:16 -05:00
|
|
|
uiControl(r)->PreferredSize = radiobuttonsPreferredSize;
|
|
|
|
uiControl(r)->Resize = radiobuttonsResize;
|
|
|
|
uiControl(r)->Sizing = radiobuttonsSizing;
|
2015-05-29 21:28:00 -05:00
|
|
|
uiControl(r)->CommitShow = radiobuttonsSHED;
|
|
|
|
uiControl(r)->CommitHide = radiobuttonsSHED;
|
|
|
|
uiControl(r)->CommitEnable = radiobuttonsSHED;
|
|
|
|
uiControl(r)->CommitDisable = radiobuttonsSHED;
|
2015-05-21 14:48:16 -05:00
|
|
|
uiControl(r)->SysFunc = radiobuttonsSysFunc;
|
|
|
|
uiControl(r)->StartZOrder = radiobuttonsStartZOrder;
|
|
|
|
|
|
|
|
uiRadioButtons(r)->Append = radiobuttonsAppend;
|
|
|
|
|
|
|
|
return uiRadioButtons(r);
|
|
|
|
}
|