]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c
MdeModulePkg: Fix parameter verification for SetAttribute
[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
28981267 114 New.Data = 0;\r
2442e62a 115 New.Colors.Foreground = Orig.Colors.Background;\r
116 New.Colors.Background = Orig.Colors.Foreground;\r
117\r
118 gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
119 gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
120\r
121 //\r
122 // clear status bar\r
123 //\r
5a2beb74 124 EditorClearLine (LastRow, LastCol, LastRow);\r
2442e62a 125\r
126 //\r
127 // print row, column fields\r
128 //\r
6878e7a7 129 if (FileRow != (UINTN)(-1) && FileCol != (UINTN)(-1)) {\r
130 ShellPrintEx (\r
131 0,\r
5a2beb74 132 (INT32)(LastRow) - 1,\r
133 L" %d,%d %s",\r
6878e7a7 134 FileRow,\r
135 FileCol,\r
136 StatusString\r
137 );\r
138 } else {\r
139 ShellPrintEx (\r
140 0,\r
5a2beb74 141 (INT32)(LastRow) - 1,\r
6878e7a7 142 L" %s",\r
143 StatusString\r
144 );\r
145 }\r
2442e62a 146\r
147 //\r
148 // print insert mode field\r
149 //\r
150 if (InsertMode) {\r
5a2beb74 151 ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"INS");\r
2442e62a 152 } else {\r
5a2beb74 153 ShellPrintEx ((INT32)(LastCol) - 21, (INT32)(LastRow) - 1, L"|%s| Help: Ctrl-E", L"OVR");\r
2442e62a 154 }\r
155 //\r
156 // restore the old screen attributes\r
157 //\r
158 gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
159\r
160 //\r
161 // restore position in edit area\r
162 //\r
163 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
164\r
165 StatusBarNeedRefresh = FALSE;\r
166 StatusStringChanged = FALSE;\r
167\r
168 return EFI_SUCCESS;\r
169}\r
170\r
171/**\r
172 Set the status string text part.\r
173\r
174 @param[in] Str The string to use.\r
175\r
176 @retval EFI_SUCCESS The operation was successful.\r
177 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
178**/\r
179EFI_STATUS\r
180EFIAPI\r
181StatusBarSetStatusString (\r
182 IN CHAR16 *Str\r
183 )\r
184{\r
185 StatusStringChanged = TRUE;\r
186\r
187 //\r
188 // free the old status string\r
189 //\r
190 SHELL_FREE_NON_NULL (StatusString);\r
191 StatusString = CatSPrint (NULL, L"%s", Str);\r
192 if (StatusString == NULL) {\r
193 return EFI_OUT_OF_RESOURCES;\r
194 }\r
195\r
196 return EFI_SUCCESS;\r
197}\r
198\r
199/**\r
200 Function to retrieve the current status string.\r
201\r
202 @return The string that is used.\r
203**/\r
204CONST CHAR16*\r
205EFIAPI\r
206StatusBarGetString (\r
207 VOID\r
208 )\r
209{\r
210 return (StatusString);\r
211}\r
212\r
213/**\r
214 Function to set the need refresh boolean to TRUE.\r
215**/\r
216VOID\r
217EFIAPI\r
218StatusBarSetRefresh(\r
219 VOID\r
220 )\r
221{\r
222 StatusBarNeedRefresh = TRUE;\r
223}\r
224\r
225/**\r
226 Function to get the need refresh boolean to TRUE.\r
227\r
228 @retval TRUE The status bar needs to be refreshed.\r
229**/\r
230BOOLEAN\r
231EFIAPI\r
232StatusBarGetRefresh(\r
233 VOID\r
234 )\r
235{\r
236 return (StatusBarNeedRefresh);\r
237}\r