]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
Change the FormBrowser behavior of "Pressing ESC":
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
1 /** @file
2 Utility functions for UI presentation.
3
4 Copyright (c) 2004 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "Setup.h"
16 #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 == FORMSET_CLASS_FRONT_PAGE) {
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 = (UINT8) (Line - (UINT8) LocalScreen.TopRow);
235 ColumnIdx = (UINT8) (Alignment - (UINT8) LocalScreen.LeftColumn);
236
237 ASSERT (RowIdx < BANNER_HEIGHT);
238 ASSERT (ColumnIdx < BANNER_COLUMNS);
239
240 if (gBannerData->Banner[RowIdx][ColumnIdx] != 0x0000) {
241 StrFrontPageBanner = GetToken (
242 gBannerData->Banner[RowIdx][ColumnIdx],
243 gFrontPageHandle
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 != FORMSET_CLASS_FRONT_PAGE) {
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 == FORMSET_CLASS_PLATFORM_SETUP) {
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 ? 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 != FORMSET_CLASS_FRONT_PAGE) {
476 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
477 PrintStringAt (
478 (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2,
479 LocalScreen.TopRow + 1,
480 StringPtr
481 );
482 }
483
484 //
485 // Remove Buffer allocated for StringPtr after it has been used.
486 //
487 FreePool (StringPtr);
488
489 //
490 // Evaluate all the Expressions in this Form
491 //
492 Status = EvaluateFormExpressions (Selection->FormSet, Selection->Form);
493 if (EFI_ERROR (Status)) {
494 return Status;
495 }
496
497 Link = GetFirstNode (&Selection->Form->StatementListHead);
498 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
499 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
500
501 if (Statement->SuppressExpression != NULL) {
502 Suppress = Statement->SuppressExpression->Result.Value.b;
503 } else {
504 Suppress = FALSE;
505 }
506
507 if (Statement->DisableExpression != NULL) {
508 Suppress = (BOOLEAN) (Suppress || Statement->DisableExpression->Result.Value.b);
509 }
510
511 if (!Suppress) {
512 StringPtr = GetToken (Statement->Prompt, Handle);
513
514 Width = GetWidth (Statement, Handle);
515
516 NumberOfLines = 1;
517 ArrayEntry = 0;
518 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
519 //
520 // If there is more string to process print on the next row and increment the Skip value
521 //
522 if (StrLen (&StringPtr[ArrayEntry]) != 0) {
523 NumberOfLines++;
524 }
525
526 FreePool (OutputString);
527 }
528
529 //
530 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
531 // it in UiFreeMenu.
532 //
533 UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount);
534 MenuItemCount++;
535 }
536
537 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
538 }
539
540 Status = UiDisplayMenu (Selection);
541
542 UiFreeMenu ();
543
544 return Status;
545 }
546
547 /**
548 Initialize the HII String Token to the correct values.
549
550 **/
551 VOID
552 InitializeBrowserStrings (
553 VOID
554 )
555 {
556 gFunctionOneString = GetToken (STRING_TOKEN (FUNCTION_ONE_STRING), gHiiHandle);
557 gFunctionNineString = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);
558 gFunctionTenString = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);
559 gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);
560 gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);
561 gEnterEscapeString = GetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), gHiiHandle);
562 gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);
563 gSaveFailed = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle);
564 gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);
565 gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);
566 gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle);
567 gHexNumericInput = GetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), gHiiHandle);
568 gToggleCheckBox = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);
569 gPromptForData = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);
570 gPromptForPassword = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);
571 gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);
572 gConfirmPassword = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);
573 gConfirmError = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);
574 gPassowordInvalid = GetToken (STRING_TOKEN (PASSWORD_INVALID), gHiiHandle);
575 gPressEnter = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);
576 gEmptyString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
577 gAreYouSure = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);
578 gYesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);
579 gNoResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);
580 gMiniString = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);
581 gPlusString = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);
582 gMinusString = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);
583 gAdjustNumber = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);
584 gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle);
585 gOptionMismatch = GetToken (STRING_TOKEN (OPTION_MISMATCH), gHiiHandle);
586 return ;
587 }
588
589 /**
590 Free up the resource allocated for all strings required
591 by Setup Browser.
592
593 **/
594 VOID
595 FreeBrowserStrings (
596 VOID
597 )
598 {
599 FreePool (gFunctionOneString);
600 FreePool (gFunctionNineString);
601 FreePool (gFunctionTenString);
602 FreePool (gEnterString);
603 FreePool (gEnterCommitString);
604 FreePool (gEnterEscapeString);
605 FreePool (gEscapeString);
606 FreePool (gMoveHighlight);
607 FreePool (gMakeSelection);
608 FreePool (gDecNumericInput);
609 FreePool (gHexNumericInput);
610 FreePool (gToggleCheckBox);
611 FreePool (gPromptForData);
612 FreePool (gPromptForPassword);
613 FreePool (gPromptForNewPassword);
614 FreePool (gConfirmPassword);
615 FreePool (gPassowordInvalid);
616 FreePool (gConfirmError);
617 FreePool (gPressEnter);
618 FreePool (gEmptyString);
619 FreePool (gAreYouSure);
620 FreePool (gYesResponse);
621 FreePool (gNoResponse);
622 FreePool (gMiniString);
623 FreePool (gPlusString);
624 FreePool (gMinusString);
625 FreePool (gAdjustNumber);
626 FreePool (gSaveChanges);
627 FreePool (gOptionMismatch);
628 return ;
629 }
630
631
632 /**
633 Update key's help imformation.
634
635 @param MenuOption The Menu option
636 @param Selected Whether or not a tag be selected
637
638 **/
639 VOID
640 UpdateKeyHelp (
641 IN UI_MENU_OPTION *MenuOption,
642 IN BOOLEAN Selected
643 )
644 {
645 UINTN SecCol;
646 UINTN ThdCol;
647 UINTN LeftColumnOfHelp;
648 UINTN RightColumnOfHelp;
649 UINTN TopRowOfHelp;
650 UINTN BottomRowOfHelp;
651 UINTN StartColumnOfHelp;
652 EFI_SCREEN_DESCRIPTOR LocalScreen;
653 FORM_BROWSER_STATEMENT *Statement;
654
655 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
656
657 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
658 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;
659
660 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
661 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
662 RightColumnOfHelp = LocalScreen.RightColumn - 2;
663 TopRowOfHelp = LocalScreen.BottomRow - 4;
664 BottomRowOfHelp = LocalScreen.BottomRow - 3;
665
666 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
667
668 Statement = MenuOption->ThisTag;
669 switch (Statement->Operand) {
670 case EFI_IFR_ORDERED_LIST_OP:
671 case EFI_IFR_ONE_OF_OP:
672 case EFI_IFR_NUMERIC_OP:
673 case EFI_IFR_TIME_OP:
674 case EFI_IFR_DATE_OP:
675 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
676
677 if (!Selected) {
678 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
679 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
680 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
681 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
682 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
683 }
684
685 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
686 (Statement->Operand == EFI_IFR_TIME_OP)) {
687 PrintAt (
688 StartColumnOfHelp,
689 BottomRowOfHelp,
690 L"%c%c%c%c%s",
691 ARROW_UP,
692 ARROW_DOWN,
693 ARROW_RIGHT,
694 ARROW_LEFT,
695 gMoveHighlight
696 );
697 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
698 } else {
699 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
700 if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) {
701 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
702 } else {
703 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
704 }
705 }
706 } else {
707 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
708
709 //
710 // If it is a selected numeric with manual input, display different message
711 //
712 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step == 0)) {
713 PrintStringAt (
714 SecCol,
715 TopRowOfHelp,
716 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
717 );
718 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
719 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
720 }
721
722 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
723 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
724 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
725 }
726
727 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
728 }
729 break;
730
731 case EFI_IFR_CHECKBOX_OP:
732 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
733
734 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
735 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
736 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
737 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
738 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
739 }
740
741 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
742 PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
743 break;
744
745 case EFI_IFR_REF_OP:
746 case EFI_IFR_PASSWORD_OP:
747 case EFI_IFR_STRING_OP:
748 case EFI_IFR_TEXT_OP:
749 case EFI_IFR_ACTION_OP:
750 case EFI_IFR_RESET_BUTTON_OP:
751 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
752
753 if (!Selected) {
754 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
755 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gFunctionOneString);
756 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
757 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
758 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
759 }
760
761 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
762 if (Statement->Operand != EFI_IFR_TEXT_OP) {
763 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
764 }
765 } else {
766 if (Statement->Operand != EFI_IFR_REF_OP) {
767 PrintStringAt (
768 (LocalScreen.RightColumn - GetStringWidth (gEnterCommitString) / 2) / 2,
769 BottomRowOfHelp,
770 gEnterCommitString
771 );
772 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
773 }
774 }
775 break;
776
777 default:
778 break;
779 }
780 }
781
782 /**
783 Functions which are registered to receive notification of
784 database events have this prototype. The actual event is encoded
785 in NotifyType. The following table describes how PackageType,
786 PackageGuid, Handle, and Package are used for each of the
787 notification types.
788
789 @param PackageType Package type of the notification.
790
791 @param PackageGuid If PackageType is
792 EFI_HII_PACKAGE_TYPE_GUID, then this is
793 the pointer to the GUID from the Guid
794 field of EFI_HII_PACKAGE_GUID_HEADER.
795 Otherwise, it must be NULL.
796
797 @param Package Points to the package referred to by the
798 notification Handle The handle of the package
799 list which contains the specified package.
800
801 @param Handle The HII handle.
802
803 @param NotifyType The type of change concerning the
804 database. See
805 EFI_HII_DATABASE_NOTIFY_TYPE.
806
807 **/
808 EFI_STATUS
809 EFIAPI
810 FormUpdateNotify (
811 IN UINT8 PackageType,
812 IN CONST EFI_GUID *PackageGuid,
813 IN CONST EFI_HII_PACKAGE_HEADER *Package,
814 IN EFI_HII_HANDLE Handle,
815 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
816 )
817 {
818 mHiiPackageListUpdated = TRUE;
819
820 return EFI_SUCCESS;
821 }
822
823 /**
824 The worker function that send the displays to the screen. On output,
825 the selection made by user is returned.
826
827 @param Selection On input, Selection tell setup browser the information
828 about the Selection, form and formset to be displayed.
829 On output, Selection return the screen item that is selected
830 by user.
831
832 @retval EFI_SUCCESS The page is displayed successfully.
833 @return Other value if the page failed to be diplayed.
834
835 **/
836 EFI_STATUS
837 SetupBrowser (
838 IN OUT UI_MENU_SELECTION *Selection
839 )
840 {
841 EFI_STATUS Status;
842 LIST_ENTRY *Link;
843 EFI_BROWSER_ACTION_REQUEST ActionRequest;
844 EFI_HANDLE NotifyHandle;
845 EFI_HII_VALUE *HiiValue;
846 FORM_BROWSER_STATEMENT *Statement;
847 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
848 FORM_BROWSER_FORMSET *FormSet;
849
850 gMenuRefreshHead = NULL;
851 gResetRequired = FALSE;
852 FormSet = Selection->FormSet;
853
854 //
855 // Register notify for Form package update
856 //
857 Status = mHiiDatabase->RegisterPackageNotify (
858 mHiiDatabase,
859 EFI_HII_PACKAGE_FORMS,
860 NULL,
861 FormUpdateNotify,
862 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
863 &NotifyHandle
864 );
865 if (EFI_ERROR (Status)) {
866 return Status;
867 }
868
869 //
870 // Initialize current settings of Questions in this FormSet
871 //
872 Status = InitializeCurrentSetting (Selection->FormSet);
873 if (EFI_ERROR (Status)) {
874 Selection->Action = UI_ACTION_EXIT;
875 goto Done;
876 }
877
878 do {
879 //
880 // Displays the Header and Footer borders
881 //
882 DisplayPageFrame ();
883
884 //
885 // Initialize Selection->Form
886 //
887 if (Selection->FormId == 0) {
888 //
889 // Zero FormId indicates display the first Form in a FormSet
890 //
891 Link = GetFirstNode (&Selection->FormSet->FormListHead);
892
893 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
894 Selection->FormId = Selection->Form->FormId;
895 } else {
896 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
897 }
898
899 if (Selection->Form == NULL) {
900 //
901 // No Form to display
902 //
903 return EFI_NOT_FOUND;
904 }
905
906 //
907 // Load Questions' Value for display
908 //
909 Status = LoadFormSetConfig (Selection->FormSet);
910 if (EFI_ERROR (Status)) {
911 return Status;
912 }
913
914 //
915 // Display form
916 //
917 Status = DisplayForm (Selection);
918 if (EFI_ERROR (Status)) {
919 return Status;
920 }
921
922 //
923 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
924 //
925 Statement = Selection->Statement;
926 if (Statement != NULL) {
927 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
928 gResetRequired = TRUE;
929 }
930
931 //
932 // Reset FormPackage update flag
933 //
934 mHiiPackageListUpdated = FALSE;
935
936 if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
937 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
938
939 HiiValue = &Statement->HiiValue;
940 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
941 //
942 // Create String in HII database for Configuration Driver to retrieve
943 //
944 HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
945 }
946
947 ConfigAccess = Selection->FormSet->ConfigAccess;
948 if (ConfigAccess == NULL) {
949 return EFI_UNSUPPORTED;
950 }
951 Status = ConfigAccess->Callback (
952 ConfigAccess,
953 EFI_BROWSER_ACTION_CHANGING,
954 Statement->QuestionId,
955 HiiValue->Type,
956 &HiiValue->Value,
957 &ActionRequest
958 );
959
960 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
961 //
962 // Clean the String in HII Database
963 //
964 DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
965 }
966
967 if (!EFI_ERROR (Status)) {
968 switch (ActionRequest) {
969 case EFI_BROWSER_ACTION_REQUEST_RESET:
970 gResetRequired = TRUE;
971 break;
972
973 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
974 SubmitForm (Selection->FormSet, Selection->Form);
975 break;
976
977 case EFI_BROWSER_ACTION_REQUEST_EXIT:
978 Selection->Action = UI_ACTION_EXIT;
979 gNvUpdateRequired = FALSE;
980 break;
981
982 default:
983 break;
984 }
985 }
986 }
987
988 //
989 // Check whether Form Package has been updated during Callback
990 //
991 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
992 //
993 // Force to reparse IFR binary of target Formset
994 //
995 Selection->Action = UI_ACTION_REFRESH_FORMSET;
996 }
997 }
998 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
999
1000 //
1001 // Record the old formset
1002 //
1003 if (gOldFormSet != NULL) {
1004 DestroyFormSet (gOldFormSet);
1005 }
1006 gOldFormSet = FormSet;
1007
1008 Done:
1009 //
1010 // Unregister notify for Form package update
1011 //
1012 Status = mHiiDatabase->UnregisterPackageNotify (
1013 mHiiDatabase,
1014 NotifyHandle
1015 );
1016 return Status;
1017 }