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