LCOV - code coverage report
Current view: top level - sc/source/ui/app - drwtrans.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 367 1.1 %
Date: 2015-06-13 12:38:46 Functions: 3 24 12.5 %
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/uno/Exception.hpp>
      23             : 
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      26             : #include <com/sun/star/form/FormButtonType.hpp>
      27             : #include <toolkit/helper/vclunohelper.hxx>
      28             : #include <unotools/streamwrap.hxx>
      29             : 
      30             : #include <svx/unomodel.hxx>
      31             : #include <unotools/tempfile.hxx>
      32             : #include <unotools/ucbstreamhelper.hxx>
      33             : #include <comphelper/storagehelper.hxx>
      34             : #include <comphelper/servicehelper.hxx>
      35             : 
      36             : #include <svtools/embedtransfer.hxx>
      37             : #include <sot/storage.hxx>
      38             : #include <vcl/virdev.hxx>
      39             : #include <svx/fmglob.hxx>
      40             : #include <svx/svditer.hxx>
      41             : #include <svx/svdograf.hxx>
      42             : #include <svx/svdoole2.hxx>
      43             : #include <svx/svdouno.hxx>
      44             : #include <svx/svdpage.hxx>
      45             : #include <svx/svdxcgv.hxx>
      46             : #include <sfx2/docfile.hxx>
      47             : #include <svl/itempool.hxx>
      48             : #include <svl/urlbmk.hxx>
      49             : #include <tools/urlobj.hxx>
      50             : #include <osl/mutex.hxx>
      51             : 
      52             : #include "drwtrans.hxx"
      53             : #include "docsh.hxx"
      54             : #include "drwlayer.hxx"
      55             : #include "drawview.hxx"
      56             : #include "viewdata.hxx"
      57             : #include "scmod.hxx"
      58             : #include "chartlis.hxx"
      59             : #include "rangeutl.hxx"
      60             : #include <formula/grammar.hxx>
      61             : #include "dragdata.hxx"
      62             : #include "clipdata.hxx"
      63             : 
      64             : // #108584#
      65             : #include "scitems.hxx"
      66             : 
      67             : // #108584#
      68             : #include <editeng/eeitem.hxx>
      69             : 
      70             : // #108584#
      71             : #include <editeng/fhgtitem.hxx>
      72             : #include <vcl/svapp.hxx>
      73             : 
      74             : using namespace com::sun::star;
      75             : 
      76             : #define SCDRAWTRANS_TYPE_EMBOBJ         SotClipboardFormatId::STRING
      77             : #define SCDRAWTRANS_TYPE_DRAWMODEL      SotClipboardFormatId::BITMAP
      78             : #define SCDRAWTRANS_TYPE_DOCUMENT       SotClipboardFormatId::GDIMETAFILE
      79             : 
      80           0 : ScDrawTransferObj::ScDrawTransferObj( SdrModel* pClipModel, ScDocShell* pContainerShell,
      81             :                                         const TransferableObjectDescriptor& rDesc ) :
      82             :     pModel( pClipModel ),
      83             :     aObjDesc( rDesc ),
      84             :     pBookmark( NULL ),
      85             :     bGraphic( false ),
      86             :     bGrIsBit( false ),
      87             :     bOleObj( false ),
      88             :     pDragSourceView( NULL ),
      89             :     nDragSourceFlags( 0 ),
      90             :     bDragWasInternal( false ),
      91             :     nSourceDocID( 0 ),
      92           0 :     maShellID(SfxObjectShell::CreateShellID(pContainerShell))
      93             : {
      94             : 
      95             :     //  check what kind of objects are contained
      96             : 
      97           0 :     SdrPage* pPage = pModel->GetPage(0);
      98           0 :     if (pPage)
      99             :     {
     100           0 :         SdrObjListIter aIter( *pPage, IM_FLAT );
     101           0 :         SdrObject* pObject = aIter.Next();
     102           0 :         if (pObject && !aIter.Next())               // exactly one object?
     103             :         {
     104             : 
     105             :             //  OLE object
     106             : 
     107           0 :             sal_uInt16 nSdrObjKind = pObject->GetObjIdentifier();
     108           0 :             if (nSdrObjKind == OBJ_OLE2)
     109             :             {
     110             :                 // if object has no persistence it must be copied as a part of document
     111             :                 try
     112             :                 {
     113           0 :                     uno::Reference< embed::XEmbedPersist > xPersObj( static_cast<SdrOle2Obj*>(pObject)->GetObjRef(), uno::UNO_QUERY );
     114           0 :                     if ( xPersObj.is() && xPersObj->hasEntry() )
     115           0 :                         bOleObj = true;
     116             :                 }
     117           0 :                 catch( uno::Exception& )
     118             :                 {}
     119             :                 // aOleData is initialized later
     120             :             }
     121             : 
     122             :             //  Graphic object
     123             : 
     124           0 :             if (nSdrObjKind == OBJ_GRAF)
     125             :             {
     126           0 :                 bGraphic = true;
     127           0 :                 if ( static_cast<SdrGrafObj*>(pObject)->GetGraphic().GetType() == GRAPHIC_BITMAP )
     128           0 :                     bGrIsBit = true;
     129             :             }
     130             : 
     131             :             //  URL button
     132             : 
     133           0 :             SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, pObject);
     134           0 :             if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
     135             :             {
     136           0 :                 uno::Reference<awt::XControlModel> xControlModel = pUnoCtrl->GetUnoControlModel();
     137             :                 OSL_ENSURE( xControlModel.is(), "uno control without model" );
     138           0 :                 if ( xControlModel.is() )
     139             :                 {
     140           0 :                     uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
     141           0 :                     uno::Reference< beans::XPropertySetInfo > xInfo = xPropSet->getPropertySetInfo();
     142             : 
     143           0 :                     OUString sPropButtonType( "ButtonType" );
     144           0 :                     OUString sPropTargetURL( "TargetURL" );
     145           0 :                     OUString sPropLabel( "Label" );
     146             : 
     147           0 :                     if(xInfo->hasPropertyByName( sPropButtonType ))
     148             :                     {
     149           0 :                         uno::Any aAny = xPropSet->getPropertyValue( sPropButtonType );
     150             :                         form::FormButtonType eTmp;
     151           0 :                         if ( (aAny >>= eTmp) && eTmp == form::FormButtonType_URL )
     152             :                         {
     153             :                             // URL
     154           0 :                             if(xInfo->hasPropertyByName( sPropTargetURL ))
     155             :                             {
     156           0 :                                 aAny = xPropSet->getPropertyValue( sPropTargetURL );
     157           0 :                                 OUString sTmp;
     158           0 :                                 if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
     159             :                                 {
     160           0 :                                     OUString aUrl = sTmp;
     161           0 :                                     OUString aAbs;
     162             :                                     const SfxMedium* pMedium;
     163           0 :                                     if (pContainerShell && (pMedium = pContainerShell->GetMedium()) != NULL)
     164             :                                     {
     165           0 :                                         bool bWasAbs = true;
     166           0 :                                         aAbs = pMedium->GetURLObject().smartRel2Abs( aUrl, bWasAbs ).
     167           0 :                                                     GetMainURL(INetURLObject::NO_DECODE);
     168             :                                         // full path as stored INetBookmark must be encoded
     169             :                                     }
     170             :                                     else
     171           0 :                                         aAbs = aUrl;
     172             : 
     173             :                                     // Label
     174           0 :                                     OUString aLabel;
     175           0 :                                     if(xInfo->hasPropertyByName( sPropLabel ))
     176             :                                     {
     177           0 :                                         aAny = xPropSet->getPropertyValue( sPropLabel );
     178           0 :                                         if ( (aAny >>= sTmp) && !sTmp.isEmpty() )
     179             :                                         {
     180           0 :                                             aLabel = sTmp;
     181             :                                         }
     182             :                                     }
     183           0 :                                     pBookmark = new INetBookmark( aAbs, aLabel );
     184           0 :                                 }
     185             :                             }
     186           0 :                         }
     187           0 :                     }
     188           0 :                 }
     189             :             }
     190           0 :         }
     191             :     }
     192             : 
     193             :     //  get size for object descriptor
     194             : 
     195             :     // #i71538# use complete SdrViews
     196             :     // SdrExchangeView aView(pModel);
     197           0 :     SdrView aView(pModel);
     198           0 :     SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
     199           0 :     aView.MarkAllObj(pPv);
     200           0 :     aSrcSize = aView.GetAllMarkedRect().GetSize();
     201             : 
     202           0 :     if ( bOleObj )              // single OLE object
     203             :     {
     204           0 :         SdrOle2Obj* pObj = GetSingleObject();
     205           0 :         if ( pObj && pObj->GetObjRef().is() )
     206           0 :             SvEmbedTransferHelper::FillTransferableObjectDescriptor( aObjDesc, pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect() );
     207             :     }
     208             : 
     209           0 :     aObjDesc.maSize = aSrcSize;
     210           0 :     PrepareOLE( aObjDesc );
     211             : 
     212             :     // remember a unique ID of the source document
     213             : 
     214           0 :     if ( pContainerShell )
     215             :     {
     216           0 :         ScDocument& rDoc = pContainerShell->GetDocument();
     217           0 :         nSourceDocID = rDoc.GetDocumentID();
     218           0 :         if ( pPage )
     219             :         {
     220           0 :             ScChartHelper::FillProtectedChartRangesVector( m_aProtectedChartRangesVector, &rDoc, pPage );
     221             :         }
     222           0 :     }
     223           0 : }
     224             : 
     225           0 : ScDrawTransferObj::~ScDrawTransferObj()
     226             : {
     227           0 :     SolarMutexGuard aSolarGuard;
     228             : 
     229           0 :     ScModule* pScMod = SC_MOD();
     230           0 :     if ( pScMod->GetClipData().pDrawClipboard == this )
     231             :     {
     232             :         OSL_FAIL("ScDrawTransferObj wasn't released");
     233           0 :         pScMod->SetClipObject( NULL, NULL );
     234             :     }
     235           0 :     if ( pScMod->GetDragData().pDrawTransfer == this )
     236             :     {
     237             :         OSL_FAIL("ScDrawTransferObj wasn't released");
     238           0 :         pScMod->ResetDragObject();
     239             :     }
     240             : 
     241           0 :     aOleData = TransferableDataHelper();        // clear before releasing the mutex
     242           0 :     aDocShellRef.Clear();
     243             : 
     244           0 :     delete pModel;
     245           0 :     aDrawPersistRef.Clear();                    // after the model
     246             : 
     247           0 :     delete pBookmark;
     248           0 :     delete pDragSourceView;
     249           0 : }
     250             : 
     251         157 : ScDrawTransferObj* ScDrawTransferObj::GetOwnClipboard( vcl::Window* )
     252             : {
     253         157 :     ScDrawTransferObj* pObj = SC_MOD()->GetClipData().pDrawClipboard;
     254         157 :     return pObj;
     255             : }
     256             : 
     257           0 : static bool lcl_HasOnlyControls( SdrModel* pModel )
     258             : {
     259           0 :     bool bOnlyControls = false;         // default if there are no objects
     260             : 
     261           0 :     if ( pModel )
     262             :     {
     263           0 :         SdrPage* pPage = pModel->GetPage(0);
     264           0 :         if (pPage)
     265             :         {
     266           0 :             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
     267           0 :             SdrObject* pObj = aIter.Next();
     268           0 :             if ( pObj )
     269             :             {
     270           0 :                 bOnlyControls = true;   // only set if there are any objects at all
     271           0 :                 while ( pObj )
     272             :                 {
     273           0 :                     if (!pObj->ISA(SdrUnoObj))
     274             :                     {
     275           0 :                         bOnlyControls = false;
     276           0 :                         break;
     277             :                     }
     278           0 :                     pObj = aIter.Next();
     279             :                 }
     280           0 :             }
     281             :         }
     282             :     }
     283             : 
     284           0 :     return bOnlyControls;
     285             : }
     286             : 
     287           0 : void ScDrawTransferObj::AddSupportedFormats()
     288             : {
     289           0 :     if ( bGrIsBit )             // single bitmap graphic
     290             :     {
     291           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     292           0 :         AddFormat( SotClipboardFormatId::SVXB );
     293           0 :         AddFormat( SotClipboardFormatId::PNG );
     294           0 :         AddFormat( SotClipboardFormatId::BITMAP );
     295           0 :         AddFormat( SotClipboardFormatId::GDIMETAFILE );
     296             :     }
     297           0 :     else if ( bGraphic )        // other graphic
     298             :     {
     299             :         // #i25616#
     300           0 :         AddFormat( SotClipboardFormatId::DRAWING );
     301             : 
     302           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     303           0 :         AddFormat( SotClipboardFormatId::SVXB );
     304           0 :         AddFormat( SotClipboardFormatId::GDIMETAFILE );
     305           0 :         AddFormat( SotClipboardFormatId::PNG );
     306           0 :         AddFormat( SotClipboardFormatId::BITMAP );
     307             :     }
     308           0 :     else if ( pBookmark )       // url button
     309             :     {
     310             : //      AddFormat( SotClipboardFormatId::EMBED_SOURCE );
     311           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     312           0 :         AddFormat( SotClipboardFormatId::SOLK );
     313           0 :         AddFormat( SotClipboardFormatId::STRING );
     314           0 :         AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
     315           0 :         AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
     316           0 :         AddFormat( SotClipboardFormatId::DRAWING );
     317             :     }
     318           0 :     else if ( bOleObj )         // single OLE object
     319             :     {
     320           0 :         AddFormat( SotClipboardFormatId::EMBED_SOURCE );
     321           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     322           0 :         AddFormat( SotClipboardFormatId::GDIMETAFILE );
     323             : 
     324           0 :         CreateOLEData();
     325             : 
     326           0 :         if ( aOleData.GetTransferable().is() )
     327             :         {
     328             :             //  get format list from object snapshot
     329             :             //  (this must be after inserting the default formats!)
     330             : 
     331           0 :             DataFlavorExVector              aVector( aOleData.GetDataFlavorExVector() );
     332           0 :             DataFlavorExVector::iterator    aIter( aVector.begin() ), aEnd( aVector.end() );
     333             : 
     334           0 :             while( aIter != aEnd )
     335           0 :                 AddFormat( *aIter++ );
     336             :         }
     337             :     }
     338             :     else                        // any drawing objects
     339             :     {
     340           0 :         AddFormat( SotClipboardFormatId::EMBED_SOURCE );
     341           0 :         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
     342           0 :         AddFormat( SotClipboardFormatId::DRAWING );
     343             : 
     344             :         // leave out bitmap and metafile if there are only controls
     345           0 :         if ( !lcl_HasOnlyControls( pModel ) )
     346             :         {
     347           0 :             AddFormat( SotClipboardFormatId::PNG );
     348           0 :             AddFormat( SotClipboardFormatId::BITMAP );
     349           0 :             AddFormat( SotClipboardFormatId::GDIMETAFILE );
     350             :         }
     351             :     }
     352             : 
     353             : //  if( pImageMap )
     354             : //      AddFormat( SotClipboardFormatId::SVIM );
     355           0 : }
     356             : 
     357           0 : bool ScDrawTransferObj::GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc )
     358             : {
     359           0 :     bool bOK = false;
     360           0 :     SotClipboardFormatId nFormat = SotExchange::GetFormat( rFlavor );
     361             : 
     362           0 :     if ( bOleObj && nFormat != SotClipboardFormatId::GDIMETAFILE )
     363             :     {
     364           0 :         CreateOLEData();
     365             : 
     366           0 :         if( aOleData.GetTransferable().is() && aOleData.HasFormat( rFlavor ) )
     367             :         {
     368           0 :             SdrSwapGraphicsMode nOldSwapMode(SdrSwapGraphicsMode::DEFAULT);
     369             : 
     370           0 :             if( pModel )
     371             :             {
     372           0 :                 nOldSwapMode = pModel->GetSwapGraphicsMode();
     373           0 :                 pModel->SetSwapGraphicsMode( SdrSwapGraphicsMode::PURGE );
     374             :             }
     375             : 
     376           0 :             bOK = SetAny( aOleData.GetAny(rFlavor, rDestDoc), rFlavor );
     377             : 
     378           0 :             if( pModel )
     379           0 :                 pModel->SetSwapGraphicsMode( nOldSwapMode );
     380             : 
     381           0 :             return bOK;
     382             :         }
     383             :     }
     384             : 
     385           0 :     if( HasFormat( nFormat ) )
     386             :     {
     387           0 :         if ( nFormat == SotClipboardFormatId::LINKSRCDESCRIPTOR || nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR )
     388             :         {
     389           0 :             bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor );
     390             :         }
     391           0 :         else if ( nFormat == SotClipboardFormatId::DRAWING )
     392             :         {
     393           0 :             bOK = SetObject( pModel, SCDRAWTRANS_TYPE_DRAWMODEL, rFlavor );
     394             :         }
     395           0 :         else if ( nFormat == SotClipboardFormatId::BITMAP
     396           0 :             || nFormat == SotClipboardFormatId::PNG
     397           0 :             || nFormat == SotClipboardFormatId::GDIMETAFILE )
     398             :         {
     399             :             // #i71538# use complete SdrViews
     400             :             // SdrExchangeView aView( pModel );
     401           0 :             SdrView aView( pModel );
     402           0 :             SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
     403             :             OSL_ENSURE( pPv, "pPv not there..." );
     404           0 :             aView.MarkAllObj( pPv );
     405           0 :             if ( nFormat == SotClipboardFormatId::GDIMETAFILE )
     406           0 :                 bOK = SetGDIMetaFile( aView.GetMarkedObjMetaFile(true), rFlavor );
     407             :             else
     408           0 :                 bOK = SetBitmapEx( aView.GetMarkedObjBitmapEx(true), rFlavor );
     409             :         }
     410           0 :         else if ( nFormat == SotClipboardFormatId::SVXB )
     411             :         {
     412             :             // only enabled for single graphics object
     413             : 
     414           0 :             SdrPage* pPage = pModel->GetPage(0);
     415           0 :             if (pPage)
     416             :             {
     417           0 :                 SdrObjListIter aIter( *pPage, IM_FLAT );
     418           0 :                 SdrObject* pObject = aIter.Next();
     419           0 :                 if (pObject && pObject->GetObjIdentifier() == OBJ_GRAF)
     420             :                 {
     421           0 :                     SdrGrafObj* pGraphObj = static_cast<SdrGrafObj*>(pObject);
     422           0 :                     bOK = SetGraphic( pGraphObj->GetGraphic(), rFlavor );
     423           0 :                 }
     424             :             }
     425             :         }
     426           0 :         else if ( nFormat == SotClipboardFormatId::EMBED_SOURCE )
     427             :         {
     428           0 :             if ( bOleObj )              // single OLE object
     429             :             {
     430           0 :                 SdrOle2Obj* pObj = GetSingleObject();
     431           0 :                 if ( pObj && pObj->GetObjRef().is() )
     432             :                 {
     433           0 :                     bOK = SetObject( pObj->GetObjRef().get(), SCDRAWTRANS_TYPE_EMBOBJ, rFlavor );
     434             :                 }
     435             :             }
     436             :             else                        // create object from contents
     437             :             {
     438             :                 //TODO/LATER: needs new Format, because now single OLE and "this" are different
     439           0 :                 InitDocShell();         // set aDocShellRef
     440             : 
     441           0 :                 SfxObjectShell* pEmbObj = aDocShellRef;
     442           0 :                 bOK = SetObject( pEmbObj, SCDRAWTRANS_TYPE_DOCUMENT, rFlavor );
     443             :             }
     444             :         }
     445           0 :         else if( pBookmark )
     446             :         {
     447           0 :             bOK = SetINetBookmark( *pBookmark, rFlavor );
     448             :         }
     449             :     }
     450           0 :     return bOK;
     451             : }
     452             : 
     453           0 : bool ScDrawTransferObj::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, SotClipboardFormatId nUserObjectId,
     454             :                                         const ::com::sun::star::datatransfer::DataFlavor& /* rFlavor */ )
     455             : {
     456             :     // called from SetObject, put data into stream
     457             : 
     458           0 :     bool bRet = false;
     459           0 :     switch (nUserObjectId)
     460             :     {
     461             :         case SCDRAWTRANS_TYPE_DRAWMODEL:
     462             :             {
     463           0 :                 SdrModel* pDrawModel = static_cast<SdrModel*>(pUserObject);
     464           0 :                 rxOStm->SetBufferSize( 0xff00 );
     465             : 
     466             :                 // #108584#
     467             :                 // for the changed pool defaults from drawing layer pool set those
     468             :                 // attributes as hard attributes to preserve them for saving
     469           0 :                 const SfxItemPool& rItemPool = pModel->GetItemPool();
     470           0 :                 const SvxFontHeightItem& rDefaultFontHeight = static_cast<const SvxFontHeightItem&>(rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT));
     471             : 
     472             :                 // SW should have no MasterPages
     473             :                 OSL_ENSURE(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
     474             : 
     475           0 :                 for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
     476             :                 {
     477           0 :                     const SdrPage* pPage = pModel->GetPage(a);
     478           0 :                     SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS);
     479             : 
     480           0 :                     while(aIter.IsMore())
     481             :                     {
     482           0 :                         SdrObject* pObj = aIter.Next();
     483           0 :                         const SvxFontHeightItem& rItem = static_cast<const SvxFontHeightItem&>(pObj->GetMergedItem(EE_CHAR_FONTHEIGHT));
     484             : 
     485           0 :                         if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
     486             :                         {
     487           0 :                             pObj->SetMergedItem(rDefaultFontHeight);
     488             :                         }
     489             :                     }
     490           0 :                 }
     491             : 
     492             :                 {
     493           0 :                     com::sun::star::uno::Reference<com::sun::star::io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
     494           0 :                     if( SvxDrawingLayerExport( pDrawModel, xDocOut ) )
     495           0 :                         rxOStm->Commit();
     496             :                 }
     497             : 
     498           0 :                 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
     499             :             }
     500           0 :             break;
     501             : 
     502             :         case SCDRAWTRANS_TYPE_EMBOBJ:
     503             :             {
     504             :                 // impl. for "single OLE"
     505           0 :                 embed::XEmbeddedObject* pEmbObj = static_cast<embed::XEmbeddedObject*>(pUserObject);
     506             : 
     507           0 :                 ::utl::TempFile     aTempFile;
     508           0 :                 aTempFile.EnableKillingFile();
     509             :                 uno::Reference< embed::XStorage > xWorkStore =
     510           0 :                     ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
     511             : 
     512           0 :                 uno::Reference < embed::XEmbedPersist > xPers( static_cast<embed::XVisualObject*>(pEmbObj), uno::UNO_QUERY );
     513           0 :                 if ( xPers.is() )
     514             :                 {
     515             :                     try
     516             :                     {
     517           0 :                         uno::Sequence < beans::PropertyValue > aSeq;
     518           0 :                         OUString aDummyName("Dummy");
     519           0 :                         xPers->storeToEntry( xWorkStore, aDummyName, aSeq, aSeq );
     520           0 :                         if ( xWorkStore->isStreamElement( aDummyName ) )
     521             :                         {
     522           0 :                             uno::Reference < io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxOStm ) );
     523           0 :                             uno::Reference < io::XStream > xNewStream = xWorkStore->openStreamElement( aDummyName, embed::ElementModes::READ );
     524           0 :                             ::comphelper::OStorageHelper::CopyInputToOutput( xNewStream->getInputStream(), xDocOut );
     525             :                         }
     526             :                         else
     527             :                         {
     528           0 :                             uno::Reference < io::XStream > xDocStr( new utl::OStreamWrapper( *rxOStm ) );
     529           0 :                             uno::Reference< embed::XStorage > xDocStg = ::comphelper::OStorageHelper::GetStorageFromStream( xDocStr );
     530           0 :                             uno::Reference < embed::XStorage > xNewStg = xWorkStore->openStorageElement( aDummyName, embed::ElementModes::READ );
     531           0 :                             xNewStg->copyToStorage( xDocStg );
     532           0 :                             uno::Reference < embed::XTransactedObject > xTrans( xDocStg, uno::UNO_QUERY );
     533           0 :                             if ( xTrans.is() )
     534           0 :                                 xTrans->commit();
     535             :                         }
     536             : 
     537           0 :                         rxOStm->Commit();
     538             :                     }
     539           0 :                     catch ( uno::Exception& )
     540             :                     {
     541             :                     }
     542             :                 }
     543             : 
     544           0 :                 break;
     545             :             }
     546             :         case SCDRAWTRANS_TYPE_DOCUMENT:
     547             :             {
     548             :                 // impl. for "DocShell"
     549           0 :                 SfxObjectShell*   pEmbObj = static_cast<SfxObjectShell*>(pUserObject);
     550             : 
     551             :                 try
     552             :                 {
     553           0 :                     ::utl::TempFile     aTempFile;
     554           0 :                     aTempFile.EnableKillingFile();
     555             :                     uno::Reference< embed::XStorage > xWorkStore =
     556           0 :                         ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
     557             : 
     558             :                     // write document storage
     559           0 :                     pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, false, false );
     560             : 
     561             :                     // mba: no relative URLs for clipboard!
     562           0 :                     SfxMedium aMedium( xWorkStore, OUString() );
     563           0 :                     bRet = pEmbObj->DoSaveObjectAs( aMedium, false );
     564           0 :                     pEmbObj->DoSaveCompleted();
     565             : 
     566           0 :                     uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
     567           0 :                     if ( xTransact.is() )
     568           0 :                         xTransact->commit();
     569             : 
     570           0 :                     SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
     571           0 :                     if( pSrcStm )
     572             :                     {
     573           0 :                         rxOStm->SetBufferSize( 0xff00 );
     574           0 :                         rxOStm->WriteStream( *pSrcStm );
     575           0 :                         delete pSrcStm;
     576             :                     }
     577             : 
     578           0 :                     bRet = true;
     579             : 
     580           0 :                     xWorkStore->dispose();
     581           0 :                     xWorkStore = uno::Reference < embed::XStorage >();
     582           0 :                     rxOStm->Commit();
     583             :                 }
     584           0 :                 catch ( uno::Exception& )
     585             :                 {}
     586             : 
     587           0 :                 bRet = ( rxOStm->GetError() == ERRCODE_NONE );
     588             :             }
     589           0 :             break;
     590             : 
     591             :         default:
     592             :             OSL_FAIL("unknown object id");
     593             :     }
     594           0 :     return bRet;
     595             : }
     596             : 
     597           0 : void ScDrawTransferObj::ObjectReleased()
     598             : {
     599           0 :     ScModule* pScMod = SC_MOD();
     600           0 :     if ( pScMod->GetClipData().pDrawClipboard == this )
     601           0 :         pScMod->SetClipObject( NULL, NULL );
     602             : 
     603           0 :     TransferableHelper::ObjectReleased();
     604           0 : }
     605             : 
     606           0 : void ScDrawTransferObj::DragFinished( sal_Int8 nDropAction )
     607             : {
     608           0 :     if ( nDropAction == DND_ACTION_MOVE && !bDragWasInternal && !(nDragSourceFlags & SC_DROP_NAVIGATOR) )
     609             :     {
     610             :         //  move: delete source objects
     611             : 
     612           0 :         if ( pDragSourceView )
     613           0 :             pDragSourceView->DeleteMarked();
     614             :     }
     615             : 
     616           0 :     ScModule* pScMod = SC_MOD();
     617           0 :     if ( pScMod->GetDragData().pDrawTransfer == this )
     618           0 :         pScMod->ResetDragObject();
     619             : 
     620           0 :     DELETEZ( pDragSourceView );
     621             : 
     622           0 :     TransferableHelper::DragFinished( nDropAction );
     623           0 : }
     624             : 
     625           0 : void ScDrawTransferObj::SetDrawPersist( const SfxObjectShellRef& rRef )
     626             : {
     627           0 :     aDrawPersistRef = rRef;
     628           0 : }
     629             : 
     630           0 : static void lcl_InitMarks( SdrMarkView& rDest, const SdrMarkView& rSource, SCTAB nTab )
     631             : {
     632           0 :     rDest.ShowSdrPage(rDest.GetModel()->GetPage(nTab));
     633           0 :     SdrPageView* pDestPV = rDest.GetSdrPageView();
     634             :     OSL_ENSURE(pDestPV,"PageView ?");
     635             : 
     636           0 :     const SdrMarkList& rMarkList = rSource.GetMarkedObjectList();
     637           0 :     const size_t nCount = rMarkList.GetMarkCount();
     638           0 :     for (size_t i=0; i<nCount; ++i)
     639             :     {
     640           0 :         SdrMark* pMark = rMarkList.GetMark(i);
     641           0 :         SdrObject* pObj = pMark->GetMarkedSdrObj();
     642             : 
     643           0 :         rDest.MarkObj(pObj, pDestPV);
     644             :     }
     645           0 : }
     646             : 
     647           0 : void ScDrawTransferObj::SetDragSource( ScDrawView* pView )
     648             : {
     649           0 :     DELETEZ( pDragSourceView );
     650           0 :     pDragSourceView = new SdrView( pView->GetModel() );
     651           0 :     lcl_InitMarks( *pDragSourceView, *pView, pView->GetTab() );
     652             : 
     653             :     //! add as listener with document, delete pDragSourceView if document gone
     654           0 : }
     655             : 
     656           0 : void ScDrawTransferObj::SetDragSourceObj( SdrObject* pObj, SCTAB nTab )
     657             : {
     658           0 :     DELETEZ( pDragSourceView );
     659           0 :     pDragSourceView = new SdrView( pObj->GetModel() );
     660           0 :     pDragSourceView->ShowSdrPage(pDragSourceView->GetModel()->GetPage(nTab));
     661           0 :     SdrPageView* pPV = pDragSourceView->GetSdrPageView();
     662           0 :     pDragSourceView->MarkObj(pObj, pPV);
     663             : 
     664             :     //! add as listener with document, delete pDragSourceView if document gone
     665           0 : }
     666             : 
     667           0 : void ScDrawTransferObj::SetDragSourceFlags( sal_uInt16 nFlags )
     668             : {
     669           0 :     nDragSourceFlags = nFlags;
     670           0 : }
     671             : 
     672           0 : void ScDrawTransferObj::SetDragWasInternal()
     673             : {
     674           0 :     bDragWasInternal = true;
     675           0 : }
     676             : 
     677           0 : OUString ScDrawTransferObj::GetShellID() const
     678             : {
     679           0 :     return maShellID;
     680             : }
     681             : 
     682           0 : SdrOle2Obj* ScDrawTransferObj::GetSingleObject()
     683             : {
     684             :     //  if single OLE object was copied, get its object
     685             : 
     686           0 :     SdrPage* pPage = pModel->GetPage(0);
     687           0 :     if (pPage)
     688             :     {
     689           0 :         SdrObjListIter aIter( *pPage, IM_FLAT );
     690           0 :         SdrObject* pObject = aIter.Next();
     691           0 :         if (pObject && pObject->GetObjIdentifier() == OBJ_OLE2)
     692             :         {
     693           0 :             return static_cast<SdrOle2Obj*>(pObject);
     694           0 :         }
     695             :     }
     696             : 
     697           0 :     return NULL;
     698             : }
     699             : 
     700           0 : void ScDrawTransferObj::CreateOLEData()
     701             : {
     702           0 :     if (aOleData.GetTransferable().is())
     703             :         // Already created.
     704           0 :         return;
     705             : 
     706           0 :     SdrOle2Obj* pObj = GetSingleObject();
     707           0 :     if (!pObj || !pObj->GetObjRef().is())
     708             :         // No OLE object present.
     709           0 :         return;
     710             : 
     711             :     SvEmbedTransferHelper* pEmbedTransfer =
     712             :         new SvEmbedTransferHelper(
     713           0 :             pObj->GetObjRef(), pObj->GetGraphic(), pObj->GetAspect());
     714             : 
     715           0 :     pEmbedTransfer->SetParentShellID(maShellID);
     716             : 
     717           0 :     aOleData = TransferableDataHelper(pEmbedTransfer);
     718             : }
     719             : 
     720             : //  initialize aDocShellRef with a live document from the ClipDoc
     721             : 
     722           0 : void ScDrawTransferObj::InitDocShell()
     723             : {
     724           0 :     if ( !aDocShellRef.Is() )
     725             :     {
     726           0 :         ScDocShell* pDocSh = new ScDocShell;
     727           0 :         aDocShellRef = pDocSh;      // ref must be there before InitNew
     728             : 
     729           0 :         pDocSh->DoInitNew(NULL);
     730             : 
     731           0 :         ScDocument& rDestDoc = pDocSh->GetDocument();
     732           0 :         rDestDoc.InitDrawLayer( pDocSh );
     733             : 
     734           0 :         SdrModel* pDestModel = rDestDoc.GetDrawLayer();
     735             :         // #i71538# use complete SdrViews
     736             :         // SdrExchangeView aDestView( pDestModel );
     737           0 :         SdrView aDestView( pDestModel );
     738           0 :         aDestView.ShowSdrPage(aDestView.GetModel()->GetPage(0));
     739             :         aDestView.Paste(
     740             :             *pModel,
     741           0 :             Point(aSrcSize.Width()/2, aSrcSize.Height()/2),
     742           0 :             NULL, SdrInsertFlags::NONE, OUString(), OUString());
     743             : 
     744             :         // put objects to right layer (see ScViewFunc::PasteDataFormat for SotClipboardFormatId::DRAWING)
     745             : 
     746           0 :         SdrPage* pPage = pDestModel->GetPage(0);
     747           0 :         if (pPage)
     748             :         {
     749           0 :             SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
     750           0 :             SdrObject* pObject = aIter.Next();
     751           0 :             while (pObject)
     752             :             {
     753           0 :                 if ( pObject->ISA(SdrUnoObj) )
     754           0 :                     pObject->NbcSetLayer(SC_LAYER_CONTROLS);
     755             :                 else
     756           0 :                     pObject->NbcSetLayer(SC_LAYER_FRONT);
     757           0 :                 pObject = aIter.Next();
     758           0 :             }
     759             :         }
     760             : 
     761           0 :         Point aTmpPoint;
     762           0 :         Rectangle aDestArea( aTmpPoint, aSrcSize );
     763           0 :         pDocSh->SetVisArea( aDestArea );
     764             : 
     765           0 :         ScViewOptions aViewOpt( rDestDoc.GetViewOptions() );
     766           0 :         aViewOpt.SetOption( VOPT_GRID, false );
     767           0 :         rDestDoc.SetViewOptions( aViewOpt );
     768             : 
     769           0 :         ScViewData aViewData( pDocSh, NULL );
     770           0 :         aViewData.SetTabNo( 0 );
     771           0 :         aViewData.SetScreen( aDestArea );
     772           0 :         aViewData.SetCurX( 0 );
     773           0 :         aViewData.SetCurY( 0 );
     774           0 :         pDocSh->UpdateOle(&aViewData, true);
     775             :     }
     776           0 : }
     777             : 
     778             : namespace
     779             : {
     780             :     class theScDrawTransferObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScDrawTransferObjUnoTunnelId > {};
     781             : }
     782             : 
     783           0 : const com::sun::star::uno::Sequence< sal_Int8 >& ScDrawTransferObj::getUnoTunnelId()
     784             : {
     785           0 :     return theScDrawTransferObjUnoTunnelId::get().getSeq();
     786             : }
     787             : 
     788           0 : sal_Int64 SAL_CALL ScDrawTransferObj::getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( com::sun::star::uno::RuntimeException, std::exception )
     789             : {
     790             :     sal_Int64 nRet;
     791           0 :     if( ( rId.getLength() == 16 ) &&
     792           0 :         ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
     793             :     {
     794           0 :         nRet = reinterpret_cast< sal_Int64 >( this );
     795             :     }
     796             :     else
     797           0 :         nRet = TransferableHelper::getSomething(rId);
     798           0 :     return nRet;
     799         156 : }
     800             : 
     801             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11