VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDebug1CommandsLib/EditMenuBar.c@ 109091

Last change on this file since 109091 was 108794, checked in by vboxsync, 5 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette