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 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.
22 #include <reactos/buildno.h>
24 DBG_DEFAULT_CHANNEL(UI
);
26 BOOLEAN UiMinimal
= FALSE
; // Tells us if we are using a minimal console-like UI
28 ULONG UiScreenWidth
; // Screen Width
29 ULONG UiScreenHeight
; // Screen Height
31 UCHAR UiStatusBarFgColor
= COLOR_BLACK
; // Status bar foreground color
32 UCHAR UiStatusBarBgColor
= COLOR_CYAN
; // Status bar background color
33 UCHAR UiBackdropFgColor
= COLOR_WHITE
; // Backdrop foreground color
34 UCHAR UiBackdropBgColor
= COLOR_BLUE
; // Backdrop background color
35 UCHAR UiBackdropFillStyle
= MEDIUM_FILL
; // Backdrop fill style
36 UCHAR UiTitleBoxFgColor
= COLOR_WHITE
; // Title box foreground color
37 UCHAR UiTitleBoxBgColor
= COLOR_RED
; // Title box background color
38 UCHAR UiMessageBoxFgColor
= COLOR_WHITE
; // Message box foreground color
39 UCHAR UiMessageBoxBgColor
= COLOR_BLUE
; // Message box background color
40 UCHAR UiMenuFgColor
= COLOR_WHITE
; // Menu foreground color
41 UCHAR UiMenuBgColor
= COLOR_BLUE
; // Menu background color
42 UCHAR UiTextColor
= COLOR_YELLOW
; // Normal text color
43 UCHAR UiSelectedTextColor
= COLOR_BLACK
; // Selected text color
44 UCHAR UiSelectedTextBgColor
= COLOR_GRAY
; // Selected text background color
45 UCHAR UiEditBoxTextColor
= COLOR_WHITE
; // Edit box text color
46 UCHAR UiEditBoxBgColor
= COLOR_BLACK
; // Edit box text background color
48 CHAR UiTitleBoxTitleText
[260] = "Boot Menu"; // Title box's title text
50 BOOLEAN UiUseSpecialEffects
= FALSE
; // Tells us if we should use fade effects
51 BOOLEAN UiDrawTime
= TRUE
; // Tells us if we should draw the time
52 BOOLEAN UiCenterMenu
= TRUE
; // Tells us if we should use a centered or left-aligned menu
53 BOOLEAN UiMenuBox
= TRUE
; // Tells us if we shuld draw a box around the menu
54 CHAR UiTimeText
[260] = "[Time Remaining: ] ";
56 const CHAR UiMonthNames
[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
71 NoUiMessageBoxCritical
,
72 NoUiDrawProgressBarCenter
,
83 BOOLEAN
UiInitialize(BOOLEAN ShowGui
)
85 VIDEODISPLAYMODE UiDisplayMode
; // Tells us if we are in text or graphics mode
87 CHAR DisplayModeText
[260];
88 CHAR SettingText
[260];
93 if (!UiVtbl
.Initialize())
95 MachVideoSetDisplayMode(NULL
, FALSE
);
101 TRACE("Initializing User Interface.\n");
102 TRACE("Reading in UI settings from [Display] section.\n");
104 DisplayModeText
[0] = '\0';
105 if (IniOpenSection("Display", &SectionId
))
107 if (!IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, sizeof(DisplayModeText
)))
109 DisplayModeText
[0] = '\0';
111 if (IniReadSettingByName(SectionId
, "MinimalUI", SettingText
, sizeof(SettingText
)))
113 UiMinimal
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
117 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
118 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
120 if (VideoTextMode
== UiDisplayMode
)
121 UiVtbl
= (UiMinimal
? MiniTuiVtbl
: TuiVtbl
);
125 if (!UiVtbl
.Initialize())
127 MachVideoSetDisplayMode(NULL
, FALSE
);
131 if (IniOpenSection("Display", &SectionId
))
133 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, sizeof(SettingText
)))
135 strcpy(UiTitleBoxTitleText
, SettingText
);
137 if (IniReadSettingByName(SectionId
, "TimeText", SettingText
, sizeof(SettingText
)))
139 strcpy(UiTimeText
, SettingText
);
141 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, sizeof(SettingText
)))
143 UiStatusBarBgColor
= UiTextToColor(SettingText
);
145 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, sizeof(SettingText
)))
147 UiStatusBarFgColor
= UiTextToColor(SettingText
);
149 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, sizeof(SettingText
)))
151 UiBackdropFgColor
= UiTextToColor(SettingText
);
153 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, sizeof(SettingText
)))
155 UiBackdropBgColor
= UiTextToColor(SettingText
);
157 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, sizeof(SettingText
)))
159 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
161 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, sizeof(SettingText
)))
163 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
165 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, sizeof(SettingText
)))
167 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
169 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, sizeof(SettingText
)))
171 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
173 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, sizeof(SettingText
)))
175 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
177 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, sizeof(SettingText
)))
179 UiMenuFgColor
= UiTextToColor(SettingText
);
181 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, sizeof(SettingText
)))
183 UiMenuBgColor
= UiTextToColor(SettingText
);
185 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, sizeof(SettingText
)))
187 UiTextColor
= UiTextToColor(SettingText
);
189 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, sizeof(SettingText
)))
191 UiSelectedTextColor
= UiTextToColor(SettingText
);
193 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, sizeof(SettingText
)))
195 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
197 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, sizeof(SettingText
)))
199 UiEditBoxTextColor
= UiTextToColor(SettingText
);
201 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, sizeof(SettingText
)))
203 UiEditBoxBgColor
= UiTextToColor(SettingText
);
205 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, sizeof(SettingText
)))
207 UiUseSpecialEffects
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
209 if (IniReadSettingByName(SectionId
, "ShowTime", SettingText
, sizeof(SettingText
)))
211 UiDrawTime
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
213 if (IniReadSettingByName(SectionId
, "MenuBox", SettingText
, sizeof(SettingText
)))
215 UiMenuBox
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
217 if (IniReadSettingByName(SectionId
, "CenterMenu", SettingText
, sizeof(SettingText
)))
219 UiCenterMenu
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
223 // Draw the backdrop and fade it in if special effects are enabled
226 TRACE("UiInitialize() returning TRUE.\n");
230 VOID
UiUnInitialize(PCSTR BootText
)
233 UiDrawStatusText("Booting...");
236 UiVtbl
.UnInitialize();
239 VOID
UiDrawBackdrop(VOID
)
241 UiVtbl
.DrawBackdrop();
244 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
246 UiVtbl
.FillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
249 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
251 UiVtbl
.DrawShadow(Left
, Top
, Right
, Bottom
);
254 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
256 UiVtbl
.DrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
259 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
261 UiVtbl
.DrawText(X
, Y
, Text
, Attr
);
264 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
266 UiVtbl
.DrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
269 VOID
UiDrawStatusText(PCSTR StatusText
)
271 UiVtbl
.DrawStatusText(StatusText
);
274 VOID
UiUpdateDateTime(VOID
)
276 UiVtbl
.UpdateDateTime();
279 VOID
UiInfoBox(PCSTR MessageText
)
284 ULONG LineBreakCount
;
292 TextLength
= strlen(MessageText
);
294 // Count the new lines and the box width
298 for (Index
=0; Index
<TextLength
; Index
++)
300 if (MessageText
[Index
] == '\n')
307 if ((Index
- LastIndex
) > BoxWidth
)
309 BoxWidth
= (ULONG
)(Index
- LastIndex
);
314 // Calc the box width & height
316 BoxHeight
= LineBreakCount
+ 4;
318 // Calc the box coordinates
319 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
320 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
321 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
322 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
333 ATTR(UiMenuFgColor
, UiMenuBgColor
)
337 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
340 VOID
UiMessageBox(PCSTR MessageText
)
342 UiVtbl
.MessageBox(MessageText
);
345 VOID
UiMessageBoxCritical(PCSTR MessageText
)
347 UiVtbl
.MessageBoxCritical(MessageText
);
350 UCHAR
UiTextToColor(PCSTR ColorText
)
352 return UiVtbl
.TextToColor(ColorText
);
355 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
357 return UiVtbl
.TextToFillStyle(FillStyleText
);
360 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
362 UiVtbl
.DrawProgressBarCenter(Position
, Range
, ProgressText
);
365 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
367 UiVtbl
.DrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
370 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
373 CHAR SettingName
[80];
374 CHAR SettingValue
[80];
375 PCHAR MessageBoxText
;
376 ULONG MessageBoxTextSize
;
379 if (!IniOpenSection(SectionName
, &SectionId
))
385 // Find all the message box settings and run them
387 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
389 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), SettingValue
, sizeof(SettingValue
));
391 if (_stricmp(SettingName
, "MessageBox") == 0)
393 // Get the real length of the MessageBox text
394 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
396 //if (MessageBoxTextSize > 0)
398 // Allocate enough memory to hold the text
399 MessageBoxText
= MmHeapAlloc(MessageBoxTextSize
);
403 // Get the MessageBox text
404 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), MessageBoxText
, MessageBoxTextSize
);
407 UiEscapeString(MessageBoxText
);
410 UiMessageBox(MessageBoxText
);
413 MmHeapFree(MessageBoxText
);
420 VOID
UiEscapeString(PCHAR String
)
424 for (Idx
=0; Idx
<strlen(String
); Idx
++)
426 // Escape the new line characters
427 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
429 // Escape the character
432 // Move the rest of the string up
433 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
438 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
440 if (strlen(StringText
) > MaxChars
)
442 strcpy(&StringText
[MaxChars
- 3], "...");
446 BOOLEAN
UiDisplayMenu(PCSTR MenuTitle
, PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOLEAN CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
448 return UiVtbl
.DisplayMenu(MenuTitle
, MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
451 VOID
UiFadeInBackdrop(VOID
)
453 UiVtbl
.FadeInBackdrop();
461 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
463 return UiVtbl
.EditBox(MessageText
, EditTextBuffer
, Length
);
467 /* SETUP MODE *****************************************************************/
469 VOID
SetupUiDrawBackdrop(VOID
)
474 // Draw the backdrop and fade it in if special effects are enabled
475 UiVtbl
.FillArea(0, 0, UiScreenWidth
- 1, UiScreenHeight
- 2, 0,
476 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
478 Length
= min( strlen("ReactOS " KERNEL_VERSION_STR
" Setup"),
479 sizeof(Underline
) - 1 );
480 memset(Underline
, 0xcd, Length
); // Underline title
481 Underline
[Length
] = '\0';
483 UiVtbl
.DrawText(4, 1, "ReactOS " KERNEL_VERSION_STR
" Setup", ATTR(COLOR_GRAY
, UiBackdropBgColor
));
484 UiVtbl
.DrawText(4, 2, Underline
, ATTR(COLOR_GRAY
, UiBackdropBgColor
));
486 // Update the screen buffer
487 VideoCopyOffScreenBufferToVRAM();
490 BOOLEAN
SetupUiInitialize(VOID
)
496 // Initialize the video
497 MachVideoSetDisplayMode(NULL
, TRUE
);
498 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
500 // Use Text UI with a modified backdrop and set display properties
502 UiVtbl
.DrawBackdrop
= SetupUiDrawBackdrop
;
504 UiStatusBarFgColor
= COLOR_BLACK
;
505 UiStatusBarBgColor
= COLOR_GRAY
;
506 UiBackdropFgColor
= COLOR_WHITE
;
507 UiBackdropBgColor
= COLOR_BLUE
;
508 UiBackdropFillStyle
= MEDIUM_FILL
;
509 UiTitleBoxFgColor
= COLOR_WHITE
;
510 UiTitleBoxBgColor
= COLOR_RED
;
511 UiMessageBoxFgColor
= COLOR_WHITE
;
512 UiMessageBoxBgColor
= COLOR_BLUE
;
513 UiMenuFgColor
= COLOR_WHITE
;
514 UiMenuBgColor
= COLOR_BLUE
;
515 UiTextColor
= COLOR_YELLOW
;
516 UiSelectedTextColor
= COLOR_BLACK
;
517 UiSelectedTextBgColor
= COLOR_GRAY
;
518 UiEditBoxTextColor
= COLOR_WHITE
;
519 UiEditBoxBgColor
= COLOR_BLACK
;
520 UiUseSpecialEffects
= FALSE
;
529 TRACE("SetupUiInitialize() returning TRUE.\n");