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.
31 ULONG UiScreenWidth
= 80; // Screen Width
32 ULONG UiScreenHeight
= 25; // Screen Height
34 UCHAR UiStatusBarFgColor
= COLOR_BLACK
; // Status bar foreground color
35 UCHAR UiStatusBarBgColor
= COLOR_CYAN
; // Status bar background color
36 UCHAR UiBackdropFgColor
= COLOR_WHITE
; // Backdrop foreground color
37 UCHAR UiBackdropBgColor
= COLOR_BLUE
; // Backdrop background color
38 UCHAR UiBackdropFillStyle
= MEDIUM_FILL
; // Backdrop fill style
39 UCHAR UiTitleBoxFgColor
= COLOR_WHITE
; // Title box foreground color
40 UCHAR UiTitleBoxBgColor
= COLOR_RED
; // Title box background color
41 UCHAR UiMessageBoxFgColor
= COLOR_WHITE
; // Message box foreground color
42 UCHAR UiMessageBoxBgColor
= COLOR_BLUE
; // Message box background color
43 UCHAR UiMenuFgColor
= COLOR_WHITE
; // Menu foreground color
44 UCHAR UiMenuBgColor
= COLOR_BLUE
; // Menu background color
45 UCHAR UiTextColor
= COLOR_YELLOW
; // Normal text color
46 UCHAR UiSelectedTextColor
= COLOR_BLACK
; // Selected text color
47 UCHAR UiSelectedTextBgColor
= COLOR_GRAY
; // Selected text background color
48 UCHAR UiEditBoxTextColor
= COLOR_WHITE
; // Edit box text color
49 UCHAR UiEditBoxBgColor
= COLOR_BLACK
; // Edit box text background color
51 UCHAR UiTitleBoxTitleText
[260] = "Boot Menu"; // Title box's title text
53 BOOL UserInterfaceUp
= FALSE
; // Tells us if the user interface is displayed
55 VIDEODISPLAYMODE UiDisplayMode
= VideoTextMode
; // Tells us if we are in text or graphics mode
57 BOOL UiUseSpecialEffects
= FALSE
; // Tells us if we should use fade effects
59 UCHAR UiMonthNames
[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
62 BOOL
UiInitialize(BOOLEAN ShowGui
)
65 UCHAR DisplayModeText
[260];
66 UCHAR SettingText
[260];
72 MachVideoSetDisplayMode(NULL
, FALSE
);
75 UserInterfaceUp
= FALSE
;
79 DbgPrint((DPRINT_UI
, "Initializing User Interface.\n"));
81 DbgPrint((DPRINT_UI
, "Reading in UI settings from [Display] section.\n"));
83 DisplayModeText
[0] = '\0';
84 if (IniOpenSection("Display", &SectionId
))
86 if (! IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, 260))
88 DisplayModeText
[0] = '\0';
91 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, 260))
93 strcpy(UiTitleBoxTitleText
, SettingText
);
95 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, 260))
97 UiStatusBarBgColor
= UiTextToColor(SettingText
);
99 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, 260))
101 UiStatusBarFgColor
= UiTextToColor(SettingText
);
103 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, 260))
105 UiBackdropFgColor
= UiTextToColor(SettingText
);
107 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, 260))
109 UiBackdropBgColor
= UiTextToColor(SettingText
);
111 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, 260))
113 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
115 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, 260))
117 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
119 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, 260))
121 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
123 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, 260))
125 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
127 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, 260))
129 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
131 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, 260))
133 UiMenuFgColor
= UiTextToColor(SettingText
);
135 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, 260))
137 UiMenuBgColor
= UiTextToColor(SettingText
);
139 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, 260))
141 UiTextColor
= UiTextToColor(SettingText
);
143 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, 260))
145 UiSelectedTextColor
= UiTextToColor(SettingText
);
147 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, 260))
149 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
151 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, 260))
153 UiEditBoxTextColor
= UiTextToColor(SettingText
);
155 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, 260))
157 UiEditBoxBgColor
= UiTextToColor(SettingText
);
159 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, 260))
161 if (stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3)
163 UiUseSpecialEffects
= TRUE
;
167 UiUseSpecialEffects
= FALSE
;
172 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
173 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
176 if (VideoTextMode
== UiDisplayMode
)
178 if (!TuiInitialize())
180 MachVideoSetDisplayMode(NULL
, FALSE
);
187 //if (!GuiInitialize())
189 // MachSetDisplayMode(NULL, FALSE);
194 // Draw the backdrop and fade it in if special effects are enabled
197 UserInterfaceUp
= TRUE
;
199 DbgPrint((DPRINT_UI
, "UiInitialize() returning TRUE.\n"));
204 VOID
UiUnInitialize(PUCHAR BootText
)
207 UiDrawStatusText("Booting...");
210 if (VideoTextMode
== UiDisplayMode
)
221 VOID
UiDrawBackdrop(VOID
)
223 if (!UserInterfaceUp
) return;
225 if (VideoTextMode
== UiDisplayMode
)
236 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR FillChar
, UCHAR Attr
/* Color Attributes */)
238 if (VideoTextMode
== UiDisplayMode
)
240 TuiFillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
245 //GuiFillArea(Left, Top, Right, Bottom, FillChar, Attr);
249 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
251 if (VideoTextMode
== UiDisplayMode
)
253 TuiDrawShadow(Left
, Top
, Right
, Bottom
);
258 //GuiDrawShadow(Left, Top, Right, Bottom);
262 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOL Fill
, BOOL Shadow
, UCHAR Attr
)
264 if (VideoTextMode
== UiDisplayMode
)
266 TuiDrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
271 //GuiDrawBox(Left, Top, Right, Bottom, VertStyle, HorzStyle, Fill, Shadow, Attr);
275 VOID
UiDrawText(ULONG X
, ULONG Y
, PUCHAR Text
, UCHAR Attr
)
277 if (VideoTextMode
== UiDisplayMode
)
279 TuiDrawText(X
, Y
, Text
, Attr
);
284 //GuiDrawText(X, Y, Text, Attr);
288 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PUCHAR TextString
, UCHAR Attr
)
290 if (VideoTextMode
== UiDisplayMode
)
292 TuiDrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
297 //GuiDrawCenteredText(Left, Top, Right, Bottom, TextString, Attr);
301 VOID
UiDrawStatusText(PUCHAR StatusText
)
303 if (!UserInterfaceUp
) return;
305 if (VideoTextMode
== UiDisplayMode
)
307 TuiDrawStatusText(StatusText
);
312 //GuiDrawStatusText(StatusText);
316 VOID
UiUpdateDateTime(VOID
)
318 if (VideoTextMode
== UiDisplayMode
)
325 //GuiUpdateDateTime();
329 VOID
UiInfoBox(PUCHAR MessageText
)
334 ULONG LineBreakCount
;
342 TextLength
= strlen(MessageText
);
344 // Count the new lines and the box width
348 for (Index
=0; Index
<TextLength
; Index
++)
350 if (MessageText
[Index
] == '\n')
357 if ((Index
- LastIndex
) > BoxWidth
)
359 BoxWidth
= (Index
- LastIndex
);
364 // Calc the box width & height
366 BoxHeight
= LineBreakCount
+ 4;
368 // Calc the box coordinates
369 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
370 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
371 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
372 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
383 ATTR(UiMenuFgColor
, UiMenuBgColor
)
387 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
390 VOID
UiMessageBox(PUCHAR MessageText
)
392 // We have not yet displayed the user interface
393 // We are probably still reading the .ini file
394 // and have encountered an error. Just use printf()
396 if (!UserInterfaceUp
)
398 printf("%s\n", MessageText
);
399 printf("Press any key\n");
404 if (VideoTextMode
== UiDisplayMode
)
406 TuiMessageBox(MessageText
);
411 //GuiMessageBox(MessageText);
415 VOID
UiMessageBoxCritical(PUCHAR MessageText
)
417 // We have not yet displayed the user interface
418 // We are probably still reading the .ini file
419 // and have encountered an error. Just use printf()
421 if (!UserInterfaceUp
)
423 printf("%s\n", MessageText
);
424 printf("Press any key\n");
429 if (VideoTextMode
== UiDisplayMode
)
431 TuiMessageBoxCritical(MessageText
);
436 //GuiMessageBoxCritical(MessageText);
440 UCHAR
UiTextToColor(PUCHAR ColorText
)
442 if (VideoTextMode
== UiDisplayMode
)
444 return TuiTextToColor(ColorText
);
450 //return GuiTextToColor(ColorText);
454 UCHAR
UiTextToFillStyle(PUCHAR FillStyleText
)
456 if (VideoTextMode
== UiDisplayMode
)
458 return TuiTextToFillStyle(FillStyleText
);
464 //return GuiTextToFillStyle(FillStyleText);
468 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PUCHAR ProgressText
)
470 if (!UserInterfaceUp
) return;
472 if (VideoTextMode
== UiDisplayMode
)
474 TuiDrawProgressBarCenter(Position
, Range
, ProgressText
);
479 //GuiDrawProgressBarCenter(Position, Range, ProgressText);
483 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PUCHAR ProgressText
)
485 if (VideoTextMode
== UiDisplayMode
)
487 TuiDrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
492 //GuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
496 VOID
UiShowMessageBoxesInSection(PUCHAR SectionName
)
499 UCHAR SettingName
[80];
500 UCHAR SettingValue
[80];
501 PUCHAR MessageBoxText
;
502 ULONG MessageBoxTextSize
;
505 if (!IniOpenSection(SectionName
, &SectionId
))
507 sprintf(SettingName
, "Section %s not found in freeldr.ini.\n", SectionName
);
508 UiMessageBox(SettingName
);
513 // Find all the message box settings and run them
515 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
517 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, 79, SettingValue
, 79);
519 if (stricmp(SettingName
, "MessageBox") == 0)
521 // Get the real length of the MessageBox text
522 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
524 //if (MessageBoxTextSize > 0)
526 // Allocate enough memory to hold the text
527 MessageBoxText
= (PUCHAR
)MmAllocateMemory(MessageBoxTextSize
);
531 // Get the MessageBox text
532 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, 80, MessageBoxText
, MessageBoxTextSize
);
535 UiEscapeString(MessageBoxText
);
538 UiMessageBox(MessageBoxText
);
541 MmFreeMemory(MessageBoxText
);
548 VOID
UiEscapeString(PUCHAR String
)
552 for (Idx
=0; Idx
<strlen(String
); Idx
++)
554 // Escape the new line characters
555 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
557 // Escape the character
560 // Move the rest of the string up
561 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
566 VOID
UiTruncateStringEllipsis(PUCHAR StringText
, ULONG MaxChars
)
568 if (strlen(StringText
) > MaxChars
)
570 strcpy(&StringText
[MaxChars
- 3], "...");
574 BOOL
UiDisplayMenu(PUCHAR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOL CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
576 if (VideoTextMode
== UiDisplayMode
)
578 return TuiDisplayMenu(MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
584 //return GuiDisplayMenu(MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem, CanEscape, KeyPressFilter);
588 VOID
UiFadeInBackdrop(VOID
)
590 if (VideoTextMode
== UiDisplayMode
)
597 //GuiFadeInBackdrop();
603 if (VideoTextMode
== UiDisplayMode
)
614 BOOL
UiEditBox(PUCHAR MessageText
, PUCHAR EditTextBuffer
, ULONG Length
)
616 if (VideoTextMode
== UiDisplayMode
)
618 return TuiEditBox(MessageText
, EditTextBuffer
, Length
);
624 //return GuiEditBox(MessageText, EditTextBuffer, Length);