[Libreoffice-commits] core.git: dtrans/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Tue Jan 28 19:09:20 UTC 2020
dtrans/source/win32/dtobj/DOTransferable.cxx | 47 ++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
New commits:
commit 5d1a540963d1c5b952655414fc77367f67db968d
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Jan 28 17:57:30 2020 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Jan 28 20:08:46 2020 +0100
dtrans win32: implement support for pasting when the handle type is stream
Steps to reproduce the problem: select an image in Word on Windows,
copy, paste into Writer -> nothing happens. A workaround is to use paste
special, and select the metafile paste, not the bitmap one.
The root cause was that clipboard contents on Windows can have different
handle types and we only supported the memory and the metafile cases.
An alternative fix would be to handle this at a higher level, e.g.
TransferableDataHelper::GetBitmapEx() in vcl could fall back to EMF when
the bitmap formats fail, but that would not work for other applications
that only offer bitmap formats with a stream handle type.
Change-Id: Iccaaf33df949ee73185acbd55b61d00a12d210ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87649
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
diff --git a/dtrans/source/win32/dtobj/DOTransferable.cxx b/dtrans/source/win32/dtobj/DOTransferable.cxx
index afa705abfc56..c331b1d95b90 100644
--- a/dtrans/source/win32/dtobj/DOTransferable.cxx
+++ b/dtrans/source/win32/dtobj/DOTransferable.cxx
@@ -20,6 +20,7 @@
#include <sal/types.h>
#include <rtl/process.h>
#include <osl/diagnose.h>
+#include <sal/log.hxx>
#include "DOTransferable.hxx"
#include "../misc/ImplHelper.hxx"
@@ -59,6 +60,7 @@ namespace
void clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM stgmedium, CDOTransferable::ByteSequence_t& aByteSequence )
{
CStgTransferHelper memTransferHelper;
+ LPSTREAM pStream = nullptr;
switch( stgmedium.tymed )
{
@@ -75,7 +77,7 @@ void clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM stgmedium, CDOTransferable::
break;
case TYMED_ISTREAM:
- //TODO: Has to be implemented
+ pStream = stgmedium.pstm;
break;
default:
@@ -83,6 +85,41 @@ void clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM stgmedium, CDOTransferable::
break;
}
+ if (pStream)
+ {
+ // We have a stream, read from it.
+ STATSTG aStat;
+ HRESULT hr = pStream->Stat(&aStat, STATFLAG_NONAME);
+ if (FAILED(hr))
+ {
+ SAL_WARN("dtrans", "clipDataToByteStream: Stat() failed");
+ return;
+ }
+
+ size_t nMemSize = aStat.cbSize.QuadPart;
+ aByteSequence.realloc(nMemSize);
+ LARGE_INTEGER li;
+ li.QuadPart = 0;
+ hr = pStream->Seek(li, STREAM_SEEK_SET, NULL);
+ if (FAILED(hr))
+ {
+ SAL_WARN("dtrans", "clipDataToByteStream: Seek() failed");
+ }
+
+ ULONG nRead = 0;
+ hr = pStream->Read(aByteSequence.getArray(), nMemSize, &nRead);
+ if (FAILED(hr))
+ {
+ SAL_WARN("dtrans", "clipDataToByteStream: Read() failed");
+ }
+ if (nRead < nMemSize)
+ {
+ SAL_WARN("dtrans", "clipDataToByteStream: Read() was partial");
+ }
+
+ return;
+ }
+
int nMemSize = memTransferHelper.memSize( cf );
aByteSequence.realloc( nMemSize );
memTransferHelper.read( aByteSequence.getArray( ), nMemSize );
@@ -393,6 +430,14 @@ CDOTransferable::ByteSequence_t CDOTransferable::getClipboardData( CFormatEtc& a
hr = m_rDataObject->GetData( aTempFormat, &stgmedium );
}
+ if (FAILED(hr) && aFormatEtc.getTymed() == TYMED_HGLOBAL)
+ {
+ // Handle type is not memory, try stream.
+ CFormatEtc aTempFormat(aFormatEtc);
+ aTempFormat.setTymed(TYMED_ISTREAM);
+ hr = m_rDataObject->GetData(aTempFormat, &stgmedium);
+ }
+
if ( FAILED( hr ) )
{
OSL_ASSERT( (hr != E_INVALIDARG) &&
More information about the Libreoffice-commits
mailing list