From 24189dbf387e7d33d65b15c9756292d7f0e8da2a Mon Sep 17 00:00:00 2001 From: johnsonj Date: Sat, 6 Feb 2016 15:15:20 +1100 Subject: Move IME code into IMContext. --- win32/ScintillaWin.cxx | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 67d61b834..f03648fe7 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -210,6 +210,24 @@ public: if (hIMC) ::ImmReleaseContext(hwnd, hIMC); } + + unsigned int GetImeCaretPos() { + return ImmGetCompositionStringW(hIMC, GCS_CURSORPOS, NULL, 0); + } + + std::vector GetImeAttributes() { + int attrLen = ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, NULL, 0); + std::vector attr(attrLen, 0); + ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, &attr[0], static_cast(attr.size())); + return attr; + } + + std::wstring GetCompositionString(DWORD dwIndex) { + const LONG byteLen = ::ImmGetCompositionStringW(hIMC, dwIndex, NULL, 0); + std::wstring wcs(byteLen / 2, 0); + ::ImmGetCompositionStringW(hIMC, dwIndex, &wcs[0], byteLen); + return wcs; + } }; } @@ -1002,17 +1020,6 @@ void ScintillaWin::ToggleHanja() { namespace { -unsigned int GetImeCaretPos(HIMC hIMC) { - return ImmGetCompositionStringW(hIMC, GCS_CURSORPOS, NULL, 0); -} - -std::vector GetImeAttributes(HIMC hIMC) { - int attrLen = ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, NULL, 0); - std::vector attr(attrLen, 0); - ::ImmGetCompositionStringW(hIMC, GCS_COMPATTR, &attr[0], static_cast(attr.size())); - return attr; -} - std::vector MapImeIndicators(std::vector inputStyle) { std::vector imeIndicator(inputStyle.size(), SC_INDICATOR_UNKNOWN); for (size_t i = 0; i < inputStyle.size(); i++) { @@ -1035,13 +1042,6 @@ std::vector MapImeIndicators(std::vector inputStyle) { return imeIndicator; } -std::wstring GetCompositionString(HIMC hIMC, DWORD dwIndex) { - const LONG byteLen = ::ImmGetCompositionStringW(hIMC, dwIndex, NULL, 0); - std::wstring wcs(byteLen / 2, 0); - ::ImmGetCompositionStringW(hIMC, dwIndex, &wcs[0], byteLen); - return wcs; -} - } sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { @@ -1067,7 +1067,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { view.imeCaretBlockOverride = false; if (lParam & GCS_COMPSTR) { - const std::wstring wcs = GetCompositionString(imc.hIMC, GCS_COMPSTR); + const std::wstring wcs = imc.GetCompositionString(GCS_COMPSTR); if ((wcs.size() == 0) || (wcs.size() >= maxLenInputIME)) { ShowCaretAtCurrentPosition(); return 0; @@ -1075,7 +1075,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { pdoc->TentativeStart(); // TentativeActive from now on. - std::vector imeIndicator = MapImeIndicators(GetImeAttributes(imc.hIMC)); + std::vector imeIndicator = MapImeIndicators(imc.GetImeAttributes()); // Display character by character. int numBytes = 0; @@ -1100,13 +1100,13 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { recordingMacro = tmpRecordingMacro; // Move IME caret position. - unsigned int imeCursorPos = GetImeCaretPos(imc.hIMC); + unsigned int imeCursorPos = imc.GetImeCaretPos(); MoveImeCarets(-imeCharPos[wcs.size()] + imeCharPos[imeCursorPos]); if (KoreanIME()) { view.imeCaretBlockOverride = true; } } else if (lParam & GCS_RESULTSTR) { - const std::wstring wcs = GetCompositionString(imc.hIMC, GCS_RESULTSTR); + const std::wstring wcs = imc.GetCompositionString(GCS_RESULTSTR); for (size_t i = 0; i < wcs.size();) { const size_t ucWidth = UTF16CharLength(wcs[i]); const std::wstring uniChar(wcs, i, ucWidth); -- cgit v1.2.3