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