]>
Commit | Line | Data |
---|---|---|
2442e62a | 1 | /** @file\r |
2 | implements menubar interface functions.\r | |
3 | \r | |
5563281f | 4 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>\r |
56ba3746 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
2442e62a | 6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "EditMenuBar.h"\r | |
10 | #include "UefiShellDebug1CommandsLib.h"\r | |
11 | #include "EditStatusBar.h"\r | |
12 | \r | |
47d20b54 MK |
13 | EDITOR_MENU_ITEM *MenuItems;\r |
14 | MENU_ITEM_FUNCTION *ControlBasedMenuFunctions;\r | |
15 | UINTN NumItems;\r | |
2442e62a | 16 | \r |
17 | /**\r | |
18 | Cleanup function for a menu bar. frees all allocated memory.\r | |
19 | **/\r | |
20 | VOID\r | |
2442e62a | 21 | MenuBarCleanup (\r |
22 | VOID\r | |
23 | )\r | |
24 | {\r | |
47d20b54 | 25 | SHELL_FREE_NON_NULL (MenuItems);\r |
2442e62a | 26 | }\r |
27 | \r | |
28 | /**\r | |
5a2beb74 | 29 | Initialize the menu bar with the specified items.\r |
2442e62a | 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 | |
2442e62a | 37 | MenuBarInit (\r |
38 | IN CONST EDITOR_MENU_ITEM *Items\r | |
39 | )\r | |
40 | {\r | |
41 | CONST EDITOR_MENU_ITEM *ItemsWalker;\r | |
42 | \r | |
47d20b54 MK |
43 | for (NumItems = 0, ItemsWalker = Items; ItemsWalker != NULL && ItemsWalker->Function != NULL; ItemsWalker++, NumItems++) {\r |
44 | }\r | |
ba0014b9 | 45 | \r |
47d20b54 | 46 | MenuItems = AllocateZeroPool ((NumItems+1) * sizeof (EDITOR_MENU_ITEM));\r |
2442e62a | 47 | if (MenuItems == NULL) {\r |
48 | return EFI_OUT_OF_RESOURCES;\r | |
49 | }\r | |
47d20b54 MK |
50 | \r |
51 | CopyMem (MenuItems, Items, (NumItems+1) * sizeof (EDITOR_MENU_ITEM));\r | |
2442e62a | 52 | return EFI_SUCCESS;\r |
53 | }\r | |
54 | \r | |
5a2beb74 | 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 | |
5a2beb74 | 63 | ControlHotKeyInit (\r |
64 | IN MENU_ITEM_FUNCTION *Items\r | |
65 | )\r | |
66 | {\r | |
67 | ControlBasedMenuFunctions = Items;\r | |
ba0014b9 | 68 | return EFI_SUCCESS;\r |
5a2beb74 | 69 | }\r |
47d20b54 | 70 | \r |
2442e62a | 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 | |
2442e62a | 80 | MenuBarRefresh (\r |
47d20b54 MK |
81 | IN CONST UINTN LastRow,\r |
82 | IN CONST UINTN LastCol\r | |
2442e62a | 83 | )\r |
84 | {\r | |
85 | EDITOR_MENU_ITEM *Item;\r | |
47d20b54 MK |
86 | UINTN Col;\r |
87 | UINTN Row;\r | |
88 | UINTN Width;\r | |
89 | CHAR16 *NameString;\r | |
90 | CHAR16 *FunctionKeyString;\r | |
2442e62a | 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 | |
47d20b54 | 103 | EditorClearLine (LastRow, LastCol, LastRow);\r |
2442e62a | 104 | \r |
105 | //\r | |
106 | // print out the menu items\r | |
107 | //\r | |
108 | for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {\r | |
47d20b54 | 109 | NameString = HiiGetString (gShellDebug1HiiHandle, Item->NameToken, NULL);\r |
2442e62a | 110 | \r |
47d20b54 | 111 | Width = MAX ((StrLen (NameString) + 6), 20);\r |
2442e62a | 112 | if (((Col + Width) > LastCol)) {\r |
113 | Row++;\r | |
114 | Col = 1;\r | |
115 | }\r | |
116 | \r | |
47d20b54 | 117 | FunctionKeyString = HiiGetString (gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);\r |
2442e62a | 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 | |
ba0014b9 | 134 | @retval EFI_NOT_FOUND The key was not a valid function key\r |
2442e62a | 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 | |
2442e62a | 139 | MenuBarDispatchFunctionKey (\r |
47d20b54 | 140 | IN CONST EFI_INPUT_KEY *Key\r |
2442e62a | 141 | )\r |
142 | {\r | |
47d20b54 | 143 | UINTN Index;\r |
2442e62a | 144 | \r |
47d20b54 | 145 | Index = Key->ScanCode - SCAN_F1;\r |
2442e62a | 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 | |
5a2beb74 | 158 | /**\r |
159 | Function to dispatch the correct function based on a control-based key (ctrl+o...)\r | |
160 | \r | |
5563281f | 161 | @param[in] KeyData The pressed key.\r |
5a2beb74 | 162 | \r |
ba0014b9 | 163 | @retval EFI_NOT_FOUND The key was not a valid control-based key\r |
5a2beb74 | 164 | (an error was sent to the status bar).\r |
165 | @return EFI_SUCCESS.\r | |
166 | **/\r | |
167 | EFI_STATUS\r | |
5a2beb74 | 168 | MenuBarDispatchControlHotKey (\r |
47d20b54 | 169 | IN CONST EFI_KEY_DATA *KeyData\r |
5a2beb74 | 170 | )\r |
171 | {\r | |
47d20b54 | 172 | UINT16 ControlIndex;\r |
5563281f RN |
173 | \r |
174 | //\r | |
175 | // Set to invalid value first.\r | |
176 | //\r | |
177 | ControlIndex = MAX_UINT16;\r | |
178 | \r | |
7cb03133 | 179 | if (((KeyData->KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) ||\r |
47d20b54 MK |
180 | (KeyData->KeyState.KeyShiftState == EFI_SHIFT_STATE_VALID))\r |
181 | {\r | |
5563281f | 182 | //\r |
7cb03133 | 183 | // For consoles that don't support/report shift state,\r |
5563281f RN |
184 | // Ctrl+A is translated to 1 (UnicodeChar).\r |
185 | //\r | |
186 | ControlIndex = KeyData->Key.UnicodeChar;\r | |
7cb03133 RN |
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 | |
47d20b54 MK |
189 | ((KeyData->KeyState.KeyShiftState & ~(EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED | EFI_LEFT_CONTROL_PRESSED)) == 0))\r |
190 | {\r | |
5563281f | 191 | //\r |
7cb03133 | 192 | // For consoles that supports/reports shift state,\r |
5563281f RN |
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 | |
47d20b54 MK |
201 | \r |
202 | if ( (SCAN_CONTROL_Z < ControlIndex)\r | |
203 | || (NULL == ControlBasedMenuFunctions[ControlIndex]))\r | |
5a2beb74 | 204 | {\r |
47d20b54 | 205 | return EFI_NOT_FOUND;\r |
5a2beb74 | 206 | }\r |
207 | \r | |
5563281f | 208 | ControlBasedMenuFunctions[ControlIndex]();\r |
5a2beb74 | 209 | return EFI_SUCCESS;\r |
210 | }\r |