LCOV - code coverage report
Current view: top level - sd/source/ui/app - sdxfer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 380 0.0 %
Date: 2014-04-14 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      44             : 
      45             : #include <com/sun/star/form/FormButtonType.hpp>
      46             : #include <com/sun/star/beans/XPropertySet.hpp>
      47             : #include <unotools/streamwrap.hxx>
      48             : 
      49             : #include <svx/svdotable.hxx>
      50             : #include <svx/unomodel.hxx>
      51             : #include <svx/svditer.hxx>
      52             : #include <sfx2/docfile.hxx>
      53             : #include <comphelper/storagehelper.hxx>
      54             : #include <comphelper/servicehelper.hxx>
      55             : #include <svtools/embedtransfer.hxx>
      56             : #include "DrawDocShell.hxx"
      57             : #include "View.hxx"
      58             : #include "sdpage.hxx"
      59             : #include "drawview.hxx"
      60             : #include "drawdoc.hxx"
      61             : #include "stlpool.hxx"
      62             : #include "strings.hrc"
      63             : #include "sdresid.hxx"
      64             : #include "imapinfo.hxx"
      65             : #include "sdxfer.hxx"
      66             : #include "unomodel.hxx"
      67             : #include <vcl/virdev.hxx>
      68             : 
      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;
      75             : 
      76             : #define SDTRANSFER_OBJECTTYPE_DRAWMODEL         0x00000001
      77             : #define SDTRANSFER_OBJECTTYPE_DRAWOLE           0x00000002
      78             : 
      79           0 : SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, sal_Bool bInitOnGetData )
      80             : :   mpPageDocShell( NULL )
      81             : ,   mpOLEDataHelper( NULL )
      82             : ,   mpObjDesc( NULL )
      83             : ,   mpSdView( pWorkView )
      84             : ,   mpSdViewIntern( pWorkView )
      85             : ,   mpSdDrawDocument( NULL )
      86             : ,   mpSdDrawDocumentIntern( NULL )
      87             : ,   mpSourceDoc( pSrcDoc )
      88             : ,   mpVDev( NULL )
      89             : ,   mpBookmark( NULL )
      90             : ,   mpGraphic( NULL )
      91             : ,   mpImageMap( NULL )
      92             : ,   mbInternalMove( sal_False )
      93             : ,   mbOwnDocument( sal_False )
      94             : ,   mbOwnView( sal_False )
      95             : ,   mbLateInit( bInitOnGetData )
      96             : ,   mbPageTransferable( sal_False )
      97             : ,   mbPageTransferablePersistent( sal_False )
      98             : ,   mbIsUnoObj( false )
      99           0 : ,   maUserData()
     100             : {
     101           0 :     if( mpSourceDoc )
     102           0 :         StartListening( *mpSourceDoc );
     103             : 
     104           0 :     if( pWorkView )
     105           0 :         StartListening( *pWorkView );
     106             : 
     107           0 :     if( !mbLateInit )
     108           0 :         CreateData();
     109           0 : }
     110             : 
     111           0 : SdTransferable::~SdTransferable()
     112             : {
     113           0 :     if( mpSourceDoc )
     114           0 :         EndListening( *mpSourceDoc );
     115             : 
     116           0 :     if( mpSdView )
     117           0 :         EndListening( *const_cast< sd::View *>( mpSdView) );
     118             : 
     119           0 :     SolarMutexGuard aSolarGuard;
     120             : 
     121           0 :     ObjectReleased();
     122             : 
     123           0 :     if( mbOwnView )
     124           0 :         delete mpSdViewIntern;
     125             : 
     126           0 :     delete mpOLEDataHelper;
     127             : 
     128           0 :     if( maDocShellRef.Is() )
     129             :     {
     130           0 :         SfxObjectShell* pObj = maDocShellRef;
     131           0 :         ::sd::DrawDocShell* pDocSh = static_cast< ::sd::DrawDocShell*>(pObj);
     132           0 :         pDocSh->DoClose();
     133             :     }
     134             : 
     135           0 :     maDocShellRef.Clear();
     136             : 
     137           0 :     if( mbOwnDocument )
     138           0 :         delete mpSdDrawDocumentIntern;
     139             : 
     140           0 :     delete mpGraphic;
     141           0 :     delete mpBookmark;
     142           0 :     delete mpImageMap;
     143             : 
     144           0 :     delete mpVDev;
     145           0 :     delete mpObjDesc;
     146             : 
     147           0 : }
     148             : 
     149           0 : void SdTransferable::CreateObjectReplacement( SdrObject* pObj )
     150             : {
     151           0 :     if( pObj )
     152             :     {
     153           0 :         delete mpOLEDataHelper, mpOLEDataHelper = NULL;
     154           0 :         delete mpGraphic, mpGraphic = NULL;
     155           0 :         delete mpBookmark, mpBookmark = NULL;
     156           0 :         delete mpImageMap, mpImageMap = NULL;
     157             : 
     158           0 :         if( pObj->ISA( SdrOle2Obj ) )
     159             :         {
     160             :             try
     161             :             {
     162           0 :                 uno::Reference < embed::XEmbeddedObject > xObj = static_cast< SdrOle2Obj* >( pObj )->GetObjRef();
     163           0 :                 uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
     164           0 :                 if( xObj.is() && xPersist.is() && xPersist->hasEntry() )
     165             :                 {
     166           0 :                     mpOLEDataHelper = new TransferableDataHelper( new SvEmbedTransferHelper( xObj, static_cast< SdrOle2Obj* >( pObj )->GetGraphic(), static_cast< SdrOle2Obj* >( pObj )->GetAspect() ) );
     167             : 
     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           0 :                     const Graphic* pObjGr = static_cast< SdrOle2Obj* >( pObj )->GetGraphic();
     171           0 :                     if ( pObjGr )
     172           0 :                         mpGraphic = new Graphic( *pObjGr );
     173           0 :                 }
     174             :             }
     175           0 :             catch( uno::Exception& )
     176             :             {}
     177             :         }
     178           0 :         else if( pObj->ISA( SdrGrafObj ) && (mpSourceDoc && !mpSourceDoc->GetAnimationInfo( pObj )) )
     179             :         {
     180           0 :             mpGraphic = new Graphic( static_cast< SdrGrafObj* >( pObj )->GetTransformedGraphic() );
     181             :         }
     182           0 :         else if( pObj->IsUnoObj() && FmFormInventor == pObj->GetObjInventor() && ( pObj->GetObjIdentifier() == (sal_uInt16) OBJ_FM_BUTTON ) )
     183             :         {
     184           0 :             SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( pObj );
     185             : 
     186           0 :             if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
     187             :             {
     188           0 :                 Reference< ::com::sun::star::awt::XControlModel > xControlModel( pUnoCtrl->GetUnoControlModel() );
     189             : 
     190           0 :                 if( !xControlModel.is() )
     191           0 :                     return;
     192             : 
     193           0 :                 Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xControlModel, UNO_QUERY );
     194             : 
     195           0 :                 if( !xPropSet.is() )
     196           0 :                     return;
     197             : 
     198             :                 ::com::sun::star::form::FormButtonType  eButtonType;
     199           0 :                 Any                                     aTmp( xPropSet->getPropertyValue( "ButtonType" ) );
     200             : 
     201           0 :                 if( aTmp >>= eButtonType )
     202             :                 {
     203           0 :                     OUString aLabel, aURL;
     204             : 
     205           0 :                     xPropSet->getPropertyValue( "Label" ) >>= aLabel;
     206           0 :                     xPropSet->getPropertyValue( "TargetURL" ) >>= aURL;
     207             : 
     208           0 :                     mpBookmark = new INetBookmark( aURL, aLabel );
     209           0 :                 }
     210             :             }
     211             :         }
     212           0 :         else if( pObj->ISA( SdrTextObj ) )
     213             :         {
     214             :             const OutlinerParaObject* pPara;
     215             : 
     216           0 :             if( (pPara = static_cast< SdrTextObj* >( pObj )->GetOutlinerParaObject()) != 0 )
     217             :             {
     218             :                 const SvxFieldItem* pField;
     219             : 
     220           0 :                 if( (pField = pPara->GetTextObject().GetField()) != 0 )
     221             :                 {
     222           0 :                     const SvxFieldData* pData = pField->GetField();
     223             : 
     224           0 :                     if( pData && pData->ISA( SvxURLField ) )
     225             :                     {
     226           0 :                         const SvxURLField* pURL = (SvxURLField*) pData;
     227             : 
     228           0 :                         mpBookmark = new INetBookmark( pURL->GetURL(), pURL->GetRepresentation() );
     229             :                     }
     230             :                 }
     231             :             }
     232             :         }
     233             : 
     234           0 :         SdIMapInfo* pInfo = static_cast< SdDrawDocument* >( pObj->GetModel() )->GetIMapInfo( static_cast< SdrObject* >( pObj ) );
     235             : 
     236           0 :         if( pInfo )
     237           0 :             mpImageMap = new ImageMap( pInfo->GetImageMap() );
     238             : 
     239           0 :         mbIsUnoObj = pObj && pObj->IsUnoObj();
     240             :     }
     241             : }
     242             : 
     243           0 : void SdTransferable::CreateData()
     244             : {
     245           0 :     if( mpSdDrawDocument && !mpSdViewIntern )
     246             :     {
     247           0 :         mbOwnView = sal_True;
     248             : 
     249           0 :         SdPage* pPage = mpSdDrawDocument->GetSdPage(0, PK_STANDARD);
     250             : 
     251           0 :         if( 1 == pPage->GetObjCount() )
     252           0 :             CreateObjectReplacement( pPage->GetObj( 0 ) );
     253             : 
     254           0 :         mpVDev = new VirtualDevice( *Application::GetDefaultDevice() );
     255           0 :         mpVDev->SetMapMode( MapMode( mpSdDrawDocumentIntern->GetScaleUnit(), Point(), mpSdDrawDocumentIntern->GetScaleFraction(), mpSdDrawDocumentIntern->GetScaleFraction() ) );
     256           0 :         mpSdViewIntern = new ::sd::View( *mpSdDrawDocumentIntern, mpVDev );
     257           0 :         mpSdViewIntern->EndListening(*mpSdDrawDocumentIntern );
     258           0 :         mpSdViewIntern->hideMarkHandles();
     259           0 :         SdrPageView* pPageView = mpSdViewIntern->ShowSdrPage(pPage);
     260           0 :         ((SdrMarkView*)mpSdViewIntern)->MarkAllObj(pPageView);
     261             :     }
     262           0 :     else if( mpSdView && !mpSdDrawDocumentIntern )
     263             :     {
     264           0 :         const SdrMarkList& rMarkList = mpSdView->GetMarkedObjectList();
     265             : 
     266           0 :         if( rMarkList.GetMarkCount() == 1 )
     267           0 :             CreateObjectReplacement( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
     268             : 
     269           0 :         if( mpSourceDoc )
     270           0 :             mpSourceDoc->CreatingDataObj(this);
     271           0 :         mpSdDrawDocumentIntern = (SdDrawDocument*) mpSdView->GetMarkedObjModel();
     272           0 :         if( mpSourceDoc )
     273           0 :             mpSourceDoc->CreatingDataObj(0);
     274             : 
     275           0 :         if( !maDocShellRef.Is() && mpSdDrawDocumentIntern->GetDocSh() )
     276           0 :             maDocShellRef = mpSdDrawDocumentIntern->GetDocSh();
     277             : 
     278           0 :         if( !maDocShellRef.Is() )
     279             :         {
     280             :             OSL_FAIL( "SdTransferable::CreateData(), failed to create a model with persist, clipboard operation will fail for OLE objects!" );
     281           0 :             mbOwnDocument = sal_True;
     282             :         }
     283             : 
     284             :         // Use dimension of source page
     285           0 :         SdrPageView*        pPgView = mpSdView->GetSdrPageView();
     286           0 :         SdPage*             pOldPage = (SdPage*) pPgView->GetPage();
     287           0 :         SdrModel*           pOldModel = mpSdView->GetModel();
     288           0 :         SdStyleSheetPool*   pOldStylePool = (SdStyleSheetPool*) pOldModel->GetStyleSheetPool();
     289           0 :         SdStyleSheetPool*   pNewStylePool = (SdStyleSheetPool*) mpSdDrawDocumentIntern->GetStyleSheetPool();
     290           0 :         SdPage*             pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
     291           0 :         OUString            aOldLayoutName( pOldPage->GetLayoutName() );
     292             : 
     293           0 :         pPage->SetSize( pOldPage->GetSize() );
     294           0 :         pPage->SetLayoutName( aOldLayoutName );
     295           0 :         pNewStylePool->CopyGraphicSheets( *pOldStylePool );
     296           0 :         pNewStylePool->CopyCellSheets( *pOldStylePool );
     297           0 :         pNewStylePool->CopyTableStyles( *pOldStylePool );
     298           0 :         sal_Int32 nPos = aOldLayoutName.indexOf( SD_LT_SEPARATOR );
     299           0 :         if( nPos != -1 )
     300           0 :             aOldLayoutName = aOldLayoutName.copy( 0, nPos );
     301           0 :         SdStyleSheetVector aCreatedSheets;
     302           0 :         pNewStylePool->CopyLayoutSheets( aOldLayoutName, *pOldStylePool, aCreatedSheets );
     303             :     }
     304             : 
     305             :     // set VisArea and adjust objects if necessary
     306           0 :     if( maVisArea.IsEmpty() &&
     307           0 :         mpSdDrawDocumentIntern && mpSdViewIntern &&
     308           0 :         mpSdDrawDocumentIntern->GetPageCount() )
     309             :     {
     310           0 :         SdPage* pPage = mpSdDrawDocumentIntern->GetSdPage( 0, PK_STANDARD );
     311             : 
     312           0 :         if( 1 == mpSdDrawDocumentIntern->GetPageCount() )
     313             :         {
     314             :             // #112978# need to use GetAllMarkedBoundRect instead of GetAllMarkedRect to get
     315             :             // fat lines correctly
     316           0 :             Point   aOrigin( ( maVisArea = mpSdViewIntern->GetAllMarkedBoundRect() ).TopLeft() );
     317           0 :             Size    aVector( -aOrigin.X(), -aOrigin.Y() );
     318             : 
     319           0 :             for( sal_uLong nObj = 0, nObjCount = pPage->GetObjCount(); nObj < nObjCount; nObj++ )
     320             :             {
     321           0 :                 SdrObject* pObj = pPage->GetObj( nObj );
     322           0 :                 pObj->NbcMove( aVector );
     323             :             }
     324             :         }
     325             :         else
     326           0 :             maVisArea.SetSize( pPage->GetSize() );
     327             : 
     328             :         // output is at the zero point
     329           0 :         maVisArea.SetPos( Point() );
     330             :     }
     331           0 : }
     332             : 
     333           0 : static sal_Bool lcl_HasOnlyControls( SdrModel* pModel )
     334             : {
     335           0 :     sal_Bool bOnlyControls = sal_False;         // default if there are no objects
     336             : 
     337           0 :     if ( pModel )
     338             :     {
     339           0 :         SdrPage* pPage = pModel->GetPage(0);
     340           0 :         if (pPage)
     341             :         {
     342           0 :             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
     343           0 :             SdrObject* pObj = aIter.Next();
     344           0 :             if ( pObj )
     345             :             {
     346           0 :                 bOnlyControls = sal_True;   // only set if there are any objects at all
     347           0 :                 while ( pObj )
     348             :                 {
     349           0 :                     if (!pObj->ISA(SdrUnoObj))
     350             :                     {
     351           0 :                         bOnlyControls = sal_False;
     352           0 :                         break;
     353             :                     }
     354           0 :                     pObj = aIter.Next();
     355             :                 }
     356           0 :             }
     357             :         }
     358             :     }
     359             : 
     360           0 :     return bOnlyControls;
     361             : }
     362             : 
     363           0 : static bool lcl_HasOnlyOneTable( SdrModel* pModel )
     364             : {
     365           0 :     if ( pModel )
     366             :     {
     367           0 :         SdrPage* pPage = pModel->GetPage(0);
     368           0 :         if (pPage && pPage->GetObjCount() == 1 )
     369             :         {
     370           0 :             if( dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) ) != 0 )
     371           0 :                 return true;
     372             :         }
     373             :     }
     374           0 :     return false;
     375             : }
     376             : 
     377           0 : void SdTransferable::AddSupportedFormats()
     378             : {
     379           0 :     if( !mbPageTransferable || mbPageTransferablePersistent )
     380             :     {
     381           0 :         if( !mbLateInit )
     382           0 :             CreateData();
     383             : 
     384           0 :         if( mpObjDesc )
     385           0 :             AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
     386             : 
     387           0 :         if( mpOLEDataHelper )
     388             :         {
     389           0 :             AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
     390             : 
     391           0 :             DataFlavorExVector              aVector( mpOLEDataHelper->GetDataFlavorExVector() );
     392           0 :             DataFlavorExVector::iterator    aIter( aVector.begin() ), aEnd( aVector.end() );
     393             : 
     394           0 :             while( aIter != aEnd )
     395           0 :                 AddFormat( *aIter++ );
     396             :         }
     397           0 :         else if( mpGraphic )
     398             :         {
     399             :             // #i25616#
     400           0 :             AddFormat( SOT_FORMATSTR_ID_DRAWING );
     401             : 
     402           0 :             AddFormat( SOT_FORMATSTR_ID_SVXB );
     403             : 
     404           0 :             if( mpGraphic->GetType() == GRAPHIC_BITMAP )
     405             :             {
     406           0 :                 AddFormat( SOT_FORMATSTR_ID_PNG );
     407           0 :                 AddFormat( SOT_FORMAT_BITMAP );
     408           0 :                 AddFormat( SOT_FORMAT_GDIMETAFILE );
     409             :             }
     410             :             else
     411             :             {
     412           0 :                 AddFormat( SOT_FORMAT_GDIMETAFILE );
     413           0 :                 AddFormat( SOT_FORMATSTR_ID_PNG );
     414           0 :                 AddFormat( SOT_FORMAT_BITMAP );
     415             :             }
     416             :         }
     417           0 :         else if( mpBookmark )
     418             :         {
     419           0 :             AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
     420           0 :             AddFormat( FORMAT_STRING );
     421             :         }
     422             :         else
     423             :         {
     424           0 :             AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
     425           0 :             AddFormat( SOT_FORMATSTR_ID_DRAWING );
     426           0 :             if( !mpSdDrawDocument || !lcl_HasOnlyControls( mpSdDrawDocument ) )
     427             :             {
     428           0 :                 AddFormat( SOT_FORMAT_GDIMETAFILE );
     429           0 :                 AddFormat( SOT_FORMATSTR_ID_PNG );
     430           0 :                 AddFormat( SOT_FORMAT_BITMAP );
     431             :             }
     432             : 
     433           0 :             if( lcl_HasOnlyOneTable( mpSdDrawDocument ) )
     434           0 :                 AddFormat( SOT_FORMAT_RTF );
     435             :         }
     436             : 
     437           0 :         if( mpImageMap )
     438           0 :             AddFormat( SOT_FORMATSTR_ID_SVIM );
     439             :     }
     440           0 : }
     441             : 
     442           0 : bool SdTransferable::GetData( const DataFlavor& rFlavor )
     443             : {
     444           0 :     if (SD_MOD()==NULL)
     445           0 :         return false;
     446             : 
     447           0 :     sal_uInt32  nFormat = SotExchange::GetFormat( rFlavor );
     448           0 :     bool        bOK = false;
     449             : 
     450           0 :     CreateData();
     451             : 
     452           0 :     if( nFormat == SOT_FORMAT_RTF && lcl_HasOnlyOneTable( mpSdDrawDocument ) )
     453             :     {
     454           0 :         bOK = SetTableRTF( mpSdDrawDocument, rFlavor );
     455             :     }
     456           0 :     else if( mpOLEDataHelper && mpOLEDataHelper->HasFormat( rFlavor ) )
     457             :     {
     458           0 :         sal_uLong nOldSwapMode = 0;
     459             : 
     460           0 :         if( mpSdDrawDocumentIntern )
     461             :         {
     462           0 :             nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
     463           0 :             mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
     464             :         }
     465             : 
     466             :         // TODO/LATER: support all the graphical formats, the embedded object scenario should not have separated handling
     467           0 :         if( nFormat == FORMAT_GDIMETAFILE && mpGraphic )
     468           0 :             bOK = SetGDIMetaFile( mpGraphic->GetGDIMetaFile(), rFlavor );
     469             :         else
     470           0 :             bOK = SetAny( mpOLEDataHelper->GetAny( rFlavor ), rFlavor );
     471             : 
     472           0 :         if( mpSdDrawDocumentIntern )
     473           0 :             mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
     474             :     }
     475           0 :     else if( HasFormat( nFormat ) )
     476             :     {
     477           0 :         if( ( nFormat == SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR || nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) && mpObjDesc )
     478             :         {
     479           0 :             bOK = SetTransferableObjectDescriptor( *mpObjDesc, rFlavor );
     480             :         }
     481           0 :         else if( nFormat == SOT_FORMATSTR_ID_DRAWING )
     482             :         {
     483           0 :             SfxObjectShellRef aOldRef( maDocShellRef );
     484             : 
     485           0 :             maDocShellRef.Clear();
     486             : 
     487           0 :             if( mpSdViewIntern )
     488             :             {
     489           0 :                 SdDrawDocument& rInternDoc = mpSdViewIntern->GetDoc();
     490           0 :                 rInternDoc.CreatingDataObj(this);
     491           0 :                 SdDrawDocument* pDoc = dynamic_cast< SdDrawDocument* >( mpSdViewIntern->GetMarkedObjModel() );
     492           0 :                 rInternDoc.CreatingDataObj(0);
     493             : 
     494           0 :                 bOK = SetObject( pDoc, SDTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
     495             : 
     496           0 :                 if( maDocShellRef.Is() )
     497             :                 {
     498           0 :                     maDocShellRef->DoClose();
     499             :                 }
     500             :                 else
     501             :                 {
     502           0 :                     delete pDoc;
     503             :                 }
     504             :             }
     505             : 
     506           0 :             maDocShellRef = aOldRef;
     507             :         }
     508           0 :         else if( nFormat == FORMAT_GDIMETAFILE )
     509             :         {
     510           0 :             if( mpSdViewIntern )
     511           0 :                 bOK = SetGDIMetaFile( mpSdViewIntern->GetMarkedObjMetaFile( true ), rFlavor );
     512             :         }
     513           0 :         else if( FORMAT_BITMAP == nFormat || SOT_FORMATSTR_ID_PNG == nFormat )
     514             :         {
     515           0 :             if( mpSdViewIntern )
     516           0 :                 bOK = SetBitmapEx( mpSdViewIntern->GetMarkedObjBitmapEx(true), rFlavor );
     517             :         }
     518           0 :         else if( ( nFormat == FORMAT_STRING ) && mpBookmark )
     519             :         {
     520           0 :             bOK = SetString( mpBookmark->GetURL(), rFlavor );
     521             :         }
     522           0 :         else if( ( nFormat == SOT_FORMATSTR_ID_SVXB ) && mpGraphic )
     523             :         {
     524           0 :             bOK = SetGraphic( *mpGraphic, rFlavor );
     525             :         }
     526           0 :         else if( ( nFormat == SOT_FORMATSTR_ID_SVIM ) && mpImageMap )
     527             :         {
     528           0 :             bOK = SetImageMap( *mpImageMap, rFlavor );
     529             :         }
     530           0 :         else if( mpBookmark )
     531             :         {
     532           0 :             bOK = SetINetBookmark( *mpBookmark, rFlavor );
     533             :         }
     534           0 :         else if( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
     535             :         {
     536           0 :             sal_uLong nOldSwapMode = 0;
     537             : 
     538           0 :             if( mpSdDrawDocumentIntern )
     539             :             {
     540           0 :                 nOldSwapMode = mpSdDrawDocumentIntern->GetSwapGraphicsMode();
     541           0 :                 mpSdDrawDocumentIntern->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_PURGE );
     542             : 
     543           0 :                 if( !maDocShellRef.Is() )
     544             :                 {
     545           0 :                     maDocShellRef = new ::sd::DrawDocShell(
     546             :                         mpSdDrawDocumentIntern,
     547             :                         SFX_CREATE_MODE_EMBEDDED,
     548             :                         sal_True,
     549           0 :                         mpSdDrawDocumentIntern->GetDocumentType());
     550           0 :                     mbOwnDocument = sal_False;
     551           0 :                     maDocShellRef->DoInitNew( NULL );
     552             :                 }
     553             : 
     554           0 :                 maDocShellRef->SetVisArea( maVisArea );
     555           0 :                 bOK = SetObject( &maDocShellRef, SDTRANSFER_OBJECTTYPE_DRAWOLE, rFlavor );
     556             : 
     557           0 :                 mpSdDrawDocumentIntern->SetSwapGraphicsMode( nOldSwapMode );
     558             :             }
     559             :         }
     560             :     }
     561             : 
     562           0 :     return bOK;
     563             : }
     564             : 
     565           0 : bool SdTransferable::WriteObject( SotStorageStreamRef& rxOStm, void* pObject, sal_uInt32 nObjectType, const DataFlavor& )
     566             : {
     567           0 :     bool bRet = false;
     568             : 
     569           0 :     switch( nObjectType )
     570             :     {
     571             :         case( SDTRANSFER_OBJECTTYPE_DRAWMODEL ):
     572             :         {
     573             :             try
     574             :             {
     575           0 :                 static const sal_Bool bDontBurnInStyleSheet = ( getenv( "AVOID_BURN_IN_FOR_GALLERY_THEME" ) != NULL );
     576           0 :                 SdDrawDocument* pDoc = (SdDrawDocument*) pObject;
     577           0 :                 if ( !bDontBurnInStyleSheet )
     578           0 :                     pDoc->BurnInStyleSheetAttributes();
     579           0 :                 rxOStm->SetBufferSize( 16348 );
     580             : 
     581           0 :                 Reference< XComponent > xComponent( new SdXImpressDocument( pDoc, true ) );
     582           0 :                 pDoc->setUnoModel( Reference< XInterface >::query( xComponent ) );
     583             : 
     584             :                 {
     585           0 :                     com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
     586           0 :                     if( SvxDrawingLayerExport( pDoc, xDocOut, xComponent, (pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) ? "com.sun.star.comp.Impress.XMLClipboardExporter" : "com.sun.star.comp.DrawingLayer.XMLExporter" ) )
     587           0 :                         rxOStm->Commit();
     588             :                 }
     589             : 
     590           0 :                 xComponent->dispose();
     591           0 :                 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
     592             :             }
     593           0 :             catch( Exception& )
     594             :             {
     595             :                 OSL_FAIL( "sd::SdTransferable::WriteObject(), exception catched!" );
     596           0 :                 bRet = false;
     597             :             }
     598             :         }
     599           0 :         break;
     600             : 
     601             :         case( SDTRANSFER_OBJECTTYPE_DRAWOLE ):
     602             :         {
     603           0 :             SfxObjectShell*   pEmbObj = (SfxObjectShell*) pObject;
     604           0 :             ::utl::TempFile     aTempFile;
     605           0 :             aTempFile.EnableKillingFile();
     606             : 
     607             :             try
     608             :             {
     609             :                 uno::Reference< embed::XStorage > xWorkStore =
     610           0 :                     ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
     611             : 
     612             :                 // write document storage
     613           0 :                 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false );
     614             :                 // mba: no relative ULRs for clipboard!
     615           0 :                 SfxMedium aMedium( xWorkStore, OUString() );
     616           0 :                 bRet = pEmbObj->DoSaveObjectAs( aMedium, false );
     617           0 :                 pEmbObj->DoSaveCompleted();
     618             : 
     619           0 :                 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
     620           0 :                 if ( xTransact.is() )
     621           0 :                     xTransact->commit();
     622             : 
     623           0 :                 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
     624           0 :                 if( pSrcStm )
     625             :                 {
     626           0 :                     rxOStm->SetBufferSize( 0xff00 );
     627           0 :                     rxOStm->WriteStream( *pSrcStm );
     628           0 :                     delete pSrcStm;
     629             :                 }
     630             : 
     631           0 :                 bRet = true;
     632           0 :                 rxOStm->Commit();
     633             :             }
     634           0 :             catch ( Exception& )
     635           0 :             {}
     636             :         }
     637             : 
     638           0 :         break;
     639             : 
     640             :         default:
     641           0 :         break;
     642             :     }
     643             : 
     644           0 :     return bRet;
     645             : }
     646             : 
     647           0 : void SdTransferable::DragFinished( sal_Int8 nDropAction )
     648             : {
     649           0 :     if( mpSdView )
     650           0 :         ( (::sd::View*) mpSdView )->DragFinished( nDropAction );
     651           0 : }
     652             : 
     653           0 : void SdTransferable::ObjectReleased()
     654             : {
     655           0 :     if( this == SD_MOD()->pTransferClip )
     656           0 :         SD_MOD()->pTransferClip = NULL;
     657             : 
     658           0 :     if( this == SD_MOD()->pTransferDrag )
     659           0 :         SD_MOD()->pTransferDrag = NULL;
     660             : 
     661           0 :     if( this == SD_MOD()->pTransferSelection )
     662           0 :         SD_MOD()->pTransferSelection = NULL;
     663           0 : }
     664             : 
     665           0 : void SdTransferable::SetObjectDescriptor( const TransferableObjectDescriptor& rObjDesc )
     666             : {
     667           0 :     delete mpObjDesc;
     668           0 :     mpObjDesc = new TransferableObjectDescriptor( rObjDesc );
     669           0 :     PrepareOLE( rObjDesc );
     670           0 : }
     671             : 
     672           0 : void SdTransferable::SetPageBookmarks( const std::vector<OUString> &rPageBookmarks, sal_Bool bPersistent )
     673             : {
     674           0 :     if( mpSourceDoc )
     675             :     {
     676           0 :         if( mpSdViewIntern )
     677           0 :             mpSdViewIntern->HideSdrPage();
     678             : 
     679           0 :         mpSdDrawDocument->ClearModel(false);
     680             : 
     681           0 :         mpPageDocShell = NULL;
     682             : 
     683           0 :         maPageBookmarks.clear();
     684             : 
     685           0 :         if( bPersistent )
     686             :         {
     687           0 :             mpSdDrawDocument->CreateFirstPages(mpSourceDoc);
     688             :             mpSdDrawDocument->InsertBookmarkAsPage( rPageBookmarks, NULL, sal_False, sal_True, 1, sal_True,
     689           0 :                                                     mpSourceDoc->GetDocSh(), sal_True, sal_True, sal_False );
     690             :         }
     691             :         else
     692             :         {
     693           0 :             mpPageDocShell = mpSourceDoc->GetDocSh();
     694           0 :             maPageBookmarks = rPageBookmarks;
     695             :         }
     696             : 
     697           0 :         if( mpSdViewIntern )
     698             :         {
     699           0 :             SdPage* pPage = mpSdDrawDocument->GetSdPage( 0, PK_STANDARD );
     700             : 
     701           0 :             if( pPage )
     702             :             {
     703           0 :                 ( (SdrMarkView*) mpSdViewIntern )->MarkAllObj( (SdrPageView*) mpSdViewIntern->ShowSdrPage( pPage ) );
     704             :             }
     705             :         }
     706             : 
     707             :         // set flags for page transferable; if ( mbPageTransferablePersistent == sal_False ),
     708             :         // don't offer any formats => it's just for internal puposes
     709           0 :         mbPageTransferable = sal_True;
     710           0 :         mbPageTransferablePersistent = bPersistent;
     711             :     }
     712           0 : }
     713             : 
     714           0 : sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
     715             : {
     716             :     sal_Int64 nRet;
     717             : 
     718           0 :     if( ( rId.getLength() == 16 ) &&
     719           0 :         ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
     720             :     {
     721           0 :         nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
     722             :     }
     723             :     else
     724             :     {
     725           0 :         nRet = 0;
     726             :     }
     727             : 
     728           0 :     return nRet;
     729             : }
     730             : 
     731             : 
     732           0 : SdDrawDocument* SdTransferable::GetSourceDoc (void) const
     733             : {
     734           0 :     return mpSourceDoc;
     735             : }
     736             : 
     737           0 : void SdTransferable::AddUserData (const ::boost::shared_ptr<UserData>& rpData)
     738             : {
     739           0 :     maUserData.push_back(rpData);
     740           0 : }
     741             : 
     742           0 : sal_Int32 SdTransferable::GetUserDataCount (void) const
     743             : {
     744           0 :     return maUserData.size();
     745             : }
     746             : 
     747           0 : ::boost::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const
     748             : {
     749           0 :     if (nIndex>=0 && nIndex<sal_Int32(maUserData.size()))
     750           0 :         return maUserData[nIndex];
     751             :     else
     752           0 :         return ::boost::shared_ptr<UserData>();
     753             : }
     754             : 
     755             : namespace
     756             : {
     757             :     class theSdTransferableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSdTransferableUnoTunnelId > {};
     758             : }
     759             : 
     760           0 : const ::com::sun::star::uno::Sequence< sal_Int8 >& SdTransferable::getUnoTunnelId()
     761             : {
     762           0 :     return theSdTransferableUnoTunnelId::get().getSeq();
     763             : }
     764             : 
     765           0 : SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >& rxData ) throw()
     766             : {
     767             :     try
     768             :     {
     769           0 :         Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
     770           0 :         return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
     771             :     }
     772           0 :     catch( const ::com::sun::star::uno::Exception& )
     773             :     {
     774             :     }
     775           0 :     return NULL;
     776             : }
     777             : 
     778           0 : void SdTransferable::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     779             : {
     780           0 :     const SdrHint* pSdrHint = dynamic_cast< const SdrHint* >( &rHint );
     781           0 :     if( pSdrHint )
     782             :     {
     783           0 :         if( HINT_MODELCLEARED == pSdrHint->GetKind() )
     784             :         {
     785           0 :             EndListening(*mpSourceDoc);
     786           0 :             mpSourceDoc = 0;
     787             :         }
     788             :     }
     789             :     else
     790             :     {
     791           0 :         const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint * >(&rHint);
     792           0 :         if(pSimpleHint && (pSimpleHint->GetId() == SFX_HINT_DYING) )
     793             :         {
     794           0 :             if( &rBC == mpSourceDoc )
     795           0 :                 mpSourceDoc = 0;
     796           0 :             if( &rBC == mpSdViewIntern )
     797           0 :                 mpSdViewIntern = 0;
     798           0 :             if( &rBC == mpSdView )
     799           0 :                 mpSdView = 0;
     800             :         }
     801             :     }
     802           0 : }
     803             : 
     804           0 : sal_Bool SdTransferable::SetTableRTF( SdDrawDocument* pModel, const DataFlavor& rFlavor)
     805             : {
     806           0 :     if ( pModel )
     807             :     {
     808           0 :         SdrPage* pPage = pModel->GetPage(0);
     809           0 :         if (pPage && pPage->GetObjCount() == 1 )
     810             :         {
     811           0 :             sdr::table::SdrTableObj* pTableObj = dynamic_cast< sdr::table::SdrTableObj* >( pPage->GetObj(0) );
     812           0 :             if( pTableObj )
     813             :             {
     814           0 :                 SvMemoryStream aMemStm( 65535, 65535 );
     815           0 :                 sdr::table::SdrTableObj::ExportAsRTF( aMemStm, *pTableObj );
     816           0 :                 return SetAny( Any( Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ) ), rFlavor );
     817             :             }
     818             :         }
     819             :     }
     820             : 
     821           0 :     return sal_False;
     822             : }
     823             : 
     824             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10