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
;
23 Cleanup function for a menu bar. frees all allocated memory.
31 SHELL_FREE_NON_NULL(MenuItems
);
35 Initializa 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.
45 IN CONST EDITOR_MENU_ITEM
*Items
48 CONST EDITOR_MENU_ITEM
*ItemsWalker
;
50 for (NumItems
= 0, ItemsWalker
= Items
; ItemsWalker
!= NULL
&& ItemsWalker
->Function
!= NULL
; ItemsWalker
++,NumItems
++);
52 MenuItems
= AllocateZeroPool((NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
53 if (MenuItems
== NULL
) {
54 return EFI_OUT_OF_RESOURCES
;
56 CopyMem(MenuItems
, Items
, (NumItems
+1) * sizeof(EDITOR_MENU_ITEM
));
61 Refresh function for the menu bar.
63 @param[in] LastRow The last printable row.
64 @param[in] LastCol The last printable column.
66 @retval EFI_SUCCESS The refresh was successful.
71 IN CONST UINTN LastRow
,
72 IN CONST UINTN LastCol
75 EDITOR_MENU_ITEM
*Item
;
80 CHAR16
*FunctionKeyString
;
83 // variable initialization
89 // clear menu bar rows
91 EditorClearLine (LastRow
- 2, LastCol
, LastRow
);
92 EditorClearLine (LastRow
- 1, LastCol
, LastRow
);
93 EditorClearLine (LastRow
, LastCol
, LastRow
);
97 // print out the menu items
99 for (Item
= MenuItems
; Item
!= NULL
&& Item
->Function
!= NULL
; Item
++) {
102 NameString
= HiiGetString(gShellDebug1HiiHandle
, Item
->NameToken
, NULL
);
105 Width
= MAX ((StrLen (NameString
) + 6), 20);
106 if (((Col
+ Width
) > LastCol
)) {
111 FunctionKeyString
= HiiGetString(gShellDebug1HiiHandle
, Item
->FunctionKeyToken
, NULL
);
113 ShellPrintEx ((INT32
)(Col
) - 1, (INT32
)(Row
) - 1, L
"%E%s%N %H%s%N ", FunctionKeyString
, NameString
);
115 FreePool (NameString
);
116 FreePool (FunctionKeyString
);
124 Function to dispatch the correct function based on a function key (F1...)
126 @param[in] Key The pressed key.
128 @retval EFI_NOT_FOUND The key was not a valid function key
129 (an error was sent to the status bar).
130 @return The return value from the called dispatch function.
134 MenuBarDispatchFunctionKey (
135 IN CONST EFI_INPUT_KEY
*Key
140 Index
= Key
->ScanCode
- SCAN_F1
;
143 // check whether in range
145 if (Index
> (NumItems
- 1)) {
146 StatusBarSetStatusString (L
"Unknown Command");
150 return (MenuItems
[Index
].Function ());