LCOV - code coverage report
Current view: top level - svtools/source/misc - embedtransfer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 105 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 240 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/embed/XComponentSupplier.hpp>
      30                 :            : #include <com/sun/star/embed/EmbedStates.hpp>
      31                 :            : #include <com/sun/star/embed/XVisualObject.hpp>
      32                 :            : #include <com/sun/star/embed/XEmbedPersist.hpp>
      33                 :            : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
      34                 :            : #include <com/sun/star/datatransfer/XTransferable.hpp>
      35                 :            : #include <com/sun/star/embed/Aspects.hpp>
      36                 :            : 
      37                 :            : #include <svtools/embedtransfer.hxx>
      38                 :            : #include <tools/mapunit.hxx>
      39                 :            : #include <vcl/outdev.hxx>
      40                 :            : #include <comphelper/storagehelper.hxx>
      41                 :            : #include <unotools/ucbstreamhelper.hxx>
      42                 :            : #include <unotools/streamwrap.hxx>
      43                 :            : #include <unotools/tempfile.hxx>
      44                 :            : #include <toolkit/helper/vclunohelper.hxx>
      45                 :            : 
      46                 :            : #include <svtools/embedhlp.hxx>
      47                 :            : 
      48                 :            : using namespace ::com::sun::star;
      49                 :            : 
      50                 :          0 : SvEmbedTransferHelper::SvEmbedTransferHelper( const uno::Reference< embed::XEmbeddedObject >& xObj,
      51                 :            :                                                 Graphic* pGraphic,
      52                 :            :                                                 sal_Int64 nAspect )
      53                 :            : : m_xObj( xObj )
      54         [ #  # ]:          0 : , m_pGraphic( pGraphic ? new Graphic( *pGraphic ) : NULL )
      55 [ #  # ][ #  # ]:          0 : , m_nAspect( nAspect )
      56                 :            : {
      57         [ #  # ]:          0 :     if( xObj.is() )
      58                 :            :     {
      59         [ #  # ]:          0 :         TransferableObjectDescriptor aObjDesc;
      60                 :            : 
      61         [ #  # ]:          0 :         FillTransferableObjectDescriptor( aObjDesc, m_xObj, NULL, m_nAspect );
      62 [ #  # ][ #  # ]:          0 :         PrepareOLE( aObjDesc );
      63                 :            :     }
      64                 :          0 : }
      65                 :            : 
      66                 :            : // -----------------------------------------------------------------------------
      67                 :            : 
      68                 :          0 : SvEmbedTransferHelper::~SvEmbedTransferHelper()
      69                 :            : {
      70         [ #  # ]:          0 :     if ( m_pGraphic )
      71                 :            :     {
      72 [ #  # ][ #  # ]:          0 :         delete m_pGraphic;
      73                 :          0 :         m_pGraphic = NULL;
      74                 :            :     }
      75         [ #  # ]:          0 : }
      76                 :            : 
      77                 :            : // -----------------------------------------------------------------------------
      78                 :            : 
      79                 :          0 : void SvEmbedTransferHelper::AddSupportedFormats()
      80                 :            : {
      81                 :          0 :     AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
      82                 :          0 :     AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
      83                 :          0 :     AddFormat( FORMAT_GDIMETAFILE );
      84                 :          0 : }
      85                 :            : 
      86                 :            : // -----------------------------------------------------------------------------
      87                 :            : 
      88                 :          0 : sal_Bool SvEmbedTransferHelper::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
      89                 :            : {
      90                 :          0 :     sal_Bool bRet = sal_False;
      91                 :            : 
      92         [ #  # ]:          0 :     if( m_xObj.is() )
      93                 :            :     {
      94                 :            :         try
      95                 :            :         {
      96         [ #  # ]:          0 :             sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
      97 [ #  # ][ #  # ]:          0 :             if( HasFormat( nFormat ) )
      98                 :            :             {
      99         [ #  # ]:          0 :                 if( nFormat == SOT_FORMATSTR_ID_OBJECTDESCRIPTOR )
     100                 :            :                 {
     101         [ #  # ]:          0 :                     TransferableObjectDescriptor aDesc;
     102         [ #  # ]:          0 :                     FillTransferableObjectDescriptor( aDesc, m_xObj, m_pGraphic, m_nAspect );
     103 [ #  # ][ #  # ]:          0 :                     bRet = SetTransferableObjectDescriptor( aDesc, rFlavor );
     104                 :            :                 }
     105         [ #  # ]:          0 :                 else if( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
     106                 :            :                 {
     107                 :            :                     try
     108                 :            :                     {
     109                 :            :                         // TODO/LATER: Propbably the graphic should be copied here as well
     110                 :            :                         // currently it is handled by the applications
     111         [ #  # ]:          0 :                         utl::TempFile aTmp;
     112                 :          0 :                         aTmp.EnableKillingFile( sal_True );
     113         [ #  # ]:          0 :                         uno::Reference < embed::XEmbedPersist > xPers( m_xObj, uno::UNO_QUERY );
     114         [ #  # ]:          0 :                         if ( xPers.is() )
     115                 :            :                         {
     116         [ #  # ]:          0 :                             uno::Reference < embed::XStorage > xStg = comphelper::OStorageHelper::GetTemporaryStorage();
     117         [ #  # ]:          0 :                             ::rtl::OUString aName( RTL_CONSTASCII_USTRINGPARAM( "Dummy" ));
     118                 :          0 :                             SvStream* pStream = NULL;
     119                 :          0 :                             sal_Bool bDeleteStream = sal_False;
     120         [ #  # ]:          0 :                             uno::Sequence < beans::PropertyValue > aEmpty;
     121 [ #  # ][ #  # ]:          0 :                             xPers->storeToEntry( xStg, aName, aEmpty, aEmpty );
     122 [ #  # ][ #  # ]:          0 :                             if ( xStg->isStreamElement( aName ) )
                 [ #  # ]
     123                 :            :                             {
     124 [ #  # ][ #  # ]:          0 :                                 uno::Reference < io::XStream > xStm = xStg->cloneStreamElement( aName );
     125         [ #  # ]:          0 :                                 pStream = utl::UcbStreamHelper::CreateStream( xStm );
     126                 :          0 :                                 bDeleteStream = sal_True;
     127                 :            :                             }
     128                 :            :                             else
     129                 :            :                             {
     130         [ #  # ]:          0 :                                 pStream = aTmp.GetStream( STREAM_STD_READWRITE );
     131 [ #  # ][ #  # ]:          0 :                                 uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetStorageFromStream( new utl::OStreamWrapper( *pStream ) );
         [ #  # ][ #  # ]
     132 [ #  # ][ #  # ]:          0 :                                 xStg->openStorageElement( aName, embed::ElementModes::READ )->copyToStorage( xStor );
         [ #  # ][ #  # ]
     133                 :            :                             }
     134                 :            : 
     135                 :          0 :                             ::com::sun::star::uno::Any                  aAny;
     136         [ #  # ]:          0 :                             const sal_uInt32                            nLen = pStream->Seek( STREAM_SEEK_TO_END );
     137         [ #  # ]:          0 :                             ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
     138                 :            : 
     139         [ #  # ]:          0 :                             pStream->Seek( STREAM_SEEK_TO_BEGIN );
     140 [ #  # ][ #  # ]:          0 :                             pStream->Read( aSeq.getArray(),  nLen );
     141         [ #  # ]:          0 :                             if ( bDeleteStream )
     142 [ #  # ][ #  # ]:          0 :                                 delete pStream;
     143                 :            : 
     144         [ #  # ]:          0 :                             if( ( bRet = ( aSeq.getLength() > 0 ) ) == sal_True )
     145                 :            :                             {
     146         [ #  # ]:          0 :                                 aAny <<= aSeq;
     147         [ #  # ]:          0 :                                 SetAny( aAny, rFlavor );
     148 [ #  # ][ #  # ]:          0 :                             }
     149                 :            :                         }
     150                 :            :                         else
     151                 :            :                         {
     152                 :            :                             //TODO/LATER: how to handle objects without persistance?!
     153 [ #  # ][ #  # ]:          0 :                         }
     154                 :            :                     }
     155         [ #  # ]:          0 :                     catch ( uno::Exception& )
     156                 :            :                     {
     157                 :            :                     }
     158                 :            :                 }
     159 [ #  # ][ #  # ]:          0 :                 else if ( nFormat == FORMAT_GDIMETAFILE && m_pGraphic )
     160                 :            :                 {
     161         [ #  # ]:          0 :                     SvMemoryStream aMemStm( 65535, 65535 );
     162                 :          0 :                     aMemStm.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
     163                 :            : 
     164         [ #  # ]:          0 :                     const GDIMetaFile& aMetaFile = m_pGraphic->GetGDIMetaFile();
     165         [ #  # ]:          0 :                     ((GDIMetaFile*)(&aMetaFile))->Write( aMemStm );
     166                 :          0 :                     uno::Any aAny;
     167         [ #  # ]:          0 :                     aAny <<= uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ),
     168 [ #  # ][ #  # ]:          0 :                                                     aMemStm.Seek( STREAM_SEEK_TO_END ) );
         [ #  # ][ #  # ]
     169         [ #  # ]:          0 :                     SetAny( aAny, rFlavor );
     170         [ #  # ]:          0 :                     bRet = sal_True;
     171                 :            :                 }
     172 [ #  # ][ #  # ]:          0 :                 else if ( m_xObj.is() && :: svt::EmbeddedObjectRef::TryRunningState( m_xObj ) )
         [ #  # ][ #  # ]
     173                 :            :                 {
     174 [ #  # ][ #  # ]:          0 :                     uno::Reference< datatransfer::XTransferable > xTransferable( m_xObj->getComponent(), uno::UNO_QUERY );
                 [ #  # ]
     175         [ #  # ]:          0 :                     if ( xTransferable.is() )
     176                 :            :                     {
     177 [ #  # ][ #  # ]:          0 :                         uno::Any aAny = xTransferable->getTransferData( rFlavor );
     178         [ #  # ]:          0 :                         SetAny( aAny, rFlavor );
     179                 :          0 :                         bRet = sal_True;
     180         [ #  # ]:          0 :                     }
     181                 :            :                 }
     182                 :            :             }
     183                 :            :         }
     184                 :          0 :         catch( uno::Exception& )
     185                 :            :         {
     186                 :            :             // Error handling?
     187                 :            :         }
     188                 :            :     }
     189                 :            : 
     190                 :          0 :     return bRet;
     191                 :            : }
     192                 :            : 
     193                 :            : // -----------------------------------------------------------------------------
     194                 :            : 
     195                 :          0 : void SvEmbedTransferHelper::ObjectReleased()
     196                 :            : {
     197         [ #  # ]:          0 :     m_xObj = uno::Reference< embed::XEmbeddedObject >();
     198                 :          0 : }
     199                 :            : 
     200                 :          0 : void SvEmbedTransferHelper::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc,
     201                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedObject >& xObj,
     202                 :            :     Graphic* pGraphic,
     203                 :            :     sal_Int64 nAspect )
     204                 :            : {
     205                 :            :     //TODO/LATER: need TypeName to fill it into the Descriptor (will be shown in listbox)
     206                 :          0 :     ::com::sun::star::datatransfer::DataFlavor aFlavor;
     207         [ #  # ]:          0 :     SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aFlavor );
     208                 :            : 
     209 [ #  # ][ #  # ]:          0 :     rDesc.maClassName = SvGlobalName( xObj->getClassID() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     210         [ #  # ]:          0 :     rDesc.maTypeName = aFlavor.HumanPresentableName;
     211                 :            : 
     212                 :            :     //TODO/LATER: the aspect size in the descriptor is wrong, unfortunately the stream
     213                 :            :     // representation of the descriptor allows only 4 bytes for the aspect
     214                 :            :     // so for internal transport something different should be found
     215                 :          0 :     rDesc.mnViewAspect = sal::static_int_cast<sal_uInt16>( nAspect );
     216                 :            : 
     217                 :            :     //TODO/LATER: status needs to become sal_Int64
     218 [ #  # ][ #  # ]:          0 :     rDesc.mnOle2Misc = sal::static_int_cast<sal_Int32>(xObj->getStatus( rDesc.mnViewAspect ));
     219                 :            : 
     220                 :          0 :     Size aSize;
     221         [ #  # ]:          0 :     MapMode aMapMode( MAP_100TH_MM );
     222         [ #  # ]:          0 :     if ( nAspect == embed::Aspects::MSOLE_ICON )
     223                 :            :     {
     224         [ #  # ]:          0 :         if ( pGraphic )
     225                 :            :         {
     226 [ #  # ][ #  # ]:          0 :             aMapMode = pGraphic->GetPrefMapMode();
           [ #  #  #  # ]
     227         [ #  # ]:          0 :             aSize = pGraphic->GetPrefSize();
     228                 :            :         }
     229                 :            :         else
     230                 :          0 :             aSize = Size( 2500, 2500 );
     231                 :            :     }
     232                 :            :     else
     233                 :            :     {
     234                 :            :         try
     235                 :            :         {
     236                 :          0 :             awt::Size aSz;
     237 [ #  # ][ #  # ]:          0 :             aSz = xObj->getVisualAreaSize( rDesc.mnViewAspect );
     238                 :          0 :             aSize = Size( aSz.Width, aSz.Height );
     239                 :            :         }
     240         [ #  # ]:          0 :         catch( embed::NoVisualAreaSizeException& )
     241                 :            :         {
     242                 :            :             OSL_FAIL( "Can not get visual area size!\n" );
     243                 :          0 :             aSize = Size( 5000, 5000 );
     244                 :            :         }
     245                 :            : 
     246                 :            :         // TODO/LEAN: getMapUnit can switch object to running state
     247 [ #  # ][ #  # ]:          0 :         aMapMode = MapMode( VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( rDesc.mnViewAspect ) ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     248                 :            :     }
     249                 :            : 
     250 [ #  # ][ #  # ]:          0 :     rDesc.maSize = OutputDevice::LogicToLogic( aSize, aMapMode, MapMode( MAP_100TH_MM ) );
                 [ #  # ]
     251                 :          0 :     rDesc.maDragStartPos = Point();
     252 [ #  # ][ #  # ]:          0 :     rDesc.maDisplayName = String();
                 [ #  # ]
     253         [ #  # ]:          0 :     rDesc.mbCanLink = sal_False;
     254                 :          0 : }
     255                 :            : 
     256                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10