]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c
ShellPkg: Parse new SMBIOS 3.0 fields.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / EditMenuBar.c
CommitLineData
2442e62a 1/** @file\r
2 implements menubar interface functions.\r
3\r
4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "EditMenuBar.h"\r
16#include "UefiShellDebug1CommandsLib.h"\r
17#include "EditStatusBar.h"\r
18\r
5a2beb74 19EDITOR_MENU_ITEM *MenuItems;\r
20MENU_ITEM_FUNCTION *ControlBasedMenuFunctions;\r
2442e62a 21UINTN NumItems;\r
22\r
23/**\r
24 Cleanup function for a menu bar. frees all allocated memory.\r
25**/\r
26VOID\r
27EFIAPI\r
28MenuBarCleanup (\r
29 VOID\r
30 )\r
31{\r
32 SHELL_FREE_NON_NULL(MenuItems);\r
33}\r
34\r
35/**\r
5a2beb74 36 Initialize the menu bar with the specified items.\r
2442e62a 37\r
38 @param[in] Items The items to display and their functions.\r
39\r
40 @retval EFI_SUCCESS The initialization was correct.\r
41 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
42**/\r
43EFI_STATUS\r
44EFIAPI\r
45MenuBarInit (\r
46 IN CONST EDITOR_MENU_ITEM *Items\r
47 )\r
48{\r
49 CONST EDITOR_MENU_ITEM *ItemsWalker;\r
50\r
51 for (NumItems = 0, ItemsWalker = Items ; ItemsWalker != NULL && ItemsWalker->Function != NULL ; ItemsWalker++,NumItems++);\r
52 \r
53 MenuItems = AllocateZeroPool((NumItems+1) * sizeof(EDITOR_MENU_ITEM));\r
54 if (MenuItems == NULL) {\r
55 return EFI_OUT_OF_RESOURCES;\r
56 }\r
57 CopyMem(MenuItems, Items, (NumItems+1) * sizeof(EDITOR_MENU_ITEM));\r
58 return EFI_SUCCESS;\r
59}\r
60\r
5a2beb74 61/**\r
62 Initialize the control hot-key with the specified items.\r
63\r
64 @param[in] Items The hot-key functions.\r
65\r
66 @retval EFI_SUCCESS The initialization was correct.\r
67**/\r
68EFI_STATUS\r
69EFIAPI\r
70ControlHotKeyInit (\r
71 IN MENU_ITEM_FUNCTION *Items\r
72 )\r
73{\r
74 ControlBasedMenuFunctions = Items;\r
75 return EFI_SUCCESS; \r
76}\r
2442e62a 77/**\r
78 Refresh function for the menu bar.\r
79\r
80 @param[in] LastRow The last printable row.\r
81 @param[in] LastCol The last printable column.\r
82\r
83 @retval EFI_SUCCESS The refresh was successful.\r
84**/\r
85EFI_STATUS\r
86EFIAPI\r
87MenuBarRefresh (\r
88 IN CONST UINTN LastRow,\r
89 IN CONST UINTN LastCol\r
90 )\r
91{\r
92 EDITOR_MENU_ITEM *Item;\r
93 UINTN Col;\r
94 UINTN Row;\r
95 UINTN Width;\r
96 CHAR16 *NameString;\r
97 CHAR16 *FunctionKeyString;\r
98\r
99 //\r
100 // variable initialization\r
101 //\r
102 Col = 1;\r
103 Row = (LastRow - 2);\r
104\r
105 //\r
106 // clear menu bar rows\r
107 //\r
108 EditorClearLine (LastRow - 2, LastCol, LastRow);\r
109 EditorClearLine (LastRow - 1, LastCol, LastRow);\r
110 EditorClearLine (LastRow , LastCol, LastRow);\r
111\r
112\r
113 //\r
114 // print out the menu items\r
115 //\r
116 for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {\r
117\r
118\r
119 NameString = HiiGetString(gShellDebug1HiiHandle, Item->NameToken, NULL);\r
120\r
121\r
122 Width = MAX ((StrLen (NameString) + 6), 20);\r
123 if (((Col + Width) > LastCol)) {\r
124 Row++;\r
125 Col = 1;\r
126 }\r
127\r
128 FunctionKeyString = HiiGetString(gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);\r
129\r
130 ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString);\r
131\r
132 FreePool (NameString);\r
133 FreePool (FunctionKeyString);\r
134 Col += Width;\r
135 }\r
136\r
137 return EFI_SUCCESS;\r
138}\r
139\r
140/**\r
141 Function to dispatch the correct function based on a function key (F1...)\r
142\r
143 @param[in] Key The pressed key.\r
144\r
145 @retval EFI_NOT_FOUND The key was not a valid function key \r
146 (an error was sent to the status bar).\r
147 @return The return value from the called dispatch function.\r
148**/\r
149EFI_STATUS\r
150EFIAPI\r
151MenuBarDispatchFunctionKey (\r
152 IN CONST EFI_INPUT_KEY *Key\r
153 )\r
154{\r
155 UINTN Index;\r
156\r
157 Index = Key->ScanCode - SCAN_F1;\r
158\r
159 //\r
160 // check whether in range\r
161 //\r
162 if (Index > (NumItems - 1)) {\r
163 StatusBarSetStatusString (L"Unknown Command");\r
164 return EFI_SUCCESS;\r
165 }\r
166\r
167 return (MenuItems[Index].Function ());\r
168}\r
169\r
5a2beb74 170/**\r
171 Function to dispatch the correct function based on a control-based key (ctrl+o...)\r
172\r
173 @param[in] Key The pressed key.\r
174\r
175 @retval EFI_NOT_FOUND The key was not a valid control-based key \r
176 (an error was sent to the status bar).\r
177 @return EFI_SUCCESS.\r
178**/\r
179EFI_STATUS\r
180EFIAPI\r
181MenuBarDispatchControlHotKey (\r
182 IN CONST EFI_INPUT_KEY *Key\r
183 )\r
184{\r
185 \r
186 if ((SCAN_CONTROL_Z < Key->UnicodeChar)\r
187 ||(NULL == ControlBasedMenuFunctions[Key->UnicodeChar]))\r
188 {\r
189 return EFI_NOT_FOUND;\r
190 }\r
191\r
192 ControlBasedMenuFunctions[Key->UnicodeChar]();\r
193 return EFI_SUCCESS;\r
194}\r
195\r
196\r