Browse Source

Use unicode for key events despite the fact that our current Plasma20 fonts only support latin-1

Adam Johnson 14 years ago committed by Branan Purvine-Riley
parent
commit
a29a7deda0
  1. 7
      Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp
  2. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp
  3. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h
  4. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp
  5. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h
  6. 4
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp
  7. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h
  8. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp
  9. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h
  10. 4
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp
  11. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h
  12. 5
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp
  13. 2
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h
  14. 2
      Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp
  15. 117
      Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp
  16. 2
      Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h

7
Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp

@ -519,7 +519,8 @@ hsBool pfConsole::MsgReceive( plMessage *msg )
void pfConsole::IHandleKey( plKeyEventMsg *msg )
{
char *c, key;
char *c;
wchar_t key;
int i,eol;
static hsBool findAgain = false;
static UInt32 findCounter = 0;
@ -831,13 +832,13 @@ void pfConsole::IHandleKey( plKeyEventMsg *msg )
{
key = plKeyboardDevice::KeyEventToChar( msg );
// do they want to go into help mode?
if( !fPythonMode && key == '?' && fWorkingCursor == 0 )
if( !fPythonMode && key == L'?' && fWorkingCursor == 0 )
{
/// Go into help mode
fHelpMode = true;
}
// do they want to go into Python mode?
else if( !fHelpMode && key == '\\' && fWorkingCursor == 0 )
else if( !fHelpMode && key == L'\\' && fWorkingCursor == 0 )
{
// toggle Python mode
fPythonMode = fPythonMode ? false:true;

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp

@ -879,7 +879,7 @@ void pfGUIControlMod::Write( hsStream *s, hsResMgr *mgr )
//// HandleKeyPress/Event ////////////////////////////////////////////////////
hsBool pfGUIControlMod::HandleKeyPress( char key, UInt8 modifiers )
hsBool pfGUIControlMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{
return false;
}

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h

@ -193,7 +193,7 @@ class pfGUIControlMod : public plSingleModifier
virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers ) {;}
virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers ) {;}
virtual hsBool HandleKeyPress( char key, UInt8 modifiers );
virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
void SetHandler( pfGUICtrlProcObject *h ) { ISetHandler( h, true ); }

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp

@ -551,7 +551,7 @@ hsBool pfGUIDialogMod::HandleKeyEvent( pfGameGUIMgr::EventType event, plKey
//// HandleKeyPress //////////////////////////////////////////////////////////
hsBool pfGUIDialogMod::HandleKeyPress( char key, UInt8 modifiers )
hsBool pfGUIDialogMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{
// Same deal as HandleKeyPress. Only problem is, we needed the msg to translate
// to a char, so it had to be done up at the mgr level (sadly)

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.h

@ -119,7 +119,7 @@ class pfGUIDialogMod : public plSingleModifier
virtual hsBool HandleMouseEvent( pfGameGUIMgr::EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers );
hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
hsBool HandleKeyPress( char key, UInt8 modifiers );
hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
void UpdateInterestingThings( hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, hsBool modalPreset );
void SetControlOfInterest( pfGUIControlMod *c );

4
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp

@ -277,10 +277,8 @@ void pfGUIEditBoxMod::HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers )
{
}
hsBool pfGUIEditBoxMod::HandleKeyPress( char inKey, UInt8 modifiers )
hsBool pfGUIEditBoxMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{
wchar_t key = (wchar_t)inKey;
if( fBuffer == nil )
return false;

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h

@ -90,7 +90,7 @@ class pfGUIEditBoxMod : public pfGUIControlMod
virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers );
virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers );
virtual hsBool HandleKeyPress( char key, UInt8 modifiers );
virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
virtual void PurgeDynaTextMapImage();

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp

@ -905,7 +905,7 @@ void pfGUIListBoxMod::AddSelection( Int32 item )
//// HandleKeyPress //////////////////////////////////////////////////////////
hsBool pfGUIListBoxMod::HandleKeyPress( char key, UInt8 modifiers )
hsBool pfGUIListBoxMod::HandleKeyPress( wchar_t key, UInt8 modifiers )
{
return false;
}

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.h

@ -133,7 +133,7 @@ class pfGUIListBoxMod : public pfGUIControlMod
virtual void HandleMouseHover( hsPoint3 &mousePt, UInt8 modifiers );
virtual void HandleMouseDblClick( hsPoint3 &mousePt, UInt8 modifiers );
virtual hsBool HandleKeyPress( char key, UInt8 modifiers );
virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
virtual hsBool FilterMousePosition( hsPoint3 &mousePt );

4
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp

@ -1072,10 +1072,8 @@ void pfGUIMultiLineEditCtrl::HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifi
IMoveCursorTo( IPointToPosition( (Int16)(mousePt.fX), (Int16)(mousePt.fY) ) );
}
hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( char keyIn, UInt8 modifiers )
hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( wchar_t key, UInt8 modifiers )
{
wchar_t key = (wchar_t)keyIn;
if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine()))
return true; // we're ignoring if we can't actually edit our visible frame (and we're linked)

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h

