]>
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 | |
19 | EDITOR_MENU_ITEM *MenuItems;\r | |
20 | UINTN NumItems;\r | |
21 | \r | |
22 | /**\r | |
23 | Cleanup function for a menu bar. frees all allocated memory.\r | |
24 | **/\r | |
25 | VOID\r | |
26 | EFIAPI\r | |
27 | MenuBarCleanup (\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | SHELL_FREE_NON_NULL(MenuItems);\r | |
32 | }\r | |
33 | \r | |
34 | /**\r | |
35 | Initializa the menu bar with the specified items.\r | |
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 | |
43 | EFIAPI\r | |
44 | MenuBarInit (\r | |
45 | IN CONST EDITOR_MENU_ITEM *Items\r | |
46 | )\r | |
47 | {\r | |
48 | CONST EDITOR_MENU_ITEM *ItemsWalker;\r | |
49 | \r | |
50 | for (NumItems = 0, ItemsWalker = Items ; ItemsWalker != NULL && ItemsWalker->Function != NULL ; ItemsWalker++,NumItems++);\r | |
51 | \r | |
52 | MenuItems = AllocateZeroPool((NumItems+1) * sizeof(EDITOR_MENU_ITEM));\r | |
53 | if (MenuItems == NULL) {\r | |
54 | return EFI_OUT_OF_RESOURCES;\r | |
55 | }\r | |
56 | CopyMem(MenuItems, Items, (NumItems+1) * sizeof(EDITOR_MENU_ITEM));\r | |
57 | return EFI_SUCCESS;\r | |
58 | }\r | |
59 | \r | |
60 | /**\r | |
61 | Refresh function for the menu bar.\r | |
62 | \r | |
63 | @param[in] LastRow The last printable row.\r | |
64 | @param[in] LastCol The last printable column.\r | |
65 | \r | |
66 | @retval EFI_SUCCESS The refresh was successful.\r | |
67 | **/\r | |
68 | EFI_STATUS\r | |
69 | EFIAPI\r | |
70 | MenuBarRefresh (\r | |
71 | IN CONST UINTN LastRow,\r | |
72 | IN CONST UINTN LastCol\r | |
73 | )\r | |
74 | {\r | |
75 | EDITOR_MENU_ITEM *Item;\r | |
76 | UINTN Col;\r | |
77 | UINTN Row;\r | |
78 | UINTN Width;\r | |
79 | CHAR16 *NameString;\r | |
80 | CHAR16 *FunctionKeyString;\r | |
81 | \r | |
82 | //\r | |
83 | // variable initialization\r | |
84 | //\r | |
85 | Col = 1;\r | |
86 | Row = (LastRow - 2);\r | |
87 | \r | |
88 | //\r | |
89 | // clear menu bar rows\r | |
90 | //\r | |
91 | EditorClearLine (LastRow - 2, LastCol, LastRow);\r | |
92 | EditorClearLine (LastRow - 1, LastCol, LastRow);\r | |
93 | EditorClearLine (LastRow , LastCol, LastRow);\r | |
94 | \r | |
95 | \r | |
96 | //\r | |
97 | // print out the menu items\r | |
98 | //\r | |
99 | for (Item = MenuItems; Item != NULL && Item->Function != NULL; Item++) {\r | |
100 | \r | |
101 | \r | |
102 | NameString = HiiGetString(gShellDebug1HiiHandle, Item->NameToken, NULL);\r | |
103 | \r | |
104 | \r | |
105 | Width = MAX ((StrLen (NameString) + 6), 20);\r | |
106 | if (((Col + Width) > LastCol)) {\r | |
107 | Row++;\r | |
108 | Col = 1;\r | |
109 | }\r | |
110 | \r | |
111 | FunctionKeyString = HiiGetString(gShellDebug1HiiHandle, Item->FunctionKeyToken, NULL);\r | |
112 | \r | |
113 | ShellPrintEx ((INT32)(Col) - 1, (INT32)(Row) - 1, L"%E%s%N %H%s%N ", FunctionKeyString, NameString);\r | |
114 | \r | |
115 | FreePool (NameString);\r | |
116 | FreePool (FunctionKeyString);\r | |
117 | Col += Width;\r | |
118 | }\r | |
119 | \r | |
120 | return EFI_SUCCESS;\r | |
121 | }\r | |
122 | \r | |
123 | /**\r | |
124 | Function to dispatch the correct function based on a function key (F1...)\r | |
125 | \r | |
126 | @param[in] Key The pressed key.\r | |
127 | \r | |
128 | @retval EFI_NOT_FOUND The key was not a valid function key \r | |
129 | (an error was sent to the status bar).\r | |
130 | @return The return value from the called dispatch function.\r | |
131 | **/\r | |
132 | EFI_STATUS\r | |
133 | EFIAPI\r | |
134 | MenuBarDispatchFunctionKey (\r | |
135 | IN CONST EFI_INPUT_KEY *Key\r | |
136 | )\r | |
137 | {\r | |
138 | UINTN Index;\r | |
139 | \r | |
140 | Index = Key->ScanCode - SCAN_F1;\r | |
141 | \r | |
142 | //\r | |
143 | // check whether in range\r | |
144 | //\r | |
145 | if (Index > (NumItems - 1)) {\r | |
146 | StatusBarSetStatusString (L"Unknown Command");\r | |
147 | return EFI_SUCCESS;\r | |
148 | }\r | |
149 | \r | |
150 | return (MenuItems[Index].Function ());\r | |
151 | }\r | |
152 | \r |