/********************************************************************* * * LISTBOX_SetItemDisabled */ void LISTBOX_SetItemDisabled(LISTBOX_Handle hObj, unsigned Index, int OnOff) { if (hObj) { unsigned NumItems; LISTBOX_Obj* pObj; WM_LOCK(); pObj = LISTBOX_H2P(hObj); NumItems = LISTBOX__GetNumItems(pObj); if (Index < NumItems) { WM_HMEM hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, Index); if (hItem) { LISTBOX_ITEM * pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem); if (OnOff) { if (!(pItem->Status & LISTBOX_ITEM_DISABLED)) { pItem->Status |= LISTBOX_ITEM_DISABLED; LISTBOX__InvalidateItem(hObj, pObj, Index); } } else { if (pItem->Status & LISTBOX_ITEM_DISABLED) { pItem->Status &= ~LISTBOX_ITEM_DISABLED; LISTBOX__InvalidateItem(hObj, pObj, Index); } } } } WM_UNLOCK(); } }
/********************************************************************* * * _ToggleMultiSel */ static void _ToggleMultiSel(LISTBOX_Handle hObj, LISTBOX_Obj* pObj, int Sel) { if (pObj->Flags & LISTBOX_SF_MULTISEL) { WM_HMEM hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, Sel); if (hItem) { LISTBOX_ITEM * pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem); if (!(pItem->Status & LISTBOX_ITEM_DISABLED)) { pItem->Status ^= LISTBOX_ITEM_SELECTED; _NotifyOwner(hObj, WM_NOTIFICATION_SEL_CHANGED); LISTBOX__InvalidateItem(hObj, pObj, Sel); } } } }
/********************************************************************* * * LISTBOX_GetItemDisabled */ int LISTBOX_GetItemDisabled(LISTBOX_Handle hObj, unsigned Index) { int Ret = 0; if (hObj) { unsigned NumItems; LISTBOX_Obj* pObj; WM_LOCK(); pObj = LISTBOX_H2P(hObj); NumItems = LISTBOX__GetNumItems(pObj); if (Index < NumItems) { WM_HMEM hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, Index); if (hItem) { LISTBOX_ITEM * pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem); if (pItem->Status & LISTBOX_ITEM_DISABLED) { Ret = 1; } } } WM_UNLOCK(); } return Ret; }
/********************************************************************* * * LISTBOX_GetItemSel */ int LISTBOX_GetItemSel(LISTBOX_Handle hObj, unsigned Index) { int Ret = 0; if (hObj) { unsigned NumItems; LISTBOX_Obj* pObj; WM_LOCK(); pObj = LISTBOX_H2P(hObj); NumItems = LISTBOX__GetNumItems(pObj); if ((Index < NumItems) && (pObj->Flags & LISTBOX_SF_MULTISEL)) { WM_HMEM hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, Index); if (hItem) { LISTBOX_ITEM * pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem); if (pItem->Status & LISTBOX_ITEM_SELECTED) { Ret = 1; } } } WM_UNLOCK(); } return Ret; }
/********************************************************************* * * LISTBOX_SetSel */ void LISTBOX_SetSel (LISTBOX_Handle hObj, int NewSel) { if (hObj) { LISTBOX_Obj* pObj; int MaxSel; WM_LOCK(); pObj = LISTBOX_H2P(hObj); MaxSel = LISTBOX__GetNumItems(pObj); MaxSel = MaxSel ? MaxSel - 1 : 0; if (NewSel > MaxSel) { NewSel = MaxSel; } if (NewSel < 0) { NewSel = -1; } else { WM_HMEM hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, NewSel); if (hItem) { LISTBOX_ITEM* pItem = (LISTBOX_ITEM*)GUI_ALLOC_h2p(hItem); if (pItem->Status & LISTBOX_ITEM_DISABLED) { NewSel = -1; } } } if (NewSel != pObj->Sel) { int OldSel; OldSel = pObj->Sel; pObj->Sel = NewSel; if (_UpdateScrollPos(hObj, pObj)) { LISTBOX__InvalidateInsideArea(hObj); } else { LISTBOX__InvalidateItem(hObj, pObj, OldSel); LISTBOX__InvalidateItem(hObj, pObj, NewSel); } _NotifyOwner(hObj, WM_NOTIFICATION_SEL_CHANGED); } WM_UNLOCK(); } }
/********************************************************************* * * _MoveSel * * Moves the selection/focus to the next valid item */ static void _MoveSel(LISTBOX_Handle hObj, int Dir) { int Index, NewSel = -1, NumItems; LISTBOX_Obj * pObj; pObj = LISTBOX_H2P(hObj); Index = LISTBOX_GetSel(hObj); NumItems = LISTBOX__GetNumItems(pObj); do { WM_HMEM hItem; Index += Dir; if ((Index < 0) || (Index >= NumItems)) { break; } hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, Index); if (hItem) { LISTBOX_ITEM * pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem); if (!(pItem->Status & LISTBOX_ITEM_DISABLED)) { NewSel = Index; } } } while(NewSel < 0); if (NewSel >= 0) { LISTBOX_SetSel(hObj, NewSel); } }
/********************************************************************* * * _GethItem Returns: Handle of the specified item */ static WM_HMEM _GethItem(DROPDOWN_Obj* pObj, int Index) { return GUI_ARRAY_GethItem(&pObj->Handles, Index); }
/********************************************************************* * * LISTBOX_OwnerDraw */ int LISTBOX_OwnerDraw(const WIDGET_ITEM_DRAW_INFO* pDrawItemInfo) { switch (pDrawItemInfo->Cmd) { case WIDGET_ITEM_GET_XSIZE: { LISTBOX_Obj* pObj; const GUI_FONT GUI_UNI_PTR* pOldFont; const char* s; int DistX; pObj = LISTBOX_H2P(pDrawItemInfo->hWin); pOldFont = GUI_SetFont(pObj->Props.pFont); s = LISTBOX__GetpString(pObj, pDrawItemInfo->ItemIndex); DistX = GUI_GetStringDistX(s); GUI_SetFont(pOldFont); return DistX; } case WIDGET_ITEM_GET_YSIZE: { LISTBOX_Obj* pObj; pObj = LISTBOX_H2P(pDrawItemInfo->hWin); return GUI_GetYDistOfFont(pObj->Props.pFont) + pObj->ItemSpacing; } case WIDGET_ITEM_DRAW: { LISTBOX_Obj* pObj; LISTBOX_ITEM* pItem; WM_HMEM hItem; GUI_RECT r; int FontDistY; int ItemIndex = pDrawItemInfo->ItemIndex; const char* s; int ColorIndex; char IsDisabled; char IsSelected; pObj = LISTBOX_H2P(pDrawItemInfo->hWin); hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, ItemIndex); pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem); WM_GetInsideRect(&r); FontDistY = GUI_GetFontDistY(); /* Calculate color index */ IsDisabled = (pItem->Status & LISTBOX_ITEM_DISABLED) ? 1 : 0; IsSelected = (pItem->Status & LISTBOX_ITEM_SELECTED) ? 1 : 0; if (pObj->Flags & LISTBOX_SF_MULTISEL) { if (IsDisabled) { ColorIndex = 3; } else { ColorIndex = (IsSelected) ? 2 : 0; } } else { if (IsDisabled) { ColorIndex = 3; } else { if (ItemIndex == pObj->Sel) { ColorIndex = (pObj->Widget.State & WIDGET_STATE_FOCUS) ? 2 : 1; } else { ColorIndex = 0; } } } /* Display item */ LCD_SetBkColor(pObj->Props.aBackColor[ColorIndex]); LCD_SetColor (pObj->Props.aTextColor[ColorIndex]); s = LISTBOX__GetpString(pObj, ItemIndex); GUI_SetTextMode(GUI_TM_TRANS); GUI_Clear(); GUI_DispStringAt(s, pDrawItemInfo->x0 + 1, pDrawItemInfo->y0); /* Display focus rectangle */ if ((pObj->Flags & LISTBOX_SF_MULTISEL) && (ItemIndex == pObj->Sel)) { GUI_RECT rFocus; rFocus.x0 = pDrawItemInfo->x0; rFocus.y0 = pDrawItemInfo->y0; rFocus.x1 = r.x1; rFocus.y1 = pDrawItemInfo->y0 + FontDistY - 1; LCD_SetColor(GUI_WHITE - pObj->Props.aBackColor[ColorIndex]); GUI_DrawFocusRect(&rFocus, 0); } return 0; } } return 0; }