X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FSetupBrowserDxe%2FPresentation.c;h=ee8ab75a28880694b83475f9265929269dc4c976;hb=ca20ce504257b864c53d970ebd42e9165ea45e08;hp=69c0496c8d8bfdfed08337e0cfca238793a5bf0a;hpb=eccfeab1cac23a27c5b87154765b1713ecb12e22;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c b/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c index 69c0496c8d..ee8ab75a28 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c @@ -1,8 +1,8 @@ /** @file Utility functions for UI presentation. -Copyright (c) 2004 - 2009, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2013, 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 @@ -16,7 +16,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. BOOLEAN mHiiPackageListUpdated; UI_MENU_SELECTION *gCurrentSelection; - +EFI_HII_HANDLE mCurrentHiiHandle = NULL; +EFI_GUID mCurrentFormSetGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}}; +UINT16 mCurrentFormId = 0; /** Clear retangle with specified text attribute. @@ -109,6 +111,8 @@ NewStrCat ( hit, then 2 Unicode character will consume an output storage space with size of CHAR16 till a NARROW_CHAR is hit. + If String is NULL, then ASSERT (). + @param String The input string to be counted. @return Storage space for the input string. @@ -123,6 +127,11 @@ GetStringWidth ( UINTN Count; UINTN IncrementValue; + ASSERT (String != NULL); + if (String == NULL) { + return 0; + } + Index = 0; Count = 0; IncrementValue = 1; @@ -173,10 +182,13 @@ GetStringWidth ( /** This function displays the page frame. + @param Selection Selection contains the information about + the Selection, form and formset to be displayed. + Selection action may be updated in retrieve callback. **/ VOID DisplayPageFrame ( - VOID + IN UI_MENU_SELECTION *Selection ) { UINTN Index; @@ -194,6 +206,10 @@ DisplayPageFrame ( gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &LocalScreen.RightColumn, &LocalScreen.BottomRow); ClearLines (0, LocalScreen.RightColumn, 0, LocalScreen.BottomRow, KEYHELP_BACKGROUND); + if (Selection->Form->ModalForm) { + return; + } + CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR)); // @@ -208,7 +224,7 @@ DisplayPageFrame ( Buffer[Index] = Character; } - if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) { + if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) { // // ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND); // @@ -250,7 +266,7 @@ DisplayPageFrame ( // // Handle left column // - PrintStringAt (LocalScreen.LeftColumn, Line, StrFrontPageBanner); + PrintStringAt (LocalScreen.LeftColumn + BANNER_LEFT_COLUMN_INDENT, Line, StrFrontPageBanner); break; case 1: @@ -284,12 +300,12 @@ DisplayPageFrame ( ClearLines ( LocalScreen.LeftColumn, LocalScreen.RightColumn, - LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT, + LocalScreen.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 1, KEYHELP_TEXT | KEYHELP_BACKGROUND ); - if (gClassOfVfr != FORMSET_CLASS_FRONT_PAGE) { + if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) { ClearLines ( LocalScreen.LeftColumn, LocalScreen.RightColumn, @@ -324,7 +340,7 @@ DisplayPageFrame ( Character = BOXDRAW_UP_LEFT; PrintChar (Character); - if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) { + if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) { // // Print Bottom border line // +------------------------------------------------------------------------------+ @@ -332,14 +348,14 @@ DisplayPageFrame ( // +------------------------------------------------------------------------------+ // Character = BOXDRAW_DOWN_RIGHT; - PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT, Character); + PrintCharAt (LocalScreen.LeftColumn, LocalScreen.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight, Character); PrintString (Buffer); Character = BOXDRAW_DOWN_LEFT; PrintChar (Character); Character = BOXDRAW_VERTICAL; - for (Row = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT + 1; + for (Row = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight + 1; Row <= LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2; Row++ ) { @@ -387,9 +403,11 @@ EvaluateFormExpressions ( Link = GetNextNode (&Form->ExpressionListHead, Link); if (Expression->Type == EFI_HII_EXPRESSION_INCONSISTENT_IF || - Expression->Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) { + Expression->Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF || + Expression->Type == EFI_HII_EXPRESSION_WRITE || + (Expression->Type == EFI_HII_EXPRESSION_READ && Form->FormType != STANDARD_MAP_FORM_TYPE)) { // - // Postpone Form validation to Question editing or Form submiting + // Postpone Form validation to Question editing or Form submitting or Question Write or Question Read for nonstandard form. // continue; } @@ -450,7 +468,6 @@ DisplayForm ( CHAR16 *StringPtr; UINT16 MenuItemCount; EFI_HII_HANDLE Handle; - BOOLEAN Suppress; EFI_SCREEN_DESCRIPTOR LocalScreen; UINT16 Width; UINTN ArrayEntry; @@ -460,6 +477,7 @@ DisplayForm ( UINT16 NumberOfLines; EFI_STATUS Status; UI_MENU_OPTION *MenuOption; + UINT16 GlyphWidth; Handle = Selection->Handle; MenuItemCount = 0; @@ -472,8 +490,12 @@ DisplayForm ( StringPtr = GetToken (Selection->Form->FormTitle, Handle); - if (gClassOfVfr != FORMSET_CLASS_FRONT_PAGE) { - gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND); + if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) { + if (Selection->Form->ModalForm) { + gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | EFI_BACKGROUND_BLACK); + } else { + gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND); + } PrintStringAt ( (LocalScreen.RightColumn + LocalScreen.LeftColumn - GetStringWidth (StringPtr) / 2) / 2, LocalScreen.TopRow + 1, @@ -499,24 +521,16 @@ DisplayForm ( while (!IsNull (&Selection->Form->StatementListHead, Link)) { Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link); - if (Statement->SuppressExpression != NULL) { - Suppress = Statement->SuppressExpression->Result.Value.b; - } else { - Suppress = FALSE; - } - - if (Statement->DisableExpression != NULL) { - Suppress = (BOOLEAN) (Suppress || Statement->DisableExpression->Result.Value.b); - } - - if (!Suppress) { + if (EvaluateExpressionList(Statement->Expression, FALSE, NULL, NULL) <= ExpressGrayOut) { StringPtr = GetToken (Statement->Prompt, Handle); + ASSERT (StringPtr != NULL); Width = GetWidth (Statement, Handle); NumberOfLines = 1; ArrayEntry = 0; - for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) { + GlyphWidth = 1; + for (; GetLineByWidth (StringPtr, Width, &GlyphWidth,&ArrayEntry, &OutputString) != 0x0000;) { // // If there is more string to process print on the next row and increment the Skip value // @@ -531,7 +545,7 @@ DisplayForm ( // We are NOT!! removing this StringPtr buffer via FreePool since it is being used in the menuoptions, we will do // it in UiFreeMenu. // - MenuOption = UiAddMenuOption (StringPtr, Selection->Handle, Statement, NumberOfLines, MenuItemCount); + MenuOption = UiAddMenuOption (StringPtr, Selection->Handle, Selection->Form, Statement, NumberOfLines, MenuItemCount); MenuItemCount++; if (MenuOption->IsQuestion && !MenuOption->ReadOnly) { @@ -561,13 +575,10 @@ InitializeBrowserStrings ( VOID ) { - gFunctionNineString = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle); - gFunctionTenString = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle); gEnterString = GetToken (STRING_TOKEN (ENTER_STRING), gHiiHandle); gEnterCommitString = GetToken (STRING_TOKEN (ENTER_COMMIT_STRING), gHiiHandle); gEnterEscapeString = GetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), gHiiHandle); gEscapeString = GetToken (STRING_TOKEN (ESCAPE_STRING), gHiiHandle); - gSaveFailed = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle); gMoveHighlight = GetToken (STRING_TOKEN (MOVE_HIGHLIGHT), gHiiHandle); gMakeSelection = GetToken (STRING_TOKEN (MAKE_SELECTION), gHiiHandle); gDecNumericInput = GetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), gHiiHandle); @@ -591,6 +602,7 @@ InitializeBrowserStrings ( gSaveChanges = GetToken (STRING_TOKEN (SAVE_CHANGES), gHiiHandle); gOptionMismatch = GetToken (STRING_TOKEN (OPTION_MISMATCH), gHiiHandle); gFormSuppress = GetToken (STRING_TOKEN (FORM_SUPPRESSED), gHiiHandle); + gProtocolNotFound = GetToken (STRING_TOKEN (PROTOCOL_NOT_FOUND), gHiiHandle); return ; } @@ -604,8 +616,6 @@ FreeBrowserStrings ( VOID ) { - FreePool (gFunctionNineString); - FreePool (gFunctionTenString); FreePool (gEnterString); FreePool (gEnterCommitString); FreePool (gEnterEscapeString); @@ -633,9 +643,68 @@ FreeBrowserStrings ( FreePool (gSaveChanges); FreePool (gOptionMismatch); FreePool (gFormSuppress); + FreePool (gProtocolNotFound); return ; } +/** + Show all registered HotKey help strings on bottom Rows. + +**/ +VOID +PrintHotKeyHelpString ( + VOID + ) +{ + UINTN CurrentCol; + UINTN CurrentRow; + UINTN BottomRowOfHotKeyHelp; + UINTN ColumnWidth; + UINTN Index; + EFI_SCREEN_DESCRIPTOR LocalScreen; + LIST_ENTRY *Link; + BROWSER_HOT_KEY *HotKey; + + CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR)); + ColumnWidth = (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3; + BottomRowOfHotKeyHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 3; + + // + // Calculate total number of Register HotKeys. + // + Index = 0; + Link = GetFirstNode (&gBrowserHotKeyList); + while (!IsNull (&gBrowserHotKeyList, Link)) { + HotKey = BROWSER_HOT_KEY_FROM_LINK (Link); + // + // Help string can't exceed ColumnWidth. One Row will show three Help information. + // + if (StrLen (HotKey->HelpString) > ColumnWidth) { + HotKey->HelpString[ColumnWidth] = L'\0'; + } + // + // Calculate help information Column and Row. + // + if ((Index % 3) != 2) { + CurrentCol = LocalScreen.LeftColumn + (2 - Index % 3) * ColumnWidth; + } else { + CurrentCol = LocalScreen.LeftColumn + 2; + } + CurrentRow = BottomRowOfHotKeyHelp - Index / 3; + // + // Print HotKey help string on bottom Row. + // + PrintStringAt (CurrentCol, CurrentRow, HotKey->HelpString); + + // + // Get Next Hot Key. + // + Link = GetNextNode (&gBrowserHotKeyList, Link); + Index ++; + } + + return; +} /** Update key's help imformation. @@ -662,18 +731,22 @@ UpdateKeyHelp ( EFI_SCREEN_DESCRIPTOR LocalScreen; FORM_BROWSER_STATEMENT *Statement; + gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND); + + if (Selection->Form->ModalForm) { + return; + } + CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR)); SecCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3; - ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) * 2 / 3; + ThdCol = LocalScreen.LeftColumn + (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3 * 2; StartColumnOfHelp = LocalScreen.LeftColumn + 2; LeftColumnOfHelp = LocalScreen.LeftColumn + 1; RightColumnOfHelp = LocalScreen.RightColumn - 2; - TopRowOfHelp = LocalScreen.BottomRow - 4; - BottomRowOfHelp = LocalScreen.BottomRow - 3; - - gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND); + TopRowOfHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight + 1; + BottomRowOfHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 2; Statement = MenuOption->ThisTag; switch (Statement->Operand) { @@ -685,11 +758,15 @@ UpdateKeyHelp ( ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND); if (!Selected) { - if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) { - if (Selection->FormEditable) { - PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString); - PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString); - } + // + // On system setting, HotKey will show on every form. + // + if (gBrowserSettingScope == SystemLevel || + (Selection->FormEditable && gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) { + PrintHotKeyHelpString (); + } + + if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) { PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString); } @@ -705,14 +782,14 @@ UpdateKeyHelp ( ARROW_LEFT, gMoveHighlight ); - PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber); + PrintStringAt (SecCol, BottomRowOfHelp, gEnterString); + PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber); } else { PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight); if (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0) { - PrintStringAt (SecCol, BottomRowOfHelp, gAdjustNumber); - } else { - PrintStringAt (SecCol, BottomRowOfHelp, gEnterString); - } + PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber); + } + PrintStringAt (SecCol, BottomRowOfHelp, gEnterString); } } else { PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString); @@ -720,7 +797,9 @@ UpdateKeyHelp ( // // If it is a selected numeric with manual input, display different message // - if ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step == 0)) { + if ((Statement->Operand == EFI_IFR_NUMERIC_OP) || + (Statement->Operand == EFI_IFR_DATE_OP) || + (Statement->Operand == EFI_IFR_TIME_OP)) { PrintStringAt ( SecCol, TopRowOfHelp, @@ -742,11 +821,14 @@ UpdateKeyHelp ( case EFI_IFR_CHECKBOX_OP: ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND); - if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) { - if (Selection->FormEditable) { - PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString); - PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString); - } + // + // On system setting, HotKey will show on every form. + // + if (gBrowserSettingScope == SystemLevel || + (Selection->FormEditable && gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) { + PrintHotKeyHelpString (); + } + if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) { PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString); } @@ -760,19 +842,23 @@ UpdateKeyHelp ( case EFI_IFR_TEXT_OP: case EFI_IFR_ACTION_OP: case EFI_IFR_RESET_BUTTON_OP: + case EFI_IFR_SUBTITLE_OP: ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND); if (!Selected) { - if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) { - if (Selection->FormEditable) { - PrintStringAt (SecCol, TopRowOfHelp, gFunctionNineString); - PrintStringAt (ThdCol, TopRowOfHelp, gFunctionTenString); - } + // + // On system setting, HotKey will show on every form. + // + if (gBrowserSettingScope == SystemLevel || + (Selection->FormEditable && gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) { + PrintHotKeyHelpString (); + } + if ((gClassOfVfr & FORMSET_CLASS_PLATFORM_SETUP) == FORMSET_CLASS_PLATFORM_SETUP) { PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString); } PrintAt (StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight); - if (Statement->Operand != EFI_IFR_TEXT_OP) { + if (Statement->Operand != EFI_IFR_TEXT_OP && Statement->Operand != EFI_IFR_SUBTITLE_OP) { PrintStringAt (SecCol, BottomRowOfHelp, gEnterString); } } else { @@ -833,6 +919,462 @@ FormUpdateNotify ( return EFI_SUCCESS; } +/** + check whether the formset need to update the NV. + + @param FormSet FormSet data structure. + + @retval TRUE Need to update the NV. + @retval FALSE No need to update the NV. +**/ +BOOLEAN +IsNvUpdateRequired ( + IN FORM_BROWSER_FORMSET *FormSet + ) +{ + LIST_ENTRY *Link; + FORM_BROWSER_FORM *Form; + + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + + if (Form->NvUpdateRequired ) { + return TRUE; + } + + Link = GetNextNode (&FormSet->FormListHead, Link); + } + + return FALSE; +} + +/** + check whether the formset need to update the NV. + + @param FormSet FormSet data structure. + @param SetValue Whether set new value or clear old value. + +**/ +VOID +UpdateNvInfoInForm ( + IN FORM_BROWSER_FORMSET *FormSet, + IN BOOLEAN SetValue + ) +{ + LIST_ENTRY *Link; + FORM_BROWSER_FORM *Form; + + Link = GetFirstNode (&FormSet->FormListHead); + while (!IsNull (&FormSet->FormListHead, Link)) { + Form = FORM_BROWSER_FORM_FROM_LINK (Link); + + Form->NvUpdateRequired = SetValue; + + Link = GetNextNode (&FormSet->FormListHead, Link); + } +} +/** + Find menu which will show next time. + + @param Selection On input, Selection tell setup browser the information + about the Selection, form and formset to be displayed. + On output, Selection return the screen item that is selected + by user. + @param Repaint Whether need to repaint the menu. + @param NewLine Whether need to show at new line. + + @retval TRUE Need return. + @retval FALSE No need to return. +**/ +BOOLEAN +FindNextMenu ( + IN OUT UI_MENU_SELECTION *Selection, + IN BOOLEAN *Repaint, + IN BOOLEAN *NewLine + ) +{ + UI_MENU_LIST *CurrentMenu; + CHAR16 YesResponse; + CHAR16 NoResponse; + EFI_INPUT_KEY Key; + BROWSER_SETTING_SCOPE Scope; + + CurrentMenu = Selection->CurrentMenu; + + if (CurrentMenu != NULL && CurrentMenu->Parent != NULL) { + // + // we have a parent, so go to the parent menu + // + if (CompareGuid (&CurrentMenu->FormSetGuid, &CurrentMenu->Parent->FormSetGuid)) { + // + // The parent menu and current menu are in the same formset + // + Selection->Action = UI_ACTION_REFRESH_FORM; + Scope = FormLevel; + } else { + Selection->Action = UI_ACTION_REFRESH_FORMSET; + CopyMem (&Selection->FormSetGuid, &CurrentMenu->Parent->FormSetGuid, sizeof (EFI_GUID)); + Selection->Handle = CurrentMenu->Parent->HiiHandle; + Scope = FormSetLevel; + } + + // + // Form Level Check whether the data is changed. + // + if ((gBrowserSettingScope == FormLevel && Selection->Form->NvUpdateRequired) || + (gBrowserSettingScope == FormSetLevel && IsNvUpdateRequired(Selection->FormSet) && Scope == FormSetLevel)) { + gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + + YesResponse = gYesResponse[0]; + NoResponse = gNoResponse[0]; + + // + // If NV flag is up, prompt user + // + do { + CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveChanges, 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 (Key.ScanCode == SCAN_ESC) { + // + // User hits the ESC key, Ingore. + // + if (Repaint != NULL) { + *Repaint = TRUE; + } + if (NewLine != NULL) { + *NewLine = TRUE; + } + + Selection->Action = UI_ACTION_NONE; + return FALSE; + } + + if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) { + // + // If the user hits the YesResponse key + // + SubmitForm (Selection->FormSet, Selection->Form, Scope); + } else { + // + // If the user hits the NoResponse key + // + DiscardForm (Selection->FormSet, Selection->Form, Scope); + } + } + + Selection->Statement = NULL; + + Selection->FormId = CurrentMenu->Parent->FormId; + Selection->QuestionId = CurrentMenu->Parent->QuestionId; + + // + // Clear highlight record for this menu + // + CurrentMenu->QuestionId = 0; + return FALSE; + } + + if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) { + // + // We never exit FrontPage, so skip the ESC + // + Selection->Action = UI_ACTION_NONE; + return FALSE; + } + + // + // We are going to leave current FormSet, so check uncommited data in this FormSet + // + if (gBrowserSettingScope != SystemLevel && IsNvUpdateRequired(Selection->FormSet)) { + gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + + YesResponse = gYesResponse[0]; + NoResponse = gNoResponse[0]; + + // + // If NV flag is up, prompt user + // + do { + CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveChanges, 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 (Key.ScanCode == SCAN_ESC) { + // + // User hits the ESC key + // + if (Repaint != NULL) { + *Repaint = TRUE; + } + + if (NewLine != NULL) { + *NewLine = TRUE; + } + + Selection->Action = UI_ACTION_NONE; + return FALSE; + } + + if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) { + // + // If the user hits the YesResponse key + // + SubmitForm (Selection->FormSet, Selection->Form, FormSetLevel); + } else { + // + // If the user hits the NoResponse key + // + DiscardForm (Selection->FormSet, Selection->Form, FormSetLevel); + } + } + + Selection->Statement = NULL; + if (CurrentMenu != NULL) { + CurrentMenu->QuestionId = 0; + } + + Selection->Action = UI_ACTION_EXIT; + return TRUE; +} + +/** + Call the call back function for the question and process the return action. + + @param Selection On input, Selection tell setup browser the information + about the Selection, form and formset to be displayed. + On output, Selection return the screen item that is selected + by user. + @param Question The Question which need to call. + @param Action The action request. + @param SkipSaveOrDiscard Whether skip save or discard action. + + @retval EFI_SUCCESS The call back function excutes successfully. + @return Other value if the call back function failed to excute. +**/ +EFI_STATUS +ProcessCallBackFunction ( + IN OUT UI_MENU_SELECTION *Selection, + IN FORM_BROWSER_STATEMENT *Question, + IN EFI_BROWSER_ACTION Action, + IN BOOLEAN SkipSaveOrDiscard + ) +{ + EFI_STATUS Status; + EFI_BROWSER_ACTION_REQUEST ActionRequest; + EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; + EFI_HII_VALUE *HiiValue; + EFI_IFR_TYPE_VALUE *TypeValue; + FORM_BROWSER_STATEMENT *Statement; + BOOLEAN SubmitFormIsRequired; + BOOLEAN DiscardFormIsRequired; + BOOLEAN NeedExit; + LIST_ENTRY *Link; + BROWSER_SETTING_SCOPE SettingLevel; + + ConfigAccess = Selection->FormSet->ConfigAccess; + SubmitFormIsRequired = FALSE; + SettingLevel = FormSetLevel; + DiscardFormIsRequired = FALSE; + NeedExit = FALSE; + Status = EFI_SUCCESS; + ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; + + if (ConfigAccess == NULL) { + return EFI_SUCCESS; + } + + Link = GetFirstNode (&Selection->Form->StatementListHead); + while (!IsNull (&Selection->Form->StatementListHead, Link)) { + Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link); + Link = GetNextNode (&Selection->Form->StatementListHead, Link); + + // + // if Question != NULL, only process the question. Else, process all question in this form. + // + if ((Question != NULL) && (Statement != Question)) { + continue; + } + + if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) { + continue; + } + + // + // Check whether Statement is disabled. + // + if (Statement->Expression != NULL) { + if (EvaluateExpressionList(Statement->Expression, TRUE, Selection->FormSet, Selection->Form) == ExpressDisable) { + continue; + } + } + + HiiValue = &Statement->HiiValue; + TypeValue = &HiiValue->Value; + if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) { + // + // For OrderedList, passing in the value buffer to Callback() + // + TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue; + } + + ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; + Status = ConfigAccess->Callback ( + ConfigAccess, + Action, + Statement->QuestionId, + HiiValue->Type, + TypeValue, + &ActionRequest + ); + if (!EFI_ERROR (Status)) { + // + // Only for EFI_BROWSER_ACTION_CHANGED need to handle this ActionRequest. + // + if (Action == EFI_BROWSER_ACTION_CHANGED) { + switch (ActionRequest) { + case EFI_BROWSER_ACTION_REQUEST_RESET: + gResetRequired = TRUE; + Selection->Action = UI_ACTION_EXIT; + break; + + case EFI_BROWSER_ACTION_REQUEST_SUBMIT: + SubmitFormIsRequired = TRUE; + Selection->Action = UI_ACTION_EXIT; + break; + + case EFI_BROWSER_ACTION_REQUEST_EXIT: + Selection->Action = UI_ACTION_EXIT; + break; + + case EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT: + SubmitFormIsRequired = TRUE; + SettingLevel = FormLevel; + NeedExit = TRUE; + break; + + case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT: + DiscardFormIsRequired = TRUE; + SettingLevel = FormLevel; + NeedExit = TRUE; + break; + + case EFI_BROWSER_ACTION_REQUEST_FORM_APPLY: + SubmitFormIsRequired = TRUE; + SettingLevel = FormLevel; + break; + + case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD: + DiscardFormIsRequired = TRUE; + SettingLevel = FormLevel; + break; + + default: + break; + } + } + + // + // According the spec, return value from call back of "changing" and + // "retrieve" should update to the question's temp buffer. + // + if (Action == EFI_BROWSER_ACTION_CHANGING || Action == EFI_BROWSER_ACTION_RETRIEVE) { + SetQuestionValue(Selection->FormSet, Selection->Form, Statement, GetSetValueWithEditBuffer); + } + } else { + // + // According the spec, return fail from call back of "changing" and + // "retrieve", should restore the question's value. + // + if (Action == EFI_BROWSER_ACTION_CHANGING || Action == EFI_BROWSER_ACTION_RETRIEVE) { + GetQuestionValue(Selection->FormSet, Selection->Form, Statement, GetSetValueWithEditBuffer); + } + + if (Status == EFI_UNSUPPORTED) { + // + // If return EFI_UNSUPPORTED, also consider Hii driver suceess deal with it. + // + Status = EFI_SUCCESS; + } + } + } + + if (SubmitFormIsRequired && !SkipSaveOrDiscard) { + SubmitForm (Selection->FormSet, Selection->Form, SettingLevel); + } + + if (DiscardFormIsRequired && !SkipSaveOrDiscard) { + DiscardForm (Selection->FormSet, Selection->Form, SettingLevel); + } + + if (NeedExit) { + FindNextMenu (Selection, NULL, NULL); + } + + return Status; +} + +/** + Call the retrieve type call back function for one question to get the initialize data. + + This function only used when in the initialize stage, because in this stage, the + Selection->Form is not ready. For other case, use the ProcessCallBackFunction instead. + + @param ConfigAccess The config access protocol produced by the hii driver. + @param Statement The Question which need to call. + + @retval EFI_SUCCESS The call back function excutes successfully. + @return Other value if the call back function failed to excute. +**/ +EFI_STATUS +ProcessRetrieveForQuestion ( + IN EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess, + IN FORM_BROWSER_STATEMENT *Statement + ) +{ + EFI_STATUS Status; + EFI_BROWSER_ACTION_REQUEST ActionRequest; + EFI_HII_VALUE *HiiValue; + EFI_IFR_TYPE_VALUE *TypeValue; + + Status = EFI_SUCCESS; + ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; + + if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) { + return EFI_UNSUPPORTED; + } + + HiiValue = &Statement->HiiValue; + TypeValue = &HiiValue->Value; + if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) { + // + // For OrderedList, passing in the value buffer to Callback() + // + TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue; + } + + ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; + Status = ConfigAccess->Callback ( + ConfigAccess, + EFI_BROWSER_ACTION_RETRIEVE, + Statement->QuestionId, + HiiValue->Type, + TypeValue, + &ActionRequest + ); + return Status; +} + /** The worker function that send the displays to the screen. On output, the selection made by user is returned. @@ -853,18 +1395,13 @@ SetupBrowser ( { EFI_STATUS Status; LIST_ENTRY *Link; - EFI_BROWSER_ACTION_REQUEST ActionRequest; EFI_HANDLE NotifyHandle; - EFI_HII_VALUE *HiiValue; - EFI_IFR_TYPE_VALUE *TypeValue; FORM_BROWSER_STATEMENT *Statement; EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; - FORM_BROWSER_FORMSET *FormSet; EFI_INPUT_KEY Key; gMenuRefreshHead = NULL; - gResetRequired = FALSE; - FormSet = Selection->FormSet; + ConfigAccess = Selection->FormSet->ConfigAccess; // // Register notify for Form package update @@ -881,63 +1418,35 @@ SetupBrowser ( return Status; } - // - // Before display the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN - // - ConfigAccess = Selection->FormSet->ConfigAccess; - if ((ConfigAccess != NULL) && (Selection->Action != UI_ACTION_REFRESH_FORMSET)) { - ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; - mHiiPackageListUpdated = FALSE; - Status = ConfigAccess->Callback ( - ConfigAccess, - EFI_BROWSER_ACTION_FORM_OPEN, - 0, - EFI_IFR_TYPE_UNDEFINED, - NULL, - &ActionRequest - ); - - if (!EFI_ERROR (Status)) { - switch (ActionRequest) { - case EFI_BROWSER_ACTION_REQUEST_RESET: - gResetRequired = TRUE; - break; - - case EFI_BROWSER_ACTION_REQUEST_SUBMIT: - // - // Till now there is no uncommitted data, so ignore this request - // - break; - - case EFI_BROWSER_ACTION_REQUEST_EXIT: - Selection->Action = UI_ACTION_EXIT; - break; - - default: - break; - } - } - - if (mHiiPackageListUpdated) { - // - // IFR is updated during callback, force to reparse the IFR binary - // - mHiiPackageListUpdated = FALSE; - Selection->Action = UI_ACTION_REFRESH_FORMSET; - goto Done; - } - } - // // Initialize current settings of Questions in this FormSet // Status = InitializeCurrentSetting (Selection->FormSet); if (EFI_ERROR (Status)) { - Selection->Action = UI_ACTION_EXIT; goto Done; } + // + // Update gOldFormSet on maintain back up FormSet list. + // And, make gOldFormSet point to current FormSet. + // + if (gOldFormSet != NULL) { + RemoveEntryList (&gOldFormSet->Link); + DestroyFormSet (gOldFormSet); + } + gOldFormSet = Selection->FormSet; + InsertTailList (&gBrowserFormSetList, &gOldFormSet->Link); + do { + // + // IFR is updated, force to reparse the IFR binary + // + if (mHiiPackageListUpdated) { + Selection->Action = UI_ACTION_REFRESH_FORMSET; + mHiiPackageListUpdated = FALSE; + break; + } + // // Initialize Selection->Form // @@ -957,19 +1466,15 @@ SetupBrowser ( // // No Form to display // - return EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; + goto Done; } // // Check Form is suppressed. // if (Selection->Form->SuppressExpression != NULL) { - Status = EvaluateExpression (Selection->FormSet, Selection->Form, Selection->Form->SuppressExpression); - if (EFI_ERROR (Status)) { - return Status; - } - - if (Selection->Form->SuppressExpression->Result.Value.b) { + if (EvaluateExpressionList(Selection->Form->SuppressExpression, TRUE, Selection->FormSet, Selection->Form) == ExpressSuppress) { // // Form is suppressed. // @@ -977,43 +1482,83 @@ SetupBrowser ( CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString); } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); - return EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; + goto Done; } } - + // - // Reset FormPackage update flag + // Before display new form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN + // for each question with callback flag. + // New form may be the first form, or the different form after another form close. // - mHiiPackageListUpdated = FALSE; + if ((ConfigAccess != NULL) && + ((Selection->Handle != mCurrentHiiHandle) || + (!CompareGuid (&Selection->FormSetGuid, &mCurrentFormSetGuid)) || + (Selection->FormId != mCurrentFormId))) { + + // + // Keep current form information + // + mCurrentHiiHandle = Selection->Handle; + CopyGuid (&mCurrentFormSetGuid, &Selection->FormSetGuid); + mCurrentFormId = Selection->FormId; + + Status = ProcessCallBackFunction (Selection, NULL, EFI_BROWSER_ACTION_FORM_OPEN, FALSE); + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // EXIT requests to close form. + // + if (Selection->Action == UI_ACTION_EXIT) { + goto Done; + } + // + // IFR is updated during callback of open form, force to reparse the IFR binary + // + if (mHiiPackageListUpdated) { + Selection->Action = UI_ACTION_REFRESH_FORMSET; + mHiiPackageListUpdated = FALSE; + break; + } + } // // Load Questions' Value for display // Status = LoadFormSetConfig (Selection, Selection->FormSet); if (EFI_ERROR (Status)) { - return Status; + goto Done; } + // + // EXIT requests to close form. + // + if (Selection->Action == UI_ACTION_EXIT) { + goto Done; + } // // IFR is updated during callback of read value, force to reparse the IFR binary // if (mHiiPackageListUpdated) { Selection->Action = UI_ACTION_REFRESH_FORMSET; mHiiPackageListUpdated = FALSE; - goto Done; + break; } // // Displays the Header and Footer borders // - DisplayPageFrame (); + DisplayPageFrame (Selection); // // Display form // Status = DisplayForm (Selection); if (EFI_ERROR (Status)) { - return Status; + goto Done; } // @@ -1025,71 +1570,22 @@ SetupBrowser ( gResetRequired = TRUE; } - // - // Reset FormPackage update flag - // - mHiiPackageListUpdated = FALSE; - - if (((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && (Statement->Operand != EFI_IFR_PASSWORD_OP)) { - ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; - - if (ConfigAccess == NULL) { - return EFI_UNSUPPORTED; - } - - HiiValue = &Statement->HiiValue; - TypeValue = &HiiValue->Value; - if (HiiValue->Type == EFI_IFR_TYPE_STRING) { - // - // Create String in HII database for Configuration Driver to retrieve + if ((ConfigAccess != NULL) && + ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && + (Statement->Operand != EFI_IFR_PASSWORD_OP)) { + Status = ProcessCallBackFunction(Selection, Statement, EFI_BROWSER_ACTION_CHANGING, FALSE); + if (Statement->Operand == EFI_IFR_REF_OP && Selection->Action != UI_ACTION_EXIT) { // - HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle); - } else if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) { + // Process dynamic update ref opcode. // - // For OrderedList, passing in the value buffer to Callback() - // - TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue; - } - - Status = ConfigAccess->Callback ( - ConfigAccess, - EFI_BROWSER_ACTION_CHANGING, - Statement->QuestionId, - HiiValue->Type, - TypeValue, - &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; + if (!EFI_ERROR (Status)) { + Status = ProcessGotoOpCode(Statement, Selection, NULL, NULL); } - } else if (Status != EFI_UNSUPPORTED) { + // - // Callback return error status other than EFI_UNSUPPORTED + // Callback return error status or status return from process goto opcode. // - if (Statement->Operand == EFI_IFR_REF_OP) { + if (EFI_ERROR (Status)) { // // Cross reference will not be taken // @@ -1097,70 +1593,46 @@ SetupBrowser ( Selection->QuestionId = 0; } } - } - // - // Check whether Form Package has been updated during Callback - // - if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) { - // - // Force to reparse IFR binary of target Formset - // - mHiiPackageListUpdated = FALSE; - Selection->Action = UI_ACTION_REFRESH_FORMSET; + if (!EFI_ERROR (Status) && Statement->Operand != EFI_IFR_REF_OP) { + ProcessCallBackFunction(Selection, Statement, EFI_BROWSER_ACTION_CHANGED, FALSE); + } } } - } while (Selection->Action == UI_ACTION_REFRESH_FORM); - // - // Before exit the formset, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE - // - if ((ConfigAccess != NULL) && (Selection->Action == UI_ACTION_EXIT)) { - ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; - Status = ConfigAccess->Callback ( - ConfigAccess, - EFI_BROWSER_ACTION_FORM_CLOSE, - 0, - EFI_IFR_TYPE_UNDEFINED, - NULL, - &ActionRequest - ); - - 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: - gNvUpdateRequired = FALSE; - break; + // + // Before exit the form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_CLOSE + // for each question with callback flag. + // + if ((ConfigAccess != NULL) && + ((Selection->Action == UI_ACTION_EXIT) || + (Selection->Handle != mCurrentHiiHandle) || + (!CompareGuid (&Selection->FormSetGuid, &mCurrentFormSetGuid)) || + (Selection->FormId != mCurrentFormId))) { - default: - break; + Status = ProcessCallBackFunction (Selection, NULL, EFI_BROWSER_ACTION_FORM_CLOSE, FALSE); + if (EFI_ERROR (Status)) { + goto Done; } } - } + } while (Selection->Action == UI_ACTION_REFRESH_FORM); +Done: // - // Record the old formset + // Reset current form information to the initial setting when error happens or form exit. // - if (gOldFormSet != NULL) { - DestroyFormSet (gOldFormSet); + if (EFI_ERROR (Status) || Selection->Action == UI_ACTION_EXIT) { + mCurrentHiiHandle = NULL; + CopyGuid (&mCurrentFormSetGuid, &gZeroGuid); + mCurrentFormId = 0; } - gOldFormSet = FormSet; -Done: // // Unregister notify for Form package update // - Status = mHiiDatabase->UnregisterPackageNotify ( - mHiiDatabase, - NotifyHandle - ); + mHiiDatabase->UnregisterPackageNotify ( + mHiiDatabase, + NotifyHandle + ); return Status; }