mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-12 08:00:55 +02:00
Fix for text input
This commit is contained in:
+15
-13
@@ -345,10 +345,9 @@ void EditClass::Draw_Text(char const * text)
|
||||
*=============================================================================================*/
|
||||
bool EditClass::Handle_Key(KeyNumType key, unsigned flags)
|
||||
{
|
||||
unsigned char testAscii = UserInput.KeyB.ASCII;
|
||||
//if (key & KN_SHIFT_BIT || key & KN_CAPSLOCK_BIT) testAscii = toupper(testAscii);
|
||||
unsigned rawKey = key & 0xff;
|
||||
|
||||
switch (key & 0xff) {
|
||||
switch (rawKey) {
|
||||
/*
|
||||
** Handle the special case of a non-keyboard event. It is possible that this
|
||||
** key code might be passed to this routine if this routine has been overridden
|
||||
@@ -357,6 +356,7 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags)
|
||||
case 0:
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
** If the return key is pressed, then remove the focus from this edit
|
||||
** gadget but otherwise let the normal gadget processing proceed. This
|
||||
@@ -384,11 +384,13 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags)
|
||||
** if it can legally be added to the edit string and do so if possible.
|
||||
*/
|
||||
default:
|
||||
unsigned char keyAscii = UserInput.KeyB.ASCII;
|
||||
if (key & KN_SHIFT_BIT || key & KN_CAPSLOCK_BIT) keyAscii = toupper(keyAscii);
|
||||
|
||||
/*
|
||||
** Don't add a character if the length is greater than edit width.
|
||||
*/
|
||||
if (((int)String_Pixel_Width(String) + (int)Char_Pixel_Width(testAscii) ) >= (Width-2)) {
|
||||
if (((int)String_Pixel_Width(String) + (int)Char_Pixel_Width(keyAscii) ) >= (Width-2)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -401,21 +403,21 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags)
|
||||
** Invisible characters are never added to the string. This is
|
||||
** especially true for spaces at the beginning of the string.
|
||||
*/
|
||||
if (!isgraph(testAscii) && testAscii != ' ') break;
|
||||
if (testAscii == ' ' && Length == 0) break;
|
||||
if (!isgraph(keyAscii) && keyAscii != ' ') break;
|
||||
if (keyAscii == ' ' && Length == 0) break;
|
||||
|
||||
/*
|
||||
** If this is an upper case only edit gadget, then force the alphabetic
|
||||
** character to upper case.
|
||||
*/
|
||||
if ((EditFlags & UPPERCASE) && isalpha(testAscii)) {
|
||||
testAscii = (KeyASCIIType)toupper(testAscii);
|
||||
if ((EditFlags & UPPERCASE) && isalpha(keyAscii)) {
|
||||
rawKey = (KeyASCIIType)toupper(keyAscii);
|
||||
}
|
||||
|
||||
if ((!(EditFlags & NUMERIC) || !isdigit(testAscii)) &&
|
||||
(!(EditFlags & ALPHA) || !isalpha(testAscii)) &&
|
||||
(!(EditFlags & MISC) || isalnum(testAscii)) &&
|
||||
testAscii != ' ') {
|
||||
if ((!(EditFlags & NUMERIC) || !isdigit(keyAscii)) &&
|
||||
(!(EditFlags & ALPHA) || !isalpha(keyAscii)) &&
|
||||
(!(EditFlags & MISC) || isalnum(keyAscii)) &&
|
||||
rawKey != ' ') {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -425,7 +427,7 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags)
|
||||
** because the event flag has been cleared. This prevents the gadget's ID
|
||||
** number from being returned just because the gadget has been edited.
|
||||
*/
|
||||
String[Length++] = testAscii;
|
||||
String[Length++] = keyAscii;
|
||||
String[Length] = '\0';
|
||||
|
||||
Flag_To_Redraw();
|
||||
|
||||
Reference in New Issue
Block a user