1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdxfer.cxx,v $
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>
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>
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"
77 #include "drawview.hxx"
78 #include "drawdoc.hxx"
79 #include "stlpool.hxx"
80 #include "strings.hrc"
81 #include "sdresid.hxx"
82 #include "imapinfo.hxx"
84 #include "unomodel.hxx"
85 #include <vcl/virdev.hxx>
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
;
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
)
113 , mpSdView( pWorkView
)
114 , mpSdViewIntern( pWorkView
)
115 , mpSdDrawDocument( NULL
)
116 , mpSdDrawDocumentIntern( NULL
)
117 , mpSourceDoc( pSrcDoc
)
122 , mbInternalMove( FALSE
)
123 , mbOwnDocument( FALSE
)
125 , mbLateInit( bInitOnGetData
)
126 , mbPageTransferable( FALSE
)
127 , mbPageTransferablePersistent( FALSE
)
128 , mbIsUnoObj( false )
131 StartListening( *mpSourceDoc
);
134 StartListening( *pWorkView
);
140 // -----------------------------------------------------------------------------
142 SdTransferable::~SdTransferable()
145 EndListening( *mpSourceDoc
);
148 EndListening( *const_cast< sd::View
*>( mpSdView
) );
150 Application::GetSolarMutex().acquire();
154 for( void* p
= maPageBookmarks
.First(); p
; p
= maPageBookmarks
.Next() )
155 delete static_cast< String
* >( p
);
158 delete mpSdViewIntern
;
160 delete mpOLEDataHelper
;
162 if( maDocShellRef
.Is() )
164 SfxObjectShell
* pObj
= maDocShellRef
;
165 ::sd::DrawDocShell
* pDocSh
= static_cast< ::sd::DrawDocShell
*>(pObj
);
169 maDocShellRef
.Clear();
172 delete mpSdDrawDocumentIntern
;
181 Application::GetSolarMutex().release();
184 // -----------------------------------------------------------------------------
186 void SdTransferable::CreateObjectReplacement( SdrObject
* 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();
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() )
230 Reference
< ::com::sun::star::beans::XPropertySet
> xPropSet( xControlModel
, UNO_QUERY
);
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
) );
274 mpImageMap
= new ImageMap( pInfo
->GetImageMap() );
276 mbIsUnoObj
= pObj
&& pObj
->IsUnoObj();
280 // -----------------------------------------------------------------------------
282 void SdTransferable::CreateData()
284 if( mpSdDrawDocument
&& !mpSdViewIntern
)
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() );
309 mpSourceDoc
->CreatingDataObj(this);
310 mpSdDrawDocumentIntern
= (SdDrawDocument
*) mpSdView
->GetAllMarkedModel();
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
);
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
376 SdrPage
* pPage
= pModel
->GetPage(0);
379 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
380 SdrObject
* pObj
= aIter
.Next();
383 bOnlyControls
= TRUE
; // only set if there are any objects at all
386 if (!pObj
->ISA(SdrUnoObj
))
388 bOnlyControls
= FALSE
;
397 return bOnlyControls
;
400 // -----------------------------------------------------------------------------
402 bool lcl_HasOnlyOneTable( SdrModel
* pModel
)
406 SdrPage
* pPage
= pModel
->GetPage(0);
407 if (pPage
&& pPage
->GetObjCount() == 1 )
409 if( dynamic_cast< sdr::table::SdrTableObj
* >( pPage
->GetObj(0) ) != 0 )
416 // -----------------------------------------------------------------------------
418 void SdTransferable::AddSupportedFormats()
420 if( !mbPageTransferable
|| mbPageTransferablePersistent
)
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
++ );
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
);
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
);
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
);
476 AddFormat( SOT_FORMATSTR_ID_SVIM
);
480 // -----------------------------------------------------------------------------
482 sal_Bool
SdTransferable::GetData( const DataFlavor
& rFlavor
)
487 sal_uInt32 nFormat
= SotExchange::GetFormat( rFlavor
);
488 sal_Bool bOK
= sal_False
;
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
);
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();
529 SdDrawDocument
* pInternDoc
= mpSdViewIntern
->GetDoc();
531 pInternDoc
->CreatingDataObj(this);
532 SdDrawDocument
* pDoc
= dynamic_cast< SdDrawDocument
* >( mpSdViewIntern
->GetAllMarkedModel() );
534 pInternDoc
->CreatingDataObj(0);
536 bOK
= SetObject( pDoc
, SDTRANSFER_OBJECTTYPE_DRAWMODEL
, rFlavor
);
538 if( maDocShellRef
.Is() )
540 maDocShellRef
->DoClose();
548 maDocShellRef
= aOldRef
;
550 else if( nFormat
== FORMAT_GDIMETAFILE
)
553 bOK
= SetGDIMetaFile( mpSdViewIntern
->GetAllMarkedMetaFile( TRUE
), rFlavor
);
555 else if( nFormat
== FORMAT_BITMAP
)
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
,
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
);
608 // -----------------------------------------------------------------------------
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" ) )
641 const rtl::OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "file:///e:/test.xml" ) );
642 SfxMedium aMedium( aURL, STREAM_WRITE | STREAM_TRUNC, TRUE );
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" ) )
650 xComponent
->dispose();
651 bRet
= ( rxOStm
->GetError() == ERRCODE_NONE
);
655 DBG_ERROR( "sd::SdTransferable::WriteObject(), exception catched!" );
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() )
683 SvStream
* pSrcStm
= ::utl::UcbStreamHelper::CreateStream( aTempFile
.GetURL(), STREAM_READ
);
686 rxOStm
->SetBufferSize( 0xff00 );
707 // -----------------------------------------------------------------------------
709 void SdTransferable::DragFinished( sal_Int8 nDropAction
)
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
)
734 mpObjDesc
= new TransferableObjectDescriptor( rObjDesc
);
735 PrepareOLE( rObjDesc
);
738 // -----------------------------------------------------------------------------
740 void SdTransferable::SetPageBookmarks( const List
& rPageBookmarks
, BOOL bPersistent
)
745 mpSdViewIntern
->HideSdrPage();
748 mpSdDrawDocument
->ClearModel(sal_False
);
750 mpPageDocShell
= NULL
;
752 for( void* p
= maPageBookmarks
.First(); p
; p
= maPageBookmarks
.Next() )
753 delete static_cast< String
* >( p
);
757 mpSdDrawDocument
->CreateFirstPages(mpSourceDoc
);
758 mpSdDrawDocument
->InsertBookmarkAsPage( const_cast< List
* >( &rPageBookmarks
), NULL
, FALSE
, TRUE
, 1, TRUE
, mpSourceDoc
->GetDocSh(), TRUE
, TRUE
, FALSE
);
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
);
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
)
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));
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
);
816 rtl_createUuid( reinterpret_cast< sal_uInt8
* >( aSeq
.getArray() ), 0, sal_True
);
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
& )
837 // -----------------------------------------------------------------------------
840 void SdTransferable::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
842 const SdrHint
* pSdrHint
= dynamic_cast< const SdrHint
* >( &rHint
);
845 if( HINT_MODELCLEARED
== pSdrHint
->GetKind() )
847 EndListening(*mpSourceDoc
);
853 const SfxSimpleHint
* pSimpleHint
= dynamic_cast< const SfxSimpleHint
* >(&rHint
);
854 if(pSimpleHint
&& (pSimpleHint
->GetId() == SFX_HINT_DYING
) )
856 if( &rBC
== mpSourceDoc
)
858 if( &rBC
== mpSdViewIntern
)
860 if( &rBC
== mpSdView
)
866 sal_Bool
SdTransferable::SetTableRTF( SdDrawDocument
* pModel
, const DataFlavor
& rFlavor
)
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) );
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
);