2 Utility functions for User Interface functions.
4 Copyright (c) 2004 - 2007, 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
[] = {
121 Set Buffer to Value for Size bytes.
123 @param Buffer Memory to set.
124 @param Size Number of bytes to set
125 @param Value Value of the set operation.
138 while ((Size
--) != 0) {
145 Initialize Menu option list.
153 InitializeListHead (&Menu
);
158 Initialize Menu option list.
166 InitializeListHead (&gMenuList
);
171 Remove a Menu in list, and return FormId/QuestionId for previous Menu.
173 @param Selection Menu selection.
177 UiRemoveMenuListEntry (
178 OUT UI_MENU_SELECTION
*Selection
181 UI_MENU_LIST
*UiMenuList
;
183 if (!IsListEmpty (&gMenuList
)) {
184 UiMenuList
= CR (gMenuList
.ForwardLink
, UI_MENU_LIST
, MenuLink
, UI_MENU_LIST_SIGNATURE
);
186 Selection
->FormId
= UiMenuList
->FormId
;
187 Selection
->QuestionId
= UiMenuList
->QuestionId
;
188 RemoveEntryList (&UiMenuList
->MenuLink
);
189 gBS
->FreePool (UiMenuList
);
195 Free Menu option linked list.
203 UI_MENU_LIST
*UiMenuList
;
205 while (!IsListEmpty (&gMenuList
)) {
206 UiMenuList
= CR (gMenuList
.ForwardLink
, UI_MENU_LIST
, MenuLink
, UI_MENU_LIST_SIGNATURE
);
207 RemoveEntryList (&UiMenuList
->MenuLink
);
208 gBS
->FreePool (UiMenuList
);
214 Add one menu entry to the linked lst
216 @param Selection Menu selection.
221 IN UI_MENU_SELECTION
*Selection
224 UI_MENU_LIST
*UiMenuList
;
226 UiMenuList
= AllocateZeroPool (sizeof (UI_MENU_LIST
));
227 ASSERT (UiMenuList
!= NULL
);
229 UiMenuList
->Signature
= UI_MENU_LIST_SIGNATURE
;
230 UiMenuList
->FormId
= Selection
->FormId
;
231 UiMenuList
->QuestionId
= Selection
->QuestionId
;
233 InsertHeadList (&gMenuList
, &UiMenuList
->MenuLink
);
238 Free Menu option linked list.
246 UI_MENU_OPTION
*MenuOption
;
248 while (!IsListEmpty (&Menu
)) {
249 MenuOption
= MENU_OPTION_FROM_LINK (Menu
.ForwardLink
);
250 RemoveEntryList (&MenuOption
->Link
);
253 // We allocated space for this description when we did a GetToken, free it here
255 if (MenuOption
->Skip
!= 0) {
257 // For date/time, MenuOption->Description is shared by three Menu Options
258 // Data format : [01/02/2004] [11:22:33]
259 // Line number : 0 0 1 0 0 1
261 gBS
->FreePool (MenuOption
->Description
);
263 gBS
->FreePool (MenuOption
);
269 Free Menu option linked list.
277 MENU_REFRESH_ENTRY
*OldMenuRefreshEntry
;
279 while (gMenuRefreshHead
!= NULL
) {
280 OldMenuRefreshEntry
= gMenuRefreshHead
->Next
;
281 gBS
->FreePool (gMenuRefreshHead
);
282 gMenuRefreshHead
= OldMenuRefreshEntry
;
285 gMenuRefreshHead
= NULL
;
299 CHAR16
*OptionString
;
300 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
304 UI_MENU_SELECTION
*Selection
;
305 FORM_BROWSER_STATEMENT
*Question
;
309 if (gMenuRefreshHead
!= NULL
) {
311 MenuRefreshEntry
= gMenuRefreshHead
;
314 gST
->ConOut
->SetAttribute (gST
->ConOut
, MenuRefreshEntry
->CurrentAttribute
);
316 Selection
= MenuRefreshEntry
->Selection
;
317 Question
= MenuRefreshEntry
->MenuOption
->ThisTag
;
320 // Don't update Question being edited
322 if (Question
!= MenuRefreshEntry
->Selection
->Statement
) {
324 Status
= GetQuestionValue (Selection
->FormSet
, Selection
->Form
, Question
, FALSE
);
325 if (EFI_ERROR (Status
)) {
329 ProcessOptions (Selection
, MenuRefreshEntry
->MenuOption
, FALSE
, &OptionString
);
331 if (OptionString
!= NULL
) {
333 // If leading spaces on OptionString - remove the spaces
335 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
338 for (Loop
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
339 OptionString
[Loop
] = OptionString
[Index
];
343 OptionString
[Loop
] = CHAR_NULL
;
345 PrintStringAt (MenuRefreshEntry
->CurrentColumn
, MenuRefreshEntry
->CurrentRow
, OptionString
);
346 gBS
->FreePool (OptionString
);
350 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
352 } while (MenuRefreshEntry
!= NULL
);
358 Wait for a given event to fire, or for an optional timeout to expire.
360 @param Event The event to wait for
361 @param Timeout An optional timeout value in 100 ns units.
362 @param RefreshInterval Menu refresh interval (in seconds).
364 @retval EFI_SUCCESS Event fired before Timeout expired.
365 @retval EFI_TIME_OUT Timout expired before Event fired.
369 UiWaitForSingleEvent (
371 IN UINT64 Timeout
, OPTIONAL
372 IN UINT8 RefreshInterval OPTIONAL
377 EFI_EVENT TimerEvent
;
378 EFI_EVENT WaitList
[2];
382 // Create a timer event
384 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
385 if (!EFI_ERROR (Status
)) {
387 // Set the timer event
396 // Wait for the original event or the timer
399 WaitList
[1] = TimerEvent
;
400 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
401 gBS
->CloseEvent (TimerEvent
);
404 // If the timer expired, change the return to timed out
406 if (!EFI_ERROR (Status
) && Index
== 1) {
407 Status
= EFI_TIMEOUT
;
412 // Update screen every second
414 if (RefreshInterval
== 0) {
415 Timeout
= ONE_SECOND
;
417 Timeout
= RefreshInterval
* ONE_SECOND
;
421 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
424 // Set the timer event
433 // Wait for the original event or the timer
436 WaitList
[1] = TimerEvent
;
437 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
440 // If the timer expired, update anything that needs a refresh and keep waiting
442 if (!EFI_ERROR (Status
) && Index
== 1) {
443 Status
= EFI_TIMEOUT
;
444 if (RefreshInterval
!= 0) {
449 gBS
->CloseEvent (TimerEvent
);
450 } while (Status
== EFI_TIMEOUT
);
458 Add one menu option by specified description and context.
460 @param String String description for this option.
461 @param Handle Hii handle for the package list.
462 @param Statement Statement of this Menu Option.
463 @param NumberOfLines Display lines for this Menu Option.
464 @param MenuItemCount The index for this Option in the Menu.
470 IN EFI_HII_HANDLE Handle
,
471 IN FORM_BROWSER_STATEMENT
*Statement
,
472 IN UINT16 NumberOfLines
,
473 IN UINT16 MenuItemCount
476 UI_MENU_OPTION
*MenuOption
;
482 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
484 // Add three MenuOptions for Date/Time
485 // Data format : [01/02/2004] [11:22:33]
486 // Line number : 0 0 1 0 0 1
491 if (Statement
->Storage
== NULL
) {
493 // For RTC type of date/time, set default refresh interval to be 1 second
495 if (Statement
->RefreshInterval
== 0) {
496 Statement
->RefreshInterval
= 1;
501 for (Index
= 0; Index
< Count
; Index
++) {
502 MenuOption
= AllocateZeroPool (sizeof (UI_MENU_OPTION
));
505 MenuOption
->Signature
= UI_MENU_OPTION_SIGNATURE
;
506 MenuOption
->Description
= String
;
507 MenuOption
->Handle
= Handle
;
508 MenuOption
->ThisTag
= Statement
;
509 MenuOption
->EntryNumber
= MenuItemCount
;
513 // Override LineNumber for the MenuOption in Date/Time sequence
515 MenuOption
->Skip
= 1;
517 MenuOption
->Skip
= NumberOfLines
;
519 MenuOption
->Sequence
= Index
;
521 if (Statement
->GrayOutExpression
!= NULL
) {
522 MenuOption
->GrayOut
= Statement
->GrayOutExpression
->Result
.Value
.b
;
525 if ((Statement
->ValueExpression
!= NULL
) ||
526 ((Statement
->QuestionFlags
& EFI_IFR_FLAG_READ_ONLY
) != 0)) {
527 MenuOption
->ReadOnly
= TRUE
;
530 InsertTailList (&Menu
, &MenuOption
->Link
);
536 Routine used to abstract a generic dialog interface and return the selected key or string
538 @param NumberOfLines The number of lines for the dialog box
539 @param HotKey Defines whether a single character is parsed
540 (TRUE) and returned in KeyValue or a string is
541 returned in StringBuffer. Two special characters
542 are considered when entering a string, a SCAN_ESC
543 and an CHAR_CARRIAGE_RETURN. SCAN_ESC terminates
544 string input and returns
545 @param MaximumStringSize The maximum size in bytes of a typed in string
546 (each character is a CHAR16) and the minimum
547 string returned is two bytes
548 @param StringBuffer The passed in pointer to the buffer which will
549 hold the typed in string if HotKey is FALSE
550 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
551 @param ... A series of (quantity == NumberOfLines) text
552 strings which will be used to construct the dialog
555 @retval EFI_SUCCESS Displayed dialog and received user interaction
556 @retval EFI_INVALID_PARAMETER One of the parameters was invalid (e.g.
557 (StringBuffer == NULL) && (HotKey == FALSE))
558 @retval EFI_DEVICE_ERROR User typed in an ESC character to exit the routine
563 IN UINTN NumberOfLines
,
565 IN UINTN MaximumStringSize
,
566 OUT CHAR16
*StringBuffer
,
567 OUT EFI_INPUT_KEY
*KeyValue
,
572 VA_LIST MarkerBackup
;
577 CHAR16
*BufferedString
;
584 BOOLEAN SelectionComplete
;
586 UINTN CurrentAttribute
;
587 UINTN DimensionsWidth
;
588 UINTN DimensionsHeight
;
590 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
591 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
593 SelectionComplete
= FALSE
;
595 TempString
= AllocateZeroPool (MaximumStringSize
* 2);
596 BufferedString
= AllocateZeroPool (MaximumStringSize
* 2);
597 CurrentAttribute
= gST
->ConOut
->Mode
->Attribute
;
600 ASSERT (BufferedString
);
602 VA_START (Marker
, KeyValue
);
603 MarkerBackup
= Marker
;
606 // Zero the outgoing buffer
608 ZeroMem (StringBuffer
, MaximumStringSize
);
611 if (KeyValue
== NULL
) {
612 return EFI_INVALID_PARAMETER
;
615 if (StringBuffer
== NULL
) {
616 return EFI_INVALID_PARAMETER
;
622 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
627 // Determine the largest string in the dialog box
628 // Notice we are starting with 1 since String is the first string
630 for (Count
= 0; Count
< NumberOfLines
; Count
++) {
631 StackString
= VA_ARG (Marker
, CHAR16
*);
633 if (StackString
[0] == L
' ') {
634 InputOffset
= Count
+ 1;
637 if ((GetStringWidth (StackString
) / 2) > LargestString
) {
639 // Size of the string visually and subtract the width by one for the null-terminator
641 LargestString
= (GetStringWidth (StackString
) / 2);
645 Start
= (DimensionsWidth
- LargestString
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
646 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
653 CreateSharedPopUp (LargestString
, NumberOfLines
, MarkerBackup
);
656 // Take the first key typed and report it back?
659 Status
= WaitForKeyStroke (&Key
);
660 ASSERT_EFI_ERROR (Status
);
661 CopyMem (KeyValue
, &Key
, sizeof (EFI_INPUT_KEY
));
665 Status
= WaitForKeyStroke (&Key
);
667 switch (Key
.UnicodeChar
) {
669 switch (Key
.ScanCode
) {
671 gBS
->FreePool (TempString
);
672 gBS
->FreePool (BufferedString
);
673 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
674 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
675 return EFI_DEVICE_ERROR
;
683 case CHAR_CARRIAGE_RETURN
:
684 SelectionComplete
= TRUE
;
685 gBS
->FreePool (TempString
);
686 gBS
->FreePool (BufferedString
);
687 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
688 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
693 if (StringBuffer
[0] != CHAR_NULL
) {
694 for (Index
= 0; StringBuffer
[Index
] != CHAR_NULL
; Index
++) {
695 TempString
[Index
] = StringBuffer
[Index
];
698 // Effectively truncate string by 1 character
700 TempString
[Index
- 1] = CHAR_NULL
;
701 StrCpy (StringBuffer
, TempString
);
706 // If it is the beginning of the string, don't worry about checking maximum limits
708 if ((StringBuffer
[0] == CHAR_NULL
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
709 StrnCpy (StringBuffer
, &Key
.UnicodeChar
, 1);
710 StrnCpy (TempString
, &Key
.UnicodeChar
, 1);
711 } else if ((GetStringWidth (StringBuffer
) < MaximumStringSize
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
712 KeyPad
[0] = Key
.UnicodeChar
;
713 KeyPad
[1] = CHAR_NULL
;
714 StrCat (StringBuffer
, KeyPad
);
715 StrCat (TempString
, KeyPad
);
718 // If the width of the input string is now larger than the screen, we nee to
719 // adjust the index to start printing portions of the string
721 SetUnicodeMem (BufferedString
, LargestString
, L
' ');
723 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
725 if ((GetStringWidth (StringBuffer
) / 2) > (DimensionsWidth
- 2)) {
726 Index
= (GetStringWidth (StringBuffer
) / 2) - DimensionsWidth
+ 2;
731 for (Count
= 0; Index
+ 1 < GetStringWidth (StringBuffer
) / 2; Index
++, Count
++) {
732 BufferedString
[Count
] = StringBuffer
[Index
];
735 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
738 } while (!SelectionComplete
);
741 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
742 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
747 Draw a pop up windows based on the dimension, number of lines and
750 @param RequestedWidth The width of the pop-up.
751 @param NumberOfLines The number of lines.
752 @param Marker The variable argument list for the list of string to be printed.
757 IN UINTN RequestedWidth
,
758 IN UINTN NumberOfLines
,
770 UINTN DimensionsWidth
;
771 UINTN DimensionsHeight
;
773 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
774 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
776 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
778 if ((RequestedWidth
+ 2) > DimensionsWidth
) {
779 RequestedWidth
= DimensionsWidth
- 2;
783 // Subtract the PopUp width from total Columns, allow for one space extra on
784 // each end plus a border.
786 Start
= (DimensionsWidth
- RequestedWidth
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
787 End
= Start
+ RequestedWidth
+ 1;
789 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
790 Bottom
= Top
+ NumberOfLines
+ 2;
792 Character
= BOXDRAW_DOWN_RIGHT
;
793 PrintCharAt (Start
, Top
, Character
);
794 Character
= BOXDRAW_HORIZONTAL
;
795 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
796 PrintChar (Character
);
799 Character
= BOXDRAW_DOWN_LEFT
;
800 PrintChar (Character
);
801 Character
= BOXDRAW_VERTICAL
;
804 for (Index
= Top
; Index
+ 2 < Bottom
; Index
++, Count
++) {
805 String
= VA_ARG (Marker
, CHAR16
*);
808 // This will clear the background of the line - we never know who might have been
809 // here before us. This differs from the next clear in that it used the non-reverse
810 // video for normal printing.
812 if (GetStringWidth (String
) / 2 > 1) {
813 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
817 // Passing in a space results in the assumption that this is where typing will occur
819 if (String
[0] == L
' ') {
820 ClearLines (Start
+ 1, End
- 1, Index
+ 1, Index
+ 1, POPUP_INVERSE_TEXT
| POPUP_INVERSE_BACKGROUND
);
824 // Passing in a NULL results in a blank space
826 if (String
[0] == CHAR_NULL
) {
827 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
831 ((DimensionsWidth
- GetStringWidth (String
) / 2) / 2) + gScreenDimensions
.LeftColumn
+ 1,
835 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
836 PrintCharAt (Start
, Index
+ 1, Character
);
837 PrintCharAt (End
- 1, Index
+ 1, Character
);
840 Character
= BOXDRAW_UP_RIGHT
;
841 PrintCharAt (Start
, Bottom
- 1, Character
);
842 Character
= BOXDRAW_HORIZONTAL
;
843 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
844 PrintChar (Character
);
847 Character
= BOXDRAW_UP_LEFT
;
848 PrintChar (Character
);
852 Draw a pop up windows based on the dimension, number of lines and
855 @param RequestedWidth The width of the pop-up.
856 @param NumberOfLines The number of lines.
857 @param ... A series of text strings that displayed in the pop-up.
862 IN UINTN RequestedWidth
,
863 IN UINTN NumberOfLines
,
869 VA_START (Marker
, NumberOfLines
);
871 CreateSharedPopUp (RequestedWidth
, NumberOfLines
, Marker
);
878 Update status bar on the bottom of menu.
880 @param MessageType The type of message to be shown.
881 @param Flags The flags in Question header.
882 @param State Set or clear.
887 IN UINTN MessageType
,
893 STATIC BOOLEAN InputError
;
894 CHAR16
*NvUpdateMessage
;
895 CHAR16
*InputErrorMessage
;
897 NvUpdateMessage
= GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE
), gHiiHandle
);
898 InputErrorMessage
= GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE
), gHiiHandle
);
900 switch (MessageType
) {
903 gST
->ConOut
->SetAttribute (gST
->ConOut
, ERROR_TEXT
);
905 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
,
906 gScreenDimensions
.BottomRow
- 1,
911 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
912 for (Index
= 0; Index
< (GetStringWidth (InputErrorMessage
) - 2) / 2; Index
++) {
913 PrintAt (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ Index
, gScreenDimensions
.BottomRow
- 1, L
" ");
920 case NV_UPDATE_REQUIRED
:
921 if (gClassOfVfr
!= EFI_FRONT_PAGE_SUBCLASS
) {
923 gST
->ConOut
->SetAttribute (gST
->ConOut
, INFO_TEXT
);
925 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
,
926 gScreenDimensions
.BottomRow
- 1,
929 gResetRequired
= (BOOLEAN
) (gResetRequired
| ((Flags
& EFI_IFR_FLAG_RESET_REQUIRED
) == EFI_IFR_FLAG_RESET_REQUIRED
));
931 gNvUpdateRequired
= TRUE
;
933 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
934 for (Index
= 0; Index
< (GetStringWidth (NvUpdateMessage
) - 2) / 2; Index
++) {
936 (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ Index
),
937 gScreenDimensions
.BottomRow
- 1,
942 gNvUpdateRequired
= FALSE
;
947 case REFRESH_STATUS_BAR
:
949 UpdateStatusBar (INPUT_ERROR
, Flags
, TRUE
);
952 if (gNvUpdateRequired
) {
953 UpdateStatusBar (NV_UPDATE_REQUIRED
, Flags
, TRUE
);
961 gBS
->FreePool (InputErrorMessage
);
962 gBS
->FreePool (NvUpdateMessage
);
968 Get the supported width for a particular op-code
970 @param Statement The FORM_BROWSER_STATEMENT structure passed in.
971 @param Handle The handle in the HII database being used
973 @return Returns the number of CHAR16 characters that is support.
978 IN FORM_BROWSER_STATEMENT
*Statement
,
979 IN EFI_HII_HANDLE Handle
989 // See if the second text parameter is really NULL
991 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
992 String
= GetToken (Statement
->TextTwo
, Handle
);
993 Size
= StrLen (String
);
994 gBS
->FreePool (String
);
997 if ((Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
998 (Statement
->Operand
== EFI_IFR_REF_OP
) ||
999 (Statement
->Operand
== EFI_IFR_PASSWORD_OP
) ||
1000 (Statement
->Operand
== EFI_IFR_ACTION_OP
) ||
1001 (Statement
->Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1003 // Allow a wide display if text op-code and no secondary text op-code
1005 ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Size
== 0))
1007 Width
= (UINT16
) (gPromptBlockWidth
+ gOptionBlockWidth
);
1009 Width
= (UINT16
) gPromptBlockWidth
;
1012 if (Statement
->InSubtitle
) {
1013 Width
-= SUBTITLE_INDENT
;
1020 STATIC BOOLEAN GetLineByWidthFinished
= FALSE
;
1023 Will copy LineWidth amount of a string in the OutputString buffer and return the
1024 number of CHAR16 characters that were copied into the OutputString buffer.
1026 @param InputString String description for this option.
1027 @param LineWidth Width of the desired string to extract in CHAR16
1029 @param Index Where in InputString to start the copy process
1030 @param OutputString Buffer to copy the string into
1032 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.
1037 IN CHAR16
*InputString
,
1038 IN UINT16 LineWidth
,
1039 IN OUT UINTN
*Index
,
1040 OUT CHAR16
**OutputString
1046 if (GetLineByWidthFinished
) {
1047 GetLineByWidthFinished
= FALSE
;
1054 *OutputString
= AllocateZeroPool (((UINTN
) (LineWidth
+ 1) * 2));
1057 // Ensure we have got a valid buffer
1059 if (*OutputString
!= NULL
) {
1062 //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.
1063 //To avoid displaying this empty line in screen, just skip the two CHARs here.
1065 if ((InputString
[*Index
] == NARROW_CHAR
) && (InputString
[*Index
+ 1] == CHAR_CARRIAGE_RETURN
)) {
1066 *Index
= *Index
+ 2;
1070 // Fast-forward the string and see if there is a carriage-return in the string
1072 for (; (InputString
[*Index
+ Count2
] != CHAR_CARRIAGE_RETURN
) && (Count2
!= LineWidth
); Count2
++)
1076 // Copy the desired LineWidth of data to the output buffer.
1077 // Also make sure that we don't copy more than the string.
1078 // Also make sure that if there are linefeeds, we account for them.
1080 if ((StrSize (&InputString
[*Index
]) <= ((UINTN
) (LineWidth
+ 1) * 2)) &&
1081 (StrSize (&InputString
[*Index
]) <= ((UINTN
) (Count2
+ 1) * 2))
1084 // Convert to CHAR16 value and show that we are done with this operation
1086 LineWidth
= (UINT16
) ((StrSize (&InputString
[*Index
]) - 2) / 2);
1087 if (LineWidth
!= 0) {
1088 GetLineByWidthFinished
= TRUE
;
1091 if (Count2
== LineWidth
) {
1093 // Rewind the string from the maximum size until we see a space to break the line
1095 for (; (InputString
[*Index
+ LineWidth
] != CHAR_SPACE
) && (LineWidth
!= 0); LineWidth
--)
1097 if (LineWidth
== 0) {
1105 CopyMem (*OutputString
, &InputString
[*Index
], LineWidth
* 2);
1108 // If currently pointing to a space, increment the index to the first non-space character
1111 (InputString
[*Index
+ LineWidth
] == CHAR_SPACE
) || (InputString
[*Index
+ LineWidth
] == CHAR_CARRIAGE_RETURN
);
1115 *Index
= (UINT16
) (*Index
+ LineWidth
);
1124 Update display lines for a Menu Option.
1126 @param Selection The user's selection.
1127 @param MenuOption The MenuOption to be checked.
1128 @param OptionalString The option string.
1129 @param SkipValue The number of lins to skip.
1133 UpdateOptionSkipLines (
1134 IN UI_MENU_SELECTION
*Selection
,
1135 IN UI_MENU_OPTION
*MenuOption
,
1136 OUT CHAR16
**OptionalString
,
1144 CHAR16
*OutputString
;
1145 CHAR16
*OptionString
;
1148 OptionString
= *OptionalString
;
1149 OutputString
= NULL
;
1151 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1153 if (OptionString
!= NULL
) {
1154 Width
= (UINT16
) gOptionBlockWidth
;
1158 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1160 // If there is more string to process print on the next row and increment the Skip value
1162 if (StrLen (&OptionString
[Index
])) {
1163 if (SkipValue
== 0) {
1166 // Since the Number of lines for this menu entry may or may not be reflected accurately
1167 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1168 // some testing to ensure we are keeping this in-sync.
1170 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1172 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1178 gBS
->FreePool (OutputString
);
1179 if (SkipValue
!= 0) {
1187 *OptionalString
= OptionString
;
1192 Check whether this Menu Option could be highlighted.
1194 This is an internal function.
1196 @param MenuOption The MenuOption to be checked.
1198 @retval TRUE This Menu Option is selectable.
1199 @retval FALSE This Menu Option could not be selected.
1204 UI_MENU_OPTION
*MenuOption
1207 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1208 MenuOption
->GrayOut
|| MenuOption
->ReadOnly
) {
1217 Determine if the menu is the last menu that can be selected.
1219 This is an internal function.
1221 @param Direction The scroll direction. False is down. True is up.
1222 @param CurrentPos The current focus.
1224 @return FALSE -- the menu isn't the last menu that can be selected.
1225 @return TRUE -- the menu is the last menu that can be selected.
1230 IN BOOLEAN Direction
,
1231 IN LIST_ENTRY
*CurrentPos
1235 UI_MENU_OPTION
*MenuOption
;
1237 Temp
= Direction
? CurrentPos
->BackLink
: CurrentPos
->ForwardLink
;
1239 if (Temp
== &Menu
) {
1243 for (; Temp
!= &Menu
; Temp
= Direction
? Temp
->BackLink
: Temp
->ForwardLink
) {
1244 MenuOption
= MENU_OPTION_FROM_LINK (Temp
);
1245 if (IsSelectable (MenuOption
)) {
1255 Move to next selectable statement.
1257 This is an internal function.
1259 @param GoUp The navigation direction. TRUE: up, FALSE: down.
1260 @param CurrentPosition Current position.
1262 @return The row distance from current MenuOption to next selectable MenuOption.
1266 MoveToNextStatement (
1268 IN OUT LIST_ENTRY
**CurrentPosition
1274 UI_MENU_OPTION
*NextMenuOption
;
1277 Pos
= *CurrentPosition
;
1281 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1282 if (IsSelectable (NextMenuOption
)) {
1285 if ((GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &Menu
) {
1289 Distance
+= NextMenuOption
->Skip
;
1290 Pos
= (GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1295 // If we hit end there is still no statement can be focused,
1296 // we go backwards to find the statement can be focused.
1299 Pos
= *CurrentPosition
;
1302 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1303 if (IsSelectable (NextMenuOption
)) {
1306 if ((!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &Menu
) {
1310 Distance
-= NextMenuOption
->Skip
;
1311 Pos
= (!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1315 *CurrentPosition
= &NextMenuOption
->Link
;
1321 Adjust Data and Time position accordingly.
1322 Data format : [01/02/2004] [11:22:33]
1323 Line number : 0 0 1 0 0 1
1325 This is an internal function.
1327 @param DirectionUp the up or down direction. False is down. True is
1329 @param CurrentPosition Current position. On return: Point to the last
1330 Option (Year or Second) if up; Point to the first
1331 Option (Month or Hour) if down.
1333 @return Return line number to pad. It is possible that we stand on a zero-advance
1334 @return data or time opcode, so pad one line when we judge if we are going to scroll outside.
1338 AdjustDateAndTimePosition (
1339 IN BOOLEAN DirectionUp
,
1340 IN OUT LIST_ENTRY
**CurrentPosition
1344 LIST_ENTRY
*NewPosition
;
1345 UI_MENU_OPTION
*MenuOption
;
1346 UINTN PadLineNumber
;
1349 NewPosition
= *CurrentPosition
;
1350 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1352 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
1353 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
1355 // Calculate the distance from current position to the last Date/Time MenuOption
1358 while (MenuOption
->Skip
== 0) {
1360 NewPosition
= NewPosition
->ForwardLink
;
1361 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1365 NewPosition
= *CurrentPosition
;
1368 // Since the behavior of hitting the up arrow on a Date/Time MenuOption is intended
1369 // to be one that back to the previous set of MenuOptions, we need to advance to the first
1370 // Date/Time MenuOption and leave the remaining logic in CfUiUp intact so the appropriate
1371 // checking can be done.
1373 while (Count
++ < 2) {
1374 NewPosition
= NewPosition
->BackLink
;
1378 // Since the behavior of hitting the down arrow on a Date/Time MenuOption is intended
1379 // to be one that progresses to the next set of MenuOptions, we need to advance to the last
1380 // Date/Time MenuOption and leave the remaining logic in CfUiDown intact so the appropriate
1381 // checking can be done.
1383 while (Count
-- > 0) {
1384 NewPosition
= NewPosition
->ForwardLink
;
1388 *CurrentPosition
= NewPosition
;
1391 return PadLineNumber
;
1396 Display menu and wait for user to select one menu option, then return it.
1397 If AutoBoot is enabled, then if user doesn't select any option,
1398 after period of time, it will automatically return the first menu option.
1400 @param Selection Menu selection.
1402 @retval EFI_SUCESSS This function always return successfully for now.
1407 IN OUT UI_MENU_SELECTION
*Selection
1413 UINTN DistanceValue
;
1425 CHAR16
*OptionString
;
1426 CHAR16
*OutputString
;
1427 CHAR16
*FormattedString
;
1437 LIST_ENTRY
*TopOfScreen
;
1438 LIST_ENTRY
*SavedListEntry
;
1439 UI_MENU_OPTION
*MenuOption
;
1440 UI_MENU_OPTION
*NextMenuOption
;
1441 UI_MENU_OPTION
*SavedMenuOption
;
1442 UI_MENU_OPTION
*PreviousMenuOption
;
1443 UI_CONTROL_FLAG ControlFlag
;
1444 EFI_SCREEN_DESCRIPTOR LocalScreen
;
1445 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
1446 UI_SCREEN_OPERATION ScreenOperation
;
1447 UINT8 MinRefreshInterval
;
1450 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1451 FORM_BROWSER_STATEMENT
*Statement
;
1453 CopyMem (&LocalScreen
, &gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1455 Status
= EFI_SUCCESS
;
1456 FormattedString
= NULL
;
1457 OptionString
= NULL
;
1458 ScreenOperation
= UiNoOperation
;
1460 MinRefreshInterval
= 0;
1463 OutputString
= NULL
;
1468 MenuRefreshEntry
= gMenuRefreshHead
;
1470 NextMenuOption
= NULL
;
1471 PreviousMenuOption
= NULL
;
1472 SavedMenuOption
= NULL
;
1474 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
1476 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
1477 TopRow
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1478 Row
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1480 TopRow
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1481 Row
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1484 Col
= LocalScreen
.LeftColumn
;
1485 BottomRow
= LocalScreen
.BottomRow
- STATUS_BAR_HEIGHT
- FOOTER_HEIGHT
- SCROLL_ARROW_HEIGHT
- 1;
1487 Selection
->TopRow
= TopRow
;
1488 Selection
->BottomRow
= BottomRow
;
1489 Selection
->PromptCol
= Col
;
1490 Selection
->OptionCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1491 Selection
->Statement
= NULL
;
1493 TopOfScreen
= Menu
.ForwardLink
;
1498 // Get user's selection
1500 NewPos
= Menu
.ForwardLink
;
1502 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
1503 UpdateStatusBar (REFRESH_STATUS_BAR
, (UINT8
) 0, TRUE
);
1505 ControlFlag
= CfInitialization
;
1506 Selection
->Action
= UI_ACTION_NONE
;
1508 switch (ControlFlag
) {
1509 case CfInitialization
:
1510 if (IsListEmpty (&Menu
)) {
1511 ControlFlag
= CfReadKey
;
1513 ControlFlag
= CfCheckSelection
;
1517 case CfCheckSelection
:
1518 if (Selection
->Action
!= UI_ACTION_NONE
) {
1519 ControlFlag
= CfExit
;
1521 ControlFlag
= CfRepaint
;
1526 ControlFlag
= CfRefreshHighLight
;
1540 LocalScreen
.LeftColumn
,
1541 LocalScreen
.RightColumn
,
1542 TopRow
- SCROLL_ARROW_HEIGHT
,
1543 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1544 FIELD_TEXT
| FIELD_BACKGROUND
1547 UiFreeRefreshList ();
1548 MinRefreshInterval
= 0;
1550 for (Link
= TopOfScreen
; Link
!= &Menu
; Link
= Link
->ForwardLink
) {
1551 MenuOption
= MENU_OPTION_FROM_LINK (Link
);
1552 MenuOption
->Row
= Row
;
1553 MenuOption
->Col
= Col
;
1554 MenuOption
->OptCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1556 Statement
= MenuOption
->ThisTag
;
1557 if (Statement
->InSubtitle
) {
1558 MenuOption
->Col
+= SUBTITLE_INDENT
;
1561 if (MenuOption
->GrayOut
) {
1562 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
1564 if (Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) {
1565 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
1569 Width
= GetWidth (Statement
, MenuOption
->Handle
);
1572 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
1573 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1574 PrintStringAt (MenuOption
->Col
, Row
, OutputString
);
1577 // If there is more string to process print on the next row and increment the Skip value
1579 if (StrLen (&MenuOption
->Description
[Index
])) {
1585 gBS
->FreePool (OutputString
);
1594 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1595 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1597 if (OptionString
!= NULL
) {
1598 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
1600 // If leading spaces on OptionString - remove the spaces
1602 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++) {
1603 MenuOption
->OptCol
++;
1606 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1607 OptionString
[Count
] = OptionString
[Index
];
1611 OptionString
[Count
] = CHAR_NULL
;
1615 // If Question request refresh, register the op-code
1617 if (Statement
->RefreshInterval
!= 0) {
1619 // Menu will be refreshed at minimal interval of all Questions
1620 // which have refresh request
1622 if (MinRefreshInterval
== 0 || Statement
->RefreshInterval
< MinRefreshInterval
) {
1623 MinRefreshInterval
= Statement
->RefreshInterval
;
1626 if (gMenuRefreshHead
== NULL
) {
1627 MenuRefreshEntry
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1628 ASSERT (MenuRefreshEntry
!= NULL
);
1629 MenuRefreshEntry
->MenuOption
= MenuOption
;
1630 MenuRefreshEntry
->Selection
= Selection
;
1631 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1632 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1633 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1634 gMenuRefreshHead
= MenuRefreshEntry
;
1637 // Advance to the last entry
1639 for (MenuRefreshEntry
= gMenuRefreshHead
;
1640 MenuRefreshEntry
->Next
!= NULL
;
1641 MenuRefreshEntry
= MenuRefreshEntry
->Next
1644 MenuRefreshEntry
->Next
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1645 ASSERT (MenuRefreshEntry
->Next
!= NULL
);
1646 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
1647 MenuRefreshEntry
->MenuOption
= MenuOption
;
1648 MenuRefreshEntry
->Selection
= Selection
;
1649 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1650 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1651 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1655 Width
= (UINT16
) gOptionBlockWidth
;
1658 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1659 if ((Temp2
== 0) && (Row
<= BottomRow
)) {
1660 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1663 // If there is more string to process print on the next row and increment the Skip value
1665 if (StrLen (&OptionString
[Index
])) {
1669 // Since the Number of lines for this menu entry may or may not be reflected accurately
1670 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1671 // some testing to ensure we are keeping this in-sync.
1673 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1675 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1681 gBS
->FreePool (OutputString
);
1690 gBS
->FreePool (OptionString
);
1693 // If this is a text op with secondary text information
1695 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1696 StringPtr
= GetToken (Statement
->TextTwo
, MenuOption
->Handle
);
1698 Width
= (UINT16
) gOptionBlockWidth
;
1701 for (Index
= 0; GetLineByWidth (StringPtr
, Width
, &Index
, &OutputString
) != 0x0000;) {
1702 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1703 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1706 // If there is more string to process print on the next row and increment the Skip value
1708 if (StrLen (&StringPtr
[Index
])) {
1712 // Since the Number of lines for this menu entry may or may not be reflected accurately
1713 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1714 // some testing to ensure we are keeping this in-sync.
1716 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1718 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1724 gBS
->FreePool (OutputString
);
1731 gBS
->FreePool (StringPtr
);
1735 // Need to handle the bottom of the display
1737 if (MenuOption
->Skip
> 1) {
1738 Row
+= MenuOption
->Skip
- SkipValue
;
1741 Row
+= MenuOption
->Skip
;
1744 if (Row
> BottomRow
) {
1745 if (!ValueIsScroll (FALSE
, Link
)) {
1749 Row
= BottomRow
+ 1;
1754 if (!ValueIsScroll (TRUE
, TopOfScreen
)) {
1759 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
1761 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
1762 TopRow
- SCROLL_ARROW_HEIGHT
,
1766 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1770 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
1772 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
1773 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1777 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1784 case CfRefreshHighLight
:
1786 // MenuOption: Last menu option that need to remove hilight
1787 // MenuOption is set to NULL in Repaint
1788 // NewPos: Current menu option that need to hilight
1790 ControlFlag
= CfUpdateHelpString
;
1793 // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily
1794 // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.
1796 SavedValue
= Repaint
;
1799 if (Selection
->QuestionId
!= 0) {
1800 NewPos
= Menu
.ForwardLink
;
1801 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1803 while (SavedMenuOption
->ThisTag
->QuestionId
!= Selection
->QuestionId
&& NewPos
->ForwardLink
!= &Menu
) {
1804 NewPos
= NewPos
->ForwardLink
;
1805 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1807 if (SavedMenuOption
->ThisTag
->QuestionId
== Selection
->QuestionId
) {
1809 // Target Question found, find its MenuOption
1813 for (Index
= TopRow
; Index
<= BottomRow
&& Link
!= NewPos
;) {
1814 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
1815 Index
+= SavedMenuOption
->Skip
;
1816 Link
= Link
->ForwardLink
;
1819 if (Link
!= NewPos
|| Index
> BottomRow
) {
1821 // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page
1824 for (Index
= TopRow
; Index
<= BottomRow
; ) {
1825 Link
= Link
->BackLink
;
1826 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
1827 Index
+= SavedMenuOption
->Skip
;
1829 TopOfScreen
= Link
->ForwardLink
;
1833 ControlFlag
= CfRepaint
;
1838 // Target Question not found, highlight the default menu option
1840 NewPos
= TopOfScreen
;
1843 Selection
->QuestionId
= 0;
1846 if (NewPos
!= NULL
&& (MenuOption
== NULL
|| NewPos
!= &MenuOption
->Link
)) {
1847 if (MenuOption
!= NULL
) {
1849 // Remove highlight on last Menu Option
1851 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
1852 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1853 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1854 if (OptionString
!= NULL
) {
1855 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
1856 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
1859 // If leading spaces on OptionString - remove the spaces
1861 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
1864 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1865 OptionString
[Count
] = OptionString
[Index
];
1869 OptionString
[Count
] = CHAR_NULL
;
1872 Width
= (UINT16
) gOptionBlockWidth
;
1873 OriginalRow
= MenuOption
->Row
;
1875 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1876 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
1877 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
1880 // If there is more string to process print on the next row and increment the Skip value
1882 if (StrLen (&OptionString
[Index
])) {
1886 gBS
->FreePool (OutputString
);
1889 MenuOption
->Row
= OriginalRow
;
1891 gBS
->FreePool (OptionString
);
1894 if (MenuOption
->GrayOut
) {
1895 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
1896 } else if (MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) {
1897 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
1900 OriginalRow
= MenuOption
->Row
;
1901 Width
= GetWidth (MenuOption
->ThisTag
, MenuOption
->Handle
);
1903 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
1904 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
1905 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
1908 // If there is more string to process print on the next row and increment the Skip value
1910 if (StrLen (&MenuOption
->Description
[Index
])) {
1914 gBS
->FreePool (OutputString
);
1917 MenuOption
->Row
= OriginalRow
;
1918 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1924 // This is only possible if we entered this page and the first menu option is
1925 // a "non-menu" item. In that case, force it UiDown
1927 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1928 if (!IsSelectable (MenuOption
)) {
1929 ASSERT (ScreenOperation
== UiNoOperation
);
1930 ScreenOperation
= UiDown
;
1931 ControlFlag
= CfScreenOperation
;
1936 // This is the current selected statement
1938 Statement
= MenuOption
->ThisTag
;
1939 Selection
->Statement
= Statement
;
1942 // Set reverse attribute
1944 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
);
1945 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
1948 // Assuming that we have a refresh linked-list created, lets annotate the
1949 // appropriate entry that we are highlighting with its new attribute. Just prior to this
1950 // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh
1952 if (gMenuRefreshHead
!= NULL
) {
1953 for (MenuRefreshEntry
= gMenuRefreshHead
; MenuRefreshEntry
!= NULL
; MenuRefreshEntry
= MenuRefreshEntry
->Next
) {
1954 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1955 if (MenuRefreshEntry
->MenuOption
== MenuOption
) {
1956 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
;
1961 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1962 if (OptionString
!= NULL
) {
1963 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
1965 // If leading spaces on OptionString - remove the spaces
1967 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
1970 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1971 OptionString
[Count
] = OptionString
[Index
];
1975 OptionString
[Count
] = CHAR_NULL
;
1977 Width
= (UINT16
) gOptionBlockWidth
;
1979 OriginalRow
= MenuOption
->Row
;
1981 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1982 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
1983 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
1986 // If there is more string to process print on the next row and increment the Skip value
1988 if (StrLen (&OptionString
[Index
])) {
1992 gBS
->FreePool (OutputString
);
1995 MenuOption
->Row
= OriginalRow
;
1997 gBS
->FreePool (OptionString
);
2000 OriginalRow
= MenuOption
->Row
;
2002 Width
= GetWidth (Statement
, MenuOption
->Handle
);
2004 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2005 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2006 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2009 // If there is more string to process print on the next row and increment the Skip value
2011 if (StrLen (&MenuOption
->Description
[Index
])) {
2015 gBS
->FreePool (OutputString
);
2018 MenuOption
->Row
= OriginalRow
;
2023 if (((NewPos
->ForwardLink
!= &Menu
) && (ScreenOperation
== UiDown
)) ||
2024 ((NewPos
->BackLink
!= &Menu
) && (ScreenOperation
== UiUp
)) ||
2025 (ScreenOperation
== UiNoOperation
)
2027 UpdateKeyHelp (MenuOption
, FALSE
);
2030 // Clear reverse attribute
2032 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2035 // Repaint flag will be used when process CfUpdateHelpString, so restore its value
2036 // if we didn't break halfway when process CfRefreshHighLight.
2038 Repaint
= SavedValue
;
2041 case CfUpdateHelpString
:
2042 ControlFlag
= CfPrepareToReadKey
;
2044 if ((Repaint
|| NewLine
) && (gClassOfVfr
!= EFI_GENERAL_APPLICATION_SUBCLASS
)) {
2046 // Don't print anything if it is a NULL help token
2048 if (MenuOption
->ThisTag
->Help
== 0) {
2051 StringPtr
= GetToken (MenuOption
->ThisTag
->Help
, MenuOption
->Handle
);
2054 ProcessHelpString (StringPtr
, &FormattedString
, BottomRow
- TopRow
);
2056 gST
->ConOut
->SetAttribute (gST
->ConOut
, HELP_TEXT
| FIELD_BACKGROUND
);
2058 for (Index
= 0; Index
< BottomRow
- TopRow
; Index
++) {
2060 // Pad String with spaces to simulate a clearing of the previous line
2062 for (; GetStringWidth (&FormattedString
[Index
* gHelpBlockWidth
* 2]) / 2 < gHelpBlockWidth
;) {
2063 StrCat (&FormattedString
[Index
* gHelpBlockWidth
* 2], L
" ");
2067 LocalScreen
.RightColumn
- gHelpBlockWidth
,
2069 &FormattedString
[Index
* gHelpBlockWidth
* 2]
2074 // Reset this flag every time we finish using it.
2080 case CfPrepareToReadKey
:
2081 ControlFlag
= CfReadKey
;
2082 ScreenOperation
= UiNoOperation
;
2086 ControlFlag
= CfScreenOperation
;
2089 // Wait for user's selection
2092 Status
= UiWaitForSingleEvent (gST
->ConIn
->WaitForKey
, 0, MinRefreshInterval
);
2093 } while (Status
== EFI_TIMEOUT
);
2095 if (Status
== EFI_TIMEOUT
) {
2096 Key
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
2098 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2100 // if we encounter error, continue to read another key in.
2102 if (EFI_ERROR (Status
)) {
2103 ControlFlag
= CfReadKey
;
2108 if (IsListEmpty (&Menu
) && Key
.UnicodeChar
!= CHAR_NULL
) {
2110 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2115 switch (Key
.UnicodeChar
) {
2116 case CHAR_CARRIAGE_RETURN
:
2117 ScreenOperation
= UiSelect
;
2122 // We will push the adjustment of these numeric values directly to the input handler
2123 // NOTE: we won't handle manual input numeric
2127 Statement
= MenuOption
->ThisTag
;
2128 if ((Statement
->Operand
== EFI_IFR_DATE_OP
)
2129 || (Statement
->Operand
== EFI_IFR_TIME_OP
)
2130 || ((Statement
->Operand
== EFI_IFR_NUMERIC_OP
) && (Statement
->Step
!= 0))
2132 if (Key
.UnicodeChar
== '+') {
2133 gDirection
= SCAN_RIGHT
;
2135 gDirection
= SCAN_LEFT
;
2137 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2138 SafeFreePool (OptionString
);
2143 ScreenOperation
= UiUp
;
2148 ScreenOperation
= UiDown
;
2152 if (gClassOfVfr
!= EFI_FRONT_PAGE_SUBCLASS
) {
2153 if (MenuOption
->ThisTag
->Operand
== EFI_IFR_CHECKBOX_OP
&& !MenuOption
->GrayOut
) {
2154 ScreenOperation
= UiSelect
;
2160 if (((Key
.ScanCode
== SCAN_F1
) && ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
)) ||
2161 ((Key
.ScanCode
== SCAN_F2
) && ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
)) ||
2162 ((Key
.ScanCode
== SCAN_F9
) && ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
)) ||
2163 ((Key
.ScanCode
== SCAN_F10
) && ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
))
2166 // If the function key has been disabled, just ignore the key.
2169 for (Index
= 0; Index
< sizeof (gScanCodeToOperation
) / sizeof (gScanCodeToOperation
[0]); Index
++) {
2170 if (Key
.ScanCode
== gScanCodeToOperation
[Index
].ScanCode
) {
2171 if (Key
.ScanCode
== SCAN_F9
) {
2173 // Reset to standard default
2175 DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2177 ScreenOperation
= gScanCodeToOperation
[Index
].ScreenOperation
;
2186 case CfScreenOperation
:
2187 if (ScreenOperation
!= UiPrevious
&& ScreenOperation
!= UiReset
) {
2189 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2190 // ignore the selection and go back to reading keys.
2192 if (IsListEmpty (&Menu
)) {
2193 ControlFlag
= CfReadKey
;
2197 // if there is nothing logical to place a cursor on, just move on to wait for a key.
2199 for (Link
= Menu
.ForwardLink
; Link
!= &Menu
; Link
= Link
->ForwardLink
) {
2200 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2201 if (IsSelectable (NextMenuOption
)) {
2206 if (Link
== &Menu
) {
2207 ControlFlag
= CfPrepareToReadKey
;
2210 } else if (ScreenOperation
== UiReset
) {
2212 // Press ESC to exit FormSet
2214 Selection
->Action
= UI_ACTION_EXIT
;
2215 Selection
->Statement
= NULL
;
2219 Index
< sizeof (gScreenOperationToControlFlag
) / sizeof (gScreenOperationToControlFlag
[0]);
2222 if (ScreenOperation
== gScreenOperationToControlFlag
[Index
].ScreenOperation
) {
2223 ControlFlag
= gScreenOperationToControlFlag
[Index
].ControlFlag
;
2230 ControlFlag
= CfCheckSelection
;
2232 if (IsListEmpty (&gMenuList
)) {
2233 Selection
->Action
= UI_ACTION_NONE
;
2234 if (IsListEmpty (&Menu
)) {
2235 ControlFlag
= CfReadKey
;
2241 // Remove the Cached page entry
2243 UiRemoveMenuListEntry (Selection
);
2245 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2246 Selection
->Statement
= NULL
;
2250 ControlFlag
= CfCheckSelection
;
2252 Statement
= MenuOption
->ThisTag
;
2253 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) ||
2254 (Statement
->Operand
== EFI_IFR_DATE_OP
) ||
2255 (Statement
->Operand
== EFI_IFR_TIME_OP
) ||
2256 (Statement
->Operand
== EFI_IFR_NUMERIC_OP
&& Statement
->Step
!= 0)) {
2261 // Keep highlight on current MenuOption
2263 Selection
->QuestionId
= Statement
->QuestionId
;
2265 switch (Statement
->Operand
) {
2266 case EFI_IFR_REF_OP
:
2267 if (Statement
->RefDevicePath
!= 0) {
2269 // Goto another Hii Package list
2271 ControlFlag
= CfUiReset
;
2272 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2274 StringPtr
= GetToken (Statement
->RefDevicePath
, Selection
->FormSet
->HiiHandle
);
2275 if (StringPtr
== NULL
) {
2277 // No device path string not found, exit
2279 Selection
->Action
= UI_ACTION_EXIT
;
2280 Selection
->Statement
= NULL
;
2283 BufferSize
= StrLen (StringPtr
) / 2;
2284 DevicePath
= AllocatePool (BufferSize
);
2286 HexStringToBuffer ((UINT8
*) DevicePath
, &BufferSize
, StringPtr
);
2287 Selection
->Handle
= HiiLibDevicePathToHiiHandle (DevicePath
);
2288 if (Selection
->Handle
== NULL
) {
2290 // If target Hii Handle not found, exit
2292 Selection
->Action
= UI_ACTION_EXIT
;
2293 Selection
->Statement
= NULL
;
2297 gBS
->FreePool (StringPtr
);
2298 gBS
->FreePool (DevicePath
);
2300 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2301 Selection
->FormId
= Statement
->RefFormId
;
2302 Selection
->QuestionId
= Statement
->RefQuestionId
;
2303 } else if (!CompareGuid (&Statement
->RefFormSetId
, &gZeroGuid
)) {
2305 // Goto another Formset, check for uncommitted data
2307 ControlFlag
= CfUiReset
;
2308 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2310 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2311 Selection
->FormId
= Statement
->RefFormId
;
2312 Selection
->QuestionId
= Statement
->RefQuestionId
;
2313 } else if (Statement
->RefFormId
!= 0) {
2315 // Goto another form inside this formset,
2317 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2320 // Link current form so that we can always go back when someone hits the UiPrevious
2322 UiAddMenuListEntry (Selection
);
2324 Selection
->FormId
= Statement
->RefFormId
;
2325 Selection
->QuestionId
= Statement
->RefQuestionId
;
2326 } else if (Statement
->RefQuestionId
!= 0) {
2328 // Goto another Question
2330 Selection
->QuestionId
= Statement
->RefQuestionId
;
2332 if ((Statement
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) {
2333 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2342 case EFI_IFR_ACTION_OP
:
2344 // Process the Config string <ConfigResp>
2346 Status
= ProcessQuestionConfig (Selection
, Statement
);
2348 if (EFI_ERROR (Status
)) {
2353 // The action button may change some Question value, so refresh the form
2355 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2358 case EFI_IFR_RESET_BUTTON_OP
:
2360 // Reset Question to default value specified by DefaultId
2362 ControlFlag
= CfUiDefault
;
2363 DefaultId
= Statement
->DefaultId
;
2368 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
2370 UpdateKeyHelp (MenuOption
, TRUE
);
2371 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2373 if (EFI_ERROR (Status
)) {
2379 if (OptionString
!= NULL
) {
2380 PrintStringAt (LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ 1, MenuOption
->Row
, OptionString
);
2381 gBS
->FreePool (OptionString
);
2384 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2391 // We are going to leave current FormSet, so check uncommited data in this FormSet
2393 ControlFlag
= CfCheckSelection
;
2395 if (gClassOfVfr
== EFI_FRONT_PAGE_SUBCLASS
) {
2397 // There is no parent menu for FrontPage
2399 Selection
->Action
= UI_ACTION_NONE
;
2400 Selection
->Statement
= MenuOption
->ThisTag
;
2405 // If NV flag is up, prompt user
2407 if (gNvUpdateRequired
) {
2408 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2410 YesResponse
= gYesResponse
[0];
2411 NoResponse
= gNoResponse
[0];
2414 CreateDialog (3, TRUE
, 0, NULL
, &Key
, gEmptyString
, gAreYouSure
, gEmptyString
);
2417 (Key
.ScanCode
!= SCAN_ESC
) &&
2418 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (NoResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
2419 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (YesResponse
| UPPER_LOWER_CASE_OFFSET
))
2423 // If the user hits the YesResponse key
2425 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (YesResponse
| UPPER_LOWER_CASE_OFFSET
)) {
2430 Selection
->Action
= UI_ACTION_NONE
;
2435 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2436 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2439 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2443 ControlFlag
= CfCheckSelection
;
2444 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2445 if (MenuOption
->Sequence
!= 0) {
2447 // In the middle or tail of the Date/Time op-code set, go left.
2449 NewPos
= NewPos
->BackLink
;
2455 ControlFlag
= CfCheckSelection
;
2456 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2457 if (MenuOption
->Sequence
!= 2) {
2459 // In the middle or tail of the Date/Time op-code set, go left.
2461 NewPos
= NewPos
->ForwardLink
;
2467 ControlFlag
= CfCheckSelection
;
2469 SavedListEntry
= TopOfScreen
;
2471 if (NewPos
->BackLink
!= &Menu
) {
2474 // Adjust Date/Time position before we advance forward.
2476 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2479 // Caution that we have already rewind to the top, don't go backward in this situation.
2481 if (NewPos
->BackLink
!= &Menu
) {
2482 NewPos
= NewPos
->BackLink
;
2485 PreviousMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2486 DistanceValue
= PreviousMenuOption
->Skip
;
2489 // Since the behavior of hitting the up arrow on a Date/Time op-code is intended
2490 // to be one that back to the previous set of op-codes, we need to advance to the sencond
2491 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2492 // checking can be done.
2494 DistanceValue
+= AdjustDateAndTimePosition (TRUE
, &NewPos
);
2497 // Check the previous menu entry to see if it was a zero-length advance. If it was,
2498 // don't worry about a redraw.
2500 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2502 TopOfScreen
= NewPos
;
2505 Difference
= MoveToNextStatement (TRUE
, &NewPos
);
2506 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2507 if (Difference
> 0) {
2509 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
2511 TopOfScreen
= NewPos
;
2515 if (Difference
< 0) {
2517 // We want to goto previous MenuOption, but finally we go down.
2518 // it means that we hit the begining MenuOption that can be focused
2519 // so we simply scroll to the top
2521 if (SavedListEntry
!= Menu
.ForwardLink
) {
2522 TopOfScreen
= Menu
.ForwardLink
;
2528 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2530 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2532 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2534 SavedMenuOption
= MenuOption
;
2535 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2536 if (!IsSelectable (MenuOption
)) {
2538 // If we are at the end of the list and sitting on a text op, we need to more forward
2540 ScreenOperation
= UiDown
;
2541 ControlFlag
= CfScreenOperation
;
2545 MenuOption
= SavedMenuOption
;
2550 ControlFlag
= CfCheckSelection
;
2552 if (NewPos
->BackLink
== &Menu
) {
2561 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2563 while ((Index
>= TopRow
) && (Link
->BackLink
!= &Menu
)) {
2564 Index
= Index
- PreviousMenuOption
->Skip
;
2565 Link
= Link
->BackLink
;
2566 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2570 Difference
= MoveToNextStatement (TRUE
, &Link
);
2571 if (Difference
> 0) {
2573 // The focus MenuOption is above the TopOfScreen
2576 } else if (Difference
< 0) {
2578 // This happens when there is no MenuOption can be focused from
2579 // Current MenuOption to the first MenuOption
2581 TopOfScreen
= Menu
.ForwardLink
;
2583 Index
+= Difference
;
2584 if (Index
< TopRow
) {
2588 if (NewPos
== Link
) {
2596 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2597 // Don't do this when we are already in the first page.
2599 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2600 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2604 ControlFlag
= CfCheckSelection
;
2606 if (NewPos
->ForwardLink
== &Menu
) {
2615 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2617 while ((Index
<= BottomRow
) && (Link
->ForwardLink
!= &Menu
)) {
2618 Index
= Index
+ NextMenuOption
->Skip
;
2619 Link
= Link
->ForwardLink
;
2620 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2623 Index
+= MoveToNextStatement (FALSE
, &Link
);
2624 if (Index
> BottomRow
) {
2626 // There are more MenuOption needing scrolling
2631 if (NewPos
== Link
&& Index
<= BottomRow
) {
2633 // Finally we know that NewPos is the last MenuOption can be focused.
2642 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2643 // Don't do this when we are already in the last page.
2645 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2646 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2650 ControlFlag
= CfCheckSelection
;
2652 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
2653 // to be one that progresses to the next set of op-codes, we need to advance to the last
2654 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2655 // checking can be done. The only other logic we need to introduce is that if a Date/Time
2656 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
2657 // the Date/Time op-code.
2659 SavedListEntry
= NewPos
;
2660 DistanceValue
= AdjustDateAndTimePosition (FALSE
, &NewPos
);
2662 if (NewPos
->ForwardLink
!= &Menu
) {
2663 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2665 NewPos
= NewPos
->ForwardLink
;
2666 NextMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2668 DistanceValue
+= NextMenuOption
->Skip
;
2669 DistanceValue
+= MoveToNextStatement (FALSE
, &NewPos
);
2671 // An option might be multi-line, so we need to reflect that data in the overall skip value
2673 UpdateOptionSkipLines (Selection
, NextMenuOption
, &OptionString
, SkipValue
);
2675 Temp
= MenuOption
->Row
+ MenuOption
->Skip
+ DistanceValue
- 1;
2676 if ((MenuOption
->Row
+ MenuOption
->Skip
== BottomRow
+ 1) &&
2677 (NextMenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
||
2678 NextMenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
2684 // If we are going to scroll, update TopOfScreen
2686 if (Temp
> BottomRow
) {
2689 // Is the current top of screen a zero-advance op-code?
2690 // If so, keep moving forward till we hit a >0 advance op-code
2692 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2695 // If bottom op-code is more than one line or top op-code is more than one line
2697 if ((DistanceValue
> 1) || (MenuOption
->Skip
> 1)) {
2699 // Is the bottom op-code greater than or equal in size to the top op-code?
2701 if ((Temp
- BottomRow
) >= (SavedMenuOption
->Skip
- OldSkipValue
)) {
2703 // Skip the top op-code
2705 TopOfScreen
= TopOfScreen
->ForwardLink
;
2706 Difference
= (Temp
- BottomRow
) - (SavedMenuOption
->Skip
- OldSkipValue
);
2708 OldSkipValue
= Difference
;
2710 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2713 // If we have a remainder, skip that many more op-codes until we drain the remainder
2716 Difference
>= (INTN
) SavedMenuOption
->Skip
;
2717 Difference
= Difference
- (INTN
) SavedMenuOption
->Skip
2720 // Since the Difference is greater than or equal to this op-code's skip value, skip it
2722 TopOfScreen
= TopOfScreen
->ForwardLink
;
2723 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2724 if (Difference
< (INTN
) SavedMenuOption
->Skip
) {
2725 Difference
= SavedMenuOption
->Skip
- Difference
- 1;
2728 if (Difference
== (INTN
) SavedMenuOption
->Skip
) {
2729 TopOfScreen
= TopOfScreen
->ForwardLink
;
2730 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2731 Difference
= SavedMenuOption
->Skip
- Difference
;
2737 // Since we will act on this op-code in the next routine, and increment the
2738 // SkipValue, set the skips to one less than what is required.
2740 SkipValue
= Difference
- 1;
2744 // Since we will act on this op-code in the next routine, and increment the
2745 // SkipValue, set the skips to one less than what is required.
2747 SkipValue
= OldSkipValue
+ (Temp
- BottomRow
) - 1;
2750 if ((OldSkipValue
+ 1) == (INTN
) SavedMenuOption
->Skip
) {
2751 TopOfScreen
= TopOfScreen
->ForwardLink
;
2754 SkipValue
= OldSkipValue
;
2758 // If the op-code at the top of the screen is more than one line, let's not skip it yet
2759 // Let's set a skip flag to smoothly scroll the top of the screen.
2761 if (SavedMenuOption
->Skip
> 1) {
2762 if (SavedMenuOption
== NextMenuOption
) {
2769 TopOfScreen
= TopOfScreen
->ForwardLink
;
2771 } while (SavedMenuOption
->Skip
== 0);
2774 OldSkipValue
= SkipValue
;
2777 MenuOption
= MENU_OPTION_FROM_LINK (SavedListEntry
);
2779 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2782 SavedMenuOption
= MenuOption
;
2783 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2784 if (!IsSelectable (MenuOption
)) {
2786 // If we are at the end of the list and sitting on a text op, we need to more forward
2788 ScreenOperation
= UiUp
;
2789 ControlFlag
= CfScreenOperation
;
2793 MenuOption
= SavedMenuOption
;
2795 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
2797 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2802 ControlFlag
= CfCheckSelection
;
2807 Status
= SubmitForm (Selection
->FormSet
, Selection
->Form
);
2809 if (!EFI_ERROR (Status
)) {
2810 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2811 UpdateStatusBar (NV_UPDATE_REQUIRED
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2814 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gSaveFailed
, gPressEnter
, gEmptyString
);
2815 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
2823 ControlFlag
= CfCheckSelection
;
2825 Status
= ExtractFormDefault (Selection
->FormSet
, Selection
->Form
, DefaultId
);
2827 if (!EFI_ERROR (Status
)) {
2828 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2831 // Show NV update flag on status bar
2833 gNvUpdateRequired
= TRUE
;
2837 case CfUiNoOperation
:
2838 ControlFlag
= CfCheckSelection
;
2842 UiFreeRefreshList ();
2844 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2845 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, Row
+ 4);
2846 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2847 gST
->ConOut
->OutputString (gST
->ConOut
, L
"\n");