Better encapsulation of generic list

svn path=/trunk/; revision=33450
This commit is contained in:
Hervé Poussineau 2008-05-11 21:17:57 +00:00
parent 0e6c1e1d3a
commit 2199183bbe
4 changed files with 116 additions and 52 deletions

View file

@ -33,6 +33,28 @@
/* FUNCTIONS ****************************************************************/
typedef struct _GENERIC_LIST_ENTRY
{
LIST_ENTRY Entry;
PGENERIC_LIST List;
PVOID UserData;
CHAR Text[1];
} GENERIC_LIST_ENTRY;
typedef struct _GENERIC_LIST
{
LIST_ENTRY ListHead;
SHORT Left;
SHORT Top;
SHORT Right;
SHORT Bottom;
PGENERIC_LIST_ENTRY CurrentEntry;
PGENERIC_LIST_ENTRY BackupEntry;
} GENERIC_LIST;
PGENERIC_LIST
CreateGenericList(VOID)
{
@ -98,6 +120,7 @@ AppendGenericListEntry(PGENERIC_LIST List,
return FALSE;
strcpy (Entry->Text, Text);
Entry->List = List;
Entry->UserData = UserData;
InsertTailList(&List->ListHead,
@ -313,6 +336,59 @@ ScrollUpGenericList (PGENERIC_LIST List)
}
}
VOID
SetCurrentListEntry(PGENERIC_LIST List, PGENERIC_LIST_ENTRY Entry)
{
if (Entry->List != List)
return;
List->CurrentEntry = Entry;
}
PGENERIC_LIST_ENTRY
GetCurrentListEntry(PGENERIC_LIST List)
{
return List->CurrentEntry;
}
PGENERIC_LIST_ENTRY
GetFirstListEntry(PGENERIC_LIST List)
{
PLIST_ENTRY Entry = List->ListHead.Flink;
if (Entry == &List->ListHead)
return NULL;
return CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry);
}
PGENERIC_LIST_ENTRY
GetNextListEntry(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
GetListEntryUserData(PGENERIC_LIST_ENTRY List)
{
return List->UserData;
}
LPCSTR
GetListEntryText(PGENERIC_LIST_ENTRY List)
{
return List->Text;
}
VOID
GenericListKeyPress (PGENERIC_LIST GenericList, CHAR AsciChar)
{
@ -355,12 +431,6 @@ Reset:
DrawListEntries(GenericList);
}
PGENERIC_LIST_ENTRY
GetGenericListEntry(PGENERIC_LIST List)
{
return List->CurrentEntry;
}
VOID
SaveGenericListState(PGENERIC_LIST List)

View file

@ -27,28 +27,10 @@
#ifndef __GENLIST_H__
#define __GENLIST_H__
typedef struct _GENERIC_LIST_ENTRY
{
LIST_ENTRY Entry;
PVOID UserData;
CHAR Text[1];
} GENERIC_LIST_ENTRY, *PGENERIC_LIST_ENTRY;
typedef struct _GENERIC_LIST
{
LIST_ENTRY ListHead;
SHORT Left;
SHORT Top;
SHORT Right;
SHORT Bottom;
PGENERIC_LIST_ENTRY CurrentEntry;
PGENERIC_LIST_ENTRY BackupEntry;
} GENERIC_LIST, *PGENERIC_LIST;
struct _GENERIC_LIST_ENTRY;
typedef struct _GENERIC_LIST_ENTRY *PGENERIC_LIST_ENTRY;
struct _GENERIC_LIST;
typedef struct _GENERIC_LIST *PGENERIC_LIST;
PGENERIC_LIST
CreateGenericList(VOID);
@ -76,8 +58,23 @@ ScrollDownGenericList(PGENERIC_LIST List);
VOID
ScrollUpGenericList(PGENERIC_LIST List);
VOID
SetCurrentListEntry(PGENERIC_LIST List, PGENERIC_LIST_ENTRY Entry);
PGENERIC_LIST_ENTRY
GetGenericListEntry(PGENERIC_LIST List);
GetCurrentListEntry(PGENERIC_LIST List);
PGENERIC_LIST_ENTRY
GetFirstListEntry(PGENERIC_LIST List);
PGENERIC_LIST_ENTRY
GetNextListEntry(PGENERIC_LIST_ENTRY Entry);
PVOID
GetListEntryUserData(PGENERIC_LIST_ENTRY List);
LPCSTR
GetListEntryText(PGENERIC_LIST_ENTRY List);
VOID
SaveGenericListState(PGENERIC_LIST List);

View file

@ -563,7 +563,6 @@ CheckUnattendedSetup(VOID)
VOID
UpdateKBLayout(VOID)
{
PLIST_ENTRY Entry;
PGENERIC_LIST_ENTRY ListEntry;
LPCWSTR pszNewLayout;
@ -574,22 +573,20 @@ UpdateKBLayout(VOID)
LayoutList = CreateKeyboardLayoutList(SetupInf, DefaultKBLayout);
}
Entry = LayoutList->ListHead.Flink;
ListEntry = GetFirstListEntry(LayoutList);
/* Search for default layout (if provided) */
if (pszNewLayout != NULL)
{
while (Entry != &LayoutList->ListHead)
while (ListEntry != NULL)
{
ListEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry);
if (!wcscmp(pszNewLayout, ListEntry->UserData))
if (!wcscmp(pszNewLayout, GetListEntryUserData(ListEntry)))
{
LayoutList->CurrentEntry = ListEntry;
SetCurrentListEntry(LayoutList, ListEntry);
break;
}
Entry = Entry->Flink;
ListEntry = GetNextListEntry(ListEntry);
}
}
}
@ -647,7 +644,7 @@ LanguagePage(PINPUT_RECORD Ir)
}
else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */
{
SelectedLanguageId = (PWCHAR)LanguageList->CurrentEntry->UserData;
SelectedLanguageId = (PWCHAR)GetListEntryUserData(GetCurrentListEntry(LanguageList));
if (wcscmp(SelectedLanguageId, DefaultLanguage))
{
@ -1019,10 +1016,10 @@ DeviceSettingsPage(PINPUT_RECORD Ir)
MUIDisplayPage(DEVICE_SETTINGS_PAGE);
CONSOLE_SetTextXY(25, 11, GetGenericListEntry(ComputerList)->Text);
CONSOLE_SetTextXY(25, 12, GetGenericListEntry(DisplayList)->Text);
CONSOLE_SetTextXY(25, 13, GetGenericListEntry(KeyboardList)->Text);
CONSOLE_SetTextXY(25, 14, GetGenericListEntry(LayoutList)->Text);
CONSOLE_SetTextXY(25, 11, GetListEntryText(GetCurrentListEntry((ComputerList))));
CONSOLE_SetTextXY(25, 12, GetListEntryText(GetCurrentListEntry((DisplayList))));
CONSOLE_SetTextXY(25, 13, GetListEntryText(GetCurrentListEntry((KeyboardList))));
CONSOLE_SetTextXY(25, 14, GetListEntryText(GetCurrentListEntry((LayoutList))));
CONSOLE_InvertTextXY(24, Line, 48, 1);

View file

@ -485,15 +485,15 @@ ProcessComputerFiles(HINF InfFile, PGENERIC_LIST List, PWCHAR* AdditionalSection
DPRINT("ProcessComputerFiles() called\n");
Entry = GetGenericListEntry(List);
Entry = GetCurrentListEntry(List);
if (Entry == NULL)
{
DPRINT("GetGenericListEntry() failed\n");
DPRINT("GetCurrentListEntry() failed\n");
return FALSE;
}
wcscpy(SectionName, L"Files.");
wcscat(SectionName, (const wchar_t*) Entry->UserData);
wcscat(SectionName, (const wchar_t*)GetListEntryUserData(Entry));
*AdditionalSectionName = SectionName;
return TRUE;
@ -514,14 +514,14 @@ ProcessDisplayRegistry(HINF InfFile, PGENERIC_LIST List)
DPRINT("ProcessDisplayRegistry() called\n");
Entry = GetGenericListEntry(List);
Entry = GetCurrentListEntry(List);
if (Entry == NULL)
{
DPRINT("GetGenericListEntry() failed\n");
DPRINT("GetCurrentListEntry() failed\n");
return FALSE;
}
if (!SetupFindFirstLineW(InfFile, L"Display", (WCHAR*) Entry->UserData, &Context))
if (!SetupFindFirstLineW(InfFile, L"Display", (WCHAR*)GetListEntryUserData(Entry), &Context))
{
DPRINT("SetupFindFirstLineW() failed\n");
return FALSE;
@ -629,11 +629,11 @@ ProcessLocaleRegistry(PGENERIC_LIST List)
HANDLE KeyHandle;
NTSTATUS Status;
Entry = GetGenericListEntry(List);
Entry = GetCurrentListEntry(List);
if (Entry == NULL)
return FALSE;
LanguageId = (PWCHAR)Entry->UserData;
LanguageId = (PWCHAR)GetListEntryUserData(Entry);
if (LanguageId == NULL)
return FALSE;
@ -877,11 +877,11 @@ ProcessKeyboardLayoutRegistry(PGENERIC_LIST List)
NTSTATUS Status;
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
Entry = GetGenericListEntry(List);
Entry = GetCurrentListEntry(List);
if (Entry == NULL)
return FALSE;
LanguageId = (PWCHAR)Entry->UserData;
LanguageId = (PWCHAR)GetListEntryUserData(Entry);
if (LanguageId == NULL)
return FALSE;