android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / app / sdxfer.cxx
blob693dd399c321ddaf7f175022bcb5bd50bdbbfa9d
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 <sal/config.h>
22 #include <com/sun/star/embed/XEmbeddedObject.hpp>
23 #include <com/sun/star/embed/XTransactedObject.hpp>
24 #include <com/sun/star/embed/XEmbedPersist.hpp>
25 #include <com/sun/star/embed/ElementModes.hpp>
26 #include <com/sun/star/lang/XComponent.hpp>
27 #include <comphelper/fileformat.h>
28 #include <unotools/ucbstreamhelper.hxx>
29 #include <unotools/tempfile.hxx>
30 #include <editeng/flditem.hxx>
31 #include <svx/svdpagv.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 <editeng/editobj.hxx>
38 #include <o3tl/safeint.hxx>
39 #include <svx/svdobjkind.hxx>
40 #include <svx/svdouno.hxx>
41 #include <svx/ImageMapInfo.hxx>
42 #include <sot/formats.hxx>
43 #include <svl/urlbmk.hxx>
44 #include <comphelper/diagnose_ex.hxx>
46 #include <com/sun/star/form/FormButtonType.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <unotools/streamwrap.hxx>
50 #include <svx/svdotable.hxx>
51 #include <svx/unomodel.hxx>
52 #include <svx/svditer.hxx>
53 #include <sfx2/docfile.hxx>
54 #include <comphelper/storagehelper.hxx>
55 #include <comphelper/servicehelper.hxx>
56 #include <svtools/embedtransfer.hxx>
57 #include <DrawDocShell.hxx>
58 #include <View.hxx>
59 #include <sdmod.hxx>
60 #include <sdpage.hxx>
61 #include <drawdoc.hxx>
62 #include <stlpool.hxx>
63 #include <sdxfer.hxx>
64 #include <unomodel.hxx>
65 #include <vcl/virdev.hxx>
66 #include <vcl/svapp.hxx>
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::lang;
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::io;
72 using namespace ::com::sun::star::datatransfer;
73 using namespace ::com::sun::star::datatransfer::clipboard;
75 constexpr sal_uInt32 SDTRANSFER_OBJECTTYPE_DRAWMODEL = 1;
76 constexpr sal_uInt32 SDTRANSFER_OBJECTTYPE_DRAWOLE = 2;
78 SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, bool bInitOnGetData )
79 : mpPageDocShell( nullptr )
80 , mpSdView( pWorkView )
81 , mpSdViewIntern( pWorkView )
82 , mpSdDrawDocument( nullptr )
83 , mpSdDrawDocumentIntern( nullptr )
84 , mpSourceDoc( pSrcDoc )
85 , mpVDev( nullptr )
86 , mbInternalMove( false )
87 , mbOwnDocument( false )
88 , mbOwnView( false )
89 , mbLateInit( bInitOnGetData )
90 , mbPageTransferable( false )
91 , mbPageTransferablePersistent( false )
93 if( mpSourceDoc )
94 StartListening( *mpSourceDoc );
96 if( pWorkView )
97 StartListening( *pWorkView );
99 if( !mbLateInit )
100 CreateData();
103 SdTransferable::~SdTransferable()
105 SolarMutexGuard g;
107 if( mpSourceDoc )
108 EndListening( *mpSourceDoc );
110 if( mpSdView )
111 EndListening( *const_cast< sd::View *>( mpSdView) );
113 ObjectReleased();
115 if( mbOwnView )
116 delete mpSdViewIntern;
118 mpOLEDataHelper.reset();
120 if( maDocShellRef.is() )
122 SfxObjectShell* pObj = maDocShellRef.get();
123 ::sd::DrawDocShell* pDocSh = static_cast< ::sd::DrawDocShell*>(pObj);
124 pDocSh->DoClose();
127 maDocShellRef.clear();
129 if( mbOwnDocument )
130 delete mpSdDrawDocumentIntern;
132 moGraphic.reset();
133 moBookmark.reset();
134 mpImageMap.reset();
136 mpVDev.disposeAndClear();
137 mpObjDesc.reset();
139 //call explicitly at end of dtor to be covered by above SolarMutex
140 maUserData.clear();
143 void SdTransferable::CreateObjectReplacement( SdrObject* pObj )
145 if( !pObj )
146 return;
148 mpOLEDataHelper.reset();
149 moGraphic.reset();
150 moBookmark.reset();
151 mpImageMap.reset();
153 if( auto pOleObj = dynamic_cast< SdrOle2Obj* >( pObj ) )
157 uno::Reference < embed::XEmbeddedObject > xObj = pOleObj->GetObjRef();
158 uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
159 if( xObj.is() && xPersist.is() && xPersist->hasEntry() )
161 mpOLEDataHelper.reset( new TransferableDataHelper( new SvEmbedTransferHelper( xObj, pOleObj->GetGraphic(), pOleObj->GetAspect() ) ) );
163 // TODO/LATER: the standalone handling of the graphic should not be used any more in future
164 // The EmbedDataHelper should bring the graphic in future
165 const Graphic* pObjGr = pOleObj->GetGraphic();
166 if ( pObjGr )
167 moGraphic.emplace(*pObjGr);
170 catch( uno::Exception& )
173 else if( dynamic_cast< const SdrGrafObj *>( pObj ) != nullptr && (mpSourceDoc && !SdDrawDocument::GetAnimationInfo( pObj )) )
175 moGraphic.emplace( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() );
177 else if( pObj->IsUnoObj() && SdrInventor::FmForm == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == SdrObjKind::FormButton ) )
179 SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( pObj );
181 if (SdrInventor::FmForm == pUnoCtrl->GetObjInventor())
183 const Reference< css::awt::XControlModel >& xControlModel( pUnoCtrl->GetUnoControlModel() );
185 if( !xControlModel.is() )
186 return;
188 Reference< css::beans::XPropertySet > xPropSet( xControlModel, UNO_QUERY );
190 if( !xPropSet.is() )
191 return;
193 css::form::FormButtonType eButtonType;
194 Any aTmp( xPropSet->getPropertyValue( "ButtonType" ) );
196 if( aTmp >>= eButtonType )
198 OUString aLabel, aURL;
200 xPropSet->getPropertyValue( "Label" ) >>= aLabel;
201 xPropSet->getPropertyValue( "TargetURL" ) >>= aURL;
203 moBookmark.emplace( aURL, aLabel );
207 else if( auto pTextObj = DynCastSdrTextObj( pObj ) )
209 const OutlinerParaObject* pPara;
211 if( (pPara = pTextObj->GetOutlinerParaObject()) != nullptr )
213 const SvxFieldItem* pField;
215 if( (pField = pPara->GetTextObject().GetField()) != nullptr )
217 const SvxFieldData* pData = pField->GetField();
219 if( auto pURL = dynamic_cast< const SvxURLField *>( pData ) )
221 // #i63399# This special code identifies TextFrames which have just a URL
222 // as content and directly add this to the clipboard, probably to avoid adding
223 // an unnecessary DrawObject to the target where paste may take place. This is
224 // wanted only for SdrObjects with no fill and no line, else it is necessary to
225 // use the whole SdrObject. Test here for Line/FillStyle and take shortcut only
226 // when both are unused
227 if(!pObj->HasFillStyle() && !pObj->HasLineStyle())
229 moBookmark.emplace( pURL->GetURL(), pURL->GetRepresentation() );
236 SvxIMapInfo* pInfo = SvxIMapInfo::GetIMapInfo( pObj );
238 if( pInfo )
239 mpImageMap.reset( new ImageMap( pInfo->GetImageMap() ) );
242 void SdTransferable::CreateData()
244 if( mpSdDrawDocument && !mpSdViewIntern )
246 mbOwnView = true;
248 SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PageKind::Standard);
250 if( pPage && 1 == pPage->GetObjCount() )
251 CreateObjectReplacement( pPage->GetObj( 0 ) );
253 mpVDev = VclPtr<VirtualDevice>::Create( *Application::GetDefaultDevice() );
254 mpVDev->SetMapMode(MapMode(mpSdDrawDocumentIntern->GetScaleUnit()));
255 mpSdViewIntern = new ::sd::View( *mpSdDrawDocumentIntern, mpVDev );
256 mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern );
257 mpSdViewIntern->hideMarkHandles();
258 SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage);
259 mpSdViewIntern->MarkAllObj(pPageView);
261 else if( mpSdView && !mpSdDrawDocumentIntern )
263 const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList();
265 if( rMarkList.GetMarkCount() == 1 )
266 CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
268 if( mpSourceDoc )
269 mpSourceDoc->CreatingDataObj(this);
270 mpSdDrawDocumentIntern = static_cast<SdDrawDocument*>( mpSdView->CreateMarkedObjModel().release() );
271 if( mpSourceDoc )
272 mpSourceDoc->CreatingDataObj(nullptr);
274 if( !maDocShellRef.is() && mpSdDrawDocumentIntern->GetDocSh() )
275 maDocShellRef = mpSdDrawDocumentIntern->GetDocSh();
277 if( !maDocShellRef.is() )
279 OSL_FAIL( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
280 mbOwnDocument = true;
283 // Use dimension of source page
284 SdrPageView* pPgView = mpSdView->GetSdrPageView();
285 SdPage* pOldPage = static_cast<SdPage*>( pPgView->GetPage() );
286 SdStyleSheetPool* pOldStylePool = static_cast<SdStyleSheetPool*>(mpSdView->GetModel().GetStyleSheetPool());
287 SdStyleSheetPool* pNewStylePool = static_cast<SdStyleSheetPool*>( mpSdDrawDocumentIntern->GetStyleSheetPool() );
288 SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PageKind::Standard );
289 OUString aOldLayoutName( pOldPage->GetLayoutName() );
291 pPage->SetSize( pOldPage->GetSize() );
292 pPage->SetLayoutName( aOldLayoutName );
293 pNewStylePool->CopyGraphicSheets( *pOldStylePool );
294 pNewStylePool->CopyCellSheets( *pOldStylePool );
295 pNewStylePool->CopyTableStyles( *pOldStylePool );
296 sal_Int32 nPos = aOldLayoutName.indexOf( SD_LT_SEPARATOR );
297 if( nPos != -1 )
298 aOldLayoutName = aOldLayoutName.copy( 0, nPos );
299 StyleSheetCopyResultVector 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()) )
307 return;
309 SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PageKind::Standard );
311 if( 1 == mpSdDrawDocumentIntern->GetPageCount() )
313 // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
314 // fat lines correctly
315 maVisArea = mpSdViewIntern->GetAllMarkedBoundRect();
316 Point aOrigin( maVisArea.TopLeft() );
317 Size aVector( -aOrigin.X(), -aOrigin.Y() );
319 for( size_t nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; ++nObj )
321 SdrObject* pObj = pPage->GetObj( nObj );
322 pObj->NbcMove( aVector );
325 else
326 maVisArea.SetSize( pPage->GetSize() );
328 // output is at the zero point
329 maVisArea.SetPos( Point() );
332 static bool lcl_HasOnlyControls( SdrModel* pModel )
334 bool bOnlyControls = false; // default if there are no objects
336 if ( pModel )
338 SdrPage* pPage = pModel->GetPage(0);
339 if (pPage)
341 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
342 SdrObject* pObj = aIter.Next();
343 if ( pObj )
345 bOnlyControls = true; // only set if there are any objects at all
346 while ( pObj )
348 if (dynamic_cast< const SdrUnoObj *>( pObj ) == nullptr)
350 bOnlyControls = false;
351 break;
353 pObj = aIter.Next();
359 return bOnlyControls;
362 static bool lcl_HasOnlyOneTable( SdrModel* pModel )
364 if ( pModel )
366 SdrPage* pPage = pModel->GetPage(0);
367 if (pPage && pPage->GetObjCount() == 1 )
369 if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != nullptr )
370 return true;
373 return false;
376 void SdTransferable::AddSupportedFormats()
378 if( mbPageTransferable && !mbPageTransferablePersistent )
379 return;
381 if( !mbLateInit )
382 CreateData();
384 if( mpObjDesc )
385 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
387 if( mpOLEDataHelper )
389 AddFormat( SotClipboardFormatId::EMBED_SOURCE );
391 DataFlavorExVector aVector( mpOLEDataHelper->GetDataFlavorExVector() );
393 for( const auto& rItem : aVector )
394 AddFormat( rItem );
396 else if( moGraphic )
398 // #i25616#
399 AddFormat( SotClipboardFormatId::DRAWING );
401 AddFormat( SotClipboardFormatId::SVXB );
403 if( moGraphic->GetType() == GraphicType::Bitmap )
405 AddFormat( SotClipboardFormatId::PNG );
406 AddFormat( SotClipboardFormatId::BITMAP );
407 AddFormat( SotClipboardFormatId::GDIMETAFILE );
409 else
411 AddFormat( SotClipboardFormatId::GDIMETAFILE );
412 AddFormat( SotClipboardFormatId::PNG );
413 AddFormat( SotClipboardFormatId::BITMAP );
416 else if( moBookmark )
418 AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
419 AddFormat( SotClipboardFormatId::STRING );
421 else
423 AddFormat( SotClipboardFormatId::EMBED_SOURCE );
424 AddFormat( SotClipboardFormatId::DRAWING );
425 if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
427 AddFormat( SotClipboardFormatId::GDIMETAFILE );
428 AddFormat( SotClipboardFormatId::PNG );
429 AddFormat( SotClipboardFormatId::BITMAP );
432 if( lcl_HasOnlyOneTable( mpSdDrawDocument ) ) {
433 AddFormat( SotClipboardFormatId::RTF );
434 AddFormat( SotClipboardFormatId::RICHTEXT );
438 if( mpImageMap )
439 AddFormat( SotClipboardFormatId::SVIM );
442 bool SdTransferable::GetData( const DataFlavor& rFlavor, const OUString& rDestDoc )
444 if (SD_MOD()==nullptr)
445 return false;
447 SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
448 bool bOK = false;
450 CreateData();
452 if( nFormat == SotClipboardFormatId::RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
454 bOK = SetTableRTF( mpSdDrawDocument );
456 else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
458 // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
459 if( nFormat == SotClipboardFormatId::GDIMETAFILE && moGraphic )
460 bOK = SetGDIMetaFile( moGraphic->GetGDIMetaFile() );
461 else
462 bOK = SetAny( mpOLEDataHelper->GetAny(rFlavor, rDestDoc) );
464 else if( HasFormat( nFormat ) )
466 if( ( nFormat == SotClipboardFormatId::LINKSRCDESCRIPTOR || nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR ) && mpObjDesc )
468 bOK = SetTransferableObjectDescriptor( *mpObjDesc );
470 else if( nFormat == SotClipboardFormatId::DRAWING )
472 SfxObjectShellRef aOldRef( maDocShellRef );
474 maDocShellRef.clear();
476 if( mpSdViewIntern )
478 SdDrawDocument& rInternDoc = mpSdViewIntern->GetDoc();
479 rInternDoc.CreatingDataObj(this);
480 SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->CreateMarkedObjModel().release() );
481 rInternDoc.CreatingDataObj(nullptr);
483 bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
485 if( maDocShellRef.is() )
487 maDocShellRef->DoClose();
489 else
491 delete pDoc;
495 maDocShellRef = aOldRef;
497 else if( nFormat == SotClipboardFormatId::GDIMETAFILE )
499 if (mpSdViewIntern)
501 const bool bToggleOnlineSpell = mpSdDrawDocumentIntern && mpSdDrawDocumentIntern->GetOnlineSpell();
502 if (bToggleOnlineSpell)
503 mpSdDrawDocumentIntern->SetOnlineSpell(false);
504 bOK = SetGDIMetaFile( mpSdViewIntern->GetMarkedObjMetaFile( true ) );
505 if (bToggleOnlineSpell)
506 mpSdDrawDocumentIntern->SetOnlineSpell(true);
509 else if( SotClipboardFormatId::BITMAP == nFormat || SotClipboardFormatId::PNG == nFormat )
511 if (mpSdViewIntern)
513 const bool bToggleOnlineSpell = mpSdDrawDocumentIntern && mpSdDrawDocumentIntern->GetOnlineSpell();
514 if (bToggleOnlineSpell)
515 mpSdDrawDocumentIntern->SetOnlineSpell(false);
516 bOK = SetBitmapEx( mpSdViewIntern->GetMarkedObjBitmapEx(true), rFlavor );
517 if (bToggleOnlineSpell)
518 mpSdDrawDocumentIntern->SetOnlineSpell(true);
521 else if( ( nFormat == SotClipboardFormatId::STRING ) && moBookmark )
523 bOK = SetString( moBookmark->GetURL() );
525 else if( ( nFormat == SotClipboardFormatId::SVXB ) && moGraphic )
527 bOK = SetGraphic( *moGraphic );
529 else if( ( nFormat == SotClipboardFormatId::SVIM ) && mpImageMap )
531 bOK = SetImageMap( *mpImageMap );
533 else if( moBookmark )
535 bOK = SetINetBookmark( *moBookmark, rFlavor );
537 else if( nFormat == SotClipboardFormatId::EMBED_SOURCE )
539 if( mpSdDrawDocumentIntern )
541 if( !maDocShellRef.is() )
543 maDocShellRef = new ::sd::DrawDocShell(
544 mpSdDrawDocumentIntern,
545 SfxObjectCreateMode::EMBEDDED,
546 true,
547 mpSdDrawDocumentIntern->GetDocumentType());
548 mbOwnDocument = false;
549 maDocShellRef->DoInitNew();
552 maDocShellRef->SetVisArea( maVisArea );
553 bOK = SetObject( maDocShellRef.get(), SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
558 return bOK;
561 bool SdTransferable::WriteObject( tools::SvRef<SotTempStream>& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& )
563 bool bRet = false;
565 switch( nObjectType )
567 case SDTRANSFER_OBJECTTYPE_DRAWMODEL:
571 static const bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != nullptr );
572 SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(pObject);
573 if ( !bDontBurnInStyleSheet )
574 pDoc->BurnInStyleSheetAttributes();
575 rxOStm->SetBufferSize( 16348 );
577 Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, true ) );
578 pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
581 css::uno::Reference<css::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
582 SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DocumentType::Impress) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" );
585 xComponent->dispose();
586 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
588 catch( Exception& )
590 TOOLS_WARN_EXCEPTION( "sd", "sd::SdTransferable::WriteObject()" );
591 bRet = false;
594 break;
596 case SDTRANSFER_OBJECTTYPE_DRAWOLE:
598 SfxObjectShell* pEmbObj = static_cast<SfxObjectShell*>(pObject);
599 ::utl::TempFileFast aTempFile;
600 SvStream* pTempStream = aTempFile.GetStream(StreamMode::READWRITE);
604 uno::Reference< embed::XStorage > xWorkStore =
605 ::comphelper::OStorageHelper::GetStorageFromStream( new utl::OStreamWrapper(*pTempStream), embed::ElementModes::READWRITE );
607 // write document storage
608 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
609 // mba: no relative URLs for clipboard!
610 SfxMedium aMedium( xWorkStore, OUString() );
611 pEmbObj->DoSaveObjectAs( aMedium, false );
612 pEmbObj->DoSaveCompleted();
614 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
615 if ( xTransact.is() )
616 xTransact->commit();
618 rxOStm->SetBufferSize( 0xff00 );
619 rxOStm->WriteStream( *pTempStream );
621 bRet = true;
623 catch ( Exception& )
627 break;
629 default:
630 break;
633 return bRet;
636 void SdTransferable::DragFinished( sal_Int8 nDropAction )
638 if( mpSdView )
639 const_cast< ::sd::View* >(mpSdView)->DragFinished( nDropAction );
642 void SdTransferable::ObjectReleased()
644 SdModule *pModule = SD_MOD();
645 if (!pModule)
646 return;
648 if( this == pModule->pTransferClip )
649 pModule->pTransferClip = nullptr;
651 if( this == pModule->pTransferDrag )
652 pModule->pTransferDrag = nullptr;
654 if( this == pModule->pTransferSelection )
655 pModule->pTransferSelection = nullptr;
658 void SdTransferable::SetObjectDescriptor( std::unique_ptr<TransferableObjectDescriptor> pObjDesc )
660 mpObjDesc = std::move(pObjDesc);
661 PrepareOLE( *mpObjDesc );
664 void SdTransferable::SetPageBookmarks( std::vector<OUString> && rPageBookmarks, bool bPersistent )
666 if( !mpSourceDoc )
667 return;
669 if( mpSdViewIntern )
670 mpSdViewIntern->HideSdrPage();
672 mpSdDrawDocument->ClearModel(false);
674 mpPageDocShell = nullptr;
676 maPageBookmarks.clear();
678 if( bPersistent )
680 mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
681 mpSdDrawDocument->InsertBookmarkAsPage( rPageBookmarks, nullptr, false, true, 1, true,
682 mpSourceDoc->GetDocSh(), true, true, false );
684 else
686 mpPageDocShell = mpSourceDoc->GetDocSh();
687 maPageBookmarks = std::move(rPageBookmarks);
690 if( mpSdViewIntern )
692 SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PageKind::Standard );
694 if( pPage )
696 mpSdViewIntern->MarkAllObj( mpSdViewIntern->ShowSdrPage( pPage ) );
700 // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
701 // don't offer any formats => it's just for internal purposes
702 mbPageTransferable = true;
703 mbPageTransferablePersistent = bPersistent;
706 void SdTransferable::AddUserData (const std::shared_ptr<UserData>& rpData)
708 maUserData.push_back(rpData);
711 sal_Int32 SdTransferable::GetUserDataCount() const
713 return maUserData.size();
716 std::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const
718 if (nIndex>=0 && o3tl::make_unsigned(nIndex)<maUserData.size())
719 return maUserData[nIndex];
720 else
721 return std::shared_ptr<UserData>();
724 SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) noexcept
726 return dynamic_cast<SdTransferable*>(rxData.get());
729 void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
731 if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint)
733 const SdrHint* pSdrHint = static_cast< const SdrHint* >( &rHint );
734 if( SdrHintKind::ModelCleared == pSdrHint->GetKind() )
736 EndListening(*mpSourceDoc);
737 mpSourceDoc = nullptr;
740 else
742 if( rHint.GetId() == SfxHintId::Dying )
744 if( &rBC == mpSourceDoc )
745 mpSourceDoc = nullptr;
746 if( &rBC == mpSdViewIntern )
747 mpSdViewIntern = nullptr;
748 if( &rBC == mpSdView )
749 mpSdView = nullptr;
754 void SdTransferable::SetView(const ::sd::View* pView)
756 if (mpSdView)
757 EndListening(*const_cast<sd::View*>(mpSdView));
758 mpSdView = pView;
759 if (mpSdView)
760 StartListening(*const_cast<sd::View*>(mpSdView));
763 bool SdTransferable::SetTableRTF( SdDrawDocument* pModel )
765 if ( pModel )
767 SdrPage* pPage = pModel->GetPage(0);
768 if (pPage && pPage->GetObjCount() == 1 )
770 sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
771 if( pTableObj )
773 SvMemoryStream aMemStm( 65535, 65535 );
774 sdr::table::ExportAsRTF( aMemStm, *pTableObj );
775 return SetAny( Any( Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.TellEnd() ) ) );
780 return false;
783 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */