winrt: store mimedata in clipboard
In addition to setting the clipboard, we also need to store the mimedata being passed. Otherwise requesting the mimedata returns a different object, causing comparisons to fail. Change-Id: I2ffea76e78be091cb98426e387619ac6788ea270 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
5f895fe0e2
commit
ea4aa5b722
@ -56,6 +56,7 @@ typedef IEventHandler<IInspectable *> ContentChangedHandler;
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
QWinRTClipboard::QWinRTClipboard()
|
QWinRTClipboard::QWinRTClipboard()
|
||||||
|
: m_mimeData(Q_NULLPTR)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_WINPHONE
|
#ifndef Q_OS_WINPHONE
|
||||||
QEventDispatcherWinRT::runOnXamlThread([this]() {
|
QEventDispatcherWinRT::runOnXamlThread([this]() {
|
||||||
@ -100,9 +101,16 @@ QMimeData *QWinRTClipboard::mimeData(QClipboard::Mode mode)
|
|||||||
const wchar_t *textStr = result.GetRawBuffer(&size);
|
const wchar_t *textStr = result.GetRawBuffer(&size);
|
||||||
QString text = QString::fromWCharArray(textStr, size);
|
QString text = QString::fromWCharArray(textStr, size);
|
||||||
text.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
|
text.replace(QStringLiteral("\r\n"), QStringLiteral("\n"));
|
||||||
m_mimeData.setText(text);
|
|
||||||
|
|
||||||
return &m_mimeData;
|
if (m_mimeData) {
|
||||||
|
if (m_mimeData->text() == text)
|
||||||
|
return m_mimeData;
|
||||||
|
delete m_mimeData;
|
||||||
|
}
|
||||||
|
m_mimeData = new QMimeData();
|
||||||
|
m_mimeData->setText(text);
|
||||||
|
|
||||||
|
return m_mimeData;
|
||||||
#else // Q_OS_WINPHONE
|
#else // Q_OS_WINPHONE
|
||||||
return QPlatformClipboard::mimeData(mode);
|
return QPlatformClipboard::mimeData(mode);
|
||||||
#endif // Q_OS_WINPHONE
|
#endif // Q_OS_WINPHONE
|
||||||
@ -143,6 +151,12 @@ void QWinRTClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
#ifndef Q_OS_WINPHONE
|
#ifndef Q_OS_WINPHONE
|
||||||
|
const bool newData = !m_mimeData || m_mimeData != data;
|
||||||
|
if (newData) {
|
||||||
|
if (m_mimeData)
|
||||||
|
delete m_mimeData;
|
||||||
|
m_mimeData = data;
|
||||||
|
}
|
||||||
const QString text = data ? data->text() : QString();
|
const QString text = data ? data->text() : QString();
|
||||||
HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, text]() {
|
HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, text]() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
@ -70,7 +70,7 @@ private:
|
|||||||
#ifndef Q_OS_WINPHONE
|
#ifndef Q_OS_WINPHONE
|
||||||
Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::DataTransfer::IClipboardStatics> m_nativeClipBoard;
|
Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::DataTransfer::IClipboardStatics> m_nativeClipBoard;
|
||||||
#endif
|
#endif
|
||||||
QMimeData m_mimeData;
|
QMimeData *m_mimeData;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
Reference in New Issue
Block a user