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