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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 /* COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS text-mode setup
21 * FILE: base/setup/usetup/genlist.c
22 * PURPOSE: Generic list functions
23 * PROGRAMMER: Eric Kohl
24 * Christoph von Wittich <christoph at reactos.org>
27 /* INCLUDES *****************************************************************/
34 /* FUNCTIONS ****************************************************************/
38 IN OUT PGENERIC_LIST_UI ListUi
,
39 IN PGENERIC_LIST List
)
42 ListUi
->FirstShown
= NULL
;
43 ListUi
->LastShown
= NULL
;
49 ListUi
->Redraw
= TRUE
;
55 IN PGENERIC_LIST_UI ListUi
)
61 /* Draw upper left corner */
62 coPos
.X
= ListUi
->Left
;
63 coPos
.Y
= ListUi
->Top
;
64 FillConsoleOutputCharacterA (StdOutput
,
71 coPos
.X
= ListUi
->Left
+ 1;
72 coPos
.Y
= ListUi
->Top
;
73 FillConsoleOutputCharacterA (StdOutput
,
75 ListUi
->Right
- ListUi
->Left
- 1,
79 /* Draw upper right corner */
80 coPos
.X
= ListUi
->Right
;
81 coPos
.Y
= ListUi
->Top
;
82 FillConsoleOutputCharacterA (StdOutput
,
88 /* Draw left and right edge */
89 for (i
= ListUi
->Top
+ 1; i
< ListUi
->Bottom
; i
++)
91 coPos
.X
= ListUi
->Left
;
93 FillConsoleOutputCharacterA (StdOutput
,
99 coPos
.X
= ListUi
->Right
;
100 FillConsoleOutputCharacterA (StdOutput
,
107 /* Draw lower left corner */
108 coPos
.X
= ListUi
->Left
;
109 coPos
.Y
= ListUi
->Bottom
;
110 FillConsoleOutputCharacterA (StdOutput
,
116 /* Draw lower edge */
117 coPos
.X
= ListUi
->Left
+ 1;
118 coPos
.Y
= ListUi
->Bottom
;
119 FillConsoleOutputCharacterA (StdOutput
,
121 ListUi
->Right
- ListUi
->Left
- 1,
125 /* Draw lower right corner */
126 coPos
.X
= ListUi
->Right
;
127 coPos
.Y
= ListUi
->Bottom
;
128 FillConsoleOutputCharacterA (StdOutput
,
138 IN PGENERIC_LIST_UI ListUi
)
140 PGENERIC_LIST List
= ListUi
->List
;
141 PGENERIC_LIST_ENTRY ListEntry
;
147 coPos
.X
= ListUi
->Left
+ 1;
148 coPos
.Y
= ListUi
->Top
+ 1;
149 Width
= ListUi
->Right
- ListUi
->Left
- 1;
151 Entry
= ListUi
->FirstShown
;
152 while (Entry
!= &List
->ListHead
)
154 ListEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
156 if (coPos
.Y
== ListUi
->Bottom
)
158 ListUi
->LastShown
= Entry
;
160 FillConsoleOutputAttribute (StdOutput
,
161 (List
->CurrentEntry
== ListEntry
) ?
162 FOREGROUND_BLUE
| BACKGROUND_WHITE
:
163 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
168 FillConsoleOutputCharacterA (StdOutput
,
175 WriteConsoleOutputCharacterA (StdOutput
,
177 min (strlen(ListEntry
->Text
), (SIZE_T
)Width
- 2),
183 Entry
= Entry
->Flink
;
186 while (coPos
.Y
< ListUi
->Bottom
)
188 FillConsoleOutputAttribute (StdOutput
,
189 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
194 FillConsoleOutputCharacterA (StdOutput
,
205 DrawScrollBarGenericList(
206 IN PGENERIC_LIST_UI ListUi
)
208 PGENERIC_LIST List
= ListUi
->List
;
212 coPos
.X
= ListUi
->Right
+ 1;
213 coPos
.Y
= ListUi
->Top
;
215 if (ListUi
->FirstShown
!= List
->ListHead
.Flink
)
217 FillConsoleOutputCharacterA (StdOutput
,
225 FillConsoleOutputCharacterA (StdOutput
,
232 coPos
.Y
= ListUi
->Bottom
;
233 if (ListUi
->LastShown
!= List
->ListHead
.Blink
)
235 FillConsoleOutputCharacterA (StdOutput
,
243 FillConsoleOutputCharacterA (StdOutput
,
253 CenterCurrentListItem(
254 IN PGENERIC_LIST_UI ListUi
)
256 PGENERIC_LIST List
= ListUi
->List
;
258 ULONG MaxVisibleItems
, ItemCount
, i
;
260 if ((ListUi
->Top
== 0 && ListUi
->Bottom
== 0) ||
261 IsListEmpty(&List
->ListHead
) ||
262 List
->CurrentEntry
== NULL
)
267 MaxVisibleItems
= (ULONG
)(ListUi
->Bottom
- ListUi
->Top
- 1);
269 /*****************************************
271 Entry = List->ListHead.Flink;
272 while (Entry != &List->ListHead)
275 Entry = Entry->Flink;
277 *****************************************/
278 ItemCount
= List
->NumOfEntries
; // GetNumberOfListEntries(List);
280 if (ItemCount
> MaxVisibleItems
)
282 Entry
= &List
->CurrentEntry
->Entry
;
283 for (i
= 0; i
< MaxVisibleItems
/ 2; i
++)
285 if (Entry
->Blink
!= &List
->ListHead
)
286 Entry
= Entry
->Blink
;
289 ListUi
->FirstShown
= Entry
;
291 for (i
= 0; i
< MaxVisibleItems
; i
++)
293 if (Entry
->Flink
!= &List
->ListHead
)
294 Entry
= Entry
->Flink
;
297 ListUi
->LastShown
= Entry
;
303 IN PGENERIC_LIST_UI ListUi
,
309 PGENERIC_LIST List
= ListUi
->List
;
311 ListUi
->FirstShown
= List
->ListHead
.Flink
;
314 ListUi
->Right
= Right
;
315 ListUi
->Bottom
= Bottom
;
317 DrawListFrame(ListUi
);
319 if (IsListEmpty(&List
->ListHead
))
322 CenterCurrentListItem(ListUi
);
324 DrawListEntries(ListUi
);
325 DrawScrollBarGenericList(ListUi
);
329 ScrollDownGenericList(
330 IN PGENERIC_LIST_UI ListUi
)
332 PGENERIC_LIST List
= ListUi
->List
;
335 if (List
->CurrentEntry
== NULL
)
338 if (List
->CurrentEntry
->Entry
.Flink
!= &List
->ListHead
)
340 Entry
= List
->CurrentEntry
->Entry
.Flink
;
341 if (ListUi
->LastShown
== &List
->CurrentEntry
->Entry
)
343 ListUi
->FirstShown
= ListUi
->FirstShown
->Flink
;
344 ListUi
->LastShown
= ListUi
->LastShown
->Flink
;
346 List
->CurrentEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
350 DrawListEntries(ListUi
);
351 DrawScrollBarGenericList(ListUi
);
358 IN PGENERIC_LIST_UI ListUi
)
360 PGENERIC_LIST List
= ListUi
->List
;
363 if (List
->CurrentEntry
== NULL
)
366 if (List
->CurrentEntry
->Entry
.Blink
!= &List
->ListHead
)
368 Entry
= List
->CurrentEntry
->Entry
.Blink
;
369 if (ListUi
->FirstShown
== &List
->CurrentEntry
->Entry
)
371 ListUi
->FirstShown
= ListUi
->FirstShown
->Blink
;
372 ListUi
->LastShown
= ListUi
->LastShown
->Blink
;
374 List
->CurrentEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
378 DrawListEntries(ListUi
);
379 DrawScrollBarGenericList(ListUi
);
385 ScrollPageDownGenericList(
386 IN PGENERIC_LIST_UI ListUi
)
390 /* Suspend auto-redraw */
391 ListUi
->Redraw
= FALSE
;
393 for (i
= ListUi
->Top
+ 1; i
< ListUi
->Bottom
- 1; i
++)
395 ScrollDownGenericList(ListUi
);
398 /* Update user interface */
399 DrawListEntries(ListUi
);
400 DrawScrollBarGenericList(ListUi
);
402 /* Re enable auto-redraw */
403 ListUi
->Redraw
= TRUE
;
407 ScrollPageUpGenericList(
408 IN PGENERIC_LIST_UI ListUi
)
412 /* Suspend auto-redraw */
413 ListUi
->Redraw
= FALSE
;
415 for (i
= ListUi
->Bottom
- 1; i
> ListUi
->Top
+ 1; i
--)
417 ScrollUpGenericList(ListUi
);
420 /* Update user interface */
421 DrawListEntries(ListUi
);
422 DrawScrollBarGenericList(ListUi
);
424 /* Re enable auto-redraw */
425 ListUi
->Redraw
= TRUE
;
429 ScrollToPositionGenericList(
430 IN PGENERIC_LIST_UI ListUi
,
433 PGENERIC_LIST List
= ListUi
->List
;
437 if (List
->CurrentEntry
== NULL
|| uIndex
== 0)
442 if (List
->CurrentEntry
->Entry
.Flink
!= &List
->ListHead
)
444 Entry
= List
->CurrentEntry
->Entry
.Flink
;
445 if (ListUi
->LastShown
== &List
->CurrentEntry
->Entry
)
447 ListUi
->FirstShown
= ListUi
->FirstShown
->Flink
;
448 ListUi
->LastShown
= ListUi
->LastShown
->Flink
;
450 List
->CurrentEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
454 while (uIndex
!= uCount
);
458 DrawListEntries(ListUi
);
459 DrawScrollBarGenericList(ListUi
);
465 IN PGENERIC_LIST_UI ListUi
)
467 if (ListUi
->List
->CurrentEntry
== NULL
)
472 DrawListEntries(ListUi
);
473 DrawScrollBarGenericList(ListUi
);
479 IN PGENERIC_LIST_UI ListUi
,
482 PGENERIC_LIST List
= ListUi
->List
;
483 PGENERIC_LIST_ENTRY ListEntry
;
484 PGENERIC_LIST_ENTRY OldListEntry
;
485 BOOLEAN Flag
= FALSE
;
487 ListEntry
= List
->CurrentEntry
;
488 OldListEntry
= List
->CurrentEntry
;
490 ListUi
->Redraw
= FALSE
;
492 if ((strlen(ListEntry
->Text
) > 0) && (tolower(ListEntry
->Text
[0]) == AsciiChar
) &&
493 (List
->CurrentEntry
->Entry
.Flink
!= &List
->ListHead
))
495 ScrollDownGenericList(ListUi
);
496 ListEntry
= List
->CurrentEntry
;
498 if ((strlen(ListEntry
->Text
) > 0) && (tolower(ListEntry
->Text
[0]) == AsciiChar
))
502 while (List
->CurrentEntry
->Entry
.Blink
!= &List
->ListHead
)
503 ScrollUpGenericList(ListUi
);
505 ListEntry
= List
->CurrentEntry
;
509 if ((strlen(ListEntry
->Text
) > 0) && (tolower(ListEntry
->Text
[0]) == AsciiChar
))
515 if (List
->CurrentEntry
->Entry
.Flink
== &List
->ListHead
)
518 ScrollDownGenericList(ListUi
);
519 ListEntry
= List
->CurrentEntry
;
524 while (List
->CurrentEntry
->Entry
.Blink
!= &List
->ListHead
)
526 if (List
->CurrentEntry
!= OldListEntry
)
527 ScrollUpGenericList(ListUi
);
534 DrawListEntries(ListUi
);
535 DrawScrollBarGenericList(ListUi
);
537 ListUi
->Redraw
= TRUE
;