2 Utility functions for User Interface functions.
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 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
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.
17 LIST_ENTRY gMenuOption
;
18 LIST_ENTRY gMenuList
= INITIALIZE_LIST_HEAD_VARIABLE (gMenuList
);
19 MENU_REFRESH_ENTRY
*gMenuRefreshHead
;
22 // Search table for UiDisplayMenu()
24 SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation
[] = {
63 SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag
[] = {
111 BOOLEAN GetLineByWidthFinished
= FALSE
;
115 Set Buffer to Value for Size bytes.
117 @param Buffer Memory to set.
118 @param Size Number of bytes to set
119 @param Value Value of the set operation.
132 while ((Size
--) != 0) {
139 Initialize Menu option list.
147 InitializeListHead (&gMenuOption
);
152 Free Menu option linked list.
160 UI_MENU_OPTION
*MenuOption
;
162 while (!IsListEmpty (&gMenuOption
)) {
163 MenuOption
= MENU_OPTION_FROM_LINK (gMenuOption
.ForwardLink
);
164 RemoveEntryList (&MenuOption
->Link
);
167 // We allocated space for this description when we did a GetToken, free it here
169 if (MenuOption
->Skip
!= 0) {
171 // For date/time, MenuOption->Description is shared by three Menu Options
172 // Data format : [01/02/2004] [11:22:33]
173 // Line number : 0 0 1 0 0 1
175 FreePool (MenuOption
->Description
);
177 FreePool (MenuOption
);
183 Create a menu with specified formset GUID and form ID, and add it as a child
184 of the given parent menu.
186 @param Parent The parent of menu to be added.
187 @param FormSetGuid The Formset Guid of menu to be added.
188 @param FormId The Form ID of menu to be added.
190 @return A pointer to the newly added menu or NULL if memory is insufficient.
195 IN OUT UI_MENU_LIST
*Parent
,
196 IN EFI_GUID
*FormSetGuid
,
200 UI_MENU_LIST
*MenuList
;
202 MenuList
= AllocateZeroPool (sizeof (UI_MENU_LIST
));
203 if (MenuList
== NULL
) {
207 MenuList
->Signature
= UI_MENU_LIST_SIGNATURE
;
208 InitializeListHead (&MenuList
->ChildListHead
);
210 CopyMem (&MenuList
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
211 MenuList
->FormId
= FormId
;
212 MenuList
->Parent
= Parent
;
214 if (Parent
== NULL
) {
216 // If parent is not specified, it is the root Form of a Formset
218 InsertTailList (&gMenuList
, &MenuList
->Link
);
220 InsertTailList (&Parent
->ChildListHead
, &MenuList
->Link
);
228 Search Menu with given FormId in the parent menu and all its child menus.
230 @param Parent The parent of menu to search.
231 @param FormId The Form ID of menu to search.
233 @return A pointer to menu found or NULL if not found.
237 UiFindChildMenuList (
238 IN UI_MENU_LIST
*Parent
,
244 UI_MENU_LIST
*MenuList
;
246 if (Parent
->FormId
== FormId
) {
250 Link
= GetFirstNode (&Parent
->ChildListHead
);
251 while (!IsNull (&Parent
->ChildListHead
, Link
)) {
252 Child
= UI_MENU_LIST_FROM_LINK (Link
);
254 MenuList
= UiFindChildMenuList (Child
, FormId
);
255 if (MenuList
!= NULL
) {
259 Link
= GetNextNode (&Parent
->ChildListHead
, Link
);
267 Search Menu with given FormSetGuid and FormId in all cached menu list.
269 @param FormSetGuid The Formset GUID of the menu to search.
270 @param FormId The Form ID of menu to search.
272 @return A pointer to menu found or NULL if not found.
277 IN EFI_GUID
*FormSetGuid
,
282 UI_MENU_LIST
*MenuList
;
285 Link
= GetFirstNode (&gMenuList
);
286 while (!IsNull (&gMenuList
, Link
)) {
287 MenuList
= UI_MENU_LIST_FROM_LINK (Link
);
289 if (CompareGuid (FormSetGuid
, &MenuList
->FormSetGuid
)) {
291 // This is the formset we are looking for, find the form in this formset
293 Child
= UiFindChildMenuList (MenuList
, FormId
);
299 Link
= GetNextNode (&gMenuList
, Link
);
307 Free Menu option linked list.
315 MENU_REFRESH_ENTRY
*OldMenuRefreshEntry
;
317 while (gMenuRefreshHead
!= NULL
) {
318 OldMenuRefreshEntry
= gMenuRefreshHead
->Next
;
319 FreePool (gMenuRefreshHead
);
320 gMenuRefreshHead
= OldMenuRefreshEntry
;
323 gMenuRefreshHead
= NULL
;
337 CHAR16
*OptionString
;
338 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
341 UI_MENU_SELECTION
*Selection
;
342 FORM_BROWSER_STATEMENT
*Question
;
343 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
344 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
346 if (gMenuRefreshHead
!= NULL
) {
348 MenuRefreshEntry
= gMenuRefreshHead
;
351 // Reset FormPackage update flag
353 mHiiPackageListUpdated
= FALSE
;
356 gST
->ConOut
->SetAttribute (gST
->ConOut
, MenuRefreshEntry
->CurrentAttribute
);
358 Selection
= MenuRefreshEntry
->Selection
;
359 Question
= MenuRefreshEntry
->MenuOption
->ThisTag
;
361 Status
= GetQuestionValue (Selection
->FormSet
, Selection
->Form
, Question
, FALSE
);
362 if (EFI_ERROR (Status
)) {
367 ProcessOptions (Selection
, MenuRefreshEntry
->MenuOption
, FALSE
, &OptionString
);
369 if (OptionString
!= NULL
) {
371 // If leading spaces on OptionString - remove the spaces
373 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
376 PrintStringAt (MenuRefreshEntry
->CurrentColumn
, MenuRefreshEntry
->CurrentRow
, &OptionString
[Index
]);
377 FreePool (OptionString
);
381 // Question value may be changed, need invoke its Callback()
383 ConfigAccess
= Selection
->FormSet
->ConfigAccess
;
384 if (((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
385 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
386 Status
= ConfigAccess
->Callback (
388 EFI_BROWSER_ACTION_CHANGING
,
389 Question
->QuestionId
,
390 Question
->HiiValue
.Type
,
391 &Question
->HiiValue
.Value
,
394 if (!EFI_ERROR (Status
)) {
395 switch (ActionRequest
) {
396 case EFI_BROWSER_ACTION_REQUEST_RESET
:
397 gResetRequired
= TRUE
;
400 case EFI_BROWSER_ACTION_REQUEST_SUBMIT
:
401 SubmitForm (Selection
->FormSet
, Selection
->Form
);
404 case EFI_BROWSER_ACTION_REQUEST_EXIT
:
405 Selection
->Action
= UI_ACTION_EXIT
;
406 gNvUpdateRequired
= FALSE
;
415 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
417 } while (MenuRefreshEntry
!= NULL
);
419 if (mHiiPackageListUpdated
) {
421 // Package list is updated, force to reparse IFR binary of target Formset
423 mHiiPackageListUpdated
= FALSE
;
424 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
434 Wait for a given event to fire, or for an optional timeout to expire.
436 @param Event The event to wait for
437 @param Timeout An optional timeout value in 100 ns units.
438 @param RefreshInterval Menu refresh interval (in seconds).
440 @retval EFI_SUCCESS Event fired before Timeout expired.
441 @retval EFI_TIME_OUT Timout expired before Event fired.
445 UiWaitForSingleEvent (
447 IN UINT64 Timeout
, OPTIONAL
448 IN UINT8 RefreshInterval OPTIONAL
453 EFI_EVENT TimerEvent
;
454 EFI_EVENT WaitList
[2];
458 // Create a timer event
460 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
461 if (!EFI_ERROR (Status
)) {
463 // Set the timer event
472 // Wait for the original event or the timer
475 WaitList
[1] = TimerEvent
;
476 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
477 gBS
->CloseEvent (TimerEvent
);
480 // If the timer expired, change the return to timed out
482 if (!EFI_ERROR (Status
) && Index
== 1) {
483 Status
= EFI_TIMEOUT
;
488 // Update screen every second
490 if (RefreshInterval
== 0) {
491 Timeout
= ONE_SECOND
;
493 Timeout
= RefreshInterval
* ONE_SECOND
;
497 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
500 // Set the timer event
509 // Wait for the original event or the timer
512 WaitList
[1] = TimerEvent
;
513 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
516 // If the timer expired, update anything that needs a refresh and keep waiting
518 if (!EFI_ERROR (Status
) && Index
== 1) {
519 Status
= EFI_TIMEOUT
;
520 if (RefreshInterval
!= 0) {
521 Status
= RefreshForm ();
525 gBS
->CloseEvent (TimerEvent
);
526 } while (Status
== EFI_TIMEOUT
);
534 Add one menu option by specified description and context.
536 @param String String description for this option.
537 @param Handle Hii handle for the package list.
538 @param Statement Statement of this Menu Option.
539 @param NumberOfLines Display lines for this Menu Option.
540 @param MenuItemCount The index for this Option in the Menu.
542 @retval Pointer Pointer to the added Menu Option.
548 IN EFI_HII_HANDLE Handle
,
549 IN FORM_BROWSER_STATEMENT
*Statement
,
550 IN UINT16 NumberOfLines
,
551 IN UINT16 MenuItemCount
554 UI_MENU_OPTION
*MenuOption
;
561 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
563 // Add three MenuOptions for Date/Time
564 // Data format : [01/02/2004] [11:22:33]
565 // Line number : 0 0 1 0 0 1
570 if (Statement
->Storage
== NULL
) {
572 // For RTC type of date/time, set default refresh interval to be 1 second
574 if (Statement
->RefreshInterval
== 0) {
575 Statement
->RefreshInterval
= 1;
580 for (Index
= 0; Index
< Count
; Index
++) {
581 MenuOption
= AllocateZeroPool (sizeof (UI_MENU_OPTION
));
584 MenuOption
->Signature
= UI_MENU_OPTION_SIGNATURE
;
585 MenuOption
->Description
= String
;
586 MenuOption
->Handle
= Handle
;
587 MenuOption
->ThisTag
= Statement
;
588 MenuOption
->EntryNumber
= MenuItemCount
;
592 // Override LineNumber for the MenuOption in Date/Time sequence
594 MenuOption
->Skip
= 1;
596 MenuOption
->Skip
= NumberOfLines
;
598 MenuOption
->Sequence
= Index
;
600 if (Statement
->GrayOutExpression
!= NULL
) {
601 MenuOption
->GrayOut
= Statement
->GrayOutExpression
->Result
.Value
.b
;
604 switch (Statement
->Operand
) {
605 case EFI_IFR_ORDERED_LIST_OP
:
606 case EFI_IFR_ONE_OF_OP
:
607 case EFI_IFR_NUMERIC_OP
:
608 case EFI_IFR_TIME_OP
:
609 case EFI_IFR_DATE_OP
:
610 case EFI_IFR_CHECKBOX_OP
:
611 case EFI_IFR_PASSWORD_OP
:
612 case EFI_IFR_STRING_OP
:
614 // User could change the value of these items
616 MenuOption
->IsQuestion
= TRUE
;
620 MenuOption
->IsQuestion
= FALSE
;
624 if ((Statement
->ValueExpression
!= NULL
) ||
625 ((Statement
->QuestionFlags
& EFI_IFR_FLAG_READ_ONLY
) != 0)) {
626 MenuOption
->ReadOnly
= TRUE
;
629 InsertTailList (&gMenuOption
, &MenuOption
->Link
);
637 Routine used to abstract a generic dialog interface and return the selected key or string
639 @param NumberOfLines The number of lines for the dialog box
640 @param HotKey Defines whether a single character is parsed
641 (TRUE) and returned in KeyValue or a string is
642 returned in StringBuffer. Two special characters
643 are considered when entering a string, a SCAN_ESC
644 and an CHAR_CARRIAGE_RETURN. SCAN_ESC terminates
645 string input and returns
646 @param MaximumStringSize The maximum size in bytes of a typed in string
647 (each character is a CHAR16) and the minimum
648 string returned is two bytes
649 @param StringBuffer The passed in pointer to the buffer which will
650 hold the typed in string if HotKey is FALSE
651 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
652 @param ... A series of (quantity == NumberOfLines) text
653 strings which will be used to construct the dialog
656 @retval EFI_SUCCESS Displayed dialog and received user interaction
657 @retval EFI_INVALID_PARAMETER One of the parameters was invalid (e.g.
658 (StringBuffer == NULL) && (HotKey == FALSE))
659 @retval EFI_DEVICE_ERROR User typed in an ESC character to exit the routine
665 IN UINTN NumberOfLines
,
667 IN UINTN MaximumStringSize
,
668 OUT CHAR16
*StringBuffer
,
669 OUT EFI_INPUT_KEY
*KeyValue
,
678 CHAR16
*BufferedString
;
685 BOOLEAN SelectionComplete
;
687 UINTN CurrentAttribute
;
688 UINTN DimensionsWidth
;
689 UINTN DimensionsHeight
;
691 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
692 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
694 SelectionComplete
= FALSE
;
696 TempString
= AllocateZeroPool (MaximumStringSize
* 2);
697 BufferedString
= AllocateZeroPool (MaximumStringSize
* 2);
698 CurrentAttribute
= gST
->ConOut
->Mode
->Attribute
;
701 ASSERT (BufferedString
);
703 VA_START (Marker
, KeyValue
);
706 // Zero the outgoing buffer
708 ZeroMem (StringBuffer
, MaximumStringSize
);
711 if (KeyValue
== NULL
) {
712 return EFI_INVALID_PARAMETER
;
715 if (StringBuffer
== NULL
) {
716 return EFI_INVALID_PARAMETER
;
722 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
727 // Determine the largest string in the dialog box
728 // Notice we are starting with 1 since String is the first string
730 for (Count
= 0; Count
< NumberOfLines
; Count
++) {
731 StackString
= VA_ARG (Marker
, CHAR16
*);
733 if (StackString
[0] == L
' ') {
734 InputOffset
= Count
+ 1;
737 if ((GetStringWidth (StackString
) / 2) > LargestString
) {
739 // Size of the string visually and subtract the width by one for the null-terminator
741 LargestString
= (GetStringWidth (StackString
) / 2);
746 Start
= (DimensionsWidth
- LargestString
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
747 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
754 VA_START (Marker
, KeyValue
);
755 CreateSharedPopUp (LargestString
, NumberOfLines
, Marker
);
759 // Take the first key typed and report it back?
762 Status
= WaitForKeyStroke (&Key
);
763 ASSERT_EFI_ERROR (Status
);
764 CopyMem (KeyValue
, &Key
, sizeof (EFI_INPUT_KEY
));
768 Status
= WaitForKeyStroke (&Key
);
770 switch (Key
.UnicodeChar
) {
772 switch (Key
.ScanCode
) {
774 FreePool (TempString
);
775 FreePool (BufferedString
);
776 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
777 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
778 return EFI_DEVICE_ERROR
;
786 case CHAR_CARRIAGE_RETURN
:
787 SelectionComplete
= TRUE
;
788 FreePool (TempString
);
789 FreePool (BufferedString
);
790 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
791 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
796 if (StringBuffer
[0] != CHAR_NULL
) {
797 for (Index
= 0; StringBuffer
[Index
] != CHAR_NULL
; Index
++) {
798 TempString
[Index
] = StringBuffer
[Index
];
801 // Effectively truncate string by 1 character
803 TempString
[Index
- 1] = CHAR_NULL
;
804 StrCpy (StringBuffer
, TempString
);
809 // If it is the beginning of the string, don't worry about checking maximum limits
811 if ((StringBuffer
[0] == CHAR_NULL
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
812 StrnCpy (StringBuffer
, &Key
.UnicodeChar
, 1);
813 StrnCpy (TempString
, &Key
.UnicodeChar
, 1);
814 } else if ((GetStringWidth (StringBuffer
) < MaximumStringSize
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
815 KeyPad
[0] = Key
.UnicodeChar
;
816 KeyPad
[1] = CHAR_NULL
;
817 StrCat (StringBuffer
, KeyPad
);
818 StrCat (TempString
, KeyPad
);
821 // If the width of the input string is now larger than the screen, we nee to
822 // adjust the index to start printing portions of the string
824 SetUnicodeMem (BufferedString
, LargestString
, L
' ');
826 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
828 if ((GetStringWidth (StringBuffer
) / 2) > (DimensionsWidth
- 2)) {
829 Index
= (GetStringWidth (StringBuffer
) / 2) - DimensionsWidth
+ 2;
834 for (Count
= 0; Index
+ 1 < GetStringWidth (StringBuffer
) / 2; Index
++, Count
++) {
835 BufferedString
[Count
] = StringBuffer
[Index
];
838 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
841 } while (!SelectionComplete
);
844 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
845 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
850 Draw a pop up windows based on the dimension, number of lines and
853 @param RequestedWidth The width of the pop-up.
854 @param NumberOfLines The number of lines.
855 @param Marker The variable argument list for the list of string to be printed.
860 IN UINTN RequestedWidth
,
861 IN UINTN NumberOfLines
,
873 UINTN DimensionsWidth
;
874 UINTN DimensionsHeight
;
876 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
877 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
879 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
881 if ((RequestedWidth
+ 2) > DimensionsWidth
) {
882 RequestedWidth
= DimensionsWidth
- 2;
886 // Subtract the PopUp width from total Columns, allow for one space extra on
887 // each end plus a border.
889 Start
= (DimensionsWidth
- RequestedWidth
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
890 End
= Start
+ RequestedWidth
+ 1;
892 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
893 Bottom
= Top
+ NumberOfLines
+ 2;
895 Character
= BOXDRAW_DOWN_RIGHT
;
896 PrintCharAt (Start
, Top
, Character
);
897 Character
= BOXDRAW_HORIZONTAL
;
898 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
899 PrintChar (Character
);
902 Character
= BOXDRAW_DOWN_LEFT
;
903 PrintChar (Character
);
904 Character
= BOXDRAW_VERTICAL
;
907 for (Index
= Top
; Index
+ 2 < Bottom
; Index
++, Count
++) {
908 String
= VA_ARG (Marker
, CHAR16
*);
911 // This will clear the background of the line - we never know who might have been
912 // here before us. This differs from the next clear in that it used the non-reverse
913 // video for normal printing.
915 if (GetStringWidth (String
) / 2 > 1) {
916 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
920 // Passing in a space results in the assumption that this is where typing will occur
922 if (String
[0] == L
' ') {
923 ClearLines (Start
+ 1, End
- 1, Index
+ 1, Index
+ 1, POPUP_INVERSE_TEXT
| POPUP_INVERSE_BACKGROUND
);
927 // Passing in a NULL results in a blank space
929 if (String
[0] == CHAR_NULL
) {
930 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
934 ((DimensionsWidth
- GetStringWidth (String
) / 2) / 2) + gScreenDimensions
.LeftColumn
+ 1,
938 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
939 PrintCharAt (Start
, Index
+ 1, Character
);
940 PrintCharAt (End
- 1, Index
+ 1, Character
);
943 Character
= BOXDRAW_UP_RIGHT
;
944 PrintCharAt (Start
, Bottom
- 1, Character
);
945 Character
= BOXDRAW_HORIZONTAL
;
946 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
947 PrintChar (Character
);
950 Character
= BOXDRAW_UP_LEFT
;
951 PrintChar (Character
);
955 Draw a pop up windows based on the dimension, number of lines and
958 @param RequestedWidth The width of the pop-up.
959 @param NumberOfLines The number of lines.
960 @param ... A series of text strings that displayed in the pop-up.
965 CreateMultiStringPopUp (
966 IN UINTN RequestedWidth
,
967 IN UINTN NumberOfLines
,
973 VA_START (Marker
, NumberOfLines
);
975 CreateSharedPopUp (RequestedWidth
, NumberOfLines
, Marker
);
982 Update status bar on the bottom of menu.
984 @param MessageType The type of message to be shown.
985 @param Flags The flags in Question header.
986 @param State Set or clear.
991 IN UINTN MessageType
,
997 CHAR16
*NvUpdateMessage
;
998 CHAR16
*InputErrorMessage
;
1000 NvUpdateMessage
= GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE
), gHiiHandle
);
1001 InputErrorMessage
= GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE
), gHiiHandle
);
1003 switch (MessageType
) {
1006 gST
->ConOut
->SetAttribute (gST
->ConOut
, ERROR_TEXT
);
1008 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
,
1009 gScreenDimensions
.BottomRow
- 1,
1014 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextHighlightColor
));
1015 for (Index
= 0; Index
< (GetStringWidth (InputErrorMessage
) - 2) / 2; Index
++) {
1016 PrintAt (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ Index
, gScreenDimensions
.BottomRow
- 1, L
" ");
1019 mInputError
= FALSE
;
1023 case NV_UPDATE_REQUIRED
:
1024 if ((gClassOfVfr
& FORMSET_CLASS_FRONT_PAGE
) != FORMSET_CLASS_FRONT_PAGE
) {
1026 gST
->ConOut
->SetAttribute (gST
->ConOut
, INFO_TEXT
);
1028 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
,
1029 gScreenDimensions
.BottomRow
- 1,
1032 gResetRequired
= (BOOLEAN
) (gResetRequired
| ((Flags
& EFI_IFR_FLAG_RESET_REQUIRED
) == EFI_IFR_FLAG_RESET_REQUIRED
));
1034 gNvUpdateRequired
= TRUE
;
1036 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextHighlightColor
));
1037 for (Index
= 0; Index
< (GetStringWidth (NvUpdateMessage
) - 2) / 2; Index
++) {
1039 (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ Index
),
1040 gScreenDimensions
.BottomRow
- 1,
1045 gNvUpdateRequired
= FALSE
;
1050 case REFRESH_STATUS_BAR
:
1052 UpdateStatusBar (INPUT_ERROR
, Flags
, TRUE
);
1055 if (gNvUpdateRequired
) {
1056 UpdateStatusBar (NV_UPDATE_REQUIRED
, Flags
, TRUE
);
1064 FreePool (InputErrorMessage
);
1065 FreePool (NvUpdateMessage
);
1071 Get the supported width for a particular op-code
1073 @param Statement The FORM_BROWSER_STATEMENT structure passed in.
1074 @param Handle The handle in the HII database being used
1076 @return Returns the number of CHAR16 characters that is support.
1081 IN FORM_BROWSER_STATEMENT
*Statement
,
1082 IN EFI_HII_HANDLE Handle
1092 // See if the second text parameter is really NULL
1094 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1095 String
= GetToken (Statement
->TextTwo
, Handle
);
1096 Size
= StrLen (String
);
1100 if ((Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1101 (Statement
->Operand
== EFI_IFR_REF_OP
) ||
1102 (Statement
->Operand
== EFI_IFR_PASSWORD_OP
) ||
1103 (Statement
->Operand
== EFI_IFR_ACTION_OP
) ||
1104 (Statement
->Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1106 // Allow a wide display if text op-code and no secondary text op-code
1108 ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Size
== 0))
1110 Width
= (UINT16
) (gPromptBlockWidth
+ gOptionBlockWidth
);
1112 Width
= (UINT16
) gPromptBlockWidth
;
1115 if (Statement
->InSubtitle
) {
1116 Width
-= SUBTITLE_INDENT
;
1119 return (UINT16
) (Width
- LEFT_SKIPPED_COLUMNS
);
1123 Will copy LineWidth amount of a string in the OutputString buffer and return the
1124 number of CHAR16 characters that were copied into the OutputString buffer.
1126 @param InputString String description for this option.
1127 @param LineWidth Width of the desired string to extract in CHAR16
1129 @param Index Where in InputString to start the copy process
1130 @param OutputString Buffer to copy the string into
1132 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.
1137 IN CHAR16
*InputString
,
1138 IN UINT16 LineWidth
,
1139 IN OUT UINTN
*Index
,
1140 OUT CHAR16
**OutputString
1146 if (GetLineByWidthFinished
) {
1147 GetLineByWidthFinished
= FALSE
;
1154 *OutputString
= AllocateZeroPool (((UINTN
) (LineWidth
+ 1) * 2));
1157 // Ensure we have got a valid buffer
1159 if (*OutputString
!= NULL
) {
1162 //NARROW_CHAR can not be printed in screen, so if a line only contain the two CHARs: 'NARROW_CHAR + CHAR_CARRIAGE_RETURN' , it is a empty line in Screen.
1163 //To avoid displaying this empty line in screen, just skip the two CHARs here.
1165 if ((InputString
[*Index
] == NARROW_CHAR
) && (InputString
[*Index
+ 1] == CHAR_CARRIAGE_RETURN
)) {
1166 *Index
= *Index
+ 2;
1170 // Fast-forward the string and see if there is a carriage-return in the string
1172 for (; (InputString
[*Index
+ Count2
] != CHAR_CARRIAGE_RETURN
) && (Count2
!= LineWidth
); Count2
++)
1176 // Copy the desired LineWidth of data to the output buffer.
1177 // Also make sure that we don't copy more than the string.
1178 // Also make sure that if there are linefeeds, we account for them.
1180 if ((StrSize (&InputString
[*Index
]) <= ((UINTN
) (LineWidth
+ 1) * 2)) &&
1181 (StrSize (&InputString
[*Index
]) <= ((UINTN
) (Count2
+ 1) * 2))
1184 // Convert to CHAR16 value and show that we are done with this operation
1186 LineWidth
= (UINT16
) ((StrSize (&InputString
[*Index
]) - 2) / 2);
1187 if (LineWidth
!= 0) {
1188 GetLineByWidthFinished
= TRUE
;
1191 if (Count2
== LineWidth
) {
1193 // Rewind the string from the maximum size until we see a space to break the line
1195 for (; (InputString
[*Index
+ LineWidth
] != CHAR_SPACE
) && (LineWidth
!= 0); LineWidth
--)
1197 if (LineWidth
== 0) {
1205 CopyMem (*OutputString
, &InputString
[*Index
], LineWidth
* 2);
1208 // If currently pointing to a space, increment the index to the first non-space character
1211 (InputString
[*Index
+ LineWidth
] == CHAR_SPACE
) || (InputString
[*Index
+ LineWidth
] == CHAR_CARRIAGE_RETURN
);
1215 *Index
= (UINT16
) (*Index
+ LineWidth
);
1224 Update display lines for a Menu Option.
1226 @param Selection The user's selection.
1227 @param MenuOption The MenuOption to be checked.
1228 @param OptionalString The option string.
1229 @param SkipValue The number of lins to skip.
1233 UpdateOptionSkipLines (
1234 IN UI_MENU_SELECTION
*Selection
,
1235 IN UI_MENU_OPTION
*MenuOption
,
1236 OUT CHAR16
**OptionalString
,
1244 CHAR16
*OutputString
;
1245 CHAR16
*OptionString
;
1248 OptionString
= *OptionalString
;
1249 OutputString
= NULL
;
1251 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1253 if (OptionString
!= NULL
) {
1254 Width
= (UINT16
) gOptionBlockWidth
;
1258 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1260 // If there is more string to process print on the next row and increment the Skip value
1262 if (StrLen (&OptionString
[Index
]) != 0) {
1263 if (SkipValue
== 0) {
1266 // Since the Number of lines for this menu entry may or may not be reflected accurately
1267 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1268 // some testing to ensure we are keeping this in-sync.
1270 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1272 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1278 FreePool (OutputString
);
1279 if (SkipValue
!= 0) {
1287 *OptionalString
= OptionString
;
1292 Check whether this Menu Option could be highlighted.
1294 This is an internal function.
1296 @param MenuOption The MenuOption to be checked.
1298 @retval TRUE This Menu Option is selectable.
1299 @retval FALSE This Menu Option could not be selected.
1304 UI_MENU_OPTION
*MenuOption
1307 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1308 MenuOption
->GrayOut
|| MenuOption
->ReadOnly
) {
1317 Determine if the menu is the last menu that can be selected.
1319 This is an internal function.
1321 @param Direction The scroll direction. False is down. True is up.
1322 @param CurrentPos The current focus.
1324 @return FALSE -- the menu isn't the last menu that can be selected.
1325 @return TRUE -- the menu is the last menu that can be selected.
1330 IN BOOLEAN Direction
,
1331 IN LIST_ENTRY
*CurrentPos
1335 UI_MENU_OPTION
*MenuOption
;
1337 Temp
= Direction
? CurrentPos
->BackLink
: CurrentPos
->ForwardLink
;
1339 if (Temp
== &gMenuOption
) {
1343 for (; Temp
!= &gMenuOption
; Temp
= Direction
? Temp
->BackLink
: Temp
->ForwardLink
) {
1344 MenuOption
= MENU_OPTION_FROM_LINK (Temp
);
1345 if (IsSelectable (MenuOption
)) {
1355 Move to next selectable statement.
1357 This is an internal function.
1359 @param GoUp The navigation direction. TRUE: up, FALSE: down.
1360 @param CurrentPosition Current position.
1362 @return The row distance from current MenuOption to next selectable MenuOption.
1366 MoveToNextStatement (
1368 IN OUT LIST_ENTRY
**CurrentPosition
1374 UI_MENU_OPTION
*NextMenuOption
;
1377 Pos
= *CurrentPosition
;
1381 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1382 if (IsSelectable (NextMenuOption
)) {
1385 if ((GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &gMenuOption
) {
1389 Distance
+= NextMenuOption
->Skip
;
1390 Pos
= (GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1395 // If we hit end there is still no statement can be focused,
1396 // we go backwards to find the statement can be focused.
1399 Pos
= *CurrentPosition
;
1402 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1403 if (IsSelectable (NextMenuOption
)) {
1406 if ((!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &gMenuOption
) {
1410 Distance
-= NextMenuOption
->Skip
;
1411 Pos
= (!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1415 *CurrentPosition
= &NextMenuOption
->Link
;
1421 Adjust Data and Time position accordingly.
1422 Data format : [01/02/2004] [11:22:33]
1423 Line number : 0 0 1 0 0 1
1425 This is an internal function.
1427 @param DirectionUp the up or down direction. False is down. True is
1429 @param CurrentPosition Current position. On return: Point to the last
1430 Option (Year or Second) if up; Point to the first
1431 Option (Month or Hour) if down.
1433 @return Return line number to pad. It is possible that we stand on a zero-advance
1434 @return data or time opcode, so pad one line when we judge if we are going to scroll outside.
1438 AdjustDateAndTimePosition (
1439 IN BOOLEAN DirectionUp
,
1440 IN OUT LIST_ENTRY
**CurrentPosition
1444 LIST_ENTRY
*NewPosition
;
1445 UI_MENU_OPTION
*MenuOption
;
1446 UINTN PadLineNumber
;
1449 NewPosition
= *CurrentPosition
;
1450 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1452 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
1453 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
1455 // Calculate the distance from current position to the last Date/Time MenuOption
1458 while (MenuOption
->Skip
== 0) {
1460 NewPosition
= NewPosition
->ForwardLink
;
1461 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1465 NewPosition
= *CurrentPosition
;
1468 // Since the behavior of hitting the up arrow on a Date/Time MenuOption is intended
1469 // to be one that back to the previous set of MenuOptions, we need to advance to the first
1470 // Date/Time MenuOption and leave the remaining logic in CfUiUp intact so the appropriate
1471 // checking can be done.
1473 while (Count
++ < 2) {
1474 NewPosition
= NewPosition
->BackLink
;
1478 // Since the behavior of hitting the down arrow on a Date/Time MenuOption is intended
1479 // to be one that progresses to the next set of MenuOptions, we need to advance to the last
1480 // Date/Time MenuOption and leave the remaining logic in CfUiDown intact so the appropriate
1481 // checking can be done.
1483 while (Count
-- > 0) {
1484 NewPosition
= NewPosition
->ForwardLink
;
1488 *CurrentPosition
= NewPosition
;
1491 return PadLineNumber
;
1495 Find HII Handle in the HII database associated with given Device Path.
1497 If DevicePath is NULL, then ASSERT.
1499 @param DevicePath Device Path associated with the HII package list
1502 @retval Handle HII package list Handle associated with the Device
1504 @retval NULL Hii Package list handle is not found.
1509 DevicePathToHiiHandle (
1510 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1514 EFI_DEVICE_PATH_PROTOCOL
*TmpDevicePath
;
1519 EFI_HANDLE DriverHandle
;
1520 EFI_HII_HANDLE
*HiiHandles
;
1521 EFI_HII_HANDLE HiiHandle
;
1523 ASSERT (DevicePath
!= NULL
);
1525 TmpDevicePath
= DevicePath
;
1527 // Locate Device Path Protocol handle buffer
1529 Status
= gBS
->LocateDevicePath (
1530 &gEfiDevicePathProtocolGuid
,
1534 if (EFI_ERROR (Status
) || !IsDevicePathEnd (TmpDevicePath
)) {
1539 // Retrieve all HII Handles from HII database
1541 BufferSize
= 0x1000;
1542 HiiHandles
= AllocatePool (BufferSize
);
1543 ASSERT (HiiHandles
!= NULL
);
1544 Status
= mHiiDatabase
->ListPackageLists (
1546 EFI_HII_PACKAGE_TYPE_ALL
,
1551 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1552 FreePool (HiiHandles
);
1553 HiiHandles
= AllocatePool (BufferSize
);
1554 ASSERT (HiiHandles
!= NULL
);
1556 Status
= mHiiDatabase
->ListPackageLists (
1558 EFI_HII_PACKAGE_TYPE_ALL
,
1565 if (EFI_ERROR (Status
)) {
1566 FreePool (HiiHandles
);
1571 // Search Hii Handle by Driver Handle
1574 HandleCount
= BufferSize
/ sizeof (EFI_HII_HANDLE
);
1575 for (Index
= 0; Index
< HandleCount
; Index
++) {
1576 Status
= mHiiDatabase
->GetPackageListHandle (
1581 if (!EFI_ERROR (Status
) && (Handle
== DriverHandle
)) {
1582 HiiHandle
= HiiHandles
[Index
];
1587 FreePool (HiiHandles
);
1592 Display menu and wait for user to select one menu option, then return it.
1593 If AutoBoot is enabled, then if user doesn't select any option,
1594 after period of time, it will automatically return the first menu option.
1596 @param Selection Menu selection.
1598 @retval EFI_SUCESSS This function always return successfully for now.
1603 IN OUT UI_MENU_SELECTION
*Selection
1609 UINTN DistanceValue
;
1621 CHAR16
*OptionString
;
1622 CHAR16
*OutputString
;
1623 CHAR16
*FormattedString
;
1635 LIST_ENTRY
*TopOfScreen
;
1636 LIST_ENTRY
*SavedListEntry
;
1637 UI_MENU_OPTION
*MenuOption
;
1638 UI_MENU_OPTION
*NextMenuOption
;
1639 UI_MENU_OPTION
*SavedMenuOption
;
1640 UI_MENU_OPTION
*PreviousMenuOption
;
1641 UI_CONTROL_FLAG ControlFlag
;
1642 EFI_SCREEN_DESCRIPTOR LocalScreen
;
1643 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
1644 UI_SCREEN_OPERATION ScreenOperation
;
1645 UINT8 MinRefreshInterval
;
1648 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1649 FORM_BROWSER_STATEMENT
*Statement
;
1651 UINT8
*DevicePathBuffer
;
1653 UI_MENU_LIST
*CurrentMenu
;
1654 UI_MENU_LIST
*MenuList
;
1655 FORM_BROWSER_FORM
*RefForm
;
1657 CopyMem (&LocalScreen
, &gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1659 Status
= EFI_SUCCESS
;
1660 FormattedString
= NULL
;
1661 OptionString
= NULL
;
1662 ScreenOperation
= UiNoOperation
;
1664 MinRefreshInterval
= 0;
1667 OutputString
= NULL
;
1672 MenuRefreshEntry
= gMenuRefreshHead
;
1674 NextMenuOption
= NULL
;
1675 PreviousMenuOption
= NULL
;
1676 SavedMenuOption
= NULL
;
1679 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
1681 if ((gClassOfVfr
& FORMSET_CLASS_FRONT_PAGE
) == FORMSET_CLASS_FRONT_PAGE
){
1682 TopRow
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1683 Row
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1685 TopRow
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1686 Row
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1689 Col
= LocalScreen
.LeftColumn
+ LEFT_SKIPPED_COLUMNS
;
1690 BottomRow
= LocalScreen
.BottomRow
- STATUS_BAR_HEIGHT
- FOOTER_HEIGHT
- SCROLL_ARROW_HEIGHT
- 1;
1692 Selection
->TopRow
= TopRow
;
1693 Selection
->BottomRow
= BottomRow
;
1694 Selection
->PromptCol
= Col
;
1695 Selection
->OptionCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1696 Selection
->Statement
= NULL
;
1698 TopOfScreen
= gMenuOption
.ForwardLink
;
1703 // Find current Menu
1705 CurrentMenu
= UiFindMenuList (&Selection
->FormSetGuid
, Selection
->FormId
);
1706 if (CurrentMenu
== NULL
) {
1708 // Current menu not found, add it to the menu tree
1710 CurrentMenu
= UiAddMenuList (NULL
, &Selection
->FormSetGuid
, Selection
->FormId
);
1712 ASSERT (CurrentMenu
!= NULL
);
1714 if (Selection
->QuestionId
== 0) {
1716 // Highlight not specified, fetch it from cached menu
1718 Selection
->QuestionId
= CurrentMenu
->QuestionId
;
1722 // Get user's selection
1724 NewPos
= gMenuOption
.ForwardLink
;
1726 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
1727 UpdateStatusBar (REFRESH_STATUS_BAR
, (UINT8
) 0, TRUE
);
1729 ControlFlag
= CfInitialization
;
1730 Selection
->Action
= UI_ACTION_NONE
;
1732 switch (ControlFlag
) {
1733 case CfInitialization
:
1734 if (IsListEmpty (&gMenuOption
)) {
1735 ControlFlag
= CfReadKey
;
1737 ControlFlag
= CfCheckSelection
;
1741 case CfCheckSelection
:
1742 if (Selection
->Action
!= UI_ACTION_NONE
) {
1743 ControlFlag
= CfExit
;
1745 ControlFlag
= CfRepaint
;
1750 ControlFlag
= CfRefreshHighLight
;
1760 Temp
= (UINTN
) SkipValue
;
1761 Temp2
= (UINTN
) SkipValue
;
1764 LocalScreen
.LeftColumn
,
1765 LocalScreen
.RightColumn
,
1766 TopRow
- SCROLL_ARROW_HEIGHT
,
1767 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1768 PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
1771 UiFreeRefreshList ();
1772 MinRefreshInterval
= 0;
1774 for (Link
= TopOfScreen
; Link
!= &gMenuOption
; Link
= Link
->ForwardLink
) {
1775 MenuOption
= MENU_OPTION_FROM_LINK (Link
);
1776 MenuOption
->Row
= Row
;
1777 MenuOption
->Col
= Col
;
1778 MenuOption
->OptCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1780 Statement
= MenuOption
->ThisTag
;
1781 if (Statement
->InSubtitle
) {
1782 MenuOption
->Col
+= SUBTITLE_INDENT
;
1785 if (MenuOption
->GrayOut
) {
1786 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
1788 if (Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) {
1789 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserSubtitleTextColor
) | FIELD_BACKGROUND
);
1793 Width
= GetWidth (Statement
, MenuOption
->Handle
);
1796 if (Statement
->Operand
== EFI_IFR_REF_OP
&&
1797 ((gClassOfVfr
& FORMSET_CLASS_PLATFORM_SETUP
) == FORMSET_CLASS_PLATFORM_SETUP
) &&
1798 MenuOption
->Col
> 2) {
1800 // Print Arrow for Goto button.
1803 MenuOption
->Col
- 2,
1806 GEOMETRICSHAPE_RIGHT_TRIANGLE
1810 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
1811 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1812 PrintStringAt (MenuOption
->Col
, Row
, OutputString
);
1815 // If there is more string to process print on the next row and increment the Skip value
1817 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
1823 FreePool (OutputString
);
1832 Status
= ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1833 if (EFI_ERROR (Status
)) {
1835 // Repaint to clear possible error prompt pop-up
1839 ControlFlag
= CfRepaint
;
1843 if (OptionString
!= NULL
) {
1844 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
1846 // If leading spaces on OptionString - remove the spaces
1848 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++) {
1849 MenuOption
->OptCol
++;
1852 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1853 OptionString
[Count
] = OptionString
[Index
];
1857 OptionString
[Count
] = CHAR_NULL
;
1861 // If Question request refresh, register the op-code
1863 if (Statement
->RefreshInterval
!= 0) {
1865 // Menu will be refreshed at minimal interval of all Questions
1866 // which have refresh request
1868 if (MinRefreshInterval
== 0 || Statement
->RefreshInterval
< MinRefreshInterval
) {
1869 MinRefreshInterval
= Statement
->RefreshInterval
;
1872 if (gMenuRefreshHead
== NULL
) {
1873 MenuRefreshEntry
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1874 ASSERT (MenuRefreshEntry
!= NULL
);
1875 MenuRefreshEntry
->MenuOption
= MenuOption
;
1876 MenuRefreshEntry
->Selection
= Selection
;
1877 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1878 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1879 MenuRefreshEntry
->CurrentAttribute
= PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
;
1880 gMenuRefreshHead
= MenuRefreshEntry
;
1883 // Advance to the last entry
1885 for (MenuRefreshEntry
= gMenuRefreshHead
;
1886 MenuRefreshEntry
->Next
!= NULL
;
1887 MenuRefreshEntry
= MenuRefreshEntry
->Next
1890 MenuRefreshEntry
->Next
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1891 ASSERT (MenuRefreshEntry
->Next
!= NULL
);
1892 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
1893 MenuRefreshEntry
->MenuOption
= MenuOption
;
1894 MenuRefreshEntry
->Selection
= Selection
;
1895 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1896 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1897 MenuRefreshEntry
->CurrentAttribute
= PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
;
1901 Width
= (UINT16
) gOptionBlockWidth
;
1904 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1905 if ((Temp2
== 0) && (Row
<= BottomRow
)) {
1906 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1909 // If there is more string to process print on the next row and increment the Skip value
1911 if (StrLen (&OptionString
[Index
]) != 0) {
1915 // Since the Number of lines for this menu entry may or may not be reflected accurately
1916 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1917 // some testing to ensure we are keeping this in-sync.
1919 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1921 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1927 FreePool (OutputString
);
1936 FreePool (OptionString
);
1939 // If this is a text op with secondary text information
1941 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1942 StringPtr
= GetToken (Statement
->TextTwo
, MenuOption
->Handle
);
1944 Width
= (UINT16
) gOptionBlockWidth
;
1947 for (Index
= 0; GetLineByWidth (StringPtr
, Width
, &Index
, &OutputString
) != 0x0000;) {
1948 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1949 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1952 // If there is more string to process print on the next row and increment the Skip value
1954 if (StrLen (&StringPtr
[Index
]) != 0) {
1958 // Since the Number of lines for this menu entry may or may not be reflected accurately
1959 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1960 // some testing to ensure we are keeping this in-sync.
1962 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1964 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1970 FreePool (OutputString
);
1977 FreePool (StringPtr
);
1979 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
);
1982 // Need to handle the bottom of the display
1984 if (MenuOption
->Skip
> 1) {
1985 Row
+= MenuOption
->Skip
- SkipValue
;
1988 Row
+= MenuOption
->Skip
;
1991 if (Row
> BottomRow
) {
1992 if (!ValueIsScroll (FALSE
, Link
)) {
1996 Row
= BottomRow
+ 1;
2001 if (!ValueIsScroll (TRUE
, TopOfScreen
)) {
2006 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
2008 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
2009 TopRow
- SCROLL_ARROW_HEIGHT
,
2013 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
);
2017 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
2019 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
2020 BottomRow
+ SCROLL_ARROW_HEIGHT
,
2024 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
);
2031 case CfRefreshHighLight
:
2033 // MenuOption: Last menu option that need to remove hilight
2034 // MenuOption is set to NULL in Repaint
2035 // NewPos: Current menu option that need to hilight
2037 ControlFlag
= CfUpdateHelpString
;
2040 // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily
2041 // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.
2043 SavedValue
= Repaint
;
2046 if (Selection
->QuestionId
!= 0) {
2047 NewPos
= gMenuOption
.ForwardLink
;
2048 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2050 while (SavedMenuOption
->ThisTag
->QuestionId
!= Selection
->QuestionId
&& NewPos
->ForwardLink
!= &gMenuOption
) {
2051 NewPos
= NewPos
->ForwardLink
;
2052 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2054 if (SavedMenuOption
->ThisTag
->QuestionId
== Selection
->QuestionId
) {
2056 // Target Question found, find its MenuOption
2060 for (Index
= TopRow
; Index
<= BottomRow
&& Link
!= NewPos
;) {
2061 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2062 Index
+= SavedMenuOption
->Skip
;
2063 Link
= Link
->ForwardLink
;
2066 if (Link
!= NewPos
|| Index
> BottomRow
) {
2068 // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page
2071 for (Index
= TopRow
; Index
<= BottomRow
; ) {
2072 Link
= Link
->BackLink
;
2073 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2074 Index
+= SavedMenuOption
->Skip
;
2076 TopOfScreen
= Link
->ForwardLink
;
2080 ControlFlag
= CfRepaint
;
2085 // Target Question not found, highlight the default menu option
2087 NewPos
= TopOfScreen
;
2090 Selection
->QuestionId
= 0;
2093 if (NewPos
!= NULL
&& (MenuOption
== NULL
|| NewPos
!= &MenuOption
->Link
)) {
2094 if (MenuOption
!= NULL
) {
2096 // Remove highlight on last Menu Option
2098 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
2099 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
2100 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
);
2101 if (OptionString
!= NULL
) {
2102 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
2103 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
2106 // If leading spaces on OptionString - remove the spaces
2108 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
2111 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
2112 OptionString
[Count
] = OptionString
[Index
];
2116 OptionString
[Count
] = CHAR_NULL
;
2119 Width
= (UINT16
) gOptionBlockWidth
;
2120 OriginalRow
= MenuOption
->Row
;
2122 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
2123 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2124 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
2127 // If there is more string to process print on the next row and increment the Skip value
2129 if (StrLen (&OptionString
[Index
]) != 0) {
2133 FreePool (OutputString
);
2136 MenuOption
->Row
= OriginalRow
;
2138 FreePool (OptionString
);
2141 if (MenuOption
->GrayOut
) {
2142 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
2143 } else if (MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) {
2144 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserSubtitleTextColor
) | FIELD_BACKGROUND
);
2147 OriginalRow
= MenuOption
->Row
;
2148 Width
= GetWidth (MenuOption
->ThisTag
, MenuOption
->Handle
);
2150 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2151 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2152 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2155 // If there is more string to process print on the next row and increment the Skip value
2157 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
2161 FreePool (OutputString
);
2164 MenuOption
->Row
= OriginalRow
;
2165 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
);
2171 // This is only possible if we entered this page and the first menu option is
2172 // a "non-menu" item. In that case, force it UiDown
2174 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2175 if (!IsSelectable (MenuOption
)) {
2176 ASSERT (ScreenOperation
== UiNoOperation
);
2177 ScreenOperation
= UiDown
;
2178 ControlFlag
= CfScreenOperation
;
2183 // This is the current selected statement
2185 Statement
= MenuOption
->ThisTag
;
2186 Selection
->Statement
= Statement
;
2188 // Record highlight for current menu
2190 CurrentMenu
->QuestionId
= Statement
->QuestionId
;
2193 // Set reverse attribute
2195 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextHighlightColor
) | PcdGet8 (PcdBrowserFieldBackgroundHighlightColor
));
2196 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
2199 // Assuming that we have a refresh linked-list created, lets annotate the
2200 // appropriate entry that we are highlighting with its new attribute. Just prior to this
2201 // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh
2203 if (gMenuRefreshHead
!= NULL
) {
2204 for (MenuRefreshEntry
= gMenuRefreshHead
; MenuRefreshEntry
!= NULL
; MenuRefreshEntry
= MenuRefreshEntry
->Next
) {
2205 MenuRefreshEntry
->CurrentAttribute
= PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
;
2206 if (MenuRefreshEntry
->MenuOption
== MenuOption
) {
2207 MenuRefreshEntry
->CurrentAttribute
= PcdGet8 (PcdBrowserFieldTextHighlightColor
) | PcdGet8 (PcdBrowserFieldBackgroundHighlightColor
);
2212 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
2213 if (OptionString
!= NULL
) {
2214 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
2216 // If leading spaces on OptionString - remove the spaces
2218 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
2221 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
2222 OptionString
[Count
] = OptionString
[Index
];
2226 OptionString
[Count
] = CHAR_NULL
;
2228 Width
= (UINT16
) gOptionBlockWidth
;
2230 OriginalRow
= MenuOption
->Row
;
2232 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
2233 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2234 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
2237 // If there is more string to process print on the next row and increment the Skip value
2239 if (StrLen (&OptionString
[Index
]) != 0) {
2243 FreePool (OutputString
);
2246 MenuOption
->Row
= OriginalRow
;
2248 FreePool (OptionString
);
2251 OriginalRow
= MenuOption
->Row
;
2253 Width
= GetWidth (Statement
, MenuOption
->Handle
);
2255 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2256 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2257 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2260 // If there is more string to process print on the next row and increment the Skip value
2262 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
2266 FreePool (OutputString
);
2269 MenuOption
->Row
= OriginalRow
;
2274 UpdateKeyHelp (Selection
, MenuOption
, FALSE
);
2277 // Clear reverse attribute
2279 gST
->ConOut
->SetAttribute (gST
->ConOut
, PcdGet8 (PcdBrowserFieldTextColor
) | FIELD_BACKGROUND
);
2282 // Repaint flag will be used when process CfUpdateHelpString, so restore its value
2283 // if we didn't break halfway when process CfRefreshHighLight.
2285 Repaint
= SavedValue
;
2288 case CfUpdateHelpString
:
2289 ControlFlag
= CfPrepareToReadKey
;
2291 if (Repaint
|| NewLine
) {
2293 // Don't print anything if it is a NULL help token
2295 ASSERT(MenuOption
!= NULL
);
2296 if (MenuOption
->ThisTag
->Help
== 0) {
2299 StringPtr
= GetToken (MenuOption
->ThisTag
->Help
, MenuOption
->Handle
);
2302 ProcessHelpString (StringPtr
, &FormattedString
, BottomRow
- TopRow
);
2304 gST
->ConOut
->SetAttribute (gST
->ConOut
, HELP_TEXT
| FIELD_BACKGROUND
);
2306 for (Index
= 0; Index
< BottomRow
- TopRow
; Index
++) {
2308 // Pad String with spaces to simulate a clearing of the previous line
2310 for (; GetStringWidth (&FormattedString
[Index
* gHelpBlockWidth
* 2]) / 2 < gHelpBlockWidth
;) {
2311 StrCat (&FormattedString
[Index
* gHelpBlockWidth
* 2], L
" ");
2315 LocalScreen
.RightColumn
- gHelpBlockWidth
,
2317 &FormattedString
[Index
* gHelpBlockWidth
* 2]
2322 // Reset this flag every time we finish using it.
2328 case CfPrepareToReadKey
:
2329 ControlFlag
= CfReadKey
;
2330 ScreenOperation
= UiNoOperation
;
2334 ControlFlag
= CfScreenOperation
;
2337 // Wait for user's selection
2340 Status
= UiWaitForSingleEvent (gST
->ConIn
->WaitForKey
, 0, MinRefreshInterval
);
2341 } while (Status
== EFI_TIMEOUT
);
2343 if (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
) {
2345 // IFR is updated in Callback of refresh opcode, re-parse it
2347 Selection
->Statement
= NULL
;
2351 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2353 // If we encounter error, continue to read another key in.
2355 if (EFI_ERROR (Status
)) {
2356 ControlFlag
= CfReadKey
;
2360 switch (Key
.UnicodeChar
) {
2361 case CHAR_CARRIAGE_RETURN
:
2362 ScreenOperation
= UiSelect
;
2367 // We will push the adjustment of these numeric values directly to the input handler
2368 // NOTE: we won't handle manual input numeric
2373 // If the screen has no menu items, and the user didn't select UiReset
2374 // ignore the selection and go back to reading keys.
2376 if(IsListEmpty (&gMenuOption
)) {
2377 ControlFlag
= CfReadKey
;
2381 ASSERT(MenuOption
!= NULL
);
2382 Statement
= MenuOption
->ThisTag
;
2383 if ((Statement
->Operand
== EFI_IFR_DATE_OP
)
2384 || (Statement
->Operand
== EFI_IFR_TIME_OP
)
2385 || ((Statement
->Operand
== EFI_IFR_NUMERIC_OP
) && (Statement
->Step
!= 0))
2387 if (Key
.UnicodeChar
== '+') {
2388 gDirection
= SCAN_RIGHT
;
2390 gDirection
= SCAN_LEFT
;
2392 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2393 if (EFI_ERROR (Status
)) {
2395 // Repaint to clear possible error prompt pop-up
2400 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2402 if (OptionString
!= NULL
) {
2403 FreePool (OptionString
);
2409 ScreenOperation
= UiUp
;
2414 ScreenOperation
= UiDown
;
2418 if ((gClassOfVfr
& FORMSET_CLASS_FRONT_PAGE
) != FORMSET_CLASS_FRONT_PAGE
) {
2420 // If the screen has no menu items, and the user didn't select UiReset
2421 // ignore the selection and go back to reading keys.
2423 if(IsListEmpty (&gMenuOption
)) {
2424 ControlFlag
= CfReadKey
;
2428 ASSERT(MenuOption
!= NULL
);
2429 if (MenuOption
->ThisTag
->Operand
== EFI_IFR_CHECKBOX_OP
&& !MenuOption
->GrayOut
) {
2430 ScreenOperation
= UiSelect
;
2436 if (((Key
.ScanCode
== SCAN_F9
) && ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
)) ||
2437 ((Key
.ScanCode
== SCAN_F10
) && ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
))
2440 // If the function key has been disabled, just ignore the key.
2443 for (Index
= 0; Index
< sizeof (gScanCodeToOperation
) / sizeof (gScanCodeToOperation
[0]); Index
++) {
2444 if (Key
.ScanCode
== gScanCodeToOperation
[Index
].ScanCode
) {
2445 if (Key
.ScanCode
== SCAN_F9
) {
2447 // Reset to standard default
2449 DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2451 ScreenOperation
= gScanCodeToOperation
[Index
].ScreenOperation
;
2460 case CfScreenOperation
:
2461 if (ScreenOperation
!= UiReset
) {
2463 // If the screen has no menu items, and the user didn't select UiReset
2464 // ignore the selection and go back to reading keys.
2466 if (IsListEmpty (&gMenuOption
)) {
2467 ControlFlag
= CfReadKey
;
2471 // if there is nothing logical to place a cursor on, just move on to wait for a key.
2473 for (Link
= gMenuOption
.ForwardLink
; Link
!= &gMenuOption
; Link
= Link
->ForwardLink
) {
2474 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2475 if (IsSelectable (NextMenuOption
)) {
2480 if (Link
== &gMenuOption
) {
2481 ControlFlag
= CfPrepareToReadKey
;
2487 Index
< sizeof (gScreenOperationToControlFlag
) / sizeof (gScreenOperationToControlFlag
[0]);
2490 if (ScreenOperation
== gScreenOperationToControlFlag
[Index
].ScreenOperation
) {
2491 ControlFlag
= gScreenOperationToControlFlag
[Index
].ControlFlag
;
2498 ControlFlag
= CfCheckSelection
;
2500 ASSERT(MenuOption
!= NULL
);
2501 Statement
= MenuOption
->ThisTag
;
2502 if (Statement
->Operand
== EFI_IFR_TEXT_OP
) {
2507 // Keep highlight on current MenuOption
2509 Selection
->QuestionId
= Statement
->QuestionId
;
2511 switch (Statement
->Operand
) {
2512 case EFI_IFR_REF_OP
:
2513 if (Statement
->RefDevicePath
!= 0) {
2515 // Goto another Hii Package list
2517 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2519 StringPtr
= GetToken (Statement
->RefDevicePath
, Selection
->FormSet
->HiiHandle
);
2520 if (StringPtr
== NULL
) {
2522 // No device path string not found, exit
2524 Selection
->Action
= UI_ACTION_EXIT
;
2525 Selection
->Statement
= NULL
;
2528 BufferSize
= StrLen (StringPtr
) / 2;
2529 DevicePath
= AllocatePool (BufferSize
);
2530 ASSERT (DevicePath
!= NULL
);
2533 // Convert from Device Path String to DevicePath Buffer in the reverse order.
2535 DevicePathBuffer
= (UINT8
*) DevicePath
;
2536 for (Index
= 0; StringPtr
[Index
] != L
'\0'; Index
++) {
2537 TemStr
[0] = StringPtr
[Index
];
2538 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
2539 if (DigitUint8
== 0 && TemStr
[0] != L
'0') {
2541 // Invalid Hex Char as the tail.
2545 if ((Index
& 1) == 0) {
2546 DevicePathBuffer
[Index
/2] = DigitUint8
;
2548 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
2552 Selection
->Handle
= DevicePathToHiiHandle (DevicePath
);
2553 if (Selection
->Handle
== NULL
) {
2555 // If target Hii Handle not found, exit
2557 Selection
->Action
= UI_ACTION_EXIT
;
2558 Selection
->Statement
= NULL
;
2562 FreePool (StringPtr
);
2563 FreePool (DevicePath
);
2565 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2566 Selection
->FormId
= Statement
->RefFormId
;
2567 Selection
->QuestionId
= Statement
->RefQuestionId
;
2568 } else if (!CompareGuid (&Statement
->RefFormSetId
, &gZeroGuid
)) {
2570 // Goto another Formset, check for uncommitted data
2572 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2574 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2575 Selection
->FormId
= Statement
->RefFormId
;
2576 Selection
->QuestionId
= Statement
->RefQuestionId
;
2577 } else if (Statement
->RefFormId
!= 0) {
2579 // Check whether target From is suppressed.
2581 RefForm
= IdToForm (Selection
->FormSet
, Statement
->RefFormId
);
2583 if ((RefForm
!= NULL
) && (RefForm
->SuppressExpression
!= NULL
)) {
2584 Status
= EvaluateExpression (Selection
->FormSet
, RefForm
, RefForm
->SuppressExpression
);
2585 if (EFI_ERROR (Status
)) {
2589 if (RefForm
->SuppressExpression
->Result
.Value
.b
) {
2591 // Form is suppressed.
2594 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gFormSuppress
, gPressEnter
, gEmptyString
);
2595 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
2603 // Goto another form inside this formset,
2605 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2608 // Link current form so that we can always go back when someone hits the ESC
2610 MenuList
= UiFindMenuList (&Selection
->FormSetGuid
, Statement
->RefFormId
);
2611 if (MenuList
== NULL
) {
2612 MenuList
= UiAddMenuList (CurrentMenu
, &Selection
->FormSetGuid
, Statement
->RefFormId
);
2615 Selection
->FormId
= Statement
->RefFormId
;
2616 Selection
->QuestionId
= Statement
->RefQuestionId
;
2617 } else if (Statement
->RefQuestionId
!= 0) {
2619 // Goto another Question
2621 Selection
->QuestionId
= Statement
->RefQuestionId
;
2623 if ((Statement
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) {
2624 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2633 case EFI_IFR_ACTION_OP
:
2635 // Process the Config string <ConfigResp>
2637 Status
= ProcessQuestionConfig (Selection
, Statement
);
2639 if (EFI_ERROR (Status
)) {
2644 // The action button may change some Question value, so refresh the form
2646 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2649 case EFI_IFR_RESET_BUTTON_OP
:
2651 // Reset Question to default value specified by DefaultId
2653 ControlFlag
= CfUiDefault
;
2654 DefaultId
= Statement
->DefaultId
;
2659 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
2661 UpdateKeyHelp (Selection
, MenuOption
, TRUE
);
2662 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2664 if (EFI_ERROR (Status
)) {
2667 UpdateKeyHelp (Selection
, MenuOption
, FALSE
);
2669 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2672 if (OptionString
!= NULL
) {
2673 FreePool (OptionString
);
2681 // We come here when someone press ESC
2683 ControlFlag
= CfCheckSelection
;
2685 if (CurrentMenu
->Parent
!= NULL
) {
2687 // we have a parent, so go to the parent menu
2689 if (CompareGuid (&CurrentMenu
->FormSetGuid
, &CurrentMenu
->Parent
->FormSetGuid
)) {
2691 // The parent menu and current menu are in the same formset
2693 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2695 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2697 Selection
->Statement
= NULL
;
2699 Selection
->FormId
= CurrentMenu
->Parent
->FormId
;
2700 Selection
->QuestionId
= CurrentMenu
->Parent
->QuestionId
;
2703 // Clear highlight record for this menu
2705 CurrentMenu
->QuestionId
= 0;
2709 if ((gClassOfVfr
& FORMSET_CLASS_FRONT_PAGE
) == FORMSET_CLASS_FRONT_PAGE
) {
2711 // We never exit FrontPage, so skip the ESC
2713 Selection
->Action
= UI_ACTION_NONE
;
2718 // We are going to leave current FormSet, so check uncommited data in this FormSet
2720 if (gNvUpdateRequired
) {
2721 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2723 YesResponse
= gYesResponse
[0];
2724 NoResponse
= gNoResponse
[0];
2727 // If NV flag is up, prompt user
2730 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gSaveChanges
, gAreYouSure
, gEmptyString
);
2733 (Key
.ScanCode
!= SCAN_ESC
) &&
2734 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (NoResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
2735 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (YesResponse
| UPPER_LOWER_CASE_OFFSET
))
2738 if (Key
.ScanCode
== SCAN_ESC
) {
2740 // User hits the ESC key
2745 Selection
->Action
= UI_ACTION_NONE
;
2750 // If the user hits the YesResponse key
2752 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (YesResponse
| UPPER_LOWER_CASE_OFFSET
)) {
2753 Status
= SubmitForm (Selection
->FormSet
, Selection
->Form
);
2757 Selection
->Action
= UI_ACTION_EXIT
;
2758 Selection
->Statement
= NULL
;
2759 CurrentMenu
->QuestionId
= 0;
2764 ControlFlag
= CfCheckSelection
;
2765 ASSERT(MenuOption
!= NULL
);
2766 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2767 if (MenuOption
->Sequence
!= 0) {
2769 // In the middle or tail of the Date/Time op-code set, go left.
2771 ASSERT(NewPos
!= NULL
);
2772 NewPos
= NewPos
->BackLink
;
2778 ControlFlag
= CfCheckSelection
;
2779 ASSERT(MenuOption
!= NULL
);
2780 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2781 if (MenuOption
->Sequence
!= 2) {
2783 // In the middle or tail of the Date/Time op-code set, go left.
2785 ASSERT(NewPos
!= NULL
);
2786 NewPos
= NewPos
->ForwardLink
;
2792 ControlFlag
= CfCheckSelection
;
2794 SavedListEntry
= TopOfScreen
;
2796 ASSERT(NewPos
!= NULL
);
2797 if (NewPos
->BackLink
!= &gMenuOption
) {
2800 // Adjust Date/Time position before we advance forward.
2802 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2805 // Caution that we have already rewind to the top, don't go backward in this situation.
2807 if (NewPos
->BackLink
!= &gMenuOption
) {
2808 NewPos
= NewPos
->BackLink
;
2811 Difference
= MoveToNextStatement (TRUE
, &NewPos
);
2812 PreviousMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2813 DistanceValue
= PreviousMenuOption
->Skip
;
2816 // Since the behavior of hitting the up arrow on a Date/Time op-code is intended
2817 // to be one that back to the previous set of op-codes, we need to advance to the sencond
2818 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2819 // checking can be done.
2821 DistanceValue
+= AdjustDateAndTimePosition (TRUE
, &NewPos
);
2823 ASSERT (MenuOption
!= NULL
);
2824 if (Difference
< 0) {
2826 // We want to goto previous MenuOption, but finally we go down.
2827 // it means that we hit the begining MenuOption that can be focused
2828 // so we simply scroll to the top
2830 if (SavedListEntry
!= gMenuOption
.ForwardLink
) {
2831 TopOfScreen
= gMenuOption
.ForwardLink
;
2834 } else if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
- Difference
< (INTN
) TopRow
) {
2836 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
2838 TopOfScreen
= NewPos
;
2845 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2847 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2849 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2851 SavedMenuOption
= MenuOption
;
2852 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2853 if (!IsSelectable (MenuOption
)) {
2855 // If we are at the end of the list and sitting on a text op, we need to more forward
2857 ScreenOperation
= UiDown
;
2858 ControlFlag
= CfScreenOperation
;
2862 MenuOption
= SavedMenuOption
;
2867 ControlFlag
= CfCheckSelection
;
2869 ASSERT(NewPos
!= NULL
);
2870 if (NewPos
->BackLink
== &gMenuOption
) {
2879 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2881 while ((Index
>= TopRow
) && (Link
->BackLink
!= &gMenuOption
)) {
2882 Index
= Index
- PreviousMenuOption
->Skip
;
2883 Link
= Link
->BackLink
;
2884 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2888 Difference
= MoveToNextStatement (TRUE
, &Link
);
2889 if (Difference
> 0) {
2891 // The focus MenuOption is above the TopOfScreen
2894 } else if (Difference
< 0) {
2896 // This happens when there is no MenuOption can be focused from
2897 // Current MenuOption to the first MenuOption
2899 TopOfScreen
= gMenuOption
.ForwardLink
;
2901 Index
+= Difference
;
2902 if (Index
< TopRow
) {
2906 if (NewPos
== Link
) {
2914 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2915 // Don't do this when we are already in the first page.
2917 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2918 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2922 ControlFlag
= CfCheckSelection
;
2924 ASSERT (NewPos
!= NULL
);
2925 if (NewPos
->ForwardLink
== &gMenuOption
) {
2934 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2936 while ((Index
<= BottomRow
) && (Link
->ForwardLink
!= &gMenuOption
)) {
2937 Index
= Index
+ NextMenuOption
->Skip
;
2938 Link
= Link
->ForwardLink
;
2939 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2942 Index
+= MoveToNextStatement (FALSE
, &Link
);
2943 if (Index
> BottomRow
) {
2945 // There are more MenuOption needing scrolling
2950 if (NewPos
== Link
&& Index
<= BottomRow
) {
2952 // Finally we know that NewPos is the last MenuOption can be focused.
2961 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2962 // Don't do this when we are already in the last page.
2964 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2965 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2969 ControlFlag
= CfCheckSelection
;
2971 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
2972 // to be one that progresses to the next set of op-codes, we need to advance to the last
2973 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2974 // checking can be done. The only other logic we need to introduce is that if a Date/Time
2975 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
2976 // the Date/Time op-code.
2978 SavedListEntry
= NewPos
;
2979 DistanceValue
= AdjustDateAndTimePosition (FALSE
, &NewPos
);
2981 if (NewPos
->ForwardLink
!= &gMenuOption
) {
2982 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2984 NewPos
= NewPos
->ForwardLink
;
2986 DistanceValue
+= MoveToNextStatement (FALSE
, &NewPos
);
2987 NextMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2990 // An option might be multi-line, so we need to reflect that data in the overall skip value
2992 UpdateOptionSkipLines (Selection
, NextMenuOption
, &OptionString
, (UINTN
) SkipValue
);
2993 DistanceValue
+= NextMenuOption
->Skip
;
2995 Temp
= MenuOption
->Row
+ MenuOption
->Skip
+ DistanceValue
- 1;
2996 if ((MenuOption
->Row
+ MenuOption
->Skip
== BottomRow
+ 1) &&
2997 (NextMenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
||
2998 NextMenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
3004 // If we are going to scroll, update TopOfScreen
3006 if (Temp
> BottomRow
) {
3009 // Is the current top of screen a zero-advance op-code?
3010 // If so, keep moving forward till we hit a >0 advance op-code
3012 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
3015 // If bottom op-code is more than one line or top op-code is more than one line
3017 if ((DistanceValue
> 1) || (MenuOption
->Skip
> 1)) {
3019 // Is the bottom op-code greater than or equal in size to the top op-code?
3021 if ((Temp
- BottomRow
) >= (SavedMenuOption
->Skip
- OldSkipValue
)) {
3023 // Skip the top op-code
3025 TopOfScreen
= TopOfScreen
->ForwardLink
;
3026 Difference
= (Temp
- BottomRow
) - (SavedMenuOption
->Skip
- OldSkipValue
);
3028 OldSkipValue
= Difference
;
3030 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
3033 // If we have a remainder, skip that many more op-codes until we drain the remainder
3035 while (Difference
>= (INTN
) SavedMenuOption
->Skip
) {
3037 // Since the Difference is greater than or equal to this op-code's skip value, skip it
3039 Difference
= Difference
- (INTN
) SavedMenuOption
->Skip
;
3040 TopOfScreen
= TopOfScreen
->ForwardLink
;
3041 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
3044 // Since we will act on this op-code in the next routine, and increment the
3045 // SkipValue, set the skips to one less than what is required.
3047 SkipValue
= Difference
- 1;
3051 // Since we will act on this op-code in the next routine, and increment the
3052 // SkipValue, set the skips to one less than what is required.
3054 SkipValue
= OldSkipValue
+ (Temp
- BottomRow
) - 1;
3057 if ((OldSkipValue
+ 1) == (INTN
) SavedMenuOption
->Skip
) {
3058 TopOfScreen
= TopOfScreen
->ForwardLink
;
3061 SkipValue
= OldSkipValue
;
3065 // If the op-code at the top of the screen is more than one line, let's not skip it yet
3066 // Let's set a skip flag to smoothly scroll the top of the screen.
3068 if (SavedMenuOption
->Skip
> 1) {
3069 if (SavedMenuOption
== NextMenuOption
) {
3074 } else if (SavedMenuOption
->Skip
== 1) {
3078 TopOfScreen
= TopOfScreen
->ForwardLink
;
3080 } while (SavedMenuOption
->Skip
== 0);
3083 OldSkipValue
= SkipValue
;
3086 MenuOption
= MENU_OPTION_FROM_LINK (SavedListEntry
);
3088 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3091 SavedMenuOption
= MenuOption
;
3092 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
3093 if (!IsSelectable (MenuOption
)) {
3095 // If we are at the end of the list and sitting on a text op, we need to more forward
3097 ScreenOperation
= UiUp
;
3098 ControlFlag
= CfScreenOperation
;
3102 MenuOption
= SavedMenuOption
;
3104 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
3106 AdjustDateAndTimePosition (TRUE
, &NewPos
);
3111 ControlFlag
= CfCheckSelection
;
3116 Status
= SubmitForm (Selection
->FormSet
, Selection
->Form
);
3118 if (!EFI_ERROR (Status
)) {
3119 ASSERT(MenuOption
!= NULL
);
3120 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3121 UpdateStatusBar (NV_UPDATE_REQUIRED
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3124 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gSaveFailed
, gPressEnter
, gEmptyString
);
3125 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
3133 ControlFlag
= CfCheckSelection
;
3134 if (!Selection
->FormEditable
) {
3136 // This Form is not editable, ignore the F9 (reset to default)
3141 Status
= ExtractFormDefault (Selection
->FormSet
, Selection
->Form
, DefaultId
);
3143 if (!EFI_ERROR (Status
)) {
3144 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
3145 Selection
->Statement
= NULL
;
3148 // Show NV update flag on status bar
3150 gNvUpdateRequired
= TRUE
;
3154 case CfUiNoOperation
:
3155 ControlFlag
= CfCheckSelection
;
3159 UiFreeRefreshList ();
3161 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
3162 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, Row
+ 4);
3163 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
3164 gST
->ConOut
->OutputString (gST
->ConOut
, L
"\n");