]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c
ShellPkg/[hex]edit: use SimpleTextInEx to read console
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditMenuBar.c
index 390c707bc6ecdd14c3ae81c50bca586c0571aab9..b86594bb283e146cd1063a6ee632e34321777416 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   implements menubar interface functions.\r
 \r
-  Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include "UefiShellDebug1CommandsLib.h"\r
 #include "EditStatusBar.h"\r
 \r
-EDITOR_MENU_ITEM  *MenuItems;\r
+EDITOR_MENU_ITEM   *MenuItems;\r
+MENU_ITEM_FUNCTION *ControlBasedMenuFunctions;\r
 UINTN                 NumItems;\r
 \r
 /**\r
   Cleanup function for a menu bar.  frees all allocated memory.\r
 **/\r
 VOID\r
-EFIAPI\r
 MenuBarCleanup (\r
   VOID\r
   )\r
@@ -32,7 +32,7 @@ MenuBarCleanup (
 }\r
 \r
 /**\r
-  Initializa the menu bar with the specified items.\r
+  Initialize the menu bar with the specified items.\r
 \r
   @param[in] Items              The items to display and their functions.\r
 \r
@@ -40,7 +40,6 @@ MenuBarCleanup (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MenuBarInit (\r
   IN CONST EDITOR_MENU_ITEM  *Items\r
   )\r
@@ -57,6 +56,21 @@ MenuBarInit (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Initialize the control hot-key with the specified items.\r
+\r
+  @param[in] Items              The hot-key functions.\r
+\r
+  @retval EFI_SUCCESS           The initialization was correct.\r
+**/\r
+EFI_STATUS\r
+ControlHotKeyInit (\r
+  IN MENU_ITEM_FUNCTION  *Items\r
+  )\r
+{\r
+  ControlBasedMenuFunctions = Items;\r
+  return EFI_SUCCESS; \r
+}\r
 /**\r
   Refresh function for the menu bar.\r
 \r
@@ -66,7 +80,6 @@ MenuBarInit (
   @retval EFI_SUCCESS           The refresh was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MenuBarRefresh (\r
   IN CONST UINTN LastRow,\r
   IN CONST UINTN LastCol\r
@@ -130,7 +143,6 @@ MenuBarRefresh (
   @return The return value from the called dispatch function.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 MenuBarDispatchFunctionKey (\r
   IN CONST EFI_INPUT_KEY   *Key\r
   )\r
@@ -150,3 +162,53 @@ MenuBarDispatchFunctionKey (
   return (MenuItems[Index].Function ());\r
 }\r
 \r
+/**\r
+  Function to dispatch the correct function based on a control-based key (ctrl+o...)\r
+\r
+  @param[in] KeyData                The pressed key.\r
+\r
+  @retval EFI_NOT_FOUND         The key was not a valid control-based key \r
+                                (an error was sent to the status bar).\r
+  @return EFI_SUCCESS.\r
+**/\r
+EFI_STATUS\r
+MenuBarDispatchControlHotKey (\r
+  IN CONST EFI_KEY_DATA   *KeyData\r
+  )\r
+{\r
+  UINT16                  ControlIndex;\r
+\r
+  //\r
+  // Set to invalid value first.\r
+  //\r
+  ControlIndex = MAX_UINT16;\r
+\r
+  if ((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) {\r
+    //\r
+    // For those console devices that cannot report the CONTROL state,\r
+    // Ctrl+A is translated to 1 (UnicodeChar).\r
+    //\r
+    ControlIndex = KeyData->Key.UnicodeChar;\r
+  } else if (((KeyData->KeyState.KeyShiftState & (EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) != 0) &&\r
+             ((KeyData->KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) == 0)) {\r
+    //\r
+    // For those console devices that can report the CONTROL state,\r
+    // make sure only CONTROL is pressed.\r
+    //\r
+    if ((KeyData->Key.UnicodeChar >= L'A') && (KeyData->Key.UnicodeChar <= L'Z')) {\r
+      ControlIndex = KeyData->Key.UnicodeChar - L'A' + 1;\r
+    } else if ((KeyData->Key.UnicodeChar >= L'a') && (KeyData->Key.UnicodeChar <= L'z')) {\r
+      ControlIndex = KeyData->Key.UnicodeChar - L'a' + 1;\r
+    }\r
+  }\r
+  if ((SCAN_CONTROL_Z < ControlIndex)\r
+    ||(NULL == ControlBasedMenuFunctions[ControlIndex]))\r
+  {\r
+      return EFI_NOT_FOUND;\r
+  }\r
+\r
+  ControlBasedMenuFunctions[ControlIndex]();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r