X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FSetupBrowserDxe%2FInputHandler.c;h=844590770a68d9a867bf4294dc189a48dad2dc67;hb=61f1b7c51e77b71c0101d4af172aee1d08a1096c;hp=8f3b9e72dc61f4699c1c587df8f317606ea239ac;hpb=c3342aa81fabe01d70520a987bd15b018eb117ce;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c b/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c index 8f3b9e72dc..844590770a 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/InputHandler.c @@ -1,7 +1,7 @@ /** @file Implementation for handling user input from the User Interfaces. -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2012, 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 @@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @param MenuOption Pointer to the current input menu. @param Prompt The prompt string shown on popup window. - @param StringPtr Destination for use input string. + @param StringPtr Old user input and destination for use input string. @retval EFI_SUCCESS If string input is read successfully @retval EFI_DEVICE_ERROR If operation fails @@ -28,9 +28,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ EFI_STATUS ReadString ( - IN UI_MENU_OPTION *MenuOption, - IN CHAR16 *Prompt, - OUT CHAR16 *StringPtr + IN UI_MENU_OPTION *MenuOption, + IN CHAR16 *Prompt, + IN OUT CHAR16 *StringPtr ) { EFI_STATUS Status; @@ -42,11 +42,13 @@ ReadString ( CHAR16 *TempString; CHAR16 *BufferedString; UINTN Index; + UINTN Index2; UINTN Count; UINTN Start; UINTN Top; UINTN DimensionsWidth; UINTN DimensionsHeight; + UINTN CurrentCursor; BOOLEAN CursorVisible; UINTN Minimum; UINTN Maximum; @@ -98,6 +100,40 @@ ReadString ( CursorVisible = gST->ConOut->Mode->CursorVisible; gST->ConOut->EnableCursor (gST->ConOut, TRUE); + CurrentCursor = GetStringWidth (StringPtr) / 2 - 1; + if (CurrentCursor != 0) { + // + // Show the string which has beed saved before. + // + SetUnicodeMem (BufferedString, ScreenSize - 1, L' '); + PrintStringAt (Start + 1, Top + 3, BufferedString); + + if ((GetStringWidth (StringPtr) / 2) > (DimensionsWidth - 2)) { + Index = (GetStringWidth (StringPtr) / 2) - DimensionsWidth + 2; + } else { + Index = 0; + } + + if (IsPassword) { + gST->ConOut->SetCursorPosition (gST->ConOut, Start + 1, Top + 3); + } + + for (Count = 0; Index + 1 < GetStringWidth (StringPtr) / 2; Index++, Count++) { + BufferedString[Count] = StringPtr[Index]; + + if (IsPassword) { + PrintChar (L'*'); + } + } + + if (!IsPassword) { + PrintStringAt (Start + 1, Top + 3, BufferedString); + } + + gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK)); + gST->ConOut->SetCursorPosition (gST->ConOut, Start + GetStringWidth (StringPtr) / 2, Top + 3); + } + do { Status = WaitForKeyStroke (&Key); ASSERT_EFI_ERROR (Status); @@ -107,9 +143,15 @@ ReadString ( case CHAR_NULL: switch (Key.ScanCode) { case SCAN_LEFT: + if (CurrentCursor > 0) { + CurrentCursor--; + } break; case SCAN_RIGHT: + if (CurrentCursor < (GetStringWidth (StringPtr) / 2 - 1)) { + CurrentCursor++; + } break; case SCAN_ESC: @@ -152,15 +194,22 @@ ReadString ( break; case CHAR_BACKSPACE: - if (StringPtr[0] != CHAR_NULL) { - for (Index = 0; StringPtr[Index] != CHAR_NULL; Index++) { + if (StringPtr[0] != CHAR_NULL && CurrentCursor != 0) { + for (Index = 0; Index < CurrentCursor - 1; Index++) { TempString[Index] = StringPtr[Index]; } + Count = GetStringWidth (StringPtr) / 2 - 1; + if (Count >= CurrentCursor) { + for (Index = CurrentCursor - 1, Index2 = CurrentCursor; Index2 < Count; Index++, Index2++) { + TempString[Index] = StringPtr[Index2]; + } + TempString[Index] = CHAR_NULL; + } // // Effectively truncate string by 1 character // - TempString[Index - 1] = CHAR_NULL; StrCpy (StringPtr, TempString); + CurrentCursor --; } default: @@ -169,12 +218,23 @@ ReadString ( // if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) { StrnCpy (StringPtr, &Key.UnicodeChar, 1); - StrnCpy (TempString, &Key.UnicodeChar, 1); + CurrentCursor++; } else if ((GetStringWidth (StringPtr) < ((Maximum + 1) * sizeof (CHAR16))) && (Key.UnicodeChar != CHAR_BACKSPACE)) { KeyPad[0] = Key.UnicodeChar; KeyPad[1] = CHAR_NULL; - StrCat (StringPtr, KeyPad); - StrCat (TempString, KeyPad); + Count = GetStringWidth (StringPtr) / 2 - 1; + if (CurrentCursor < Count) { + for (Index = 0; Index < CurrentCursor; Index++) { + TempString[Index] = StringPtr[Index]; + } + TempString[Index] = CHAR_NULL; + StrCat (TempString, KeyPad); + StrCat (TempString, StringPtr + CurrentCursor); + StrCpy (StringPtr, TempString); + } else { + StrCat (StringPtr, KeyPad); + } + CurrentCursor++; } // @@ -209,11 +269,75 @@ ReadString ( } gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK)); - gST->ConOut->SetCursorPosition (gST->ConOut, Start + GetStringWidth (StringPtr) / 2, Top + 3); + gST->ConOut->SetCursorPosition (gST->ConOut, Start + CurrentCursor + 1, Top + 3); } while (TRUE); } +/** + Adjust the value to the correct one. Rules follow the sample: + like: Year change: 2012.02.29 -> 2013.02.29 -> 2013.02.01 + Month change: 2013.03.29 -> 2013.02.29 -> 2013.02.28 + + @param Question Pointer to current question. + @param Sequence The sequence of the field in the question. +**/ +VOID +AdjustQuestionValue ( + IN FORM_BROWSER_STATEMENT *Question, + IN UINT8 Sequence + ) +{ + UINT8 Month; + UINT16 Year; + UINT8 Maximum; + UINT8 Minimum; + + if (Question->Operand != EFI_IFR_DATE_OP) { + return; + } + + Month = Question->HiiValue.Value.date.Month; + Year = Question->HiiValue.Value.date.Year; + Minimum = 1; + + switch (Month) { + case 2: + if ((Year % 4) == 0 && ((Year % 100) != 0 || (Year % 400) == 0)) { + Maximum = 29; + } else { + Maximum = 28; + } + break; + case 4: + case 6: + case 9: + case 11: + Maximum = 30; + break; + default: + Maximum = 31; + break; + } + + // + // Change the month area. + // + if (Sequence == 0) { + if (Question->HiiValue.Value.date.Day > Maximum) { + Question->HiiValue.Value.date.Day = Maximum; + } + } + + // + // Change the Year area. + // + if (Sequence == 2) { + if (Question->HiiValue.Value.date.Day > Maximum) { + Question->HiiValue.Value.date.Day = Minimum; + } + } +} /** This routine reads a numeric value from the user input. @@ -602,6 +726,16 @@ TheKey2: EnterCarriageReturn: case CHAR_CARRIAGE_RETURN: + // + // Validate input value with Minimum value. + // + if (EditValue < Minimum) { + UpdateStatusBar (Selection, INPUT_ERROR, Question->QuestionFlags, TRUE); + break; + } else { + UpdateStatusBar (Selection, INPUT_ERROR, Question->QuestionFlags, FALSE); + } + // // Store Edit value back to Question // @@ -646,6 +780,16 @@ EnterCarriageReturn: QuestionValue->Value.u64 = EditValue; } + // + // Adjust the value to the correct one. + // Sample like: 2012.02.29 -> 2013.02.29 -> 2013.02.01 + // 2013.03.29 -> 2013.02.29 -> 2013.02.28 + // + if (Question->Operand == EFI_IFR_DATE_OP && + (MenuOption->Sequence == 0 || MenuOption->Sequence == 2)) { + AdjustQuestionValue (Question, (UINT8)MenuOption->Sequence); + } + // // Check to see if the Value is something reasonable against consistency limitations. // If not, let's kick the error specified. @@ -655,9 +799,9 @@ EnterCarriageReturn: // // Input value is not valid, restore Question Value // - GetQuestionValue (FormSet, Form, Question, TRUE); + GetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer); } else { - SetQuestionValue (FormSet, Form, Question, TRUE); + SetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer); if (!DateOrTime || (Question->Storage != NULL)) { // // NV flag is unnecessary for RTC type of Date/Time @@ -797,6 +941,7 @@ GetSelectionInputPopUp ( QUESTION_OPTION *OneOfOption; QUESTION_OPTION *CurrentOption; FORM_BROWSER_STATEMENT *Question; + INTN Result; DimensionsWidth = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn; @@ -842,48 +987,49 @@ GetSelectionInputPopUp ( } // - // Prepare HiiValue array + // Move valid Option to list head. // - HiiValueArray = AllocateZeroPool (OptionCount * sizeof (EFI_HII_VALUE)); - ASSERT (HiiValueArray != NULL); - Link = GetFirstNode (&Question->OptionListHead); - for (Index = 0; Index < OptionCount; Index++) { - if (OrderedList) { + PopUpMenuLines = 0; + if (OrderedList) { + // + // Prepare HiiValue array + // + HiiValueArray = AllocateZeroPool (OptionCount * sizeof (EFI_HII_VALUE)); + ASSERT (HiiValueArray != NULL); + for (Index = 0; Index < OptionCount; Index++) { HiiValueArray[Index].Type = ValueType; HiiValueArray[Index].Value.u64 = GetArrayData (ValueArray, ValueType, Index); - } else { - OneOfOption = QUESTION_OPTION_FROM_LINK (Link); - CopyMem (&HiiValueArray[Index], &OneOfOption->Value, sizeof (EFI_HII_VALUE)); - Link = GetNextNode (&Question->OptionListHead, Link); } - } - // - // Move Suppressed Option to list tail - // - PopUpMenuLines = 0; - for (Index = 0; Index < OptionCount; Index++) { - OneOfOption = ValueToOption (Question, &HiiValueArray[OptionCount - Index - 1]); - if (OneOfOption == NULL) { - return EFI_NOT_FOUND; - } + for (Index = 0; Index < OptionCount; Index++) { + OneOfOption = ValueToOption (Question, &HiiValueArray[OptionCount - Index - 1]); + if (OneOfOption == NULL) { + return EFI_NOT_FOUND; + } - RemoveEntryList (&OneOfOption->Link); + RemoveEntryList (&OneOfOption->Link); - if ((OneOfOption->SuppressExpression != NULL) && - (OneOfOption->SuppressExpression->Result.Value.b)) { - // - // This option is suppressed, insert to tail // - InsertTailList (&Question->OptionListHead, &OneOfOption->Link); - } else { - // - // Insert to head + // Insert to head. // InsertHeadList (&Question->OptionListHead, &OneOfOption->Link); PopUpMenuLines++; } + + FreePool (HiiValueArray); + } else { + Link = GetFirstNode (&Question->OptionListHead); + for (Index = 0; Index < OptionCount; Index++) { + OneOfOption = QUESTION_OPTION_FROM_LINK (Link); + Link = GetNextNode (&Question->OptionListHead, Link); + if ((OneOfOption->SuppressExpression != NULL) && + EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) > ExpressFalse) { + continue; + } else { + PopUpMenuLines++; + } + } } // @@ -894,6 +1040,13 @@ GetSelectionInputPopUp ( Link = GetFirstNode (&Question->OptionListHead); for (Index = 0; Index < PopUpMenuLines; Index++) { OneOfOption = QUESTION_OPTION_FROM_LINK (Link); + Link = GetNextNode (&Question->OptionListHead, Link); + + if (!OrderedList && (OneOfOption->SuppressExpression != NULL) && + EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) > ExpressFalse) { + Index--; + continue; + } StringPtr = GetToken (OneOfOption->Text, MenuOption->Handle); if (StrLen (StringPtr) > PopUpWidth) { @@ -901,14 +1054,12 @@ GetSelectionInputPopUp ( } FreePool (StringPtr); - if (!OrderedList && CompareHiiValue (&Question->HiiValue, &OneOfOption->Value, NULL) == 0) { + if (!OrderedList && (CompareHiiValue (&Question->HiiValue, &OneOfOption->Value, &Result, NULL) == EFI_SUCCESS) && (Result == 0)) { // // Find current selected Option for OneOf // HighlightOptionIndex = Index; } - - Link = GetNextNode (&Question->OptionListHead, Link); } // @@ -926,7 +1077,7 @@ GetSelectionInputPopUp ( Start = (DimensionsWidth - PopUpWidth - POPUP_FRAME_WIDTH) / 2 + gScreenDimensions.LeftColumn; End = Start + PopUpWidth + POPUP_FRAME_WIDTH; Top = gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT; - Bottom = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT - 1; + Bottom = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight - 1; MenuLinesInView = Bottom - Top - 1; if (MenuLinesInView >= PopUpMenuLines) { @@ -977,6 +1128,13 @@ GetSelectionInputPopUp ( Link = GetFirstNode (&Question->OptionListHead); for (Index = 0; Index < TopOptionIndex; Index++) { Link = GetNextNode (&Question->OptionListHead, Link); + + OneOfOption = QUESTION_OPTION_FROM_LINK (Link); + if (!OrderedList && (OneOfOption->SuppressExpression != NULL) && + EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) > ExpressFalse) { + Index--; + continue; + } } // @@ -987,7 +1145,14 @@ GetSelectionInputPopUp ( OneOfOption = QUESTION_OPTION_FROM_LINK (Link); Link = GetNextNode (&Question->OptionListHead, Link); + if (!OrderedList && (OneOfOption->SuppressExpression != NULL) && + EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) > ExpressFalse) { + Index--; + continue; + } + StringPtr = GetToken (OneOfOption->Text, MenuOption->Handle); + ASSERT (StringPtr != NULL); // // If the string occupies multiple lines, truncate it to fit in one line, // and append a "..." for indication. @@ -1164,7 +1329,6 @@ TheKey: } } - FreePool (HiiValueArray); return EFI_DEVICE_ERROR; default: @@ -1182,6 +1346,12 @@ TheKey: Link = GetFirstNode (&Question->OptionListHead); while (!IsNull (&Question->OptionListHead, Link)) { OneOfOption = QUESTION_OPTION_FROM_LINK (Link); + Link = GetNextNode (&Question->OptionListHead, Link); + + if ((OneOfOption->SuppressExpression != NULL) && + EvaluateExpressionList(OneOfOption->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) { + continue; + } SetArrayData (ValueArray, ValueType, Index, OneOfOption->Value.Value.u64); @@ -1189,8 +1359,6 @@ TheKey: if (Index > Question->MaxContainers) { break; } - - Link = GetNextNode (&Question->OptionListHead, Link); } } else { ASSERT (CurrentOption != NULL); @@ -1198,16 +1366,15 @@ TheKey: } gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute); - FreePool (HiiValueArray); Status = ValidateQuestion (Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF); if (EFI_ERROR (Status)) { // // Input value is not valid, restore Question Value // - GetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE); + GetQuestionValue (Selection->FormSet, Selection->Form, Question, GetSetValueWithEditBuffer); } else { - SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE); + SetQuestionValue (Selection->FormSet, Selection->Form, Question, GetSetValueWithEditBuffer); UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE); } @@ -1235,10 +1402,17 @@ WaitForKeyStroke ( { EFI_STATUS Status; - do { - UiWaitForSingleEvent (gST->ConIn->WaitForKey, 0, 0); + while (TRUE) { Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key); - } while (EFI_ERROR(Status)); + if (!EFI_ERROR (Status)) { + break; + } + + if (Status != EFI_NOT_READY) { + continue; + } + UiWaitForSingleEvent (gST->ConIn->WaitForKey, 0, 0); + } return Status; }