[FREELDR] Some enhancements for the UI code. (#1763)

- EditBox: Display the initial contents of the text buffer.
  This allows modifying already existing text in the passed buffer.

- Menu:
  * Make both MenuHeader and MenuFooter optional (but the latter is
    more "optional" than the former...).

  * Allow passing a user-provided "Context" structure to the key-press
    filter callback, and pass also the index of the menu item that has
    been selected.

- Minor formatting fixes.
This commit is contained in:
Hermès Bélusca-Maïto 2019-08-02 21:35:23 +02:00
parent 268cdf5702
commit 5d5b6a5600
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
13 changed files with 367 additions and 265 deletions

View file

@ -206,7 +206,11 @@ LONG GetTimeOut(VOID)
return TimeOut;
}
BOOLEAN MainBootMenuKeyPressFilter(ULONG KeyPress)
BOOLEAN
MainBootMenuKeyPressFilter(
IN ULONG KeyPress,
IN ULONG SelectedMenuItem,
IN PVOID Context OPTIONAL)
{
if (KeyPress == KEY_F8)
{
@ -309,7 +313,8 @@ VOID RunLoader(VOID)
TimeOut,
&SelectedOperatingSystem,
FALSE,
MainBootMenuKeyPressFilter))
MainBootMenuKeyPressFilter,
OperatingSystemList))
{
UiMessageBox("Press ENTER to reboot.");
goto Reboot;

View file

@ -53,14 +53,14 @@ VOID OptionMenuCustomBoot(VOID)
};
ULONG SelectedMenuItem;
if (!UiDisplayMenu("Please choose a boot method:", "",
if (!UiDisplayMenu("Please choose a boot method:", NULL,
FALSE,
CustomBootMenuList,
sizeof(CustomBootMenuList) / sizeof(CustomBootMenuList[0]),
0, -1,
&SelectedMenuItem,
TRUE,
NULL))
NULL, NULL))
{
/* The user pressed ESC */
return;

View file

@ -97,24 +97,42 @@ VOID UiFadeOut(VOID); // Fades the scr
typedef struct tagUI_MENU_INFO
{
PCSTR MenuHeader;
PCSTR MenuFooter;
BOOLEAN ShowBootOptions;
PCSTR MenuHeader;
PCSTR MenuFooter;
BOOLEAN ShowBootOptions;
PCSTR* MenuItemList;
ULONG MenuItemCount;
LONG MenuTimeRemaining;
ULONG SelectedMenuItem;
PCSTR* MenuItemList;
ULONG MenuItemCount;
LONG MenuTimeRemaining;
ULONG SelectedMenuItem;
PVOID Context;
ULONG Left;
ULONG Top;
ULONG Right;
ULONG Bottom;
ULONG Left;
ULONG Top;
ULONG Right;
ULONG Bottom;
} UI_MENU_INFO, *PUI_MENU_INFO;
typedef BOOLEAN (*UiMenuKeyPressFilterCallback)(ULONG KeyPress);
typedef
BOOLEAN
(*UiMenuKeyPressFilterCallback)(
IN ULONG KeyPress,
IN ULONG SelectedMenuItem,
IN PVOID Context OPTIONAL);
BOOLEAN UiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter);
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);
///////////////////////////////////////////////////////////////////////////////////////
//
@ -145,7 +163,19 @@ typedef struct tagUIVTBL
VOID (*FadeInBackdrop)(VOID);
VOID (*FadeOut)(VOID);
BOOLEAN (*DisplayMenu)(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter);
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;

View file

@ -49,6 +49,19 @@ UCHAR GuiTextToFillStyle(PCSTR FillStyleText); // Converts the
// Menu Functions
//
///////////////////////////////////////////////////////////////////////////////////////
BOOLEAN GuiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem);
BOOLEAN
GuiDisplayMenu(
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);
extern const UIVTBL GuiVtbl;

View file

