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 <volker.hilsheimer@qt.io>
bb10
Ilya Fedin 2023-02-09 09:51:54 +04:00 committed by Volker Hilsheimer
parent 7273a0eacc
commit 481771a331
1 changed files with 3 additions and 2 deletions

View File

@ -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<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;
}