mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 04:37:15 +00:00

- Apart from allowing a UI cache variable that may be used when displaying GENERIC_LIST_ENTRY-ies, do not store any display strings associated to these list entries. They should be instead computed only when initializing a list UI (or a combo-box or list control if the code is used in Win32 environment). For this matter a callback is provided to InitGenericListUi() that does the job of computing the displayed string corresponding to a given GENERIC_LIST_ENTRY. - Simplify the calls to InitGenericListUi(), and refactor the RestoreGenericListUiState() function. - Use for-loops for iterating over GENERIC_LIST items. - Adapt the storage data format for lists of settings items. - The txtsetup.sif INF format specified in LoadSetupInf() should not be INF_STYLE_WIN4 (to be investigated...).
158 lines
3.3 KiB
C
158 lines
3.3 KiB
C
/*
|
|
* PROJECT: ReactOS Setup Library
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
* PURPOSE: Generic list functions
|
|
* COPYRIGHT: Copyright 2008-2018 Christoph von Wittich <christoph at reactos.org>
|
|
*/
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
#include "precomp.h"
|
|
|
|
#include "genlist.h"
|
|
|
|
#define NDEBUG
|
|
#include <debug.h>
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
PGENERIC_LIST
|
|
CreateGenericList(VOID)
|
|
{
|
|
PGENERIC_LIST List;
|
|
|
|
List = RtlAllocateHeap(ProcessHeap, 0, sizeof(GENERIC_LIST));
|
|
if (List == NULL)
|
|
return NULL;
|
|
|
|
InitializeListHead(&List->ListHead);
|
|
List->NumOfEntries = 0;
|
|
List->CurrentEntry = NULL;
|
|
|
|
return List;
|
|
}
|
|
|
|
VOID
|
|
DestroyGenericList(
|
|
IN OUT PGENERIC_LIST List,
|
|
IN BOOLEAN FreeData)
|
|
{
|
|
PGENERIC_LIST_ENTRY ListEntry;
|
|
PLIST_ENTRY Entry;
|
|
|
|
/* Release list entries */
|
|
while (!IsListEmpty(&List->ListHead))
|
|
{
|
|
Entry = RemoveHeadList(&List->ListHead);
|
|
ListEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry);
|
|
|
|
/* Release user data */
|
|
if (FreeData && ListEntry->Data != NULL)
|
|
RtlFreeHeap(ProcessHeap, 0, ListEntry->Data);
|
|
|
|
/* Release list entry */
|
|
RtlFreeHeap(ProcessHeap, 0, ListEntry);
|
|
}
|
|
|
|
/* Release list head */
|
|
RtlFreeHeap(ProcessHeap, 0, List);
|
|
}
|
|
|
|
BOOLEAN
|
|
AppendGenericListEntry(
|
|
IN OUT PGENERIC_LIST List,
|
|
IN PVOID Data,
|
|
IN BOOLEAN Current)
|
|
{
|
|
PGENERIC_LIST_ENTRY Entry;
|
|
|
|
Entry = RtlAllocateHeap(ProcessHeap, 0, sizeof(GENERIC_LIST_ENTRY));
|
|
if (Entry == NULL)
|
|
return FALSE;
|
|
|
|
Entry->List = List;
|
|
Entry->Data = Data;
|
|
Entry->UiData = 0;
|
|
|
|
InsertTailList(&List->ListHead, &Entry->Entry);
|
|
++List->NumOfEntries;
|
|
|
|
if (Current || List->CurrentEntry == NULL)
|
|
List->CurrentEntry = Entry;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
VOID
|
|
SetCurrentListEntry(
|
|
IN PGENERIC_LIST List,
|
|
IN PGENERIC_LIST_ENTRY Entry)
|
|
{
|
|
if (Entry->List != List)
|
|
return;
|
|
List->CurrentEntry = Entry;
|
|
}
|
|
|
|
PGENERIC_LIST_ENTRY
|
|
GetCurrentListEntry(
|
|
IN PGENERIC_LIST List)
|
|
{
|
|
return List->CurrentEntry;
|
|
}
|
|
|
|
PGENERIC_LIST_ENTRY
|
|
GetFirstListEntry(
|
|
IN PGENERIC_LIST List)
|
|
{
|
|
if (IsListEmpty(&List->ListHead))
|
|
return NULL;
|
|
|
|
return CONTAINING_RECORD(List->ListHead.Flink, GENERIC_LIST_ENTRY, Entry);
|
|
}
|
|
|
|
PGENERIC_LIST_ENTRY
|
|
GetNextListEntry(
|
|
IN PGENERIC_LIST_ENTRY Entry)
|
|
{
|
|
PLIST_ENTRY Next = Entry->Entry.Flink;
|
|
|
|
if (Next == &Entry->List->ListHead)
|
|
return NULL;
|
|
|
|
return CONTAINING_RECORD(Next, GENERIC_LIST_ENTRY, Entry);
|
|
}
|
|
|
|
PVOID
|
|
GetListEntryData(
|
|
IN PGENERIC_LIST_ENTRY Entry)
|
|
{
|
|
return Entry->Data;
|
|
}
|
|
|
|
ULONG_PTR
|
|
GetListEntryUiData(
|
|
IN PGENERIC_LIST_ENTRY Entry)
|
|
{
|
|
return Entry->UiData;
|
|
}
|
|
|
|
ULONG
|
|
GetNumberOfListEntries(
|
|
IN PGENERIC_LIST List)
|
|
{
|
|
return List->NumOfEntries;
|
|
}
|
|
|
|
BOOLEAN
|
|
GenericListHasSingleEntry(
|
|
IN PGENERIC_LIST List)
|
|
{
|
|
/*
|
|
* If both list head pointers (which normally point to the first and last
|
|
* list member, respectively) point to the same entry then it means that
|
|
* there is just a single thing in there, otherwise... false!
|
|
*/
|
|
return (!IsListEmpty(&List->ListHead) && (List->ListHead.Flink == List->ListHead.Blink));
|
|
}
|
|
|
|
/* EOF */
|