VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c

Last change on this file was 99404, checked in by vboxsync, 21 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/** @file
2 Implements statusbar 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 "EditStatusBar.h"
10#include "UefiShellDebug1CommandsLib.h"
11
12CHAR16 *StatusString;
13BOOLEAN StatusBarNeedRefresh;
14BOOLEAN StatusStringChanged;
15
16/**
17 Initialization function for Status Bar.
18
19 @retval EFI_SUCCESS The operation was successful.
20 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
21 @sa StatusBarSetStatusString
22**/
23EFI_STATUS
24StatusBarInit (
25 VOID
26 )
27{
28 //
29 // initialize the statusbar
30 //
31 StatusString = NULL;
32 StatusBarNeedRefresh = TRUE;
33 StatusStringChanged = FALSE;
34
35 //
36 // status string set to ""
37 //
38 return (StatusBarSetStatusString (L""));
39}
40
41/**
42 Cleanup function for the status bar.
43**/
44VOID
45StatusBarCleanup (
46 VOID
47 )
48{
49 //
50 // free the status string and backvar's status string
51 //
52 SHELL_FREE_NON_NULL (StatusString);
53}
54
55typedef struct {
56 UINT32 Foreground : 4;
57 UINT32 Background : 3;
58} STATUS_BAR_COLOR_ATTRIBUTES;
59
60typedef union {
61 STATUS_BAR_COLOR_ATTRIBUTES Colors;
62 UINTN Data;
63} STATUS_BAR_COLOR_UNION;
64
65/**
66 Cause the status bar to refresh it's printing on the screen.
67
68 @param[in] EditorFirst TRUE to indicate the first launch of the editor.
69 FALSE otherwise.
70 @param[in] LastRow LastPrintable row.
71 @param[in] LastCol Last printable column.
72 @param[in] FileRow Row in the file.
73 @param[in] FileCol Column in the file.
74 @param[in] InsertMode TRUE to indicate InsertMode. FALSE otherwise.
75
76 @retval EFI_SUCCESS The operation was successful.
77**/
78EFI_STATUS
79StatusBarRefresh (
80 IN BOOLEAN EditorFirst,
81 IN UINTN LastRow,
82 IN UINTN LastCol,
83 IN UINTN FileRow,
84 IN UINTN FileCol,
85 IN BOOLEAN InsertMode
86 )
87{
88 STATUS_BAR_COLOR_UNION Orig;
89 STATUS_BAR_COLOR_UNION New;
90
91 if (!StatusStringChanged && StatusBarNeedRefresh) {
92 StatusBarSetStatusString (L"\0");
93 }
94
95 //
96 // when it's called first time after editor launch, so refresh is mandatory
97 //
98 if (!StatusBarNeedRefresh && !StatusStringChanged) {
99 return EFI_SUCCESS;
100 }
101
102 //
103 // back up the screen attributes
104 //
105 Orig.Data = gST->ConOut->Mode->Attribute;
106 New.Data = 0;
107 New.Colors.Foreground = Orig.Colors.Background & 0xF;
108 New.Colors.Background = Orig.Colors.Foreground & 0x7;
109
110 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
111 gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
112
113 //
114 // clear status bar
115 //
116 EditorClearLine (LastRow, LastCol, LastRow);
117
118 //
119 // print row, column fields
120 //
121 if ((FileRow != (UINTN)(-1)) && (FileCol != (UINTN)(-1))) {
122 ShellPrintEx (
123 0,
124 (INT32)(LastRow) - 1,
125 L" %d,%d %s",
126 FileRow,
127 FileCol,
128 StatusString
129 );
130 } else {
131 ShellPrintEx (
132 0,
133 (INT32)(LastRow) - 1,
134 L" %s",
135 StatusString
136 );
137 }
138
139 //
140 // print insert mode field
141 //
142 if (InsertMode) {
143 ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"INS");
144 } else {
145 ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"OVR");
146 }
147
148 //
149 // restore the old screen attributes
150 //
151 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
152
153 //
154 // restore position in edit area
155 //
156 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
157
158 StatusBarNeedRefresh = FALSE;
159 StatusStringChanged = FALSE;
160
161 return EFI_SUCCESS;
162}
163
164/**
165 Set the status string text part.
166
167 @param[in] Str The string to use.
168
169 @retval EFI_SUCCESS The operation was successful.
170 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
171**/
172EFI_STATUS
173StatusBarSetStatusString (
174 IN CHAR16 *Str
175 )
176{
177 StatusStringChanged = TRUE;
178
179 //
180 // free the old status string
181 //
182 SHELL_FREE_NON_NULL (StatusString);
183 StatusString = CatSPrint (NULL, L"%s", Str);
184 if (StatusString == NULL) {
185 return EFI_OUT_OF_RESOURCES;
186 }
187
188 return EFI_SUCCESS;
189}
190
191/**
192 Function to retrieve the current status string.
193
194 @return The string that is used.
195**/
196CONST CHAR16 *
197StatusBarGetString (
198 VOID
199 )
200{
201 return (StatusString);
202}
203
204/**
205 Function to set the need refresh boolean to TRUE.
206**/
207VOID
208StatusBarSetRefresh (
209 VOID
210 )
211{
212 StatusBarNeedRefresh = TRUE;
213}
214
215/**
216 Function to get the need refresh boolean to TRUE.
217
218 @retval TRUE The status bar needs to be refreshed.
219**/
220BOOLEAN
221StatusBarGetRefresh (
222 VOID
223 )
224{
225 return (StatusBarNeedRefresh);
226}
Note: See TracBrowser for help on using the repository browser.

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