]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
enhanced security check.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
1 /** @file
2 Utility functions for UI presentation.
3
4 Copyright (c) 2004 - 2008, 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 #include "Ui.h"
17
18 BOOLEAN mHiiPackageListUpdated;
19 UI_MENU_SELECTION *gCurrentSelection;
20
21
22 /**
23 Clear retangle with specified text attribute.
24
25 @param LeftColumn Left column of retangle.
26 @param RightColumn Right column of retangle.
27 @param TopRow Start row of retangle.
28 @param BottomRow End row of retangle.
29 @param TextAttribute The character foreground and background.
30
31 **/
32 VOID
33 ClearLines (
34 UINTN LeftColumn,
35 UINTN RightColumn,
36 UINTN TopRow,
37 UINTN BottomRow,
38 UINTN TextAttribute
39 )
40 {
41 CHAR16 *Buffer;
42 UINTN Row;
43
44 //
45 // For now, allocate an arbitrarily long buffer
46 //
47 Buffer = AllocateZeroPool (0x10000);
48 ASSERT (Buffer != NULL);
49
50 //
51 // Set foreground and background as defined
52 //
53 gST->ConOut->SetAttribute (gST->ConOut, TextAttribute);
54
55 //
56 // Much faster to buffer the long string instead of print it a character at a time
57 //
58 SetUnicodeMem (Buffer, RightColumn - LeftColumn, L' ');
59
60 //
61 // Clear the desired area with the appropriate foreground/background
62 //
63 for (Row = TopRow; Row <= BottomRow; Row++) {
64 PrintStringAt (LeftColumn, Row, Buffer);
65 }
66
67 gST->ConOut->SetCursorPosition (gST->ConOut, LeftColumn, TopRow);
68
69 FreePool (Buffer);
70 return ;
71 }
72
73 /**
74 Concatenate a narrow string to another string.
75
76 @param Destination The destination string.
77 @param Source The source string. The string to be concatenated.
78 to the end of Destination.
79
80 **/
81 VOID
82 NewStrCat (
83 CHAR16 *Destination,
84 CHAR16 *Source
85 )
86 {
87 UINTN Length;
88
89 for (Length = 0; Destination[Length] != 0; Length++)
90 ;
91
92 //
93 // We now have the length of the original string
94 // We can safely assume for now that we are concatenating a narrow value to this string.
95 // For instance, the string is "XYZ" and cat'ing ">"
96 // If this assumption changes, we need to make this routine a bit more complex
97 //
98 Destination[Length] = NARROW_CHAR;
99 Length++;
100
101 StrCpy (Destination + Length, Source);
102 }
103
104 /**
105 Count the storage space of a Unicode string.
106
107 This function handles the Unicode string with NARROW_CHAR
108 and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
109 does not count in the resultant output. If a WIDE_CHAR is
110 hit, then 2 Unicode character will consume an output storage
111 space with size of CHAR16 till a NARROW_CHAR is hit.
112
113 @param String The input string to be counted.
114
115 @return Storage space for the input string.
116
117 **/
118 UINTN
119 GetStringWidth (
120 CHAR16 *String
121 )
122 {
123 UINTN Index;
124 UINTN Count;
125 UINTN IncrementValue;
126
127 Index = 0;
128 Count = 0;
129 IncrementValue = 1;
130
131 do {
132 //
133 // Advance to the null-terminator or to the first width directive
134 //
135 for (;
136 (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);
137 Index++, Count = Count + IncrementValue
138 )
139 ;
140
141 //
142 // We hit the null-terminator, we now have a count
143 //
144 if (String[Index] == 0) {
145 break;
146 }
147 //
148 // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed
149 // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)
150 //
151 if (String[Index] == NARROW_CHAR) {
152 //
153 // Skip to the next character
154 //
155 Index++;
156 IncrementValue = 1;
157 } else {
158 //
159 // Skip to the next character
160 //
161 Index++;
162 IncrementValue = 2;
163 }
164 } while (String[Index] != 0);
165
166 //
167 // Increment by one to include the null-terminator in the size
168 //
169 Count++;
170
171 return Count * sizeof (CHAR16);
172 }
173
174 /**
175 This function displays the page frame.
176
177 **/
178 VOID
179 DisplayPageFrame (
180 VOID
181 )
182 {
183 UINTN Index;
184 UINT8 Line;
185 UINT8 Alignment;
186 CHAR16 Character;
187 CHAR16 *Buffer;
188 CHAR16 *StrFrontPageBanner;
189 UINTN Row;
190 EFI_SCREEN_DESCRIPTOR LocalScreen;
191 UINT8 RowIdx;
192 UINT8 ColumnIdx;
193
194 ZeroMem (&LocalScreen, sizeof (EFI_SCREEN_DESCRIPTOR));
195 gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &LocalScreen.RightColumn, &LocalScreen.BottomRow);
196 ClearLines (0, LocalScreen.RightColumn, 0, LocalScreen.BottomRow, KEYHELP_BACKGROUND);
197
198 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
199
200 //
201 // For now, allocate an arbitrarily long buffer
202 //
203 Buffer = AllocateZeroPool (0x10000);
204 ASSERT (Buffer != NULL);
205
206 Character = BOXDRAW_HORIZONTAL;
207
208 for (Index = 0; Index + 2 < (LocalScreen.RightColumn - LocalScreen.LeftColumn); Index++) {
209 Buffer[Index] = Character;
210 }
211
212 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {
213 //
214 // ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND);
215 //
216 ClearLines (
217 LocalScreen.LeftColumn,
218 LocalScreen.RightColumn,
219 LocalScreen.TopRow,
220 FRONT_PAGE_HEADER_HEIGHT - 1 + LocalScreen.TopRow,
221 BANNER_TEXT | BANNER_BACKGROUND
222 );
223 //
224 // for (Line = 0; Line < BANNER_HEIGHT; Line++) {
225 //
226 for (Line = (UINT8) LocalScreen.TopRow; Line < BANNER_HEIGHT + (UINT8) LocalScreen.TopRow; Line++) {
227 //
228 // for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) {
229 //
230 for (Alignment = (UINT8) LocalScreen.LeftColumn;
231 Alignment < BANNER_COLUMNS + (UINT8) LocalScreen.LeftColumn;
232 Alignment++
233 ) {
234 RowIdx = Line - (UINT8) LocalScreen.TopRow;
235 ColumnIdx = Alignment - (UINT8) LocalScreen.LeftColumn;
236
237 ASSERT (RowIdx < BANNER_HEIGHT);
238 ASSERT (ColumnIdx < BANNER_COLUMNS);
239
240 if (BannerData->Banner[RowIdx][ColumnIdx] != 0x0000) {
241 StrFrontPageBanner = GetToken (
242 BannerData->Banner[RowIdx][ColumnIdx],
243 FrontPageHandle
244 );
245 } else {
246 continue;
247 }
248
249 switch (Alignment - LocalScreen.LeftColumn) {
250 case 0:
251 //
252 // Handle left column
253 //
254 PrintStringAt (LocalScreen.LeftColumn, Line, StrFrontPageBanner);
255 break;
256
257 case 1:
258 //
259 // Handle center column
260 //
261 PrintStringAt (
262 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3,
263 Line,
264 StrFrontPageBanner
265 );
266 break;
267
268 case 2:
269 //
270 // Handle right column
271 //
272 PrintStringAt (
273 LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3,
274 Line,
275 StrFrontPageBanner
276 );
277 break;
278 }
279
280 FreePool (StrFrontPageBanner);
281 }
282 }
283 }
284
285 ClearLines (
286 LocalScreen.LeftColumn,
287 LocalScreen.RightColumn,
288 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT,
289 LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1,
290 KEYHELP_TEXT | KEYHELP_BACKGROUND
291 );
292
293 if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {
294 ClearLines (
295 LocalScreen.LeftColumn,
296 LocalScreen.RightColumn,
297 LocalScreen.TopRow,
298 LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1,
299 TITLE_TEXT | TITLE_BACKGROUND
300 );
301 //
302 // Print Top border line
303 // +------------------------------------------------------------------------------+
304 // ? ?
305 // +------------------------------------------------------------------------------+
306 //
307 Character = BOXDRAW_DOWN_RIGHT;
308
309 PrintChar (Character);
310 PrintString (Buffer);
311
312 Character = BOXDRAW_DOWN_LEFT;
313 PrintChar (Character);
314
315 Character = BOXDRAW_VERTICAL;
316 for (Row = LocalScreen.TopRow + 1; Row <= LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 2; Row++) {
317 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
318 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
319 }
320
321 Character = BOXDRAW_UP_RIGHT;
322 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1, Character);
323 PrintString (Buffer);
324
325 Character = BOXDRAW_UP_LEFT;
326 PrintChar (Character);
327
328 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
329 //
330 // Print Bottom border line
331 // +------------------------------------------------------------------------------+
332 // ? ?
333 // +------------------------------------------------------------------------------+
334 //
335 Character = BOXDRAW_DOWN_RIGHT;
336 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT, Character);
337
338 PrintString (Buffer);
339
340 Character = BOXDRAW_DOWN_LEFT;
341 PrintChar (Character);
342 Character = BOXDRAW_VERTICAL;
343 for (Row = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT + 1;
344 Row <= LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2;
345 Row++
346 ) {
347 PrintCharAt (LocalScreen.LeftColumn, Row, Character);
348 PrintCharAt (LocalScreen.RightColumn - 1, Row, Character);
349 }
350
351 Character = BOXDRAW_UP_RIGHT;
352 PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1, Character);
353
354 PrintString (Buffer);
355
356 Character = BOXDRAW_UP_LEFT;
357 PrintChar (Character);
358 }
359 }
360
361 FreePool (Buffer);
362
363 }
364
365
366 /**
367 Evaluate all expressions in a Form.
368
369 @param FormSet FormSet this Form belongs to.
370 @param Form The Form.
371
372 @retval EFI_SUCCESS The expression evaluated successfuly
373
374 **/
375 EFI_STATUS
376 EvaluateFormExpressions (
377 IN FORM_BROWSER_FORMSET *FormSet,
378 IN FORM_BROWSER_FORM *Form
379 )
380 {
381 EFI_STATUS Status;
382 LIST_ENTRY *Link;
383 FORM_EXPRESSION *Expression;
384
385 Link = GetFirstNode (&Form->ExpressionListHead);
386 while (!IsNull (&Form->ExpressionListHead, Link)) {
387 Expression = FORM_EXPRESSION_FROM_LINK (Link);
388 Link = GetNextNode (&Form->ExpressionListHead, Link);
389
390 if (Expression->Type == EFI_HII_EXPRESSION_INCONSISTENT_IF ||
391 Expression->Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) {
392 //
393 // Postpone Form validation to Question editing or Form submiting
394 //
395 continue;
396 }
397
398 Status = EvaluateExpression (FormSet, Form, Expression);
399 if (EFI_ERROR (Status)) {
400 return Status;
401 }
402 }
403
404 return EFI_SUCCESS;
405 }
406
407 /*
408 +------------------------------------------------------------------------------+
409 ?F2=Previous Page Setup Page ?
410 +------------------------------------------------------------------------------+
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428 +------------------------------------------------------------------------------+
429 ?F1=Scroll Help F9=Reset to Defaults F10=Save and Exit ?
430 | ^"=Move Highlight <Spacebar> Toggles Checkbox Esc=Discard Changes |
431 +------------------------------------------------------------------------------+
432 */
433
434 /**
435
436
437 Display form and wait for user to select one menu option, then return it.
438
439 @param Selection On input, Selection tell setup browser the information
440 about the Selection, form and formset to be displayed.
441 On output, Selection return the screen item that is selected
442 by user.
443 @retval EFI_SUCESSS This function always return successfully for now.
444
445 **/
446 EFI_STATUS
447 DisplayForm (
448 IN OUT UI_MENU_SELECTION *Selection
449 )
450 {
451 CHAR16 *StringPtr;
452 UINT16 MenuItemCount;
453 EFI_HII_HANDLE Handle;
454 BOOLEAN Suppress;
455 EFI_SCREEN_DESCRIPTOR LocalScreen;
456 UINT16 Width;
457 UINTN ArrayEntry;
458 CHAR16 *OutputString;
459 LIST_ENTRY *Link;
460 FORM_BROWSER_STATEMENT *Statement;
461 UINT16 NumberOfLines;
462 EFI_STATUS Status;
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 != EFI_FRONT_PAGE_SUBCLASS) {
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 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
485 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
486
487 //
488 // Display the infrastructure strings
489 //
490 if (!IsListEmpty (&gMenuList)) {
491 PrintStringAt (LocalScreen.LeftColumn + 2, LocalScreen.TopRow + 1, gFunctionTwoString);
492 }
493 }
494 //
495 // Remove Buffer allocated for StringPtr after it has been used.
496 //
497 FreePool (StringPtr);
498
499 //
500 // Evaluate all the Expressions in this Form
501 //
502 Status = EvaluateFormExpressions (Selection->FormSet, Selection->Form);
503 if (EFI_ERROR (Status)) {
504 return Status;
505 }
506
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 (!Suppress) {
518 StringPtr = GetToken (Statement->Prompt, Handle);
519
520 Width = GetWidth (Statement, Handle);
521
522 NumberOfLines = 1;
523 ArrayEntry = 0;
524 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
525 //
526 // If there is more string to process print on the next row and increment the Skip value
527 //
528 if (StrLen (&StringPtr[ArrayEntry]) != 0) {
529 NumberOfLines++;
530 }
531
532 FreePool (OutputString);
533 }
534
535 //
536 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
537 // it in UiFreeMenu.
538 //
539 UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount);
540 MenuItemCount++;
541 }
542
543 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
544 }
545
546 Status = UiDisplayMenu (Selection);
547
548 UiFreeMenu ();
549
550 return Status;
551 }
552
553 /**
554 Initialize the HII String Token to the correct values.
555
556 **/
557 VOID
558 InitializeBrowserStrings (
559 VOID
560 )
561 {
562 gFunctionOneString = GetToken (STRING_TOKEN (FUNCTION_ONE_STRING), gHiiHandle);
563 gFunctionTwoString = GetToken (STRING_TOKEN (FUNCTION_TWO_STRING), gHiiHandle);
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 return ;
594 }
595
596 /**
597 Free up the resource allocated for all strings required
598 by Setup Browser.
599
600 **/
601 VOID
602 FreeBrowserStrings (
603 VOID
604 )
605 {
606 FreePool (gFunctionOneString);
607 FreePool (gFunctionTwoString);
608 FreePool (gFunctionNineString);
609 FreePool (gFunctionTenString);
610 FreePool (gEnterString);
611 FreePool (gEnterCommitString);
612 FreePool (gEnterEscapeString);
613 FreePool (gEscapeString);
614 FreePool (gMoveHighlight);
615 FreePool (gMakeSelection);
616 FreePool (gDecNumericInput);
617 FreePool (gHexNumericInput);
618 FreePool (gToggleCheckBox);
619 FreePool (gPromptForData);
620 FreePool (gPromptForPassword);
621 FreePool (gPromptForNewPassword);
622 FreePool (gConfirmPassword);
623 FreePool (gPassowordInvalid);
624 FreePool (gConfirmError);
625 FreePool (gPressEnter);
626 FreePool (gEmptyString);
627 FreePool (gAreYouSure);
628 FreePool (gYesResponse);
629 FreePool (gNoResponse);
630 FreePool (gMiniString);
631 FreePool (gPlusString);
632 FreePool (gMinusString);
633 FreePool (gAdjustNumber);
634 FreePool (gSaveChanges);
635 FreePool (gOptionMismatch);
636 return ;
637 }
638
639
640 /**
641 Update key's help imformation.
642
643 @param MenuOption The Menu option
644 @param Selected Whether or not a tag be selected
645
646 **/
647 VOID
648 UpdateKeyHelp (
649 IN UI_MENU_OPTION *MenuOption,
650 IN BOOLEAN Selected
651 )
652 {
653 UINTN SecCol;
654 UINTN ThdCol;
655 UINTN LeftColumnOfHelp;
656 UINTN RightColumnOfHelp;
657 UINTN TopRowOfHelp;
658 UINTN BottomRowOfHelp;
659 UINTN StartColumnOfHelp;
660 EFI_SCREEN_DESCRIPTOR LocalScreen;
661 FORM_BROWSER_STATEMENT *Statement;
662
663 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
664
665 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
666 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;
667
668 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
669 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
670 RightColumnOfHelp = LocalScreen.RightColumn - 2;
671 TopRowOfHelp = LocalScreen.BottomRow - 4;
672 BottomRowOfHelp = LocalScreen.BottomRow - 3;
673
674 if (gClassOfVfr == EFI_GENERAL_APPLICATION_SUBCLASS) {
675 return ;
676 }
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 == EFI_SETUP_APPLICATION_SUBCLASS) {
691 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
692 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
693 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
694 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
695 }
696
697 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
698 (Statement->Operand == EFI_IFR_TIME_OP)) {
699 PrintAt (
700 StartColumnOfHelp,
701 BottomRowOfHelp,
702 L"%c%c%c%c%s",
703 ARROW_UP,
704 ARROW_DOWN,
705 ARROW_RIGHT,
706 ARROW_LEFT,
707 gMoveHighlight
708 );
709 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
710 } else {
711 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
712 if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) {
713 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
714 } else {
715 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
716 }
717 }
718 } else {
719 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
720
721 //
722 // If it is a selected numeric with manual input, display different message
723 //
724 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step == 0)) {
725 PrintStringAt (
726 SecCol,
727 TopRowOfHelp,
728 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
729 );
730 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
731 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
732 }
733
734 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
735 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
736 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
737 }
738
739 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
740 }
741 break;
742
743 case EFI_IFR_CHECKBOX_OP:
744 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
745
746 if (gClassOfVfr == EFI_SETUP_APPLICATION_SUBCLASS) {
747 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
748 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
749 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
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 == EFI_SETUP_APPLICATION_SUBCLASS) {
767 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
768 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
769 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
770 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
771 }
772
773 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
774 if (Statement->Operand != EFI_IFR_TEXT_OP) {
775 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
776 }
777 } else {
778 if (Statement->Operand != EFI_IFR_REF_OP) {
779 PrintStringAt (
780 (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,
781 BottomRowOfHelp,
782 gEnterCommitString
783 );
784 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
785 }
786 }
787 break;
788
789 default:
790 break;
791 }
792 }
793
794 /**
795 Functions which are registered to receive notification of
796 database events have this prototype. The actual event is encoded
797 in NotifyType. The following table describes how PackageType,
798 PackageGuid, Handle, and Package are used for each of the
799 notification types.
800
801 @param PackageType Package type of the notification.
802
803 @param PackageGuid If PackageType is
804 EFI_HII_PACKAGE_TYPE_GUID, then this is
805 the pointer to the GUID from the Guid
806 field of EFI_HII_PACKAGE_GUID_HEADER.
807 Otherwise, it must be NULL.
808
809 @param Package Points to the package referred to by the
810 notification Handle The handle of the package
811 list which contains the specified package.
812
813 @param Handle The HII handle.
814
815 @param NotifyType The type of change concerning the
816 database. See
817 EFI_HII_DATABASE_NOTIFY_TYPE.
818
819 **/
820 EFI_STATUS
821 FormUpdateNotify (
822 IN UINT8 PackageType,
823 IN CONST EFI_GUID *PackageGuid,
824 IN CONST EFI_HII_PACKAGE_HEADER *Package,
825 IN EFI_HII_HANDLE Handle,
826 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
827 )
828 {
829 mHiiPackageListUpdated = TRUE;
830
831 return EFI_SUCCESS;
832 }
833
834 /**
835 The worker function that send the displays to the screen. On output,
836 the selection made by user is returned.
837
838 @param Selection On input, Selection tell setup browser the information
839 about the Selection, form and formset to be displayed.
840 On output, Selection return the screen item that is selected
841 by user.
842
843 @retval EFI_SUCCESS The page is displayed successfully.
844 @return Other value if the page failed to be diplayed.
845
846 **/
847 EFI_STATUS
848 SetupBrowser (
849 IN OUT UI_MENU_SELECTION *Selection
850 )
851 {
852 EFI_STATUS Status;
853 LIST_ENTRY *Link;
854 EFI_BROWSER_ACTION_REQUEST ActionRequest;
855 EFI_HANDLE NotifyHandle;
856 EFI_HII_VALUE *HiiValue;
857 FORM_BROWSER_STATEMENT *Statement;
858 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
859 EFI_INPUT_KEY Key;
860 CHAR16 YesResponse;
861 CHAR16 NoResponse;
862
863 gMenuRefreshHead = NULL;
864 gResetRequired = FALSE;
865 gNvUpdateRequired = FALSE;
866
867 UiInitMenuList ();
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 do {
885 //
886 // Displays the Header and Footer borders
887 //
888 DisplayPageFrame ();
889
890 //
891 // Initialize Selection->Form
892 //
893 if (Selection->FormId == 0) {
894 //
895 // Zero FormId indicates display the first Form in a FormSet
896 //
897 Link = GetFirstNode (&Selection->FormSet->FormListHead);
898
899 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
900 Selection->FormId = Selection->Form->FormId;
901 } else {
902 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
903 }
904
905 //
906 // Load Questions' Value for display
907 //
908 Status = LoadFormConfig (Selection->FormSet, Selection->Form);
909 if (EFI_ERROR (Status)) {
910 return Status;
911 }
912
913 //
914 // Display form
915 //
916 Status = DisplayForm (Selection);
917 if (EFI_ERROR (Status)) {
918 return Status;
919 }
920
921 //
922 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
923 //
924 Statement = Selection->Statement;
925 if (Statement != NULL) {
926 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
927 gResetRequired = TRUE;
928 }
929
930 //
931 // Reset FormPackage update flag
932 //
933 mHiiPackageListUpdated = FALSE;
934
935 if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
936 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
937
938 HiiValue = &Statement->HiiValue;
939 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
940 //
941 // Create String in HII database for Configuration Driver to retrieve
942 //
943 HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
944 }
945
946 ConfigAccess = Selection->FormSet->ConfigAccess;
947 if (ConfigAccess == NULL) {
948 return EFI_UNSUPPORTED;
949 }
950 Status = ConfigAccess->Callback (
951 ConfigAccess,
952 EFI_BROWSER_ACTION_CHANGING,
953 Statement->QuestionId,
954 HiiValue->Type,
955 &HiiValue->Value,
956 &ActionRequest
957 );
958
959 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
960 //
961 // Clean the String in HII Database
962 //
963 DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
964 }
965
966 if (!EFI_ERROR (Status)) {
967 switch (ActionRequest) {
968 case EFI_BROWSER_ACTION_REQUEST_RESET:
969 gResetRequired = TRUE;
970 break;
971
972 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
973 SubmitForm (Selection->FormSet, Selection->Form);
974 break;
975
976 case EFI_BROWSER_ACTION_REQUEST_EXIT:
977 Selection->Action = UI_ACTION_EXIT;
978 gNvUpdateRequired = FALSE;
979 break;
980
981 default:
982 break;
983 }
984 }
985 }
986
987 //
988 // Check whether Form Package has been updated during Callback
989 //
990 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
991 //
992 // Force to reparse IFR binary of target Formset
993 //
994 Selection->Action = UI_ACTION_REFRESH_FORMSET;
995
996 //
997 // Uncommitted data will be lost after IFR binary re-pasing, so confirm on whether to save
998 //
999 if (gNvUpdateRequired) {
1000 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
1001
1002 YesResponse = gYesResponse[0];
1003 NoResponse = gNoResponse[0];
1004
1005 do {
1006 CreateDialog (3, TRUE, 0, NULL, &Key, gEmptyString, gSaveChanges, gEmptyString);
1007 } while
1008 (
1009 (Key.ScanCode != SCAN_ESC) &&
1010 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
1011 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
1012 );
1013
1014 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
1015 //
1016 // If the user hits the YesResponse key
1017 //
1018 SubmitForm (Selection->FormSet, Selection->Form);
1019 }
1020 }
1021 }
1022 }
1023 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1024
1025 //
1026 // Unregister notify for Form package update
1027 //
1028 Status = mHiiDatabase->UnregisterPackageNotify (
1029 mHiiDatabase,
1030 NotifyHandle
1031 );
1032 return Status;
1033 }