/********************************************************************* * * _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); } } } }
/********************************************************************* * * 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(); } }
/********************************************************************* * * _HandleSetValue */ static void _HandleSetValue(RADIO_Handle hObj, RADIO_Obj* pObj, int v) { if (v < 0) { WM_HWIN hWin = _GetPrevInGroup(hObj, pObj->GroupId); if (hWin) { WM_SetFocus(hWin); _SetValue(hWin, 0x7FFF); RADIO__SetValue(hObj, pObj, -1); } } else if (v >= pObj->NumItems) { WM_HWIN hWin = _GetNextInGroup(pObj->Widget.Win.hNext, pObj->GroupId); if (hWin) { WM_SetFocus(hWin); _SetValue(hWin, 0); RADIO__SetValue(hObj, pObj, -1); } } else { if (pObj->Sel != v) { _ClearSelection(hObj, pObj->GroupId); RADIO__SetValue(hObj, pObj, v); } } }
/********************************************************************* * * RADIO_SetValue */ void RADIO_SetValue(RADIO_Handle hObj, int v) { if (hObj) { RADIO_Obj* pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); if (pObj->GroupId && RADIO__pfHandleSetValue) { (*RADIO__pfHandleSetValue)(hObj, pObj, v); } else { if (v < 0) { v = 0; } RADIO__SetValue(hObj, pObj, v); } WM_UNLOCK(); } }
/********************************************************************* * * _SetValue */ static void _SetValue(RADIO_Handle hObj, int v) { RADIO_Obj* pObj; pObj = RADIO_H2P(hObj); RADIO__SetValue(hObj, pObj, v); }