⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
📖 第 1 页 / 共 2 页
字号:
    curr = list->first;
    while (count < index && curr)
    {
        curr = curr->next;
        count++;
    }

    if (curr != NULL)
    {
        if (curr->next != NULL)
            curr->next->prev = curr->prev;
        else
            list->last = curr->prev;
        if (curr->prev != NULL)
            curr->prev->next = curr->next;
        else
            list->first = curr->next;
        if (curr->data && (list->attr & LS_OWNSITEMS))
        {
            if (list->f && list->f->FreeItem)
                (*list->f->FreeItem)(curr->data);
            else
                FreeClass(curr->data);
            curr->data = NULL;
        }
        if (curr->data)
            FreeClass(curr->data);    //LINGZJ MODIFY
        FreeClass(curr);
        return ListGetCount(list);
    }
    else
        return -1;
}

/*-------------------------------------------------------------------*/
/*
Name: ListRemoveItem
Desc: Removes the item in the list at the position (starting at 0) supplied in
Index. It specifically does not free the object, regardless of the attributes
of the List.
Returns the item entry, after removing it from the list.
*/
void *ListRemoveItem(UILIST * list, UINT16 index)
{
    UINT16 count = 0;
    UILISTENTRY *curr;
    void *RetVal = NULL;

    curr = list->first;
    while (count < index && curr)
    {
        curr = curr->next;
        count++;
    }

    if (curr != NULL)
    {
        RetVal = curr->data;
        if (curr->next != NULL)
            curr->next->prev = curr->prev;
        else
            list->last = curr->prev;
        if (curr->prev != NULL)
            curr->prev->next = curr->next;
        else
            list->first = curr->next;
    }
    return RetVal;
}

/*-------------------------------------------------------------------*/
/*
Name: ListGetCount
Desc: Returns the number of items in the list.
*/
UINT16 ListGetCount(const UILIST * list)

{
    UILISTENTRY *curr;
    UINT16 count = 0;

    if (NULL == list)
        curr = NULL;
    else
        curr = list->first;
    while (curr)
    {
        curr = curr->next;
        count++;
    }
    return count;
}

/*-------------------------------------------------------------------*/
/*
Name: ListClear
Desc: Deletes al of the items in the list.
*/
void  ListClear(UILIST * list)

{
    while (ListGetCount(list))
        ListDeleteItem(list, 0);
}

/*-------------------------------------------------------------------*/
/*
Name: ListGetSelCount
Desc: Returns the number of selected items in the list box. For single- or
multiple-selection list boxes.
*/
UINT16 ListGetSelCount(const UILIST * list)

{
    UILISTENTRY *curr;
    UINT16 count = 0;

    curr = list->first;
    while (curr)
    {
        if (curr->selected)
            count++;
        curr = curr->next;
    }
    return count;
}

/*-------------------------------------------------------------------*/
/*
Name: ListGetSelIndex
Desc: Returns the positive index (starting at 0) of the currently selected item,
or a negative value if no item is selected. For single selection list boxes.
*/
INT32 ListGetSelIndex(const UILIST * list)

{
    UILISTENTRY *curr;
    UINT16 count = 0;

    if (list->attr & LS_MULTIPLESEL)
        return -1;

    curr = list->first;
    while (curr)
    {
        if (curr->selected)
            return count;
        curr = curr->next;
        count++;
    }
    return -1;
}

/*-------------------------------------------------------------------*/
/*
Name: ListGetSelIndexes
Desc: Fills the indexes array with the indexes of up to maxCount selected strings.
Returns the number of items put in indexes (-1 for single-selection list
boxes).
*/
INT32 ListGetSelIndexes(const UILIST * list, UINT16 * indexes, UINT16 maxCount)

{
    UILISTENTRY *curr;
    UINT16 count = 0;
    UINT16 selcount = 0;

    if (!(list->attr & LS_MULTIPLESEL))
        return -1;

    curr = list->first;
    while (curr)
    {
        if (curr->selected)
        {
            indexes[selcount++] = count;
            if (selcount >= maxCount)
                return selcount; /* Just have to work on those selections we can report */
        }
        curr = curr->next;
        count++;
    }
    return selcount;
}

