2 implements menubar interface functions.
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
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.
15 #include "EditMenuBar.h"
16 #include "UefiShellDebug1CommandsLib.h"
17 #include "EditStatusBar.h"
19 EDITOR_MENU_ITEM
*MenuItems
;
20 MENU_ITEM_FUNCTION
*ControlBasedMenuFunctions
;
24 Cleanup function for a menu bar. frees all allocated memory.
31 SHELL_FREE_NON_NULL(MenuItems
);
35 Initialize the menu bar with the specified items.
37 @param[in] Items The items to display and their functions.
39 @retval EFI_SUCCESS The initialization was correct.
40 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
44 IN CONST EDITOR_MENU_ITEM
*Items
47 CONST EDITOR_MENU_ITEM
*ItemsWalker
;
49 for (NumItems
= 0, ItemsWalker
= Items
; ItemsWalker
!= NULL
&& ItemsWalker
->Function
!= NULL
; ItemsWalker
++,NumItems
++);
51 MenuItems
= AllocateZeroPool((NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
52 if (MenuItems
== NULL
) {
53 return EFI_OUT_OF_RESOURCES
;
55 CopyMem(MenuItems
, Items
, (NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
60 Initialize the control hot-key with the specified items.
62 @param[in] Items The hot-key functions.
64 @retval EFI_SUCCESS The initialization was correct.
68 IN MENU_ITEM_FUNCTION
*Items
71 ControlBasedMenuFunctions
= Items
;
75 Refresh function for the menu bar.
77 @param[in] LastRow The last printable row.
78 @param[in] LastCol The last printable column.
80 @retval EFI_SUCCESS The refresh was successful.
84 IN CONST UINTN LastRow
,
85 IN CONST UINTN LastCol
88 EDITOR_MENU_ITEM
*Item
;
93 CHAR16
*FunctionKeyString
;
96 // variable initialization
102 // clear menu bar rows
104 EditorClearLine (LastRow
- 2, LastCol
, LastRow
);
105 EditorClearLine (LastRow
- 1, LastCol
, LastRow
);
106 EditorClearLine (LastRow
, LastCol
, LastRow
);
110 // print out the menu items
112 for (Item
= MenuItems
; Item
!= NULL
&& Item
->Function
!= NULL
; Item
++) {
115 NameString
= HiiGetString(gShellDebug1HiiHandle
, Item
->NameToken
, NULL
);
118 Width
= MAX ((StrLen (NameString
) + 6), 20);
119 if (((Col
+ Width
) > LastCol
)) {
124 FunctionKeyString
= HiiGetString(gShellDebug1HiiHandle
, Item
->FunctionKeyToken
, NULL
);
126 ShellPrintEx ((INT32
)(Col
) - 1, (INT32
)(Row
) - 1, L
"%E%s%N %H%s%N ", FunctionKeyString
, NameString
);
128 FreePool (NameString
);
129 FreePool (FunctionKeyString
);
137 Function to dispatch the correct function based on a function key (F1...)
139 @param[in] Key The pressed key.
141 @retval EFI_NOT_FOUND The key was not a valid function key
142 (an error was sent to the status bar).
143 @return The return value from the called dispatch function.
146 MenuBarDispatchFunctionKey (
147 IN CONST EFI_INPUT_KEY
*Key
152 Index
= Key
->ScanCode
- SCAN_F1
;
155 // check whether in range
157 if (Index
> (NumItems
- 1)) {
158 StatusBarSetStatusString (L
"Unknown Command");
162 return (MenuItems
[Index
].Function ());
166 Function to dispatch the correct function based on a control-based key (ctrl+o...)
168 @param[in] Key The pressed key.
170 @retval EFI_NOT_FOUND The key was not a valid control-based key
171 (an error was sent to the status bar).
175 MenuBarDispatchControlHotKey (
176 IN CONST EFI_INPUT_KEY
*Key
180 if ((SCAN_CONTROL_Z
< Key
->UnicodeChar
)
181 ||(NULL
== ControlBasedMenuFunctions
[Key
->UnicodeChar
]))
183 return EFI_NOT_FOUND
;
186 ControlBasedMenuFunctions
[Key
->UnicodeChar
]();