Esempio n. 1
0
/*********************************************************************
*
*       LISTBOX_CreateEx
*/
LISTBOX_Handle LISTBOX_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
                                int WinFlags, int ExFlags, int Id, const GUI_ConstString* ppText)
{
  LISTBOX_Handle hObj;
  GUI_USE_PARA(ExFlags);
  hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WinFlags, _LISTBOX_Callback,
                                sizeof(LISTBOX_Obj) - sizeof(WM_Obj));
  if (hObj) {
    LISTBOX_Obj* pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
     /* Init sub-classes */
    GUI_ARRAY_CREATE(&pObj->ItemArray);
   /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE);
    pObj->Props = LISTBOX_DefaultProps;
    if (ppText) {
      /* init member variables */
      /* Set non-zero attributes */
      LISTBOX_SetText(hObj, ppText);
    }
    INIT_ID(pObj);
    LISTBOX_UpdateScrollers(hObj);
    WM_UNLOCK();
  }
  return hObj;
}
/*********************************************************************
*
*       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();
  }
}
Esempio n. 3
0
/*********************************************************************
*
*       _AddKey
*
* Returns: 1 if Key has been consumed
*          0 else 
*/
static int _AddKey(LISTBOX_Handle hObj, int Key) {
  LISTBOX_Obj* pObj;
  pObj = LISTBOX_H2P(hObj);
  switch (Key) {
  case ' ':
    _ToggleMultiSel(hObj, pObj, pObj->Sel);
    return 1;               /* Key has been consumed */
  case GUI_KEY_RIGHT:
    if (WM_SetScrollValue(&pObj->ScrollStateH, pObj->ScrollStateH.v + pObj->Props.ScrollStepH)) {
      LISTBOX_UpdateScrollers(hObj);
      LISTBOX__InvalidateInsideArea(hObj);
    }
    return 1;               /* Key has been consumed */
  case GUI_KEY_LEFT:
    if (WM_SetScrollValue(&pObj->ScrollStateH, pObj->ScrollStateH.v - pObj->Props.ScrollStepH)) {
      LISTBOX_UpdateScrollers(hObj);
      LISTBOX__InvalidateInsideArea(hObj);
    }
    return 1;               /* Key has been consumed */
  case GUI_KEY_DOWN:
    LISTBOX_IncSel(hObj);
    return 1;               /* Key has been consumed */
  case GUI_KEY_UP:
    LISTBOX_DecSel(hObj);
    return 1;               /* Key has been consumed */
  default:
    if(_IsAlphaNum(Key)) {
      _SelectByKey(hObj, Key);
      return 1;               /* Key has been consumed */
    }
  }
  return 0;
}
/*********************************************************************
*
*       LISTBOX_SetScrollStepH
*/
void LISTBOX_SetScrollStepH(LISTBOX_Handle hObj, int Value) {
  if (hObj) {
    LISTBOX_Obj * pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    pObj->Props.ScrollStepH = Value;
    WM_UNLOCK();
  }
}
Esempio n. 5
0
/*********************************************************************
*
*       _NotifyOwner
*
* Purpose:
*   Notify owner of the window.
*   If no owner is registered, the parent is considered owner.
*/
static void _NotifyOwner(WM_HWIN hObj, int Notification) {
  WM_MESSAGE Msg = {0};
  WM_HWIN hOwner;
  LISTBOX_Obj* pObj    = LISTBOX_H2P(hObj);
  hOwner = pObj->hOwner ? pObj->hOwner : WM_GetParent(hObj);
  Msg.MsgId  = WM_NOTIFY_PARENT;
  Msg.Data.v = Notification;
  Msg.hWinSrc= hObj;
  WM_SendMessage(hOwner, &Msg);
}
Esempio n. 6
0
/*********************************************************************
*
*       LISTBOX_SetOwner
*/
void LISTBOX_SetOwner(LISTBOX_Handle hObj, WM_HWIN hOwner) {
  if (hObj) {
    LISTBOX_Obj* pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    pObj->hOwner = hOwner;
    LISTBOX__InvalidateInsideArea(hObj);
    WM_UNLOCK();
  }
}
/*********************************************************************
*
*       LISTBOX_SetOwnerDraw
*/
void LISTBOX_SetOwnerDraw(LISTBOX_Handle hObj, WIDGET_DRAW_ITEM_FUNC * pfDrawItem) {
  LISTBOX_Obj* pObj;
  if (hObj) {
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    pObj->pfDrawItem = pfDrawItem;
    LISTBOX_InvalidateItem(hObj, LISTBOX_ALL_ITEMS);
    WM_UNLOCK();
  }
}
LISTBOX_Handle LISTBOX_CreateAsChild(
  const GUI_ConstString* ppText,
  WM_HWIN hWinParent,
  int x0, int y0, int xsize, int ysize, int Flags)
{
  LISTBOX_Handle hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, 
                                               hWinParent, Flags, _LISTBOX_Callback,
                                               sizeof(LISTBOX_Obj)-sizeof(WM_Obj));
  if (hObj) {
    LISTBOX_Obj* pObj   = LISTBOX_H2P(hObj);
    /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, WIDGET_STATE_FOCUSSABLE | WIDGET_STATE_ENABLED);
    /* pObj->ppText = 0; */   /* Zero init not required */
    pObj->pFont  = _pDefaultFont;
    pObj->aBackColor[0] = 0xffffff;            /* Non selected state */
    pObj->aBackColor[1] = LISTBOX_BKCOLOR1_DEFAULT;    /* selected state */
    pObj->aBackColor[2] = GUI_BLUE;            /* selected state with focus */
    pObj->aTextColor[0] = 0x000000;            /* Non selected state */
    pObj->aTextColor[1] = 0xffffff;            /* selected state */
    pObj->aTextColor[2] = 0xffffff;            /* selected state with focus */
    if (hObj && ppText) {
      LISTBOX_Obj* pObj   = LISTBOX_H2P(hObj);
      INIT_ID(pObj);
      /* init member variables */
      /* Check size */
      if (!xsize) {
        const GUI_FONT* pFontOld = GUI_SetFont(pObj->pFont);
        int i;
		    for (i=0; *(ppText+i); i++) {
          int Size = GUI_GetStringDistX(*(ppText+i));
          if (Size>xsize)
			      xsize = Size;
		    }
        GUI_SetFont(pFontOld);
	    }
      /* Set non-zero attributes */
      pObj->ppText = ppText;
    }
    _CalcScrollParas(hObj);
  }
  return hObj;
}
/*********************************************************************
*
*       LISTBOX_GetScrollStepH
*/
int LISTBOX_GetScrollStepH(LISTBOX_Handle hObj) {
  int Value = 0;
  if (hObj) {
    LISTBOX_Obj * pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    Value = pObj->Props.ScrollStepH;
    WM_UNLOCK();
  }
  return Value;
}
Esempio n. 10
0
void LISTBOX_SetTextColor(LISTBOX_Handle hObj, int index, GUI_COLOR color) {
  LISTBOX_Obj* pObj;
  if (hObj) {
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    ASSERT_IS_VALID_PTR(pObj);
    pObj->aTextColor[index] = color;
    LISTBOX_Invalidate(hObj);
    WM_UNLOCK();
  }
}
Esempio n. 11
0
/*********************************************************************
*
*       LISTBOX_GetNumItems
*/
unsigned LISTBOX_GetNumItems(LISTBOX_Handle hObj) {
  int r = 0;
  if (hObj) {
    LISTBOX_Obj* pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    r = LISTBOX__GetNumItems(pObj);
    WM_UNLOCK();
  }
  return r;
}
Esempio n. 12
0
/*********************************************************************
*
*       LISTBOX_GetSel
*/
int  LISTBOX_GetSel (LISTBOX_Handle hObj) {
  int r = -1;
  LISTBOX_Obj* pObj;
  if (hObj) {
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    ASSERT_IS_VALID_PTR(pObj);
    r = pObj->Sel;
    WM_UNLOCK();
  }
  return r;
}
Esempio n. 13
0
/*********************************************************************
*
*       LISTBOX_SetTextAlign
*/
int LISTBOX_GetTextAlign(LISTBOX_Handle hObj) {
  int Align = 0;
  if (hObj) {
    LISTBOX_Obj* pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    Align = pObj->Props.Align;
    WM_Invalidate(hObj);
    WM_UNLOCK();
  }
  return Align;
}
Esempio n. 14
0
void LISTBOX_SetFont(LISTBOX_Handle hObj, const GUI_FONT* pfont) {
  LISTBOX_Obj* pObj;
  if (hObj) {
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    ASSERT_IS_VALID_PTR(pObj);
    pObj->pFont = pfont;
    _CalcScrollParas(hObj);
    LISTBOX_Invalidate(hObj);
    WM_UNLOCK();
  }
}
Esempio n. 15
0
void LISTBOX_SetText(LISTBOX_Handle hObj, const GUI_ConstString* ppText) {
  LISTBOX_Obj* pObj;
  if (hObj) {
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    ASSERT_IS_VALID_PTR(pObj);
    pObj->ppText = ppText;
    _CalcScrollParas(hObj);
    LISTBOX_Invalidate(hObj);
    WM_UNLOCK();
  }
}
Esempio n. 16
0
static void _SelectByKey(LISTBOX_Handle hObj, int Key) {
  int i;
  LISTBOX_Obj* pObj = LISTBOX_H2P(hObj);
  Key = _Tolower(Key);
  for (i = 0; i < _GetNumItems(pObj); i++) {
    char c = _Tolower(*(*(pObj->ppText + i)));
    if (c == Key) {
      LISTBOX_SetSel(hObj, i);
      break;
    }
  }
}
Esempio n. 17
0
/*********************************************************************
*
*       _CalcScrollParas
*/
static int _CalcScrollParas(LISTBOX_Handle hObj) {
  GUI_RECT Rect;
  LISTBOX_Obj* pObj = LISTBOX_H2P(hObj);
  /* Calc vertical scroll parameters */
  pObj->ScrollStateV.NumItems = LISTBOX__GetNumItems(pObj);
  pObj->ScrollStateV.PageSize = _GetNumVisItems(pObj, hObj);
  /* Calc horizontal scroll parameters */
  WM_GetInsideRectExScrollbar(hObj, &Rect);
  pObj->ScrollStateH.NumItems = _GetContentsSizeX(hObj);
  pObj->ScrollStateH.PageSize = Rect.x1 - Rect.x0 + 1;
  return _UpdateScrollPos(hObj, pObj);
}
Esempio n. 18
0
/*********************************************************************
*
*       LISTBOX_SetBkColor
*/
void LISTBOX_SetBkColor(LISTBOX_Handle hObj, unsigned Index, GUI_COLOR color) {
  LISTBOX_Obj* pObj;
  if (hObj) {
    if ((unsigned int)Index < GUI_COUNTOF(pObj->Props.aBackColor)) {
      WM_LOCK();
      pObj = LISTBOX_H2P(hObj);
      pObj->Props.aBackColor[Index] = color;
      LISTBOX__InvalidateInsideArea(hObj);
      WM_UNLOCK();
    }
  }
}
Esempio n. 19
0
/*********************************************************************
*
*       _SelectByKey
*/
static void _SelectByKey(LISTBOX_Handle hObj, int Key) {
  unsigned i;
  LISTBOX_Obj* pObj;
  pObj = LISTBOX_H2P(hObj);
  Key = _Tolower(Key);
  for (i = 0; i < LISTBOX__GetNumItems(pObj); i++) {
    const char* s = LISTBOX__GetpString(pObj, i);
    if (_Tolower(*s) == Key) {
      LISTBOX_SetSel(hObj, i);
      break;
    }
  }
}
Esempio n. 20
0
/*********************************************************************
*
*       _GetContentsSizeX
*/
static int _GetContentsSizeX(LISTBOX_Handle hObj) {
  LISTBOX_Obj* pObj;
  int i, NumItems, SizeX;
  int Result = 0;
  pObj = LISTBOX_H2P(hObj);
  NumItems = LISTBOX__GetNumItems(pObj);
  for (i = 0; i < NumItems; i++) {
    SizeX = _GetItemSizeX(hObj, pObj, i);
    if (Result < SizeX) {
      Result = SizeX;
    }
  }
  return Result;
}
Esempio n. 21
0
static void _CheckSel(LISTBOX_Handle hObj) {
  int Sel;
  LISTBOX_Obj* pObj = LISTBOX_H2P(hObj);
  Sel = pObj->Sel;
  /* Check if we have to scroll up */
  if (Sel < pObj->ScrollState.v) {
    _SetScroll(hObj, pObj, Sel);
  } else {
  /* Check if we have to scroll down */
    if (Sel > pObj->ScrollState.v + pObj->ScrollState.PageSize -1) {
      _SetScroll(hObj, pObj, Sel - (pObj->ScrollState.PageSize -1));
    }
  }   
}
Esempio n. 22
0
/*********************************************************************
*
*       LISTBOX_GetMulti
*/
int LISTBOX_GetMulti(LISTBOX_Handle hObj) {
  int Multi = 0;
  if (hObj) {
    LISTBOX_Obj* pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    if (!(pObj->Flags & LISTBOX_SF_MULTISEL)) {
      Multi = 0;
    } else {
      Multi = 1;
    }
    WM_UNLOCK();
  }
  return Multi;
}
Esempio n. 23
0
/*********************************************************************
*
*       LISTBOX_AddString
*/
void LISTBOX_AddString(LISTBOX_Handle hObj, const char* s) {
  if (hObj && s) {
    LISTBOX_Obj* pObj;
    LISTBOX_ITEM Item = {0, 0};
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    if (GUI_ARRAY_AddItem(&pObj->ItemArray, &Item, sizeof(LISTBOX_ITEM) + strlen(s)) == 0) {
      unsigned ItemIndex = GUI_ARRAY_GetNumItems(&pObj->ItemArray) - 1;
      LISTBOX_ITEM* pItem= (LISTBOX_ITEM*)GUI_ARRAY_GetpItem(&pObj->ItemArray, ItemIndex);
      strcpy(pItem->acText, s);
      LISTBOX__InvalidateItemSize(pObj, ItemIndex);
      LISTBOX_UpdateScrollers(hObj);
      LISTBOX__InvalidateItem(hObj, pObj, ItemIndex);
    }
    WM_UNLOCK();
  }
}
Esempio n. 24
0
/*********************************************************************
*
*       LISTBOX_SetString
*/
void LISTBOX_SetString(LISTBOX_Handle hObj, const char* s, unsigned int Index) {
  if (hObj) {
    LISTBOX_Obj* pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    if (Index < (unsigned int)LISTBOX__GetNumItems(pObj)) {
      LISTBOX_ITEM* pItem;
      pItem = (LISTBOX_ITEM*)GUI_ARRAY_ResizeItem(&pObj->ItemArray, Index, sizeof(LISTBOX_ITEM) + strlen(s));
      if (pItem) {
        strcpy(pItem->acText, s);
        LISTBOX__InvalidateItemSize(pObj, Index);
        LISTBOX_UpdateScrollers(hObj);
        LISTBOX__InvalidateItem(hObj, pObj, Index);
      }
    }
    WM_UNLOCK();
  }
}
Esempio n. 25
0
LISTBOX_Handle LISTBOX_CreateIndirect(const GUI_WIDGET_CREATE_INFO* pCreateInfo, WM_HWIN hWinParent, int x0, int y0, WM_CALLBACK* cb) {
  LISTBOX_Handle  hThis;
  GUI_USE_PARA(cb);
  hThis = LISTBOX_CreateAsChild(0,
                                hWinParent,
                                pCreateInfo->x0 + x0, 
                                pCreateInfo->y0 + y0, 
                                pCreateInfo->xSize, 
                                pCreateInfo->ySize, 
                                pCreateInfo->Flags);
  if (hThis) {
    LISTBOX_Obj* pObj = LISTBOX_H2P(hThis);
    INIT_ID(pObj);
    pObj->Widget.Id     = pCreateInfo->Id;
    pObj->Widget.State  = LISTBOX_STATE_INACTIVE;
  }
  return hThis;
}
Esempio n. 26
0
/*********************************************************************
*
*       LISTBOX_SetMulti
*/
void LISTBOX_SetMulti(LISTBOX_Handle hObj, int Mode) {
  if (hObj) {
    LISTBOX_Obj* pObj;
    WM_LOCK();
    pObj = LISTBOX_H2P(hObj);
    if (Mode) {
      if (!(pObj->Flags & LISTBOX_SF_MULTISEL)) {
        pObj->Flags |= LISTBOX_SF_MULTISEL;
        LISTBOX__InvalidateInsideArea(hObj);
      }
    } else {
      if (pObj->Flags & LISTBOX_SF_MULTISEL) {
        pObj->Flags &= ~LISTBOX_SF_MULTISEL;
        LISTBOX__InvalidateInsideArea(hObj);
      }
    }
    WM_UNLOCK();
  }
}
Esempio n. 27
0
/*********************************************************************
*
*       _ManageAutoScroll
*/
static void _ManageAutoScroll(LISTBOX_Handle hObj) {
  char IsRequired;
  LISTBOX_Obj* pObj = LISTBOX_H2P(hObj);
  if (pObj->Flags & LISTBOX_SF_AUTOSCROLLBAR_V) {
    IsRequired = (_GetNumVisItems(pObj, hObj) < LISTBOX__GetNumItems(pObj));
    WM_SetScrollbarV(hObj, IsRequired);
  }
  if (pObj->Flags & LISTBOX_SF_AUTOSCROLLBAR_H) {
    GUI_RECT Rect;
    int xSize, xSizeContents;
    xSizeContents = _GetContentsSizeX(hObj);
    WM_GetInsideRectExScrollbar(hObj, &Rect);
    xSize = Rect.x1 - Rect.x0 + 1;
    IsRequired = (xSizeContents > xSize);
    WM_SetScrollbarH(hObj, IsRequired);
  }
  if (pObj->ScrollbarWidth) {
    LISTBOX__SetScrollbarWidth(hObj, pObj);
  }
}
Esempio n. 28
0
/*********************************************************************
*
*       Callback
*/
static void _LISTBOX_Callback (WM_MESSAGE*pMsg) {
  LISTBOX_Handle hObj = pMsg->hWin;
  LISTBOX_Obj* pObj = LISTBOX_H2P(hObj);
  WM_SCROLL_STATE ScrollState;
  /* Let widget handle the standard messages */
  if (WIDGET_HandleActive(hObj, pMsg) == 0) {
    return;
  }
  switch (pMsg->MsgId) {
  case WM_NOTIFY_PARENT:
    if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) {
      WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
    }
    pObj->ScrollState.v = ScrollState.v;
    WM_InvalidateWindow(hObj);
    break;
  case WM_ADD_SCROLLBAR:
    _SetScrollState(hObj);
    break;
  case WM_PAINT:
    _Paint(hObj);
    break;
  case WM_TOUCH:
    if (_OnTouch(hObj, pObj, pMsg) == 0)
      return;
    break;
  case WM_KEY:
    if ( ((WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt >0) {
      int Key = ((WM_KEY_INFO*)(pMsg->Data.p))->Key;
      switch (Key) {
        case GUI_KEY_TAB:
          break;                    /* Send to parent by not doing anything */
        default:
          LISTBOX_AddKey(hObj, Key);
          return;
      }
    }
    break;
  }
  WM_DefaultProc(pMsg);
}
/*********************************************************************
*
*       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;
}
Esempio n. 30
0
/*********************************************************************
*
*       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;
}