]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
Per UEFI spec, on CallBack action EFI_BROWSER_ACTION_CHANGING, the return value of...
[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 - gFooterHeight,
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 - gFooterHeight, 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 - gFooterHeight + 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 ASSERT (StringPtr != NULL);
537
538 Width = GetWidth (Statement, Handle);
539
540 NumberOfLines = 1;
541 ArrayEntry = 0;
542 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
543 //
544 // If there is more string to process print on the next row and increment the Skip value
545 //
546 if (StrLen (&StringPtr[ArrayEntry]) != 0) {
547 NumberOfLines++;
548 }
549
550 FreePool (OutputString);
551 }
552
553 //
554 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
555 // it in UiFreeMenu.
556 //
557 MenuOption = UiAddMenuOption (StringPtr, Selection->Handle, Selection->Form, Statement, NumberOfLines, MenuItemCount);
558 MenuItemCount++;
559
560 if (MenuOption->IsQuestion && !MenuOption->ReadOnly) {
561 //
562 // At least one item is not readonly, this Form is considered as editable
563 //
564 Selection->FormEditable = TRUE;
565 }
566 }
567
568 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
569 }
570
571 Status = UiDisplayMenu (Selection);
572
573 UiFreeMenu ();
574
575 return Status;
576 }
577
578 /**
579 Initialize the HII String Token to the correct values.
580
581 **/
582 VOID
583 InitializeBrowserStrings (
584 VOID
585 )
586 {
587 gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);
588 gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);
589 gEnterEscapeString = GetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), gHiiHandle);
590 gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);
591 gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);
592 gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);
593 gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle);
594 gHexNumericInput = GetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), gHiiHandle);
595 gToggleCheckBox = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);
596 gPromptForData = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);
597 gPromptForPassword = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);
598 gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);
599 gConfirmPassword = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);
600 gConfirmError = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);
601 gPassowordInvalid = GetToken (STRING_TOKEN (PASSWORD_INVALID), gHiiHandle);
602 gPressEnter = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);
603 gEmptyString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
604 gAreYouSure = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);
605 gYesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);
606 gNoResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);
607 gMiniString = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);
608 gPlusString = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);
609 gMinusString = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);
610 gAdjustNumber = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);
611 gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle);
612 gOptionMismatch = GetToken (STRING_TOKEN (OPTION_MISMATCH), gHiiHandle);
613 gFormSuppress = GetToken (STRING_TOKEN (FORM_SUPPRESSED), gHiiHandle);
614 return ;
615 }
616
617 /**
618 Free up the resource allocated for all strings required
619 by Setup Browser.
620
621 **/
622 VOID
623 FreeBrowserStrings (
624 VOID
625 )
626 {
627 FreePool (gEnterString);
628 FreePool (gEnterCommitString);
629 FreePool (gEnterEscapeString);
630 FreePool (gEscapeString);
631 FreePool (gMoveHighlight);
632 FreePool (gMakeSelection);
633 FreePool (gDecNumericInput);
634 FreePool (gHexNumericInput);
635 FreePool (gToggleCheckBox);
636 FreePool (gPromptForData);
637 FreePool (gPromptForPassword);
638 FreePool (gPromptForNewPassword);
639 FreePool (gConfirmPassword);
640 FreePool (gPassowordInvalid);
641 FreePool (gConfirmError);
642 FreePool (gPressEnter);
643 FreePool (gEmptyString);
644 FreePool (gAreYouSure);
645 FreePool (gYesResponse);
646 FreePool (gNoResponse);
647 FreePool (gMiniString);
648 FreePool (gPlusString);
649 FreePool (gMinusString);
650 FreePool (gAdjustNumber);
651 FreePool (gSaveChanges);
652 FreePool (gOptionMismatch);
653 FreePool (gFormSuppress);
654 return ;
655 }
656
657 /**
658 Show all registered HotKey help strings on bottom Rows.
659
660 **/
661 VOID
662 PrintHotKeyHelpString (
663 VOID
664 )
665 {
666 UINTN CurrentCol;
667 UINTN CurrentRow;
668 UINTN BottomRowOfHotKeyHelp;
669 UINTN ColumnWidth;
670 UINTN Index;
671 EFI_SCREEN_DESCRIPTOR LocalScreen;
672 LIST_ENTRY *Link;
673 BROWSER_HOT_KEY *HotKey;
674
675 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
676 ColumnWidth = (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
677 BottomRowOfHotKeyHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 3;
678
679 //
680 // Calculate total number of Register HotKeys.
681 //
682 Index = 0;
683 Link = GetFirstNode (&gBrowserHotKeyList);
684 while (!IsNull (&gBrowserHotKeyList, Link)) {
685 HotKey = BROWSER_HOT_KEY_FROM_LINK (Link);
686 //
687 // Help string can't exceed ColumnWidth. One Row will show three Help information.
688 //
689 if (StrLen (HotKey->HelpString) > ColumnWidth) {
690 HotKey->HelpString[ColumnWidth] = L'\0';
691 }
692 //
693 // Calculate help information Column and Row.
694 //
695 if ((Index % 3) != 2) {
696 CurrentCol = LocalScreen.LeftColumn + (2 - Index % 3) * ColumnWidth;
697 } else {
698 CurrentCol = LocalScreen.LeftColumn + 2;
699 }
700 CurrentRow = BottomRowOfHotKeyHelp - Index / 3;
701 //
702 // Print HotKey help string on bottom Row.
703 //
704 PrintStringAt (CurrentCol, CurrentRow, HotKey->HelpString);
705
706 //
707 // Get Next Hot Key.
708 //
709 Link = GetNextNode (&gBrowserHotKeyList, Link);
710 Index ++;
711 }
712
713 return;
714 }
715
716 /**
717 Update key's help imformation.
718
719 @param Selection Tell setup browser the information about the Selection
720 @param MenuOption The Menu option
721 @param Selected Whether or not a tag be selected
722
723 **/
724 VOID
725 UpdateKeyHelp (
726 IN UI_MENU_SELECTION *Selection,
727 IN UI_MENU_OPTION *MenuOption,
728 IN BOOLEAN Selected
729 )
730 {
731 UINTN SecCol;
732 UINTN ThdCol;
733 UINTN LeftColumnOfHelp;
734 UINTN RightColumnOfHelp;
735 UINTN TopRowOfHelp;
736 UINTN BottomRowOfHelp;
737 UINTN StartColumnOfHelp;
738 EFI_SCREEN_DESCRIPTOR LocalScreen;
739 FORM_BROWSER_STATEMENT *Statement;
740
741 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
742
743 if (Selection->Form->ModalForm) {
744 return;
745 }
746
747 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
748
749 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
750 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3 * 2;
751
752 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
753 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
754 RightColumnOfHelp = LocalScreen.RightColumn - 2;
755 TopRowOfHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight + 1;
756 BottomRowOfHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2;
757
758 Statement = MenuOption->ThisTag;
759 switch (Statement->Operand) {
760 case EFI_IFR_ORDERED_LIST_OP:
761 case EFI_IFR_ONE_OF_OP:
762 case EFI_IFR_NUMERIC_OP:
763 case EFI_IFR_TIME_OP:
764 case EFI_IFR_DATE_OP:
765 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
766
767 if (!Selected) {
768 //
769 // On system setting, HotKey will show on every form.
770 //
771 if (gBrowserSettingScope == SystemLevel ||
772 (Selection->FormEditable && gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) {
773 PrintHotKeyHelpString ();
774 }
775
776 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
777 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
778 }
779
780 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
781 (Statement->Operand == EFI_IFR_TIME_OP)) {
782 PrintAt (
783 StartColumnOfHelp,
784 BottomRowOfHelp,
785 L"%c%c%c%c%s",
786 ARROW_UP,
787 ARROW_DOWN,
788 ARROW_RIGHT,
789 ARROW_LEFT,
790 gMoveHighlight
791 );
792 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
793 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber);
794 } else {
795 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
796 if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) {
797 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber);
798 }
799 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
800 }
801 } else {
802 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
803
804 //
805 // If it is a selected numeric with manual input, display different message
806 //
807 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) ||
808 (Statement->Operand == EFI_IFR_DATE_OP) ||
809 (Statement->Operand == EFI_IFR_TIME_OP)) {
810 PrintStringAt (
811 SecCol,
812 TopRowOfHelp,
813 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
814 );
815 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
816 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
817 }
818
819 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
820 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
821 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
822 }
823
824 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
825 }
826 break;
827
828 case EFI_IFR_CHECKBOX_OP:
829 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
830
831 //
832 // On system setting, HotKey will show on every form.
833 //
834 if (gBrowserSettingScope == SystemLevel ||
835 (Selection->FormEditable && gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) {
836 PrintHotKeyHelpString ();
837 }
838 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
839 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
840 }
841
842 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
843 PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
844 break;
845
846 case EFI_IFR_REF_OP:
847 case EFI_IFR_PASSWORD_OP:
848 case EFI_IFR_STRING_OP:
849 case EFI_IFR_TEXT_OP:
850 case EFI_IFR_ACTION_OP:
851 case EFI_IFR_RESET_BUTTON_OP:
852 case EFI_IFR_SUBTITLE_OP:
853 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
854
855 if (!Selected) {
856 //
857 // On system setting, HotKey will show on every form.
858 //
859 if (gBrowserSettingScope == SystemLevel ||
860 (Selection->FormEditable && gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) {
861 PrintHotKeyHelpString ();
862 }
863 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
864 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
865 }
866
867 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
868 if (Statement->Operand != EFI_IFR_TEXT_OP && Statement->Operand != EFI_IFR_SUBTITLE_OP) {
869 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
870 }
871 } else {
872 if (Statement->Operand != EFI_IFR_REF_OP) {
873 PrintStringAt (
874 (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,
875 BottomRowOfHelp,
876 gEnterCommitString
877 );
878 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
879 }
880 }
881 break;
882
883 default:
884 break;
885 }
886 }
887
888 /**
889 Functions which are registered to receive notification of
890 database events have this prototype. The actual event is encoded
891 in NotifyType. The following table describes how PackageType,
892 PackageGuid, Handle, and Package are used for each of the
893 notification types.
894
895 @param PackageType Package type of the notification.
896
897 @param PackageGuid If PackageType is
898 EFI_HII_PACKAGE_TYPE_GUID, then this is
899 the pointer to the GUID from the Guid
900 field of EFI_HII_PACKAGE_GUID_HEADER.
901 Otherwise, it must be NULL.
902
903 @param Package Points to the package referred to by the
904 notification Handle The handle of the package
905 list which contains the specified package.
906
907 @param Handle The HII handle.
908
909 @param NotifyType The type of change concerning the
910 database. See
911 EFI_HII_DATABASE_NOTIFY_TYPE.
912
913 **/
914 EFI_STATUS
915 EFIAPI
916 FormUpdateNotify (
917 IN UINT8 PackageType,
918 IN CONST EFI_GUID *PackageGuid,
919 IN CONST EFI_HII_PACKAGE_HEADER *Package,
920 IN EFI_HII_HANDLE Handle,
921 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
922 )
923 {
924 mHiiPackageListUpdated = TRUE;
925
926 return EFI_SUCCESS;
927 }
928
929 /**
930 check whether the formset need to update the NV.
931
932 @param FormSet FormSet data structure.
933
934 @retval TRUE Need to update the NV.
935 @retval FALSE No need to update the NV.
936 **/
937 BOOLEAN
938 IsNvUpdateRequired (
939 IN FORM_BROWSER_FORMSET *FormSet
940 )
941 {
942 LIST_ENTRY *Link;
943 FORM_BROWSER_FORM *Form;
944
945 Link = GetFirstNode (&FormSet->FormListHead);
946 while (!IsNull (&FormSet->FormListHead, Link)) {
947 Form = FORM_BROWSER_FORM_FROM_LINK (Link);
948
949 if (Form->NvUpdateRequired ) {
950 return TRUE;
951 }
952
953 Link = GetNextNode (&FormSet->FormListHead, Link);
954 }
955
956 return FALSE;
957 }
958
959 /**
960 check whether the formset need to update the NV.
961
962 @param FormSet FormSet data structure.
963 @param SetValue Whether set new value or clear old value.
964
965 **/
966 VOID
967 UpdateNvInfoInForm (
968 IN FORM_BROWSER_FORMSET *FormSet,
969 IN BOOLEAN SetValue
970 )
971 {
972 LIST_ENTRY *Link;
973 FORM_BROWSER_FORM *Form;
974
975 Link = GetFirstNode (&FormSet->FormListHead);
976 while (!IsNull (&FormSet->FormListHead, Link)) {
977 Form = FORM_BROWSER_FORM_FROM_LINK (Link);
978
979 Form->NvUpdateRequired = SetValue;
980
981 Link = GetNextNode (&FormSet->FormListHead, Link);
982 }
983 }
984 /**
985 Find menu which will show next time.
986
987 @param Selection On input, Selection tell setup browser the information
988 about the Selection, form and formset to be displayed.
989 On output, Selection return the screen item that is selected
990 by user.
991 @param Repaint Whether need to repaint the menu.
992 @param NewLine Whether need to show at new line.
993
994 @retval TRUE Need return.
995 @retval FALSE No need to return.
996 **/
997 BOOLEAN
998 FindNextMenu (
999 IN OUT UI_MENU_SELECTION *Selection,
1000 IN BOOLEAN *Repaint,
1001 IN BOOLEAN *NewLine
1002 )
1003 {
1004 UI_MENU_LIST *CurrentMenu;
1005 CHAR16 YesResponse;
1006 CHAR16 NoResponse;
1007 EFI_INPUT_KEY Key;
1008 BROWSER_SETTING_SCOPE Scope;
1009
1010 CurrentMenu = Selection->CurrentMenu;
1011
1012 if (CurrentMenu != NULL && CurrentMenu->Parent != NULL) {
1013 //
1014 // we have a parent, so go to the parent menu
1015 //
1016 if (CompareGuid (&CurrentMenu->FormSetGuid, &CurrentMenu->Parent->FormSetGuid)) {
1017 //
1018 // The parent menu and current menu are in the same formset
1019 //
1020 Selection->Action = UI_ACTION_REFRESH_FORM;
1021 Scope = FormLevel;
1022 } else {
1023 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1024 CopyMem (&Selection->FormSetGuid, &CurrentMenu->Parent->FormSetGuid, sizeof (EFI_GUID));
1025 Selection->Handle = CurrentMenu->Parent->HiiHandle;
1026 Scope = FormSetLevel;
1027 }
1028
1029 //
1030 // Form Level Check whether the data is changed.
1031 //
1032 if ((gBrowserSettingScope == FormLevel && Selection->Form->NvUpdateRequired) ||
1033 (gBrowserSettingScope == FormSetLevel && IsNvUpdateRequired(Selection->FormSet) && Scope == FormSetLevel)) {
1034 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
1035
1036 YesResponse = gYesResponse[0];
1037 NoResponse = gNoResponse[0];
1038
1039 //
1040 // If NV flag is up, prompt user
1041 //
1042 do {
1043 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveChanges, gAreYouSure, gEmptyString);
1044 } while
1045 (
1046 (Key.ScanCode != SCAN_ESC) &&
1047 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
1048 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
1049 );
1050
1051 if (Key.ScanCode == SCAN_ESC) {
1052 //
1053 // User hits the ESC key, Ingore.
1054 //
1055 if (Repaint != NULL) {
1056 *Repaint = TRUE;
1057 }
1058 if (NewLine != NULL) {
1059 *NewLine = TRUE;
1060 }
1061
1062 Selection->Action = UI_ACTION_NONE;
1063 return FALSE;
1064 }
1065
1066 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
1067 //
1068 // If the user hits the YesResponse key
1069 //
1070 SubmitForm (Selection->FormSet, Selection->Form, Scope);
1071 } else {
1072 //
1073 // If the user hits the NoResponse key
1074 //
1075 DiscardForm (Selection->FormSet, Selection->Form, Scope);
1076 }
1077 }
1078
1079 Selection->Statement = NULL;
1080
1081 Selection->FormId = CurrentMenu->Parent->FormId;
1082 Selection->QuestionId = CurrentMenu->Parent->QuestionId;
1083
1084 //
1085 // Clear highlight record for this menu
1086 //
1087 CurrentMenu->QuestionId = 0;
1088 return FALSE;
1089 }
1090
1091 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) {
1092 //
1093 // We never exit FrontPage, so skip the ESC
1094 //
1095 Selection->Action = UI_ACTION_NONE;
1096 return FALSE;
1097 }
1098
1099 //
1100 // We are going to leave current FormSet, so check uncommited data in this FormSet
1101 //
1102 if (gBrowserSettingScope != SystemLevel && IsNvUpdateRequired(Selection->FormSet)) {
1103 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
1104
1105 YesResponse = gYesResponse[0];
1106 NoResponse = gNoResponse[0];
1107
1108 //
1109 // If NV flag is up, prompt user
1110 //
1111 do {
1112 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveChanges, gAreYouSure, gEmptyString);
1113 } while
1114 (
1115 (Key.ScanCode != SCAN_ESC) &&
1116 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
1117 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
1118 );
1119
1120 if (Key.ScanCode == SCAN_ESC) {
1121 //
1122 // User hits the ESC key
1123 //
1124 if (Repaint != NULL) {
1125 *Repaint = TRUE;
1126 }
1127
1128 if (NewLine != NULL) {
1129 *NewLine = TRUE;
1130 }
1131
1132 Selection->Action = UI_ACTION_NONE;
1133 return FALSE;
1134 }
1135
1136 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
1137 //
1138 // If the user hits the YesResponse key
1139 //
1140 SubmitForm (Selection->FormSet, Selection->Form, FormSetLevel);
1141 } else {
1142 //
1143 // If the user hits the NoResponse key
1144 //
1145 DiscardForm (Selection->FormSet, Selection->Form, FormSetLevel);
1146 }
1147 }
1148
1149 Selection->Statement = NULL;
1150 if (CurrentMenu != NULL) {
1151 CurrentMenu->QuestionId = 0;
1152 }
1153
1154 Selection->Action = UI_ACTION_EXIT;
1155 return TRUE;
1156 }
1157
1158 /**
1159 Call the call back function for the question and process the return action.
1160
1161 @param Selection On input, Selection tell setup browser the information
1162 about the Selection, form and formset to be displayed.
1163 On output, Selection return the screen item that is selected
1164 by user.
1165 @param Question The Question which need to call.
1166 @param Action The action request.
1167 @param SkipSaveOrDiscard Whether skip save or discard action.
1168
1169 @retval EFI_SUCCESS The call back function excutes successfully.
1170 @return Other value if the call back function failed to excute.
1171 **/
1172 EFI_STATUS
1173 ProcessCallBackFunction (
1174 IN OUT UI_MENU_SELECTION *Selection,
1175 IN FORM_BROWSER_STATEMENT *Question,
1176 IN EFI_BROWSER_ACTION Action,
1177 IN BOOLEAN SkipSaveOrDiscard
1178 )
1179 {
1180 EFI_STATUS Status;
1181 EFI_BROWSER_ACTION_REQUEST ActionRequest;
1182 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
1183 EFI_HII_VALUE *HiiValue;
1184 EFI_IFR_TYPE_VALUE *TypeValue;
1185 FORM_BROWSER_STATEMENT *Statement;
1186 BOOLEAN SubmitFormIsRequired;
1187 BOOLEAN DiscardFormIsRequired;
1188 BOOLEAN NeedExit;
1189 LIST_ENTRY *Link;
1190 BROWSER_SETTING_SCOPE SettingLevel;
1191
1192 ConfigAccess = Selection->FormSet->ConfigAccess;
1193 SubmitFormIsRequired = FALSE;
1194 SettingLevel = FormSetLevel;
1195 DiscardFormIsRequired = FALSE;
1196 NeedExit = FALSE;
1197 Status = EFI_SUCCESS;
1198 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1199
1200 if (ConfigAccess == NULL) {
1201 return EFI_SUCCESS;
1202 }
1203
1204 Link = GetFirstNode (&Selection->Form->StatementListHead);
1205 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
1206 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1207 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
1208
1209 //
1210 // if Question != NULL, only process the question. Else, process all question in this form.
1211 //
1212 if ((Question != NULL) && (Statement != Question)) {
1213 continue;
1214 }
1215
1216 if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) {
1217 continue;
1218 }
1219
1220 //
1221 // Check whether Statement is disabled.
1222 //
1223 if (Statement->DisableExpression != NULL) {
1224 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Statement->DisableExpression);
1225 if (!EFI_ERROR (Status) &&
1226 (Statement->DisableExpression->Result.Type == EFI_IFR_TYPE_BOOLEAN) &&
1227 (Statement->DisableExpression->Result.Value.b)) {
1228 continue;
1229 }
1230 }
1231
1232 HiiValue = &Statement->HiiValue;
1233 TypeValue = &HiiValue->Value;
1234 if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
1235 //
1236 // For OrderedList, passing in the value buffer to Callback()
1237 //
1238 TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue;
1239 }
1240
1241 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1242 Status = ConfigAccess->Callback (
1243 ConfigAccess,
1244 Action,
1245 Statement->QuestionId,
1246 HiiValue->Type,
1247 TypeValue,
1248 &ActionRequest
1249 );
1250 if (!EFI_ERROR (Status)) {
1251 //
1252 // Only for EFI_BROWSER_ACTION_CHANGED need to handle this ActionRequest.
1253 //
1254 if (Action == EFI_BROWSER_ACTION_CHANGED) {
1255 switch (ActionRequest) {
1256 case EFI_BROWSER_ACTION_REQUEST_RESET:
1257 gResetRequired = TRUE;
1258 Selection->Action = UI_ACTION_EXIT;
1259 break;
1260
1261 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1262 SubmitFormIsRequired = TRUE;
1263 Selection->Action = UI_ACTION_EXIT;
1264 break;
1265
1266 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1267 Selection->Action = UI_ACTION_EXIT;
1268 break;
1269
1270 case EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT:
1271 SubmitFormIsRequired = TRUE;
1272 SettingLevel = FormLevel;
1273 NeedExit = TRUE;
1274 break;
1275
1276 case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT:
1277 DiscardFormIsRequired = TRUE;
1278 SettingLevel = FormLevel;
1279 NeedExit = TRUE;
1280 break;
1281
1282 case EFI_BROWSER_ACTION_REQUEST_FORM_APPLY:
1283 SubmitFormIsRequired = TRUE;
1284 SettingLevel = FormLevel;
1285 break;
1286
1287 case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD:
1288 DiscardFormIsRequired = TRUE;
1289 SettingLevel = FormLevel;
1290 break;
1291
1292 default:
1293 break;
1294 }
1295 }
1296
1297 //
1298 // According the spec, return value from call back of "changing" and
1299 // "retrieve" should update to the question's temp buffer.
1300 //
1301 if (Action == EFI_BROWSER_ACTION_CHANGING || Action == EFI_BROWSER_ACTION_RETRIEVE) {
1302 SetQuestionValue(Selection->FormSet, Selection->Form, Statement, TRUE);
1303 }
1304 } else {
1305 //
1306 // According the spec, return fail from call back of "changing" and
1307 // "retrieve", should restore the question's value.
1308 //
1309 if (Action == EFI_BROWSER_ACTION_CHANGING || Action == EFI_BROWSER_ACTION_RETRIEVE) {
1310 GetQuestionValue(Selection->FormSet, Selection->Form, Statement, TRUE);
1311 }
1312
1313 if (Status == EFI_UNSUPPORTED) {
1314 //
1315 // If return EFI_UNSUPPORTED, also consider Hii driver suceess deal with it.
1316 //
1317 Status = EFI_SUCCESS;
1318 }
1319 }
1320 }
1321
1322 if (SubmitFormIsRequired && !SkipSaveOrDiscard) {
1323 SubmitForm (Selection->FormSet, Selection->Form, SettingLevel);
1324 }
1325
1326 if (DiscardFormIsRequired && !SkipSaveOrDiscard) {
1327 DiscardForm (Selection->FormSet, Selection->Form, SettingLevel);
1328 }
1329
1330 if (NeedExit) {
1331 FindNextMenu (Selection, NULL, NULL);
1332 }
1333
1334 return Status;
1335 }
1336
1337 /**
1338 The worker function that send the displays to the screen. On output,
1339 the selection made by user is returned.
1340
1341 @param Selection On input, Selection tell setup browser the information
1342 about the Selection, form and formset to be displayed.
1343 On output, Selection return the screen item that is selected
1344 by user.
1345
1346 @retval EFI_SUCCESS The page is displayed successfully.
1347 @return Other value if the page failed to be diplayed.
1348
1349 **/
1350 EFI_STATUS
1351 SetupBrowser (
1352 IN OUT UI_MENU_SELECTION *Selection
1353 )
1354 {
1355 EFI_STATUS Status;
1356 LIST_ENTRY *Link;
1357 EFI_HANDLE NotifyHandle;
1358 FORM_BROWSER_STATEMENT *Statement;
1359 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
1360 EFI_INPUT_KEY Key;
1361
1362 gMenuRefreshHead = NULL;
1363 ConfigAccess = Selection->FormSet->ConfigAccess;
1364
1365 //
1366 // Register notify for Form package update
1367 //
1368 Status = mHiiDatabase->RegisterPackageNotify (
1369 mHiiDatabase,
1370 EFI_HII_PACKAGE_FORMS,
1371 NULL,
1372 FormUpdateNotify,
1373 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
1374 &NotifyHandle
1375 );
1376 if (EFI_ERROR (Status)) {
1377 return Status;
1378 }
1379
1380 //
1381 // Initialize current settings of Questions in this FormSet
1382 //
1383 Status = InitializeCurrentSetting (Selection->FormSet);
1384 if (EFI_ERROR (Status)) {
1385 goto Done;
1386 }
1387
1388 //
1389 // Update gOldFormSet on maintain back up FormSet list.
1390 // And, make gOldFormSet point to current FormSet.
1391 //
1392 if (gOldFormSet != NULL) {
1393 RemoveEntryList (&gOldFormSet->Link);
1394 DestroyFormSet (gOldFormSet);
1395 }
1396 gOldFormSet = Selection->FormSet;
1397 InsertTailList (&gBrowserFormSetList, &gOldFormSet->Link);
1398
1399 do {
1400 //
1401 // Initialize Selection->Form
1402 //
1403 if (Selection->FormId == 0) {
1404 //
1405 // Zero FormId indicates display the first Form in a FormSet
1406 //
1407 Link = GetFirstNode (&Selection->FormSet->FormListHead);
1408
1409 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
1410 Selection->FormId = Selection->Form->FormId;
1411 } else {
1412 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
1413 }
1414
1415 if (Selection->Form == NULL) {
1416 //
1417 // No Form to display
1418 //
1419 Status = EFI_NOT_FOUND;
1420 goto Done;
1421 }
1422
1423 //
1424 // Check Form is suppressed.
1425 //
1426 if (Selection->Form->SuppressExpression != NULL) {
1427 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Selection->Form->SuppressExpression);
1428 if (EFI_ERROR (Status) || (Selection->Form->SuppressExpression->Result.Type != EFI_IFR_TYPE_BOOLEAN)) {
1429 Status = EFI_INVALID_PARAMETER;
1430 goto Done;
1431 }
1432
1433 if (Selection->Form->SuppressExpression->Result.Value.b) {
1434 //
1435 // Form is suppressed.
1436 //
1437 do {
1438 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString);
1439 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1440
1441 Status = EFI_NOT_FOUND;
1442 goto Done;
1443 }
1444 }
1445
1446 //
1447 // Reset FormPackage update flag
1448 //
1449 mHiiPackageListUpdated = FALSE;
1450
1451 //
1452 // Before display new form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN
1453 // for each question with callback flag.
1454 // New form may be the first form, or the different form after another form close.
1455 //
1456 if ((ConfigAccess != NULL) &&
1457 ((Selection->Handle != mCurrentHiiHandle) ||
1458 (!CompareGuid (&Selection->FormSetGuid, &mCurrentFormSetGuid)) ||
1459 (Selection->FormId != mCurrentFormId))) {
1460
1461 //
1462 // Keep current form information
1463 //
1464 mCurrentHiiHandle = Selection->Handle;
1465 CopyGuid (&mCurrentFormSetGuid, &Selection->FormSetGuid);
1466 mCurrentFormId = Selection->FormId;
1467
1468 Status = ProcessCallBackFunction (Selection, NULL, EFI_BROWSER_ACTION_FORM_OPEN, FALSE);
1469 if (EFI_ERROR (Status)) {
1470 goto Done;
1471 }
1472
1473 //
1474 // EXIT requests to close form.
1475 //
1476 if (Selection->Action == UI_ACTION_EXIT) {
1477 goto Done;
1478 }
1479 //
1480 // IFR is updated during callback of open form, force to reparse the IFR binary
1481 //
1482 if (mHiiPackageListUpdated) {
1483 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1484 mHiiPackageListUpdated = FALSE;
1485 break;
1486 }
1487 }
1488
1489 //
1490 // Load Questions' Value for display
1491 //
1492 Status = LoadFormSetConfig (Selection, Selection->FormSet);
1493 if (EFI_ERROR (Status)) {
1494 goto Done;
1495 }
1496
1497 //
1498 // EXIT requests to close form.
1499 //
1500 if (Selection->Action == UI_ACTION_EXIT) {
1501 goto Done;
1502 }
1503 //
1504 // IFR is updated during callback of read value, force to reparse the IFR binary
1505 //
1506 if (mHiiPackageListUpdated) {
1507 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1508 mHiiPackageListUpdated = FALSE;
1509 break;
1510 }
1511
1512 //
1513 // Displays the Header and Footer borders
1514 //
1515 DisplayPageFrame (Selection);
1516
1517 //
1518 // Display form
1519 //
1520 Status = DisplayForm (Selection);
1521 if (EFI_ERROR (Status)) {
1522 goto Done;
1523 }
1524
1525 //
1526 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
1527 //
1528 Statement = Selection->Statement;
1529 if (Statement != NULL) {
1530 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
1531 gResetRequired = TRUE;
1532 }
1533
1534 //
1535 // Reset FormPackage update flag
1536 //
1537 mHiiPackageListUpdated = FALSE;
1538
1539 if ((ConfigAccess != NULL) &&
1540 ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) &&
1541 (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
1542 Status = ProcessCallBackFunction(Selection, Statement, EFI_BROWSER_ACTION_CHANGING, FALSE);
1543 if (Statement->Operand == EFI_IFR_REF_OP && Selection->Action != UI_ACTION_EXIT) {
1544 //
1545 // Process dynamic update ref opcode.
1546 //
1547 if (!EFI_ERROR (Status)) {
1548 Status = ProcessGotoOpCode(Statement, Selection, NULL, NULL);
1549 }
1550
1551 //
1552 // Callback return error status or status return from process goto opcode.
1553 //
1554 if (EFI_ERROR (Status)) {
1555 //
1556 // Cross reference will not be taken
1557 //
1558 Selection->FormId = Selection->Form->FormId;
1559 Selection->QuestionId = 0;
1560 }
1561 }
1562
1563 if (!EFI_ERROR (Status) && Statement->Operand != EFI_IFR_REF_OP) {
1564 ProcessCallBackFunction(Selection, Statement, EFI_BROWSER_ACTION_CHANGED, FALSE);
1565 }
1566 }
1567
1568 //
1569 // Check whether Form Package has been updated during Callback
1570 //
1571 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
1572 //
1573 // Force to reparse IFR binary of target Formset
1574 //
1575 mHiiPackageListUpdated = FALSE;
1576 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1577 }
1578 }
1579
1580 //
1581 // Before exit the form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE
1582 // for each question with callback flag.
1583 //
1584 if ((ConfigAccess != NULL) &&
1585 ((Selection->Action == UI_ACTION_EXIT) ||
1586 (Selection->Handle != mCurrentHiiHandle) ||
1587 (!CompareGuid (&Selection->FormSetGuid, &mCurrentFormSetGuid)) ||
1588 (Selection->FormId != mCurrentFormId))) {
1589
1590 Status = ProcessCallBackFunction (Selection, NULL, EFI_BROWSER_ACTION_FORM_CLOSE, FALSE);
1591 if (EFI_ERROR (Status)) {
1592 goto Done;
1593 }
1594 }
1595 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1596
1597 Done:
1598 //
1599 // Reset current form information to the initial setting when error happens or form exit.
1600 //
1601 if (EFI_ERROR (Status) || Selection->Action == UI_ACTION_EXIT) {
1602 mCurrentHiiHandle = NULL;
1603 CopyGuid (&mCurrentFormSetGuid, &gZeroGuid);
1604 mCurrentFormId = 0;
1605 }
1606
1607 //
1608 // Unregister notify for Form package update
1609 //
1610 mHiiDatabase->UnregisterPackageNotify (
1611 mHiiDatabase,
1612 NotifyHandle
1613 );
1614 return Status;
1615 }