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