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.
32 SHELL_FREE_NON_NULL(MenuItems
);
36 Initialize the menu bar with the specified items.
38 @param[in] Items The items to display and their functions.
40 @retval EFI_SUCCESS The initialization was correct.
41 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
46 IN CONST EDITOR_MENU_ITEM
*Items
49 CONST EDITOR_MENU_ITEM
*ItemsWalker
;
51 for (NumItems
= 0, ItemsWalker
= Items
; ItemsWalker
!= NULL
&& ItemsWalker
->Function
!= NULL
; ItemsWalker
++,NumItems
++);
53 MenuItems
= AllocateZeroPool((NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
54 if (MenuItems
== NULL
) {
55 return EFI_OUT_OF_RESOURCES
;
57 CopyMem(MenuItems
, Items
, (NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
62 Initialize the control hot-key with the specified items.
64 @param[in] Items The hot-key functions.
66 @retval EFI_SUCCESS The initialization was correct.
71 IN MENU_ITEM_FUNCTION
*Items
74 ControlBasedMenuFunctions
= Items
;
78 Refresh function for the menu bar.
80 @param[in] LastRow The last printable row.
81 @param[in] LastCol The last printable column.
83 @retval EFI_SUCCESS The refresh was successful.
88 IN CONST UINTN LastRow
,
89 IN CONST UINTN LastCol
92 EDITOR_MENU_ITEM
*Item
;
97 CHAR16
*FunctionKeyString
;
100 // variable initialization
106 // clear menu bar rows
108 EditorClearLine (LastRow
- 2, LastCol
, LastRow
);
109 EditorClearLine (LastRow
- 1, LastCol
, LastRow
);
110 EditorClearLine (LastRow
, LastCol
, LastRow
);
114 // print out the menu items
116 for (Item
= MenuItems
; Item
!= NULL
&& Item
->Function
!= NULL
; Item
++) {
119 NameString
= HiiGetString(gShellDebug1HiiHandle
, Item
->NameToken
, NULL
);
122 Width
= MAX ((StrLen (NameString
) + 6), 20);
123 if (((Col
+ Width
) > LastCol
)) {
128 FunctionKeyString
= HiiGetString(gShellDebug1HiiHandle
, Item
->FunctionKeyToken
, NULL
);
130 ShellPrintEx ((INT32
)(Col
) - 1, (INT32
)(Row
) - 1, L
"%E%s%N %H%s%N ", FunctionKeyString
, NameString
);
132 FreePool (NameString
);
133 FreePool (FunctionKeyString
);
141 Function to dispatch the correct function based on a function key (F1...)
143 @param[in] Key The pressed key.
145 @retval EFI_NOT_FOUND The key was not a valid function key
146 (an error was sent to the status bar).
147 @return The return value from the called dispatch function.
151 MenuBarDispatchFunctionKey (
152 IN CONST EFI_INPUT_KEY
*Key
157 Index
= Key
->ScanCode
- SCAN_F1
;
160 // check whether in range
162 if (Index
> (NumItems
- 1)) {
163 StatusBarSetStatusString (L
"Unknown Command");
167 return (MenuItems
[Index
].Function ());
171 Function to dispatch the correct function based on a control-based key (ctrl+o...)
173 @param[in] Key The pressed key.
175 @retval EFI_NOT_FOUND The key was not a valid control-based key
176 (an error was sent to the status bar).
181 MenuBarDispatchControlHotKey (
182 IN CONST EFI_INPUT_KEY
*Key
186 if ((SCAN_CONTROL_Z
< Key
->UnicodeChar
)
187 ||(NULL
== ControlBasedMenuFunctions
[Key
->UnicodeChar
]))
189 return EFI_NOT_FOUND
;
192 ControlBasedMenuFunctions
[Key
->UnicodeChar
]();