From 481771a331b904810ce3da459d4b6293a83fcec0 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 9 Feb 2023 09:51:54 +0400 Subject: [PATCH] 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 Pick-to: 6.5 6.4 6.2 Change-Id: Ie024a618556d9bb5b5c7ac70507d279b959ff6db Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/windows/qwindowsmimeregistry.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsmimeregistry.cpp b/src/plugins/platforms/windows/qwindowsmimeregistry.cpp index 64b5dc463e..2d1c42df91 100644 --- a/src/plugins/platforms/windows/qwindowsmimeregistry.cpp +++ b/src/plugins/platforms/windows/qwindowsmimeregistry.cpp @@ -347,7 +347,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(); } /* @@ -448,7 +448,8 @@ QList QWindowsMimeText::formatsForMime(const QString &mimeType, const QList 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; }