Implemented likewise on Windows.

This commit is contained in:
Pietro Gagliardi 2016-06-06 19:51:46 -04:00
parent 8ede507d36
commit 9a5bc738c5
1 changed files with 37 additions and 0 deletions

View File

@ -12,6 +12,8 @@ struct uiRadioButtons {
uiWindowsControl c;
HWND hwnd; // of the container
std::vector<HWND> *hwnds; // of the buttons
void (*onSelected)(uiRadioButtons *, void *);
void *onSelectedData;
};
static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult)
@ -28,10 +30,16 @@ static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult
check = BST_CHECKED;
SendMessage(hwnd, BM_SETCHECK, check, 0);
}
(*(r->onSelected))(r, r->onSelectedData);
*lResult = 0;
return TRUE;
}
static void defaultOnSelected(uiRadioButtons *r, void *data)
{
// do nothing
}
static void uiRadioButtonsDestroy(uiControl *c)
{
uiRadioButtons *r = uiRadioButtons(c);
@ -141,6 +149,33 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
uiWindowsControlMinimumSizeChanged(uiWindowsControl(r));
}
intmax_t uiRadioButtonsSelected(uiRadioButtons *r)
{
size_t i;
for (i = 0; i < r->hwnds->size(); i++)
if (SendMessage((*(r->hwnds))[i], BM_GETCHECK, 0, 0) == BST_CHECKED)
return i;
return -1;
}
void uiRadioButtonsSetSelected(uiRadioButtons *r, intmax_t n)
{
intmax_t m;
m = uiRadioButtonsSelected(r);
if (m != -1)
SendMessage((*(r->hwnds))[m], BM_SETCHECK, BST_UNCHECKED, 0);
if (n != -1)
SendMessage((*(r->hwnds))[n], BM_SETCHECK, BST_CHECKED, 0);
}
void uiRadioButtonsOnSelected(uiRadioButtons *r, void (*f)(uiRadioButtons *, void *), void *data)
{
r->onSelected = f;
r->onSelectedData = data;
}
static void onResize(uiWindowsControl *c)
{
radiobuttonsRelayout(uiRadioButtons(c));
@ -156,5 +191,7 @@ uiRadioButtons *uiNewRadioButtons(void)
r->hwnds = new std::vector<HWND>;
uiRadioButtonsOnSelected(r, defaultOnSelected, NULL);
return r;
}