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 ULONG UiScreenWidth
; // Screen Width
25 ULONG UiScreenHeight
; // Screen Height
27 UCHAR UiStatusBarFgColor
= COLOR_BLACK
; // Status bar foreground color
28 UCHAR UiStatusBarBgColor
= COLOR_CYAN
; // Status bar background color
29 UCHAR UiBackdropFgColor
= COLOR_WHITE
; // Backdrop foreground color
30 UCHAR UiBackdropBgColor
= COLOR_BLUE
; // Backdrop background color
31 UCHAR UiBackdropFillStyle
= MEDIUM_FILL
; // Backdrop fill style
32 UCHAR UiTitleBoxFgColor
= COLOR_WHITE
; // Title box foreground color
33 UCHAR UiTitleBoxBgColor
= COLOR_RED
; // Title box background color
34 UCHAR UiMessageBoxFgColor
= COLOR_WHITE
; // Message box foreground color
35 UCHAR UiMessageBoxBgColor
= COLOR_BLUE
; // Message box background color
36 UCHAR UiMenuFgColor
= COLOR_WHITE
; // Menu foreground color
37 UCHAR UiMenuBgColor
= COLOR_BLUE
; // Menu background color
38 UCHAR UiTextColor
= COLOR_YELLOW
; // Normal text color
39 UCHAR UiSelectedTextColor
= COLOR_BLACK
; // Selected text color
40 UCHAR UiSelectedTextBgColor
= COLOR_GRAY
; // Selected text background color
41 UCHAR UiEditBoxTextColor
= COLOR_WHITE
; // Edit box text color
42 UCHAR UiEditBoxBgColor
= COLOR_BLACK
; // Edit box text background color
44 CHAR UiTitleBoxTitleText
[260] = "Boot Menu"; // Title box's title text
46 BOOLEAN UiUseSpecialEffects
= FALSE
; // Tells us if we should use fade effects
47 BOOLEAN UiDrawTime
= TRUE
; // Tells us if we should draw the time
48 BOOLEAN UiCenterMenu
= TRUE
; // Tells us if we should use a centered or left-aligned menu
49 BOOLEAN UiMenuBox
= TRUE
; // Tells us if we shuld draw a box around the menu
50 CHAR UiTimeText
[260] = "[Time Remaining: ] ";
52 const CHAR UiMonthNames
[12][15] = { "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
67 NoUiMessageBoxCritical
,
68 NoUiDrawProgressBarCenter
,
79 BOOLEAN
UiInitialize(BOOLEAN ShowGui
)
81 VIDEODISPLAYMODE UiDisplayMode
; // Tells us if we are in text or graphics mode
82 BOOLEAN UiMinimal
= FALSE
; // Tells us if we should use a minimal console-like UI
84 CHAR DisplayModeText
[260];
85 CHAR SettingText
[260];
89 if (!UiVtbl
.Initialize())
91 MachVideoSetDisplayMode(NULL
, FALSE
);
97 DPRINTM(DPRINT_UI
, "Initializing User Interface.\n");
98 DPRINTM(DPRINT_UI
, "Reading in UI settings from [Display] section.\n");
100 DisplayModeText
[0] = '\0';
101 if (IniOpenSection("Display", &SectionId
))
103 if (! IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, sizeof(DisplayModeText
)))
105 DisplayModeText
[0] = '\0';
107 if (IniReadSettingByName(SectionId
, "MinimalUI", SettingText
, sizeof(SettingText
)))
109 UiMinimal
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
113 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
114 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
116 if (VideoTextMode
== UiDisplayMode
)
117 UiVtbl
= UiMinimal
? MiniTuiVtbl
: TuiVtbl
;
121 if (!UiVtbl
.Initialize())
123 MachVideoSetDisplayMode(NULL
, FALSE
);
127 if (IniOpenSection("Display", &SectionId
))
129 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, sizeof(SettingText
)))
131 strcpy(UiTitleBoxTitleText
, SettingText
);
133 if (IniReadSettingByName(SectionId
, "TimeText", SettingText
, sizeof(SettingText
)))
135 strcpy(UiTimeText
, SettingText
);
137 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, sizeof(SettingText
)))
139 UiStatusBarBgColor
= UiTextToColor(SettingText
);
141 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, sizeof(SettingText
)))
143 UiStatusBarFgColor
= UiTextToColor(SettingText
);
145 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, sizeof(SettingText
)))
147 UiBackdropFgColor
= UiTextToColor(SettingText
);
149 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, sizeof(SettingText
)))
151 UiBackdropBgColor
= UiTextToColor(SettingText
);
153 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, sizeof(SettingText
)))
155 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
157 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, sizeof(SettingText
)))
159 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
161 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, sizeof(SettingText
)))
163 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
165 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, sizeof(SettingText
)))
167 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
169 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, sizeof(SettingText
)))
171 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
173 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, sizeof(SettingText
)))
175 UiMenuFgColor
= UiTextToColor(SettingText
);
177 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, sizeof(SettingText
)))
179 UiMenuBgColor
= UiTextToColor(SettingText
);
181 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, sizeof(SettingText
)))
183 UiTextColor
= UiTextToColor(SettingText
);
185 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, sizeof(SettingText
)))
187 UiSelectedTextColor
= UiTextToColor(SettingText
);
189 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, sizeof(SettingText
)))
191 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
193 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, sizeof(SettingText
)))
195 UiEditBoxTextColor
= UiTextToColor(SettingText
);
197 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, sizeof(SettingText
)))
199 UiEditBoxBgColor
= UiTextToColor(SettingText
);
201 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, sizeof(SettingText
)))
203 UiUseSpecialEffects
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
205 if (IniReadSettingByName(SectionId
, "ShowTime", SettingText
, sizeof(SettingText
)))
207 UiDrawTime
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
209 if (IniReadSettingByName(SectionId
, "MenuBox", SettingText
, sizeof(SettingText
)))
211 UiMenuBox
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
213 if (IniReadSettingByName(SectionId
, "CenterMenu", SettingText
, sizeof(SettingText
)))
215 UiCenterMenu
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
219 // Draw the backdrop and fade it in if special effects are enabled
222 DPRINTM(DPRINT_UI
, "UiInitialize() returning TRUE.\n");
226 BOOLEAN
SetupUiInitialize(VOID
)
228 VIDEODISPLAYMODE UiDisplayMode
;
229 CHAR DisplayModeText
[260];
233 DisplayModeText
[0] = '\0';
235 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
236 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
241 // Draw the backdrop and fade it in if special effects are enabled
247 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
250 UiStatusBarBgColor
= 7;
252 Length
= strlen("ReactOS " KERNEL_VERSION_STR
" Setup");
253 memset(DisplayModeText
, 0xcd, Length
+ 2);
254 DisplayModeText
[Length
+ 2] = '\0';
256 UiVtbl
.DrawText(4, 1, "ReactOS " KERNEL_VERSION_STR
" Setup", ATTR(COLOR_GRAY
, UiBackdropBgColor
));
257 UiVtbl
.DrawText(3, 2, DisplayModeText
, ATTR(COLOR_GRAY
, UiBackdropBgColor
));
259 DPRINTM(DPRINT_UI
, "UiInitialize() returning TRUE.\n");
264 VOID
UiUnInitialize(PCSTR BootText
)
267 UiDrawStatusText("Booting...");
270 UiVtbl
.UnInitialize();
273 VOID
UiDrawBackdrop(VOID
)
275 UiVtbl
.DrawBackdrop();
278 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
280 UiVtbl
.FillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
283 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
285 UiVtbl
.DrawShadow(Left
, Top
, Right
, Bottom
);
288 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
290 UiVtbl
.DrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
293 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
295 UiVtbl
.DrawText(X
, Y
, Text
, Attr
);
298 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
300 UiVtbl
.DrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
303 VOID
UiDrawStatusText(PCSTR StatusText
)
305 UiVtbl
.DrawStatusText(StatusText
);
308 VOID
UiUpdateDateTime(VOID
)
310 UiVtbl
.UpdateDateTime();
313 VOID
UiInfoBox(PCSTR MessageText
)
318 ULONG LineBreakCount
;
326 TextLength
= strlen(MessageText
);
328 // Count the new lines and the box width
332 for (Index
=0; Index
<TextLength
; Index
++)
334 if (MessageText
[Index
] == '\n')
341 if ((Index
- LastIndex
) > BoxWidth
)
343 BoxWidth
= (Index
- LastIndex
);
348 // Calc the box width & height
350 BoxHeight
= LineBreakCount
+ 4;
352 // Calc the box coordinates
353 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
354 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
355 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
356 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
367 ATTR(UiMenuFgColor
, UiMenuBgColor
)
371 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
374 VOID
UiMessageBox(PCSTR MessageText
)
376 UiVtbl
.MessageBox(MessageText
);
379 VOID
UiMessageBoxCritical(PCSTR MessageText
)
381 UiVtbl
.MessageBoxCritical(MessageText
);
384 UCHAR
UiTextToColor(PCSTR ColorText
)
386 return UiVtbl
.TextToColor(ColorText
);
389 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
391 return UiVtbl
.TextToFillStyle(FillStyleText
);
394 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
396 UiVtbl
.DrawProgressBarCenter(Position
, Range
, ProgressText
);
399 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
401 UiVtbl
.DrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
404 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
407 CHAR SettingName
[80];
408 CHAR SettingValue
[80];
409 PCHAR MessageBoxText
;
410 ULONG MessageBoxTextSize
;
413 if (!IniOpenSection(SectionName
, &SectionId
))
419 // Find all the message box settings and run them
421 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
423 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), SettingValue
, sizeof(SettingValue
));
425 if (_stricmp(SettingName
, "MessageBox") == 0)
427 // Get the real length of the MessageBox text
428 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
430 //if (MessageBoxTextSize > 0)
432 // Allocate enough memory to hold the text
433 MessageBoxText
= MmHeapAlloc(MessageBoxTextSize
);
437 // Get the MessageBox text
438 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), MessageBoxText
, MessageBoxTextSize
);
441 UiEscapeString(MessageBoxText
);
444 UiMessageBox(MessageBoxText
);
447 MmHeapFree(MessageBoxText
);
454 VOID
UiEscapeString(PCHAR String
)
458 for (Idx
=0; Idx
<strlen(String
); Idx
++)
460 // Escape the new line characters
461 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
463 // Escape the character
466 // Move the rest of the string up
467 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
472 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
474 if (strlen(StringText
) > MaxChars
)
476 strcpy(&StringText
[MaxChars
- 3], "...");
480 BOOLEAN
UiDisplayMenu(PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOLEAN CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
482 return UiVtbl
.DisplayMenu(MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
485 VOID
UiFadeInBackdrop(VOID
)
487 UiVtbl
.FadeInBackdrop();
495 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
497 return UiVtbl
.EditBox(MessageText
, EditTextBuffer
, Length
);