2 Utility functions for User Interface functions.
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
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.
18 LIST_ENTRY gMenuOption
;
19 LIST_ENTRY gMenuList
= INITIALIZE_LIST_HEAD_VARIABLE (gMenuList
);
20 MENU_REFRESH_ENTRY
*gMenuRefreshHead
;
23 // Search table for UiDisplayMenu()
25 SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation
[] = {
64 SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag
[] = {
112 BOOLEAN GetLineByWidthFinished
= FALSE
;
116 Set Buffer to Value for Size bytes.
118 @param Buffer Memory to set.
119 @param Size Number of bytes to set
120 @param Value Value of the set operation.
133 while ((Size
--) != 0) {
140 Initialize Menu option list.
148 InitializeListHead (&gMenuOption
);
153 Free Menu option linked list.
161 UI_MENU_OPTION
*MenuOption
;
163 while (!IsListEmpty (&gMenuOption
)) {
164 MenuOption
= MENU_OPTION_FROM_LINK (gMenuOption
.ForwardLink
);
165 RemoveEntryList (&MenuOption
->Link
);
168 // We allocated space for this description when we did a GetToken, free it here
170 if (MenuOption
->Skip
!= 0) {
172 // For date/time, MenuOption->Description is shared by three Menu Options
173 // Data format : [01/02/2004] [11:22:33]
174 // Line number : 0 0 1 0 0 1
176 FreePool (MenuOption
->Description
);
178 FreePool (MenuOption
);
184 Create a menu with specified formset GUID and form ID, and add it as a child
185 of the given parent menu.
187 @param Parent The parent of menu to be added.
188 @param FormSetGuid The Formset Guid of menu to be added.
189 @param FormId The Form ID of menu to be added.
191 @return A pointer to the newly added menu or NULL if memory is insufficient.
196 IN OUT UI_MENU_LIST
*Parent
,
197 IN EFI_GUID
*FormSetGuid
,
201 UI_MENU_LIST
*MenuList
;
203 MenuList
= AllocateZeroPool (sizeof (UI_MENU_LIST
));
204 if (MenuList
== NULL
) {
208 MenuList
->Signature
= UI_MENU_LIST_SIGNATURE
;
209 InitializeListHead (&MenuList
->ChildListHead
);
211 CopyMem (&MenuList
->FormSetGuid
, FormSetGuid
, sizeof (EFI_GUID
));
212 MenuList
->FormId
= FormId
;
213 MenuList
->Parent
= Parent
;
215 if (Parent
== NULL
) {
217 // If parent is not specified, it is the root Form of a Formset
219 InsertTailList (&gMenuList
, &MenuList
->Link
);
221 InsertTailList (&Parent
->ChildListHead
, &MenuList
->Link
);
229 Search Menu with given FormId in the parent menu and all its child menus.
231 @param Parent The parent of menu to search.
232 @param FormId The Form ID of menu to search.
234 @return A pointer to menu found or NULL if not found.
238 UiFindChildMenuList (
239 IN UI_MENU_LIST
*Parent
,
245 UI_MENU_LIST
*MenuList
;
247 if (Parent
->FormId
== FormId
) {
251 Link
= GetFirstNode (&Parent
->ChildListHead
);
252 while (!IsNull (&Parent
->ChildListHead
, Link
)) {
253 Child
= UI_MENU_LIST_FROM_LINK (Link
);
255 MenuList
= UiFindChildMenuList (Child
, FormId
);
256 if (MenuList
!= NULL
) {
260 Link
= GetNextNode (&Parent
->ChildListHead
, Link
);
268 Search Menu with given FormSetGuid and FormId in all cached menu list.
270 @param FormSetGuid The Formset GUID of the menu to search.
271 @param FormId The Form ID of menu to search.
273 @return A pointer to menu found or NULL if not found.
278 IN EFI_GUID
*FormSetGuid
,
283 UI_MENU_LIST
*MenuList
;
286 Link
= GetFirstNode (&gMenuList
);
287 while (!IsNull (&gMenuList
, Link
)) {
288 MenuList
= UI_MENU_LIST_FROM_LINK (Link
);
290 if (CompareGuid (FormSetGuid
, &MenuList
->FormSetGuid
)) {
292 // This is the formset we are looking for, find the form in this formset
294 Child
= UiFindChildMenuList (MenuList
, FormId
);
300 Link
= GetNextNode (&gMenuList
, Link
);
308 Free Menu option linked list.
316 MENU_REFRESH_ENTRY
*OldMenuRefreshEntry
;
318 while (gMenuRefreshHead
!= NULL
) {
319 OldMenuRefreshEntry
= gMenuRefreshHead
->Next
;
320 FreePool (gMenuRefreshHead
);
321 gMenuRefreshHead
= OldMenuRefreshEntry
;
324 gMenuRefreshHead
= NULL
;
338 CHAR16
*OptionString
;
339 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
342 UI_MENU_SELECTION
*Selection
;
343 FORM_BROWSER_STATEMENT
*Question
;
344 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
345 EFI_HII_VALUE
*HiiValue
;
346 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
348 if (gMenuRefreshHead
!= NULL
) {
350 MenuRefreshEntry
= gMenuRefreshHead
;
353 // Reset FormPackage update flag
355 mHiiPackageListUpdated
= FALSE
;
358 gST
->ConOut
->SetAttribute (gST
->ConOut
, MenuRefreshEntry
->CurrentAttribute
);
360 Selection
= MenuRefreshEntry
->Selection
;
361 Question
= MenuRefreshEntry
->MenuOption
->ThisTag
;
363 Status
= GetQuestionValue (Selection
->FormSet
, Selection
->Form
, Question
, FALSE
);
364 if (EFI_ERROR (Status
)) {
369 ProcessOptions (Selection
, MenuRefreshEntry
->MenuOption
, FALSE
, &OptionString
);
371 if (OptionString
!= NULL
) {
373 // If leading spaces on OptionString - remove the spaces
375 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
378 PrintStringAt (MenuRefreshEntry
->CurrentColumn
, MenuRefreshEntry
->CurrentRow
, &OptionString
[Index
]);
379 FreePool (OptionString
);
383 // Question value may be changed, need invoke its Callback()
385 ConfigAccess
= Selection
->FormSet
->ConfigAccess
;
386 if (((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
387 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
389 HiiValue
= &Question
->HiiValue
;
390 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
392 // Create String in HII database for Configuration Driver to retrieve
394 HiiValue
->Value
.string
= NewString ((CHAR16
*) Question
->BufferValue
, Selection
->FormSet
->HiiHandle
);
397 Status
= ConfigAccess
->Callback (
399 EFI_BROWSER_ACTION_CHANGING
,
400 Question
->QuestionId
,
406 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
408 // Clean the String in HII Database
410 DeleteString (HiiValue
->Value
.string
, Selection
->FormSet
->HiiHandle
);
413 if (!EFI_ERROR (Status
)) {
414 switch (ActionRequest
) {
415 case EFI_BROWSER_ACTION_REQUEST_RESET
:
416 gResetRequired
= TRUE
;
419 case EFI_BROWSER_ACTION_REQUEST_SUBMIT
:
420 SubmitForm (Selection
->FormSet
, Selection
->Form
);
423 case EFI_BROWSER_ACTION_REQUEST_EXIT
:
424 Selection
->Action
= UI_ACTION_EXIT
;
425 gNvUpdateRequired
= FALSE
;
434 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
436 } while (MenuRefreshEntry
!= NULL
);
438 if (mHiiPackageListUpdated
) {
440 // Package list is updated, force to reparse IFR binary of target Formset
442 mHiiPackageListUpdated
= FALSE
;
443 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
453 Wait for a given event to fire, or for an optional timeout to expire.
455 @param Event The event to wait for
456 @param Timeout An optional timeout value in 100 ns units.
457 @param RefreshInterval Menu refresh interval (in seconds).
459 @retval EFI_SUCCESS Event fired before Timeout expired.
460 @retval EFI_TIME_OUT Timout expired before Event fired.
464 UiWaitForSingleEvent (
466 IN UINT64 Timeout
, OPTIONAL
467 IN UINT8 RefreshInterval OPTIONAL
472 EFI_EVENT TimerEvent
;
473 EFI_EVENT WaitList
[2];
477 // Create a timer event
479 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
480 if (!EFI_ERROR (Status
)) {
482 // Set the timer event
491 // Wait for the original event or the timer
494 WaitList
[1] = TimerEvent
;
495 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
496 gBS
->CloseEvent (TimerEvent
);
499 // If the timer expired, change the return to timed out
501 if (!EFI_ERROR (Status
) && Index
== 1) {
502 Status
= EFI_TIMEOUT
;
507 // Update screen every second
509 if (RefreshInterval
== 0) {
510 Timeout
= ONE_SECOND
;
512 Timeout
= RefreshInterval
* ONE_SECOND
;
516 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
519 // Set the timer event
528 // Wait for the original event or the timer
531 WaitList
[1] = TimerEvent
;
532 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
535 // If the timer expired, update anything that needs a refresh and keep waiting
537 if (!EFI_ERROR (Status
) && Index
== 1) {
538 Status
= EFI_TIMEOUT
;
539 if (RefreshInterval
!= 0) {
540 Status
= RefreshForm ();
544 gBS
->CloseEvent (TimerEvent
);
545 } while (Status
== EFI_TIMEOUT
);
553 Add one menu option by specified description and context.
555 @param String String description for this option.
556 @param Handle Hii handle for the package list.
557 @param Statement Statement of this Menu Option.
558 @param NumberOfLines Display lines for this Menu Option.
559 @param MenuItemCount The index for this Option in the Menu.
561 @retval Pointer Pointer to the added Menu Option.
567 IN EFI_HII_HANDLE Handle
,
568 IN FORM_BROWSER_STATEMENT
*Statement
,
569 IN UINT16 NumberOfLines
,
570 IN UINT16 MenuItemCount
573 UI_MENU_OPTION
*MenuOption
;
580 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
582 // Add three MenuOptions for Date/Time
583 // Data format : [01/02/2004] [11:22:33]
584 // Line number : 0 0 1 0 0 1
589 if (Statement
->Storage
== NULL
) {
591 // For RTC type of date/time, set default refresh interval to be 1 second
593 if (Statement
->RefreshInterval
== 0) {
594 Statement
->RefreshInterval
= 1;
599 for (Index
= 0; Index
< Count
; Index
++) {
600 MenuOption
= AllocateZeroPool (sizeof (UI_MENU_OPTION
));
603 MenuOption
->Signature
= UI_MENU_OPTION_SIGNATURE
;
604 MenuOption
->Description
= String
;
605 MenuOption
->Handle
= Handle
;
606 MenuOption
->ThisTag
= Statement
;
607 MenuOption
->EntryNumber
= MenuItemCount
;
611 // Override LineNumber for the MenuOption in Date/Time sequence
613 MenuOption
->Skip
= 1;
615 MenuOption
->Skip
= NumberOfLines
;
617 MenuOption
->Sequence
= Index
;
619 if (Statement
->GrayOutExpression
!= NULL
) {
620 MenuOption
->GrayOut
= Statement
->GrayOutExpression
->Result
.Value
.b
;
623 switch (Statement
->Operand
) {
624 case EFI_IFR_ORDERED_LIST_OP
:
625 case EFI_IFR_ONE_OF_OP
:
626 case EFI_IFR_NUMERIC_OP
:
627 case EFI_IFR_TIME_OP
:
628 case EFI_IFR_DATE_OP
:
629 case EFI_IFR_CHECKBOX_OP
:
630 case EFI_IFR_PASSWORD_OP
:
631 case EFI_IFR_STRING_OP
:
633 // User could change the value of these items
635 MenuOption
->IsQuestion
= TRUE
;
639 MenuOption
->IsQuestion
= FALSE
;
643 if ((Statement
->ValueExpression
!= NULL
) ||
644 ((Statement
->QuestionFlags
& EFI_IFR_FLAG_READ_ONLY
) != 0)) {
645 MenuOption
->ReadOnly
= TRUE
;
648 InsertTailList (&gMenuOption
, &MenuOption
->Link
);
656 Routine used to abstract a generic dialog interface and return the selected key or string
658 @param NumberOfLines The number of lines for the dialog box
659 @param HotKey Defines whether a single character is parsed
660 (TRUE) and returned in KeyValue or a string is
661 returned in StringBuffer. Two special characters
662 are considered when entering a string, a SCAN_ESC
663 and an CHAR_CARRIAGE_RETURN. SCAN_ESC terminates
664 string input and returns
665 @param MaximumStringSize The maximum size in bytes of a typed in string
666 (each character is a CHAR16) and the minimum
667 string returned is two bytes
668 @param StringBuffer The passed in pointer to the buffer which will
669 hold the typed in string if HotKey is FALSE
670 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
671 @param ... A series of (quantity == NumberOfLines) text
672 strings which will be used to construct the dialog
675 @retval EFI_SUCCESS Displayed dialog and received user interaction
676 @retval EFI_INVALID_PARAMETER One of the parameters was invalid (e.g.
677 (StringBuffer == NULL) && (HotKey == FALSE))
678 @retval EFI_DEVICE_ERROR User typed in an ESC character to exit the routine
683 IN UINTN NumberOfLines
,
685 IN UINTN MaximumStringSize
,
686 OUT CHAR16
*StringBuffer
,
687 OUT EFI_INPUT_KEY
*KeyValue
,
696 CHAR16
*BufferedString
;
703 BOOLEAN SelectionComplete
;
705 UINTN CurrentAttribute
;
706 UINTN DimensionsWidth
;
707 UINTN DimensionsHeight
;
709 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
710 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
712 SelectionComplete
= FALSE
;
714 TempString
= AllocateZeroPool (MaximumStringSize
* 2);
715 BufferedString
= AllocateZeroPool (MaximumStringSize
* 2);
716 CurrentAttribute
= gST
->ConOut
->Mode
->Attribute
;
719 ASSERT (BufferedString
);
721 VA_START (Marker
, KeyValue
);
724 // Zero the outgoing buffer
726 ZeroMem (StringBuffer
, MaximumStringSize
);
729 if (KeyValue
== NULL
) {
730 return EFI_INVALID_PARAMETER
;
733 if (StringBuffer
== NULL
) {
734 return EFI_INVALID_PARAMETER
;
740 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
745 // Determine the largest string in the dialog box
746 // Notice we are starting with 1 since String is the first string
748 for (Count
= 0; Count
< NumberOfLines
; Count
++) {
749 StackString
= VA_ARG (Marker
, CHAR16
*);
751 if (StackString
[0] == L
' ') {
752 InputOffset
= Count
+ 1;
755 if ((GetStringWidth (StackString
) / 2) > LargestString
) {
757 // Size of the string visually and subtract the width by one for the null-terminator
759 LargestString
= (GetStringWidth (StackString
) / 2);
764 Start
= (DimensionsWidth
- LargestString
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
765 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
772 VA_START (Marker
, KeyValue
);
773 CreateSharedPopUp (LargestString
, NumberOfLines
, Marker
);
777 // Take the first key typed and report it back?
780 Status
= WaitForKeyStroke (&Key
);
781 ASSERT_EFI_ERROR (Status
);
782 CopyMem (KeyValue
, &Key
, sizeof (EFI_INPUT_KEY
));
786 Status
= WaitForKeyStroke (&Key
);
788 switch (Key
.UnicodeChar
) {
790 switch (Key
.ScanCode
) {
792 FreePool (TempString
);
793 FreePool (BufferedString
);
794 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
795 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
796 return EFI_DEVICE_ERROR
;
804 case CHAR_CARRIAGE_RETURN
:
805 SelectionComplete
= TRUE
;
806 FreePool (TempString
);
807 FreePool (BufferedString
);
808 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
809 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
814 if (StringBuffer
[0] != CHAR_NULL
) {
815 for (Index
= 0; StringBuffer
[Index
] != CHAR_NULL
; Index
++) {
816 TempString
[Index
] = StringBuffer
[Index
];
819 // Effectively truncate string by 1 character
821 TempString
[Index
- 1] = CHAR_NULL
;
822 StrCpy (StringBuffer
, TempString
);
827 // If it is the beginning of the string, don't worry about checking maximum limits
829 if ((StringBuffer
[0] == CHAR_NULL
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
830 StrnCpy (StringBuffer
, &Key
.UnicodeChar
, 1);
831 StrnCpy (TempString
, &Key
.UnicodeChar
, 1);
832 } else if ((GetStringWidth (StringBuffer
) < MaximumStringSize
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
833 KeyPad
[0] = Key
.UnicodeChar
;
834 KeyPad
[1] = CHAR_NULL
;
835 StrCat (StringBuffer
, KeyPad
);
836 StrCat (TempString
, KeyPad
);
839 // If the width of the input string is now larger than the screen, we nee to
840 // adjust the index to start printing portions of the string
842 SetUnicodeMem (BufferedString
, LargestString
, L
' ');
844 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
846 if ((GetStringWidth (StringBuffer
) / 2) > (DimensionsWidth
- 2)) {
847 Index
= (GetStringWidth (StringBuffer
) / 2) - DimensionsWidth
+ 2;
852 for (Count
= 0; Index
+ 1 < GetStringWidth (StringBuffer
) / 2; Index
++, Count
++) {
853 BufferedString
[Count
] = StringBuffer
[Index
];
856 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
859 } while (!SelectionComplete
);
862 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
863 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
868 Draw a pop up windows based on the dimension, number of lines and
871 @param RequestedWidth The width of the pop-up.
872 @param NumberOfLines The number of lines.
873 @param Marker The variable argument list for the list of string to be printed.
878 IN UINTN RequestedWidth
,
879 IN UINTN NumberOfLines
,
891 UINTN DimensionsWidth
;
892 UINTN DimensionsHeight
;
894 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
895 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
897 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
899 if ((RequestedWidth
+ 2) > DimensionsWidth
) {
900 RequestedWidth
= DimensionsWidth
- 2;
904 // Subtract the PopUp width from total Columns, allow for one space extra on
905 // each end plus a border.
907 Start
= (DimensionsWidth
- RequestedWidth
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
908 End
= Start
+ RequestedWidth
+ 1;
910 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
911 Bottom
= Top
+ NumberOfLines
+ 2;
913 Character
= BOXDRAW_DOWN_RIGHT
;
914 PrintCharAt (Start
, Top
, Character
);
915 Character
= BOXDRAW_HORIZONTAL
;
916 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
917 PrintChar (Character
);
920 Character
= BOXDRAW_DOWN_LEFT
;
921 PrintChar (Character
);
922 Character
= BOXDRAW_VERTICAL
;
925 for (Index
= Top
; Index
+ 2 < Bottom
; Index
++, Count
++) {
926 String
= VA_ARG (Marker
, CHAR16
*);
929 // This will clear the background of the line - we never know who might have been
930 // here before us. This differs from the next clear in that it used the non-reverse
931 // video for normal printing.
933 if (GetStringWidth (String
) / 2 > 1) {
934 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
938 // Passing in a space results in the assumption that this is where typing will occur
940 if (String
[0] == L
' ') {
941 ClearLines (Start
+ 1, End
- 1, Index
+ 1, Index
+ 1, POPUP_INVERSE_TEXT
| POPUP_INVERSE_BACKGROUND
);
945 // Passing in a NULL results in a blank space
947 if (String
[0] == CHAR_NULL
) {
948 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
952 ((DimensionsWidth
- GetStringWidth (String
) / 2) / 2) + gScreenDimensions
.LeftColumn
+ 1,
956 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
957 PrintCharAt (Start
, Index
+ 1, Character
);
958 PrintCharAt (End
- 1, Index
+ 1, Character
);
961 Character
= BOXDRAW_UP_RIGHT
;
962 PrintCharAt (Start
, Bottom
- 1, Character
);
963 Character
= BOXDRAW_HORIZONTAL
;
964 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
965 PrintChar (Character
);
968 Character
= BOXDRAW_UP_LEFT
;
969 PrintChar (Character
);
973 Draw a pop up windows based on the dimension, number of lines and
976 @param RequestedWidth The width of the pop-up.
977 @param NumberOfLines The number of lines.
978 @param ... A series of text strings that displayed in the pop-up.
982 CreateMultiStringPopUp (
983 IN UINTN RequestedWidth
,
984 IN UINTN NumberOfLines
,
990 VA_START (Marker
, NumberOfLines
);
992 CreateSharedPopUp (RequestedWidth
, NumberOfLines
, Marker
);
999 Update status bar on the bottom of menu.
1001 @param MessageType The type of message to be shown.
1002 @param Flags The flags in Question header.
1003 @param State Set or clear.
1008 IN UINTN MessageType
,
1014 CHAR16
*NvUpdateMessage
;
1015 CHAR16
*InputErrorMessage
;
1017 NvUpdateMessage
= GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE
), gHiiHandle
);
1018 InputErrorMessage
= GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE
), gHiiHandle
);
1020 switch (MessageType
) {
1023 gST
->ConOut
->SetAttribute (gST
->ConOut
, ERROR_TEXT
);
1025 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
,
1026 gScreenDimensions
.BottomRow
- 1,
1031 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
1032 for (Index
= 0; Index
< (GetStringWidth (InputErrorMessage
) - 2) / 2; Index
++) {
1033 PrintAt (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ Index
, gScreenDimensions
.BottomRow
- 1, L
" ");
1036 mInputError
= FALSE
;
1040 case NV_UPDATE_REQUIRED
:
1041 if (gClassOfVfr
!= FORMSET_CLASS_FRONT_PAGE
) {
1043 gST
->ConOut
->SetAttribute (gST
->ConOut
, INFO_TEXT
);
1045 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
,
1046 gScreenDimensions
.BottomRow
- 1,
1049 gResetRequired
= (BOOLEAN
) (gResetRequired
| ((Flags
& EFI_IFR_FLAG_RESET_REQUIRED
) == EFI_IFR_FLAG_RESET_REQUIRED
));
1051 gNvUpdateRequired
= TRUE
;
1053 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
1054 for (Index
= 0; Index
< (GetStringWidth (NvUpdateMessage
) - 2) / 2; Index
++) {
1056 (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ Index
),
1057 gScreenDimensions
.BottomRow
- 1,
1062 gNvUpdateRequired
= FALSE
;
1067 case REFRESH_STATUS_BAR
:
1069 UpdateStatusBar (INPUT_ERROR
, Flags
, TRUE
);
1072 if (gNvUpdateRequired
) {
1073 UpdateStatusBar (NV_UPDATE_REQUIRED
, Flags
, TRUE
);
1081 FreePool (InputErrorMessage
);
1082 FreePool (NvUpdateMessage
);
1088 Get the supported width for a particular op-code
1090 @param Statement The FORM_BROWSER_STATEMENT structure passed in.
1091 @param Handle The handle in the HII database being used
1093 @return Returns the number of CHAR16 characters that is support.
1098 IN FORM_BROWSER_STATEMENT
*Statement
,
1099 IN EFI_HII_HANDLE Handle
1109 // See if the second text parameter is really NULL
1111 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1112 String
= GetToken (Statement
->TextTwo
, Handle
);
1113 Size
= StrLen (String
);
1117 if ((Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1118 (Statement
->Operand
== EFI_IFR_REF_OP
) ||
1119 (Statement
->Operand
== EFI_IFR_PASSWORD_OP
) ||
1120 (Statement
->Operand
== EFI_IFR_ACTION_OP
) ||
1121 (Statement
->Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1123 // Allow a wide display if text op-code and no secondary text op-code
1125 ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Size
== 0))
1127 Width
= (UINT16
) (gPromptBlockWidth
+ gOptionBlockWidth
);
1129 Width
= (UINT16
) gPromptBlockWidth
;
1132 if (Statement
->InSubtitle
) {
1133 Width
-= SUBTITLE_INDENT
;
1140 Will copy LineWidth amount of a string in the OutputString buffer and return the
1141 number of CHAR16 characters that were copied into the OutputString buffer.
1143 @param InputString String description for this option.
1144 @param LineWidth Width of the desired string to extract in CHAR16
1146 @param Index Where in InputString to start the copy process
1147 @param OutputString Buffer to copy the string into
1149 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.
1154 IN CHAR16
*InputString
,
1155 IN UINT16 LineWidth
,
1156 IN OUT UINTN
*Index
,
1157 OUT CHAR16
**OutputString
1163 if (GetLineByWidthFinished
) {
1164 GetLineByWidthFinished
= FALSE
;
1171 *OutputString
= AllocateZeroPool (((UINTN
) (LineWidth
+ 1) * 2));
1174 // Ensure we have got a valid buffer
1176 if (*OutputString
!= NULL
) {
1179 //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.
1180 //To avoid displaying this empty line in screen, just skip the two CHARs here.
1182 if ((InputString
[*Index
] == NARROW_CHAR
) && (InputString
[*Index
+ 1] == CHAR_CARRIAGE_RETURN
)) {
1183 *Index
= *Index
+ 2;
1187 // Fast-forward the string and see if there is a carriage-return in the string
1189 for (; (InputString
[*Index
+ Count2
] != CHAR_CARRIAGE_RETURN
) && (Count2
!= LineWidth
); Count2
++)
1193 // Copy the desired LineWidth of data to the output buffer.
1194 // Also make sure that we don't copy more than the string.
1195 // Also make sure that if there are linefeeds, we account for them.
1197 if ((StrSize (&InputString
[*Index
]) <= ((UINTN
) (LineWidth
+ 1) * 2)) &&
1198 (StrSize (&InputString
[*Index
]) <= ((UINTN
) (Count2
+ 1) * 2))
1201 // Convert to CHAR16 value and show that we are done with this operation
1203 LineWidth
= (UINT16
) ((StrSize (&InputString
[*Index
]) - 2) / 2);
1204 if (LineWidth
!= 0) {
1205 GetLineByWidthFinished
= TRUE
;
1208 if (Count2
== LineWidth
) {
1210 // Rewind the string from the maximum size until we see a space to break the line
1212 for (; (InputString
[*Index
+ LineWidth
] != CHAR_SPACE
) && (LineWidth
!= 0); LineWidth
--)
1214 if (LineWidth
== 0) {
1222 CopyMem (*OutputString
, &InputString
[*Index
], LineWidth
* 2);
1225 // If currently pointing to a space, increment the index to the first non-space character
1228 (InputString
[*Index
+ LineWidth
] == CHAR_SPACE
) || (InputString
[*Index
+ LineWidth
] == CHAR_CARRIAGE_RETURN
);
1232 *Index
= (UINT16
) (*Index
+ LineWidth
);
1241 Update display lines for a Menu Option.
1243 @param Selection The user's selection.
1244 @param MenuOption The MenuOption to be checked.
1245 @param OptionalString The option string.
1246 @param SkipValue The number of lins to skip.
1250 UpdateOptionSkipLines (
1251 IN UI_MENU_SELECTION
*Selection
,
1252 IN UI_MENU_OPTION
*MenuOption
,
1253 OUT CHAR16
**OptionalString
,
1261 CHAR16
*OutputString
;
1262 CHAR16
*OptionString
;
1265 OptionString
= *OptionalString
;
1266 OutputString
= NULL
;
1268 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1270 if (OptionString
!= NULL
) {
1271 Width
= (UINT16
) gOptionBlockWidth
;
1275 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1277 // If there is more string to process print on the next row and increment the Skip value
1279 if (StrLen (&OptionString
[Index
]) != 0) {
1280 if (SkipValue
== 0) {
1283 // Since the Number of lines for this menu entry may or may not be reflected accurately
1284 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1285 // some testing to ensure we are keeping this in-sync.
1287 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1289 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1295 FreePool (OutputString
);
1296 if (SkipValue
!= 0) {
1304 *OptionalString
= OptionString
;
1309 Check whether this Menu Option could be highlighted.
1311 This is an internal function.
1313 @param MenuOption The MenuOption to be checked.
1315 @retval TRUE This Menu Option is selectable.
1316 @retval FALSE This Menu Option could not be selected.
1321 UI_MENU_OPTION
*MenuOption
1324 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1325 MenuOption
->GrayOut
|| MenuOption
->ReadOnly
) {
1334 Determine if the menu is the last menu that can be selected.
1336 This is an internal function.
1338 @param Direction The scroll direction. False is down. True is up.
1339 @param CurrentPos The current focus.
1341 @return FALSE -- the menu isn't the last menu that can be selected.
1342 @return TRUE -- the menu is the last menu that can be selected.
1347 IN BOOLEAN Direction
,
1348 IN LIST_ENTRY
*CurrentPos
1352 UI_MENU_OPTION
*MenuOption
;
1354 Temp
= Direction
? CurrentPos
->BackLink
: CurrentPos
->ForwardLink
;
1356 if (Temp
== &gMenuOption
) {
1360 for (; Temp
!= &gMenuOption
; Temp
= Direction
? Temp
->BackLink
: Temp
->ForwardLink
) {
1361 MenuOption
= MENU_OPTION_FROM_LINK (Temp
);
1362 if (IsSelectable (MenuOption
)) {
1372 Move to next selectable statement.
1374 This is an internal function.
1376 @param GoUp The navigation direction. TRUE: up, FALSE: down.
1377 @param CurrentPosition Current position.
1379 @return The row distance from current MenuOption to next selectable MenuOption.
1383 MoveToNextStatement (
1385 IN OUT LIST_ENTRY
**CurrentPosition
1391 UI_MENU_OPTION
*NextMenuOption
;
1394 Pos
= *CurrentPosition
;
1398 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1399 if (IsSelectable (NextMenuOption
)) {
1402 if ((GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &gMenuOption
) {
1406 Distance
+= NextMenuOption
->Skip
;
1407 Pos
= (GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1412 // If we hit end there is still no statement can be focused,
1413 // we go backwards to find the statement can be focused.
1416 Pos
= *CurrentPosition
;
1419 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1420 if (IsSelectable (NextMenuOption
)) {
1423 if ((!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &gMenuOption
) {
1427 Distance
-= NextMenuOption
->Skip
;
1428 Pos
= (!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1432 *CurrentPosition
= &NextMenuOption
->Link
;
1438 Adjust Data and Time position accordingly.
1439 Data format : [01/02/2004] [11:22:33]
1440 Line number : 0 0 1 0 0 1
1442 This is an internal function.
1444 @param DirectionUp the up or down direction. False is down. True is
1446 @param CurrentPosition Current position. On return: Point to the last
1447 Option (Year or Second) if up; Point to the first
1448 Option (Month or Hour) if down.
1450 @return Return line number to pad. It is possible that we stand on a zero-advance
1451 @return data or time opcode, so pad one line when we judge if we are going to scroll outside.
1455 AdjustDateAndTimePosition (
1456 IN BOOLEAN DirectionUp
,
1457 IN OUT LIST_ENTRY
**CurrentPosition
1461 LIST_ENTRY
*NewPosition
;
1462 UI_MENU_OPTION
*MenuOption
;
1463 UINTN PadLineNumber
;
1466 NewPosition
= *CurrentPosition
;
1467 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1469 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
1470 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
1472 // Calculate the distance from current position to the last Date/Time MenuOption
1475 while (MenuOption
->Skip
== 0) {
1477 NewPosition
= NewPosition
->ForwardLink
;
1478 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1482 NewPosition
= *CurrentPosition
;
1485 // Since the behavior of hitting the up arrow on a Date/Time MenuOption is intended
1486 // to be one that back to the previous set of MenuOptions, we need to advance to the first
1487 // Date/Time MenuOption and leave the remaining logic in CfUiUp intact so the appropriate
1488 // checking can be done.
1490 while (Count
++ < 2) {
1491 NewPosition
= NewPosition
->BackLink
;
1495 // Since the behavior of hitting the down arrow on a Date/Time MenuOption is intended
1496 // to be one that progresses to the next set of MenuOptions, we need to advance to the last
1497 // Date/Time MenuOption and leave the remaining logic in CfUiDown intact so the appropriate
1498 // checking can be done.
1500 while (Count
-- > 0) {
1501 NewPosition
= NewPosition
->ForwardLink
;
1505 *CurrentPosition
= NewPosition
;
1508 return PadLineNumber
;
1512 Find HII Handle in the HII database associated with given Device Path.
1514 If DevicePath is NULL, then ASSERT.
1516 @param DevicePath Device Path associated with the HII package list
1519 @retval Handle HII package list Handle associated with the Device
1521 @retval NULL Hii Package list handle is not found.
1526 DevicePathToHiiHandle (
1527 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1531 EFI_DEVICE_PATH_PROTOCOL
*TmpDevicePath
;
1536 EFI_HANDLE DriverHandle
;
1537 EFI_HII_HANDLE
*HiiHandles
;
1538 EFI_HII_HANDLE HiiHandle
;
1540 ASSERT (DevicePath
!= NULL
);
1542 TmpDevicePath
= DevicePath
;
1544 // Locate Device Path Protocol handle buffer
1546 Status
= gBS
->LocateDevicePath (
1547 &gEfiDevicePathProtocolGuid
,
1551 if (EFI_ERROR (Status
) || !IsDevicePathEnd (TmpDevicePath
)) {
1556 // Retrieve all HII Handles from HII database
1558 BufferSize
= 0x1000;
1559 HiiHandles
= AllocatePool (BufferSize
);
1560 ASSERT (HiiHandles
!= NULL
);
1561 Status
= mHiiDatabase
->ListPackageLists (
1563 EFI_HII_PACKAGE_TYPE_ALL
,
1568 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1569 FreePool (HiiHandles
);
1570 HiiHandles
= AllocatePool (BufferSize
);
1571 ASSERT (HiiHandles
!= NULL
);
1573 Status
= mHiiDatabase
->ListPackageLists (
1575 EFI_HII_PACKAGE_TYPE_ALL
,
1582 if (EFI_ERROR (Status
)) {
1583 FreePool (HiiHandles
);
1588 // Search Hii Handle by Driver Handle
1591 HandleCount
= BufferSize
/ sizeof (EFI_HII_HANDLE
);
1592 for (Index
= 0; Index
< HandleCount
; Index
++) {
1593 Status
= mHiiDatabase
->GetPackageListHandle (
1598 if (!EFI_ERROR (Status
) && (Handle
== DriverHandle
)) {
1599 HiiHandle
= HiiHandles
[Index
];
1604 FreePool (HiiHandles
);
1609 Display menu and wait for user to select one menu option, then return it.
1610 If AutoBoot is enabled, then if user doesn't select any option,
1611 after period of time, it will automatically return the first menu option.
1613 @param Selection Menu selection.
1615 @retval EFI_SUCESSS This function always return successfully for now.
1620 IN OUT UI_MENU_SELECTION
*Selection
1626 UINTN DistanceValue
;
1638 CHAR16
*OptionString
;
1639 CHAR16
*OutputString
;
1640 CHAR16
*FormattedString
;
1652 LIST_ENTRY
*TopOfScreen
;
1653 LIST_ENTRY
*SavedListEntry
;
1654 UI_MENU_OPTION
*MenuOption
;
1655 UI_MENU_OPTION
*NextMenuOption
;
1656 UI_MENU_OPTION
*SavedMenuOption
;
1657 UI_MENU_OPTION
*PreviousMenuOption
;
1658 UI_CONTROL_FLAG ControlFlag
;
1659 EFI_SCREEN_DESCRIPTOR LocalScreen
;
1660 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
1661 UI_SCREEN_OPERATION ScreenOperation
;
1662 UINT8 MinRefreshInterval
;
1665 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1666 FORM_BROWSER_STATEMENT
*Statement
;
1668 UINT8
*DevicePathBuffer
;
1670 UI_MENU_LIST
*CurrentMenu
;
1671 UI_MENU_LIST
*MenuList
;
1673 CopyMem (&LocalScreen
, &gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1675 Status
= EFI_SUCCESS
;
1676 FormattedString
= NULL
;
1677 OptionString
= NULL
;
1678 ScreenOperation
= UiNoOperation
;
1680 MinRefreshInterval
= 0;
1683 OutputString
= NULL
;
1688 MenuRefreshEntry
= gMenuRefreshHead
;
1690 NextMenuOption
= NULL
;
1691 PreviousMenuOption
= NULL
;
1692 SavedMenuOption
= NULL
;
1694 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
1696 if (gClassOfVfr
== FORMSET_CLASS_FRONT_PAGE
) {
1697 TopRow
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1698 Row
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1700 TopRow
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1701 Row
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1704 Col
= LocalScreen
.LeftColumn
;
1705 BottomRow
= LocalScreen
.BottomRow
- STATUS_BAR_HEIGHT
- FOOTER_HEIGHT
- SCROLL_ARROW_HEIGHT
- 1;
1707 Selection
->TopRow
= TopRow
;
1708 Selection
->BottomRow
= BottomRow
;
1709 Selection
->PromptCol
= Col
;
1710 Selection
->OptionCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1711 Selection
->Statement
= NULL
;
1713 TopOfScreen
= gMenuOption
.ForwardLink
;
1718 // Find current Menu
1720 CurrentMenu
= UiFindMenuList (&Selection
->FormSetGuid
, Selection
->FormId
);
1721 if (CurrentMenu
== NULL
) {
1723 // Current menu not found, add it to the menu tree
1725 CurrentMenu
= UiAddMenuList (NULL
, &Selection
->FormSetGuid
, Selection
->FormId
);
1727 ASSERT (CurrentMenu
!= NULL
);
1729 if (Selection
->QuestionId
== 0) {
1731 // Highlight not specified, fetch it from cached menu
1733 Selection
->QuestionId
= CurrentMenu
->QuestionId
;
1737 // Get user's selection
1739 NewPos
= gMenuOption
.ForwardLink
;
1741 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
1742 UpdateStatusBar (REFRESH_STATUS_BAR
, (UINT8
) 0, TRUE
);
1744 ControlFlag
= CfInitialization
;
1745 Selection
->Action
= UI_ACTION_NONE
;
1747 switch (ControlFlag
) {
1748 case CfInitialization
:
1749 if (IsListEmpty (&gMenuOption
)) {
1750 ControlFlag
= CfReadKey
;
1752 ControlFlag
= CfCheckSelection
;
1756 case CfCheckSelection
:
1757 if (Selection
->Action
!= UI_ACTION_NONE
) {
1758 ControlFlag
= CfExit
;
1760 ControlFlag
= CfRepaint
;
1765 ControlFlag
= CfRefreshHighLight
;
1779 LocalScreen
.LeftColumn
,
1780 LocalScreen
.RightColumn
,
1781 TopRow
- SCROLL_ARROW_HEIGHT
,
1782 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1783 FIELD_TEXT
| FIELD_BACKGROUND
1786 UiFreeRefreshList ();
1787 MinRefreshInterval
= 0;
1789 for (Link
= TopOfScreen
; Link
!= &gMenuOption
; Link
= Link
->ForwardLink
) {
1790 MenuOption
= MENU_OPTION_FROM_LINK (Link
);
1791 MenuOption
->Row
= Row
;
1792 MenuOption
->Col
= Col
;
1793 MenuOption
->OptCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1795 Statement
= MenuOption
->ThisTag
;
1796 if (Statement
->InSubtitle
) {
1797 MenuOption
->Col
+= SUBTITLE_INDENT
;
1800 if (MenuOption
->GrayOut
) {
1801 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
1803 if (Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) {
1804 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
1808 Width
= GetWidth (Statement
, MenuOption
->Handle
);
1811 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
1812 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1813 PrintStringAt (MenuOption
->Col
, Row
, OutputString
);
1816 // If there is more string to process print on the next row and increment the Skip value
1818 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
1824 FreePool (OutputString
);
1833 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1834 Status
= ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1835 if (EFI_ERROR (Status
)) {
1837 // Repaint to clear possible error prompt pop-up
1841 ControlFlag
= CfRepaint
;
1845 if (OptionString
!= NULL
) {
1846 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
1848 // If leading spaces on OptionString - remove the spaces
1850 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++) {
1851 MenuOption
->OptCol
++;
1854 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1855 OptionString
[Count
] = OptionString
[Index
];
1859 OptionString
[Count
] = CHAR_NULL
;
1863 // If Question request refresh, register the op-code
1865 if (Statement
->RefreshInterval
!= 0) {
1867 // Menu will be refreshed at minimal interval of all Questions
1868 // which have refresh request
1870 if (MinRefreshInterval
== 0 || Statement
->RefreshInterval
< MinRefreshInterval
) {
1871 MinRefreshInterval
= Statement
->RefreshInterval
;
1874 if (gMenuRefreshHead
== NULL
) {
1875 MenuRefreshEntry
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1876 ASSERT (MenuRefreshEntry
!= NULL
);
1877 MenuRefreshEntry
->MenuOption
= MenuOption
;
1878 MenuRefreshEntry
->Selection
= Selection
;
1879 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1880 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1881 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1882 gMenuRefreshHead
= MenuRefreshEntry
;
1885 // Advance to the last entry
1887 for (MenuRefreshEntry
= gMenuRefreshHead
;
1888 MenuRefreshEntry
->Next
!= NULL
;
1889 MenuRefreshEntry
= MenuRefreshEntry
->Next
1892 MenuRefreshEntry
->Next
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1893 ASSERT (MenuRefreshEntry
->Next
!= NULL
);
1894 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
1895 MenuRefreshEntry
->MenuOption
= MenuOption
;
1896 MenuRefreshEntry
->Selection
= Selection
;
1897 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1898 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1899 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1903 Width
= (UINT16
) gOptionBlockWidth
;
1906 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1907 if ((Temp2
== 0) && (Row
<= BottomRow
)) {
1908 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1911 // If there is more string to process print on the next row and increment the Skip value
1913 if (StrLen (&OptionString
[Index
]) != 0) {
1917 // Since the Number of lines for this menu entry may or may not be reflected accurately
1918 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1919 // some testing to ensure we are keeping this in-sync.
1921 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1923 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1929 FreePool (OutputString
);
1938 FreePool (OptionString
);
1941 // If this is a text op with secondary text information
1943 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1944 StringPtr
= GetToken (Statement
->TextTwo
, MenuOption
->Handle
);
1946 Width
= (UINT16
) gOptionBlockWidth
;
1949 for (Index
= 0; GetLineByWidth (StringPtr
, Width
, &Index
, &OutputString
) != 0x0000;) {
1950 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1951 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1954 // If there is more string to process print on the next row and increment the Skip value
1956 if (StrLen (&StringPtr
[Index
]) != 0) {
1960 // Since the Number of lines for this menu entry may or may not be reflected accurately
1961 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1962 // some testing to ensure we are keeping this in-sync.
1964 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1966 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1972 FreePool (OutputString
);
1979 FreePool (StringPtr
);
1983 // Need to handle the bottom of the display
1985 if (MenuOption
->Skip
> 1) {
1986 Row
+= MenuOption
->Skip
- SkipValue
;
1989 Row
+= MenuOption
->Skip
;
1992 if (Row
> BottomRow
) {
1993 if (!ValueIsScroll (FALSE
, Link
)) {
1997 Row
= BottomRow
+ 1;
2002 if (!ValueIsScroll (TRUE
, TopOfScreen
)) {
2007 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
2009 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
2010 TopRow
- SCROLL_ARROW_HEIGHT
,
2014 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2018 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
2020 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
2021 BottomRow
+ SCROLL_ARROW_HEIGHT
,
2025 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2032 case CfRefreshHighLight
:
2034 // MenuOption: Last menu option that need to remove hilight
2035 // MenuOption is set to NULL in Repaint
2036 // NewPos: Current menu option that need to hilight
2038 ControlFlag
= CfUpdateHelpString
;
2041 // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily
2042 // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.
2044 SavedValue
= Repaint
;
2047 if (Selection
->QuestionId
!= 0) {
2048 NewPos
= gMenuOption
.ForwardLink
;
2049 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2051 while (SavedMenuOption
->ThisTag
->QuestionId
!= Selection
->QuestionId
&& NewPos
->ForwardLink
!= &gMenuOption
) {
2052 NewPos
= NewPos
->ForwardLink
;
2053 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2055 if (SavedMenuOption
->ThisTag
->QuestionId
== Selection
->QuestionId
) {
2057 // Target Question found, find its MenuOption
2061 for (Index
= TopRow
; Index
<= BottomRow
&& Link
!= NewPos
;) {
2062 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2063 Index
+= SavedMenuOption
->Skip
;
2064 Link
= Link
->ForwardLink
;
2067 if (Link
!= NewPos
|| Index
> BottomRow
) {
2069 // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page
2072 for (Index
= TopRow
; Index
<= BottomRow
; ) {
2073 Link
= Link
->BackLink
;
2074 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2075 Index
+= SavedMenuOption
->Skip
;
2077 TopOfScreen
= Link
->ForwardLink
;
2081 ControlFlag
= CfRepaint
;
2086 // Target Question not found, highlight the default menu option
2088 NewPos
= TopOfScreen
;
2091 Selection
->QuestionId
= 0;
2094 if (NewPos
!= NULL
&& (MenuOption
== NULL
|| NewPos
!= &MenuOption
->Link
)) {
2095 if (MenuOption
!= NULL
) {
2097 // Remove highlight on last Menu Option
2099 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
2100 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
2101 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2102 if (OptionString
!= NULL
) {
2103 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
2104 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
2107 // If leading spaces on OptionString - remove the spaces
2109 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
2112 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
2113 OptionString
[Count
] = OptionString
[Index
];
2117 OptionString
[Count
] = CHAR_NULL
;
2120 Width
= (UINT16
) gOptionBlockWidth
;
2121 OriginalRow
= MenuOption
->Row
;
2123 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
2124 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2125 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
2128 // If there is more string to process print on the next row and increment the Skip value
2130 if (StrLen (&OptionString
[Index
]) != 0) {
2134 FreePool (OutputString
);
2137 MenuOption
->Row
= OriginalRow
;
2139 FreePool (OptionString
);
2142 if (MenuOption
->GrayOut
) {
2143 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
2144 } else if (MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) {
2145 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
2148 OriginalRow
= MenuOption
->Row
;
2149 Width
= GetWidth (MenuOption
->ThisTag
, MenuOption
->Handle
);
2151 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2152 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2153 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2156 // If there is more string to process print on the next row and increment the Skip value
2158 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
2162 FreePool (OutputString
);
2165 MenuOption
->Row
= OriginalRow
;
2166 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2172 // This is only possible if we entered this page and the first menu option is
2173 // a "non-menu" item. In that case, force it UiDown
2175 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2176 if (!IsSelectable (MenuOption
)) {
2177 ASSERT (ScreenOperation
== UiNoOperation
);
2178 ScreenOperation
= UiDown
;
2179 ControlFlag
= CfScreenOperation
;
2184 // This is the current selected statement
2186 Statement
= MenuOption
->ThisTag
;
2187 Selection
->Statement
= Statement
;
2189 // Record highlight for current menu
2191 CurrentMenu
->QuestionId
= Statement
->QuestionId
;
2194 // Set reverse attribute
2196 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
);
2197 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
2200 // Assuming that we have a refresh linked-list created, lets annotate the
2201 // appropriate entry that we are highlighting with its new attribute. Just prior to this
2202 // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh
2204 if (gMenuRefreshHead
!= NULL
) {
2205 for (MenuRefreshEntry
= gMenuRefreshHead
; MenuRefreshEntry
!= NULL
; MenuRefreshEntry
= MenuRefreshEntry
->Next
) {
2206 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
2207 if (MenuRefreshEntry
->MenuOption
== MenuOption
) {
2208 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
;
2213 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
2214 if (OptionString
!= NULL
) {
2215 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
2217 // If leading spaces on OptionString - remove the spaces
2219 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
2222 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
2223 OptionString
[Count
] = OptionString
[Index
];
2227 OptionString
[Count
] = CHAR_NULL
;
2229 Width
= (UINT16
) gOptionBlockWidth
;
2231 OriginalRow
= MenuOption
->Row
;
2233 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
2234 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2235 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
2238 // If there is more string to process print on the next row and increment the Skip value
2240 if (StrLen (&OptionString
[Index
]) != 0) {
2244 FreePool (OutputString
);
2247 MenuOption
->Row
= OriginalRow
;
2249 FreePool (OptionString
);
2252 OriginalRow
= MenuOption
->Row
;
2254 Width
= GetWidth (Statement
, MenuOption
->Handle
);
2256 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2257 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2258 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2261 // If there is more string to process print on the next row and increment the Skip value
2263 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
2267 FreePool (OutputString
);
2270 MenuOption
->Row
= OriginalRow
;
2275 UpdateKeyHelp (Selection
, MenuOption
, FALSE
);
2278 // Clear reverse attribute
2280 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2283 // Repaint flag will be used when process CfUpdateHelpString, so restore its value
2284 // if we didn't break halfway when process CfRefreshHighLight.
2286 Repaint
= SavedValue
;
2289 case CfUpdateHelpString
:
2290 ControlFlag
= CfPrepareToReadKey
;
2292 if (Repaint
|| NewLine
) {
2294 // Don't print anything if it is a NULL help token
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
2372 Statement
= MenuOption
->ThisTag
;
2373 if ((Statement
->Operand
== EFI_IFR_DATE_OP
)
2374 || (Statement
->Operand
== EFI_IFR_TIME_OP
)
2375 || ((Statement
->Operand
== EFI_IFR_NUMERIC_OP
) && (Statement
->Step
!= 0))
2377 if (Key
.UnicodeChar
== '+') {
2378 gDirection
= SCAN_RIGHT
;
2380 gDirection
= SCAN_LEFT
;
2382 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2383 if (EFI_ERROR (Status
)) {
2385 // Repaint to clear possible error prompt pop-up
2390 if (OptionString
!= NULL
) {
2391 FreePool (OptionString
);
2397 ScreenOperation
= UiUp
;
2402 ScreenOperation
= UiDown
;
2406 if (gClassOfVfr
!= FORMSET_CLASS_FRONT_PAGE
) {
2407 if (MenuOption
->ThisTag
->Operand
== EFI_IFR_CHECKBOX_OP
&& !MenuOption
->GrayOut
) {
2408 ScreenOperation
= UiSelect
;
2414 if (((Key
.ScanCode
== SCAN_F9
) && ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
)) ||
2415 ((Key
.ScanCode
== SCAN_F10
) && ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
))
2418 // If the function key has been disabled, just ignore the key.
2421 for (Index
= 0; Index
< sizeof (gScanCodeToOperation
) / sizeof (gScanCodeToOperation
[0]); Index
++) {
2422 if (Key
.ScanCode
== gScanCodeToOperation
[Index
].ScanCode
) {
2423 if (Key
.ScanCode
== SCAN_F9
) {
2425 // Reset to standard default
2427 DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2429 ScreenOperation
= gScanCodeToOperation
[Index
].ScreenOperation
;
2438 case CfScreenOperation
:
2439 if (ScreenOperation
!= UiReset
) {
2441 // If the screen has no menu items, and the user didn't select UiReset
2442 // ignore the selection and go back to reading keys.
2444 if (IsListEmpty (&gMenuOption
)) {
2445 ControlFlag
= CfReadKey
;
2449 // if there is nothing logical to place a cursor on, just move on to wait for a key.
2451 for (Link
= gMenuOption
.ForwardLink
; Link
!= &gMenuOption
; Link
= Link
->ForwardLink
) {
2452 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2453 if (IsSelectable (NextMenuOption
)) {
2458 if (Link
== &gMenuOption
) {
2459 ControlFlag
= CfPrepareToReadKey
;
2465 Index
< sizeof (gScreenOperationToControlFlag
) / sizeof (gScreenOperationToControlFlag
[0]);
2468 if (ScreenOperation
== gScreenOperationToControlFlag
[Index
].ScreenOperation
) {
2469 ControlFlag
= gScreenOperationToControlFlag
[Index
].ControlFlag
;
2476 ControlFlag
= CfCheckSelection
;
2478 Statement
= MenuOption
->ThisTag
;
2479 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) ||
2480 (Statement
->Operand
== EFI_IFR_DATE_OP
) ||
2481 (Statement
->Operand
== EFI_IFR_TIME_OP
) ||
2482 (Statement
->Operand
== EFI_IFR_NUMERIC_OP
&& Statement
->Step
!= 0)) {
2487 // Keep highlight on current MenuOption
2489 Selection
->QuestionId
= Statement
->QuestionId
;
2491 switch (Statement
->Operand
) {
2492 case EFI_IFR_REF_OP
:
2493 if (Statement
->RefDevicePath
!= 0) {
2495 // Goto another Hii Package list
2497 ControlFlag
= CfCheckSelection
;
2498 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2500 StringPtr
= GetToken (Statement
->RefDevicePath
, Selection
->FormSet
->HiiHandle
);
2501 if (StringPtr
== NULL
) {
2503 // No device path string not found, exit
2505 Selection
->Action
= UI_ACTION_EXIT
;
2506 Selection
->Statement
= NULL
;
2509 BufferSize
= StrLen (StringPtr
) / 2;
2510 DevicePath
= AllocatePool (BufferSize
);
2513 // Convert from Device Path String to DevicePath Buffer in the reverse order.
2515 DevicePathBuffer
= (UINT8
*) DevicePath
;
2516 for (Index
= 0; StringPtr
[Index
] != L
'\0'; Index
++) {
2517 TemStr
[0] = StringPtr
[Index
];
2518 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
2519 if (DigitUint8
== 0 && TemStr
[0] != L
'0') {
2521 // Invalid Hex Char as the tail.
2525 if ((Index
& 1) == 0) {
2526 DevicePathBuffer
[Index
/2] = DigitUint8
;
2528 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
2532 Selection
->Handle
= DevicePathToHiiHandle (DevicePath
);
2533 if (Selection
->Handle
== NULL
) {
2535 // If target Hii Handle not found, exit
2537 Selection
->Action
= UI_ACTION_EXIT
;
2538 Selection
->Statement
= NULL
;
2542 FreePool (StringPtr
);
2543 FreePool (DevicePath
);
2545 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2546 Selection
->FormId
= Statement
->RefFormId
;
2547 Selection
->QuestionId
= Statement
->RefQuestionId
;
2548 } else if (!CompareGuid (&Statement
->RefFormSetId
, &gZeroGuid
)) {
2550 // Goto another Formset, check for uncommitted data
2552 ControlFlag
= CfCheckSelection
;
2553 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2555 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2556 Selection
->FormId
= Statement
->RefFormId
;
2557 Selection
->QuestionId
= Statement
->RefQuestionId
;
2558 } else if (Statement
->RefFormId
!= 0) {
2560 // Goto another form inside this formset,
2562 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2565 // Link current form so that we can always go back when someone hits the ESC
2567 MenuList
= UiFindMenuList (&Selection
->FormSetGuid
, Statement
->RefFormId
);
2568 if (MenuList
== NULL
) {
2569 MenuList
= UiAddMenuList (CurrentMenu
, &Selection
->FormSetGuid
, Statement
->RefFormId
);
2572 Selection
->FormId
= Statement
->RefFormId
;
2573 Selection
->QuestionId
= Statement
->RefQuestionId
;
2574 } else if (Statement
->RefQuestionId
!= 0) {
2576 // Goto another Question
2578 Selection
->QuestionId
= Statement
->RefQuestionId
;
2580 if ((Statement
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) {
2581 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2590 case EFI_IFR_ACTION_OP
:
2592 // Process the Config string <ConfigResp>
2594 Status
= ProcessQuestionConfig (Selection
, Statement
);
2596 if (EFI_ERROR (Status
)) {
2601 // The action button may change some Question value, so refresh the form
2603 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2606 case EFI_IFR_RESET_BUTTON_OP
:
2608 // Reset Question to default value specified by DefaultId
2610 ControlFlag
= CfUiDefault
;
2611 DefaultId
= Statement
->DefaultId
;
2616 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
2618 UpdateKeyHelp (Selection
, MenuOption
, TRUE
);
2619 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2621 if (EFI_ERROR (Status
)) {
2624 UpdateKeyHelp (Selection
, MenuOption
, FALSE
);
2626 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2629 if (OptionString
!= NULL
) {
2630 FreePool (OptionString
);
2638 // We come here when someone press ESC
2640 ControlFlag
= CfCheckSelection
;
2642 if (CurrentMenu
->Parent
!= NULL
) {
2644 // we have a parent, so go to the parent menu
2646 if (CompareGuid (&CurrentMenu
->FormSetGuid
, &CurrentMenu
->Parent
->FormSetGuid
)) {
2648 // The parent menu and current menu are in the same formset
2650 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2652 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2654 Selection
->Statement
= NULL
;
2656 Selection
->FormId
= CurrentMenu
->Parent
->FormId
;
2657 Selection
->QuestionId
= CurrentMenu
->Parent
->QuestionId
;
2660 // Clear highlight record for this menu
2662 CurrentMenu
->QuestionId
= 0;
2666 if (gClassOfVfr
== FORMSET_CLASS_FRONT_PAGE
) {
2668 // We never exit FrontPage, so skip the ESC
2670 Selection
->Action
= UI_ACTION_NONE
;
2675 // We are going to leave current FormSet, so check uncommited data in this FormSet
2677 if (gNvUpdateRequired
) {
2678 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2680 YesResponse
= gYesResponse
[0];
2681 NoResponse
= gNoResponse
[0];
2684 // If NV flag is up, prompt user
2687 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gSaveChanges
, gAreYouSure
, gEmptyString
);
2690 (Key
.ScanCode
!= SCAN_ESC
) &&
2691 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (NoResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
2692 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (YesResponse
| UPPER_LOWER_CASE_OFFSET
))
2695 if (Key
.ScanCode
== SCAN_ESC
) {
2697 // User hits the ESC key
2702 Selection
->Action
= UI_ACTION_NONE
;
2707 // If the user hits the YesResponse key
2709 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (YesResponse
| UPPER_LOWER_CASE_OFFSET
)) {
2710 Status
= SubmitForm (Selection
->FormSet
, Selection
->Form
);
2714 Selection
->Action
= UI_ACTION_EXIT
;
2715 Selection
->Statement
= NULL
;
2716 CurrentMenu
->QuestionId
= 0;
2721 ControlFlag
= CfCheckSelection
;
2722 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2723 if (MenuOption
->Sequence
!= 0) {
2725 // In the middle or tail of the Date/Time op-code set, go left.
2727 NewPos
= NewPos
->BackLink
;
2733 ControlFlag
= CfCheckSelection
;
2734 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2735 if (MenuOption
->Sequence
!= 2) {
2737 // In the middle or tail of the Date/Time op-code set, go left.
2739 NewPos
= NewPos
->ForwardLink
;
2745 ControlFlag
= CfCheckSelection
;
2747 SavedListEntry
= TopOfScreen
;
2749 if (NewPos
->BackLink
!= &gMenuOption
) {
2752 // Adjust Date/Time position before we advance forward.
2754 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2757 // Caution that we have already rewind to the top, don't go backward in this situation.
2759 if (NewPos
->BackLink
!= &gMenuOption
) {
2760 NewPos
= NewPos
->BackLink
;
2763 PreviousMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2764 DistanceValue
= PreviousMenuOption
->Skip
;
2767 // Since the behavior of hitting the up arrow on a Date/Time op-code is intended
2768 // to be one that back to the previous set of op-codes, we need to advance to the sencond
2769 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2770 // checking can be done.
2772 DistanceValue
+= AdjustDateAndTimePosition (TRUE
, &NewPos
);
2775 // Check the previous menu entry to see if it was a zero-length advance. If it was,
2776 // don't worry about a redraw.
2778 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2780 TopOfScreen
= NewPos
;
2783 Difference
= MoveToNextStatement (TRUE
, &NewPos
);
2784 PreviousMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2785 DistanceValue
+= PreviousMenuOption
->Skip
;
2787 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2788 if (Difference
> 0) {
2790 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
2792 TopOfScreen
= NewPos
;
2798 if (Difference
< 0) {
2800 // We want to goto previous MenuOption, but finally we go down.
2801 // it means that we hit the begining MenuOption that can be focused
2802 // so we simply scroll to the top
2804 if (SavedListEntry
!= gMenuOption
.ForwardLink
) {
2805 TopOfScreen
= gMenuOption
.ForwardLink
;
2811 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2813 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2815 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2817 SavedMenuOption
= MenuOption
;
2818 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2819 if (!IsSelectable (MenuOption
)) {
2821 // If we are at the end of the list and sitting on a text op, we need to more forward
2823 ScreenOperation
= UiDown
;
2824 ControlFlag
= CfScreenOperation
;
2828 MenuOption
= SavedMenuOption
;
2833 ControlFlag
= CfCheckSelection
;
2835 if (NewPos
->BackLink
== &gMenuOption
) {
2844 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2846 while ((Index
>= TopRow
) && (Link
->BackLink
!= &gMenuOption
)) {
2847 Index
= Index
- PreviousMenuOption
->Skip
;
2848 Link
= Link
->BackLink
;
2849 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2853 Difference
= MoveToNextStatement (TRUE
, &Link
);
2854 if (Difference
> 0) {
2856 // The focus MenuOption is above the TopOfScreen
2859 } else if (Difference
< 0) {
2861 // This happens when there is no MenuOption can be focused from
2862 // Current MenuOption to the first MenuOption
2864 TopOfScreen
= gMenuOption
.ForwardLink
;
2866 Index
+= Difference
;
2867 if (Index
< TopRow
) {
2871 if (NewPos
== Link
) {
2879 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2880 // Don't do this when we are already in the first page.
2882 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2883 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2887 ControlFlag
= CfCheckSelection
;
2889 if (NewPos
->ForwardLink
== &gMenuOption
) {
2898 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2900 while ((Index
<= BottomRow
) && (Link
->ForwardLink
!= &gMenuOption
)) {
2901 Index
= Index
+ NextMenuOption
->Skip
;
2902 Link
= Link
->ForwardLink
;
2903 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2906 Index
+= MoveToNextStatement (FALSE
, &Link
);
2907 if (Index
> BottomRow
) {
2909 // There are more MenuOption needing scrolling
2914 if (NewPos
== Link
&& Index
<= BottomRow
) {
2916 // Finally we know that NewPos is the last MenuOption can be focused.
2925 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2926 // Don't do this when we are already in the last page.
2928 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2929 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2933 ControlFlag
= CfCheckSelection
;
2935 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
2936 // to be one that progresses to the next set of op-codes, we need to advance to the last
2937 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2938 // checking can be done. The only other logic we need to introduce is that if a Date/Time
2939 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
2940 // the Date/Time op-code.
2942 SavedListEntry
= NewPos
;
2943 DistanceValue
= AdjustDateAndTimePosition (FALSE
, &NewPos
);
2945 if (NewPos
->ForwardLink
!= &gMenuOption
) {
2946 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2948 NewPos
= NewPos
->ForwardLink
;
2949 NextMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2951 DistanceValue
+= NextMenuOption
->Skip
;
2952 DistanceValue
+= MoveToNextStatement (FALSE
, &NewPos
);
2954 // An option might be multi-line, so we need to reflect that data in the overall skip value
2956 UpdateOptionSkipLines (Selection
, NextMenuOption
, &OptionString
, SkipValue
);
2958 Temp
= MenuOption
->Row
+ MenuOption
->Skip
+ DistanceValue
- 1;
2959 if ((MenuOption
->Row
+ MenuOption
->Skip
== BottomRow
+ 1) &&
2960 (NextMenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
||
2961 NextMenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
2967 // If we are going to scroll, update TopOfScreen
2969 if (Temp
> BottomRow
) {
2972 // Is the current top of screen a zero-advance op-code?
2973 // If so, keep moving forward till we hit a >0 advance op-code
2975 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2978 // If bottom op-code is more than one line or top op-code is more than one line
2980 if ((DistanceValue
> 1) || (MenuOption
->Skip
> 1)) {
2982 // Is the bottom op-code greater than or equal in size to the top op-code?
2984 if ((Temp
- BottomRow
) >= (SavedMenuOption
->Skip
- OldSkipValue
)) {
2986 // Skip the top op-code
2988 TopOfScreen
= TopOfScreen
->ForwardLink
;
2989 Difference
= (Temp
- BottomRow
) - (SavedMenuOption
->Skip
- OldSkipValue
);
2991 OldSkipValue
= Difference
;
2993 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2996 // If we have a remainder, skip that many more op-codes until we drain the remainder
2999 Difference
>= (INTN
) SavedMenuOption
->Skip
;
3000 Difference
= Difference
- (INTN
) SavedMenuOption
->Skip
3003 // Since the Difference is greater than or equal to this op-code's skip value, skip it
3005 TopOfScreen
= TopOfScreen
->ForwardLink
;
3006 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
3007 if (Difference
< (INTN
) SavedMenuOption
->Skip
) {
3008 Difference
= SavedMenuOption
->Skip
- Difference
- 1;
3011 if (Difference
== (INTN
) SavedMenuOption
->Skip
) {
3012 TopOfScreen
= TopOfScreen
->ForwardLink
;
3013 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
3014 Difference
= SavedMenuOption
->Skip
- Difference
;
3020 // Since we will act on this op-code in the next routine, and increment the
3021 // SkipValue, set the skips to one less than what is required.
3023 SkipValue
= Difference
- 1;
3027 // Since we will act on this op-code in the next routine, and increment the
3028 // SkipValue, set the skips to one less than what is required.
3030 SkipValue
= OldSkipValue
+ (Temp
- BottomRow
) - 1;
3033 if ((OldSkipValue
+ 1) == (INTN
) SavedMenuOption
->Skip
) {
3034 TopOfScreen
= TopOfScreen
->ForwardLink
;
3037 SkipValue
= OldSkipValue
;
3041 // If the op-code at the top of the screen is more than one line, let's not skip it yet
3042 // Let's set a skip flag to smoothly scroll the top of the screen.
3044 if (SavedMenuOption
->Skip
> 1) {
3045 if (SavedMenuOption
== NextMenuOption
) {
3052 TopOfScreen
= TopOfScreen
->ForwardLink
;
3054 } while (SavedMenuOption
->Skip
== 0);
3057 OldSkipValue
= SkipValue
;
3060 MenuOption
= MENU_OPTION_FROM_LINK (SavedListEntry
);
3062 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3065 SavedMenuOption
= MenuOption
;
3066 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
3067 if (!IsSelectable (MenuOption
)) {
3069 // If we are at the end of the list and sitting on a text op, we need to more forward
3071 ScreenOperation
= UiUp
;
3072 ControlFlag
= CfScreenOperation
;
3076 MenuOption
= SavedMenuOption
;
3078 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
3080 AdjustDateAndTimePosition (TRUE
, &NewPos
);
3085 ControlFlag
= CfCheckSelection
;
3090 Status
= SubmitForm (Selection
->FormSet
, Selection
->Form
);
3092 if (!EFI_ERROR (Status
)) {
3093 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3094 UpdateStatusBar (NV_UPDATE_REQUIRED
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3097 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gSaveFailed
, gPressEnter
, gEmptyString
);
3098 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
3106 ControlFlag
= CfCheckSelection
;
3107 if (!Selection
->FormEditable
) {
3109 // This Form is not editable, ignore the F9 (reset to default)
3114 Status
= ExtractFormDefault (Selection
->FormSet
, Selection
->Form
, DefaultId
);
3116 if (!EFI_ERROR (Status
)) {
3117 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
3118 Selection
->Statement
= NULL
;
3121 // Show NV update flag on status bar
3123 gNvUpdateRequired
= TRUE
;
3127 case CfUiNoOperation
:
3128 ControlFlag
= CfCheckSelection
;
3132 UiFreeRefreshList ();
3134 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
3135 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, Row
+ 4);
3136 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
3137 gST
->ConOut
->OutputString (gST
->ConOut
, L
"\n");