dtrans/source/win32/dtobj/DOTransferable.cxx |   47 ++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

New commits:
commit 0dc855977610f109caec2ec36303a0aad56fa7ae
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jan 28 17:57:30 2020 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Jan 29 11:53:26 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.
    
    (cherry picked from commit 5d1a540963d1c5b952655414fc77367f67db968d)
    
    Change-Id: Iccaaf33df949ee73185acbd55b61d00a12d210ee

diff --git a/dtrans/source/win32/dtobj/DOTransferable.cxx 
b/dtrans/source/win32/dtobj/DOTransferable.cxx
index ceca4996a7db..09bce44a48ea 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"
@@ -61,6 +62,7 @@ namespace
 void clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM stgmedium, 
CDOTransferable::ByteSequence_t& aByteSequence )
 {
     CStgTransferHelper memTransferHelper;
+    LPSTREAM pStream = nullptr;
 
     switch( stgmedium.tymed )
     {
@@ -77,7 +79,7 @@ void clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM 
stgmedium, CDOTransferable::
         break;
 
     case TYMED_ISTREAM:
-        //TODO: Has to be implemented
+        pStream = stgmedium.pstm;
         break;
 
     default:
@@ -85,6 +87,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 );
@@ -399,6 +436,14 @@ CDOTransferable::ByteSequence_t SAL_CALL 
CDOTransferable::getClipboardData( CFor
         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) &&
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to