]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
Per UEFI spec, FORM_OPEN/FORM_CLOSE Callback function should be called for each quest...
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
1 /** @file
2 Utility functions for UI presentation.
3
4 Copyright (c) 2004 - 2010, 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
20
21 /**
22 Clear retangle with specified text attribute.
23
24 @param LeftColumn Left column of retangle.
25 @param RightColumn Right column of retangle.
26 @param TopRow Start row of retangle.
27 @param BottomRow End row of retangle.
28 @param TextAttribute The character foreground and background.
29
30 **/
31 VOID
32 ClearLines (
33 IN UINTN LeftColumn,
34 IN UINTN RightColumn,
35 IN UINTN TopRow,
36 IN UINTN BottomRow,
37 IN UINTN TextAttribute
38 )
39 {
40 CHAR16 *Buffer;
41 UINTN Row;
42
43 //
44 // For now, allocate an arbitrarily long buffer
45 //
46 Buffer = AllocateZeroPool (0x10000);
47 ASSERT (Buffer != NULL);
48
49 //
50 // Set foreground and background as defined
51 //
52 gST->ConOut->SetAttribute (gST->ConOut, TextAttribute);
53
54 //
55 // Much faster to buffer the long string instead of print it a character at a time
56 //
57 SetUnicodeMem (Buffer, RightColumn - LeftColumn, L' ');
58
59 //
60 // Clear the desired area with the appropriate foreground/background
61 //
62 for (Row = TopRow; Row <= BottomRow; Row++) {
63 PrintStringAt (LeftColumn, Row, Buffer);
64 }
65
66 gST->ConOut->SetCursorPosition (gST->ConOut, LeftColumn, TopRow);
67
68 FreePool (Buffer);
69 return ;
70 }
71
72 /**
73 Concatenate a narrow string to another string.
74
75 @param Destination The destination string.
76 @param Source The source string. The string to be concatenated.
77 to the end of Destination.
78
79 **/
80 VOID
81 NewStrCat (
82 IN OUT CHAR16 *Destination,
83 IN CHAR16 *Source
84 )
85 {
86 UINTN Length;
87
88 for (Length = 0; Destination[Length] != 0; Length++)
89 ;
90
91 //
92 // We now have the length of the original string
93 // We can safely assume for now that we are concatenating a narrow value to this string.
94 // For instance, the string is "XYZ" and cat'ing ">"
95 // If this assumption changes, we need to make this routine a bit more complex
96 //
97 Destination[Length] = NARROW_CHAR;
98 Length++;
99
100 StrCpy (Destination + Length, Source);
101 }
102
103 /**
104 Count the storage space of a Unicode string.
105
106 This function handles the Unicode string with NARROW_CHAR
107 and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
108 does not count in the resultant output. If a WIDE_CHAR is
109 hit, then 2 Unicode character will consume an output storage
110 space with size of CHAR16 till a NARROW_CHAR is hit.
111
112 If String is NULL, then ASSERT ().
113
114 @param String The input string to be counted.
115
116 @return Storage space for the input string.
117
118 **/
119 UINTN
120 GetStringWidth (
121 IN CHAR16 *String
122 )
123 {
124 UINTN Index;
125 UINTN Count;
126 UINTN IncrementValue;
127
128 ASSERT (String != NULL);
129 if (String == NULL) {
130 return 0;
131 }
132
133 Index = 0;
134 Count = 0;
135 IncrementValue = 1;
136
137 do {
138 //
139 // Advance to the null-terminator or to the first width directive
140 //
141 for (;
142 (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);
143 Index++, Count = Count + IncrementValue
144 )
145 ;
146
147 //
148 // We hit the null-terminator, we now have a count
149 //
150 if (String[Index] == 0) {
151 break;
152 }
153 //
154 // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed
155 // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)
156 //
157 if (String[Index] == NARROW_CHAR) {
158 //
159 // Skip to the next character
160 //
161 Index++;
162 IncrementValue = 1;
163 } else {
164 //
165 // Skip to the next character
166 //
167 Index++;
168 IncrementValue = 2;
169 }
170 } while (String[Index] != 0);
171
172 //
173 // Increment by one to include the null-terminator in the size
174 //
175 Count++;
176
177 return Count * sizeof (CHAR16);
178 }
179
180 /**
181 This function displays the page frame.
182
183 **/
184 VOID
185 DisplayPageFrame (
186 VOID
187 )
188 {
189 UINTN Index;
190 UINT8 Line;
191 UINT8 Alignment;
192 CHAR16 Character;
193 CHAR16 *Buffer;
194 CHAR16 *StrFrontPageBanner;
195 UINTN Row;
196 EFI_SCREEN_DESCRIPTOR LocalScreen;
197 UINT8 RowIdx;
198 UINT8 ColumnIdx;
199
200 ZeroMem (&LocalScreen, sizeof (EFI_SCREEN_DESCRIPTOR));
201 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &LocalScreen.RightColumn, &LocalScreen.BottomRow);
202 ClearLines (0, LocalScreen.RightColumn, 0, LocalScreen.BottomRow, KEYHELP_BACKGROUND);
203
204 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
205
206 //
207 // For now, allocate an arbitrarily long buffer
208 //
209 Buffer = AllocateZeroPool (0x10000);
210 ASSERT (Buffer != NULL);
211
212 Character = BOXDRAW_HORIZONTAL;
213
214 for (Index = 0; Index + 2 < (LocalScreen.RightColumn - LocalScreen.LeftColumn); Index++) {
215 Buffer[Index] = Character;
216 }
217
218 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) {
219 //
220 // ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND);
221 //
222 ClearLines (
223 LocalScreen.LeftColumn,
224 LocalScreen.RightColumn,
225 LocalScreen.TopRow,
226 FRONT_PAGE_HEADER_HEIGHT - 1 + LocalScreen.TopRow,
227 BANNER_TEXT | BANNER_BACKGROUND
228 );
229 //
230 // for (Line = 0; Line < BANNER_HEIGHT; Line++) {
231 //
232 for (Line = (UINT8) LocalScreen.TopRow; Line < BANNER_HEIGHT + (UINT8) LocalScreen.TopRow; Line++) {
233 //
234 // for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) {
235 //
236 for (Alignment = (UINT8) LocalScreen.LeftColumn;
237 Alignment < BANNER_COLUMNS + (UINT8) LocalScreen.LeftColumn;
238 Alignment++
239 ) {
240 RowIdx = (UINT8) (Line - (UINT8) LocalScreen.TopRow);
241 ColumnIdx = (UINT8) (Alignment - (UINT8) LocalScreen.LeftColumn);
242
243 ASSERT (RowIdx < BANNER_HEIGHT);
244 ASSERT (ColumnIdx < BANNER_COLUMNS);
245
246 if (gBannerData->Banner[RowIdx][ColumnIdx] != 0x0000) {
247 StrFrontPageBanner = GetToken (
248 gBannerData->Banner[RowIdx][ColumnIdx],
249 gFrontPageHandle
250 );
251 } else {
252 continue;
253 }
254
255 switch (Alignment - LocalScreen.LeftColumn) {
256 case 0:
257 //
258 // Handle left column
259 //
260 PrintStringAt (LocalScreen.LeftColumn, Line, StrFrontPageBanner);
261 break;
262
263 case 1:
264 //
265 // Handle center column
266 //
267 PrintStringAt (
268 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,
269 Line,
270 StrFrontPageBanner
271 );
272 break;
273
274 case 2:
275 //
276 // Handle right column
277 //
278 PrintStringAt (
279 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3,
280 Line,
281 StrFrontPageBanner
282 );
283 break;
284 }
285
286 FreePool (StrFrontPageBanner);
287 }
288 }
289 }
290
291 ClearLines (
292 LocalScreen.LeftColumn,
293 LocalScreen.RightColumn,
294 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT,
295 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1,
296 KEYHELP_TEXT | KEYHELP_BACKGROUND
297 );
298
299 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) {
300 ClearLines (
301 LocalScreen.LeftColumn,
302 LocalScreen.RightColumn,
303 LocalScreen.TopRow,
304 LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1,
305 TITLE_TEXT | TITLE_BACKGROUND
306 );
307 //
308 // Print Top border line
309 // +------------------------------------------------------------------------------+
310 // ? ?
311 // +------------------------------------------------------------------------------+
312 //
313 Character = BOXDRAW_DOWN_RIGHT;
314
315 PrintChar (Character);
316 PrintString (Buffer);
317
318 Character = BOXDRAW_DOWN_LEFT;
319 PrintChar (Character);
320
321 Character = BOXDRAW_VERTICAL;
322 for (Row = LocalScreen.TopRow + 1; Row <= LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 2; Row++) {
323 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
324 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
325 }
326
327 Character = BOXDRAW_UP_RIGHT;
328 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1, Character);
329 PrintString (Buffer);
330
331 Character = BOXDRAW_UP_LEFT;
332 PrintChar (Character);
333
334 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
335 //
336 // Print Bottom border line
337 // +------------------------------------------------------------------------------+
338 // ? ?
339 // +------------------------------------------------------------------------------+
340 //
341 Character = BOXDRAW_DOWN_RIGHT;
342 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT, Character);
343
344 PrintString (Buffer);
345
346 Character = BOXDRAW_DOWN_LEFT;
347 PrintChar (Character);
348 Character = BOXDRAW_VERTICAL;
349 for (Row = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT + 1;
350 Row <= LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2;
351 Row++
352 ) {
353 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
354 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
355 }
356
357 Character = BOXDRAW_UP_RIGHT;
358 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1, Character);
359
360 PrintString (Buffer);
361
362 Character = BOXDRAW_UP_LEFT;
363 PrintChar (Character);
364 }
365 }
366
367 FreePool (Buffer);
368
369 }
370
371
372 /**
373 Evaluate all expressions in a Form.
374
375 @param FormSet FormSet this Form belongs to.
376 @param Form The Form.
377
378 @retval EFI_SUCCESS The expression evaluated successfuly
379
380 **/
381 EFI_STATUS
382 EvaluateFormExpressions (
383 IN FORM_BROWSER_FORMSET *FormSet,
384 IN FORM_BROWSER_FORM *Form
385 )
386 {
387 EFI_STATUS Status;
388 LIST_ENTRY *Link;
389 FORM_EXPRESSION *Expression;
390
391 Link = GetFirstNode (&Form->ExpressionListHead);
392 while (!IsNull (&Form->ExpressionListHead, Link)) {
393 Expression = FORM_EXPRESSION_FROM_LINK (Link);
394 Link = GetNextNode (&Form->ExpressionListHead, Link);
395
396 if (Expression->Type == EFI_HII_EXPRESSION_INCONSISTENT_IF ||
397 Expression->Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF ||
398 Expression->Type == EFI_HII_EXPRESSION_WRITE ||
399 (Expression->Type == EFI_HII_EXPRESSION_READ && Form->FormType != STANDARD_MAP_FORM_TYPE)) {
400 //
401 // Postpone Form validation to Question editing or Form submitting or Question Write or Question Read for nonstandard form.
402 //
403 continue;
404 }
405
406 Status = EvaluateExpression (FormSet, Form, Expression);
407 if (EFI_ERROR (Status)) {
408 return Status;
409 }
410 }
411
412 return EFI_SUCCESS;
413 }
414
415 /*
416 +------------------------------------------------------------------------------+
417 ? Setup Page ?
418 +------------------------------------------------------------------------------+
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436 +------------------------------------------------------------------------------+
437 ?F1=Scroll Help F9=Reset to Defaults F10=Save and Exit ?
438 | ^"=Move Highlight <Spacebar> Toggles Checkbox Esc=Discard Changes |
439 +------------------------------------------------------------------------------+
440 */
441
442 /**
443
444
445 Display form and wait for user to select one menu option, then return it.
446
447 @param Selection On input, Selection tell setup browser the information
448 about the Selection, form and formset to be displayed.
449 On output, Selection return the screen item that is selected
450 by user.
451 @retval EFI_SUCESSS This function always return successfully for now.
452
453 **/
454 EFI_STATUS
455 DisplayForm (
456 IN OUT UI_MENU_SELECTION *Selection
457 )
458 {
459 CHAR16 *StringPtr;
460 UINT16 MenuItemCount;
461 EFI_HII_HANDLE Handle;
462 BOOLEAN Suppress;
463 EFI_SCREEN_DESCRIPTOR LocalScreen;
464 UINT16 Width;
465 UINTN ArrayEntry;
466 CHAR16 *OutputString;
467 LIST_ENTRY *Link;
468 FORM_BROWSER_STATEMENT *Statement;
469 UINT16 NumberOfLines;
470 EFI_STATUS Status;
471 UI_MENU_OPTION *MenuOption;
472
473 Handle = Selection->Handle;
474 MenuItemCount = 0;
475 ArrayEntry = 0;
476 OutputString = NULL;
477
478 UiInitMenu ();
479
480 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
481
482 StringPtr = GetToken (Selection->Form->FormTitle, Handle);
483
484 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) {
485 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
486 PrintStringAt (
487 (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2,
488 LocalScreen.TopRow + 1,
489 StringPtr
490 );
491 }
492
493 //
494 // Remove Buffer allocated for StringPtr after it has been used.
495 //
496 FreePool (StringPtr);
497
498 //
499 // Evaluate all the Expressions in this Form
500 //
501 Status = EvaluateFormExpressions (Selection->FormSet, Selection->Form);
502 if (EFI_ERROR (Status)) {
503 return Status;
504 }
505
506 Selection->FormEditable = FALSE;
507 Link = GetFirstNode (&Selection->Form->StatementListHead);
508 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
509 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
510
511 if (Statement->SuppressExpression != NULL) {
512 Suppress = Statement->SuppressExpression->Result.Value.b;
513 } else {
514 Suppress = FALSE;
515 }
516
517 if (Statement->DisableExpression != NULL) {
518 Suppress = (BOOLEAN) (Suppress || Statement->DisableExpression->Result.Value.b);
519 }
520
521 if (!Suppress) {
522 StringPtr = GetToken (Statement->Prompt, Handle);
523
524 Width = GetWidth (Statement, Handle);
525
526 NumberOfLines = 1;
527 ArrayEntry = 0;
528 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
529 //
530 // If there is more string to process print on the next row and increment the Skip value
531 //
532 if (StrLen (&StringPtr[ArrayEntry]) != 0) {
533 NumberOfLines++;
534 }
535
536 FreePool (OutputString);
537 }
538
539 //
540 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
541 // it in UiFreeMenu.
542 //
543 MenuOption = UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount);
544 MenuItemCount++;
545
546 if (MenuOption->IsQuestion && !MenuOption->ReadOnly) {
547 //
548 // At least one item is not readonly, this Form is considered as editable
549 //
550 Selection->FormEditable = TRUE;
551 }
552 }
553
554 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
555 }
556
557 Status = UiDisplayMenu (Selection);
558
559 UiFreeMenu ();
560
561 return Status;
562 }
563
564 /**
565 Initialize the HII String Token to the correct values.
566
567 **/
568 VOID
569 InitializeBrowserStrings (
570 VOID
571 )
572 {
573 gFunctionNineString = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);
574 gFunctionTenString = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);
575 gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);
576 gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);
577 gEnterEscapeString = GetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), gHiiHandle);
578 gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);
579 gSaveFailed = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle);
580 gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);
581 gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);
582 gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle);
583 gHexNumericInput = GetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), gHiiHandle);
584 gToggleCheckBox = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);
585 gPromptForData = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);
586 gPromptForPassword = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);
587 gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);
588 gConfirmPassword = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);
589 gConfirmError = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);
590 gPassowordInvalid = GetToken (STRING_TOKEN (PASSWORD_INVALID), gHiiHandle);
591 gPressEnter = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);
592 gEmptyString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
593 gAreYouSure = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);
594 gYesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);
595 gNoResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);
596 gMiniString = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);
597 gPlusString = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);
598 gMinusString = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);
599 gAdjustNumber = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);
600 gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle);
601 gOptionMismatch = GetToken (STRING_TOKEN (OPTION_MISMATCH), gHiiHandle);
602 gFormSuppress = GetToken (STRING_TOKEN (FORM_SUPPRESSED), gHiiHandle);
603 return ;
604 }
605
606 /**
607 Free up the resource allocated for all strings required
608 by Setup Browser.
609
610 **/
611 VOID
612 FreeBrowserStrings (
613 VOID
614 )
615 {
616 FreePool (gFunctionNineString);
617 FreePool (gFunctionTenString);
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 /**
650 Update key's help imformation.
651
652 @param Selection Tell setup browser the information about the Selection
653 @param MenuOption The Menu option
654 @param Selected Whether or not a tag be selected
655
656 **/
657 VOID
658 UpdateKeyHelp (
659 IN UI_MENU_SELECTION *Selection,
660 IN UI_MENU_OPTION *MenuOption,
661 IN BOOLEAN Selected
662 )
663 {
664 UINTN SecCol;
665 UINTN ThdCol;
666 UINTN LeftColumnOfHelp;
667 UINTN RightColumnOfHelp;
668 UINTN TopRowOfHelp;
669 UINTN BottomRowOfHelp;
670 UINTN StartColumnOfHelp;
671 EFI_SCREEN_DESCRIPTOR LocalScreen;
672 FORM_BROWSER_STATEMENT *Statement;
673
674 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
675
676 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
677 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;
678
679 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
680 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
681 RightColumnOfHelp = LocalScreen.RightColumn - 2;
682 TopRowOfHelp = LocalScreen.BottomRow - 4;
683 BottomRowOfHelp = LocalScreen.BottomRow - 3;
684
685 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
686
687 Statement = MenuOption->ThisTag;
688 switch (Statement->Operand) {
689 case EFI_IFR_ORDERED_LIST_OP:
690 case EFI_IFR_ONE_OF_OP:
691 case EFI_IFR_NUMERIC_OP:
692 case EFI_IFR_TIME_OP:
693 case EFI_IFR_DATE_OP:
694 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
695
696 if (!Selected) {
697 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
698 if (Selection->FormEditable) {
699 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
700 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
701 }
702 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
703 }
704
705 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
706 (Statement->Operand == EFI_IFR_TIME_OP)) {
707 PrintAt (
708 StartColumnOfHelp,
709 BottomRowOfHelp,
710 L"%c%c%c%c%s",
711 ARROW_UP,
712 ARROW_DOWN,
713 ARROW_RIGHT,
714 ARROW_LEFT,
715 gMoveHighlight
716 );
717 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
718 } else {
719 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
720 if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) {
721 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
722 } else {
723 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
724 }
725 }
726 } else {
727 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
728
729 //
730 // If it is a selected numeric with manual input, display different message
731 //
732 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step == 0)) {
733 PrintStringAt (
734 SecCol,
735 TopRowOfHelp,
736 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
737 );
738 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
739 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
740 }
741
742 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
743 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
744 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
745 }
746
747 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
748 }
749 break;
750
751 case EFI_IFR_CHECKBOX_OP:
752 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
753
754 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
755 if (Selection->FormEditable) {
756 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
757 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
758 }
759 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
760 }
761
762 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
763 PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
764 break;
765
766 case EFI_IFR_REF_OP:
767 case EFI_IFR_PASSWORD_OP:
768 case EFI_IFR_STRING_OP:
769 case EFI_IFR_TEXT_OP:
770 case EFI_IFR_ACTION_OP:
771 case EFI_IFR_RESET_BUTTON_OP:
772 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
773
774 if (!Selected) {
775 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
776 if (Selection->FormEditable) {
777 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
778 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
779 }
780 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
781 }
782
783 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
784 if (Statement->Operand != EFI_IFR_TEXT_OP) {
785 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
786 }
787 } else {
788 if (Statement->Operand != EFI_IFR_REF_OP) {
789 PrintStringAt (
790 (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,
791 BottomRowOfHelp,
792 gEnterCommitString
793 );
794 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
795 }
796 }
797 break;
798
799 default:
800 break;
801 }
802 }
803
804 /**
805 Functions which are registered to receive notification of
806 database events have this prototype. The actual event is encoded
807 in NotifyType. The following table describes how PackageType,
808 PackageGuid, Handle, and Package are used for each of the
809 notification types.
810
811 @param PackageType Package type of the notification.
812
813 @param PackageGuid If PackageType is
814 EFI_HII_PACKAGE_TYPE_GUID, then this is
815 the pointer to the GUID from the Guid
816 field of EFI_HII_PACKAGE_GUID_HEADER.
817 Otherwise, it must be NULL.
818
819 @param Package Points to the package referred to by the
820 notification Handle The handle of the package
821 list which contains the specified package.
822
823 @param Handle The HII handle.
824
825 @param NotifyType The type of change concerning the
826 database. See
827 EFI_HII_DATABASE_NOTIFY_TYPE.
828
829 **/
830 EFI_STATUS
831 EFIAPI
832 FormUpdateNotify (
833 IN UINT8 PackageType,
834 IN CONST EFI_GUID *PackageGuid,
835 IN CONST EFI_HII_PACKAGE_HEADER *Package,
836 IN EFI_HII_HANDLE Handle,
837 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
838 )
839 {
840 mHiiPackageListUpdated = TRUE;
841
842 return EFI_SUCCESS;
843 }
844
845 BOOLEAN mFormCloseCallBack = FALSE;
846
847 /**
848 The worker function that send the displays to the screen. On output,
849 the selection made by user is returned.
850
851 @param Selection On input, Selection tell setup browser the information
852 about the Selection, form and formset to be displayed.
853 On output, Selection return the screen item that is selected
854 by user.
855
856 @retval EFI_SUCCESS The page is displayed successfully.
857 @return Other value if the page failed to be diplayed.
858
859 **/
860 EFI_STATUS
861 SetupBrowser (
862 IN OUT UI_MENU_SELECTION *Selection
863 )
864 {
865 EFI_STATUS Status;
866 LIST_ENTRY *Link;
867 EFI_BROWSER_ACTION_REQUEST ActionRequest;
868 EFI_HANDLE NotifyHandle;
869 EFI_HII_VALUE *HiiValue;
870 EFI_IFR_TYPE_VALUE *TypeValue;
871 FORM_BROWSER_STATEMENT *Statement;
872 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
873 FORM_BROWSER_FORMSET *FormSet;
874 EFI_INPUT_KEY Key;
875 BOOLEAN FormOpenCallBack;
876 BOOLEAN SubmitFormIsRequired;
877 EFI_GUID CurrentFormSetGuid;
878 EFI_HII_HANDLE CurrentHiiHandle;
879 UINT16 CurrentFormId;
880
881 gMenuRefreshHead = NULL;
882 gResetRequired = FALSE;
883 FormSet = Selection->FormSet;
884 ConfigAccess = Selection->FormSet->ConfigAccess;
885
886 //
887 // Register notify for Form package update
888 //
889 Status = mHiiDatabase->RegisterPackageNotify (
890 mHiiDatabase,
891 EFI_HII_PACKAGE_FORMS,
892 NULL,
893 FormUpdateNotify,
894 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
895 &NotifyHandle
896 );
897 if (EFI_ERROR (Status)) {
898 return Status;
899 }
900
901 //
902 // Initialize current settings of Questions in this FormSet
903 //
904 Status = InitializeCurrentSetting (Selection->FormSet);
905 if (EFI_ERROR (Status)) {
906 Selection->Action = UI_ACTION_EXIT;
907 goto Done;
908 }
909
910 do {
911 //
912 // Initialize Selection->Form
913 //
914 FormOpenCallBack = FALSE;
915 if (Selection->FormId == 0) {
916 //
917 // First Form will open.
918 //
919 FormOpenCallBack = TRUE;
920
921 //
922 // Zero FormId indicates display the first Form in a FormSet
923 //
924 Link = GetFirstNode (&Selection->FormSet->FormListHead);
925
926 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
927 Selection->FormId = Selection->Form->FormId;
928 } else {
929 if (Selection->Form == NULL) {
930 //
931 // First Form will open.
932 //
933 FormOpenCallBack = TRUE;
934 }
935 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
936 }
937
938 if (Selection->Form == NULL) {
939 //
940 // No Form to display
941 //
942 return EFI_NOT_FOUND;
943 }
944
945 //
946 // Check Form is suppressed.
947 //
948 if (Selection->Form->SuppressExpression != NULL) {
949 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Selection->Form->SuppressExpression);
950 if (EFI_ERROR (Status)) {
951 return Status;
952 }
953
954 if (Selection->Form->SuppressExpression->Result.Value.b) {
955 //
956 // Form is suppressed.
957 //
958 do {
959 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString);
960 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
961
962 return EFI_NOT_FOUND;
963 }
964 }
965
966 //
967 // Keep current form information
968 //
969 CurrentHiiHandle = Selection->Handle;
970 CopyGuid (&CurrentFormSetGuid, &Selection->FormSetGuid);
971 CurrentFormId = Selection->FormId;
972
973 //
974 // Reset FormPackage update flag
975 //
976 mHiiPackageListUpdated = FALSE;
977
978 //
979 // Before display new form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN
980 // for each question with callback flag.
981 // New form may be the first form, or the different form after another form close.
982 //
983 if ((FormOpenCallBack || mFormCloseCallBack) && (ConfigAccess != NULL)) {
984 mFormCloseCallBack = FALSE;
985 //
986 // Go through each statement in this form
987 //
988 SubmitFormIsRequired = FALSE;
989 Link = GetFirstNode (&Selection->Form->StatementListHead);
990 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
991 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
992 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
993
994 if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) {
995 continue;
996 }
997
998 //
999 // Check whether Statement is disabled.
1000 //
1001 if (Statement->DisableExpression != NULL) {
1002 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Statement->DisableExpression);
1003 if (!EFI_ERROR (Status) &&
1004 (Statement->DisableExpression->Result.Type == EFI_IFR_TYPE_BOOLEAN) &&
1005 (Statement->DisableExpression->Result.Value.b)) {
1006 continue;
1007 }
1008 }
1009
1010 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1011 Status = ConfigAccess->Callback (
1012 ConfigAccess,
1013 EFI_BROWSER_ACTION_FORM_OPEN,
1014 Statement->QuestionId,
1015 EFI_IFR_TYPE_UNDEFINED,
1016 NULL,
1017 &ActionRequest
1018 );
1019
1020 if (!EFI_ERROR (Status)) {
1021 switch (ActionRequest) {
1022 case EFI_BROWSER_ACTION_REQUEST_RESET:
1023 gResetRequired = TRUE;
1024 break;
1025
1026 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1027 SubmitFormIsRequired = TRUE;
1028 break;
1029
1030 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1031 Selection->Action = UI_ACTION_EXIT;
1032 gNvUpdateRequired = FALSE;
1033 break;
1034
1035 default:
1036 break;
1037 }
1038 }
1039 }
1040 if (SubmitFormIsRequired) {
1041 SubmitForm (Selection->FormSet, Selection->Form);
1042 }
1043 //
1044 // EXIT requests to close form.
1045 //
1046 if (Selection->Action == UI_ACTION_EXIT) {
1047 goto Done;
1048 }
1049 //
1050 // IFR is updated during callback of open form, force to reparse the IFR binary
1051 //
1052 if (mHiiPackageListUpdated) {
1053 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1054 mHiiPackageListUpdated = FALSE;
1055 goto Done;
1056 }
1057 }
1058
1059 //
1060 // Load Questions' Value for display
1061 //
1062 Status = LoadFormSetConfig (Selection, Selection->FormSet);
1063 if (EFI_ERROR (Status)) {
1064 return Status;
1065 }
1066
1067 //
1068 // EXIT requests to close form.
1069 //
1070 if (Selection->Action == UI_ACTION_EXIT) {
1071 goto Done;
1072 }
1073 //
1074 // IFR is updated during callback of read value, force to reparse the IFR binary
1075 //
1076 if (mHiiPackageListUpdated) {
1077 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1078 mHiiPackageListUpdated = FALSE;
1079 goto Done;
1080 }
1081
1082 //
1083 // Displays the Header and Footer borders
1084 //
1085 DisplayPageFrame ();
1086
1087 //
1088 // Display form
1089 //
1090 Status = DisplayForm (Selection);
1091 if (EFI_ERROR (Status)) {
1092 return Status;
1093 }
1094
1095 //
1096 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
1097 //
1098 Statement = Selection->Statement;
1099 if (Statement != NULL) {
1100 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
1101 gResetRequired = TRUE;
1102 }
1103
1104 //
1105 // Reset FormPackage update flag
1106 //
1107 mHiiPackageListUpdated = FALSE;
1108
1109 if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
1110 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1111
1112 if (ConfigAccess == NULL) {
1113 return EFI_UNSUPPORTED;
1114 }
1115
1116 HiiValue = &Statement->HiiValue;
1117 TypeValue = &HiiValue->Value;
1118 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
1119 //
1120 // Create String in HII database for Configuration Driver to retrieve
1121 //
1122 HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
1123 } else if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
1124 //
1125 // For OrderedList, passing in the value buffer to Callback()
1126 //
1127 TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue;
1128 }
1129
1130 Status = ConfigAccess->Callback (
1131 ConfigAccess,
1132 EFI_BROWSER_ACTION_CHANGING,
1133 Statement->QuestionId,
1134 HiiValue->Type,
1135 TypeValue,
1136 &ActionRequest
1137 );
1138
1139 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
1140 //
1141 // Clean the String in HII Database
1142 //
1143 DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
1144 }
1145
1146 if (!EFI_ERROR (Status)) {
1147 switch (ActionRequest) {
1148 case EFI_BROWSER_ACTION_REQUEST_RESET:
1149 gResetRequired = TRUE;
1150 break;
1151
1152 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1153 SubmitForm (Selection->FormSet, Selection->Form);
1154 break;
1155
1156 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1157 Selection->Action = UI_ACTION_EXIT;
1158 gNvUpdateRequired = FALSE;
1159 break;
1160
1161 default:
1162 break;
1163 }
1164 } else if (Status != EFI_UNSUPPORTED) {
1165 //
1166 // Callback return error status other than EFI_UNSUPPORTED
1167 //
1168 if (Statement->Operand == EFI_IFR_REF_OP) {
1169 //
1170 // Cross reference will not be taken
1171 //
1172 Selection->FormId = Selection->Form->FormId;
1173 Selection->QuestionId = 0;
1174 }
1175 }
1176 }
1177
1178 //
1179 // Check whether Form Package has been updated during Callback
1180 //
1181 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
1182 //
1183 // Force to reparse IFR binary of target Formset
1184 //
1185 mHiiPackageListUpdated = FALSE;
1186 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1187 }
1188 }
1189
1190 //
1191 // Before exit the form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE
1192 // for each question with callback flag.
1193 //
1194 mFormCloseCallBack = FALSE;
1195 if ((ConfigAccess != NULL) &&
1196 ((Selection->Action == UI_ACTION_EXIT) ||
1197 (Selection->Handle != CurrentHiiHandle) ||
1198 (!CompareGuid (&CurrentFormSetGuid, &Selection->FormSetGuid)) ||
1199 (Selection->FormId != CurrentFormId))) {
1200 //
1201 // Go through each statement in this form
1202 //
1203 mFormCloseCallBack = TRUE;
1204 SubmitFormIsRequired = FALSE;
1205 Link = GetFirstNode (&Selection->Form->StatementListHead);
1206 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
1207 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
1208 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
1209
1210 if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) {
1211 continue;
1212 }
1213
1214 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1215 Status = ConfigAccess->Callback (
1216 ConfigAccess,
1217 EFI_BROWSER_ACTION_FORM_CLOSE,
1218 Statement->QuestionId,
1219 EFI_IFR_TYPE_UNDEFINED,
1220 NULL,
1221 &ActionRequest
1222 );
1223
1224 if (!EFI_ERROR (Status)) {
1225 switch (ActionRequest) {
1226 case EFI_BROWSER_ACTION_REQUEST_RESET:
1227 gResetRequired = TRUE;
1228 break;
1229
1230 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1231 SubmitFormIsRequired = TRUE;
1232 break;
1233
1234 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1235 Selection->Action = UI_ACTION_EXIT;
1236 gNvUpdateRequired = FALSE;
1237 break;
1238
1239 default:
1240 break;
1241 }
1242 }
1243 }
1244 if (SubmitFormIsRequired) {
1245 SubmitForm (Selection->FormSet, Selection->Form);
1246 }
1247 }
1248 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1249
1250 //
1251 // Record the old formset
1252 //
1253 if (gOldFormSet != NULL) {
1254 DestroyFormSet (gOldFormSet);
1255 }
1256 gOldFormSet = FormSet;
1257
1258 Done:
1259 //
1260 // Unregister notify for Form package update
1261 //
1262 Status = mHiiDatabase->UnregisterPackageNotify (
1263 mHiiDatabase,
1264 NotifyHandle
1265 );
1266 return Status;
1267 }