/********************************************************************* * * _RADIO_Callback */ static void _RADIO_Callback (WM_MESSAGE* pMsg) { RADIO_Handle hObj; RADIO_Obj* pObj; hObj = pMsg->hWin; pObj = RADIO_H2P(hObj); /* Let widget handle the standard messages */ if (WIDGET_HandleActive(hObj, pMsg) == 0) { return; } switch (pMsg->MsgId) { case WM_PAINT: GUI_DEBUG_LOG("RADIO: _Callback(WM_PAINT)\n"); _OnPaint(hObj, pObj); return; case WM_GET_RADIOGROUP: pMsg->Data.v = pObj->GroupId; return; case WM_TOUCH: _OnTouch(hObj, pObj, pMsg); break; case WM_KEY: _OnKey(hObj, pMsg); break; case WM_DELETE: GUI_ARRAY_Delete(&pObj->TextArray); break; } WM_DefaultProc(pMsg); }
/********************************************************************* * * RADIO_AddValue */ void RADIO_AddValue(RADIO_Handle hObj, int Add) { if (hObj) { RADIO_Obj* pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); RADIO_SetValue(hObj, pObj->Sel + Add); WM_UNLOCK(); } }
/********************************************************************* * * RADIO_GetValue */ int RADIO_GetValue(RADIO_Handle hObj) { int r = 0; if (hObj) { RADIO_Obj* pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); r = pObj->Sel; WM_UNLOCK(); } return r; }
/********************************************************************* * * RADIO_SetText */ void RADIO_SetText(RADIO_Handle hObj, const char* pText, unsigned Index) { if (hObj) { RADIO_Obj* pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); if (Index < (unsigned)pObj->NumItems) { GUI_ARRAY_SetItem(&pObj->TextArray, Index, pText, pText ? (GUI__strlen(pText) + 1) : 0); WM_InvalidateWindow(hObj); } WM_UNLOCK(); } }
/********************************************************************* * * RADIO_SetFont */ void RADIO_SetFont(RADIO_Handle hObj, const GUI_FONT GUI_UNI_PTR* pFont) { if (hObj) { RADIO_Obj* pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); if (pFont != pObj->pFont) { pObj->pFont = pFont; if (GUI_ARRAY_GetNumItems(&pObj->TextArray)) { WM_InvalidateWindow(hObj); } } WM_UNLOCK(); } }
/********************************************************************* * * RADIO_CreateEx */ RADIO_Handle RADIO_CreateEx(int x0, int y0, int xSize, int ySize, WM_HWIN hParent, int WinFlags, int ExFlags, int Id, int NumItems, int Spacing) { RADIO_Handle hObj; int Height, i; /* Calculate helper variables */ Height = RADIO__apDefaultImage[0]->YSize + RADIO_BORDER * 2; Spacing = (Spacing <= 0) ? 20 : Spacing; NumItems = (NumItems <= 0) ? 2 : NumItems; if (ySize == 0) { ySize = Height + ((NumItems - 1) * Spacing); } if (xSize == 0) { xSize = RADIO__apDefaultImage[0]->XSize + RADIO_BORDER * 2; } #if WM_SUPPORT_TRANSPARENCY WinFlags |= WM_CF_HASTRANS; #endif /* Create the window */ hObj = WM_CreateWindowAsChild(x0, y0, xSize, ySize, hParent, WinFlags, _RADIO_Callback, sizeof(RADIO_Obj) - sizeof(WM_Obj)); if (hObj) { RADIO_Obj* pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); /* Init sub-classes */ GUI_ARRAY_CREATE(&pObj->TextArray); for (i = 0; i < NumItems; i++) { GUI_ARRAY_AddItem(&pObj->TextArray, NULL, 0); } /* Init widget specific variables */ ExFlags &= RADIO_TEXTPOS_LEFT; WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE | ExFlags); /* Init member variables */ RADIO_INIT_ID(pObj); pObj->apBmRadio[0] = RADIO__apDefaultImage[0]; pObj->apBmRadio[1] = RADIO__apDefaultImage[1]; pObj->pBmCheck = RADIO__pDefaultImageCheck; pObj->pFont = RADIO__pDefaultFont; pObj->TextColor = RADIO__DefaultTextColor; pObj->BkColor = WM_GetBkColor(hParent); pObj->NumItems = NumItems; pObj->Spacing = Spacing; pObj->Height = Height; WM_UNLOCK(); } else { GUI_DEBUG_ERROROUT_IF(hObj==0, "RADIO_Create failed") } return hObj; }
/********************************************************************* * * 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(); } }
/********************************************************************* * * RADIO_SetImage */ void RADIO_SetImage(RADIO_Handle hObj, const GUI_BITMAP * pBitmap, unsigned int Index) { if (hObj) { RADIO_Obj * pObj; GUI_LOCK(); pObj = RADIO_H2P(hObj); switch (Index) { case RADIO_BI_INACTIV: case RADIO_BI_ACTIV: pObj->Props.apBmRadio[Index] = pBitmap; break; case RADIO_BI_CHECK: pObj->Props.pBmCheck = pBitmap; break; } WM_InvalidateWindow(hObj); GUI_UNLOCK(); } }
/********************************************************************* * * RADIO_SetBkColor */ void RADIO_SetBkColor(RADIO_Handle hObj, GUI_COLOR Color) { if (hObj) { RADIO_Obj* pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); if (Color != pObj->Props.BkColor) { pObj->Props.BkColor = Color; #if WM_SUPPORT_TRANSPARENCY if (Color <= 0xFFFFFF) { WM_SetTransState(hObj, 0); } else { WM_SetTransState(hObj, WM_CF_HASTRANS); } #endif WM_InvalidateWindow(hObj); } WM_UNLOCK(); } }
/********************************************************************* * * 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(); } }
/********************************************************************* * * RADIO_GetText */ int RADIO_GetText(RADIO_Handle hObj, unsigned Index, char * pBuffer, int MaxLen) { int Len = 0; if (hObj) { const char * pText; RADIO_Obj * pObj; WM_LOCK(); pObj = RADIO_H2P(hObj); if (Index < (unsigned)pObj->NumItems) { pText = (const char *)GUI_ARRAY_GetpItem(&pObj->TextArray, Index); if (pText) { Len = strlen(pText); if (Len > (MaxLen - 1)) { Len = MaxLen - 1; } memcpy(pBuffer, pText, Len); *(pBuffer + Len) = 0; } } WM_UNLOCK(); } return Len; }
/********************************************************************* * * _SetValue */ static void _SetValue(RADIO_Handle hObj, int v) { RADIO_Obj* pObj; pObj = RADIO_H2P(hObj); RADIO__SetValue(hObj, pObj, v); }