From 5bd22e191228518acad7a2ef2f56fff474957f22 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Mon, 27 Feb 2012 20:29:10 +0100 Subject: [PATCH] Filter WM_CHAR messages with control characters. Fix multiline edit input for keyboard layouts using alt key --- .../pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp | 10 +++++++--- .../Plasma/PubUtilLib/plInputCore/plInputManager.cpp | 12 ++++++------ .../Plasma/PubUtilLib/plInputCore/plInputManager.h | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp index 1db3a13e..ffd54868 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.cpp @@ -1035,9 +1035,6 @@ hsBool pfGUIMultiLineEditCtrl::HandleKeyPress( wchar_t key, uint8_t modifiers ) if ((fPrevCtrl || fNextCtrl) && (fLineStarts.GetCount() <= GetFirstVisibleLine())) return true; // we're ignoring if we can't actually edit our visible frame (and we're linked) - if (modifiers & pfGameGUIMgr::kCtrlDown) - return true; // we're ignoring ctrl key events - if( fIgnoreNextKey ) { // So we don't process keys that already got handled by HandleKeyEvent() @@ -1111,6 +1108,13 @@ hsBool pfGUIMultiLineEditCtrl::HandleKeyEvent( pfGameGUIMgr::EventType event, p return true; DeleteChar(); + } + else if( key == KEY_ENTER ) + { + if( IsLocked() ) + return true; + + InsertChar('\n'); } else if( key == KEY_ESCAPE ) { diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp index d5d3f9ab..77ce1ec2 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp @@ -119,7 +119,8 @@ plInputManager* plInputManager::fInstance = nil; plInputManager::plInputManager( hsWindowHndl hWnd ) : fDInputMgr(nil), -fInterfaceMgr(nil) +fInterfaceMgr(nil), +localeC("C") { fhWnd = hWnd; fInstance = this; @@ -289,9 +290,11 @@ void plInputManager::HandleWin32ControlEvent(UINT message, WPARAM Wparam, LPARAM break; case CHAR_MSG: { + wchar_t ch = (wchar_t)Wparam; + // These are handled by KEYUP/KEYDOWN and should not be sent // We don't like garbage getting in string fields - if (Wparam == KEY_BACKSPACE || Wparam == KEY_ESCAPE) + if (std::iscntrl(ch, localeC)) break; BYTE scan = (BYTE)(Lparam >> 16); @@ -300,10 +303,7 @@ void plInputManager::HandleWin32ControlEvent(UINT message, WPARAM Wparam, LPARAM bExtended = Lparam >> 24 & 1; hsBool bRepeat = ((Lparam >> 29) & 0xf) != 0; bool down = !(Lparam >> 31); - wchar_t ch = (wchar_t)Wparam; - // for the return key, Windows sends CR, but multiline text input fields want LF (CR is rendered as a wide horizontal space) - if (ch == 0x0D) - ch = 0x0A; + for (int i=0; iHandleKeyEvent( CHAR_MSG, (plKeyDef)vkey, down, bRepeat, ch ); } diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.h b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.h index d7c701a7..03df9589 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.h +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.h @@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsTemplates.h" #include "pnKeyedObject/hsKeyedObject.h" #include "pnInputCore/plInputMap.h" +#include class plDInputMgr; class plInputDevice; @@ -99,6 +100,7 @@ protected: float fMouseScale; static uint8_t bRecenterMouse; static hsWindowHndl fhWnd; + std::locale localeC; public: #if HS_BUILD_FOR_WIN32