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