/*********************************************************************
*
*       _GetpCellInfo
*/
static LISTVIEW_CELL_INFO* _GetpCellInfo(LISTVIEW_Handle hObj, unsigned Column, unsigned Row, unsigned int Index) {
  LISTVIEW_CELL_INFO* pCellInfo = 0;
  if (hObj) {
    LISTVIEW_Obj* pObj;
    pObj = LISTVIEW_H2P(hObj);
    if (Index < GUI_COUNTOF(pCellInfo->aTextColor)) {
      if ((Column < LISTVIEW__GetNumColumns(pObj)) && (Row < LISTVIEW__GetNumRows(pObj))) {
        LISTVIEW_ROW*  pRow;
        LISTVIEW_CELL* pCell;
        pRow  = (LISTVIEW_ROW*)  GUI_ARRAY_GetpItem(&pObj->RowArray,  Row);
        pCell = (LISTVIEW_CELL*) GUI_ARRAY_GetpItem(&pRow->CellArray, Column);
        if (!pCell->hCellInfo) {
          int i;
          pCell->hCellInfo = GUI_ALLOC_AllocZero(sizeof(LISTVIEW_CELL_INFO));
          pCellInfo = (LISTVIEW_CELL_INFO*) GUI_ALLOC_h2p(pCell->hCellInfo);
          for (i = 0; i < GUI_COUNTOF(pCellInfo->aTextColor); i++) {
            pCellInfo->aTextColor[i] = LISTVIEW_GetTextColor(hObj, i);
            pCellInfo->aBkColor[i]   = LISTVIEW_GetBkColor  (hObj, i);
          }
        } else {
          pCellInfo = (LISTVIEW_CELL_INFO*) GUI_ALLOC_h2p(pCell->hCellInfo);
        }
      }
    }
  }
  return pCellInfo;
}
/*********************************************************************
*
*       GUI_ARRAY_InsertBlankItem
*
* Purpose:
*   Inserts a blank element in a GUI_ARRAY.
*
* Parameters:
*   Index   Index of the element to insert before
*           0 means: Insert before first element
*           1 means: Insert before second element
*
* Return value:
*   1 if successful
*   0 if failed
*
* Notes:
*   (1) Index changes
*       The index of all items after the one inserted will change
*       (Increment by 1)
*/
char GUI_ARRAY_InsertBlankItem(GUI_ARRAY* pThis, unsigned int Index) {
  GUI_ARRAY_CHECK(pThis);    /* Sanity checks at higher debug levels only */

  if (Index >= (unsigned)pThis->NumItems) {
    GUI_DEBUG_ERROROUT("GUI_ARRAY_InsertBlankItem: Illegal index");
  } else {
    WM_HMEM hNewBuffer;
    hNewBuffer = GUI_ALLOC_AllocZero(sizeof(WM_HMEM) * (pThis->NumItems + 1));
    if (hNewBuffer == 0) {
      GUI_DEBUG_ERROROUT("GUI_ARRAY_InsertBlankItem: Failed to alloc buffer");
    } else {
      WM_HMEM *pOldBuffer;
      WM_HMEM *pNewBuffer;
      pNewBuffer = (WM_HMEM*) GUI_ALLOC_h2p(hNewBuffer);
      pOldBuffer = (WM_HMEM*) GUI_ALLOC_h2p(pThis->haHandle);
      memcpy(pNewBuffer, pOldBuffer, Index * sizeof(WM_HMEM));
      memcpy(pNewBuffer + (Index + 1), pOldBuffer + Index, (pThis->NumItems - Index) * sizeof(WM_HMEM));
      GUI_ALLOC_Free(pThis->haHandle);
      pThis->haHandle = hNewBuffer;
      pThis->NumItems++;
      return 1;               /* Successfull */
    }
  }
  return 0;                   /* Failed */
}
Beispiel #3
0
/*********************************************************************
*
*       _OnPaint
*/
static void _OnPaint(GRAPH_DATA_Handle hDataObj, GUI_RECT * pRect) {
  GUI_POINT         * pData;
  GRAPH_DATA_XY_OBJ * pDataXYObj;
  GUI_USE_PARA(pRect);
  pDataXYObj = (GRAPH_DATA_XY_OBJ *)GUI_ALLOC_h2p(hDataObj);
  pData = (GUI_POINT *)GUI_ALLOC_h2p(pDataXYObj->hData);
  if (pData) {
    GUI_RECT Rect;
    GRAPH_OBJ * pObj;
    int xPos, yPos;
    int BorderL, BorderT, BorderR, BorderB;
    pObj = GRAPH_H2P(pDataXYObj->GraphDataObj.PaintObj.hGraph);
    BorderL = pObj->Props.BorderL;
    BorderT = pObj->Props.BorderT;
    BorderR = pObj->Props.BorderR;
    BorderB = pObj->Props.BorderB;
    WM_GetInsideRectExScrollbar(pDataXYObj->GraphDataObj.PaintObj.hGraph, &Rect);
    Rect.x0 += BorderL;
    Rect.y0 += BorderT;
    Rect.x1 -= BorderR;
    Rect.y1 -= BorderB;
    xPos     = Rect.x0 + pDataXYObj->GraphDataObj.OffX;
    yPos     = Rect.y1 - pDataXYObj->GraphDataObj.OffY;
    pObj = GRAPH_H2P(pDataXYObj->GraphDataObj.PaintObj.hGraph);
    GUI_SetColor(pDataXYObj->GraphDataObj.Color);
    GUI_SetPenSize(pDataXYObj->PenSize);
    GUI_SetLineStyle(pDataXYObj->LineStyle);
    _DrawPolyLine(pData, pDataXYObj->GraphDataObj.NumItems, xPos + pObj->ScrollStateH.v, yPos + pObj->ScrollStateV.v);
  }
}
Beispiel #4
0
/*********************************************************************
*
*       WM_CreateTimer
*
*  Returns:    0 if failed, else != 0
*  Parameters:
*                hWin        Window handle of the window to receive the WM_TIMER message
*                UserId      User defined Id. If not needed, use 0.
*                Period      Number of time units (ticks)
*                Mode        0: one-shot
*
*/
int WM_CreateTimer               (WM_HWIN hWin, int UserId, int Period, int Mode) {
  int r = 0;
  int TimerId;
  GUI_HMEM hTimerLink;
  TIMER_LINK* pLink;
  WM_LOCK();
  TimerId = GUI_X_CREATE_TIMER(Period, _OnTimer);
  if (TimerId) {
    hTimerLink = GUI_ALLOC_AllocZero(sizeof(TIMER_LINK));
    if (hTimerLink) {
      pLink = (TIMER_LINK*) GUI_ALLOC_h2p(hTimerLink);
      /* Put new timer at beginning of the linked list */
      pLink->hNext = _hFirst;
      if (_hFirst) {
        TIMER_LINK* pNext;
        pNext = (TIMER_LINK*) GUI_ALLOC_h2p(_hFirst);
      }
      _hFirst = hTimerLink;
      /* Fill in link data */
      pLink->hWin    = hWin;
      pLink->TimerId = TimerId;
      pLink->UserId  = UserId;
      r = 1;            /* All right, we have successfully created a new timer */
    }
  }
  /* Cleanup in case of problem */
  if (r == 0) {
    if (TimerId) {
      GUI_X_DELETE_TIMER(TimerId);
    }
  }
  WM_UNLOCK();
  return r;
}
Beispiel #5
0
/*********************************************************************
*
*       TEXT_CreateEx
*/
TEXT_Handle TEXT_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
                          int WinFlags, int ExFlags, int Id, const char* pText)
{
  TEXT_Handle hObj;
  /* Create the window */
  #if TEXT_SUPPORT_TRANSPARENCY
    WinFlags |= WM_CF_HASTRANS;
  #endif
  WM_LOCK();
  hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WinFlags, TEXT_Callback,
                                sizeof(TEXT_Obj) - sizeof(WM_Obj));
  if (hObj) {
    TEXT_Obj* pObj;
    WM_HMEM hMem = 0;
    pObj = (TEXT_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
    /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, Id, 0);
    /* init member variables */
    TEXT_INIT_ID(pObj);
    if (pText) {
      hMem = GUI_ALLOC_AllocZero(strlen(pText) + 1);
      if (hMem) {
        strcpy((char*) GUI_ALLOC_h2p(hMem), pText);
      }
    }
    pObj->hpText = hMem;
    pObj->Align  = ExFlags;
    pObj->Props  = TEXT__DefaultProps;
  } else {
    GUI_DEBUG_ERROROUT_IF(hObj==0, "TEXT_Create failed")
  }
  WM_UNLOCK();
  return hObj;
}
Beispiel #6
0
/*********************************************************************
*
*       GRAPH_DATA_XY_Create
*/
GRAPH_DATA_Handle GRAPH_DATA_XY_Create(GUI_COLOR Color, unsigned MaxNumItems, GUI_POINT * pItems, unsigned NumItems) {
  GRAPH_DATA_Handle  hDataObj;
  WM_LOCK();
  hDataObj = GUI_ALLOC_AllocZero(sizeof(GRAPH_DATA_XY_OBJ));
  if (hDataObj) {
    GRAPH_DATA_XY_OBJ * pDataXYObj;
    WM_HMEM             hData;
    int                 BufferSize;
    BufferSize = sizeof(GUI_POINT) * MaxNumItems;
    hData = GUI_ALLOC_AllocZero(BufferSize);
    if (hData && pItems && NumItems) {
      void * p;
      p = GUI_ALLOC_h2p(hData);
      memcpy(p, pItems, sizeof(GUI_POINT) * NumItems);
    }
    pDataXYObj = (GRAPH_DATA_XY_OBJ *)GUI_ALLOC_h2p(hDataObj);
    pDataXYObj->hData = hData;
    pDataXYObj->PenSize = 1;
    pDataXYObj->GraphDataObj.Color               = Color;
    pDataXYObj->GraphDataObj.MaxNumItems         = MaxNumItems;
    pDataXYObj->GraphDataObj.NumItems            = NumItems;
    pDataXYObj->GraphDataObj.PaintObj.pfOnPaint  = _OnPaint;
    pDataXYObj->GraphDataObj.PaintObj.pfOnDelete = _OnDelete;
  }
  WM_UNLOCK();
  return hDataObj;
}
/*********************************************************************
*
*       _Sort
*
* Purpose:
*   Sorts the contents of the LISTVIEW by using the qsort algorithm.
*   The compare function is called for each compare operation with valid
*   pointers to cell data of the specified column.
*/
static int _Sort(LISTVIEW_Handle hObj) {
    WM_HMEM hSortArray;
    SORT_OBJECT SortObject;
    int NumItems, NumItemsReq, i, Sel;
    SortObject.pObj = LISTVIEW_H2P(hObj);
    if (((SortObject.pObj->IsPresorted) && (SortObject.pObj->IsSorted)) || (SortObject.pObj->hSort == 0)) {
        return 0;
    }
    SortObject.pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(SortObject.pObj->hSort);
    NumItemsReq = SortObject.pObj->RowArray.NumItems;
    NumItems    = SortObject.pSort->SortArrayNumItems;
    Sel = _GetSelUnsorted(SortObject.pObj);
    /* Adjust number of items in sort array */
    if (NumItems != NumItemsReq) {
        if (!SortObject.pSort->hSortArray) {
            hSortArray = GUI_ALLOC_AllocZero(sizeof(SORT_TYPE) * NumItemsReq);
        } else {
            hSortArray = GUI_ALLOC_Realloc(SortObject.pSort->hSortArray, sizeof(SORT_TYPE) * NumItemsReq);
        }
        if (!hSortArray) {
            return 1;
        }
        SortObject.pObj = LISTVIEW_H2P(hObj);
        SortObject.pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(SortObject.pObj->hSort);
        SortObject.pSort->hSortArray = hSortArray;
    }
    SortObject.paSortArray = (SORT_TYPE *)GUI_ALLOC_h2p(SortObject.pSort->hSortArray);
    if (SortObject.pObj->IsPresorted) {
        /* Add new indices */
        if (NumItems < NumItemsReq) {
            SortObject.pObj->ReverseSort = 0; /* Reverse sort only allowed if listview is presorted and no rows are added */
            for (i = NumItems; i < NumItemsReq; i++) {
                *(SortObject.paSortArray + i) = i;
            }
        }
    } else {
        SortObject.pObj->ReverseSort = 0; /* Reverse sort only allowed if listview is presorted */
        /* Fill with indices if not presorted */
        for (i = 0; i < NumItemsReq; i++) {
            *(SortObject.paSortArray + i) = i;
        }
    }
    SortObject.pSort->SortArrayNumItems = NumItemsReq;
    /* Sort only if more than one item is available */
    if (NumItemsReq > 1) {
        if (SortObject.pObj->ReverseSort) {
            _Reverse(&SortObject);
        } else {
            _BubbleSort(0, NumItemsReq - 1, &SortObject);
        }
        _SetSelUnsorted(hObj, SortObject.pObj, Sel);
    }
    SortObject.pObj->IsPresorted = 1;
    SortObject.pObj->IsSorted    = 1;
    HEADER_SetDirIndicator(SortObject.pObj->hHeader, SortObject.pObj->SortIndex, SortObject.pSort->Reverse);
    return 0;
}
Beispiel #8
0
/*********************************************************************
*
*       GRAPH_DATA_XY_AddPoint
*/
void GRAPH_DATA_XY_AddPoint(GRAPH_DATA_Handle hDataObj, GUI_POINT * pPoint) {
  GRAPH_DATA_XY_OBJ * pDataXYObj;
  WM_LOCK();
  pDataXYObj = (GRAPH_DATA_XY_OBJ *)GUI_ALLOC_h2p(hDataObj);
  if (pDataXYObj) {
    GUI_POINT * pData;
    pData = (GUI_POINT *)GUI_ALLOC_h2p(pDataXYObj->hData);
    GRAPH__AddValue(&pDataXYObj->GraphDataObj, pData, pPoint, sizeof(GUI_POINT));
  }
  WM_UNLOCK();
}
Beispiel #9
0
/*********************************************************************
*
*       _GetpRow
*/
static LISTVIEW_ROW * _GetpRow(LISTVIEW_Obj * pObj, int Index) {
  if (pObj->hSort && (pObj->SortIndex >= 0)) {
    LISTVIEW_SORT * pSort;
    SORT_TYPE * pData;
    pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(pObj->hSort);
    pData = (SORT_TYPE *)GUI_ALLOC_h2p(pSort->hSortArray);
    if (Index >= pSort->SortArrayNumItems) {
      return NULL;
    }
    return (LISTVIEW_ROW *)GUI_ARRAY_GetpItem(&pObj->RowArray, *(pData + Index));
  } else {
    return (LISTVIEW_ROW *)GUI_ARRAY_GetpItem(&pObj->RowArray, Index);
  }
}
/*********************************************************************
*
*       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();
  }
}
Beispiel #11
0
/*********************************************************************
*
*       CHECKBOX_Callback
*/
void CHECKBOX_Callback (WM_MESSAGE *pMsg) {
  CHECKBOX_Handle hObj;
  CHECKBOX_Obj* pObj;
  hObj = pMsg->hWin;
  pObj = (CHECKBOX_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
  /* Let widget handle the standard messages */
  if (WIDGET_HandleActive(hObj, pMsg) == 0) {
    return;
  }
  switch (pMsg->MsgId) {
  case WM_KEY:
    _OnKey(hObj, pObj, pMsg);
    break;
  case WM_PAINT:
    GUI_DEBUG_LOG("CHECKBOX: _Callback(WM_PAINT)\n");
    _Paint(pObj, hObj);
    return;
  case WM_TOUCH:
    _OnTouch(hObj, pObj, pMsg);
    break;
  case WM_DELETE:
    GUI_DEBUG_LOG("CHECKBOX: _Callback(WM_DELETE)\n");
    _Delete(pObj);
    break;       /* No return here ... WM_DefaultProc needs to be called */
  }
  WM_DefaultProc(pMsg);
}
Beispiel #12
0
/*********************************************************************
*
*       _Draw
*/
static void _Draw(void) {
  int x, y, xSize, ySize;
  LCD_PIXELINDEX* pData;
  const GUI_BITMAP GUI_UNI_PTR * pBM;
  GUI_LOCK();
  if (_hBuffer) {
    /* Save bitmap data */
    pBM = _pCursor->pBitmap;
    pData = (LCD_PIXELINDEX*)GUI_ALLOC_h2p(_hBuffer);
    xSize = _Rect.x1 - _Rect.x0 + 1;
    ySize = _Rect.y1 - _Rect.y0 + 1;
    for (y = 0; y < ySize; y++) {
      for (x = 0; x < xSize; x++) {
        int BitmapPixel;
        *(pData + x) = _GetPixelIndex(_Rect.x0 + x, _Rect.y0 + y);
        BitmapPixel = GUI_GetBitmapPixelIndex(pBM, x, y);
        if (BitmapPixel) {
          _SetPixelIndex(_Rect.x0 + x, _Rect.y0 + y, _Log2Phys(BitmapPixel));
        }
      }
      pData += pBM->XSize;
    }
  }
  GUI_UNLOCK();
}
/*********************************************************************
*
*       DROPDOWN_InsertString
*/
void DROPDOWN_InsertString(DROPDOWN_Handle hObj, const char * s, unsigned int Index) {
  if (hObj && s) {
    DROPDOWN_Obj* pObj;
    unsigned int NumItems;
    WM_LOCK();
    pObj = DROPDOWN_H2P(hObj);
    NumItems = DROPDOWN_GetNumItems(hObj);
    if (Index < NumItems) {
      WM_HMEM hItem;
      hItem = GUI_ARRAY_InsertItem(&pObj->Handles, Index, strlen(s) + 1);
      if (hItem) {
        char * pBuffer = (char *)GUI_ALLOC_h2p(hItem);
        strcpy(pBuffer, s);
      }
      WM_InvalidateWindow(hObj);
      if (pObj->hListWin) {
        LISTBOX_InsertString(pObj->hListWin, s, Index);
      }
    } else {
      DROPDOWN_AddString(hObj, s);
      if (pObj->hListWin) {
        LISTBOX_AddString(pObj->hListWin, s);
      }
    }
    WM_UNLOCK();
  }
}
/*******************************************************************
*
*       _DemoSineWave
*/
static void _DemoSineWave(void) {
  PARAM Param;
  I16 * pStart;
  int t0, Cnt = 0;
  GUI_RECT Rect = {19, (LCD_YSIZE - 20) - YSIZE, (LCD_XSIZE - 2), (LCD_YSIZE - 21)};
  GUI_HMEM hMem = GUI_ALLOC_AllocZero(405 * sizeof(I16));
  GUI_SetColor(GUI_WHITE);
  GUI_SetBkColor(GUI_RED);
  GUI_ClearRect(0, 55, LCD_XSIZE, 75);
  GUI_SetFont(&GUI_FontComic18B_1);
  GUI_DispStringAt("Sine wave", 20, 55);
  pStart = GUI_ALLOC_h2p(hMem);
  _GetSineData(pStart, 405);
  GUI_SetFont(&GUI_Font6x8);
  t0 = GUI_GetTime();
  while((GUI_GetTime() - t0) < 10000) {
    int t1, tDiff2;
    if (Cnt++ % 90) {
      Param.aY++;
    } else {
      Param.aY = pStart;
    }
    t1 = GUI_GetTime();
    GUI_MEMDEV_Draw(&Rect, _Draw2, &Param, 0, 0);
    tDiff2 = GUI_GetTime() - t1;
    if (tDiff2 < 100) {
      GUI_Delay(100 - tDiff2);
    }
  }
  GUI_ALLOC_Free(hMem);
}
/*******************************************************************
*
*       _DemoRandomGraph
*/
static void _DemoRandomGraph(void) {
  PARAM Param;
  int tDiff, t0;
  GUI_RECT Rect = {19, (LCD_YSIZE - 20) - YSIZE, (LCD_XSIZE - 2), (LCD_YSIZE - 21)};
  GUI_HMEM hMem = GUI_ALLOC_AllocZero((LCD_XSIZE - 20) * sizeof(I16));
  GUI_SetColor(GUI_WHITE);
  GUI_SetBkColor(GUI_RED);
  GUI_ClearRect(0, 55, LCD_XSIZE, 75);
  GUI_SetFont(&GUI_FontComic18B_1);
  GUI_DispStringAt("Random graph", 20, 55);
  GUI_Lock();
  Param.aY = GUI_ALLOC_h2p(hMem);
  GUI_SetFont(&GUI_Font6x8);
  t0 = GUI_GetTime();
  while((tDiff = (GUI_GetTime() - t0)) < 10000) {
    int t1, tDiff2;
    _GetRandomData(Param.aY, tDiff, (LCD_XSIZE - 20));
    t1 = GUI_GetTime();
    GUI_MEMDEV_Draw(&Rect, _Draw, &Param, 0, 0);
    tDiff2 = GUI_GetTime() - t1;
    if (tDiff2 < 100) {
      GUI_Delay(100 - tDiff2);
    }
  }
  GUI_Unlock();
  GUI_ALLOC_Free(hMem);
}
Beispiel #16
0
/*********************************************************************
*
*       PROGBAR_CreateEx
*/
PROGBAR_Handle PROGBAR_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
                                int WinFlags, int ExFlags, int Id)
{
  PROGBAR_Handle hObj;
  GUI_USE_PARA(ExFlags);
  hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WinFlags, _PROGBAR_Callback,
                                sizeof(PROGBAR_Obj) - sizeof(WM_Obj));
  if (hObj) {
    PROGBAR_Obj* pObj;
    WM_LOCK();
    pObj = (PROGBAR_Obj*) GUI_ALLOC_h2p(hObj);
    /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, Id, 0);
    WIDGET_SetEffect(hObj, &WIDGET_Effect_None); /* Standard effect for progbar: None */
    INIT_ID(pObj);
    /* init member variables */
    pObj->pFont        = GUI_DEFAULT_FONT;
    pObj->BarColor[0]  = PROGBAR_DEFAULT_BARCOLOR0;
    pObj->BarColor[1]  = PROGBAR_DEFAULT_BARCOLOR1;
    pObj->TextColor[0] = PROGBAR_DEFAULT_TEXTCOLOR0;
    pObj->TextColor[1] = PROGBAR_DEFAULT_TEXTCOLOR1;
    pObj->TextAlign    = GUI_TA_CENTER;
    pObj->Max          = 100;
    pObj->Min          = 0;
    WM_UNLOCK();
  }
  return hObj;
}
Beispiel #17
0
/*********************************************************************
*
*       _UpdateBuffer
*/
static void _UpdateBuffer(EDIT_Handle hObj) {
  char * s;
  EDIT_Obj * pObj;
  pObj = EDIT_H2P(hObj); /* The GUI needs not to be locked here. This function is called only from EDIT_AddKey which has already locked the GUI */
  s = (char*) GUI_ALLOC_h2p(pObj->hpText);
  GUI_AddHex(pObj->CurrentValue, pObj->MaxLen, &s);
}
Beispiel #18
0
/*********************************************************************
*
*       SLIDER_CreateEx
*/
SLIDER_Handle SLIDER_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
                              int WinFlags, int ExFlags, int Id)
{
  SLIDER_Handle hObj;
  /* Create the window */
  WM_LOCK();
  #if SLIDER_SUPPORT_TRANSPARENCY
    WinFlags |= WM_CF_HASTRANS;
  #endif
  hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WinFlags, SLIDER_Callback, sizeof(SLIDER_Obj) - sizeof(WM_Obj));
  if (hObj) {
    SLIDER_Obj * pObj;
    U16 InitState;
    pObj = (SLIDER_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
    /* Handle SpecialFlags */
    InitState = WIDGET_STATE_FOCUSSABLE;
    if (ExFlags & SLIDER_CF_VERTICAL) {
      InitState |= WIDGET_CF_VERTICAL;
    }
    /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, Id, InitState);
    /* init member variables */
    SLIDER_INIT_ID(pObj);
    pObj->Props = SLIDER__DefaultProps;
    pObj->Width       = 8;
    pObj->Max         = 100;
    pObj->Min         = 0;
    pObj->NumTicks    = -1;
  } else {
    GUI_DEBUG_ERROROUT_IF(hObj==0, "SLIDER_Create failed")
  }
  WM_UNLOCK();
  return hObj;
}
Beispiel #19
0
static void _DemoRandomGraph(void) {
  PARAM Param;
  int tDiff, t0, Cnt = 0;
  GUI_RECT Rect = {19, (LCD_YSIZE - 20) - YSIZE, (LCD_XSIZE - 2), (LCD_YSIZE - 21)};
  GUI_HMEM hMem = GUI_ALLOC_AllocZero((LCD_XSIZE - 20) * sizeof(I16));
  _ShowText("Random graph");
  Param.aY = (I16*)GUI_ALLOC_h2p(hMem);
  /*
  GUI_SetFont(&GUI_Font6x8);
  GUI_DispStringAt("msec/graph:", 10, 50);
  */
  _LabelMS();
  t0 = GUI_GetTime();
  while(((tDiff = (GUI_GetTime() - t0)) < 10000) && !GUIDEMO_CheckCancel()) {
    int t1, tDiff2;
    _GetRandomData(Param.aY, tDiff, (LCD_XSIZE - 20));
    t1 = GUI_GetTime();
    GUI_MEMDEV_Draw(&Rect, _Draw, &Param, 0, GUI_MEMDEV_NOTRANS);
    tDiff2 = GUI_GetTime() - t1;
    if (tDiff2 < 100) {
      GUI_Delay(100 - tDiff2);
    }
    if(!((++Cnt)%10)) {
      _DisplayTime(tDiff2);
      /*
      GUI_GotoXY(80, 50);
      GUI_SetColor(GUI_WHITE);
      GUI_SetBkColor(GUI_RED);
      GUI_DispDecSpace(tDiff2, 3);
      */
    }
  }
  GUI_ALLOC_Free(hMem);
}
Beispiel #20
0
/*********************************************************************
*
*       GUI_DRAW__Draw
*/
void GUI_DRAW__Draw(GUI_DRAW_HANDLE hDrawObj, int x, int y) {
  if (hDrawObj) {
    GUI_DRAW * pDrawObj;
    pDrawObj = (GUI_DRAW *)GUI_ALLOC_h2p(hDrawObj);
    pDrawObj->pConsts->pfDraw(pDrawObj, x, y);
  }
}
Beispiel #21
0
/*********************************************************************
*
*       EDIT_CreateEx
*/
EDIT_Handle EDIT_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent, int WinFlags, int ExFlags,
                          int Id, int MaxLen)
{
  EDIT_Handle hObj;
  GUI_USE_PARA(ExFlags);
  WM_LOCK();
  /* Alloc memory for obj */
  WinFlags |= WM_CF_LATE_CLIP;    /* Always use late clipping since widget is optimized for it. */
  hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WM_CF_SHOW | WinFlags, EDIT_Callback,
                                sizeof(EDIT_Obj) - sizeof(WM_Obj));
  if (hObj) {
    EDIT_Obj* pObj;
    pObj = (EDIT_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */
    /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE);
    /* init member variables */
    EDIT_INIT_ID(pObj);
    pObj->Props         = EDIT__DefaultProps;
    pObj->XSizeCursor   = 1;
    pObj->MaxLen        = (MaxLen == 0) ? 8 : MaxLen;
    pObj->BufferSize    = 0;
    pObj->hpText        = 0;
    if (_IncrementBuffer(pObj, pObj->MaxLen + 1) == 0) {
      GUI_DEBUG_ERROROUT("EDIT_Create failed to alloc buffer");
      EDIT_Delete(hObj);
      hObj = 0;
    }
  }
  WM_UNLOCK();
  return hObj;
}
Beispiel #22
0
/*********************************************************************
*
*       _FreeAttached
*
* Purpose:
*   Delete attached objects (if any).
*/
static void _FreeAttached(LISTVIEW_Obj * pObj) {
  int i, j, NumRows, NumColumns;
  NumRows    = LISTVIEW__GetNumRows(pObj);
  NumColumns = LISTVIEW__GetNumColumns(pObj);
  for (i = 0; i < NumRows; i++) {
    LISTVIEW_ROW* pRow;
    pRow = (LISTVIEW_ROW*) GUI_ARRAY_GetpItem(&pObj->RowArray, i);
    /* Delete attached info items */
    for (j = 0; j < NumColumns; j++) {
      LISTVIEW_CELL* pCell;
      pCell = (LISTVIEW_CELL*) GUI_ARRAY_GetpItem(&pRow->CellArray, j);
      if (pCell) {
        if (pCell->hCellInfo) {
          GUI_ALLOC_Free(pCell->hCellInfo);
        }
      }
    }
    /* Delete row */
    GUI_ARRAY_Delete(&pRow->CellArray);
  }
  /* Delete sort object */
  if (pObj->hSort) {
    ((LISTVIEW_SORT *)GUI_ALLOC_h2p(pObj->hSort))->fpFree(pObj->hSort);
  }
  GUI_ARRAY_Delete(&pObj->ColumnArray);
  GUI_ARRAY_Delete(&pObj->RowArray);
}
Beispiel #23
0
/*********************************************************************
*
*       EDIT_SetMaxLen
*/
void EDIT_SetMaxLen(EDIT_Handle  hObj, int MaxLen) {
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (MaxLen != pObj->MaxLen) {
      if (MaxLen < pObj->MaxLen) {
        if (pObj->hpText) {
          char* pText;
          int   NumChars;
          pText    = (char*) GUI_ALLOC_h2p(pObj->hpText);
          NumChars = GUI__GetNumChars(pText);
          if (NumChars > MaxLen) {
            int NumBytes;
            NumBytes = GUI_UC__NumChars2NumBytes(pText, MaxLen);
            *(pText + NumBytes) = 0;
          }
        }
      }
      _IncrementBuffer(pObj, MaxLen - pObj->BufferSize + 1);
      pObj->MaxLen = MaxLen;
      EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
  }
}
Beispiel #24
0
/*********************************************************************
*
*       _OnDelete
*/
static void _OnDelete(GRAPH_DATA_Handle hDataObj) {
  GRAPH_DATA_XY_OBJ * pDataXYObj;
  pDataXYObj = (GRAPH_DATA_XY_OBJ *)GUI_ALLOC_h2p(hDataObj);
  if (pDataXYObj->hData) {
    GUI_ALLOC_Free(pDataXYObj->hData);
  }
}
Beispiel #25
0
/*********************************************************************
*
*        GUI_MEMDEV_WriteAt
*/
void GUI_MEMDEV_WriteAt(GUI_MEMDEV_Handle hMem, int x, int y) {
  if (hMem) {
    GUI_MEMDEV* pDevData;
    #if (GUI_WINSUPPORT)
      GUI_RECT r;
    #endif
    GUI_LOCK();
    pDevData = (GUI_MEMDEV*) GUI_ALLOC_h2p(hMem);  /* Convert to pointer */
    if (x == GUI_POS_AUTO) {
      x = pDevData->x0;
      y = pDevData->y0;
    }
    #if (GUI_WINSUPPORT)
      /* Calculate rectangle */
      r.x1 = (r.x0 = x) + pDevData->XSize-1;
      r.y1 = (r.y0 = y) + pDevData->YSize-1;;
      /* Do the drawing. WIndow manager has to be on */
      WM_ITERATE_START(&r) {
        GUI_MEMDEV__WriteToActiveAt(hMem,x,y);
      } WM_ITERATE_END();
    #else
      GUI_MEMDEV__WriteToActiveAt(hMem,x,y);
    #endif
    GUI_UNLOCK();
  }
}
Beispiel #26
0
int GUI__strcmp_hp(GUI_HMEM  hs0, const char GUI_UNI_PTR * s1) {
  const char* s0 = NULL;
  if (hs0) {
    s0 = (const char*)GUI_ALLOC_h2p(hs0);
  }
  return GUI__strcmp(s0, s1);
}
Beispiel #27
0
/*********************************************************************
*
*       _Paint
*/
static void _Paint(TEXT_Handle hObj, TEXT_Obj* pObj) {
  const char * s;
  GUI_RECT Rect;
  GUI_USE_PARA(hObj);
  LCD_SetColor(pObj->Props.TextColor);
  GUI_SetFont    (pObj->Props.pFont);
  /* Fill with parents background color */
  #if !TEXT_SUPPORT_TRANSPARENCY   /* Not needed any more, since window is transparent*/
    if (pObj->Props.BkColor == GUI_INVALID_COLOR) {
      LCD_SetBkColor(WIDGET__GetBkColor(hObj));
    } else {
      LCD_SetBkColor(pObj->Props.BkColor);
    }
    GUI_Clear();
  #else
    if (!WM_GetHasTrans(hObj)) {
      LCD_SetBkColor(pObj->Props.BkColor);
      GUI_Clear();
    }
  #endif
  /* Show the text */
  if (pObj->hpText) {
    s = (const char*) GUI_ALLOC_h2p(pObj->hpText);
    GUI_SetTextMode(GUI_TM_TRANS);
    WM_GetClientRect(&Rect);
    GUI_DispStringInRectWrap(s, &Rect, pObj->Align, pObj->Props.WrapMode);
  }
}
/*********************************************************************
*
*       _GetSelUnsorted
*/
static int _GetSelUnsorted(LISTVIEW_Obj * pObj) {
    int r;
    if ((LISTVIEW__GetSel(pObj) >= 0) && (pObj->hSort)) {
        LISTVIEW_SORT * pSort;
        pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(pObj->hSort);
        if (!pSort->SortArrayNumItems) {
            r = LISTVIEW__GetSel(pObj);
        } else {
            SORT_TYPE * paSortArray;
            paSortArray = (SORT_TYPE *)GUI_ALLOC_h2p(pSort->hSortArray);
            r = *(paSortArray + LISTVIEW__GetSel(pObj));
        }
    } else {
        r = LISTVIEW__GetSel(pObj);
    }
    return r;
}
Beispiel #29
0
/*********************************************************************
*
*       _GetpItem

  Returns:
    Pointer to the specified item
*/
static const char* _GetpItem(DROPDOWN_Obj* pObj, int Index) {
  const char* s = NULL;
  WM_HMEM h = _GethItem(pObj, Index);
  if (h) {
    s = (const char*) GUI_ALLOC_h2p(h);
  }
  return s;
}
Beispiel #30
0
/*********************************************************************
*
*       GUI_ALLOC_Realloc
*
* Purpose:
*   Reallocate a memory block. This is typically used to grow memory
*   blocks. The contents of the old memory block are copied into the
*   new block (or as much as fits in case of shrinkage).
*   In case of error the old memory block (and its handle) remain
*   unchanged.
*
* Return value:
*   On success:    Handle of newly allocated memory block
*   On error:      0
*/
GUI_HMEM GUI_ALLOC_Realloc(GUI_HMEM hOld, int NewSize) {
  GUI_HMEM hNew;
  hNew = GUI_ALLOC_AllocNoInit(NewSize);
  if (hNew && hOld) {
    void *pNew, *pOld;
    int Size, OldSize;
    OldSize = GUI_ALLOC_GetSize(hOld);
    Size = (OldSize < NewSize) ? OldSize : NewSize;
    GUI_LOCK();
    pNew = GUI_ALLOC_h2p(hNew);
    pOld = GUI_ALLOC_h2p(hOld);
    memcpy(pNew, pOld, Size);
    GUI_UNLOCK();
    GUI_ALLOC_Free(hOld);
  }
  return hNew;
}