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