]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
1 /** @file
2 Utility functions for UI presentation.
3
4 Copyright (c) 2004 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "Setup.h"
16 #include "Ui.h"
17
18 BOOLEAN mHiiPackageListUpdated;
19 UI_MENU_SELECTION *gCurrentSelection;
20
21
22 /**
23 Clear retangle with specified text attribute.
24
25 @param LeftColumn Left column of retangle.
26 @param RightColumn Right column of retangle.
27 @param TopRow Start row of retangle.
28 @param BottomRow End row of retangle.
29 @param TextAttribute The character foreground and background.
30
31 **/
32 VOID
33 ClearLines (
34 UINTN LeftColumn,
35 UINTN RightColumn,
36 UINTN TopRow,
37 UINTN BottomRow,
38 UINTN TextAttribute
39 )
40 {
41 CHAR16 *Buffer;
42 UINTN Row;
43
44 //
45 // For now, allocate an arbitrarily long buffer
46 //
47 Buffer = AllocateZeroPool (0x10000);
48 ASSERT (Buffer != NULL);
49
50 //
51 // Set foreground and background as defined
52 //
53 gST->ConOut->SetAttribute (gST->ConOut, TextAttribute);
54
55 //
56 // Much faster to buffer the long string instead of print it a character at a time
57 //
58 SetUnicodeMem (Buffer, RightColumn - LeftColumn, L' ');
59
60 //
61 // Clear the desired area with the appropriate foreground/background
62 //
63 for (Row = TopRow; Row <= BottomRow; Row++) {
64 PrintStringAt (LeftColumn, Row, Buffer);
65 }
66
67 gST->ConOut->SetCursorPosition (gST->ConOut, LeftColumn, TopRow);
68
69 gBS->FreePool (Buffer);
70 return ;
71 }
72
73 /**
74 Concatenate a narrow string to another string.
75
76 @param Destination The destination string.
77 @param Source The source string. The string to be concatenated.
78 to the end of Destination.
79
80 **/
81 VOID
82 NewStrCat (
83 CHAR16 *Destination,
84 CHAR16 *Source
85 )
86 {
87 UINTN Length;
88
89 for (Length = 0; Destination[Length] != 0; Length++)
90 ;
91
92 //
93 // We now have the length of the original string
94 // We can safely assume for now that we are concatenating a narrow value to this string.
95 // For instance, the string is "XYZ" and cat'ing ">"
96 // If this assumption changes, we need to make this routine a bit more complex
97 //
98 Destination[Length] = NARROW_CHAR;
99 Length++;
100
101 StrCpy (Destination + Length, Source);
102 }
103
104 /**
105 Count the storage space of a Unicode string.
106
107 This function handles the Unicode string with NARROW_CHAR
108 and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
109 does not count in the resultant output. If a WIDE_CHAR is
110 hit, then 2 Unicode character will consume an output storage
111 space with size of CHAR16 till a NARROW_CHAR is hit.
112
113 @param String The input string to be counted.
114
115 @return Storage space for the input string.
116
117 **/
118 UINTN
119 GetStringWidth (
120 CHAR16 *String
121 )
122 {
123 UINTN Index;
124 UINTN Count;
125 UINTN IncrementValue;
126
127 Index = 0;
128 Count = 0;
129 IncrementValue = 1;
130
131 do {
132 //
133 // Advance to the null-terminator or to the first width directive
134 //
135 for (;
136 (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);
137 Index++, Count = Count + IncrementValue
138 )
139 ;
140
141 //
142 // We hit the null-terminator, we now have a count
143 //
144 if (String[Index] == 0) {
145 break;
146 }
147 //
148 // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed
149 // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)
150 //
151 if (String[Index] == NARROW_CHAR) {
152 //
153 // Skip to the next character
154 //
155 Index++;
156 IncrementValue = 1;
157 } else {
158 //
159 // Skip to the next character
160 //
161 Index++;
162 IncrementValue = 2;
163 }
164 } while (String[Index] != 0);
165
166 //
167 // Increment by one to include the null-terminator in the size
168 //
169 Count++;
170
171 return Count * sizeof (CHAR16);
172 }
173
174 /**
175 This function displays the page frame.
176
177 **/
178 VOID
179 DisplayPageFrame (
180 VOID
181 )
182 {
183 UINTN Index;
184 UINT8 Line;
185 UINT8 Alignment;
186 CHAR16 Character;
187 CHAR16 *Buffer;
188 CHAR16 *StrFrontPageBanner;
189 UINTN Row;
190 EFI_SCREEN_DESCRIPTOR LocalScreen;
191
192 ZeroMem (&LocalScreen, sizeof (EFI_SCREEN_DESCRIPTOR));
193 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &LocalScreen.RightColumn, &LocalScreen.BottomRow);
194 ClearLines (0, LocalScreen.RightColumn, 0, LocalScreen.BottomRow, KEYHELP_BACKGROUND);
195
196 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
197
198 //
199 // For now, allocate an arbitrarily long buffer
200 //
201 Buffer = AllocateZeroPool (0x10000);
202 ASSERT (Buffer != NULL);
203
204 Character = BOXDRAW_HORIZONTAL;
205
206 for (Index = 0; Index + 2 < (LocalScreen.RightColumn - LocalScreen.LeftColumn); Index++) {
207 Buffer[Index] = Character;
208 }
209
210 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {
211 //
212 // ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND);
213 //
214 ClearLines (
215 LocalScreen.LeftColumn,
216 LocalScreen.RightColumn,
217 LocalScreen.TopRow,
218 FRONT_PAGE_HEADER_HEIGHT - 1 + LocalScreen.TopRow,
219 BANNER_TEXT | BANNER_BACKGROUND
220 );
221 //
222 // for (Line = 0; Line < BANNER_HEIGHT; Line++) {
223 //
224 for (Line = (UINT8) LocalScreen.TopRow; Line < BANNER_HEIGHT + (UINT8) LocalScreen.TopRow; Line++) {
225 //
226 // for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) {
227 //
228 for (Alignment = (UINT8) LocalScreen.LeftColumn;
229 Alignment < BANNER_COLUMNS + (UINT8) LocalScreen.LeftColumn;
230 Alignment++
231 ) {
232 if (BannerData->Banner[Line - (UINT8) LocalScreen.TopRow][Alignment - (UINT8) LocalScreen.LeftColumn] != 0x0000) {
233 StrFrontPageBanner = GetToken (
234 BannerData->Banner[Line - (UINT8) LocalScreen.TopRow][Alignment - (UINT8) LocalScreen.LeftColumn],
235 FrontPageHandle
236 );
237 } else {
238 continue;
239 }
240
241 switch (Alignment - LocalScreen.LeftColumn) {
242 case 0:
243 //
244 // Handle left column
245 //
246 PrintStringAt (LocalScreen.LeftColumn, Line, StrFrontPageBanner);
247 break;
248
249 case 1:
250 //
251 // Handle center column
252 //
253 PrintStringAt (
254 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,
255 Line,
256 StrFrontPageBanner
257 );
258 break;
259
260 case 2:
261 //
262 // Handle right column
263 //
264 PrintStringAt (
265 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3,
266 Line,
267 StrFrontPageBanner
268 );
269 break;
270 }
271
272 gBS->FreePool (StrFrontPageBanner);
273 }
274 }
275 }
276
277 ClearLines (
278 LocalScreen.LeftColumn,
279 LocalScreen.RightColumn,
280 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT,
281 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1,
282 KEYHELP_TEXT | KEYHELP_BACKGROUND
283 );
284
285 if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {
286 ClearLines (
287 LocalScreen.LeftColumn,
288 LocalScreen.RightColumn,
289 LocalScreen.TopRow,
290 LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1,
291 TITLE_TEXT | TITLE_BACKGROUND
292 );
293 //
294 // Print Top border line
295 // +------------------------------------------------------------------------------+
296 // ? ?
297 // +------------------------------------------------------------------------------+
298 //
299 Character = BOXDRAW_DOWN_RIGHT;
300
301 PrintChar (Character);
302 PrintString (Buffer);
303
304 Character = BOXDRAW_DOWN_LEFT;
305 PrintChar (Character);
306
307 Character = BOXDRAW_VERTICAL;
308 for (Row = LocalScreen.TopRow + 1; Row <= LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 2; Row++) {
309 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
310 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
311 }
312
313 Character = BOXDRAW_UP_RIGHT;
314 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1, Character);
315 PrintString (Buffer);
316
317 Character = BOXDRAW_UP_LEFT;
318 PrintChar (Character);
319
320 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
321 //
322 // Print Bottom border line
323 // +------------------------------------------------------------------------------+
324 // ? ?
325 // +------------------------------------------------------------------------------+
326 //
327 Character = BOXDRAW_DOWN_RIGHT;
328 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT, Character);
329
330 PrintString (Buffer);
331
332 Character = BOXDRAW_DOWN_LEFT;
333 PrintChar (Character);
334 Character = BOXDRAW_VERTICAL;
335 for (Row = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT + 1;
336 Row <= LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2;
337 Row++
338 ) {
339 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
340 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
341 }
342
343 Character = BOXDRAW_UP_RIGHT;
344 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1, Character);
345
346 PrintString (Buffer);
347
348 Character = BOXDRAW_UP_LEFT;
349 PrintChar (Character);
350 }
351 }
352
353 gBS->FreePool (Buffer);
354
355 }
356
357
358 /**
359 Evaluate all expressions in a Form.
360
361 @param FormSet FormSet this Form belongs to.
362 @param Form The Form.
363
364 @retval EFI_SUCCESS The expression evaluated successfuly
365
366 **/
367 EFI_STATUS
368 EvaluateFormExpressions (
369 IN FORM_BROWSER_FORMSET *FormSet,
370 IN FORM_BROWSER_FORM *Form
371 )
372 {
373 EFI_STATUS Status;
374 LIST_ENTRY *Link;
375 FORM_EXPRESSION *Expression;
376
377 Link = GetFirstNode (&Form->ExpressionListHead);
378 while (!IsNull (&Form->ExpressionListHead, Link)) {
379 Expression = FORM_EXPRESSION_FROM_LINK (Link);
380 Link = GetNextNode (&Form->ExpressionListHead, Link);
381
382 if (Expression->Type == EFI_HII_EXPRESSION_INCONSISTENT_IF ||
383 Expression->Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) {
384 //
385 // Postpone Form validation to Question editing or Form submiting
386 //
387 continue;
388 }
389
390 Status = EvaluateExpression (FormSet, Form, Expression);
391 if (EFI_ERROR (Status)) {
392 return Status;
393 }
394 }
395
396 return EFI_SUCCESS;
397 }
398
399 /*
400 +------------------------------------------------------------------------------+
401 ?F2=Previous Page Setup Page ?
402 +------------------------------------------------------------------------------+
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420 +------------------------------------------------------------------------------+
421 ?F1=Scroll Help F9=Reset to Defaults F10=Save and Exit ?
422 | ^"=Move Highlight <Spacebar> Toggles Checkbox Esc=Discard Changes |
423 +------------------------------------------------------------------------------+
424 */
425
426 /**
427
428
429 Display form and wait for user to select one menu option, then return it.
430
431 @param Selection On input, Selection tell setup browser the information
432 about the Selection, form and formset to be displayed.
433 On output, Selection return the screen item that is selected
434 by user.
435 @retval EFI_SUCESSS This function always return successfully for now.
436
437 **/
438 EFI_STATUS
439 DisplayForm (
440 IN OUT UI_MENU_SELECTION *Selection
441 )
442 {
443 CHAR16 *StringPtr;
444 UINT16 MenuItemCount;
445 EFI_HII_HANDLE Handle;
446 BOOLEAN Suppress;
447 EFI_SCREEN_DESCRIPTOR LocalScreen;
448 UINT16 Width;
449 UINTN ArrayEntry;
450 CHAR16 *OutputString;
451 LIST_ENTRY *Link;
452 FORM_BROWSER_STATEMENT *Statement;
453 UINT16 NumberOfLines;
454 EFI_STATUS Status;
455
456 Handle = Selection->Handle;
457 MenuItemCount = 0;
458 ArrayEntry = 0;
459 OutputString = NULL;
460
461 UiInitMenu ();
462
463 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
464
465 StringPtr = GetToken (Selection->Form->FormTitle, Handle);
466
467 if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {
468 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
469 PrintStringAt (
470 (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2,
471 LocalScreen.TopRow + 1,
472 StringPtr
473 );
474 }
475
476 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
477 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
478
479 //
480 // Display the infrastructure strings
481 //
482 if (!IsListEmpty (&gMenuList)) {
483 PrintStringAt (LocalScreen.LeftColumn + 2, LocalScreen.TopRow + 1, gFunctionTwoString);
484 }
485
486 PrintStringAt (LocalScreen.LeftColumn + 2, LocalScreen.BottomRow - 4, gFunctionOneString);
487 PrintStringAt (
488 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,
489 LocalScreen.BottomRow - 4,
490 gFunctionNineString
491 );
492 PrintStringAt (
493 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3,
494 LocalScreen.BottomRow - 4,
495 gFunctionTenString
496 );
497 PrintAt (LocalScreen.LeftColumn + 2, LocalScreen.BottomRow - 3, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
498 PrintStringAt (
499 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,
500 LocalScreen.BottomRow - 3,
501 gEscapeString
502 );
503 }
504 //
505 // Remove Buffer allocated for StringPtr after it has been used.
506 //
507 gBS->FreePool (StringPtr);
508
509 //
510 // Evaluate all the Expressions in this Form
511 //
512 Status = EvaluateFormExpressions (Selection->FormSet, Selection->Form);
513 if (EFI_ERROR (Status)) {
514 return Status;
515 }
516
517 Link = GetFirstNode (&Selection->Form->StatementListHead);
518 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
519 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
520
521 if (Statement->SuppressExpression != NULL) {
522 Suppress = Statement->SuppressExpression->Result.Value.b;
523 } else {
524 Suppress = FALSE;
525 }
526
527 if (!Suppress) {
528 StringPtr = GetToken (Statement->Prompt, Handle);
529
530 Width = GetWidth (Statement, Handle);
531
532 NumberOfLines = 1;
533 ArrayEntry = 0;
534 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
535 //
536 // If there is more string to process print on the next row and increment the Skip value
537 //
538 if (StrLen (&StringPtr[ArrayEntry])) {
539 NumberOfLines++;
540 }
541
542 gBS->FreePool (OutputString);
543 }
544
545 //
546 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
547 // it in UiFreeMenu.
548 //
549 UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount);
550 MenuItemCount++;
551 }
552
553 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
554 }
555
556 Status = UiDisplayMenu (Selection);
557
558 UiFreeMenu ();
559
560 return Status;
561 }
562
563 /**
564 Initialize the HII String Token to the correct values.
565
566 **/
567 VOID
568 InitializeBrowserStrings (
569 VOID
570 )
571 {
572 gFunctionOneString = GetToken (STRING_TOKEN (FUNCTION_ONE_STRING), gHiiHandle);
573 gFunctionTwoString = GetToken (STRING_TOKEN (FUNCTION_TWO_STRING), gHiiHandle);
574 gFunctionNineString = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);
575 gFunctionTenString = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);
576 gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);
577 gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);
578 gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);
579 gSaveFailed = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle);
580 gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);
581 gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);
582 gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle);
583 gHexNumericInput = GetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), gHiiHandle);
584 gToggleCheckBox = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);
585 gPromptForData = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);
586 gPromptForPassword = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);
587 gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);
588 gConfirmPassword = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);
589 gConfirmError = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);
590 gPassowordInvalid = GetToken (STRING_TOKEN (PASSWORD_INVALID), gHiiHandle);
591 gPressEnter = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);
592 gEmptyString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
593 gAreYouSure = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);
594 gYesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);
595 gNoResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);
596 gMiniString = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);
597 gPlusString = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);
598 gMinusString = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);
599 gAdjustNumber = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);
600 gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle);
601 return ;
602 }
603
604 /**
605 Free up the resource allocated for all strings required
606 by Setup Browser.
607
608 **/
609 VOID
610 FreeBrowserStrings (
611 VOID
612 )
613 {
614 FreePool (gFunctionOneString);
615 FreePool (gFunctionTwoString);
616 FreePool (gFunctionNineString);
617 FreePool (gFunctionTenString);
618 FreePool (gEnterString);
619 FreePool (gEnterCommitString);
620 FreePool (gEscapeString);
621 FreePool (gMoveHighlight);
622 FreePool (gMakeSelection);
623 FreePool (gDecNumericInput);
624 FreePool (gHexNumericInput);
625 FreePool (gToggleCheckBox);
626 FreePool (gPromptForData);
627 FreePool (gPromptForPassword);
628 FreePool (gPromptForNewPassword);
629 FreePool (gConfirmPassword);
630 FreePool (gPassowordInvalid);
631 FreePool (gConfirmError);
632 FreePool (gPressEnter);
633 FreePool (gEmptyString);
634 FreePool (gAreYouSure);
635 FreePool (gYesResponse);
636 FreePool (gNoResponse);
637 FreePool (gMiniString);
638 FreePool (gPlusString);
639 FreePool (gMinusString);
640 FreePool (gAdjustNumber);
641 FreePool (gSaveChanges);
642 return ;
643 }
644
645
646 /**
647 Update key's help imformation.
648
649 @param MenuOption The Menu option
650 @param Selected Whether or not a tag be selected
651
652 **/
653 VOID
654 UpdateKeyHelp (
655 IN UI_MENU_OPTION *MenuOption,
656 IN BOOLEAN Selected
657 )
658 {
659 UINTN SecCol;
660 UINTN ThdCol;
661 UINTN LeftColumnOfHelp;
662 UINTN RightColumnOfHelp;
663 UINTN TopRowOfHelp;
664 UINTN BottomRowOfHelp;
665 UINTN StartColumnOfHelp;
666 EFI_SCREEN_DESCRIPTOR LocalScreen;
667 FORM_BROWSER_STATEMENT *Statement;
668
669 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
670
671 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
672 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;
673
674 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
675 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
676 RightColumnOfHelp = LocalScreen.RightColumn - 2;
677 TopRowOfHelp = LocalScreen.BottomRow - 4;
678 BottomRowOfHelp = LocalScreen.BottomRow - 3;
679
680 if (gClassOfVfr == EFI_GENERAL_APPLICATION_SUBCLASS) {
681 return ;
682 }
683
684 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
685
686 Statement = MenuOption->ThisTag;
687 switch (Statement->Operand) {
688 case EFI_IFR_ORDERED_LIST_OP:
689 case EFI_IFR_ONE_OF_OP:
690 case EFI_IFR_NUMERIC_OP:
691 case EFI_IFR_TIME_OP:
692 case EFI_IFR_DATE_OP:
693 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
694
695 if (!Selected) {
696 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
697 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
698 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
699 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
700 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
701 }
702
703 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
704 (Statement->Operand == EFI_IFR_TIME_OP) ||
705 (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0)) {
706 PrintAt (
707 StartColumnOfHelp,
708 BottomRowOfHelp,
709 L"%c%c%c%c%s",
710 ARROW_UP,
711 ARROW_DOWN,
712 ARROW_RIGHT,
713 ARROW_LEFT,
714 gMoveHighlight
715 );
716 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
717 } else {
718 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
719 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
720 }
721 } else {
722 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
723
724 //
725 // If it is a selected numeric with manual input, display different message
726 //
727 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step == 0)) {
728 PrintStringAt (
729 SecCol,
730 TopRowOfHelp,
731 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
732 );
733 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
734 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
735 }
736
737 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
738 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
739 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
740 }
741
742 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
743 }
744 break;
745
746 case EFI_IFR_CHECKBOX_OP:
747 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
748
749 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
750 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
751 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
752 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
753 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
754 }
755
756 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
757 PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
758 break;
759
760 case EFI_IFR_REF_OP:
761 case EFI_IFR_PASSWORD_OP:
762 case EFI_IFR_STRING_OP:
763 case EFI_IFR_TEXT_OP:
764 case EFI_IFR_ACTION_OP:
765 case EFI_IFR_RESET_BUTTON_OP:
766 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
767
768 if (!Selected) {
769 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
770 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
771 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
772 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
773 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
774 }
775
776 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
777 if (Statement->Operand != EFI_IFR_TEXT_OP) {
778 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
779 }
780 } else {
781 if (Statement->Operand != EFI_IFR_REF_OP) {
782 PrintStringAt (
783 (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,
784 BottomRowOfHelp,
785 gEnterCommitString
786 );
787 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
788 }
789 }
790 break;
791
792 default:
793 break;
794 }
795 }
796
797 /**
798 Functions which are registered to receive notification of
799 database events have this prototype. The actual event is encoded
800 in NotifyType. The following table describes how PackageType,
801 PackageGuid, Handle, and Package are used for each of the
802 notification types.
803
804 @param PackageType Package type of the notification.
805
806 @param PackageGuid If PackageType is
807 EFI_HII_PACKAGE_TYPE_GUID, then this is
808 the pointer to the GUID from the Guid
809 field of EFI_HII_PACKAGE_GUID_HEADER.
810 Otherwise, it must be NULL.
811
812 @param Package Points to the package referred to by the
813 notification Handle The handle of the package
814 list which contains the specified package.
815
816 @param Handle The HII handle.
817
818 @param NotifyType The type of change concerning the
819 database. See
820 EFI_HII_DATABASE_NOTIFY_TYPE.
821
822 **/
823 EFI_STATUS
824 FormUpdateNotify (
825 IN UINT8 PackageType,
826 IN CONST EFI_GUID *PackageGuid,
827 IN CONST EFI_HII_PACKAGE_HEADER *Package,
828 IN EFI_HII_HANDLE Handle,
829 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
830 )
831 {
832 mHiiPackageListUpdated = TRUE;
833
834 return EFI_SUCCESS;
835 }
836
837 /**
838 The worker function that send the displays to the screen. On output,
839 the selection made by user is returned.
840
841 @param Selection On input, Selection tell setup browser the information
842 about the Selection, form and formset to be displayed.
843 On output, Selection return the screen item that is selected
844 by user.
845
846 @retval EFI_SUCCESS The page is displayed successfully.
847 @return Other value if the page failed to be diplayed.
848
849 **/
850 EFI_STATUS
851 SetupBrowser (
852 IN OUT UI_MENU_SELECTION *Selection
853 )
854 {
855 EFI_STATUS Status;
856 LIST_ENTRY *Link;
857 EFI_BROWSER_ACTION_REQUEST ActionRequest;
858 EFI_HANDLE NotifyHandle;
859 EFI_HII_VALUE *HiiValue;
860 FORM_BROWSER_STATEMENT *Statement;
861 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
862 EFI_INPUT_KEY Key;
863 CHAR16 YesResponse;
864 CHAR16 NoResponse;
865
866 gMenuRefreshHead = NULL;
867 gResetRequired = FALSE;
868 gNvUpdateRequired = FALSE;
869
870 UiInitMenuList ();
871
872 //
873 // Register notify for Form package update
874 //
875 Status = mHiiDatabase->RegisterPackageNotify (
876 mHiiDatabase,
877 EFI_HII_PACKAGE_FORM,
878 NULL,
879 FormUpdateNotify,
880 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
881 &NotifyHandle
882 );
883 if (EFI_ERROR (Status)) {
884 return Status;
885 }
886
887 do {
888 //
889 // Displays the Header and Footer borders
890 //
891 DisplayPageFrame ();
892
893 //
894 // Initialize Selection->Form
895 //
896 if (Selection->FormId == 0) {
897 //
898 // Zero FormId indicates display the first Form in a FormSet
899 //
900 Link = GetFirstNode (&Selection->FormSet->FormListHead);
901
902 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
903 Selection->FormId = Selection->Form->FormId;
904 } else {
905 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
906 }
907
908 //
909 // Load Questions' Value for display
910 //
911 Status = LoadFormConfig (Selection->FormSet, Selection->Form);
912 if (EFI_ERROR (Status)) {
913 return Status;
914 }
915
916 //
917 // Display form
918 //
919 Status = DisplayForm (Selection);
920 if (EFI_ERROR (Status)) {
921 return Status;
922 }
923
924 //
925 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
926 //
927 Statement = Selection->Statement;
928 if (Statement != NULL) {
929 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
930 gResetRequired = TRUE;
931 }
932
933 //
934 // Reset FormPackage update flag
935 //
936 mHiiPackageListUpdated = FALSE;
937
938 if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
939 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
940
941 HiiValue = &Statement->HiiValue;
942 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
943 //
944 // Create String in HII database for Configuration Driver to retrieve
945 //
946 HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
947 }
948
949 ConfigAccess = Selection->FormSet->ConfigAccess;
950 if (ConfigAccess == NULL) {
951 return EFI_UNSUPPORTED;
952 }
953 Status = ConfigAccess->Callback (
954 ConfigAccess,
955 EFI_BROWSER_ACTION_CHANGING,
956 Statement->QuestionId,
957 HiiValue->Type,
958 &HiiValue->Value,
959 &ActionRequest
960 );
961
962 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
963 //
964 // Clean the String in HII Database
965 //
966 DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
967 }
968
969 if (!EFI_ERROR (Status)) {
970 switch (ActionRequest) {
971 case EFI_BROWSER_ACTION_REQUEST_RESET:
972 gResetRequired = TRUE;
973 break;
974
975 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
976 SubmitForm (Selection->FormSet, Selection->Form);
977 break;
978
979 case EFI_BROWSER_ACTION_REQUEST_EXIT:
980 Selection->Action = UI_ACTION_EXIT;
981 gNvUpdateRequired = FALSE;
982 break;
983
984 default:
985 break;
986 }
987 }
988 }
989
990 //
991 // Check whether Form Package has been updated during Callback
992 //
993 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
994 //
995 // Force to reparse IFR binary of target Formset
996 //
997 Selection->Action = UI_ACTION_REFRESH_FORMSET;
998
999 //
1000 // Uncommitted data will be lost after IFR binary re-pasing, so confirm on whether to save
1001 //
1002 if (gNvUpdateRequired) {
1003 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
1004
1005 YesResponse = gYesResponse[0];
1006 NoResponse = gNoResponse[0];
1007
1008 do {
1009 CreateDialog (3, TRUE, 0, NULL, &Key, gEmptyString, gSaveChanges, gEmptyString);
1010 } while
1011 (
1012 (Key.ScanCode != SCAN_ESC) &&
1013 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
1014 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
1015 );
1016
1017 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
1018 //
1019 // If the user hits the YesResponse key
1020 //
1021 SubmitForm (Selection->FormSet, Selection->Form);
1022 }
1023 }
1024 }
1025 }
1026 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1027
1028 //
1029 // Unregister notify for Form package update
1030 //
1031 Status = mHiiDatabase->UnregisterPackageNotify (
1032 mHiiDatabase,
1033 NotifyHandle
1034 );
1035 return Status;
1036 }