1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
59 #include "drawview.hxx"
60 #include "drawdoc.hxx"
61 #include "stlpool.hxx"
62 #include "strings.hrc"
63 #include "sdresid.hxx"
64 #include "imapinfo.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 0x00000001
77 #define SDTRANSFER_OBJECTTYPE_DRAWOLE 0x00000002
79 SdTransferable::SdTransferable( SdDrawDocument
* pSrcDoc
, ::sd::View
* pWorkView
, sal_Bool bInitOnGetData
)
80 : mpPageDocShell( NULL
)
81 , mpOLEDataHelper( NULL
)
83 , mpSdView( pWorkView
)
84 , mpSdViewIntern( pWorkView
)
85 , mpSdDrawDocument( NULL
)
86 , mpSdDrawDocumentIntern( NULL
)
87 , mpSourceDoc( pSrcDoc
)
92 , mbInternalMove( sal_False
)
93 , mbOwnDocument( sal_False
)
94 , mbOwnView( sal_False
)
95 , mbLateInit( bInitOnGetData
)
96 , mbPageTransferable( sal_False
)
97 , mbPageTransferablePersistent( sal_False
)
102 StartListening( *mpSourceDoc
);
105 StartListening( *pWorkView
);
111 SdTransferable::~SdTransferable()
114 EndListening( *mpSourceDoc
);
117 EndListening( *const_cast< sd::View
*>( mpSdView
) );
119 SolarMutexGuard aSolarGuard
;
124 delete mpSdViewIntern
;
126 delete mpOLEDataHelper
;
128 if( maDocShellRef
.Is() )
130 SfxObjectShell
* pObj
= maDocShellRef
;
131 ::sd::DrawDocShell
* pDocSh
= static_cast< ::sd::DrawDocShell
*>(pObj
);
135 maDocShellRef
.Clear();
138 delete mpSdDrawDocumentIntern
;
149 void SdTransferable::CreateObjectReplacement( SdrObject
* pObj
)
153 delete mpOLEDataHelper
, mpOLEDataHelper
= NULL
;
154 delete mpGraphic
, mpGraphic
= NULL
;
155 delete mpBookmark
, mpBookmark
= NULL
;
156 delete mpImageMap
, mpImageMap
= NULL
;
158 if( pObj
->ISA( SdrOle2Obj
) )
162 uno::Reference
< embed::XEmbeddedObject
> xObj
= static_cast< SdrOle2Obj
* >( pObj
)->GetObjRef();
163 uno::Reference
< embed::XEmbedPersist
> xPersist( xObj
, uno::UNO_QUERY
);
164 if( xObj
.is() && xPersist
.is() && xPersist
->hasEntry() )
166 mpOLEDataHelper
= new TransferableDataHelper( new SvEmbedTransferHelper( xObj
, static_cast< SdrOle2Obj
* >( pObj
)->GetGraphic(), static_cast< SdrOle2Obj
* >( pObj
)->GetAspect() ) );
168 // TODO/LATER: the standalone handling of the graphic should not be used any more in future
169 // The EmbedDataHelper should bring the graphic in future
170 const Graphic
* pObjGr
= static_cast< SdrOle2Obj
* >( pObj
)->GetGraphic();
172 mpGraphic
= new Graphic( *pObjGr
);
175 catch( uno::Exception
& )
178 else if( pObj
->ISA( SdrGrafObj
) && (mpSourceDoc
&& !mpSourceDoc
->GetAnimationInfo( pObj
)) )
180 mpGraphic
= new Graphic( static_cast< SdrGrafObj
* >( pObj
)->GetTransformedGraphic() );
182 else if( pObj
->IsUnoObj() && FmFormInventor
== pObj
->GetObjInventor() && ( pObj
->GetObjIdentifier() == (sal_uInt16
) OBJ_FM_BUTTON
) )
184 SdrUnoObj
* pUnoCtrl
= static_cast< SdrUnoObj
* >( pObj
);
186 if (pUnoCtrl
&& FmFormInventor
== pUnoCtrl
->GetObjInventor())
188 Reference
< ::com::sun::star::awt::XControlModel
> xControlModel( pUnoCtrl
->GetUnoControlModel() );
190 if( !xControlModel
.is() )
193 Reference
< ::com::sun::star::beans::XPropertySet
> xPropSet( xControlModel
, UNO_QUERY
);
198 ::com::sun::star::form::FormButtonType eButtonType
;
199 Any
aTmp( xPropSet
->getPropertyValue( "ButtonType" ) );
201 if( aTmp
>>= eButtonType
)
203 OUString aLabel
, aURL
;
205 xPropSet
->getPropertyValue( "Label" ) >>= aLabel
;
206 xPropSet
->getPropertyValue( "TargetURL" ) >>= aURL
;
208 mpBookmark
= new INetBookmark( String( aURL
), String( aLabel
) );
212 else if( pObj
->ISA( SdrTextObj
) )
214 const OutlinerParaObject
* pPara
;
216 if( (pPara
= static_cast< SdrTextObj
* >( pObj
)->GetOutlinerParaObject()) != 0 )
218 const SvxFieldItem
* pField
;
220 if( (pField
= pPara
->GetTextObject().GetField()) != 0 )
222 const SvxFieldData
* pData
= pField
->GetField();
224 if( pData
&& pData
->ISA( SvxURLField
) )
226 const SvxURLField
* pURL
= (SvxURLField
*) pData
;
228 mpBookmark
= new INetBookmark( pURL
->GetURL(), pURL
->GetRepresentation() );
234 SdIMapInfo
* pInfo
= static_cast< SdDrawDocument
* >( pObj
->GetModel() )->GetIMapInfo( static_cast< SdrObject
* >( pObj
) );
237 mpImageMap
= new ImageMap( pInfo
->GetImageMap() );
239 mbIsUnoObj
= pObj
&& pObj
->IsUnoObj();
243 void SdTransferable::CreateData()
245 if( mpSdDrawDocument
&& !mpSdViewIntern
)
247 mbOwnView
= sal_True
;
249 SdPage
* pPage
= mpSdDrawDocument
->GetSdPage(0, PK_STANDARD
);
251 if( 1 == pPage
->GetObjCount() )
252 CreateObjectReplacement( pPage
->GetObj( 0 ) );
254 mpVDev
= new VirtualDevice( *Application::GetDefaultDevice() );
255 mpVDev
->SetMapMode( MapMode( mpSdDrawDocumentIntern
->GetScaleUnit(), Point(), mpSdDrawDocumentIntern
->GetScaleFraction(), mpSdDrawDocumentIntern
->GetScaleFraction() ) );
256 mpSdViewIntern
= new ::sd::View( *mpSdDrawDocumentIntern
, mpVDev
);
257 mpSdViewIntern
->EndListening(*mpSdDrawDocumentIntern
);
258 mpSdViewIntern
->hideMarkHandles();
259 SdrPageView
* pPageView
= mpSdViewIntern
->ShowSdrPage(pPage
);
260 ((SdrMarkView
*)mpSdViewIntern
)->MarkAllObj(pPageView
);
262 else if( mpSdView
&& !mpSdDrawDocumentIntern
)
264 const SdrMarkList
& rMarkList
= mpSdView
->GetMarkedObjectList();
266 if( rMarkList
.GetMarkCount() == 1 )
267 CreateObjectReplacement( rMarkList
.GetMark( 0 )->GetMarkedSdrObj() );
270 mpSourceDoc
->CreatingDataObj(this);
271 mpSdDrawDocumentIntern
= (SdDrawDocument
*) mpSdView
->GetMarkedObjModel();
273 mpSourceDoc
->CreatingDataObj(0);
275 if( !maDocShellRef
.Is() && mpSdDrawDocumentIntern
->GetDocSh() )
276 maDocShellRef
= mpSdDrawDocumentIntern
->GetDocSh();
278 if( !maDocShellRef
.Is() )
280 OSL_FAIL( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
281 mbOwnDocument
= sal_True
;
284 // Use dimension of source page
285 SdrPageView
* pPgView
= mpSdView
->GetSdrPageView();
286 SdPage
* pOldPage
= (SdPage
*) pPgView
->GetPage();
287 SdrModel
* pOldModel
= mpSdView
->GetModel();
288 SdStyleSheetPool
* pOldStylePool
= (SdStyleSheetPool
*) pOldModel
->GetStyleSheetPool();
289 SdStyleSheetPool
* pNewStylePool
= (SdStyleSheetPool
*) mpSdDrawDocumentIntern
->GetStyleSheetPool();
290 SdPage
* pPage
= mpSdDrawDocumentIntern
->GetSdPage( 0, PK_STANDARD
);
291 String
aOldLayoutName( pOldPage
->GetLayoutName() );
293 pPage
->SetSize( pOldPage
->GetSize() );
294 pPage
->SetLayoutName( aOldLayoutName
);
295 pNewStylePool
->CopyGraphicSheets( *pOldStylePool
);
296 pNewStylePool
->CopyCellSheets( *pOldStylePool
);
297 pNewStylePool
->CopyTableStyles( *pOldStylePool
);
298 aOldLayoutName
.Erase( aOldLayoutName
.SearchAscii( SD_LT_SEPARATOR
) );
299 SdStyleSheetVector aCreatedSheets
;
300 pNewStylePool
->CopyLayoutSheets( aOldLayoutName
, *pOldStylePool
, aCreatedSheets
);
303 // set VisArea and adjust objects if necessary
304 if( maVisArea
.IsEmpty() &&
305 mpSdDrawDocumentIntern
&& mpSdViewIntern
&&
306 mpSdDrawDocumentIntern
->GetPageCount() )
308 SdPage
* pPage
= mpSdDrawDocumentIntern
->GetSdPage( 0, PK_STANDARD
);
310 if( 1 == mpSdDrawDocumentIntern
->GetPageCount() )
312 // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
313 // fat lines correctly
314 Point
aOrigin( ( maVisArea
= mpSdViewIntern
->GetAllMarkedBoundRect() ).TopLeft() );
315 Size
aVector( -aOrigin
.X(), -aOrigin
.Y() );
317 for( sal_uLong nObj
= 0, nObjCount
= pPage
->GetObjCount(); nObj
< nObjCount
; nObj
++ )
319 SdrObject
* pObj
= pPage
->GetObj( nObj
);
320 pObj
->NbcMove( aVector
);
324 maVisArea
.SetSize( pPage
->GetSize() );
326 // output is at the zero point
327 maVisArea
.SetPos( Point() );
331 static sal_Bool
lcl_HasOnlyControls( SdrModel
* pModel
)
333 sal_Bool bOnlyControls
= sal_False
; // default if there are no objects
337 SdrPage
* pPage
= pModel
->GetPage(0);
340 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
341 SdrObject
* pObj
= aIter
.Next();
344 bOnlyControls
= sal_True
; // only set if there are any objects at all
347 if (!pObj
->ISA(SdrUnoObj
))
349 bOnlyControls
= sal_False
;
358 return bOnlyControls
;
361 static bool lcl_HasOnlyOneTable( SdrModel
* pModel
)
365 SdrPage
* pPage
= pModel
->GetPage(0);
366 if (pPage
&& pPage
->GetObjCount() == 1 )
368 if( dynamic_cast< sdr::table::SdrTableObj
* >( pPage
->GetObj(0) ) != 0 )
375 void SdTransferable::AddSupportedFormats()
377 if( !mbPageTransferable
|| mbPageTransferablePersistent
)
383 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
);
385 if( mpOLEDataHelper
)
387 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
389 DataFlavorExVector
aVector( mpOLEDataHelper
->GetDataFlavorExVector() );
390 DataFlavorExVector::iterator
aIter( aVector
.begin() ), aEnd( aVector
.end() );
392 while( aIter
!= aEnd
)
393 AddFormat( *aIter
++ );
398 AddFormat( SOT_FORMATSTR_ID_DRAWING
);
400 AddFormat( SOT_FORMATSTR_ID_SVXB
);
402 if( mpGraphic
->GetType() == GRAPHIC_BITMAP
)
404 AddFormat( SOT_FORMAT_BITMAP
);
405 AddFormat( SOT_FORMAT_GDIMETAFILE
);
409 AddFormat( SOT_FORMAT_GDIMETAFILE
);
410 AddFormat( SOT_FORMAT_BITMAP
);
413 else if( mpBookmark
)
415 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK
);
416 AddFormat( FORMAT_STRING
);
420 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE
);
421 AddFormat( SOT_FORMATSTR_ID_DRAWING
);
422 if( !mpSdDrawDocument
|| !lcl_HasOnlyControls( mpSdDrawDocument
) )
424 AddFormat( SOT_FORMAT_GDIMETAFILE
);
425 AddFormat( SOT_FORMAT_BITMAP
);
428 if( lcl_HasOnlyOneTable( mpSdDrawDocument
) )
429 AddFormat( SOT_FORMAT_RTF
);
433 AddFormat( SOT_FORMATSTR_ID_SVIM
);
437 sal_Bool
SdTransferable::GetData( const DataFlavor
& rFlavor
)
442 sal_uInt32 nFormat
= SotExchange::GetFormat( rFlavor
);
443 sal_Bool bOK
= sal_False
;
447 if( nFormat
== SOT_FORMAT_RTF
&& lcl_HasOnlyOneTable( mpSdDrawDocument
) )
449 bOK
= SetTableRTF( mpSdDrawDocument
, rFlavor
);
451 else if( mpOLEDataHelper
&& mpOLEDataHelper
->HasFormat( rFlavor
) )
453 sal_uLong nOldSwapMode
= 0;
455 if( mpSdDrawDocumentIntern
)
457 nOldSwapMode
= mpSdDrawDocumentIntern
->GetSwapGraphicsMode();
458 mpSdDrawDocumentIntern
->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE
);
461 // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
462 if( nFormat
== FORMAT_GDIMETAFILE
&& mpGraphic
)
463 bOK
= SetGDIMetaFile( mpGraphic
->GetGDIMetaFile(), rFlavor
);
465 bOK
= SetAny( mpOLEDataHelper
->GetAny( rFlavor
), rFlavor
);
467 if( mpSdDrawDocumentIntern
)
468 mpSdDrawDocumentIntern
->SetSwapGraphicsMode( nOldSwapMode
);
470 else if( HasFormat( nFormat
) )
472 if( ( nFormat
== SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR
|| nFormat
== SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
) && mpObjDesc
)
474 bOK
= SetTransferableObjectDescriptor( *mpObjDesc
, rFlavor
);
476 else if( nFormat
== SOT_FORMATSTR_ID_DRAWING
)
478 SfxObjectShellRef
aOldRef( maDocShellRef
);
480 maDocShellRef
.Clear();
484 SdDrawDocument
& rInternDoc
= mpSdViewIntern
->GetDoc();
485 rInternDoc
.CreatingDataObj(this);
486 SdDrawDocument
* pDoc
= dynamic_cast< SdDrawDocument
* >( mpSdViewIntern
->GetMarkedObjModel() );
487 rInternDoc
.CreatingDataObj(0);
489 bOK
= SetObject( pDoc
, SDTRANSFER_OBJECTTYPE_DRAWMODEL
, rFlavor
);
491 if( maDocShellRef
.Is() )
493 maDocShellRef
->DoClose();
501 maDocShellRef
= aOldRef
;
503 else if( nFormat
== FORMAT_GDIMETAFILE
)
506 bOK
= SetGDIMetaFile( mpSdViewIntern
->GetMarkedObjMetaFile( true ), rFlavor
);
508 else if( nFormat
== FORMAT_BITMAP
)
511 bOK
= SetBitmap( mpSdViewIntern
->GetMarkedObjBitmapEx( true ).GetBitmap(), rFlavor
);
513 else if( ( nFormat
== FORMAT_STRING
) && mpBookmark
)
515 bOK
= SetString( mpBookmark
->GetURL(), rFlavor
);
517 else if( ( nFormat
== SOT_FORMATSTR_ID_SVXB
) && mpGraphic
)
519 bOK
= SetGraphic( *mpGraphic
, rFlavor
);
521 else if( ( nFormat
== SOT_FORMATSTR_ID_SVIM
) && mpImageMap
)
523 bOK
= SetImageMap( *mpImageMap
, rFlavor
);
525 else if( mpBookmark
)
527 bOK
= SetINetBookmark( *mpBookmark
, rFlavor
);
529 else if( nFormat
== SOT_FORMATSTR_ID_EMBED_SOURCE
)
531 sal_uLong nOldSwapMode
= 0;
533 if( mpSdDrawDocumentIntern
)
535 nOldSwapMode
= mpSdDrawDocumentIntern
->GetSwapGraphicsMode();
536 mpSdDrawDocumentIntern
->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE
);
539 if( !maDocShellRef
.Is() )
541 maDocShellRef
= new ::sd::DrawDocShell(
542 mpSdDrawDocumentIntern
,
543 SFX_CREATE_MODE_EMBEDDED
,
545 mpSdDrawDocumentIntern
->GetDocumentType());
546 mbOwnDocument
= sal_False
;
547 maDocShellRef
->DoInitNew( NULL
);
550 maDocShellRef
->SetVisArea( maVisArea
);
551 bOK
= SetObject( &maDocShellRef
, SDTRANSFER_OBJECTTYPE_DRAWOLE
, rFlavor
);
553 if( mpSdDrawDocumentIntern
)
554 mpSdDrawDocumentIntern
->SetSwapGraphicsMode( nOldSwapMode
);
561 sal_Bool
SdTransferable::WriteObject( SotStorageStreamRef
& rxOStm
, void* pObject
, sal_uInt32 nObjectType
, const DataFlavor
& )
563 sal_Bool bRet
= sal_False
;
565 switch( nObjectType
)
567 case( SDTRANSFER_OBJECTTYPE_DRAWMODEL
):
571 static const sal_Bool bDontBurnInStyleSheet
= ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL
);
572 SdDrawDocument
* pDoc
= (SdDrawDocument
*) pObject
;
573 if ( !bDontBurnInStyleSheet
)
574 pDoc
->BurnInStyleSheetAttributes();
575 rxOStm
->SetBufferSize( 16348 );
577 Reference
< XComponent
> xComponent( new SdXImpressDocument( pDoc
, sal_True
) );
578 pDoc
->setUnoModel( Reference
< XInterface
>::query( xComponent
) );
581 com::sun::star::uno::Reference
<com::sun::star::io::XOutputStream
> xDocOut( new utl::OOutputStreamWrapper( *rxOStm
) );
582 if( SvxDrawingLayerExport( pDoc
, xDocOut
, xComponent
, (pDoc
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
586 xComponent
->dispose();
587 bRet
= ( rxOStm
->GetError() == ERRCODE_NONE
);
591 OSL_FAIL( "sd::SdTransferable::WriteObject(), exception catched!" );
597 case( SDTRANSFER_OBJECTTYPE_DRAWOLE
):
599 SfxObjectShell
* pEmbObj
= (SfxObjectShell
*) pObject
;
600 ::utl::TempFile aTempFile
;
601 aTempFile
.EnableKillingFile();
605 uno::Reference
< embed::XStorage
> xWorkStore
=
606 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile
.GetURL(), embed::ElementModes::READWRITE
);
608 // write document storage
609 pEmbObj
->SetupStorage( xWorkStore
, SOFFICE_FILEFORMAT_CURRENT
, sal_False
);
610 // mba: no relative ULRs for clipboard!
611 SfxMedium
aMedium( xWorkStore
, String() );
612 bRet
= pEmbObj
->DoSaveObjectAs( aMedium
, sal_False
);
613 pEmbObj
->DoSaveCompleted();
615 uno::Reference
< embed::XTransactedObject
> xTransact( xWorkStore
, uno::UNO_QUERY
);
616 if ( xTransact
.is() )
619 SvStream
* pSrcStm
= ::utl::UcbStreamHelper::CreateStream( aTempFile
.GetURL(), STREAM_READ
);
622 rxOStm
->SetBufferSize( 0xff00 );
643 void SdTransferable::DragFinished( sal_Int8 nDropAction
)
646 ( (::sd::View
*) mpSdView
)->DragFinished( nDropAction
);
649 void SdTransferable::ObjectReleased()
651 if( this == SD_MOD()->pTransferClip
)
652 SD_MOD()->pTransferClip
= NULL
;
654 if( this == SD_MOD()->pTransferDrag
)
655 SD_MOD()->pTransferDrag
= NULL
;
657 if( this == SD_MOD()->pTransferSelection
)
658 SD_MOD()->pTransferSelection
= NULL
;
661 void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor
& rObjDesc
)
664 mpObjDesc
= new TransferableObjectDescriptor( rObjDesc
);
665 PrepareOLE( rObjDesc
);
668 void SdTransferable::SetPageBookmarks( const std::vector
<OUString
> &rPageBookmarks
, sal_Bool bPersistent
)
673 mpSdViewIntern
->HideSdrPage();
675 mpSdDrawDocument
->ClearModel(sal_False
);
677 mpPageDocShell
= NULL
;
679 maPageBookmarks
.clear();
683 mpSdDrawDocument
->CreateFirstPages(mpSourceDoc
);
684 mpSdDrawDocument
->InsertBookmarkAsPage( rPageBookmarks
, NULL
, sal_False
, sal_True
, 1, sal_True
,
685 mpSourceDoc
->GetDocSh(), sal_True
, sal_True
, sal_False
);
689 mpPageDocShell
= mpSourceDoc
->GetDocSh();
690 maPageBookmarks
= rPageBookmarks
;
693 if( mpSdViewIntern
&& mpSdDrawDocument
)
695 SdPage
* pPage
= mpSdDrawDocument
->GetSdPage( 0, PK_STANDARD
);
699 ( (SdrMarkView
*) mpSdViewIntern
)->MarkAllObj( (SdrPageView
*) mpSdViewIntern
->ShowSdrPage( pPage
) );
703 // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
704 // don't offer any formats => it's just for internal puposes
705 mbPageTransferable
= sal_True
;
706 mbPageTransferablePersistent
= bPersistent
;
710 sal_Int64 SAL_CALL
SdTransferable::getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( ::com::sun::star::uno::RuntimeException
)
714 if( ( rId
.getLength() == 16 ) &&
715 ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId
.getConstArray(), 16 ) ) )
717 nRet
= sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
728 SdDrawDocument
* SdTransferable::GetSourceDoc (void) const
733 void SdTransferable::AddUserData (const ::boost::shared_ptr
<UserData
>& rpData
)
735 maUserData
.push_back(rpData
);
738 sal_Int32
SdTransferable::GetUserDataCount (void) const
740 return maUserData
.size();
743 ::boost::shared_ptr
<SdTransferable::UserData
> SdTransferable::GetUserData (const sal_Int32 nIndex
) const
745 if (nIndex
>=0 && nIndex
<sal_Int32(maUserData
.size()))
746 return maUserData
[nIndex
];
748 return ::boost::shared_ptr
<UserData
>();
753 class theSdTransferableUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSdTransferableUnoTunnelId
> {};
756 const ::com::sun::star::uno::Sequence
< sal_Int8
>& SdTransferable::getUnoTunnelId()
758 return theSdTransferableUnoTunnelId::get().getSeq();
761 SdTransferable
* SdTransferable::getImplementation( const Reference
< XInterface
>& rxData
) throw()
765 Reference
< ::com::sun::star::lang::XUnoTunnel
> xUnoTunnel( rxData
, UNO_QUERY_THROW
);
766 return reinterpret_cast<SdTransferable
*>(sal::static_int_cast
<sal_uIntPtr
>(xUnoTunnel
->getSomething( SdTransferable::getUnoTunnelId()) ) );
768 catch( const ::com::sun::star::uno::Exception
& )
774 void SdTransferable::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
776 const SdrHint
* pSdrHint
= dynamic_cast< const SdrHint
* >( &rHint
);
779 if( HINT_MODELCLEARED
== pSdrHint
->GetKind() )
781 EndListening(*mpSourceDoc
);
787 const SfxSimpleHint
* pSimpleHint
= dynamic_cast< const SfxSimpleHint
* >(&rHint
);
788 if(pSimpleHint
&& (pSimpleHint
->GetId() == SFX_HINT_DYING
) )
790 if( &rBC
== mpSourceDoc
)
792 if( &rBC
== mpSdViewIntern
)
794 if( &rBC
== mpSdView
)
800 sal_Bool
SdTransferable::SetTableRTF( SdDrawDocument
* pModel
, const DataFlavor
& rFlavor
)
804 SdrPage
* pPage
= pModel
->GetPage(0);
805 if (pPage
&& pPage
->GetObjCount() == 1 )
807 sdr::table::SdrTableObj
* pTableObj
= dynamic_cast< sdr::table::SdrTableObj
* >( pPage
->GetObj(0) );
810 SvMemoryStream
aMemStm( 65535, 65535 );
811 sdr::table::SdrTableObj::ExportAsRTF( aMemStm
, *pTableObj
);
812 return SetAny( Any( Sequence
< sal_Int8
>( reinterpret_cast< const sal_Int8
* >( aMemStm
.GetData() ), aMemStm
.Seek( STREAM_SEEK_TO_END
) ) ), rFlavor
);
820 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */