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: Christoph von Wittich <christoph at reactos.org>
26 /* INCLUDES *****************************************************************/
33 /* FUNCTIONS ****************************************************************/
37 IN OUT PGENERIC_LIST_UI ListUi
,
38 IN PGENERIC_LIST List
)
41 ListUi
->FirstShown
= NULL
;
42 ListUi
->LastShown
= NULL
;
48 ListUi
->Redraw
= TRUE
;
54 IN PGENERIC_LIST_UI ListUi
)
60 /* Draw upper left corner */
61 coPos
.X
= ListUi
->Left
;
62 coPos
.Y
= ListUi
->Top
;
63 FillConsoleOutputCharacterA (StdOutput
,
70 coPos
.X
= ListUi
->Left
+ 1;
71 coPos
.Y
= ListUi
->Top
;
72 FillConsoleOutputCharacterA (StdOutput
,
74 ListUi
->Right
- ListUi
->Left
- 1,
78 /* Draw upper right corner */
79 coPos
.X
= ListUi
->Right
;
80 coPos
.Y
= ListUi
->Top
;
81 FillConsoleOutputCharacterA (StdOutput
,
87 /* Draw left and right edge */
88 for (i
= ListUi
->Top
+ 1; i
< ListUi
->Bottom
; i
++)
90 coPos
.X
= ListUi
->Left
;
92 FillConsoleOutputCharacterA (StdOutput
,
98 coPos
.X
= ListUi
->Right
;
99 FillConsoleOutputCharacterA (StdOutput
,
106 /* Draw lower left corner */
107 coPos
.X
= ListUi
->Left
;
108 coPos
.Y
= ListUi
->Bottom
;
109 FillConsoleOutputCharacterA (StdOutput
,
115 /* Draw lower edge */
116 coPos
.X
= ListUi
->Left
+ 1;
117 coPos
.Y
= ListUi
->Bottom
;
118 FillConsoleOutputCharacterA (StdOutput
,
120 ListUi
->Right
- ListUi
->Left
- 1,
124 /* Draw lower right corner */
125 coPos
.X
= ListUi
->Right
;
126 coPos
.Y
= ListUi
->Bottom
;
127 FillConsoleOutputCharacterA (StdOutput
,
137 IN PGENERIC_LIST_UI ListUi
)
139 PGENERIC_LIST List
= ListUi
->List
;
140 PGENERIC_LIST_ENTRY ListEntry
;
146 coPos
.X
= ListUi
->Left
+ 1;
147 coPos
.Y
= ListUi
->Top
+ 1;
148 Width
= ListUi
->Right
- ListUi
->Left
- 1;
150 Entry
= ListUi
->FirstShown
;
151 while (Entry
!= &List
->ListHead
)
153 ListEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
155 if (coPos
.Y
== ListUi
->Bottom
)
157 ListUi
->LastShown
= Entry
;
159 FillConsoleOutputAttribute (StdOutput
,
160 (List
->CurrentEntry
== ListEntry
) ?
161 FOREGROUND_BLUE
| BACKGROUND_WHITE
:
162 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
167 FillConsoleOutputCharacterA (StdOutput
,
174 WriteConsoleOutputCharacterA (StdOutput
,
176 min (strlen(ListEntry
->Text
), (SIZE_T
)Width
- 2),
182 Entry
= Entry
->Flink
;
185 while (coPos
.Y
< ListUi
->Bottom
)
187 FillConsoleOutputAttribute (StdOutput
,
188 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
193 FillConsoleOutputCharacterA (StdOutput
,
204 DrawScrollBarGenericList(
205 IN PGENERIC_LIST_UI ListUi
)
207 PGENERIC_LIST List
= ListUi
->List
;
211 coPos
.X
= ListUi
->Right
+ 1;
212 coPos
.Y
= ListUi
->Top
;
214 if (ListUi
->FirstShown
!= List
->ListHead
.Flink
)
216 FillConsoleOutputCharacterA (StdOutput
,
224 FillConsoleOutputCharacterA (StdOutput
,
231 coPos
.Y
= ListUi
->Bottom
;
232 if (ListUi
->LastShown
!= List
->ListHead
.Blink
)
234 FillConsoleOutputCharacterA (StdOutput
,
242 FillConsoleOutputCharacterA (StdOutput
,
252 CenterCurrentListItem(
253 IN PGENERIC_LIST_UI ListUi
)
255 PGENERIC_LIST List
= ListUi
->List
;
257 ULONG MaxVisibleItems
, ItemCount
, i
;
259 if ((ListUi
->Top
== 0 && ListUi
->Bottom
== 0) ||
260 IsListEmpty(&List
->ListHead
) ||
261 List
->CurrentEntry
== NULL
)
266 MaxVisibleItems
= (ULONG
)(ListUi
->Bottom
- ListUi
->Top
- 1);
268 /*****************************************
270 Entry = List->ListHead.Flink;
271 while (Entry != &List->ListHead)
274 Entry = Entry->Flink;
276 *****************************************/
277 ItemCount
= List
->NumOfEntries
; // GetNumberOfListEntries(List);
279 if (ItemCount
> MaxVisibleItems
)
281 Entry
= &List
->CurrentEntry
->Entry
;
282 for (i
= 0; i
< MaxVisibleItems
/ 2; i
++)
284 if (Entry
->Blink
!= &List
->ListHead
)
285 Entry
= Entry
->Blink
;
288 ListUi
->FirstShown
= Entry
;
290 for (i
= 0; i
< MaxVisibleItems
; i
++)
292 if (Entry
->Flink
!= &List
->ListHead
)
293 Entry
= Entry
->Flink
;
296 ListUi
->LastShown
= Entry
;
302 IN PGENERIC_LIST_UI ListUi
,
308 PGENERIC_LIST List
= ListUi
->List
;
310 ListUi
->FirstShown
= List
->ListHead
.Flink
;
313 ListUi
->Right
= Right
;
314 ListUi
->Bottom
= Bottom
;
316 DrawListFrame(ListUi
);
318 if (IsListEmpty(&List
->ListHead
))
321 CenterCurrentListItem(ListUi
);
323 DrawListEntries(ListUi
);
324 DrawScrollBarGenericList(ListUi
);
328 ScrollDownGenericList(
329 IN PGENERIC_LIST_UI ListUi
)
331 PGENERIC_LIST List
= ListUi
->List
;
334 if (List
->CurrentEntry
== NULL
)
337 if (List
->CurrentEntry
->Entry
.Flink
!= &List
->ListHead
)
339 Entry
= List
->CurrentEntry
->Entry
.Flink
;
340 if (ListUi
->LastShown
== &List
->CurrentEntry
->Entry
)
342 ListUi
->FirstShown
= ListUi
->FirstShown
->Flink
;
343 ListUi
->LastShown
= ListUi
->LastShown
->Flink
;
345 List
->CurrentEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
349 DrawListEntries(ListUi
);
350 DrawScrollBarGenericList(ListUi
);
357 IN PGENERIC_LIST_UI ListUi
)
359 PGENERIC_LIST List
= ListUi
->List
;
362 if (List
->CurrentEntry
== NULL
)
365 if (List
->CurrentEntry
->Entry
.Blink
!= &List
->ListHead
)
367 Entry
= List
->CurrentEntry
->Entry
.Blink
;
368 if (ListUi
->FirstShown
== &List
->CurrentEntry
->Entry
)
370 ListUi
->FirstShown
= ListUi
->FirstShown
->Blink
;
371 ListUi
->LastShown
= ListUi
->LastShown
->Blink
;
373 List
->CurrentEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
377 DrawListEntries(ListUi
);
378 DrawScrollBarGenericList(ListUi
);
384 ScrollPageDownGenericList(
385 IN PGENERIC_LIST_UI ListUi
)
389 /* Suspend auto-redraw */
390 ListUi
->Redraw
= FALSE
;
392 for (i
= ListUi
->Top
+ 1; i
< ListUi
->Bottom
- 1; i
++)
394 ScrollDownGenericList(ListUi
);
397 /* Update user interface */
398 DrawListEntries(ListUi
);
399 DrawScrollBarGenericList(ListUi
);
401 /* Re enable auto-redraw */
402 ListUi
->Redraw
= TRUE
;
406 ScrollPageUpGenericList(
407 IN PGENERIC_LIST_UI ListUi
)
411 /* Suspend auto-redraw */
412 ListUi
->Redraw
= FALSE
;
414 for (i
= ListUi
->Bottom
- 1; i
> ListUi
->Top
+ 1; i
--)
416 ScrollUpGenericList(ListUi
);
419 /* Update user interface */
420 DrawListEntries(ListUi
);
421 DrawScrollBarGenericList(ListUi
);
423 /* Re enable auto-redraw */
424 ListUi
->Redraw
= TRUE
;
428 ScrollToPositionGenericList(
429 IN PGENERIC_LIST_UI ListUi
,
432 PGENERIC_LIST List
= ListUi
->List
;
436 if (List
->CurrentEntry
== NULL
|| uIndex
== 0)
441 if (List
->CurrentEntry
->Entry
.Flink
!= &List
->ListHead
)
443 Entry
= List
->CurrentEntry
->Entry
.Flink
;
444 if (ListUi
->LastShown
== &List
->CurrentEntry
->Entry
)
446 ListUi
->FirstShown
= ListUi
->FirstShown
->Flink
;
447 ListUi
->LastShown
= ListUi
->LastShown
->Flink
;
449 List
->CurrentEntry
= CONTAINING_RECORD(Entry
, GENERIC_LIST_ENTRY
, Entry
);
453 while (uIndex
!= uCount
);
457 DrawListEntries(ListUi
);
458 DrawScrollBarGenericList(ListUi
);
464 IN PGENERIC_LIST_UI ListUi
)
466 if (ListUi
->List
->CurrentEntry
== NULL
)
471 DrawListEntries(ListUi
);
472 DrawScrollBarGenericList(ListUi
);
478 IN PGENERIC_LIST_UI ListUi
,
481 PGENERIC_LIST List
= ListUi
->List
;
482 PGENERIC_LIST_ENTRY ListEntry
;
483 PGENERIC_LIST_ENTRY OldListEntry
;
484 BOOLEAN Flag
= FALSE
;
486 ListEntry
= List
->CurrentEntry
;
487 OldListEntry
= List
->CurrentEntry
;
489 ListUi
->Redraw
= FALSE
;
491 if ((strlen(ListEntry
->Text
) > 0) && (tolower(ListEntry
->Text
[0]) == AsciiChar
) &&
492 (List
->CurrentEntry
->Entry
.Flink
!= &List
->ListHead
))
494 ScrollDownGenericList(ListUi
);
495 ListEntry
= List
->CurrentEntry
;
497 if ((strlen(ListEntry
->Text
) > 0) && (tolower(ListEntry
->Text
[0]) == AsciiChar
))
501 while (List
->CurrentEntry
->Entry
.Blink
!= &List
->ListHead
)
502 ScrollUpGenericList(ListUi
);
504 ListEntry
= List
->CurrentEntry
;
508 if ((strlen(ListEntry
->Text
) > 0) && (tolower(ListEntry
->Text
[0]) == AsciiChar
))
514 if (List
->CurrentEntry
->Entry
.Flink
== &List
->ListHead
)
517 ScrollDownGenericList(ListUi
);
518 ListEntry
= List
->CurrentEntry
;
523 while (List
->CurrentEntry
->Entry
.Blink
!= &List
->ListHead
)
525 if (List
->CurrentEntry
!= OldListEntry
)
526 ScrollUpGenericList(ListUi
);
533 DrawListEntries(ListUi
);
534 DrawScrollBarGenericList(ListUi
);
536 ListUi
->Redraw
= TRUE
;