]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
9edc73ad | 2 | This module provide help function for displaying unicode string.\r |
e386b444 | 3 | \r |
9095d37b | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e386b444 | 6 | \r |
e386b444 | 7 | **/\r |
8 | \r | |
f734a10a | 9 | #include "UefiLibInternal.h"\r |
e386b444 | 10 | \r |
11 | typedef struct {\r | |
2f88bd3a MK |
12 | CHAR16 WChar;\r |
13 | UINT32 Width;\r | |
e386b444 | 14 | } UNICODE_WIDTH_ENTRY;\r |
15 | \r | |
2f88bd3a MK |
16 | #define NARROW_CHAR 0xFFF0\r |
17 | #define WIDE_CHAR 0xFFF1\r | |
33026ccf | 18 | \r |
2f88bd3a | 19 | GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = {\r |
e386b444 | 20 | //\r |
21 | // General script area\r | |
22 | //\r | |
2f88bd3a MK |
23 | { (CHAR16)0x1FFF, 1 },\r |
24 | \r | |
e386b444 | 25 | /*\r |
9095d37b | 26 | * Merge the blocks and replace them with the above entry as they fall to\r |
e386b444 | 27 | * the same category and they are all narrow glyph. This will reduce search\r |
28 | * time and table size. The merge will omit the reserved code.\r | |
29 | *\r | |
30 | * Remove the above item if below is un-commented.\r | |
31 | *\r | |
32 | {(CHAR16)0x007F, 1}, // C0 controls and basic Latin. 0x0000-0x007F\r | |
33 | {(CHAR16)0x00FF, 1}, // C1 controls and Latin-1 support. 0x0080-0x00FF\r | |
34 | {(CHAR16)0x017F, 1}, // Latin extended-A. 0x0100-0x017F\r | |
35 | {(CHAR16)0x024F, 1}, // Latin extended-B. 0x0180-0x024F\r | |
36 | {(CHAR16)0x02AF, 1}, // IPA extensions. 0x0250-0x02AF\r | |
37 | {(CHAR16)0x02FF, 1}, // Spacing modifier letters. 0x02B0-0x02FF\r | |
38 | {(CHAR16)0x036F, 1}, // Combining diacritical marks. 0x0300-0x036F\r | |
39 | {(CHAR16)0x03FF, 1}, // Greek. 0x0370-0x03FF\r | |
40 | {(CHAR16)0x04FF, 1}, // Cyrillic. 0x0400-0x04FF\r | |
41 | {(CHAR16)0x052F, 0}, // Unassigned. As Armenian in ver3.0. 0x0500-0x052F\r | |
42 | {(CHAR16)0x058F, 1}, // Armenian. 0x0530-0x058F\r | |
43 | {(CHAR16)0x05FF, 1}, // Hebrew. 0x0590-0x05FF\r | |
44 | {(CHAR16)0x06FF, 1}, // Arabic. 0x0600-0x06FF\r | |
45 | {(CHAR16)0x08FF, 0}, // Unassigned. 0x0700-0x08FF\r | |
46 | {(CHAR16)0x097F, 1}, // Devanagari. 0x0900-0x097F\r | |
47 | {(CHAR16)0x09FF, 1}, // Bengali. 0x0980-0x09FF\r | |
48 | {(CHAR16)0x0A7F, 1}, // Gurmukhi. 0x0A00-0x0A7F\r | |
49 | {(CHAR16)0x0AFF, 1}, // Gujarati. 0x0A80-0x0AFF\r | |
50 | {(CHAR16)0x0B7F, 1}, // Oriya. 0x0B00-0x0B7F\r | |
51 | {(CHAR16)0x0BFF, 1}, // Tamil. (See page 7-92). 0x0B80-0x0BFF\r | |
52 | {(CHAR16)0x0C7F, 1}, // Telugu. 0x0C00-0x0C7F\r | |
53 | {(CHAR16)0x0CFF, 1}, // Kannada. (See page 7-100). 0x0C80-0x0CFF\r | |
54 | {(CHAR16)0x0D7F, 1}, // Malayalam (See page 7-104). 0x0D00-0x0D7F\r | |
55 | {(CHAR16)0x0DFF, 0}, // Unassigned. 0x0D80-0x0DFF\r | |
56 | {(CHAR16)0x0E7F, 1}, // Thai. 0x0E00-0x0E7F\r | |
57 | {(CHAR16)0x0EFF, 1}, // Lao. 0x0E80-0x0EFF\r | |
58 | {(CHAR16)0x0FBF, 1}, // Tibetan. 0x0F00-0x0FBF\r | |
59 | {(CHAR16)0x109F, 0}, // Unassigned. 0x0FC0-0x109F\r | |
60 | {(CHAR16)0x10FF, 1}, // Georgian. 0x10A0-0x10FF\r | |
61 | {(CHAR16)0x11FF, 1}, // Hangul Jamo. 0x1100-0x11FF\r | |
62 | {(CHAR16)0x1DFF, 0}, // Unassigned. 0x1200-0x1DFF\r | |
63 | {(CHAR16)0x1EFF, 1}, // Latin extended additional. 0x1E00-0x1EFF\r | |
64 | {(CHAR16)0x1FFF, 1}, // Greek extended. 0x1F00-0x1FFF\r | |
65 | *\r | |
66 | */\r | |
67 | \r | |
68 | //\r | |
69 | // Symbol area\r | |
70 | //\r | |
2f88bd3a MK |
71 | { (CHAR16)0x2FFF, 1 },\r |
72 | \r | |
e386b444 | 73 | /*\r |
9095d37b | 74 | * Merge the blocks and replace them with the above entry as they fall to\r |
e386b444 | 75 | * the same category and they are all narrow glyph. This will reduce search\r |
76 | * time and table size. The merge will omit the reserved code.\r | |
77 | *\r | |
78 | * Remove the above item if below is un-commented.\r | |
79 | *\r | |
80 | {(CHAR16)0x206F, 1}, // General punctuation. (See page7-154). 0x200-0x206F\r | |
81 | {(CHAR16)0x209F, 1}, // Superscripts and subscripts. 0x2070-0x209F\r | |
82 | {(CHAR16)0x20CF, 1}, // Currency symbols. 0x20A0-0x20CF\r | |
83 | {(CHAR16)0x20FF, 1}, // Combining diacritical marks for symbols. 0x20D0-0x20FF\r | |
84 | {(CHAR16)0x214F, 1}, // Letterlike sympbols. 0x2100-0x214F\r | |
85 | {(CHAR16)0x218F, 1}, // Number forms. 0x2150-0x218F\r | |
86 | {(CHAR16)0x21FF, 1}, // Arrows. 0x2190-0x21FF\r | |
87 | {(CHAR16)0x22FF, 1}, // Mathematical operators. 0x2200-0x22FF\r | |
88 | {(CHAR16)0x23FF, 1}, // Miscellaneous technical. 0x2300-0x23FF\r | |
89 | {(CHAR16)0x243F, 1}, // Control pictures. 0x2400-0x243F\r | |
90 | {(CHAR16)0x245F, 1}, // Optical character recognition. 0x2440-0x245F\r | |
91 | {(CHAR16)0x24FF, 1}, // Enclosed alphanumerics. 0x2460-0x24FF\r | |
92 | {(CHAR16)0x257F, 1}, // Box drawing. 0x2500-0x257F\r | |
93 | {(CHAR16)0x259F, 1}, // Block elements. 0x2580-0x259F\r | |
94 | {(CHAR16)0x25FF, 1}, // Geometric shapes. 0x25A0-0x25FF\r | |
95 | {(CHAR16)0x26FF, 1}, // Miscellaneous symbols. 0x2600-0x26FF\r | |
96 | {(CHAR16)0x27BF, 1}, // Dingbats. 0x2700-0x27BF\r | |
97 | {(CHAR16)0x2FFF, 0}, // Reserved. 0x27C0-0x2FFF\r | |
98 | *\r | |
99 | */\r | |
100 | \r | |
101 | //\r | |
102 | // CJK phonetics and symbol area\r | |
103 | //\r | |
2f88bd3a MK |
104 | { (CHAR16)0x33FF, 2 },\r |
105 | \r | |
e386b444 | 106 | /*\r |
9095d37b | 107 | * Merge the blocks and replace them with the above entry as they fall to\r |
e386b444 | 108 | * the same category and they are all wide glyph. This will reduce search\r |
109 | * time and table size. The merge will omit the reserved code.\r | |
110 | *\r | |
111 | * Remove the above item if below is un-commented.\r | |
112 | *\r | |
113 | {(CHAR16)0x303F, 2}, // CJK symbols and punctuation. 0x3000-0x303F\r | |
114 | {(CHAR16)0x309F, 2}, // Hiragana. 0x3040-0x309F\r | |
115 | {(CHAR16)0x30FF, 2}, // Katakana. 0x30A0-0x30FF\r | |
116 | {(CHAR16)0x312F, 2}, // Bopomofo. 0x3100-0x312F\r | |
117 | {(CHAR16)0x318F, 2}, // Hangul compatibility jamo. 0x3130-0x318F\r | |
118 | {(CHAR16)0x319F, 2}, // Kanbun. 0x3190-0x319F\r | |
119 | {(CHAR16)0x31FF, 0}, // Reserved. As Bopomofo extended in ver3.0. 0x31A0-0x31FF\r | |
120 | {(CHAR16)0x32FF, 2}, // Enclosed CJK letters and months. 0x3200-0x32FF\r | |
121 | {(CHAR16)0x33FF, 2}, // CJK compatibility. 0x3300-0x33FF\r | |
122 | *\r | |
123 | */\r | |
124 | \r | |
125 | //\r | |
126 | // CJK ideograph area\r | |
127 | //\r | |
2f88bd3a MK |
128 | { (CHAR16)0x9FFF, 2 },\r |
129 | \r | |
e386b444 | 130 | /*\r |
9095d37b | 131 | * Merge the blocks and replace them with the above entry as they fall to\r |
e386b444 | 132 | * the same category and they are all wide glyph. This will reduce search\r |
133 | * time and table size. The merge will omit the reserved code.\r | |
134 | *\r | |
135 | * Remove the above item if below is un-commented.\r | |
136 | *\r | |
9095d37b | 137 | {(CHAR16)0x4DFF, 0}, // Reserved. 0x3400-0x4DBF as CJK unified ideographs\r |
e386b444 | 138 | // extension A in ver3.0. 0x3400-0x4DFF\r |
139 | {(CHAR16)0x9FFF, 2}, // CJK unified ideographs. 0x4E00-0x9FFF\r | |
140 | *\r | |
141 | */\r | |
142 | \r | |
143 | //\r | |
144 | // Reserved\r | |
145 | //\r | |
2f88bd3a | 146 | { (CHAR16)0xABFF, 0 }, // Reserved. 0xA000-0xA490 as Yi syllables. 0xA490-0xA4D0\r |
e386b444 | 147 | // as Yi radicals in ver3.0. 0xA000-0xABFF\r |
148 | //\r | |
149 | // Hangul syllables\r | |
150 | //\r | |
2f88bd3a MK |
151 | { (CHAR16)0xD7FF, 2 },\r |
152 | \r | |
e386b444 | 153 | /*\r |
9095d37b | 154 | * Merge the blocks and replace them with the above entry as they fall to\r |
e386b444 | 155 | * the same category and they are all wide glyph. This will reduce search\r |
156 | * time and table size. The merge will omit the reserved code.\r | |
157 | *\r | |
158 | * Remove the above item if below is un-commented.\r | |
159 | *\r | |
160 | {(CHAR16)0xD7A3, 2}, // Hangul syllables. 0xAC00-0xD7A3\r | |
161 | {(CHAR16)0xD7FF, 0}, // Reserved. 0xD7A3-0xD7FF\r | |
162 | *\r | |
163 | */\r | |
164 | \r | |
165 | //\r | |
166 | // Surrogates area\r | |
167 | //\r | |
2f88bd3a | 168 | { (CHAR16)0xDFFF, 0 }, // Surrogates, not used now. 0xD800-0xDFFF\r |
e386b444 | 169 | \r |
170 | //\r | |
171 | // Private use area\r | |
172 | //\r | |
2f88bd3a | 173 | { (CHAR16)0xF8FF, 0 }, // Private use area. 0xE000-0xF8FF\r |
e386b444 | 174 | \r |
175 | //\r | |
176 | // Compatibility area and specials\r | |
177 | //\r | |
2f88bd3a MK |
178 | { (CHAR16)0xFAFF, 2 }, // CJK compatibility ideographs. 0xF900-0xFAFF\r |
179 | { (CHAR16)0xFB4F, 1 }, // Alphabetic presentation forms. 0xFB00-0xFB4F\r | |
180 | { (CHAR16)0xFDFF, 1 }, // Arabic presentation forms-A. 0xFB50-0xFDFF\r | |
181 | { (CHAR16)0xFE1F, 0 }, // Reserved. As variation selectors in ver3.0. 0xFE00-0xFE1F\r | |
182 | { (CHAR16)0xFE2F, 1 }, // Combining half marks. 0xFE20-0xFE2F\r | |
183 | { (CHAR16)0xFE4F, 2 }, // CJK compatibility forms. 0xFE30-0xFE4F\r | |
184 | { (CHAR16)0xFE6F, 1 }, // Small Form Variants. 0xFE50-0xFE6F\r | |
185 | { (CHAR16)0xFEFF, 1 }, // Arabic presentation forms-B. 0xFE70-0xFEFF\r | |
186 | { (CHAR16)0xFFEF, 1 }, // Half width and full width forms. 0xFF00-0xFFEF\r | |
187 | { (CHAR16)0xFFFF, 0 }, // Speicials. 0xFFF0-0xFFFF\r | |
e386b444 | 188 | };\r |
189 | \r | |
190 | /**\r | |
cf8ae2f6 | 191 | Retrieves the width of a Unicode character.\r |
192 | \r | |
193 | This function computes and returns the width of the Unicode character specified\r | |
194 | by UnicodeChar.\r | |
e386b444 | 195 | \r |
196 | @param UnicodeChar A Unicode character.\r | |
197 | \r | |
198 | @retval 0 The width if UnicodeChar could not be determined.\r | |
199 | @retval 1 UnicodeChar is a narrow glyph.\r | |
200 | @retval 2 UnicodeChar is a wide glyph.\r | |
201 | \r | |
202 | **/\r | |
203 | UINTN\r | |
204 | EFIAPI\r | |
205 | GetGlyphWidth (\r | |
206 | IN CHAR16 UnicodeChar\r | |
207 | )\r | |
208 | {\r | |
2f88bd3a MK |
209 | UINTN Index;\r |
210 | UINTN Low;\r | |
211 | UINTN High;\r | |
212 | CONST UNICODE_WIDTH_ENTRY *Item;\r | |
213 | \r | |
214 | Item = NULL;\r | |
215 | Low = 0;\r | |
216 | High = (sizeof (mUnicodeWidthTable)) / (sizeof (UNICODE_WIDTH_ENTRY)) - 1;\r | |
e386b444 | 217 | while (Low <= High) {\r |
218 | Index = (Low + High) >> 1;\r | |
219 | Item = &(mUnicodeWidthTable[Index]);\r | |
220 | if (Index == 0) {\r | |
221 | if (UnicodeChar <= Item->WChar) {\r | |
222 | break;\r | |
223 | }\r | |
224 | \r | |
225 | return 0;\r | |
226 | }\r | |
227 | \r | |
228 | if (UnicodeChar > Item->WChar) {\r | |
229 | Low = Index + 1;\r | |
230 | } else if (UnicodeChar <= mUnicodeWidthTable[Index - 1].WChar) {\r | |
231 | High = Index - 1;\r | |
232 | } else {\r | |
233 | //\r | |
234 | // Index - 1 < UnicodeChar <= Index. Found\r | |
235 | //\r | |
236 | break;\r | |
237 | }\r | |
238 | }\r | |
239 | \r | |
240 | if (Low <= High) {\r | |
241 | return Item->Width;\r | |
242 | }\r | |
243 | \r | |
244 | return 0;\r | |
245 | }\r | |
246 | \r | |
247 | /**\r | |
1d37ab9f | 248 | Computes the display length of a Null-terminated Unicode String.\r |
249 | \r | |
9095d37b LG |
250 | This function computes and returns the display length of the Null-terminated\r |
251 | Unicode string specified by String. If String is NULL then 0 is returned. If\r | |
252 | any of the widths of the Unicode characters in String can not be determined,\r | |
253 | then 0 is returned. The display width of String can be computed by summing the\r | |
254 | display widths of each Unicode character in String. Unicode characters that\r | |
255 | are narrow glyphs have a width of 1, and Unicode characters that are width glyphs\r | |
58380e9c | 256 | have a width of 2. If String is not aligned on a 16-bit boundary, then ASSERT().\r |
e386b444 | 257 | \r |
258 | @param String A pointer to a Null-terminated Unicode string.\r | |
259 | \r | |
260 | @return The display length of the Null-terminated Unicode string specified by String.\r | |
9095d37b | 261 | \r |
e386b444 | 262 | **/\r |
263 | UINTN\r | |
264 | EFIAPI\r | |
265 | UnicodeStringDisplayLength (\r | |
266 | IN CONST CHAR16 *String\r | |
267 | )\r | |
268 | {\r | |
2f88bd3a MK |
269 | UINTN Length;\r |
270 | UINTN Width;\r | |
e386b444 | 271 | \r |
272 | if (String == NULL) {\r | |
273 | return 0;\r | |
274 | }\r | |
275 | \r | |
276 | Length = 0;\r | |
277 | while (*String != 0) {\r | |
278 | Width = GetGlyphWidth (*String);\r | |
279 | if (Width == 0) {\r | |
280 | return 0;\r | |
281 | }\r | |
282 | \r | |
283 | Length += Width;\r | |
284 | String++;\r | |
285 | }\r | |
286 | \r | |
287 | return Length;\r | |
288 | }\r | |
db2ef756 | 289 | \r |
33026ccf | 290 | /**\r |
9095d37b | 291 | Count the storage space of a Unicode string.\r |
33026ccf ED |
292 | \r |
293 | This function handles the Unicode string with NARROW_CHAR\r | |
294 | and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR\r | |
295 | does not count in the resultant output. If a WIDE_CHAR is\r | |
296 | hit, then 2 Unicode character will consume an output storage\r | |
297 | space with size of CHAR16 till a NARROW_CHAR is hit.\r | |
298 | \r | |
299 | @param String The input string to be counted.\r | |
300 | @param LimitLen Whether need to limit the string length.\r | |
301 | @param MaxWidth The max length this function supported.\r | |
9095d37b | 302 | @param Offset The max index of the string can be show out.\r |
33026ccf ED |
303 | \r |
304 | @return Storage space for the input string.\r | |
305 | \r | |
306 | **/\r | |
307 | UINTN\r | |
308 | UefiLibGetStringWidth (\r | |
2f88bd3a MK |
309 | IN CHAR16 *String,\r |
310 | IN BOOLEAN LimitLen,\r | |
311 | IN UINTN MaxWidth,\r | |
312 | OUT UINTN *Offset\r | |
33026ccf ED |
313 | )\r |
314 | {\r | |
2f88bd3a MK |
315 | UINTN Index;\r |
316 | UINTN Count;\r | |
317 | UINTN IncrementValue;\r | |
33026ccf ED |
318 | \r |
319 | if (String == NULL) {\r | |
320 | return 0;\r | |
321 | }\r | |
322 | \r | |
2f88bd3a MK |
323 | Index = 0;\r |
324 | Count = 0;\r | |
325 | IncrementValue = 1;\r | |
33026ccf ED |
326 | \r |
327 | do {\r | |
328 | //\r | |
329 | // Advance to the null-terminator or to the first width directive\r | |
330 | //\r | |
2f88bd3a | 331 | for ( ; (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0); Index++) {\r |
8b5b3d42 ED |
332 | Count = Count + IncrementValue;\r |
333 | \r | |
2f88bd3a | 334 | if (LimitLen && (Count > MaxWidth)) {\r |
33026ccf ED |
335 | break;\r |
336 | }\r | |
337 | }\r | |
338 | \r | |
339 | //\r | |
340 | // We hit the null-terminator, we now have a count\r | |
341 | //\r | |
342 | if (String[Index] == 0) {\r | |
343 | break;\r | |
344 | }\r | |
345 | \r | |
2f88bd3a | 346 | if (LimitLen && (Count > MaxWidth)) {\r |
8b5b3d42 | 347 | *Offset = Index;\r |
33026ccf ED |
348 | break;\r |
349 | }\r | |
350 | \r | |
351 | //\r | |
352 | // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed\r | |
353 | // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)\r | |
354 | //\r | |
355 | if (String[Index] == NARROW_CHAR) {\r | |
356 | //\r | |
357 | // Skip to the next character\r | |
358 | //\r | |
359 | Index++;\r | |
360 | IncrementValue = 1;\r | |
361 | } else {\r | |
362 | //\r | |
363 | // Skip to the next character\r | |
364 | //\r | |
365 | Index++;\r | |
366 | IncrementValue = 2;\r | |
367 | }\r | |
368 | } while (String[Index] != 0);\r | |
369 | \r | |
33026ccf ED |
370 | return Count * sizeof (CHAR16);\r |
371 | }\r | |
372 | \r | |
db2ef756 | 373 | /**\r |
9095d37b | 374 | Draws a dialog box to the console output device specified by\r |
db2ef756 | 375 | ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke\r |
9095d37b | 376 | from the console input device specified by ConIn defined in the\r |
db2ef756 LG |
377 | EFI_SYSTEM_TABLE.\r |
378 | \r | |
379 | If there are no strings in the variable argument list, then ASSERT().\r | |
380 | If all the strings in the variable argument list are empty, then ASSERT().\r | |
381 | \r | |
382 | @param[in] Attribute Specifies the foreground and background color of the popup.\r | |
9095d37b | 383 | @param[out] Key A pointer to the EFI_KEY value of the key that was\r |
db2ef756 LG |
384 | pressed. This is an optional parameter that may be NULL.\r |
385 | If it is NULL then no wait for a keypress will be performed.\r | |
386 | @param[in] ... The variable argument list that contains pointers to Null-\r | |
9095d37b | 387 | terminated Unicode strings to display in the dialog box.\r |
db2ef756 LG |
388 | The variable argument list is terminated by a NULL.\r |
389 | \r | |
390 | **/\r | |
391 | VOID\r | |
392 | EFIAPI\r | |
393 | CreatePopUp (\r | |
9095d37b | 394 | IN UINTN Attribute,\r |
d0e2f823 | 395 | OUT EFI_INPUT_KEY *Key OPTIONAL,\r |
db2ef756 LG |
396 | ...\r |
397 | )\r | |
398 | {\r | |
f04544be | 399 | EFI_STATUS Status;\r |
db2ef756 LG |
400 | VA_LIST Args;\r |
401 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r | |
402 | EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode;\r | |
403 | UINTN Columns;\r | |
404 | UINTN Rows;\r | |
405 | UINTN Column;\r | |
406 | UINTN Row;\r | |
407 | UINTN NumberOfLines;\r | |
408 | UINTN MaxLength;\r | |
409 | CHAR16 *String;\r | |
410 | UINTN Length;\r | |
411 | CHAR16 *Line;\r | |
412 | UINTN EventIndex;\r | |
8b5b3d42 | 413 | CHAR16 *TmpString;\r |
db2ef756 LG |
414 | \r |
415 | //\r | |
9095d37b | 416 | // Determine the length of the longest line in the popup and the the total\r |
db2ef756 LG |
417 | // number of lines in the popup\r |
418 | //\r | |
419 | VA_START (Args, Key);\r | |
2f88bd3a | 420 | MaxLength = 0;\r |
db2ef756 LG |
421 | NumberOfLines = 0;\r |
422 | while ((String = VA_ARG (Args, CHAR16 *)) != NULL) {\r | |
33026ccf | 423 | MaxLength = MAX (MaxLength, UefiLibGetStringWidth (String, FALSE, 0, NULL) / 2);\r |
db2ef756 LG |
424 | NumberOfLines++;\r |
425 | }\r | |
2f88bd3a | 426 | \r |
db2ef756 LG |
427 | VA_END (Args);\r |
428 | \r | |
429 | //\r | |
430 | // If the total number of lines in the popup is zero, then ASSERT()\r | |
431 | //\r | |
432 | ASSERT (NumberOfLines != 0);\r | |
433 | \r | |
434 | //\r | |
435 | // If the maximum length of all the strings is zero, then ASSERT()\r | |
436 | //\r | |
437 | ASSERT (MaxLength != 0);\r | |
438 | \r | |
439 | //\r | |
440 | // Cache a pointer to the Simple Text Output Protocol in the EFI System Table\r | |
441 | //\r | |
442 | ConOut = gST->ConOut;\r | |
9095d37b | 443 | \r |
db2ef756 LG |
444 | //\r |
445 | // Save the current console cursor position and attributes\r | |
446 | //\r | |
447 | CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode));\r | |
448 | \r | |
449 | //\r | |
450 | // Retrieve the number of columns and rows in the current console mode\r | |
451 | //\r | |
452 | ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows);\r | |
453 | \r | |
454 | //\r | |
455 | // Disable cursor and set the foreground and background colors specified by Attribute\r | |
456 | //\r | |
457 | ConOut->EnableCursor (ConOut, FALSE);\r | |
458 | ConOut->SetAttribute (ConOut, Attribute);\r | |
459 | \r | |
460 | //\r | |
461 | // Limit NumberOfLines to height of the screen minus 3 rows for the box itself\r | |
462 | //\r | |
463 | NumberOfLines = MIN (NumberOfLines, Rows - 3);\r | |
464 | \r | |
465 | //\r | |
466 | // Limit MaxLength to width of the screen minus 2 columns for the box itself\r | |
467 | //\r | |
468 | MaxLength = MIN (MaxLength, Columns - 2);\r | |
469 | \r | |
470 | //\r | |
471 | // Compute the starting row and starting column for the popup\r | |
472 | //\r | |
473 | Row = (Rows - (NumberOfLines + 3)) / 2;\r | |
474 | Column = (Columns - (MaxLength + 2)) / 2;\r | |
475 | \r | |
476 | //\r | |
477 | // Allocate a buffer for a single line of the popup with borders and a Null-terminator\r | |
478 | //\r | |
479 | Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16));\r | |
11171f03 | 480 | ASSERT (Line != NULL);\r |
db2ef756 LG |
481 | \r |
482 | //\r | |
9095d37b | 483 | // Draw top of popup box\r |
db2ef756 LG |
484 | //\r |
485 | SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r | |
486 | Line[0] = BOXDRAW_DOWN_RIGHT;\r | |
487 | Line[MaxLength + 1] = BOXDRAW_DOWN_LEFT;\r | |
488 | Line[MaxLength + 2] = L'\0';\r | |
489 | ConOut->SetCursorPosition (ConOut, Column, Row++);\r | |
490 | ConOut->OutputString (ConOut, Line);\r | |
491 | \r | |
492 | //\r | |
493 | // Draw middle of the popup with strings\r | |
494 | //\r | |
495 | VA_START (Args, Key);\r | |
496 | while ((String = VA_ARG (Args, CHAR16 *)) != NULL && NumberOfLines > 0) {\r | |
db2ef756 | 497 | SetMem16 (Line, (MaxLength + 2) * 2, L' ');\r |
33026ccf ED |
498 | Line[0] = BOXDRAW_VERTICAL;\r |
499 | Line[MaxLength + 1] = BOXDRAW_VERTICAL;\r | |
500 | Line[MaxLength + 2] = L'\0';\r | |
501 | ConOut->SetCursorPosition (ConOut, Column, Row);\r | |
502 | ConOut->OutputString (ConOut, Line);\r | |
503 | Length = UefiLibGetStringWidth (String, FALSE, 0, NULL) / 2;\r | |
db2ef756 LG |
504 | if (Length <= MaxLength) {\r |
505 | //\r | |
506 | // Length <= MaxLength\r | |
507 | //\r | |
33026ccf ED |
508 | ConOut->SetCursorPosition (ConOut, Column + 1 + (MaxLength - Length) / 2, Row++);\r |
509 | ConOut->OutputString (ConOut, String);\r | |
db2ef756 LG |
510 | } else {\r |
511 | //\r | |
512 | // Length > MaxLength\r | |
513 | //\r | |
33026ccf | 514 | UefiLibGetStringWidth (String, TRUE, MaxLength, &Length);\r |
8b5b3d42 ED |
515 | TmpString = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));\r |
516 | ASSERT (TmpString != NULL);\r | |
df1e74f5 HW |
517 | StrnCpyS (TmpString, Length + 1, String, Length - 3);\r |
518 | StrCatS (TmpString, Length + 1, L"...");\r | |
33026ccf ED |
519 | \r |
520 | ConOut->SetCursorPosition (ConOut, Column + 1, Row++);\r | |
8b5b3d42 ED |
521 | ConOut->OutputString (ConOut, TmpString);\r |
522 | FreePool (TmpString);\r | |
db2ef756 | 523 | }\r |
2f88bd3a | 524 | \r |
db2ef756 LG |
525 | NumberOfLines--;\r |
526 | }\r | |
2f88bd3a | 527 | \r |
db2ef756 LG |
528 | VA_END (Args);\r |
529 | \r | |
530 | //\r | |
531 | // Draw bottom of popup box\r | |
532 | //\r | |
533 | SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r | |
534 | Line[0] = BOXDRAW_UP_RIGHT;\r | |
535 | Line[MaxLength + 1] = BOXDRAW_UP_LEFT;\r | |
536 | Line[MaxLength + 2] = L'\0';\r | |
537 | ConOut->SetCursorPosition (ConOut, Column, Row++);\r | |
538 | ConOut->OutputString (ConOut, Line);\r | |
539 | \r | |
540 | //\r | |
541 | // Free the allocated line buffer\r | |
542 | //\r | |
543 | FreePool (Line);\r | |
544 | \r | |
545 | //\r | |
546 | // Restore the cursor visibility, position, and attributes\r | |
547 | //\r | |
2f88bd3a | 548 | ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible);\r |
db2ef756 | 549 | ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow);\r |
2f88bd3a | 550 | ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute);\r |
db2ef756 LG |
551 | \r |
552 | //\r | |
553 | // Wait for a keystroke\r | |
554 | //\r | |
555 | if (Key != NULL) {\r | |
f04544be RN |
556 | while (TRUE) {\r |
557 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key);\r | |
558 | if (!EFI_ERROR (Status)) {\r | |
559 | break;\r | |
560 | }\r | |
561 | \r | |
562 | //\r | |
563 | // If we encounter error, continue to read another key in.\r | |
564 | //\r | |
565 | if (Status != EFI_NOT_READY) {\r | |
566 | continue;\r | |
567 | }\r | |
2f88bd3a | 568 | \r |
f04544be RN |
569 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r |
570 | }\r | |
db2ef756 LG |
571 | }\r |
572 | }\r |