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/uno/Exception.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/XPropertySetInfo.hpp>
26 #include <com/sun/star/form/FormButtonType.hpp>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <unotools/streamwrap.hxx>
30 #include <svx/unomodel.hxx>
31 #include <unotools/tempfile.hxx>
32 #include <unotools/ucbstreamhelper.hxx>
33 #include <comphelper/storagehelper.hxx>
34 #include <comphelper/servicehelper.hxx>
36 #include <svtools/embedtransfer.hxx>
37 #include <sot/storage.hxx>
38 #include <vcl/virdev.hxx>
39 #include <svx/fmglob.hxx>
40 #include <svx/svditer.hxx>
41 #include <svx/svdograf.hxx>
42 #include <svx/svdoole2.hxx>
43 #include <svx/svdouno.hxx>
44 #include <svx/svdpage.hxx>
45 #include <svx/svdxcgv.hxx>
46 #include <sfx2/docfile.hxx>
47 #include <svl/itempool.hxx>
48 #include <svl/urlbmk.hxx>
49 #include <tools/urlobj.hxx>
50 #include <osl/mutex.hxx>
52 #include "drwtrans.hxx"
54 #include "drwlayer.hxx"
55 #include "drawview.hxx"
56 #include "viewdata.hxx"
58 #include "chartlis.hxx"
59 #include "rangeutl.hxx"
60 #include <formula/grammar.hxx>
61 #include "dragdata.hxx"
62 #include "clipdata.hxx"
65 #include "scitems.hxx"
68 #include <editeng/eeitem.hxx>
71 #include <editeng/fhgtitem.hxx>
72 #include <vcl/svapp.hxx>
74 using namespace com::sun::star
;
76 #define SCDRAWTRANS_TYPE_EMBOBJ SotClipboardFormatId::STRING
77 #define SCDRAWTRANS_TYPE_DRAWMODEL SotClipboardFormatId::BITMAP
78 #define SCDRAWTRANS_TYPE_DOCUMENT SotClipboardFormatId::GDIMETAFILE
80 ScDrawTransferObj::ScDrawTransferObj( SdrModel
* pClipModel
, ScDocShell
* pContainerShell
,
81 const TransferableObjectDescriptor
& rDesc
) :
88 pDragSourceView( NULL
),
89 nDragSourceFlags( 0 ),
90 bDragWasInternal( false ),
92 maShellID(SfxObjectShell::CreateShellID(pContainerShell
))
95 // check what kind of objects are contained
97 SdrPage
* pPage
= pModel
->GetPage(0);
100 SdrObjListIter
aIter( *pPage
, IM_FLAT
);
101 SdrObject
* pObject
= aIter
.Next();
102 if (pObject
&& !aIter
.Next()) // exactly one object?
107 sal_uInt16 nSdrObjKind
= pObject
->GetObjIdentifier();
108 if (nSdrObjKind
== OBJ_OLE2
)
110 // if object has no persistence it must be copied as a part of document
113 uno::Reference
< embed::XEmbedPersist
> xPersObj( static_cast<SdrOle2Obj
*>(pObject
)->GetObjRef(), uno::UNO_QUERY
);
114 if ( xPersObj
.is() && xPersObj
->hasEntry() )
117 catch( uno::Exception
& )
119 // aOleData is initialized later
124 if (nSdrObjKind
== OBJ_GRAF
)
127 if ( static_cast<SdrGrafObj
*>(pObject
)->GetGraphic().GetType() == GRAPHIC_BITMAP
)
133 SdrUnoObj
* pUnoCtrl
= PTR_CAST(SdrUnoObj
, pObject
);
134 if (pUnoCtrl
&& FmFormInventor
== pUnoCtrl
->GetObjInventor())
136 uno::Reference
<awt::XControlModel
> xControlModel
= pUnoCtrl
->GetUnoControlModel();
137 OSL_ENSURE( xControlModel
.is(), "uno control without model" );
138 if ( xControlModel
.is() )
140 uno::Reference
< beans::XPropertySet
> xPropSet( xControlModel
, uno::UNO_QUERY
);
141 uno::Reference
< beans::XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
143 OUString
sPropButtonType( "ButtonType" );
144 OUString
sPropTargetURL( "TargetURL" );
145 OUString
sPropLabel( "Label" );
147 if(xInfo
->hasPropertyByName( sPropButtonType
))
149 uno::Any aAny
= xPropSet
->getPropertyValue( sPropButtonType
);
150 form::FormButtonType eTmp
;
151 if ( (aAny
>>= eTmp
) && eTmp
== form::FormButtonType_URL
)
154 if(xInfo
->hasPropertyByName( sPropTargetURL
))
156 aAny
= xPropSet
->getPropertyValue( sPropTargetURL
);
158 if ( (aAny
>>= sTmp
) && !sTmp
.isEmpty() )
160 OUString aUrl
= sTmp
;
162 const SfxMedium
* pMedium
;
163 if (pContainerShell
&& (pMedium
= pContainerShell
->GetMedium()) != NULL
)
166 aAbs
= pMedium
->GetURLObject().smartRel2Abs( aUrl
, bWasAbs
).
167 GetMainURL(INetURLObject::NO_DECODE
);
168 // full path as stored INetBookmark must be encoded
175 if(xInfo
->hasPropertyByName( sPropLabel
))
177 aAny
= xPropSet
->getPropertyValue( sPropLabel
);
178 if ( (aAny
>>= sTmp
) && !sTmp
.isEmpty() )
183 pBookmark
= new INetBookmark( aAbs
, aLabel
);
193 // get size for object descriptor
195 // #i71538# use complete SdrViews
196 // SdrExchangeView aView(pModel);
197 SdrView
aView(pModel
);
198 SdrPageView
* pPv
= aView
.ShowSdrPage(aView
.GetModel()->GetPage(0));
199 aView
.MarkAllObj(pPv
);
200 aSrcSize
= aView
.GetAllMarkedRect().GetSize();
202 if ( bOleObj
) // single OLE object
204 SdrOle2Obj
* pObj
= GetSingleObject();
205 if ( pObj
&& pObj
->GetObjRef().is() )
206 SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc
, pObj
->GetObjRef(), pObj
->GetGraphic(), pObj
->GetAspect() );
209 aObjDesc
.maSize
= aSrcSize
;
210 PrepareOLE( aObjDesc
);
212 // remember a unique ID of the source document
214 if ( pContainerShell
)
216 ScDocument
& rDoc
= pContainerShell
->GetDocument();
217 nSourceDocID
= rDoc
.GetDocumentID();
220 ScChartHelper::FillProtectedChartRangesVector( m_aProtectedChartRangesVector
, &rDoc
, pPage
);
225 ScDrawTransferObj::~ScDrawTransferObj()
227 SolarMutexGuard aSolarGuard
;
229 ScModule
* pScMod
= SC_MOD();
230 if ( pScMod
->GetClipData().pDrawClipboard
== this )
232 OSL_FAIL("ScDrawTransferObj wasn't released");
233 pScMod
->SetClipObject( NULL
, NULL
);
235 if ( pScMod
->GetDragData().pDrawTransfer
== this )
237 OSL_FAIL("ScDrawTransferObj wasn't released");
238 pScMod
->ResetDragObject();
241 aOleData
= TransferableDataHelper(); // clear before releasing the mutex
242 aDocShellRef
.Clear();
245 aDrawPersistRef
.Clear(); // after the model
248 delete pDragSourceView
;
251 ScDrawTransferObj
* ScDrawTransferObj::GetOwnClipboard( vcl::Window
* )
253 ScDrawTransferObj
* pObj
= SC_MOD()->GetClipData().pDrawClipboard
;
257 static bool lcl_HasOnlyControls( SdrModel
* pModel
)
259 bool bOnlyControls
= false; // default if there are no objects
263 SdrPage
* pPage
= pModel
->GetPage(0);
266 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
267 SdrObject
* pObj
= aIter
.Next();
270 bOnlyControls
= true; // only set if there are any objects at all
273 if (!pObj
->ISA(SdrUnoObj
))
275 bOnlyControls
= false;
284 return bOnlyControls
;
287 void ScDrawTransferObj::AddSupportedFormats()
289 if ( bGrIsBit
) // single bitmap graphic
291 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
292 AddFormat( SotClipboardFormatId::SVXB
);
293 AddFormat( SotClipboardFormatId::PNG
);
294 AddFormat( SotClipboardFormatId::BITMAP
);
295 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
297 else if ( bGraphic
) // other graphic
300 AddFormat( SotClipboardFormatId::DRAWING
);
302 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
303 AddFormat( SotClipboardFormatId::SVXB
);
304 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
305 AddFormat( SotClipboardFormatId::PNG
);
306 AddFormat( SotClipboardFormatId::BITMAP
);
308 else if ( pBookmark
) // url button
310 // AddFormat( SotClipboardFormatId::EMBED_SOURCE );
311 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
312 AddFormat( SotClipboardFormatId::SOLK
);
313 AddFormat( SotClipboardFormatId::STRING
);
314 AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
);
315 AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK
);
316 AddFormat( SotClipboardFormatId::DRAWING
);
318 else if ( bOleObj
) // single OLE object
320 AddFormat( SotClipboardFormatId::EMBED_SOURCE
);
321 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
322 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
326 if ( aOleData
.GetTransferable().is() )
328 // get format list from object snapshot
329 // (this must be after inserting the default formats!)
331 DataFlavorExVector
aVector( aOleData
.GetDataFlavorExVector() );
332 DataFlavorExVector::iterator
aIter( aVector
.begin() ), aEnd( aVector
.end() );
334 while( aIter
!= aEnd
)
335 AddFormat( *aIter
++ );
338 else // any drawing objects
340 AddFormat( SotClipboardFormatId::EMBED_SOURCE
);
341 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR
);
342 AddFormat( SotClipboardFormatId::DRAWING
);
344 // leave out bitmap and metafile if there are only controls
345 if ( !lcl_HasOnlyControls( pModel
) )
347 AddFormat( SotClipboardFormatId::PNG
);
348 AddFormat( SotClipboardFormatId::BITMAP
);
349 AddFormat( SotClipboardFormatId::GDIMETAFILE
);
354 // AddFormat( SotClipboardFormatId::SVIM );
357 bool ScDrawTransferObj::GetData( const css::datatransfer::DataFlavor
& rFlavor
, const OUString
& rDestDoc
)
360 SotClipboardFormatId nFormat
= SotExchange::GetFormat( rFlavor
);
362 if ( bOleObj
&& nFormat
!= SotClipboardFormatId::GDIMETAFILE
)
366 if( aOleData
.GetTransferable().is() && aOleData
.HasFormat( rFlavor
) )
368 SdrSwapGraphicsMode
nOldSwapMode(SdrSwapGraphicsMode::DEFAULT
);
372 nOldSwapMode
= pModel
->GetSwapGraphicsMode();
373 pModel
->SetSwapGraphicsMode( SdrSwapGraphicsMode::PURGE
);
376 bOK
= SetAny( aOleData
.GetAny(rFlavor
, rDestDoc
), rFlavor
);
379 pModel
->SetSwapGraphicsMode( nOldSwapMode
);
385 if( HasFormat( nFormat
) )
387 if ( nFormat
== SotClipboardFormatId::LINKSRCDESCRIPTOR
|| nFormat
== SotClipboardFormatId::OBJECTDESCRIPTOR
)
389 bOK
= SetTransferableObjectDescriptor( aObjDesc
, rFlavor
);
391 else if ( nFormat
== SotClipboardFormatId::DRAWING
)
393 bOK
= SetObject( pModel
, SCDRAWTRANS_TYPE_DRAWMODEL
, rFlavor
);
395 else if ( nFormat
== SotClipboardFormatId::BITMAP
396 || nFormat
== SotClipboardFormatId::PNG
397 || nFormat
== SotClipboardFormatId::GDIMETAFILE
)
399 // #i71538# use complete SdrViews
400 // SdrExchangeView aView( pModel );
401 SdrView
aView( pModel
);
402 SdrPageView
* pPv
= aView
.ShowSdrPage(aView
.GetModel()->GetPage(0));
403 OSL_ENSURE( pPv
, "pPv not there..." );
404 aView
.MarkAllObj( pPv
);
405 if ( nFormat
== SotClipboardFormatId::GDIMETAFILE
)
406 bOK
= SetGDIMetaFile( aView
.GetMarkedObjMetaFile(true), rFlavor
);
408 bOK
= SetBitmapEx( aView
.GetMarkedObjBitmapEx(true), rFlavor
);
410 else if ( nFormat
== SotClipboardFormatId::SVXB
)
412 // only enabled for single graphics object
414 SdrPage
* pPage
= pModel
->GetPage(0);
417 SdrObjListIter
aIter( *pPage
, IM_FLAT
);
418 SdrObject
* pObject
= aIter
.Next();
419 if (pObject
&& pObject
->GetObjIdentifier() == OBJ_GRAF
)
421 SdrGrafObj
* pGraphObj
= static_cast<SdrGrafObj
*>(pObject
);
422 bOK
= SetGraphic( pGraphObj
->GetGraphic(), rFlavor
);
426 else if ( nFormat
== SotClipboardFormatId::EMBED_SOURCE
)
428 if ( bOleObj
) // single OLE object
430 SdrOle2Obj
* pObj
= GetSingleObject();
431 if ( pObj
&& pObj
->GetObjRef().is() )
433 bOK
= SetObject( pObj
->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ
, rFlavor
);
436 else // create object from contents
438 //TODO/LATER: needs new Format, because now single OLE and "this" are different
439 InitDocShell(); // set aDocShellRef
441 SfxObjectShell
* pEmbObj
= aDocShellRef
;
442 bOK
= SetObject( pEmbObj
, SCDRAWTRANS_TYPE_DOCUMENT
, rFlavor
);
447 bOK
= SetINetBookmark( *pBookmark
, rFlavor
);
453 bool ScDrawTransferObj::WriteObject( tools::SvRef
<SotStorageStream
>& rxOStm
, void* pUserObject
, SotClipboardFormatId nUserObjectId
,
454 const ::com::sun::star::datatransfer::DataFlavor
& /* rFlavor */ )
456 // called from SetObject, put data into stream
459 switch (nUserObjectId
)
461 case SCDRAWTRANS_TYPE_DRAWMODEL
:
463 SdrModel
* pDrawModel
= static_cast<SdrModel
*>(pUserObject
);
464 rxOStm
->SetBufferSize( 0xff00 );
467 // for the changed pool defaults from drawing layer pool set those
468 // attributes as hard attributes to preserve them for saving
469 const SfxItemPool
& rItemPool
= pModel
->GetItemPool();
470 const SvxFontHeightItem
& rDefaultFontHeight
= static_cast<const SvxFontHeightItem
&>(rItemPool
.GetDefaultItem(EE_CHAR_FONTHEIGHT
));
472 // SW should have no MasterPages
473 OSL_ENSURE(0L == pModel
->GetMasterPageCount(), "SW with MasterPages (!)");
475 for(sal_uInt16
a(0); a
< pModel
->GetPageCount(); a
++)
477 const SdrPage
* pPage
= pModel
->GetPage(a
);
478 SdrObjListIter
aIter(*pPage
, IM_DEEPNOGROUPS
);
480 while(aIter
.IsMore())
482 SdrObject
* pObj
= aIter
.Next();
483 const SvxFontHeightItem
& rItem
= static_cast<const SvxFontHeightItem
&>(pObj
->GetMergedItem(EE_CHAR_FONTHEIGHT
));
485 if(rItem
.GetHeight() == rDefaultFontHeight
.GetHeight())
487 pObj
->SetMergedItem(rDefaultFontHeight
);
493 com::sun::star::uno::Reference
<com::sun::star::io::XOutputStream
> xDocOut( new utl::OOutputStreamWrapper( *rxOStm
) );
494 if( SvxDrawingLayerExport( pDrawModel
, xDocOut
) )
498 bRet
= ( rxOStm
->GetError() == ERRCODE_NONE
);
502 case SCDRAWTRANS_TYPE_EMBOBJ
:
504 // impl. for "single OLE"
505 embed::XEmbeddedObject
* pEmbObj
= static_cast<embed::XEmbeddedObject
*>(pUserObject
);
507 ::utl::TempFile aTempFile
;
508 aTempFile
.EnableKillingFile();
509 uno::Reference
< embed::XStorage
> xWorkStore
=
510 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile
.GetURL(), embed::ElementModes::READWRITE
);
512 uno::Reference
< embed::XEmbedPersist
> xPers( (embed::XVisualObject
*)pEmbObj
, uno::UNO_QUERY
);
517 uno::Sequence
< beans::PropertyValue
> aSeq
;
518 OUString
aDummyName("Dummy");
519 xPers
->storeToEntry( xWorkStore
, aDummyName
, aSeq
, aSeq
);
520 if ( xWorkStore
->isStreamElement( aDummyName
) )
522 uno::Reference
< io::XOutputStream
> xDocOut( new utl::OOutputStreamWrapper( *rxOStm
) );
523 uno::Reference
< io::XStream
> xNewStream
= xWorkStore
->openStreamElement( aDummyName
, embed::ElementModes::READ
);
524 ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream
->getInputStream(), xDocOut
);
528 uno::Reference
< io::XStream
> xDocStr( new utl::OStreamWrapper( *rxOStm
) );
529 uno::Reference
< embed::XStorage
> xDocStg
= ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr
);
530 uno::Reference
< embed::XStorage
> xNewStg
= xWorkStore
->openStorageElement( aDummyName
, embed::ElementModes::READ
);
531 xNewStg
->copyToStorage( xDocStg
);
532 uno::Reference
< embed::XTransactedObject
> xTrans( xDocStg
, uno::UNO_QUERY
);
539 catch ( uno::Exception
& )
546 case SCDRAWTRANS_TYPE_DOCUMENT
:
548 // impl. for "DocShell"
549 SfxObjectShell
* pEmbObj
= static_cast<SfxObjectShell
*>(pUserObject
);
553 ::utl::TempFile aTempFile
;
554 aTempFile
.EnableKillingFile();
555 uno::Reference
< embed::XStorage
> xWorkStore
=
556 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile
.GetURL(), embed::ElementModes::READWRITE
);
558 // write document storage
559 pEmbObj
->SetupStorage( xWorkStore
, SOFFICE_FILEFORMAT_CURRENT
, false, false );
561 // mba: no relative URLs for clipboard!
562 SfxMedium
aMedium( xWorkStore
, OUString() );
563 bRet
= pEmbObj
->DoSaveObjectAs( aMedium
, false );
564 pEmbObj
->DoSaveCompleted();
566 uno::Reference
< embed::XTransactedObject
> xTransact( xWorkStore
, uno::UNO_QUERY
);
567 if ( xTransact
.is() )
570 SvStream
* pSrcStm
= ::utl::UcbStreamHelper::CreateStream( aTempFile
.GetURL(), StreamMode::READ
);
573 rxOStm
->SetBufferSize( 0xff00 );
574 rxOStm
->WriteStream( *pSrcStm
);
580 xWorkStore
->dispose();
581 xWorkStore
= uno::Reference
< embed::XStorage
>();
584 catch ( uno::Exception
& )
587 bRet
= ( rxOStm
->GetError() == ERRCODE_NONE
);
592 OSL_FAIL("unknown object id");
597 void ScDrawTransferObj::ObjectReleased()
599 ScModule
* pScMod
= SC_MOD();
600 if ( pScMod
->GetClipData().pDrawClipboard
== this )
601 pScMod
->SetClipObject( NULL
, NULL
);
603 TransferableHelper::ObjectReleased();
606 void ScDrawTransferObj::DragFinished( sal_Int8 nDropAction
)
608 if ( nDropAction
== DND_ACTION_MOVE
&& !bDragWasInternal
&& !(nDragSourceFlags
& SC_DROP_NAVIGATOR
) )
610 // move: delete source objects
612 if ( pDragSourceView
)
613 pDragSourceView
->DeleteMarked();
616 ScModule
* pScMod
= SC_MOD();
617 if ( pScMod
->GetDragData().pDrawTransfer
== this )
618 pScMod
->ResetDragObject();
620 DELETEZ( pDragSourceView
);
622 TransferableHelper::DragFinished( nDropAction
);
625 void ScDrawTransferObj::SetDrawPersist( const SfxObjectShellRef
& rRef
)
627 aDrawPersistRef
= rRef
;
630 static void lcl_InitMarks( SdrMarkView
& rDest
, const SdrMarkView
& rSource
, SCTAB nTab
)
632 rDest
.ShowSdrPage(rDest
.GetModel()->GetPage(nTab
));
633 SdrPageView
* pDestPV
= rDest
.GetSdrPageView();
634 OSL_ENSURE(pDestPV
,"PageView ?");
636 const SdrMarkList
& rMarkList
= rSource
.GetMarkedObjectList();
637 const size_t nCount
= rMarkList
.GetMarkCount();
638 for (size_t i
=0; i
<nCount
; ++i
)
640 SdrMark
* pMark
= rMarkList
.GetMark(i
);
641 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
643 rDest
.MarkObj(pObj
, pDestPV
);
647 void ScDrawTransferObj::SetDragSource( ScDrawView
* pView
)
649 DELETEZ( pDragSourceView
);
650 pDragSourceView
= new SdrView( pView
->GetModel() );
651 lcl_InitMarks( *pDragSourceView
, *pView
, pView
->GetTab() );
653 //! add as listener with document, delete pDragSourceView if document gone
656 void ScDrawTransferObj::SetDragSourceObj( SdrObject
* pObj
, SCTAB nTab
)
658 DELETEZ( pDragSourceView
);
659 pDragSourceView
= new SdrView( pObj
->GetModel() );
660 pDragSourceView
->ShowSdrPage(pDragSourceView
->GetModel()->GetPage(nTab
));
661 SdrPageView
* pPV
= pDragSourceView
->GetSdrPageView();
662 pDragSourceView
->MarkObj(pObj
, pPV
);
664 //! add as listener with document, delete pDragSourceView if document gone
667 void ScDrawTransferObj::SetDragSourceFlags( sal_uInt16 nFlags
)
669 nDragSourceFlags
= nFlags
;
672 void ScDrawTransferObj::SetDragWasInternal()
674 bDragWasInternal
= true;
677 OUString
ScDrawTransferObj::GetShellID() const
682 SdrOle2Obj
* ScDrawTransferObj::GetSingleObject()
684 // if single OLE object was copied, get its object
686 SdrPage
* pPage
= pModel
->GetPage(0);
689 SdrObjListIter
aIter( *pPage
, IM_FLAT
);
690 SdrObject
* pObject
= aIter
.Next();
691 if (pObject
&& pObject
->GetObjIdentifier() == OBJ_OLE2
)
693 return static_cast<SdrOle2Obj
*>(pObject
);
700 void ScDrawTransferObj::CreateOLEData()
702 if (aOleData
.GetTransferable().is())
706 SdrOle2Obj
* pObj
= GetSingleObject();
707 if (!pObj
|| !pObj
->GetObjRef().is())
708 // No OLE object present.
711 SvEmbedTransferHelper
* pEmbedTransfer
=
712 new SvEmbedTransferHelper(
713 pObj
->GetObjRef(), pObj
->GetGraphic(), pObj
->GetAspect());
715 pEmbedTransfer
->SetParentShellID(maShellID
);
717 aOleData
= TransferableDataHelper(pEmbedTransfer
);
720 // initialize aDocShellRef with a live document from the ClipDoc
722 void ScDrawTransferObj::InitDocShell()
724 if ( !aDocShellRef
.Is() )
726 ScDocShell
* pDocSh
= new ScDocShell
;
727 aDocShellRef
= pDocSh
; // ref must be there before InitNew
729 pDocSh
->DoInitNew(NULL
);
731 ScDocument
& rDestDoc
= pDocSh
->GetDocument();
732 rDestDoc
.InitDrawLayer( pDocSh
);
734 SdrModel
* pDestModel
= rDestDoc
.GetDrawLayer();
735 // #i71538# use complete SdrViews
736 // SdrExchangeView aDestView( pDestModel );
737 SdrView
aDestView( pDestModel
);
738 aDestView
.ShowSdrPage(aDestView
.GetModel()->GetPage(0));
741 Point(aSrcSize
.Width()/2, aSrcSize
.Height()/2),
742 NULL
, SdrInsertFlags::NONE
, OUString(), OUString());
744 // put objects to right layer (see ScViewFunc::PasteDataFormat for SotClipboardFormatId::DRAWING)
746 SdrPage
* pPage
= pDestModel
->GetPage(0);
749 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
750 SdrObject
* pObject
= aIter
.Next();
753 if ( pObject
->ISA(SdrUnoObj
) )
754 pObject
->NbcSetLayer(SC_LAYER_CONTROLS
);
756 pObject
->NbcSetLayer(SC_LAYER_FRONT
);
757 pObject
= aIter
.Next();
762 Rectangle
aDestArea( aTmpPoint
, aSrcSize
);
763 pDocSh
->SetVisArea( aDestArea
);
765 ScViewOptions
aViewOpt( rDestDoc
.GetViewOptions() );
766 aViewOpt
.SetOption( VOPT_GRID
, false );
767 rDestDoc
.SetViewOptions( aViewOpt
);
769 ScViewData
aViewData( pDocSh
, NULL
);
770 aViewData
.SetTabNo( 0 );
771 aViewData
.SetScreen( aDestArea
);
772 aViewData
.SetCurX( 0 );
773 aViewData
.SetCurY( 0 );
774 pDocSh
->UpdateOle(&aViewData
, true);
780 class theScDrawTransferObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScDrawTransferObjUnoTunnelId
> {};
783 const com::sun::star::uno::Sequence
< sal_Int8
>& ScDrawTransferObj::getUnoTunnelId()
785 return theScDrawTransferObjUnoTunnelId::get().getSeq();
788 sal_Int64 SAL_CALL
ScDrawTransferObj::getSomething( const com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( com::sun::star::uno::RuntimeException
, std::exception
)
791 if( ( rId
.getLength() == 16 ) &&
792 ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId
.getConstArray(), 16 ) ) )
794 nRet
= reinterpret_cast< sal_Int64
>( this );
797 nRet
= TransferableHelper::getSomething(rId
);
801 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */