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