From 52692b0459905074dbb5141a7233dc09ea01cd7f Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 27 Dec 2015 13:23:17 -1000 Subject: [PATCH] Xlib in sync with new text system --- include/boo/IWindow.hpp | 3 +-- lib/win/ApplicationWin32.cpp | 1 + lib/win/WindowWin32.cpp | 20 +++++++++++++++----- lib/x11/WindowXlib.cpp | 9 ++++++++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/boo/IWindow.hpp b/include/boo/IWindow.hpp index 92a04b8..da476d2 100644 --- a/include/boo/IWindow.hpp +++ b/include/boo/IWindow.hpp @@ -115,7 +115,7 @@ struct ITextInputCallback virtual std::string substringForRange(const std::pair& range, std::pair& actualRange) const=0; - virtual void insertText(const std::string& str, const std::pair& range)=0; + virtual void insertText(const std::string& str, const std::pair& range={-1,0})=0; virtual int characterIndexAtPoint(const SWindowCoord& point) const=0; virtual SWindowRect rectForCharacterRange(const std::pair& range, std::pair& actualRange) const=0; @@ -158,7 +158,6 @@ public: {(void)mod;(void)isRepeat;} virtual void modKeyUp(EModifierKey mod) {(void)mod;} - virtual void utf8FragmentDown(const std::string& str) {(void)str;} virtual ITextInputCallback* getTextInputCallback() {return nullptr;} virtual void focusLost() {} diff --git a/lib/win/ApplicationWin32.cpp b/lib/win/ApplicationWin32.cpp index e0e5468..dc4709a 100644 --- a/lib/win/ApplicationWin32.cpp +++ b/lib/win/ApplicationWin32.cpp @@ -267,6 +267,7 @@ public: case WM_NCMOUSELEAVE: case WM_MOUSEHOVER: case WM_NCMOUSEHOVER: + case WM_UNICHAR: case WM_IME_COMPOSITION: window->_incomingEvent(&HWNDEvent(uMsg, wParam, lParam)); diff --git a/lib/win/WindowWin32.cpp b/lib/win/WindowWin32.cpp index 13e70cd..e4a6cff 100644 --- a/lib/win/WindowWin32.cpp +++ b/lib/win/WindowWin32.cpp @@ -1170,10 +1170,23 @@ public: } return; } + case WM_UNICHAR: + { + if (m_callback) + { + ITextInputCallback* inputCb = m_callback->getTextInputCallback(); + uint8_t utf8ch[4]; + size_t len = utf8proc_encode_char(e.wParam, utf8ch); + if (inputCb && len) + inputCb->insertText(std::string((char*)utf8ch, len)); + } + return; + } case WM_IME_COMPOSITION: { if (m_callback) { + ITextInputCallback* inputCb = m_callback->getTextInputCallback(); if ((e.lParam & GCS_RESULTSTR) != 0) { wchar_t str[512]; @@ -1182,11 +1195,8 @@ public: { size_t szOut; std::unique_ptr out = MakeUnicodeLF(str, len/2, szOut); - if (szOut) - { - std::string strOut((char*)out.get(), szOut); - m_callback->utf8FragmentDown(strOut); - } + if (szOut && inputCb) + inputCb->insertText(std::string((char*)out.get(), szOut)); } } } diff --git a/lib/x11/WindowXlib.cpp b/lib/x11/WindowXlib.cpp index 0516915..d013b2e 100644 --- a/lib/x11/WindowXlib.cpp +++ b/lib/x11/WindowXlib.cpp @@ -1237,15 +1237,22 @@ public: unsigned int state = event->xkey.state; event->xkey.state &= ~ControlMask; std::string utf8Frag = translateUTF8(&event->xkey, m_xIC); + ITextInputCallback* inputCb = m_callback->getTextInputCallback(); if (utf8Frag.size()) { - m_callback->utf8FragmentDown(utf8Frag); + if (inputCb) + inputCb->insertText(utf8Frag); return; } char charCode = translateKeysym(&event->xkey, specialKey, modifierKey); EModifierKey modifierMask = translateModifiers(state); if (charCode) + { + if (inputCb && + (modifierMask & (EModifierKey::Ctrl|EModifierKey::Command)) == EModifierKey::None) + inputCb->insertText(std::string(1, charCode)); m_callback->charKeyDown(charCode, modifierMask, false); + } else if (specialKey != ESpecialKey::None) m_callback->specialKeyDown(specialKey, modifierMask, false); else if (modifierKey != EModifierKey::None)