@ -42,5 +42,18 @@ VOID NoUiFadeOut(VOID);
//
///////////////////////////////////////////////////////////////////////////////////////
BOOLEAN NoUiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter);
BOOLEAN
NoUiDisplayMenu(
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 NoUiDrawMenu(PUI_MENU_INFO MenuInfo);

View file

@ -59,12 +59,25 @@ VOID TuiFadeOut(VOID); // Fades the sc
//
///////////////////////////////////////////////////////////////////////////////////////
VOID NTAPI TuiCalcMenuBoxSize(PUI_MENU_INFO MenuInfo);
VOID TuiDrawMenu(PUI_MENU_INFO MenuInfo);
VOID NTAPI TuiDrawMenuBox(PUI_MENU_INFO MenuInfo);
VOID NTAPI TuiDrawMenuItem(PUI_MENU_INFO MenuInfo, ULONG MenuItemNumber);
ULONG NTAPI TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo, UiMenuKeyPressFilterCallback KeyPressFilter);
BOOLEAN TuiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter);
VOID TuiCalcMenuBoxSize(PUI_MENU_INFO MenuInfo);
VOID TuiDrawMenu(PUI_MENU_INFO MenuInfo);
VOID TuiDrawMenuBox(PUI_MENU_INFO MenuInfo);
VOID TuiDrawMenuItem(PUI_MENU_INFO MenuInfo, ULONG MenuItemNumber);
ULONG TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo, UiMenuKeyPressFilterCallback KeyPressFilter);
BOOLEAN
TuiDisplayMenu(
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);
/* Definitions for corners, depending on HORIZ and VERT */
#define UL (0xda)

View file

