2 implements menubar interface functions.
4 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "EditMenuBar.h"
10 #include "UefiShellDebug1CommandsLib.h"
11 #include "EditStatusBar.h"
13 EDITOR_MENU_ITEM
*MenuItems
;
14 MENU_ITEM_FUNCTION
*ControlBasedMenuFunctions
;
18 Cleanup function for a menu bar. frees all allocated memory.
25 SHELL_FREE_NON_NULL(MenuItems
);
29 Initialize the menu bar with the specified items.
31 @param[in] Items The items to display and their functions.
33 @retval EFI_SUCCESS The initialization was correct.
34 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
38 IN CONST EDITOR_MENU_ITEM
*Items
41 CONST EDITOR_MENU_ITEM
*ItemsWalker
;
43 for (NumItems
= 0, ItemsWalker
= Items
; ItemsWalker
!= NULL
&& ItemsWalker
->Function
!= NULL
; ItemsWalker
++,NumItems
++);
45 MenuItems
= AllocateZeroPool((NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
46 if (MenuItems
== NULL
) {
47 return EFI_OUT_OF_RESOURCES
;
49 CopyMem(MenuItems
, Items
, (NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
54 Initialize the control hot-key with the specified items.
56 @param[in] Items The hot-key functions.
58 @retval EFI_SUCCESS The initialization was correct.
62 IN MENU_ITEM_FUNCTION
*Items
65 ControlBasedMenuFunctions
= Items
;
69 Refresh function for the menu bar.
71 @param[in] LastRow The last printable row.
72 @param[in] LastCol The last printable column.
74 @retval EFI_SUCCESS The refresh was successful.
78 IN CONST UINTN LastRow
,
79 IN CONST UINTN LastCol
82 EDITOR_MENU_ITEM
*Item
;
87 CHAR16
*FunctionKeyString
;
90 // variable initialization
96 // clear menu bar rows
98 EditorClearLine (LastRow
- 2, LastCol
, LastRow
);
99 EditorClearLine (LastRow
- 1, LastCol
, LastRow
);
100 EditorClearLine (LastRow
, LastCol
, LastRow
);
104 // print out the menu items
106 for (Item
= MenuItems
; Item
!= NULL
&& Item
->Function
!= NULL
; Item
++) {
109 NameString
= HiiGetString(gShellDebug1HiiHandle
, Item
->NameToken
, NULL
);
112 Width
= MAX ((StrLen (NameString
) + 6), 20);
113 if (((Col
+ Width
) > LastCol
)) {
118 FunctionKeyString
= HiiGetString(gShellDebug1HiiHandle
, Item
->FunctionKeyToken
, NULL
);
120 ShellPrintEx ((INT32
)(Col
) - 1, (INT32
)(Row
) - 1, L
"%E%s%N %H%s%N ", FunctionKeyString
, NameString
);
122 FreePool (NameString
);
123 FreePool (FunctionKeyString
);
131 Function to dispatch the correct function based on a function key (F1...)
133 @param[in] Key The pressed key.
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.
140 MenuBarDispatchFunctionKey (
141 IN CONST EFI_INPUT_KEY
*Key
146 Index
= Key
->ScanCode
- SCAN_F1
;
149 // check whether in range
151 if (Index
> (NumItems
- 1)) {
152 StatusBarSetStatusString (L
"Unknown Command");
156 return (MenuItems
[Index
].Function ());
160 Function to dispatch the correct function based on a control-based key (ctrl+o...)
162 @param[in] KeyData The pressed key.
164 @retval EFI_NOT_FOUND The key was not a valid control-based key
165 (an error was sent to the status bar).
169 MenuBarDispatchControlHotKey (
170 IN CONST EFI_KEY_DATA
*KeyData
176 // Set to invalid value first.
178 ControlIndex
= MAX_UINT16
;
180 if (((KeyData
->KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) == 0) ||
181 (KeyData
->KeyState
.KeyShiftState
== EFI_SHIFT_STATE_VALID
)) {
183 // For consoles that don't support/report shift state,
184 // Ctrl+A is translated to 1 (UnicodeChar).
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)) {
191 // For consoles that supports/reports shift state,
192 // make sure only CONTROL is pressed.
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;
200 if ((SCAN_CONTROL_Z
< ControlIndex
)
201 ||(NULL
== ControlBasedMenuFunctions
[ControlIndex
]))
203 return EFI_NOT_FOUND
;
206 ControlBasedMenuFunctions
[ControlIndex
]();