From 91bceae90265921efeb1b815313d62de7d93a215 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 3 Nov 2020 08:55:45 +0800 Subject: [PATCH] Fix UTF-16 character input pair events --- nel/include/nel/misc/win_event_emitter.h | 3 ++- nel/src/misc/win_event_emitter.cpp | 27 ++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/nel/include/nel/misc/win_event_emitter.h b/nel/include/nel/misc/win_event_emitter.h index d23d9d040..ee709ec04 100644 --- a/nel/include/nel/misc/win_event_emitter.h +++ b/nel/include/nel/misc/win_event_emitter.h @@ -36,7 +36,7 @@ namespace NLMISC { class CWinEventEmitter : public IEventEmitter { public: - CWinEventEmitter () : _MouseEventsEnabled(true), _KeyboardEventsEnabled(true), _IMEEventsEnabled(true) + CWinEventEmitter () : _Utf16Pair(0), _MouseEventsEnabled(true), _KeyboardEventsEnabled(true), _IMEEventsEnabled(true) { _HWnd=NULL; resetButtonFlagState (); @@ -106,6 +106,7 @@ public: private: CWinEventServer _InternalServer; HWND _HWnd; + wchar_t _Utf16Pair; public: // private: may need to be in sync with direct input flags however... bool _CtrlButton; diff --git a/nel/src/misc/win_event_emitter.cpp b/nel/src/misc/win_event_emitter.cpp index dfc385bd9..939ad0477 100644 --- a/nel/src/misc/win_event_emitter.cpp +++ b/nel/src/misc/win_event_emitter.cpp @@ -24,6 +24,7 @@ #include "nel/misc/event_emitter.h" #include "nel/misc/win_event_emitter.h" #include "nel/misc/event_server.h" +#include "nel/misc/utf_string_view.h" #ifdef NL_OS_WINDOWS #include @@ -177,10 +178,28 @@ bool CWinEventEmitter::processMessage (HWND hWnd, uint32 msg, WPARAM wParam, LPA { //if (wParam < KeyCount) //nlinfo("WM_CHAR with %u", wParam); -#ifndef WM_UNICHAR - // FIXME: Combine UTF-16 pairs -#endif - server->postEvent (new CEventChar ((ucchar)wParam, getKeyButton(_AltButton, _ShiftButton, _CtrlButton), this)); + wchar_t c = (wchar_t)wParam; + if ((c & 0xFC00) == 0xD800) + { + _Utf16Pair = c; + } + else if (_Utf16Pair && (c & 0xFC00) == 0xDC00) + { + wchar_t cc[] = { _Utf16Pair, c, 0 }; + _Utf16Pair = 0; + CUtfStringView cv = CUtfStringView(cc); + for (CUtfStringView::iterator it(cv.begin()), end(cv.end()); it != end; ++it) + server->postEvent(new CEventChar(*it, getKeyButton(_AltButton, _ShiftButton, _CtrlButton), this)); + } + else + { + if (_Utf16Pair) + { + server->postEvent(new CEventChar(_Utf16Pair, getKeyButton(_AltButton, _ShiftButton, _CtrlButton), this)); + _Utf16Pair = 0; + } + server->postEvent(new CEventChar(c, getKeyButton(_AltButton, _ShiftButton, _CtrlButton), this)); + } } break; /*case WM_IME_CHAR: