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

Generated by: LCOV version 1.10