X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FSetupBrowserDxe%2FUi.c;h=ca2ec3b169f7ff97db9e6c9f31218bc9da49a27f;hb=febca2e36407e6c7acddb420606d901f28a4b4a9;hp=cc9652ee1767cb18c8216822bb11e19e4e5e3c08;hpb=aa79b0b3799e95bc21e0df32a135cc5a4d749e4b;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c index cc9652ee17..ca2ec3b169 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c @@ -1,8 +1,8 @@ /** @file Utility functions for User Interface functions. -Copyright (c) 2004 - 2008, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -12,12 +12,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#include "Ui.h" #include "Setup.h" -LIST_ENTRY Menu; -LIST_ENTRY gMenuList; -MENU_REFRESH_ENTRY *gMenuRefreshHead; +LIST_ENTRY gMenuOption; +LIST_ENTRY gMenuList = INITIALIZE_LIST_HEAD_VARIABLE (gMenuList); +MENU_REFRESH_ENTRY *gMenuRefreshHead; // Menu list used for refresh timer opcode. +MENU_REFRESH_ENTRY *gMenuEventGuidRefreshHead; // Menu list used for refresh event guid opcode. // // Search table for UiDisplayMenu() @@ -43,10 +43,6 @@ SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation[] = { SCAN_ESC, UiReset, }, - { - SCAN_F2, - UiPrevious, - }, { SCAN_LEFT, UiLeft, @@ -54,26 +50,16 @@ SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation[] = { { SCAN_RIGHT, UiRight, - }, - { - SCAN_F9, - UiDefault, - }, - { - SCAN_F10, - UiSave } }; +UINTN mScanCodeNumber = sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]); + SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag[] = { { UiNoOperation, CfUiNoOperation, }, - { - UiDefault, - CfUiDefault, - }, { UiSelect, CfUiSelect, @@ -98,14 +84,6 @@ SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag[] = { UiReset, CfUiReset, }, - { - UiSave, - CfUiSave, - }, - { - UiPrevious, - CfUiPrevious, - }, { UiPageUp, CfUiPageUp, @@ -113,6 +91,10 @@ SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag[] = { { UiPageDown, CfUiPageDown + }, + { + UiHotKey, + CfUiHotKey } }; @@ -127,8 +109,6 @@ BOOLEAN GetLineByWidthFinished = FALSE; @param Size Number of bytes to set @param Value Value of the set operation. - @return Value. - **/ VOID SetUnicodeMem ( @@ -155,87 +135,164 @@ UiInitMenu ( VOID ) { - InitializeListHead (&Menu); + InitializeListHead (&gMenuOption); } /** - Initialize Menu option list. + Free Menu option linked list. **/ VOID -UiInitMenuList ( +UiFreeMenu ( VOID ) { - InitializeListHead (&gMenuList); + UI_MENU_OPTION *MenuOption; + + while (!IsListEmpty (&gMenuOption)) { + MenuOption = MENU_OPTION_FROM_LINK (gMenuOption.ForwardLink); + RemoveEntryList (&MenuOption->Link); + + // + // We allocated space for this description when we did a GetToken, free it here + // + if (MenuOption->Skip != 0) { + // + // For date/time, MenuOption->Description is shared by three Menu Options + // Data format : [01/02/2004] [11:22:33] + // Line number : 0 0 1 0 0 1 + // + FreePool (MenuOption->Description); + } + FreePool (MenuOption); + } } /** - Remove a Menu in list, and return FormId/QuestionId for previous Menu. + Create a menu with specified formset GUID and form ID, and add it as a child + of the given parent menu. - @param Selection Menu selection. + @param Parent The parent of menu to be added. + @param HiiHandle Hii handle related to this formset. + @param FormSetGuid The Formset Guid of menu to be added. + @param FormId The Form ID of menu to be added. + + @return A pointer to the newly added menu or NULL if memory is insufficient. **/ -VOID -UiRemoveMenuListEntry ( - OUT UI_MENU_SELECTION *Selection +UI_MENU_LIST * +UiAddMenuList ( + IN OUT UI_MENU_LIST *Parent, + IN EFI_HII_HANDLE HiiHandle, + IN EFI_GUID *FormSetGuid, + IN UINT16 FormId ) { - UI_MENU_LIST *UiMenuList; + UI_MENU_LIST *MenuList; + + MenuList = AllocateZeroPool (sizeof (UI_MENU_LIST)); + if (MenuList == NULL) { + return NULL; + } - if (!IsListEmpty (&gMenuList)) { - UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE); + MenuList->Signature = UI_MENU_LIST_SIGNATURE; + InitializeListHead (&MenuList->ChildListHead); - Selection->FormId = UiMenuList->FormId; - Selection->QuestionId = UiMenuList->QuestionId; - RemoveEntryList (&UiMenuList->MenuLink); - FreePool (UiMenuList); + MenuList->HiiHandle = HiiHandle; + CopyMem (&MenuList->FormSetGuid, FormSetGuid, sizeof (EFI_GUID)); + MenuList->FormId = FormId; + MenuList->Parent = Parent; + + if (Parent == NULL) { + // + // If parent is not specified, it is the root Form of a Formset + // + InsertTailList (&gMenuList, &MenuList->Link); + } else { + InsertTailList (&Parent->ChildListHead, &MenuList->Link); } + + return MenuList; } /** - Free Menu option linked list. + Search Menu with given FormId and FormSetGuid in all cached menu list. + + @param Parent The parent of menu to search. + @param FormSetGuid The Formset GUID of the menu to search. + @param FormId The Form ID of menu to search. + + @return A pointer to menu found or NULL if not found. **/ -VOID -UiFreeMenuList ( - VOID +UI_MENU_LIST * +UiFindChildMenuList ( + IN UI_MENU_LIST *Parent, + IN EFI_GUID *FormSetGuid, + IN UINT16 FormId ) { - UI_MENU_LIST *UiMenuList; + LIST_ENTRY *Link; + UI_MENU_LIST *Child; + UI_MENU_LIST *MenuList; + + ASSERT (Parent != NULL); + + if (Parent->FormId == FormId && CompareGuid (FormSetGuid, &Parent->FormSetGuid)) { + return Parent; + } + + Link = GetFirstNode (&Parent->ChildListHead); + while (!IsNull (&Parent->ChildListHead, Link)) { + Child = UI_MENU_LIST_FROM_LINK (Link); + + MenuList = UiFindChildMenuList (Child, FormSetGuid, FormId); + if (MenuList != NULL) { + return MenuList; + } - while (!IsListEmpty (&gMenuList)) { - UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE); - RemoveEntryList (&UiMenuList->MenuLink); - FreePool (UiMenuList); + Link = GetNextNode (&Parent->ChildListHead, Link); } + + return NULL; } /** - Add one menu entry to the linked lst + Search Menu with given FormSetGuid and FormId in all cached menu list. - @param Selection Menu selection. + @param FormSetGuid The Formset GUID of the menu to search. + @param FormId The Form ID of menu to search. + + @return A pointer to menu found or NULL if not found. **/ -VOID -UiAddMenuListEntry ( - IN UI_MENU_SELECTION *Selection +UI_MENU_LIST * +UiFindMenuList ( + IN EFI_GUID *FormSetGuid, + IN UINT16 FormId ) { - UI_MENU_LIST *UiMenuList; + LIST_ENTRY *Link; + UI_MENU_LIST *MenuList; + UI_MENU_LIST *Child; - UiMenuList = AllocateZeroPool (sizeof (UI_MENU_LIST)); - ASSERT (UiMenuList != NULL); + Link = GetFirstNode (&gMenuList); + while (!IsNull (&gMenuList, Link)) { + MenuList = UI_MENU_LIST_FROM_LINK (Link); - UiMenuList->Signature = UI_MENU_LIST_SIGNATURE; - UiMenuList->FormId = Selection->FormId; - UiMenuList->QuestionId = Selection->QuestionId; + Child = UiFindChildMenuList(MenuList, FormSetGuid, FormId); + if (Child != NULL) { + return Child; + } + + Link = GetNextNode (&gMenuList, Link); + } - InsertHeadList (&gMenuList, &UiMenuList->MenuLink); + return NULL; } @@ -244,52 +301,217 @@ UiAddMenuListEntry ( **/ VOID -UiFreeMenu ( +UiFreeRefreshList ( VOID ) { - UI_MENU_OPTION *MenuOption; + MENU_REFRESH_ENTRY *OldMenuRefreshEntry; - while (!IsListEmpty (&Menu)) { - MenuOption = MENU_OPTION_FROM_LINK (Menu.ForwardLink); - RemoveEntryList (&MenuOption->Link); + while (gMenuRefreshHead != NULL) { + OldMenuRefreshEntry = gMenuRefreshHead->Next; + FreePool (gMenuRefreshHead); + gMenuRefreshHead = OldMenuRefreshEntry; + } + + while (gMenuEventGuidRefreshHead != NULL) { + OldMenuRefreshEntry = gMenuEventGuidRefreshHead->Next; + if (gMenuEventGuidRefreshHead != NULL) { + gBS->CloseEvent(gMenuEventGuidRefreshHead->Event); + } + FreePool (gMenuEventGuidRefreshHead); + gMenuEventGuidRefreshHead = OldMenuRefreshEntry; + } +} + + +/** + Process option string for date/time opcode. + @param MenuOption Menu option point to date/time. + @param OptionString Option string input for process. + @param AddOptCol Whether need to update MenuOption->OptCol. + +**/ +VOID +ProcessStringForDateTime ( + UI_MENU_OPTION *MenuOption, + CHAR16 *OptionString, + BOOLEAN AddOptCol + ) +{ + UINTN Index; + UINTN Count; + FORM_BROWSER_STATEMENT *Statement; + + ASSERT (MenuOption != NULL && OptionString != NULL); + + Statement = MenuOption->ThisTag; + + // + // If leading spaces on OptionString - remove the spaces + // + for (Index = 0; OptionString[Index] == L' '; Index++) { // - // We allocated space for this description when we did a GetToken, free it here + // Base on the blockspace to get the option column info. // - if (MenuOption->Skip != 0) { + if (AddOptCol) { + MenuOption->OptCol++; + } + } + + for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) { + OptionString[Count] = OptionString[Index]; + Count++; + } + OptionString[Count] = CHAR_NULL; + + // + // Enable to suppress field in the opcode base on the flag. + // + if (Statement->Operand == EFI_IFR_DATE_OP) { + // + // OptionString format is: <**: **: ****> + // |month|day|year| + // 4 3 5 + // + if ((Statement->Flags & EFI_QF_DATE_MONTH_SUPPRESS) && (MenuOption->Sequence == 0)) { // - // For date/time, MenuOption->Description is shared by three Menu Options - // Data format : [01/02/2004] [11:22:33] - // Line number : 0 0 1 0 0 1 + // At this point, only "<**:" in the optionstring. + // Clean the day's ** field, after clean, the format is "< :" // - FreePool (MenuOption->Description); + SetUnicodeMem (&OptionString[1], 2, L' '); + } else if ((Statement->Flags & EFI_QF_DATE_DAY_SUPPRESS) && (MenuOption->Sequence == 1)) { + // + // At this point, only "**:" in the optionstring. + // Clean the month's "**" field, after clean, the format is " :" + // + SetUnicodeMem (&OptionString[0], 2, L' '); + } else if ((Statement->Flags & EFI_QF_DATE_YEAR_SUPPRESS) && (MenuOption->Sequence == 2)) { + // + // At this point, only "****>" in the optionstring. + // Clean the year's "****" field, after clean, the format is " >" + // + SetUnicodeMem (&OptionString[0], 4, L' '); + } + } else if (Statement->Operand == EFI_IFR_TIME_OP) { + // + // OptionString format is: <**: **: **> + // |hour|minute|second| + // 4 3 3 + // + if ((Statement->Flags & QF_TIME_HOUR_SUPPRESS) && (MenuOption->Sequence == 0)) { + // + // At this point, only "<**:" in the optionstring. + // Clean the hour's ** field, after clean, the format is "< :" + // + SetUnicodeMem (&OptionString[1], 2, L' '); + } else if ((Statement->Flags & QF_TIME_MINUTE_SUPPRESS) && (MenuOption->Sequence == 1)) { + // + // At this point, only "**:" in the optionstring. + // Clean the minute's "**" field, after clean, the format is " :" + // + SetUnicodeMem (&OptionString[0], 2, L' '); + } else if ((Statement->Flags & QF_TIME_SECOND_SUPPRESS) && (MenuOption->Sequence == 2)) { + // + // At this point, only "**>" in the optionstring. + // Clean the second's "**" field, after clean, the format is " >" + // + SetUnicodeMem (&OptionString[0], 2, L' '); } - FreePool (MenuOption); } } - /** - Free Menu option linked list. + Refresh question. + @param MenuRefreshEntry Menu refresh structure which has info about the refresh question. **/ -VOID -UiFreeRefreshList ( - VOID +EFI_STATUS +RefreshQuestion ( + IN MENU_REFRESH_ENTRY *MenuRefreshEntry ) { - MENU_REFRESH_ENTRY *OldMenuRefreshEntry; + CHAR16 *OptionString; + EFI_STATUS Status; + UI_MENU_SELECTION *Selection; + FORM_BROWSER_STATEMENT *Question; - while (gMenuRefreshHead != NULL) { - OldMenuRefreshEntry = gMenuRefreshHead->Next; - FreePool (gMenuRefreshHead); - gMenuRefreshHead = OldMenuRefreshEntry; + Selection = MenuRefreshEntry->Selection; + Question = MenuRefreshEntry->MenuOption->ThisTag; + + Status = GetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE); + if (EFI_ERROR (Status)) { + return Status; + } + + OptionString = NULL; + ProcessOptions (Selection, MenuRefreshEntry->MenuOption, FALSE, &OptionString); + + if (OptionString != NULL) { + // + // If old Text is longer than new string, need to clean the old string before paint the newer. + // This option is no need for time/date opcode, because time/data opcode has fixed string length. + // + if ((MenuRefreshEntry->MenuOption->ThisTag->Operand != EFI_IFR_DATE_OP) && + (MenuRefreshEntry->MenuOption->ThisTag->Operand != EFI_IFR_TIME_OP)) { + ClearLines ( + MenuRefreshEntry->CurrentColumn, + MenuRefreshEntry->CurrentColumn + gOptionBlockWidth - 1, + MenuRefreshEntry->CurrentRow, + MenuRefreshEntry->CurrentRow, + PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND + ); + } + + gST->ConOut->SetAttribute (gST->ConOut, MenuRefreshEntry->CurrentAttribute); + ProcessStringForDateTime(MenuRefreshEntry->MenuOption, OptionString, FALSE); + PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, OptionString); + FreePool (OptionString); } - gMenuRefreshHead = NULL; + // + // Question value may be changed, need invoke its Callback() + // + Status = ProcessCallBackFunction (Selection, Question, EFI_BROWSER_ACTION_CHANGING, FALSE); + + return Status; } +/** + Refresh the question which has refresh guid event attribute. + + @param Event The event which has this function related. + @param Context The input context info related to this event or the status code return to the caller. +**/ +VOID +EFIAPI +RefreshQuestionNotify( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + MENU_REFRESH_ENTRY *MenuRefreshEntry; + UI_MENU_SELECTION *Selection; + + // + // Reset FormPackage update flag + // + mHiiPackageListUpdated = FALSE; + + MenuRefreshEntry = (MENU_REFRESH_ENTRY *)Context; + ASSERT (MenuRefreshEntry != NULL); + Selection = MenuRefreshEntry->Selection; + + RefreshQuestion (MenuRefreshEntry); + + if (mHiiPackageListUpdated) { + // + // Package list is updated, force to reparse IFR binary of target Formset + // + mHiiPackageListUpdated = FALSE; + Selection->Action = UI_ACTION_REFRESH_FORMSET; + } +} /** @@ -301,102 +523,27 @@ RefreshForm ( VOID ) { - CHAR16 *OptionString; MENU_REFRESH_ENTRY *MenuRefreshEntry; - UINTN Index; EFI_STATUS Status; UI_MENU_SELECTION *Selection; - FORM_BROWSER_STATEMENT *Question; - EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; - EFI_HII_VALUE *HiiValue; - EFI_BROWSER_ACTION_REQUEST ActionRequest; if (gMenuRefreshHead != NULL) { - + // + // call from refresh interval process. + // MenuRefreshEntry = gMenuRefreshHead; - + Selection = MenuRefreshEntry->Selection; // // Reset FormPackage update flag // mHiiPackageListUpdated = FALSE; do { - gST->ConOut->SetAttribute (gST->ConOut, MenuRefreshEntry->CurrentAttribute); - - Selection = MenuRefreshEntry->Selection; - Question = MenuRefreshEntry->MenuOption->ThisTag; - - Status = GetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE); + Status = RefreshQuestion (MenuRefreshEntry); if (EFI_ERROR (Status)) { return Status; } - OptionString = NULL; - ProcessOptions (Selection, MenuRefreshEntry->MenuOption, FALSE, &OptionString); - - if (OptionString != NULL) { - // - // If leading spaces on OptionString - remove the spaces - // - for (Index = 0; OptionString[Index] == L' '; Index++) - ; - - PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, &OptionString[Index]); - FreePool (OptionString); - } - - // - // Question value may be changed, need invoke its Callback() - // - ConfigAccess = Selection->FormSet->ConfigAccess; - if (((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) && (ConfigAccess != NULL)) { - ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; - - HiiValue = &Question->HiiValue; - if (HiiValue->Type == EFI_IFR_TYPE_STRING) { - // - // Create String in HII database for Configuration Driver to retrieve - // - HiiValue->Value.string = NewString ((CHAR16 *) Question->BufferValue, Selection->FormSet->HiiHandle); - } - - Status = ConfigAccess->Callback ( - ConfigAccess, - EFI_BROWSER_ACTION_CHANGING, - Question->QuestionId, - HiiValue->Type, - &HiiValue->Value, - &ActionRequest - ); - - if (HiiValue->Type == EFI_IFR_TYPE_STRING) { - // - // Clean the String in HII Database - // - DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle); - } - - if (!EFI_ERROR (Status)) { - switch (ActionRequest) { - case EFI_BROWSER_ACTION_REQUEST_RESET: - gResetRequired = TRUE; - break; - - case EFI_BROWSER_ACTION_REQUEST_SUBMIT: - SubmitForm (Selection->FormSet, Selection->Form); - break; - - case EFI_BROWSER_ACTION_REQUEST_EXIT: - Selection->Action = UI_ACTION_EXIT; - gNvUpdateRequired = FALSE; - break; - - default: - break; - } - } - } - MenuRefreshEntry = MenuRefreshEntry->Next; } while (MenuRefreshEntry != NULL); @@ -520,15 +667,19 @@ UiWaitForSingleEvent ( @param String String description for this option. @param Handle Hii handle for the package list. + @param Form The form this statement belong to. @param Statement Statement of this Menu Option. @param NumberOfLines Display lines for this Menu Option. @param MenuItemCount The index for this Option in the Menu. + @retval Pointer Pointer to the added Menu Option. + **/ -VOID +UI_MENU_OPTION * UiAddMenuOption ( IN CHAR16 *String, IN EFI_HII_HANDLE Handle, + IN FORM_BROWSER_FORM *Form, IN FORM_BROWSER_STATEMENT *Statement, IN UINT16 NumberOfLines, IN UINT16 MenuItemCount @@ -539,6 +690,7 @@ UiAddMenuOption ( UINTN Count; Count = 1; + MenuOption = NULL; if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) { // @@ -583,13 +735,51 @@ UiAddMenuOption ( MenuOption->GrayOut = Statement->GrayOutExpression->Result.Value.b; } + // + // If the form or the question has the lock attribute, deal same as grayout. + // + if (Form->Locked || Statement->Locked) { + MenuOption->GrayOut = TRUE; + } + + switch (Statement->Operand) { + case EFI_IFR_ORDERED_LIST_OP: + case EFI_IFR_ONE_OF_OP: + case EFI_IFR_NUMERIC_OP: + case EFI_IFR_TIME_OP: + case EFI_IFR_DATE_OP: + case EFI_IFR_CHECKBOX_OP: + case EFI_IFR_PASSWORD_OP: + case EFI_IFR_STRING_OP: + // + // User could change the value of these items + // + MenuOption->IsQuestion = TRUE; + break; + + case EFI_IFR_TEXT_OP: + if (FeaturePcdGet (PcdBrowserGrayOutTextStatement)) { + // + // Initializing GrayOut option as TRUE for Text setup options + // so that those options will be Gray in colour and un selectable. + // + MenuOption->GrayOut = TRUE; + } + + default: + MenuOption->IsQuestion = FALSE; + break; + } + if ((Statement->ValueExpression != NULL) || ((Statement->QuestionFlags & EFI_IFR_FLAG_READ_ONLY) != 0)) { MenuOption->ReadOnly = TRUE; } - InsertTailList (&Menu, &MenuOption->Link); + InsertTailList (&gMenuOption, &MenuOption->Link); } + + return MenuOption; } @@ -620,6 +810,7 @@ UiAddMenuOption ( **/ EFI_STATUS +EFIAPI CreateDialog ( IN UINTN NumberOfLines, IN BOOLEAN HotKey, @@ -630,7 +821,6 @@ CreateDialog ( ) { VA_LIST Marker; - VA_LIST MarkerBackup; UINTN Count; EFI_INPUT_KEY Key; UINTN LargestString; @@ -661,7 +851,6 @@ CreateDialog ( ASSERT (BufferedString); VA_START (Marker, KeyValue); - MarkerBackup = Marker; // // Zero the outgoing buffer @@ -702,6 +891,7 @@ CreateDialog ( LargestString = (GetStringWidth (StackString) / 2); } } + VA_END (Marker); Start = (DimensionsWidth - LargestString - 2) / 2 + gScreenDimensions.LeftColumn + 1; Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + gScreenDimensions.TopRow - 1; @@ -711,7 +901,9 @@ CreateDialog ( // // Display the Popup // - CreateSharedPopUp (LargestString, NumberOfLines, MarkerBackup); + VA_START (Marker, KeyValue); + CreateSharedPopUp (LargestString, NumberOfLines, Marker); + VA_END (Marker); // // Take the first key typed and report it back? @@ -919,7 +1111,8 @@ CreateSharedPopUp ( **/ VOID -CreatePopUp ( +EFIAPI +CreateMultiStringPopUp ( IN UINTN RequestedWidth, IN UINTN NumberOfLines, ... @@ -928,7 +1121,7 @@ CreatePopUp ( VA_LIST Marker; VA_START (Marker, NumberOfLines); - + CreateSharedPopUp (RequestedWidth, NumberOfLines, Marker); VA_END (Marker); @@ -938,6 +1131,7 @@ CreatePopUp ( /** Update status bar on the bottom of menu. + @param Selection Current Selction info. @param MessageType The type of message to be shown. @param Flags The flags in Question header. @param State Set or clear. @@ -945,6 +1139,7 @@ CreatePopUp ( **/ VOID UpdateStatusBar ( + IN UI_MENU_SELECTION *Selection, IN UINTN MessageType, IN UINT8 Flags, IN BOOLEAN State @@ -953,7 +1148,10 @@ UpdateStatusBar ( UINTN Index; CHAR16 *NvUpdateMessage; CHAR16 *InputErrorMessage; - + LIST_ENTRY *Link; + FORM_BROWSER_FORMSET *LocalFormSet; + FORM_BROWSER_STATEMENT *Question; + NvUpdateMessage = GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE), gHiiHandle); InputErrorMessage = GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE), gHiiHandle); @@ -968,7 +1166,7 @@ UpdateStatusBar ( ); mInputError = TRUE; } else { - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextHighlightColor)); for (Index = 0; Index < (GetStringWidth (InputErrorMessage) - 2) / 2; Index++) { PrintAt (gScreenDimensions.LeftColumn + gPromptBlockWidth + Index, gScreenDimensions.BottomRow - 1, L" "); } @@ -978,40 +1176,69 @@ UpdateStatusBar ( break; case NV_UPDATE_REQUIRED: - if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) { - if (State) { + // + // Global setting support. Show configuration change on every form. + // + if (State) { + gResetRequired = (BOOLEAN) (gResetRequired | ((Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED)); + + if (Selection != NULL && Selection->Statement != NULL) { + Question = Selection->Statement; + if (Question->Storage != NULL || Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) { + // + // Update only for Question value that need to be saved into Storage. + // + Selection->Form->NvUpdateRequired = TRUE; + } + } + + if (Selection == NULL || IsNvUpdateRequired (Selection->FormSet)) { gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT); PrintStringAt ( gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth, gScreenDimensions.BottomRow - 1, NvUpdateMessage ); - gResetRequired = (BOOLEAN) (gResetRequired | ((Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED)); - - gNvUpdateRequired = TRUE; - } else { - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT); - for (Index = 0; Index < (GetStringWidth (NvUpdateMessage) - 2) / 2; Index++) { - PrintAt ( - (gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + Index), - gScreenDimensions.BottomRow - 1, - L" " - ); - } - - gNvUpdateRequired = FALSE; + } + } else { + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextHighlightColor)); + for (Index = 0; Index < (GetStringWidth (NvUpdateMessage) - 2) / 2; Index++) { + PrintAt ( + (gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + Index), + gScreenDimensions.BottomRow - 1, + L" " + ); } } break; case REFRESH_STATUS_BAR: if (mInputError) { - UpdateStatusBar (INPUT_ERROR, Flags, TRUE); + UpdateStatusBar (Selection, INPUT_ERROR, Flags, TRUE); } - if (gNvUpdateRequired) { - UpdateStatusBar (NV_UPDATE_REQUIRED, Flags, TRUE); + switch (gBrowserSettingScope) { + case SystemLevel: + // + // Check the maintain list to see whether there is any change. + // + Link = GetFirstNode (&gBrowserFormSetList); + while (!IsNull (&gBrowserFormSetList, Link)) { + LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link); + if (IsNvUpdateRequired(LocalFormSet)) { + UpdateStatusBar (NULL, NV_UPDATE_REQUIRED, Flags, TRUE); + break; + } + Link = GetNextNode (&gBrowserFormSetList, Link); + } + break; + case FormSetLevel: + case FormLevel: + UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Flags, TRUE); + default: + break; } + break; default: @@ -1073,7 +1300,7 @@ GetWidth ( Width -= SUBTITLE_INDENT; } - return Width; + return (UINT16) (Width - LEFT_SKIPPED_COLUMNS); } /** @@ -1182,16 +1409,12 @@ GetLineByWidth ( @param Selection The user's selection. @param MenuOption The MenuOption to be checked. - @param OptionalString The option string. - @param SkipValue The number of lins to skip. **/ VOID UpdateOptionSkipLines ( IN UI_MENU_SELECTION *Selection, - IN UI_MENU_OPTION *MenuOption, - OUT CHAR16 **OptionalString, - IN UINTN SkipValue + IN UI_MENU_OPTION *MenuOption ) { UINTN Index; @@ -1202,9 +1425,7 @@ UpdateOptionSkipLines ( CHAR16 *OptionString; Row = 0; - OptionString = *OptionalString; - OutputString = NULL; - + OptionString = NULL; ProcessOptions (Selection, MenuOption, FALSE, &OptionString); if (OptionString != NULL) { @@ -1216,32 +1437,29 @@ UpdateOptionSkipLines ( // // If there is more string to process print on the next row and increment the Skip value // - if (StrLen (&OptionString[Index])) { - if (SkipValue == 0) { - Row++; - // - // Since the Number of lines for this menu entry may or may not be reflected accurately - // since the prompt might be 1 lines and option might be many, and vice versa, we need to do - // some testing to ensure we are keeping this in-sync. - // - // If the difference in rows is greater than or equal to the skip value, increase the skip value - // - if ((Row - OriginalRow) >= MenuOption->Skip) { - MenuOption->Skip++; - } + if (StrLen (&OptionString[Index]) != 0) { + Row++; + // + // Since the Number of lines for this menu entry may or may not be reflected accurately + // since the prompt might be 1 lines and option might be many, and vice versa, we need to do + // some testing to ensure we are keeping this in-sync. + // + // If the difference in rows is greater than or equal to the skip value, increase the skip value + // + if ((Row - OriginalRow) >= MenuOption->Skip) { + MenuOption->Skip++; } } FreePool (OutputString); - if (SkipValue != 0) { - SkipValue--; - } } Row = OriginalRow; } - *OptionalString = OptionString; + if (OptionString != NULL) { + FreePool (OptionString); + } } @@ -1274,7 +1492,7 @@ IsSelectable ( Determine if the menu is the last menu that can be selected. This is an internal function. - + @param Direction The scroll direction. False is down. True is up. @param CurrentPos The current focus. @@ -1289,84 +1507,86 @@ ValueIsScroll ( ) { LIST_ENTRY *Temp; - UI_MENU_OPTION *MenuOption; Temp = Direction ? CurrentPos->BackLink : CurrentPos->ForwardLink; - if (Temp == &Menu) { + if (Temp == &gMenuOption) { return TRUE; } - for (; Temp != &Menu; Temp = Direction ? Temp->BackLink : Temp->ForwardLink) { - MenuOption = MENU_OPTION_FROM_LINK (Temp); - if (IsSelectable (MenuOption)) { - return FALSE; - } - } - - return TRUE; + return FALSE; } /** Move to next selectable statement. - + This is an internal function. - + + @param Selection Menu selection. @param GoUp The navigation direction. TRUE: up, FALSE: down. @param CurrentPosition Current position. + @param GapToTop Gap position to top or bottom. @return The row distance from current MenuOption to next selectable MenuOption. **/ INTN MoveToNextStatement ( + IN UI_MENU_SELECTION *Selection, IN BOOLEAN GoUp, - IN OUT LIST_ENTRY **CurrentPosition + IN OUT LIST_ENTRY **CurrentPosition, + IN UINTN GapToTop ) { INTN Distance; LIST_ENTRY *Pos; - BOOLEAN HitEnd; UI_MENU_OPTION *NextMenuOption; + UI_MENU_OPTION *PreMenuOption; - Distance = 0; - Pos = *CurrentPosition; - HitEnd = FALSE; + Distance = 0; + Pos = *CurrentPosition; + PreMenuOption = MENU_OPTION_FROM_LINK (Pos); while (TRUE) { NextMenuOption = MENU_OPTION_FROM_LINK (Pos); + if (NextMenuOption->Row == 0) { + UpdateOptionSkipLines (Selection, NextMenuOption); + } + + if (GoUp && (PreMenuOption != NextMenuOption)) { + // + // Current Position doesn't need to be caculated when go up. + // Caculate distanct at first when go up + // + if ((UINTN) Distance + NextMenuOption->Skip > GapToTop) { + NextMenuOption = PreMenuOption; + break; + } + Distance += NextMenuOption->Skip; + } if (IsSelectable (NextMenuOption)) { break; } - if ((GoUp ? Pos->BackLink : Pos->ForwardLink) == &Menu) { - HitEnd = TRUE; + if ((GoUp ? Pos->BackLink : Pos->ForwardLink) == &gMenuOption) { + // + // Arrive at top. + // + Distance = -1; break; } - Distance += NextMenuOption->Skip; - Pos = (GoUp ? Pos->BackLink : Pos->ForwardLink); - } - - if (HitEnd) { - // - // If we hit end there is still no statement can be focused, - // we go backwards to find the statement can be focused. - // - Distance = 0; - Pos = *CurrentPosition; - - while (TRUE) { - NextMenuOption = MENU_OPTION_FROM_LINK (Pos); - if (IsSelectable (NextMenuOption)) { - break; - } - if ((!GoUp ? Pos->BackLink : Pos->ForwardLink) == &Menu) { - ASSERT (FALSE); + if (!GoUp) { + // + // Caculate distanct at later when go down + // + if ((UINTN) Distance + NextMenuOption->Skip > GapToTop) { + NextMenuOption = PreMenuOption; break; } - Distance -= NextMenuOption->Skip; - Pos = (!GoUp ? Pos->BackLink : Pos->ForwardLink); + Distance += NextMenuOption->Skip; } + PreMenuOption = NextMenuOption; + Pos = (GoUp ? Pos->BackLink : Pos->ForwardLink); } *CurrentPosition = &NextMenuOption->Link; @@ -1378,7 +1598,7 @@ MoveToNextStatement ( Adjust Data and Time position accordingly. Data format : [01/02/2004] [11:22:33] Line number : 0 0 1 0 0 1 - + This is an internal function. @param DirectionUp the up or down direction. False is down. True is @@ -1448,6 +1668,399 @@ AdjustDateAndTimePosition ( return PadLineNumber; } +/** + Find HII Handle in the HII database associated with given Device Path. + + If DevicePath is NULL, then ASSERT. + + @param DevicePath Device Path associated with the HII package list + handle. + + @retval Handle HII package list Handle associated with the Device + Path. + @retval NULL Hii Package list handle is not found. + +**/ +EFI_HII_HANDLE +EFIAPI +DevicePathToHiiHandle ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + UINTN BufferSize; + UINTN HandleCount; + UINTN Index; + EFI_HANDLE Handle; + EFI_HANDLE DriverHandle; + EFI_HII_HANDLE *HiiHandles; + EFI_HII_HANDLE HiiHandle; + + ASSERT (DevicePath != NULL); + + TmpDevicePath = DevicePath; + // + // Locate Device Path Protocol handle buffer + // + Status = gBS->LocateDevicePath ( + &gEfiDevicePathProtocolGuid, + &TmpDevicePath, + &DriverHandle + ); + if (EFI_ERROR (Status) || !IsDevicePathEnd (TmpDevicePath)) { + return NULL; + } + + // + // Retrieve all HII Handles from HII database + // + BufferSize = 0x1000; + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + Status = mHiiDatabase->ListPackageLists ( + mHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (HiiHandles); + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + + Status = mHiiDatabase->ListPackageLists ( + mHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + } + + if (EFI_ERROR (Status)) { + FreePool (HiiHandles); + return NULL; + } + + // + // Search Hii Handle by Driver Handle + // + HiiHandle = NULL; + HandleCount = BufferSize / sizeof (EFI_HII_HANDLE); + for (Index = 0; Index < HandleCount; Index++) { + Status = mHiiDatabase->GetPackageListHandle ( + mHiiDatabase, + HiiHandles[Index], + &Handle + ); + if (!EFI_ERROR (Status) && (Handle == DriverHandle)) { + HiiHandle = HiiHandles[Index]; + break; + } + } + + FreePool (HiiHandles); + return HiiHandle; +} + +/** + Find HII Handle in the HII database associated with given form set guid. + + If FormSetGuid is NULL, then ASSERT. + + @param ComparingGuid FormSet Guid associated with the HII package list + handle. + + @retval Handle HII package list Handle associated with the Device + Path. + @retval NULL Hii Package list handle is not found. + +**/ +EFI_HII_HANDLE +FormSetGuidToHiiHandle ( + EFI_GUID *ComparingGuid + ) +{ + EFI_HII_HANDLE *HiiHandles; + UINTN Index; + EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; + UINTN BufferSize; + UINT32 Offset; + UINT32 Offset2; + UINT32 PackageListLength; + EFI_HII_PACKAGE_HEADER PackageHeader; + UINT8 *Package; + UINT8 *OpCodeData; + EFI_STATUS Status; + EFI_HII_HANDLE HiiHandle; + + ASSERT (ComparingGuid != NULL); + + HiiHandle = NULL; + // + // Get all the Hii handles + // + HiiHandles = HiiGetHiiHandles (NULL); + ASSERT (HiiHandles != NULL); + + // + // Search for formset of each class type + // + for (Index = 0; HiiHandles[Index] != NULL; Index++) { + BufferSize = 0; + HiiPackageList = NULL; + Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, HiiHandles[Index], &BufferSize, HiiPackageList); + if (Status == EFI_BUFFER_TOO_SMALL) { + HiiPackageList = AllocatePool (BufferSize); + ASSERT (HiiPackageList != NULL); + + Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, HiiHandles[Index], &BufferSize, HiiPackageList); + } + if (EFI_ERROR (Status) || HiiPackageList == NULL) { + return NULL; + } + + // + // Get Form package from this HII package List + // + Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); + Offset2 = 0; + CopyMem (&PackageListLength, &HiiPackageList->PackageLength, sizeof (UINT32)); + + while (Offset < PackageListLength) { + Package = ((UINT8 *) HiiPackageList) + Offset; + CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER)); + + if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) { + // + // Search FormSet in this Form Package + // + Offset2 = sizeof (EFI_HII_PACKAGE_HEADER); + while (Offset2 < PackageHeader.Length) { + OpCodeData = Package + Offset2; + + if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) { + // + // Try to compare against formset GUID + // + if (CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) { + HiiHandle = HiiHandles[Index]; + break; + } + } + + Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length; + } + } + if (HiiHandle != NULL) { + break; + } + Offset += PackageHeader.Length; + } + + FreePool (HiiPackageList); + if (HiiHandle != NULL) { + break; + } + } + + FreePool (HiiHandles); + + return HiiHandle; +} + +/** + Process the goto op code, update the info in the selection structure. + + @param Statement The statement belong to goto op code. + @param Selection The selection info. + @param Repaint Whether need to repaint the menu. + @param NewLine Whether need to create new line. + + @retval EFI_SUCCESS The menu process successfully. + @return Other value if the process failed. +**/ +EFI_STATUS +ProcessGotoOpCode ( + IN OUT FORM_BROWSER_STATEMENT *Statement, + IN OUT UI_MENU_SELECTION *Selection, + OUT BOOLEAN *Repaint, + OUT BOOLEAN *NewLine + ) +{ + CHAR16 *StringPtr; + UINTN StringLen; + UINTN BufferSize; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + CHAR16 TemStr[2]; + UINT8 *DevicePathBuffer; + UINTN Index; + UINT8 DigitUint8; + FORM_BROWSER_FORM *RefForm; + EFI_INPUT_KEY Key; + EFI_STATUS Status; + UI_MENU_LIST *MenuList; + BOOLEAN UpdateFormInfo; + + Status = EFI_SUCCESS; + UpdateFormInfo = TRUE; + StringPtr = NULL; + StringLen = 0; + + // + // Prepare the device path check, get the device path info first. + // + if (Statement->HiiValue.Value.ref.DevicePath != 0) { + StringPtr = GetToken (Statement->HiiValue.Value.ref.DevicePath, Selection->FormSet->HiiHandle); + if (StringPtr != NULL) { + StringLen = StrLen (StringPtr); + } + } + + // + // Check whether the device path string is a valid string. + // + if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL && StringLen != 0) { + if (Selection->Form->ModalForm) { + return Status; + } + // + // Goto another Hii Package list + // + Selection->Action = UI_ACTION_REFRESH_FORMSET; + BufferSize = StrLen (StringPtr) / 2; + DevicePath = AllocatePool (BufferSize); + ASSERT (DevicePath != NULL); + + // + // Convert from Device Path String to DevicePath Buffer in the reverse order. + // + DevicePathBuffer = (UINT8 *) DevicePath; + for (Index = 0; StringPtr[Index] != L'\0'; Index ++) { + TemStr[0] = StringPtr[Index]; + DigitUint8 = (UINT8) StrHexToUint64 (TemStr); + if (DigitUint8 == 0 && TemStr[0] != L'0') { + // + // Invalid Hex Char as the tail. + // + break; + } + if ((Index & 1) == 0) { + DevicePathBuffer [Index/2] = DigitUint8; + } else { + DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8); + } + } + FreePool (StringPtr); + + Selection->Handle = DevicePathToHiiHandle (DevicePath); + FreePool (DevicePath); + + if (Selection->Handle == NULL) { + // + // If target Hii Handle not found, exit + // + Selection->Action = UI_ACTION_EXIT; + Selection->Statement = NULL; + return Status; + } + + CopyMem (&Selection->FormSetGuid,&Statement->HiiValue.Value.ref.FormSetGuid, sizeof (EFI_GUID)); + Selection->FormId = Statement->HiiValue.Value.ref.FormId; + Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId; + } else if (!CompareGuid (&Statement->HiiValue.Value.ref.FormSetGuid, &gZeroGuid)) { + if (Selection->Form->ModalForm) { + return Status; + } + // + // Goto another Formset, check for uncommitted data + // + Selection->Action = UI_ACTION_REFRESH_FORMSET; + + Selection->Handle = FormSetGuidToHiiHandle(&Statement->HiiValue.Value.ref.FormSetGuid); + if (Selection->Handle == NULL) { + // + // If target Hii Handle not found, exit + // + Selection->Action = UI_ACTION_EXIT; + Selection->Statement = NULL; + return Status; + } + + CopyMem (&Selection->FormSetGuid, &Statement->HiiValue.Value.ref.FormSetGuid, sizeof (EFI_GUID)); + Selection->FormId = Statement->HiiValue.Value.ref.FormId; + Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId; + } else if (Statement->HiiValue.Value.ref.FormId != 0) { + // + // Check whether target From is suppressed. + // + RefForm = IdToForm (Selection->FormSet, Statement->HiiValue.Value.ref.FormId); + + if ((RefForm != NULL) && (RefForm->SuppressExpression != NULL)) { + Status = EvaluateExpression (Selection->FormSet, RefForm, RefForm->SuppressExpression); + if (EFI_ERROR (Status)) { + return Status; + } + + if (RefForm->SuppressExpression->Result.Value.b) { + // + // Form is suppressed. + // + do { + CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + if (Repaint != NULL) { + *Repaint = TRUE; + } + return Status; + } + } + + // + // Goto another form inside this formset, + // + Selection->Action = UI_ACTION_REFRESH_FORM; + + Selection->FormId = Statement->HiiValue.Value.ref.FormId; + Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId; + } else if (Statement->HiiValue.Value.ref.QuestionId != 0) { + // + // Goto another Question + // + Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId; + + if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) { + Selection->Action = UI_ACTION_REFRESH_FORM; + } else { + if (Repaint != NULL) { + *Repaint = TRUE; + } + if (NewLine != NULL) { + *NewLine = TRUE; + } + } + UpdateFormInfo = FALSE; + } else { + if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) { + Selection->Action = UI_ACTION_REFRESH_FORM; + } + UpdateFormInfo = FALSE; + } + + if (UpdateFormInfo) { + // + // Link current form so that we can always go back when someone hits the ESC + // + MenuList = UiFindMenuList (&Selection->FormSetGuid, Selection->FormId); + if (MenuList == NULL && Selection->CurrentMenu != NULL) { + MenuList = UiAddMenuList (Selection->CurrentMenu, Selection->Handle, &Selection->FormSetGuid, Selection->FormId); + } + } + + return Status; +} /** Display menu and wait for user to select one menu option, then return it. @@ -1476,17 +2089,17 @@ UiDisplayMenu ( UINTN BottomRow; UINTN OriginalRow; UINTN Index; - UINT32 Count; UINT16 Width; CHAR16 *StringPtr; CHAR16 *OptionString; CHAR16 *OutputString; CHAR16 *FormattedString; - CHAR16 YesResponse; - CHAR16 NoResponse; BOOLEAN NewLine; BOOLEAN Repaint; BOOLEAN SavedValue; + BOOLEAN UpArrow; + BOOLEAN DownArrow; + BOOLEAN InitializedFlag; EFI_STATUS Status; EFI_INPUT_KEY Key; LIST_ENTRY *Link; @@ -1500,12 +2113,14 @@ UiDisplayMenu ( UI_CONTROL_FLAG ControlFlag; EFI_SCREEN_DESCRIPTOR LocalScreen; MENU_REFRESH_ENTRY *MenuRefreshEntry; + MENU_REFRESH_ENTRY *MenuUpdateEntry; UI_SCREEN_OPERATION ScreenOperation; UINT8 MinRefreshInterval; - UINTN BufferSize; UINT16 DefaultId; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; FORM_BROWSER_STATEMENT *Statement; + UI_MENU_LIST *CurrentMenu; + UINTN ModalSkipColumn; + BROWSER_HOT_KEY *HotKey; CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR)); @@ -1518,8 +2133,8 @@ UiDisplayMenu ( DefaultId = 0; OutputString = NULL; - gUpArrow = FALSE; - gDownArrow = FALSE; + UpArrow = FALSE; + DownArrow = FALSE; SkipValue = 0; OldSkipValue = 0; MenuRefreshEntry = gMenuRefreshHead; @@ -1527,10 +2142,12 @@ UiDisplayMenu ( NextMenuOption = NULL; PreviousMenuOption = NULL; SavedMenuOption = NULL; + HotKey = NULL; + ModalSkipColumn = (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 6; ZeroMem (&Key, sizeof (EFI_INPUT_KEY)); - if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) { + if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE){ TopRow = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT; Row = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT; } else { @@ -1538,8 +2155,13 @@ UiDisplayMenu ( Row = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT; } - Col = LocalScreen.LeftColumn; - BottomRow = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT - SCROLL_ARROW_HEIGHT - 1; + if (Selection->Form->ModalForm) { + Col = LocalScreen.LeftColumn + LEFT_SKIPPED_COLUMNS + ModalSkipColumn; + } else { + Col = LocalScreen.LeftColumn + LEFT_SKIPPED_COLUMNS; + } + + BottomRow = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight - SCROLL_ARROW_HEIGHT - 1; Selection->TopRow = TopRow; Selection->BottomRow = BottomRow; @@ -1547,24 +2169,46 @@ UiDisplayMenu ( Selection->OptionCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn; Selection->Statement = NULL; - TopOfScreen = Menu.ForwardLink; + TopOfScreen = gMenuOption.ForwardLink; Repaint = TRUE; MenuOption = NULL; // - // Get user's selection + // Find current Menu + // + CurrentMenu = UiFindMenuList (&Selection->FormSetGuid, Selection->FormId); + if (CurrentMenu == NULL) { + // + // Current menu not found, add it to the menu tree + // + CurrentMenu = UiAddMenuList (NULL, Selection->Handle, &Selection->FormSetGuid, Selection->FormId); + } + ASSERT (CurrentMenu != NULL); + Selection->CurrentMenu = CurrentMenu; + + if (Selection->QuestionId == 0) { + // + // Highlight not specified, fetch it from cached menu + // + Selection->QuestionId = CurrentMenu->QuestionId; + Selection->Sequence = CurrentMenu->Sequence; + } + + // + // Init option as the current user's selection // - NewPos = Menu.ForwardLink; + InitializedFlag = TRUE; + NewPos = gMenuOption.ForwardLink; gST->ConOut->EnableCursor (gST->ConOut, FALSE); - UpdateStatusBar (REFRESH_STATUS_BAR, (UINT8) 0, TRUE); + UpdateStatusBar (Selection, REFRESH_STATUS_BAR, (UINT8) 0, TRUE); ControlFlag = CfInitialization; Selection->Action = UI_ACTION_NONE; while (TRUE) { switch (ControlFlag) { case CfInitialization: - if (IsListEmpty (&Menu)) { + if (IsListEmpty (&gMenuOption)) { ControlFlag = CfReadKey; } else { ControlFlag = CfCheckSelection; @@ -1586,29 +2230,42 @@ UiDisplayMenu ( // // Display menu // - gDownArrow = FALSE; - gUpArrow = FALSE; + DownArrow = FALSE; + UpArrow = FALSE; Row = TopRow; - Temp = SkipValue; - Temp2 = SkipValue; - - ClearLines ( - LocalScreen.LeftColumn, - LocalScreen.RightColumn, - TopRow - SCROLL_ARROW_HEIGHT, - BottomRow + SCROLL_ARROW_HEIGHT, - FIELD_TEXT | FIELD_BACKGROUND - ); + Temp = (UINTN) SkipValue; + Temp2 = (UINTN) SkipValue; + if (Selection->Form->ModalForm) { + ClearLines ( + LocalScreen.LeftColumn + ModalSkipColumn, + LocalScreen.LeftColumn + ModalSkipColumn + gPromptBlockWidth + gOptionBlockWidth, + TopRow - SCROLL_ARROW_HEIGHT, + BottomRow + SCROLL_ARROW_HEIGHT, + PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND + ); + } else { + ClearLines ( + LocalScreen.LeftColumn, + LocalScreen.RightColumn, + TopRow - SCROLL_ARROW_HEIGHT, + BottomRow + SCROLL_ARROW_HEIGHT, + PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND + ); + } UiFreeRefreshList (); MinRefreshInterval = 0; - for (Link = TopOfScreen; Link != &Menu; Link = Link->ForwardLink) { + for (Link = TopOfScreen; Link != &gMenuOption; Link = Link->ForwardLink) { MenuOption = MENU_OPTION_FROM_LINK (Link); MenuOption->Row = Row; MenuOption->Col = Col; - MenuOption->OptCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn; + if (Selection->Form->ModalForm) { + MenuOption->OptCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn + ModalSkipColumn; + } else { + MenuOption->OptCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn; + } Statement = MenuOption->ThisTag; if (Statement->InSubtitle) { @@ -1619,13 +2276,25 @@ UiDisplayMenu ( gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND); } else { if (Statement->Operand == EFI_IFR_SUBTITLE_OP) { - gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserSubtitleTextColor) | FIELD_BACKGROUND); } } Width = GetWidth (Statement, MenuOption->Handle); OriginalRow = Row; + if (Statement->Operand == EFI_IFR_REF_OP && MenuOption->Col >= 2) { + // + // Print Arrow for Goto button. + // + PrintAt ( + MenuOption->Col - 2, + Row, + L"%c", + GEOMETRICSHAPE_RIGHT_TRIANGLE + ); + } + for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) { if ((Temp == 0) && (Row <= BottomRow)) { PrintStringAt (MenuOption->Col, Row, OutputString); @@ -1633,7 +2302,7 @@ UiDisplayMenu ( // // If there is more string to process print on the next row and increment the Skip value // - if (StrLen (&MenuOption->Description[Index])) { + if (StrLen (&MenuOption->Description[Index]) != 0) { if (Temp == 0) { Row++; } @@ -1648,7 +2317,6 @@ UiDisplayMenu ( Temp = 0; Row = OriginalRow; - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND); Status = ProcessOptions (Selection, MenuOption, FALSE, &OptionString); if (EFI_ERROR (Status)) { // @@ -1662,60 +2330,7 @@ UiDisplayMenu ( if (OptionString != NULL) { if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) { - // - // If leading spaces on OptionString - remove the spaces - // - for (Index = 0; OptionString[Index] == L' '; Index++) { - MenuOption->OptCol++; - } - - for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) { - OptionString[Count] = OptionString[Index]; - Count++; - } - - OptionString[Count] = CHAR_NULL; - } - - // - // If Question request refresh, register the op-code - // - if (Statement->RefreshInterval != 0) { - // - // Menu will be refreshed at minimal interval of all Questions - // which have refresh request - // - if (MinRefreshInterval == 0 || Statement->RefreshInterval < MinRefreshInterval) { - MinRefreshInterval = Statement->RefreshInterval; - } - - if (gMenuRefreshHead == NULL) { - MenuRefreshEntry = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY)); - ASSERT (MenuRefreshEntry != NULL); - MenuRefreshEntry->MenuOption = MenuOption; - MenuRefreshEntry->Selection = Selection; - MenuRefreshEntry->CurrentColumn = MenuOption->OptCol; - MenuRefreshEntry->CurrentRow = MenuOption->Row; - MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND; - gMenuRefreshHead = MenuRefreshEntry; - } else { - // - // Advance to the last entry - // - for (MenuRefreshEntry = gMenuRefreshHead; - MenuRefreshEntry->Next != NULL; - MenuRefreshEntry = MenuRefreshEntry->Next - ) - ; - MenuRefreshEntry->Next = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY)); - ASSERT (MenuRefreshEntry->Next != NULL); - MenuRefreshEntry = MenuRefreshEntry->Next; - MenuRefreshEntry->MenuOption = MenuOption; - MenuRefreshEntry->Selection = Selection; - MenuRefreshEntry->CurrentColumn = MenuOption->OptCol; - MenuRefreshEntry->CurrentRow = MenuOption->Row; - MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND; - } + ProcessStringForDateTime(MenuOption, OptionString, TRUE); } Width = (UINT16) gOptionBlockWidth; @@ -1728,7 +2343,7 @@ UiDisplayMenu ( // // If there is more string to process print on the next row and increment the Skip value // - if (StrLen (&OptionString[Index])) { + if (StrLen (&OptionString[Index]) != 0) { if (Temp2 == 0) { Row++; // @@ -1755,26 +2370,91 @@ UiDisplayMenu ( FreePool (OptionString); } + // - // If this is a text op with secondary text information + // If Question has refresh guid, register the op-code. // - if ((Statement->Operand == EFI_IFR_TEXT_OP) && (Statement->TextTwo != 0)) { - StringPtr = GetToken (Statement->TextTwo, MenuOption->Handle); - - Width = (UINT16) gOptionBlockWidth; - OriginalRow = Row; - - for (Index = 0; GetLineByWidth (StringPtr, Width, &Index, &OutputString) != 0x0000;) { - if ((Temp == 0) && (Row <= BottomRow)) { - PrintStringAt (MenuOption->OptCol, Row, OutputString); + if (!CompareGuid (&Statement->RefreshGuid, &gZeroGuid)) { + if (gMenuEventGuidRefreshHead == NULL) { + MenuUpdateEntry = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY)); + gMenuEventGuidRefreshHead = MenuUpdateEntry; + } else { + MenuUpdateEntry = gMenuEventGuidRefreshHead; + while (MenuUpdateEntry->Next != NULL) { + MenuUpdateEntry = MenuUpdateEntry->Next; } - // - // If there is more string to process print on the next row and increment the Skip value - // - if (StrLen (&StringPtr[Index])) { - if (Temp2 == 0) { - Row++; - // + MenuUpdateEntry->Next = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY)); + MenuUpdateEntry = MenuUpdateEntry->Next; + } + ASSERT (MenuUpdateEntry != NULL); + Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, RefreshQuestionNotify, MenuUpdateEntry, &Statement->RefreshGuid, &MenuUpdateEntry->Event); + ASSERT (!EFI_ERROR (Status)); + MenuUpdateEntry->MenuOption = MenuOption; + MenuUpdateEntry->Selection = Selection; + MenuUpdateEntry->CurrentColumn = MenuOption->OptCol; + MenuUpdateEntry->CurrentRow = MenuOption->Row; + if (MenuOption->GrayOut) { + MenuUpdateEntry->CurrentAttribute = FIELD_TEXT_GRAYED | FIELD_BACKGROUND; + } else { + MenuUpdateEntry->CurrentAttribute = PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND; + } + } + + // + // If Question request refresh, register the op-code + // + if (Statement->RefreshInterval != 0) { + // + // Menu will be refreshed at minimal interval of all Questions + // which have refresh request + // + if (MinRefreshInterval == 0 || Statement->RefreshInterval < MinRefreshInterval) { + MinRefreshInterval = Statement->RefreshInterval; + } + + if (gMenuRefreshHead == NULL) { + MenuRefreshEntry = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY)); + gMenuRefreshHead = MenuRefreshEntry; + } else { + MenuRefreshEntry = gMenuRefreshHead; + while (MenuRefreshEntry->Next != NULL) { + MenuRefreshEntry = MenuRefreshEntry->Next; + } + MenuRefreshEntry->Next = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY)); + MenuRefreshEntry = MenuRefreshEntry->Next; + } + ASSERT (MenuRefreshEntry != NULL); + MenuRefreshEntry->MenuOption = MenuOption; + MenuRefreshEntry->Selection = Selection; + MenuRefreshEntry->CurrentColumn = MenuOption->OptCol; + MenuRefreshEntry->CurrentRow = MenuOption->Row; + if (MenuOption->GrayOut) { + MenuRefreshEntry->CurrentAttribute = FIELD_TEXT_GRAYED | FIELD_BACKGROUND; + } else { + MenuRefreshEntry->CurrentAttribute = PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND; + } + } + + // + // If this is a text op with secondary text information + // + if ((Statement->Operand == EFI_IFR_TEXT_OP) && (Statement->TextTwo != 0)) { + StringPtr = GetToken (Statement->TextTwo, MenuOption->Handle); + + Width = (UINT16) gOptionBlockWidth; + OriginalRow = Row; + + for (Index = 0; GetLineByWidth (StringPtr, Width, &Index, &OutputString) != 0x0000;) { + if ((Temp == 0) && (Row <= BottomRow)) { + PrintStringAt (MenuOption->OptCol, Row, OutputString); + } + // + // If there is more string to process print on the next row and increment the Skip value + // + if (StrLen (&StringPtr[Index]) != 0) { + if (Temp2 == 0) { + Row++; + // // Since the Number of lines for this menu entry may or may not be reflected accurately // since the prompt might be 1 lines and option might be many, and vice versa, we need to do // some testing to ensure we are keeping this in-sync. @@ -1796,6 +2476,7 @@ UiDisplayMenu ( Row = OriginalRow; FreePool (StringPtr); } + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND); // // Need to handle the bottom of the display @@ -1809,7 +2490,7 @@ UiDisplayMenu ( if (Row > BottomRow) { if (!ValueIsScroll (FALSE, Link)) { - gDownArrow = TRUE; + DownArrow = TRUE; } Row = BottomRow + 1; @@ -1818,10 +2499,10 @@ UiDisplayMenu ( } if (!ValueIsScroll (TRUE, TopOfScreen)) { - gUpArrow = TRUE; + UpArrow = TRUE; } - if (gUpArrow) { + if (UpArrow) { gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND); PrintAt ( LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1, @@ -1829,10 +2510,10 @@ UiDisplayMenu ( L"%c", ARROW_UP ); - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND); } - if (gDownArrow) { + if (DownArrow) { gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND); PrintAt ( LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1, @@ -1840,7 +2521,7 @@ UiDisplayMenu ( L"%c", ARROW_DOWN ); - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND); } MenuOption = NULL; @@ -1854,6 +2535,10 @@ UiDisplayMenu ( // NewPos: Current menu option that need to hilight // ControlFlag = CfUpdateHelpString; + if (InitializedFlag) { + InitializedFlag = FALSE; + MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow); + } // // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily @@ -1863,10 +2548,12 @@ UiDisplayMenu ( Repaint = FALSE; if (Selection->QuestionId != 0) { - NewPos = Menu.ForwardLink; + NewPos = gMenuOption.ForwardLink; SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos); - while (SavedMenuOption->ThisTag->QuestionId != Selection->QuestionId && NewPos->ForwardLink != &Menu) { + while ((SavedMenuOption->ThisTag->QuestionId != Selection->QuestionId || + SavedMenuOption->Sequence != Selection->Sequence) && + NewPos->ForwardLink != &gMenuOption) { NewPos = NewPos->ForwardLink; SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos); } @@ -1879,20 +2566,49 @@ UiDisplayMenu ( for (Index = TopRow; Index <= BottomRow && Link != NewPos;) { SavedMenuOption = MENU_OPTION_FROM_LINK (Link); Index += SavedMenuOption->Skip; + if (Link == TopOfScreen) { + Index -= OldSkipValue; + } Link = Link->ForwardLink; } + if (NewPos == Link) { + SavedMenuOption = MENU_OPTION_FROM_LINK (Link); + } - if (Link != NewPos || Index > BottomRow) { + if (Link != NewPos || Index > BottomRow || (Link == NewPos && SavedMenuOption->Row + SavedMenuOption->Skip - 1 > BottomRow)) { + // + // Find the MenuOption which has the skip value for Date/Time opcode. + // + AdjustDateAndTimePosition(FALSE, &NewPos); // // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page // + SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos); + // + // SavedMenuOption->Row == 0 means the menu not show yet. + // + if (SavedMenuOption->Row == 0) { + UpdateOptionSkipLines (Selection, SavedMenuOption); + } + Link = NewPos; - for (Index = TopRow; Index <= BottomRow; ) { + for (Index = TopRow + SavedMenuOption->Skip; Index <= BottomRow + 1; ) { Link = Link->BackLink; SavedMenuOption = MENU_OPTION_FROM_LINK (Link); + if (SavedMenuOption->Row == 0) { + UpdateOptionSkipLines (Selection, SavedMenuOption); + } Index += SavedMenuOption->Skip; } - TopOfScreen = Link->ForwardLink; + + SkipValue = Index - BottomRow - 1; + if (SkipValue > 0 && SkipValue < (INTN) SavedMenuOption->Skip) { + TopOfScreen = Link; + OldSkipValue = SkipValue; + } else { + SkipValue = 0; + TopOfScreen = Link->ForwardLink; + } Repaint = TRUE; NewLine = TRUE; @@ -1916,23 +2632,12 @@ UiDisplayMenu ( // gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row); ProcessOptions (Selection, MenuOption, FALSE, &OptionString); - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND); if (OptionString != NULL) { if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP) ) { - // - // If leading spaces on OptionString - remove the spaces - // - for (Index = 0; OptionString[Index] == L' '; Index++) - ; - - for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) { - OptionString[Count] = OptionString[Index]; - Count++; - } - - OptionString[Count] = CHAR_NULL; + ProcessStringForDateTime(MenuOption, OptionString, FALSE); } Width = (UINT16) gOptionBlockWidth; @@ -1945,7 +2650,7 @@ UiDisplayMenu ( // // If there is more string to process print on the next row and increment the Skip value // - if (StrLen (&OptionString[Index])) { + if (StrLen (&OptionString[Index]) != 0) { MenuOption->Row++; } @@ -1960,7 +2665,7 @@ UiDisplayMenu ( if (MenuOption->GrayOut) { gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND); } else if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP) { - gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserSubtitleTextColor) | FIELD_BACKGROUND); } OriginalRow = MenuOption->Row; @@ -1973,7 +2678,7 @@ UiDisplayMenu ( // // If there is more string to process print on the next row and increment the Skip value // - if (StrLen (&MenuOption->Description[Index])) { + if (StrLen (&MenuOption->Description[Index]) != 0) { MenuOption->Row++; } @@ -1981,33 +2686,33 @@ UiDisplayMenu ( } MenuOption->Row = OriginalRow; - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND); } } } // - // This is only possible if we entered this page and the first menu option is - // a "non-menu" item. In that case, force it UiDown + // This is the current selected statement // MenuOption = MENU_OPTION_FROM_LINK (NewPos); + Statement = MenuOption->ThisTag; + Selection->Statement = Statement; if (!IsSelectable (MenuOption)) { - ASSERT (ScreenOperation == UiNoOperation); - ScreenOperation = UiDown; - ControlFlag = CfScreenOperation; + Repaint = SavedValue; + UpdateKeyHelp (Selection, MenuOption, FALSE); break; } // - // This is the current selected statement + // Record highlight for current menu // - Statement = MenuOption->ThisTag; - Selection->Statement = Statement; + CurrentMenu->QuestionId = Statement->QuestionId; + CurrentMenu->Sequence = MenuOption->Sequence; // // Set reverse attribute // - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextHighlightColor) | PcdGet8 (PcdBrowserFieldBackgroundHighlightColor)); gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row); // @@ -2017,9 +2722,13 @@ UiDisplayMenu ( // if (gMenuRefreshHead != NULL) { for (MenuRefreshEntry = gMenuRefreshHead; MenuRefreshEntry != NULL; MenuRefreshEntry = MenuRefreshEntry->Next) { - MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND; + if (MenuRefreshEntry->MenuOption->GrayOut) { + MenuRefreshEntry->CurrentAttribute = FIELD_TEXT_GRAYED | FIELD_BACKGROUND; + } else { + MenuRefreshEntry->CurrentAttribute = PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND; + } if (MenuRefreshEntry->MenuOption == MenuOption) { - MenuRefreshEntry->CurrentAttribute = FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT; + MenuRefreshEntry->CurrentAttribute = PcdGet8 (PcdBrowserFieldTextHighlightColor) | PcdGet8 (PcdBrowserFieldBackgroundHighlightColor); } } } @@ -2027,18 +2736,7 @@ UiDisplayMenu ( ProcessOptions (Selection, MenuOption, FALSE, &OptionString); if (OptionString != NULL) { if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) { - // - // If leading spaces on OptionString - remove the spaces - // - for (Index = 0; OptionString[Index] == L' '; Index++) - ; - - for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) { - OptionString[Count] = OptionString[Index]; - Count++; - } - - OptionString[Count] = CHAR_NULL; + ProcessStringForDateTime(MenuOption, OptionString, FALSE); } Width = (UINT16) gOptionBlockWidth; @@ -2051,7 +2749,7 @@ UiDisplayMenu ( // // If there is more string to process print on the next row and increment the Skip value // - if (StrLen (&OptionString[Index])) { + if (StrLen (&OptionString[Index]) != 0) { MenuOption->Row++; } @@ -2074,7 +2772,7 @@ UiDisplayMenu ( // // If there is more string to process print on the next row and increment the Skip value // - if (StrLen (&MenuOption->Description[Index])) { + if (StrLen (&MenuOption->Description[Index]) != 0) { MenuOption->Row++; } @@ -2086,12 +2784,12 @@ UiDisplayMenu ( } } - UpdateKeyHelp (MenuOption, FALSE); + UpdateKeyHelp (Selection, MenuOption, FALSE); // // Clear reverse attribute // - gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND); + gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND); } // // Repaint flag will be used when process CfUpdateHelpString, so restore its value @@ -2102,12 +2800,16 @@ UiDisplayMenu ( case CfUpdateHelpString: ControlFlag = CfPrepareToReadKey; + if (Selection->Form->ModalForm) { + break; + } - if ((Repaint || NewLine) && (gClassOfVfr != EFI_GENERAL_APPLICATION_SUBCLASS)) { + if (Repaint || NewLine) { // // Don't print anything if it is a NULL help token // - if (MenuOption->ThisTag->Help == 0) { + ASSERT(MenuOption != NULL); + if (MenuOption->ThisTag->Help == 0 || !IsSelectable (MenuOption)) { StringPtr = L"\0"; } else { StringPtr = GetToken (MenuOption->ThisTag->Help, MenuOption->Handle); @@ -2158,29 +2860,27 @@ UiDisplayMenu ( // // IFR is updated in Callback of refresh opcode, re-parse it // - ControlFlag = CfUiReset; + ControlFlag = CfCheckSelection; Selection->Statement = NULL; break; } Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); // - // if we encounter error, continue to read another key in. + // If we encounter error, continue to read another key in. // if (EFI_ERROR (Status)) { ControlFlag = CfReadKey; break; } - if (IsListEmpty (&Menu) && Key.UnicodeChar != CHAR_NULL) { - // - // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset - // - break; - } - switch (Key.UnicodeChar) { case CHAR_CARRIAGE_RETURN: + if(MenuOption->GrayOut || MenuOption->ReadOnly) { + ControlFlag = CfReadKey; + break; + } + ScreenOperation = UiSelect; gDirection = 0; break; @@ -2191,6 +2891,16 @@ UiDisplayMenu ( // case '+': case '-': + // + // If the screen has no menu items, and the user didn't select UiReset + // ignore the selection and go back to reading keys. + // + if(IsListEmpty (&gMenuOption) || MenuOption->GrayOut || MenuOption->ReadOnly) { + ControlFlag = CfReadKey; + break; + } + + ASSERT(MenuOption != NULL); Statement = MenuOption->ThisTag; if ((Statement->Operand == EFI_IFR_DATE_OP) || (Statement->Operand == EFI_IFR_TIME_OP) @@ -2208,6 +2918,8 @@ UiDisplayMenu ( // Repaint = TRUE; NewLine = TRUE; + } else { + Selection->Action = UI_ACTION_REFRESH_FORM; } if (OptionString != NULL) { FreePool (OptionString); @@ -2225,34 +2937,46 @@ UiDisplayMenu ( break; case ' ': - if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) { - if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut) { + if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) { + // + // If the screen has no menu items, and the user didn't select UiReset + // ignore the selection and go back to reading keys. + // + if(IsListEmpty (&gMenuOption)) { + ControlFlag = CfReadKey; + break; + } + + ASSERT(MenuOption != NULL); + if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut && !MenuOption->ReadOnly) { ScreenOperation = UiSelect; } } break; case CHAR_NULL: - if (((Key.ScanCode == SCAN_F1) && ((gFunctionKeySetting & FUNCTION_ONE) != FUNCTION_ONE)) || - ((Key.ScanCode == SCAN_F2) && ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO)) || - ((Key.ScanCode == SCAN_F9) && ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE)) || - ((Key.ScanCode == SCAN_F10) && ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN)) - ) { + for (Index = 0; Index < mScanCodeNumber; Index++) { + if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) { + ScreenOperation = gScanCodeToOperation[Index].ScreenOperation; + break; + } + } + + if (Selection->Form->ModalForm && (Key.ScanCode == SCAN_ESC || Index == mScanCodeNumber)) { // - // If the function key has been disabled, just ignore the key. + // ModalForm has no ESC key and Hot Key. // - } else { - for (Index = 0; Index < sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]); Index++) { - if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) { - if (Key.ScanCode == SCAN_F9) { - // - // Reset to standard default - // - DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; - } - ScreenOperation = gScanCodeToOperation[Index].ScreenOperation; - break; - } + ControlFlag = CfReadKey; + } else if (Index == mScanCodeNumber) { + // + // Check whether Key matches the registered hot key. + // + HotKey = NULL; + if ((gBrowserSettingScope == SystemLevel) || (gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) { + HotKey = GetHotKeyFromRegisterList (&Key); + } + if (HotKey != NULL) { + ScreenOperation = UiHotKey; } } break; @@ -2260,35 +2984,15 @@ UiDisplayMenu ( break; case CfScreenOperation: - if (ScreenOperation != UiPrevious && ScreenOperation != UiReset) { + if (ScreenOperation != UiReset) { // - // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset + // If the screen has no menu items, and the user didn't select UiReset // ignore the selection and go back to reading keys. // - if (IsListEmpty (&Menu)) { + if (IsListEmpty (&gMenuOption)) { ControlFlag = CfReadKey; break; } - // - // if there is nothing logical to place a cursor on, just move on to wait for a key. - // - for (Link = Menu.ForwardLink; Link != &Menu; Link = Link->ForwardLink) { - NextMenuOption = MENU_OPTION_FROM_LINK (Link); - if (IsSelectable (NextMenuOption)) { - break; - } - } - - if (Link == &Menu) { - ControlFlag = CfPrepareToReadKey; - break; - } - } else if (ScreenOperation == UiReset) { - // - // Press ESC to exit FormSet - // - Selection->Action = UI_ACTION_EXIT; - Selection->Statement = NULL; } for (Index = 0; @@ -2302,34 +3006,12 @@ UiDisplayMenu ( } break; - case CfUiPrevious: - ControlFlag = CfCheckSelection; - - if (IsListEmpty (&gMenuList)) { - Selection->Action = UI_ACTION_NONE; - if (IsListEmpty (&Menu)) { - ControlFlag = CfReadKey; - } - break; - } - - // - // Remove the Cached page entry - // - UiRemoveMenuListEntry (Selection); - - Selection->Action = UI_ACTION_REFRESH_FORM; - Selection->Statement = NULL; - break; - case CfUiSelect: ControlFlag = CfCheckSelection; + ASSERT(MenuOption != NULL); Statement = MenuOption->ThisTag; - if ((Statement->Operand == EFI_IFR_TEXT_OP) || - (Statement->Operand == EFI_IFR_DATE_OP) || - (Statement->Operand == EFI_IFR_TIME_OP) || - (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0)) { + if (Statement->Operand == EFI_IFR_TEXT_OP) { break; } @@ -2340,79 +3022,7 @@ UiDisplayMenu ( switch (Statement->Operand) { case EFI_IFR_REF_OP: - if (Statement->RefDevicePath != 0) { - // - // Goto another Hii Package list - // - ControlFlag = CfUiReset; - Selection->Action = UI_ACTION_REFRESH_FORMSET; - - StringPtr = GetToken (Statement->RefDevicePath, Selection->FormSet->HiiHandle); - if (StringPtr == NULL) { - // - // No device path string not found, exit - // - Selection->Action = UI_ACTION_EXIT; - Selection->Statement = NULL; - break; - } - BufferSize = StrLen (StringPtr) / 2; - DevicePath = AllocatePool (BufferSize); - - HexStringToBufInReverseOrder ((UINT8 *) DevicePath, &BufferSize, StringPtr); - Selection->Handle = HiiLibDevicePathToHiiHandle (DevicePath); - if (Selection->Handle == NULL) { - // - // If target Hii Handle not found, exit - // - Selection->Action = UI_ACTION_EXIT; - Selection->Statement = NULL; - break; - } - - FreePool (StringPtr); - FreePool (DevicePath); - - CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID)); - Selection->FormId = Statement->RefFormId; - Selection->QuestionId = Statement->RefQuestionId; - } else if (!CompareGuid (&Statement->RefFormSetId, &gZeroGuid)) { - // - // Goto another Formset, check for uncommitted data - // - ControlFlag = CfUiReset; - Selection->Action = UI_ACTION_REFRESH_FORMSET; - - CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID)); - Selection->FormId = Statement->RefFormId; - Selection->QuestionId = Statement->RefQuestionId; - } else if (Statement->RefFormId != 0) { - // - // Goto another form inside this formset, - // - Selection->Action = UI_ACTION_REFRESH_FORM; - - // - // Link current form so that we can always go back when someone hits the UiPrevious - // - UiAddMenuListEntry (Selection); - - Selection->FormId = Statement->RefFormId; - Selection->QuestionId = Statement->RefQuestionId; - } else if (Statement->RefQuestionId != 0) { - // - // Goto another Question - // - Selection->QuestionId = Statement->RefQuestionId; - - if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) { - Selection->Action = UI_ACTION_REFRESH_FORM; - } else { - Repaint = TRUE; - NewLine = TRUE; - break; - } - } + ProcessGotoOpCode(Statement, Selection, &Repaint, &NewLine); break; case EFI_IFR_ACTION_OP: @@ -2443,84 +3053,41 @@ UiDisplayMenu ( // // Editable Questions: oneof, ordered list, checkbox, numeric, string, password // - UpdateKeyHelp (MenuOption, TRUE); + UpdateKeyHelp (Selection, MenuOption, TRUE); Status = ProcessOptions (Selection, MenuOption, TRUE, &OptionString); if (EFI_ERROR (Status)) { Repaint = TRUE; NewLine = TRUE; - UpdateKeyHelp (MenuOption, FALSE); - } else { - Selection->Action = UI_ACTION_REFRESH_FORM; - } + UpdateKeyHelp (Selection, MenuOption, FALSE); + } else { + Selection->Action = UI_ACTION_REFRESH_FORM; + } - if (OptionString != NULL) { - FreePool (OptionString); - } + if (OptionString != NULL) { + FreePool (OptionString); + } break; } break; case CfUiReset: // - // We are going to leave current FormSet, so check uncommited data in this FormSet + // We come here when someone press ESC // ControlFlag = CfCheckSelection; - - if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) { - // - // There is no parent menu for FrontPage - // - Selection->Action = UI_ACTION_NONE; - Selection->Statement = MenuOption->ThisTag; - break; - } - - // - // If NV flag is up, prompt user - // - if (gNvUpdateRequired) { - Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - - YesResponse = gYesResponse[0]; - NoResponse = gNoResponse[0]; - - do { - CreateDialog (3, TRUE, 0, NULL, &Key, gEmptyString, gAreYouSure, gEmptyString); - } while - ( - (Key.ScanCode != SCAN_ESC) && - ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) && - ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET)) - ); - - // - // If the user hits the YesResponse key - // - if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) { - } else { - Repaint = TRUE; - NewLine = TRUE; - - Selection->Action = UI_ACTION_NONE; - break; - } - } - - gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK)); - gST->ConOut->EnableCursor (gST->ConOut, TRUE); - - UiFreeMenuList (); - gST->ConOut->ClearScreen (gST->ConOut); - return EFI_SUCCESS; + FindNextMenu (Selection, &Repaint, &NewLine); + break; case CfUiLeft: ControlFlag = CfCheckSelection; + ASSERT(MenuOption != NULL); if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) { if (MenuOption->Sequence != 0) { // // In the middle or tail of the Date/Time op-code set, go left. // + ASSERT(NewPos != NULL); NewPos = NewPos->BackLink; } } @@ -2528,11 +3095,13 @@ UiDisplayMenu ( case CfUiRight: ControlFlag = CfCheckSelection; + ASSERT(MenuOption != NULL); if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) { if (MenuOption->Sequence != 2) { // // In the middle or tail of the Date/Time op-code set, go left. // + ASSERT(NewPos != NULL); NewPos = NewPos->ForwardLink; } } @@ -2541,90 +3110,89 @@ UiDisplayMenu ( case CfUiUp: ControlFlag = CfCheckSelection; - SavedListEntry = TopOfScreen; - - if (NewPos->BackLink != &Menu) { - NewLine = TRUE; - // - // Adjust Date/Time position before we advance forward. - // - AdjustDateAndTimePosition (TRUE, &NewPos); + SavedListEntry = NewPos; - // - // Caution that we have already rewind to the top, don't go backward in this situation. - // - if (NewPos->BackLink != &Menu) { - NewPos = NewPos->BackLink; - } + ASSERT(NewPos != NULL); + // + // Adjust Date/Time position before we advance forward. + // + AdjustDateAndTimePosition (TRUE, &NewPos); + if (NewPos->BackLink != &gMenuOption) { + MenuOption = MENU_OPTION_FROM_LINK (NewPos); + ASSERT (MenuOption != NULL); + NewLine = TRUE; + NewPos = NewPos->BackLink; PreviousMenuOption = MENU_OPTION_FROM_LINK (NewPos); - DistanceValue = PreviousMenuOption->Skip; - - // - // Since the behavior of hitting the up arrow on a Date/Time op-code is intended - // to be one that back to the previous set of op-codes, we need to advance to the sencond - // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate - // checking can be done. - // - DistanceValue += AdjustDateAndTimePosition (TRUE, &NewPos); - - // - // Check the previous menu entry to see if it was a zero-length advance. If it was, - // don't worry about a redraw. - // - if ((INTN) MenuOption->Row - (INTN) DistanceValue < (INTN) TopRow) { - Repaint = TRUE; - TopOfScreen = NewPos; + if (PreviousMenuOption->Row == 0) { + UpdateOptionSkipLines (Selection, PreviousMenuOption); } - - Difference = MoveToNextStatement (TRUE, &NewPos); - if ((INTN) MenuOption->Row - (INTN) DistanceValue < (INTN) TopRow) { - if (Difference > 0) { - // - // Previous focus MenuOption is above the TopOfScreen, so we need to scroll - // - TopOfScreen = NewPos; - Repaint = TRUE; - } + DistanceValue = PreviousMenuOption->Skip; + Difference = 0; + if (MenuOption->Row >= DistanceValue + TopRow) { + Difference = MoveToNextStatement (Selection, TRUE, &NewPos, MenuOption->Row - TopRow - DistanceValue); } + NextMenuOption = MENU_OPTION_FROM_LINK (NewPos); + if (Difference < 0) { // - // We want to goto previous MenuOption, but finally we go down. - // it means that we hit the begining MenuOption that can be focused - // so we simply scroll to the top + // We hit the begining MenuOption that can be focused + // so we simply scroll to the top. // - if (SavedListEntry != Menu.ForwardLink) { - TopOfScreen = Menu.ForwardLink; + if (TopOfScreen != gMenuOption.ForwardLink) { + TopOfScreen = gMenuOption.ForwardLink; Repaint = TRUE; + } else { + // + // Scroll up to the last page when we have arrived at top page. + // + NewPos = &gMenuOption; + TopOfScreen = &gMenuOption; + MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry); + ScreenOperation = UiPageUp; + ControlFlag = CfScreenOperation; + break; } + } else if (MenuOption->Row < TopRow + DistanceValue + Difference) { + // + // Previous focus MenuOption is above the TopOfScreen, so we need to scroll + // + TopOfScreen = NewPos; + Repaint = TRUE; + SkipValue = 0; + OldSkipValue = 0; + } else if (!IsSelectable (NextMenuOption)) { + // + // Continue to go up until scroll to next page or the selectable option is found. + // + ScreenOperation = UiUp; + ControlFlag = CfScreenOperation; } // // If we encounter a Date/Time op-code set, rewind to the first op-code of the set. // AdjustDateAndTimePosition (TRUE, &TopOfScreen); - - UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE); + AdjustDateAndTimePosition (TRUE, &NewPos); + MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry); + UpdateStatusBar (Selection, INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE); } else { - SavedMenuOption = MenuOption; - MenuOption = MENU_OPTION_FROM_LINK (NewPos); - if (!IsSelectable (MenuOption)) { - // - // If we are at the end of the list and sitting on a text op, we need to more forward - // - ScreenOperation = UiDown; - ControlFlag = CfScreenOperation; - break; - } - - MenuOption = SavedMenuOption; + // + // Scroll up to the last page. + // + NewPos = &gMenuOption; + TopOfScreen = &gMenuOption; + MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry); + ScreenOperation = UiPageUp; + ControlFlag = CfScreenOperation; } break; case CfUiPageUp: ControlFlag = CfCheckSelection; - if (NewPos->BackLink == &Menu) { + ASSERT(NewPos != NULL); + if (NewPos->BackLink == &gMenuOption) { NewLine = FALSE; Repaint = FALSE; break; @@ -2633,38 +3201,62 @@ UiDisplayMenu ( NewLine = TRUE; Repaint = TRUE; Link = TopOfScreen; - PreviousMenuOption = MENU_OPTION_FROM_LINK (Link); - Index = BottomRow; - while ((Index >= TopRow) && (Link->BackLink != &Menu)) { - Index = Index - PreviousMenuOption->Skip; + Index = BottomRow; + while ((Index >= TopRow) && (Link->BackLink != &gMenuOption)) { Link = Link->BackLink; PreviousMenuOption = MENU_OPTION_FROM_LINK (Link); + if (PreviousMenuOption->Row == 0) { + UpdateOptionSkipLines (Selection, PreviousMenuOption); + } + if (Index < PreviousMenuOption->Skip) { + Index = 0; + break; + } + Index = Index - PreviousMenuOption->Skip; } + + if ((Link->BackLink == &gMenuOption) && (Index >= TopRow)) { + if (TopOfScreen == &gMenuOption) { + TopOfScreen = gMenuOption.ForwardLink; + NewPos = gMenuOption.BackLink; + MoveToNextStatement (Selection, TRUE, &NewPos, BottomRow - TopRow); + Repaint = FALSE; + } else if (TopOfScreen != Link) { + TopOfScreen = Link; + NewPos = Link; + MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow); + } else { + // + // Finally we know that NewPos is the last MenuOption can be focused. + // + Repaint = FALSE; + NewPos = Link; + MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow); + } + } else { + if (Index + 1 < TopRow) { + // + // Back up the previous option. + // + Link = Link->ForwardLink; + } - TopOfScreen = Link; - Difference = MoveToNextStatement (TRUE, &Link); - if (Difference > 0) { // - // The focus MenuOption is above the TopOfScreen + // Move to the option in Next page. // - TopOfScreen = Link; - } else if (Difference < 0) { + if (TopOfScreen == &gMenuOption) { + NewPos = gMenuOption.BackLink; + MoveToNextStatement (Selection, TRUE, &NewPos, BottomRow - TopRow); + } else { + NewPos = Link; + MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow); + } + // - // This happens when there is no MenuOption can be focused from - // Current MenuOption to the first MenuOption + // There are more MenuOption needing scrolling up. // - TopOfScreen = Menu.ForwardLink; - } - Index += Difference; - if (Index < TopRow) { - MenuOption = NULL; - } - - if (NewPos == Link) { - Repaint = FALSE; - NewLine = FALSE; - } else { - NewPos = Link; + TopOfScreen = Link; + MenuOption = NULL; } // @@ -2678,7 +3270,8 @@ UiDisplayMenu ( case CfUiPageDown: ControlFlag = CfCheckSelection; - if (NewPos->ForwardLink == &Menu) { + ASSERT (NewPos != NULL); + if (NewPos->ForwardLink == &gMenuOption) { NewLine = FALSE; Repaint = FALSE; break; @@ -2689,34 +3282,41 @@ UiDisplayMenu ( Link = TopOfScreen; NextMenuOption = MENU_OPTION_FROM_LINK (Link); Index = TopRow; - while ((Index <= BottomRow) && (Link->ForwardLink != &Menu)) { + while ((Index <= BottomRow) && (Link->ForwardLink != &gMenuOption)) { Index = Index + NextMenuOption->Skip; Link = Link->ForwardLink; NextMenuOption = MENU_OPTION_FROM_LINK (Link); } - Index += MoveToNextStatement (FALSE, &Link); - if (Index > BottomRow) { + if ((Link->ForwardLink == &gMenuOption) && (Index <= BottomRow)) { // - // There are more MenuOption needing scrolling + // Finally we know that NewPos is the last MenuOption can be focused. + // + Repaint = FALSE; + MoveToNextStatement (Selection, TRUE, &Link, Index - TopRow); + } else { + if (Index - 1 > BottomRow) { + // + // Back up the previous option. + // + Link = Link->BackLink; + } + // + // There are more MenuOption needing scrolling down. // TopOfScreen = Link; MenuOption = NULL; - } - if (NewPos == Link && Index <= BottomRow) { // - // Finally we know that NewPos is the last MenuOption can be focused. + // Move to the option in Next page. // - NewLine = FALSE; - Repaint = FALSE; - } else { - NewPos = Link; + MoveToNextStatement (Selection, FALSE, &Link, BottomRow - TopRow); } // // If we encounter a Date/Time op-code set, rewind to the first op-code of the set. // Don't do this when we are already in the last page. // + NewPos = Link; AdjustDateAndTimePosition (TRUE, &TopOfScreen); AdjustDateAndTimePosition (TRUE, &NewPos); break; @@ -2732,20 +3332,49 @@ UiDisplayMenu ( // the Date/Time op-code. // SavedListEntry = NewPos; - DistanceValue = AdjustDateAndTimePosition (FALSE, &NewPos); + AdjustDateAndTimePosition (FALSE, &NewPos); - if (NewPos->ForwardLink != &Menu) { + if (NewPos->ForwardLink != &gMenuOption) { MenuOption = MENU_OPTION_FROM_LINK (NewPos); NewLine = TRUE; NewPos = NewPos->ForwardLink; + + Difference = 0; + if (BottomRow >= MenuOption->Row + MenuOption->Skip) { + Difference = MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - MenuOption->Row - MenuOption->Skip); + // + // We hit the end of MenuOption that can be focused + // so we simply scroll to the first page. + // + if (Difference < 0) { + // + // Scroll to the first page. + // + if (TopOfScreen != gMenuOption.ForwardLink) { + TopOfScreen = gMenuOption.ForwardLink; + Repaint = TRUE; + MenuOption = NULL; + } else { + MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry); + } + NewPos = gMenuOption.ForwardLink; + MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow); + + // + // If we are at the end of the list and sitting on a Date/Time op, rewind to the head. + // + AdjustDateAndTimePosition (TRUE, &TopOfScreen); + AdjustDateAndTimePosition (TRUE, &NewPos); + break; + } + } NextMenuOption = MENU_OPTION_FROM_LINK (NewPos); - DistanceValue += NextMenuOption->Skip; - DistanceValue += MoveToNextStatement (FALSE, &NewPos); // // An option might be multi-line, so we need to reflect that data in the overall skip value // - UpdateOptionSkipLines (Selection, NextMenuOption, &OptionString, SkipValue); + UpdateOptionSkipLines (Selection, NextMenuOption); + DistanceValue = Difference + NextMenuOption->Skip; Temp = MenuOption->Row + MenuOption->Skip + DistanceValue - 1; if ((MenuOption->Row + MenuOption->Skip == BottomRow + 1) && @@ -2787,26 +3416,13 @@ UiDisplayMenu ( // // If we have a remainder, skip that many more op-codes until we drain the remainder // - for (; - Difference >= (INTN) SavedMenuOption->Skip; - Difference = Difference - (INTN) SavedMenuOption->Skip - ) { + while (Difference >= (INTN) SavedMenuOption->Skip) { // // Since the Difference is greater than or equal to this op-code's skip value, skip it // + Difference = Difference - (INTN) SavedMenuOption->Skip; TopOfScreen = TopOfScreen->ForwardLink; SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen); - if (Difference < (INTN) SavedMenuOption->Skip) { - Difference = SavedMenuOption->Skip - Difference - 1; - break; - } else { - if (Difference == (INTN) SavedMenuOption->Skip) { - TopOfScreen = TopOfScreen->ForwardLink; - SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen); - Difference = SavedMenuOption->Skip - Difference; - break; - } - } } // // Since we will act on this op-code in the next routine, and increment the @@ -2839,6 +3455,8 @@ UiDisplayMenu ( } else { SkipValue++; } + } else if (SavedMenuOption->Skip == 1) { + SkipValue = 0; } else { SkipValue = 0; TopOfScreen = TopOfScreen->ForwardLink; @@ -2847,66 +3465,156 @@ UiDisplayMenu ( Repaint = TRUE; OldSkipValue = SkipValue; + } else if (!IsSelectable (NextMenuOption)) { + // + // Continue to go down until scroll to next page or the selectable option is found. + // + ScreenOperation = UiDown; + ControlFlag = CfScreenOperation; } MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry); - UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE); + UpdateStatusBar (Selection, INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE); } else { - SavedMenuOption = MenuOption; - MenuOption = MENU_OPTION_FROM_LINK (NewPos); - if (!IsSelectable (MenuOption)) { - // - // If we are at the end of the list and sitting on a text op, we need to more forward - // - ScreenOperation = UiUp; - ControlFlag = CfScreenOperation; - break; - } - - MenuOption = SavedMenuOption; // - // If we are at the end of the list and sitting on a Date/Time op, rewind to the head. + // Scroll to the first page. // - AdjustDateAndTimePosition (TRUE, &NewPos); + if (TopOfScreen != gMenuOption.ForwardLink) { + TopOfScreen = gMenuOption.ForwardLink; + Repaint = TRUE; + MenuOption = NULL; + } else { + MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry); + } + NewLine = TRUE; + NewPos = gMenuOption.ForwardLink; + MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow); } + + // + // If we are at the end of the list and sitting on a Date/Time op, rewind to the head. + // + AdjustDateAndTimePosition (TRUE, &TopOfScreen); + AdjustDateAndTimePosition (TRUE, &NewPos); break; - case CfUiSave: + case CfUiHotKey: ControlFlag = CfCheckSelection; - + + Status = EFI_SUCCESS; // - // Submit the form + // Discard changes. After it, no NV flag is showed. // - Status = SubmitForm (Selection->FormSet, Selection->Form); + if ((HotKey->Action & BROWSER_ACTION_DISCARD) == BROWSER_ACTION_DISCARD) { + Status = DiscardForm (Selection->FormSet, Selection->Form, gBrowserSettingScope); + if (!EFI_ERROR (Status)) { + Selection->Action = UI_ACTION_REFRESH_FORM; + Selection->Statement = NULL; + gResetRequired = FALSE; + } else { + do { + CreateDialog (4, TRUE, 0, NULL, &Key, HotKey->HelpString, gDiscardFailed, gPressEnter, gEmptyString); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + // + // Still show current page. + // + Selection->Action = UI_ACTION_NONE; + Repaint = TRUE; + NewLine = TRUE; + break; + } + } - if (!EFI_ERROR (Status)) { - UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE); - UpdateStatusBar (NV_UPDATE_REQUIRED, MenuOption->ThisTag->QuestionFlags, FALSE); - } else { - do { - CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveFailed, gPressEnter, gEmptyString); - } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + // + // Reterieve default setting. After it. NV flag will be showed. + // + if ((HotKey->Action & BROWSER_ACTION_DEFAULT) == BROWSER_ACTION_DEFAULT) { + Status = ExtractDefault (Selection->FormSet, Selection->Form, HotKey->DefaultId, gBrowserSettingScope); + if (!EFI_ERROR (Status)) { + Selection->Action = UI_ACTION_REFRESH_FORM; + Selection->Statement = NULL; + gResetRequired = TRUE; + } else { + do { + CreateDialog (4, TRUE, 0, NULL, &Key, HotKey->HelpString, gDefaultFailed, gPressEnter, gEmptyString); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + // + // Still show current page. + // + Selection->Action = UI_ACTION_NONE; + Repaint = TRUE; + NewLine = TRUE; + break; + } + } - Repaint = TRUE; - NewLine = TRUE; + // + // Save changes. After it, no NV flag is showed. + // + if ((HotKey->Action & BROWSER_ACTION_SUBMIT) == BROWSER_ACTION_SUBMIT) { + Status = SubmitForm (Selection->FormSet, Selection->Form, gBrowserSettingScope); + if (!EFI_ERROR (Status)) { + ASSERT(MenuOption != NULL); + UpdateStatusBar (Selection, INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE); + UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, MenuOption->ThisTag->QuestionFlags, FALSE); + } else { + do { + CreateDialog (4, TRUE, 0, NULL, &Key, HotKey->HelpString, gSaveFailed, gPressEnter, gEmptyString); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + // + // Still show current page. + // + Selection->Action = UI_ACTION_NONE; + Repaint = TRUE; + NewLine = TRUE; + break; + } + } + + // + // Set Reset required Flag + // + if ((HotKey->Action & BROWSER_ACTION_RESET) == BROWSER_ACTION_RESET) { + gResetRequired = TRUE; + } + + // + // Exit Action + // + if ((HotKey->Action & BROWSER_ACTION_EXIT) == BROWSER_ACTION_EXIT) { + // + // Form Exit without saving, Similar to ESC Key. + // FormSet Exit without saving, Exit SendForm. + // System Exit without saving, CallExitHandler and Exit SendForm. + // + DiscardForm (Selection->FormSet, Selection->Form, gBrowserSettingScope); + if (gBrowserSettingScope == FormLevel) { + ControlFlag = CfUiReset; + } else if (gBrowserSettingScope == FormSetLevel) { + Selection->Action = UI_ACTION_EXIT; + } else if (gBrowserSettingScope == SystemLevel) { + if (ExitHandlerFunction != NULL) { + ExitHandlerFunction (); + } + Selection->Action = UI_ACTION_EXIT; + } + Selection->Statement = NULL; } break; case CfUiDefault: ControlFlag = CfCheckSelection; - - Status = ExtractFormDefault (Selection->FormSet, Selection->Form, DefaultId); + // + // Reset to default value for all forms in the whole system. + // + Status = ExtractDefault (Selection->FormSet, NULL, DefaultId, FormSetLevel); if (!EFI_ERROR (Status)) { Selection->Action = UI_ACTION_REFRESH_FORM; Selection->Statement = NULL; - - // - // Show NV update flag on status bar - // - gNvUpdateRequired = TRUE; + gResetRequired = TRUE; } break;