]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c
add Edit and Hexedit shared features.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditMenuBar.c
1 /** @file
2 implements menubar interface functions.
3
4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "EditMenuBar.h"
16 #include "UefiShellDebug1CommandsLib.h"
17 #include "EditStatusBar.h"
18
19 EDITOR_MENU_ITEM *MenuItems;
20 UINTN NumItems;
21
22 /**
23 Cleanup function for a menu bar. frees all allocated memory.
24 **/
25 VOID
26 EFIAPI
27 MenuBarCleanup (
28 VOID
29 )
30 {
31 SHELL_FREE_NON_NULL(MenuItems);
32 }
33
34 /**
35 Initializa the menu bar with the specified items.
36
37 @param[in] Items The items to display and their functions.
38
39 @retval EFI_SUCCESS The initialization was correct.
40 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
41 **/
42 EFI_STATUS
43 EFIAPI
44 MenuBarInit (
45 IN CONST EDITOR_MENU_ITEM *Items
46 )
47 {
48 CONST EDITOR_MENU_ITEM *ItemsWalker;
49
50 for (NumItems = 0, ItemsWalker = Items ; ItemsWalker != NULL && ItemsWalker->Function != NULL ; ItemsWalker++,NumItems++);
51
52 MenuItems = AllocateZeroPool((NumItems+1) * sizeof(EDITOR_MENU_ITEM));
53 if (MenuItems == NULL) {
54 return EFI_OUT_OF_RESOURCES;
55 }
56 CopyMem(MenuItems, Items, (NumItems+1) * sizeof(EDITOR_MENU_ITEM));
57 return EFI_SUCCESS;
58 }
59
60 /**
61 Refresh function for the menu bar.
62
63 @param[in] LastRow The last printable row.
64 @param[in] LastCol The last printable column.
65
66 @retval EFI_SUCCESS The refresh was successful.
67 **/
68 EFI_STATUS
69 EFIAPI
70 MenuBarRefresh (
71 IN CONST UINTN LastRow,
72 IN CONST UINTN LastCol
73 )
74 {
75 EDITOR_MENU_ITEM *Item;
76 UINTN Col;
77 UINTN Row;
78 UINTN Width;
79 CHAR16 *NameString;
80 CHAR16 *FunctionKeyString;
81
82 //
83 // variable initialization
84 //
85 Col = 1;
86 Row = (LastRow - 2);
87
88 //
89 // clear menu bar rows
90 //
91 EditorClearLine (LastRow - 2, LastCol, LastRow);
92 EditorClearLine (LastRow - 1, LastCol, LastRow);
93 EditorClearLine (LastRow , LastCol, LastRow);
94
95
96 //
97 // print out the menu items
98 //
99 for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {
100
101
102 NameString = HiiGetString(gShellDebug1HiiHandle, Item->NameToken, NULL);
103
104
105 Width = MAX ((StrLen (NameString) + 6), 20);
106 if (((Col + Width) > LastCol)) {
107 Row++;
108 Col = 1;
109 }
110
111 FunctionKeyString = HiiGetString(gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);
112
113 ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString);
114
115 FreePool (NameString);
116 FreePool (FunctionKeyString);
117 Col += Width;
118 }
119
120 return EFI_SUCCESS;
121 }
122
123 /**
124 Function to dispatch the correct function based on a function key (F1...)
125
126 @param[in] Key The pressed key.
127
128 @retval EFI_NOT_FOUND The key was not a valid function key
129 (an error was sent to the status bar).
130 @return The return value from the called dispatch function.
131 **/
132 EFI_STATUS
133 EFIAPI
134 MenuBarDispatchFunctionKey (
135 IN CONST EFI_INPUT_KEY *Key
136 )
137 {
138 UINTN Index;
139
140 Index = Key->ScanCode - SCAN_F1;
141
142 //
143 // check whether in range
144 //
145 if (Index > (NumItems - 1)) {
146 StatusBarSetStatusString (L"Unknown Command");
147 return EFI_SUCCESS;
148 }
149
150 return (MenuItems[Index].Function ());
151 }
152