3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
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.
26 ULONG UiScreenWidth
= 80; // Screen Width
27 ULONG UiScreenHeight
= 25; // Screen Height
29 UCHAR UiStatusBarFgColor
= COLOR_BLACK
; // Status bar foreground color
30 UCHAR UiStatusBarBgColor
= COLOR_CYAN
; // Status bar background color
31 UCHAR UiBackdropFgColor
= COLOR_WHITE
; // Backdrop foreground color
32 UCHAR UiBackdropBgColor
= COLOR_BLUE
; // Backdrop background color
33 UCHAR UiBackdropFillStyle
= MEDIUM_FILL
; // Backdrop fill style
34 UCHAR UiTitleBoxFgColor
= COLOR_WHITE
; // Title box foreground color
35 UCHAR UiTitleBoxBgColor
= COLOR_RED
; // Title box background color
36 UCHAR UiMessageBoxFgColor
= COLOR_WHITE
; // Message box foreground color
37 UCHAR UiMessageBoxBgColor
= COLOR_BLUE
; // Message box background color
38 UCHAR UiMenuFgColor
= COLOR_WHITE
; // Menu foreground color
39 UCHAR UiMenuBgColor
= COLOR_BLUE
; // Menu background color
40 UCHAR UiTextColor
= COLOR_YELLOW
; // Normal text color
41 UCHAR UiSelectedTextColor
= COLOR_BLACK
; // Selected text color
42 UCHAR UiSelectedTextBgColor
= COLOR_GRAY
; // Selected text background color
43 UCHAR UiEditBoxTextColor
= COLOR_WHITE
; // Edit box text color
44 UCHAR UiEditBoxBgColor
= COLOR_BLACK
; // Edit box text background color
46 CHAR UiTitleBoxTitleText
[260] = "Boot Menu"; // Title box's title text
48 BOOL UserInterfaceUp
= FALSE
; // Tells us if the user interface is displayed
50 VIDEODISPLAYMODE UiDisplayMode
= VideoTextMode
; // Tells us if we are in text or graphics mode
52 BOOL UiUseSpecialEffects
= FALSE
; // Tells us if we should use fade effects
53 BOOL UiDrawTime
= TRUE
; // Tells us if we should draw the time
54 BOOL UiMinimal
= FALSE
; // Tells us if we should use a minimal console-like UI
55 BOOL UiCenterMenu
= TRUE
; // Tells us if we should use a centered or left-aligned menu
56 BOOL UiMenuBox
= TRUE
; // Tells us if we shuld draw a box around the menu
57 CHAR UiTimeText
[260] = "[Time Remaining: ] ";
59 const CHAR UiMonthNames
[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
62 BOOL
UiInitialize(BOOLEAN ShowGui
)
65 CHAR DisplayModeText
[260];
66 CHAR SettingText
[260];
72 MachVideoSetDisplayMode(NULL
, FALSE
);
75 UserInterfaceUp
= FALSE
;
79 DbgPrint((DPRINT_UI
, "Initializing User Interface.\n"));
81 DbgPrint((DPRINT_UI
, "Reading in UI settings from [Display] section.\n"));
83 DisplayModeText
[0] = '\0';
84 if (IniOpenSection("Display", &SectionId
))
86 if (! IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, 260))
88 DisplayModeText
[0] = '\0';
91 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, 260))
93 strcpy(UiTitleBoxTitleText
, SettingText
);
95 if (IniReadSettingByName(SectionId
, "TimeText", SettingText
, 260))
97 strcpy(UiTimeText
, SettingText
);
99 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, 260))
101 UiStatusBarBgColor
= UiTextToColor(SettingText
);
103 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, 260))
105 UiStatusBarFgColor
= UiTextToColor(SettingText
);
107 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, 260))
109 UiBackdropFgColor
= UiTextToColor(SettingText
);
111 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, 260))
113 UiBackdropBgColor
= UiTextToColor(SettingText
);
115 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, 260))
117 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
119 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, 260))
121 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
123 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, 260))
125 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
127 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, 260))
129 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
131 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, 260))
133 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
135 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, 260))
137 UiMenuFgColor
= UiTextToColor(SettingText
);
139 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, 260))
141 UiMenuBgColor
= UiTextToColor(SettingText
);
143 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, 260))
145 UiTextColor
= UiTextToColor(SettingText
);
147 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, 260))
149 UiSelectedTextColor
= UiTextToColor(SettingText
);
151 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, 260))
153 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
155 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, 260))
157 UiEditBoxTextColor
= UiTextToColor(SettingText
);
159 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, 260))
161 UiEditBoxBgColor
= UiTextToColor(SettingText
);
163 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, 260))
165 if (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3)
167 UiUseSpecialEffects
= TRUE
;
171 UiUseSpecialEffects
= FALSE
;
174 if (IniReadSettingByName(SectionId
, "ShowTime", SettingText
, 260))
176 if (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3)
185 if (IniReadSettingByName(SectionId
, "MinimalUI", SettingText
, 260))
187 if (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3)
196 if (IniReadSettingByName(SectionId
, "MenuBox", SettingText
, 260))
198 if (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3)
207 if (IniReadSettingByName(SectionId
, "CenterMenu", SettingText
, 260))
209 if (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3)
215 UiCenterMenu
= FALSE
;
220 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
221 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
224 if (VideoTextMode
== UiDisplayMode
)
226 if (!TuiInitialize())
228 MachVideoSetDisplayMode(NULL
, FALSE
);
235 //if (!GuiInitialize())
237 // MachSetDisplayMode(NULL, FALSE);
242 // Draw the backdrop and fade it in if special effects are enabled
245 UserInterfaceUp
= TRUE
;
247 DbgPrint((DPRINT_UI
, "UiInitialize() returning TRUE.\n"));
251 BOOL
SetupUiInitialize(VOID
)
254 CHAR DisplayModeText
[260];
258 DisplayModeText
[0] = '\0';
261 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
262 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
266 // Draw the backdrop and fade it in if special effects are enabled
272 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
274 UiStatusBarBgColor
= 7;
275 UserInterfaceUp
= TRUE
;
277 TuiDrawText(4, 1, "ReactOS " KERNEL_VERSION_STR
" Setup", ATTR(COLOR_GRAY
, UiBackdropBgColor
));
278 TuiDrawText(3, 2, "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD", ATTR(COLOR_GRAY
, UiBackdropBgColor
));
280 DbgPrint((DPRINT_UI
, "UiInitialize() returning TRUE.\n"));
285 VOID
UiUnInitialize(PCSTR BootText
)
288 UiDrawStatusText("Booting...");
291 if (VideoTextMode
== UiDisplayMode
)
302 VOID
UiDrawBackdrop(VOID
)
304 if (!UserInterfaceUp
) return;
306 if (VideoTextMode
== UiDisplayMode
)
317 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
319 if (VideoTextMode
== UiDisplayMode
)
321 TuiFillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
326 //GuiFillArea(Left, Top, Right, Bottom, FillChar, Attr);
330 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
332 if (VideoTextMode
== UiDisplayMode
)
334 TuiDrawShadow(Left
, Top
, Right
, Bottom
);
339 //GuiDrawShadow(Left, Top, Right, Bottom);
343 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOL Fill
, BOOL Shadow
, UCHAR Attr
)
345 if (VideoTextMode
== UiDisplayMode
)
347 TuiDrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
352 //GuiDrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
356 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
358 if (VideoTextMode
== UiDisplayMode
)
360 TuiDrawText(X
, Y
, Text
, Attr
);
365 //GuiDrawText(X, Y, Text, Attr);
369 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
371 if (VideoTextMode
== UiDisplayMode
)
373 TuiDrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
378 //GuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
382 VOID
UiDrawStatusText(PCSTR StatusText
)
384 if (!UserInterfaceUp
) return;
386 if (VideoTextMode
== UiDisplayMode
)
388 TuiDrawStatusText(StatusText
);
393 //GuiDrawStatusText(StatusText);
397 VOID
UiUpdateDateTime(VOID
)
399 if (VideoTextMode
== UiDisplayMode
)
406 //GuiUpdateDateTime();
410 VOID
UiInfoBox(PCSTR MessageText
)
415 ULONG LineBreakCount
;
423 TextLength
= strlen(MessageText
);
425 // Count the new lines and the box width
429 for (Index
=0; Index
<TextLength
; Index
++)
431 if (MessageText
[Index
] == '\n')
438 if ((Index
- LastIndex
) > BoxWidth
)
440 BoxWidth
= (Index
- LastIndex
);
445 // Calc the box width & height
447 BoxHeight
= LineBreakCount
+ 4;
449 // Calc the box coordinates
450 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
451 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
452 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
453 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
464 ATTR(UiMenuFgColor
, UiMenuBgColor
)
468 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
471 VOID
UiMessageBox(PCSTR MessageText
)
473 // We have not yet displayed the user interface
474 // We are probably still reading the .ini file
475 // and have encountered an error. Just use printf()
477 if (!UserInterfaceUp
)
479 printf("%s\n", MessageText
);
480 printf("Press any key\n");
485 if (VideoTextMode
== UiDisplayMode
)
487 TuiMessageBox(MessageText
);
492 //GuiMessageBox(MessageText);
496 VOID
UiMessageBoxCritical(PCSTR MessageText
)
498 // We have not yet displayed the user interface
499 // We are probably still reading the .ini file
500 // and have encountered an error. Just use printf()
502 if (!UserInterfaceUp
)
504 printf("%s\n", MessageText
);
505 printf("Press any key\n");
510 if (VideoTextMode
== UiDisplayMode
)
512 TuiMessageBoxCritical(MessageText
);
517 //GuiMessageBoxCritical(MessageText);
521 UCHAR
UiTextToColor(PCSTR ColorText
)
523 if (VideoTextMode
== UiDisplayMode
)
525 return TuiTextToColor(ColorText
);
531 //return GuiTextToColor(ColorText);
535 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
537 if (VideoTextMode
== UiDisplayMode
)
539 return TuiTextToFillStyle(FillStyleText
);
545 //return GuiTextToFillStyle(FillStyleText);
549 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
551 if (!UserInterfaceUp
) return;
553 if (VideoTextMode
== UiDisplayMode
)
555 TuiDrawProgressBarCenter(Position
, Range
, ProgressText
);
560 //GuiDrawProgressBarCenter(Position, Range, ProgressText);
564 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
566 if (VideoTextMode
== UiDisplayMode
)
568 TuiDrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
573 //GuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
577 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
580 CHAR SettingName
[80];
581 CHAR SettingValue
[80];
582 PCHAR MessageBoxText
;
583 ULONG MessageBoxTextSize
;
586 if (!IniOpenSection(SectionName
, &SectionId
))
588 sprintf(SettingName
, "Section %s not found in freeldr.ini.\n", SectionName
);
589 UiMessageBox(SettingName
);
594 // Find all the message box settings and run them
596 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
598 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, 79, SettingValue
, 79);
600 if (_stricmp(SettingName
, "MessageBox") == 0)
602 // Get the real length of the MessageBox text
603 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
605 //if (MessageBoxTextSize > 0)
607 // Allocate enough memory to hold the text
608 MessageBoxText
= MmAllocateMemory(MessageBoxTextSize
);
612 // Get the MessageBox text
613 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, 80, MessageBoxText
, MessageBoxTextSize
);
616 UiEscapeString(MessageBoxText
);
619 UiMessageBox(MessageBoxText
);
622 MmFreeMemory(MessageBoxText
);
629 VOID
UiEscapeString(PCHAR String
)
633 for (Idx
=0; Idx
<strlen(String
); Idx
++)
635 // Escape the new line characters
636 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
638 // Escape the character
641 // Move the rest of the string up
642 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
647 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
649 if (strlen(StringText
) > MaxChars
)
651 strcpy(&StringText
[MaxChars
- 3], "...");
655 BOOL
UiDisplayMenu(PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOL CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
657 if (VideoTextMode
== UiDisplayMode
)
659 return TuiDisplayMenu(MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
665 //return GuiDisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem, CanEscape, KeyPressFilter);
669 VOID
UiFadeInBackdrop(VOID
)
671 if (VideoTextMode
== UiDisplayMode
)
678 //GuiFadeInBackdrop();
684 if (VideoTextMode
== UiDisplayMode
)
695 BOOL
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
697 if (VideoTextMode
== UiDisplayMode
)
699 return TuiEditBox(MessageText
, EditTextBuffer
, Length
);
705 //return GuiEditBox(MessageText, EditTextBuffer, Length);