1 /** @file
2 implements menubar interface functions.
3
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
9
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.
12
13 **/
14
15 #include "EditMenuBar.h"
16 #include "UefiShellDebug1CommandsLib.h"
17 #include "EditStatusBar.h"
18
19 EDITOR_MENU_ITEM *MenuItems;
20 MENU_ITEM_FUNCTION *ControlBasedMenuFunctions;
21 UINTN NumItems;
22
23 /**
24 Cleanup function for a menu bar. frees all allocated memory.
25 **/
26 VOID
27 EFIAPI
MenuBarCleanup(VOID)28 MenuBarCleanup (
29 VOID
30 )
31 {
32 SHELL_FREE_NON_NULL(MenuItems);
33 }
34
35 /**
36 Initialize the menu bar with the specified items.
37
38 @param[in] Items The items to display and their functions.
39
40 @retval EFI_SUCCESS The initialization was correct.
41 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
42 **/
43 EFI_STATUS
44 EFIAPI
MenuBarInit(IN CONST EDITOR_MENU_ITEM * Items)45 MenuBarInit (
46 IN CONST EDITOR_MENU_ITEM *Items
47 )
48 {
49 CONST EDITOR_MENU_ITEM *ItemsWalker;
50
51 for (NumItems = 0, ItemsWalker = Items ; ItemsWalker != NULL && ItemsWalker->Function != NULL ; ItemsWalker++,NumItems++);
52
53 MenuItems = AllocateZeroPool((NumItems+1) * sizeof(EDITOR_MENU_ITEM));
54 if (MenuItems == NULL) {
55 return EFI_OUT_OF_RESOURCES;
56 }
57 CopyMem(MenuItems, Items, (NumItems+1) * sizeof(EDITOR_MENU_ITEM));
58 return EFI_SUCCESS;
59 }
60
61 /**
62 Initialize the control hot-key with the specified items.
63
64 @param[in] Items The hot-key functions.
65
66 @retval EFI_SUCCESS The initialization was correct.
67 **/
68 EFI_STATUS
69 EFIAPI
ControlHotKeyInit(IN MENU_ITEM_FUNCTION * Items)70 ControlHotKeyInit (
71 IN MENU_ITEM_FUNCTION *Items
72 )
73 {
74 ControlBasedMenuFunctions = Items;
75 return EFI_SUCCESS;
76 }
77 /**
78 Refresh function for the menu bar.
79
80 @param[in] LastRow The last printable row.
81 @param[in] LastCol The last printable column.
82
83 @retval EFI_SUCCESS The refresh was successful.
84 **/
85 EFI_STATUS
86 EFIAPI
MenuBarRefresh(IN CONST UINTN LastRow,IN CONST UINTN LastCol)87 MenuBarRefresh (
88 IN CONST UINTN LastRow,
89 IN CONST UINTN LastCol
90 )
91 {
92 EDITOR_MENU_ITEM *Item;
93 UINTN Col;
94 UINTN Row;
95 UINTN Width;
96 CHAR16 *NameString;
97 CHAR16 *FunctionKeyString;
98
99 //
100 // variable initialization
101 //
102 Col = 1;
103 Row = (LastRow - 2);
104
105 //
106 // clear menu bar rows
107 //
108 EditorClearLine (LastRow - 2, LastCol, LastRow);
109 EditorClearLine (LastRow - 1, LastCol, LastRow);
110 EditorClearLine (LastRow , LastCol, LastRow);
111
112
113 //
114 // print out the menu items
115 //
116 for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {
117
118
119 NameString = HiiGetString(gShellDebug1HiiHandle, Item->NameToken, NULL);
120
121
122 Width = MAX ((StrLen (NameString) + 6), 20);
123 if (((Col + Width) > LastCol)) {
124 Row++;
125 Col = 1;
126 }
127
128 FunctionKeyString = HiiGetString(gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);
129
130 ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString);
131
132 FreePool (NameString);
133 FreePool (FunctionKeyString);
134 Col += Width;
135 }
136
137 return EFI_SUCCESS;
138 }
139
140 /**
141 Function to dispatch the correct function based on a function key (F1...)
142
143 @param[in] Key The pressed key.
144
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.
148 **/
149 EFI_STATUS
150 EFIAPI
MenuBarDispatchFunctionKey(IN CONST EFI_INPUT_KEY * Key)151 MenuBarDispatchFunctionKey (
152 IN CONST EFI_INPUT_KEY *Key
153 )
154 {
155 UINTN Index;
156
157 Index = Key->ScanCode - SCAN_F1;
158
159 //
160 // check whether in range
161 //
162 if (Index > (NumItems - 1)) {
163 StatusBarSetStatusString (L"Unknown Command");
164 return EFI_SUCCESS;
165 }
166
167 return (MenuItems[Index].Function ());
168 }
169
170 /**
171 Function to dispatch the correct function based on a control-based key (ctrl+o...)
172
173 @param[in] Key The pressed key.
174
175 @retval EFI_NOT_FOUND The key was not a valid control-based key
176 (an error was sent to the status bar).
177 @return EFI_SUCCESS.
178 **/
179 EFI_STATUS
180 EFIAPI
MenuBarDispatchControlHotKey(IN CONST EFI_INPUT_KEY * Key)181 MenuBarDispatchControlHotKey (
182 IN CONST EFI_INPUT_KEY *Key
183 )
184 {
185
186 if ((SCAN_CONTROL_Z < Key->UnicodeChar)
187 ||(NULL == ControlBasedMenuFunctions[Key->UnicodeChar]))
188 {
189 return EFI_NOT_FOUND;
190 }
191
192 ControlBasedMenuFunctions[Key->UnicodeChar]();
193 return EFI_SUCCESS;
194 }
195
196
197