/*********************************************************************
*
*       _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;
}
Exemple #2
0
/*********************************************************************
*
*       _IncrementBuffer
*
* Increments the buffer size by AddBytes.
*/
static int _IncrementBuffer(EDIT_Obj* pObj, unsigned AddBytes) {
  WM_HMEM hNew;
  int NewSize;
  NewSize = pObj->BufferSize + AddBytes;
  hNew    = GUI_ALLOC_Realloc(pObj->hpText, NewSize);
  if (hNew) {
    if (!(pObj->hpText)) {
      char* pText;
      pText  = (char*) GUI_ALLOC_h2p(hNew);
      *pText = 0;
    }
    pObj->BufferSize = NewSize;
    pObj->hpText     = hNew;
    return 1;
  }
  return 0;
}