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
++) {
46 MenuItems
= AllocateZeroPool ((NumItems
+1) * sizeof (EDITOR_MENU_ITEM
));
47 if (MenuItems
== NULL
) {
48 return EFI_OUT_OF_RESOURCES
;
51 CopyMem (MenuItems
, Items
, (NumItems
+1) * sizeof (EDITOR_MENU_ITEM
));
56 Initialize the control hot-key with the specified items.
58 @param[in] Items The hot-key functions.
60 @retval EFI_SUCCESS The initialization was correct.
64 IN MENU_ITEM_FUNCTION
*Items
67 ControlBasedMenuFunctions
= Items
;
72 Refresh function for the menu bar.
74 @param[in] LastRow The last printable row.
75 @param[in] LastCol The last printable column.
77 @retval EFI_SUCCESS The refresh was successful.
81 IN CONST UINTN LastRow
,
82 IN CONST UINTN LastCol
85 EDITOR_MENU_ITEM
*Item
;
90 CHAR16
*FunctionKeyString
;
93 // variable initialization
99 // clear menu bar rows
101 EditorClearLine (LastRow
- 2, LastCol
, LastRow
);
102 EditorClearLine (LastRow
- 1, LastCol
, LastRow
);
103 EditorClearLine (LastRow
, LastCol
, LastRow
);
106 // print out the menu items
108 for (Item
= MenuItems
; Item
!= NULL
&& Item
->Function
!= NULL
; Item
++) {
109 NameString
= HiiGetString (gShellDebug1HiiHandle
, Item
->NameToken
, NULL
);
111 Width
= MAX ((StrLen (NameString
) + 6), 20);
112 if (((Col
+ Width
) > LastCol
)) {
117 FunctionKeyString
= HiiGetString (gShellDebug1HiiHandle
, Item
->FunctionKeyToken
, NULL
);
119 ShellPrintEx ((INT32
)(Col
) - 1, (INT32
)(Row
) - 1, L
"%E%s%N %H%s%N ", FunctionKeyString
, NameString
);
121 FreePool (NameString
);
122 FreePool (FunctionKeyString
);
130 Function to dispatch the correct function based on a function key (F1...)
132 @param[in] Key The pressed key.
134 @retval EFI_NOT_FOUND The key was not a valid function key
135 (an error was sent to the status bar).
136 @return The return value from the called dispatch function.
139 MenuBarDispatchFunctionKey (
140 IN CONST EFI_INPUT_KEY
*Key
145 Index
= Key
->ScanCode
- SCAN_F1
;
148 // check whether in range
150 if (Index
> (NumItems
- 1)) {
151 StatusBarSetStatusString (L
"Unknown Command");
155 return (MenuItems
[Index
].Function ());
159 Function to dispatch the correct function based on a control-based key (ctrl+o...)
161 @param[in] KeyData The pressed key.
163 @retval EFI_NOT_FOUND The key was not a valid control-based key
164 (an error was sent to the status bar).
168 MenuBarDispatchControlHotKey (
169 IN CONST EFI_KEY_DATA
*KeyData
175 // Set to invalid value first.
177 ControlIndex
= MAX_UINT16
;
179 if (((KeyData
->KeyState
.KeyShiftState
& EFI_SHIFT_STATE_VALID
) == 0) ||
180 (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))
192 // For consoles that supports/reports shift state,
193 // make sure only CONTROL is pressed.
195 if ((KeyData
->Key
.UnicodeChar
>= L
'A') && (KeyData
->Key
.UnicodeChar
<= L
'Z')) {
196 ControlIndex
= KeyData
->Key
.UnicodeChar
- L
'A' + 1;
197 } else if ((KeyData
->Key
.UnicodeChar
>= L
'a') && (KeyData
->Key
.UnicodeChar
<= L
'z')) {
198 ControlIndex
= KeyData
->Key
.UnicodeChar
- L
'a' + 1;
202 if ( (SCAN_CONTROL_Z
< ControlIndex
)
203 || (NULL
== ControlBasedMenuFunctions
[ControlIndex
]))
205 return EFI_NOT_FOUND
;
208 ControlBasedMenuFunctions
[ControlIndex
]();