Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / app / drwtrans.cxx
blob5288b1d7ac5f796a317a0ff99cdb63b68ff530bd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
53 #include "docsh.hxx"
54 #include "drwlayer.hxx"
55 #include "drawview.hxx"
56 #include "viewdata.hxx"
57 #include "scmod.hxx"
58 #include "chartlis.hxx"
59 #include "rangeutl.hxx"
60 #include <formula/grammar.hxx>
61 #include "dragdata.hxx"
62 #include "clipdata.hxx"
64 // #108584#
65 #include "scitems.hxx"
67 // #108584#
68 #include <editeng/eeitem.hxx>
70 // #108584#
71 #include <editeng/fhgtitem.hxx>
72 #include <vcl/svapp.hxx>
75 using namespace com::sun::star;
77 #define SCDRAWTRANS_TYPE_EMBOBJ 1
78 #define SCDRAWTRANS_TYPE_DRAWMODEL 2
79 #define SCDRAWTRANS_TYPE_DOCUMENT 3
83 ScDrawTransferObj::ScDrawTransferObj( SdrModel* pClipModel, ScDocShell* pContainerShell,
84 const TransferableObjectDescriptor& rDesc ) :
85 pModel( pClipModel ),
86 aObjDesc( rDesc ),
87 pBookmark( NULL ),
88 bGraphic( false ),
89 bGrIsBit( false ),
90 bOleObj( false ),
91 pDragSourceView( NULL ),
92 nDragSourceFlags( 0 ),
93 bDragWasInternal( false ),
94 nSourceDocID( 0 ),
95 maShellID(SfxObjectShell::CreateShellID(pContainerShell))
98 // check what kind of objects are contained
101 SdrPage* pPage = pModel->GetPage(0);
102 if (pPage)
104 SdrObjListIter aIter( *pPage, IM_FLAT );
105 SdrObject* pObject = aIter.Next();
106 if (pObject && !aIter.Next()) // exactly one object?
109 // OLE object
112 sal_uInt16 nSdrObjKind = pObject->GetObjIdentifier();
113 if (nSdrObjKind == OBJ_OLE2)
115 // if object has no persistence it must be copied as a part of document
118 uno::Reference< embed::XEmbedPersist > xPersObj( ((SdrOle2Obj*)pObject)->GetObjRef(), uno::UNO_QUERY );
119 if ( xPersObj.is() && xPersObj->hasEntry() )
120 bOleObj = true;
122 catch( uno::Exception& )
124 // aOleData is initialized later
128 // Graphic object
131 if (nSdrObjKind == OBJ_GRAF)
133 bGraphic = true;
134 if ( ((SdrGrafObj*)pObject)->GetGraphic().GetType() == GRAPHIC_BITMAP )
135 bGrIsBit = true;
139 // URL button
142 SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObject);
143 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
145 uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
146 OSL_ENSURE( xControlModel.is(), "uno control without model" );
147 if ( xControlModel.is() )
149 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
150 uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
152 OUString sPropButtonType( "ButtonType" );
153 OUString sPropTargetURL( "TargetURL" );
154 OUString sPropLabel( "Label" );
156 if(xInfo->hasPropertyByName( sPropButtonType ))
158 uno::Any aAny = xPropSet->getPropertyValue( sPropButtonType );
159 form::FormButtonType eTmp;
160 if ( (aAny >>= eTmp) && eTmp == form::FormButtonType_URL )
162 // URL
163 if(xInfo->hasPropertyByName( sPropTargetURL ))
165 aAny = xPropSet->getPropertyValue( sPropTargetURL );
166 OUString sTmp;
167 if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
169 OUString aUrl = sTmp;
170 OUString aAbs;
171 const SfxMedium* pMedium;
172 if (pContainerShell && (pMedium = pContainerShell->GetMedium()) != NULL)
174 bool bWasAbs = true;
175 aAbs = pMedium->GetURLObject().smartRel2Abs( aUrl, bWasAbs ).
176 GetMainURL(INetURLObject::NO_DECODE);
177 // full path as stored INetBookmark must be encoded
179 else
180 aAbs = aUrl;
182 // Label
183 OUString aLabel;
184 if(xInfo->hasPropertyByName( sPropLabel ))
186 aAny = xPropSet->getPropertyValue( sPropLabel );
187 if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
189 aLabel = sTmp;
192 pBookmark = new INetBookmark( aAbs, aLabel );
203 // get size for object descriptor
206 // #i71538# use complete SdrViews
207 // SdrExchangeView aView(pModel);
208 SdrView aView(pModel);
209 SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
210 aView.MarkAllObj(pPv);
211 aSrcSize = aView.GetAllMarkedRect().GetSize();
213 if ( bOleObj ) // single OLE object
215 SdrOle2Obj* pObj = GetSingleObject();
216 if ( pObj && pObj->GetObjRef().is() )
217 SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() );
220 aObjDesc.maSize = aSrcSize;
221 PrepareOLE( aObjDesc );
224 // remember a unique ID of the source document
226 if ( pContainerShell )
228 ScDocument* pDoc = pContainerShell->GetDocument();
229 if ( pDoc )
231 nSourceDocID = pDoc->GetDocumentID();
232 if ( pPage )
234 ScChartHelper::FillProtectedChartRangesVector( m_aProtectedChartRangesVector, pDoc, pPage );
240 ScDrawTransferObj::~ScDrawTransferObj()
242 SolarMutexGuard aSolarGuard;
244 ScModule* pScMod = SC_MOD();
245 if ( pScMod->GetClipData().pDrawClipboard == this )
247 OSL_FAIL("ScDrawTransferObj wasn't released");
248 pScMod->SetClipObject( NULL, NULL );
250 if ( pScMod->GetDragData().pDrawTransfer == this )
252 OSL_FAIL("ScDrawTransferObj wasn't released");
253 pScMod->ResetDragObject();
256 aOleData = TransferableDataHelper(); // clear before releasing the mutex
257 aDocShellRef.Clear();
259 delete pModel;
260 aDrawPersistRef.Clear(); // after the model
262 delete pBookmark;
263 delete pDragSourceView;
266 ScDrawTransferObj* ScDrawTransferObj::GetOwnClipboard( Window* )
268 ScDrawTransferObj* pObj = SC_MOD()->GetClipData().pDrawClipboard;
269 return pObj;
272 static bool lcl_HasOnlyControls( SdrModel* pModel )
274 bool bOnlyControls = false; // default if there are no objects
276 if ( pModel )
278 SdrPage* pPage = pModel->GetPage(0);
279 if (pPage)
281 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
282 SdrObject* pObj = aIter.Next();
283 if ( pObj )
285 bOnlyControls = true; // only set if there are any objects at all
286 while ( pObj )
288 if (!pObj->ISA(SdrUnoObj))
290 bOnlyControls = false;
291 break;
293 pObj = aIter.Next();
299 return bOnlyControls;
302 void ScDrawTransferObj::AddSupportedFormats()
304 if ( bGrIsBit ) // single bitmap graphic
306 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
307 AddFormat( SOT_FORMATSTR_ID_SVXB );
308 AddFormat( SOT_FORMATSTR_ID_PNG );
309 AddFormat( SOT_FORMAT_BITMAP );
310 AddFormat( SOT_FORMAT_GDIMETAFILE );
312 else if ( bGraphic ) // other graphic
314 // #i25616#
315 AddFormat( SOT_FORMATSTR_ID_DRAWING );
317 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
318 AddFormat( SOT_FORMATSTR_ID_SVXB );
319 AddFormat( SOT_FORMAT_GDIMETAFILE );
320 AddFormat( SOT_FORMATSTR_ID_PNG );
321 AddFormat( SOT_FORMAT_BITMAP );
323 else if ( pBookmark ) // url button
325 // AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
326 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
327 AddFormat( SOT_FORMATSTR_ID_SOLK );
328 AddFormat( SOT_FORMAT_STRING );
329 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
330 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
331 AddFormat( SOT_FORMATSTR_ID_DRAWING );
333 else if ( bOleObj ) // single OLE object
335 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
336 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
337 AddFormat( SOT_FORMAT_GDIMETAFILE );
339 CreateOLEData();
341 if ( aOleData.GetTransferable().is() )
343 // get format list from object snapshot
344 // (this must be after inserting the default formats!)
346 DataFlavorExVector aVector( aOleData.GetDataFlavorExVector() );
347 DataFlavorExVector::iterator aIter( aVector.begin() ), aEnd( aVector.end() );
349 while( aIter != aEnd )
350 AddFormat( *aIter++ );
353 else // any drawing objects
355 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
356 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
357 AddFormat( SOT_FORMATSTR_ID_DRAWING );
359 // leave out bitmap and metafile if there are only controls
360 if ( !lcl_HasOnlyControls( pModel ) )
362 AddFormat( SOT_FORMATSTR_ID_PNG );
363 AddFormat( SOT_FORMAT_BITMAP );
364 AddFormat( SOT_FORMAT_GDIMETAFILE );
368 // if( pImageMap )
369 // AddFormat( SOT_FORMATSTR_ID_SVIM );
372 bool ScDrawTransferObj::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc )
374 bool bOK = false;
375 sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
377 if ( bOleObj && nFormat != SOT_FORMAT_GDIMETAFILE )
379 CreateOLEData();
381 if( aOleData.GetTransferable().is() && aOleData.HasFormat( rFlavor ) )
383 sal_uLong nOldSwapMode = 0;
385 if( pModel )
387 nOldSwapMode = pModel->GetSwapGraphicsMode();
388 pModel->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
391 bOK = SetAny( aOleData.GetAny(rFlavor, rDestDoc), rFlavor );
393 if( pModel )
394 pModel->SetSwapGraphicsMode( nOldSwapMode );
396 return bOK;
400 if( HasFormat( nFormat ) )
402 if ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
404 bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor );
406 else if ( nFormat == SOT_FORMATSTR_ID_DRAWING )
408 bOK = SetObject( pModel, SCDRAWTRANS_TYPE_DRAWMODEL, rFlavor );
410 else if ( nFormat == SOT_FORMAT_BITMAP
411 || nFormat == SOT_FORMATSTR_ID_PNG
412 || nFormat == SOT_FORMAT_GDIMETAFILE )
414 // #i71538# use complete SdrViews
415 // SdrExchangeView aView( pModel );
416 SdrView aView( pModel );
417 SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
418 OSL_ENSURE( pPv, "pPv not there..." );
419 aView.MarkAllObj( pPv );
420 if ( nFormat == SOT_FORMAT_GDIMETAFILE )
421 bOK = SetGDIMetaFile( aView.GetMarkedObjMetaFile(true), rFlavor );
422 else
423 bOK = SetBitmapEx( aView.GetMarkedObjBitmapEx(true), rFlavor );
425 else if ( nFormat == SOT_FORMATSTR_ID_SVXB )
427 // only enabled for single graphics object
429 SdrPage* pPage = pModel->GetPage(0);
430 if (pPage)
432 SdrObjListIter aIter( *pPage, IM_FLAT );
433 SdrObject* pObject = aIter.Next();
434 if (pObject && pObject->GetObjIdentifier() == OBJ_GRAF)
436 SdrGrafObj* pGraphObj = (SdrGrafObj*) pObject;
437 bOK = SetGraphic( pGraphObj->GetGraphic(), rFlavor );
441 else if ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
443 if ( bOleObj ) // single OLE object
445 SdrOle2Obj* pObj = GetSingleObject();
446 if ( pObj && pObj->GetObjRef().is() )
448 bOK = SetObject( pObj->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ, rFlavor );
451 else // create object from contents
453 //TODO/LATER: needs new Format, because now single OLE and "this" are different
454 InitDocShell(); // set aDocShellRef
456 SfxObjectShell* pEmbObj = aDocShellRef;
457 bOK = SetObject( pEmbObj, SCDRAWTRANS_TYPE_DOCUMENT, rFlavor );
460 else if( pBookmark )
462 bOK = SetINetBookmark( *pBookmark, rFlavor );
465 return bOK;
468 bool ScDrawTransferObj::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
469 const ::com::sun::star::datatransfer::DataFlavor& /* rFlavor */ )
471 // called from SetObject, put data into stream
473 bool bRet = false;
474 switch (nUserObjectId)
476 case SCDRAWTRANS_TYPE_DRAWMODEL:
478 SdrModel* pDrawModel = (SdrModel*)pUserObject;
479 rxOStm->SetBufferSize( 0xff00 );
481 // #108584#
482 // for the changed pool defaults from drawing layer pool set those
483 // attributes as hard attributes to preserve them for saving
484 const SfxItemPool& rItemPool = pModel->GetItemPool();
485 const SvxFontHeightItem& rDefaultFontHeight = (const SvxFontHeightItem&)rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
487 // SW should have no MasterPages
488 OSL_ENSURE(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
490 for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
492 const SdrPage* pPage = pModel->GetPage(a);
493 SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS);
495 while(aIter.IsMore())
497 SdrObject* pObj = aIter.Next();
498 const SvxFontHeightItem& rItem = (const SvxFontHeightItem&)pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
500 if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
502 pObj->SetMergedItem(rDefaultFontHeight);
508 com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
509 if( SvxDrawingLayerExport( pDrawModel, xDocOut ) )
510 rxOStm->Commit();
513 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
515 break;
517 case SCDRAWTRANS_TYPE_EMBOBJ:
519 // impl. for "single OLE"
520 embed::XEmbeddedObject* pEmbObj = (embed::XEmbeddedObject*) pUserObject;
522 ::utl::TempFile aTempFile;
523 aTempFile.EnableKillingFile();
524 uno::Reference< embed::XStorage > xWorkStore =
525 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
527 uno::Reference < embed::XEmbedPersist > xPers( (embed::XVisualObject*)pEmbObj, uno::UNO_QUERY );
528 if ( xPers.is() )
532 uno::Sequence < beans::PropertyValue > aSeq;
533 OUString aDummyName("Dummy");
534 xPers->storeToEntry( xWorkStore, aDummyName, aSeq, aSeq );
535 if ( xWorkStore->isStreamElement( aDummyName ) )
537 uno::Reference < io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
538 uno::Reference < io::XStream > xNewStream = xWorkStore->openStreamElement( aDummyName, embed::ElementModes::READ );
539 ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream->getInputStream(), xDocOut );
541 else
543 uno::Reference < io::XStream > xDocStr( new utl::OStreamWrapper( *rxOStm ) );
544 uno::Reference< embed::XStorage > xDocStg = ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr );
545 uno::Reference < embed::XStorage > xNewStg = xWorkStore->openStorageElement( aDummyName, embed::ElementModes::READ );
546 xNewStg->copyToStorage( xDocStg );
547 uno::Reference < embed::XTransactedObject > xTrans( xDocStg, uno::UNO_QUERY );
548 if ( xTrans.is() )
549 xTrans->commit();
552 rxOStm->Commit();
554 catch ( uno::Exception& )
559 break;
561 case SCDRAWTRANS_TYPE_DOCUMENT:
563 // impl. for "DocShell"
564 SfxObjectShell* pEmbObj = (SfxObjectShell*) pUserObject;
568 ::utl::TempFile aTempFile;
569 aTempFile.EnableKillingFile();
570 uno::Reference< embed::XStorage > xWorkStore =
571 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
573 // write document storage
574 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false, false );
576 // mba: no relative URLs for clipboard!
577 SfxMedium aMedium( xWorkStore, OUString() );
578 bRet = pEmbObj->DoSaveObjectAs( aMedium, false );
579 pEmbObj->DoSaveCompleted();
581 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
582 if ( xTransact.is() )
583 xTransact->commit();
585 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
586 if( pSrcStm )
588 rxOStm->SetBufferSize( 0xff00 );
589 rxOStm->WriteStream( *pSrcStm );
590 delete pSrcStm;
593 bRet = true;
595 xWorkStore->dispose();
596 xWorkStore = uno::Reference < embed::XStorage >();
597 rxOStm->Commit();
599 catch ( uno::Exception& )
602 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
604 break;
606 default:
607 OSL_FAIL("unknown object id");
609 return bRet;
612 void ScDrawTransferObj::ObjectReleased()
614 ScModule* pScMod = SC_MOD();
615 if ( pScMod->GetClipData().pDrawClipboard == this )
616 pScMod->SetClipObject( NULL, NULL );
618 TransferableHelper::ObjectReleased();
621 void ScDrawTransferObj::DragFinished( sal_Int8 nDropAction )
623 if ( nDropAction == DND_ACTION_MOVE && !bDragWasInternal && !(nDragSourceFlags & SC_DROP_NAVIGATOR) )
625 // move: delete source objects
627 if ( pDragSourceView )
628 pDragSourceView->DeleteMarked();
631 ScModule* pScMod = SC_MOD();
632 if ( pScMod->GetDragData().pDrawTransfer == this )
633 pScMod->ResetDragObject();
635 DELETEZ( pDragSourceView );
637 TransferableHelper::DragFinished( nDropAction );
640 void ScDrawTransferObj::SetDrawPersist( const SfxObjectShellRef& rRef )
642 aDrawPersistRef = rRef;
645 static void lcl_InitMarks( SdrMarkView& rDest, const SdrMarkView& rSource, SCTAB nTab )
647 rDest.ShowSdrPage(rDest.GetModel()->GetPage(nTab));
648 SdrPageView* pDestPV = rDest.GetSdrPageView();
649 OSL_ENSURE(pDestPV,"PageView ?");
651 const SdrMarkList& rMarkList = rSource.GetMarkedObjectList();
652 sal_uLong nCount = rMarkList.GetMarkCount();
653 for (sal_uLong i=0; i<nCount; i++)
655 SdrMark* pMark = rMarkList.GetMark(i);
656 SdrObject* pObj = pMark->GetMarkedSdrObj();
658 rDest.MarkObj(pObj, pDestPV);
662 void ScDrawTransferObj::SetDragSource( ScDrawView* pView )
664 DELETEZ( pDragSourceView );
665 pDragSourceView = new SdrView( pView->GetModel() );
666 lcl_InitMarks( *pDragSourceView, *pView, pView->GetTab() );
668 //! add as listener with document, delete pDragSourceView if document gone
671 void ScDrawTransferObj::SetDragSourceObj( SdrObject* pObj, SCTAB nTab )
673 DELETEZ( pDragSourceView );
674 pDragSourceView = new SdrView( pObj->GetModel() );
675 pDragSourceView->ShowSdrPage(pDragSourceView->GetModel()->GetPage(nTab));
676 SdrPageView* pPV = pDragSourceView->GetSdrPageView();
677 pDragSourceView->MarkObj(pObj, pPV);
679 //! add as listener with document, delete pDragSourceView if document gone
682 void ScDrawTransferObj::SetDragSourceFlags( sal_uInt16 nFlags )
684 nDragSourceFlags = nFlags;
687 void ScDrawTransferObj::SetDragWasInternal()
689 bDragWasInternal = true;
692 OUString ScDrawTransferObj::GetShellID() const
694 return maShellID;
697 SdrOle2Obj* ScDrawTransferObj::GetSingleObject()
699 // if single OLE object was copied, get its object
701 SdrPage* pPage = pModel->GetPage(0);
702 if (pPage)
704 SdrObjListIter aIter( *pPage, IM_FLAT );
705 SdrObject* pObject = aIter.Next();
706 if (pObject && pObject->GetObjIdentifier() == OBJ_OLE2)
708 return (SdrOle2Obj*) pObject;
712 return NULL;
715 void ScDrawTransferObj::CreateOLEData()
717 if (aOleData.GetTransferable().is())
718 // Already created.
719 return;
721 SdrOle2Obj* pObj = GetSingleObject();
722 if (!pObj || !pObj->GetObjRef().is())
723 // No OLE object present.
724 return;
726 SvEmbedTransferHelper* pEmbedTransfer =
727 new SvEmbedTransferHelper(
728 pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect());
730 pEmbedTransfer->SetParentShellID(maShellID);
732 aOleData = TransferableDataHelper(pEmbedTransfer);
736 // initialize aDocShellRef with a live document from the ClipDoc
739 void ScDrawTransferObj::InitDocShell()
741 if ( !aDocShellRef.Is() )
743 ScDocShell* pDocSh = new ScDocShell;
744 aDocShellRef = pDocSh; // ref must be there before InitNew
746 pDocSh->DoInitNew(NULL);
748 ScDocument* pDestDoc = pDocSh->GetDocument();
749 pDestDoc->InitDrawLayer( pDocSh );
751 SdrModel* pDestModel = pDestDoc->GetDrawLayer();
752 // #i71538# use complete SdrViews
753 // SdrExchangeView aDestView( pDestModel );
754 SdrView aDestView( pDestModel );
755 aDestView.ShowSdrPage(aDestView.GetModel()->GetPage(0));
756 aDestView.Paste(
757 *pModel,
758 Point(aSrcSize.Width()/2, aSrcSize.Height()/2),
759 NULL, 0, OUString(), OUString());
761 // put objects to right layer (see ScViewFunc::PasteDataFormat for SOT_FORMATSTR_ID_DRAWING)
763 SdrPage* pPage = pDestModel->GetPage(0);
764 if (pPage)
766 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
767 SdrObject* pObject = aIter.Next();
768 while (pObject)
770 if ( pObject->ISA(SdrUnoObj) )
771 pObject->NbcSetLayer(SC_LAYER_CONTROLS);
772 else
773 pObject->NbcSetLayer(SC_LAYER_FRONT);
774 pObject = aIter.Next();
778 Point aTmpPoint;
779 Rectangle aDestArea( aTmpPoint, aSrcSize );
780 pDocSh->SetVisArea( aDestArea );
782 ScViewOptions aViewOpt( pDestDoc->GetViewOptions() );
783 aViewOpt.SetOption( VOPT_GRID, false );
784 pDestDoc->SetViewOptions( aViewOpt );
786 ScViewData aViewData( pDocSh, NULL );
787 aViewData.SetTabNo( 0 );
788 aViewData.SetScreen( aDestArea );
789 aViewData.SetCurX( 0 );
790 aViewData.SetCurY( 0 );
791 pDocSh->UpdateOle(&aViewData, true);
795 namespace
797 class theScDrawTransferObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScDrawTransferObjUnoTunnelId > {};
800 const com::sun::star::uno::Sequence< sal_Int8 >& ScDrawTransferObj::getUnoTunnelId()
802 return theScDrawTransferObjUnoTunnelId::get().getSeq();
805 sal_Int64 SAL_CALL ScDrawTransferObj::getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException, std::exception )
807 sal_Int64 nRet;
808 if( ( rId.getLength() == 16 ) &&
809 ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
811 nRet = reinterpret_cast< sal_Int64 >( this );
813 else
814 nRet = TransferableHelper::getSomething(rId);
815 return nRet;
819 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */