]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
6d5a3db2e585b76a8fdc58d979c998b8aa211c00
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
1 /** @file
2 Utility functions for UI presentation.
3
4 Copyright (c) 2004 - 2010, 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 Expression->Type == EFI_HII_EXPRESSION_WRITE ||
392 (Expression->Type == EFI_HII_EXPRESSION_READ && Form->FormType != STANDARD_MAP_FORM_TYPE)) {
393 //
394 // Postpone Form validation to Question editing or Form submitting or Question Write or Question Read for nonstandard form.
395 //
396 continue;
397 }
398
399 Status = EvaluateExpression (FormSet, Form, Expression);
400 if (EFI_ERROR (Status)) {
401 return Status;
402 }
403 }
404
405 return EFI_SUCCESS;
406 }
407
408 /*
409 +------------------------------------------------------------------------------+
410 ? Setup Page ?
411 +------------------------------------------------------------------------------+
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429 +------------------------------------------------------------------------------+
430 ?F1=Scroll Help F9=Reset to Defaults F10=Save and Exit ?
431 | ^"=Move Highlight <Spacebar> Toggles Checkbox Esc=Discard Changes |
432 +------------------------------------------------------------------------------+
433 */
434
435 /**
436
437
438 Display form and wait for user to select one menu option, then return it.
439
440 @param Selection On input, Selection tell setup browser the information
441 about the Selection, form and formset to be displayed.
442 On output, Selection return the screen item that is selected
443 by user.
444 @retval EFI_SUCESSS This function always return successfully for now.
445
446 **/
447 EFI_STATUS
448 DisplayForm (
449 IN OUT UI_MENU_SELECTION *Selection
450 )
451 {
452 CHAR16 *StringPtr;
453 UINT16 MenuItemCount;
454 EFI_HII_HANDLE Handle;
455 BOOLEAN Suppress;
456 EFI_SCREEN_DESCRIPTOR LocalScreen;
457 UINT16 Width;
458 UINTN ArrayEntry;
459 CHAR16 *OutputString;
460 LIST_ENTRY *Link;
461 FORM_BROWSER_STATEMENT *Statement;
462 UINT16 NumberOfLines;
463 EFI_STATUS Status;
464 UI_MENU_OPTION *MenuOption;
465
466 Handle = Selection->Handle;
467 MenuItemCount = 0;
468 ArrayEntry = 0;
469 OutputString = NULL;
470
471 UiInitMenu ();
472
473 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
474
475 StringPtr = GetToken (Selection->Form->FormTitle, Handle);
476
477 if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) {
478 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
479 PrintStringAt (
480 (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2,
481 LocalScreen.TopRow + 1,
482 StringPtr
483 );
484 }
485
486 //
487 // Remove Buffer allocated for StringPtr after it has been used.
488 //
489 FreePool (StringPtr);
490
491 //
492 // Evaluate all the Expressions in this Form
493 //
494 Status = EvaluateFormExpressions (Selection->FormSet, Selection->Form);
495 if (EFI_ERROR (Status)) {
496 return Status;
497 }
498
499 Selection->FormEditable = FALSE;
500 Link = GetFirstNode (&Selection->Form->StatementListHead);
501 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
502 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
503
504 if (Statement->SuppressExpression != NULL) {
505 Suppress = Statement->SuppressExpression->Result.Value.b;
506 } else {
507 Suppress = FALSE;
508 }
509
510 if (Statement->DisableExpression != NULL) {
511 Suppress = (BOOLEAN) (Suppress || Statement->DisableExpression->Result.Value.b);
512 }
513
514 if (!Suppress) {
515 StringPtr = GetToken (Statement->Prompt, Handle);
516
517 Width = GetWidth (Statement, Handle);
518
519 NumberOfLines = 1;
520 ArrayEntry = 0;
521 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
522 //
523 // If there is more string to process print on the next row and increment the Skip value
524 //
525 if (StrLen (&StringPtr[ArrayEntry]) != 0) {
526 NumberOfLines++;
527 }
528
529 FreePool (OutputString);
530 }
531
532 //
533 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
534 // it in UiFreeMenu.
535 //
536 MenuOption = UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount);
537 MenuItemCount++;
538
539 if (MenuOption->IsQuestion && !MenuOption->ReadOnly) {
540 //
541 // At least one item is not readonly, this Form is considered as editable
542 //
543 Selection->FormEditable = TRUE;
544 }
545 }
546
547 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
548 }
549
550 Status = UiDisplayMenu (Selection);
551
552 UiFreeMenu ();
553
554 return Status;
555 }
556
557 /**
558 Initialize the HII String Token to the correct values.
559
560 **/
561 VOID
562 InitializeBrowserStrings (
563 VOID
564 )
565 {
566 gFunctionNineString = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);
567 gFunctionTenString = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);
568 gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);
569 gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);
570 gEnterEscapeString = GetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), gHiiHandle);
571 gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);
572 gSaveFailed = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle);
573 gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);
574 gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);
575 gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle);
576 gHexNumericInput = GetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), gHiiHandle);
577 gToggleCheckBox = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);
578 gPromptForData = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);
579 gPromptForPassword = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);
580 gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);
581 gConfirmPassword = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);
582 gConfirmError = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);
583 gPassowordInvalid = GetToken (STRING_TOKEN (PASSWORD_INVALID), gHiiHandle);
584 gPressEnter = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);
585 gEmptyString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
586 gAreYouSure = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);
587 gYesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);
588 gNoResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);
589 gMiniString = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);
590 gPlusString = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);
591 gMinusString = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);
592 gAdjustNumber = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);
593 gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle);
594 gOptionMismatch = GetToken (STRING_TOKEN (OPTION_MISMATCH), gHiiHandle);
595 gFormSuppress = GetToken (STRING_TOKEN (FORM_SUPPRESSED), gHiiHandle);
596 return ;
597 }
598
599 /**
600 Free up the resource allocated for all strings required
601 by Setup Browser.
602
603 **/
604 VOID
605 FreeBrowserStrings (
606 VOID
607 )
608 {
609 FreePool (gFunctionNineString);
610 FreePool (gFunctionTenString);
611 FreePool (gEnterString);
612 FreePool (gEnterCommitString);
613 FreePool (gEnterEscapeString);
614 FreePool (gEscapeString);
615 FreePool (gMoveHighlight);
616 FreePool (gMakeSelection);
617 FreePool (gDecNumericInput);
618 FreePool (gHexNumericInput);
619 FreePool (gToggleCheckBox);
620 FreePool (gPromptForData);
621 FreePool (gPromptForPassword);
622 FreePool (gPromptForNewPassword);
623 FreePool (gConfirmPassword);
624 FreePool (gPassowordInvalid);
625 FreePool (gConfirmError);
626 FreePool (gPressEnter);
627 FreePool (gEmptyString);
628 FreePool (gAreYouSure);
629 FreePool (gYesResponse);
630 FreePool (gNoResponse);
631 FreePool (gMiniString);
632 FreePool (gPlusString);
633 FreePool (gMinusString);
634 FreePool (gAdjustNumber);
635 FreePool (gSaveChanges);
636 FreePool (gOptionMismatch);
637 FreePool (gFormSuppress);
638 return ;
639 }
640
641
642 /**
643 Update key's help imformation.
644
645 @param Selection Tell setup browser the information about the Selection
646 @param MenuOption The Menu option
647 @param Selected Whether or not a tag be selected
648
649 **/
650 VOID
651 UpdateKeyHelp (
652 IN UI_MENU_SELECTION *Selection,
653 IN UI_MENU_OPTION *MenuOption,
654 IN BOOLEAN Selected
655 )
656 {
657 UINTN SecCol;
658 UINTN ThdCol;
659 UINTN LeftColumnOfHelp;
660 UINTN RightColumnOfHelp;
661 UINTN TopRowOfHelp;
662 UINTN BottomRowOfHelp;
663 UINTN StartColumnOfHelp;
664 EFI_SCREEN_DESCRIPTOR LocalScreen;
665 FORM_BROWSER_STATEMENT *Statement;
666
667 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
668
669 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
670 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;
671
672 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
673 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
674 RightColumnOfHelp = LocalScreen.RightColumn - 2;
675 TopRowOfHelp = LocalScreen.BottomRow - 4;
676 BottomRowOfHelp = LocalScreen.BottomRow - 3;
677
678 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
679
680 Statement = MenuOption->ThisTag;
681 switch (Statement->Operand) {
682 case EFI_IFR_ORDERED_LIST_OP:
683 case EFI_IFR_ONE_OF_OP:
684 case EFI_IFR_NUMERIC_OP:
685 case EFI_IFR_TIME_OP:
686 case EFI_IFR_DATE_OP:
687 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
688
689 if (!Selected) {
690 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
691 if (Selection->FormEditable) {
692 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
693 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
694 }
695 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
696 }
697
698 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
699 (Statement->Operand == EFI_IFR_TIME_OP)) {
700 PrintAt (
701 StartColumnOfHelp,
702 BottomRowOfHelp,
703 L"%c%c%c%c%s",
704 ARROW_UP,
705 ARROW_DOWN,
706 ARROW_RIGHT,
707 ARROW_LEFT,
708 gMoveHighlight
709 );
710 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
711 } else {
712 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
713 if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) {
714 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
715 } else {
716 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
717 }
718 }
719 } else {
720 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
721
722 //
723 // If it is a selected numeric with manual input, display different message
724 //
725 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step == 0)) {
726 PrintStringAt (
727 SecCol,
728 TopRowOfHelp,
729 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
730 );
731 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
732 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
733 }
734
735 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
736 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
737 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
738 }
739
740 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
741 }
742 break;
743
744 case EFI_IFR_CHECKBOX_OP:
745 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
746
747 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
748 if (Selection->FormEditable) {
749 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
750 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
751 }
752 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
753 }
754
755 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
756 PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
757 break;
758
759 case EFI_IFR_REF_OP:
760 case EFI_IFR_PASSWORD_OP:
761 case EFI_IFR_STRING_OP:
762 case EFI_IFR_TEXT_OP:
763 case EFI_IFR_ACTION_OP:
764 case EFI_IFR_RESET_BUTTON_OP:
765 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
766
767 if (!Selected) {
768 if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) {
769 if (Selection->FormEditable) {
770 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
771 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
772 }
773 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
774 }
775
776 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
777 if (Statement->Operand != EFI_IFR_TEXT_OP) {
778 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
779 }
780 } else {
781 if (Statement->Operand != EFI_IFR_REF_OP) {
782 PrintStringAt (
783 (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,
784 BottomRowOfHelp,
785 gEnterCommitString
786 );
787 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
788 }
789 }
790 break;
791
792 default:
793 break;
794 }
795 }
796
797 /**
798 Functions which are registered to receive notification of
799 database events have this prototype. The actual event is encoded
800 in NotifyType. The following table describes how PackageType,
801 PackageGuid, Handle, and Package are used for each of the
802 notification types.
803
804 @param PackageType Package type of the notification.
805
806 @param PackageGuid If PackageType is
807 EFI_HII_PACKAGE_TYPE_GUID, then this is
808 the pointer to the GUID from the Guid
809 field of EFI_HII_PACKAGE_GUID_HEADER.
810 Otherwise, it must be NULL.
811
812 @param Package Points to the package referred to by the
813 notification Handle The handle of the package
814 list which contains the specified package.
815
816 @param Handle The HII handle.
817
818 @param NotifyType The type of change concerning the
819 database. See
820 EFI_HII_DATABASE_NOTIFY_TYPE.
821
822 **/
823 EFI_STATUS
824 EFIAPI
825 FormUpdateNotify (
826 IN UINT8 PackageType,
827 IN CONST EFI_GUID *PackageGuid,
828 IN CONST EFI_HII_PACKAGE_HEADER *Package,
829 IN EFI_HII_HANDLE Handle,
830 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
831 )
832 {
833 mHiiPackageListUpdated = TRUE;
834
835 return EFI_SUCCESS;
836 }
837
838 /**
839 The worker function that send the displays to the screen. On output,
840 the selection made by user is returned.
841
842 @param Selection On input, Selection tell setup browser the information
843 about the Selection, form and formset to be displayed.
844 On output, Selection return the screen item that is selected
845 by user.
846
847 @retval EFI_SUCCESS The page is displayed successfully.
848 @return Other value if the page failed to be diplayed.
849
850 **/
851 EFI_STATUS
852 SetupBrowser (
853 IN OUT UI_MENU_SELECTION *Selection
854 )
855 {
856 EFI_STATUS Status;
857 LIST_ENTRY *Link;
858 EFI_BROWSER_ACTION_REQUEST ActionRequest;
859 EFI_HANDLE NotifyHandle;
860 EFI_HII_VALUE *HiiValue;
861 EFI_IFR_TYPE_VALUE *TypeValue;
862 FORM_BROWSER_STATEMENT *Statement;
863 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
864 FORM_BROWSER_FORMSET *FormSet;
865 EFI_INPUT_KEY Key;
866
867 gMenuRefreshHead = NULL;
868 gResetRequired = FALSE;
869 FormSet = Selection->FormSet;
870
871 //
872 // Register notify for Form package update
873 //
874 Status = mHiiDatabase->RegisterPackageNotify (
875 mHiiDatabase,
876 EFI_HII_PACKAGE_FORMS,
877 NULL,
878 FormUpdateNotify,
879 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
880 &NotifyHandle
881 );
882 if (EFI_ERROR (Status)) {
883 return Status;
884 }
885
886 //
887 // Before display the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN
888 //
889 ConfigAccess = Selection->FormSet->ConfigAccess;
890 if ((ConfigAccess != NULL) && (Selection->Action != UI_ACTION_REFRESH_FORMSET)) {
891 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
892 mHiiPackageListUpdated = FALSE;
893 Status = ConfigAccess->Callback (
894 ConfigAccess,
895 EFI_BROWSER_ACTION_FORM_OPEN,
896 0,
897 EFI_IFR_TYPE_UNDEFINED,
898 NULL,
899 &ActionRequest
900 );
901
902 if (!EFI_ERROR (Status)) {
903 switch (ActionRequest) {
904 case EFI_BROWSER_ACTION_REQUEST_RESET:
905 gResetRequired = TRUE;
906 break;
907
908 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
909 //
910 // Till now there is no uncommitted data, so ignore this request
911 //
912 break;
913
914 case EFI_BROWSER_ACTION_REQUEST_EXIT:
915 Selection->Action = UI_ACTION_EXIT;
916 break;
917
918 default:
919 break;
920 }
921 }
922
923 if (mHiiPackageListUpdated) {
924 //
925 // IFR is updated during callback, force to reparse the IFR binary
926 //
927 mHiiPackageListUpdated = FALSE;
928 Selection->Action = UI_ACTION_REFRESH_FORMSET;
929 goto Done;
930 }
931 }
932
933 //
934 // Initialize current settings of Questions in this FormSet
935 //
936 Status = InitializeCurrentSetting (Selection->FormSet);
937 if (EFI_ERROR (Status)) {
938 Selection->Action = UI_ACTION_EXIT;
939 goto Done;
940 }
941
942 do {
943 //
944 // Initialize Selection->Form
945 //
946 if (Selection->FormId == 0) {
947 //
948 // Zero FormId indicates display the first Form in a FormSet
949 //
950 Link = GetFirstNode (&Selection->FormSet->FormListHead);
951
952 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
953 Selection->FormId = Selection->Form->FormId;
954 } else {
955 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
956 }
957
958 if (Selection->Form == NULL) {
959 //
960 // No Form to display
961 //
962 return EFI_NOT_FOUND;
963 }
964
965 //
966 // Check Form is suppressed.
967 //
968 if (Selection->Form->SuppressExpression != NULL) {
969 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Selection->Form->SuppressExpression);
970 if (EFI_ERROR (Status)) {
971 return Status;
972 }
973
974 if (Selection->Form->SuppressExpression->Result.Value.b) {
975 //
976 // Form is suppressed.
977 //
978 do {
979 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString);
980 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
981
982 return EFI_NOT_FOUND;
983 }
984 }
985
986 //
987 // Reset FormPackage update flag
988 //
989 mHiiPackageListUpdated = FALSE;
990
991 //
992 // Load Questions' Value for display
993 //
994 Status = LoadFormSetConfig (Selection, Selection->FormSet);
995 if (EFI_ERROR (Status)) {
996 return Status;
997 }
998
999 //
1000 // IFR is updated during callback of read value, force to reparse the IFR binary
1001 //
1002 if (mHiiPackageListUpdated) {
1003 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1004 mHiiPackageListUpdated = FALSE;
1005 goto Done;
1006 }
1007
1008 //
1009 // Displays the Header and Footer borders
1010 //
1011 DisplayPageFrame ();
1012
1013 //
1014 // Display form
1015 //
1016 Status = DisplayForm (Selection);
1017 if (EFI_ERROR (Status)) {
1018 return Status;
1019 }
1020
1021 //
1022 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
1023 //
1024 Statement = Selection->Statement;
1025 if (Statement != NULL) {
1026 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
1027 gResetRequired = TRUE;
1028 }
1029
1030 //
1031 // Reset FormPackage update flag
1032 //
1033 mHiiPackageListUpdated = FALSE;
1034
1035 if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
1036 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1037
1038 if (ConfigAccess == NULL) {
1039 return EFI_UNSUPPORTED;
1040 }
1041
1042 HiiValue = &Statement->HiiValue;
1043 TypeValue = &HiiValue->Value;
1044 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
1045 //
1046 // Create String in HII database for Configuration Driver to retrieve
1047 //
1048 HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
1049 } else if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
1050 //
1051 // For OrderedList, passing in the value buffer to Callback()
1052 //
1053 TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue;
1054 }
1055
1056 Status = ConfigAccess->Callback (
1057 ConfigAccess,
1058 EFI_BROWSER_ACTION_CHANGING,
1059 Statement->QuestionId,
1060 HiiValue->Type,
1061 TypeValue,
1062 &ActionRequest
1063 );
1064
1065 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
1066 //
1067 // Clean the String in HII Database
1068 //
1069 DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
1070 }
1071
1072 if (!EFI_ERROR (Status)) {
1073 switch (ActionRequest) {
1074 case EFI_BROWSER_ACTION_REQUEST_RESET:
1075 gResetRequired = TRUE;
1076 break;
1077
1078 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1079 SubmitForm (Selection->FormSet, Selection->Form);
1080 break;
1081
1082 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1083 Selection->Action = UI_ACTION_EXIT;
1084 gNvUpdateRequired = FALSE;
1085 break;
1086
1087 default:
1088 break;
1089 }
1090 } else if (Status != EFI_UNSUPPORTED) {
1091 //
1092 // Callback return error status other than EFI_UNSUPPORTED
1093 //
1094 if (Statement->Operand == EFI_IFR_REF_OP) {
1095 //
1096 // Cross reference will not be taken
1097 //
1098 Selection->FormId = Selection->Form->FormId;
1099 Selection->QuestionId = 0;
1100 }
1101 }
1102 }
1103
1104 //
1105 // Check whether Form Package has been updated during Callback
1106 //
1107 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
1108 //
1109 // Force to reparse IFR binary of target Formset
1110 //
1111 mHiiPackageListUpdated = FALSE;
1112 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1113 }
1114 }
1115 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1116
1117 //
1118 // Before exit the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE
1119 //
1120 if ((ConfigAccess != NULL) && (Selection->Action == UI_ACTION_EXIT)) {
1121 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1122 Status = ConfigAccess->Callback (
1123 ConfigAccess,
1124 EFI_BROWSER_ACTION_FORM_CLOSE,
1125 0,
1126 EFI_IFR_TYPE_UNDEFINED,
1127 NULL,
1128 &ActionRequest
1129 );
1130
1131 if (!EFI_ERROR (Status)) {
1132 switch (ActionRequest) {
1133 case EFI_BROWSER_ACTION_REQUEST_RESET:
1134 gResetRequired = TRUE;
1135 break;
1136
1137 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1138 SubmitForm (Selection->FormSet, Selection->Form);
1139 break;
1140
1141 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1142 gNvUpdateRequired = FALSE;
1143 break;
1144
1145 default:
1146 break;
1147 }
1148 }
1149 }
1150
1151 //
1152 // Record the old formset
1153 //
1154 if (gOldFormSet != NULL) {
1155 DestroyFormSet (gOldFormSet);
1156 }
1157 gOldFormSet = FormSet;
1158
1159 Done:
1160 //
1161 // Unregister notify for Form package update
1162 //
1163 Status = mHiiDatabase->UnregisterPackageNotify (
1164 mHiiDatabase,
1165 NotifyHandle
1166 );
1167 return Status;
1168 }