]> git.proxmox.com Git - mirror_edk2.git/commitdiff
add Edit and Hexedit shared features.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Mar 2011 21:15:26 +0000 (21:15 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Mar 2011 21:15:26 +0000 (21:15 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11437 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c [new file with mode: 0644]
ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h [new file with mode: 0644]
ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c [new file with mode: 0644]
ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h [new file with mode: 0644]
ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c [new file with mode: 0644]
ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.h [new file with mode: 0644]
ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c [new file with mode: 0644]
ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.h [new file with mode: 0644]

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c
new file mode 100644 (file)
index 0000000..2c74e06
--- /dev/null
@@ -0,0 +1,330 @@
+/** @file\r
+  Implements inputbar 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 "EditInputBar.h"\r
+#include "UefiShellDebug1CommandsLib.h"\r
+\r
+CHAR16  *mPrompt;        // Input bar mPrompt string.\r
+CHAR16  *mReturnString;  // The returned string.\r
+UINTN   StringSize;      // Size of mReturnString space size.\r
+\r
+/**\r
+  Initialize the input bar.\r
+**/\r
+VOID\r
+EFIAPI\r
+InputBarInit (\r
+  VOID\r
+  )\r
+{\r
+  mPrompt       = NULL;\r
+  mReturnString = NULL;\r
+  StringSize    = 0;\r
+}\r
+\r
+/**\r
+  Cleanup function for input bar.\r
+**/\r
+VOID\r
+EFIAPI\r
+InputBarCleanup (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // free input bar's prompt and input string\r
+  //\r
+  SHELL_FREE_NON_NULL (mPrompt);\r
+  SHELL_FREE_NON_NULL (mReturnString);\r
+  mPrompt       = NULL;\r
+  mReturnString = NULL;\r
+}\r
+\r
+/**\r
+  Display the prompt.\r
+  Do the requesting of input.\r
+\r
+  @param[in]  LastColumn   The last printable column.\r
+  @param[in]  LastRow      The last printable row.\r
+**/\r
+VOID\r
+EFIAPI\r
+InputBarPrintInput (\r
+  IN UINTN LastColumn,\r
+  IN UINTN LastRow\r
+  )\r
+{\r
+  UINTN   Limit;\r
+  UINTN   Size;\r
+  CHAR16  *Buffer;\r
+  UINTN   Index;\r
+  UINTN   mPromptLen;\r
+\r
+  mPromptLen = StrLen (mPrompt);\r
+  Limit     = LastColumn - mPromptLen - 1;\r
+  Size      = StrLen (mReturnString);\r
+\r
+  //\r
+  // check whether the mPrompt length and input length will\r
+  // exceed limit\r
+  //\r
+  if (Size <= Limit) {\r
+    Buffer = mReturnString;\r
+  } else {\r
+    Buffer = mReturnString + Size - Limit;\r
+  }\r
+\r
+  gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
+\r
+  ShellPrintEx (((INT32)mPromptLen), ((INT32)LastRow) - 4, L"%s", Buffer);\r
+  Size = StrLen (Buffer);\r
+\r
+  //\r
+  // print " " after mPrompt\r
+  //\r
+  for (Index = Size; Index < Limit; Index++) {\r
+    ShellPrintEx ((INT32)(mPromptLen + Size), ((INT32)LastRow) - 4, L" ");\r
+  }\r
+\r
+  gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+  gST->ConOut->SetCursorPosition (gST->ConOut, Size + mPromptLen, LastRow - 4);\r
+}\r
+\r
+typedef struct {\r
+  UINT32  Foreground : 4;\r
+  UINT32  Background : 4;\r
+} INPUT_BAR_COLOR_ATTRIBUTES;\r
+\r
+typedef union {\r
+  INPUT_BAR_COLOR_ATTRIBUTES  Colors;\r
+  UINTN                       Data;\r
+} INPUT_BAR_COLOR_UNION;\r
+\r
+\r
+/**\r
+  The refresh function for InputBar, it will wait for user input\r
+\r
+  @param[in] LastRow            The last printable row.\r
+  @param[in] LastColumn         The last printable column.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InputBarRefresh (\r
+  UINTN LastRow,\r
+  UINTN LastColumn\r
+  )\r
+{\r
+  INPUT_BAR_COLOR_UNION   Orig;\r
+  INPUT_BAR_COLOR_UNION   New;\r
+  EFI_INPUT_KEY           Key;\r
+  UINTN                   Size;\r
+  EFI_STATUS              Status;\r
+  BOOLEAN                 NoDisplay;\r
+  UINTN                   Limit;\r
+  UINTN                   mPromptLen;\r
+  UINTN                   EventIndex;\r
+  UINTN                   CursorRow;\r
+  UINTN                   CursorCol;\r
+\r
+  //\r
+  // variable initialization\r
+  //\r
+  Size    = 0;\r
+  Status  = EFI_SUCCESS;\r
+\r
+  //\r
+  // back up the old screen attributes\r
+  //\r
+  CursorCol             = gST->ConOut->Mode->CursorColumn;\r
+  CursorRow             = gST->ConOut->Mode->CursorRow;\r
+  Orig.Data             = gST->ConOut->Mode->Attribute;\r
+  New.Colors.Foreground = Orig.Colors.Background;\r
+  New.Colors.Background = Orig.Colors.Foreground;\r
+\r
+  gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+\r
+  //\r
+  // clear input bar\r
+  //\r
+  EditorClearLine (LastRow - 3, LastColumn, LastRow);\r
+\r
+  gST->ConOut->SetCursorPosition (gST->ConOut, 0, LastRow - 4);\r
+  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR), gShellDebug1HiiHandle, mPrompt);\r
+\r
+  //\r
+  // that's the maximum input length that can be displayed on screen\r
+  //\r
+  mPromptLen = StrLen (mPrompt);\r
+  Limit     = LastColumn - mPromptLen;\r
+\r
+  //\r
+  // this is a selection mPrompt, cursor will stay in edit area\r
+  // actually this is for search , search/replace\r
+  //\r
+  if (StrStr (mPrompt, L"Yes/No")) {\r
+    NoDisplay = TRUE;\r
+    gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);\r
+    gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+  } else {\r
+    NoDisplay = FALSE;\r
+  }\r
+  //\r
+  // wait for user input\r
+  //\r
+  for (;;) {\r
+    gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
+    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+    //\r
+    // pressed ESC\r
+    //\r
+    if (Key.ScanCode == SCAN_ESC) {\r
+      Size    = 0;\r
+      Status  = EFI_NOT_READY;\r
+      break;\r
+    }\r
+    //\r
+    // return pressed\r
+    //\r
+    if (Key.UnicodeChar == CHAR_LINEFEED || Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
+      break;\r
+    } else if (Key.UnicodeChar == CHAR_BACKSPACE) {\r
+      //\r
+      // backspace\r
+      //\r
+      if (Size > 0) {\r
+        Size--;\r
+        mReturnString[Size] = CHAR_NULL;\r
+        if (!NoDisplay) {\r
+\r
+          InputBarPrintInput (LastColumn, LastRow);\r
+\r
+        }\r
+      }\r
+    } else if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) {\r
+      //\r
+      // VALID ASCII char pressed\r
+      //\r
+      mReturnString[Size] = Key.UnicodeChar;\r
+\r
+      //\r
+      // should be less than specified length\r
+      //\r
+      if (Size >= StringSize) {\r
+        continue;\r
+      }\r
+\r
+      Size++;\r
+\r
+      mReturnString[Size] = CHAR_NULL;\r
+\r
+      if (!NoDisplay) {\r
+\r
+        InputBarPrintInput (LastColumn, LastRow);\r
+\r
+      } else {\r
+        //\r
+        // if just choose yes/no\r
+        //\r
+        break;\r
+      }\r
+\r
+    }\r
+  }\r
+\r
+  mReturnString[Size] = CHAR_NULL;\r
+  \r
+\r
+  //\r
+  // restore screen attributes\r
+  //\r
+  gST->ConOut->SetCursorPosition (gST->ConOut, CursorCol, CursorRow);\r
+  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  SetPrompt and wait for input.\r
+\r
+  @param[in] Str                The prompt string.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InputBarSetPrompt (\r
+  IN CONST CHAR16 *Str\r
+  )\r
+{\r
+  //\r
+  // FREE the old mPrompt string\r
+  //\r
+  SHELL_FREE_NON_NULL (mPrompt);\r
+\r
+  mPrompt = CatSPrint (NULL, L"%s ", Str);\r
+  if (mPrompt == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Set the size of the string in characters.\r
+\r
+  @param[in] Size               The max number of characters to accept.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InputBarSetStringSize (\r
+  UINTN   Size\r
+  )\r
+{\r
+  //\r
+  // free the old ReturnStirng\r
+  //\r
+  SHELL_FREE_NON_NULL (mReturnString);\r
+\r
+  StringSize = Size;\r
+  mReturnString = AllocateZeroPool ((StringSize + 1) * sizeof(mReturnString[0]));\r
+  if (mReturnString == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to retrieve the input from the user.\r
+\r
+  @retval NULL                  No input has been received.\r
+  @return The string that was input.\r
+**/\r
+CONST CHAR16*\r
+EFIAPI\r
+InputBarGetString (\r
+  VOID\r
+  )\r
+{\r
+  return (mReturnString);\r
+}\r
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.h
new file mode 100644 (file)
index 0000000..c8557a8
--- /dev/null
@@ -0,0 +1,91 @@
+/** @file\r
+  Declares imputbar 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
+#ifndef _LIB_INPUT_BAR_H_\r
+#define _LIB_INPUT_BAR_H_\r
+\r
+/**\r
+  Initialize the input bar.\r
+**/\r
+VOID\r
+EFIAPI\r
+InputBarInit (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Cleanup function for input bar.\r
+**/\r
+VOID\r
+EFIAPI\r
+InputBarCleanup (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  The refresh function for InputBar, it will wait for user input\r
+\r
+  @param[in] LastRow            The last printable row.\r
+  @param[in] LastColumn         The last printable column.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InputBarRefresh (\r
+  UINTN LastRow,\r
+  UINTN LastColumn\r
+  );\r
+\r
+/**\r
+  SetPrompt and wait for input.\r
+\r
+  @param[in] Str                The prompt string.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InputBarSetPrompt (\r
+  IN CONST CHAR16 *Str\r
+  );\r
+\r
+/**\r
+  Set the size of the string in characters.\r
+\r
+  @param[in] Size               The max number of characters to accept.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InputBarSetStringSize (\r
+  UINTN   Size\r
+  );\r
+\r
+/**\r
+  Function to retrieve the input from the user.\r
+\r
+  @retval NULL                  No input has been received.\r
+  @return The string that was input.\r
+**/\r
+CONST CHAR16*\r
+EFIAPI\r
+InputBarGetString (\r
+  VOID\r
+  );\r
+\r
+#endif\r
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
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.h
new file mode 100644 (file)
index 0000000..407f259
--- /dev/null
@@ -0,0 +1,83 @@
+/** @file\r
+  Declares 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
+#ifndef _LIB_MENU_BAR_H_\r
+#define _LIB_MENU_BAR_H_\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *MENU_ITEM_FUNCTION) (\r
+  VOID\r
+  );\r
+\r
+typedef struct _EDITOR_MENU_ITEM {\r
+  EFI_STRING_ID           NameToken;\r
+  CHAR16                  FunctionKeyToken;\r
+  MENU_ITEM_FUNCTION  Function;\r
+} EDITOR_MENU_ITEM;\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
+/**\r
+  Cleanup function for a menu bar.  frees all allocated memory.\r
+**/\r
+VOID\r
+EFIAPI\r
+MenuBarCleanup (\r
+  VOID\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
+/**\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
+#endif\r
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c
new file mode 100644 (file)
index 0000000..3fd604d
--- /dev/null
@@ -0,0 +1,227 @@
+/** @file\r
+  Implements statusbar 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 "EditStatusBar.h"\r
+#include "UefiShellDebug1CommandsLib.h"\r
+\r
+CHAR16  *StatusString;\r
+BOOLEAN StatusBarNeedRefresh;\r
+BOOLEAN StatusStringChanged;\r
+\r
+/**\r
+  Initialization function for Status Bar.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+  @sa StatusBarSetStatusString\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StatusBarInit (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // initialize the statusbar\r
+  //\r
+  StatusString         = NULL;\r
+  StatusBarNeedRefresh = TRUE;\r
+  StatusStringChanged  = FALSE;\r
+\r
+  //\r
+  // status string set to ""\r
+  //\r
+  return (StatusBarSetStatusString (L""));\r
+}\r
+\r
+/**\r
+  Cleanup function for the status bar.\r
+**/\r
+VOID\r
+EFIAPI\r
+StatusBarCleanup (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // free the status string and backvar's status string\r
+  //\r
+  SHELL_FREE_NON_NULL (StatusString);\r
+}\r
+\r
+typedef struct {\r
+  UINT32  Foreground : 4;\r
+  UINT32  Background : 4;\r
+} STATUS_BAR_COLOR_ATTRIBUTES;\r
+\r
+typedef union {\r
+  STATUS_BAR_COLOR_ATTRIBUTES  Colors;\r
+  UINTN                       Data;\r
+} STATUS_BAR_COLOR_UNION;\r
+\r
+/**\r
+  Cause the status bar to refresh it's printing on the screen.\r
+\r
+  @param[in] EditorFirst      TRUE to indicate the first launch of the editor.  \r
+                              FALSE otherwise.\r
+  @param[in] LastRow          LastPrintable row.\r
+  @param[in] LastCol          Last printable column.\r
+  @param[in] FileRow          Row in the file.\r
+  @param[in] FileCol          Column in the file.\r
+  @param[in] InsertMode       TRUE to indicate InsertMode.  FALSE otherwise.\r
+\r
+  @retval EFI_SUCCESS         The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StatusBarRefresh (\r
+  IN BOOLEAN  EditorFirst,\r
+  IN UINTN    LastRow,\r
+  IN UINTN    LastCol,\r
+  IN UINTN    FileRow,\r
+  IN UINTN    FileCol,\r
+  IN BOOLEAN  InsertMode\r
+  )\r
+{\r
+  STATUS_BAR_COLOR_UNION  Orig;\r
+  STATUS_BAR_COLOR_UNION  New;\r
+\r
+  if (!StatusStringChanged && StatusBarNeedRefresh) {\r
+    StatusBarSetStatusString (L"\0");\r
+  }\r
+  //\r
+  // when it's called first time after editor launch, so refresh is mandatory\r
+  //\r
+  if (!StatusBarNeedRefresh && !StatusStringChanged) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // back up the screen attributes\r
+  //\r
+  Orig.Data             = gST->ConOut->Mode->Attribute;\r
+  New.Colors.Foreground = Orig.Colors.Background;\r
+  New.Colors.Background = Orig.Colors.Foreground;\r
+\r
+  gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
+  gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+\r
+  //\r
+  // clear status bar\r
+  //\r
+  EditorClearLine (LastRow - 3, LastCol, LastRow);\r
+\r
+  //\r
+  // print row, column fields\r
+  //\r
+  ShellPrintEx (\r
+    0,\r
+    (INT32)(LastRow) - 4,\r
+    L"  Row: %d  Col: %d       %s",\r
+    FileRow,\r
+    FileCol,\r
+    StatusString\r
+    );\r
+\r
+  //\r
+  // print insert mode field\r
+  //\r
+  if (InsertMode) {\r
+    ShellPrintEx ((INT32)(LastCol) - 10, (INT32)(LastRow) - 4, L"|%s|", L"INS");\r
+  } else {\r
+    ShellPrintEx ((INT32)(LastCol) - 10, (INT32)(LastRow) - 4, L"|%s|", L"OVR");\r
+  }\r
+  //\r
+  // restore the old screen attributes\r
+  //\r
+  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+\r
+  //\r
+  // restore position in edit area\r
+  //\r
+  gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
+\r
+  StatusBarNeedRefresh  = FALSE;\r
+  StatusStringChanged   = FALSE;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Set the status string text part.\r
+\r
+  @param[in] Str                The string to use.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StatusBarSetStatusString (\r
+  IN CHAR16 *Str\r
+  )\r
+{\r
+  StatusStringChanged = TRUE;\r
+\r
+  //\r
+  // free the old status string\r
+  //\r
+  SHELL_FREE_NON_NULL (StatusString);\r
+  StatusString = CatSPrint (NULL, L"%s", Str);\r
+  if (StatusString == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to retrieve the current status string.\r
+\r
+  @return The string that is used.\r
+**/\r
+CONST CHAR16*\r
+EFIAPI\r
+StatusBarGetString (\r
+  VOID\r
+  )\r
+{\r
+  return (StatusString);\r
+}\r
+\r
+/**\r
+  Function to set the need refresh boolean to TRUE.\r
+**/\r
+VOID\r
+EFIAPI\r
+StatusBarSetRefresh(\r
+  VOID\r
+  )\r
+{\r
+  StatusBarNeedRefresh = TRUE;\r
+}\r
+\r
+/**\r
+  Function to get the need refresh boolean to TRUE.\r
+\r
+  @retval TRUE    The status bar needs to be refreshed.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+StatusBarGetRefresh(\r
+  VOID\r
+  )\r
+{\r
+  return (StatusBarNeedRefresh);\r
+}\r
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.h
new file mode 100644 (file)
index 0000000..debf83a
--- /dev/null
@@ -0,0 +1,109 @@
+/** @file\r
+  Declares statusbar 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
+#ifndef _LIB_STATUS_BAR_H_\r
+#define _LIB_STATUS_BAR_H_\r
+\r
+/**\r
+  Initialization function for Status Bar.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+  @sa StatusBarSetStatusString\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StatusBarInit (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Cleanup function for the status bar.\r
+**/\r
+VOID\r
+EFIAPI\r
+StatusBarCleanup (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Cause the status bar to refresh it's printing on the screen.\r
+\r
+  @param[in] EditorFirst      TRUE to indicate the first launch of the editor.  \r
+                              FALSE otherwise.\r
+  @param[in] LastRow          LastPrintable row.\r
+  @param[in] LastCol          Last printable column.\r
+  @param[in] FileRow          Row in the file.\r
+  @param[in] FileCol          Column in the file.\r
+  @param[in] InsertMode       TRUE to indicate InsertMode.  FALSE otherwise.\r
+\r
+  @retval EFI_SUCCESS         The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StatusBarRefresh (\r
+  IN BOOLEAN  EditorFirst,\r
+  IN UINTN    LastRow,\r
+  IN UINTN    LastCol,\r
+  IN UINTN    FileRow,\r
+  IN UINTN    FileCol,\r
+  IN BOOLEAN  InsertMode\r
+  );\r
+\r
+/**\r
+  Set the status string text part.\r
+\r
+  @param[in] Str                The string to use.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StatusBarSetStatusString (\r
+  IN CHAR16 *Str\r
+  );\r
+\r
+/**\r
+  Function to retrieve the current status string.\r
+\r
+  @return The string that is used.\r
+**/\r
+CONST CHAR16*\r
+EFIAPI\r
+StatusBarGetString (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Function to set the need refresh boolean to TRUE.\r
+**/\r
+VOID\r
+EFIAPI\r
+StatusBarSetRefresh(\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Function to get the need refresh boolean to TRUE.\r
+\r
+  @retval TRUE    The status bar needs to be refreshed.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+StatusBarGetRefresh(\r
+  VOID\r
+  );\r
+\r
+#endif\r
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c
new file mode 100644 (file)
index 0000000..1f71c8b
--- /dev/null
@@ -0,0 +1,200 @@
+/** @file\r
+  Implements titlebar 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 "EditTitleBar.h"\r
+#include "UefiShellDebug1CommandsLib.h"\r
+\r
+CHAR16  *Title = NULL;\r
+\r
+/**\r
+  Initialize a title bar.\r
+\r
+  @param[in] Prompt             The prompt to print in the title bar.\r
+\r
+  @retval EFI_SUCCESS           The initialization was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MainTitleBarInit (\r
+  CONST CHAR16 *Prompt\r
+  )\r
+{\r
+  SHELL_FREE_NON_NULL (Title);\r
+  if (Prompt == NULL) {\r
+    Title = CatSPrint (NULL, L"");\r
+  } else {\r
+    //\r
+    // set Title\r
+    //\r
+    Title = CatSPrint (NULL, L"%s", Prompt);\r
+  }\r
+  if (Title == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Clean up the memory used.\r
+**/\r
+VOID\r
+EFIAPI\r
+MainTitleBarCleanup (\r
+  VOID\r
+  )\r
+{\r
+  SHELL_FREE_NON_NULL (Title);\r
+  Title = NULL;\r
+}\r
+\r
+typedef struct {\r
+  UINT32  Foreground : 4;\r
+  UINT32  Background : 4;\r
+} TITLE_BAR_COLOR_ATTRIBUTES;\r
+\r
+typedef union {\r
+  TITLE_BAR_COLOR_ATTRIBUTES  Colors;\r
+  UINTN                       Data;\r
+} TITLE_BAR_COLOR_UNION;\r
+\r
+/**\r
+  Refresh function for MainTitleBar\r
+\r
+  @param[in] FileName           The open file's name (or NULL).\r
+  @param[in] FileType           The type fo the file.\r
+  @param[in] ReadOnly           TRUE if the file is read only.  FALSE otherwise.\r
+  @param[in] Modified           TRUE if the file was modified.  FALSE otherwise.\r
+  @param[in] LastCol            The last printable column.\r
+  @param[in] LastRow            The last printable row.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MainTitleBarRefresh (\r
+  IN CONST CHAR16                 *FileName OPTIONAL,\r
+  IN CONST EDIT_FILE_TYPE         FileType,\r
+  IN BOOLEAN                      ReadOnly,\r
+  IN BOOLEAN                      Modified,\r
+  IN UINTN                        LastCol,\r
+  IN UINTN                        LastRow\r
+  )\r
+{\r
+  TITLE_BAR_COLOR_UNION   Orig;\r
+  TITLE_BAR_COLOR_UNION   New;\r
+  CONST CHAR16            *FileNameTmp;\r
+  INTN                    TempInteger;\r
+\r
+\r
+  //\r
+  // backup the old screen attributes\r
+  //\r
+  Orig.Data             = gST->ConOut->Mode->Attribute;\r
+  New.Colors.Foreground = Orig.Colors.Background;\r
+  New.Colors.Background = Orig.Colors.Foreground;\r
+\r
+  gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+\r
+  //\r
+  // clear the title line\r
+  //\r
+  EditorClearLine (1, LastCol, LastRow);\r
+\r
+  if (Title != NULL) {\r
+    //\r
+    // print the new title bar prefix\r
+    //\r
+    ShellPrintEx (\r
+      0,\r
+      0,\r
+      L"%s ",\r
+      Title\r
+      );\r
+  }\r
+  if (FileName == NULL) {\r
+    gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // First Extract the FileName from fullpath\r
+  //\r
+  FileNameTmp = FileName;\r
+  for (TempInteger = StrLen (FileNameTmp) - 1; TempInteger >= 0; TempInteger--) {\r
+    if (FileNameTmp[TempInteger] == L'\\') {\r
+      break;\r
+    }\r
+  }\r
+\r
+  FileNameTmp = FileNameTmp + TempInteger + 1;\r
+\r
+  //\r
+  // the space for file name is 20 characters\r
+  //\r
+  if (StrLen (FileNameTmp) <= 20) {\r
+    ShellPrintEx (-1,-1, L"%s   ", FileNameTmp);\r
+    for (TempInteger = StrLen (FileNameTmp); TempInteger < 20; TempInteger++) {\r
+      ShellPrintEx (-1,-1, L" ");\r
+    }\r
+\r
+  } else {\r
+    for (TempInteger = 0; TempInteger < 17; TempInteger++) {\r
+      ShellPrintEx (-1,-1, L"%c", FileNameTmp[TempInteger]);\r
+    }\r
+    //\r
+    // print "..."\r
+    //\r
+    ShellPrintEx (-1,-1, L"...   ");\r
+  }\r
+  //\r
+  // print file type field\r
+  //\r
+  switch (FileType){\r
+    case FileTypeAscii:\r
+    case FileTypeUnicode:\r
+      if (FileType == FileTypeAscii){\r
+        ShellPrintEx (-1,-1, L"     UNICODE   ");\r
+      }\r
+      //\r
+      // print read-only field for text files\r
+      //\r
+      if (ReadOnly) {\r
+        ShellPrintEx (-1,-1, L"ReadOnly   ");\r
+      } else {\r
+        ShellPrintEx (-1,-1, L"           ");\r
+      }\r
+    break;\r
+    case FileTypeDiskBuffer:\r
+    case FileTypeMemBuffer:\r
+      //\r
+      // Print the offset.\r
+      //\r
+      ASSERT(FALSE);\r
+    case FileTypeFileBuffer:\r
+      break;\r
+  }\r
+  //\r
+  // print modified field\r
+  //\r
+  if (Modified) {\r
+    ShellPrintEx (-1,-1, L"Modified");\r
+  }\r
+  //\r
+  // restore the old attribute\r
+  //\r
+  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.h
new file mode 100644 (file)
index 0000000..908b5a3
--- /dev/null
@@ -0,0 +1,73 @@
+/** @file\r
+  Declares titlebar 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
+#ifndef _LIB_TITLE_BAR_H_\r
+#define _LIB_TITLE_BAR_H_\r
+\r
+/**\r
+  Initialize a title bar.\r
+\r
+  @param[in] Prompt             The prompt to print in the title bar.\r
+\r
+  @retval EFI_SUCCESS           The initialization was successful.\r
+  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MainTitleBarInit (\r
+  CONST CHAR16 *Prompt\r
+  );\r
+\r
+/**\r
+  Clean up the memory used.\r
+**/\r
+VOID\r
+EFIAPI\r
+MainTitleBarCleanup (\r
+  VOID\r
+  );\r
+\r
+typedef enum {\r
+  FileTypeNone,\r
+  FileTypeAscii,\r
+  FileTypeUnicode,\r
+  FileTypeDiskBuffer,\r
+  FileTypeMemBuffer,\r
+  FileTypeFileBuffer\r
+} EDIT_FILE_TYPE;\r
+\r
+/**\r
+  Refresh function for MainTitleBar\r
+\r
+  @param[in] FileName           The open file's name (or NULL).\r
+  @param[in] FileType           The type fo the file.\r
+  @param[in] ReadOnly           TRUE if the file is read only.  FALSE otherwise.\r
+  @param[in] Modified           TRUE if the file was modified.  FALSE otherwise.\r
+  @param[in] LastCol            The last printable column.\r
+  @param[in] LastRow            The last printable row.\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MainTitleBarRefresh (\r
+  IN CONST CHAR16                 *FileName OPTIONAL,\r
+  IN CONST EDIT_FILE_TYPE         FileType,\r
+  IN BOOLEAN                      ReadOnly,\r
+  IN BOOLEAN                      Modified,\r
+  IN UINTN                        LastCol,\r
+  IN UINTN                        LastRow\r
+  );\r
+\r
+#endif\r