]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/SetupBrowser.c
String Reference Cleanup.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / SetupBrowser.c
CommitLineData
26a76fbc 1/** @file\r
0368663f 2Framework to UEFI 2.1 Setup Browser Thunk. The file consume EFI_FORM_BROWSER2_PROTOCOL\r
3to produce a EFI_FORM_BROWSER_PROTOCOL.\r
4\r
584d5652
HT
5Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
0368663f 7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "HiiDatabase.h"\r
a235abd2 17#include "SetupBrowser.h"\r
18\r
19EFI_GUID gFrameworkBdsFrontPageFormsetGuid = FRAMEWORK_BDS_FRONTPAGE_FORMSET_GUID;\r
20EFI_HII_HANDLE gStringPackHandle = NULL;\r
21BOOLEAN mFrontPageDisplayed = FALSE;\r
22//\r
23// 106F3545-B788-4cb5-9D2A-CE0CDB208DF5\r
24//\r
25EFI_GUID gEfiHiiThunkProducerGuid = { 0x106f3545, 0xb788, 0x4cb5, { 0x9d, 0x2a, 0xce, 0xc, 0xdb, 0x20, 0x8d, 0xf5 } }; \r
26\r
27\r
28/**\r
29 Get string by string id from HII Interface\r
30\r
31\r
32 @param Id String ID.\r
33\r
34 @retval CHAR16 * String from ID.\r
35 @retval NULL If error occurs.\r
36\r
37**/\r
38CHAR16 *\r
39GetStringById (\r
40 IN EFI_STRING_ID Id\r
41 )\r
42{\r
cb7d01c0 43 return HiiGetString (gStringPackHandle, Id, NULL);\r
a235abd2 44}\r
cb7d01c0 45\r
a235abd2 46/**\r
47\r
48 Show progress bar with title above it. It only works in Graphics mode.\r
49\r
50\r
51 @param TitleForeground Foreground color for Title.\r
52 @param TitleBackground Background color for Title.\r
53 @param Title Title above progress bar.\r
54 @param ProgressColor Progress bar color.\r
55 @param Progress Progress (0-100)\r
56 @param PreviousValue The previous value of the progress.\r
57\r
58 @retval EFI_STATUS Success update the progress bar\r
59\r
60**/\r
61EFI_STATUS\r
62PlatformBdsShowProgress (\r
63 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,\r
64 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,\r
65 IN CHAR16 *Title,\r
66 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,\r
67 IN UINTN Progress,\r
68 IN UINTN PreviousValue\r
69 )\r
70{\r
71 EFI_STATUS Status;\r
72 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
73 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
74 UINT32 SizeOfX;\r
75 UINT32 SizeOfY;\r
76 UINT32 ColorDepth;\r
77 UINT32 RefreshRate;\r
78 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r
79 UINTN BlockHeight;\r
80 UINTN BlockWidth;\r
81 UINTN BlockNum;\r
82 UINTN PosX;\r
83 UINTN PosY;\r
84 UINTN Index;\r
85\r
86 if (Progress > 100) {\r
87 return EFI_INVALID_PARAMETER;\r
88 }\r
89\r
90 UgaDraw = NULL;\r
91 Status = gBS->HandleProtocol (\r
92 gST->ConsoleOutHandle,\r
93 &gEfiGraphicsOutputProtocolGuid,\r
94 (VOID **) &GraphicsOutput\r
95 );\r
96 if (EFI_ERROR (Status)) {\r
97 GraphicsOutput = NULL;\r
98\r
99 Status = gBS->HandleProtocol (\r
100 gST->ConsoleOutHandle,\r
101 &gEfiUgaDrawProtocolGuid,\r
102 (VOID **) &UgaDraw\r
103 );\r
104 }\r
234980f6 105 if (EFI_ERROR (Status) || (GraphicsOutput == NULL && UgaDraw == NULL)) {\r
a235abd2 106 return EFI_UNSUPPORTED;\r
107 }\r
108\r
109 SizeOfX = 0;\r
110 SizeOfY = 0;\r
111 if (GraphicsOutput != NULL) {\r
112 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
113 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
114 } else {\r
115 Status = UgaDraw->GetMode (\r
116 UgaDraw,\r
117 &SizeOfX,\r
118 &SizeOfY,\r
119 &ColorDepth,\r
120 &RefreshRate\r
121 );\r
122 if (EFI_ERROR (Status)) {\r
123 return EFI_UNSUPPORTED;\r
124 }\r
125 }\r
126\r
127 BlockWidth = SizeOfX / 100;\r
128 BlockHeight = SizeOfY / 50;\r
129\r
130 BlockNum = Progress;\r
131\r
132 PosX = 0;\r
133 PosY = SizeOfY * 48 / 50;\r
134\r
135 if (BlockNum == 0) {\r
136 //\r
137 // Clear progress area\r
138 //\r
139 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
140\r
141 if (GraphicsOutput != NULL) {\r
142 Status = GraphicsOutput->Blt (\r
143 GraphicsOutput,\r
144 &Color,\r
145 EfiBltVideoFill,\r
146 0,\r
147 0,\r
148 0,\r
149 PosY - EFI_GLYPH_HEIGHT - 1,\r
150 SizeOfX,\r
151 SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),\r
152 SizeOfX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
153 );\r
154 } else {\r
155 Status = UgaDraw->Blt (\r
156 UgaDraw,\r
157 (EFI_UGA_PIXEL *) &Color,\r
158 EfiUgaVideoFill,\r
159 0,\r
160 0,\r
161 0,\r
162 PosY - EFI_GLYPH_HEIGHT - 1,\r
163 SizeOfX,\r
164 SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),\r
165 SizeOfX * sizeof (EFI_UGA_PIXEL)\r
166 );\r
167 }\r
168 }\r
169 //\r
170 // Show progress by drawing blocks\r
171 //\r
172 for (Index = PreviousValue; Index < BlockNum; Index++) {\r
173 PosX = Index * BlockWidth;\r
174 if (GraphicsOutput != NULL) {\r
175 Status = GraphicsOutput->Blt (\r
176 GraphicsOutput,\r
177 &ProgressColor,\r
178 EfiBltVideoFill,\r
179 0,\r
180 0,\r
181 PosX,\r
182 PosY,\r
183 BlockWidth - 1,\r
184 BlockHeight,\r
185 (BlockWidth) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
186 );\r
187 } else {\r
188 Status = UgaDraw->Blt (\r
189 UgaDraw,\r
190 (EFI_UGA_PIXEL *) &ProgressColor,\r
191 EfiUgaVideoFill,\r
192 0,\r
193 0,\r
194 PosX,\r
195 PosY,\r
196 BlockWidth - 1,\r
197 BlockHeight,\r
198 (BlockWidth) * sizeof (EFI_UGA_PIXEL)\r
199 );\r
200 }\r
201 }\r
202\r
203 PrintXY (\r
204 (SizeOfX - StrLen (Title) * EFI_GLYPH_WIDTH) / 2,\r
205 PosY - EFI_GLYPH_HEIGHT - 1,\r
206 &TitleForeground,\r
207 &TitleBackground,\r
208 Title\r
209 );\r
210\r
211 return EFI_SUCCESS;\r
212}\r
213\r
214/**\r
215 Function waits for a given event to fire, or for an optional timeout to expire.\r
216\r
217\r
218 @param Event The event to wait for\r
219 \r
220 @param Timeout An optional timeout value in 100 ns units.\r
221\r
222 @retval EFI_SUCCESS Event fired before Timeout expired.\r
223 @retval EFI_TIME_OUT Timout expired before Event fired..\r
224\r
225**/\r
226EFI_STATUS\r
227WaitForSingleEvent (\r
228 IN EFI_EVENT Event,\r
229 IN UINT64 Timeout OPTIONAL\r
230 )\r
231{\r
232 EFI_STATUS Status;\r
233 UINTN Index;\r
234 EFI_EVENT TimerEvent;\r
235 EFI_EVENT WaitList[2];\r
236\r
237 if (Timeout != 0) {\r
238 //\r
239 // Create a timer event\r
240 //\r
241 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
242 if (!EFI_ERROR (Status)) {\r
243 //\r
244 // Set the timer event\r
245 //\r
246 gBS->SetTimer (\r
247 TimerEvent,\r
248 TimerRelative,\r
249 Timeout\r
250 );\r
251\r
252 //\r
253 // Wait for the original event or the timer\r
254 //\r
255 WaitList[0] = Event;\r
256 WaitList[1] = TimerEvent;\r
257 Status = gBS->WaitForEvent (2, WaitList, &Index);\r
258 gBS->CloseEvent (TimerEvent);\r
259\r
260 //\r
261 // If the timer expired, change the return to timed out\r
262 //\r
263 if (!EFI_ERROR (Status) && Index == 1) {\r
264 Status = EFI_TIMEOUT;\r
265 }\r
266 }\r
267 } else {\r
268 //\r
269 // No timeout... just wait on the event\r
270 //\r
271 Status = gBS->WaitForEvent (1, &Event, &Index);\r
272 ASSERT (!EFI_ERROR (Status));\r
273 ASSERT (Index == 0);\r
274 }\r
275\r
276 return Status;\r
277}\r
278\r
279/**\r
280 Function show progress bar to wait for user input.\r
281\r
282\r
283 @param TimeoutDefault - The fault time out value before the system\r
284 continue to boot.\r
285\r
286 @retval EFI_SUCCESS User pressed some key except "Enter"\r
287 @retval EFI_TIME_OUT Timout expired or user press "Enter"\r
288\r
289**/\r
290EFI_STATUS\r
291ShowProgress (\r
292 IN UINT16 TimeoutDefault\r
293 )\r
294{\r
295 EFI_STATUS Status;\r
296 CHAR16 *TmpStr;\r
297 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
298 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
299 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r
300 EFI_INPUT_KEY Key;\r
301 UINT16 TimeoutRemain;\r
302\r
303 if (TimeoutDefault == 0) {\r
304 return EFI_TIMEOUT;\r
305 }\r
306\r
307 DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));\r
308 \r
309 SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
310 SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
311 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
312\r
313 //\r
314 // Clear the progress status bar first\r
315 //\r
316 TmpStr = GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION));\r
317 if (TmpStr != NULL) {\r
318 PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);\r
319 }\r
320\r
321 TimeoutRemain = TimeoutDefault;\r
322 while (TimeoutRemain != 0) {\r
323 DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));\r
324 \r
325 Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);\r
326 if (Status != EFI_TIMEOUT) {\r
327 break;\r
328 }\r
329 TimeoutRemain--;\r
330\r
331 //\r
332 // Show progress\r
333 //\r
334 if (TmpStr != NULL) {\r
335 PlatformBdsShowProgress (\r
336 Foreground,\r
337 Background,\r
338 TmpStr,\r
339 Color,\r
340 ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),\r
341 0\r
342 );\r
343 }\r
344 }\r
345 gBS->FreePool (TmpStr);\r
346\r
347 //\r
348 // Timeout expired\r
349 //\r
350 if (TimeoutRemain == 0) {\r
351 return EFI_TIMEOUT;\r
352 }\r
353\r
354 //\r
355 // User pressed some key\r
356 //\r
357 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
358 if (EFI_ERROR (Status)) {\r
359 return Status;\r
360 }\r
361\r
362 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
363 //\r
364 // User pressed enter, equivalent to select "continue"\r
365 //\r
366 return EFI_TIMEOUT;\r
367 }\r
368\r
369 return EFI_SUCCESS;\r
370}\r
371\r
372/**\r
373 Return the default value for system Timeout variable.\r
374\r
375 @return Timeout value.\r
376\r
377**/\r
378UINT16\r
379EFIAPI\r
380GetTimeout (\r
381 VOID\r
382 )\r
383{\r
78b719ae 384 return PcdGet16 (PcdPlatformBootTimeOut);\r
a235abd2 385}\r
386\r
0368663f 387\r
a9d85320 388/**\r
389 This is the Framework Setup Browser interface which displays a FormSet.\r
390\r
391 @param This The EFI_FORM_BROWSER_PROTOCOL context.\r
392 @param UseDatabase TRUE if the FormSet is from HII database. The Thunk implementation\r
393 only support UseDatabase is TRUE.\r
394 @param Handle The Handle buffer.\r
395 @param HandleCount The number of Handle in the Handle Buffer. It must be 1 for this implementation.\r
396 @param Packet The pointer to data buffer containing IFR and String package. Not supported.\r
397 @param CallbackHandle Not supported.\r
398 @param NvMapOverride The buffer is used only when there is no NV variable to define the \r
399 current settings and the caller needs to provide to the browser the\r
400 current settings for the the "fake" NV variable. If used, no saving of\r
401 an NV variable is possbile. This parameter is also ignored if Handle is NULL.\r
26a76fbc
LG
402 @param ScreenDimensions \r
403 Allows the browser to be called so that it occupies a portion of the physical \r
404 screen instead of dynamically determining the screen dimensions.\r
405 @param ResetRequired This BOOLEAN value denotes whether a reset is required based on the data that \r
406 might have been changed. The ResetRequired parameter is primarily applicable \r
407 for configuration applications, and is an optional parameter.\r
a9d85320 408\r
409 @retval EFI_SUCCESS If the Formset is displayed correctly.\r
410 @retval EFI_UNSUPPORTED If UseDatabase is FALSE or HandleCount is not 1.\r
411 @retval EFI_INVALID_PARAMETER If the *Handle passed in is not found in the database.\r
412**/\r
0368663f 413EFI_STATUS\r
414EFIAPI \r
415ThunkSendForm (\r
416 IN EFI_FORM_BROWSER_PROTOCOL *This,\r
417 IN BOOLEAN UseDatabase,\r
418 IN FRAMEWORK_EFI_HII_HANDLE *Handle,\r
419 IN UINTN HandleCount,\r
aa2ebe0f 420 IN EFI_IFR_PACKET *Packet, OPTIONAL\r
0368663f 421 IN EFI_HANDLE CallbackHandle, OPTIONAL\r
422 IN UINT8 *NvMapOverride, OPTIONAL\r
423 IN FRAMEWORK_EFI_SCREEN_DESCRIPTOR *ScreenDimensions, OPTIONAL\r
424 OUT BOOLEAN *ResetRequired OPTIONAL\r
425 )\r
426{\r
427 EFI_STATUS Status;\r
428 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
429 HII_THUNK_CONTEXT *ThunkContext;\r
430 HII_THUNK_PRIVATE_DATA *Private;\r
431 EFI_FORMBROWSER_THUNK_PRIVATE_DATA *BrowserPrivate;\r
432\r
433 if (!UseDatabase) {\r
434 //\r
a3318eaf 435 // ThunkSendForm only support displays forms registered into the HII database.\r
0368663f 436 //\r
437 return EFI_UNSUPPORTED;\r
438 }\r
439\r
440 if (HandleCount != 1 ) {\r
441 return EFI_UNSUPPORTED;\r
442 }\r
443\r
444 BrowserPrivate = EFI_FORMBROWSER_THUNK_PRIVATE_DATA_FROM_THIS (This);\r
445 Private = BrowserPrivate->ThunkPrivate;\r
446\r
447 ThunkContext = FwHiiHandleToThunkContext (Private, *Handle);\r
448 if (ThunkContext == NULL) {\r
449 return EFI_INVALID_PARAMETER;\r
450 }\r
451\r
a235abd2 452 //\r
453 // Following UEFI spec to do auto booting after a time-out. This feature is implemented \r
454 // in Framework Setup Browser and moved to MdeModulePkg/Universal/BdsDxe. The auto booting is\r
455 // moved here in HII Thunk module. \r
456 //\r
457 if (CompareGuid (&gFrameworkBdsFrontPageFormsetGuid, &ThunkContext->FormSet->Guid) && !mFrontPageDisplayed) {\r
458 //\r
459 // Send form is called before entering the \r
460 //\r
461 mFrontPageDisplayed = TRUE;\r
462 Status = ShowProgress (GetTimeout ());\r
463\r
464 if (EFI_ERROR (Status)) {\r
465 return Status;\r
466 }\r
467 }\r
468 \r
0368663f 469 if (NvMapOverride != NULL) {\r
470 ThunkContext->NvMapOverride = NvMapOverride;\r
471 }\r
472\r
473 Status = mFormBrowser2Protocol->SendForm (\r
474 mFormBrowser2Protocol,\r
475 &ThunkContext->UefiHiiHandle,\r
476 1,\r
477 NULL,\r
478 0,\r
479 (EFI_SCREEN_DESCRIPTOR *) ScreenDimensions,\r
480 &ActionRequest\r
481 );\r
482\r
483 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
484 *ResetRequired = TRUE;\r
485 }\r
486 \r
487 return Status;\r
488}\r
489\r
a9d85320 490/** \r
491\r
492 Rountine used to display a generic dialog interface and return \r
493 the Key or Input from user input.\r
494\r
a5420536 495 @param LinesNumber The number of lines for the dialog box.\r
a9d85320 496 @param HotKey Defines if a single character is parsed (TRUE) and returned in KeyValue\r
497 or if a string is returned in StringBuffer.\r
498 @param MaximumStringSize The maximum size in bytes of a typed-in string.\r
a5420536
LG
499 @param StringBuffer On return contains the typed-in string if HotKey is FALSE.\r
500 @param Key The EFI_INPUT_KEY value returned if HotKey is TRUE.\r
501 @param FirstString The pointer to the first string in the list of strings\r
a9d85320 502 that comprise the dialog box.\r
503 @param ... A series of NumberOfLines text strings that will be used\r
504 to construct the dialog box.\r
505 @retval EFI_SUCCESS The dialog is created successfully and user interaction was received.\r
506 @retval EFI_DEVICE_ERROR The user typed in an ESC.\r
507 @retval EFI_INVALID_PARAMETER One of the parameters was invalid.(StringBuffer == NULL && HotKey == FALSE).\r
508**/\r
0368663f 509EFI_STATUS\r
510EFIAPI \r
511ThunkCreatePopUp (\r
a5420536 512 IN UINTN LinesNumber,\r
0368663f 513 IN BOOLEAN HotKey,\r
514 IN UINTN MaximumStringSize,\r
515 OUT CHAR16 *StringBuffer,\r
a5420536
LG
516 OUT EFI_INPUT_KEY *Key,\r
517 IN CHAR16 *FirstString,\r
0368663f 518 ...\r
519 )\r
520{\r
a5420536
LG
521 VA_LIST Args;\r
522 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r
523 EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode;\r
524 UINTN Columns;\r
525 UINTN Rows;\r
526 UINTN Column;\r
527 UINTN Row;\r
528 UINTN NumberOfLines;\r
529 UINTN MaxLength;\r
530 CHAR16 *String;\r
531 UINTN Length;\r
532 CHAR16 *Line;\r
533 UINTN EventIndex;\r
534\r
535 if (!HotKey) {\r
0368663f 536 return EFI_UNSUPPORTED;\r
537 }\r
a5420536
LG
538 \r
539 if (MaximumStringSize == 0) {\r
540 //\r
541 // Blank strint to output\r
542 //\r
543 return EFI_INVALID_PARAMETER;\r
544 }\r
545\r
546 //\r
547 // Determine the length of the longest line in the popup and the the total \r
548 // number of lines in the popup\r
549 //\r
550 MaxLength = StrLen (FirstString);\r
551 NumberOfLines = 1;\r
552 VA_START (Args, FirstString);\r
553 while ((String = VA_ARG (Args, CHAR16 *)) != NULL) {\r
554 MaxLength = MAX (MaxLength, StrLen (String));\r
555 NumberOfLines++;\r
556 }\r
557 VA_END (Args);\r
558\r
559 //\r
560 // If the total number of lines in the popup is not same to the input NumberOfLines\r
561 // the parameter is not valid. Not check.\r
562 //\r
563 // if (NumberOfLines != LinesNumber) {\r
564 // return EFI_INVALID_PARAMETER;\r
565 // }\r
566\r
567 //\r
568 // If the maximum length of all the strings is not same to the input MaximumStringSize\r
569 // the parameter is not valid. Not check.\r
570 //\r
571 // if (MaxLength != MaximumStringSize) {\r
572 // return EFI_INVALID_PARAMETER;\r
573 // }\r
0368663f 574\r
a5420536
LG
575 //\r
576 // Cache a pointer to the Simple Text Output Protocol in the EFI System Table\r
577 //\r
578 ConOut = gST->ConOut;\r
0368663f 579 \r
a5420536
LG
580 //\r
581 // Save the current console cursor position and attributes\r
582 //\r
583 CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode));\r
584\r
585 //\r
586 // Retrieve the number of columns and rows in the current console mode\r
587 //\r
588 ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows);\r
589\r
590 //\r
591 // Disable cursor and set the foreground and background colors specified by Attribute\r
592 //\r
593 ConOut->EnableCursor (ConOut, FALSE);\r
594 ConOut->SetAttribute (ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE);\r
595\r
596 //\r
597 // Limit NumberOfLines to height of the screen minus 3 rows for the box itself\r
598 //\r
599 NumberOfLines = MIN (NumberOfLines, Rows - 3);\r
600\r
601 //\r
602 // Limit MaxLength to width of the screen minus 2 columns for the box itself\r
603 //\r
604 MaxLength = MIN (MaxLength, Columns - 2);\r
0368663f 605\r
a5420536
LG
606 //\r
607 // Compute the starting row and starting column for the popup\r
608 //\r
609 Row = (Rows - (NumberOfLines + 3)) / 2;\r
610 Column = (Columns - (MaxLength + 2)) / 2;\r
611\r
612 //\r
613 // Allocate a buffer for a single line of the popup with borders and a Null-terminator\r
614 //\r
615 Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16));\r
616 ASSERT (Line != NULL);\r
617\r
618 //\r
619 // Draw top of popup box \r
620 //\r
621 SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
622 Line[0] = BOXDRAW_DOWN_RIGHT;\r
623 Line[MaxLength + 1] = BOXDRAW_DOWN_LEFT;\r
624 Line[MaxLength + 2] = L'\0';\r
625 ConOut->SetCursorPosition (ConOut, Column, Row++);\r
626 ConOut->OutputString (ConOut, Line);\r
627\r
628 //\r
629 // Draw middle of the popup with strings\r
630 //\r
631 VA_START (Args, FirstString);\r
632 String = FirstString;\r
633 while ((String != NULL) && (NumberOfLines > 0)) {\r
634 Length = StrLen (String);\r
635 SetMem16 (Line, (MaxLength + 2) * 2, L' ');\r
636 if (Length <= MaxLength) {\r
637 //\r
638 // Length <= MaxLength\r
639 //\r
640 CopyMem (Line + 1 + (MaxLength - Length) / 2, String , Length * sizeof (CHAR16));\r
641 } else {\r
642 //\r
643 // Length > MaxLength\r
644 //\r
645 CopyMem (Line + 1, String + (Length - MaxLength) / 2 , MaxLength * sizeof (CHAR16));\r
646 }\r
647 Line[0] = BOXDRAW_VERTICAL;\r
648 Line[MaxLength + 1] = BOXDRAW_VERTICAL;\r
649 Line[MaxLength + 2] = L'\0';\r
650 ConOut->SetCursorPosition (ConOut, Column, Row++);\r
651 ConOut->OutputString (ConOut, Line);\r
652 String = VA_ARG (Args, CHAR16 *);\r
653 NumberOfLines--;\r
654 }\r
655 VA_END (Args);\r
656\r
657 //\r
658 // Draw bottom of popup box\r
659 //\r
660 SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
661 Line[0] = BOXDRAW_UP_RIGHT;\r
662 Line[MaxLength + 1] = BOXDRAW_UP_LEFT;\r
663 Line[MaxLength + 2] = L'\0';\r
664 ConOut->SetCursorPosition (ConOut, Column, Row++);\r
665 ConOut->OutputString (ConOut, Line);\r
666\r
667 //\r
668 // Free the allocated line buffer\r
669 //\r
670 FreePool (Line);\r
671\r
672 //\r
673 // Restore the cursor visibility, position, and attributes\r
674 //\r
675 ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible);\r
676 ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow);\r
677 ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute);\r
678\r
679 //\r
680 // Wait for a keystroke\r
681 //\r
682 if (Key != NULL) {\r
683 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
684 gST->ConIn->ReadKeyStroke (gST->ConIn, Key);\r
685 }\r
0368663f 686 \r
a5420536 687 return EFI_SUCCESS;\r
0368663f 688}\r
689\r
a235abd2 690/** \r
691\r
692 Initialize string packages in HII database.\r
693\r
694**/\r
695VOID\r
696InitSetBrowserStrings (\r
697 VOID\r
698 )\r
699{\r
a235abd2 700 //\r
701 // Initialize strings to HII database\r
702 //\r
cb7d01c0 703 gStringPackHandle = HiiAddPackages (\r
704 &gEfiHiiThunkProducerGuid,\r
705 NULL,\r
706 STRING_ARRAY_NAME,\r
707 NULL\r
708 );\r
709 ASSERT (gStringPackHandle != NULL);\r
a235abd2 710}\r