/********************************************************************* * * _ClearSelection */ static void _ClearSelection(RADIO_Handle hObj, U8 GroupId) { WM_HWIN hWin; WM_Obj* pWin; for (hWin = WM__GetFirstSibling(hObj); hWin; hWin = pWin->hNext) { pWin = WM_H2P(hWin); if (hWin != hObj) { if (_IsInGroup(hWin, GroupId)) { RADIO__SetValue(hWin, (RADIO_Obj*)pWin, -1); } } } }
/********************************************************************* * * WM__GetPrevSibling Return value: Handle of previous sibling (if any), otherwise 0 */ WM_HWIN WM__GetPrevSibling(WM_HWIN hWin) { WM_HWIN hi; WM_Obj* pi; for (hi = WM__GetFirstSibling(hWin); hi; hi = pi->hNext) { if (hi == hWin) { hi = 0; /* There is no previous sibling. Return 0 */ break; } pi = WM_H2P(hi); if (pi->hNext == hWin) { break; /* We found the previous one ! */ } } return hi; }
/********************************************************************* * * RADIO_SetGroupId */ void RADIO_SetGroupId(RADIO_Handle hObj, U8 NewGroupId) { if (hObj) { RADIO_Obj* pObj; U8 OldGroupId; WM_LOCK(); pObj = RADIO_H2P(hObj); OldGroupId = pObj->GroupId; if (NewGroupId != OldGroupId) { WM_HWIN hFirst; hFirst = WM__GetFirstSibling(hObj); /* Set function pointer if necessary */ if (NewGroupId && (RADIO__pfHandleSetValue == NULL)) { RADIO__pfHandleSetValue = _HandleSetValue; } /* Pass our selection, if we have one, to another radio button in */ /* our old group. So the group have a valid selection when we leave it. */ if (OldGroupId && (pObj->Sel >= 0)) { WM_HWIN hWin; pObj->GroupId = 0; /* Leave group first, so _GetNextInGroup() could */ /* not find a handle to our own window. */ hWin = _GetNextInGroup(hFirst, OldGroupId); if (hWin) { _SetValue(hWin, 0); } } /* Make sure we have a valid selection according to our new group */ if (_GetNextInGroup(hFirst, NewGroupId) != 0) { /* Join an existing group with an already valid selection, so clear our own one */ RADIO__SetValue(hObj, pObj, -1); } else if (pObj->Sel < 0) { /* We are the first window in group, so we must have a valid selection at our own. */ RADIO__SetValue(hObj, pObj, 0); } /* Change the group */ pObj->GroupId = NewGroupId; } WM_UNLOCK(); } }