2 Utility functions for User Interface functions.
4 Copyright (c) 2004 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
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.
20 MENU_REFRESH_ENTRY
*gMenuRefreshHead
;
23 // Search table for UiDisplayMenu()
25 SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation
[] = {
68 SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag
[] = {
123 Set Buffer to Value for Size bytes.
125 @param Buffer Memory to set.
126 @param Size Number of bytes to set
127 @param Value Value of the set operation.
142 while ((Size
--) != 0) {
149 Initialize Menu option list.
157 InitializeListHead (&Menu
);
162 Initialize Menu option list.
170 InitializeListHead (&gMenuList
);
175 Remove a Menu in list, and return FormId/QuestionId for previous Menu.
177 @param Selection Menu selection.
181 UiRemoveMenuListEntry (
182 OUT UI_MENU_SELECTION
*Selection
185 UI_MENU_LIST
*UiMenuList
;
187 if (!IsListEmpty (&gMenuList
)) {
188 UiMenuList
= CR (gMenuList
.ForwardLink
, UI_MENU_LIST
, MenuLink
, UI_MENU_LIST_SIGNATURE
);
190 Selection
->FormId
= UiMenuList
->FormId
;
191 Selection
->QuestionId
= UiMenuList
->QuestionId
;
192 RemoveEntryList (&UiMenuList
->MenuLink
);
193 gBS
->FreePool (UiMenuList
);
199 Free Menu option linked list.
207 UI_MENU_LIST
*UiMenuList
;
209 while (!IsListEmpty (&gMenuList
)) {
210 UiMenuList
= CR (gMenuList
.ForwardLink
, UI_MENU_LIST
, MenuLink
, UI_MENU_LIST_SIGNATURE
);
211 RemoveEntryList (&UiMenuList
->MenuLink
);
212 gBS
->FreePool (UiMenuList
);
218 Add one menu entry to the linked lst
220 @param Selection Menu selection.
225 IN UI_MENU_SELECTION
*Selection
228 UI_MENU_LIST
*UiMenuList
;
230 UiMenuList
= AllocateZeroPool (sizeof (UI_MENU_LIST
));
231 ASSERT (UiMenuList
!= NULL
);
233 UiMenuList
->Signature
= UI_MENU_LIST_SIGNATURE
;
234 UiMenuList
->FormId
= Selection
->FormId
;
235 UiMenuList
->QuestionId
= Selection
->QuestionId
;
237 InsertHeadList (&gMenuList
, &UiMenuList
->MenuLink
);
242 Free Menu option linked list.
250 UI_MENU_OPTION
*MenuOption
;
252 while (!IsListEmpty (&Menu
)) {
253 MenuOption
= MENU_OPTION_FROM_LINK (Menu
.ForwardLink
);
254 RemoveEntryList (&MenuOption
->Link
);
257 // We allocated space for this description when we did a GetToken, free it here
259 if (MenuOption
->Skip
!= 0) {
261 // For date/time, MenuOption->Description is shared by three Menu Options
262 // Data format : [01/02/2004] [11:22:33]
263 // Line number : 0 0 1 0 0 1
265 gBS
->FreePool (MenuOption
->Description
);
267 gBS
->FreePool (MenuOption
);
273 Free Menu option linked list.
281 MENU_REFRESH_ENTRY
*OldMenuRefreshEntry
;
283 while (gMenuRefreshHead
!= NULL
) {
284 OldMenuRefreshEntry
= gMenuRefreshHead
->Next
;
285 gBS
->FreePool (gMenuRefreshHead
);
286 gMenuRefreshHead
= OldMenuRefreshEntry
;
289 gMenuRefreshHead
= NULL
;
303 CHAR16
*OptionString
;
304 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
308 UI_MENU_SELECTION
*Selection
;
309 FORM_BROWSER_STATEMENT
*Question
;
313 if (gMenuRefreshHead
!= NULL
) {
315 MenuRefreshEntry
= gMenuRefreshHead
;
318 gST
->ConOut
->SetAttribute (gST
->ConOut
, MenuRefreshEntry
->CurrentAttribute
);
320 Selection
= MenuRefreshEntry
->Selection
;
321 Question
= MenuRefreshEntry
->MenuOption
->ThisTag
;
324 // Don't update Question being edited
326 if (Question
!= MenuRefreshEntry
->Selection
->Statement
) {
328 Status
= GetQuestionValue (Selection
->FormSet
, Selection
->Form
, Question
, FALSE
);
329 if (EFI_ERROR (Status
)) {
333 ProcessOptions (Selection
, MenuRefreshEntry
->MenuOption
, FALSE
, &OptionString
);
335 if (OptionString
!= NULL
) {
337 // If leading spaces on OptionString - remove the spaces
339 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
342 for (Loop
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
343 OptionString
[Loop
] = OptionString
[Index
];
347 OptionString
[Loop
] = CHAR_NULL
;
349 PrintStringAt (MenuRefreshEntry
->CurrentColumn
, MenuRefreshEntry
->CurrentRow
, OptionString
);
350 gBS
->FreePool (OptionString
);
354 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
356 } while (MenuRefreshEntry
!= NULL
);
362 Wait for a given event to fire, or for an optional timeout to expire.
364 @param Event The event to wait for
365 @param Timeout An optional timeout value in 100 ns units.
366 @param RefreshInterval Menu refresh interval (in seconds).
368 @retval EFI_SUCCESS Event fired before Timeout expired.
369 @retval EFI_TIME_OUT Timout expired before Event fired.
373 UiWaitForSingleEvent (
375 IN UINT64 Timeout
, OPTIONAL
376 IN UINT8 RefreshInterval OPTIONAL
381 EFI_EVENT TimerEvent
;
382 EFI_EVENT WaitList
[2];
386 // Create a timer event
388 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
389 if (!EFI_ERROR (Status
)) {
391 // Set the timer event
400 // Wait for the original event or the timer
403 WaitList
[1] = TimerEvent
;
404 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
405 gBS
->CloseEvent (TimerEvent
);
408 // If the timer expired, change the return to timed out
410 if (!EFI_ERROR (Status
) && Index
== 1) {
411 Status
= EFI_TIMEOUT
;
416 // Update screen every second
418 if (RefreshInterval
== 0) {
419 Timeout
= ONE_SECOND
;
421 Timeout
= RefreshInterval
* ONE_SECOND
;
425 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
428 // Set the timer event
437 // Wait for the original event or the timer
440 WaitList
[1] = TimerEvent
;
441 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
444 // If the timer expired, update anything that needs a refresh and keep waiting
446 if (!EFI_ERROR (Status
) && Index
== 1) {
447 Status
= EFI_TIMEOUT
;
448 if (RefreshInterval
!= 0) {
453 gBS
->CloseEvent (TimerEvent
);
454 } while (Status
== EFI_TIMEOUT
);
462 Add one menu option by specified description and context.
464 @param String String description for this option.
465 @param Handle Hii handle for the package list.
466 @param Statement Statement of this Menu Option.
467 @param NumberOfLines Display lines for this Menu Option.
468 @param MenuItemCount The index for this Option in the Menu.
474 IN EFI_HII_HANDLE Handle
,
475 IN FORM_BROWSER_STATEMENT
*Statement
,
476 IN UINT16 NumberOfLines
,
477 IN UINT16 MenuItemCount
480 UI_MENU_OPTION
*MenuOption
;
486 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
488 // Add three MenuOptions for Date/Time
489 // Data format : [01/02/2004] [11:22:33]
490 // Line number : 0 0 1 0 0 1
495 if (Statement
->Storage
== NULL
) {
497 // For RTC type of date/time, set default refresh interval to be 1 second
499 if (Statement
->RefreshInterval
== 0) {
500 Statement
->RefreshInterval
= 1;
505 for (Index
= 0; Index
< Count
; Index
++) {
506 MenuOption
= AllocateZeroPool (sizeof (UI_MENU_OPTION
));
509 MenuOption
->Signature
= UI_MENU_OPTION_SIGNATURE
;
510 MenuOption
->Description
= String
;
511 MenuOption
->Handle
= Handle
;
512 MenuOption
->ThisTag
= Statement
;
513 MenuOption
->EntryNumber
= MenuItemCount
;
517 // Override LineNumber for the MenuOption in Date/Time sequence
519 MenuOption
->Skip
= 1;
521 MenuOption
->Skip
= NumberOfLines
;
523 MenuOption
->Sequence
= Index
;
525 if (Statement
->GrayOutExpression
!= NULL
) {
526 MenuOption
->GrayOut
= Statement
->GrayOutExpression
->Result
.Value
.b
;
529 if ((Statement
->ValueExpression
!= NULL
) ||
530 ((Statement
->QuestionFlags
& EFI_IFR_FLAG_READ_ONLY
) != 0)) {
531 MenuOption
->ReadOnly
= TRUE
;
534 InsertTailList (&Menu
, &MenuOption
->Link
);
540 Routine used to abstract a generic dialog interface and return the selected key or string
542 @param NumberOfLines The number of lines for the dialog box
543 @param HotKey Defines whether a single character is parsed
544 (TRUE) and returned in KeyValue or a string is
545 returned in StringBuffer. Two special characters
546 are considered when entering a string, a SCAN_ESC
547 and an CHAR_CARRIAGE_RETURN. SCAN_ESC terminates
548 string input and returns
549 @param MaximumStringSize The maximum size in bytes of a typed in string
550 (each character is a CHAR16) and the minimum
551 string returned is two bytes
552 @param StringBuffer The passed in pointer to the buffer which will
553 hold the typed in string if HotKey is FALSE
554 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
555 @param ... A series of (quantity == NumberOfLines) text
556 strings which will be used to construct the dialog
559 @retval EFI_SUCCESS Displayed dialog and received user interaction
560 @retval EFI_INVALID_PARAMETER One of the parameters was invalid (e.g.
561 (StringBuffer == NULL) && (HotKey == FALSE))
562 @retval EFI_DEVICE_ERROR User typed in an ESC character to exit the routine
567 IN UINTN NumberOfLines
,
569 IN UINTN MaximumStringSize
,
570 OUT CHAR16
*StringBuffer
,
571 OUT EFI_INPUT_KEY
*KeyValue
,
576 VA_LIST MarkerBackup
;
581 CHAR16
*BufferedString
;
588 BOOLEAN SelectionComplete
;
590 UINTN CurrentAttribute
;
591 UINTN DimensionsWidth
;
592 UINTN DimensionsHeight
;
594 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
595 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
597 SelectionComplete
= FALSE
;
599 TempString
= AllocateZeroPool (MaximumStringSize
* 2);
600 BufferedString
= AllocateZeroPool (MaximumStringSize
* 2);
601 CurrentAttribute
= gST
->ConOut
->Mode
->Attribute
;
604 ASSERT (BufferedString
);
606 VA_START (Marker
, KeyValue
);
607 MarkerBackup
= Marker
;
610 // Zero the outgoing buffer
612 ZeroMem (StringBuffer
, MaximumStringSize
);
615 if (KeyValue
== NULL
) {
616 return EFI_INVALID_PARAMETER
;
619 if (StringBuffer
== NULL
) {
620 return EFI_INVALID_PARAMETER
;
626 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
631 // Determine the largest string in the dialog box
632 // Notice we are starting with 1 since String is the first string
634 for (Count
= 0; Count
< NumberOfLines
; Count
++) {
635 StackString
= VA_ARG (Marker
, CHAR16
*);
637 if (StackString
[0] == L
' ') {
638 InputOffset
= Count
+ 1;
641 if ((GetStringWidth (StackString
) / 2) > LargestString
) {
643 // Size of the string visually and subtract the width by one for the null-terminator
645 LargestString
= (GetStringWidth (StackString
) / 2);
649 Start
= (DimensionsWidth
- LargestString
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
650 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
657 CreateSharedPopUp (LargestString
, NumberOfLines
, MarkerBackup
);
660 // Take the first key typed and report it back?
663 Status
= WaitForKeyStroke (&Key
);
664 ASSERT_EFI_ERROR (Status
);
665 CopyMem (KeyValue
, &Key
, sizeof (EFI_INPUT_KEY
));
669 Status
= WaitForKeyStroke (&Key
);
671 switch (Key
.UnicodeChar
) {
673 switch (Key
.ScanCode
) {
675 gBS
->FreePool (TempString
);
676 gBS
->FreePool (BufferedString
);
677 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
678 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
679 return EFI_DEVICE_ERROR
;
687 case CHAR_CARRIAGE_RETURN
:
688 SelectionComplete
= TRUE
;
689 gBS
->FreePool (TempString
);
690 gBS
->FreePool (BufferedString
);
691 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
692 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
697 if (StringBuffer
[0] != CHAR_NULL
) {
698 for (Index
= 0; StringBuffer
[Index
] != CHAR_NULL
; Index
++) {
699 TempString
[Index
] = StringBuffer
[Index
];
702 // Effectively truncate string by 1 character
704 TempString
[Index
- 1] = CHAR_NULL
;
705 StrCpy (StringBuffer
, TempString
);
710 // If it is the beginning of the string, don't worry about checking maximum limits
712 if ((StringBuffer
[0] == CHAR_NULL
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
713 StrnCpy (StringBuffer
, &Key
.UnicodeChar
, 1);
714 StrnCpy (TempString
, &Key
.UnicodeChar
, 1);
715 } else if ((GetStringWidth (StringBuffer
) < MaximumStringSize
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
716 KeyPad
[0] = Key
.UnicodeChar
;
717 KeyPad
[1] = CHAR_NULL
;
718 StrCat (StringBuffer
, KeyPad
);
719 StrCat (TempString
, KeyPad
);
722 // If the width of the input string is now larger than the screen, we nee to
723 // adjust the index to start printing portions of the string
725 SetUnicodeMem (BufferedString
, LargestString
, L
' ');
727 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
729 if ((GetStringWidth (StringBuffer
) / 2) > (DimensionsWidth
- 2)) {
730 Index
= (GetStringWidth (StringBuffer
) / 2) - DimensionsWidth
+ 2;
735 for (Count
= 0; Index
+ 1 < GetStringWidth (StringBuffer
) / 2; Index
++, Count
++) {
736 BufferedString
[Count
] = StringBuffer
[Index
];
739 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
742 } while (!SelectionComplete
);
745 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
746 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
751 Draw a pop up windows based on the dimension, number of lines and
754 @param RequestedWidth The width of the pop-up.
755 @param NumberOfLines The number of lines.
756 @param Marker The variable argument list for the list of string to be printed.
761 IN UINTN RequestedWidth
,
762 IN UINTN NumberOfLines
,
774 UINTN DimensionsWidth
;
775 UINTN DimensionsHeight
;
777 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
778 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
780 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
782 if ((RequestedWidth
+ 2) > DimensionsWidth
) {
783 RequestedWidth
= DimensionsWidth
- 2;
787 // Subtract the PopUp width from total Columns, allow for one space extra on
788 // each end plus a border.
790 Start
= (DimensionsWidth
- RequestedWidth
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
791 End
= Start
+ RequestedWidth
+ 1;
793 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
794 Bottom
= Top
+ NumberOfLines
+ 2;
796 Character
= BOXDRAW_DOWN_RIGHT
;
797 PrintCharAt (Start
, Top
, Character
);
798 Character
= BOXDRAW_HORIZONTAL
;
799 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
800 PrintChar (Character
);
803 Character
= BOXDRAW_DOWN_LEFT
;
804 PrintChar (Character
);
805 Character
= BOXDRAW_VERTICAL
;
808 for (Index
= Top
; Index
+ 2 < Bottom
; Index
++, Count
++) {
809 String
= VA_ARG (Marker
, CHAR16
*);
812 // This will clear the background of the line - we never know who might have been
813 // here before us. This differs from the next clear in that it used the non-reverse
814 // video for normal printing.
816 if (GetStringWidth (String
) / 2 > 1) {
817 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
821 // Passing in a space results in the assumption that this is where typing will occur
823 if (String
[0] == L
' ') {
824 ClearLines (Start
+ 1, End
- 1, Index
+ 1, Index
+ 1, POPUP_INVERSE_TEXT
| POPUP_INVERSE_BACKGROUND
);
828 // Passing in a NULL results in a blank space
830 if (String
[0] == CHAR_NULL
) {
831 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
835 ((DimensionsWidth
- GetStringWidth (String
) / 2) / 2) + gScreenDimensions
.LeftColumn
+ 1,
839 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
840 PrintCharAt (Start
, Index
+ 1, Character
);
841 PrintCharAt (End
- 1, Index
+ 1, Character
);
844 Character
= BOXDRAW_UP_RIGHT
;
845 PrintCharAt (Start
, Bottom
- 1, Character
);
846 Character
= BOXDRAW_HORIZONTAL
;
847 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
848 PrintChar (Character
);
851 Character
= BOXDRAW_UP_LEFT
;
852 PrintChar (Character
);
856 Draw a pop up windows based on the dimension, number of lines and
859 @param RequestedWidth The width of the pop-up.
860 @param NumberOfLines The number of lines.
861 @param ... A series of text strings that displayed in the pop-up.
866 IN UINTN RequestedWidth
,
867 IN UINTN NumberOfLines
,
873 VA_START (Marker
, NumberOfLines
);
875 CreateSharedPopUp (RequestedWidth
, NumberOfLines
, Marker
);
882 Update status bar on the bottom of menu.
884 @param MessageType The type of message to be shown.
885 @param Flags The flags in Question header.
886 @param State Set or clear.
891 IN UINTN MessageType
,
897 CHAR16
*NvUpdateMessage
;
898 CHAR16
*InputErrorMessage
;
900 NvUpdateMessage
= GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE
), gHiiHandle
);
901 InputErrorMessage
= GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE
), gHiiHandle
);
903 switch (MessageType
) {
906 gST
->ConOut
->SetAttribute (gST
->ConOut
, ERROR_TEXT
);
908 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
,
909 gScreenDimensions
.BottomRow
- 1,
914 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
915 for (Index
= 0; Index
< (GetStringWidth (InputErrorMessage
) - 2) / 2; Index
++) {
916 PrintAt (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ Index
, gScreenDimensions
.BottomRow
- 1, L
" ");
923 case NV_UPDATE_REQUIRED
:
924 if (gClassOfVfr
!= EFI_FRONT_PAGE_SUBCLASS
) {
926 gST
->ConOut
->SetAttribute (gST
->ConOut
, INFO_TEXT
);
928 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
,
929 gScreenDimensions
.BottomRow
- 1,
932 gResetRequired
= (BOOLEAN
) (gResetRequired
| ((Flags
& EFI_IFR_FLAG_RESET_REQUIRED
) == EFI_IFR_FLAG_RESET_REQUIRED
));
934 gNvUpdateRequired
= TRUE
;
936 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
937 for (Index
= 0; Index
< (GetStringWidth (NvUpdateMessage
) - 2) / 2; Index
++) {
939 (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ Index
),
940 gScreenDimensions
.BottomRow
- 1,
945 gNvUpdateRequired
= FALSE
;
950 case REFRESH_STATUS_BAR
:
952 UpdateStatusBar (INPUT_ERROR
, Flags
, TRUE
);
955 if (gNvUpdateRequired
) {
956 UpdateStatusBar (NV_UPDATE_REQUIRED
, Flags
, TRUE
);
964 gBS
->FreePool (InputErrorMessage
);
965 gBS
->FreePool (NvUpdateMessage
);
971 Get the supported width for a particular op-code
973 @param Statement The FORM_BROWSER_STATEMENT structure passed in.
974 @param Handle The handle in the HII database being used
976 @return Returns the number of CHAR16 characters that is support.
981 IN FORM_BROWSER_STATEMENT
*Statement
,
982 IN EFI_HII_HANDLE Handle
992 // See if the second text parameter is really NULL
994 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
995 String
= GetToken (Statement
->TextTwo
, Handle
);
996 Size
= StrLen (String
);
997 gBS
->FreePool (String
);
1000 if ((Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1001 (Statement
->Operand
== EFI_IFR_REF_OP
) ||
1002 (Statement
->Operand
== EFI_IFR_PASSWORD_OP
) ||
1003 (Statement
->Operand
== EFI_IFR_ACTION_OP
) ||
1004 (Statement
->Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1006 // Allow a wide display if text op-code and no secondary text op-code
1008 ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Size
== 0))
1010 Width
= (UINT16
) (gPromptBlockWidth
+ gOptionBlockWidth
);
1012 Width
= (UINT16
) gPromptBlockWidth
;
1015 if (Statement
->InSubtitle
) {
1016 Width
-= SUBTITLE_INDENT
;
1023 BOOLEAN GetLineByWidthFinished
= FALSE
;
1026 Will copy LineWidth amount of a string in the OutputString buffer and return the
1027 number of CHAR16 characters that were copied into the OutputString buffer.
1029 @param InputString String description for this option.
1030 @param LineWidth Width of the desired string to extract in CHAR16
1032 @param Index Where in InputString to start the copy process
1033 @param OutputString Buffer to copy the string into
1035 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.
1040 IN CHAR16
*InputString
,
1041 IN UINT16 LineWidth
,
1042 IN OUT UINTN
*Index
,
1043 OUT CHAR16
**OutputString
1049 if (GetLineByWidthFinished
) {
1050 GetLineByWidthFinished
= FALSE
;
1057 *OutputString
= AllocateZeroPool (((UINTN
) (LineWidth
+ 1) * 2));
1060 // Ensure we have got a valid buffer
1062 if (*OutputString
!= NULL
) {
1065 //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.
1066 //To avoid displaying this empty line in screen, just skip the two CHARs here.
1068 if ((InputString
[*Index
] == NARROW_CHAR
) && (InputString
[*Index
+ 1] == CHAR_CARRIAGE_RETURN
)) {
1069 *Index
= *Index
+ 2;
1073 // Fast-forward the string and see if there is a carriage-return in the string
1075 for (; (InputString
[*Index
+ Count2
] != CHAR_CARRIAGE_RETURN
) && (Count2
!= LineWidth
); Count2
++)
1079 // Copy the desired LineWidth of data to the output buffer.
1080 // Also make sure that we don't copy more than the string.
1081 // Also make sure that if there are linefeeds, we account for them.
1083 if ((StrSize (&InputString
[*Index
]) <= ((UINTN
) (LineWidth
+ 1) * 2)) &&
1084 (StrSize (&InputString
[*Index
]) <= ((UINTN
) (Count2
+ 1) * 2))
1087 // Convert to CHAR16 value and show that we are done with this operation
1089 LineWidth
= (UINT16
) ((StrSize (&InputString
[*Index
]) - 2) / 2);
1090 if (LineWidth
!= 0) {
1091 GetLineByWidthFinished
= TRUE
;
1094 if (Count2
== LineWidth
) {
1096 // Rewind the string from the maximum size until we see a space to break the line
1098 for (; (InputString
[*Index
+ LineWidth
] != CHAR_SPACE
) && (LineWidth
!= 0); LineWidth
--)
1100 if (LineWidth
== 0) {
1108 CopyMem (*OutputString
, &InputString
[*Index
], LineWidth
* 2);
1111 // If currently pointing to a space, increment the index to the first non-space character
1114 (InputString
[*Index
+ LineWidth
] == CHAR_SPACE
) || (InputString
[*Index
+ LineWidth
] == CHAR_CARRIAGE_RETURN
);
1118 *Index
= (UINT16
) (*Index
+ LineWidth
);
1127 Update display lines for a Menu Option.
1129 @param Selection The user's selection.
1130 @param MenuOption The MenuOption to be checked.
1131 @param OptionalString The option string.
1132 @param SkipValue The number of lins to skip.
1136 UpdateOptionSkipLines (
1137 IN UI_MENU_SELECTION
*Selection
,
1138 IN UI_MENU_OPTION
*MenuOption
,
1139 OUT CHAR16
**OptionalString
,
1147 CHAR16
*OutputString
;
1148 CHAR16
*OptionString
;
1151 OptionString
= *OptionalString
;
1152 OutputString
= NULL
;
1154 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1156 if (OptionString
!= NULL
) {
1157 Width
= (UINT16
) gOptionBlockWidth
;
1161 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1163 // If there is more string to process print on the next row and increment the Skip value
1165 if (StrLen (&OptionString
[Index
])) {
1166 if (SkipValue
== 0) {
1169 // Since the Number of lines for this menu entry may or may not be reflected accurately
1170 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1171 // some testing to ensure we are keeping this in-sync.
1173 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1175 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1181 gBS
->FreePool (OutputString
);
1182 if (SkipValue
!= 0) {
1190 *OptionalString
= OptionString
;
1195 Check whether this Menu Option could be highlighted.
1197 This is an internal function.
1199 @param MenuOption The MenuOption to be checked.
1201 @retval TRUE This Menu Option is selectable.
1202 @retval FALSE This Menu Option could not be selected.
1207 UI_MENU_OPTION
*MenuOption
1210 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1211 MenuOption
->GrayOut
|| MenuOption
->ReadOnly
) {
1220 Determine if the menu is the last menu that can be selected.
1222 This is an internal function.
1224 @param Direction The scroll direction. False is down. True is up.
1225 @param CurrentPos The current focus.
1227 @return FALSE -- the menu isn't the last menu that can be selected.
1228 @return TRUE -- the menu is the last menu that can be selected.
1233 IN BOOLEAN Direction
,
1234 IN LIST_ENTRY
*CurrentPos
1238 UI_MENU_OPTION
*MenuOption
;
1240 Temp
= Direction
? CurrentPos
->BackLink
: CurrentPos
->ForwardLink
;
1242 if (Temp
== &Menu
) {
1246 for (; Temp
!= &Menu
; Temp
= Direction
? Temp
->BackLink
: Temp
->ForwardLink
) {
1247 MenuOption
= MENU_OPTION_FROM_LINK (Temp
);
1248 if (IsSelectable (MenuOption
)) {
1258 Move to next selectable statement.
1260 This is an internal function.
1262 @param GoUp The navigation direction. TRUE: up, FALSE: down.
1263 @param CurrentPosition Current position.
1265 @return The row distance from current MenuOption to next selectable MenuOption.
1269 MoveToNextStatement (
1271 IN OUT LIST_ENTRY
**CurrentPosition
1277 UI_MENU_OPTION
*NextMenuOption
;
1280 Pos
= *CurrentPosition
;
1284 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1285 if (IsSelectable (NextMenuOption
)) {
1288 if ((GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &Menu
) {
1292 Distance
+= NextMenuOption
->Skip
;
1293 Pos
= (GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1298 // If we hit end there is still no statement can be focused,
1299 // we go backwards to find the statement can be focused.
1302 Pos
= *CurrentPosition
;
1305 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1306 if (IsSelectable (NextMenuOption
)) {
1309 if ((!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &Menu
) {
1313 Distance
-= NextMenuOption
->Skip
;
1314 Pos
= (!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1318 *CurrentPosition
= &NextMenuOption
->Link
;
1324 Adjust Data and Time position accordingly.
1325 Data format : [01/02/2004] [11:22:33]
1326 Line number : 0 0 1 0 0 1
1328 This is an internal function.
1330 @param DirectionUp the up or down direction. False is down. True is
1332 @param CurrentPosition Current position. On return: Point to the last
1333 Option (Year or Second) if up; Point to the first
1334 Option (Month or Hour) if down.
1336 @return Return line number to pad. It is possible that we stand on a zero-advance
1337 @return data or time opcode, so pad one line when we judge if we are going to scroll outside.
1341 AdjustDateAndTimePosition (
1342 IN BOOLEAN DirectionUp
,
1343 IN OUT LIST_ENTRY
**CurrentPosition
1347 LIST_ENTRY
*NewPosition
;
1348 UI_MENU_OPTION
*MenuOption
;
1349 UINTN PadLineNumber
;
1352 NewPosition
= *CurrentPosition
;
1353 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1355 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
1356 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
1358 // Calculate the distance from current position to the last Date/Time MenuOption
1361 while (MenuOption
->Skip
== 0) {
1363 NewPosition
= NewPosition
->ForwardLink
;
1364 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1368 NewPosition
= *CurrentPosition
;
1371 // Since the behavior of hitting the up arrow on a Date/Time MenuOption is intended
1372 // to be one that back to the previous set of MenuOptions, we need to advance to the first
1373 // Date/Time MenuOption and leave the remaining logic in CfUiUp intact so the appropriate
1374 // checking can be done.
1376 while (Count
++ < 2) {
1377 NewPosition
= NewPosition
->BackLink
;
1381 // Since the behavior of hitting the down arrow on a Date/Time MenuOption is intended
1382 // to be one that progresses to the next set of MenuOptions, we need to advance to the last
1383 // Date/Time MenuOption and leave the remaining logic in CfUiDown intact so the appropriate
1384 // checking can be done.
1386 while (Count
-- > 0) {
1387 NewPosition
= NewPosition
->ForwardLink
;
1391 *CurrentPosition
= NewPosition
;
1394 return PadLineNumber
;
1399 Display menu and wait for user to select one menu option, then return it.
1400 If AutoBoot is enabled, then if user doesn't select any option,
1401 after period of time, it will automatically return the first menu option.
1403 @param Selection Menu selection.
1405 @retval EFI_SUCESSS This function always return successfully for now.
1410 IN OUT UI_MENU_SELECTION
*Selection
1416 UINTN DistanceValue
;
1428 CHAR16
*OptionString
;
1429 CHAR16
*OutputString
;
1430 CHAR16
*FormattedString
;
1440 LIST_ENTRY
*TopOfScreen
;
1441 LIST_ENTRY
*SavedListEntry
;
1442 UI_MENU_OPTION
*MenuOption
;
1443 UI_MENU_OPTION
*NextMenuOption
;
1444 UI_MENU_OPTION
*SavedMenuOption
;
1445 UI_MENU_OPTION
*PreviousMenuOption
;
1446 UI_CONTROL_FLAG ControlFlag
;
1447 EFI_SCREEN_DESCRIPTOR LocalScreen
;
1448 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
1449 UI_SCREEN_OPERATION ScreenOperation
;
1450 UINT8 MinRefreshInterval
;
1453 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1454 FORM_BROWSER_STATEMENT
*Statement
;
1456 CopyMem (&LocalScreen
, &gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1458 Status
= EFI_SUCCESS
;
1459 FormattedString
= NULL
;
1460 OptionString
= NULL
;
1461 ScreenOperation
= UiNoOperation
;
1463 MinRefreshInterval
= 0;
1466 OutputString
= NULL
;
1471 MenuRefreshEntry
= gMenuRefreshHead
;
1473 NextMenuOption
= NULL
;
1474 PreviousMenuOption
= NULL
;
1475 SavedMenuOption
= NULL
;
1477 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
1479 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
1480 TopRow
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1481 Row
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1483 TopRow
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1484 Row
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1487 Col
= LocalScreen
.LeftColumn
;
1488 BottomRow
= LocalScreen
.BottomRow
- STATUS_BAR_HEIGHT
- FOOTER_HEIGHT
- SCROLL_ARROW_HEIGHT
- 1;
1490 Selection
->TopRow
= TopRow
;
1491 Selection
->BottomRow
= BottomRow
;
1492 Selection
->PromptCol
= Col
;
1493 Selection
->OptionCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1494 Selection
->Statement
= NULL
;
1496 TopOfScreen
= Menu
.ForwardLink
;
1501 // Get user's selection
1503 NewPos
= Menu
.ForwardLink
;
1505 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
1506 UpdateStatusBar (REFRESH_STATUS_BAR
, (UINT8
) 0, TRUE
);
1508 ControlFlag
= CfInitialization
;
1509 Selection
->Action
= UI_ACTION_NONE
;
1511 switch (ControlFlag
) {
1512 case CfInitialization
:
1513 if (IsListEmpty (&Menu
)) {
1514 ControlFlag
= CfReadKey
;
1516 ControlFlag
= CfCheckSelection
;
1520 case CfCheckSelection
:
1521 if (Selection
->Action
!= UI_ACTION_NONE
) {
1522 ControlFlag
= CfExit
;
1524 ControlFlag
= CfRepaint
;
1529 ControlFlag
= CfRefreshHighLight
;
1543 LocalScreen
.LeftColumn
,
1544 LocalScreen
.RightColumn
,
1545 TopRow
- SCROLL_ARROW_HEIGHT
,
1546 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1547 FIELD_TEXT
| FIELD_BACKGROUND
1550 UiFreeRefreshList ();
1551 MinRefreshInterval
= 0;
1553 for (Link
= TopOfScreen
; Link
!= &Menu
; Link
= Link
->ForwardLink
) {
1554 MenuOption
= MENU_OPTION_FROM_LINK (Link
);
1555 MenuOption
->Row
= Row
;
1556 MenuOption
->Col
= Col
;
1557 MenuOption
->OptCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1559 Statement
= MenuOption
->ThisTag
;
1560 if (Statement
->InSubtitle
) {
1561 MenuOption
->Col
+= SUBTITLE_INDENT
;
1564 if (MenuOption
->GrayOut
) {
1565 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
1567 if (Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) {
1568 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
1572 Width
= GetWidth (Statement
, MenuOption
->Handle
);
1575 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
1576 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1577 PrintStringAt (MenuOption
->Col
, Row
, OutputString
);
1580 // If there is more string to process print on the next row and increment the Skip value
1582 if (StrLen (&MenuOption
->Description
[Index
])) {
1588 gBS
->FreePool (OutputString
);
1597 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1598 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1600 if (OptionString
!= NULL
) {
1601 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
1603 // If leading spaces on OptionString - remove the spaces
1605 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++) {
1606 MenuOption
->OptCol
++;
1609 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1610 OptionString
[Count
] = OptionString
[Index
];
1614 OptionString
[Count
] = CHAR_NULL
;
1618 // If Question request refresh, register the op-code
1620 if (Statement
->RefreshInterval
!= 0) {
1622 // Menu will be refreshed at minimal interval of all Questions
1623 // which have refresh request
1625 if (MinRefreshInterval
== 0 || Statement
->RefreshInterval
< MinRefreshInterval
) {
1626 MinRefreshInterval
= Statement
->RefreshInterval
;
1629 if (gMenuRefreshHead
== NULL
) {
1630 MenuRefreshEntry
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1631 ASSERT (MenuRefreshEntry
!= NULL
);
1632 MenuRefreshEntry
->MenuOption
= MenuOption
;
1633 MenuRefreshEntry
->Selection
= Selection
;
1634 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1635 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1636 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1637 gMenuRefreshHead
= MenuRefreshEntry
;
1640 // Advance to the last entry
1642 for (MenuRefreshEntry
= gMenuRefreshHead
;
1643 MenuRefreshEntry
->Next
!= NULL
;
1644 MenuRefreshEntry
= MenuRefreshEntry
->Next
1647 MenuRefreshEntry
->Next
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1648 ASSERT (MenuRefreshEntry
->Next
!= NULL
);
1649 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
1650 MenuRefreshEntry
->MenuOption
= MenuOption
;
1651 MenuRefreshEntry
->Selection
= Selection
;
1652 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1653 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1654 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1658 Width
= (UINT16
) gOptionBlockWidth
;
1661 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1662 if ((Temp2
== 0) && (Row
<= BottomRow
)) {
1663 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1666 // If there is more string to process print on the next row and increment the Skip value
1668 if (StrLen (&OptionString
[Index
])) {
1672 // Since the Number of lines for this menu entry may or may not be reflected accurately
1673 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1674 // some testing to ensure we are keeping this in-sync.
1676 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1678 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1684 gBS
->FreePool (OutputString
);
1693 gBS
->FreePool (OptionString
);
1696 // If this is a text op with secondary text information
1698 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1699 StringPtr
= GetToken (Statement
->TextTwo
, MenuOption
->Handle
);
1701 Width
= (UINT16
) gOptionBlockWidth
;
1704 for (Index
= 0; GetLineByWidth (StringPtr
, Width
, &Index
, &OutputString
) != 0x0000;) {
1705 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1706 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1709 // If there is more string to process print on the next row and increment the Skip value
1711 if (StrLen (&StringPtr
[Index
])) {
1715 // Since the Number of lines for this menu entry may or may not be reflected accurately
1716 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1717 // some testing to ensure we are keeping this in-sync.
1719 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1721 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1727 gBS
->FreePool (OutputString
);
1734 gBS
->FreePool (StringPtr
);
1738 // Need to handle the bottom of the display
1740 if (MenuOption
->Skip
> 1) {
1741 Row
+= MenuOption
->Skip
- SkipValue
;
1744 Row
+= MenuOption
->Skip
;
1747 if (Row
> BottomRow
) {
1748 if (!ValueIsScroll (FALSE
, Link
)) {
1752 Row
= BottomRow
+ 1;
1757 if (!ValueIsScroll (TRUE
, TopOfScreen
)) {
1762 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
1764 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
1765 TopRow
- SCROLL_ARROW_HEIGHT
,
1769 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1773 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
1775 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
1776 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1780 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1787 case CfRefreshHighLight
:
1789 // MenuOption: Last menu option that need to remove hilight
1790 // MenuOption is set to NULL in Repaint
1791 // NewPos: Current menu option that need to hilight
1793 ControlFlag
= CfUpdateHelpString
;
1796 // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily
1797 // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.
1799 SavedValue
= Repaint
;
1802 if (Selection
->QuestionId
!= 0) {
1803 NewPos
= Menu
.ForwardLink
;
1804 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1806 while (SavedMenuOption
->ThisTag
->QuestionId
!= Selection
->QuestionId
&& NewPos
->ForwardLink
!= &Menu
) {
1807 NewPos
= NewPos
->ForwardLink
;
1808 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1810 if (SavedMenuOption
->ThisTag
->QuestionId
== Selection
->QuestionId
) {
1812 // Target Question found, find its MenuOption
1816 for (Index
= TopRow
; Index
<= BottomRow
&& Link
!= NewPos
;) {
1817 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
1818 Index
+= SavedMenuOption
->Skip
;
1819 Link
= Link
->ForwardLink
;
1822 if (Link
!= NewPos
|| Index
> BottomRow
) {
1824 // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page
1827 for (Index
= TopRow
; Index
<= BottomRow
; ) {
1828 Link
= Link
->BackLink
;
1829 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
1830 Index
+= SavedMenuOption
->Skip
;
1832 TopOfScreen
= Link
->ForwardLink
;
1836 ControlFlag
= CfRepaint
;
1841 // Target Question not found, highlight the default menu option
1843 NewPos
= TopOfScreen
;
1846 Selection
->QuestionId
= 0;
1849 if (NewPos
!= NULL
&& (MenuOption
== NULL
|| NewPos
!= &MenuOption
->Link
)) {
1850 if (MenuOption
!= NULL
) {
1852 // Remove highlight on last Menu Option
1854 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
1855 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1856 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1857 if (OptionString
!= NULL
) {
1858 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
1859 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
1862 // If leading spaces on OptionString - remove the spaces
1864 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
1867 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1868 OptionString
[Count
] = OptionString
[Index
];
1872 OptionString
[Count
] = CHAR_NULL
;
1875 Width
= (UINT16
) gOptionBlockWidth
;
1876 OriginalRow
= MenuOption
->Row
;
1878 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1879 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
1880 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
1883 // If there is more string to process print on the next row and increment the Skip value
1885 if (StrLen (&OptionString
[Index
])) {
1889 gBS
->FreePool (OutputString
);
1892 MenuOption
->Row
= OriginalRow
;
1894 gBS
->FreePool (OptionString
);
1897 if (MenuOption
->GrayOut
) {
1898 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
1899 } else if (MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) {
1900 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
1903 OriginalRow
= MenuOption
->Row
;
1904 Width
= GetWidth (MenuOption
->ThisTag
, MenuOption
->Handle
);
1906 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
1907 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
1908 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
1911 // If there is more string to process print on the next row and increment the Skip value
1913 if (StrLen (&MenuOption
->Description
[Index
])) {
1917 gBS
->FreePool (OutputString
);
1920 MenuOption
->Row
= OriginalRow
;
1921 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1927 // This is only possible if we entered this page and the first menu option is
1928 // a "non-menu" item. In that case, force it UiDown
1930 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1931 if (!IsSelectable (MenuOption
)) {
1932 ASSERT (ScreenOperation
== UiNoOperation
);
1933 ScreenOperation
= UiDown
;
1934 ControlFlag
= CfScreenOperation
;
1939 // This is the current selected statement
1941 Statement
= MenuOption
->ThisTag
;
1942 Selection
->Statement
= Statement
;
1945 // Set reverse attribute
1947 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
);
1948 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
1951 // Assuming that we have a refresh linked-list created, lets annotate the
1952 // appropriate entry that we are highlighting with its new attribute. Just prior to this
1953 // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh
1955 if (gMenuRefreshHead
!= NULL
) {
1956 for (MenuRefreshEntry
= gMenuRefreshHead
; MenuRefreshEntry
!= NULL
; MenuRefreshEntry
= MenuRefreshEntry
->Next
) {
1957 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1958 if (MenuRefreshEntry
->MenuOption
== MenuOption
) {
1959 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
;
1964 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1965 if (OptionString
!= NULL
) {
1966 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
1968 // If leading spaces on OptionString - remove the spaces
1970 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
1973 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1974 OptionString
[Count
] = OptionString
[Index
];
1978 OptionString
[Count
] = CHAR_NULL
;
1980 Width
= (UINT16
) gOptionBlockWidth
;
1982 OriginalRow
= MenuOption
->Row
;
1984 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1985 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
1986 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
1989 // If there is more string to process print on the next row and increment the Skip value
1991 if (StrLen (&OptionString
[Index
])) {
1995 gBS
->FreePool (OutputString
);
1998 MenuOption
->Row
= OriginalRow
;
2000 gBS
->FreePool (OptionString
);
2003 OriginalRow
= MenuOption
->Row
;
2005 Width
= GetWidth (Statement
, MenuOption
->Handle
);
2007 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2008 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2009 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2012 // If there is more string to process print on the next row and increment the Skip value
2014 if (StrLen (&MenuOption
->Description
[Index
])) {
2018 gBS
->FreePool (OutputString
);
2021 MenuOption
->Row
= OriginalRow
;
2026 if (((NewPos
->ForwardLink
!= &Menu
) && (ScreenOperation
== UiDown
)) ||
2027 ((NewPos
->BackLink
!= &Menu
) && (ScreenOperation
== UiUp
)) ||
2028 (ScreenOperation
== UiNoOperation
)
2030 UpdateKeyHelp (MenuOption
, FALSE
);
2033 // Clear reverse attribute
2035 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2038 // Repaint flag will be used when process CfUpdateHelpString, so restore its value
2039 // if we didn't break halfway when process CfRefreshHighLight.
2041 Repaint
= SavedValue
;
2044 case CfUpdateHelpString
:
2045 ControlFlag
= CfPrepareToReadKey
;
2047 if ((Repaint
|| NewLine
) && (gClassOfVfr
!= EFI_GENERAL_APPLICATION_SUBCLASS
)) {
2049 // Don't print anything if it is a NULL help token
2051 if (MenuOption
->ThisTag
->Help
== 0) {
2054 StringPtr
= GetToken (MenuOption
->ThisTag
->Help
, MenuOption
->Handle
);
2057 ProcessHelpString (StringPtr
, &FormattedString
, BottomRow
- TopRow
);
2059 gST
->ConOut
->SetAttribute (gST
->ConOut
, HELP_TEXT
| FIELD_BACKGROUND
);
2061 for (Index
= 0; Index
< BottomRow
- TopRow
; Index
++) {
2063 // Pad String with spaces to simulate a clearing of the previous line
2065 for (; GetStringWidth (&FormattedString
[Index
* gHelpBlockWidth
* 2]) / 2 < gHelpBlockWidth
;) {
2066 StrCat (&FormattedString
[Index
* gHelpBlockWidth
* 2], L
" ");
2070 LocalScreen
.RightColumn
- gHelpBlockWidth
,
2072 &FormattedString
[Index
* gHelpBlockWidth
* 2]
2077 // Reset this flag every time we finish using it.
2083 case CfPrepareToReadKey
:
2084 ControlFlag
= CfReadKey
;
2085 ScreenOperation
= UiNoOperation
;
2089 ControlFlag
= CfScreenOperation
;
2092 // Wait for user's selection
2095 Status
= UiWaitForSingleEvent (gST
->ConIn
->WaitForKey
, 0, MinRefreshInterval
);
2096 } while (Status
== EFI_TIMEOUT
);
2098 if (Status
== EFI_TIMEOUT
) {
2099 Key
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
2101 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2103 // if we encounter error, continue to read another key in.
2105 if (EFI_ERROR (Status
)) {
2106 ControlFlag
= CfReadKey
;
2111 if (IsListEmpty (&Menu
) && Key
.UnicodeChar
!= CHAR_NULL
) {
2113 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2118 switch (Key
.UnicodeChar
) {
2119 case CHAR_CARRIAGE_RETURN
:
2120 ScreenOperation
= UiSelect
;
2125 // We will push the adjustment of these numeric values directly to the input handler
2126 // NOTE: we won't handle manual input numeric
2130 Statement
= MenuOption
->ThisTag
;
2131 if ((Statement
->Operand
== EFI_IFR_DATE_OP
)
2132 || (Statement
->Operand
== EFI_IFR_TIME_OP
)
2133 || ((Statement
->Operand
== EFI_IFR_NUMERIC_OP
) && (Statement
->Step
!= 0))
2135 if (Key
.UnicodeChar
== '+') {
2136 gDirection
= SCAN_RIGHT
;
2138 gDirection
= SCAN_LEFT
;
2140 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2141 if (OptionString
!= NULL
) {
2142 FreePool (OptionString
);
2148 ScreenOperation
= UiUp
;
2153 ScreenOperation
= UiDown
;
2157 if (gClassOfVfr
!= EFI_FRONT_PAGE_SUBCLASS
) {
2158 if (MenuOption
->ThisTag
->Operand
== EFI_IFR_CHECKBOX_OP
&& !MenuOption
->GrayOut
) {
2159 ScreenOperation
= UiSelect
;
2165 if (((Key
.ScanCode
== SCAN_F1
) && ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
)) ||
2166 ((Key
.ScanCode
== SCAN_F2
) && ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
)) ||
2167 ((Key
.ScanCode
== SCAN_F9
) && ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
)) ||
2168 ((Key
.ScanCode
== SCAN_F10
) && ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
))
2171 // If the function key has been disabled, just ignore the key.
2174 for (Index
= 0; Index
< sizeof (gScanCodeToOperation
) / sizeof (gScanCodeToOperation
[0]); Index
++) {
2175 if (Key
.ScanCode
== gScanCodeToOperation
[Index
].ScanCode
) {
2176 if (Key
.ScanCode
== SCAN_F9
) {
2178 // Reset to standard default
2180 DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2182 ScreenOperation
= gScanCodeToOperation
[Index
].ScreenOperation
;
2191 case CfScreenOperation
:
2192 if (ScreenOperation
!= UiPrevious
&& ScreenOperation
!= UiReset
) {
2194 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2195 // ignore the selection and go back to reading keys.
2197 if (IsListEmpty (&Menu
)) {
2198 ControlFlag
= CfReadKey
;
2202 // if there is nothing logical to place a cursor on, just move on to wait for a key.
2204 for (Link
= Menu
.ForwardLink
; Link
!= &Menu
; Link
= Link
->ForwardLink
) {
2205 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2206 if (IsSelectable (NextMenuOption
)) {
2211 if (Link
== &Menu
) {
2212 ControlFlag
= CfPrepareToReadKey
;
2215 } else if (ScreenOperation
== UiReset
) {
2217 // Press ESC to exit FormSet
2219 Selection
->Action
= UI_ACTION_EXIT
;
2220 Selection
->Statement
= NULL
;
2224 Index
< sizeof (gScreenOperationToControlFlag
) / sizeof (gScreenOperationToControlFlag
[0]);
2227 if (ScreenOperation
== gScreenOperationToControlFlag
[Index
].ScreenOperation
) {
2228 ControlFlag
= gScreenOperationToControlFlag
[Index
].ControlFlag
;
2235 ControlFlag
= CfCheckSelection
;
2237 if (IsListEmpty (&gMenuList
)) {
2238 Selection
->Action
= UI_ACTION_NONE
;
2239 if (IsListEmpty (&Menu
)) {
2240 ControlFlag
= CfReadKey
;
2246 // Remove the Cached page entry
2248 UiRemoveMenuListEntry (Selection
);
2250 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2251 Selection
->Statement
= NULL
;
2255 ControlFlag
= CfCheckSelection
;
2257 Statement
= MenuOption
->ThisTag
;
2258 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) ||
2259 (Statement
->Operand
== EFI_IFR_DATE_OP
) ||
2260 (Statement
->Operand
== EFI_IFR_TIME_OP
) ||
2261 (Statement
->Operand
== EFI_IFR_NUMERIC_OP
&& Statement
->Step
!= 0)) {
2266 // Keep highlight on current MenuOption
2268 Selection
->QuestionId
= Statement
->QuestionId
;
2270 switch (Statement
->Operand
) {
2271 case EFI_IFR_REF_OP
:
2272 if (Statement
->RefDevicePath
!= 0) {
2274 // Goto another Hii Package list
2276 ControlFlag
= CfUiReset
;
2277 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2279 StringPtr
= GetToken (Statement
->RefDevicePath
, Selection
->FormSet
->HiiHandle
);
2280 if (StringPtr
== NULL
) {
2282 // No device path string not found, exit
2284 Selection
->Action
= UI_ACTION_EXIT
;
2285 Selection
->Statement
= NULL
;
2288 BufferSize
= StrLen (StringPtr
) / 2;
2289 DevicePath
= AllocatePool (BufferSize
);
2291 HexStringToBufInReverseOrder ((UINT8
*) DevicePath
, &BufferSize
, StringPtr
);
2292 Selection
->Handle
= HiiLibDevicePathToHiiHandle (DevicePath
);
2293 if (Selection
->Handle
== NULL
) {
2295 // If target Hii Handle not found, exit
2297 Selection
->Action
= UI_ACTION_EXIT
;
2298 Selection
->Statement
= NULL
;
2302 gBS
->FreePool (StringPtr
);
2303 gBS
->FreePool (DevicePath
);
2305 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2306 Selection
->FormId
= Statement
->RefFormId
;
2307 Selection
->QuestionId
= Statement
->RefQuestionId
;
2308 } else if (!CompareGuid (&Statement
->RefFormSetId
, &gZeroGuid
)) {
2310 // Goto another Formset, check for uncommitted data
2312 ControlFlag
= CfUiReset
;
2313 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2315 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2316 Selection
->FormId
= Statement
->RefFormId
;
2317 Selection
->QuestionId
= Statement
->RefQuestionId
;
2318 } else if (Statement
->RefFormId
!= 0) {
2320 // Goto another form inside this formset,
2322 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2325 // Link current form so that we can always go back when someone hits the UiPrevious
2327 UiAddMenuListEntry (Selection
);
2329 Selection
->FormId
= Statement
->RefFormId
;
2330 Selection
->QuestionId
= Statement
->RefQuestionId
;
2331 } else if (Statement
->RefQuestionId
!= 0) {
2333 // Goto another Question
2335 Selection
->QuestionId
= Statement
->RefQuestionId
;
2337 if ((Statement
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) {
2338 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2347 case EFI_IFR_ACTION_OP
:
2349 // Process the Config string <ConfigResp>
2351 Status
= ProcessQuestionConfig (Selection
, Statement
);
2353 if (EFI_ERROR (Status
)) {
2358 // The action button may change some Question value, so refresh the form
2360 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2363 case EFI_IFR_RESET_BUTTON_OP
:
2365 // Reset Question to default value specified by DefaultId
2367 ControlFlag
= CfUiDefault
;
2368 DefaultId
= Statement
->DefaultId
;
2373 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
2375 UpdateKeyHelp (MenuOption
, TRUE
);
2376 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2378 if (EFI_ERROR (Status
)) {
2384 if (OptionString
!= NULL
) {
2385 PrintStringAt (LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ 1, MenuOption
->Row
, OptionString
);
2386 gBS
->FreePool (OptionString
);
2389 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2396 // We are going to leave current FormSet, so check uncommited data in this FormSet
2398 ControlFlag
= CfCheckSelection
;
2400 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2402 // There is no parent menu for FrontPage
2404 Selection
->Action
= UI_ACTION_NONE
;
2405 Selection
->Statement
= MenuOption
->ThisTag
;
2410 // If NV flag is up, prompt user
2412 if (gNvUpdateRequired
) {
2413 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2415 YesResponse
= gYesResponse
[0];
2416 NoResponse
= gNoResponse
[0];
2419 CreateDialog (3, TRUE
, 0, NULL
, &Key
, gEmptyString
, gAreYouSure
, gEmptyString
);
2422 (Key
.ScanCode
!= SCAN_ESC
) &&
2423 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (NoResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
2424 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (YesResponse
| UPPER_LOWER_CASE_OFFSET
))
2428 // If the user hits the YesResponse key
2430 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (YesResponse
| UPPER_LOWER_CASE_OFFSET
)) {
2435 Selection
->Action
= UI_ACTION_NONE
;
2440 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2441 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2444 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2448 ControlFlag
= CfCheckSelection
;
2449 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2450 if (MenuOption
->Sequence
!= 0) {
2452 // In the middle or tail of the Date/Time op-code set, go left.
2454 NewPos
= NewPos
->BackLink
;
2460 ControlFlag
= CfCheckSelection
;
2461 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2462 if (MenuOption
->Sequence
!= 2) {
2464 // In the middle or tail of the Date/Time op-code set, go left.
2466 NewPos
= NewPos
->ForwardLink
;
2472 ControlFlag
= CfCheckSelection
;
2474 SavedListEntry
= TopOfScreen
;
2476 if (NewPos
->BackLink
!= &Menu
) {
2479 // Adjust Date/Time position before we advance forward.
2481 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2484 // Caution that we have already rewind to the top, don't go backward in this situation.
2486 if (NewPos
->BackLink
!= &Menu
) {
2487 NewPos
= NewPos
->BackLink
;
2490 PreviousMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2491 DistanceValue
= PreviousMenuOption
->Skip
;
2494 // Since the behavior of hitting the up arrow on a Date/Time op-code is intended
2495 // to be one that back to the previous set of op-codes, we need to advance to the sencond
2496 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2497 // checking can be done.
2499 DistanceValue
+= AdjustDateAndTimePosition (TRUE
, &NewPos
);
2502 // Check the previous menu entry to see if it was a zero-length advance. If it was,
2503 // don't worry about a redraw.
2505 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2507 TopOfScreen
= NewPos
;
2510 Difference
= MoveToNextStatement (TRUE
, &NewPos
);
2511 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2512 if (Difference
> 0) {
2514 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
2516 TopOfScreen
= NewPos
;
2520 if (Difference
< 0) {
2522 // We want to goto previous MenuOption, but finally we go down.
2523 // it means that we hit the begining MenuOption that can be focused
2524 // so we simply scroll to the top
2526 if (SavedListEntry
!= Menu
.ForwardLink
) {
2527 TopOfScreen
= Menu
.ForwardLink
;
2533 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2535 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2537 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2539 SavedMenuOption
= MenuOption
;
2540 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2541 if (!IsSelectable (MenuOption
)) {
2543 // If we are at the end of the list and sitting on a text op, we need to more forward
2545 ScreenOperation
= UiDown
;
2546 ControlFlag
= CfScreenOperation
;
2550 MenuOption
= SavedMenuOption
;
2555 ControlFlag
= CfCheckSelection
;
2557 if (NewPos
->BackLink
== &Menu
) {
2566 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2568 while ((Index
>= TopRow
) && (Link
->BackLink
!= &Menu
)) {
2569 Index
= Index
- PreviousMenuOption
->Skip
;
2570 Link
= Link
->BackLink
;
2571 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2575 Difference
= MoveToNextStatement (TRUE
, &Link
);
2576 if (Difference
> 0) {
2578 // The focus MenuOption is above the TopOfScreen
2581 } else if (Difference
< 0) {
2583 // This happens when there is no MenuOption can be focused from
2584 // Current MenuOption to the first MenuOption
2586 TopOfScreen
= Menu
.ForwardLink
;
2588 Index
+= Difference
;
2589 if (Index
< TopRow
) {
2593 if (NewPos
== Link
) {
2601 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2602 // Don't do this when we are already in the first page.
2604 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2605 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2609 ControlFlag
= CfCheckSelection
;
2611 if (NewPos
->ForwardLink
== &Menu
) {
2620 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2622 while ((Index
<= BottomRow
) && (Link
->ForwardLink
!= &Menu
)) {
2623 Index
= Index
+ NextMenuOption
->Skip
;
2624 Link
= Link
->ForwardLink
;
2625 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2628 Index
+= MoveToNextStatement (FALSE
, &Link
);
2629 if (Index
> BottomRow
) {
2631 // There are more MenuOption needing scrolling
2636 if (NewPos
== Link
&& Index
<= BottomRow
) {
2638 // Finally we know that NewPos is the last MenuOption can be focused.
2647 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2648 // Don't do this when we are already in the last page.
2650 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2651 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2655 ControlFlag
= CfCheckSelection
;
2657 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
2658 // to be one that progresses to the next set of op-codes, we need to advance to the last
2659 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2660 // checking can be done. The only other logic we need to introduce is that if a Date/Time
2661 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
2662 // the Date/Time op-code.
2664 SavedListEntry
= NewPos
;
2665 DistanceValue
= AdjustDateAndTimePosition (FALSE
, &NewPos
);
2667 if (NewPos
->ForwardLink
!= &Menu
) {
2668 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2670 NewPos
= NewPos
->ForwardLink
;
2671 NextMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2673 DistanceValue
+= NextMenuOption
->Skip
;
2674 DistanceValue
+= MoveToNextStatement (FALSE
, &NewPos
);
2676 // An option might be multi-line, so we need to reflect that data in the overall skip value
2678 UpdateOptionSkipLines (Selection
, NextMenuOption
, &OptionString
, SkipValue
);
2680 Temp
= MenuOption
->Row
+ MenuOption
->Skip
+ DistanceValue
- 1;
2681 if ((MenuOption
->Row
+ MenuOption
->Skip
== BottomRow
+ 1) &&
2682 (NextMenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
||
2683 NextMenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
2689 // If we are going to scroll, update TopOfScreen
2691 if (Temp
> BottomRow
) {
2694 // Is the current top of screen a zero-advance op-code?
2695 // If so, keep moving forward till we hit a >0 advance op-code
2697 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2700 // If bottom op-code is more than one line or top op-code is more than one line
2702 if ((DistanceValue
> 1) || (MenuOption
->Skip
> 1)) {
2704 // Is the bottom op-code greater than or equal in size to the top op-code?
2706 if ((Temp
- BottomRow
) >= (SavedMenuOption
->Skip
- OldSkipValue
)) {
2708 // Skip the top op-code
2710 TopOfScreen
= TopOfScreen
->ForwardLink
;
2711 Difference
= (Temp
- BottomRow
) - (SavedMenuOption
->Skip
- OldSkipValue
);
2713 OldSkipValue
= Difference
;
2715 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2718 // If we have a remainder, skip that many more op-codes until we drain the remainder
2721 Difference
>= (INTN
) SavedMenuOption
->Skip
;
2722 Difference
= Difference
- (INTN
) SavedMenuOption
->Skip
2725 // Since the Difference is greater than or equal to this op-code's skip value, skip it
2727 TopOfScreen
= TopOfScreen
->ForwardLink
;
2728 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2729 if (Difference
< (INTN
) SavedMenuOption
->Skip
) {
2730 Difference
= SavedMenuOption
->Skip
- Difference
- 1;
2733 if (Difference
== (INTN
) SavedMenuOption
->Skip
) {
2734 TopOfScreen
= TopOfScreen
->ForwardLink
;
2735 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2736 Difference
= SavedMenuOption
->Skip
- Difference
;
2742 // Since we will act on this op-code in the next routine, and increment the
2743 // SkipValue, set the skips to one less than what is required.
2745 SkipValue
= Difference
- 1;
2749 // Since we will act on this op-code in the next routine, and increment the
2750 // SkipValue, set the skips to one less than what is required.
2752 SkipValue
= OldSkipValue
+ (Temp
- BottomRow
) - 1;
2755 if ((OldSkipValue
+ 1) == (INTN
) SavedMenuOption
->Skip
) {
2756 TopOfScreen
= TopOfScreen
->ForwardLink
;
2759 SkipValue
= OldSkipValue
;
2763 // If the op-code at the top of the screen is more than one line, let's not skip it yet
2764 // Let's set a skip flag to smoothly scroll the top of the screen.
2766 if (SavedMenuOption
->Skip
> 1) {
2767 if (SavedMenuOption
== NextMenuOption
) {
2774 TopOfScreen
= TopOfScreen
->ForwardLink
;
2776 } while (SavedMenuOption
->Skip
== 0);
2779 OldSkipValue
= SkipValue
;
2782 MenuOption
= MENU_OPTION_FROM_LINK (SavedListEntry
);
2784 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2787 SavedMenuOption
= MenuOption
;
2788 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2789 if (!IsSelectable (MenuOption
)) {
2791 // If we are at the end of the list and sitting on a text op, we need to more forward
2793 ScreenOperation
= UiUp
;
2794 ControlFlag
= CfScreenOperation
;
2798 MenuOption
= SavedMenuOption
;
2800 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
2802 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2807 ControlFlag
= CfCheckSelection
;
2812 Status
= SubmitForm (Selection
->FormSet
, Selection
->Form
);
2814 if (!EFI_ERROR (Status
)) {
2815 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2816 UpdateStatusBar (NV_UPDATE_REQUIRED
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2819 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gSaveFailed
, gPressEnter
, gEmptyString
);
2820 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
2828 ControlFlag
= CfCheckSelection
;
2830 Status
= ExtractFormDefault (Selection
->FormSet
, Selection
->Form
, DefaultId
);
2832 if (!EFI_ERROR (Status
)) {
2833 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2834 Selection
->Statement
= NULL
;
2837 // Show NV update flag on status bar
2839 gNvUpdateRequired
= TRUE
;
2843 case CfUiNoOperation
:
2844 ControlFlag
= CfCheckSelection
;
2848 UiFreeRefreshList ();
2850 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2851 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, Row
+ 4);
2852 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2853 gST
->ConOut
->OutputString (gST
->ConOut
, L
"\n");