update dev300-m58
[ooovba.git] / sc / source / ui / app / drwtrans.cxx
blob4c63c2746091908ec5670e0bd3b04de0af07be13
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drwtrans.cxx,v $
10 * $Revision: 1.38 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
37 #include <com/sun/star/embed/XTransactedObject.hpp>
38 #include <com/sun/star/embed/XEmbedPersist.hpp>
39 #include <com/sun/star/uno/Exception.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/beans/XPropertySetInfo.hpp>
43 #include <com/sun/star/form/FormButtonType.hpp>
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <unotools/streamwrap.hxx>
47 #include <svx/unomodel.hxx>
48 #include <unotools/tempfile.hxx>
49 #include <unotools/ucbstreamhelper.hxx>
50 #include <comphelper/storagehelper.hxx>
52 #include <svtools/embedtransfer.hxx>
53 #include <sot/storage.hxx>
54 #include <vcl/virdev.hxx>
55 #include <svx/fmglob.hxx>
56 #include <svx/svditer.hxx>
57 #include <svx/svdograf.hxx>
58 #include <svx/svdoole2.hxx>
59 #include <svx/svdouno.hxx>
60 #include <svx/svdpage.hxx>
61 #include <svx/svdxcgv.hxx>
62 #include <sfx2/docfile.hxx>
63 #include <svtools/itempool.hxx>
64 #include <svtools/urlbmk.hxx>
65 #include <tools/urlobj.hxx>
66 #include <vos/mutex.hxx>
68 #include "drwtrans.hxx"
69 #include "docsh.hxx"
70 #include "drwlayer.hxx"
71 #include "drawview.hxx"
72 #include "viewdata.hxx"
73 #include "scmod.hxx"
75 // #108584#
76 #include "scitems.hxx"
78 // #108584#
79 #include <svx/eeitem.hxx>
81 // #108584#
82 #include <svx/fhgtitem.hxx>
83 #include <vcl/svapp.hxx>
85 using namespace com::sun::star;
87 // -----------------------------------------------------------------------
89 #define SCDRAWTRANS_TYPE_EMBOBJ 1
90 #define SCDRAWTRANS_TYPE_DRAWMODEL 2
91 #define SCDRAWTRANS_TYPE_DOCUMENT 3
93 // -----------------------------------------------------------------------
95 // -----------------------------------------------------------------------
97 ScDrawTransferObj::ScDrawTransferObj( SdrModel* pClipModel, ScDocShell* pContainerShell,
98 const TransferableObjectDescriptor& rDesc ) :
99 pModel( pClipModel ),
100 aObjDesc( rDesc ),
101 pBookmark( NULL ),
102 bGraphic( FALSE ),
103 bGrIsBit( FALSE ),
104 bOleObj( FALSE ),
105 pDragSourceView( NULL ),
106 nDragSourceFlags( 0 ),
107 bDragWasInternal( FALSE ),
108 nSourceDocID( 0 )
111 // check what kind of objects are contained
114 SdrPage* pPage = pModel->GetPage(0);
115 if (pPage)
117 SdrObjListIter aIter( *pPage, IM_FLAT );
118 SdrObject* pObject = aIter.Next();
119 if (pObject && !aIter.Next()) // exactly one object?
122 // OLE object
125 UINT16 nSdrObjKind = pObject->GetObjIdentifier();
126 if (nSdrObjKind == OBJ_OLE2)
128 // if object has no persistence it must be copied as a part of document
131 uno::Reference< embed::XEmbedPersist > xPersObj( ((SdrOle2Obj*)pObject)->GetObjRef(), uno::UNO_QUERY );
132 if ( xPersObj.is() && xPersObj->hasEntry() )
133 bOleObj = TRUE;
135 catch( uno::Exception& )
137 // aOleData is initialized later
141 // Graphic object
144 if (nSdrObjKind == OBJ_GRAF)
146 bGraphic = TRUE;
147 if ( ((SdrGrafObj*)pObject)->GetGraphic().GetType() == GRAPHIC_BITMAP )
148 bGrIsBit = TRUE;
152 // URL button
155 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObject);
156 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
158 uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
159 DBG_ASSERT( xControlModel.is(), "uno control without model" );
160 if ( xControlModel.is() )
162 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
163 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
165 rtl::OUString sPropButtonType = rtl::OUString::createFromAscii( "ButtonType" );
166 rtl::OUString sPropTargetURL = rtl::OUString::createFromAscii( "TargetURL" );
167 rtl::OUString sPropLabel = rtl::OUString::createFromAscii( "Label" );
169 if(xInfo->hasPropertyByName( sPropButtonType ))
171 uno::Any aAny = xPropSet->getPropertyValue( sPropButtonType );
172 form::FormButtonType eTmp;
173 if ( (aAny >>= eTmp) && eTmp == form::FormButtonType_URL )
175 // URL
176 if(xInfo->hasPropertyByName( sPropTargetURL ))
178 aAny = xPropSet->getPropertyValue( sPropTargetURL );
179 rtl::OUString sTmp;
180 if ( (aAny >>= sTmp) && sTmp.getLength() )
182 String aUrl = sTmp;
183 String aAbs;
184 const SfxMedium* pMedium;
185 if (pContainerShell && (pMedium = pContainerShell->GetMedium()) != NULL)
187 bool bWasAbs = true;
188 aAbs = pMedium->GetURLObject().smartRel2Abs( aUrl, bWasAbs ).
189 GetMainURL(INetURLObject::NO_DECODE);
190 // full path as stored INetBookmark must be encoded
192 else
193 aAbs = aUrl;
195 // Label
196 String aLabel;
197 if(xInfo->hasPropertyByName( sPropLabel ))
199 aAny = xPropSet->getPropertyValue( sPropLabel );
200 if ( (aAny >>= sTmp) && sTmp.getLength() )
202 aLabel = String(sTmp);
205 pBookmark = new INetBookmark( aAbs, aLabel );
216 // get size for object descriptor
219 // #i71538# use complete SdrViews
220 // SdrExchangeView aView(pModel);
221 SdrView aView(pModel);
222 SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
223 aView.MarkAllObj(pPv);
224 aSrcSize = aView.GetAllMarkedRect().GetSize();
226 if ( bOleObj ) // single OLE object
228 SdrOle2Obj* pObj = GetSingleObject();
229 if ( pObj && pObj->GetObjRef().is() )
230 SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() );
233 aObjDesc.maSize = aSrcSize;
234 PrepareOLE( aObjDesc );
237 // remember a unique ID of the source document
239 if ( pContainerShell )
241 const ScDocument* pDoc = pContainerShell->GetDocument();
242 if ( pDoc )
243 nSourceDocID = pDoc->GetDocumentID();
247 ScDrawTransferObj::~ScDrawTransferObj()
249 Application::GetSolarMutex().acquire(); //! ???
251 ScModule* pScMod = SC_MOD();
252 if ( pScMod->GetClipData().pDrawClipboard == this )
254 DBG_ERROR("ScDrawTransferObj wasn't released");
255 pScMod->SetClipObject( NULL, NULL );
257 if ( pScMod->GetDragData().pDrawTransfer == this )
259 DBG_ERROR("ScDrawTransferObj wasn't released");
260 pScMod->ResetDragObject();
263 aOleData = TransferableDataHelper(); // clear before releasing the mutex
264 aDocShellRef.Clear();
266 delete pModel;
267 aDrawPersistRef.Clear(); // after the model
269 delete pBookmark;
270 delete pDragSourceView;
272 Application::GetSolarMutex().release(); //! ???
275 // static
276 ScDrawTransferObj* ScDrawTransferObj::GetOwnClipboard( Window* )
278 ScDrawTransferObj* pObj = SC_MOD()->GetClipData().pDrawClipboard;
279 return pObj;
282 BOOL lcl_HasOnlyControls( SdrModel* pModel )
284 BOOL bOnlyControls = FALSE; // default if there are no objects
286 if ( pModel )
288 SdrPage* pPage = pModel->GetPage(0);
289 if (pPage)
291 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
292 SdrObject* pObj = aIter.Next();
293 if ( pObj )
295 bOnlyControls = TRUE; // only set if there are any objects at all
296 while ( pObj )
298 if (!pObj->ISA(SdrUnoObj))
300 bOnlyControls = FALSE;
301 break;
303 pObj = aIter.Next();
309 return bOnlyControls;
312 void ScDrawTransferObj::AddSupportedFormats()
314 if ( bGrIsBit ) // single bitmap graphic
316 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
317 AddFormat( SOT_FORMATSTR_ID_SVXB );
318 AddFormat( SOT_FORMAT_BITMAP );
319 AddFormat( SOT_FORMAT_GDIMETAFILE );
321 else if ( bGraphic ) // other graphic
323 // #i25616#
324 AddFormat( SOT_FORMATSTR_ID_DRAWING );
326 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
327 AddFormat( SOT_FORMATSTR_ID_SVXB );
328 AddFormat( SOT_FORMAT_GDIMETAFILE );
329 AddFormat( SOT_FORMAT_BITMAP );
331 else if ( pBookmark ) // url button
333 // AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
334 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
335 AddFormat( SOT_FORMATSTR_ID_SOLK );
336 AddFormat( SOT_FORMAT_STRING );
337 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
338 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
339 AddFormat( SOT_FORMATSTR_ID_DRAWING );
341 else if ( bOleObj ) // single OLE object
343 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
344 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
345 AddFormat( SOT_FORMAT_GDIMETAFILE );
347 if ( !aOleData.GetTransferable().is() )
349 SdrOle2Obj* pObj = GetSingleObject();
350 if ( pObj && pObj->GetObjRef().is() )
351 aOleData = TransferableDataHelper( new SvEmbedTransferHelper( pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() ) ) ;
353 if ( aOleData.GetTransferable().is() )
355 // get format list from object snapshot
356 // (this must be after inserting the default formats!)
358 DataFlavorExVector aVector( aOleData.GetDataFlavorExVector() );
359 DataFlavorExVector::iterator aIter( aVector.begin() ), aEnd( aVector.end() );
361 while( aIter != aEnd )
362 AddFormat( *aIter++ );
365 else // any drawing objects
367 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
368 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
369 AddFormat( SOT_FORMATSTR_ID_DRAWING );
371 // #103556# leave out bitmap and metafile if there are only controls
372 if ( !lcl_HasOnlyControls( pModel ) )
374 AddFormat( SOT_FORMAT_BITMAP );
375 AddFormat( SOT_FORMAT_GDIMETAFILE );
379 // if( pImageMap )
380 // AddFormat( SOT_FORMATSTR_ID_SVIM );
383 sal_Bool ScDrawTransferObj::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
385 sal_Bool bOK = sal_False;
386 sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
388 if ( bOleObj && nFormat != SOT_FORMAT_GDIMETAFILE )
390 if ( !aOleData.GetTransferable().is() )
392 SdrOle2Obj* pObj = GetSingleObject();
393 if ( pObj && pObj->GetObjRef().is() )
394 aOleData = TransferableDataHelper( new SvEmbedTransferHelper( pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() ) ) ;
397 if( aOleData.GetTransferable().is() && aOleData.HasFormat( rFlavor ) )
399 ULONG nOldSwapMode = 0;
401 if( pModel )
403 nOldSwapMode = pModel->GetSwapGraphicsMode();
404 pModel->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
407 bOK = SetAny( aOleData.GetAny( rFlavor ), rFlavor );
409 if( pModel )
410 pModel->SetSwapGraphicsMode( nOldSwapMode );
412 return bOK;
416 if( HasFormat( nFormat ) )
418 if ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
420 bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor );
422 else if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
424 bOK = SetObject( pModel, SCDRAWTRANS_TYPE_DRAWMODEL, rFlavor );
426 else if ( nFormat == SOT_FORMAT_BITMAP || nFormat == SOT_FORMAT_GDIMETAFILE )
428 // #i71538# use complete SdrViews
429 // SdrExchangeView aView( pModel );
430 SdrView aView( pModel );
431 SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
432 DBG_ASSERT( pPv, "pPv not there..." );
433 aView.MarkAllObj( pPv );
434 if ( nFormat == SOT_FORMAT_GDIMETAFILE )
435 bOK = SetGDIMetaFile( aView.GetAllMarkedMetaFile( TRUE ), rFlavor );
436 else
437 bOK = SetBitmap( aView.GetAllMarkedBitmap( TRUE ), rFlavor );
439 else if ( nFormat == SOT_FORMATSTR_ID_SVXB )
441 // only enabled for single graphics object
443 SdrPage* pPage = pModel->GetPage(0);
444 if (pPage)
446 SdrObjListIter aIter( *pPage, IM_FLAT );
447 SdrObject* pObject = aIter.Next();
448 if (pObject && pObject->GetObjIdentifier() == OBJ_GRAF)
450 SdrGrafObj* pGraphObj = (SdrGrafObj*) pObject;
451 bOK = SetGraphic( pGraphObj->GetGraphic(), rFlavor );
455 else if ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
457 if ( bOleObj ) // single OLE object
459 SdrOle2Obj* pObj = GetSingleObject();
460 if ( pObj && pObj->GetObjRef().is() )
462 bOK = SetObject( pObj->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ, rFlavor );
465 else // create object from contents
467 //TODO/LATER: needs new Format, because now single OLE and "this" are different
468 InitDocShell(); // set aDocShellRef
470 SfxObjectShell* pEmbObj = aDocShellRef;
471 bOK = SetObject( pEmbObj, SCDRAWTRANS_TYPE_DOCUMENT, rFlavor );
474 else if( pBookmark )
476 bOK = SetINetBookmark( *pBookmark, rFlavor );
479 return bOK;
482 sal_Bool ScDrawTransferObj::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
483 const ::com::sun::star::datatransfer::DataFlavor& /* rFlavor */ )
485 // called from SetObject, put data into stream
487 sal_Bool bRet = sal_False;
488 switch (nUserObjectId)
490 case SCDRAWTRANS_TYPE_DRAWMODEL:
492 SdrModel* pDrawModel = (SdrModel*)pUserObject;
493 rxOStm->SetBufferSize( 0xff00 );
495 // #108584#
496 // for the changed pool defaults from drawing layer pool set those
497 // attributes as hard attributes to preserve them for saving
498 const SfxItemPool& rItemPool = pModel->GetItemPool();
499 const SvxFontHeightItem& rDefaultFontHeight = (const SvxFontHeightItem&)rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
501 // SW should have no MasterPages
502 DBG_ASSERT(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
504 for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
506 const SdrPage* pPage = pModel->GetPage(a);
507 SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS);
509 while(aIter.IsMore())
511 SdrObject* pObj = aIter.Next();
512 const SvxFontHeightItem& rItem = (const SvxFontHeightItem&)pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
514 if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
516 pObj->SetMergedItem(rDefaultFontHeight);
522 com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
523 if( SvxDrawingLayerExport( pDrawModel, xDocOut ) )
524 rxOStm->Commit();
527 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
529 break;
531 case SCDRAWTRANS_TYPE_EMBOBJ:
533 // impl. for "single OLE"
534 embed::XEmbeddedObject* pEmbObj = (embed::XEmbeddedObject*) pUserObject;
536 ::utl::TempFile aTempFile;
537 aTempFile.EnableKillingFile();
538 uno::Reference< embed::XStorage > xWorkStore =
539 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
541 uno::Reference < embed::XEmbedPersist > xPers( (embed::XVisualObject*)pEmbObj, uno::UNO_QUERY );
542 if ( xPers.is() )
546 uno::Sequence < beans::PropertyValue > aSeq;
547 ::rtl::OUString aDummyName = ::rtl::OUString::createFromAscii("Dummy");
548 xPers->storeToEntry( xWorkStore, aDummyName, aSeq, aSeq );
549 if ( xWorkStore->isStreamElement( aDummyName ) )
551 uno::Reference < io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
552 uno::Reference < io::XStream > xNewStream = xWorkStore->openStreamElement( aDummyName, embed::ElementModes::READ );
553 ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream->getInputStream(), xDocOut );
555 else
557 uno::Reference < io::XStream > xDocStr( new utl::OStreamWrapper( *rxOStm ) );
558 uno::Reference< embed::XStorage > xDocStg = ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr );
559 uno::Reference < embed::XStorage > xNewStg = xWorkStore->openStorageElement( aDummyName, embed::ElementModes::READ );
560 xNewStg->copyToStorage( xDocStg );
561 uno::Reference < embed::XTransactedObject > xTrans( xDocStg, uno::UNO_QUERY );
562 if ( xTrans.is() )
563 xTrans->commit();
566 rxOStm->Commit();
568 catch ( uno::Exception& )
573 break;
575 case SCDRAWTRANS_TYPE_DOCUMENT:
577 // impl. for "DocShell"
578 SfxObjectShell* pEmbObj = (SfxObjectShell*) pUserObject;
582 ::utl::TempFile aTempFile;
583 aTempFile.EnableKillingFile();
584 uno::Reference< embed::XStorage > xWorkStore =
585 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
587 // write document storage
588 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
590 // mba: no relative ULRs for clipboard!
591 SfxMedium aMedium( xWorkStore, String() );
592 bRet = pEmbObj->DoSaveObjectAs( aMedium, FALSE );
593 pEmbObj->DoSaveCompleted();
595 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
596 if ( xTransact.is() )
597 xTransact->commit();
599 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
600 if( pSrcStm )
602 rxOStm->SetBufferSize( 0xff00 );
603 *rxOStm << *pSrcStm;
604 delete pSrcStm;
607 bRet = TRUE;
609 xWorkStore->dispose();
610 xWorkStore = uno::Reference < embed::XStorage >();
611 rxOStm->Commit();
613 catch ( uno::Exception& )
616 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
618 break;
620 default:
621 DBG_ERROR("unknown object id");
623 return bRet;
626 void ScDrawTransferObj::ObjectReleased()
628 ScModule* pScMod = SC_MOD();
629 if ( pScMod->GetClipData().pDrawClipboard == this )
630 pScMod->SetClipObject( NULL, NULL );
632 TransferableHelper::ObjectReleased();
635 void ScDrawTransferObj::DragFinished( sal_Int8 nDropAction )
637 if ( nDropAction == DND_ACTION_MOVE && !bDragWasInternal && !(nDragSourceFlags & SC_DROP_NAVIGATOR) )
639 // move: delete source objects
641 if ( pDragSourceView )
642 pDragSourceView->DeleteMarked();
645 ScModule* pScMod = SC_MOD();
646 if ( pScMod->GetDragData().pDrawTransfer == this )
647 pScMod->ResetDragObject();
649 DELETEZ( pDragSourceView );
651 TransferableHelper::DragFinished( nDropAction );
654 void ScDrawTransferObj::SetDrawPersist( const SfxObjectShellRef& rRef )
656 aDrawPersistRef = rRef;
659 void lcl_InitMarks( SdrMarkView& rDest, const SdrMarkView& rSource, SCTAB nTab )
661 rDest.ShowSdrPage(rDest.GetModel()->GetPage(nTab));
662 SdrPageView* pDestPV = rDest.GetSdrPageView();
663 DBG_ASSERT(pDestPV,"PageView ?");
665 const SdrMarkList& rMarkList = rSource.GetMarkedObjectList();
666 ULONG nCount = rMarkList.GetMarkCount();
667 for (ULONG i=0; i<nCount; i++)
669 SdrMark* pMark = rMarkList.GetMark(i);
670 SdrObject* pObj = pMark->GetMarkedSdrObj();
672 rDest.MarkObj(pObj, pDestPV);
676 void ScDrawTransferObj::SetDragSource( ScDrawView* pView )
678 DELETEZ( pDragSourceView );
679 pDragSourceView = new SdrView( pView->GetModel() );
680 lcl_InitMarks( *pDragSourceView, *pView, pView->GetTab() );
682 //! add as listener with document, delete pDragSourceView if document gone
685 void ScDrawTransferObj::SetDragSourceObj( SdrObject* pObj, SCTAB nTab )
687 DELETEZ( pDragSourceView );
688 pDragSourceView = new SdrView( pObj->GetModel() );
689 pDragSourceView->ShowSdrPage(pDragSourceView->GetModel()->GetPage(nTab));
690 SdrPageView* pPV = pDragSourceView->GetSdrPageView();
691 pDragSourceView->MarkObj(pObj, pPV);
693 //! add as listener with document, delete pDragSourceView if document gone
696 void ScDrawTransferObj::SetDragSourceFlags( USHORT nFlags )
698 nDragSourceFlags = nFlags;
701 void ScDrawTransferObj::SetDragWasInternal()
703 bDragWasInternal = TRUE;
706 SdrOle2Obj* ScDrawTransferObj::GetSingleObject()
708 // if single OLE object was copied, get its object
710 SdrPage* pPage = pModel->GetPage(0);
711 if (pPage)
713 SdrObjListIter aIter( *pPage, IM_FLAT );
714 SdrObject* pObject = aIter.Next();
715 if (pObject && pObject->GetObjIdentifier() == OBJ_OLE2)
717 return (SdrOle2Obj*) pObject;
721 return NULL;
725 // initialize aDocShellRef with a live document from the ClipDoc
728 void ScDrawTransferObj::InitDocShell()
730 if ( !aDocShellRef.Is() )
732 ScDocShell* pDocSh = new ScDocShell;
733 aDocShellRef = pDocSh; // ref must be there before InitNew
735 pDocSh->DoInitNew(NULL);
737 ScDocument* pDestDoc = pDocSh->GetDocument();
738 pDestDoc->InitDrawLayer( pDocSh );
740 SdrModel* pDestModel = pDestDoc->GetDrawLayer();
741 // #i71538# use complete SdrViews
742 // SdrExchangeView aDestView( pDestModel );
743 SdrView aDestView( pDestModel );
744 aDestView.ShowSdrPage(aDestView.GetModel()->GetPage(0));
745 aDestView.Paste( *pModel, Point( aSrcSize.Width()/2, aSrcSize.Height()/2 ) );
747 // put objects to right layer (see ScViewFunc::PasteDataFormat for SOT_FORMATSTR_ID_DRAWING)
749 SdrPage* pPage = pDestModel->GetPage(0);
750 if (pPage)
752 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
753 SdrObject* pObject = aIter.Next();
754 while (pObject)
756 if ( pObject->ISA(SdrUnoObj) )
757 pObject->NbcSetLayer(SC_LAYER_CONTROLS);
758 else
759 pObject->NbcSetLayer(SC_LAYER_FRONT);
760 pObject = aIter.Next();
764 Point aTmpPoint;
765 Rectangle aDestArea( aTmpPoint, aSrcSize );
766 pDocSh->SetVisArea( aDestArea );
768 ScViewOptions aViewOpt( pDestDoc->GetViewOptions() );
769 aViewOpt.SetOption( VOPT_GRID, FALSE );
770 pDestDoc->SetViewOptions( aViewOpt );
772 ScViewData aViewData( pDocSh, NULL );
773 aViewData.SetTabNo( 0 );
774 aViewData.SetScreen( aDestArea );
775 aViewData.SetCurX( 0 );
776 aViewData.SetCurY( 0 );
777 pDocSh->UpdateOle(&aViewData, TRUE);
781 const com::sun::star::uno::Sequence< sal_Int8 >& ScDrawTransferObj::getUnoTunnelId()
783 static com::sun::star::uno::Sequence< sal_Int8 > aSeq;
784 if( !aSeq.getLength() )
786 static osl::Mutex aCreateMutex;
787 osl::Guard< osl::Mutex > aGuard( aCreateMutex );
788 aSeq.realloc( 16 );
789 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
791 return aSeq;
794 sal_Int64 SAL_CALL ScDrawTransferObj::getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException )
796 sal_Int64 nRet;
797 if( ( rId.getLength() == 16 ) &&
798 ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
800 nRet = reinterpret_cast< sal_Int64 >( this );
802 else
803 nRet = TransferableHelper::getSomething(rId);
804 return nRet;