]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c
add Edit and Hexedit shared features.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditMenuBar.c
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c
new file mode 100644 (file)
index 0000000..390c707
--- /dev/null
@@ -0,0 +1,152 @@
+/** @file\r
+  implements menubar interface functions.\r
+\r
+  Copyright (c) 2005 - 2011, 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
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "EditMenuBar.h"\r
+#include "UefiShellDebug1CommandsLib.h"\r
+#include "EditStatusBar.h"\r
+\r
+EDITOR_MENU_ITEM  *MenuItems;\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
+{\r
+  SHELL_FREE_NON_NULL(MenuItems);\r
+}\r
+\r
+/**\r
+  Initializa the menu bar with the specified items.\r
+\r
+  @param[in] Items              The items to display and their functions.\r
+\r
+  @retval EFI_SUCCESS           The initialization was correct.\r
+  @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
+{\r
+  CONST EDITOR_MENU_ITEM  *ItemsWalker;\r
+\r
+  for (NumItems = 0, ItemsWalker = Items ; ItemsWalker != NULL && ItemsWalker->Function != NULL ; ItemsWalker++,NumItems++);\r
+  \r
+  MenuItems = AllocateZeroPool((NumItems+1) * sizeof(EDITOR_MENU_ITEM));\r
+  if (MenuItems == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  CopyMem(MenuItems, Items, (NumItems+1) * sizeof(EDITOR_MENU_ITEM));\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Refresh function for the menu bar.\r
+\r
+  @param[in] LastRow            The last printable row.\r
+  @param[in] LastCol            The last printable column.\r
+\r
+  @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
+  )\r
+{\r
+  EDITOR_MENU_ITEM  *Item;\r
+  UINTN                 Col;\r
+  UINTN                 Row;\r
+  UINTN                 Width;\r
+  CHAR16                *NameString;\r
+  CHAR16                *FunctionKeyString;\r
+\r
+  //\r
+  // variable initialization\r
+  //\r
+  Col = 1;\r
+  Row = (LastRow - 2);\r
+\r
+  //\r
+  // clear menu bar rows\r
+  //\r
+  EditorClearLine (LastRow - 2, LastCol, LastRow);\r
+  EditorClearLine (LastRow - 1, LastCol, LastRow);\r
+  EditorClearLine (LastRow    , LastCol, LastRow);\r
+\r
+\r
+  //\r
+  // print out the menu items\r
+  //\r
+  for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {\r
+\r
+\r
+    NameString = HiiGetString(gShellDebug1HiiHandle, Item->NameToken, NULL);\r
+\r
+\r
+    Width             = MAX ((StrLen (NameString) + 6), 20);\r
+    if (((Col + Width) > LastCol)) {\r
+      Row++;\r
+      Col = 1;\r
+    }\r
+\r
+    FunctionKeyString = HiiGetString(gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);\r
+\r
+    ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N  %H%s%N  ", FunctionKeyString, NameString);\r
+\r
+    FreePool (NameString);\r
+    FreePool (FunctionKeyString);\r
+    Col += Width;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to dispatch the correct function based on a function key (F1...)\r
+\r
+  @param[in] Key                The pressed key.\r
+\r
+  @retval EFI_NOT_FOUND         The key was not a valid function key \r
+                                (an error was sent to the status bar).\r
+  @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
+{\r
+  UINTN                 Index;\r
+\r
+  Index     = Key->ScanCode - SCAN_F1;\r
+\r
+  //\r
+  // check whether in range\r
+  //\r
+  if (Index > (NumItems - 1)) {\r
+    StatusBarSetStatusString (L"Unknown Command");\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return (MenuItems[Index].Function ());\r
+}\r
+\r