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
54 const CHAR UiMonthNames
[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
57 BOOL
UiInitialize(BOOLEAN ShowGui
)
60 CHAR DisplayModeText
[260];
61 CHAR SettingText
[260];
67 MachVideoSetDisplayMode(NULL
, FALSE
);
70 UserInterfaceUp
= FALSE
;
74 DbgPrint((DPRINT_UI
, "Initializing User Interface.\n"));
76 DbgPrint((DPRINT_UI
, "Reading in UI settings from [Display] section.\n"));
78 DisplayModeText
[0] = '\0';
79 if (IniOpenSection("Display", &SectionId
))
81 if (! IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, 260))
83 DisplayModeText
[0] = '\0';
86 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, 260))
88 strcpy(UiTitleBoxTitleText
, SettingText
);
90 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, 260))
92 UiStatusBarBgColor
= UiTextToColor(SettingText
);
94 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, 260))
96 UiStatusBarFgColor
= UiTextToColor(SettingText
);
98 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, 260))
100 UiBackdropFgColor
= UiTextToColor(SettingText
);
102 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, 260))
104 UiBackdropBgColor
= UiTextToColor(SettingText
);
106 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, 260))
108 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
110 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, 260))
112 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
114 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, 260))
116 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
118 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, 260))
120 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
122 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, 260))
124 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
126 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, 260))
128 UiMenuFgColor
= UiTextToColor(SettingText
);
130 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, 260))
132 UiMenuBgColor
= UiTextToColor(SettingText
);
134 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, 260))
136 UiTextColor
= UiTextToColor(SettingText
);
138 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, 260))
140 UiSelectedTextColor
= UiTextToColor(SettingText
);
142 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, 260))
144 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
146 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, 260))
148 UiEditBoxTextColor
= UiTextToColor(SettingText
);
150 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, 260))
152 UiEditBoxBgColor
= UiTextToColor(SettingText
);
154 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, 260))
156 if (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3)
158 UiUseSpecialEffects
= TRUE
;
162 UiUseSpecialEffects
= FALSE
;
167 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
168 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
171 if (VideoTextMode
== UiDisplayMode
)
173 if (!TuiInitialize())
175 MachVideoSetDisplayMode(NULL
, FALSE
);
182 //if (!GuiInitialize())
184 // MachSetDisplayMode(NULL, FALSE);
189 // Draw the backdrop and fade it in if special effects are enabled
192 UserInterfaceUp
= TRUE
;
194 DbgPrint((DPRINT_UI
, "UiInitialize() returning TRUE.\n"));
198 BOOL
SetupUiInitialize(VOID
)
201 CHAR DisplayModeText
[260];
205 DisplayModeText
[0] = '\0';
208 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
209 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
213 // Draw the backdrop and fade it in if special effects are enabled
219 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
221 UiStatusBarBgColor
= 7;
222 UserInterfaceUp
= TRUE
;
224 TuiDrawText(4, 1, "ReactOS " KERNEL_VERSION_STR
" Setup", ATTR(COLOR_GRAY
, UiBackdropBgColor
));
225 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
));
227 DbgPrint((DPRINT_UI
, "UiInitialize() returning TRUE.\n"));
232 VOID
UiUnInitialize(PCSTR BootText
)
235 UiDrawStatusText("Booting...");
238 if (VideoTextMode
== UiDisplayMode
)
249 VOID
UiDrawBackdrop(VOID
)
251 if (!UserInterfaceUp
) return;
253 if (VideoTextMode
== UiDisplayMode
)
264 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
266 if (VideoTextMode
== UiDisplayMode
)
268 TuiFillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
273 //GuiFillArea(Left, Top, Right, Bottom, FillChar, Attr);
277 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
279 if (VideoTextMode
== UiDisplayMode
)
281 TuiDrawShadow(Left
, Top
, Right
, Bottom
);
286 //GuiDrawShadow(Left, Top, Right, Bottom);
290 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOL Fill
, BOOL Shadow
, UCHAR Attr
)
292 if (VideoTextMode
== UiDisplayMode
)
294 TuiDrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
299 //GuiDrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
303 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
305 if (VideoTextMode
== UiDisplayMode
)
307 TuiDrawText(X
, Y
, Text
, Attr
);
312 //GuiDrawText(X, Y, Text, Attr);
316 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
318 if (VideoTextMode
== UiDisplayMode
)
320 TuiDrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
325 //GuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
329 VOID
UiDrawStatusText(PCSTR StatusText
)
331 if (!UserInterfaceUp
) return;
333 if (VideoTextMode
== UiDisplayMode
)
335 TuiDrawStatusText(StatusText
);
340 //GuiDrawStatusText(StatusText);
344 VOID
UiUpdateDateTime(VOID
)
346 if (VideoTextMode
== UiDisplayMode
)
353 //GuiUpdateDateTime();
357 VOID
UiInfoBox(PCSTR MessageText
)
362 ULONG LineBreakCount
;
370 TextLength
= strlen(MessageText
);
372 // Count the new lines and the box width
376 for (Index
=0; Index
<TextLength
; Index
++)
378 if (MessageText
[Index
] == '\n')
385 if ((Index
- LastIndex
) > BoxWidth
)
387 BoxWidth
= (Index
- LastIndex
);
392 // Calc the box width & height
394 BoxHeight
= LineBreakCount
+ 4;
396 // Calc the box coordinates
397 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
398 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
399 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
400 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
411 ATTR(UiMenuFgColor
, UiMenuBgColor
)
415 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
418 VOID
UiMessageBox(PCSTR MessageText
)
420 // We have not yet displayed the user interface
421 // We are probably still reading the .ini file
422 // and have encountered an error. Just use printf()
424 if (!UserInterfaceUp
)
426 printf("%s\n", MessageText
);
427 printf("Press any key\n");
432 if (VideoTextMode
== UiDisplayMode
)
434 TuiMessageBox(MessageText
);
439 //GuiMessageBox(MessageText);
443 VOID
UiMessageBoxCritical(PCSTR MessageText
)
445 // We have not yet displayed the user interface
446 // We are probably still reading the .ini file
447 // and have encountered an error. Just use printf()
449 if (!UserInterfaceUp
)
451 printf("%s\n", MessageText
);
452 printf("Press any key\n");
457 if (VideoTextMode
== UiDisplayMode
)
459 TuiMessageBoxCritical(MessageText
);
464 //GuiMessageBoxCritical(MessageText);
468 UCHAR
UiTextToColor(PCSTR ColorText
)
470 if (VideoTextMode
== UiDisplayMode
)
472 return TuiTextToColor(ColorText
);
478 //return GuiTextToColor(ColorText);
482 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
484 if (VideoTextMode
== UiDisplayMode
)
486 return TuiTextToFillStyle(FillStyleText
);
492 //return GuiTextToFillStyle(FillStyleText);
496 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
498 if (!UserInterfaceUp
) return;
500 if (VideoTextMode
== UiDisplayMode
)
502 TuiDrawProgressBarCenter(Position
, Range
, ProgressText
);
507 //GuiDrawProgressBarCenter(Position, Range, ProgressText);
511 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
513 if (VideoTextMode
== UiDisplayMode
)
515 TuiDrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
520 //GuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
524 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
527 CHAR SettingName
[80];
528 CHAR SettingValue
[80];
529 PCHAR MessageBoxText
;
530 ULONG MessageBoxTextSize
;
533 if (!IniOpenSection(SectionName
, &SectionId
))
535 sprintf(SettingName
, "Section %s not found in freeldr.ini.\n", SectionName
);
536 UiMessageBox(SettingName
);
541 // Find all the message box settings and run them
543 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
545 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, 79, SettingValue
, 79);
547 if (_stricmp(SettingName
, "MessageBox") == 0)
549 // Get the real length of the MessageBox text
550 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
552 //if (MessageBoxTextSize > 0)
554 // Allocate enough memory to hold the text
555 MessageBoxText
= MmAllocateMemory(MessageBoxTextSize
);
559 // Get the MessageBox text
560 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, 80, MessageBoxText
, MessageBoxTextSize
);
563 UiEscapeString(MessageBoxText
);
566 UiMessageBox(MessageBoxText
);
569 MmFreeMemory(MessageBoxText
);
576 VOID
UiEscapeString(PCHAR String
)
580 for (Idx
=0; Idx
<strlen(String
); Idx
++)
582 // Escape the new line characters
583 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
585 // Escape the character
588 // Move the rest of the string up
589 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
594 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
596 if (strlen(StringText
) > MaxChars
)
598 strcpy(&StringText
[MaxChars
- 3], "...");
602 BOOL
UiDisplayMenu(PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOL CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
604 if (VideoTextMode
== UiDisplayMode
)
606 return TuiDisplayMenu(MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
612 //return GuiDisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem, CanEscape, KeyPressFilter);
616 VOID
UiFadeInBackdrop(VOID
)
618 if (VideoTextMode
== UiDisplayMode
)
625 //GuiFadeInBackdrop();
631 if (VideoTextMode
== UiDisplayMode
)
642 BOOL
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
644 if (VideoTextMode
== UiDisplayMode
)
646 return TuiEditBox(MessageText
, EditTextBuffer
, Length
);
652 //return GuiEditBox(MessageText, EditTextBuffer, Length);