Update ooo320-m1
[ooovba.git] / sd / source / ui / app / sdxfer.cxx
blob5142539f0b59b7b7f99531d26e355818dfecf07f
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: sdxfer.cxx,v $
10 * $Revision: 1.58 $
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_sd.hxx"
33 #include <com/sun/star/embed/XTransactedObject.hpp>
34 #include <com/sun/star/embed/XEmbedPersist.hpp>
35 #include <com/sun/star/embed/ElementModes.hpp>
36 #include <com/sun/star/lang/XComponent.hpp>
37 #include <vos/mutex.hxx>
38 #include <unotools/ucbstreamhelper.hxx>
39 #ifndef _UNTOOLS_TEMPFILE_HXX
40 #include <unotools/tempfile.hxx>
41 #endif
42 #include <svx/eeitem.hxx>
43 #include <svx/flditem.hxx>
44 #include <svx/svdpagv.hxx>
45 #include <sfx2/app.hxx>
46 #include <vcl/msgbox.hxx>
47 #include <svx/svdoole2.hxx>
48 #include <svx/svdograf.hxx>
49 #include <svx/svdotext.hxx>
50 #include <svx/outlobj.hxx>
51 #include <sot/storage.hxx>
52 #include <svtools/itempool.hxx>
53 #include <svx/editobj.hxx>
54 #include <svx/fmglob.hxx>
55 #include <svx/svdouno.hxx>
56 #include <tools/urlobj.hxx>
57 #include <sot/formats.hxx>
58 #include <svtools/urlbmk.hxx>
59 #include <svx/outliner.hxx>
61 //#ifndef _SVDETC_HXX //autogen
62 //#include <svx/svdetc.hxx>
63 //#endif
64 #include <com/sun/star/form/FormButtonType.hpp>
65 #include <com/sun/star/beans/XPropertySet.hpp>
66 #include <unotools/streamwrap.hxx>
68 #include <svx/svdotable.hxx>
69 #include <svx/unomodel.hxx>
70 #include <svx/svditer.hxx>
71 #include <sfx2/docfile.hxx>
72 #include <comphelper/storagehelper.hxx>
73 #include <svtools/embedtransfer.hxx>
74 #include "DrawDocShell.hxx"
75 #include "View.hxx"
76 #include "sdpage.hxx"
77 #include "drawview.hxx"
78 #include "drawdoc.hxx"
79 #include "stlpool.hxx"
80 #include "strings.hrc"
81 #include "sdresid.hxx"
82 #include "imapinfo.hxx"
83 #include "sdxfer.hxx"
84 #include "unomodel.hxx"
85 #include <vcl/virdev.hxx>
87 // --------------
88 // - Namespaces -
89 // --------------
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::lang;
93 using namespace ::com::sun::star::uno;
94 using namespace ::com::sun::star::io;
95 using namespace ::com::sun::star::datatransfer;
96 using namespace ::com::sun::star::datatransfer::clipboard;
98 // -----------
99 // - Defines -
100 // -----------
102 #define SDTRANSFER_OBJECTTYPE_DRAWMODEL 0x00000001
103 #define SDTRANSFER_OBJECTTYPE_DRAWOLE 0x00000002
105 // ------------------
106 // - SdTransferable -
107 // ------------------
109 SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, BOOL bInitOnGetData )
110 : mpPageDocShell( NULL )
111 , mpOLEDataHelper( NULL )
112 , mpObjDesc( NULL )
113 , mpSdView( pWorkView )
114 , mpSdViewIntern( pWorkView )
115 , mpSdDrawDocument( NULL )
116 , mpSdDrawDocumentIntern( NULL )
117 , mpSourceDoc( pSrcDoc )
118 , mpVDev( NULL )
119 , mpBookmark( NULL )
120 , mpGraphic( NULL )
121 , mpImageMap( NULL )
122 , mbInternalMove( FALSE )
123 , mbOwnDocument( FALSE )
124 , mbOwnView( FALSE )
125 , mbLateInit( bInitOnGetData )
126 , mbPageTransferable( FALSE )
127 , mbPageTransferablePersistent( FALSE )
128 , mbIsUnoObj( false )
130 if( mpSourceDoc )
131 StartListening( *mpSourceDoc );
133 if( pWorkView )
134 StartListening( *pWorkView );
136 if( !mbLateInit )
137 CreateData();
140 // -----------------------------------------------------------------------------
142 SdTransferable::~SdTransferable()
144 if( mpSourceDoc )
145 EndListening( *mpSourceDoc );
147 if( mpSdView )
148 EndListening( *const_cast< sd::View *>( mpSdView) );
150 Application::GetSolarMutex().acquire();
152 ObjectReleased();
154 for( void* p = maPageBookmarks.First(); p; p = maPageBookmarks.Next() )
155 delete static_cast< String* >( p );
157 if( mbOwnView )
158 delete mpSdViewIntern;
160 delete mpOLEDataHelper;
162 if( maDocShellRef.Is() )
164 SfxObjectShell* pObj = maDocShellRef;
165 ::sd::DrawDocShell* pDocSh = static_cast< ::sd::DrawDocShell*>(pObj);
166 pDocSh->DoClose();
169 maDocShellRef.Clear();
171 if( mbOwnDocument )
172 delete mpSdDrawDocumentIntern;
174 delete mpGraphic;
175 delete mpBookmark;
176 delete mpImageMap;
178 delete mpVDev;
179 delete mpObjDesc;
181 Application::GetSolarMutex().release();
184 // -----------------------------------------------------------------------------
186 void SdTransferable::CreateObjectReplacement( SdrObject* pObj )
188 if( pObj )
190 delete mpOLEDataHelper, mpOLEDataHelper = NULL;
191 delete mpGraphic, mpGraphic = NULL;
192 delete mpBookmark, mpBookmark = NULL;
193 delete mpImageMap, mpImageMap = NULL;
195 if( pObj->ISA( SdrOle2Obj ) )
199 uno::Reference < embed::XEmbeddedObject > xObj = static_cast< SdrOle2Obj* >( pObj )->GetObjRef();
200 uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
201 if( xObj.is() && xPersist.is() && xPersist->hasEntry() )
203 mpOLEDataHelper = new TransferableDataHelper( new SvEmbedTransferHelper( xObj, static_cast< SdrOle2Obj* >( pObj )->GetGraphic(), static_cast< SdrOle2Obj* >( pObj )->GetAspect() ) );
205 // TODO/LATER: the standalone handling of the graphic should not be used any more in future
206 // The EmbedDataHelper should bring the graphic in future
207 Graphic* pObjGr = static_cast< SdrOle2Obj* >( pObj )->GetGraphic();
208 if ( pObjGr )
209 mpGraphic = new Graphic( *pObjGr );
212 catch( uno::Exception& )
215 else if( pObj->ISA( SdrGrafObj ) && (mpSourceDoc && !mpSourceDoc->GetAnimationInfo( pObj )) )
217 mpGraphic = new Graphic( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() );
219 else if( pObj->IsUnoObj() && FmFormInventor == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == (UINT16) OBJ_FM_BUTTON ) )
221 SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( pObj );
223 if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
225 Reference< ::com::sun::star::awt::XControlModel > xControlModel( pUnoCtrl->GetUnoControlModel() );
227 if( !xControlModel.is() )
228 return;
230 Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xControlModel, UNO_QUERY );
232 if( !xPropSet.is() )
233 return;
235 ::com::sun::star::form::FormButtonType eButtonType;
236 Any aTmp( xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ButtonType" ) ) ) );
238 if( aTmp >>= eButtonType )
240 ::rtl::OUString aLabel, aURL;
242 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Label" ) ) ) >>= aLabel;
243 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TargetURL") ) ) >>= aURL;
245 mpBookmark = new INetBookmark( String( aURL ), String( aLabel ) );
249 else if( pObj->ISA( SdrTextObj ) )
251 const OutlinerParaObject* pPara;
253 if( (pPara = static_cast< SdrTextObj* >( pObj )->GetOutlinerParaObject()) != 0 )
255 const SvxFieldItem* pField;
257 if( (pField = pPara->GetTextObject().GetField()) != 0 )
259 const SvxFieldData* pData = pField->GetField();
261 if( pData && pData->ISA( SvxURLField ) )
263 const SvxURLField* pURL = (SvxURLField*) pData;
265 mpBookmark = new INetBookmark( pURL->GetURL(), pURL->GetRepresentation() );
271 SdIMapInfo* pInfo = static_cast< SdDrawDocument* >( pObj->GetModel() )->GetIMapInfo( static_cast< SdrObject* >( pObj ) );
273 if( pInfo )
274 mpImageMap = new ImageMap( pInfo->GetImageMap() );
276 mbIsUnoObj = pObj && pObj->IsUnoObj();
280 // -----------------------------------------------------------------------------
282 void SdTransferable::CreateData()
284 if( mpSdDrawDocument && !mpSdViewIntern )
286 mbOwnView = TRUE;
288 SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PK_STANDARD);
290 if( 1 == pPage->GetObjCount() )
291 CreateObjectReplacement( pPage->GetObj( 0 ) );
293 mpVDev = new VirtualDevice( *Application::GetDefaultDevice() );
294 mpVDev->SetMapMode( MapMode( mpSdDrawDocumentIntern->GetScaleUnit(), Point(), mpSdDrawDocumentIntern->GetScaleFraction(), mpSdDrawDocumentIntern->GetScaleFraction() ) );
295 mpSdViewIntern = new ::sd::View( mpSdDrawDocumentIntern, mpVDev );
296 mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern );
297 mpSdViewIntern->hideMarkHandles();
298 SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage);
299 ((SdrMarkView*)mpSdViewIntern)->MarkAllObj(pPageView);
301 else if( mpSdView && !mpSdDrawDocumentIntern )
303 const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList();
305 if( rMarkList.GetMarkCount() == 1 )
306 CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
308 if( mpSourceDoc )
309 mpSourceDoc->CreatingDataObj(this);
310 mpSdDrawDocumentIntern = (SdDrawDocument*) mpSdView->GetAllMarkedModel();
311 if( mpSourceDoc )
312 mpSourceDoc->CreatingDataObj(0);
314 if( !maDocShellRef.Is() && mpSdDrawDocumentIntern->GetDocSh() )
315 maDocShellRef = mpSdDrawDocumentIntern->GetDocSh();
317 if( !maDocShellRef.Is() )
319 DBG_ERROR( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
320 mbOwnDocument = TRUE;
323 // Groesse der Source-Seite uebernehmen
324 SdrPageView* pPgView = mpSdView->GetSdrPageView();
325 SdPage* pOldPage = (SdPage*) pPgView->GetPage();
326 SdrModel* pOldModel = mpSdView->GetModel();
327 SdStyleSheetPool* pOldStylePool = (SdStyleSheetPool*) pOldModel->GetStyleSheetPool();
328 SdStyleSheetPool* pNewStylePool = (SdStyleSheetPool*) mpSdDrawDocumentIntern->GetStyleSheetPool();
329 SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
330 String aOldLayoutName( pOldPage->GetLayoutName() );
332 pPage->SetSize( pOldPage->GetSize() );
333 pPage->SetLayoutName( aOldLayoutName );
334 pNewStylePool->CopyGraphicSheets( *pOldStylePool );
335 pNewStylePool->CopyCellSheets( *pOldStylePool );
336 pNewStylePool->CopyTableStyles( *pOldStylePool );
337 aOldLayoutName.Erase( aOldLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
338 SdStyleSheetVector aCreatedSheets;
339 pNewStylePool->CopyLayoutSheets( aOldLayoutName, *pOldStylePool, aCreatedSheets );
342 // set VisArea and adjust objects if neccessary
343 if( maVisArea.IsEmpty() &&
344 mpSdDrawDocumentIntern && mpSdViewIntern &&
345 mpSdDrawDocumentIntern->GetPageCount() )
347 SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
349 if( 1 == mpSdDrawDocumentIntern->GetPageCount() )
351 Point aOrigin( ( maVisArea = mpSdViewIntern->GetAllMarkedRect() ).TopLeft() );
352 Size aVector( -aOrigin.X(), -aOrigin.Y() );
354 for( ULONG nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; nObj++ )
356 SdrObject* pObj = pPage->GetObj( nObj );
357 pObj->NbcMove( aVector );
360 else
361 maVisArea.SetSize( pPage->GetSize() );
363 // Die Ausgabe soll am Nullpunkt erfolgen
364 maVisArea.SetPos( Point() );
368 // -----------------------------------------------------------------------------
370 BOOL lcl_HasOnlyControls( SdrModel* pModel )
372 BOOL bOnlyControls = FALSE; // default if there are no objects
374 if ( pModel )
376 SdrPage* pPage = pModel->GetPage(0);
377 if (pPage)
379 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
380 SdrObject* pObj = aIter.Next();
381 if ( pObj )
383 bOnlyControls = TRUE; // only set if there are any objects at all
384 while ( pObj )
386 if (!pObj->ISA(SdrUnoObj))
388 bOnlyControls = FALSE;
389 break;
391 pObj = aIter.Next();
397 return bOnlyControls;
400 // -----------------------------------------------------------------------------
402 bool lcl_HasOnlyOneTable( SdrModel* pModel )
404 if ( pModel )
406 SdrPage* pPage = pModel->GetPage(0);
407 if (pPage && pPage->GetObjCount() == 1 )
409 if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != 0 )
410 return true;
413 return false;
416 // -----------------------------------------------------------------------------
418 void SdTransferable::AddSupportedFormats()
420 if( !mbPageTransferable || mbPageTransferablePersistent )
422 if( !mbLateInit )
423 CreateData();
425 if( mpObjDesc )
426 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
428 if( mpOLEDataHelper )
430 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
432 DataFlavorExVector aVector( mpOLEDataHelper->GetDataFlavorExVector() );
433 DataFlavorExVector::iterator aIter( aVector.begin() ), aEnd( aVector.end() );
435 while( aIter != aEnd )
436 AddFormat( *aIter++ );
438 else if( mpGraphic )
440 // #i25616#
441 AddFormat( SOT_FORMATSTR_ID_DRAWING );
443 AddFormat( SOT_FORMATSTR_ID_SVXB );
445 if( mpGraphic->GetType() == GRAPHIC_BITMAP )
447 AddFormat( SOT_FORMAT_BITMAP );
448 AddFormat( SOT_FORMAT_GDIMETAFILE );
450 else
452 AddFormat( SOT_FORMAT_GDIMETAFILE );
453 AddFormat( SOT_FORMAT_BITMAP );
456 else if( mpBookmark )
458 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
459 AddFormat( FORMAT_STRING );
461 else
463 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
464 AddFormat( SOT_FORMATSTR_ID_DRAWING );
465 if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
467 AddFormat( SOT_FORMAT_GDIMETAFILE );
468 AddFormat( SOT_FORMAT_BITMAP );
471 if( lcl_HasOnlyOneTable( mpSdDrawDocument ) )
472 AddFormat( SOT_FORMAT_RTF );
475 if( mpImageMap )
476 AddFormat( SOT_FORMATSTR_ID_SVIM );
480 // -----------------------------------------------------------------------------
482 sal_Bool SdTransferable::GetData( const DataFlavor& rFlavor )
484 if (SD_MOD()==NULL)
485 return sal_False;
487 sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
488 sal_Bool bOK = sal_False;
490 CreateData();
492 if( nFormat == SOT_FORMAT_RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
494 bOK = SetTableRTF( mpSdDrawDocument, rFlavor );
496 else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
498 ULONG nOldSwapMode = 0;
500 if( mpSdDrawDocumentIntern )
502 nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
503 mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
506 // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
507 if( nFormat == FORMAT_GDIMETAFILE && mpGraphic )
508 bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile(), rFlavor );
509 else
510 bOK = SetAny( mpOLEDataHelper->GetAny( rFlavor ), rFlavor );
512 if( mpSdDrawDocumentIntern )
513 mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
515 else if( HasFormat( nFormat ) )
517 if( ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) && mpObjDesc )
519 bOK = SetTransferableObjectDescriptor( *mpObjDesc, rFlavor );
521 else if( nFormat == SOT_FORMATSTR_ID_DRAWING )
523 SfxObjectShellRef aOldRef( maDocShellRef );
525 maDocShellRef.Clear();
527 if( mpSdViewIntern )
529 SdDrawDocument* pInternDoc = mpSdViewIntern->GetDoc();
530 if( pInternDoc )
531 pInternDoc->CreatingDataObj(this);
532 SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->GetAllMarkedModel() );
533 if( pInternDoc )
534 pInternDoc->CreatingDataObj(0);
536 bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
538 if( maDocShellRef.Is() )
540 maDocShellRef->DoClose();
542 else
544 delete pDoc;
548 maDocShellRef = aOldRef;
550 else if( nFormat == FORMAT_GDIMETAFILE )
552 if( mpSdViewIntern )
553 bOK = SetGDIMetaFile( mpSdViewIntern->GetAllMarkedMetaFile( TRUE ), rFlavor );
555 else if( nFormat == FORMAT_BITMAP )
557 if( mpSdViewIntern )
558 bOK = SetBitmap( mpSdViewIntern->GetAllMarkedBitmap( TRUE ), rFlavor );
560 else if( ( nFormat == FORMAT_STRING ) && mpBookmark )
562 bOK = SetString( mpBookmark->GetURL(), rFlavor );
564 else if( ( nFormat == SOT_FORMATSTR_ID_SVXB ) && mpGraphic )
566 bOK = SetGraphic( *mpGraphic, rFlavor );
568 else if( ( nFormat == SOT_FORMATSTR_ID_SVIM ) && mpImageMap )
570 bOK = SetImageMap( *mpImageMap, rFlavor );
572 else if( mpBookmark )
574 bOK = SetINetBookmark( *mpBookmark, rFlavor );
576 else if( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
578 ULONG nOldSwapMode = 0;
580 if( mpSdDrawDocumentIntern )
582 nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
583 mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
586 if( !maDocShellRef.Is() )
588 maDocShellRef = new ::sd::DrawDocShell(
589 mpSdDrawDocumentIntern,
590 SFX_CREATE_MODE_EMBEDDED,
591 TRUE,
592 mpSdDrawDocumentIntern->GetDocumentType());
593 mbOwnDocument = FALSE;
594 maDocShellRef->DoInitNew( NULL );
597 maDocShellRef->SetVisArea( maVisArea );
598 bOK = SetObject( &maDocShellRef, SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
600 if( mpSdDrawDocumentIntern )
601 mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
605 return bOK;
608 // -----------------------------------------------------------------------------
610 /* testcode
611 #include <sfx2/docfile.hxx>
614 sal_Bool SdTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& )
616 sal_Bool bRet = sal_False;
618 switch( nObjectType )
620 case( SDTRANSFER_OBJECTTYPE_DRAWMODEL ):
624 static const BOOL bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL );
625 SdDrawDocument* pDoc = (SdDrawDocument*) pObject;
626 if ( !bDontBurnInStyleSheet )
627 pDoc->BurnInStyleSheetAttributes();
628 rxOStm->SetBufferSize( 16348 );
630 Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, sal_True ) );
631 pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
634 com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
635 if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
636 rxOStm->Commit();
639 /* testcode
641 const rtl::OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
642 SfxMedium aMedium( aURL, STREAM_WRITE | STREAM_TRUNC, TRUE );
643 aMedium.IsRemote();
644 com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *aMedium.GetOutStream() ) );
645 if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
646 aMedium.Commit();
650 xComponent->dispose();
651 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
653 catch( Exception& )
655 DBG_ERROR( "sd::SdTransferable::WriteObject(), exception catched!" );
656 bRet = FALSE;
659 break;
661 case( SDTRANSFER_OBJECTTYPE_DRAWOLE ):
663 SfxObjectShell* pEmbObj = (SfxObjectShell*) pObject;
664 ::utl::TempFile aTempFile;
665 aTempFile.EnableKillingFile();
669 uno::Reference< embed::XStorage > xWorkStore =
670 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
672 // write document storage
673 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
674 // mba: no relative ULRs for clipboard!
675 SfxMedium aMedium( xWorkStore, String() );
676 bRet = pEmbObj->DoSaveObjectAs( aMedium, FALSE );
677 pEmbObj->DoSaveCompleted();
679 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
680 if ( xTransact.is() )
681 xTransact->commit();
683 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
684 if( pSrcStm )
686 rxOStm->SetBufferSize( 0xff00 );
687 *rxOStm << *pSrcStm;
688 delete pSrcStm;
691 bRet = TRUE;
692 rxOStm->Commit();
694 catch ( Exception& )
698 break;
700 default:
701 break;
704 return bRet;
707 // -----------------------------------------------------------------------------
709 void SdTransferable::DragFinished( sal_Int8 nDropAction )
711 if( mpSdView )
712 ( (::sd::View*) mpSdView )->DragFinished( nDropAction );
715 // -----------------------------------------------------------------------------
717 void SdTransferable::ObjectReleased()
719 if( this == SD_MOD()->pTransferClip )
720 SD_MOD()->pTransferClip = NULL;
722 if( this == SD_MOD()->pTransferDrag )
723 SD_MOD()->pTransferDrag = NULL;
725 if( this == SD_MOD()->pTransferSelection )
726 SD_MOD()->pTransferSelection = NULL;
729 // -----------------------------------------------------------------------------
731 void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor& rObjDesc )
733 delete mpObjDesc;
734 mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
735 PrepareOLE( rObjDesc );
738 // -----------------------------------------------------------------------------
740 void SdTransferable::SetPageBookmarks( const List& rPageBookmarks, BOOL bPersistent )
742 if( mpSourceDoc )
744 if( mpSdViewIntern )
745 mpSdViewIntern->HideSdrPage();
747 // #116168#
748 mpSdDrawDocument->ClearModel(sal_False);
750 mpPageDocShell = NULL;
752 for( void* p = maPageBookmarks.First(); p; p = maPageBookmarks.Next() )
753 delete static_cast< String* >( p );
755 if( bPersistent )
757 mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
758 mpSdDrawDocument->InsertBookmarkAsPage( const_cast< List* >( &rPageBookmarks ), NULL, FALSE, TRUE, 1, TRUE, mpSourceDoc->GetDocSh(), TRUE, TRUE, FALSE );
760 else
762 mpPageDocShell = mpSourceDoc->GetDocSh();
764 for( ULONG i = 0; i < rPageBookmarks.Count(); i++ )
765 maPageBookmarks.Insert( new String( *static_cast< String* >( rPageBookmarks.GetObject( i ) ) ), LIST_APPEND );
768 if( mpSdViewIntern && mpSdDrawDocument )
770 SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PK_STANDARD );
772 if( pPage )
774 ( (SdrMarkView*) mpSdViewIntern )->MarkAllObj( (SdrPageView*) mpSdViewIntern->ShowSdrPage( pPage ) );
778 // set flags for page transferable; if ( mbPageTransferablePersistent == FALSE ),
779 // don't offer any formats => it's just for internal puposes
780 mbPageTransferable = TRUE;
781 mbPageTransferablePersistent = bPersistent;
785 // -----------------------------------------------------------------------------
787 sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException )
789 sal_Int64 nRet;
791 if( ( rId.getLength() == 16 ) &&
792 ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
794 nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
796 else
798 nRet = 0;
801 return nRet;
804 // -----------------------------------------------------------------------------
806 const ::com::sun::star::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId()
808 static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
810 if( !aSeq.getLength() )
812 static osl::Mutex aCreateMutex;
813 osl::MutexGuard aGuard( aCreateMutex );
815 aSeq.realloc( 16 );
816 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
819 return aSeq;
822 // -----------------------------------------------------------------------------
824 SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw()
828 Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
829 return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
831 catch( const ::com::sun::star::uno::Exception& )
834 return NULL;
837 // -----------------------------------------------------------------------------
839 // SfxListener
840 void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
842 const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
843 if( pSdrHint )
845 if( HINT_MODELCLEARED == pSdrHint->GetKind() )
847 EndListening(*mpSourceDoc);
848 mpSourceDoc = 0;
851 else
853 const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint * >(&rHint);
854 if(pSimpleHint && (pSimpleHint->GetId() == SFX_HINT_DYING) )
856 if( &rBC == mpSourceDoc )
857 mpSourceDoc = 0;
858 if( &rBC == mpSdViewIntern )
859 mpSdViewIntern = 0;
860 if( &rBC == mpSdView )
861 mpSdView = 0;
866 sal_Bool SdTransferable::SetTableRTF( SdDrawDocument* pModel, const DataFlavor& rFlavor)
868 if ( pModel )
870 SdrPage* pPage = pModel->GetPage(0);
871 if (pPage && pPage->GetObjCount() == 1 )
873 sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
874 if( pTableObj )
876 SvMemoryStream aMemStm( 65535, 65535 );
877 sdr::table::SdrTableObj::ExportAsRTF( aMemStm, *pTableObj );
878 return SetAny( Any( Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ) ), rFlavor );
883 return sal_False;