/*-------------------------------------------------------------------*/
/*
Name: ListSetSelIndex
Desc: Forces the selection of the item at the position (starting at 0) supplied in
Index. If Index is -1, the list box is cleared of any selection.

Returns a negative number if an error occurs. For single-selection list
boxes.
*/
INT32 ListSetSelIndex(const UILIST * list, INT32 index)

{
    UINT16 count = 0;
    UILISTENTRY *curr;
    INT32 currentsel;

    if (list->attr & LS_MULTIPLESEL)
        return -1;

    /* Clear any existing selection */
    currentsel = ListGetSelIndex(list);
    if (currentsel >= 0)
    {
        UILISTENTRY *listEntry = ListGetListEntry(list, (UINT16) currentsel);

        if (listEntry)
            listEntry->selected = FALSE;
    }
    curr = list->first;
    if (index == -1)
    {
        while (curr)
        {
            curr->selected = FALSE;
            curr = curr->next;
        }
        return 0;
    }
    else
    {
        while (count < index && curr)
        {
            curr = curr->next;
            count++;
        }
        if (curr == NULL)
            return -1;
        curr->selected = TRUE;
        return count;
    }
}

/*-------------------------------------------------------------------*/
/*
Name: ListSetSelIndexes
Desc: For multiple-selection list boxes. Selects or deselects the strings in the
associated list box at the indexes specified in the Indexes array. If
ShouldSet is TRUE, the indexed strings are selcted and highlighted, if
ShouldSet is FALSE the highlight is removed and they are no longer selected.

Returns the number of strings successfully selected or deselected (-1 for
single selection list boxes).

If numSel is less than zero, all strings are selected or deselected,
and a negative value is returned on failure.
*/
INT32 ListSetSelIndexes(const UILIST * list, const UINT16 * indexes, INT16 numSel, BOOLEAN shouldSet)

{
    UILISTENTRY *curr;
    INT16 selcount = 0;
    UINT16 i;

    if (!(list->attr & LS_MULTIPLESEL))
        return -1;
    curr = list->first;
    if (numSel == -1)
    {
        while (curr)
        {
            curr->selected = shouldSet;
            curr = curr->next;
        }
        return 0;
    }
    else
    {
        for (i = 0; i < numSel; i++)
        {
            curr = ListGetListEntry(list, indexes[i]);
            if (curr)
            {
                curr->selected = shouldSet;
                selcount++;
            }
        }
        return selcount;
    }
}

/*-------------------------------------------------------------------*/
UINT16
ListGetAttributes(const UILIST * inList)
{
    return (inList != NULL) ? inList->attr : 0;
}

void
ListSetAttributes(UILIST * inList, UINT16 inAttributes)
{
    if (inList != NULL)
        inList->attr = inAttributes;
}

/*-------------------------------------------------------------------*/
/*
Name: ListFindItemPtr
Desc: Find an item in the list, by using the compare function.
It returns the pointer to the item in the list.
It can be used for an search into a list using an incomplete reference
*/
void *ListFindItemPtr(const UILIST * list, void *item)

{
    UILISTENTRY *curr;

    curr = list->first;
    while (curr)
    {
        if (list->f && list->f->CompareItem)
        {
            if ((*(list->f->CompareItem))(item, curr->data) == 0)
                return curr->data;
        }
        else
        {      /* By default just use stricmp */
            if (listStrcmp((char *) item, (char *) curr->data) == 0)
                return curr->data;
        }
        curr = curr->next;
    }
    return NULL;
}


int listStrcmp(const char * cs, const char * ct)
{

    if (cs == ct)
        return 0;

    return -1;;

    /*
     register signed char __res; while (1)
       {

     if ((__res = *cs - *ct++) != 0 || !*cs++)

     break;
       }

       return __res;
       */
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -