diff options
author | Neil <nyamatongwe@gmail.com> | 2020-01-11 14:42:53 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2020-01-11 14:42:53 +1100 |
commit | 680ebfaa2ed409a62bd1e1d863b3df17f706d656 (patch) | |
tree | ebbd22dc86eab89432c413d290511f065928e302 | |
parent | 8c4f17954c45401ca7cfe5d09f463e5ee3d27b1c (diff) | |
download | scintilla-mirror-680ebfaa2ed409a62bd1e1d863b3df17f706d656.tar.gz |
Clean up the code changed with 7883 dropping CF_TEXT.
-rw-r--r-- | win32/ScintillaWin.cxx | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 6847d4a83..cdaa091a3 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -340,6 +340,7 @@ class ScintillaWin : UINT CodePageOfDocument() const; bool ValidCodePage(int codePage) const override; + std::string EncodeWString(std::wstring_view wsv); sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override; void IdleWork() override; void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) override; @@ -1234,6 +1235,18 @@ UINT ScintillaWin::CodePageOfDocument() const { return CodePageFromCharSet(vs.styles[STYLE_DEFAULT].characterSet, pdoc->dbcsCodePage); } +std::string ScintillaWin::EncodeWString(std::wstring_view wsv) { + if (IsUnicodeMode()) { + const size_t len = UTF8Length(wsv); + std::string putf(len, 0); + UTF8FromUTF16(wsv, putf.data(), len); + return putf; + } else { + // Not in Unicode mode so convert from Unicode to current Scintilla code page + return StringEncode(wsv, CodePageOfDocument()); + } +} + sptr_t ScintillaWin::GetTextLength() { return pdoc->CountUTF16(0, pdoc->Length()); } @@ -2294,31 +2307,11 @@ void ScintillaWin::Paste() { } const PasteShape pasteShape = isRectangular ? pasteRectangular : (isLine ? pasteLine : pasteStream); - // Always use CF_UNICODETEXT if available + // Use CF_UNICODETEXT if available GlobalMemory memUSelection(::GetClipboardData(CF_UNICODETEXT)); - if (memUSelection) { - const wchar_t *uptr = static_cast<const wchar_t *>(memUSelection.ptr); - if (uptr) { - size_t len; - std::vector<char> putf; - // Default Scintilla behaviour in Unicode mode - if (IsUnicodeMode()) { - const size_t bytes = memUSelection.Size(); - const std::wstring_view wsv(uptr, bytes / 2); - len = UTF8Length(wsv); - putf.resize(len + 1); - UTF8FromUTF16(wsv, &putf[0], len); - } else { - // CF_UNICODETEXT available, but not in Unicode mode - // Convert from Unicode to current Scintilla code page - const UINT cpDest = CodePageOfDocument(); - len = MultiByteLenFromWideChar(cpDest, uptr); - putf.resize(len); - MultiByteFromWideChar(cpDest, uptr, &putf[0], len); - } - - InsertPasteShape(&putf[0], len, pasteShape); - } + if (const wchar_t *uptr = static_cast<const wchar_t *>(memUSelection.ptr)) { + const std::string putf = EncodeWString(uptr); + InsertPasteShape(putf.c_str(), putf.length(), pasteShape); memUSelection.Unlock(); } ::CloseClipboard(); |