TianoCore EDK2 master
Loading...
Searching...
No Matches
EditMenuBar.c
Go to the documentation of this file.
1
9#include "EditMenuBar.h"
11#include "EditStatusBar.h"
12
13EDITOR_MENU_ITEM *MenuItems;
14MENU_ITEM_FUNCTION *ControlBasedMenuFunctions;
15UINTN NumItems;
16
20VOID
22 VOID
23 )
24{
25 SHELL_FREE_NON_NULL (MenuItems);
26}
27
39 )
40{
41 CONST EDITOR_MENU_ITEM *ItemsWalker;
42
43 for (NumItems = 0, ItemsWalker = Items; ItemsWalker != NULL && ItemsWalker->Function != NULL; ItemsWalker++, NumItems++) {
44 }
45
46 MenuItems = AllocateZeroPool ((NumItems+1) * sizeof (EDITOR_MENU_ITEM));
47 if (MenuItems == NULL) {
48 return EFI_OUT_OF_RESOURCES;
49 }
50
51 CopyMem (MenuItems, Items, (NumItems+1) * sizeof (EDITOR_MENU_ITEM));
52 return EFI_SUCCESS;
53}
54
64 IN MENU_ITEM_FUNCTION *Items
65 )
66{
67 ControlBasedMenuFunctions = Items;
68 return EFI_SUCCESS;
69}
70
81 IN CONST UINTN LastRow,
82 IN CONST UINTN LastCol
83 )
84{
85 EDITOR_MENU_ITEM *Item;
86 UINTN Col;
87 UINTN Row;
88 UINTN Width;
89 CHAR16 *NameString;
90 CHAR16 *FunctionKeyString;
91
92 //
93 // variable initialization
94 //
95 Col = 1;
96 Row = (LastRow - 2);
97
98 //
99 // clear menu bar rows
100 //
101 EditorClearLine (LastRow - 2, LastCol, LastRow);
102 EditorClearLine (LastRow - 1, LastCol, LastRow);
103 EditorClearLine (LastRow, LastCol, LastRow);
104
105 //
106 // print out the menu items
107 //
108 for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {
109 NameString = HiiGetString (gShellDebug1HiiHandle, Item->NameToken, NULL);
110 if (NameString == NULL) {
111 return EFI_INVALID_PARAMETER;
112 }
113
114 Width = MAX ((StrLen (NameString) + 6), 20);
115 if (((Col + Width) > LastCol)) {
116 Row++;
117 Col = 1;
118 }
119
120 FunctionKeyString = HiiGetString (gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);
121 if (FunctionKeyString == NULL) {
122 FreePool (NameString);
123 return EFI_INVALID_PARAMETER;
124 }
125
126 ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString);
127
128 FreePool (NameString);
129 FreePool (FunctionKeyString);
130 Col += Width;
131 }
132
133 return EFI_SUCCESS;
134}
135
148 )
149{
150 UINTN Index;
151
152 Index = Key->ScanCode - SCAN_F1;
153
154 //
155 // check whether in range
156 //
157 if (Index > (NumItems - 1)) {
158 StatusBarSetStatusString (L"Unknown Command");
159 return EFI_SUCCESS;
160 }
161
162 return (MenuItems[Index].Function ());
163}
164
176 IN CONST EFI_KEY_DATA *KeyData
177 )
178{
179 UINT16 ControlIndex;
180
181 //
182 // Set to invalid value first.
183 //
184 ControlIndex = MAX_UINT16;
185
186 if (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) ||
187 (KeyData->KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID))
188 {
189 //
190 // For consoles that don't support/report shift state,
191 // Ctrl+A is translated to 1 (UnicodeChar).
192 //
193 ControlIndex = KeyData->Key.UnicodeChar;
194 } else if (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) &&
195 ((KeyData->KeyState.KeyShiftState & (EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) != 0) &&
196 ((KeyData->KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) == 0))
197 {
198 //
199 // For consoles that supports/reports shift state,
200 // make sure only CONTROL is pressed.
201 //
202 if ((KeyData->Key.UnicodeChar >= L'A') && (KeyData->Key.UnicodeChar <= L'Z')) {
203 ControlIndex = KeyData->Key.UnicodeChar - L'A' + 1;
204 } else if ((KeyData->Key.UnicodeChar >= L'a') && (KeyData->Key.UnicodeChar <= L'z')) {
205 ControlIndex = KeyData->Key.UnicodeChar - L'a' + 1;
206 }
207 }
208
209 if ( (SCAN_CONTROL_Z < ControlIndex)
210 || (NULL == ControlBasedMenuFunctions[ControlIndex]))
211 {
212 return EFI_NOT_FOUND;
213 }
214
215 ControlBasedMenuFunctions[ControlIndex]();
216 return EFI_SUCCESS;
217}
UINT64 UINTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS MenuBarDispatchFunctionKey(IN CONST EFI_INPUT_KEY *Key)
Definition: EditMenuBar.c:146
EFI_STATUS MenuBarDispatchControlHotKey(IN CONST EFI_KEY_DATA *KeyData)
Definition: EditMenuBar.c:175
VOID MenuBarCleanup(VOID)
Definition: EditMenuBar.c:21
EFI_STATUS MenuBarInit(IN CONST EDITOR_MENU_ITEM *Items)
Definition: EditMenuBar.c:37
EFI_STATUS MenuBarRefresh(IN CONST UINTN LastRow, IN CONST UINTN LastCol)
Definition: EditMenuBar.c:80
EFI_STATUS ControlHotKeyInit(IN MENU_ITEM_FUNCTION *Items)
Definition: EditMenuBar.c:63
EFI_STATUS StatusBarSetStatusString(IN CHAR16 *Str)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define MAX(a, b)
Definition: Base.h:992
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID EditorClearLine(IN UINTN Row, IN UINTN LastCol, IN UINTN LastRow)