From 9a5bc738c507f3fc55f0ff65e5c1ccc23e6988a3 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 6 Jun 2016 19:51:46 -0400 Subject: [PATCH] Implemented likewise on Windows. --- windows/radiobuttons.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/windows/radiobuttons.cpp b/windows/radiobuttons.cpp index d2b80b53..3063d3cd 100644 --- a/windows/radiobuttons.cpp +++ b/windows/radiobuttons.cpp @@ -12,6 +12,8 @@ struct uiRadioButtons { uiWindowsControl c; HWND hwnd; // of the container std::vector *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; + uiRadioButtonsOnSelected(r, defaultOnSelected, NULL); + return r; }