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 should use a minimal console-like UI
86 CHAR DisplayModeText
[260];
87 CHAR SettingText
[260];
91 if (!UiVtbl
.Initialize())
93 MachVideoSetDisplayMode(NULL
, FALSE
);
99 TRACE("Initializing User Interface.\n");
100 TRACE("Reading in UI settings from [Display] section.\n");
102 DisplayModeText
[0] = '\0';
103 if (IniOpenSection("Display", &SectionId
))
105 if (! IniReadSettingByName(SectionId
, "DisplayMode", DisplayModeText
, sizeof(DisplayModeText
)))
107 DisplayModeText
[0] = '\0';
109 if (IniReadSettingByName(SectionId
, "MinimalUI", SettingText
, sizeof(SettingText
)))
111 UiMinimal
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
115 UiDisplayMode
= MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
116 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
118 if (VideoTextMode
== UiDisplayMode
)
119 UiVtbl
= UiMinimal
? MiniTuiVtbl
: TuiVtbl
;
123 if (!UiVtbl
.Initialize())
125 MachVideoSetDisplayMode(NULL
, FALSE
);
129 if (IniOpenSection("Display", &SectionId
))
131 if (IniReadSettingByName(SectionId
, "TitleText", SettingText
, sizeof(SettingText
)))
133 strcpy(UiTitleBoxTitleText
, SettingText
);
135 if (IniReadSettingByName(SectionId
, "TimeText", SettingText
, sizeof(SettingText
)))
137 strcpy(UiTimeText
, SettingText
);
139 if (IniReadSettingByName(SectionId
, "StatusBarColor", SettingText
, sizeof(SettingText
)))
141 UiStatusBarBgColor
= UiTextToColor(SettingText
);
143 if (IniReadSettingByName(SectionId
, "StatusBarTextColor", SettingText
, sizeof(SettingText
)))
145 UiStatusBarFgColor
= UiTextToColor(SettingText
);
147 if (IniReadSettingByName(SectionId
, "BackdropTextColor", SettingText
, sizeof(SettingText
)))
149 UiBackdropFgColor
= UiTextToColor(SettingText
);
151 if (IniReadSettingByName(SectionId
, "BackdropColor", SettingText
, sizeof(SettingText
)))
153 UiBackdropBgColor
= UiTextToColor(SettingText
);
155 if (IniReadSettingByName(SectionId
, "BackdropFillStyle", SettingText
, sizeof(SettingText
)))
157 UiBackdropFillStyle
= UiTextToFillStyle(SettingText
);
159 if (IniReadSettingByName(SectionId
, "TitleBoxTextColor", SettingText
, sizeof(SettingText
)))
161 UiTitleBoxFgColor
= UiTextToColor(SettingText
);
163 if (IniReadSettingByName(SectionId
, "TitleBoxColor", SettingText
, sizeof(SettingText
)))
165 UiTitleBoxBgColor
= UiTextToColor(SettingText
);
167 if (IniReadSettingByName(SectionId
, "MessageBoxTextColor", SettingText
, sizeof(SettingText
)))
169 UiMessageBoxFgColor
= UiTextToColor(SettingText
);
171 if (IniReadSettingByName(SectionId
, "MessageBoxColor", SettingText
, sizeof(SettingText
)))
173 UiMessageBoxBgColor
= UiTextToColor(SettingText
);
175 if (IniReadSettingByName(SectionId
, "MenuTextColor", SettingText
, sizeof(SettingText
)))
177 UiMenuFgColor
= UiTextToColor(SettingText
);
179 if (IniReadSettingByName(SectionId
, "MenuColor", SettingText
, sizeof(SettingText
)))
181 UiMenuBgColor
= UiTextToColor(SettingText
);
183 if (IniReadSettingByName(SectionId
, "TextColor", SettingText
, sizeof(SettingText
)))
185 UiTextColor
= UiTextToColor(SettingText
);
187 if (IniReadSettingByName(SectionId
, "SelectedTextColor", SettingText
, sizeof(SettingText
)))
189 UiSelectedTextColor
= UiTextToColor(SettingText
);
191 if (IniReadSettingByName(SectionId
, "SelectedColor", SettingText
, sizeof(SettingText
)))
193 UiSelectedTextBgColor
= UiTextToColor(SettingText
);
195 if (IniReadSettingByName(SectionId
, "EditBoxTextColor", SettingText
, sizeof(SettingText
)))
197 UiEditBoxTextColor
= UiTextToColor(SettingText
);
199 if (IniReadSettingByName(SectionId
, "EditBoxColor", SettingText
, sizeof(SettingText
)))
201 UiEditBoxBgColor
= UiTextToColor(SettingText
);
203 if (IniReadSettingByName(SectionId
, "SpecialEffects", SettingText
, sizeof(SettingText
)))
205 UiUseSpecialEffects
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
207 if (IniReadSettingByName(SectionId
, "ShowTime", SettingText
, sizeof(SettingText
)))
209 UiDrawTime
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
211 if (IniReadSettingByName(SectionId
, "MenuBox", SettingText
, sizeof(SettingText
)))
213 UiMenuBox
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
215 if (IniReadSettingByName(SectionId
, "CenterMenu", SettingText
, sizeof(SettingText
)))
217 UiCenterMenu
= (_stricmp(SettingText
, "Yes") == 0 && strlen(SettingText
) == 3);
221 // Draw the backdrop and fade it in if special effects are enabled
224 TRACE("UiInitialize() returning TRUE.\n");
228 BOOLEAN
SetupUiInitialize(VOID
)
230 CHAR DisplayModeText
[260];
234 DisplayModeText
[0] = '\0';
236 MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
237 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
242 // Draw the backdrop and fade it in if special effects are enabled
248 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
251 UiStatusBarBgColor
= 7;
253 Length
= strlen("ReactOS " KERNEL_VERSION_STR
" Setup");
254 memset(DisplayModeText
, 0xcd, Length
+ 2);
255 DisplayModeText
[Length
+ 2] = '\0';
257 UiVtbl
.DrawText(4, 1, "ReactOS " KERNEL_VERSION_STR
" Setup", ATTR(COLOR_GRAY
, UiBackdropBgColor
));
258 UiVtbl
.DrawText(3, 2, DisplayModeText
, ATTR(COLOR_GRAY
, UiBackdropBgColor
));
260 TRACE("UiInitialize() returning TRUE.\n");
265 VOID
UiUnInitialize(PCSTR BootText
)
268 UiDrawStatusText("Booting...");
271 UiVtbl
.UnInitialize();
274 VOID
UiDrawBackdrop(VOID
)
276 UiVtbl
.DrawBackdrop();
279 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
281 UiVtbl
.FillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
284 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
286 UiVtbl
.DrawShadow(Left
, Top
, Right
, Bottom
);
289 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
291 UiVtbl
.DrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
294 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
296 UiVtbl
.DrawText(X
, Y
, Text
, Attr
);
299 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
301 UiVtbl
.DrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
304 VOID
UiDrawStatusText(PCSTR StatusText
)
306 UiVtbl
.DrawStatusText(StatusText
);
309 VOID
UiUpdateDateTime(VOID
)
311 UiVtbl
.UpdateDateTime();
314 VOID
UiInfoBox(PCSTR MessageText
)
319 ULONG LineBreakCount
;
327 TextLength
= strlen(MessageText
);
329 // Count the new lines and the box width
333 for (Index
=0; Index
<TextLength
; Index
++)
335 if (MessageText
[Index
] == '\n')
342 if ((Index
- LastIndex
) > BoxWidth
)
344 BoxWidth
= (Index
- LastIndex
);
349 // Calc the box width & height
351 BoxHeight
= LineBreakCount
+ 4;
353 // Calc the box coordinates
354 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
355 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
356 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
357 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
368 ATTR(UiMenuFgColor
, UiMenuBgColor
)
372 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
375 VOID
UiMessageBox(PCSTR MessageText
)
377 UiVtbl
.MessageBox(MessageText
);
380 VOID
UiMessageBoxCritical(PCSTR MessageText
)
382 UiVtbl
.MessageBoxCritical(MessageText
);
385 UCHAR
UiTextToColor(PCSTR ColorText
)
387 return UiVtbl
.TextToColor(ColorText
);
390 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
392 return UiVtbl
.TextToFillStyle(FillStyleText
);
395 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
397 UiVtbl
.DrawProgressBarCenter(Position
, Range
, ProgressText
);
400 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
402 UiVtbl
.DrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
405 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
408 CHAR SettingName
[80];
409 CHAR SettingValue
[80];
410 PCHAR MessageBoxText
;
411 ULONG MessageBoxTextSize
;
414 if (!IniOpenSection(SectionName
, &SectionId
))
420 // Find all the message box settings and run them
422 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
424 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), SettingValue
, sizeof(SettingValue
));
426 if (_stricmp(SettingName
, "MessageBox") == 0)
428 // Get the real length of the MessageBox text
429 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
431 //if (MessageBoxTextSize > 0)
433 // Allocate enough memory to hold the text
434 MessageBoxText
= MmHeapAlloc(MessageBoxTextSize
);
438 // Get the MessageBox text
439 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), MessageBoxText
, MessageBoxTextSize
);
442 UiEscapeString(MessageBoxText
);
445 UiMessageBox(MessageBoxText
);
448 MmHeapFree(MessageBoxText
);
455 VOID
UiEscapeString(PCHAR String
)
459 for (Idx
=0; Idx
<strlen(String
); Idx
++)
461 // Escape the new line characters
462 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
464 // Escape the character
467 // Move the rest of the string up
468 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
473 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
475 if (strlen(StringText
) > MaxChars
)
477 strcpy(&StringText
[MaxChars
- 3], "...");
481 BOOLEAN
UiDisplayMenu(PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOLEAN CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
483 return UiVtbl
.DisplayMenu(MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
486 VOID
UiFadeInBackdrop(VOID
)
488 UiVtbl
.FadeInBackdrop();
496 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
498 return UiVtbl
.EditBox(MessageText
, EditTextBuffer
, Length
);