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