More uiRadioButtons work.

This commit is contained in:
Pietro Gagliardi 2015-09-02 18:26:48 -04:00
parent a797c255c1
commit 80a5f1ac29
2 changed files with 25 additions and 33 deletions

View File

@ -5,6 +5,9 @@ HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCW
{ {
HWND hwnd; HWND hwnd;
// don't let using the arrow keys in a uiRadioButtons leave the radio buttons
if ((dwStyle & WS_TABSTOP) != 0)
dwStyle |= WS_GROUP;
hwnd = CreateWindowExW(dwExStyle, hwnd = CreateWindowExW(dwExStyle,
lpClassName, lpWindowName, lpClassName, lpWindowName,
dwStyle | WS_CHILD | WS_VISIBLE, dwStyle | WS_CHILD | WS_VISIBLE,

View File

@ -2,8 +2,11 @@
#include "uipriv_windows.h" #include "uipriv_windows.h"
// desired behavior: // desired behavior:
// - tab moves between /entire groups/ // - tab moves between the radio buttons and the adjacent controls
// - arrow keys navigate between radio buttons // - arrow keys navigate between radio buttons
// - arrow keys do not leave the radio buttons (this is done in control.c)
// - arrow keys wrap around bare groups (if the previous control has WS_GROUP but the first radio button doesn't, then it doesn't; since our radio buttons are all in their own child window we can't do that)
// - clicking on a radio button draws a focus rect
struct uiRadioButtons { struct uiRadioButtons {
uiWindowsControl c; uiWindowsControl c;
@ -19,9 +22,6 @@ uiWindowsDefineControlWithOnDestroy(
onDestroy(this); // on destroy onDestroy(this); // on destroy
) )
// TODO arrow keys don't work for changing items
// TODO this wrecks the z-order
static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult) static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult)
{ {
uiRadioButtons *r = uiRadioButtons(c); uiRadioButtons *r = uiRadioButtons(c);
@ -107,57 +107,46 @@ static void radiobuttonsRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, in
// TODO commit enable/disable // TODO commit enable/disable
/* TODO static void redoControlIDsZOrder(uiRadioButtons *r)
static uintptr_t radiobuttonsStartZOrder(uiControl *c)
{ {
struct radiobuttons *r = (struct radiobuttons *) c;
return r->insertAfter;
}
static uintptr_t radiobuttonsSetZOrder(uiControl *c, uintptr_t insertAfter)
{
struct radiobuttons *r = (struct radiobuttons *) c;
uintmax_t i;
HWND hwnd; HWND hwnd;
uintmax_t i;
LONG_PTR controlID;
HWND insertAfter;
r->insertAfter = insertAfter; controlID = 100;
insertAfter = NULL;
for (i = 0; i < r->hwnds->len; i++) { for (i = 0; i < r->hwnds->len; i++) {
hwnd = ptrArrayIndex(r->hwnds, HWND, i); hwnd = ptrArrayIndex(r->hwnds, HWND, i);
uiWindowsUtilSetZOrder(hwnd, insertAfter); uiWindowsEnsureAssignControlIDZOrder(hwnd, controlID, insertAfter);
insertAfter = (uintptr_t) hwnd; controlID++;
insertAfter = hwnd;
} }
return insertAfter;
} }
*/
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text) void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
{ {
HWND hwnd; HWND hwnd;
WCHAR *wtext; WCHAR *wtext;
//TODO HWND after; DWORD groupTabStop;
// the first radio button gets both WS_GROUP and WS_TABSTOP
// successive radio buttons get *neither*
groupTabStop = 0;
if (r->hwnds->len == 0)
groupTabStop = WS_GROUP | WS_TABSTOP;
wtext = toUTF16(text); wtext = toUTF16(text);
hwnd = uiWindowsEnsureCreateControlHWND(0, hwnd = uiWindowsEnsureCreateControlHWND(0,
L"button", wtext, L"button", wtext,
BS_RADIOBUTTON | WS_TABSTOP, BS_RADIOBUTTON | groupTabStop,
hInstance, NULL, hInstance, NULL,
TRUE); TRUE);
uiFree(wtext); uiFree(wtext);
uiWindowsEnsureSetParent(hwnd, r->hwnd); uiWindowsEnsureSetParent(hwnd, r->hwnd);
uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r)); uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r));
/* TODO
// maintain z-order
if (r->hwnds->len == 0) // first item
uiWindowsUtilSetZOrder(hwnd, r->insertAfter);
else {
after = ptrArrayIndex(r->hwnds, HWND, r->hwnds->len - 1);
uiWindowsUtilSetZOrder(hwnd, (uintptr_t) after);
}
*/
ptrArrayAppend(r->hwnds, hwnd); ptrArrayAppend(r->hwnds, hwnd);
redoControlIDsZOrder(r);
uiWindowsControlQueueRelayout(uiWindowsControl(r)); uiWindowsControlQueueRelayout(uiWindowsControl(r));
} }