1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/embed/XTransactedObject.hpp>
21 #include <com/sun/star/embed/XEmbedPersist.hpp>
22 #include <com/sun/star/embed/XEmbeddedObject.hpp>
23 #include <com/sun/star/uno/Exception.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/beans/XPropertySetInfo.hpp>
27 #include <com/sun/star/form/FormButtonType.hpp>
28 #include <unotools/streamwrap.hxx>
30 #include <svx/unomodel.hxx>
31 #include <unotools/tempfile.hxx>
32 #include <unotools/ucbstreamhelper.hxx>
33 #include <comphelper/fileformat.h>
34 #include <comphelper/storagehelper.hxx>
35 #include <comphelper/servicehelper.hxx>
37 #include <svtools/embedtransfer.hxx>
38 #include <sot/storage.hxx>
39 #include <svx/svditer.hxx>
40 #include <svx/svdograf.hxx>
41 #include <svx/svdoole2.hxx>
42 #include <svx/svdouno.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <svl/itempool.hxx>
45 #include <svl/urlbmk.hxx>
46 #include <tools/urlobj.hxx>
47 #include <osl/diagnose.h>
49 #include <drwtrans.hxx>
51 #include <drwlayer.hxx>
52 #include <drawview.hxx>
54 #include <viewdata.hxx>
56 #include <dragdata.hxx>
57 #include <stlpool.hxx>
58 #include <scresid.hxx>
59 #include <globstr.hrc>
61 #include <editeng/eeitem.hxx>
63 #include <editeng/fhgtitem.hxx>
64 #include <vcl/svapp.hxx>
66 using namespace com::sun::star
;
68 constexpr sal_uInt32 SCDRAWTRANS_TYPE_EMBOBJ
= 1;
69 constexpr sal_uInt32 SCDRAWTRANS_TYPE_DRAWMODEL
= 2;
70 constexpr sal_uInt32 SCDRAWTRANS_TYPE_DOCUMENT
= 3;
72 ScDrawTransferObj::ScDrawTransferObj( std::unique_ptr
<SdrModel
> pClipModel
, ScDocShell
* pContainerShell
,
73 TransferableObjectDescriptor aDesc
) :
74 m_pModel( std::move(pClipModel
) ),
75 m_aObjDesc(std::move( aDesc
)),
79 m_nDragSourceFlags( ScDragSrc::Undefined
),
80 m_bDragWasInternal( false ),
81 maShellID(SfxObjectShell::CreateShellID(pContainerShell
))
84 // check what kind of objects are contained
86 SdrPage
* pPage
= m_pModel
->GetPage(0);
89 SdrObjListIter
aIter( pPage
, SdrIterMode::Flat
);
90 SdrObject
* pObject
= aIter
.Next();
91 if (pObject
&& !aIter
.Next()) // exactly one object?
96 SdrObjKind nSdrObjKind
= pObject
->GetObjIdentifier();
97 if (nSdrObjKind
== SdrObjKind::OLE2
)
99 // if object has no persistence it must be copied as a part of document
102 uno::Reference
< embed::XEmbedPersist
> xPersObj( static_cast<SdrOle2Obj
*>(pObject
)->GetObjRef(), uno::UNO_QUERY
);
103 if ( xPersObj
.is() && xPersObj
->hasEntry() )
106 catch( uno::Exception
& )
108 // aOleData is initialized later
113 if (nSdrObjKind
== SdrObjKind::Graphic
)
116 if ( static_cast<SdrGrafObj
*>(pObject
)->GetGraphic().GetType() == GraphicType::Bitmap
)
122 SdrUnoObj
* pUnoCtrl
= dynamic_cast<SdrUnoObj
*>( pObject
);
123 if (pUnoCtrl
&& SdrInventor::FmForm
== pUnoCtrl
->GetObjInventor())
125 const uno::Reference
<awt::XControlModel
>& xControlModel
= pUnoCtrl
->GetUnoControlModel();
126 OSL_ENSURE( xControlModel
.is(), "uno control without model" );
127 if ( xControlModel
.is() )
129 uno::Reference
< beans::XPropertySet
> xPropSet( xControlModel
, uno::UNO_QUERY
);
130 uno::Reference
< beans::XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
132 OUString
sPropButtonType( u
"ButtonType"_ustr
);
134 if(xInfo
->hasPropertyByName( sPropButtonType
))
136 uno::Any aAny
= xPropSet
->getPropertyValue( sPropButtonType
);
137 form::FormButtonType eTmp
;
138 if ( (aAny
>>= eTmp
) && eTmp
== form::FormButtonType_URL
)
141 OUString
sPropTargetURL( u
"TargetURL"_ustr
);
142 if(xInfo
->hasPropertyByName( sPropTargetURL
))
144 aAny
= xPropSet
->getPropertyValue( sPropTargetURL
);
146 if ( (aAny
>>= sTmp
) && !sTmp
.isEmpty() )
148 OUString aUrl
= sTmp
;
149 OUString aAbs
= aUrl
;
152 const SfxMedium
* pMedium
= pContainerShell
->GetMedium();
156 aAbs
= pMedium
->GetURLObject().smartRel2Abs( aUrl
, bWasAbs
).
157 GetMainURL(INetURLObject::DecodeMechanism::NONE
);
158 // full path as stored INetBookmark must be encoded
164 OUString
sPropLabel( u
"Label"_ustr
);
165 if(xInfo
->hasPropertyByName( sPropLabel
))
167 aAny
= xPropSet
->getPropertyValue( sPropLabel
);
168 if ( (aAny
>>= sTmp
) && !sTmp
.isEmpty() )
173 m_oBookmark
.emplace( aAbs
, aLabel
);
183 // get size for object descriptor
185 // #i71538# use complete SdrViews
186 // SdrExchangeView aView(pModel);
187 SdrView
aView(*m_pModel
);
188 SdrPageView
* pPv
= aView
.ShowSdrPage(aView
.GetModel().GetPage(0));
189 aView
.MarkAllObj(pPv
);
190 m_aSrcSize
= aView
.GetAllMarkedRect().GetSize();
192 if ( m_bOleObj
) // single OLE object
194 SdrOle2Obj
* pObj
= GetSingleObject();
195 if ( pObj
&& pObj
->GetObjRef().is() )
196 SvEmbedTransferHelper::FillTransferableObjectDescriptor( m_aObjDesc
, pObj
->GetObjRef(), pObj
->GetGraphic(), pObj
->GetAspect() );
199 m_aObjDesc
.maSize
= m_aSrcSize
;
200 PrepareOLE( m_aObjDesc
);
202 // remember a unique ID of the source document
204 if ( pContainerShell
)
206 ScDocument
& rDoc
= pContainerShell
->GetDocument();
209 ScChartHelper::FillProtectedChartRangesVector( m_aProtectedChartRangesVector
, rDoc
, pPage
);
214 ScDrawTransferObj::~ScDrawTransferObj()
216 SolarMutexGuard aSolarGuard
;
218 ScModule
* pScMod
= ScModule::get();
219 if (pScMod
&& pScMod
->GetDragData().pDrawTransfer
== this)
221 OSL_FAIL("ScDrawTransferObj wasn't released");
222 pScMod
->ResetDragObject();
225 m_aOleData
= TransferableDataHelper(); // clear before releasing the mutex
226 m_aDocShellRef
.clear();
229 m_aDrawPersistRef
.clear(); // after the model
232 m_pDragSourceView
.reset();
235 ScDrawTransferObj
* ScDrawTransferObj::GetOwnClipboard(const uno::Reference
<datatransfer::XTransferable2
>& xTransferable
)
237 return dynamic_cast<ScDrawTransferObj
*>(xTransferable
.get());
240 static bool lcl_HasOnlyControls( SdrModel
* pModel
)
242 bool bOnlyControls
= false; // default if there are no objects
246 SdrPage
* pPage
= pModel
->GetPage(0);
249 SdrObjListIter
aIter( pPage
, SdrIterMode::DeepNoGroups
);
250 SdrObject
* pObj
= aIter
.Next();
253 bOnlyControls
= true; // only set if there are any objects at all
256 if (dynamic_cast<const SdrUnoObj
*>( pObj
) == nullptr)
258 bOnlyControls
= false;
267 return bOnlyControls
;
270 void ScDrawTransferObj::AddSupportedFormats()
272 if ( m_bGrIsBit
) // single bitmap graphic
274 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
275 AddFormat( SotClipboardFormatId::SVXB
);
276 AddFormat( SotClipboardFormatId::PNG
);
277 AddFormat( SotClipboardFormatId::BITMAP
);
278 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
280 else if ( m_bGraphic
) // other graphic
283 AddFormat( SotClipboardFormatId::DRAWING
);
285 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
286 AddFormat( SotClipboardFormatId::SVXB
);
287 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
288 AddFormat( SotClipboardFormatId::PNG
);
289 AddFormat( SotClipboardFormatId::BITMAP
);
291 else if ( m_oBookmark
) // url button
293 // AddFormat( SotClipboardFormatId::EMBED_SOURCE );
294 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
295 AddFormat( SotClipboardFormatId::SOLK
);
296 AddFormat( SotClipboardFormatId::STRING
);
297 AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
);
298 AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK
);
299 AddFormat( SotClipboardFormatId::DRAWING
);
301 else if ( m_bOleObj
) // single OLE object
303 AddFormat( SotClipboardFormatId::EMBED_SOURCE
);
304 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
305 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
309 if ( m_aOleData
.GetTransferable().is() )
311 // get format list from object snapshot
312 // (this must be after inserting the default formats!)
314 DataFlavorExVector
aVector( m_aOleData
.GetDataFlavorExVector() );
316 for( const auto& rItem
: aVector
)
320 else // any drawing objects
322 AddFormat( SotClipboardFormatId::EMBED_SOURCE
);
323 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
324 AddFormat( SotClipboardFormatId::DRAWING
);
326 // leave out bitmap and metafile if there are only controls
327 if ( !lcl_HasOnlyControls( m_pModel
.get() ) )
329 AddFormat( SotClipboardFormatId::PNG
);
330 AddFormat( SotClipboardFormatId::BITMAP
);
331 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
336 // AddFormat( SotClipboardFormatId::SVIM );
339 bool ScDrawTransferObj::GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
)
342 SotClipboardFormatId nFormat
= SotExchange::GetFormat( rFlavor
);
344 if ( m_bOleObj
&& nFormat
!= SotClipboardFormatId::GDIMETAFILE
)
348 if( m_aOleData
.GetTransferable().is() && m_aOleData
.HasFormat( rFlavor
) )
350 bOK
= SetAny( m_aOleData
.GetAny(rFlavor
, rDestDoc
) );
356 if( HasFormat( nFormat
) )
358 if ( nFormat
== SotClipboardFormatId::LINKSRCDESCRIPTOR
|| nFormat
== SotClipboardFormatId::OBJECTDESCRIPTOR
)
360 bOK
= SetTransferableObjectDescriptor( m_aObjDesc
);
362 else if ( nFormat
== SotClipboardFormatId::DRAWING
)
364 SdrView
aView(*m_pModel
);
365 SdrPageView
* pPv
= aView
.ShowSdrPage(aView
.GetModel().GetPage(0));
366 aView
.MarkAllObj( pPv
);
367 auto pNewModel
= aView
.CreateMarkedObjModel();
368 bOK
= SetObject( pNewModel
.get(), SCDRAWTRANS_TYPE_DRAWMODEL
, rFlavor
);
370 else if ( nFormat
== SotClipboardFormatId::BITMAP
371 || nFormat
== SotClipboardFormatId::PNG
372 || nFormat
== SotClipboardFormatId::GDIMETAFILE
)
374 // #i71538# use complete SdrViews
375 // SdrExchangeView aView( pModel );
376 SdrView
aView(*m_pModel
);
377 SdrPageView
* pPv
= aView
.ShowSdrPage(aView
.GetModel().GetPage(0));
378 OSL_ENSURE( pPv
, "pPv not there..." );
379 aView
.MarkAllObj( pPv
);
380 if ( nFormat
== SotClipboardFormatId::GDIMETAFILE
)
381 bOK
= SetGDIMetaFile( aView
.GetMarkedObjMetaFile(true) );
383 bOK
= SetBitmapEx( aView
.GetMarkedObjBitmapEx(true), rFlavor
);
385 else if ( nFormat
== SotClipboardFormatId::SVXB
)
387 // only enabled for single graphics object
389 SdrPage
* pPage
= m_pModel
->GetPage(0);
392 SdrObjListIter
aIter( pPage
, SdrIterMode::Flat
);
393 SdrObject
* pObject
= aIter
.Next();
394 if (pObject
&& pObject
->GetObjIdentifier() == SdrObjKind::Graphic
)
396 SdrGrafObj
* pGraphObj
= static_cast<SdrGrafObj
*>(pObject
);
397 bOK
= SetGraphic( pGraphObj
->GetGraphic() );
401 else if ( nFormat
== SotClipboardFormatId::EMBED_SOURCE
)
403 if ( m_bOleObj
) // single OLE object
405 SdrOle2Obj
* pObj
= GetSingleObject();
406 if ( pObj
&& pObj
->GetObjRef().is() )
408 bOK
= SetObject( pObj
->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ
, rFlavor
);
411 else // create object from contents
413 //TODO/LATER: needs new Format, because now single OLE and "this" are different
414 InitDocShell(); // set aDocShellRef
416 SfxObjectShell
* pEmbObj
= m_aDocShellRef
.get();
417 bOK
= SetObject( pEmbObj
, SCDRAWTRANS_TYPE_DOCUMENT
, rFlavor
);
420 else if( m_oBookmark
)
422 bOK
= SetINetBookmark( *m_oBookmark
, rFlavor
);
428 bool ScDrawTransferObj::WriteObject( SvStream
& rOStm
, void* pUserObject
, sal_uInt32 nUserObjectId
,
429 const css::datatransfer::DataFlavor
& /* rFlavor */ )
431 // called from SetObject, put data into stream
434 switch (nUserObjectId
)
436 case SCDRAWTRANS_TYPE_DRAWMODEL
:
438 SdrModel
* pDrawModel
= static_cast<SdrModel
*>(pUserObject
);
439 pDrawModel
->BurnInStyleSheetAttributes();
440 rOStm
.SetBufferSize( 0xff00 );
442 // for the changed pool defaults from drawing layer pool set those
443 // attributes as hard attributes to preserve them for saving
444 const SfxItemPool
& rItemPool
= pDrawModel
->GetItemPool();
445 const SvxFontHeightItem
& rDefaultFontHeight
= rItemPool
.GetUserOrPoolDefaultItem(EE_CHAR_FONTHEIGHT
);
447 // SW should have no MasterPages
448 OSL_ENSURE(0 == pDrawModel
->GetMasterPageCount(), "SW with MasterPages (!)");
450 for(sal_uInt16
a(0); a
< pDrawModel
->GetPageCount(); a
++)
452 const SdrPage
* pPage(pDrawModel
->GetPage(a
));
453 SdrObjListIter
aIter(pPage
, SdrIterMode::DeepNoGroups
);
455 while(aIter
.IsMore())
457 SdrObject
* pObj
= aIter
.Next();
458 const SvxFontHeightItem
& rItem
= pObj
->GetMergedItem(EE_CHAR_FONTHEIGHT
);
460 if(rItem
.GetHeight() == rDefaultFontHeight
.GetHeight())
462 pObj
->SetMergedItem(rDefaultFontHeight
);
468 css::uno::Reference
<css::io::XOutputStream
> xDocOut( new utl::OOutputStreamWrapper( rOStm
) );
469 SvxDrawingLayerExport( pDrawModel
, xDocOut
);
472 bRet
= ( rOStm
.GetError() == ERRCODE_NONE
);
476 case SCDRAWTRANS_TYPE_EMBOBJ
:
478 // impl. for "single OLE"
479 embed::XEmbeddedObject
* pEmbObj
= static_cast<embed::XEmbeddedObject
*>(pUserObject
);
481 ::utl::TempFileFast aTempFile
;
482 SvStream
* pTempStream
= aTempFile
.GetStream(StreamMode::READWRITE
);
483 uno::Reference
< embed::XStorage
> xWorkStore
=
484 ::comphelper::OStorageHelper::GetStorageFromStream( new utl::OStreamWrapper(*pTempStream
) );
486 uno::Reference
< embed::XEmbedPersist
> xPers( static_cast<embed::XVisualObject
*>(pEmbObj
), uno::UNO_QUERY
);
491 uno::Sequence
< beans::PropertyValue
> aSeq
;
492 OUString
aDummyName(u
"Dummy"_ustr
);
493 xPers
->storeToEntry( xWorkStore
, aDummyName
, aSeq
, aSeq
);
494 if ( xWorkStore
->isStreamElement( aDummyName
) )
496 uno::Reference
< io::XOutputStream
> xDocOut( new utl::OOutputStreamWrapper( rOStm
) );
497 uno::Reference
< io::XStream
> xNewStream
= xWorkStore
->openStreamElement( aDummyName
, embed::ElementModes::READ
);
498 ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream
->getInputStream(), xDocOut
);
502 uno::Reference
< io::XStream
> xDocStr( new utl::OStreamWrapper( rOStm
) );
503 uno::Reference
< embed::XStorage
> xDocStg
= ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr
);
504 uno::Reference
< embed::XStorage
> xNewStg
= xWorkStore
->openStorageElement( aDummyName
, embed::ElementModes::READ
);
505 xNewStg
->copyToStorage( xDocStg
);
506 uno::Reference
< embed::XTransactedObject
> xTrans( xDocStg
, uno::UNO_QUERY
);
511 catch ( uno::Exception
& )
518 case SCDRAWTRANS_TYPE_DOCUMENT
:
520 // impl. for "DocShell"
521 SfxObjectShell
* pEmbObj
= static_cast<SfxObjectShell
*>(pUserObject
);
525 ::utl::TempFileFast aTempFile
;
526 SvStream
* pTempStream
= aTempFile
.GetStream(StreamMode::READWRITE
);
527 uno::Reference
< embed::XStorage
> xWorkStore
=
528 ::comphelper::OStorageHelper::GetStorageFromStream( new utl::OStreamWrapper(*pTempStream
) );
530 // write document storage
531 pEmbObj
->SetupStorage( xWorkStore
, SOFFICE_FILEFORMAT_CURRENT
, false );
533 // mba: no relative URLs for clipboard!
534 SfxMedium
aMedium( xWorkStore
, OUString() );
535 pEmbObj
->DoSaveObjectAs( aMedium
, false );
536 pEmbObj
->DoSaveCompleted();
538 uno::Reference
< embed::XTransactedObject
> xTransact( xWorkStore
, uno::UNO_QUERY
);
539 if ( xTransact
.is() )
542 rOStm
.SetBufferSize( 0xff00 );
543 rOStm
.WriteStream( *pTempStream
);
545 xWorkStore
->dispose();
548 catch ( uno::Exception
& )
551 bRet
= ( rOStm
.GetError() == ERRCODE_NONE
);
556 OSL_FAIL("unknown object id");
561 void ScDrawTransferObj::DragFinished( sal_Int8 nDropAction
)
563 if ( nDropAction
== DND_ACTION_MOVE
&& !m_bDragWasInternal
&& !(m_nDragSourceFlags
& ScDragSrc::Navigator
) )
565 // move: delete source objects
567 if ( m_pDragSourceView
)
568 m_pDragSourceView
->DeleteMarked();
571 ScModule
* pScMod
= ScModule::get();
572 if ( pScMod
->GetDragData().pDrawTransfer
== this )
573 pScMod
->ResetDragObject();
575 m_pDragSourceView
.reset();
577 TransferDataContainer::DragFinished( nDropAction
);
580 void ScDrawTransferObj::SetDrawPersist( const SfxObjectShellRef
& rRef
)
582 m_aDrawPersistRef
= rRef
;
585 static void lcl_InitMarks( SdrMarkView
& rDest
, const SdrMarkView
& rSource
, SCTAB nTab
)
587 rDest
.ShowSdrPage(rDest
.GetModel().GetPage(nTab
));
588 SdrPageView
* pDestPV
= rDest
.GetSdrPageView();
589 OSL_ENSURE(pDestPV
,"PageView ?");
591 const SdrMarkList
& rMarkList
= rSource
.GetMarkedObjectList();
592 const size_t nCount
= rMarkList
.GetMarkCount();
593 for (size_t i
=0; i
<nCount
; ++i
)
595 SdrMark
* pMark
= rMarkList
.GetMark(i
);
596 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
598 rDest
.MarkObj(pObj
, pDestPV
);
602 void ScDrawTransferObj::SetDragSource( const ScDrawView
* pView
)
604 m_pDragSourceView
.reset(new SdrView(pView
->getSdrModelFromSdrView())); // TTTT pView should be reference
605 lcl_InitMarks( *m_pDragSourceView
, *pView
, pView
->GetTab() );
607 //! add as listener with document, delete pDragSourceView if document gone
610 void ScDrawTransferObj::SetDragSourceObj( SdrObject
& rObj
, SCTAB nTab
)
612 m_pDragSourceView
.reset(new SdrView(rObj
.getSdrModelFromSdrObject()));
613 m_pDragSourceView
->ShowSdrPage(m_pDragSourceView
->GetModel().GetPage(nTab
));
614 SdrPageView
* pPV
= m_pDragSourceView
->GetSdrPageView();
615 m_pDragSourceView
->MarkObj(&rObj
, pPV
); // TTTT MarkObj should take SdrObject&
617 //! add as listener with document, delete pDragSourceView if document gone
620 void ScDrawTransferObj::SetDragSourceFlags(ScDragSrc nFlags
)
622 m_nDragSourceFlags
= nFlags
;
625 void ScDrawTransferObj::SetDragWasInternal()
627 m_bDragWasInternal
= true;
630 const OUString
& ScDrawTransferObj::GetShellID() const
635 SdrOle2Obj
* ScDrawTransferObj::GetSingleObject()
637 // if single OLE object was copied, get its object
639 SdrPage
* pPage
= m_pModel
->GetPage(0);
642 SdrObjListIter
aIter( pPage
, SdrIterMode::Flat
);
643 SdrObject
* pObject
= aIter
.Next();
644 if (pObject
&& pObject
->GetObjIdentifier() == SdrObjKind::OLE2
)
646 return static_cast<SdrOle2Obj
*>(pObject
);
653 void ScDrawTransferObj::CreateOLEData()
655 if (m_aOleData
.GetTransferable().is())
659 SdrOle2Obj
* pObj
= GetSingleObject();
660 if (!pObj
|| !pObj
->GetObjRef().is())
661 // No OLE object present.
664 rtl::Reference
<SvEmbedTransferHelper
> pEmbedTransfer
=
665 new SvEmbedTransferHelper(
666 pObj
->GetObjRef(), pObj
->GetGraphic(), pObj
->GetAspect());
668 pEmbedTransfer
->SetParentShellID(maShellID
);
670 m_aOleData
= TransferableDataHelper(pEmbedTransfer
);
673 // initialize aDocShellRef with a live document from the ClipDoc
675 void ScDrawTransferObj::InitDocShell()
677 if ( m_aDocShellRef
.is() )
680 m_aDocShellRef
= new ScDocShell
; // ref must be there before InitNew
682 m_aDocShellRef
->DoInitNew();
684 ScDocument
& rDestDoc
= m_aDocShellRef
->GetDocument();
685 rDestDoc
.InitDrawLayer(m_aDocShellRef
.get());
687 auto pPool
= rDestDoc
.GetStyleSheetPool();
688 pPool
->CopyStyleFrom(m_pModel
->GetStyleSheetPool(), ScResId(STR_STYLENAME_STANDARD
), SfxStyleFamily::Frame
);
689 pPool
->CopyUsedGraphicStylesFrom(m_pModel
->GetStyleSheetPool());
691 SdrModel
* pDestModel
= rDestDoc
.GetDrawLayer();
692 // #i71538# use complete SdrViews
693 // SdrExchangeView aDestView( pDestModel );
694 SdrView
aDestView(*pDestModel
);
695 aDestView
.ShowSdrPage(aDestView
.GetModel().GetPage(0));
698 Point(m_aSrcSize
.Width()/2, m_aSrcSize
.Height()/2),
699 nullptr, SdrInsertFlags::NONE
);
701 // put objects to right layer (see ScViewFunc::PasteDataFormat for SotClipboardFormatId::DRAWING)
703 SdrPage
* pPage
= pDestModel
->GetPage(0);
706 SdrObjListIter
aIter( pPage
, SdrIterMode::DeepWithGroups
);
707 SdrObject
* pObject
= aIter
.Next();
710 if ( dynamic_cast<const SdrUnoObj
*>( pObject
) != nullptr )
711 pObject
->NbcSetLayer(SC_LAYER_CONTROLS
);
713 pObject
->NbcSetLayer(SC_LAYER_FRONT
);
714 pObject
= aIter
.Next();
718 tools::Rectangle
aDestArea( Point(), m_aSrcSize
);
719 m_aDocShellRef
->SetVisArea(aDestArea
);
721 ScViewOptions
aViewOpt( rDestDoc
.GetViewOptions() );
722 aViewOpt
.SetOption( VOPT_GRID
, false );
723 rDestDoc
.SetViewOptions( aViewOpt
);
725 ScViewData
aViewData(*m_aDocShellRef
, nullptr);
726 aViewData
.SetTabNo( 0 );
727 aViewData
.SetScreen( aDestArea
);
728 aViewData
.SetCurX( 0 );
729 aViewData
.SetCurY( 0 );
730 m_aDocShellRef
->UpdateOle(aViewData
, true);
733 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */