vcl/source/treelist/transfer.cxx | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
New commits: commit 3191b322b59cab22ec4c67c0d83520ff577f7ae8 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Oct 10 15:59:04 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Oct 11 06:14:17 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> diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx index 812b9609b07f..4ca968e84b8d 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> @@ -109,6 +110,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; @@ -1279,6 +1317,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; } }