3 * Copyright (C) 2004 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: subsys/system/usetup/genlist.c
23 * PURPOSE: Generic list functions
24 * PROGRAMMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
34 /* FUNCTIONS ****************************************************************/
37 CreateGenericList(VOID
)
41 List
= (PGENERIC_LIST
)RtlAllocateHeap(ProcessHeap
,
43 sizeof(GENERIC_LIST
));
47 InitializeListHead(&List
->ListHead
);
54 List
->CurrentEntry
= NULL
;
61 DestroyGenericList(PGENERIC_LIST List
,
64 PGENERIC_LIST_ENTRY ListEntry
;
67 /* Release list entries */
68 while (!IsListEmpty (&List
->ListHead
))
70 Entry
= RemoveHeadList (&List
->ListHead
);
71 ListEntry
= CONTAINING_RECORD (Entry
, GENERIC_LIST_ENTRY
, Entry
);
73 /* Release user data */
74 if (FreeUserData
&& ListEntry
->UserData
!= NULL
)
75 RtlFreeHeap (ProcessHeap
, 0, &ListEntry
->UserData
);
77 /* Release list entry */
78 RtlFreeHeap (ProcessHeap
, 0, ListEntry
);
81 /* Release list head */
82 RtlFreeHeap (ProcessHeap
, 0, List
);
87 AppendGenericListEntry(PGENERIC_LIST List
,
92 PGENERIC_LIST_ENTRY Entry
;
94 Entry
= (PGENERIC_LIST_ENTRY
)RtlAllocateHeap(ProcessHeap
,
96 sizeof(GENERIC_LIST_ENTRY
) + strlen(Text
));
100 strcpy (Entry
->Text
, Text
);
101 Entry
->UserData
= UserData
;
103 InsertTailList(&List
->ListHead
,
106 if (Current
|| List
->CurrentEntry
== NULL
)
108 List
->CurrentEntry
= Entry
;
116 DrawListFrame(PGENERIC_LIST GenericList
)
122 /* Draw upper left corner */
123 coPos
.X
= GenericList
->Left
;
124 coPos
.Y
= GenericList
->Top
;
125 FillConsoleOutputCharacter (0xDA, // '+',
130 /* Draw upper edge */
131 coPos
.X
= GenericList
->Left
+ 1;
132 coPos
.Y
= GenericList
->Top
;
133 FillConsoleOutputCharacter (0xC4, // '-',
134 GenericList
->Right
- GenericList
->Left
- 1,
138 /* Draw upper right corner */
139 coPos
.X
= GenericList
->Right
;
140 coPos
.Y
= GenericList
->Top
;
141 FillConsoleOutputCharacter (0xBF, // '+',
146 /* Draw left and right edge */
147 for (i
= GenericList
->Top
+ 1; i
< GenericList
->Bottom
; i
++)
149 coPos
.X
= GenericList
->Left
;
151 FillConsoleOutputCharacter (0xB3, // '|',
156 coPos
.X
= GenericList
->Right
;
157 FillConsoleOutputCharacter (0xB3, //'|',
163 /* Draw lower left corner */
164 coPos
.X
= GenericList
->Left
;
165 coPos
.Y
= GenericList
->Bottom
;
166 FillConsoleOutputCharacter (0xC0, // '+',
171 /* Draw lower edge */
172 coPos
.X
= GenericList
->Left
+ 1;
173 coPos
.Y
= GenericList
->Bottom
;
174 FillConsoleOutputCharacter (0xC4, // '-',
175 GenericList
->Right
- GenericList
->Left
- 1,
179 /* Draw lower right corner */
180 coPos
.X
= GenericList
->Right
;
181 coPos
.Y
= GenericList
->Bottom
;
182 FillConsoleOutputCharacter (0xD9, // '+',
190 DrawListEntries(PGENERIC_LIST GenericList
)
192 PGENERIC_LIST_ENTRY ListEntry
;
198 coPos
.X
= GenericList
->Left
+ 1;
199 coPos
.Y
= GenericList
->Top
+ 1;
200 Width
= GenericList
->Right
- GenericList
->Left
- 1;
202 Entry
= GenericList
->ListHead
.Flink
;
203 while (Entry
!= &GenericList
->ListHead
)
205 ListEntry
= CONTAINING_RECORD (Entry
, GENERIC_LIST_ENTRY
, Entry
);
207 if (coPos
.Y
== GenericList
->Bottom
)
210 FillConsoleOutputAttribute ((GenericList
->CurrentEntry
== ListEntry
) ? 0x71 : 0x17,
215 FillConsoleOutputCharacter (' ',
221 WriteConsoleOutputCharacters (ListEntry
->Text
,
222 min (strlen(ListEntry
->Text
), (SIZE_T
)Width
- 2),
227 Entry
= Entry
->Flink
;
230 while (coPos
.Y
< GenericList
->Bottom
)
232 FillConsoleOutputAttribute (0x17,
237 FillConsoleOutputCharacter (' ',
247 DrawGenericList(PGENERIC_LIST List
,
256 List
->Bottom
= Bottom
;
260 if (IsListEmpty(&List
->ListHead
))
263 DrawListEntries(List
);
268 ScrollDownGenericList (PGENERIC_LIST List
)
272 if (List
->CurrentEntry
== NULL
)
275 if (List
->CurrentEntry
->Entry
.Flink
!= &List
->ListHead
)
277 Entry
= List
->CurrentEntry
->Entry
.Flink
;
278 List
->CurrentEntry
= CONTAINING_RECORD (Entry
, GENERIC_LIST_ENTRY
, Entry
);
279 DrawListEntries(List
);
285 ScrollUpGenericList (PGENERIC_LIST List
)
289 if (List
->CurrentEntry
== NULL
)
292 if (List
->CurrentEntry
->Entry
.Blink
!= &List
->ListHead
)
294 Entry
= List
->CurrentEntry
->Entry
.Blink
;
295 List
->CurrentEntry
= CONTAINING_RECORD (Entry
, GENERIC_LIST_ENTRY
, Entry
);
296 DrawListEntries(List
);
302 GetGenericListEntry(PGENERIC_LIST List
)
304 return List
->CurrentEntry
;
309 SaveGenericListState(PGENERIC_LIST List
)
311 List
->BackupEntry
= List
->CurrentEntry
;
316 RestoreGenericListState(PGENERIC_LIST List
)
318 List
->CurrentEntry
= List
->BackupEntry
;