diff options
author | johnsonj <unknown> | 2023-05-06 19:39:54 +1000 |
---|---|---|
committer | johnsonj <unknown> | 2023-05-06 19:39:54 +1000 |
commit | 17decc27587b4e58942ac8fe5492ee35049caf79 (patch) | |
tree | 1e46aa7bdc3d90dc251d4ff24a98d958e9241194 | |
parent | 52f4c2abbaa34c5f254ccaad52c85c086e65b9c2 (diff) | |
download | scintilla-mirror-17decc27587b4e58942ac8fe5492ee35049caf79.tar.gz |
Feature [feature-requests:#1310] Implement IME context with IMR_DOCUMENTFEED.
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 48 |
2 files changed, 52 insertions, 0 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 57bdd6902..f0cb2ba43 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -587,6 +587,10 @@ Released 8 March 2023. </li> <li> + On Win32, implement IME context sensitivity with IMR_DOCUMENTFEED. + <a href="https://sourceforge.net/p/scintilla/feature-requests/1310/">Feature #1310</a>. + </li> + <li> On Win32 remove dependence on MSIMG32.DLL by replacing AlphaBlend by GdiAlphaBlend. <a href="https://sourceforge.net/p/scintilla/bugs/1923/">Bug #1923</a>. diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 9a26cf5b7..970054f03 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -416,6 +416,7 @@ class ScintillaWin : void ImeStartComposition(); void ImeEndComposition(); LRESULT ImeOnReconvert(LPARAM lParam); + LRESULT ImeOnDocumentFeed(LPARAM lParam) const; sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam); sptr_t HandleCompositionInline(uptr_t wParam, sptr_t lParam); static bool KoreanIME() noexcept; @@ -1773,6 +1774,9 @@ sptr_t ScintillaWin::IMEMessage(unsigned int iMessage, uptr_t wParam, sptr_t lPa if (wParam == IMR_RECONVERTSTRING) { return ImeOnReconvert(lParam); } + if (wParam == IMR_DOCUMENTFEED) { + return ImeOnDocumentFeed(lParam); + } return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam); } @@ -3127,6 +3131,50 @@ LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) { return rcSize; } +LRESULT ScintillaWin::ImeOnDocumentFeed(LPARAM lParam) const { + // This is called while typing preedit string in. + // So there is no selection. + // Limit feed within one line without EOL. + // Look around: lineStart |<-- |compStart| - caret - compEnd| -->| lineEnd. + + const Sci::Position curPos = CurrentPosition(); + const Sci::Line curLine = pdoc->SciLineFromPosition(curPos); + const Sci::Position lineStart = pdoc->LineStart(curLine); + const Sci::Position lineEnd = pdoc->LineEnd(curLine); + + const std::wstring rcFeed = StringDecode(RangeText(lineStart, lineEnd), CodePageOfDocument()); + const int rcFeedLen = static_cast<int>(rcFeed.length()) * sizeof(wchar_t); + const int rcSize = sizeof(RECONVERTSTRING) + rcFeedLen + sizeof(wchar_t); + + RECONVERTSTRING *rc = static_cast<RECONVERTSTRING *>(PtrFromSPtr(lParam)); + if (!rc) + return rcSize; + + wchar_t *rcFeedStart = reinterpret_cast<wchar_t*>(rc + 1); + memcpy(rcFeedStart, &rcFeed[0], rcFeedLen); + + IMContext imc(MainHWND()); + if (!imc.hIMC) + return 0; + + const size_t compStrLen = imc.GetCompositionString(GCS_COMPSTR).size(); + const int imeCaretPos = imc.GetImeCaretPos(); + const Sci::Position compStart = pdoc->GetRelativePositionUTF16(curPos, -imeCaretPos); + const Sci::Position compStrOffset = pdoc->CountUTF16(lineStart, compStart); + + // Fill in reconvert structure. + // Let IME to decide what the target is. + rc->dwVersion = 0; //constant + rc->dwStrLen = static_cast<DWORD>(rcFeed.length()); + rc->dwStrOffset = sizeof(RECONVERTSTRING); //constant + rc->dwCompStrLen = static_cast<DWORD>(compStrLen); + rc->dwCompStrOffset = static_cast<DWORD>(compStrOffset) * sizeof(wchar_t); + rc->dwTargetStrLen = rc->dwCompStrLen; + rc->dwTargetStrOffset = rc->dwCompStrOffset; + + return rcSize; // MS API says reconv structure to be returned. +} + void ScintillaWin::GetIntelliMouseParameters() noexcept { // This retrieves the number of lines per scroll as configured in the Mouse Properties sheet in Control Panel ::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerScroll, 0); |