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.
22 #include <reactos/buildno.h>
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];
235 DisplayModeText
[0] = '\0';
237 MachVideoSetDisplayMode(DisplayModeText
, TRUE
);
238 MachVideoGetDisplaySize(&UiScreenWidth
, &UiScreenHeight
, &Depth
);
243 // Draw the backdrop and fade it in if special effects are enabled
249 ATTR(UiBackdropFgColor
, UiBackdropBgColor
));
252 UiStatusBarBgColor
= 7;
254 Length
= strlen("ReactOS " KERNEL_VERSION_STR
" Setup");
255 memset(DisplayModeText
, 0xcd, Length
+ 2);
256 DisplayModeText
[Length
+ 2] = '\0';
258 UiVtbl
.DrawText(4, 1, "ReactOS " KERNEL_VERSION_STR
" Setup", ATTR(COLOR_GRAY
, UiBackdropBgColor
));
259 UiVtbl
.DrawText(3, 2, DisplayModeText
, ATTR(COLOR_GRAY
, UiBackdropBgColor
));
261 TRACE("UiInitialize() returning TRUE.\n");
266 VOID
UiUnInitialize(PCSTR BootText
)
269 UiDrawStatusText("Booting...");
272 UiVtbl
.UnInitialize();
275 VOID
UiDrawBackdrop(VOID
)
277 UiVtbl
.DrawBackdrop();
280 VOID
UiFillArea(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, CHAR FillChar
, UCHAR Attr
/* Color Attributes */)
282 UiVtbl
.FillArea(Left
, Top
, Right
, Bottom
, FillChar
, Attr
);
285 VOID
UiDrawShadow(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
)
287 UiVtbl
.DrawShadow(Left
, Top
, Right
, Bottom
);
290 VOID
UiDrawBox(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, UCHAR VertStyle
, UCHAR HorzStyle
, BOOLEAN Fill
, BOOLEAN Shadow
, UCHAR Attr
)
292 UiVtbl
.DrawBox(Left
, Top
, Right
, Bottom
, VertStyle
, HorzStyle
, Fill
, Shadow
, Attr
);
295 VOID
UiDrawText(ULONG X
, ULONG Y
, PCSTR Text
, UCHAR Attr
)
297 UiVtbl
.DrawText(X
, Y
, Text
, Attr
);
300 VOID
UiDrawCenteredText(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, PCSTR TextString
, UCHAR Attr
)
302 UiVtbl
.DrawCenteredText(Left
, Top
, Right
, Bottom
, TextString
, Attr
);
305 VOID
UiDrawStatusText(PCSTR StatusText
)
307 UiVtbl
.DrawStatusText(StatusText
);
310 VOID
UiUpdateDateTime(VOID
)
312 UiVtbl
.UpdateDateTime();
315 VOID
UiInfoBox(PCSTR MessageText
)
320 ULONG LineBreakCount
;
328 TextLength
= strlen(MessageText
);
330 // Count the new lines and the box width
334 for (Index
=0; Index
<TextLength
; Index
++)
336 if (MessageText
[Index
] == '\n')
343 if ((Index
- LastIndex
) > BoxWidth
)
345 BoxWidth
= (ULONG
)(Index
- LastIndex
);
350 // Calc the box width & height
352 BoxHeight
= LineBreakCount
+ 4;
354 // Calc the box coordinates
355 Left
= (UiScreenWidth
/ 2) - (BoxWidth
/ 2);
356 Top
=(UiScreenHeight
/ 2) - (BoxHeight
/ 2);
357 Right
= (UiScreenWidth
/ 2) + (BoxWidth
/ 2);
358 Bottom
= (UiScreenHeight
/ 2) + (BoxHeight
/ 2);
369 ATTR(UiMenuFgColor
, UiMenuBgColor
)
373 UiDrawCenteredText(Left
, Top
, Right
, Bottom
, MessageText
, ATTR(UiTextColor
, UiMenuBgColor
));
376 VOID
UiMessageBox(PCSTR MessageText
)
378 UiVtbl
.MessageBox(MessageText
);
381 VOID
UiMessageBoxCritical(PCSTR MessageText
)
383 UiVtbl
.MessageBoxCritical(MessageText
);
386 UCHAR
UiTextToColor(PCSTR ColorText
)
388 return UiVtbl
.TextToColor(ColorText
);
391 UCHAR
UiTextToFillStyle(PCSTR FillStyleText
)
393 return UiVtbl
.TextToFillStyle(FillStyleText
);
396 VOID
UiDrawProgressBarCenter(ULONG Position
, ULONG Range
, PCHAR ProgressText
)
398 UiVtbl
.DrawProgressBarCenter(Position
, Range
, ProgressText
);
401 VOID
UiDrawProgressBar(ULONG Left
, ULONG Top
, ULONG Right
, ULONG Bottom
, ULONG Position
, ULONG Range
, PCHAR ProgressText
)
403 UiVtbl
.DrawProgressBar(Left
, Top
, Right
, Bottom
, Position
, Range
, ProgressText
);
406 VOID
UiShowMessageBoxesInSection(PCSTR SectionName
)
409 CHAR SettingName
[80];
410 CHAR SettingValue
[80];
411 PCHAR MessageBoxText
;
412 ULONG MessageBoxTextSize
;
415 if (!IniOpenSection(SectionName
, &SectionId
))
421 // Find all the message box settings and run them
423 for (Idx
=0; Idx
<IniGetNumSectionItems(SectionId
); Idx
++)
425 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), SettingValue
, sizeof(SettingValue
));
427 if (_stricmp(SettingName
, "MessageBox") == 0)
429 // Get the real length of the MessageBox text
430 MessageBoxTextSize
= IniGetSectionSettingValueSize(SectionId
, Idx
);
432 //if (MessageBoxTextSize > 0)
434 // Allocate enough memory to hold the text
435 MessageBoxText
= MmHeapAlloc(MessageBoxTextSize
);
439 // Get the MessageBox text
440 IniReadSettingByNumber(SectionId
, Idx
, SettingName
, sizeof(SettingName
), MessageBoxText
, MessageBoxTextSize
);
443 UiEscapeString(MessageBoxText
);
446 UiMessageBox(MessageBoxText
);
449 MmHeapFree(MessageBoxText
);
456 VOID
UiEscapeString(PCHAR String
)
460 for (Idx
=0; Idx
<strlen(String
); Idx
++)
462 // Escape the new line characters
463 if (String
[Idx
] == '\\' && String
[Idx
+1] == 'n')
465 // Escape the character
468 // Move the rest of the string up
469 strcpy(&String
[Idx
+1], &String
[Idx
+2]);
474 VOID
UiTruncateStringEllipsis(PCHAR StringText
, ULONG MaxChars
)
476 if (strlen(StringText
) > MaxChars
)
478 strcpy(&StringText
[MaxChars
- 3], "...");
482 BOOLEAN
UiDisplayMenu(PCSTR MenuItemList
[], ULONG MenuItemCount
, ULONG DefaultMenuItem
, LONG MenuTimeOut
, ULONG
* SelectedMenuItem
, BOOLEAN CanEscape
, UiMenuKeyPressFilterCallback KeyPressFilter
)
484 return UiVtbl
.DisplayMenu(MenuItemList
, MenuItemCount
, DefaultMenuItem
, MenuTimeOut
, SelectedMenuItem
, CanEscape
, KeyPressFilter
);
487 VOID
UiFadeInBackdrop(VOID
)
489 UiVtbl
.FadeInBackdrop();
497 BOOLEAN
UiEditBox(PCSTR MessageText
, PCHAR EditTextBuffer
, ULONG Length
)
499 return UiVtbl
.EditBox(MessageText
, EditTextBuffer
, Length
);