bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / app / sdxfer.cxx
blobf90cac33d57825a1c5a8b5d6a76adec06184a38a
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/embed/ElementModes.hpp>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <osl/mutex.hxx>
25 #include <unotools/ucbstreamhelper.hxx>
26 #include <unotools/tempfile.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <editeng/flditem.hxx>
29 #include <svx/svdpagv.hxx>
30 #include <sfx2/app.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/svdograf.hxx>
34 #include <svx/svdotext.hxx>
35 #include <editeng/outlobj.hxx>
36 #include <sot/storage.hxx>
37 #include <svl/itempool.hxx>
38 #include <editeng/editobj.hxx>
39 #include <svx/fmglob.hxx>
40 #include <svx/svdouno.hxx>
41 #include <sot/formats.hxx>
42 #include <svl/urlbmk.hxx>
43 #include <editeng/outliner.hxx>
45 #include <com/sun/star/form/FormButtonType.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <unotools/streamwrap.hxx>
49 #include <svx/svdotable.hxx>
50 #include <svx/unomodel.hxx>
51 #include <svx/svditer.hxx>
52 #include <sfx2/docfile.hxx>
53 #include <comphelper/storagehelper.hxx>
54 #include <comphelper/servicehelper.hxx>
55 #include <svtools/embedtransfer.hxx>
56 #include "DrawDocShell.hxx"
57 #include "View.hxx"
58 #include "sdpage.hxx"
59 #include "drawview.hxx"
60 #include "drawdoc.hxx"
61 #include "stlpool.hxx"
62 #include "strings.hrc"
63 #include "sdresid.hxx"
64 #include "imapinfo.hxx"
65 #include "sdxfer.hxx"
66 #include "unomodel.hxx"
67 #include <vcl/virdev.hxx>
69 using namespace ::com::sun::star;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::io;
73 using namespace ::com::sun::star::datatransfer;
74 using namespace ::com::sun::star::datatransfer::clipboard;
76 #define SDTRANSFER_OBJECTTYPE_DRAWMODEL static_cast<SotClipboardFormatId>(0x00000001)
77 #define SDTRANSFER_OBJECTTYPE_DRAWOLE static_cast<SotClipboardFormatId>(0x00000002)
79 SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, bool bInitOnGetData )
80 : mpPageDocShell( NULL )
81 , mpOLEDataHelper( NULL )
82 , mpObjDesc( NULL )
83 , mpSdView( pWorkView )
84 , mpSdViewIntern( pWorkView )
85 , mpSdDrawDocument( NULL )
86 , mpSdDrawDocumentIntern( NULL )
87 , mpSourceDoc( pSrcDoc )
88 , mpVDev( NULL )
89 , mpBookmark( NULL )
90 , mpGraphic( NULL )
91 , mpImageMap( NULL )
92 , mbInternalMove( false )
93 , mbOwnDocument( false )
94 , mbOwnView( false )
95 , mbLateInit( bInitOnGetData )
96 , mbPageTransferable( false )
97 , mbPageTransferablePersistent( false )
98 , mbIsUnoObj( false )
99 , maUserData()
101 if( mpSourceDoc )
102 StartListening( *mpSourceDoc );
104 if( pWorkView )
105 StartListening( *pWorkView );
107 if( !mbLateInit )
108 CreateData();
111 SdTransferable::~SdTransferable()
113 SolarMutexGuard g;
115 if( mpSourceDoc )
116 EndListening( *mpSourceDoc );
118 if( mpSdView )
119 EndListening( *const_cast< sd::View *>( mpSdView) );
121 ObjectReleased();
123 if( mbOwnView )
124 delete mpSdViewIntern;
126 delete mpOLEDataHelper;
128 if( maDocShellRef.Is() )
130 SfxObjectShell* pObj = maDocShellRef;
131 ::sd::DrawDocShell* pDocSh = static_cast< ::sd::DrawDocShell*>(pObj);
132 pDocSh->DoClose();
135 maDocShellRef.Clear();
137 if( mbOwnDocument )
138 delete mpSdDrawDocumentIntern;
140 delete mpGraphic;
141 delete mpBookmark;
142 delete mpImageMap;
144 mpVDev.disposeAndClear();
145 delete mpObjDesc;
147 //call explicitly at end of dtor to be covered by above SolarMutex
148 maUserData.clear();
151 void SdTransferable::CreateObjectReplacement( SdrObject* pObj )
153 if( pObj )
155 delete mpOLEDataHelper, mpOLEDataHelper = NULL;
156 delete mpGraphic, mpGraphic = NULL;
157 delete mpBookmark, mpBookmark = NULL;
158 delete mpImageMap, mpImageMap = NULL;
160 if( pObj->ISA( SdrOle2Obj ) )
164 uno::Reference < embed::XEmbeddedObject > xObj = static_cast< SdrOle2Obj* >( pObj )->GetObjRef();
165 uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
166 if( xObj.is() && xPersist.is() && xPersist->hasEntry() )
168 mpOLEDataHelper = new TransferableDataHelper( new SvEmbedTransferHelper( xObj, static_cast< SdrOle2Obj* >( pObj )->GetGraphic(), static_cast< SdrOle2Obj* >( pObj )->GetAspect() ) );
170 // TODO/LATER: the standalone handling of the graphic should not be used any more in future
171 // The EmbedDataHelper should bring the graphic in future
172 const Graphic* pObjGr = static_cast< SdrOle2Obj* >( pObj )->GetGraphic();
173 if ( pObjGr )
174 mpGraphic = new Graphic( *pObjGr );
177 catch( uno::Exception& )
180 else if( pObj->ISA( SdrGrafObj ) && (mpSourceDoc && !mpSourceDoc->GetAnimationInfo( pObj )) )
182 mpGraphic = new Graphic( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() );
184 else if( pObj->IsUnoObj() && FmFormInventor == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == (sal_uInt16) OBJ_FM_BUTTON ) )
186 SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( pObj );
188 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
190 Reference< ::com::sun::star::awt::XControlModel > xControlModel( pUnoCtrl->GetUnoControlModel() );
192 if( !xControlModel.is() )
193 return;
195 Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xControlModel, UNO_QUERY );
197 if( !xPropSet.is() )
198 return;
200 ::com::sun::star::form::FormButtonType eButtonType;
201 Any aTmp( xPropSet->getPropertyValue( "ButtonType" ) );
203 if( aTmp >>= eButtonType )
205 OUString aLabel, aURL;
207 xPropSet->getPropertyValue( "Label" ) >>= aLabel;
208 xPropSet->getPropertyValue( "TargetURL" ) >>= aURL;
210 mpBookmark = new INetBookmark( aURL, aLabel );
214 else if( pObj->ISA( SdrTextObj ) )
216 const OutlinerParaObject* pPara;
218 if( (pPara = static_cast< SdrTextObj* >( pObj )->GetOutlinerParaObject()) != 0 )
220 const SvxFieldItem* pField;
222 if( (pField = pPara->GetTextObject().GetField()) != 0 )
224 const SvxFieldData* pData = pField->GetField();
226 if( pData && pData->ISA( SvxURLField ) )
228 const SvxURLField* pURL = static_cast<const SvxURLField*>(pData);
230 // #i63399# This special code identifies TextFrames which have just an URL
231 // as content and directly add this to the clipboard, probably to avoid adding
232 // an unnecessary DrawObject to the target where paste may take place. This is
233 // wanted only for SdrObjects with no fill and no line, else it is necessary to
234 // use the whole SdrObect. Test here for Line/FillStyle and take shortcut only
235 // when both are unused
236 if(!pObj->HasFillStyle() && !pObj->HasLineStyle())
238 mpBookmark = new INetBookmark( pURL->GetURL(), pURL->GetRepresentation() );
245 SdIMapInfo* pInfo = static_cast< SdDrawDocument* >( pObj->GetModel() )->GetIMapInfo( static_cast< SdrObject* >( pObj ) );
247 if( pInfo )
248 mpImageMap = new ImageMap( pInfo->GetImageMap() );
250 mbIsUnoObj = pObj && pObj->IsUnoObj();
254 void SdTransferable::CreateData()
256 if( mpSdDrawDocument && !mpSdViewIntern )
258 mbOwnView = true;
260 SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PK_STANDARD);
262 if( 1 == pPage->GetObjCount() )
263 CreateObjectReplacement( pPage->GetObj( 0 ) );
265 mpVDev = VclPtr<VirtualDevice>::Create( *Application::GetDefaultDevice() );
266 mpVDev->SetMapMode( MapMode( mpSdDrawDocumentIntern->GetScaleUnit(), Point(), mpSdDrawDocumentIntern->GetScaleFraction(), mpSdDrawDocumentIntern->GetScaleFraction() ) );
267 mpSdViewIntern = new ::sd::View( *mpSdDrawDocumentIntern, mpVDev );
268 mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern );
269 mpSdViewIntern->hideMarkHandles();
270 SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage);
271 ((SdrMarkView*)mpSdViewIntern)->MarkAllObj(pPageView);
273 else if( mpSdView && !mpSdDrawDocumentIntern )
275 const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList();
277 if( rMarkList.GetMarkCount() == 1 )
278 CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
280 if( mpSourceDoc )
281 mpSourceDoc->CreatingDataObj(this);
282 mpSdDrawDocumentIntern = static_cast<SdDrawDocument*>( mpSdView->GetMarkedObjModel() );
283 if( mpSourceDoc )
284 mpSourceDoc->CreatingDataObj(0);
286 if( !maDocShellRef.Is() && mpSdDrawDocumentIntern->GetDocSh() )
287 maDocShellRef = mpSdDrawDocumentIntern->GetDocSh();
289 if( !maDocShellRef.Is() )
291 OSL_FAIL( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
292 mbOwnDocument = true;
295 // Use dimension of source page
296 SdrPageView* pPgView = mpSdView->GetSdrPageView();
297 SdPage* pOldPage = static_cast<SdPage*>( pPgView->GetPage() );
298 SdrModel* pOldModel = mpSdView->GetModel();
299 SdStyleSheetPool* pOldStylePool = static_cast<SdStyleSheetPool*>( pOldModel->GetStyleSheetPool() );
300 SdStyleSheetPool* pNewStylePool = static_cast<SdStyleSheetPool*>( mpSdDrawDocumentIntern->GetStyleSheetPool() );
301 SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
302 OUString aOldLayoutName( pOldPage->GetLayoutName() );
304 pPage->SetSize( pOldPage->GetSize() );
305 pPage->SetLayoutName( aOldLayoutName );
306 pNewStylePool->CopyGraphicSheets( *pOldStylePool );
307 pNewStylePool->CopyCellSheets( *pOldStylePool );
308 pNewStylePool->CopyTableStyles( *pOldStylePool );
309 sal_Int32 nPos = aOldLayoutName.indexOf( SD_LT_SEPARATOR );
310 if( nPos != -1 )
311 aOldLayoutName = aOldLayoutName.copy( 0, nPos );
312 SdStyleSheetVector aCreatedSheets;
313 pNewStylePool->CopyLayoutSheets( aOldLayoutName, *pOldStylePool, aCreatedSheets );
316 // set VisArea and adjust objects if necessary
317 if( maVisArea.IsEmpty() &&
318 mpSdDrawDocumentIntern && mpSdViewIntern &&
319 mpSdDrawDocumentIntern->GetPageCount() )
321 SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
323 if( 1 == mpSdDrawDocumentIntern->GetPageCount() )
325 // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
326 // fat lines correctly
327 Point aOrigin( ( maVisArea = mpSdViewIntern->GetAllMarkedBoundRect() ).TopLeft() );
328 Size aVector( -aOrigin.X(), -aOrigin.Y() );
330 for( size_t nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; ++nObj )
332 SdrObject* pObj = pPage->GetObj( nObj );
333 pObj->NbcMove( aVector );
336 else
337 maVisArea.SetSize( pPage->GetSize() );
339 // output is at the zero point
340 maVisArea.SetPos( Point() );
344 static bool lcl_HasOnlyControls( SdrModel* pModel )
346 bool bOnlyControls = false; // default if there are no objects
348 if ( pModel )
350 SdrPage* pPage = pModel->GetPage(0);
351 if (pPage)
353 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
354 SdrObject* pObj = aIter.Next();
355 if ( pObj )
357 bOnlyControls = true; // only set if there are any objects at all
358 while ( pObj )
360 if (!pObj->ISA(SdrUnoObj))
362 bOnlyControls = false;
363 break;
365 pObj = aIter.Next();
371 return bOnlyControls;
374 static bool lcl_HasOnlyOneTable( SdrModel* pModel )
376 if ( pModel )
378 SdrPage* pPage = pModel->GetPage(0);
379 if (pPage && pPage->GetObjCount() == 1 )
381 if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != 0 )
382 return true;
385 return false;
388 void SdTransferable::AddSupportedFormats()
390 if( !mbPageTransferable || mbPageTransferablePersistent )
392 if( !mbLateInit )
393 CreateData();
395 if( mpObjDesc )
396 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
398 if( mpOLEDataHelper )
400 AddFormat( SotClipboardFormatId::EMBED_SOURCE );
402 DataFlavorExVector aVector( mpOLEDataHelper->GetDataFlavorExVector() );
403 DataFlavorExVector::iterator aIter( aVector.begin() ), aEnd( aVector.end() );
405 while( aIter != aEnd )
406 AddFormat( *aIter++ );
408 else if( mpGraphic )
410 // #i25616#
411 AddFormat( SotClipboardFormatId::DRAWING );
413 AddFormat( SotClipboardFormatId::SVXB );
415 if( mpGraphic->GetType() == GRAPHIC_BITMAP )
417 AddFormat( SotClipboardFormatId::PNG );
418 AddFormat( SotClipboardFormatId::BITMAP );
419 AddFormat( SotClipboardFormatId::GDIMETAFILE );
421 else
423 AddFormat( SotClipboardFormatId::GDIMETAFILE );
424 AddFormat( SotClipboardFormatId::PNG );
425 AddFormat( SotClipboardFormatId::BITMAP );
428 else if( mpBookmark )
430 AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
431 AddFormat( SotClipboardFormatId::STRING );
433 else
435 AddFormat( SotClipboardFormatId::EMBED_SOURCE );
436 AddFormat( SotClipboardFormatId::DRAWING );
437 if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
439 AddFormat( SotClipboardFormatId::GDIMETAFILE );
440 AddFormat( SotClipboardFormatId::PNG );
441 AddFormat( SotClipboardFormatId::BITMAP );
444 if( lcl_HasOnlyOneTable( mpSdDrawDocument ) )
445 AddFormat( SotClipboardFormatId::RTF );
448 if( mpImageMap )
449 AddFormat( SotClipboardFormatId::SVIM );
453 bool SdTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDoc )
455 if (SD_MOD()==NULL)
456 return false;
458 SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
459 bool bOK = false;
461 CreateData();
463 if( nFormat == SotClipboardFormatId::RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
465 bOK = SetTableRTF( mpSdDrawDocument, rFlavor );
467 else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
469 SdrSwapGraphicsMode nOldSwapMode(SdrSwapGraphicsMode::DEFAULT);
471 if( mpSdDrawDocumentIntern )
473 nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
474 mpSdDrawDocumentIntern->SetSwapGraphicsMode( SdrSwapGraphicsMode::PURGE );
477 // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
478 if( nFormat == SotClipboardFormatId::GDIMETAFILE && mpGraphic )
479 bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile(), rFlavor );
480 else
481 bOK = SetAny( mpOLEDataHelper->GetAny(rFlavor, rDestDoc), rFlavor );
483 if( mpSdDrawDocumentIntern )
484 mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
486 else if( HasFormat( nFormat ) )
488 if( ( nFormat == SotClipboardFormatId::LINKSRCDESCRIPTOR || nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR ) && mpObjDesc )
490 bOK = SetTransferableObjectDescriptor( *mpObjDesc, rFlavor );
492 else if( nFormat == SotClipboardFormatId::DRAWING )
494 SfxObjectShellRef aOldRef( maDocShellRef );
496 maDocShellRef.Clear();
498 if( mpSdViewIntern )
500 SdDrawDocument& rInternDoc = mpSdViewIntern->GetDoc();
501 rInternDoc.CreatingDataObj(this);
502 SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->GetMarkedObjModel() );
503 rInternDoc.CreatingDataObj(0);
505 bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
507 if( maDocShellRef.Is() )
509 maDocShellRef->DoClose();
511 else
513 delete pDoc;
517 maDocShellRef = aOldRef;
519 else if( nFormat == SotClipboardFormatId::GDIMETAFILE )
521 if (mpSdViewIntern)
523 const bool bToggleOnlineSpell = mpSdDrawDocumentIntern && mpSdDrawDocumentIntern->GetOnlineSpell();
524 if (bToggleOnlineSpell)
525 mpSdDrawDocumentIntern->SetOnlineSpell(false);
526 bOK = SetGDIMetaFile( mpSdViewIntern->GetMarkedObjMetaFile( true ), rFlavor );
527 if (bToggleOnlineSpell)
528 mpSdDrawDocumentIntern->SetOnlineSpell(true);
531 else if( SotClipboardFormatId::BITMAP == nFormat || SotClipboardFormatId::PNG == nFormat )
533 if (mpSdViewIntern)
535 const bool bToggleOnlineSpell = mpSdDrawDocumentIntern && mpSdDrawDocumentIntern->GetOnlineSpell();
536 if (bToggleOnlineSpell)
537 mpSdDrawDocumentIntern->SetOnlineSpell(false);
538 bOK = SetBitmapEx( mpSdViewIntern->GetMarkedObjBitmapEx(true), rFlavor );
539 if (bToggleOnlineSpell)
540 mpSdDrawDocumentIntern->SetOnlineSpell(true);
543 else if( ( nFormat == SotClipboardFormatId::STRING ) && mpBookmark )
545 bOK = SetString( mpBookmark->GetURL(), rFlavor );
547 else if( ( nFormat == SotClipboardFormatId::SVXB ) && mpGraphic )
549 bOK = SetGraphic( *mpGraphic, rFlavor );
551 else if( ( nFormat == SotClipboardFormatId::SVIM ) && mpImageMap )
553 bOK = SetImageMap( *mpImageMap, rFlavor );
555 else if( mpBookmark )
557 bOK = SetINetBookmark( *mpBookmark, rFlavor );
559 else if( nFormat == SotClipboardFormatId::EMBED_SOURCE )
561 if( mpSdDrawDocumentIntern )
563 SdrSwapGraphicsMode nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
564 mpSdDrawDocumentIntern->SetSwapGraphicsMode( SdrSwapGraphicsMode::PURGE );
566 if( !maDocShellRef.Is() )
568 maDocShellRef = new ::sd::DrawDocShell(
569 mpSdDrawDocumentIntern,
570 SfxObjectCreateMode::EMBEDDED,
571 true,
572 mpSdDrawDocumentIntern->GetDocumentType());
573 mbOwnDocument = false;
574 maDocShellRef->DoInitNew( NULL );
577 maDocShellRef->SetVisArea( maVisArea );
578 bOK = SetObject( &maDocShellRef, SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
580 mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
585 return bOK;
588 bool SdTransferable::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pObject, SotClipboardFormatId nObjectType, const DataFlavor& )
590 bool bRet = false;
592 switch( nObjectType )
594 case( SDTRANSFER_OBJECTTYPE_DRAWMODEL ):
598 static const bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL );
599 SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(pObject);
600 if ( !bDontBurnInStyleSheet )
601 pDoc->BurnInStyleSheetAttributes();
602 rxOStm->SetBufferSize( 16348 );
604 Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, true ) );
605 pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
608 com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
609 if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
610 rxOStm->Commit();
613 xComponent->dispose();
614 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
616 catch( Exception& )
618 OSL_FAIL( "sd::SdTransferable::WriteObject(), exception catched!" );
619 bRet = false;
622 break;
624 case( SDTRANSFER_OBJECTTYPE_DRAWOLE ):
626 SfxObjectShell* pEmbObj = static_cast<SfxObjectShell*>(pObject);
627 ::utl::TempFile aTempFile;
628 aTempFile.EnableKillingFile();
632 uno::Reference< embed::XStorage > xWorkStore =
633 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
635 // write document storage
636 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
637 // mba: no relative URLs for clipboard!
638 SfxMedium aMedium( xWorkStore, OUString() );
639 bRet = pEmbObj->DoSaveObjectAs( aMedium, false );
640 pEmbObj->DoSaveCompleted();
642 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
643 if ( xTransact.is() )
644 xTransact->commit();
646 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
647 if( pSrcStm )
649 rxOStm->SetBufferSize( 0xff00 );
650 rxOStm->WriteStream( *pSrcStm );
651 delete pSrcStm;
654 bRet = true;
655 rxOStm->Commit();
657 catch ( Exception& )
661 break;
663 default:
664 break;
667 return bRet;
670 void SdTransferable::DragFinished( sal_Int8 nDropAction )
672 if( mpSdView )
673 const_cast< ::sd::View* >(mpSdView)->DragFinished( nDropAction );
676 void SdTransferable::ObjectReleased()
678 if( this == SD_MOD()->pTransferClip )
679 SD_MOD()->pTransferClip = NULL;
681 if( this == SD_MOD()->pTransferDrag )
682 SD_MOD()->pTransferDrag = NULL;
684 if( this == SD_MOD()->pTransferSelection )
685 SD_MOD()->pTransferSelection = NULL;
688 void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor& rObjDesc )
690 delete mpObjDesc;
691 mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
692 PrepareOLE( rObjDesc );
695 void SdTransferable::SetPageBookmarks( const std::vector<OUString> &rPageBookmarks, bool bPersistent )
697 if( mpSourceDoc )
699 if( mpSdViewIntern )
700 mpSdViewIntern->HideSdrPage();
702 mpSdDrawDocument->ClearModel(false);
704 mpPageDocShell = NULL;
706 maPageBookmarks.clear();
708 if( bPersistent )
710 mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
711 mpSdDrawDocument->InsertBookmarkAsPage( rPageBookmarks, NULL, false, true, 1, true,
712 mpSourceDoc->GetDocSh(), true, true, false );
714 else
716 mpPageDocShell = mpSourceDoc->GetDocSh();
717 maPageBookmarks = rPageBookmarks;
720 if( mpSdViewIntern )
722 SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PK_STANDARD );
724 if( pPage )
726 ( (SdrMarkView*) mpSdViewIntern )->MarkAllObj( mpSdViewIntern->ShowSdrPage( pPage ) );
730 // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
731 // don't offer any formats => it's just for internal purposes
732 mbPageTransferable = true;
733 mbPageTransferablePersistent = bPersistent;
737 sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
739 sal_Int64 nRet;
741 if( ( rId.getLength() == 16 ) &&
742 ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
744 nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
746 else
748 nRet = 0;
751 return nRet;
754 void SdTransferable::AddUserData (const ::boost::shared_ptr<UserData>& rpData)
756 maUserData.push_back(rpData);
759 sal_Int32 SdTransferable::GetUserDataCount() const
761 return maUserData.size();
764 ::boost::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const
766 if (nIndex>=0 && nIndex<sal_Int32(maUserData.size()))
767 return maUserData[nIndex];
768 else
769 return ::boost::shared_ptr<UserData>();
772 namespace
774 class theSdTransferableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSdTransferableUnoTunnelId > {};
777 const ::com::sun::star::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId()
779 return theSdTransferableUnoTunnelId::get().getSeq();
782 SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw()
786 Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
787 return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
789 catch( const ::com::sun::star::uno::Exception& )
792 return NULL;
795 void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
797 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
798 if( pSdrHint )
800 if( HINT_MODELCLEARED == pSdrHint->GetKind() )
802 EndListening(*mpSourceDoc);
803 mpSourceDoc = 0;
806 else
808 const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint * >(&rHint);
809 if(pSimpleHint && (pSimpleHint->GetId() == SFX_HINT_DYING) )
811 if( &rBC == mpSourceDoc )
812 mpSourceDoc = 0;
813 if( &rBC == mpSdViewIntern )
814 mpSdViewIntern = 0;
815 if( &rBC == mpSdView )
816 mpSdView = 0;
821 void SdTransferable::SetView(const ::sd::View* pView)
823 if (mpSdView)
824 EndListening(*const_cast<sd::View*>(mpSdView));
825 mpSdView = pView;
826 if (mpSdView)
827 StartListening(*const_cast<sd::View*>(mpSdView));
830 bool SdTransferable::SetTableRTF( SdDrawDocument* pModel, const DataFlavor& rFlavor)
832 if ( pModel )
834 SdrPage* pPage = pModel->GetPage(0);
835 if (pPage && pPage->GetObjCount() == 1 )
837 sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
838 if( pTableObj )
840 SvMemoryStream aMemStm( 65535, 65535 );
841 sdr::table::SdrTableObj::ExportAsRTF( aMemStm, *pTableObj );
842 return SetAny( Any( Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ) ), rFlavor );
847 return false;
850 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */