Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612/* * ReactOS kernel * Copyright (C) 2004 ReactOS Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *//* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS text-mode setup * FILE: base/setup/usetup/genlist.c * PURPOSE: Generic list functions * PROGRAMMER: Christoph von Wittich <christoph at reactos.org> */
/* INCLUDES *****************************************************************/
#include "usetup.h"
#define NDEBUG#include <debug.h>
/* FUNCTIONS ****************************************************************/
VOIDInitGenericListUi( IN OUT PGENERIC_LIST_UI ListUi, IN PGENERIC_LIST List, IN PGET_ENTRY_DESCRIPTION GetEntryDescriptionProc){ ListUi->List = List; ListUi->FirstShown = NULL; ListUi->LastShown = NULL; ListUi->BackupEntry = NULL;
ListUi->GetEntryDescriptionProc = GetEntryDescriptionProc;
ListUi->Left = 0; ListUi->Top = 0; ListUi->Right = 0; ListUi->Bottom = 0; ListUi->Redraw = TRUE;
ListUi->CurrentItemText[0] = ANSI_NULL;
/* SaveGenericListUiState(ListUi); */ ListUi->BackupEntry = ListUi->List->CurrentEntry;}
VOIDRestoreGenericListUiState( IN PGENERIC_LIST_UI ListUi){ ListUi->List->CurrentEntry = ListUi->BackupEntry;}
staticVOIDDrawListFrame( IN PGENERIC_LIST_UI ListUi){ COORD coPos; DWORD Written; SHORT i;
/* Draw upper left corner */ coPos.X = ListUi->Left; coPos.Y = ListUi->Top; FillConsoleOutputCharacterA(StdOutput, CharUpperLeftCorner, // '+', 1, coPos, &Written);
/* Draw upper edge */ coPos.X = ListUi->Left + 1; coPos.Y = ListUi->Top; FillConsoleOutputCharacterA(StdOutput, CharHorizontalLine, // '-', ListUi->Right - ListUi->Left - 1, coPos, &Written);
/* Draw upper right corner */ coPos.X = ListUi->Right; coPos.Y = ListUi->Top; FillConsoleOutputCharacterA(StdOutput, CharUpperRightCorner, // '+', 1, coPos, &Written);
/* Draw left and right edge */ for (i = ListUi->Top + 1; i < ListUi->Bottom; i++) { coPos.X = ListUi->Left; coPos.Y = i; FillConsoleOutputCharacterA(StdOutput, CharVerticalLine, // '|', 1, coPos, &Written);
coPos.X = ListUi->Right; FillConsoleOutputCharacterA(StdOutput, CharVerticalLine, //'|', 1, coPos, &Written); }
/* Draw lower left corner */ coPos.X = ListUi->Left; coPos.Y = ListUi->Bottom; FillConsoleOutputCharacterA(StdOutput, CharLowerLeftCorner, // '+', 1, coPos, &Written);
/* Draw lower edge */ coPos.X = ListUi->Left + 1; coPos.Y = ListUi->Bottom; FillConsoleOutputCharacterA(StdOutput, CharHorizontalLine, // '-', ListUi->Right - ListUi->Left - 1, coPos, &Written);
/* Draw lower right corner */ coPos.X = ListUi->Right; coPos.Y = ListUi->Bottom; FillConsoleOutputCharacterA(StdOutput, CharLowerRightCorner, // '+', 1, coPos, &Written);}
staticVOIDDrawListEntries( IN PGENERIC_LIST_UI ListUi){ PGENERIC_LIST List = ListUi->List; PGENERIC_LIST_ENTRY ListEntry; PLIST_ENTRY Entry; COORD coPos; DWORD Written; USHORT Width;
coPos.X = ListUi->Left + 1; coPos.Y = ListUi->Top + 1; Width = ListUi->Right - ListUi->Left - 1;
Entry = ListUi->FirstShown; while (Entry != &List->ListHead) { ListEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry);
if (coPos.Y == ListUi->Bottom) break; ListUi->LastShown = Entry;
ListUi->CurrentItemText[0] = ANSI_NULL; if (ListUi->GetEntryDescriptionProc) { ListUi->GetEntryDescriptionProc(ListEntry, ListUi->CurrentItemText, ARRAYSIZE(ListUi->CurrentItemText)); }
FillConsoleOutputAttribute(StdOutput, (List->CurrentEntry == ListEntry) ? FOREGROUND_BLUE | BACKGROUND_WHITE : FOREGROUND_WHITE | BACKGROUND_BLUE, Width, coPos, &Written);
FillConsoleOutputCharacterA(StdOutput, ' ', Width, coPos, &Written);
coPos.X++; WriteConsoleOutputCharacterA(StdOutput, ListUi->CurrentItemText, min(strlen(ListUi->CurrentItemText), (SIZE_T)Width - 2), coPos, &Written); coPos.X--;
coPos.Y++; Entry = Entry->Flink; }
while (coPos.Y < ListUi->Bottom) { FillConsoleOutputAttribute(StdOutput, FOREGROUND_WHITE | BACKGROUND_BLUE, Width, coPos, &Written);
FillConsoleOutputCharacterA(StdOutput, ' ', Width, coPos, &Written); coPos.Y++; }}
staticVOIDDrawScrollBarGenericList( IN PGENERIC_LIST_UI ListUi){ PGENERIC_LIST List = ListUi->List; COORD coPos; DWORD Written;
coPos.X = ListUi->Right + 1; coPos.Y = ListUi->Top;
if (ListUi->FirstShown != List->ListHead.Flink) { FillConsoleOutputCharacterA(StdOutput, CharUpArrow, 1, coPos, &Written); } else { FillConsoleOutputCharacterA(StdOutput, ' ', 1, coPos, &Written); }
coPos.Y = ListUi->Bottom; if (ListUi->LastShown != List->ListHead.Blink) { FillConsoleOutputCharacterA(StdOutput, CharDownArrow, 1, coPos, &Written); } else { FillConsoleOutputCharacterA(StdOutput, ' ', 1, coPos, &Written); }}
staticVOIDCenterCurrentListItem( IN PGENERIC_LIST_UI ListUi){ PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry; ULONG MaxVisibleItems, ItemCount, i;
if ((ListUi->Top == 0 && ListUi->Bottom == 0) || IsListEmpty(&List->ListHead) || List->CurrentEntry == NULL) { return; }
MaxVisibleItems = (ULONG)(ListUi->Bottom - ListUi->Top - 1);
/***************************************** ItemCount = 0; Entry = List->ListHead.Flink; while (Entry != &List->ListHead) { ItemCount++; Entry = Entry->Flink; }*****************************************/ ItemCount = List->NumOfEntries; // GetNumberOfListEntries(List);
if (ItemCount > MaxVisibleItems) { Entry = &List->CurrentEntry->Entry; for (i = 0; i < MaxVisibleItems / 2; i++) { if (Entry->Blink != &List->ListHead) Entry = Entry->Blink; }
ListUi->FirstShown = Entry;
for (i = 0; i < MaxVisibleItems; i++) { if (Entry->Flink != &List->ListHead) Entry = Entry->Flink; }
ListUi->LastShown = Entry; }}
VOIDDrawGenericList( IN PGENERIC_LIST_UI ListUi, IN SHORT Left, IN SHORT Top, IN SHORT Right, IN SHORT Bottom){ PGENERIC_LIST List = ListUi->List;
ListUi->FirstShown = List->ListHead.Flink; ListUi->Left = Left; ListUi->Top = Top; ListUi->Right = Right; ListUi->Bottom = Bottom;
DrawListFrame(ListUi);
if (IsListEmpty(&List->ListHead)) return;
CenterCurrentListItem(ListUi);
DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi);}
VOIDDrawGenericListCurrentItem( IN PGENERIC_LIST List, IN PGET_ENTRY_DESCRIPTION GetEntryDescriptionProc, IN SHORT Left, IN SHORT Top){ CHAR CurrentItemText[256];
if (GetEntryDescriptionProc && GetNumberOfListEntries(List) > 0) { GetEntryDescriptionProc(GetCurrentListEntry(List), CurrentItemText, ARRAYSIZE(CurrentItemText)); CONSOLE_SetTextXY(Left, Top, CurrentItemText); } else { CONSOLE_SetTextXY(Left, Top, ""); }}
VOIDScrollDownGenericList( IN PGENERIC_LIST_UI ListUi){ PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry;
if (List->CurrentEntry == NULL) return;
if (List->CurrentEntry->Entry.Flink != &List->ListHead) { Entry = List->CurrentEntry->Entry.Flink; if (ListUi->LastShown == &List->CurrentEntry->Entry) { ListUi->FirstShown = ListUi->FirstShown->Flink; ListUi->LastShown = ListUi->LastShown->Flink; } List->CurrentEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry);
if (ListUi->Redraw) { DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi); } }}
VOIDScrollUpGenericList( IN PGENERIC_LIST_UI ListUi){ PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry;
if (List->CurrentEntry == NULL) return;
if (List->CurrentEntry->Entry.Blink != &List->ListHead) { Entry = List->CurrentEntry->Entry.Blink; if (ListUi->FirstShown == &List->CurrentEntry->Entry) { ListUi->FirstShown = ListUi->FirstShown->Blink; ListUi->LastShown = ListUi->LastShown->Blink; } List->CurrentEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry);
if (ListUi->Redraw) { DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi); } }}
VOIDScrollPageDownGenericList( IN PGENERIC_LIST_UI ListUi){ SHORT i;
/* Suspend auto-redraw */ ListUi->Redraw = FALSE;
for (i = ListUi->Top + 1; i < ListUi->Bottom - 1; i++) { ScrollDownGenericList(ListUi); }
/* Update user interface */ DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi);
/* Re enable auto-redraw */ ListUi->Redraw = TRUE;}
VOIDScrollPageUpGenericList( IN PGENERIC_LIST_UI ListUi){ SHORT i;
/* Suspend auto-redraw */ ListUi->Redraw = FALSE;
for (i = ListUi->Bottom - 1; i > ListUi->Top + 1; i--) { ScrollUpGenericList(ListUi); }
/* Update user interface */ DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi);
/* Re enable auto-redraw */ ListUi->Redraw = TRUE;}
VOIDScrollToPositionGenericList( IN PGENERIC_LIST_UI ListUi, IN ULONG uIndex){ PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry; ULONG uCount = 0;
if (List->CurrentEntry == NULL || uIndex == 0) return;
do { if (List->CurrentEntry->Entry.Flink != &List->ListHead) { Entry = List->CurrentEntry->Entry.Flink; if (ListUi->LastShown == &List->CurrentEntry->Entry) { ListUi->FirstShown = ListUi->FirstShown->Flink; ListUi->LastShown = ListUi->LastShown->Flink; } List->CurrentEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry); } uCount++; } while (uIndex != uCount);
if (ListUi->Redraw) { DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi); }}
VOIDRedrawGenericList( IN PGENERIC_LIST_UI ListUi){ if (ListUi->List->CurrentEntry == NULL) return;
if (ListUi->Redraw) { DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi); }}
VOIDGenericListKeyPress( IN PGENERIC_LIST_UI ListUi, IN CHAR AsciiChar){ PGENERIC_LIST List = ListUi->List; PGENERIC_LIST_ENTRY ListEntry; PGENERIC_LIST_ENTRY OldListEntry; BOOLEAN Flag = FALSE;
ListEntry = List->CurrentEntry; OldListEntry = List->CurrentEntry;
ListUi->Redraw = FALSE;
ListUi->CurrentItemText[0] = ANSI_NULL; if (ListUi->GetEntryDescriptionProc) { ListUi->GetEntryDescriptionProc(ListEntry, ListUi->CurrentItemText, ARRAYSIZE(ListUi->CurrentItemText)); }
if ((strlen(ListUi->CurrentItemText) > 0) && (tolower(ListUi->CurrentItemText[0]) == AsciiChar) && (List->CurrentEntry->Entry.Flink != &List->ListHead)) { ScrollDownGenericList(ListUi); ListEntry = List->CurrentEntry;
ListUi->CurrentItemText[0] = ANSI_NULL; if (ListUi->GetEntryDescriptionProc) { ListUi->GetEntryDescriptionProc(ListEntry, ListUi->CurrentItemText, ARRAYSIZE(ListUi->CurrentItemText)); }
if ((strlen(ListUi->CurrentItemText) > 0) && (tolower(ListUi->CurrentItemText[0]) == AsciiChar)) goto End; }
while (List->CurrentEntry->Entry.Blink != &List->ListHead) ScrollUpGenericList(ListUi);
ListEntry = List->CurrentEntry;
for (;;) { ListUi->CurrentItemText[0] = ANSI_NULL; if (ListUi->GetEntryDescriptionProc) { ListUi->GetEntryDescriptionProc(ListEntry, ListUi->CurrentItemText, ARRAYSIZE(ListUi->CurrentItemText)); }
if ((strlen(ListUi->CurrentItemText) > 0) && (tolower(ListUi->CurrentItemText[0]) == AsciiChar)) { Flag = TRUE; break; }
if (List->CurrentEntry->Entry.Flink == &List->ListHead) break;
ScrollDownGenericList(ListUi); ListEntry = List->CurrentEntry; }
if (!Flag) { while (List->CurrentEntry->Entry.Blink != &List->ListHead) { if (List->CurrentEntry != OldListEntry) ScrollUpGenericList(ListUi); else break; } }
End: DrawListEntries(ListUi); DrawScrollBarGenericList(ListUi);
ListUi->Redraw = TRUE;}
/* EOF */