]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
93267f0fdeecfce49ad10287fa1769be543eea80
[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 IN UINTN LeftColumn,
35 IN UINTN RightColumn,
36 IN UINTN TopRow,
37 IN UINTN BottomRow,
38 IN 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 IN OUT CHAR16 *Destination,
84 IN 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 IN 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 UI_MENU_OPTION *MenuOption;
464
465 Handle = Selection->Handle;
466 MenuItemCount = 0;
467 ArrayEntry = 0;
468 OutputString = NULL;
469
470 UiInitMenu ();
471
472 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
473
474 StringPtr = GetToken (Selection->Form->FormTitle, Handle);
475
476 if (gClassOfVfr != FORMSET_CLASS_FRONT_PAGE) {
477 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
478 PrintStringAt (
479 (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2,
480 LocalScreen.TopRow + 1,
481 StringPtr
482 );
483 }
484
485 //
486 // Remove Buffer allocated for StringPtr after it has been used.
487 //
488 FreePool (StringPtr);
489
490 //
491 // Evaluate all the Expressions in this Form
492 //
493 Status = EvaluateFormExpressions (Selection->FormSet, Selection->Form);
494 if (EFI_ERROR (Status)) {
495 return Status;
496 }
497
498 Selection->FormEditable = FALSE;
499 Link = GetFirstNode (&Selection->Form->StatementListHead);
500 while (!IsNull (&Selection->Form->StatementListHead, Link)) {
501 Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
502
503 if (Statement->SuppressExpression != NULL) {
504 Suppress = Statement->SuppressExpression->Result.Value.b;
505 } else {
506 Suppress = FALSE;
507 }
508
509 if (Statement->DisableExpression != NULL) {
510 Suppress = (BOOLEAN) (Suppress || Statement->DisableExpression->Result.Value.b);
511 }
512
513 if (!Suppress) {
514 StringPtr = GetToken (Statement->Prompt, Handle);
515
516 Width = GetWidth (Statement, Handle);
517
518 NumberOfLines = 1;
519 ArrayEntry = 0;
520 for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {
521 //
522 // If there is more string to process print on the next row and increment the Skip value
523 //
524 if (StrLen (&StringPtr[ArrayEntry]) != 0) {
525 NumberOfLines++;
526 }
527
528 FreePool (OutputString);
529 }
530
531 //
532 // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do
533 // it in UiFreeMenu.
534 //
535 MenuOption = UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount);
536 MenuItemCount++;
537
538 if (MenuOption->IsQuestion && !MenuOption->ReadOnly) {
539 //
540 // At least one item is not readonly, this Form is considered as editable
541 //
542 Selection->FormEditable = TRUE;
543 }
544 }
545
546 Link = GetNextNode (&Selection->Form->StatementListHead, Link);
547 }
548
549 Status = UiDisplayMenu (Selection);
550
551 UiFreeMenu ();
552
553 return Status;
554 }
555
556 /**
557 Initialize the HII String Token to the correct values.
558
559 **/
560 VOID
561 InitializeBrowserStrings (
562 VOID
563 )
564 {
565 gFunctionNineString = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);
566 gFunctionTenString = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);
567 gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle);
568 gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle);
569 gEnterEscapeString = GetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), gHiiHandle);
570 gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle);
571 gSaveFailed = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle);
572 gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle);
573 gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle);
574 gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle);
575 gHexNumericInput = GetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), gHiiHandle);
576 gToggleCheckBox = GetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), gHiiHandle);
577 gPromptForData = GetToken (STRING_TOKEN (PROMPT_FOR_DATA), gHiiHandle);
578 gPromptForPassword = GetToken (STRING_TOKEN (PROMPT_FOR_PASSWORD), gHiiHandle);
579 gPromptForNewPassword = GetToken (STRING_TOKEN (PROMPT_FOR_NEW_PASSWORD), gHiiHandle);
580 gConfirmPassword = GetToken (STRING_TOKEN (CONFIRM_PASSWORD), gHiiHandle);
581 gConfirmError = GetToken (STRING_TOKEN (CONFIRM_ERROR), gHiiHandle);
582 gPassowordInvalid = GetToken (STRING_TOKEN (PASSWORD_INVALID), gHiiHandle);
583 gPressEnter = GetToken (STRING_TOKEN (PRESS_ENTER), gHiiHandle);
584 gEmptyString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
585 gAreYouSure = GetToken (STRING_TOKEN (ARE_YOU_SURE), gHiiHandle);
586 gYesResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);
587 gNoResponse = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);
588 gMiniString = GetToken (STRING_TOKEN (MINI_STRING), gHiiHandle);
589 gPlusString = GetToken (STRING_TOKEN (PLUS_STRING), gHiiHandle);
590 gMinusString = GetToken (STRING_TOKEN (MINUS_STRING), gHiiHandle);
591 gAdjustNumber = GetToken (STRING_TOKEN (ADJUST_NUMBER), gHiiHandle);
592 gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle);
593 gOptionMismatch = GetToken (STRING_TOKEN (OPTION_MISMATCH), gHiiHandle);
594 return ;
595 }
596
597 /**
598 Free up the resource allocated for all strings required
599 by Setup Browser.
600
601 **/
602 VOID
603 FreeBrowserStrings (
604 VOID
605 )
606 {
607 FreePool (gFunctionNineString);
608 FreePool (gFunctionTenString);
609 FreePool (gEnterString);
610 FreePool (gEnterCommitString);
611 FreePool (gEnterEscapeString);
612 FreePool (gEscapeString);
613 FreePool (gMoveHighlight);
614 FreePool (gMakeSelection);
615 FreePool (gDecNumericInput);
616 FreePool (gHexNumericInput);
617 FreePool (gToggleCheckBox);
618 FreePool (gPromptForData);
619 FreePool (gPromptForPassword);
620 FreePool (gPromptForNewPassword);
621 FreePool (gConfirmPassword);
622 FreePool (gPassowordInvalid);
623 FreePool (gConfirmError);
624 FreePool (gPressEnter);
625 FreePool (gEmptyString);
626 FreePool (gAreYouSure);
627 FreePool (gYesResponse);
628 FreePool (gNoResponse);
629 FreePool (gMiniString);
630 FreePool (gPlusString);
631 FreePool (gMinusString);
632 FreePool (gAdjustNumber);
633 FreePool (gSaveChanges);
634 FreePool (gOptionMismatch);
635 return ;
636 }
637
638
639 /**
640 Update key's help imformation.
641
642 @param Selection Tell setup browser the information about the Selection
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_SELECTION *Selection,
650 IN UI_MENU_OPTION *MenuOption,
651 IN BOOLEAN Selected
652 )
653 {
654 UINTN SecCol;
655 UINTN ThdCol;
656 UINTN LeftColumnOfHelp;
657 UINTN RightColumnOfHelp;
658 UINTN TopRowOfHelp;
659 UINTN BottomRowOfHelp;
660 UINTN StartColumnOfHelp;
661 EFI_SCREEN_DESCRIPTOR LocalScreen;
662 FORM_BROWSER_STATEMENT *Statement;
663
664 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
665
666 SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
667 ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3;
668
669 StartColumnOfHelp = LocalScreen.LeftColumn + 2;
670 LeftColumnOfHelp = LocalScreen.LeftColumn + 1;
671 RightColumnOfHelp = LocalScreen.RightColumn - 2;
672 TopRowOfHelp = LocalScreen.BottomRow - 4;
673 BottomRowOfHelp = LocalScreen.BottomRow - 3;
674
675 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
676
677 Statement = MenuOption->ThisTag;
678 switch (Statement->Operand) {
679 case EFI_IFR_ORDERED_LIST_OP:
680 case EFI_IFR_ONE_OF_OP:
681 case EFI_IFR_NUMERIC_OP:
682 case EFI_IFR_TIME_OP:
683 case EFI_IFR_DATE_OP:
684 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
685
686 if (!Selected) {
687 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
688 if (Selection->FormEditable) {
689 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
690 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
691 }
692 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
693 }
694
695 if ((Statement->Operand == EFI_IFR_DATE_OP) ||
696 (Statement->Operand == EFI_IFR_TIME_OP)) {
697 PrintAt (
698 StartColumnOfHelp,
699 BottomRowOfHelp,
700 L"%c%c%c%c%s",
701 ARROW_UP,
702 ARROW_DOWN,
703 ARROW_RIGHT,
704 ARROW_LEFT,
705 gMoveHighlight
706 );
707 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
708 } else {
709 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
710 if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) {
711 PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber);
712 } else {
713 PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
714 }
715 }
716 } else {
717 PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
718
719 //
720 // If it is a selected numeric with manual input, display different message
721 //
722 if ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step == 0)) {
723 PrintStringAt (
724 SecCol,
725 TopRowOfHelp,
726 ((Statement->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX) ? gHexNumericInput : gDecNumericInput
727 );
728 } else if (Statement->Operand != EFI_IFR_ORDERED_LIST_OP) {
729 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
730 }
731
732 if (Statement->Operand == EFI_IFR_ORDERED_LIST_OP) {
733 PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
734 PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
735 }
736
737 PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
738 }
739 break;
740
741 case EFI_IFR_CHECKBOX_OP:
742 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
743
744 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
745 if (Selection->FormEditable) {
746 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
747 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
748 }
749 PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
750 }
751
752 PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
753 PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
754 break;
755
756 case EFI_IFR_REF_OP:
757 case EFI_IFR_PASSWORD_OP:
758 case EFI_IFR_STRING_OP:
759 case EFI_IFR_TEXT_OP:
760 case EFI_IFR_ACTION_OP:
761 case EFI_IFR_RESET_BUTTON_OP:
762 ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
763
764 if (!Selected) {
765 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
766 if (Selection->FormEditable) {
767 PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString);
768 PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString);
769 }
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 EFIAPI
822 FormUpdateNotify (
823 IN UINT8 PackageType,
824 IN CONST EFI_GUID *PackageGuid,
825 IN CONST EFI_HII_PACKAGE_HEADER *Package,
826 IN EFI_HII_HANDLE Handle,
827 IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType
828 )
829 {
830 mHiiPackageListUpdated = TRUE;
831
832 return EFI_SUCCESS;
833 }
834
835 /**
836 The worker function that send the displays to the screen. On output,
837 the selection made by user is returned.
838
839 @param Selection On input, Selection tell setup browser the information
840 about the Selection, form and formset to be displayed.
841 On output, Selection return the screen item that is selected
842 by user.
843
844 @retval EFI_SUCCESS The page is displayed successfully.
845 @return Other value if the page failed to be diplayed.
846
847 **/
848 EFI_STATUS
849 SetupBrowser (
850 IN OUT UI_MENU_SELECTION *Selection
851 )
852 {
853 EFI_STATUS Status;
854 LIST_ENTRY *Link;
855 EFI_BROWSER_ACTION_REQUEST ActionRequest;
856 EFI_HANDLE NotifyHandle;
857 EFI_HII_VALUE *HiiValue;
858 FORM_BROWSER_STATEMENT *Statement;
859 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
860 FORM_BROWSER_FORMSET *FormSet;
861
862 gMenuRefreshHead = NULL;
863 gResetRequired = FALSE;
864 FormSet = Selection->FormSet;
865
866 //
867 // Register notify for Form package update
868 //
869 Status = mHiiDatabase->RegisterPackageNotify (
870 mHiiDatabase,
871 EFI_HII_PACKAGE_FORMS,
872 NULL,
873 FormUpdateNotify,
874 EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,
875 &NotifyHandle
876 );
877 if (EFI_ERROR (Status)) {
878 return Status;
879 }
880
881 //
882 // Before display the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN
883 //
884 ConfigAccess = Selection->FormSet->ConfigAccess;
885 if ((ConfigAccess != NULL) && (Selection->Action != UI_ACTION_REFRESH_FORMSET)) {
886 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
887 mHiiPackageListUpdated = FALSE;
888 Status = ConfigAccess->Callback (
889 ConfigAccess,
890 EFI_BROWSER_ACTION_FORM_OPEN,
891 0,
892 EFI_IFR_TYPE_UNDEFINED,
893 NULL,
894 &ActionRequest
895 );
896
897 if (!EFI_ERROR (Status)) {
898 switch (ActionRequest) {
899 case EFI_BROWSER_ACTION_REQUEST_RESET:
900 gResetRequired = TRUE;
901 break;
902
903 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
904 //
905 // Till now there is no uncommitted data, so ignore this request
906 //
907 break;
908
909 case EFI_BROWSER_ACTION_REQUEST_EXIT:
910 Selection->Action = UI_ACTION_EXIT;
911 break;
912
913 default:
914 break;
915 }
916 }
917
918 if (mHiiPackageListUpdated) {
919 //
920 // IFR is updated during callback, force to reparse the IFR binary
921 //
922 Selection->Action = UI_ACTION_REFRESH_FORMSET;
923 goto Done;
924 }
925 }
926
927 //
928 // Initialize current settings of Questions in this FormSet
929 //
930 Status = InitializeCurrentSetting (Selection->FormSet);
931 if (EFI_ERROR (Status)) {
932 Selection->Action = UI_ACTION_EXIT;
933 goto Done;
934 }
935
936 do {
937 //
938 // Initialize Selection->Form
939 //
940 if (Selection->FormId == 0) {
941 //
942 // Zero FormId indicates display the first Form in a FormSet
943 //
944 Link = GetFirstNode (&Selection->FormSet->FormListHead);
945
946 Selection->Form = FORM_BROWSER_FORM_FROM_LINK (Link);
947 Selection->FormId = Selection->Form->FormId;
948 } else {
949 Selection->Form = IdToForm (Selection->FormSet, Selection->FormId);
950 }
951
952 if (Selection->Form == NULL) {
953 //
954 // No Form to display
955 //
956 return EFI_NOT_FOUND;
957 }
958
959 //
960 // Load Questions' Value for display
961 //
962 Status = LoadFormSetConfig (Selection->FormSet);
963 if (EFI_ERROR (Status)) {
964 return Status;
965 }
966
967 //
968 // Displays the Header and Footer borders
969 //
970 DisplayPageFrame ();
971
972 //
973 // Display form
974 //
975 Status = DisplayForm (Selection);
976 if (EFI_ERROR (Status)) {
977 return Status;
978 }
979
980 //
981 // Check Selected Statement (if press ESC, Selection->Statement will be NULL)
982 //
983 Statement = Selection->Statement;
984 if (Statement != NULL) {
985 if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED) {
986 gResetRequired = TRUE;
987 }
988
989 //
990 // Reset FormPackage update flag
991 //
992 mHiiPackageListUpdated = FALSE;
993
994 if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) {
995 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
996
997 HiiValue = &Statement->HiiValue;
998 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
999 //
1000 // Create String in HII database for Configuration Driver to retrieve
1001 //
1002 HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
1003 }
1004
1005 if (ConfigAccess == NULL) {
1006 return EFI_UNSUPPORTED;
1007 }
1008 Status = ConfigAccess->Callback (
1009 ConfigAccess,
1010 EFI_BROWSER_ACTION_CHANGING,
1011 Statement->QuestionId,
1012 HiiValue->Type,
1013 &HiiValue->Value,
1014 &ActionRequest
1015 );
1016
1017 if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
1018 //
1019 // Clean the String in HII Database
1020 //
1021 DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
1022 }
1023
1024 if (!EFI_ERROR (Status)) {
1025 switch (ActionRequest) {
1026 case EFI_BROWSER_ACTION_REQUEST_RESET:
1027 gResetRequired = TRUE;
1028 break;
1029
1030 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1031 SubmitForm (Selection->FormSet, Selection->Form);
1032 break;
1033
1034 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1035 Selection->Action = UI_ACTION_EXIT;
1036 gNvUpdateRequired = FALSE;
1037 break;
1038
1039 default:
1040 break;
1041 }
1042 } else if (Status != EFI_UNSUPPORTED) {
1043 //
1044 // Callback return error status other than EFI_UNSUPPORTED
1045 //
1046 if (Statement->Operand == EFI_IFR_REF_OP) {
1047 //
1048 // Cross reference will not be taken
1049 //
1050 Selection->FormId = Selection->Form->FormId;
1051 Selection->QuestionId = 0;
1052 }
1053 }
1054 }
1055
1056 //
1057 // Check whether Form Package has been updated during Callback
1058 //
1059 if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {
1060 //
1061 // Force to reparse IFR binary of target Formset
1062 //
1063 Selection->Action = UI_ACTION_REFRESH_FORMSET;
1064 }
1065 }
1066 } while (Selection->Action == UI_ACTION_REFRESH_FORM);
1067
1068 //
1069 // Before exit the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE
1070 //
1071 if ((ConfigAccess != NULL) && (Selection->Action == UI_ACTION_EXIT)) {
1072 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
1073 Status = ConfigAccess->Callback (
1074 ConfigAccess,
1075 EFI_BROWSER_ACTION_FORM_CLOSE,
1076 0,
1077 EFI_IFR_TYPE_UNDEFINED,
1078 NULL,
1079 &ActionRequest
1080 );
1081
1082 if (!EFI_ERROR (Status)) {
1083 switch (ActionRequest) {
1084 case EFI_BROWSER_ACTION_REQUEST_RESET:
1085 gResetRequired = TRUE;
1086 break;
1087
1088 case EFI_BROWSER_ACTION_REQUEST_SUBMIT:
1089 SubmitForm (Selection->FormSet, Selection->Form);
1090 break;
1091
1092 case EFI_BROWSER_ACTION_REQUEST_EXIT:
1093 gNvUpdateRequired = FALSE;
1094 break;
1095
1096 default:
1097 break;
1098 }
1099 }
1100 }
1101
1102 //
1103 // Record the old formset
1104 //
1105 if (gOldFormSet != NULL) {
1106 DestroyFormSet (gOldFormSet);
1107 }
1108 gOldFormSet = FormSet;
1109
1110 Done:
1111 //
1112 // Unregister notify for Form package update
1113 //
1114 Status = mHiiDatabase->UnregisterPackageNotify (
1115 mHiiDatabase,
1116 NotifyHandle
1117 );
1118 return Status;
1119 }