reactos/boot/freeldr/freeldr/include/ui.h

232 lines
10 KiB
C
Raw Normal View History

/*
* FreeLoader
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
extern ULONG UiScreenWidth; // Screen Width
extern ULONG UiScreenHeight; // Screen Height
extern UCHAR UiStatusBarFgColor; // Status bar foreground color
extern UCHAR UiStatusBarBgColor; // Status bar background color
extern UCHAR UiBackdropFgColor; // Backdrop foreground color
extern UCHAR UiBackdropBgColor; // Backdrop background color
extern UCHAR UiBackdropFillStyle; // Backdrop fill style
extern UCHAR UiTitleBoxFgColor; // Title box foreground color
extern UCHAR UiTitleBoxBgColor; // Title box background color
extern UCHAR UiMessageBoxFgColor; // Message box foreground color
extern UCHAR UiMessageBoxBgColor; // Message box background color
extern UCHAR UiMenuFgColor; // Menu foreground color
extern UCHAR UiMenuBgColor; // Menu background color
extern UCHAR UiTextColor; // Normal text color
extern UCHAR UiSelectedTextColor; // Selected text color
extern UCHAR UiSelectedTextBgColor; // Selected text background color
extern UCHAR UiEditBoxTextColor; // Edit box text color
extern UCHAR UiEditBoxBgColor; // Edit box text background color
extern CHAR UiTitleBoxTitleText[260]; // Title box's title text
extern BOOLEAN UiUseSpecialEffects; // Tells us if we should use fade effects
extern BOOLEAN UiCenterMenu;
extern BOOLEAN UiMenuBox;
extern CHAR UiTimeText[];
extern BOOLEAN UiDrawTime;
extern const CHAR UiMonthNames[12][15];
///////////////////////////////////////////////////////////////////////////////////////
//
// User Interface Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOLEAN UiInitialize(BOOLEAN ShowGui); // Initialize User-Interface
VOID UiUnInitialize(PCSTR BootText); // Un-initialize User-Interface
VOID UiDrawBackdrop(VOID); // Fills the entire screen with a backdrop
VOID UiFillArea(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr /* Color Attributes */); // Fills the area specified with FillChar and Attr
VOID UiDrawShadow(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); // Draws a shadow on the bottom and right sides of the area specified
VOID UiDrawBox(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr); // Draws a box around the area specified
VOID UiDrawText(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified
VOID UiDrawText2(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr); // Draws text at coordinates specified
VOID UiDrawCenteredText(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr); // Draws centered text at the coordinates specified and clips the edges
VOID UiDrawStatusText(PCSTR StatusText); // Draws text at the very bottom line on the screen
VOID UiUpdateDateTime(VOID); // Updates the date and time
VOID UiInfoBox(PCSTR MessageText); // Displays a info box on the screen
VOID UiMessageBox(PCSTR Format, ...); // Displays a message box on the screen with an ok button
VOID UiMessageBoxCritical(PCSTR MessageText); // Displays a message box on the screen with an ok button using no system resources
VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled
VOID UiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText); // Draws the progress bar showing nPos percent filled
[FREELDR] Some ARC-spec compatibility refactoring + simplifications & fixes. CORE-9023 - During loading and initialization of the list of operating systems available in freeldr.ini, convert any legacy operating system entry encountered -- they are like those in NTLDR's boot.ini file, i.e.: ArcOsLoadPartition="LoadIdentifier" /List /of /Options into a new operating system INI entry, like those used by default in FreeLoader. This allows us to avoid treating this corner-case later in different parts of the code. Also, the "BootType" value is now determined there, only once. - Convert the OS loaders entry-points to ARC-compatible ones, following the "Advanced RISC Computing Specification, Version 1.2" specification https://www.netbsd.org/docs/Hardware/Machines/ARC/riscspec.pdf - Introduce helpers for retrieving options values from the argument vector in a simple way. - Simplify LoadOperatingSystem(), since now the "BootType" value has been determined once while loading the list of OSes (see above) and is well-defined there. Use the BuildArgvForOsLoader() helper to build the ARC-compatible argument vector from the corresponding INI settings for the selected operating system entry, and use it when calling the corresponding OS loader. - In the OS loaders, since we can now directly read the settings from the argument vector (instead of using INI settings), we can avoid using a bunch of fixed-size string buffers, and avoid potentially failing IniOpenSection() calls as well. - Simplify code in the Linux loader (and the RemoveQuotes() function). - Add UiShowMessageBoxesInArgv() that acts on the "MessageBox=" settings passed through the argument vector (equivalent to UiShowMessageBoxesInSection() ). - Use string-safe functions where needed (copy/concatenation/printf on fixed-size buffers).
2019-08-06 20:30:54 +00:00
[FREELDR] Code fixes and enhancements. CORE-9023 FIXES: ====== - Fix parsing of the multiboot options string. NOTE: They are not yet treated in a case-insensitive manner! - Fix a bug in ArcOpen() so that it correctly skips the first path separator (after the adapter-controller-peripheral ARC descriptors). The path separator can be either a backslash or a slash (both are allowed according to the specs); they were also already handled correctly in other parts of the code. - Fix DissectArcPath() so as to: * **OPTIONALLY** (and not mandatorily!) return the path part that follows the ARC adapter-controller-peripheral elements in the ARC path; * make it correctly handle the (yes, optional!!) partition() part in the ARC path, for the multi(x)disk(y)rdisk(z) cases. ENHANCEMENTS: ============= - Directly retrieve the default OS entry as we enumerate them and build their list (i.e. merge the GetDefaultOperatingSystem() helper within InitOperatingSystemList()). - Directly use the opened 'FreeLoader' INI section via its ID in the different functions that need it. - Make the custom-boot and linux loaders honour the boot options they are supposed to support (see FREELDR.INI documentation / template). This includes the 'BootDrive' and 'BootPartition' (alternatively the ARC 'BootPath'). This also allows them to take into account the user-specified choices in the FreeLdr custom-boot editors. - Modify the FreeLdr custom-boot editors so as to correctly honour the priorities of the boot options as specified in the FREELDR.INI documentation / template. - Use stack trick (union of structs) to reduce stack usage in the FreeLdr custom-boot editors, because there are strings buffers that are used in an alternate manner. - Extract out from the editors the LoadOperatingSystem() calls, and move it back into OptionMenuCustomBoot(), so that when this latter function is called there is no risk of having a stack almost full. - When building the ARC-compatible argument vector for the loaders, add the mandatory "SystemPartition" path. This allows the loaders to NOT call the machine-specific MachDiskGetBootPath() later on (this data is indeed passed to them by the boot manager part of FreeLdr). - Improve the FsOpenFile() helper so as to make it: * return an adequate ARC_STATUS instead of a mere uninformative BOOLEAN; * take open options, as well as a default path (optional) that would be prepended to the file name in case the latter is a relative one. - Make RamDiskLoadVirtualFile() return an actual descriptive ARC_STATUS value, and make it take an optional default path (same usage as the one in FsOpenFile() ). + Remove useless NTAPI . - UiInitialize() and TuiTextToColor(), TuiTextToFillStyle(): load or convert named settings into corresponding values using setting table and a tight for-loop, instead of duplicating 10x the same parameter reading logic. - UiInitialize(): Open the "Display" INI section just once. Remove usage of DisplayModeText[] buffer. - UiShowMessageBoxesInSection() and UiShowMessageBoxesInArgv(): reduce code indentation level. ENHANCEMENTS for NT OS loader: ============================== - Don't use MachDiskGetBootPath() but use instead the "SystemPartition" value passed via the ARC argument vector by the boot manager (+ validation checks). Use it as the "default path" when calling FsOpenFile() or loading the ramdisk. - Honour the FreeLdr-specific "Hal=" and "Kernel=" options by converting them into NT standard "/HAL=" and "/KERNEL=" options in the boot command line. Note that if the latter ones are already present on the standard "Options=" option line, they would take precedence over those passed via the separate "Hal=" and "Kernel=" FreeLdr-specific options. Also add some documentation links to Geoff Chappell's website about how the default HAL and KERNEL names are chosen depending on the detected underlying platform on which the NT OS loader is running.
2019-08-30 22:49:37 +00:00
// Displays all the message boxes in a given section.
VOID
UiShowMessageBoxesInSection(
IN ULONG_PTR SectionId);
[FREELDR] Some ARC-spec compatibility refactoring + simplifications & fixes. CORE-9023 - During loading and initialization of the list of operating systems available in freeldr.ini, convert any legacy operating system entry encountered -- they are like those in NTLDR's boot.ini file, i.e.: ArcOsLoadPartition="LoadIdentifier" /List /of /Options into a new operating system INI entry, like those used by default in FreeLoader. This allows us to avoid treating this corner-case later in different parts of the code. Also, the "BootType" value is now determined there, only once. - Convert the OS loaders entry-points to ARC-compatible ones, following the "Advanced RISC Computing Specification, Version 1.2" specification https://www.netbsd.org/docs/Hardware/Machines/ARC/riscspec.pdf - Introduce helpers for retrieving options values from the argument vector in a simple way. - Simplify LoadOperatingSystem(), since now the "BootType" value has been determined once while loading the list of OSes (see above) and is well-defined there. Use the BuildArgvForOsLoader() helper to build the ARC-compatible argument vector from the corresponding INI settings for the selected operating system entry, and use it when calling the corresponding OS loader. - In the OS loaders, since we can now directly read the settings from the argument vector (instead of using INI settings), we can avoid using a bunch of fixed-size string buffers, and avoid potentially failing IniOpenSection() calls as well. - Simplify code in the Linux loader (and the RemoveQuotes() function). - Add UiShowMessageBoxesInArgv() that acts on the "MessageBox=" settings passed through the argument vector (equivalent to UiShowMessageBoxesInSection() ). - Use string-safe functions where needed (copy/concatenation/printf on fixed-size buffers).
2019-08-06 20:30:54 +00:00
VOID
UiShowMessageBoxesInArgv(
IN ULONG Argc,
IN PCHAR Argv[]);
VOID UiEscapeString(PCHAR String); // Processes a string and changes all occurrences of "\n" to '\n'
BOOLEAN UiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length);
UCHAR UiTextToColor(PCSTR ColorText); // Converts the text color into it's equivalent color value
UCHAR UiTextToFillStyle(PCSTR FillStyleText); // Converts the text fill into it's equivalent fill value
VOID UiTruncateStringEllipsis(PCHAR StringText, ULONG MaxChars); // Truncates a string to MaxChars by adding an ellipsis on the end '...'
VOID UiFadeInBackdrop(VOID); // Draws the backdrop and fades the screen in
VOID UiFadeOut(VOID); // Fades the screen out
///////////////////////////////////////////////////////////////////////////////////////
//
// Menu Functions
//
///////////////////////////////////////////////////////////////////////////////////////
typedef struct tagUI_MENU_INFO
{
PCSTR MenuHeader;
PCSTR MenuFooter;
BOOLEAN ShowBootOptions;
PCSTR* MenuItemList;
ULONG MenuItemCount;
LONG MenuTimeRemaining;
ULONG SelectedMenuItem;
PVOID Context;
ULONG Left;
ULONG Top;
ULONG Right;
ULONG Bottom;
} UI_MENU_INFO, *PUI_MENU_INFO;
typedef
BOOLEAN
(*UiMenuKeyPressFilterCallback)(
IN ULONG KeyPress,
IN ULONG SelectedMenuItem,
IN PVOID Context OPTIONAL);
BOOLEAN
UiDisplayMenu(
IN PCSTR MenuHeader,
IN PCSTR MenuFooter OPTIONAL,
IN BOOLEAN ShowBootOptions,
IN PCSTR MenuItemList[],
IN ULONG MenuItemCount,
IN ULONG DefaultMenuItem,
IN LONG MenuTimeOut,
OUT PULONG SelectedMenuItem,
IN BOOLEAN CanEscape,
IN UiMenuKeyPressFilterCallback KeyPressFilter OPTIONAL,
IN PVOID Context OPTIONAL);
///////////////////////////////////////////////////////////////////////////////////////
//
// UI virtual table
//
///////////////////////////////////////////////////////////////////////////////////////
typedef struct tagUIVTBL
{
BOOLEAN (*Initialize)(VOID);
VOID (*UnInitialize)(VOID);
VOID (*DrawBackdrop)(VOID);
VOID (*FillArea)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, CHAR FillChar, UCHAR Attr);
VOID (*DrawShadow)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom);
VOID (*DrawBox)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR VertStyle, UCHAR HorzStyle, BOOLEAN Fill, BOOLEAN Shadow, UCHAR Attr);
VOID (*DrawText)(ULONG X, ULONG Y, PCSTR Text, UCHAR Attr);
VOID (*DrawText2)(ULONG X, ULONG Y, ULONG MaxNumChars, PCSTR Text, UCHAR Attr);
VOID (*DrawCenteredText)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, PCSTR TextString, UCHAR Attr);
VOID (*DrawStatusText)(PCSTR StatusText);
VOID (*UpdateDateTime)(VOID);
VOID (*MessageBox)(PCSTR MessageText);
VOID (*MessageBoxCritical)(PCSTR MessageText);
VOID (*DrawProgressBarCenter)(ULONG Position, ULONG Range, PCHAR ProgressText);
VOID (*DrawProgressBar)(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText);
BOOLEAN (*EditBox)(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length);
UCHAR (*TextToColor)(PCSTR ColorText);
UCHAR (*TextToFillStyle)(PCSTR FillStyleText);
VOID (*FadeInBackdrop)(VOID);
VOID (*FadeOut)(VOID);
BOOLEAN (*DisplayMenu)(
IN PCSTR MenuHeader,
IN PCSTR MenuFooter OPTIONAL,
IN BOOLEAN ShowBootOptions,
IN PCSTR MenuItemList[],
IN ULONG MenuItemCount,
IN ULONG DefaultMenuItem,
IN LONG MenuTimeOut,
OUT PULONG SelectedMenuItem,
IN BOOLEAN CanEscape,
IN UiMenuKeyPressFilterCallback KeyPressFilter OPTIONAL,
IN PVOID Context OPTIONAL);
VOID (*DrawMenu)(PUI_MENU_INFO MenuInfo);
} UIVTBL, *PUIVTBL;
VOID UiInit(const char *CmdLine);
extern UIVTBL UiVtbl;
/*
* Combines the foreground and background colors into a single attribute byte
*/
#define ATTR(cFore, cBack) ((cBack << 4)|cFore)
/*
* Fill styles for DrawBackdrop()
*/
#define LIGHT_FILL 0xB0
#define MEDIUM_FILL 0xB1
#define DARK_FILL 0xB2
/*
* Screen colors
*/
#define COLOR_BLACK 0
#define COLOR_BLUE 1
#define COLOR_GREEN 2
#define COLOR_CYAN 3
#define COLOR_RED 4
#define COLOR_MAGENTA 5
#define COLOR_BROWN 6
#define COLOR_GRAY 7
#define COLOR_DARKGRAY 8
#define COLOR_LIGHTBLUE 9
#define COLOR_LIGHTGREEN 10
#define COLOR_LIGHTCYAN 11
#define COLOR_LIGHTRED 12
#define COLOR_LIGHTMAGENTA 13
#define COLOR_YELLOW 14
#define COLOR_WHITE 15
/* Add COLOR_BLINK to a background to cause blinking */
//#define COLOR_BLINK 8
/*
* Defines for IBM box drawing characters
*/
#define HORZ (0xc4) /* Single horizontal line */
#define D_HORZ (0xcd) /* Double horizontal line.*/
#define VERT (0xb3) /* Single vertical line */
#define D_VERT (0xba) /* Double vertical line. */