mirror of https://github.com/acidanthera/audk.git
Enable the follow feature for string op-code:
1. Show old string before enter new. 2. Enable cursor moves left or right and insert new char or remove the char before the cursor. Signed-off-by:ydong10 Reviewed-by:lgao4 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12231 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
2e7c8ac41d
commit
da58863885
|
@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
@param MenuOption Pointer to the current input menu.
|
@param MenuOption Pointer to the current input menu.
|
||||||
@param Prompt The prompt string shown on popup window.
|
@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_SUCCESS If string input is read successfully
|
||||||
@retval EFI_DEVICE_ERROR If operation fails
|
@retval EFI_DEVICE_ERROR If operation fails
|
||||||
|
@ -28,9 +28,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
ReadString (
|
ReadString (
|
||||||
IN UI_MENU_OPTION *MenuOption,
|
IN UI_MENU_OPTION *MenuOption,
|
||||||
IN CHAR16 *Prompt,
|
IN CHAR16 *Prompt,
|
||||||
OUT CHAR16 *StringPtr
|
IN OUT CHAR16 *StringPtr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
@ -42,11 +42,13 @@ ReadString (
|
||||||
CHAR16 *TempString;
|
CHAR16 *TempString;
|
||||||
CHAR16 *BufferedString;
|
CHAR16 *BufferedString;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
|
UINTN Index2;
|
||||||
UINTN Count;
|
UINTN Count;
|
||||||
UINTN Start;
|
UINTN Start;
|
||||||
UINTN Top;
|
UINTN Top;
|
||||||
UINTN DimensionsWidth;
|
UINTN DimensionsWidth;
|
||||||
UINTN DimensionsHeight;
|
UINTN DimensionsHeight;
|
||||||
|
UINTN CurrentCursor;
|
||||||
BOOLEAN CursorVisible;
|
BOOLEAN CursorVisible;
|
||||||
UINTN Minimum;
|
UINTN Minimum;
|
||||||
UINTN Maximum;
|
UINTN Maximum;
|
||||||
|
@ -98,6 +100,40 @@ ReadString (
|
||||||
CursorVisible = gST->ConOut->Mode->CursorVisible;
|
CursorVisible = gST->ConOut->Mode->CursorVisible;
|
||||||
gST->ConOut->EnableCursor (gST->ConOut, TRUE);
|
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 {
|
do {
|
||||||
Status = WaitForKeyStroke (&Key);
|
Status = WaitForKeyStroke (&Key);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
@ -107,9 +143,15 @@ ReadString (
|
||||||
case CHAR_NULL:
|
case CHAR_NULL:
|
||||||
switch (Key.ScanCode) {
|
switch (Key.ScanCode) {
|
||||||
case SCAN_LEFT:
|
case SCAN_LEFT:
|
||||||
|
if (CurrentCursor > 0) {
|
||||||
|
CurrentCursor--;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCAN_RIGHT:
|
case SCAN_RIGHT:
|
||||||
|
if (CurrentCursor < (GetStringWidth (StringPtr) / 2 - 1)) {
|
||||||
|
CurrentCursor++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCAN_ESC:
|
case SCAN_ESC:
|
||||||
|
@ -152,15 +194,22 @@ ReadString (
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CHAR_BACKSPACE:
|
case CHAR_BACKSPACE:
|
||||||
if (StringPtr[0] != CHAR_NULL) {
|
if (StringPtr[0] != CHAR_NULL && CurrentCursor != 0) {
|
||||||
for (Index = 0; StringPtr[Index] != CHAR_NULL; Index++) {
|
for (Index = 0; Index < CurrentCursor - 1; Index++) {
|
||||||
TempString[Index] = StringPtr[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
|
// Effectively truncate string by 1 character
|
||||||
//
|
//
|
||||||
TempString[Index - 1] = CHAR_NULL;
|
|
||||||
StrCpy (StringPtr, TempString);
|
StrCpy (StringPtr, TempString);
|
||||||
|
CurrentCursor --;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -169,12 +218,23 @@ ReadString (
|
||||||
//
|
//
|
||||||
if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
|
if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
|
||||||
StrnCpy (StringPtr, &Key.UnicodeChar, 1);
|
StrnCpy (StringPtr, &Key.UnicodeChar, 1);
|
||||||
StrnCpy (TempString, &Key.UnicodeChar, 1);
|
CurrentCursor++;
|
||||||
} else if ((GetStringWidth (StringPtr) < ((Maximum + 1) * sizeof (CHAR16))) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
|
} else if ((GetStringWidth (StringPtr) < ((Maximum + 1) * sizeof (CHAR16))) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
|
||||||
KeyPad[0] = Key.UnicodeChar;
|
KeyPad[0] = Key.UnicodeChar;
|
||||||
KeyPad[1] = CHAR_NULL;
|
KeyPad[1] = CHAR_NULL;
|
||||||
StrCat (StringPtr, KeyPad);
|
Count = GetStringWidth (StringPtr) / 2 - 1;
|
||||||
StrCat (TempString, KeyPad);
|
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,7 +269,7 @@ ReadString (
|
||||||
}
|
}
|
||||||
|
|
||||||
gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
|
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);
|
} while (TRUE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -740,6 +740,7 @@ ProcessOptions (
|
||||||
if (Selected) {
|
if (Selected) {
|
||||||
StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));
|
StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));
|
||||||
ASSERT (StringPtr);
|
ASSERT (StringPtr);
|
||||||
|
CopyMem(StringPtr, Question->BufferValue, Maximum * sizeof (CHAR16));
|
||||||
|
|
||||||
Status = ReadString (MenuOption, gPromptForData, StringPtr);
|
Status = ReadString (MenuOption, gPromptForData, StringPtr);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
|
|
|
@ -426,7 +426,7 @@ CreateMultiStringPopUp (
|
||||||
|
|
||||||
@param MenuOption Pointer to the current input menu.
|
@param MenuOption Pointer to the current input menu.
|
||||||
@param Prompt The prompt string shown on popup window.
|
@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_SUCCESS If string input is read successfully
|
||||||
@retval EFI_DEVICE_ERROR If operation fails
|
@retval EFI_DEVICE_ERROR If operation fails
|
||||||
|
@ -434,9 +434,9 @@ CreateMultiStringPopUp (
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
ReadString (
|
ReadString (
|
||||||
IN UI_MENU_OPTION *MenuOption,
|
IN UI_MENU_OPTION *MenuOption,
|
||||||
IN CHAR16 *Prompt,
|
IN CHAR16 *Prompt,
|
||||||
OUT CHAR16 *StringPtr
|
IN OUT CHAR16 *StringPtr
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue