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