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.
24 DBG_DEFAULT_CHANNEL(UI
);
26 #define TAG_UI_TEXT 'xTiU'
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 should 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 " };
72 NoUiMessageBoxCritical
,
73 NoUiDrawProgressBarCenter
,
84 BOOLEAN
UiInitialize(BOOLEAN ShowGui
)
86 VIDEODISPLAYMODE UiDisplayMode
; // Tells us if we are in text or graphics mode
87 BOOLEAN UiMinimal
= FALSE
; // Tells us if we are using a minimal console-like UI
90 CHAR SettingText
[260];
94 if (!UiVtbl
.Initialize())
96 MachVideoSetDisplayMode(NULL
, FALSE
);
102 TRACE("Initializing User Interface.\n");
103 TRACE("Reading UI settings from [Display] section.\n");
105 /* Open the [Display] section */
106 if (!IniOpenSection("Display", &SectionId
))
109 /* Select the video mode */
110 SettingText
[0] = '\0';
111 if ((SectionId
!= 0) && !IniReadSettingByName(SectionId
, "DisplayMode", SettingText
, sizeof(SettingText
)))
113 SettingText
[0] = '\0';
115 UiDisplayMode
= MachVideoSetDisplayMode(SettingText
, TRUE
);
116 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
119 if ((SectionId
!= 0) && IniReadSettingByName(SectionId
, "MinimalUI", SettingText
, sizeof(SettingText
)))
121 UiMinimal
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
124 if (UiDisplayMode
== VideoTextMode
)
125 UiVtbl
= (UiMinimal
? MiniTuiVtbl
: TuiVtbl
);
129 if (!UiVtbl
.Initialize())
131 MachVideoSetDisplayMode(NULL
, FALSE
);
135 /* Load the settings */
142 UCHAR SettingType
; // 0: Text, 1: Yes/No, 2: Color, 3: Fill style
145 {"TitleText", &UiTitleBoxTitleText
, 0},
146 {"TimeText" , &UiTimeText
, 0},
148 {"SpecialEffects", &UiUseSpecialEffects
, 1},
149 {"ShowTime" , &UiDrawTime
, 1},
150 {"MenuBox" , &UiMenuBox
, 1},
151 {"CenterMenu" , &UiCenterMenu
, 1},
153 {"BackdropColor" , &UiBackdropBgColor
, 2},
154 {"BackdropTextColor" , &UiBackdropFgColor
, 2},
155 {"StatusBarColor" , &UiStatusBarBgColor
, 2},
156 {"StatusBarTextColor" , &UiStatusBarFgColor
, 2},
157 {"TitleBoxColor" , &UiTitleBoxBgColor
, 2},
158 {"TitleBoxTextColor" , &UiTitleBoxFgColor
, 2},
159 {"MessageBoxColor" , &UiMessageBoxBgColor
, 2},
160 {"MessageBoxTextColor", &UiMessageBoxFgColor
, 2},
161 {"MenuColor" , &UiMenuBgColor
, 2},
162 {"MenuTextColor" , &UiMenuFgColor
, 2},
163 {"TextColor" , &UiTextColor
, 2},
164 {"SelectedColor" , &UiSelectedTextBgColor
, 2},
165 {"SelectedTextColor" , &UiSelectedTextColor
, 2},
166 {"EditBoxColor" , &UiEditBoxBgColor
, 2},
167 {"EditBoxTextColor" , &UiEditBoxTextColor
, 2},
169 {"BackdropFillStyle", &UiBackdropFillStyle
, 3},
173 for (i
= 0; i
< sizeof(Settings
)/sizeof(Settings
[0]); ++i
)
175 if (!IniReadSettingByName(SectionId
, Settings
[i
].SettingName
, SettingText
, sizeof(SettingText
)))
178 switch (Settings
[i
].SettingType
)
181 strcpy((PCHAR
)Settings
[i
].SettingVar
, SettingText
);
184 *(PBOOLEAN
)Settings
[i
].SettingVar
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
187 *(PUCHAR
)Settings
[i
].SettingVar
= UiTextToColor(SettingText
);
189 case 3: // Fill style
190 *(PUCHAR
)Settings
[i
].SettingVar
= UiTextToFillStyle(SettingText
);
198 /* Draw the backdrop and fade it in if special effects are enabled */
201 TRACE("UiInitialize() returning TRUE.\n");
205 VOID
UiUnInitialize(PCSTR BootText
)
208 UiDrawStatusText(BootText
);
211 UiVtbl
.UnInitialize();
214 VOID
UiDrawBackdrop(VOID
)
216 UiVtbl
.DrawBackdrop();
219 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
221 UiVtbl
.FillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
224 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
226 UiVtbl
.DrawShadow(Left
, Top
, Right
, Bottom
);
229 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
231 UiVtbl
.DrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
234 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
236 UiVtbl
.DrawText(X
, Y
, Text
, Attr
);
239 VOID
UiDrawText2(ULONG X
, ULONG Y
, ULONG MaxNumChars
, PCSTR Text
, UCHAR Attr
)
241 UiVtbl
.DrawText2(X
, Y
, MaxNumChars
, Text
, Attr
);
244 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
246 UiVtbl
.DrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
249 VOID
UiDrawStatusText(PCSTR StatusText
)
251 UiVtbl
.DrawStatusText(StatusText
);
254 VOID
UiUpdateDateTime(VOID
)
256 UiVtbl
.UpdateDateTime();
259 VOID
UiInfoBox(PCSTR MessageText
)
264 ULONG LineBreakCount
;
272 TextLength
= strlen(MessageText
);
274 // Count the new lines and the box width
278 for (Index
=0; Index
<TextLength
; Index
++)
280 if (MessageText
[Index
] == '\n')
287 if ((Index
- LastIndex
) > BoxWidth
)
289 BoxWidth
= (ULONG
)(Index
- LastIndex
);
294 // Calc the box width & height
296 BoxHeight
= LineBreakCount
+ 4;
298 // Calc the box coordinates
299 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
300 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
301 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
302 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
313 ATTR(UiMenuFgColor
, UiMenuBgColor
)
317 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
320 VOID
UiMessageBox(PCSTR Format
, ...)
325 va_start(ap
, Format
);
326 vsnprintf(Buffer
, sizeof(Buffer
) - sizeof(CHAR
), Format
, ap
);
327 UiVtbl
.MessageBox(Buffer
);
331 VOID
UiMessageBoxCritical(PCSTR MessageText
)
333 UiVtbl
.MessageBoxCritical(MessageText
);
336 UCHAR
UiTextToColor(PCSTR ColorText
)
338 return UiVtbl
.TextToColor(ColorText
);
341 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
343 return UiVtbl
.TextToFillStyle(FillStyleText
);
346 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
348 UiVtbl
.DrawProgressBarCenter(Position
, Range
, ProgressText
);
351 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
353 UiVtbl
.DrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
357 UiShowMessageBoxesInSection(
358 IN ULONG_PTR SectionId
)
361 CHAR SettingName
[80];
362 CHAR SettingValue
[80];
363 PCHAR MessageBoxText
;
364 ULONG MessageBoxTextSize
;
369 /* Find all the message box settings and run them */
370 for (Idx
= 0; Idx
< IniGetNumSectionItems(SectionId
); Idx
++)
372 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), SettingValue
, sizeof(SettingValue
));
373 if (_stricmp(SettingName
, "MessageBox") != 0)
376 /* Get the real length of the MessageBox text */
377 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
378 // if (MessageBoxTextSize <= 0)
381 /* Allocate enough memory to hold the text */
382 MessageBoxText
= FrLdrTempAlloc(MessageBoxTextSize
, TAG_UI_TEXT
);
386 /* Get the MessageBox text */
387 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), MessageBoxText
, MessageBoxTextSize
);
390 UiEscapeString(MessageBoxText
);
393 UiMessageBox(MessageBoxText
);
395 /* Free the memory */
396 FrLdrTempFree(MessageBoxText
, TAG_UI_TEXT
);
401 UiShowMessageBoxesInArgv(
407 PCHAR MessageBoxText
;
408 SIZE_T MessageBoxTextSize
;
410 /* Find all the message box settings and run them */
412 (ArgValue
= GetNextArgumentValue(Argc
, Argv
, &LastIndex
, "MessageBox")) != NULL
;
415 /* Get the real length of the MessageBox text */
416 MessageBoxTextSize
= (strlen(ArgValue
) + 1) * sizeof(CHAR
);
418 /* Allocate enough memory to hold the text */
419 MessageBoxText
= FrLdrTempAlloc(MessageBoxTextSize
, TAG_UI_TEXT
);
423 /* Get the MessageBox text */
424 strcpy(MessageBoxText
, ArgValue
);
427 UiEscapeString(MessageBoxText
);
430 UiMessageBox(MessageBoxText
);
432 /* Free the memory */
433 FrLdrTempFree(MessageBoxText
, TAG_UI_TEXT
);
437 VOID
UiEscapeString(PCHAR String
)
441 for (Idx
=0; Idx
<strlen(String
); Idx
++)
443 // Escape the new line characters
444 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
446 // Escape the character
449 // Move the rest of the string up
450 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
455 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
457 /* If it's too large, just add some ellipsis past the maximum */
458 if (strlen(StringText
) > MaxChars
)
459 strcpy(&StringText
[MaxChars
- 3], "...");
465 IN PCSTR MenuFooter OPTIONAL
,
466 IN BOOLEAN ShowBootOptions
,
467 IN PCSTR MenuItemList
[],
468 IN ULONG MenuItemCount
,
469 IN ULONG DefaultMenuItem
,
471 OUT PULONG SelectedMenuItem
,
472 IN BOOLEAN CanEscape
,
473 IN UiMenuKeyPressFilterCallback KeyPressFilter OPTIONAL
,
474 IN PVOID Context OPTIONAL
)
476 return UiVtbl
.DisplayMenu(MenuHeader
, MenuFooter
, ShowBootOptions
,
477 MenuItemList
, MenuItemCount
, DefaultMenuItem
,
478 MenuTimeOut
, SelectedMenuItem
, CanEscape
,
479 KeyPressFilter
, Context
);
482 VOID
UiFadeInBackdrop(VOID
)
484 UiVtbl
.FadeInBackdrop();
492 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
494 return UiVtbl
.EditBox(MessageText
, EditTextBuffer
, Length
);
498 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)