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
[] = {
120 BOOLEAN GetLineByWidthFinished
= FALSE
;
124 Set Buffer to Value for Size bytes.
126 @param Buffer Memory to set.
127 @param Size Number of bytes to set
128 @param Value Value of the set operation.
143 while ((Size
--) != 0) {
150 Initialize Menu option list.
158 InitializeListHead (&Menu
);
163 Initialize Menu option list.
171 InitializeListHead (&gMenuList
);
176 Remove a Menu in list, and return FormId/QuestionId for previous Menu.
178 @param Selection Menu selection.
182 UiRemoveMenuListEntry (
183 OUT UI_MENU_SELECTION
*Selection
186 UI_MENU_LIST
*UiMenuList
;
188 if (!IsListEmpty (&gMenuList
)) {
189 UiMenuList
= CR (gMenuList
.ForwardLink
, UI_MENU_LIST
, MenuLink
, UI_MENU_LIST_SIGNATURE
);
191 Selection
->FormId
= UiMenuList
->FormId
;
192 Selection
->QuestionId
= UiMenuList
->QuestionId
;
193 RemoveEntryList (&UiMenuList
->MenuLink
);
194 FreePool (UiMenuList
);
200 Free Menu option linked list.
208 UI_MENU_LIST
*UiMenuList
;
210 while (!IsListEmpty (&gMenuList
)) {
211 UiMenuList
= CR (gMenuList
.ForwardLink
, UI_MENU_LIST
, MenuLink
, UI_MENU_LIST_SIGNATURE
);
212 RemoveEntryList (&UiMenuList
->MenuLink
);
213 FreePool (UiMenuList
);
219 Add one menu entry to the linked lst
221 @param Selection Menu selection.
226 IN UI_MENU_SELECTION
*Selection
229 UI_MENU_LIST
*UiMenuList
;
231 UiMenuList
= AllocateZeroPool (sizeof (UI_MENU_LIST
));
232 ASSERT (UiMenuList
!= NULL
);
234 UiMenuList
->Signature
= UI_MENU_LIST_SIGNATURE
;
235 UiMenuList
->FormId
= Selection
->FormId
;
236 UiMenuList
->QuestionId
= Selection
->QuestionId
;
238 InsertHeadList (&gMenuList
, &UiMenuList
->MenuLink
);
243 Free Menu option linked list.
251 UI_MENU_OPTION
*MenuOption
;
253 while (!IsListEmpty (&Menu
)) {
254 MenuOption
= MENU_OPTION_FROM_LINK (Menu
.ForwardLink
);
255 RemoveEntryList (&MenuOption
->Link
);
258 // We allocated space for this description when we did a GetToken, free it here
260 if (MenuOption
->Skip
!= 0) {
262 // For date/time, MenuOption->Description is shared by three Menu Options
263 // Data format : [01/02/2004] [11:22:33]
264 // Line number : 0 0 1 0 0 1
266 FreePool (MenuOption
->Description
);
268 FreePool (MenuOption
);
274 Free Menu option linked list.
282 MENU_REFRESH_ENTRY
*OldMenuRefreshEntry
;
284 while (gMenuRefreshHead
!= NULL
) {
285 OldMenuRefreshEntry
= gMenuRefreshHead
->Next
;
286 FreePool (gMenuRefreshHead
);
287 gMenuRefreshHead
= OldMenuRefreshEntry
;
290 gMenuRefreshHead
= NULL
;
304 CHAR16
*OptionString
;
305 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
308 UI_MENU_SELECTION
*Selection
;
309 FORM_BROWSER_STATEMENT
*Question
;
310 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
311 EFI_HII_VALUE
*HiiValue
;
312 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
314 if (gMenuRefreshHead
!= NULL
) {
316 MenuRefreshEntry
= gMenuRefreshHead
;
319 // Reset FormPackage update flag
321 mHiiPackageListUpdated
= FALSE
;
324 gST
->ConOut
->SetAttribute (gST
->ConOut
, MenuRefreshEntry
->CurrentAttribute
);
326 Selection
= MenuRefreshEntry
->Selection
;
327 Question
= MenuRefreshEntry
->MenuOption
->ThisTag
;
329 Status
= GetQuestionValue (Selection
->FormSet
, Selection
->Form
, Question
, FALSE
);
330 if (EFI_ERROR (Status
)) {
335 ProcessOptions (Selection
, MenuRefreshEntry
->MenuOption
, FALSE
, &OptionString
);
337 if (OptionString
!= NULL
) {
339 // If leading spaces on OptionString - remove the spaces
341 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
344 PrintStringAt (MenuRefreshEntry
->CurrentColumn
, MenuRefreshEntry
->CurrentRow
, &OptionString
[Index
]);
345 FreePool (OptionString
);
349 // Question value may be changed, need invoke its Callback()
351 ConfigAccess
= Selection
->FormSet
->ConfigAccess
;
352 if (((Question
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) && (ConfigAccess
!= NULL
)) {
353 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
355 HiiValue
= &Question
->HiiValue
;
356 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
358 // Create String in HII database for Configuration Driver to retrieve
360 HiiValue
->Value
.string
= NewString ((CHAR16
*) Question
->BufferValue
, Selection
->FormSet
->HiiHandle
);
363 Status
= ConfigAccess
->Callback (
365 EFI_BROWSER_ACTION_CHANGING
,
366 Question
->QuestionId
,
372 if (HiiValue
->Type
== EFI_IFR_TYPE_STRING
) {
374 // Clean the String in HII Database
376 DeleteString (HiiValue
->Value
.string
, Selection
->FormSet
->HiiHandle
);
379 if (!EFI_ERROR (Status
)) {
380 switch (ActionRequest
) {
381 case EFI_BROWSER_ACTION_REQUEST_RESET
:
382 gResetRequired
= TRUE
;
385 case EFI_BROWSER_ACTION_REQUEST_SUBMIT
:
386 SubmitForm (Selection
->FormSet
, Selection
->Form
);
389 case EFI_BROWSER_ACTION_REQUEST_EXIT
:
390 Selection
->Action
= UI_ACTION_EXIT
;
391 gNvUpdateRequired
= FALSE
;
400 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
402 } while (MenuRefreshEntry
!= NULL
);
404 if (mHiiPackageListUpdated
) {
406 // Package list is updated, force to reparse IFR binary of target Formset
408 mHiiPackageListUpdated
= FALSE
;
409 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
419 Wait for a given event to fire, or for an optional timeout to expire.
421 @param Event The event to wait for
422 @param Timeout An optional timeout value in 100 ns units.
423 @param RefreshInterval Menu refresh interval (in seconds).
425 @retval EFI_SUCCESS Event fired before Timeout expired.
426 @retval EFI_TIME_OUT Timout expired before Event fired.
430 UiWaitForSingleEvent (
432 IN UINT64 Timeout
, OPTIONAL
433 IN UINT8 RefreshInterval OPTIONAL
438 EFI_EVENT TimerEvent
;
439 EFI_EVENT WaitList
[2];
443 // Create a timer event
445 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
446 if (!EFI_ERROR (Status
)) {
448 // Set the timer event
457 // Wait for the original event or the timer
460 WaitList
[1] = TimerEvent
;
461 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
462 gBS
->CloseEvent (TimerEvent
);
465 // If the timer expired, change the return to timed out
467 if (!EFI_ERROR (Status
) && Index
== 1) {
468 Status
= EFI_TIMEOUT
;
473 // Update screen every second
475 if (RefreshInterval
== 0) {
476 Timeout
= ONE_SECOND
;
478 Timeout
= RefreshInterval
* ONE_SECOND
;
482 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
485 // Set the timer event
494 // Wait for the original event or the timer
497 WaitList
[1] = TimerEvent
;
498 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
501 // If the timer expired, update anything that needs a refresh and keep waiting
503 if (!EFI_ERROR (Status
) && Index
== 1) {
504 Status
= EFI_TIMEOUT
;
505 if (RefreshInterval
!= 0) {
506 Status
= RefreshForm ();
510 gBS
->CloseEvent (TimerEvent
);
511 } while (Status
== EFI_TIMEOUT
);
519 Add one menu option by specified description and context.
521 @param String String description for this option.
522 @param Handle Hii handle for the package list.
523 @param Statement Statement of this Menu Option.
524 @param NumberOfLines Display lines for this Menu Option.
525 @param MenuItemCount The index for this Option in the Menu.
531 IN EFI_HII_HANDLE Handle
,
532 IN FORM_BROWSER_STATEMENT
*Statement
,
533 IN UINT16 NumberOfLines
,
534 IN UINT16 MenuItemCount
537 UI_MENU_OPTION
*MenuOption
;
543 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
545 // Add three MenuOptions for Date/Time
546 // Data format : [01/02/2004] [11:22:33]
547 // Line number : 0 0 1 0 0 1
552 if (Statement
->Storage
== NULL
) {
554 // For RTC type of date/time, set default refresh interval to be 1 second
556 if (Statement
->RefreshInterval
== 0) {
557 Statement
->RefreshInterval
= 1;
562 for (Index
= 0; Index
< Count
; Index
++) {
563 MenuOption
= AllocateZeroPool (sizeof (UI_MENU_OPTION
));
566 MenuOption
->Signature
= UI_MENU_OPTION_SIGNATURE
;
567 MenuOption
->Description
= String
;
568 MenuOption
->Handle
= Handle
;
569 MenuOption
->ThisTag
= Statement
;
570 MenuOption
->EntryNumber
= MenuItemCount
;
574 // Override LineNumber for the MenuOption in Date/Time sequence
576 MenuOption
->Skip
= 1;
578 MenuOption
->Skip
= NumberOfLines
;
580 MenuOption
->Sequence
= Index
;
582 if (Statement
->GrayOutExpression
!= NULL
) {
583 MenuOption
->GrayOut
= Statement
->GrayOutExpression
->Result
.Value
.b
;
586 if ((Statement
->ValueExpression
!= NULL
) ||
587 ((Statement
->QuestionFlags
& EFI_IFR_FLAG_READ_ONLY
) != 0)) {
588 MenuOption
->ReadOnly
= TRUE
;
591 InsertTailList (&Menu
, &MenuOption
->Link
);
597 Routine used to abstract a generic dialog interface and return the selected key or string
599 @param NumberOfLines The number of lines for the dialog box
600 @param HotKey Defines whether a single character is parsed
601 (TRUE) and returned in KeyValue or a string is
602 returned in StringBuffer. Two special characters
603 are considered when entering a string, a SCAN_ESC
604 and an CHAR_CARRIAGE_RETURN. SCAN_ESC terminates
605 string input and returns
606 @param MaximumStringSize The maximum size in bytes of a typed in string
607 (each character is a CHAR16) and the minimum
608 string returned is two bytes
609 @param StringBuffer The passed in pointer to the buffer which will
610 hold the typed in string if HotKey is FALSE
611 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
612 @param ... A series of (quantity == NumberOfLines) text
613 strings which will be used to construct the dialog
616 @retval EFI_SUCCESS Displayed dialog and received user interaction
617 @retval EFI_INVALID_PARAMETER One of the parameters was invalid (e.g.
618 (StringBuffer == NULL) && (HotKey == FALSE))
619 @retval EFI_DEVICE_ERROR User typed in an ESC character to exit the routine
624 IN UINTN NumberOfLines
,
626 IN UINTN MaximumStringSize
,
627 OUT CHAR16
*StringBuffer
,
628 OUT EFI_INPUT_KEY
*KeyValue
,
633 VA_LIST MarkerBackup
;
638 CHAR16
*BufferedString
;
645 BOOLEAN SelectionComplete
;
647 UINTN CurrentAttribute
;
648 UINTN DimensionsWidth
;
649 UINTN DimensionsHeight
;
651 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
652 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
654 SelectionComplete
= FALSE
;
656 TempString
= AllocateZeroPool (MaximumStringSize
* 2);
657 BufferedString
= AllocateZeroPool (MaximumStringSize
* 2);
658 CurrentAttribute
= gST
->ConOut
->Mode
->Attribute
;
661 ASSERT (BufferedString
);
663 VA_START (Marker
, KeyValue
);
664 MarkerBackup
= Marker
;
667 // Zero the outgoing buffer
669 ZeroMem (StringBuffer
, MaximumStringSize
);
672 if (KeyValue
== NULL
) {
673 return EFI_INVALID_PARAMETER
;
676 if (StringBuffer
== NULL
) {
677 return EFI_INVALID_PARAMETER
;
683 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
688 // Determine the largest string in the dialog box
689 // Notice we are starting with 1 since String is the first string
691 for (Count
= 0; Count
< NumberOfLines
; Count
++) {
692 StackString
= VA_ARG (Marker
, CHAR16
*);
694 if (StackString
[0] == L
' ') {
695 InputOffset
= Count
+ 1;
698 if ((GetStringWidth (StackString
) / 2) > LargestString
) {
700 // Size of the string visually and subtract the width by one for the null-terminator
702 LargestString
= (GetStringWidth (StackString
) / 2);
706 Start
= (DimensionsWidth
- LargestString
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
707 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
714 CreateSharedPopUp (LargestString
, NumberOfLines
, MarkerBackup
);
717 // Take the first key typed and report it back?
720 Status
= WaitForKeyStroke (&Key
);
721 ASSERT_EFI_ERROR (Status
);
722 CopyMem (KeyValue
, &Key
, sizeof (EFI_INPUT_KEY
));
726 Status
= WaitForKeyStroke (&Key
);
728 switch (Key
.UnicodeChar
) {
730 switch (Key
.ScanCode
) {
732 FreePool (TempString
);
733 FreePool (BufferedString
);
734 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
735 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
736 return EFI_DEVICE_ERROR
;
744 case CHAR_CARRIAGE_RETURN
:
745 SelectionComplete
= TRUE
;
746 FreePool (TempString
);
747 FreePool (BufferedString
);
748 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
749 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
754 if (StringBuffer
[0] != CHAR_NULL
) {
755 for (Index
= 0; StringBuffer
[Index
] != CHAR_NULL
; Index
++) {
756 TempString
[Index
] = StringBuffer
[Index
];
759 // Effectively truncate string by 1 character
761 TempString
[Index
- 1] = CHAR_NULL
;
762 StrCpy (StringBuffer
, TempString
);
767 // If it is the beginning of the string, don't worry about checking maximum limits
769 if ((StringBuffer
[0] == CHAR_NULL
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
770 StrnCpy (StringBuffer
, &Key
.UnicodeChar
, 1);
771 StrnCpy (TempString
, &Key
.UnicodeChar
, 1);
772 } else if ((GetStringWidth (StringBuffer
) < MaximumStringSize
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
773 KeyPad
[0] = Key
.UnicodeChar
;
774 KeyPad
[1] = CHAR_NULL
;
775 StrCat (StringBuffer
, KeyPad
);
776 StrCat (TempString
, KeyPad
);
779 // If the width of the input string is now larger than the screen, we nee to
780 // adjust the index to start printing portions of the string
782 SetUnicodeMem (BufferedString
, LargestString
, L
' ');
784 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
786 if ((GetStringWidth (StringBuffer
) / 2) > (DimensionsWidth
- 2)) {
787 Index
= (GetStringWidth (StringBuffer
) / 2) - DimensionsWidth
+ 2;
792 for (Count
= 0; Index
+ 1 < GetStringWidth (StringBuffer
) / 2; Index
++, Count
++) {
793 BufferedString
[Count
] = StringBuffer
[Index
];
796 PrintStringAt (Start
+ 1, Top
+ InputOffset
, BufferedString
);
799 } while (!SelectionComplete
);
802 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
803 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
808 Draw a pop up windows based on the dimension, number of lines and
811 @param RequestedWidth The width of the pop-up.
812 @param NumberOfLines The number of lines.
813 @param Marker The variable argument list for the list of string to be printed.
818 IN UINTN RequestedWidth
,
819 IN UINTN NumberOfLines
,
831 UINTN DimensionsWidth
;
832 UINTN DimensionsHeight
;
834 DimensionsWidth
= gScreenDimensions
.RightColumn
- gScreenDimensions
.LeftColumn
;
835 DimensionsHeight
= gScreenDimensions
.BottomRow
- gScreenDimensions
.TopRow
;
837 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
839 if ((RequestedWidth
+ 2) > DimensionsWidth
) {
840 RequestedWidth
= DimensionsWidth
- 2;
844 // Subtract the PopUp width from total Columns, allow for one space extra on
845 // each end plus a border.
847 Start
= (DimensionsWidth
- RequestedWidth
- 2) / 2 + gScreenDimensions
.LeftColumn
+ 1;
848 End
= Start
+ RequestedWidth
+ 1;
850 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gScreenDimensions
.TopRow
- 1;
851 Bottom
= Top
+ NumberOfLines
+ 2;
853 Character
= BOXDRAW_DOWN_RIGHT
;
854 PrintCharAt (Start
, Top
, Character
);
855 Character
= BOXDRAW_HORIZONTAL
;
856 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
857 PrintChar (Character
);
860 Character
= BOXDRAW_DOWN_LEFT
;
861 PrintChar (Character
);
862 Character
= BOXDRAW_VERTICAL
;
865 for (Index
= Top
; Index
+ 2 < Bottom
; Index
++, Count
++) {
866 String
= VA_ARG (Marker
, CHAR16
*);
869 // This will clear the background of the line - we never know who might have been
870 // here before us. This differs from the next clear in that it used the non-reverse
871 // video for normal printing.
873 if (GetStringWidth (String
) / 2 > 1) {
874 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
878 // Passing in a space results in the assumption that this is where typing will occur
880 if (String
[0] == L
' ') {
881 ClearLines (Start
+ 1, End
- 1, Index
+ 1, Index
+ 1, POPUP_INVERSE_TEXT
| POPUP_INVERSE_BACKGROUND
);
885 // Passing in a NULL results in a blank space
887 if (String
[0] == CHAR_NULL
) {
888 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, POPUP_TEXT
| POPUP_BACKGROUND
);
892 ((DimensionsWidth
- GetStringWidth (String
) / 2) / 2) + gScreenDimensions
.LeftColumn
+ 1,
896 gST
->ConOut
->SetAttribute (gST
->ConOut
, POPUP_TEXT
| POPUP_BACKGROUND
);
897 PrintCharAt (Start
, Index
+ 1, Character
);
898 PrintCharAt (End
- 1, Index
+ 1, Character
);
901 Character
= BOXDRAW_UP_RIGHT
;
902 PrintCharAt (Start
, Bottom
- 1, Character
);
903 Character
= BOXDRAW_HORIZONTAL
;
904 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
905 PrintChar (Character
);
908 Character
= BOXDRAW_UP_LEFT
;
909 PrintChar (Character
);
913 Draw a pop up windows based on the dimension, number of lines and
916 @param RequestedWidth The width of the pop-up.
917 @param NumberOfLines The number of lines.
918 @param ... A series of text strings that displayed in the pop-up.
923 IN UINTN RequestedWidth
,
924 IN UINTN NumberOfLines
,
930 VA_START (Marker
, NumberOfLines
);
932 CreateSharedPopUp (RequestedWidth
, NumberOfLines
, Marker
);
939 Update status bar on the bottom of menu.
941 @param MessageType The type of message to be shown.
942 @param Flags The flags in Question header.
943 @param State Set or clear.
948 IN UINTN MessageType
,
954 CHAR16
*NvUpdateMessage
;
955 CHAR16
*InputErrorMessage
;
957 NvUpdateMessage
= GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE
), gHiiHandle
);
958 InputErrorMessage
= GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE
), gHiiHandle
);
960 switch (MessageType
) {
963 gST
->ConOut
->SetAttribute (gST
->ConOut
, ERROR_TEXT
);
965 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
,
966 gScreenDimensions
.BottomRow
- 1,
971 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
972 for (Index
= 0; Index
< (GetStringWidth (InputErrorMessage
) - 2) / 2; Index
++) {
973 PrintAt (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ Index
, gScreenDimensions
.BottomRow
- 1, L
" ");
980 case NV_UPDATE_REQUIRED
:
981 if (gClassOfVfr
!= FORMSET_CLASS_FRONT_PAGE
) {
983 gST
->ConOut
->SetAttribute (gST
->ConOut
, INFO_TEXT
);
985 gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
,
986 gScreenDimensions
.BottomRow
- 1,
989 gResetRequired
= (BOOLEAN
) (gResetRequired
| ((Flags
& EFI_IFR_FLAG_RESET_REQUIRED
) == EFI_IFR_FLAG_RESET_REQUIRED
));
991 gNvUpdateRequired
= TRUE
;
993 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
);
994 for (Index
= 0; Index
< (GetStringWidth (NvUpdateMessage
) - 2) / 2; Index
++) {
996 (gScreenDimensions
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ Index
),
997 gScreenDimensions
.BottomRow
- 1,
1002 gNvUpdateRequired
= FALSE
;
1007 case REFRESH_STATUS_BAR
:
1009 UpdateStatusBar (INPUT_ERROR
, Flags
, TRUE
);
1012 if (gNvUpdateRequired
) {
1013 UpdateStatusBar (NV_UPDATE_REQUIRED
, Flags
, TRUE
);
1021 FreePool (InputErrorMessage
);
1022 FreePool (NvUpdateMessage
);
1028 Get the supported width for a particular op-code
1030 @param Statement The FORM_BROWSER_STATEMENT structure passed in.
1031 @param Handle The handle in the HII database being used
1033 @return Returns the number of CHAR16 characters that is support.
1038 IN FORM_BROWSER_STATEMENT
*Statement
,
1039 IN EFI_HII_HANDLE Handle
1049 // See if the second text parameter is really NULL
1051 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1052 String
= GetToken (Statement
->TextTwo
, Handle
);
1053 Size
= StrLen (String
);
1057 if ((Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1058 (Statement
->Operand
== EFI_IFR_REF_OP
) ||
1059 (Statement
->Operand
== EFI_IFR_PASSWORD_OP
) ||
1060 (Statement
->Operand
== EFI_IFR_ACTION_OP
) ||
1061 (Statement
->Operand
== EFI_IFR_RESET_BUTTON_OP
) ||
1063 // Allow a wide display if text op-code and no secondary text op-code
1065 ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Size
== 0))
1067 Width
= (UINT16
) (gPromptBlockWidth
+ gOptionBlockWidth
);
1069 Width
= (UINT16
) gPromptBlockWidth
;
1072 if (Statement
->InSubtitle
) {
1073 Width
-= SUBTITLE_INDENT
;
1080 Will copy LineWidth amount of a string in the OutputString buffer and return the
1081 number of CHAR16 characters that were copied into the OutputString buffer.
1083 @param InputString String description for this option.
1084 @param LineWidth Width of the desired string to extract in CHAR16
1086 @param Index Where in InputString to start the copy process
1087 @param OutputString Buffer to copy the string into
1089 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.
1094 IN CHAR16
*InputString
,
1095 IN UINT16 LineWidth
,
1096 IN OUT UINTN
*Index
,
1097 OUT CHAR16
**OutputString
1103 if (GetLineByWidthFinished
) {
1104 GetLineByWidthFinished
= FALSE
;
1111 *OutputString
= AllocateZeroPool (((UINTN
) (LineWidth
+ 1) * 2));
1114 // Ensure we have got a valid buffer
1116 if (*OutputString
!= NULL
) {
1119 //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.
1120 //To avoid displaying this empty line in screen, just skip the two CHARs here.
1122 if ((InputString
[*Index
] == NARROW_CHAR
) && (InputString
[*Index
+ 1] == CHAR_CARRIAGE_RETURN
)) {
1123 *Index
= *Index
+ 2;
1127 // Fast-forward the string and see if there is a carriage-return in the string
1129 for (; (InputString
[*Index
+ Count2
] != CHAR_CARRIAGE_RETURN
) && (Count2
!= LineWidth
); Count2
++)
1133 // Copy the desired LineWidth of data to the output buffer.
1134 // Also make sure that we don't copy more than the string.
1135 // Also make sure that if there are linefeeds, we account for them.
1137 if ((StrSize (&InputString
[*Index
]) <= ((UINTN
) (LineWidth
+ 1) * 2)) &&
1138 (StrSize (&InputString
[*Index
]) <= ((UINTN
) (Count2
+ 1) * 2))
1141 // Convert to CHAR16 value and show that we are done with this operation
1143 LineWidth
= (UINT16
) ((StrSize (&InputString
[*Index
]) - 2) / 2);
1144 if (LineWidth
!= 0) {
1145 GetLineByWidthFinished
= TRUE
;
1148 if (Count2
== LineWidth
) {
1150 // Rewind the string from the maximum size until we see a space to break the line
1152 for (; (InputString
[*Index
+ LineWidth
] != CHAR_SPACE
) && (LineWidth
!= 0); LineWidth
--)
1154 if (LineWidth
== 0) {
1162 CopyMem (*OutputString
, &InputString
[*Index
], LineWidth
* 2);
1165 // If currently pointing to a space, increment the index to the first non-space character
1168 (InputString
[*Index
+ LineWidth
] == CHAR_SPACE
) || (InputString
[*Index
+ LineWidth
] == CHAR_CARRIAGE_RETURN
);
1172 *Index
= (UINT16
) (*Index
+ LineWidth
);
1181 Update display lines for a Menu Option.
1183 @param Selection The user's selection.
1184 @param MenuOption The MenuOption to be checked.
1185 @param OptionalString The option string.
1186 @param SkipValue The number of lins to skip.
1190 UpdateOptionSkipLines (
1191 IN UI_MENU_SELECTION
*Selection
,
1192 IN UI_MENU_OPTION
*MenuOption
,
1193 OUT CHAR16
**OptionalString
,
1201 CHAR16
*OutputString
;
1202 CHAR16
*OptionString
;
1205 OptionString
= *OptionalString
;
1206 OutputString
= NULL
;
1208 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1210 if (OptionString
!= NULL
) {
1211 Width
= (UINT16
) gOptionBlockWidth
;
1215 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1217 // If there is more string to process print on the next row and increment the Skip value
1219 if (StrLen (&OptionString
[Index
]) != 0) {
1220 if (SkipValue
== 0) {
1223 // Since the Number of lines for this menu entry may or may not be reflected accurately
1224 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1225 // some testing to ensure we are keeping this in-sync.
1227 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1229 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1235 FreePool (OutputString
);
1236 if (SkipValue
!= 0) {
1244 *OptionalString
= OptionString
;
1249 Check whether this Menu Option could be highlighted.
1251 This is an internal function.
1253 @param MenuOption The MenuOption to be checked.
1255 @retval TRUE This Menu Option is selectable.
1256 @retval FALSE This Menu Option could not be selected.
1261 UI_MENU_OPTION
*MenuOption
1264 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) ||
1265 MenuOption
->GrayOut
|| MenuOption
->ReadOnly
) {
1274 Determine if the menu is the last menu that can be selected.
1276 This is an internal function.
1278 @param Direction The scroll direction. False is down. True is up.
1279 @param CurrentPos The current focus.
1281 @return FALSE -- the menu isn't the last menu that can be selected.
1282 @return TRUE -- the menu is the last menu that can be selected.
1287 IN BOOLEAN Direction
,
1288 IN LIST_ENTRY
*CurrentPos
1292 UI_MENU_OPTION
*MenuOption
;
1294 Temp
= Direction
? CurrentPos
->BackLink
: CurrentPos
->ForwardLink
;
1296 if (Temp
== &Menu
) {
1300 for (; Temp
!= &Menu
; Temp
= Direction
? Temp
->BackLink
: Temp
->ForwardLink
) {
1301 MenuOption
= MENU_OPTION_FROM_LINK (Temp
);
1302 if (IsSelectable (MenuOption
)) {
1312 Move to next selectable statement.
1314 This is an internal function.
1316 @param GoUp The navigation direction. TRUE: up, FALSE: down.
1317 @param CurrentPosition Current position.
1319 @return The row distance from current MenuOption to next selectable MenuOption.
1323 MoveToNextStatement (
1325 IN OUT LIST_ENTRY
**CurrentPosition
1331 UI_MENU_OPTION
*NextMenuOption
;
1334 Pos
= *CurrentPosition
;
1338 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1339 if (IsSelectable (NextMenuOption
)) {
1342 if ((GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &Menu
) {
1346 Distance
+= NextMenuOption
->Skip
;
1347 Pos
= (GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1352 // If we hit end there is still no statement can be focused,
1353 // we go backwards to find the statement can be focused.
1356 Pos
= *CurrentPosition
;
1359 NextMenuOption
= MENU_OPTION_FROM_LINK (Pos
);
1360 if (IsSelectable (NextMenuOption
)) {
1363 if ((!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
) == &Menu
) {
1367 Distance
-= NextMenuOption
->Skip
;
1368 Pos
= (!GoUp
? Pos
->BackLink
: Pos
->ForwardLink
);
1372 *CurrentPosition
= &NextMenuOption
->Link
;
1378 Adjust Data and Time position accordingly.
1379 Data format : [01/02/2004] [11:22:33]
1380 Line number : 0 0 1 0 0 1
1382 This is an internal function.
1384 @param DirectionUp the up or down direction. False is down. True is
1386 @param CurrentPosition Current position. On return: Point to the last
1387 Option (Year or Second) if up; Point to the first
1388 Option (Month or Hour) if down.
1390 @return Return line number to pad. It is possible that we stand on a zero-advance
1391 @return data or time opcode, so pad one line when we judge if we are going to scroll outside.
1395 AdjustDateAndTimePosition (
1396 IN BOOLEAN DirectionUp
,
1397 IN OUT LIST_ENTRY
**CurrentPosition
1401 LIST_ENTRY
*NewPosition
;
1402 UI_MENU_OPTION
*MenuOption
;
1403 UINTN PadLineNumber
;
1406 NewPosition
= *CurrentPosition
;
1407 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1409 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
1410 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
1412 // Calculate the distance from current position to the last Date/Time MenuOption
1415 while (MenuOption
->Skip
== 0) {
1417 NewPosition
= NewPosition
->ForwardLink
;
1418 MenuOption
= MENU_OPTION_FROM_LINK (NewPosition
);
1422 NewPosition
= *CurrentPosition
;
1425 // Since the behavior of hitting the up arrow on a Date/Time MenuOption is intended
1426 // to be one that back to the previous set of MenuOptions, we need to advance to the first
1427 // Date/Time MenuOption and leave the remaining logic in CfUiUp intact so the appropriate
1428 // checking can be done.
1430 while (Count
++ < 2) {
1431 NewPosition
= NewPosition
->BackLink
;
1435 // Since the behavior of hitting the down arrow on a Date/Time MenuOption is intended
1436 // to be one that progresses to the next set of MenuOptions, we need to advance to the last
1437 // Date/Time MenuOption and leave the remaining logic in CfUiDown intact so the appropriate
1438 // checking can be done.
1440 while (Count
-- > 0) {
1441 NewPosition
= NewPosition
->ForwardLink
;
1445 *CurrentPosition
= NewPosition
;
1448 return PadLineNumber
;
1452 Find HII Handle in the HII database associated with given Device Path.
1454 If DevicePath is NULL, then ASSERT.
1456 @param DevicePath Device Path associated with the HII package list
1459 @retval Handle HII package list Handle associated with the Device
1461 @retval NULL Hii Package list handle is not found.
1466 DevicePathToHiiHandle (
1467 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1471 EFI_DEVICE_PATH_PROTOCOL
*TmpDevicePath
;
1476 EFI_HANDLE DriverHandle
;
1477 EFI_HII_HANDLE
*HiiHandles
;
1478 EFI_HII_HANDLE HiiHandle
;
1480 ASSERT (DevicePath
!= NULL
);
1482 TmpDevicePath
= DevicePath
;
1484 // Locate Device Path Protocol handle buffer
1486 Status
= gBS
->LocateDevicePath (
1487 &gEfiDevicePathProtocolGuid
,
1491 if (EFI_ERROR (Status
) || !IsDevicePathEnd (TmpDevicePath
)) {
1496 // Retrieve all HII Handles from HII database
1498 BufferSize
= 0x1000;
1499 HiiHandles
= AllocatePool (BufferSize
);
1500 ASSERT (HiiHandles
!= NULL
);
1501 Status
= mHiiDatabase
->ListPackageLists (
1503 EFI_HII_PACKAGE_TYPE_ALL
,
1508 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1509 FreePool (HiiHandles
);
1510 HiiHandles
= AllocatePool (BufferSize
);
1511 ASSERT (HiiHandles
!= NULL
);
1513 Status
= mHiiDatabase
->ListPackageLists (
1515 EFI_HII_PACKAGE_TYPE_ALL
,
1522 if (EFI_ERROR (Status
)) {
1523 FreePool (HiiHandles
);
1528 // Search Hii Handle by Driver Handle
1531 HandleCount
= BufferSize
/ sizeof (EFI_HII_HANDLE
);
1532 for (Index
= 0; Index
< HandleCount
; Index
++) {
1533 Status
= mHiiDatabase
->GetPackageListHandle (
1538 if (!EFI_ERROR (Status
) && (Handle
== DriverHandle
)) {
1539 HiiHandle
= HiiHandles
[Index
];
1544 FreePool (HiiHandles
);
1549 Display menu and wait for user to select one menu option, then return it.
1550 If AutoBoot is enabled, then if user doesn't select any option,
1551 after period of time, it will automatically return the first menu option.
1553 @param Selection Menu selection.
1555 @retval EFI_SUCESSS This function always return successfully for now.
1560 IN OUT UI_MENU_SELECTION
*Selection
1566 UINTN DistanceValue
;
1578 CHAR16
*OptionString
;
1579 CHAR16
*OutputString
;
1580 CHAR16
*FormattedString
;
1590 LIST_ENTRY
*TopOfScreen
;
1591 LIST_ENTRY
*SavedListEntry
;
1592 UI_MENU_OPTION
*MenuOption
;
1593 UI_MENU_OPTION
*NextMenuOption
;
1594 UI_MENU_OPTION
*SavedMenuOption
;
1595 UI_MENU_OPTION
*PreviousMenuOption
;
1596 UI_CONTROL_FLAG ControlFlag
;
1597 EFI_SCREEN_DESCRIPTOR LocalScreen
;
1598 MENU_REFRESH_ENTRY
*MenuRefreshEntry
;
1599 UI_SCREEN_OPERATION ScreenOperation
;
1600 UINT8 MinRefreshInterval
;
1603 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1604 FORM_BROWSER_STATEMENT
*Statement
;
1606 UINT8
*DevicePathBuffer
;
1609 CopyMem (&LocalScreen
, &gScreenDimensions
, sizeof (EFI_SCREEN_DESCRIPTOR
));
1611 Status
= EFI_SUCCESS
;
1612 FormattedString
= NULL
;
1613 OptionString
= NULL
;
1614 ScreenOperation
= UiNoOperation
;
1616 MinRefreshInterval
= 0;
1619 OutputString
= NULL
;
1624 MenuRefreshEntry
= gMenuRefreshHead
;
1626 NextMenuOption
= NULL
;
1627 PreviousMenuOption
= NULL
;
1628 SavedMenuOption
= NULL
;
1630 ZeroMem (&Key
, sizeof (EFI_INPUT_KEY
));
1632 if (gClassOfVfr
== FORMSET_CLASS_FRONT_PAGE
) {
1633 TopRow
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1634 Row
= LocalScreen
.TopRow
+ FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1636 TopRow
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1637 Row
= LocalScreen
.TopRow
+ NONE_FRONT_PAGE_HEADER_HEIGHT
+ SCROLL_ARROW_HEIGHT
;
1640 Col
= LocalScreen
.LeftColumn
;
1641 BottomRow
= LocalScreen
.BottomRow
- STATUS_BAR_HEIGHT
- FOOTER_HEIGHT
- SCROLL_ARROW_HEIGHT
- 1;
1643 Selection
->TopRow
= TopRow
;
1644 Selection
->BottomRow
= BottomRow
;
1645 Selection
->PromptCol
= Col
;
1646 Selection
->OptionCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1647 Selection
->Statement
= NULL
;
1649 TopOfScreen
= Menu
.ForwardLink
;
1654 // Get user's selection
1656 NewPos
= Menu
.ForwardLink
;
1658 gST
->ConOut
->EnableCursor (gST
->ConOut
, FALSE
);
1659 UpdateStatusBar (REFRESH_STATUS_BAR
, (UINT8
) 0, TRUE
);
1661 ControlFlag
= CfInitialization
;
1662 Selection
->Action
= UI_ACTION_NONE
;
1664 switch (ControlFlag
) {
1665 case CfInitialization
:
1666 if (IsListEmpty (&Menu
)) {
1667 ControlFlag
= CfReadKey
;
1669 ControlFlag
= CfCheckSelection
;
1673 case CfCheckSelection
:
1674 if (Selection
->Action
!= UI_ACTION_NONE
) {
1675 ControlFlag
= CfExit
;
1677 ControlFlag
= CfRepaint
;
1682 ControlFlag
= CfRefreshHighLight
;
1696 LocalScreen
.LeftColumn
,
1697 LocalScreen
.RightColumn
,
1698 TopRow
- SCROLL_ARROW_HEIGHT
,
1699 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1700 FIELD_TEXT
| FIELD_BACKGROUND
1703 UiFreeRefreshList ();
1704 MinRefreshInterval
= 0;
1706 for (Link
= TopOfScreen
; Link
!= &Menu
; Link
= Link
->ForwardLink
) {
1707 MenuOption
= MENU_OPTION_FROM_LINK (Link
);
1708 MenuOption
->Row
= Row
;
1709 MenuOption
->Col
= Col
;
1710 MenuOption
->OptCol
= gPromptBlockWidth
+ 1 + LocalScreen
.LeftColumn
;
1712 Statement
= MenuOption
->ThisTag
;
1713 if (Statement
->InSubtitle
) {
1714 MenuOption
->Col
+= SUBTITLE_INDENT
;
1717 if (MenuOption
->GrayOut
) {
1718 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
1720 if (Statement
->Operand
== EFI_IFR_SUBTITLE_OP
) {
1721 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
1725 Width
= GetWidth (Statement
, MenuOption
->Handle
);
1728 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
1729 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1730 PrintStringAt (MenuOption
->Col
, Row
, OutputString
);
1733 // If there is more string to process print on the next row and increment the Skip value
1735 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
1741 FreePool (OutputString
);
1750 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1751 Status
= ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
1752 if (EFI_ERROR (Status
)) {
1754 // Repaint to clear possible error prompt pop-up
1758 ControlFlag
= CfRepaint
;
1762 if (OptionString
!= NULL
) {
1763 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
1765 // If leading spaces on OptionString - remove the spaces
1767 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++) {
1768 MenuOption
->OptCol
++;
1771 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
1772 OptionString
[Count
] = OptionString
[Index
];
1776 OptionString
[Count
] = CHAR_NULL
;
1780 // If Question request refresh, register the op-code
1782 if (Statement
->RefreshInterval
!= 0) {
1784 // Menu will be refreshed at minimal interval of all Questions
1785 // which have refresh request
1787 if (MinRefreshInterval
== 0 || Statement
->RefreshInterval
< MinRefreshInterval
) {
1788 MinRefreshInterval
= Statement
->RefreshInterval
;
1791 if (gMenuRefreshHead
== NULL
) {
1792 MenuRefreshEntry
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1793 ASSERT (MenuRefreshEntry
!= NULL
);
1794 MenuRefreshEntry
->MenuOption
= MenuOption
;
1795 MenuRefreshEntry
->Selection
= Selection
;
1796 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1797 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1798 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1799 gMenuRefreshHead
= MenuRefreshEntry
;
1802 // Advance to the last entry
1804 for (MenuRefreshEntry
= gMenuRefreshHead
;
1805 MenuRefreshEntry
->Next
!= NULL
;
1806 MenuRefreshEntry
= MenuRefreshEntry
->Next
1809 MenuRefreshEntry
->Next
= AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY
));
1810 ASSERT (MenuRefreshEntry
->Next
!= NULL
);
1811 MenuRefreshEntry
= MenuRefreshEntry
->Next
;
1812 MenuRefreshEntry
->MenuOption
= MenuOption
;
1813 MenuRefreshEntry
->Selection
= Selection
;
1814 MenuRefreshEntry
->CurrentColumn
= MenuOption
->OptCol
;
1815 MenuRefreshEntry
->CurrentRow
= MenuOption
->Row
;
1816 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
1820 Width
= (UINT16
) gOptionBlockWidth
;
1823 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
1824 if ((Temp2
== 0) && (Row
<= BottomRow
)) {
1825 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1828 // If there is more string to process print on the next row and increment the Skip value
1830 if (StrLen (&OptionString
[Index
]) != 0) {
1834 // Since the Number of lines for this menu entry may or may not be reflected accurately
1835 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1836 // some testing to ensure we are keeping this in-sync.
1838 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1840 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1846 FreePool (OutputString
);
1855 FreePool (OptionString
);
1858 // If this is a text op with secondary text information
1860 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) && (Statement
->TextTwo
!= 0)) {
1861 StringPtr
= GetToken (Statement
->TextTwo
, MenuOption
->Handle
);
1863 Width
= (UINT16
) gOptionBlockWidth
;
1866 for (Index
= 0; GetLineByWidth (StringPtr
, Width
, &Index
, &OutputString
) != 0x0000;) {
1867 if ((Temp
== 0) && (Row
<= BottomRow
)) {
1868 PrintStringAt (MenuOption
->OptCol
, Row
, OutputString
);
1871 // If there is more string to process print on the next row and increment the Skip value
1873 if (StrLen (&StringPtr
[Index
]) != 0) {
1877 // Since the Number of lines for this menu entry may or may not be reflected accurately
1878 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1879 // some testing to ensure we are keeping this in-sync.
1881 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1883 if ((Row
- OriginalRow
) >= MenuOption
->Skip
) {
1889 FreePool (OutputString
);
1896 FreePool (StringPtr
);
1900 // Need to handle the bottom of the display
1902 if (MenuOption
->Skip
> 1) {
1903 Row
+= MenuOption
->Skip
- SkipValue
;
1906 Row
+= MenuOption
->Skip
;
1909 if (Row
> BottomRow
) {
1910 if (!ValueIsScroll (FALSE
, Link
)) {
1914 Row
= BottomRow
+ 1;
1919 if (!ValueIsScroll (TRUE
, TopOfScreen
)) {
1924 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
1926 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
1927 TopRow
- SCROLL_ARROW_HEIGHT
,
1931 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1935 gST
->ConOut
->SetAttribute (gST
->ConOut
, ARROW_TEXT
| ARROW_BACKGROUND
);
1937 LocalScreen
.LeftColumn
+ gPromptBlockWidth
+ gOptionBlockWidth
+ 1,
1938 BottomRow
+ SCROLL_ARROW_HEIGHT
,
1942 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
1949 case CfRefreshHighLight
:
1951 // MenuOption: Last menu option that need to remove hilight
1952 // MenuOption is set to NULL in Repaint
1953 // NewPos: Current menu option that need to hilight
1955 ControlFlag
= CfUpdateHelpString
;
1958 // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily
1959 // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.
1961 SavedValue
= Repaint
;
1964 if (Selection
->QuestionId
!= 0) {
1965 NewPos
= Menu
.ForwardLink
;
1966 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1968 while (SavedMenuOption
->ThisTag
->QuestionId
!= Selection
->QuestionId
&& NewPos
->ForwardLink
!= &Menu
) {
1969 NewPos
= NewPos
->ForwardLink
;
1970 SavedMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
1972 if (SavedMenuOption
->ThisTag
->QuestionId
== Selection
->QuestionId
) {
1974 // Target Question found, find its MenuOption
1978 for (Index
= TopRow
; Index
<= BottomRow
&& Link
!= NewPos
;) {
1979 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
1980 Index
+= SavedMenuOption
->Skip
;
1981 Link
= Link
->ForwardLink
;
1984 if (Link
!= NewPos
|| Index
> BottomRow
) {
1986 // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page
1989 for (Index
= TopRow
; Index
<= BottomRow
; ) {
1990 Link
= Link
->BackLink
;
1991 SavedMenuOption
= MENU_OPTION_FROM_LINK (Link
);
1992 Index
+= SavedMenuOption
->Skip
;
1994 TopOfScreen
= Link
->ForwardLink
;
1998 ControlFlag
= CfRepaint
;
2003 // Target Question not found, highlight the default menu option
2005 NewPos
= TopOfScreen
;
2008 Selection
->QuestionId
= 0;
2011 if (NewPos
!= NULL
&& (MenuOption
== NULL
|| NewPos
!= &MenuOption
->Link
)) {
2012 if (MenuOption
!= NULL
) {
2014 // Remove highlight on last Menu Option
2016 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
2017 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
2018 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2019 if (OptionString
!= NULL
) {
2020 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) ||
2021 (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
2024 // If leading spaces on OptionString - remove the spaces
2026 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
2029 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
2030 OptionString
[Count
] = OptionString
[Index
];
2034 OptionString
[Count
] = CHAR_NULL
;
2037 Width
= (UINT16
) gOptionBlockWidth
;
2038 OriginalRow
= MenuOption
->Row
;
2040 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
2041 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2042 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
2045 // If there is more string to process print on the next row and increment the Skip value
2047 if (StrLen (&OptionString
[Index
]) != 0) {
2051 FreePool (OutputString
);
2054 MenuOption
->Row
= OriginalRow
;
2056 FreePool (OptionString
);
2059 if (MenuOption
->GrayOut
) {
2060 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_GRAYED
| FIELD_BACKGROUND
);
2061 } else if (MenuOption
->ThisTag
->Operand
== EFI_IFR_SUBTITLE_OP
) {
2062 gST
->ConOut
->SetAttribute (gST
->ConOut
, SUBTITLE_TEXT
| FIELD_BACKGROUND
);
2065 OriginalRow
= MenuOption
->Row
;
2066 Width
= GetWidth (MenuOption
->ThisTag
, MenuOption
->Handle
);
2068 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2069 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2070 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2073 // If there is more string to process print on the next row and increment the Skip value
2075 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
2079 FreePool (OutputString
);
2082 MenuOption
->Row
= OriginalRow
;
2083 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2089 // This is only possible if we entered this page and the first menu option is
2090 // a "non-menu" item. In that case, force it UiDown
2092 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2093 if (!IsSelectable (MenuOption
)) {
2094 ASSERT (ScreenOperation
== UiNoOperation
);
2095 ScreenOperation
= UiDown
;
2096 ControlFlag
= CfScreenOperation
;
2101 // This is the current selected statement
2103 Statement
= MenuOption
->ThisTag
;
2104 Selection
->Statement
= Statement
;
2107 // Set reverse attribute
2109 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
);
2110 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, MenuOption
->Col
, MenuOption
->Row
);
2113 // Assuming that we have a refresh linked-list created, lets annotate the
2114 // appropriate entry that we are highlighting with its new attribute. Just prior to this
2115 // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh
2117 if (gMenuRefreshHead
!= NULL
) {
2118 for (MenuRefreshEntry
= gMenuRefreshHead
; MenuRefreshEntry
!= NULL
; MenuRefreshEntry
= MenuRefreshEntry
->Next
) {
2119 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT
| FIELD_BACKGROUND
;
2120 if (MenuRefreshEntry
->MenuOption
== MenuOption
) {
2121 MenuRefreshEntry
->CurrentAttribute
= FIELD_TEXT_HIGHLIGHT
| FIELD_BACKGROUND_HIGHLIGHT
;
2126 ProcessOptions (Selection
, MenuOption
, FALSE
, &OptionString
);
2127 if (OptionString
!= NULL
) {
2128 if (Statement
->Operand
== EFI_IFR_DATE_OP
|| Statement
->Operand
== EFI_IFR_TIME_OP
) {
2130 // If leading spaces on OptionString - remove the spaces
2132 for (Index
= 0; OptionString
[Index
] == L
' '; Index
++)
2135 for (Count
= 0; OptionString
[Index
] != CHAR_NULL
; Index
++) {
2136 OptionString
[Count
] = OptionString
[Index
];
2140 OptionString
[Count
] = CHAR_NULL
;
2142 Width
= (UINT16
) gOptionBlockWidth
;
2144 OriginalRow
= MenuOption
->Row
;
2146 for (Index
= 0; GetLineByWidth (OptionString
, Width
, &Index
, &OutputString
) != 0x0000;) {
2147 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2148 PrintStringAt (MenuOption
->OptCol
, MenuOption
->Row
, OutputString
);
2151 // If there is more string to process print on the next row and increment the Skip value
2153 if (StrLen (&OptionString
[Index
]) != 0) {
2157 FreePool (OutputString
);
2160 MenuOption
->Row
= OriginalRow
;
2162 FreePool (OptionString
);
2165 OriginalRow
= MenuOption
->Row
;
2167 Width
= GetWidth (Statement
, MenuOption
->Handle
);
2169 for (Index
= 0; GetLineByWidth (MenuOption
->Description
, Width
, &Index
, &OutputString
) != 0x0000;) {
2170 if (MenuOption
->Row
>= TopRow
&& MenuOption
->Row
<= BottomRow
) {
2171 PrintStringAt (MenuOption
->Col
, MenuOption
->Row
, OutputString
);
2174 // If there is more string to process print on the next row and increment the Skip value
2176 if (StrLen (&MenuOption
->Description
[Index
]) != 0) {
2180 FreePool (OutputString
);
2183 MenuOption
->Row
= OriginalRow
;
2188 UpdateKeyHelp (MenuOption
, FALSE
);
2191 // Clear reverse attribute
2193 gST
->ConOut
->SetAttribute (gST
->ConOut
, FIELD_TEXT
| FIELD_BACKGROUND
);
2196 // Repaint flag will be used when process CfUpdateHelpString, so restore its value
2197 // if we didn't break halfway when process CfRefreshHighLight.
2199 Repaint
= SavedValue
;
2202 case CfUpdateHelpString
:
2203 ControlFlag
= CfPrepareToReadKey
;
2205 if (Repaint
|| NewLine
) {
2207 // Don't print anything if it is a NULL help token
2209 if (MenuOption
->ThisTag
->Help
== 0) {
2212 StringPtr
= GetToken (MenuOption
->ThisTag
->Help
, MenuOption
->Handle
);
2215 ProcessHelpString (StringPtr
, &FormattedString
, BottomRow
- TopRow
);
2217 gST
->ConOut
->SetAttribute (gST
->ConOut
, HELP_TEXT
| FIELD_BACKGROUND
);
2219 for (Index
= 0; Index
< BottomRow
- TopRow
; Index
++) {
2221 // Pad String with spaces to simulate a clearing of the previous line
2223 for (; GetStringWidth (&FormattedString
[Index
* gHelpBlockWidth
* 2]) / 2 < gHelpBlockWidth
;) {
2224 StrCat (&FormattedString
[Index
* gHelpBlockWidth
* 2], L
" ");
2228 LocalScreen
.RightColumn
- gHelpBlockWidth
,
2230 &FormattedString
[Index
* gHelpBlockWidth
* 2]
2235 // Reset this flag every time we finish using it.
2241 case CfPrepareToReadKey
:
2242 ControlFlag
= CfReadKey
;
2243 ScreenOperation
= UiNoOperation
;
2247 ControlFlag
= CfScreenOperation
;
2250 // Wait for user's selection
2253 Status
= UiWaitForSingleEvent (gST
->ConIn
->WaitForKey
, 0, MinRefreshInterval
);
2254 } while (Status
== EFI_TIMEOUT
);
2256 if (Selection
->Action
== UI_ACTION_REFRESH_FORMSET
) {
2258 // IFR is updated in Callback of refresh opcode, re-parse it
2260 ControlFlag
= CfUiReset
;
2261 Selection
->Statement
= NULL
;
2265 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2267 // if we encounter error, continue to read another key in.
2269 if (EFI_ERROR (Status
)) {
2270 ControlFlag
= CfReadKey
;
2274 if (IsListEmpty (&Menu
) && Key
.UnicodeChar
!= CHAR_NULL
) {
2276 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2281 switch (Key
.UnicodeChar
) {
2282 case CHAR_CARRIAGE_RETURN
:
2283 ScreenOperation
= UiSelect
;
2288 // We will push the adjustment of these numeric values directly to the input handler
2289 // NOTE: we won't handle manual input numeric
2293 Statement
= MenuOption
->ThisTag
;
2294 if ((Statement
->Operand
== EFI_IFR_DATE_OP
)
2295 || (Statement
->Operand
== EFI_IFR_TIME_OP
)
2296 || ((Statement
->Operand
== EFI_IFR_NUMERIC_OP
) && (Statement
->Step
!= 0))
2298 if (Key
.UnicodeChar
== '+') {
2299 gDirection
= SCAN_RIGHT
;
2301 gDirection
= SCAN_LEFT
;
2303 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2304 if (EFI_ERROR (Status
)) {
2306 // Repaint to clear possible error prompt pop-up
2311 if (OptionString
!= NULL
) {
2312 FreePool (OptionString
);
2318 ScreenOperation
= UiUp
;
2323 ScreenOperation
= UiDown
;
2327 if (gClassOfVfr
!= FORMSET_CLASS_FRONT_PAGE
) {
2328 if (MenuOption
->ThisTag
->Operand
== EFI_IFR_CHECKBOX_OP
&& !MenuOption
->GrayOut
) {
2329 ScreenOperation
= UiSelect
;
2335 if (((Key
.ScanCode
== SCAN_F1
) && ((gFunctionKeySetting
& FUNCTION_ONE
) != FUNCTION_ONE
)) ||
2336 ((Key
.ScanCode
== SCAN_F2
) && ((gFunctionKeySetting
& FUNCTION_TWO
) != FUNCTION_TWO
)) ||
2337 ((Key
.ScanCode
== SCAN_F9
) && ((gFunctionKeySetting
& FUNCTION_NINE
) != FUNCTION_NINE
)) ||
2338 ((Key
.ScanCode
== SCAN_F10
) && ((gFunctionKeySetting
& FUNCTION_TEN
) != FUNCTION_TEN
))
2341 // If the function key has been disabled, just ignore the key.
2344 for (Index
= 0; Index
< sizeof (gScanCodeToOperation
) / sizeof (gScanCodeToOperation
[0]); Index
++) {
2345 if (Key
.ScanCode
== gScanCodeToOperation
[Index
].ScanCode
) {
2346 if (Key
.ScanCode
== SCAN_F9
) {
2348 // Reset to standard default
2350 DefaultId
= EFI_HII_DEFAULT_CLASS_STANDARD
;
2352 ScreenOperation
= gScanCodeToOperation
[Index
].ScreenOperation
;
2361 case CfScreenOperation
:
2362 if (ScreenOperation
!= UiPrevious
&& ScreenOperation
!= UiReset
) {
2364 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2365 // ignore the selection and go back to reading keys.
2367 if (IsListEmpty (&Menu
)) {
2368 ControlFlag
= CfReadKey
;
2372 // if there is nothing logical to place a cursor on, just move on to wait for a key.
2374 for (Link
= Menu
.ForwardLink
; Link
!= &Menu
; Link
= Link
->ForwardLink
) {
2375 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2376 if (IsSelectable (NextMenuOption
)) {
2381 if (Link
== &Menu
) {
2382 ControlFlag
= CfPrepareToReadKey
;
2385 } else if (ScreenOperation
== UiReset
) {
2387 // Press ESC to exit FormSet
2389 Selection
->Action
= UI_ACTION_EXIT
;
2390 Selection
->Statement
= NULL
;
2394 Index
< sizeof (gScreenOperationToControlFlag
) / sizeof (gScreenOperationToControlFlag
[0]);
2397 if (ScreenOperation
== gScreenOperationToControlFlag
[Index
].ScreenOperation
) {
2398 ControlFlag
= gScreenOperationToControlFlag
[Index
].ControlFlag
;
2405 ControlFlag
= CfCheckSelection
;
2407 if (IsListEmpty (&gMenuList
)) {
2408 Selection
->Action
= UI_ACTION_NONE
;
2409 if (IsListEmpty (&Menu
)) {
2410 ControlFlag
= CfReadKey
;
2416 // Remove the Cached page entry
2418 UiRemoveMenuListEntry (Selection
);
2420 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2421 Selection
->Statement
= NULL
;
2425 ControlFlag
= CfCheckSelection
;
2427 Statement
= MenuOption
->ThisTag
;
2428 if ((Statement
->Operand
== EFI_IFR_TEXT_OP
) ||
2429 (Statement
->Operand
== EFI_IFR_DATE_OP
) ||
2430 (Statement
->Operand
== EFI_IFR_TIME_OP
) ||
2431 (Statement
->Operand
== EFI_IFR_NUMERIC_OP
&& Statement
->Step
!= 0)) {
2436 // Keep highlight on current MenuOption
2438 Selection
->QuestionId
= Statement
->QuestionId
;
2440 switch (Statement
->Operand
) {
2441 case EFI_IFR_REF_OP
:
2442 if (Statement
->RefDevicePath
!= 0) {
2444 // Goto another Hii Package list
2446 ControlFlag
= CfUiReset
;
2447 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2449 StringPtr
= GetToken (Statement
->RefDevicePath
, Selection
->FormSet
->HiiHandle
);
2450 if (StringPtr
== NULL
) {
2452 // No device path string not found, exit
2454 Selection
->Action
= UI_ACTION_EXIT
;
2455 Selection
->Statement
= NULL
;
2458 BufferSize
= StrLen (StringPtr
) / 2;
2459 DevicePath
= AllocatePool (BufferSize
);
2462 // Convert from Device Path String to DevicePath Buffer in the reverse order.
2464 DevicePathBuffer
= (UINT8
*) DevicePath
;
2465 for (Index
= 0; StringPtr
[Index
] != L
'\0'; Index
++) {
2466 TemStr
[0] = StringPtr
[Index
];
2467 DigitUint8
= (UINT8
) StrHexToUint64 (TemStr
);
2468 if (DigitUint8
== 0 && TemStr
[0] != L
'0') {
2470 // Invalid Hex Char as the tail.
2474 if ((Index
& 1) == 0) {
2475 DevicePathBuffer
[Index
/2] = DigitUint8
;
2477 DevicePathBuffer
[Index
/2] = (UINT8
) ((DevicePathBuffer
[Index
/2] << 4) + DigitUint8
);
2481 Selection
->Handle
= DevicePathToHiiHandle (DevicePath
);
2482 if (Selection
->Handle
== NULL
) {
2484 // If target Hii Handle not found, exit
2486 Selection
->Action
= UI_ACTION_EXIT
;
2487 Selection
->Statement
= NULL
;
2491 FreePool (StringPtr
);
2492 FreePool (DevicePath
);
2494 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2495 Selection
->FormId
= Statement
->RefFormId
;
2496 Selection
->QuestionId
= Statement
->RefQuestionId
;
2497 } else if (!CompareGuid (&Statement
->RefFormSetId
, &gZeroGuid
)) {
2499 // Goto another Formset, check for uncommitted data
2501 ControlFlag
= CfUiReset
;
2502 Selection
->Action
= UI_ACTION_REFRESH_FORMSET
;
2504 CopyMem (&Selection
->FormSetGuid
, &Statement
->RefFormSetId
, sizeof (EFI_GUID
));
2505 Selection
->FormId
= Statement
->RefFormId
;
2506 Selection
->QuestionId
= Statement
->RefQuestionId
;
2507 } else if (Statement
->RefFormId
!= 0) {
2509 // Goto another form inside this formset,
2511 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2514 // Link current form so that we can always go back when someone hits the UiPrevious
2516 UiAddMenuListEntry (Selection
);
2518 Selection
->FormId
= Statement
->RefFormId
;
2519 Selection
->QuestionId
= Statement
->RefQuestionId
;
2520 } else if (Statement
->RefQuestionId
!= 0) {
2522 // Goto another Question
2524 Selection
->QuestionId
= Statement
->RefQuestionId
;
2526 if ((Statement
->QuestionFlags
& EFI_IFR_FLAG_CALLBACK
) != 0) {
2527 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2536 case EFI_IFR_ACTION_OP
:
2538 // Process the Config string <ConfigResp>
2540 Status
= ProcessQuestionConfig (Selection
, Statement
);
2542 if (EFI_ERROR (Status
)) {
2547 // The action button may change some Question value, so refresh the form
2549 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2552 case EFI_IFR_RESET_BUTTON_OP
:
2554 // Reset Question to default value specified by DefaultId
2556 ControlFlag
= CfUiDefault
;
2557 DefaultId
= Statement
->DefaultId
;
2562 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
2564 UpdateKeyHelp (MenuOption
, TRUE
);
2565 Status
= ProcessOptions (Selection
, MenuOption
, TRUE
, &OptionString
);
2567 if (EFI_ERROR (Status
)) {
2570 UpdateKeyHelp (MenuOption
, FALSE
);
2572 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
2575 if (OptionString
!= NULL
) {
2576 FreePool (OptionString
);
2584 // We are going to leave current FormSet, so check uncommited data in this FormSet
2586 ControlFlag
= CfCheckSelection
;
2588 if (gClassOfVfr
== FORMSET_CLASS_FRONT_PAGE
) {
2590 // There is no parent menu for FrontPage
2592 Selection
->Action
= UI_ACTION_NONE
;
2593 Selection
->Statement
= MenuOption
->ThisTag
;
2598 // If NV flag is up, prompt user
2600 if (gNvUpdateRequired
) {
2601 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
2603 YesResponse
= gYesResponse
[0];
2604 NoResponse
= gNoResponse
[0];
2607 CreateDialog (3, TRUE
, 0, NULL
, &Key
, gEmptyString
, gAreYouSure
, gEmptyString
);
2610 (Key
.ScanCode
!= SCAN_ESC
) &&
2611 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (NoResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
2612 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (YesResponse
| UPPER_LOWER_CASE_OFFSET
))
2616 // If the user hits the YesResponse key
2618 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (YesResponse
| UPPER_LOWER_CASE_OFFSET
)) {
2623 Selection
->Action
= UI_ACTION_NONE
;
2628 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
2629 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
2632 gST
->ConOut
->ClearScreen (gST
->ConOut
);
2636 ControlFlag
= CfCheckSelection
;
2637 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2638 if (MenuOption
->Sequence
!= 0) {
2640 // In the middle or tail of the Date/Time op-code set, go left.
2642 NewPos
= NewPos
->BackLink
;
2648 ControlFlag
= CfCheckSelection
;
2649 if ((MenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
) || (MenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)) {
2650 if (MenuOption
->Sequence
!= 2) {
2652 // In the middle or tail of the Date/Time op-code set, go left.
2654 NewPos
= NewPos
->ForwardLink
;
2660 ControlFlag
= CfCheckSelection
;
2662 SavedListEntry
= TopOfScreen
;
2664 if (NewPos
->BackLink
!= &Menu
) {
2667 // Adjust Date/Time position before we advance forward.
2669 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2672 // Caution that we have already rewind to the top, don't go backward in this situation.
2674 if (NewPos
->BackLink
!= &Menu
) {
2675 NewPos
= NewPos
->BackLink
;
2678 PreviousMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2679 DistanceValue
= PreviousMenuOption
->Skip
;
2682 // Since the behavior of hitting the up arrow on a Date/Time op-code is intended
2683 // to be one that back to the previous set of op-codes, we need to advance to the sencond
2684 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2685 // checking can be done.
2687 DistanceValue
+= AdjustDateAndTimePosition (TRUE
, &NewPos
);
2690 // Check the previous menu entry to see if it was a zero-length advance. If it was,
2691 // don't worry about a redraw.
2693 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2695 TopOfScreen
= NewPos
;
2698 Difference
= MoveToNextStatement (TRUE
, &NewPos
);
2699 if ((INTN
) MenuOption
->Row
- (INTN
) DistanceValue
< (INTN
) TopRow
) {
2700 if (Difference
> 0) {
2702 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
2704 TopOfScreen
= NewPos
;
2708 if (Difference
< 0) {
2710 // We want to goto previous MenuOption, but finally we go down.
2711 // it means that we hit the begining MenuOption that can be focused
2712 // so we simply scroll to the top
2714 if (SavedListEntry
!= Menu
.ForwardLink
) {
2715 TopOfScreen
= Menu
.ForwardLink
;
2721 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2723 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2725 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2727 SavedMenuOption
= MenuOption
;
2728 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2729 if (!IsSelectable (MenuOption
)) {
2731 // If we are at the end of the list and sitting on a text op, we need to more forward
2733 ScreenOperation
= UiDown
;
2734 ControlFlag
= CfScreenOperation
;
2738 MenuOption
= SavedMenuOption
;
2743 ControlFlag
= CfCheckSelection
;
2745 if (NewPos
->BackLink
== &Menu
) {
2754 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2756 while ((Index
>= TopRow
) && (Link
->BackLink
!= &Menu
)) {
2757 Index
= Index
- PreviousMenuOption
->Skip
;
2758 Link
= Link
->BackLink
;
2759 PreviousMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2763 Difference
= MoveToNextStatement (TRUE
, &Link
);
2764 if (Difference
> 0) {
2766 // The focus MenuOption is above the TopOfScreen
2769 } else if (Difference
< 0) {
2771 // This happens when there is no MenuOption can be focused from
2772 // Current MenuOption to the first MenuOption
2774 TopOfScreen
= Menu
.ForwardLink
;
2776 Index
+= Difference
;
2777 if (Index
< TopRow
) {
2781 if (NewPos
== Link
) {
2789 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2790 // Don't do this when we are already in the first page.
2792 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2793 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2797 ControlFlag
= CfCheckSelection
;
2799 if (NewPos
->ForwardLink
== &Menu
) {
2808 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2810 while ((Index
<= BottomRow
) && (Link
->ForwardLink
!= &Menu
)) {
2811 Index
= Index
+ NextMenuOption
->Skip
;
2812 Link
= Link
->ForwardLink
;
2813 NextMenuOption
= MENU_OPTION_FROM_LINK (Link
);
2816 Index
+= MoveToNextStatement (FALSE
, &Link
);
2817 if (Index
> BottomRow
) {
2819 // There are more MenuOption needing scrolling
2824 if (NewPos
== Link
&& Index
<= BottomRow
) {
2826 // Finally we know that NewPos is the last MenuOption can be focused.
2835 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2836 // Don't do this when we are already in the last page.
2838 AdjustDateAndTimePosition (TRUE
, &TopOfScreen
);
2839 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2843 ControlFlag
= CfCheckSelection
;
2845 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
2846 // to be one that progresses to the next set of op-codes, we need to advance to the last
2847 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2848 // checking can be done. The only other logic we need to introduce is that if a Date/Time
2849 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
2850 // the Date/Time op-code.
2852 SavedListEntry
= NewPos
;
2853 DistanceValue
= AdjustDateAndTimePosition (FALSE
, &NewPos
);
2855 if (NewPos
->ForwardLink
!= &Menu
) {
2856 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2858 NewPos
= NewPos
->ForwardLink
;
2859 NextMenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2861 DistanceValue
+= NextMenuOption
->Skip
;
2862 DistanceValue
+= MoveToNextStatement (FALSE
, &NewPos
);
2864 // An option might be multi-line, so we need to reflect that data in the overall skip value
2866 UpdateOptionSkipLines (Selection
, NextMenuOption
, &OptionString
, SkipValue
);
2868 Temp
= MenuOption
->Row
+ MenuOption
->Skip
+ DistanceValue
- 1;
2869 if ((MenuOption
->Row
+ MenuOption
->Skip
== BottomRow
+ 1) &&
2870 (NextMenuOption
->ThisTag
->Operand
== EFI_IFR_DATE_OP
||
2871 NextMenuOption
->ThisTag
->Operand
== EFI_IFR_TIME_OP
)
2877 // If we are going to scroll, update TopOfScreen
2879 if (Temp
> BottomRow
) {
2882 // Is the current top of screen a zero-advance op-code?
2883 // If so, keep moving forward till we hit a >0 advance op-code
2885 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2888 // If bottom op-code is more than one line or top op-code is more than one line
2890 if ((DistanceValue
> 1) || (MenuOption
->Skip
> 1)) {
2892 // Is the bottom op-code greater than or equal in size to the top op-code?
2894 if ((Temp
- BottomRow
) >= (SavedMenuOption
->Skip
- OldSkipValue
)) {
2896 // Skip the top op-code
2898 TopOfScreen
= TopOfScreen
->ForwardLink
;
2899 Difference
= (Temp
- BottomRow
) - (SavedMenuOption
->Skip
- OldSkipValue
);
2901 OldSkipValue
= Difference
;
2903 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2906 // If we have a remainder, skip that many more op-codes until we drain the remainder
2909 Difference
>= (INTN
) SavedMenuOption
->Skip
;
2910 Difference
= Difference
- (INTN
) SavedMenuOption
->Skip
2913 // Since the Difference is greater than or equal to this op-code's skip value, skip it
2915 TopOfScreen
= TopOfScreen
->ForwardLink
;
2916 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2917 if (Difference
< (INTN
) SavedMenuOption
->Skip
) {
2918 Difference
= SavedMenuOption
->Skip
- Difference
- 1;
2921 if (Difference
== (INTN
) SavedMenuOption
->Skip
) {
2922 TopOfScreen
= TopOfScreen
->ForwardLink
;
2923 SavedMenuOption
= MENU_OPTION_FROM_LINK (TopOfScreen
);
2924 Difference
= SavedMenuOption
->Skip
- Difference
;
2930 // Since we will act on this op-code in the next routine, and increment the
2931 // SkipValue, set the skips to one less than what is required.
2933 SkipValue
= Difference
- 1;
2937 // Since we will act on this op-code in the next routine, and increment the
2938 // SkipValue, set the skips to one less than what is required.
2940 SkipValue
= OldSkipValue
+ (Temp
- BottomRow
) - 1;
2943 if ((OldSkipValue
+ 1) == (INTN
) SavedMenuOption
->Skip
) {
2944 TopOfScreen
= TopOfScreen
->ForwardLink
;
2947 SkipValue
= OldSkipValue
;
2951 // If the op-code at the top of the screen is more than one line, let's not skip it yet
2952 // Let's set a skip flag to smoothly scroll the top of the screen.
2954 if (SavedMenuOption
->Skip
> 1) {
2955 if (SavedMenuOption
== NextMenuOption
) {
2962 TopOfScreen
= TopOfScreen
->ForwardLink
;
2964 } while (SavedMenuOption
->Skip
== 0);
2967 OldSkipValue
= SkipValue
;
2970 MenuOption
= MENU_OPTION_FROM_LINK (SavedListEntry
);
2972 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
2975 SavedMenuOption
= MenuOption
;
2976 MenuOption
= MENU_OPTION_FROM_LINK (NewPos
);
2977 if (!IsSelectable (MenuOption
)) {
2979 // If we are at the end of the list and sitting on a text op, we need to more forward
2981 ScreenOperation
= UiUp
;
2982 ControlFlag
= CfScreenOperation
;
2986 MenuOption
= SavedMenuOption
;
2988 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
2990 AdjustDateAndTimePosition (TRUE
, &NewPos
);
2995 ControlFlag
= CfCheckSelection
;
3000 Status
= SubmitForm (Selection
->FormSet
, Selection
->Form
);
3002 if (!EFI_ERROR (Status
)) {
3003 UpdateStatusBar (INPUT_ERROR
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3004 UpdateStatusBar (NV_UPDATE_REQUIRED
, MenuOption
->ThisTag
->QuestionFlags
, FALSE
);
3007 CreateDialog (4, TRUE
, 0, NULL
, &Key
, gEmptyString
, gSaveFailed
, gPressEnter
, gEmptyString
);
3008 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
3016 ControlFlag
= CfCheckSelection
;
3018 Status
= ExtractFormDefault (Selection
->FormSet
, Selection
->Form
, DefaultId
);
3020 if (!EFI_ERROR (Status
)) {
3021 Selection
->Action
= UI_ACTION_REFRESH_FORM
;
3022 Selection
->Statement
= NULL
;
3025 // Show NV update flag on status bar
3027 gNvUpdateRequired
= TRUE
;
3031 case CfUiNoOperation
:
3032 ControlFlag
= CfCheckSelection
;
3036 UiFreeRefreshList ();
3038 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
3039 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, Row
+ 4);
3040 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
3041 gST
->ConOut
->OutputString (gST
->ConOut
, L
"\n");