]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
Add the missing check for NULL pointer before use it.
[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 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 /**
846 The worker function that send the displays to the screen. On output,
847 the selection made by user is returned.
848
849 @param Selection On input, Selection tell setup browser the information
850 about the Selection, form and formset to be displayed.
851 On output, Selection return the screen item that is selected
852 by user.
853
854 @retval EFI_SUCCESS The page is displayed successfully.
855 @return Other value if the page failed to be diplayed.
856
857 **/
858 EFI_STATUS
859 SetupBrowser (
860 IN OUT UI_MENU_SELECTION *Selection
861 )
862 {
863 EFI_STATUS Status;
864 LIST_ENTRY *Link;
865 EFI_BROWSER_ACTION_REQUEST ActionRequest;
866 EFI_HANDLE NotifyHandle;
867 EFI_HII_VALUE *HiiValue;
868 EFI_IFR_TYPE_VALUE *TypeValue;
869 FORM_BROWSER_STATEMENT *Statement;
870 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
871 FORM_BROWSER_FORMSET *FormSet;
872 EFI_INPUT_KEY Key;
873
874 gMenuRefreshHead = NULL;
875 gResetRequired = FALSE;
876 FormSet = Selection->FormSet;
877
878 //
879 // Register notify for Form package update
880 //
881 Status = mHiiDatabase->RegisterPackageNotify (
882 mHiiDatabase,
883 EFI_HII_PACKAGE_FORMS,
884 NULL,
885 FormUpdateNotify,
886 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
887 &NotifyHandle
888 );
889 if (EFI_ERROR (Status)) {
890 return Status;
891 }
892
893 //
894 // Before display the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN
895 //
896 ConfigAccess = Selection->FormSet->ConfigAccess;
897 if ((ConfigAccess != NULL) && (Selection->Action != UI_ACTION_REFRESH_FORMSET)) {
898 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
899 mHiiPackageListUpdated = FALSE;
900 Status = ConfigAccess->Callback (
901 ConfigAccess,
902 EFI_BROWSER_ACTION_FORM_OPEN,
903 0,
904 EFI_IFR_TYPE_UNDEFINED,
905 NULL,
906 &ActionRequest
907 );
908
909 if (!EFI_ERROR (Status)) {
910 switch (ActionRequest) {
911 case EFI_BROWSER_ACTION_REQUEST_RESET:
912 gResetRequired = TRUE;
913 break;
914
915 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
916 //
917 // Till now there is no uncommitted data, so ignore this request
918 //
919 break;
920
921 case EFI_BROWSER_ACTION_REQUEST_EXIT:
922 Selection->Action = UI_ACTION_EXIT;
923 break;
924
925 default:
926 break;
927 }
928 }
929
930 if (mHiiPackageListUpdated) {
931 //
932 // IFR is updated during callback, force to reparse the IFR binary
933 //
934 mHiiPackageListUpdated = FALSE;
935 Selection->Action = UI_ACTION_REFRESH_FORMSET;
936 goto Done;
937 }
938 }
939
940 //
941 // Initialize current settings of Questions in this FormSet
942 //
943 Status = InitializeCurrentSetting (Selection->FormSet);
944 if (EFI_ERROR (Status)) {
945 Selection->Action = UI_ACTION_EXIT;
946 goto Done;
947 }
948
949 do {
950 //
951 // Initialize Selection->Form
952 //
953 if (Selection->FormId == 0) {
954 //
955 // Zero FormId indicates display the first Form in a FormSet
956 //
957 Link = GetFirstNode (&Selection->FormSet->FormListHead);
958
959 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
960 Selection->FormId = Selection->Form->FormId;
961 } else {
962 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
963 }
964
965 if (Selection->Form == NULL) {
966 //
967 // No Form to display
968 //
969 return EFI_NOT_FOUND;
970 }
971
972 //
973 // Check Form is suppressed.
974 //
975 if (Selection->Form->SuppressExpression != NULL) {
976 Status = EvaluateExpression (Selection->FormSet, Selection->Form, Selection->Form->SuppressExpression);
977 if (EFI_ERROR (Status)) {
978 return Status;
979 }
980
981 if (Selection->Form->SuppressExpression->Result.Value.b) {
982 //
983 // Form is suppressed.
984 //
985 do {
986 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString);
987 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
988
989 return EFI_NOT_FOUND;
990 }
991 }
992
993 //
994 // Reset FormPackage update flag
995 //
996 mHiiPackageListUpdated = FALSE;
997
998 //
999 // Load Questions' Value for display
1000 //
1001 Status = LoadFormSetConfig (Selection, Selection->FormSet);
1002 if (EFI_ERROR (Status)) {
1003 return Status;
1004 }
1005
1006 //
1007 // IFR is updated during callback of read value, force to reparse the IFR binary
1008 //
1009 if (mHiiPackageListUpdated) {
1010 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1011 mHiiPackageListUpdated = FALSE;
1012 goto Done;
1013 }
1014
1015 //
1016 // Displays the Header and Footer borders
1017 //
1018 DisplayPageFrame ();
1019
1020 //
1021 // Display form
1022 //
1023 Status = DisplayForm (Selection);
1024 if (EFI_ERROR (Status)) {
1025 return Status;
1026 }
1027
1028 //
1029 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
1030 //
1031 Statement = Selection->Statement;
1032 if (Statement != NULL) {
1033 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
1034 gResetRequired = TRUE;
1035 }
1036
1037 //
1038 // Reset FormPackage update flag
1039 //
1040 mHiiPackageListUpdated = FALSE;
1041
1042 if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
1043 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1044
1045 if (ConfigAccess == NULL) {
1046 return EFI_UNSUPPORTED;
1047 }
1048
1049 HiiValue = &Statement->HiiValue;
1050 TypeValue = &HiiValue->Value;
1051 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
1052 //
1053 // Create String in HII database for Configuration Driver to retrieve
1054 //
1055 HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
1056 } else if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
1057 //
1058 // For OrderedList, passing in the value buffer to Callback()
1059 //
1060 TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue;
1061 }
1062
1063 Status = ConfigAccess->Callback (
1064 ConfigAccess,
1065 EFI_BROWSER_ACTION_CHANGING,
1066 Statement->QuestionId,
1067 HiiValue->Type,
1068 TypeValue,
1069 &ActionRequest
1070 );
1071
1072 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
1073 //
1074 // Clean the String in HII Database
1075 //
1076 DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
1077 }
1078
1079 if (!EFI_ERROR (Status)) {
1080 switch (ActionRequest) {
1081 case EFI_BROWSER_ACTION_REQUEST_RESET:
1082 gResetRequired = TRUE;
1083 break;
1084
1085 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1086 SubmitForm (Selection->FormSet, Selection->Form);
1087 break;
1088
1089 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1090 Selection->Action = UI_ACTION_EXIT;
1091 gNvUpdateRequired = FALSE;
1092 break;
1093
1094 default:
1095 break;
1096 }
1097 } else if (Status != EFI_UNSUPPORTED) {
1098 //
1099 // Callback return error status other than EFI_UNSUPPORTED
1100 //
1101 if (Statement->Operand == EFI_IFR_REF_OP) {
1102 //
1103 // Cross reference will not be taken
1104 //
1105 Selection->FormId = Selection->Form->FormId;
1106 Selection->QuestionId = 0;
1107 }
1108 }
1109 }
1110
1111 //
1112 // Check whether Form Package has been updated during Callback
1113 //
1114 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
1115 //
1116 // Force to reparse IFR binary of target Formset
1117 //
1118 mHiiPackageListUpdated = FALSE;
1119 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1120 }
1121 }
1122 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1123
1124 //
1125 // Before exit the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE
1126 //
1127 if ((ConfigAccess != NULL) && (Selection->Action == UI_ACTION_EXIT)) {
1128 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1129 Status = ConfigAccess->Callback (
1130 ConfigAccess,
1131 EFI_BROWSER_ACTION_FORM_CLOSE,
1132 0,
1133 EFI_IFR_TYPE_UNDEFINED,
1134 NULL,
1135 &ActionRequest
1136 );
1137
1138 if (!EFI_ERROR (Status)) {
1139 switch (ActionRequest) {
1140 case EFI_BROWSER_ACTION_REQUEST_RESET:
1141 gResetRequired = TRUE;
1142 break;
1143
1144 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1145 SubmitForm (Selection->FormSet, Selection->Form);
1146 break;
1147
1148 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1149 gNvUpdateRequired = FALSE;
1150 break;
1151
1152 default:
1153 break;
1154 }
1155 }
1156 }
1157
1158 //
1159 // Record the old formset
1160 //
1161 if (gOldFormSet != NULL) {
1162 DestroyFormSet (gOldFormSet);
1163 }
1164 gOldFormSet = FormSet;
1165
1166 Done:
1167 //
1168 // Unregister notify for Form package update
1169 //
1170 Status = mHiiDatabase->UnregisterPackageNotify (
1171 mHiiDatabase,
1172 NotifyHandle
1173 );
1174 return Status;
1175 }