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