@ -195,7 +195,7 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod
virtual void HandleMouseUp( hsPoint3 &mousePt, UInt8 modifiers );
virtual void HandleMouseDrag( hsPoint3 &mousePt, UInt8 modifiers );
virtual hsBool HandleKeyPress( char key, UInt8 modifiers );
virtual hsBool HandleKeyPress( wchar_t key, UInt8 modifiers );
virtual hsBool HandleKeyEvent( pfGameGUIMgr::EventType event, plKeyDef key, UInt8 modifiers );
virtual void PurgeDynaTextMapImage();

5
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp

@ -594,10 +594,13 @@ hsBool pfGameGUIMgr::IHandleKeyEvt( EventType event, plKeyDef key, UInt8 modifi
// Like IHandleKeyPress, but takes in a char for distributing actual
// characters typed.
hsBool pfGameGUIMgr::IHandleKeyPress( char key, UInt8 modifiers )
hsBool pfGameGUIMgr::IHandleKeyPress( wchar_t key, UInt8 modifiers )
{
pfGUIDialogMod *dlg;
// Really... Don't handle any nil keypresses
if (key == nil)
return false;
for( dlg = fActiveDialogs; dlg != nil; dlg = dlg->GetNext() )
{

2
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.h

@ -153,7 +153,7 @@ class pfGameGUIMgr : public hsKeyedObject
hsBool IHandleMouse( EventType event, hsScalar mouseX, hsScalar mouseY, UInt8 modifiers, UInt32 *desiredCursor );
hsBool IHandleKeyEvt( EventType event, plKeyDef key, UInt8 modifiers );
hsBool IHandleKeyPress( char key, UInt8 modifiers );
hsBool IHandleKeyPress( wchar_t key, UInt8 modifiers );
hsBool IModalBlocking( void );

2
Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp

@ -890,7 +890,7 @@ void plPythonFileMod::RemoveTarget(plSceneObject* so)
void plPythonFileMod::HandleDiscardedKey( plKeyEventMsg *msg )
{
// So OnDefaultKeyCaught takes two parameters: the key character pressed and a boolean saying up or down
char keyChar = plKeyboardDevice::KeyEventToChar( msg );
wchar_t keyChar = plKeyboardDevice::KeyEventToChar( msg );
// if the caps lock is down then reverse upper and lowercase
if ( msg->GetCapsLockKeyDown() )

117
Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp

@ -204,120 +204,43 @@ void plKeyboardDevice::HandleWindowActivate(bool bActive, HWND hWnd)
//// KeyEventToChar //////////////////////////////////////////////////////////
// Translate a Plasma key event to an actual char
char plKeyboardDevice::KeyEventToChar( plKeyEventMsg *msg )
wchar_t plKeyboardDevice::KeyEventToChar( plKeyEventMsg *msg )
{
short code = msg->GetKeyCode();
char c = 0;
unsigned int code = msg->GetKeyCode();
wchar_t c = 0;
unsigned char kbState[256];
unsigned char buffer[256];
UINT scanCode;
wchar_t buffer[256];
unsigned int scanCode;
int retVal;
buffer[0] = 0;
switch( code )
{
case KEY_A:
case KEY_B:
case KEY_C:
case KEY_D:
case KEY_E:
case KEY_F:
case KEY_G:
case KEY_H:
case KEY_I:
case KEY_J:
case KEY_K:
case KEY_L:
case KEY_M:
case KEY_N:
case KEY_O:
case KEY_P:
case KEY_Q:
case KEY_R:
case KEY_S:
case KEY_T:
case KEY_U:
case KEY_V:
case KEY_W:
case KEY_X:
case KEY_Y:
case KEY_Z:
case KEY_1:
case KEY_2:
case KEY_3:
case KEY_4:
case KEY_5:
case KEY_6:
case KEY_7:
case KEY_8:
case KEY_9:
case KEY_0:
case KEY_TILDE:
case KEY_COMMA:
case KEY_PERIOD:
case KEY_LBRACKET:
case KEY_RBRACKET:
case KEY_BACKSLASH:
case KEY_SLASH:
case KEY_DASH:
case KEY_EQUAL:
case KEY_SEMICOLON:
case KEY_QUOTE:
// let windows translate everything for us!
scanCode = MapVirtualKeyEx(code,0,GetKeyboardLayout(0));
scanCode = MapVirtualKeyW(code, 0);
GetKeyboardState(kbState);
if (fIgnoreCapsLock)
kbState[KEY_CAPSLOCK] = 0; // clear the caps lock key
retVal = ToAsciiEx(code,scanCode,kbState,(unsigned short*)buffer,0,GetKeyboardLayout(0));
if (retVal == 2)
retVal = ToUnicode(code, scanCode, kbState, (wchar_t*)buffer, 256, 0);
if (retVal == -1)
{
if ((buffer[0] == buffer[1]) && (!fKeyIsDeadKey))
{
// it's actually a dead key, since the previous key wasn't a dead key
c = (char)buffer[0];
// It's a stored dead key.
c = 0;
fKeyIsDeadKey = true;
}
else
{
c = (char)buffer[1]; // it was an untranslated dead key, so copy the unconverted key
fKeyIsDeadKey = false;
}
}
else if (retVal == 0)
c = 0; // it's invalid
else
// Invalid crap
c = 0;
else if (retVal == 1)
{
c = (char)buffer[0];
if (retVal < 0) // the key was a dead key
fKeyIsDeadKey = true;
else
// Exactly one good character
fKeyIsDeadKey = false;
c = buffer[0];
}
break;
case KEY_ESCAPE: c = 27; break;
case KEY_TAB: c = '\t'; break;
case KEY_BACKSPACE: c = 8; break;
case KEY_ENTER: c = '\n'; break;
case KEY_SPACE: c = ' '; break;
// numlock on numbers
case KEY_NUMPAD0: c = '0'; break;
case KEY_NUMPAD1: c = '1'; break;
case KEY_NUMPAD2: c = '2'; break;
case KEY_NUMPAD3: c = '3'; break;
case KEY_NUMPAD4: c = '4'; break;
case KEY_NUMPAD5: c = '5'; break;
case KEY_NUMPAD6: c = '6'; break;
case KEY_NUMPAD7: c = '7'; break;
case KEY_NUMPAD8: c = '8'; break;
case KEY_NUMPAD9: c = '9'; break;
// everything else
default:
c = 0;
break;
else if (retVal >= 2)
{
fKeyIsDeadKey = !fKeyIsDeadKey;
if (!fKeyIsDeadKey)
c = buffer[0];
}
return c;

2
Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.h

@ -113,7 +113,7 @@ public:
static plKeyboardDevice* GetInstance() { return fInstance; }
static char KeyEventToChar( plKeyEventMsg *msg );
static wchar_t KeyEventToChar( plKeyEventMsg *msg );
};
class plPlate;

Loading…
Cancel
Save