vcl/source/treelist/transfer.cxx |   41 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

New commits:
commit b651051fce541ef5f8375154889922488189a4be
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Oct 10 15:59:04 2023 +0300
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Oct 11 11:19:00 2023 +0200

    tdf#133870: read OBJECTDESCRIPTOR from clipboard
    
    This extends commit 8ad0c29f56e5069a3679560d404b603332dcf38a
    (sw: prefer ODF over RTF when pasting from Writer, 2020-04-22).
    To see that the clipboard contains a matching EMBED_SOURCE from
    another instance of the program, the content of OBJECTDESCRIPTOR
    needs to be read into mxObjDesc of TransferableDataHelper.
    
    Change-Id: Ic4bf4ba8b077550336be231451cf2e86c42f112b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157791
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 3191b322b59cab22ec4c67c0d83520ff577f7ae8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157779
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx
index 1fd9df908854..002a6b7dd338 100644
--- a/vcl/source/treelist/transfer.cxx
+++ b/vcl/source/treelist/transfer.cxx
@@ -41,6 +41,7 @@
 #include <vcl/window.hxx>
 #include <comphelper/fileformat.h>
 #include <comphelper/processfactory.hxx>
+#include <comphelper/scopeguard.hxx>
 #include <comphelper/servicehelper.hxx>
 #include <comphelper/sequence.hxx>
 #include <sot/filelist.hxx>
@@ -108,6 +109,43 @@ SvStream& WriteTransferableObjectDescriptor( SvStream& 
rOStm, const Transferable
     return rOStm;
 }
 
+static void TryReadTransferableObjectDescriptor(SvStream& rIStm,
+                                                TransferableObjectDescriptor& 
rObjDesc)
+{
+    auto nStartPos = rIStm.Tell();
+    comphelper::ScopeGuard streamPosRestore([nStartPos, &rIStm] { 
rIStm.Seek(nStartPos); });
+
+    sal_uInt32 size;
+    rIStm.ReadUInt32(size);
+
+    SvGlobalName className;
+    rIStm >> className;
+
+    sal_uInt32 viewAspect;
+    rIStm.ReadUInt32(viewAspect);
+
+    sal_Int32 width, height;
+    rIStm.ReadInt32(width).ReadInt32(height);
+
+    sal_Int32 dragStartPosX, dragStartPosY;
+    rIStm.ReadInt32(dragStartPosX).ReadInt32(dragStartPosY);
+
+    const OUString typeName = 
rIStm.ReadUniOrByteString(osl_getThreadTextEncoding());
+    const OUString displayName = 
rIStm.ReadUniOrByteString(osl_getThreadTextEncoding());
+
+    sal_uInt32 nSig1, nSig2;
+    rIStm.ReadUInt32(nSig1).ReadUInt32(nSig2);
+
+    if (!rIStm.good() || rIStm.Tell() - nStartPos != size || nSig1 != TOD_SIG1 
|| nSig2 != TOD_SIG2)
+        return;
+
+    rObjDesc.maClassName = className;
+    rObjDesc.mnViewAspect = viewAspect;
+    rObjDesc.maSize = Size(width, height);
+    rObjDesc.maDragStartPos = Point(dragStartPosX, dragStartPosY);
+    rObjDesc.maTypeName = typeName;
+    rObjDesc.maDisplayName = displayName;
+}
 
 // the reading of the parameter is done using the special service 
css::datatransfer::MimeContentType,
 // a similar approach should be implemented for creation of the mimetype 
string;
@@ -1278,6 +1316,9 @@ void TransferableDataHelper::InitFormats()
         if( SotClipboardFormatId::OBJECTDESCRIPTOR == format.mnSotId )
         {
             ImplSetParameterString(*mxObjDesc, format);
+            auto data = GetSequence(format, {});
+            SvMemoryStream aSrcStm(data.getArray(), data.getLength(), 
StreamMode::READ);
+            TryReadTransferableObjectDescriptor(aSrcStm, *mxObjDesc);
             break;
         }
     }

Reply via email to