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 #define TAG_UI_TEXT 'xTiU'
26 DBG_DEFAULT_CHANNEL(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 " };
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
89 CHAR DisplayModeText
[260];
90 CHAR SettingText
[260];
95 if (!UiVtbl
.Initialize())
97 MachVideoSetDisplayMode(NULL
, FALSE
);
103 TRACE("Initializing User Interface.\n");
104 TRACE("Reading in UI settings from [Display] section.\n");
106 DisplayModeText
[0] = '\0';
107 if (IniOpenSection("Display", &SectionId
))
109 if (!IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, sizeof(DisplayModeText
)))
111 DisplayModeText
[0] = '\0';
113 if (IniReadSettingByName(SectionId
, "MinimalUI", SettingText
, sizeof(SettingText
)))
115 UiMinimal
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
119 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
120 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
122 if (VideoTextMode
== UiDisplayMode
)
123 UiVtbl
= (UiMinimal
? MiniTuiVtbl
: TuiVtbl
);
127 if (!UiVtbl
.Initialize())
129 MachVideoSetDisplayMode(NULL
, FALSE
);
133 if (IniOpenSection("Display", &SectionId
))
135 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, sizeof(SettingText
)))
137 strcpy(UiTitleBoxTitleText
, SettingText
);
139 if (IniReadSettingByName(SectionId
, "TimeText", SettingText
, sizeof(SettingText
)))
141 strcpy(UiTimeText
, SettingText
);
143 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, sizeof(SettingText
)))
145 UiStatusBarBgColor
= UiTextToColor(SettingText
);
147 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, sizeof(SettingText
)))
149 UiStatusBarFgColor
= UiTextToColor(SettingText
);
151 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, sizeof(SettingText
)))
153 UiBackdropFgColor
= UiTextToColor(SettingText
);
155 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, sizeof(SettingText
)))
157 UiBackdropBgColor
= UiTextToColor(SettingText
);
159 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, sizeof(SettingText
)))
161 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
163 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, sizeof(SettingText
)))
165 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
167 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, sizeof(SettingText
)))
169 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
171 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, sizeof(SettingText
)))
173 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
175 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, sizeof(SettingText
)))
177 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
179 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, sizeof(SettingText
)))
181 UiMenuFgColor
= UiTextToColor(SettingText
);
183 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, sizeof(SettingText
)))
185 UiMenuBgColor
= UiTextToColor(SettingText
);
187 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, sizeof(SettingText
)))
189 UiTextColor
= UiTextToColor(SettingText
);
191 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, sizeof(SettingText
)))
193 UiSelectedTextColor
= UiTextToColor(SettingText
);
195 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, sizeof(SettingText
)))
197 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
199 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, sizeof(SettingText
)))
201 UiEditBoxTextColor
= UiTextToColor(SettingText
);
203 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, sizeof(SettingText
)))
205 UiEditBoxBgColor
= UiTextToColor(SettingText
);
207 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, sizeof(SettingText
)))
209 UiUseSpecialEffects
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
211 if (IniReadSettingByName(SectionId
, "ShowTime", SettingText
, sizeof(SettingText
)))
213 UiDrawTime
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
215 if (IniReadSettingByName(SectionId
, "MenuBox", SettingText
, sizeof(SettingText
)))
217 UiMenuBox
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
219 if (IniReadSettingByName(SectionId
, "CenterMenu", SettingText
, sizeof(SettingText
)))
221 UiCenterMenu
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
225 // Draw the backdrop and fade it in if special effects are enabled
228 TRACE("UiInitialize() returning TRUE.\n");
232 VOID
UiUnInitialize(PCSTR BootText
)
235 UiDrawStatusText(BootText
);
238 UiVtbl
.UnInitialize();
241 VOID
UiDrawBackdrop(VOID
)
243 UiVtbl
.DrawBackdrop();
246 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
248 UiVtbl
.FillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
251 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
253 UiVtbl
.DrawShadow(Left
, Top
, Right
, Bottom
);
256 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
258 UiVtbl
.DrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
261 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
263 UiVtbl
.DrawText(X
, Y
, Text
, Attr
);
266 VOID
UiDrawText2(ULONG X
, ULONG Y
, ULONG MaxNumChars
, PCSTR Text
, UCHAR Attr
)
268 UiVtbl
.DrawText2(X
, Y
, MaxNumChars
, Text
, Attr
);
271 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
273 UiVtbl
.DrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
276 VOID
UiDrawStatusText(PCSTR StatusText
)
278 UiVtbl
.DrawStatusText(StatusText
);
281 VOID
UiUpdateDateTime(VOID
)
283 UiVtbl
.UpdateDateTime();
286 VOID
UiInfoBox(PCSTR MessageText
)
291 ULONG LineBreakCount
;
299 TextLength
= strlen(MessageText
);
301 // Count the new lines and the box width
305 for (Index
=0; Index
<TextLength
; Index
++)
307 if (MessageText
[Index
] == '\n')
314 if ((Index
- LastIndex
) > BoxWidth
)
316 BoxWidth
= (ULONG
)(Index
- LastIndex
);
321 // Calc the box width & height
323 BoxHeight
= LineBreakCount
+ 4;
325 // Calc the box coordinates
326 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
327 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
328 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
329 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
340 ATTR(UiMenuFgColor
, UiMenuBgColor
)
344 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
347 VOID
UiMessageBox(PCSTR Format
, ...)
352 va_start(ap
, Format
);
353 vsnprintf(Buffer
, sizeof(Buffer
) - sizeof(CHAR
), Format
, ap
);
354 UiVtbl
.MessageBox(Buffer
);
358 VOID
UiMessageBoxCritical(PCSTR MessageText
)
360 UiVtbl
.MessageBoxCritical(MessageText
);
363 UCHAR
UiTextToColor(PCSTR ColorText
)
365 return UiVtbl
.TextToColor(ColorText
);
368 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
370 return UiVtbl
.TextToFillStyle(FillStyleText
);
373 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
375 UiVtbl
.DrawProgressBarCenter(Position
, Range
, ProgressText
);
378 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
380 UiVtbl
.DrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
383 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
386 CHAR SettingName
[80];
387 CHAR SettingValue
[80];
388 PCHAR MessageBoxText
;
389 ULONG MessageBoxTextSize
;
392 if (!IniOpenSection(SectionName
, &SectionId
))
398 // Find all the message box settings and run them
400 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
402 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), SettingValue
, sizeof(SettingValue
));
404 if (_stricmp(SettingName
, "MessageBox") == 0)
406 // Get the real length of the MessageBox text
407 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
409 //if (MessageBoxTextSize > 0)
411 // Allocate enough memory to hold the text
412 MessageBoxText
= FrLdrTempAlloc(MessageBoxTextSize
, TAG_UI_TEXT
);
416 // Get the MessageBox text
417 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), MessageBoxText
, MessageBoxTextSize
);
420 UiEscapeString(MessageBoxText
);
423 UiMessageBox(MessageBoxText
);
426 FrLdrTempFree(MessageBoxText
, TAG_UI_TEXT
);
433 VOID
UiEscapeString(PCHAR String
)
437 for (Idx
=0; Idx
<strlen(String
); Idx
++)
439 // Escape the new line characters
440 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
442 // Escape the character
445 // Move the rest of the string up
446 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
451 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
453 if (strlen(StringText
) > MaxChars
)
455 strcpy(&StringText
[MaxChars
- 3], "...");
459 BOOLEAN
UiDisplayMenu(PCSTR MenuHeader
, PCSTR MenuFooter
, BOOLEAN ShowBootOptions
, PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOLEAN CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
461 return UiVtbl
.DisplayMenu(MenuHeader
, MenuFooter
, ShowBootOptions
, MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
464 VOID
UiFadeInBackdrop(VOID
)
466 UiVtbl
.FadeInBackdrop();
474 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
476 return UiVtbl
.EditBox(MessageText
, EditTextBuffer
, Length
);
480 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)