2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS text-mode setup
4 * FILE: base/setup/usetup/progress.c
5 * PURPOSE: Partition list functions
9 /* INCLUDES *****************************************************************/
16 /* FUNCTIONS ****************************************************************/
20 UpdateProgressPercentage(
22 IN BOOLEAN AlwaysUpdate
,
24 IN SIZE_T cchBufferSize
)
26 // static PCSTR ProgressFormatText;
27 ULONG OldProgress
= Bar
->Progress
;
29 /* Calculate the new percentage */
30 if (Bar
->StepCount
== 0)
33 Bar
->Progress
= ((100 * Bar
->CurrentStep
+ (Bar
->StepCount
/ 2)) / Bar
->StepCount
);
35 /* Build the progress string if it has changed */
36 if ( Bar
->ProgressFormatText
&&
37 (AlwaysUpdate
|| (Bar
->Progress
!= OldProgress
)) )
39 RtlStringCchPrintfA(Buffer
, cchBufferSize
,
40 Bar
->ProgressFormatText
, Bar
->Progress
);
55 /* draw upper left corner */
57 coPos
.Y
= Bar
->Top
+ 1;
58 FillConsoleOutputCharacterA(StdOutput
,
65 coPos
.X
= Bar
->Left
+ 1;
66 coPos
.Y
= Bar
->Top
+ 1;
67 FillConsoleOutputCharacterA(StdOutput
,
69 Bar
->Right
- Bar
->Left
- 1,
73 /* draw upper right corner */
75 coPos
.Y
= Bar
->Top
+ 1;
76 FillConsoleOutputCharacterA(StdOutput
,
82 /* draw left and right edge */
83 for (i
= Bar
->Top
+ 2; i
< Bar
->Bottom
; i
++)
87 FillConsoleOutputCharacterA(StdOutput
,
94 FillConsoleOutputCharacterA(StdOutput
,
101 /* draw lower left corner */
103 coPos
.Y
= Bar
->Bottom
;
104 FillConsoleOutputCharacterA(StdOutput
,
110 /* draw lower edge */
111 coPos
.X
= Bar
->Left
+ 1;
112 coPos
.Y
= Bar
->Bottom
;
113 FillConsoleOutputCharacterA(StdOutput
,
115 Bar
->Right
- Bar
->Left
- 1,
119 /* draw lower right corner */
120 coPos
.X
= Bar
->Right
;
121 coPos
.Y
= Bar
->Bottom
;
122 FillConsoleOutputCharacterA(StdOutput
,
138 /* draw upper left corner */
140 coPos
.Y
= Bar
->Top
+ 1;
141 FillConsoleOutputCharacterA(StdOutput
,
147 /* draw upper edge */
148 coPos
.X
= Bar
->Left
+ 1;
149 coPos
.Y
= Bar
->Top
+ 1;
150 FillConsoleOutputCharacterA(StdOutput
,
152 Bar
->Right
- Bar
->Left
- 1,
156 /* draw upper right corner */
157 coPos
.X
= Bar
->Right
;
158 coPos
.Y
= Bar
->Top
+ 1;
159 FillConsoleOutputCharacterA(StdOutput
,
165 /* draw left and right edge */
166 for (i
= Bar
->Top
+ 2; i
< Bar
->Bottom
; i
++)
170 FillConsoleOutputCharacterA(StdOutput
,
176 coPos
.X
= Bar
->Right
;
177 FillConsoleOutputCharacterA(StdOutput
,
184 /* draw lower left corner */
186 coPos
.Y
= Bar
->Bottom
;
187 FillConsoleOutputCharacterA(StdOutput
,
193 /* draw lower edge */
194 coPos
.X
= Bar
->Left
+ 1;
195 coPos
.Y
= Bar
->Bottom
;
196 FillConsoleOutputCharacterA(StdOutput
,
198 Bar
->Right
- Bar
->Left
- 1,
202 /* draw lower right corner */
203 coPos
.X
= Bar
->Right
;
204 coPos
.Y
= Bar
->Bottom
;
205 FillConsoleOutputCharacterA(StdOutput
,
219 PROGRESSBAR BarBorder
= *Bar
;
220 CHAR TextBuffer
[256];
222 /* Draw the progress bar "border" border */
226 BarBorder
.Bottom
+= 2;
227 BarBorder
.Right
+= 5;
229 DrawThickBorder(&BarBorder
);
232 /* Draw the progress bar border */
235 /* Display the description text */
236 if (Bar
->DescriptionText
)
237 CONSOLE_SetTextXY(Bar
->TextTop
, Bar
->TextRight
, Bar
->DescriptionText
);
239 /* Always update and display the progress */
240 if (Bar
->UpdateProgressProc
&&
241 Bar
->UpdateProgressProc(Bar
, TRUE
, TextBuffer
, ARRAYSIZE(TextBuffer
)))
243 coPos
.X
= Bar
->Left
+ (Bar
->Width
- strlen(TextBuffer
) + 1) / 2;
245 WriteConsoleOutputCharacterA(StdOutput
,
252 /* Draw the empty bar */
253 coPos
.X
= Bar
->Left
+ 1;
254 for (coPos
.Y
= Bar
->Top
+ 2; coPos
.Y
<= Bar
->Bottom
- 1; coPos
.Y
++)
256 FillConsoleOutputAttribute(StdOutput
,
262 FillConsoleOutputCharacterA(StdOutput
,
279 IN BOOLEAN DoubleEdge
,
280 IN SHORT ProgressColour
,
282 IN PCSTR DescriptionText OPTIONAL
,
283 IN PCSTR ProgressFormatText OPTIONAL
,
284 IN PUPDATE_PROGRESS UpdateProgressProc OPTIONAL
)
288 Bar
= (PPROGRESSBAR
)RtlAllocateHeap(ProcessHeap
,
290 sizeof(PROGRESSBAR
));
297 Bar
->Bottom
= Bottom
;
298 Bar
->TextTop
= TextTop
;
299 Bar
->TextRight
= TextRight
;
301 Bar
->Width
= Bar
->Right
- Bar
->Left
+ 1;
303 Bar
->DoubleEdge
= DoubleEdge
;
304 Bar
->ProgressColour
= ProgressColour
;
305 Bar
->DescriptionText
= DescriptionText
;
306 Bar
->ProgressFormatText
= ProgressFormatText
;
308 Bar
->UpdateProgressProc
= UpdateProgressProc
;
310 /* Reset the progress bar counts and initially draw it */
311 ProgressSetStepCount(Bar
, StepCount
);
324 IN BOOLEAN DoubleEdge
,
325 IN PCSTR DescriptionText OPTIONAL
)
327 /* Call the Ex variant of the function */
328 return CreateProgressBarEx(Left
, Top
, Right
, Bottom
,
331 FOREGROUND_YELLOW
| BACKGROUND_BLUE
,
335 UpdateProgressPercentage
);
340 IN OUT PPROGRESSBAR Bar
)
342 RtlFreeHeap(ProcessHeap
, 0, Bar
);
347 ProgressSetStepCount(
351 Bar
->CurrentStep
= 0;
352 Bar
->StepCount
= StepCount
;
357 DrawProgressBar(Bar
);
364 ProgressSetStep(Bar
, Bar
->CurrentStep
+ 1);
375 CHAR TextBuffer
[256];
377 if (Step
> Bar
->StepCount
)
380 Bar
->CurrentStep
= Step
;
382 /* Update the progress and redraw it if it has changed */
383 if (Bar
->UpdateProgressProc
&&
384 Bar
->UpdateProgressProc(Bar
, FALSE
, TextBuffer
, ARRAYSIZE(TextBuffer
)))
386 coPos
.X
= Bar
->Left
+ (Bar
->Width
- strlen(TextBuffer
) + 1) / 2;
388 WriteConsoleOutputCharacterA(StdOutput
,
395 /* Calculate the bar position */
396 NewPos
= (((Bar
->Width
- 2) * 2 * Bar
->CurrentStep
+ (Bar
->StepCount
/ 2)) / Bar
->StepCount
);
398 /* Redraw the bar if it has changed */
399 if (Bar
->Pos
!= NewPos
)
403 for (coPos
.Y
= Bar
->Top
+ 2; coPos
.Y
<= Bar
->Bottom
- 1; coPos
.Y
++)
405 coPos
.X
= Bar
->Left
+ 1;
406 FillConsoleOutputCharacterA(StdOutput
,
411 coPos
.X
+= Bar
->Pos
/ 2;
415 FillConsoleOutputCharacterA(StdOutput
,
423 if (coPos
.X
<= Bar
->Right
- 1)
425 FillConsoleOutputCharacterA(StdOutput
,
427 Bar
->Right
- coPos
.X
,