]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
Enable new "ref5" opcode in browser.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
1 /** @file
2 Utility functions for UI presentation.
3
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 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
17 BOOLEAN mHiiPackageListUpdated;
18 UI_MENU_SELECTION *gCurrentSelection;
19 EFI_HII_HANDLE mCurrentHiiHandle = NULL;
20 EFI_GUID mCurrentFormSetGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
21 UINT16 mCurrentFormId = 0;
22
23 /**
24 Clear retangle with specified text attribute.
25
26 @param LeftColumn Left column of retangle.
27 @param RightColumn Right column of retangle.
28 @param TopRow Start row of retangle.
29 @param BottomRow End row of retangle.
30 @param TextAttribute The character foreground and background.
31
32 **/
33 VOID
34 ClearLines (
35 IN UINTN LeftColumn,
36 IN UINTN RightColumn,
37 IN UINTN TopRow,
38 IN UINTN BottomRow,
39 IN UINTN TextAttribute
40 )
41 {
42 CHAR16 *Buffer;
43 UINTN Row;
44
45 //
46 // For now, allocate an arbitrarily long buffer
47 //
48 Buffer = AllocateZeroPool (0x10000);
49 ASSERT (Buffer != NULL);
50
51 //
52 // Set foreground and background as defined
53 //
54 gST->ConOut->SetAttribute (gST->ConOut, TextAttribute);
55
56 //
57 // Much faster to buffer the long string instead of print it a character at a time
58 //
59 SetUnicodeMem (Buffer, RightColumn - LeftColumn, L' ');
60
61 //
62 // Clear the desired area with the appropriate foreground/background
63 //
64 for (Row = TopRow; Row <= BottomRow; Row++) {
65 PrintStringAt (LeftColumn, Row, Buffer);
66 }
67
68 gST->ConOut->SetCursorPosition (gST->ConOut, LeftColumn, TopRow);
69
70 FreePool (Buffer);
71 return ;
72 }
73
74 /**
75 Concatenate a narrow string to another string.
76
77 @param Destination The destination string.
78 @param Source The source string. The string to be concatenated.
79 to the end of Destination.
80
81 **/
82 VOID
83 NewStrCat (
84 IN OUT CHAR16 *Destination,
85 IN CHAR16 *Source
86 )
87 {
88 UINTN Length;
89
90 for (Length = 0; Destination[Length] != 0; Length++)
91 ;
92
93 //
94 // We now have the length of the original string
95 // We can safely assume for now that we are concatenating a narrow value to this string.
96 // For instance, the string is "XYZ" and cat'ing ">"
97 // If this assumption changes, we need to make this routine a bit more complex
98 //
99 Destination[Length] = NARROW_CHAR;
100 Length++;
101
102 StrCpy (Destination + Length, Source);
103 }
104
105 /**
106 Count the storage space of a Unicode string.
107
108 This function handles the Unicode string with NARROW_CHAR
109 and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
110 does not count in the resultant output. If a WIDE_CHAR is
111 hit, then 2 Unicode character will consume an output storage
112 space with size of CHAR16 till a NARROW_CHAR is hit.
113
114 If String is NULL, then ASSERT ().
115
116 @param String The input string to be counted.
117
118 @return Storage space for the input string.
119
120 **/
121 UINTN
122 GetStringWidth (
123 IN CHAR16 *String
124 )
125 {
126 UINTN Index;
127 UINTN Count;
128 UINTN IncrementValue;
129
130 ASSERT (String != NULL);
131 if (String == NULL) {
132 return 0;
133 }
134
135 Index = 0;
136 Count = 0;
137 IncrementValue = 1;
138
139 do {
140 //
141 // Advance to the null-terminator or to the first width directive
142 //
143 for (;
144 (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);
145 Index++, Count = Count + IncrementValue
146 )
147 ;
148
149 //
150 // We hit the null-terminator, we now have a count
151 //
152 if (String[Index] == 0) {
153 break;
154 }
155 //
156 // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed
157 // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)
158 //
159 if (String[Index] == NARROW_CHAR) {
160 //
161 // Skip to the next character
162 //
163 Index++;
164 IncrementValue = 1;
165 } else {
166 //
167 // Skip to the next character
168 //
169 Index++;
170 IncrementValue = 2;
171 }
172 } while (String[Index] != 0);
173
174 //
175 // Increment by one to include the null-terminator in the size
176 //
177 Count++;
178
179 return Count * sizeof (CHAR16);
180 }
181
182 /**
183 This function displays the page frame.
184
185 @param Selection Selection contains the information about
186 the Selection, form and formset to be displayed.
187 Selection action may be updated in retrieve callback.
188 **/
189 VOID
190 DisplayPageFrame (
191 IN UI_MENU_SELECTION *Selection
192 )
193 {
194 UINTN Index;
195 UINT8 Line;
196 UINT8 Alignment;
197 CHAR16 Character;
198 CHAR16 *Buffer;
199 CHAR16 *StrFrontPageBanner;
200 UINTN Row;
201 EFI_SCREEN_DESCRIPTOR LocalScreen;
202 UINT8 RowIdx;
203 UINT8 ColumnIdx;
204
205 ZeroMem (&LocalScreen, sizeof (EFI_SCREEN_DESCRIPTOR));
206 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &LocalScreen.RightColumn, &LocalScreen.BottomRow);
207 ClearLines (0, LocalScreen.RightColumn, 0, LocalScreen.BottomRow, KEYHELP_BACKGROUND);
208
209 if (Selection->Form->ModalForm) {
210 return;
211 }
212
213 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
214
215 //
216 // For now, allocate an arbitrarily long buffer
217 //
218 Buffer = AllocateZeroPool (0x10000);
219 ASSERT (Buffer != NULL);
220
221 Character = BOXDRAW_HORIZONTAL;
222
223 for (Index = 0; Index + 2 < (LocalScreen.RightColumn - LocalScreen.LeftColumn); Index++) {
224 Buffer[Index] = Character;
225 }
226
227 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) {
228 //
229 // ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND);
230 //
231 ClearLines (
232 LocalScreen.LeftColumn,
233 LocalScreen.RightColumn,
234 LocalScreen.TopRow,
235 FRONT_PAGE_HEADER_HEIGHT - 1 + LocalScreen.TopRow,
236 BANNER_TEXT | BANNER_BACKGROUND
237 );
238 //
239 // for (Line = 0; Line < BANNER_HEIGHT; Line++) {
240 //
241 for (Line = (UINT8) LocalScreen.TopRow; Line < BANNER_HEIGHT + (UINT8) LocalScreen.TopRow; Line++) {
242 //
243 // for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) {
244 //
245 for (Alignment = (UINT8) LocalScreen.LeftColumn;
246 Alignment < BANNER_COLUMNS + (UINT8) LocalScreen.LeftColumn;
247 Alignment++
248 ) {
249 RowIdx = (UINT8) (Line - (UINT8) LocalScreen.TopRow);
250 ColumnIdx = (UINT8) (Alignment - (UINT8) LocalScreen.LeftColumn);
251
252 ASSERT (RowIdx < BANNER_HEIGHT);
253 ASSERT (ColumnIdx < BANNER_COLUMNS);
254
255 if (gBannerData->Banner[RowIdx][ColumnIdx] != 0x0000) {
256 StrFrontPageBanner = GetToken (
257 gBannerData->Banner[RowIdx][ColumnIdx],
258 gFrontPageHandle
259 );
260 } else {
261 continue;
262 }
263
264 switch (Alignment - LocalScreen.LeftColumn) {
265 case 0:
266 //
267 // Handle left column
268 //
269 PrintStringAt (LocalScreen.LeftColumn + BANNER_LEFT_COLUMN_INDENT, Line, StrFrontPageBanner);
270 break;
271
272 case 1:
273 //
274 // Handle center column
275 //
276 PrintStringAt (
277 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,
278 Line,
279 StrFrontPageBanner
280 );
281 break;
282
283 case 2:
284 //
285 // Handle right column
286 //
287 PrintStringAt (
288 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3,
289 Line,
290 StrFrontPageBanner
291 );
292 break;
293 }
294
295 FreePool (StrFrontPageBanner);
296 }
297 }
298 }
299
300 ClearLines (
301 LocalScreen.LeftColumn,
302 LocalScreen.RightColumn,
303 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT,
304 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1,
305 KEYHELP_TEXT | KEYHELP_BACKGROUND
306 );
307
308 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) {
309 ClearLines (
310 LocalScreen.LeftColumn,
311 LocalScreen.RightColumn,
312 LocalScreen.TopRow,
313 LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1,
314 TITLE_TEXT | TITLE_BACKGROUND
315 );
316 //
317 // Print Top border line
318 // +------------------------------------------------------------------------------+
319 // ? ?
320 // +------------------------------------------------------------------------------+
321 //
322 Character = BOXDRAW_DOWN_RIGHT;
323
324 PrintChar (Character);
325 PrintString (Buffer);
326
327 Character = BOXDRAW_DOWN_LEFT;
328 PrintChar (Character);
329
330 Character = BOXDRAW_VERTICAL;
331 for (Row = LocalScreen.TopRow + 1; Row <= LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 2; Row++) {
332 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
333 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
334 }
335
336 Character = BOXDRAW_UP_RIGHT;
337 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1, Character);
338 PrintString (Buffer);
339
340 Character = BOXDRAW_UP_LEFT;
341 PrintChar (Character);
342
343 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
344 //
345 // Print Bottom border line
346 // +------------------------------------------------------------------------------+
347 // ? ?
348 // +------------------------------------------------------------------------------+
349 //
350 Character = BOXDRAW_DOWN_RIGHT;
351 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT, Character);
352
353 PrintString (Buffer);
354
355 Character = BOXDRAW_DOWN_LEFT;
356 PrintChar (Character);
357 Character = BOXDRAW_VERTICAL;
358 for (Row = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT + 1;
359 Row <= LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2;
360 Row++
361 ) {
362 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
363 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
364 }
365
366 Character = BOXDRAW_UP_RIGHT;
367 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1, Character);
368
369 PrintString (Buffer);
370
371 Character = BOXDRAW_UP_LEFT;
372 PrintChar (Character);
373 }
374 }
375
376 FreePool (Buffer);
377
378 }
379
380
381 /**
382 Evaluate all expressions in a Form.
383
384 @param FormSet FormSet this Form belongs to.
385 @param Form The Form.
386
387 @retval EFI_SUCCESS The expression evaluated successfuly
388
389 **/
390 EFI_STATUS
391 EvaluateFormExpressions (
392 IN FORM_BROWSER_FORMSET *FormSet,
393 IN FORM_BROWSER_FORM *Form
394 )
395 {
396 EFI_STATUS Status;
397 LIST_ENTRY *Link;
398 FORM_EXPRESSION *Expression;
399
400 Link = GetFirstNode (&Form->ExpressionListHead);
401 while (!IsNull (&Form->ExpressionListHead, Link)) {
402 Expression = FORM_EXPRESSION_FROM_LINK (Link);
403 Link = GetNextNode (&Form->ExpressionListHead, Link);
404
405 if (Expression->Type == EFI_HII_EXPRESSION_INCONSISTENT_IF ||
406 Expression->Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF ||
407 Expression->Type == EFI_HII_EXPRESSION_WRITE ||
408 (Expression->Type == EFI_HII_EXPRESSION_READ && Form->FormType != STANDARD_MAP_FORM_TYPE)) {
409 //
410 // Postpone Form validation to Question editing or Form submitting or Question Write or Question Read for nonstandard form.
411 //
412 continue;
413 }
414
415 Status = EvaluateExpression (FormSet, Form, Expression);
416 if (EFI_ERROR (Status)) {
417 return Status;
418 }
419 }
420
421 return EFI_SUCCESS;
422 }
423
424 /*
425 +------------------------------------------------------------------------------+
426 ? Setup Page ?
427 +------------------------------------------------------------------------------+
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445 +------------------------------------------------------------------------------+
446 ?F1=Scroll Help F9=Reset to Defaults F10=Save and Exit ?
447 | ^"=Move Highlight <Spacebar> Toggles Checkbox Esc=Discard Changes |
448 +------------------------------------------------------------------------------+
449 */
450
451 /**
452
453
454 Display form and wait for user to select one menu option, then return it.
455
456 @param Selection On input, Selection tell setup browser the information
457 about the Selection, form and formset to be displayed.
458 On output, Selection return the screen item that is selected
459 by user.
460 @retval EFI_SUCESSS This function always return successfully for now.
461
462 **/
463 EFI_STATUS
464 DisplayForm (
465 IN OUT UI_MENU_SELECTION *Selection
466 )
467 {
468 CHAR16 *StringPtr;
469 UINT16 MenuItemCount;
470 EFI_HII_HANDLE Handle;
471 BOOLEAN Suppress;
472 EFI_SCREEN_DESCRIPTOR LocalScreen;
473 UINT16 Width;
474 UINTN ArrayEntry;
475 CHAR16 *OutputString;
476 LIST_ENTRY *Link;
477 FORM_BROWSER_STATEMENT *Statement;
478 UINT16 NumberOfLines;
479 EFI_STATUS Status;
480 UI_MENU_OPTION *MenuOption;
481
482 Handle = Selection->Handle;
483 MenuItemCount = 0;
484 ArrayEntry = 0;
485 OutputString = NULL;
486
487 UiInitMenu ();
488
489 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
490
491 StringPtr = GetToken (Selection->Form->FormTitle, Handle);
492
493 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) {
494 if (Selection->Form->ModalForm) {
495 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | EFI_BACKGROUND_BLACK);
496 } else {
497 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
498 }
499 PrintStringAt (
500 (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2,
501 LocalScreen.TopRow + 1,
502 StringPtr
503 );
504 }
505
506 //
507 // Remove Buffer allocated for StringPtr after it has been used.
508 //
509 FreePool (StringPtr);
510
511 //
512 // Evaluate all the Expressions in this Form
513 //
514 Status = EvaluateFormExpressions (Selection->FormSet, Selection->Form);
515 if (EFI_ERROR (Status)) {
516 return Status;
517 }
518
519 Selection->FormEditable = FALSE;
520 Link = GetFirstNode (&Selection->Form->StatementListHead);
521 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
522 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
523
524 if (Statement->SuppressExpression != NULL) {
525 Suppress = Statement->SuppressExpression->Result.Value.b;
526 } else {
527 Suppress = FALSE;
528 }
529
530 if (Statement->DisableExpression != NULL) {
531 Suppress = (BOOLEAN) (Suppress || Statement->DisableExpression->Result.Value.b);
532 }
533
534 if (!Suppress) {
535 StringPtr = GetToken (Statement->Prompt, Handle);
536
537 Width = GetWidth (Statement, Handle);
538
539 NumberOfLines = 1;
540 ArrayEntry = 0;
541 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
542 //
543 // If there is more string to process print on the next row and increment the Skip value
544 //
545 if (StrLen (&StringPtr[ArrayEntry]) != 0) {
546 NumberOfLines++;
547 }
548
549 FreePool (OutputString);
550 }
551
552 //
553 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
554 // it in UiFreeMenu.
555 //
556 MenuOption = UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount);
557 MenuItemCount++;
558
559 if (MenuOption->IsQuestion && !MenuOption->ReadOnly) {
560 //
561 // At least one item is not readonly, this Form is considered as editable
562 //
563 Selection->FormEditable = TRUE;
564 }
565 }
566
567 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
568 }
569
570 Status = UiDisplayMenu (Selection);
571
572 UiFreeMenu ();
573
574 return Status;
575 }
576
577 /**
578 Initialize the HII String Token to the correct values.
579
580 **/
581 VOID
582 InitializeBrowserStrings (
583 VOID
584 )
585 {
586 gFunctionNineString = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);
587 gFunctionTenString = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);
588 gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);
589 gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);
590 gEnterEscapeString = GetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), gHiiHandle);
591 gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);
592 gSaveFailed = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle);
593 gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);
594 gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);
595 gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle);
596 gHexNumericInput = GetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), gHiiHandle);
597 gToggleCheckBox = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);
598 gPromptForData = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);
599 gPromptForPassword = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);
600 gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);
601 gConfirmPassword = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);
602 gConfirmError = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);
603 gPassowordInvalid = GetToken (STRING_TOKEN (PASSWORD_INVALID), gHiiHandle);
604 gPressEnter = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);
605 gEmptyString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
606 gAreYouSure = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);
607 gYesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);
608 gNoResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);
609 gMiniString = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);
610 gPlusString = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);
611 gMinusString = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);
612 gAdjustNumber = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);
613 gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle);
614 gOptionMismatch = GetToken (STRING_TOKEN (OPTION_MISMATCH), gHiiHandle);
615 gFormSuppress = GetToken (STRING_TOKEN (FORM_SUPPRESSED), gHiiHandle);
616 return ;
617 }
618
619 /**
620 Free up the resource allocated for all strings required
621 by Setup Browser.
622
623 **/
624 VOID
625 FreeBrowserStrings (
626 VOID
627 )
628 {
629 FreePool (gFunctionNineString);
630 FreePool (gFunctionTenString);
631 FreePool (gEnterString);
632 FreePool (gEnterCommitString);
633 FreePool (gEnterEscapeString);
634 FreePool (gEscapeString);
635 FreePool (gMoveHighlight);
636 FreePool (gMakeSelection);
637 FreePool (gDecNumericInput);
638 FreePool (gHexNumericInput);
639 FreePool (gToggleCheckBox);
640 FreePool (gPromptForData);
641 FreePool (gPromptForPassword);
642 FreePool (gPromptForNewPassword);
643 FreePool (gConfirmPassword);
644 FreePool (gPassowordInvalid);
645 FreePool (gConfirmError);
646 FreePool (gPressEnter);
647 FreePool (gEmptyString);
648 FreePool (gAreYouSure);
649 FreePool (gYesResponse);
650 FreePool (gNoResponse);
651 FreePool (gMiniString);
652 FreePool (gPlusString);
653 FreePool (gMinusString);
654 FreePool (gAdjustNumber);
655 FreePool (gSaveChanges);
656 FreePool (gOptionMismatch);
657 FreePool (gFormSuppress);
658 return ;
659 }
660
661
662 /**
663 Update key's help imformation.
664
665 @param Selection Tell setup browser the information about the Selection
666 @param MenuOption The Menu option
667 @param Selected Whether or not a tag be selected
668
669 **/
670 VOID
671 UpdateKeyHelp (
672 IN UI_MENU_SELECTION *Selection,
673 IN UI_MENU_OPTION *MenuOption,
674 IN BOOLEAN Selected
675 )
676 {
677 UINTN SecCol;
678 UINTN ThdCol;
679 UINTN LeftColumnOfHelp;
680 UINTN RightColumnOfHelp;
681 UINTN TopRowOfHelp;
682 UINTN BottomRowOfHelp;
683 UINTN StartColumnOfHelp;
684 EFI_SCREEN_DESCRIPTOR LocalScreen;
685 FORM_BROWSER_STATEMENT *Statement;
686
687 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
688
689 if (Selection->Form->ModalForm) {
690 return;
691 }
692
693 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
694
695 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
696 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;
697
698 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
699 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
700 RightColumnOfHelp = LocalScreen.RightColumn - 2;
701 TopRowOfHelp = LocalScreen.BottomRow - 4;
702 BottomRowOfHelp = LocalScreen.BottomRow - 3;
703
704 Statement = MenuOption->ThisTag;
705 switch (Statement->Operand) {
706 case EFI_IFR_ORDERED_LIST_OP:
707 case EFI_IFR_ONE_OF_OP:
708 case EFI_IFR_NUMERIC_OP:
709 case EFI_IFR_TIME_OP:
710 case EFI_IFR_DATE_OP:
711 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
712
713 if (!Selected) {
714 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
715 if (Selection->FormEditable) {
716 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
717 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
718 }
719 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
720 }
721
722 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
723 (Statement->Operand == EFI_IFR_TIME_OP)) {
724 PrintAt (
725 StartColumnOfHelp,
726 BottomRowOfHelp,
727 L"%c%c%c%c%s",
728 ARROW_UP,
729 ARROW_DOWN,
730 ARROW_RIGHT,
731 ARROW_LEFT,
732 gMoveHighlight
733 );
734 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
735 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber);
736 } else {
737 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
738 if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) {
739 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber);
740 }
741 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
742 }
743 } else {
744 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
745
746 //
747 // If it is a selected numeric with manual input, display different message
748 //
749 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) ||
750 (Statement->Operand == EFI_IFR_DATE_OP) ||
751 (Statement->Operand == EFI_IFR_TIME_OP)) {
752 PrintStringAt (
753 SecCol,
754 TopRowOfHelp,
755 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
756 );
757 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
758 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
759 }
760
761 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
762 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
763 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
764 }
765
766 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
767 }
768 break;
769
770 case EFI_IFR_CHECKBOX_OP:
771 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
772
773 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
774 if (Selection->FormEditable) {
775 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
776 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
777 }
778 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
779 }
780
781 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
782 PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
783 break;
784
785 case EFI_IFR_REF_OP:
786 case EFI_IFR_PASSWORD_OP:
787 case EFI_IFR_STRING_OP:
788 case EFI_IFR_TEXT_OP:
789 case EFI_IFR_ACTION_OP:
790 case EFI_IFR_RESET_BUTTON_OP:
791 case EFI_IFR_SUBTITLE_OP:
792 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
793
794 if (!Selected) {
795 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
796 if (Selection->FormEditable) {
797 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
798 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
799 }
800 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
801 }
802
803 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
804 if (Statement->Operand != EFI_IFR_TEXT_OP && Statement->Operand != EFI_IFR_SUBTITLE_OP) {
805 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
806 }
807 } else {
808 if (Statement->Operand != EFI_IFR_REF_OP) {
809 PrintStringAt (
810 (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,
811 BottomRowOfHelp,
812 gEnterCommitString
813 );
814 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
815 }
816 }
817 break;
818
819 default:
820 break;
821 }
822 }
823
824 /**
825 Functions which are registered to receive notification of
826 database events have this prototype. The actual event is encoded
827 in NotifyType. The following table describes how PackageType,
828 PackageGuid, Handle, and Package are used for each of the
829 notification types.
830
831 @param PackageType Package type of the notification.
832
833 @param PackageGuid If PackageType is
834 EFI_HII_PACKAGE_TYPE_GUID, then this is
835 the pointer to the GUID from the Guid
836 field of EFI_HII_PACKAGE_GUID_HEADER.
837 Otherwise, it must be NULL.
838
839 @param Package Points to the package referred to by the
840 notification Handle The handle of the package
841 list which contains the specified package.
842
843 @param Handle The HII handle.
844
845 @param NotifyType The type of change concerning the
846 database. See
847 EFI_HII_DATABASE_NOTIFY_TYPE.
848
849 **/
850 EFI_STATUS
851 EFIAPI
852 FormUpdateNotify (
853 IN UINT8 PackageType,
854 IN CONST EFI_GUID *PackageGuid,
855 IN CONST EFI_HII_PACKAGE_HEADER *Package,
856 IN EFI_HII_HANDLE Handle,
857 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
858 )
859 {
860 mHiiPackageListUpdated = TRUE;
861
862 return EFI_SUCCESS;
863 }
864
865 /**
866 check whether the formset need to update the NV.
867
868 @param FormSet FormSet data structure.
869
870 @retval TRUE Need to update the NV.
871 @retval FALSE No need to update the NV.
872 **/
873 BOOLEAN
874 IsNvUpdateRequired (
875 IN FORM_BROWSER_FORMSET *FormSet
876 )
877 {
878 LIST_ENTRY *Link;
879 FORM_BROWSER_FORM *Form;
880
881 Link = GetFirstNode (&FormSet->FormListHead);
882 while (!IsNull (&FormSet->FormListHead, Link)) {
883 Form = FORM_BROWSER_FORM_FROM_LINK (Link);
884
885 if (Form->NvUpdateRequired ) {
886 return TRUE;
887 }
888
889 Link = GetNextNode (&FormSet->FormListHead, Link);
890 }
891
892 return FALSE;
893 }
894
895 /**
896 check whether the formset need to update the NV.
897
898 @param FormSet FormSet data structure.
899 @param SetValue Whether set new value or clear old value.
900
901 **/
902 VOID
903 UpdateNvInfoInForm (
904 IN FORM_BROWSER_FORMSET *FormSet,
905 IN BOOLEAN SetValue
906 )
907 {
908 LIST_ENTRY *Link;
909 FORM_BROWSER_FORM *Form;
910
911 Link = GetFirstNode (&FormSet->FormListHead);
912 while (!IsNull (&FormSet->FormListHead, Link)) {
913 Form = FORM_BROWSER_FORM_FROM_LINK (Link);
914
915 Form->NvUpdateRequired = SetValue;
916
917 Link = GetNextNode (&FormSet->FormListHead, Link);
918 }
919 }
920 /**
921 Find menu which will show next time.
922
923 @param Selection On input, Selection tell setup browser the information
924 about the Selection, form and formset to be displayed.
925 On output, Selection return the screen item that is selected
926 by user.
927 @param Repaint Whether need to repaint the menu.
928 @param NewLine Whether need to show at new line.
929
930 @retval TRUE Need return.
931 @retval FALSE No need to return.
932 **/
933 BOOLEAN
934 FindNextMenu (
935 IN OUT UI_MENU_SELECTION *Selection,
936 IN BOOLEAN *Repaint,
937 IN BOOLEAN *NewLine
938 )
939 {
940 UI_MENU_LIST *CurrentMenu;
941 CHAR16 YesResponse;
942 CHAR16 NoResponse;
943 EFI_INPUT_KEY Key;
944 EFI_STATUS Status;
945
946 CurrentMenu = Selection->CurrentMenu;
947
948 if (CurrentMenu != NULL && CurrentMenu->Parent != NULL) {
949 //
950 // we have a parent, so go to the parent menu
951 //
952 if (CompareGuid (&CurrentMenu->FormSetGuid, &CurrentMenu->Parent->FormSetGuid)) {
953 //
954 // The parent menu and current menu are in the same formset
955 //
956 Selection->Action = UI_ACTION_REFRESH_FORM;
957 } else {
958 Selection->Action = UI_ACTION_REFRESH_FORMSET;
959 }
960 Selection->Statement = NULL;
961
962 Selection->FormId = CurrentMenu->Parent->FormId;
963 Selection->QuestionId = CurrentMenu->Parent->QuestionId;
964
965 //
966 // Clear highlight record for this menu
967 //
968 CurrentMenu->QuestionId = 0;
969 return FALSE;
970 }
971
972 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) {
973 //
974 // We never exit FrontPage, so skip the ESC
975 //
976 Selection->Action = UI_ACTION_NONE;
977 return FALSE;
978 }
979
980 //
981 // We are going to leave current FormSet, so check uncommited data in this FormSet
982 //
983 if (IsNvUpdateRequired(Selection->FormSet)) {
984 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
985
986 YesResponse = gYesResponse[0];
987 NoResponse = gNoResponse[0];
988
989 //
990 // If NV flag is up, prompt user
991 //
992 do {
993 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveChanges, gAreYouSure, gEmptyString);
994 } while
995 (
996 (Key.ScanCode != SCAN_ESC) &&
997 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
998 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
999 );
1000
1001 if (Key.ScanCode == SCAN_ESC) {
1002 //
1003 // User hits the ESC key
1004 //
1005 if (Repaint != NULL) {
1006 *Repaint = TRUE;
1007 }
1008
1009 if (NewLine != NULL) {
1010 *NewLine = TRUE;
1011 }
1012
1013 Selection->Action = UI_ACTION_NONE;
1014 return FALSE;
1015 }
1016
1017 //
1018 // If the user hits the YesResponse key
1019 //
1020 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
1021 Status = SubmitForm (Selection->FormSet, Selection->Form, FALSE);
1022 }
1023 }
1024
1025 Selection->Statement = NULL;
1026 if (CurrentMenu != NULL) {
1027 CurrentMenu->QuestionId = 0;
1028 }
1029
1030 Selection->Action = UI_ACTION_EXIT;
1031 return TRUE;
1032 }
1033
1034 /**
1035 Call the call back function for the question and process the return action.
1036
1037 @param Selection On input, Selection tell setup browser the information
1038 about the Selection, form and formset to be displayed.
1039 On output, Selection return the screen item that is selected
1040 by user.
1041 @param Question The Question which need to call.
1042 @param Action The action request.
1043 @param SkipSaveOrDiscard Whether skip save or discard action.
1044
1045 @retval EFI_SUCCESS The call back function excutes successfully.
1046 @return Other value if the call back function failed to excute.
1047 **/
1048 EFI_STATUS
1049 ProcessCallBackFunction (
1050 IN OUT UI_MENU_SELECTION *Selection,
1051 IN FORM_BROWSER_STATEMENT *Question,
1052 IN EFI_BROWSER_ACTION Action,
1053 IN BOOLEAN SkipSaveOrDiscard
1054 )
1055 {
1056 EFI_STATUS Status;
1057 EFI_BROWSER_ACTION_REQUEST ActionRequest;
1058 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
1059 EFI_HII_VALUE *HiiValue;
1060 EFI_IFR_TYPE_VALUE *TypeValue;
1061 FORM_BROWSER_STATEMENT *Statement;
1062 BOOLEAN SubmitFormIsRequired;
1063 BOOLEAN SingleForm;
1064 BOOLEAN DiscardFormIsRequired;
1065 BOOLEAN NeedExit;
1066 LIST_ENTRY *Link;
1067
1068 ConfigAccess = Selection->FormSet->ConfigAccess;
1069 SubmitFormIsRequired = FALSE;
1070 SingleForm = FALSE;
1071 DiscardFormIsRequired = FALSE;
1072 NeedExit = FALSE;
1073 Status = EFI_SUCCESS;
1074 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1075
1076 if (ConfigAccess == NULL) {
1077 return EFI_SUCCESS;
1078 }
1079
1080 Link = GetFirstNode (&Selection->Form->StatementListHead);
1081 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
1082 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1083 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
1084
1085 //
1086 // if Question != NULL, only process the question. Else, process all question in this form.
1087 //
1088 if ((Question != NULL) && (Statement != Question)) {
1089 continue;
1090 }
1091
1092 if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) {
1093 continue;
1094 }
1095
1096 //
1097 // Check whether Statement is disabled.
1098 //
1099 if (Statement->DisableExpression != NULL) {
1100 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Statement->DisableExpression);
1101 if (!EFI_ERROR (Status) &&
1102 (Statement->DisableExpression->Result.Type == EFI_IFR_TYPE_BOOLEAN) &&
1103 (Statement->DisableExpression->Result.Value.b)) {
1104 continue;
1105 }
1106 }
1107
1108 HiiValue = &Statement->HiiValue;
1109 TypeValue = &HiiValue->Value;
1110 if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
1111 //
1112 // For OrderedList, passing in the value buffer to Callback()
1113 //
1114 TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue;
1115 }
1116
1117 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1118 Status = ConfigAccess->Callback (
1119 ConfigAccess,
1120 Action,
1121 Statement->QuestionId,
1122 HiiValue->Type,
1123 TypeValue,
1124 &ActionRequest
1125 );
1126 if (!EFI_ERROR (Status)) {
1127 switch (ActionRequest) {
1128 case EFI_BROWSER_ACTION_REQUEST_RESET:
1129 gResetRequired = TRUE;
1130 break;
1131
1132 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1133 SubmitFormIsRequired = TRUE;
1134 break;
1135
1136 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1137 Selection->Action = UI_ACTION_EXIT;
1138 break;
1139
1140 case EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT:
1141 SubmitFormIsRequired = TRUE;
1142 SingleForm = TRUE;
1143 NeedExit = TRUE;
1144 break;
1145
1146 case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT:
1147 DiscardFormIsRequired = TRUE;
1148 SingleForm = TRUE;
1149 NeedExit = TRUE;
1150 break;
1151
1152 case EFI_BROWSER_ACTION_REQUEST_FORM_APPLY:
1153 SubmitFormIsRequired = TRUE;
1154 SingleForm = TRUE;
1155 break;
1156
1157 case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD:
1158 DiscardFormIsRequired = TRUE;
1159 SingleForm = TRUE;
1160 break;
1161
1162 default:
1163 break;
1164 }
1165
1166 //
1167 // According the spec, return value from call back of "changing" and
1168 // "retrieve" should update to the question's temp buffer.
1169 //
1170 if (Action == EFI_BROWSER_ACTION_CHANGING || Action == EFI_BROWSER_ACTION_RETRIEVE) {
1171 SetQuestionValue(Selection->FormSet,Selection->Form, Question,TRUE);
1172 }
1173 } else if (Status == EFI_UNSUPPORTED) {
1174 //
1175 // If return EFI_UNSUPPORTED, also consider Hii driver suceess deal with it.
1176 //
1177 Status = EFI_SUCCESS;
1178 }
1179 }
1180
1181 if (SubmitFormIsRequired && !SkipSaveOrDiscard) {
1182 SubmitForm (Selection->FormSet, Selection->Form, SingleForm);
1183 }
1184
1185 if (DiscardFormIsRequired && !SkipSaveOrDiscard) {
1186 DiscardForm (Selection->FormSet, Selection->Form, SingleForm);
1187 }
1188
1189 if (NeedExit) {
1190 FindNextMenu (Selection, NULL, NULL);
1191 }
1192
1193 return Status;
1194 }
1195
1196 /**
1197 The worker function that send the displays to the screen. On output,
1198 the selection made by user is returned.
1199
1200 @param Selection On input, Selection tell setup browser the information
1201 about the Selection, form and formset to be displayed.
1202 On output, Selection return the screen item that is selected
1203 by user.
1204
1205 @retval EFI_SUCCESS The page is displayed successfully.
1206 @return Other value if the page failed to be diplayed.
1207
1208 **/
1209 EFI_STATUS
1210 SetupBrowser (
1211 IN OUT UI_MENU_SELECTION *Selection
1212 )
1213 {
1214 EFI_STATUS Status;
1215 LIST_ENTRY *Link;
1216 EFI_HANDLE NotifyHandle;
1217 FORM_BROWSER_STATEMENT *Statement;
1218 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
1219 FORM_BROWSER_FORMSET *FormSet;
1220 EFI_INPUT_KEY Key;
1221
1222 gMenuRefreshHead = NULL;
1223 gResetRequired = FALSE;
1224 FormSet = Selection->FormSet;
1225 ConfigAccess = Selection->FormSet->ConfigAccess;
1226
1227 //
1228 // Register notify for Form package update
1229 //
1230 Status = mHiiDatabase->RegisterPackageNotify (
1231 mHiiDatabase,
1232 EFI_HII_PACKAGE_FORMS,
1233 NULL,
1234 FormUpdateNotify,
1235 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
1236 &NotifyHandle
1237 );
1238 if (EFI_ERROR (Status)) {
1239 return Status;
1240 }
1241
1242 //
1243 // Initialize current settings of Questions in this FormSet
1244 //
1245 Status = InitializeCurrentSetting (Selection->FormSet);
1246 if (EFI_ERROR (Status)) {
1247 goto Done;
1248 }
1249
1250 do {
1251 //
1252 // Initialize Selection->Form
1253 //
1254 if (Selection->FormId == 0) {
1255 //
1256 // Zero FormId indicates display the first Form in a FormSet
1257 //
1258 Link = GetFirstNode (&Selection->FormSet->FormListHead);
1259
1260 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
1261 Selection->FormId = Selection->Form->FormId;
1262 } else {
1263 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
1264 }
1265
1266 if (Selection->Form == NULL) {
1267 //
1268 // No Form to display
1269 //
1270 Status = EFI_NOT_FOUND;
1271 goto Done;
1272 }
1273
1274 //
1275 // Check Form is suppressed.
1276 //
1277 if (Selection->Form->SuppressExpression != NULL) {
1278 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Selection->Form->SuppressExpression);
1279 if (EFI_ERROR (Status) || (Selection->Form->SuppressExpression->Result.Type != EFI_IFR_TYPE_BOOLEAN)) {
1280 Status = EFI_INVALID_PARAMETER;
1281 goto Done;
1282 }
1283
1284 if (Selection->Form->SuppressExpression->Result.Value.b) {
1285 //
1286 // Form is suppressed.
1287 //
1288 do {
1289 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString);
1290 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1291
1292 Status = EFI_NOT_FOUND;
1293 goto Done;
1294 }
1295 }
1296
1297 //
1298 // Reset FormPackage update flag
1299 //
1300 mHiiPackageListUpdated = FALSE;
1301
1302 //
1303 // Before display new form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN
1304 // for each question with callback flag.
1305 // New form may be the first form, or the different form after another form close.
1306 //
1307 if ((ConfigAccess != NULL) &&
1308 ((Selection->Handle != mCurrentHiiHandle) ||
1309 (!CompareGuid (&Selection->FormSetGuid, &mCurrentFormSetGuid)) ||
1310 (Selection->FormId != mCurrentFormId))) {
1311
1312 //
1313 // Keep current form information
1314 //
1315 mCurrentHiiHandle = Selection->Handle;
1316 CopyGuid (&mCurrentFormSetGuid, &Selection->FormSetGuid);
1317 mCurrentFormId = Selection->FormId;
1318
1319 Status = ProcessCallBackFunction (Selection, NULL, EFI_BROWSER_ACTION_FORM_OPEN, FALSE);
1320 if (EFI_ERROR (Status)) {
1321 goto Done;
1322 }
1323
1324 //
1325 // EXIT requests to close form.
1326 //
1327 if (Selection->Action == UI_ACTION_EXIT) {
1328 goto Done;
1329 }
1330 //
1331 // IFR is updated during callback of open form, force to reparse the IFR binary
1332 //
1333 if (mHiiPackageListUpdated) {
1334 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1335 mHiiPackageListUpdated = FALSE;
1336 break;
1337 }
1338 }
1339
1340 //
1341 // Load Questions' Value for display
1342 //
1343 Status = LoadFormSetConfig (Selection, Selection->FormSet);
1344 if (EFI_ERROR (Status)) {
1345 goto Done;
1346 }
1347
1348 //
1349 // EXIT requests to close form.
1350 //
1351 if (Selection->Action == UI_ACTION_EXIT) {
1352 goto Done;
1353 }
1354 //
1355 // IFR is updated during callback of read value, force to reparse the IFR binary
1356 //
1357 if (mHiiPackageListUpdated) {
1358 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1359 mHiiPackageListUpdated = FALSE;
1360 break;
1361 }
1362
1363 //
1364 // Displays the Header and Footer borders
1365 //
1366 DisplayPageFrame (Selection);
1367
1368 //
1369 // Display form
1370 //
1371 Status = DisplayForm (Selection);
1372 if (EFI_ERROR (Status)) {
1373 goto Done;
1374 }
1375
1376 //
1377 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
1378 //
1379 Statement = Selection->Statement;
1380 if (Statement != NULL) {
1381 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
1382 gResetRequired = TRUE;
1383 }
1384
1385 //
1386 // Reset FormPackage update flag
1387 //
1388 mHiiPackageListUpdated = FALSE;
1389
1390 if ((ConfigAccess != NULL) &&
1391 ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) &&
1392 (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
1393
1394 Status = ProcessCallBackFunction(Selection, Statement, EFI_BROWSER_ACTION_CHANGING, FALSE);
1395 if (Statement->Operand == EFI_IFR_REF_OP && Selection->Action != UI_ACTION_EXIT) {
1396 //
1397 // Process dynamic update ref opcode.
1398 //
1399 if (!EFI_ERROR (Status)) {
1400 Status = ProcessGotoOpCode(Statement, Selection, NULL, NULL);
1401 }
1402
1403 //
1404 // Callback return error status or status return from process goto opcode.
1405 //
1406 if (EFI_ERROR (Status)) {
1407 //
1408 // Cross reference will not be taken
1409 //
1410 Selection->FormId = Selection->Form->FormId;
1411 Selection->QuestionId = 0;
1412 }
1413 }
1414 }
1415
1416 //
1417 // Check whether Form Package has been updated during Callback
1418 //
1419 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
1420 //
1421 // Force to reparse IFR binary of target Formset
1422 //
1423 mHiiPackageListUpdated = FALSE;
1424 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1425 }
1426 }
1427
1428 //
1429 // Before exit the form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE
1430 // for each question with callback flag.
1431 //
1432 if ((ConfigAccess != NULL) &&
1433 ((Selection->Action == UI_ACTION_EXIT) ||
1434 (Selection->Handle != mCurrentHiiHandle) ||
1435 (!CompareGuid (&Selection->FormSetGuid, &mCurrentFormSetGuid)) ||
1436 (Selection->FormId != mCurrentFormId))) {
1437
1438 Status = ProcessCallBackFunction (Selection, NULL, EFI_BROWSER_ACTION_FORM_CLOSE, FALSE);
1439 if (EFI_ERROR (Status)) {
1440 goto Done;
1441 }
1442 }
1443 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1444
1445 //
1446 // Record the old formset
1447 //
1448 if (gOldFormSet != NULL) {
1449 DestroyFormSet (gOldFormSet);
1450 }
1451 gOldFormSet = FormSet;
1452
1453 Done:
1454 //
1455 // Reset current form information to the initial setting when error happens or form exit.
1456 //
1457 if (EFI_ERROR (Status) || Selection->Action == UI_ACTION_EXIT) {
1458 mCurrentHiiHandle = NULL;
1459 CopyGuid (&mCurrentFormSetGuid, &gZeroGuid);
1460 mCurrentFormId = 0;
1461 }
1462
1463 //
1464 // Unregister notify for Form package update
1465 //
1466 mHiiDatabase->UnregisterPackageNotify (
1467 mHiiDatabase,
1468 NotifyHandle
1469 );
1470 return Status;
1471 }