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 ULONG UiScreenWidth
; // Screen Width
27 ULONG UiScreenHeight
; // 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 BOOLEAN UiUseSpecialEffects
= FALSE
; // Tells us if we should use fade effects
49 BOOLEAN UiDrawTime
= TRUE
; // Tells us if we should draw the time
50 BOOLEAN UiCenterMenu
= TRUE
; // Tells us if we should use a centered or left-aligned menu
51 BOOLEAN UiMenuBox
= TRUE
; // Tells us if we shuld draw a box around the menu
52 CHAR UiTimeText
[260] = "[Time Remaining: ] ";
54 const CHAR UiMonthNames
[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
69 NoUiMessageBoxCritical
,
70 NoUiDrawProgressBarCenter
,
81 BOOLEAN
UiInitialize(BOOLEAN ShowGui
)
83 VIDEODISPLAYMODE UiDisplayMode
; // Tells us if we are in text or graphics mode
84 BOOLEAN UiMinimal
= FALSE
; // Tells us if we are using a minimal console-like UI
86 CHAR DisplayModeText
[260];
87 CHAR SettingText
[260];
92 if (!UiVtbl
.Initialize())
94 MachVideoSetDisplayMode(NULL
, FALSE
);
100 TRACE("Initializing User Interface.\n");
101 TRACE("Reading in UI settings from [Display] section.\n");
103 DisplayModeText
[0] = '\0';
104 if (IniOpenSection("Display", &SectionId
))
106 if (!IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, sizeof(DisplayModeText
)))
108 DisplayModeText
[0] = '\0';
110 if (IniReadSettingByName(SectionId
, "MinimalUI", SettingText
, sizeof(SettingText
)))
112 UiMinimal
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
116 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
117 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
119 if (VideoTextMode
== UiDisplayMode
)
120 UiVtbl
= (UiMinimal
? MiniTuiVtbl
: TuiVtbl
);
124 if (!UiVtbl
.Initialize())
126 MachVideoSetDisplayMode(NULL
, FALSE
);
130 if (IniOpenSection("Display", &SectionId
))
132 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, sizeof(SettingText
)))
134 strcpy(UiTitleBoxTitleText
, SettingText
);
136 if (IniReadSettingByName(SectionId
, "TimeText", SettingText
, sizeof(SettingText
)))
138 strcpy(UiTimeText
, SettingText
);
140 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, sizeof(SettingText
)))
142 UiStatusBarBgColor
= UiTextToColor(SettingText
);
144 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, sizeof(SettingText
)))
146 UiStatusBarFgColor
= UiTextToColor(SettingText
);
148 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, sizeof(SettingText
)))
150 UiBackdropFgColor
= UiTextToColor(SettingText
);
152 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, sizeof(SettingText
)))
154 UiBackdropBgColor
= UiTextToColor(SettingText
);
156 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, sizeof(SettingText
)))
158 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
160 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, sizeof(SettingText
)))
162 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
164 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, sizeof(SettingText
)))
166 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
168 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, sizeof(SettingText
)))
170 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
172 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, sizeof(SettingText
)))
174 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
176 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, sizeof(SettingText
)))
178 UiMenuFgColor
= UiTextToColor(SettingText
);
180 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, sizeof(SettingText
)))
182 UiMenuBgColor
= UiTextToColor(SettingText
);
184 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, sizeof(SettingText
)))
186 UiTextColor
= UiTextToColor(SettingText
);
188 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, sizeof(SettingText
)))
190 UiSelectedTextColor
= UiTextToColor(SettingText
);
192 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, sizeof(SettingText
)))
194 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
196 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, sizeof(SettingText
)))
198 UiEditBoxTextColor
= UiTextToColor(SettingText
);
200 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, sizeof(SettingText
)))
202 UiEditBoxBgColor
= UiTextToColor(SettingText
);
204 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, sizeof(SettingText
)))
206 UiUseSpecialEffects
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
208 if (IniReadSettingByName(SectionId
, "ShowTime", SettingText
, sizeof(SettingText
)))
210 UiDrawTime
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
212 if (IniReadSettingByName(SectionId
, "MenuBox", SettingText
, sizeof(SettingText
)))
214 UiMenuBox
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
216 if (IniReadSettingByName(SectionId
, "CenterMenu", SettingText
, sizeof(SettingText
)))
218 UiCenterMenu
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
222 // Draw the backdrop and fade it in if special effects are enabled
225 TRACE("UiInitialize() returning TRUE.\n");
229 VOID
UiUnInitialize(PCSTR BootText
)
232 UiDrawStatusText("Booting...");
235 UiVtbl
.UnInitialize();
238 VOID
UiDrawBackdrop(VOID
)
240 UiVtbl
.DrawBackdrop();
243 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
245 UiVtbl
.FillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
248 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
250 UiVtbl
.DrawShadow(Left
, Top
, Right
, Bottom
);
253 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
255 UiVtbl
.DrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
258 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
260 UiVtbl
.DrawText(X
, Y
, Text
, Attr
);
263 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
265 UiVtbl
.DrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
268 VOID
UiDrawStatusText(PCSTR StatusText
)
270 UiVtbl
.DrawStatusText(StatusText
);
273 VOID
UiUpdateDateTime(VOID
)
275 UiVtbl
.UpdateDateTime();
278 VOID
UiInfoBox(PCSTR MessageText
)
283 ULONG LineBreakCount
;
291 TextLength
= strlen(MessageText
);
293 // Count the new lines and the box width
297 for (Index
=0; Index
<TextLength
; Index
++)
299 if (MessageText
[Index
] == '\n')
306 if ((Index
- LastIndex
) > BoxWidth
)
308 BoxWidth
= (ULONG
)(Index
- LastIndex
);
313 // Calc the box width & height
315 BoxHeight
= LineBreakCount
+ 4;
317 // Calc the box coordinates
318 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
319 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
320 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
321 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
332 ATTR(UiMenuFgColor
, UiMenuBgColor
)
336 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
339 VOID
UiMessageBox(PCSTR MessageText
)
341 UiVtbl
.MessageBox(MessageText
);
344 VOID
UiMessageBoxCritical(PCSTR MessageText
)
346 UiVtbl
.MessageBoxCritical(MessageText
);
349 UCHAR
UiTextToColor(PCSTR ColorText
)
351 return UiVtbl
.TextToColor(ColorText
);
354 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
356 return UiVtbl
.TextToFillStyle(FillStyleText
);
359 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
361 UiVtbl
.DrawProgressBarCenter(Position
, Range
, ProgressText
);
364 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
366 UiVtbl
.DrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
369 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
372 CHAR SettingName
[80];
373 CHAR SettingValue
[80];
374 PCHAR MessageBoxText
;
375 ULONG MessageBoxTextSize
;
378 if (!IniOpenSection(SectionName
, &SectionId
))
384 // Find all the message box settings and run them
386 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
388 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), SettingValue
, sizeof(SettingValue
));
390 if (_stricmp(SettingName
, "MessageBox") == 0)
392 // Get the real length of the MessageBox text
393 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
395 //if (MessageBoxTextSize > 0)
397 // Allocate enough memory to hold the text
398 MessageBoxText
= MmHeapAlloc(MessageBoxTextSize
);
402 // Get the MessageBox text
403 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), MessageBoxText
, MessageBoxTextSize
);
406 UiEscapeString(MessageBoxText
);
409 UiMessageBox(MessageBoxText
);
412 MmHeapFree(MessageBoxText
);
419 VOID
UiEscapeString(PCHAR String
)
423 for (Idx
=0; Idx
<strlen(String
); Idx
++)
425 // Escape the new line characters
426 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
428 // Escape the character
431 // Move the rest of the string up
432 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
437 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
439 if (strlen(StringText
) > MaxChars
)
441 strcpy(&StringText
[MaxChars
- 3], "...");
445 BOOLEAN
UiDisplayMenu(PCSTR MenuTitle
, PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOLEAN CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
447 return UiVtbl
.DisplayMenu(MenuTitle
, MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
450 VOID
UiFadeInBackdrop(VOID
)
452 UiVtbl
.FadeInBackdrop();
460 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
462 return UiVtbl
.EditBox(MessageText
, EditTextBuffer
, Length
);