diff options
author | Ilya Fedin <fedin-ilja2010@ya.ru> | 2023-02-09 09:51:54 +0400 |
---|---|---|
committer | Ilya Fedin <fedin-ilja2010@ya.ru> | 2023-03-02 09:05:10 +0400 |
commit | 1571cca6baf52ee97cdff006dbe6278c544b800d (patch) | |
tree | 47b4810abc48514594639780bc71de4485c51923 | |
parent | f0e5910c305aa143dcf1238342fe6bf036d97dfc (diff) | |
download | qtbase-1571cca6baf52ee97cdff006dbe6278c544b800d.tar.gz |
Rely on Windows to generate CF_TEXT when active code page is UTF-8
It's possible since Windows 10 1903 to set the active code page
to UTF-8 using the manifest. In that mode, QString::toLocal8Bit
converts to UTF-8 and the legacy programs not using UTF-8 codepage
can't interpret the value.
We can detect whether the UTF-8 code page is used, and in that case
only provide data as CF_UNICODETEXT. Windows will then synthesize the
CF_TEXT format when the clipboard data is consumed, using the right code
page for the target application.
https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page
Change-Id: Ie024a618556d9bb5b5c7ac70507d279b959ff6db
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 481771a331b904810ce3da459d4b6293a83fcec0)
-rw-r--r-- | src/plugins/platforms/windows/qwindowsmime.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/plugins/platforms/windows/qwindowsmime.cpp b/src/plugins/platforms/windows/qwindowsmime.cpp index 829dc99b5b..9f22da17f0 100644 --- a/src/plugins/platforms/windows/qwindowsmime.cpp +++ b/src/plugins/platforms/windows/qwindowsmime.cpp @@ -446,7 +446,7 @@ public: bool QWindowsMimeText::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const { int cf = getCf(formatetc); - return (cf == CF_UNICODETEXT || cf == CF_TEXT) && mimeData->hasText(); + return (cf == CF_UNICODETEXT || (cf == CF_TEXT && GetACP() != CP_UTF8)) && mimeData->hasText(); } /* @@ -547,7 +547,8 @@ QList<FORMATETC> QWindowsMimeText::formatsForMime(const QString &mimeType, const QList<FORMATETC> formatics; if (mimeType.startsWith(u"text/plain") && mimeData->hasText()) { formatics += setCf(CF_UNICODETEXT); - formatics += setCf(CF_TEXT); + if (GetACP() != CP_UTF8) + formatics += setCf(CF_TEXT); } return formatics; } |