From 2199183bbe997c4c7335cc0695f6addc502b1e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Sun, 11 May 2008 21:17:57 +0000 Subject: [PATCH] Better encapsulation of generic list svn path=/trunk/; revision=33450 --- reactos/base/setup/usetup/genlist.c | 82 ++++++++++++++++++-- reactos/base/setup/usetup/genlist.h | 43 +++++----- reactos/base/setup/usetup/interface/usetup.c | 23 +++--- reactos/base/setup/usetup/settings.c | 20 ++--- 4 files changed, 116 insertions(+), 52 deletions(-) diff --git a/reactos/base/setup/usetup/genlist.c b/reactos/base/setup/usetup/genlist.c index 6c9810631f7..cb9362b06cc 100644 --- a/reactos/base/setup/usetup/genlist.c +++ b/reactos/base/setup/usetup/genlist.c @@ -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) diff --git a/reactos/base/setup/usetup/genlist.h b/reactos/base/setup/usetup/genlist.h index d5abd62284a..72e460b952e 100644 --- a/reactos/base/setup/usetup/genlist.h +++ b/reactos/base/setup/usetup/genlist.h @@ -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); diff --git a/reactos/base/setup/usetup/interface/usetup.c b/reactos/base/setup/usetup/interface/usetup.c index 271de7912ff..18d9a94e040 100644 --- a/reactos/base/setup/usetup/interface/usetup.c +++ b/reactos/base/setup/usetup/interface/usetup.c @@ -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); diff --git a/reactos/base/setup/usetup/settings.c b/reactos/base/setup/usetup/settings.c index 47fb17b512d..32bc7c4ca3f 100644 --- a/reactos/base/setup/usetup/settings.c +++ b/reactos/base/setup/usetup/settings.c @@ -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;