https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5d5b6a5600c73696fa8a42...
commit 5d5b6a5600c73696fa8a42e980f156d2f771f683 Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Fri Aug 2 21:35:23 2019 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Wed Aug 7 18:50:20 2019 +0200
[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. --- boot/freeldr/freeldr/bootmgr.c | 9 +- boot/freeldr/freeldr/custom.c | 4 +- boot/freeldr/freeldr/include/ui.h | 64 ++++++++--- boot/freeldr/freeldr/include/ui/gui.h | 15 ++- boot/freeldr/freeldr/include/ui/noui.h | 15 ++- boot/freeldr/freeldr/include/ui/tui.h | 25 +++- boot/freeldr/freeldr/options.c | 4 +- boot/freeldr/freeldr/ui/directui.c | 197 ++++++++++++++++---------------- boot/freeldr/freeldr/ui/minitui.c | 22 ++-- boot/freeldr/freeldr/ui/noui.c | 14 ++- boot/freeldr/freeldr/ui/tui.c | 21 ++-- boot/freeldr/freeldr/ui/tuimenu.c | 203 ++++++++++++++++----------------- boot/freeldr/freeldr/ui/ui.c | 21 +++- 13 files changed, 358 insertions(+), 256 deletions(-)
diff --git a/boot/freeldr/freeldr/bootmgr.c b/boot/freeldr/freeldr/bootmgr.c index 6a9cb569e29..756f74e69dd 100644 --- a/boot/freeldr/freeldr/bootmgr.c +++ b/boot/freeldr/freeldr/bootmgr.c @@ -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; diff --git a/boot/freeldr/freeldr/custom.c b/boot/freeldr/freeldr/custom.c index 25fee60a4eb..0ef5f5af160 100644 --- a/boot/freeldr/freeldr/custom.c +++ b/boot/freeldr/freeldr/custom.c @@ -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; diff --git a/boot/freeldr/freeldr/include/ui.h b/boot/freeldr/freeldr/include/ui.h index 151c0af1d48..f773ae84540 100644 --- a/boot/freeldr/freeldr/include/ui.h +++ b/boot/freeldr/freeldr/include/ui.h @@ -97,24 +97,42 @@ VOID UiFadeOut(VOID); // Fades the scr
typedef struct tagUI_MENU_INFO { - PCSTR MenuHeader; - PCSTR MenuFooter; - BOOLEAN ShowBootOptions; - - PCSTR* MenuItemList; - ULONG MenuItemCount; - LONG MenuTimeRemaining; - ULONG SelectedMenuItem; - - ULONG Left; - ULONG Top; - ULONG Right; - ULONG Bottom; + 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)(ULONG KeyPress); - -BOOLEAN UiDisplayMenu(PCSTR MenuHeader, PCSTR MenuFooter, BOOLEAN ShowBootOptions, PCSTR MenuItemList[], ULONG MenuItemCount, ULONG DefaultMenuItem, LONG MenuTimeOut, ULONG* SelectedMenuItem, BOOLEAN CanEscape, UiMenuKeyPressFilterCallback KeyPressFilter); +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);
/////////////////////////////////////////////////////////////////////////////////////// // @@ -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;
diff --git a/boot/freeldr/freeldr/include/ui/gui.h b/boot/freeldr/freeldr/include/ui/gui.h index 7ba6e3ce4d3..516394b0b8a 100644 --- a/boot/freeldr/freeldr/include/ui/gui.h +++ b/boot/freeldr/freeldr/include/ui/gui.h @@ -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; diff --git a/boot/freeldr/freeldr/include/ui/noui.h b/boot/freeldr/freeldr/include/ui/noui.h index c619834c4be..4d26bc64a6d 100644 --- a/boot/freeldr/freeldr/include/ui/noui.h +++ b/boot/freeldr/freeldr/include/ui/noui.h @@ -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); diff --git a/boot/freeldr/freeldr/include/ui/tui.h b/boot/freeldr/freeldr/include/ui/tui.h index 2c08eaac9b2..6daf7c30c43 100644 --- a/boot/freeldr/freeldr/include/ui/tui.h +++ b/boot/freeldr/freeldr/include/ui/tui.h @@ -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) diff --git a/boot/freeldr/freeldr/options.c b/boot/freeldr/freeldr/options.c index 78338f2c5d5..701f8693893 100644 --- a/boot/freeldr/freeldr/options.c +++ b/boot/freeldr/freeldr/options.c @@ -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; diff --git a/boot/freeldr/freeldr/ui/directui.c b/boot/freeldr/freeldr/ui/directui.c index b117cd3f5a4..519fd510dd0 100644 --- a/boot/freeldr/freeldr/ui/directui.c +++ b/boot/freeldr/freeldr/ui/directui.c @@ -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()) + 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 */ - if (MenuInfo->MenuTimeRemaining != -1) - { - /* Cancel it and remove it */ - MenuInfo->MenuTimeRemaining = -1; - UiDrawMenuBox(MenuInfo); - } + /* Cancel it and remove it */ + MenuInfo->MenuTimeRemaining = -1; + UiDrawMenuBox(MenuInfo); + }
- /* Get the key */ + /* 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))) - { - /* It processed the key character, so redraw and exit */ - UiDrawMenu(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;
- /* Process the key */ - if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) || - (KeyEvent == KEY_HOME) || (KeyEvent == KEY_END )) + /* Check the key and change the selected menu item */ + if ((KeyEvent == KEY_UP) && (Selected > 0)) { - /* 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)) + /* Deselect previous item and go up */ + MenuInfo->SelectedMenuItem--; + UiDrawMenuItem(MenuInfo, Selected); + Selected--; + + // 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)) + } + 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)) { - /* 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_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; diff --git a/boot/freeldr/freeldr/ui/minitui.c b/boot/freeldr/freeldr/ui/minitui.c index e90e13d399b..97a0e2857b0 100644 --- a/boot/freeldr/freeldr/ui/minitui.c +++ b/boot/freeldr/freeldr/ui/minitui.c @@ -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 diff --git a/boot/freeldr/freeldr/ui/noui.c b/boot/freeldr/freeldr/ui/noui.c index 3d16b04f5db..6f77cc4f4d6 100644 --- a/boot/freeldr/freeldr/ui/noui.c +++ b/boot/freeldr/freeldr/ui/noui.c @@ -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; diff --git a/boot/freeldr/freeldr/ui/tui.c b/boot/freeldr/freeldr/ui/tui.c index c3e42295d19..b39e6fbc36d 100644 --- a/boot/freeldr/freeldr/ui/tui.c +++ b/boot/freeldr/freeldr/ui/tui.c @@ -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; diff --git a/boot/freeldr/freeldr/ui/tuimenu.c b/boot/freeldr/freeldr/ui/tuimenu.c index 86690af784d..9b173ac8b7a 100644 --- a/boot/freeldr/freeldr/ui/tuimenu.c +++ b/boot/freeldr/freeldr/ui/tuimenu.c @@ -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 )) + { // - // Call the supplied key filter callback function to see - // if it is going to handle this keypress. + // Get the current selected item and count // - if ((KeyPressFilter) && (KeyPressFilter(KeyEvent))) - { - // - // It processed the key character, so redraw and exit - // - UiVtbl.DrawMenu(MenuInfo); - return 0; - } + Selected = MenuInfo->SelectedMenuItem; + Count = MenuInfo->MenuItemCount - 1;
// - // Process the key + // Check the key and change the selected menu item // - if ((KeyEvent == KEY_UP ) || (KeyEvent == KEY_DOWN) || - (KeyEvent == KEY_HOME) || (KeyEvent == KEY_END )) + if ((KeyEvent == KEY_UP) && (Selected > 0)) { // - // Get the current selected item and count + // Deselect previous item and go up // - Selected = MenuInfo->SelectedMenuItem; - Count = MenuInfo->MenuItemCount - 1; + MenuInfo->SelectedMenuItem--; + TuiDrawMenuItem(MenuInfo, Selected); + Selected--;
- // - // 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)) + } + 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)) { - // - // 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); } - + } + else if ( ((KeyEvent == KEY_DOWN) && (Selected == Count)) || + (KeyEvent == KEY_HOME) ) + { // - // Select new item and update video buffer + // Go to the beginning // - TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem); - VideoCopyOffScreenBufferToVRAM(); + MenuInfo->SelectedMenuItem = 0; + TuiDrawMenuItem(MenuInfo, Selected); } + + // + // Select new item and update video buffer + // + TuiDrawMenuItem(MenuInfo, MenuInfo->SelectedMenuItem); + VideoCopyOffScreenBufferToVRAM(); }
// diff --git a/boot/freeldr/freeldr/ui/ui.c b/boot/freeldr/freeldr/ui/ui.c index 98035ee84b6..e9124fbe15e 100644 --- a/boot/freeldr/freeldr/ui/ui.c +++ b/boot/freeldr/freeldr/ui/ui.c @@ -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)