[USETUP]: Instead of defining a special function "DrawInputField" just to draw an input field for entering the partition size number, just use the already existing CONSOLE_SetInputTextXY function (and adapt the calling code because the string buffer for the SetInputTextXY function wants a unicode string). We now have a consistent input UI for usetup.

CORE-9453 #resolve #comment I committed a more elegant solution to this problem.

svn path=/trunk/; revision=67546
This commit is contained in:
Hermès Bélusca-Maïto 2015-05-04 20:50:51 +00:00
parent ac4f5ac401
commit 048d0522f4
2 changed files with 33 additions and 62 deletions

View file

@ -145,13 +145,6 @@ CONSOLE_SetInputTextXY(
IN SHORT len, IN SHORT len,
IN LPCWSTR Text); IN LPCWSTR Text);
VOID
CONSOLE_SetInputTextXY(
IN SHORT x,
IN SHORT y,
IN SHORT len,
IN LPCWSTR Text);
VOID VOID
CONSOLE_SetInvertedTextXY( CONSOLE_SetInvertedTextXY(
IN SHORT x, IN SHORT x,

View file

@ -701,7 +701,7 @@ LanguagePage(PINPUT_RECORD Ir)
else if ((Ir->Event.KeyEvent.uChar.AsciiChar > 0x60) && (Ir->Event.KeyEvent.uChar.AsciiChar < 0x7b)) else if ((Ir->Event.KeyEvent.uChar.AsciiChar > 0x60) && (Ir->Event.KeyEvent.uChar.AsciiChar < 0x7b))
{ {
/* a-z */ /* a-z */
GenericListKeyPress (LanguageList, Ir->Event.KeyEvent.uChar.AsciiChar); GenericListKeyPress(LanguageList, Ir->Event.KeyEvent.uChar.AsciiChar);
RefreshPage = TRUE; RefreshPage = TRUE;
} }
@ -1678,30 +1678,6 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
static VOID
DrawInputField(ULONG FieldLength,
SHORT Left,
SHORT Top,
PCHAR FieldContent)
{
CHAR buf[100];
COORD coPos;
DWORD Written;
coPos.X = Left;
coPos.Y = Top;
memset(buf, '_', sizeof(buf));
buf[FieldLength - strlen(FieldContent)] = 0;
strcat(buf, FieldContent);
WriteConsoleOutputCharacterA(StdOutput,
buf,
strlen(buf),
coPos,
&Written);
}
#define PARTITION_SIZE_INPUT_FIELD_LENGTH 6 #define PARTITION_SIZE_INPUT_FIELD_LENGTH 6
/* Restriction for MaxSize: pow(10, PARTITION_SIZE_INPUT_FIELD_LENGTH)-1 */ /* Restriction for MaxSize: pow(10, PARTITION_SIZE_INPUT_FIELD_LENGTH)-1 */
#define PARTITION_MAXSIZE 999999 #define PARTITION_MAXSIZE 999999
@ -1720,8 +1696,9 @@ ShowPartitionSizeInputBox(SHORT Left,
COORD coPos; COORD coPos;
DWORD Written; DWORD Written;
CHAR Buffer[100]; CHAR Buffer[100];
WCHAR PartitionSizeBuffer[100];
ULONG Index; ULONG Index;
CHAR ch; WCHAR ch;
SHORT iLeft; SHORT iLeft;
SHORT iTop; SHORT iTop;
@ -1742,7 +1719,7 @@ ShowPartitionSizeInputBox(SHORT Left,
WriteConsoleOutputCharacterA(StdOutput, WriteConsoleOutputCharacterA(StdOutput,
Buffer, Buffer,
strlen (Buffer), strlen(Buffer),
coPos, coPos,
&Written); &Written);
@ -1751,16 +1728,16 @@ ShowPartitionSizeInputBox(SHORT Left,
coPos.Y = iTop; coPos.Y = iTop;
WriteConsoleOutputCharacterA(StdOutput, WriteConsoleOutputCharacterA(StdOutput,
Buffer, Buffer,
strlen (Buffer), strlen(Buffer),
coPos, coPos,
&Written); &Written);
sprintf(Buffer, "%lu", MaxSize); swprintf(PartitionSizeBuffer, L"%lu", MaxSize);
Index = strlen(Buffer); Index = wcslen(PartitionSizeBuffer);
DrawInputField(PARTITION_SIZE_INPUT_FIELD_LENGTH, CONSOLE_SetInputTextXY(iLeft,
iLeft,
iTop, iTop,
Buffer); PARTITION_SIZE_INPUT_FIELD_LENGTH,
PartitionSizeBuffer);
while (TRUE) while (TRUE)
{ {
@ -1772,7 +1749,7 @@ ShowPartitionSizeInputBox(SHORT Left,
if (Quit != NULL) if (Quit != NULL)
*Quit = TRUE; *Quit = TRUE;
Buffer[0] = 0; PartitionSizeBuffer[0] = 0;
break; break;
} }
else if (Ir.Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */ else if (Ir.Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
@ -1784,40 +1761,41 @@ ShowPartitionSizeInputBox(SHORT Left,
if (Cancel != NULL) if (Cancel != NULL)
*Cancel = TRUE; *Cancel = TRUE;
Buffer[0] = 0; PartitionSizeBuffer[0] = 0;
break; break;
} }
else if ((Ir.Event.KeyEvent.wVirtualKeyCode == VK_BACK) && /* BACKSPACE */ else if ((Ir.Event.KeyEvent.wVirtualKeyCode == VK_BACK) && /* BACKSPACE */
(Index > 0)) (Index > 0))
{ {
Index--; Index--;
Buffer[Index] = 0; PartitionSizeBuffer[Index] = 0;
DrawInputField(PARTITION_SIZE_INPUT_FIELD_LENGTH, CONSOLE_SetInputTextXY(iLeft,
iLeft,
iTop, iTop,
Buffer); PARTITION_SIZE_INPUT_FIELD_LENGTH,
PartitionSizeBuffer);
} }
else if ((Ir.Event.KeyEvent.uChar.AsciiChar != 0x00) && else if ((Ir.Event.KeyEvent.uChar.AsciiChar != 0x00) &&
(Index < PARTITION_SIZE_INPUT_FIELD_LENGTH)) (Index < PARTITION_SIZE_INPUT_FIELD_LENGTH))
{ {
ch = Ir.Event.KeyEvent.uChar.AsciiChar; ch = (WCHAR)Ir.Event.KeyEvent.uChar.AsciiChar;
if ((ch >= '0') && (ch <= '9')) if ((ch >= L'0') && (ch <= L'9'))
{ {
Buffer[Index] = ch; PartitionSizeBuffer[Index] = ch;
Index++; Index++;
Buffer[Index] = 0; PartitionSizeBuffer[Index] = 0;
DrawInputField(PARTITION_SIZE_INPUT_FIELD_LENGTH, CONSOLE_SetInputTextXY(iLeft,
iLeft,
iTop, iTop,
Buffer); PARTITION_SIZE_INPUT_FIELD_LENGTH,
PartitionSizeBuffer);
} }
} }
} }
strcpy(InputBuffer, Buffer); /* Convert UNICODE --> ANSI the poor man's way */
sprintf(InputBuffer, "%S", PartitionSizeBuffer);
} }