]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c
ShellPkg/UefiShellDebug1CommandsLib: Update to support SmBios 3.3.0
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditMenuBar.c
1 /** @file
2 implements menubar interface functions.
3
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "EditMenuBar.h"
10 #include "UefiShellDebug1CommandsLib.h"
11 #include "EditStatusBar.h"
12
13 EDITOR_MENU_ITEM *MenuItems;
14 MENU_ITEM_FUNCTION *ControlBasedMenuFunctions;
15 UINTN NumItems;
16
17 /**
18 Cleanup function for a menu bar. frees all allocated memory.
19 **/
20 VOID
21 MenuBarCleanup (
22 VOID
23 )
24 {
25 SHELL_FREE_NON_NULL(MenuItems);
26 }
27
28 /**
29 Initialize the menu bar with the specified items.
30
31 @param[in] Items The items to display and their functions.
32
33 @retval EFI_SUCCESS The initialization was correct.
34 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
35 **/
36 EFI_STATUS
37 MenuBarInit (
38 IN CONST EDITOR_MENU_ITEM *Items
39 )
40 {
41 CONST EDITOR_MENU_ITEM *ItemsWalker;
42
43 for (NumItems = 0, ItemsWalker = Items ; ItemsWalker != NULL && ItemsWalker->Function != NULL ; ItemsWalker++,NumItems++);
44
45 MenuItems = AllocateZeroPool((NumItems+1) * sizeof(EDITOR_MENU_ITEM));
46 if (MenuItems == NULL) {
47 return EFI_OUT_OF_RESOURCES;
48 }
49 CopyMem(MenuItems, Items, (NumItems+1) * sizeof(EDITOR_MENU_ITEM));
50 return EFI_SUCCESS;
51 }
52
53 /**
54 Initialize the control hot-key with the specified items.
55
56 @param[in] Items The hot-key functions.
57
58 @retval EFI_SUCCESS The initialization was correct.
59 **/
60 EFI_STATUS
61 ControlHotKeyInit (
62 IN MENU_ITEM_FUNCTION *Items
63 )
64 {
65 ControlBasedMenuFunctions = Items;
66 return EFI_SUCCESS;
67 }
68 /**
69 Refresh function for the menu bar.
70
71 @param[in] LastRow The last printable row.
72 @param[in] LastCol The last printable column.
73
74 @retval EFI_SUCCESS The refresh was successful.
75 **/
76 EFI_STATUS
77 MenuBarRefresh (
78 IN CONST UINTN LastRow,
79 IN CONST UINTN LastCol
80 )
81 {
82 EDITOR_MENU_ITEM *Item;
83 UINTN Col;
84 UINTN Row;
85 UINTN Width;
86 CHAR16 *NameString;
87 CHAR16 *FunctionKeyString;
88
89 //
90 // variable initialization
91 //
92 Col = 1;
93 Row = (LastRow - 2);
94
95 //
96 // clear menu bar rows
97 //
98 EditorClearLine (LastRow - 2, LastCol, LastRow);
99 EditorClearLine (LastRow - 1, LastCol, LastRow);
100 EditorClearLine (LastRow , LastCol, LastRow);
101
102
103 //
104 // print out the menu items
105 //
106 for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {
107
108
109 NameString = HiiGetString(gShellDebug1HiiHandle, Item->NameToken, NULL);
110
111
112 Width = MAX ((StrLen (NameString) + 6), 20);
113 if (((Col + Width) > LastCol)) {
114 Row++;
115 Col = 1;
116 }
117
118 FunctionKeyString = HiiGetString(gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);
119
120 ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString);
121
122 FreePool (NameString);
123 FreePool (FunctionKeyString);
124 Col += Width;
125 }
126
127 return EFI_SUCCESS;
128 }
129
130 /**
131 Function to dispatch the correct function based on a function key (F1...)
132
133 @param[in] Key The pressed key.
134
135 @retval EFI_NOT_FOUND The key was not a valid function key
136 (an error was sent to the status bar).
137 @return The return value from the called dispatch function.
138 **/
139 EFI_STATUS
140 MenuBarDispatchFunctionKey (
141 IN CONST EFI_INPUT_KEY *Key
142 )
143 {
144 UINTN Index;
145
146 Index = Key->ScanCode - SCAN_F1;
147
148 //
149 // check whether in range
150 //
151 if (Index > (NumItems - 1)) {
152 StatusBarSetStatusString (L"Unknown Command");
153 return EFI_SUCCESS;
154 }
155
156 return (MenuItems[Index].Function ());
157 }
158
159 /**
160 Function to dispatch the correct function based on a control-based key (ctrl+o...)
161
162 @param[in] KeyData The pressed key.
163
164 @retval EFI_NOT_FOUND The key was not a valid control-based key
165 (an error was sent to the status bar).
166 @return EFI_SUCCESS.
167 **/
168 EFI_STATUS
169 MenuBarDispatchControlHotKey (
170 IN CONST EFI_KEY_DATA *KeyData
171 )
172 {
173 UINT16 ControlIndex;
174
175 //
176 // Set to invalid value first.
177 //
178 ControlIndex = MAX_UINT16;
179
180 if (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) ||
181 (KeyData->KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID)) {
182 //
183 // For consoles that don't support/report shift state,
184 // Ctrl+A is translated to 1 (UnicodeChar).
185 //
186 ControlIndex = KeyData->Key.UnicodeChar;
187 } else if (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) &&
188 ((KeyData->KeyState.KeyShiftState & (EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) != 0) &&
189 ((KeyData->KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) == 0)) {
190 //
191 // For consoles that supports/reports shift state,
192 // make sure only CONTROL is pressed.
193 //
194 if ((KeyData->Key.UnicodeChar >= L'A') && (KeyData->Key.UnicodeChar <= L'Z')) {
195 ControlIndex = KeyData->Key.UnicodeChar - L'A' + 1;
196 } else if ((KeyData->Key.UnicodeChar >= L'a') && (KeyData->Key.UnicodeChar <= L'z')) {
197 ControlIndex = KeyData->Key.UnicodeChar - L'a' + 1;
198 }
199 }
200 if ((SCAN_CONTROL_Z < ControlIndex)
201 ||(NULL == ControlBasedMenuFunctions[ControlIndex]))
202 {
203 return EFI_NOT_FOUND;
204 }
205
206 ControlBasedMenuFunctions[ControlIndex]();
207 return EFI_SUCCESS;
208 }
209
210