@ -91,7 +91,7 @@ VOID DoOptionsMenu(VOID)
ULONG SelectedMenuItem;
CHAR DebugChannelString[100];
if (!UiDisplayMenu("Select an option:", "",
if (!UiDisplayMenu("Select an option:", NULL,
TRUE,
OptionsMenuList,
sizeof(OptionsMenuList) / sizeof(OptionsMenuList[0]),
@ -99,7 +99,7 @@ VOID DoOptionsMenu(VOID)
-1,
&SelectedMenuItem,
TRUE,
NULL))
NULL, NULL))
{
/* The user pressed ESC */
return;

View file

@ -274,7 +274,6 @@ UiTruncateStringEllipsis(IN PCHAR StringText,
}
VOID
NTAPI
UiDrawMenuBox(IN PUI_MENU_INFO MenuInfo)
{
CHAR MenuLineText[80], TempString[80];
@ -338,7 +337,6 @@ UiDrawMenuBox(IN PUI_MENU_INFO MenuInfo)
}
VOID
NTAPI
UiDrawMenuItem(IN PUI_MENU_INFO MenuInfo,
IN ULONG MenuItemNumber)
{
@ -380,10 +378,13 @@ UiDrawMenu(IN PUI_MENU_INFO MenuInfo)
ULONG i;
/* No GUI status bar text, just minimal text. Show the menu header. */
UiDrawText(0,
MenuInfo->Top - 2,
MenuInfo->MenuHeader,
ATTR(UiMenuFgColor, UiMenuBgColor));
if (MenuInfo->MenuHeader)
{
UiDrawText(0,
MenuInfo->Top - 2,
MenuInfo->MenuHeader,
ATTR(UiMenuFgColor, UiMenuBgColor));
}
/* Now tell the user how to choose */
UiDrawText(0,
@ -396,10 +397,13 @@ UiDrawMenu(IN PUI_MENU_INFO MenuInfo)
ATTR(UiMenuFgColor, UiMenuBgColor));
/* And show the menu footer */
UiDrawText(0,
UiScreenHeight - 4,
MenuInfo->MenuFooter,
ATTR(UiMenuFgColor, UiMenuBgColor));
if (MenuInfo->MenuFooter)
{
UiDrawText(0,
UiScreenHeight - 4,
MenuInfo->MenuFooter,
ATTR(UiMenuFgColor, UiMenuBgColor));
}
/* Draw the menu box */
UiDrawMenuBox(MenuInfo);
@ -418,7 +422,6 @@ UiDrawMenu(IN PUI_MENU_INFO MenuInfo)
}
ULONG
NTAPI
UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo,
IN UiMenuKeyPressFilterCallback KeyPressFilter)
{
@ -426,88 +429,88 @@ UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo,
ULONG Selected, Count;
/* Check for a keypress */
if (MachConsKbHit())
{
/* Check if the timeout is not already complete */
if (MenuInfo->MenuTimeRemaining != -1)
{
/* Cancel it and remove it */
MenuInfo->MenuTimeRemaining = -1;
UiDrawMenuBox(MenuInfo);
}
if (!MachConsKbHit())
return 0; // None, bail out
/* Get the key */
/* Check if the timeout is not already complete */
if (MenuInfo->MenuTimeRemaining != -1)
{
/* Cancel it and remove it */
MenuInfo->MenuTimeRemaining = -1;
UiDrawMenuBox(MenuInfo);
}
/* Get the key (get the extended key if needed) */
KeyEvent = MachConsGetCh();
if (KeyEvent == KEY_EXTENDED)
KeyEvent = MachConsGetCh();
/* Is it extended? Then get the extended key */
if (!KeyEvent) KeyEvent = MachConsGetCh();
/*
* Call the supplied key filter callback function to see
* if it is going to handle this keypress.
*/
if (KeyPressFilter &&
KeyPressFilter(KeyEvent, MenuInfo->SelectedMenuItem, MenuInfo->Context))
{
/* It processed the key character, so redraw and exit */
UiDrawMenu(MenuInfo);
return 0;
}
/*
* Call the supplied key filter callback function to see
* if it is going to handle this keypress.
*/
if ((KeyPressFilter) && (KeyPressFilter(KeyEvent)))
/* Process the key */
if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) ||
(KeyEvent == KEY_HOME) || (KeyEvent == KEY_END ))
{
/* Get the current selected item and count */
Selected = MenuInfo->SelectedMenuItem;
Count = MenuInfo->MenuItemCount - 1;
/* Check the key and change the selected menu item */
if ((KeyEvent == KEY_UP) && (Selected > 0))
{
/* It processed the key character, so redraw and exit */
UiDrawMenu(MenuInfo);
return 0;
}
/* Deselect previous item and go up */
MenuInfo->SelectedMenuItem--;
UiDrawMenuItem(MenuInfo, Selected);
Selected--;
/* Process the key */
if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) ||
(KeyEvent == KEY_HOME) || (KeyEvent == KEY_END ))
{
/* Get the current selected item and count */
Selected = MenuInfo->SelectedMenuItem;
Count = MenuInfo->MenuItemCount - 1;
/* Check the key and change the selected menu item */
if ((KeyEvent == KEY_UP) && (Selected > 0))
// Skip past any separators
if ((Selected > 0) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
/* Deselect previous item and go up */
MenuInfo->SelectedMenuItem--;
UiDrawMenuItem(MenuInfo, Selected);
Selected--;
// Skip past any separators
if ((Selected > 0) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
MenuInfo->SelectedMenuItem--;
}
}
else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) ||
(KeyEvent == KEY_END) )
{
/* Go to the end */
MenuInfo->SelectedMenuItem = Count;
UiDrawMenuItem(MenuInfo, Selected);
}
else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
{
/* Deselect previous item and go down */
MenuInfo->SelectedMenuItem++;
UiDrawMenuItem(MenuInfo, Selected);
Selected++;
// Skip past any separators
if ((Selected < Count) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
MenuInfo->SelectedMenuItem++;
}
}
else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) ||
(KeyEvent == KEY_HOME) )
{
/* Go to the beginning */
MenuInfo->SelectedMenuItem = 0;
UiDrawMenuItem(MenuInfo, Selected);
}
/* Select new item and update video buffer */
UiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
}
else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) ||
(KeyEvent == KEY_END) )
{
/* Go to the end */
MenuInfo->SelectedMenuItem = Count;
UiDrawMenuItem(MenuInfo, Selected);
}
else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
{
/* Deselect previous item and go down */
MenuInfo->SelectedMenuItem++;
UiDrawMenuItem(MenuInfo, Selected);
Selected++;
// Skip past any separators
if ((Selected < Count) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
MenuInfo->SelectedMenuItem++;
}
}
else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) ||
(KeyEvent == KEY_HOME) )
{
/* Go to the beginning */
MenuInfo->SelectedMenuItem = 0;
UiDrawMenuItem(MenuInfo, Selected);
}
/* Select new item and update video buffer */
UiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
}
/* Return the pressed key */
@ -515,7 +518,6 @@ UiProcessMenuKeyboardEvent(IN PUI_MENU_INFO MenuInfo,
}
VOID
NTAPI
UiCalcMenuBoxSize(IN PUI_MENU_INFO MenuInfo)
{
ULONG i, Width = 0, Height, Length;
@ -548,16 +550,18 @@ UiCalcMenuBoxSize(IN PUI_MENU_INFO MenuInfo)
}
BOOLEAN
UiDisplayMenu(IN PCSTR MenuHeader,
IN PCSTR MenuFooter,
IN BOOLEAN ShowBootOptions,
IN PCSTR MenuItemList[],
IN ULONG MenuItemCount,
IN ULONG DefaultMenuItem,
IN LONG MenuTimeOut,
OUT PULONG SelectedMenuItem,
IN BOOLEAN CanEscape,
IN UiMenuKeyPressFilterCallback KeyPressFilter)
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_MENU_INFO MenuInformation;
ULONG LastClockSecond;
@ -572,17 +576,16 @@ UiDisplayMenu(IN PCSTR MenuHeader,
*/
if (!MenuTimeOut && KeyPressFilter && MachConsKbHit())
{
/* Get the key */
/* Get the key (get the extended key if needed) */
KeyPress = MachConsGetCh();
/* Is it extended? Then get the extended key */
if (!KeyPress) KeyPress = MachConsGetCh();
if (KeyPress == KEY_EXTENDED)
KeyPress = MachConsGetCh();
/*
* Call the supplied key filter callback function to see
* if it is going to handle this keypress.
*/
if (KeyPressFilter(KeyPress))
if (KeyPressFilter(KeyPress, DefaultMenuItem, Context))
{
/* It processed the key character, cancel the timeout */
MenuTimeOut = -1;
@ -605,6 +608,7 @@ UiDisplayMenu(IN PCSTR MenuHeader,
MenuInformation.MenuItemCount = MenuItemCount;
MenuInformation.MenuTimeRemaining = MenuTimeOut;
MenuInformation.SelectedMenuItem = DefaultMenuItem;
MenuInformation.Context = Context;
/* Calculate the size of the menu box */
UiCalcMenuBoxSize(&MenuInformation);
@ -619,8 +623,7 @@ UiDisplayMenu(IN PCSTR MenuHeader,
while (TRUE)
{
/* Process key presses */
KeyPress = UiProcessMenuKeyboardEvent(&MenuInformation,
KeyPressFilter);
KeyPress = UiProcessMenuKeyboardEvent(&MenuInformation, KeyPressFilter);
/* Check for ENTER or ESC */
if (KeyPress == KEY_ENTER) break;

View file

@ -85,10 +85,13 @@ MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo)
//
// No GUI status bar text, just minimal text. Show the menu header.
//
UiVtbl.DrawText(0,
MenuInfo->Top - 2,
MenuInfo->MenuHeader,
ATTR(UiMenuFgColor, UiMenuBgColor));
if (MenuInfo->MenuHeader)
{
UiVtbl.DrawText(0,
MenuInfo->Top - 2,
MenuInfo->MenuHeader,
ATTR(UiMenuFgColor, UiMenuBgColor));
}
//
// Now tell the user how to choose
@ -105,10 +108,13 @@ MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo)
//
// And show the menu footer
//
UiVtbl.DrawText(0,
UiScreenHeight - 4,
MenuInfo->MenuFooter,
ATTR(UiMenuFgColor, UiMenuBgColor));
if (MenuInfo->MenuFooter)
{
UiVtbl.DrawText(0,
UiScreenHeight - 4,
MenuInfo->MenuFooter,
ATTR(UiMenuFgColor, UiMenuBgColor));
}
//
// Draw the menu box

View file

@ -113,7 +113,19 @@ VOID NoUiFadeOut(VOID)
//
///////////////////////////////////////////////////////////////////////////////////////
BOOLEAN NoUiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
BOOLEAN
NoUiDisplayMenu(
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)
{
*SelectedMenuItem = DefaultMenuItem;
return TRUE;

View file

@ -628,14 +628,10 @@ VOID TuiMessageBoxCritical(PCSTR MessageText)
if (MachConsKbHit())
{
key = MachConsGetCh();
if(key == KEY_EXTENDED)
if (key == KEY_EXTENDED)
key = MachConsGetCh();
if(key == KEY_ENTER)
break;
else if(key == KEY_SPACE)
break;
else if(key == KEY_ESC)
if ((key == KEY_ENTER) || (key == KEY_SPACE) || (key == KEY_ESC))
break;
}
@ -645,7 +641,6 @@ VOID TuiMessageBoxCritical(PCSTR MessageText)
MachHwIdle();
}
}
VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
@ -882,12 +877,16 @@ BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
temp[j++] = MessageText[i];
}
EditBoxTextLength = 0;
EditBoxTextLength = (ULONG)strlen(EditTextBuffer) + 1;
EditBoxTextLength = min(EditBoxTextLength, Length);
EditBoxTextPosition = 0;
EditBoxLine = y2 - 2;
EditBoxStartX = x1 + 3;
EditBoxEndX = x2 - 3;
// Draw the edit box background and the text
UiFillArea(EditBoxStartX, EditBoxLine, EditBoxEndX, EditBoxLine, ' ', ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
UiDrawText2(EditBoxStartX, EditBoxLine, EditBoxEndX - EditBoxStartX + 1, EditTextBuffer, ATTR(UiEditBoxTextColor, UiEditBoxBgColor));
// Show the cursor
EditBoxCursorX = EditBoxStartX;
@ -910,18 +909,18 @@ BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
{
Extended = FALSE;
key = MachConsGetCh();
if(key == KEY_EXTENDED)
if (key == KEY_EXTENDED)
{
Extended = TRUE;
key = MachConsGetCh();
}
if(key == KEY_ENTER)
if (key == KEY_ENTER)
{
ReturnCode = TRUE;
break;
}
else if(key == KEY_ESC)
else if (key == KEY_ESC)
{
ReturnCode = FALSE;
break;

View file

@ -14,16 +14,18 @@
/* FUNCTIONS *****************************************************************/
BOOLEAN
TuiDisplayMenu(PCSTR MenuHeader,
PCSTR MenuFooter,
BOOLEAN ShowBootOptions,
PCSTR MenuItemList[],
ULONG MenuItemCount,
ULONG DefaultMenuItem,
LONG MenuTimeOut,
ULONG* SelectedMenuItem,
BOOLEAN CanEscape,
UiMenuKeyPressFilterCallback KeyPressFilter)
TuiDisplayMenu(
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_MENU_INFO MenuInformation;
ULONG LastClockSecond;
@ -39,20 +41,17 @@ TuiDisplayMenu(PCSTR MenuHeader,
if (!MenuTimeOut && KeyPressFilter && MachConsKbHit())
{
//
// Get the key
// Get the key (get the extended key if needed)
//
KeyPress = MachConsGetCh();
//
// Is it extended? Then get the extended key
//
if (!KeyPress) KeyPress = MachConsGetCh();
if (KeyPress == KEY_EXTENDED)
KeyPress = MachConsGetCh();
//
// Call the supplied key filter callback function to see
// if it is going to handle this keypress.
//
if (KeyPressFilter(KeyPress))
if (KeyPressFilter(KeyPress, DefaultMenuItem, Context))
{
//
// It processed the key character, cancel the timeout
@ -83,6 +82,7 @@ TuiDisplayMenu(PCSTR MenuHeader,
MenuInformation.MenuItemCount = MenuItemCount;
MenuInformation.MenuTimeRemaining = MenuTimeOut;
MenuInformation.SelectedMenuItem = DefaultMenuItem;
MenuInformation.Context = Context;
//
// Calculate the size of the menu box
@ -107,8 +107,7 @@ TuiDisplayMenu(PCSTR MenuHeader,
//
// Process key presses
//
KeyPress = TuiProcessMenuKeyboardEvent(&MenuInformation,
KeyPressFilter);
KeyPress = TuiProcessMenuKeyboardEvent(&MenuInformation, KeyPressFilter);
//
// Check for ENTER or ESC
@ -169,7 +168,6 @@ TuiDisplayMenu(PCSTR MenuHeader,
}
VOID
NTAPI
TuiCalcMenuBoxSize(PUI_MENU_INFO MenuInfo)
{
ULONG i;
@ -269,7 +267,6 @@ TuiDrawMenu(PUI_MENU_INFO MenuInfo)
}
VOID
NTAPI
TuiDrawMenuBox(PUI_MENU_INFO MenuInfo)
{
CHAR MenuLineText[80], TempString[80];
@ -395,7 +392,6 @@ TuiDrawMenuBox(PUI_MENU_INFO MenuInfo)
}
VOID
NTAPI
TuiDrawMenuItem(PUI_MENU_INFO MenuInfo,
ULONG MenuItemNumber)
{
@ -477,7 +473,6 @@ TuiDrawMenuItem(PUI_MENU_INFO MenuInfo,
}
ULONG
NTAPI
TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo,
UiMenuKeyPressFilterCallback KeyPressFilter)
{
@ -487,115 +482,113 @@ TuiProcessMenuKeyboardEvent(PUI_MENU_INFO MenuInfo,
//
// Check for a keypress
//
if (MachConsKbHit())
if (!MachConsKbHit())
return 0; // None, bail out
//
// Check if the timeout is not already complete
//
if (MenuInfo->MenuTimeRemaining != -1)
{
//
// Check if the timeout is not already complete
// Cancel it and remove it
//
if (MenuInfo->MenuTimeRemaining != -1)
{
//
// Cancel it and remove it
//
MenuInfo->MenuTimeRemaining = -1;
TuiDrawMenuBox(MenuInfo); // FIXME: Remove for minimal UI too
}
MenuInfo->MenuTimeRemaining = -1;
TuiDrawMenuBox(MenuInfo); // FIXME: Remove for minimal UI too
}
//
// Get the key
//
//
// Get the key (get the extended key if needed)
//
KeyEvent = MachConsGetCh();
if (KeyEvent == KEY_EXTENDED)
KeyEvent = MachConsGetCh();
//
// Call the supplied key filter callback function to see
// if it is going to handle this keypress.
//
if (KeyPressFilter &&
KeyPressFilter(KeyEvent, MenuInfo->SelectedMenuItem, MenuInfo->Context))
{
//
// Is it extended? Then get the extended key
// It processed the key character, so redraw and exit
//
if (!KeyEvent) KeyEvent = MachConsGetCh();
UiVtbl.DrawMenu(MenuInfo);
return 0;
}
//
// Process the key
//
if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) ||
(KeyEvent == KEY_HOME) || (KeyEvent == KEY_END ))
{
//
// Get the current selected item and count
//
Selected = MenuInfo->SelectedMenuItem;
Count = MenuInfo->MenuItemCount - 1;
//
// Call the supplied key filter callback function to see
// if it is going to handle this keypress.
// Check the key and change the selected menu item
//
if ((KeyPressFilter) && (KeyPressFilter(KeyEvent)))
if ((KeyEvent == KEY_UP) && (Selected > 0))
{
//
// It processed the key character, so redraw and exit
// Deselect previous item and go up
//
UiVtbl.DrawMenu(MenuInfo);
return 0;
}
MenuInfo->SelectedMenuItem--;
TuiDrawMenuItem(MenuInfo, Selected);
Selected--;
//
// Process the key
//
if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) ||
(KeyEvent == KEY_HOME) || (KeyEvent == KEY_END ))
{
//
// Get the current selected item and count
//
Selected = MenuInfo->SelectedMenuItem;
Count = MenuInfo->MenuItemCount - 1;
//
// Check the key and change the selected menu item
//
if ((KeyEvent == KEY_UP) && (Selected > 0))
// Skip past any separators
if ((Selected > 0) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
//
// Deselect previous item and go up
//
MenuInfo->SelectedMenuItem--;
TuiDrawMenuItem(MenuInfo, Selected);
Selected--;
// Skip past any separators
if ((Selected > 0) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
MenuInfo->SelectedMenuItem--;
}
}
else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) ||
(KeyEvent == KEY_END) )
{
//
// Go to the end
//
MenuInfo->SelectedMenuItem = Count;
TuiDrawMenuItem(MenuInfo, Selected);
}
else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
{
//
// Deselect previous item and go down
//
MenuInfo->SelectedMenuItem++;
TuiDrawMenuItem(MenuInfo, Selected);
Selected++;
// Skip past any separators
if ((Selected < Count) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
MenuInfo->SelectedMenuItem++;
}
}
else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) ||
(KeyEvent == KEY_HOME) )
{
//
// Go to the beginning
//
MenuInfo->SelectedMenuItem = 0;
TuiDrawMenuItem(MenuInfo, Selected);
}
//
// Select new item and update video buffer
//
TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
VideoCopyOffScreenBufferToVRAM();
}
else if ( ((KeyEvent == KEY_UP) && (Selected == 0)) ||
(KeyEvent == KEY_END) )
{
//
// Go to the end
//
MenuInfo->SelectedMenuItem = Count;
TuiDrawMenuItem(MenuInfo, Selected);
}
else if ((KeyEvent == KEY_DOWN) && (Selected < Count))
{
//
// Deselect previous item and go down
//
MenuInfo->SelectedMenuItem++;
TuiDrawMenuItem(MenuInfo, Selected);
Selected++;
// Skip past any separators
if ((Selected < Count) &&
(MenuInfo->MenuItemList[Selected] == NULL))
{
MenuInfo->SelectedMenuItem++;
}
}
else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) ||
(KeyEvent == KEY_HOME) )
{
//
// Go to the beginning
//
MenuInfo->SelectedMenuItem = 0;
TuiDrawMenuItem(MenuInfo, Selected);
}
//
// Select new item and update video buffer
//
TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem);
VideoCopyOffScreenBufferToVRAM();
}
//

View file

@ -438,7 +438,7 @@ UiShowMessageBoxesInArgv(
ULONG LastIndex;
PCSTR ArgValue;
PCHAR MessageBoxText;
ULONG MessageBoxTextSize;
SIZE_T MessageBoxTextSize;
/* Find all the message box settings and run them */
for (LastIndex = 0;
@ -493,9 +493,24 @@ VOID UiTruncateStringEllipsis(PCHAR StringText, ULONG MaxChars)
}
}
BOOLEAN UiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter)
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)
{
return UiVtbl.DisplayMenu(MenuHeader, MenuFooter, ShowBootOptions, MenuItemList, MenuItemCount, DefaultMenuItem, MenuTimeOut, SelectedMenuItem, CanEscape, KeyPressFilter);
return UiVtbl.DisplayMenu(MenuHeader, MenuFooter, ShowBootOptions,
MenuItemList, MenuItemCount, DefaultMenuItem,
MenuTimeOut, SelectedMenuItem, CanEscape,
KeyPressFilter, Context);
}
VOID UiFadeInBackdrop(VOID)