LCOV - code coverage report
Current view: top level - embeddedobj/source/msole - oleembed.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 354 0.0 %
Date: 2012-08-25 Functions: 0 17 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 911 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 <oleembobj.hxx>
      30                 :            : #include <com/sun/star/embed/EmbedStates.hpp>
      31                 :            : #include <com/sun/star/embed/EmbedVerbs.hpp>
      32                 :            : #include <com/sun/star/embed/EntryInitModes.hpp>
      33                 :            : #include <com/sun/star/embed/XStorage.hpp>
      34                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      35                 :            : #include <com/sun/star/embed/EmbedUpdateModes.hpp>
      36                 :            : #include <com/sun/star/embed/Aspects.hpp>
      37                 :            : #include <com/sun/star/embed/NeedsRunningStateException.hpp>
      38                 :            : #include <com/sun/star/embed/StateChangeInProgressException.hpp>
      39                 :            : #include <com/sun/star/embed/EmbedMisc.hpp>
      40                 :            : #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
      41                 :            : #include <com/sun/star/io/XSeekable.hpp>
      42                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      43                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      44                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      45                 :            : #include <com/sun/star/frame/XLoadable.hpp>
      46                 :            : #include <com/sun/star/document/XStorageBasedDocument.hpp>
      47                 :            : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      48                 :            : #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
      49                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      50                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      51                 :            : #include <com/sun/star/system/XSystemShellExecute.hpp>
      52                 :            : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
      53                 :            : 
      54                 :            : #include <rtl/logfile.hxx>
      55                 :            : #include <comphelper/componentcontext.hxx>
      56                 :            : #include <cppuhelper/interfacecontainer.h>
      57                 :            : #include <comphelper/mimeconfighelper.hxx>
      58                 :            : #include <comphelper/storagehelper.hxx>
      59                 :            : 
      60                 :            : 
      61                 :            : #include <targetstatecontrol.hxx>
      62                 :            : 
      63                 :            : #include <olecomponent.hxx>
      64                 :            : 
      65                 :            : #include "ownview.hxx"
      66                 :            : 
      67                 :            : using namespace ::com::sun::star;
      68                 :            : 
      69                 :            : #ifdef WNT
      70                 :            : //----------------------------------------------
      71                 :            : void OleEmbeddedObject::SwitchComponentToRunningState_Impl()
      72                 :            : {
      73                 :            :     if ( m_pOleComponent )
      74                 :            :     {
      75                 :            :         try
      76                 :            :         {
      77                 :            :             m_pOleComponent->RunObject();
      78                 :            :         }
      79                 :            :         catch( const embed::UnreachableStateException& )
      80                 :            :         {
      81                 :            :             GetRidOfComponent();
      82                 :            :             throw;
      83                 :            :         }
      84                 :            :         catch( const embed::WrongStateException& )
      85                 :            :         {
      86                 :            :             GetRidOfComponent();
      87                 :            :             throw;
      88                 :            :         }
      89                 :            :     }
      90                 :            :     else
      91                 :            :     {
      92                 :            :         throw embed::UnreachableStateException();
      93                 :            :     }
      94                 :            : }
      95                 :            : 
      96                 :            : //----------------------------------------------
      97                 :            : uno::Sequence< sal_Int32 > OleEmbeddedObject::GetReachableStatesList_Impl(
      98                 :            :                                                         const uno::Sequence< embed::VerbDescriptor >& aVerbList )
      99                 :            : {
     100                 :            :     uno::Sequence< sal_Int32 > aStates(2);
     101                 :            :     aStates[0] = embed::EmbedStates::LOADED;
     102                 :            :     aStates[1] = embed::EmbedStates::RUNNING;
     103                 :            :     for ( sal_Int32 nInd = 0; nInd < aVerbList.getLength(); nInd++ )
     104                 :            :         if ( aVerbList[nInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_OPEN )
     105                 :            :         {
     106                 :            :             aStates.realloc(3);
     107                 :            :             aStates[2] = embed::EmbedStates::ACTIVE;
     108                 :            :         }
     109                 :            : 
     110                 :            :     return aStates;
     111                 :            : }
     112                 :            : 
     113                 :            : //----------------------------------------------
     114                 :            : uno::Sequence< sal_Int32 > OleEmbeddedObject::GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState )
     115                 :            : {
     116                 :            :     OSL_ENSURE( m_nObjectState != embed::EmbedStates::LOADED, "Loaded object is switched to running state without verbs using!" );
     117                 :            : 
     118                 :            :     // actually there will be only one verb
     119                 :            :     if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE )
     120                 :            :     {
     121                 :            :         uno::Sequence< sal_Int32 > aVerbs( 1 );
     122                 :            :         aVerbs[0] = embed::EmbedVerbs::MS_OLEVERB_OPEN;
     123                 :            :     }
     124                 :            : 
     125                 :            :     return uno::Sequence< sal_Int32 >();
     126                 :            : }
     127                 :            : #endif
     128                 :            : //----------------------------------------------
     129                 :          0 : void OleEmbeddedObject::MoveListeners()
     130                 :            : {
     131         [ #  # ]:          0 :     if ( m_pInterfaceContainer )
     132                 :            :     {
     133                 :            :         // move state change listeners
     134                 :            :         {
     135                 :            :             ::cppu::OInterfaceContainerHelper* pStateChangeContainer =
     136                 :          0 :                 m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< embed::XStateChangeListener >*) NULL ) );
     137         [ #  # ]:          0 :             if ( pStateChangeContainer != NULL )
     138                 :            :             {
     139         [ #  # ]:          0 :                 uno::Reference< embed::XStateChangeBroadcaster > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
     140         [ #  # ]:          0 :                 if ( xWrappedObject.is() )
     141                 :            :                 {
     142         [ #  # ]:          0 :                     ::cppu::OInterfaceIteratorHelper pIterator( *pStateChangeContainer );
     143         [ #  # ]:          0 :                     while ( pIterator.hasMoreElements() )
     144                 :            :                     {
     145                 :            :                         try
     146                 :            :                         {
     147 [ #  # ][ #  # ]:          0 :                             xWrappedObject->addStateChangeListener( (embed::XStateChangeListener*)pIterator.next() );
         [ #  # ][ #  # ]
     148                 :            :                         }
     149   [ #  #  #  # ]:          0 :                         catch( const uno::RuntimeException& )
     150                 :            :                         {
     151         [ #  # ]:          0 :                             pIterator.remove();
     152                 :            :                         }
     153         [ #  # ]:          0 :                     }
     154                 :          0 :                 }
     155                 :            :             }
     156                 :            :         }
     157                 :            : 
     158                 :            :         // move event listeners
     159                 :            :         {
     160                 :            :             ::cppu::OInterfaceContainerHelper* pEventContainer =
     161                 :          0 :                 m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< document::XEventListener >*) NULL ) );
     162         [ #  # ]:          0 :             if ( pEventContainer != NULL )
     163                 :            :             {
     164         [ #  # ]:          0 :                 uno::Reference< document::XEventBroadcaster > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
     165         [ #  # ]:          0 :                 if ( xWrappedObject.is() )
     166                 :            :                 {
     167         [ #  # ]:          0 :                     ::cppu::OInterfaceIteratorHelper pIterator( *pEventContainer );
     168         [ #  # ]:          0 :                     while ( pIterator.hasMoreElements() )
     169                 :            :                     {
     170                 :            :                         try
     171                 :            :                         {
     172 [ #  # ][ #  # ]:          0 :                             xWrappedObject->addEventListener( (document::XEventListener*)pIterator.next() );
         [ #  # ][ #  # ]
     173                 :            :                         }
     174   [ #  #  #  # ]:          0 :                         catch( const uno::RuntimeException& )
     175                 :            :                         {
     176         [ #  # ]:          0 :                             pIterator.remove();
     177                 :            :                         }
     178         [ #  # ]:          0 :                     }
     179                 :          0 :                 }
     180                 :            :             }
     181                 :            :         }
     182                 :            : 
     183                 :            :         // move close listeners
     184                 :            :         {
     185                 :            :             ::cppu::OInterfaceContainerHelper* pCloseContainer =
     186                 :          0 :                 m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
     187         [ #  # ]:          0 :             if ( pCloseContainer != NULL )
     188                 :            :             {
     189         [ #  # ]:          0 :                 uno::Reference< util::XCloseBroadcaster > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY );
     190         [ #  # ]:          0 :                 if ( xWrappedObject.is() )
     191                 :            :                 {
     192         [ #  # ]:          0 :                     ::cppu::OInterfaceIteratorHelper pIterator( *pCloseContainer );
     193         [ #  # ]:          0 :                     while ( pIterator.hasMoreElements() )
     194                 :            :                     {
     195                 :            :                         try
     196                 :            :                         {
     197 [ #  # ][ #  # ]:          0 :                             xWrappedObject->addCloseListener( (util::XCloseListener*)pIterator.next() );
         [ #  # ][ #  # ]
     198                 :            :                         }
     199   [ #  #  #  # ]:          0 :                         catch( const uno::RuntimeException& )
     200                 :            :                         {
     201         [ #  # ]:          0 :                             pIterator.remove();
     202                 :            :                         }
     203         [ #  # ]:          0 :                     }
     204                 :          0 :                 }
     205                 :            :             }
     206                 :            :         }
     207                 :            : 
     208         [ #  # ]:          0 :         delete m_pInterfaceContainer;
     209                 :          0 :         m_pInterfaceContainer = NULL;
     210                 :            :     }
     211                 :          0 : }
     212                 :            : 
     213                 :            : //----------------------------------------------
     214                 :          0 : uno::Reference< embed::XStorage > OleEmbeddedObject::CreateTemporarySubstorage( ::rtl::OUString& o_aStorageName )
     215                 :            : {
     216                 :          0 :     uno::Reference< embed::XStorage > xResult;
     217                 :            : 
     218 [ #  # ][ #  # ]:          0 :     for ( sal_Int32 nInd = 0; nInd < 32000 && !xResult.is(); nInd++ )
                 [ #  # ]
     219                 :            :     {
     220                 :          0 :         ::rtl::OUString aName = ::rtl::OUString::valueOf( nInd );
     221         [ #  # ]:          0 :         aName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TMPSTOR" ) );
     222                 :          0 :         aName += m_aEntryName;
     223 [ #  # ][ #  # ]:          0 :         if ( !m_xParentStorage->hasByName( aName ) )
                 [ #  # ]
     224                 :            :         {
     225 [ #  # ][ #  # ]:          0 :             xResult = m_xParentStorage->openStorageElement( aName, embed::ElementModes::READWRITE );
                 [ #  # ]
     226                 :          0 :             o_aStorageName = aName;
     227                 :            :         }
     228                 :          0 :     }
     229                 :            : 
     230         [ #  # ]:          0 :     if ( !xResult.is() )
     231                 :            :     {
     232                 :          0 :         o_aStorageName = ::rtl::OUString();
     233         [ #  # ]:          0 :         throw uno::RuntimeException();
     234                 :            :     }
     235                 :            : 
     236                 :          0 :     return xResult;
     237                 :            : }
     238                 :            : 
     239                 :            : //----------------------------------------------
     240                 :          0 : ::rtl::OUString OleEmbeddedObject::MoveToTemporarySubstream()
     241                 :            : {
     242                 :          0 :     ::rtl::OUString aResult;
     243 [ #  # ][ #  # ]:          0 :     for ( sal_Int32 nInd = 0; nInd < 32000 && aResult.isEmpty(); nInd++ )
                 [ #  # ]
     244                 :            :     {
     245                 :          0 :         ::rtl::OUString aName = ::rtl::OUString::valueOf( nInd );
     246         [ #  # ]:          0 :         aName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TMPSTREAM" ) );
     247                 :          0 :         aName += m_aEntryName;
     248 [ #  # ][ #  # ]:          0 :         if ( !m_xParentStorage->hasByName( aName ) )
                 [ #  # ]
     249                 :            :         {
     250 [ #  # ][ #  # ]:          0 :             m_xParentStorage->renameElement( m_aEntryName, aName );
     251                 :          0 :             aResult = aName;
     252                 :            :         }
     253                 :          0 :     }
     254                 :            : 
     255         [ #  # ]:          0 :     if ( aResult.isEmpty() )
     256         [ #  # ]:          0 :         throw uno::RuntimeException();
     257                 :            : 
     258                 :          0 :     return aResult;
     259                 :            : }
     260                 :            : 
     261                 :            : //----------------------------------------------
     262                 :          0 : sal_Bool OleEmbeddedObject::TryToConvertToOOo()
     263                 :            : {
     264                 :          0 :     sal_Bool bResult = sal_False;
     265                 :            : 
     266                 :          0 :     ::rtl::OUString aStorageName;
     267                 :          0 :     ::rtl::OUString aTmpStreamName;
     268                 :          0 :     sal_Int32 nStep = 0;
     269                 :            : 
     270 [ #  # ][ #  # ]:          0 :     if ( m_pOleComponent || m_bReadOnly )
     271                 :          0 :         return sal_False;
     272                 :            : 
     273                 :            :     try
     274                 :            :     {
     275         [ #  # ]:          0 :         changeState( embed::EmbedStates::LOADED );
     276                 :            : 
     277                 :            :         // the stream must be seekable
     278         [ #  # ]:          0 :         uno::Reference< io::XSeekable > xSeekable( m_xObjectStream, uno::UNO_QUERY_THROW );
     279 [ #  # ][ #  # ]:          0 :         xSeekable->seek( 0 );
     280 [ #  # ][ #  # ]:          0 :         ::rtl::OUString aFilterName = OwnView_Impl::GetFilterNameFromExtentionAndInStream( m_xFactory, ::rtl::OUString(), m_xObjectStream->getInputStream() );
                 [ #  # ]
     281                 :            : 
     282                 :            :         // use the solution only for OOXML format currently
     283 [ #  # ][ #  #  :          0 :         if ( !aFilterName.isEmpty()
          #  #  #  #  #  
                      # ]
     284                 :          0 :           && ( aFilterName == "Calc MS Excel 2007 XML" || aFilterName == "Impress MS PowerPoint 2007 XML" || aFilterName == "MS Word 2007 XML" ) )
     285                 :            :         {
     286                 :            :             uno::Reference< container::XNameAccess > xFilterFactory(
     287         [ #  # ]:          0 :                 m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ) )),
     288 [ #  # ][ #  # ]:          0 :                 uno::UNO_QUERY_THROW );
                 [ #  # ]
     289                 :            : 
     290                 :          0 :             ::rtl::OUString aDocServiceName;
     291 [ #  # ][ #  # ]:          0 :             uno::Any aFilterAnyData = xFilterFactory->getByName( aFilterName );
     292         [ #  # ]:          0 :             uno::Sequence< beans::PropertyValue > aFilterData;
     293 [ #  # ][ #  # ]:          0 :             if ( aFilterAnyData >>= aFilterData )
     294                 :            :             {
     295         [ #  # ]:          0 :                 for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
     296 [ #  # ][ #  # ]:          0 :                     if ( aFilterData[nInd].Name == "DocumentService" )
     297         [ #  # ]:          0 :                         aFilterData[nInd].Value >>= aDocServiceName;
     298                 :            :             }
     299                 :            : 
     300         [ #  # ]:          0 :             if ( !aDocServiceName.isEmpty() )
     301                 :            :             {
     302                 :            :                 // create the model
     303         [ #  # ]:          0 :                 uno::Sequence< uno::Any > aArguments(1);
     304 [ #  # ][ #  # ]:          0 :                 aArguments[0] <<= beans::NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EmbeddedObject" ) ), uno::makeAny( (sal_Bool)sal_True ));
         [ #  # ][ #  # ]
     305                 :            : 
     306 [ #  # ][ #  # ]:          0 :                 uno::Reference< util::XCloseable > xDocument( m_xFactory->createInstanceWithArguments( aDocServiceName, aArguments ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     307         [ #  # ]:          0 :                 uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY_THROW );
     308         [ #  # ]:          0 :                 uno::Reference< document::XStorageBasedDocument > xStorDoc( xDocument, uno::UNO_QUERY_THROW );
     309                 :            : 
     310                 :            :                 // let the model behave as embedded one
     311         [ #  # ]:          0 :                 uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY_THROW );
     312         [ #  # ]:          0 :                 uno::Sequence< beans::PropertyValue > aSeq( 1 );
     313 [ #  # ][ #  # ]:          0 :                 aSeq[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "SetEmbedded" ));
     314 [ #  # ][ #  # ]:          0 :                 aSeq[0].Value <<= sal_True;
     315 [ #  # ][ #  # ]:          0 :                 xModel->attachResource( ::rtl::OUString(), aSeq );
     316                 :            : 
     317                 :            :                 // load the model from the stream
     318         [ #  # ]:          0 :                 uno::Sequence< beans::PropertyValue > aArgs( 5 );
     319 [ #  # ][ #  # ]:          0 :                 aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HierarchicalDocumentName" ));
     320 [ #  # ][ #  # ]:          0 :                 aArgs[0].Value <<= m_aEntryName;
     321 [ #  # ][ #  # ]:          0 :                 aArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ReadOnly" ));
     322 [ #  # ][ #  # ]:          0 :                 aArgs[1].Value <<= sal_True;
     323 [ #  # ][ #  # ]:          0 :                 aArgs[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
     324 [ #  # ][ #  # ]:          0 :                 aArgs[2].Value <<= aFilterName;
     325 [ #  # ][ #  # ]:          0 :                 aArgs[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "URL" ));
     326 [ #  # ][ #  # ]:          0 :                 aArgs[3].Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "private:stream" ));
                 [ #  # ]
     327 [ #  # ][ #  # ]:          0 :                 aArgs[4].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "InputStream" ));
     328 [ #  # ][ #  # ]:          0 :                 aArgs[4].Value <<= m_xObjectStream->getInputStream();
         [ #  # ][ #  # ]
     329                 :            : 
     330 [ #  # ][ #  # ]:          0 :                 xSeekable->seek( 0 );
     331 [ #  # ][ #  # ]:          0 :                 xLoadable->load( aArgs );
     332                 :            : 
     333                 :            :                 // the model is successfuly loaded, create a new storage and store the model to the storage
     334         [ #  # ]:          0 :                 uno::Reference< embed::XStorage > xTmpStorage = CreateTemporarySubstorage( aStorageName );
     335 [ #  # ][ #  # ]:          0 :                 xStorDoc->storeToStorage( xTmpStorage, uno::Sequence< beans::PropertyValue >() );
         [ #  # ][ #  # ]
     336 [ #  # ][ #  # ]:          0 :                 xDocument->close( sal_True );
     337         [ #  # ]:          0 :                 uno::Reference< beans::XPropertySet > xStorProps( xTmpStorage, uno::UNO_QUERY_THROW );
     338                 :          0 :                 ::rtl::OUString aMediaType;
     339 [ #  # ][ #  # ]:          0 :                 xStorProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MediaType" )) ) >>= aMediaType;
                 [ #  # ]
     340 [ #  # ][ #  # ]:          0 :                 xTmpStorage->dispose();
     341                 :            : 
     342                 :            :                 // look for the related embedded object factory
     343         [ #  # ]:          0 :                 ::comphelper::MimeConfigurationHelper aConfigHelper( m_xFactory );
     344                 :          0 :                 ::rtl::OUString aEmbedFactory;
     345         [ #  # ]:          0 :                 if ( !aMediaType.isEmpty() )
     346         [ #  # ]:          0 :                     aEmbedFactory = aConfigHelper.GetFactoryNameByMediaType( aMediaType );
     347                 :            : 
     348         [ #  # ]:          0 :                 if ( aEmbedFactory.isEmpty() )
     349         [ #  # ]:          0 :                     throw uno::RuntimeException();
     350                 :            : 
     351 [ #  # ][ #  # ]:          0 :                 uno::Reference< uno::XInterface > xFact = m_xFactory->createInstance( aEmbedFactory );
     352                 :            : 
     353         [ #  # ]:          0 :                 uno::Reference< embed::XEmbedObjectCreator > xEmbCreator( xFact, uno::UNO_QUERY_THROW );
     354                 :            : 
     355                 :            :                 // now the object should be adjusted to become the wrapper
     356                 :          0 :                 nStep = 1;
     357         [ #  # ]:          0 :                 uno::Reference< lang::XComponent > xComp( m_xObjectStream, uno::UNO_QUERY_THROW );
     358 [ #  # ][ #  # ]:          0 :                 xComp->dispose();
     359         [ #  # ]:          0 :                 m_xObjectStream = uno::Reference< io::XStream >();
     360                 :          0 :                 m_nObjectState = -1;
     361                 :            : 
     362                 :          0 :                 nStep = 2;
     363         [ #  # ]:          0 :                 aTmpStreamName = MoveToTemporarySubstream();
     364                 :            : 
     365                 :          0 :                 nStep = 3;
     366 [ #  # ][ #  # ]:          0 :                 m_xParentStorage->renameElement( aStorageName, m_aEntryName );
     367                 :            : 
     368                 :          0 :                 nStep = 4;
     369 [ #  # ][ #  # ]:          0 :                 m_xWrappedObject.set( xEmbCreator->createInstanceInitFromEntry( m_xParentStorage, m_aEntryName, uno::Sequence< beans::PropertyValue >(), uno::Sequence< beans::PropertyValue >() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     370                 :            : 
     371                 :          0 :                 bResult = sal_True; // the change is no more revertable
     372                 :            :                 try
     373                 :            :                 {
     374 [ #  # ][ #  # ]:          0 :                     m_xParentStorage->removeElement( aTmpStreamName );
     375                 :            :                 }
     376         [ #  # ]:          0 :                 catch( const uno::Exception& )
     377                 :            :                 {
     378                 :            :                     // the success of the removing is not so important
     379 [ #  # ][ #  # ]:          0 :                 }
         [ #  # ][ #  # ]
     380         [ #  # ]:          0 :             }
     381         [ #  # ]:          0 :         }
     382                 :            :     }
     383   [ #  #  #  # ]:          0 :     catch( const uno::Exception& )
     384                 :            :     {
     385                 :            :         // repair the object if necessary
     386   [ #  #  #  # ]:          0 :         switch( nStep )
     387                 :            :         {
     388                 :            :             case 4:
     389                 :            :             case 3:
     390   [ #  #  #  #  :          0 :             if ( !aTmpStreamName.isEmpty() && aTmpStreamName != m_aEntryName )
                   #  # ]
     391                 :            :                 try
     392                 :            :                 {
     393   [ #  #  #  #  :          0 :                     if ( m_xParentStorage->hasByName( m_aEntryName ) )
                   #  # ]
     394   [ #  #  #  # ]:          0 :                         m_xParentStorage->removeElement( m_aEntryName );
     395   [ #  #  #  # ]:          0 :                     m_xParentStorage->renameElement( aTmpStreamName, m_aEntryName );
     396                 :            :                 }
     397         [ #  # ]:          0 :                 catch ( const uno::Exception& )
     398                 :            :                 {
     399                 :            :                     try {
     400         [ #  # ]:          0 :                         close( sal_True );
     401         [ #  # ]:          0 :                     } catch( const uno::Exception& ) {}
     402                 :            : 
     403   [ #  #  #  # ]:          0 :                     m_xParentStorage->dispose(); // ??? the storage has information loss, it should be closed without commiting!
     404         [ #  # ]:          0 :                     throw uno::RuntimeException(); // the repairing is not possible
     405                 :            :                 }
     406                 :            :             case 2:
     407                 :            :                 try
     408                 :            :                 {
     409   [ #  #  #  #  :          0 :                     m_xObjectStream = m_xParentStorage->openStreamElement( m_aEntryName, m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE );
          #  #  #  #  #  
                      # ]
     410                 :          0 :                     m_nObjectState = embed::EmbedStates::LOADED;
     411                 :            :                 }
     412         [ #  # ]:          0 :                 catch( const uno::Exception& )
     413                 :            :                 {
     414                 :            :                     try {
     415         [ #  # ]:          0 :                         close( sal_True );
     416         [ #  # ]:          0 :                     } catch( const uno::Exception& ) {}
     417                 :            : 
     418   [ #  #  #  # ]:          0 :                     throw uno::RuntimeException(); // the repairing is not possible
     419                 :            :                 }
     420                 :            :                 // no break as designed!
     421                 :            : 
     422                 :            :             case 1:
     423                 :            :             case 0:
     424         [ #  # ]:          0 :                 if ( !aStorageName.isEmpty() )
     425                 :            :                     try {
     426   [ #  #  #  # ]:          0 :                         m_xParentStorage->removeElement( aStorageName );
     427         [ #  # ]:          0 :                     } catch( const uno::Exception& ) { OSL_FAIL( "Can not remove temporary storage!" ); }
     428                 :          0 :                 break;
     429                 :            :         }
     430                 :            :     }
     431                 :            : 
     432         [ #  # ]:          0 :     if ( bResult )
     433                 :            :     {
     434                 :            :         // the conversion was done successfuly, now the additional initializations should happen
     435                 :            : 
     436         [ #  # ]:          0 :         MoveListeners();
     437 [ #  # ][ #  # ]:          0 :         m_xWrappedObject->setClientSite( m_xClientSite );
     438         [ #  # ]:          0 :         if ( m_xParent.is() )
     439                 :            :         {
     440         [ #  # ]:          0 :             uno::Reference< container::XChild > xChild( m_xWrappedObject, uno::UNO_QUERY );
     441         [ #  # ]:          0 :             if ( xChild.is() )
     442 [ #  # ][ #  # ]:          0 :                 xChild->setParent( m_xParent );
     443                 :            :         }
     444                 :            : 
     445                 :            :     }
     446                 :            : 
     447                 :          0 :     return bResult;
     448                 :            : }
     449                 :            : 
     450                 :            : //----------------------------------------------
     451                 :          0 : void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState )
     452                 :            :         throw ( embed::UnreachableStateException,
     453                 :            :                 embed::WrongStateException,
     454                 :            :                 uno::Exception,
     455                 :            :                 uno::RuntimeException )
     456                 :            : {
     457                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::changeState" );
     458                 :            : 
     459                 :            :     // begin wrapping related part ====================
     460                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     461         [ #  # ]:          0 :     if ( xWrappedObject.is() )
     462                 :            :     {
     463                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
     464 [ #  # ][ #  # ]:          0 :         xWrappedObject->changeState( nNewState );
     465                 :            :         return;
     466                 :            :     }
     467                 :            :     // end wrapping related part ====================
     468                 :            : 
     469         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aGuard( m_aMutex );
     470                 :            : 
     471         [ #  # ]:          0 :     if ( m_bDisposed )
     472         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     473                 :            : 
     474         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     475                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     476 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     477                 :            : 
     478                 :            :     // in case the object is already in requested state
     479         [ #  # ]:          0 :     if ( m_nObjectState == nNewState )
     480                 :            :         return;
     481                 :            : 
     482                 :            : #ifdef WNT
     483                 :            :     if ( m_pOleComponent )
     484                 :            :     {
     485                 :            :         if ( m_nTargetState != -1 )
     486                 :            :         {
     487                 :            :             // means that the object is currently trying to reach the target state
     488                 :            :             throw embed::StateChangeInProgressException( ::rtl::OUString(),
     489                 :            :                                                         uno::Reference< uno::XInterface >(),
     490                 :            :                                                         m_nTargetState );
     491                 :            :         }
     492                 :            : 
     493                 :            :         TargetStateControl_Impl aControl( m_nTargetState, nNewState );
     494                 :            : 
     495                 :            :         // TODO: additional verbs can be a problem, since nobody knows how the object
     496                 :            :         //       will behave after activation
     497                 :            : 
     498                 :            :         sal_Int32 nOldState = m_nObjectState;
     499                 :            :         aGuard.clear();
     500                 :            :         StateChangeNotification_Impl( sal_True, nOldState, nNewState );
     501                 :            :         aGuard.reset();
     502                 :            : 
     503                 :            :         try
     504                 :            :         {
     505                 :            :             if ( nNewState == embed::EmbedStates::LOADED )
     506                 :            :             {
     507                 :            :                 // This means just closing of the current object
     508                 :            :                 // If component can not be closed the object stays in loaded state
     509                 :            :                 // and it holds reference to "incomplete" component
     510                 :            :                 // If the object is switched to running state later
     511                 :            :                 // the component will become "complete"
     512                 :            : 
     513                 :            :                 // the loaded state must be set before, because of notifications!
     514                 :            :                 m_nObjectState = nNewState;
     515                 :            : 
     516                 :            :                 {
     517                 :            :                     VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController );
     518                 :            :                     m_pOleComponent->CloseObject();
     519                 :            :                 }
     520                 :            : 
     521                 :            :                 aGuard.clear();
     522                 :            :                 StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState );
     523                 :            :                 aGuard.reset();
     524                 :            :             }
     525                 :            :             else if ( nNewState == embed::EmbedStates::RUNNING || nNewState == embed::EmbedStates::ACTIVE )
     526                 :            :             {
     527                 :            :                 if ( m_nObjectState == embed::EmbedStates::LOADED )
     528                 :            :                 {
     529                 :            :                     // if the target object is in loaded state and a different state is specified
     530                 :            :                     // as a new one the object first must be switched to running state.
     531                 :            : 
     532                 :            :                     // the component can exist already in nonrunning state
     533                 :            :                     // it can be created during loading to detect type of object
     534                 :            :                     CreateOleComponentAndLoad_Impl( m_pOleComponent );
     535                 :            : 
     536                 :            :                     SwitchComponentToRunningState_Impl();
     537                 :            :                     m_nObjectState = embed::EmbedStates::RUNNING;
     538                 :            :                     aGuard.clear();
     539                 :            :                     StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState );
     540                 :            :                     aGuard.reset();
     541                 :            : 
     542                 :            :                     if ( m_pOleComponent && m_bHasSizeToSet )
     543                 :            :                     {
     544                 :            :                         aGuard.clear();
     545                 :            :                         try {
     546                 :            :                             m_pOleComponent->SetExtent( m_aSizeToSet, m_nAspectToSet );
     547                 :            :                             m_bHasSizeToSet = sal_False;
     548                 :            :                         }
     549                 :            :                         catch( const uno::Exception& ) {}
     550                 :            :                         aGuard.reset();
     551                 :            :                     }
     552                 :            : 
     553                 :            :                     if ( m_nObjectState == nNewState )
     554                 :            :                         return;
     555                 :            :                 }
     556                 :            : 
     557                 :            :                 // so now the object is either switched from Active to Running state or vise versa
     558                 :            :                 // the notification about object state change will be done asynchronously
     559                 :            :                 if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE )
     560                 :            :                 {
     561                 :            :                     // execute OPEN verb, if object does not reach active state it is an object's problem
     562                 :            :                     aGuard.clear();
     563                 :            :                     m_pOleComponent->ExecuteVerb( embed::EmbedVerbs::MS_OLEVERB_OPEN );
     564                 :            :                     aGuard.reset();
     565                 :            : 
     566                 :            :                     // some objects do not allow to set the size even in running state
     567                 :            :                     if ( m_pOleComponent && m_bHasSizeToSet )
     568                 :            :                     {
     569                 :            :                         aGuard.clear();
     570                 :            :                         try {
     571                 :            :                             m_pOleComponent->SetExtent( m_aSizeToSet, m_nAspectToSet );
     572                 :            :                             m_bHasSizeToSet = sal_False;
     573                 :            :                         }
     574                 :            :                         catch( uno::Exception& ) {}
     575                 :            :                         aGuard.reset();
     576                 :            :                     }
     577                 :            : 
     578                 :            :                     m_nObjectState = nNewState;
     579                 :            :                 }
     580                 :            :                 else if ( m_nObjectState == embed::EmbedStates::ACTIVE && nNewState == embed::EmbedStates::RUNNING )
     581                 :            :                 {
     582                 :            :                     aGuard.clear();
     583                 :            :                     m_pOleComponent->CloseObject();
     584                 :            :                     m_pOleComponent->RunObject(); // Should not fail, the object already was active
     585                 :            :                     aGuard.reset();
     586                 :            :                     m_nObjectState = nNewState;
     587                 :            :                 }
     588                 :            :                 else
     589                 :            :                 {
     590                 :            :                     throw embed::UnreachableStateException();
     591                 :            :                 }
     592                 :            :             }
     593                 :            :             else
     594                 :            :                 throw embed::UnreachableStateException();
     595                 :            :         }
     596                 :            :         catch( uno::Exception& )
     597                 :            :         {
     598                 :            :             aGuard.clear();
     599                 :            :             StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState );
     600                 :            :             throw;
     601                 :            :         }
     602                 :            :     }
     603                 :            :     else
     604                 :            : #endif
     605                 :            :     {
     606         [ #  # ]:          0 :         throw embed::UnreachableStateException();
     607         [ #  # ]:          0 :     }
     608                 :            : }
     609                 :            : 
     610                 :            : //----------------------------------------------
     611                 :          0 : uno::Sequence< sal_Int32 > SAL_CALL OleEmbeddedObject::getReachableStates()
     612                 :            :         throw ( embed::WrongStateException,
     613                 :            :                 uno::RuntimeException )
     614                 :            : {
     615                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getReachableStates" );
     616                 :            : 
     617                 :            :     // begin wrapping related part ====================
     618                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     619         [ #  # ]:          0 :     if ( xWrappedObject.is() )
     620                 :            :     {
     621                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
     622 [ #  # ][ #  # ]:          0 :         return xWrappedObject->getReachableStates();
     623                 :            :     }
     624                 :            :     // end wrapping related part ====================
     625                 :            : 
     626         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     627         [ #  # ]:          0 :     if ( m_bDisposed )
     628         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     629                 :            : 
     630         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     631                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     632 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     633                 :            : 
     634                 :            : #ifdef WNT
     635                 :            :     if ( m_pOleComponent )
     636                 :            :     {
     637                 :            :         if ( m_nObjectState == embed::EmbedStates::LOADED )
     638                 :            :         {
     639                 :            :             // the list of supported verbs can be retrieved only when object is in running state
     640                 :            :             throw embed::NeedsRunningStateException(); // TODO:
     641                 :            :         }
     642                 :            : 
     643                 :            :         // the list of states can only be guessed based on standard verbs,
     644                 :            :         // since there is no way to detect what additional verbs do
     645                 :            :         return GetReachableStatesList_Impl( m_pOleComponent->GetVerbList() );
     646                 :            :     }
     647                 :            :     else
     648                 :            : #endif
     649                 :            :     {
     650         [ #  # ]:          0 :         return uno::Sequence< sal_Int32 >();
     651         [ #  # ]:          0 :     }
     652                 :            : }
     653                 :            : 
     654                 :            : //----------------------------------------------
     655                 :          0 : sal_Int32 SAL_CALL OleEmbeddedObject::getCurrentState()
     656                 :            :         throw ( embed::WrongStateException,
     657                 :            :                 uno::RuntimeException )
     658                 :            : {
     659                 :            :     // begin wrapping related part ====================
     660                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     661         [ #  # ]:          0 :     if ( xWrappedObject.is() )
     662                 :            :     {
     663                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
     664 [ #  # ][ #  # ]:          0 :         return xWrappedObject->getCurrentState();
     665                 :            :     }
     666                 :            :     // end wrapping related part ====================
     667                 :            : 
     668         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     669         [ #  # ]:          0 :     if ( m_bDisposed )
     670         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     671                 :            : 
     672         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     673                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     674 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     675                 :            : 
     676                 :            :     // TODO: Shouldn't we ask object? ( I guess no )
     677         [ #  # ]:          0 :     return m_nObjectState;
     678                 :            : }
     679                 :            : 
     680                 :            : namespace
     681                 :            : {
     682                 :          0 :     bool lcl_CopyStream(uno::Reference<io::XInputStream> xIn, uno::Reference<io::XOutputStream> xOut)
     683                 :            :     {
     684                 :          0 :         const sal_Int32 nChunkSize = 4096;
     685         [ #  # ]:          0 :         uno::Sequence< sal_Int8 > aData(nChunkSize);
     686                 :          0 :         sal_Int32 nTotalRead = 0;
     687                 :            :         sal_Int32 nRead;
     688         [ #  # ]:          0 :         do
     689                 :            :         {
     690 [ #  # ][ #  # ]:          0 :             nRead = xIn->readBytes(aData, nChunkSize);
     691                 :          0 :             nTotalRead += nRead;
     692 [ #  # ][ #  # ]:          0 :             xOut->writeBytes(aData);
     693                 :            :         } while (nRead == nChunkSize);
     694         [ #  # ]:          0 :         return nTotalRead != 0;
     695                 :            :     }
     696                 :            : 
     697                 :            :     //Dump the objects content to a tempfile, just the "CONTENTS" stream if
     698                 :            :     //there is one for non-compound documents, otherwise the whole content.
     699                 :            :     //On success a file is returned which must be removed by the caller
     700                 :          0 :     rtl::OUString lcl_ExtractObject(::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory,
     701                 :            :         ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xObjectStream)
     702                 :            :     {
     703                 :          0 :         rtl::OUString sUrl;
     704                 :            : 
     705                 :            :         // the solution is only active for Unix systems
     706                 :            : #ifndef WNT
     707                 :            :         uno::Reference <beans::XPropertySet> xNativeTempFile(
     708         [ #  # ]:          0 :             xFactory->createInstance(
     709 [ #  # ][ #  # ]:          0 :                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile"))), uno::UNO_QUERY_THROW);
                 [ #  # ]
     710         [ #  # ]:          0 :         uno::Reference < io::XStream > xStream(xNativeTempFile, uno::UNO_QUERY_THROW);
     711                 :            : 
     712         [ #  # ]:          0 :         uno::Sequence< uno::Any > aArgs( 2 );
     713 [ #  # ][ #  # ]:          0 :         aArgs[0] <<= xObjectStream;
     714 [ #  # ][ #  # ]:          0 :         aArgs[1] <<= (sal_Bool)sal_True; // do not create copy
     715                 :            :         uno::Reference< container::XNameContainer > xNameContainer(
     716         [ #  # ]:          0 :             xFactory->createInstanceWithArguments(
     717                 :            :                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OLESimpleStorage")),
     718 [ #  # ][ #  # ]:          0 :                 aArgs ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     719                 :            : 
     720                 :          0 :         uno::Reference< io::XStream > xCONTENTS;
     721 [ #  # ][ #  # ]:          0 :         xNameContainer->getByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CONTENTS"))) >>= xCONTENTS;
         [ #  # ][ #  # ]
     722                 :            : 
     723 [ #  # ][ #  # ]:          0 :         sal_Bool bCopied = xCONTENTS.is() && lcl_CopyStream(xCONTENTS->getInputStream(), xStream->getOutputStream());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     724                 :            : 
     725         [ #  # ]:          0 :         uno::Reference< io::XSeekable > xSeekableStor(xObjectStream, uno::UNO_QUERY);
     726         [ #  # ]:          0 :         if (xSeekableStor.is())
     727 [ #  # ][ #  # ]:          0 :             xSeekableStor->seek(0);
     728                 :            : 
     729         [ #  # ]:          0 :         if (!bCopied)
     730 [ #  # ][ #  # ]:          0 :             bCopied = lcl_CopyStream(xObjectStream->getInputStream(), xStream->getOutputStream());
         [ #  # ][ #  # ]
                 [ #  # ]
     731                 :            : 
     732         [ #  # ]:          0 :         if (bCopied)
     733                 :            :         {
     734         [ #  # ]:          0 :             xNativeTempFile->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile")),
     735 [ #  # ][ #  # ]:          0 :                 uno::makeAny(sal_False));
                 [ #  # ]
     736 [ #  # ][ #  # ]:          0 :             uno::Any aUrl = xNativeTempFile->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Uri")));
                 [ #  # ]
     737                 :          0 :             aUrl >>= sUrl;
     738                 :            : 
     739         [ #  # ]:          0 :             xNativeTempFile = uno::Reference<beans::XPropertySet>();
     740                 :            : 
     741                 :            :             uno::Reference < ucb::XSimpleFileAccess2 > xSimpleFileAccess(
     742 [ #  # ][ #  # ]:          0 :                     ucb::SimpleFileAccess::create( comphelper::ComponentContext(xFactory).getUNOContext() ) );
         [ #  # ][ #  # ]
     743                 :            : 
     744 [ #  # ][ #  # ]:          0 :             xSimpleFileAccess->setReadOnly(sUrl, sal_True);
     745                 :            :         }
     746                 :            :         else
     747                 :            :         {
     748         [ #  # ]:          0 :             xNativeTempFile->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile")),
     749 [ #  # ][ #  # ]:          0 :                 uno::makeAny(sal_True));
                 [ #  # ]
     750                 :            :         }
     751                 :            : #else
     752                 :            :         (void) xFactory;
     753                 :            :         (void) xObjectStream;
     754                 :            : #endif
     755         [ #  # ]:          0 :         return sUrl;
     756                 :            :     }
     757                 :            : }
     758                 :            : 
     759                 :            : //----------------------------------------------
     760                 :          0 : void SAL_CALL OleEmbeddedObject::doVerb( sal_Int32 nVerbID )
     761                 :            :         throw ( lang::IllegalArgumentException,
     762                 :            :                 embed::WrongStateException,
     763                 :            :                 embed::UnreachableStateException,
     764                 :            :                 uno::Exception,
     765                 :            :                 uno::RuntimeException )
     766                 :            : {
     767                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::doVerb" );
     768                 :            : 
     769                 :            :     // begin wrapping related part ====================
     770                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     771         [ #  # ]:          0 :     if ( xWrappedObject.is() )
     772                 :            :     {
     773                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
     774 [ #  # ][ #  # ]:          0 :         xWrappedObject->doVerb( nVerbID );
     775                 :            :         return;
     776                 :            :     }
     777                 :            :     // end wrapping related part ====================
     778                 :            : 
     779         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aGuard( m_aMutex );
     780         [ #  # ]:          0 :     if ( m_bDisposed )
     781         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     782                 :            : 
     783         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     784                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     785 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     786                 :            : 
     787                 :            : #ifdef WNT
     788                 :            :     if ( m_pOleComponent )
     789                 :            :     {
     790                 :            :         sal_Int32 nOldState = m_nObjectState;
     791                 :            : 
     792                 :            :         // TODO/LATER detect target state here and do a notification
     793                 :            :         // StateChangeNotification_Impl( sal_True, nOldState, nNewState );
     794                 :            :         if ( m_nObjectState == embed::EmbedStates::LOADED )
     795                 :            :         {
     796                 :            :             // if the target object is in loaded state
     797                 :            :             // it must be switched to running state to execute verb
     798                 :            :             aGuard.clear();
     799                 :            :             changeState( embed::EmbedStates::RUNNING );
     800                 :            :             aGuard.reset();
     801                 :            :         }
     802                 :            : 
     803                 :            :         try {
     804                 :            :             if ( !m_pOleComponent )
     805                 :            :                 throw uno::RuntimeException();
     806                 :            : 
     807                 :            :             // ==== the STAMPIT related solution =============================
     808                 :            :             m_aVerbExecutionController.StartControlExecution();
     809                 :            :             // ===============================================================
     810                 :            : 
     811                 :            :             m_pOleComponent->ExecuteVerb( nVerbID );
     812                 :            : 
     813                 :            :             // ==== the STAMPIT related solution =============================
     814                 :            :             sal_Bool bModifiedOnExecution = m_aVerbExecutionController.EndControlExecution_WasModified();
     815                 :            : 
     816                 :            :             // this workaround is implemented for STAMPIT object
     817                 :            :             // if object was modified during verb execution it is saved here
     818                 :            :             if ( bModifiedOnExecution && m_pOleComponent->IsDirty() )
     819                 :            :                 SaveObject_Impl();
     820                 :            :             // ===============================================================
     821                 :            :         }
     822                 :            :         catch( uno::Exception& )
     823                 :            :         {
     824                 :            :             // ==== the STAMPIT related solution =============================
     825                 :            :             m_aVerbExecutionController.EndControlExecution_WasModified();
     826                 :            :             // ===============================================================
     827                 :            : 
     828                 :            :             aGuard.clear();
     829                 :            :             StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState );
     830                 :            :             throw;
     831                 :            :         }
     832                 :            : 
     833                 :            :     }
     834                 :            :     else
     835                 :            : #endif
     836                 :            :     {
     837         [ #  # ]:          0 :         if ( nVerbID == -9 )
     838                 :            :         {
     839                 :            :             // the workaround verb to show the object in case no server is available
     840                 :            : 
     841                 :            :             // if it is possible, the object will be converted to OOo format
     842         [ #  # ]:          0 :             if ( !m_bTriedConversion )
     843                 :            :             {
     844                 :          0 :                 m_bTriedConversion = sal_True;
     845 [ #  # ][ #  # ]:          0 :                 if ( TryToConvertToOOo() )
     846                 :            :                 {
     847         [ #  # ]:          0 :                     changeState( embed::EmbedStates::UI_ACTIVE );
     848                 :            :                     return;
     849                 :            :                 }
     850                 :            :             }
     851                 :            : 
     852 [ #  # ][ #  # ]:          0 :             if ( !m_pOwnView && m_xObjectStream.is() )
                 [ #  # ]
     853                 :            :             {
     854                 :            :                 try {
     855         [ #  # ]:          0 :                     uno::Reference< io::XSeekable > xSeekable( m_xObjectStream, uno::UNO_QUERY );
     856         [ #  # ]:          0 :                     if ( xSeekable.is() )
     857 [ #  # ][ #  # ]:          0 :                         xSeekable->seek( 0 );
     858                 :            : 
     859 [ #  # ][ #  # ]:          0 :                     m_pOwnView = new OwnView_Impl( m_xFactory, m_xObjectStream->getInputStream() );
                 [ #  # ]
     860                 :          0 :                     m_pOwnView->acquire();
     861                 :            :                 }
     862      [ #  #  # ]:          0 :                 catch( uno::RuntimeException& )
     863                 :            :                 {
     864                 :          0 :                     throw;
     865                 :            :                 }
     866         [ #  # ]:          0 :                 catch( uno::Exception& )
     867                 :            :                 {
     868                 :            :                 }
     869                 :            :             }
     870                 :            : 
     871 [ #  # ][ #  # ]:          0 :             if ( !m_pOwnView || !m_pOwnView->Open() )
         [ #  # ][ #  # ]
     872                 :            :             {
     873                 :            :                 //Make a RO copy and see if the OS can find something to at
     874                 :            :                 //least display the content for us
     875         [ #  # ]:          0 :                 if (m_aTempDumpURL.isEmpty())
     876         [ #  # ]:          0 :                     m_aTempDumpURL = lcl_ExtractObject(m_xFactory, m_xObjectStream);
     877                 :            : 
     878         [ #  # ]:          0 :                 if (!m_aTempDumpURL.isEmpty())
     879                 :            :                 {
     880         [ #  # ]:          0 :                     uno::Reference< ::com::sun::star::system::XSystemShellExecute > xSystemShellExecute( m_xFactory->createInstance(
     881                 :          0 :                         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.system.SystemShellExecute"))),
     882 [ #  # ][ #  # ]:          0 :                         uno::UNO_QUERY_THROW);
                 [ #  # ]
     883 [ #  # ][ #  # ]:          0 :                     xSystemShellExecute->execute(m_aTempDumpURL, ::rtl::OUString(), ::com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY);
     884                 :            :                 }
     885                 :            :                 else
     886         [ #  # ]:          0 :                     throw embed::UnreachableStateException();
     887                 :            :             }
     888                 :            :         }
     889                 :            :         else
     890                 :            :         {
     891                 :            : 
     892         [ #  # ]:          0 :             throw embed::UnreachableStateException();
     893                 :            :         }
     894 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     895                 :            : }
     896                 :            : 
     897                 :            : //----------------------------------------------
     898                 :          0 : uno::Sequence< embed::VerbDescriptor > SAL_CALL OleEmbeddedObject::getSupportedVerbs()
     899                 :            :         throw ( embed::WrongStateException,
     900                 :            :                 uno::RuntimeException )
     901                 :            : {
     902                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getSupportedVerb" );
     903                 :            : 
     904                 :            :     // begin wrapping related part ====================
     905                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     906         [ #  # ]:          0 :     if ( xWrappedObject.is() )
     907                 :            :     {
     908                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
     909 [ #  # ][ #  # ]:          0 :         return xWrappedObject->getSupportedVerbs();
     910                 :            :     }
     911                 :            :     // end wrapping related part ====================
     912                 :            : 
     913         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     914         [ #  # ]:          0 :     if ( m_bDisposed )
     915         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     916                 :            : 
     917         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     918                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     919 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     920                 :            : #ifdef WNT
     921                 :            :     if ( m_pOleComponent )
     922                 :            :     {
     923                 :            :         // registry could be used in this case
     924                 :            :         // if ( m_nObjectState == embed::EmbedStates::LOADED )
     925                 :            :         // {
     926                 :            :         //  // the list of supported verbs can be retrieved only when object is in running state
     927                 :            :         //  throw embed::NeedsRunningStateException(); // TODO:
     928                 :            :         // }
     929                 :            : 
     930                 :            :         return m_pOleComponent->GetVerbList();
     931                 :            :     }
     932                 :            :     else
     933                 :            : #endif
     934                 :            :     {
     935         [ #  # ]:          0 :         return uno::Sequence< embed::VerbDescriptor >();
     936         [ #  # ]:          0 :     }
     937                 :            : }
     938                 :            : 
     939                 :            : //----------------------------------------------
     940                 :          0 : void SAL_CALL OleEmbeddedObject::setClientSite(
     941                 :            :                 const uno::Reference< embed::XEmbeddedClient >& xClient )
     942                 :            :         throw ( embed::WrongStateException,
     943                 :            :                 uno::RuntimeException )
     944                 :            : {
     945                 :            :     // begin wrapping related part ====================
     946                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     947         [ #  # ]:          0 :     if ( xWrappedObject.is() )
     948                 :            :     {
     949                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
     950 [ #  # ][ #  # ]:          0 :         xWrappedObject->setClientSite( xClient );
     951                 :          0 :         return;
     952                 :            :     }
     953                 :            :     // end wrapping related part ====================
     954                 :            : 
     955         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     956         [ #  # ]:          0 :     if ( m_bDisposed )
     957         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     958                 :            : 
     959 [ #  # ][ #  # ]:          0 :     if ( m_xClientSite != xClient)
     960                 :            :     {
     961 [ #  # ][ #  # ]:          0 :         if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING )
     962                 :            :             throw embed::WrongStateException(
     963                 :            :                                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The client site can not be set currently!\n" )),
     964 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     965                 :            : 
     966         [ #  # ]:          0 :         m_xClientSite = xClient;
     967 [ #  # ][ #  # ]:          0 :     }
     968                 :            : }
     969                 :            : 
     970                 :            : //----------------------------------------------
     971                 :          0 : uno::Reference< embed::XEmbeddedClient > SAL_CALL OleEmbeddedObject::getClientSite()
     972                 :            :         throw ( embed::WrongStateException,
     973                 :            :                 uno::RuntimeException )
     974                 :            : {
     975                 :            :     // begin wrapping related part ====================
     976                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     977         [ #  # ]:          0 :     if ( xWrappedObject.is() )
     978                 :            :     {
     979                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
     980 [ #  # ][ #  # ]:          0 :         return xWrappedObject->getClientSite();
     981                 :            :     }
     982                 :            :     // end wrapping related part ====================
     983                 :            : 
     984         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     985         [ #  # ]:          0 :     if ( m_bDisposed )
     986         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     987                 :            : 
     988         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     989                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     990 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     991                 :            : 
     992         [ #  # ]:          0 :     return m_xClientSite;
     993                 :            : }
     994                 :            : 
     995                 :            : //----------------------------------------------
     996                 :          0 : void SAL_CALL OleEmbeddedObject::update()
     997                 :            :         throw ( embed::WrongStateException,
     998                 :            :                 uno::Exception,
     999                 :            :                 uno::RuntimeException )
    1000                 :            : {
    1001                 :            :     // begin wrapping related part ====================
    1002                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
    1003         [ #  # ]:          0 :     if ( xWrappedObject.is() )
    1004                 :            :     {
    1005                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
    1006 [ #  # ][ #  # ]:          0 :         xWrappedObject->update();
    1007                 :          0 :         return;
    1008                 :            :     }
    1009                 :            :     // end wrapping related part ====================
    1010                 :            : 
    1011         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1012         [ #  # ]:          0 :     if ( m_bDisposed )
    1013         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
    1014                 :            : 
    1015         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
    1016                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
    1017 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
    1018                 :            : 
    1019                 :          0 :     if ( m_nUpdateMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE )
    1020                 :            :     {
    1021                 :            :         // TODO: update view representation
    1022                 :            :     }
    1023                 :            :     else
    1024                 :            :     {
    1025                 :            :         // the object must be up to date
    1026                 :            :         OSL_ENSURE( m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE, "Unknown update mode!\n" );
    1027 [ #  # ][ #  # ]:          0 :     }
    1028                 :            : }
    1029                 :            : 
    1030                 :            : //----------------------------------------------
    1031                 :          0 : void SAL_CALL OleEmbeddedObject::setUpdateMode( sal_Int32 nMode )
    1032                 :            :         throw ( embed::WrongStateException,
    1033                 :            :                 uno::RuntimeException )
    1034                 :            : {
    1035                 :            :     // begin wrapping related part ====================
    1036                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
    1037         [ #  # ]:          0 :     if ( xWrappedObject.is() )
    1038                 :            :     {
    1039                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
    1040 [ #  # ][ #  # ]:          0 :         xWrappedObject->setUpdateMode( nMode );
    1041                 :          0 :         return;
    1042                 :            :     }
    1043                 :            :     // end wrapping related part ====================
    1044                 :            : 
    1045         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1046         [ #  # ]:          0 :     if ( m_bDisposed )
    1047         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
    1048                 :            : 
    1049         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
    1050                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
    1051 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
    1052                 :            : 
    1053                 :            :     OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE
    1054                 :            :                     || nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE,
    1055                 :            :                 "Unknown update mode!\n" );
    1056 [ #  # ][ #  # ]:          0 :     m_nUpdateMode = nMode;
    1057                 :            : }
    1058                 :            : 
    1059                 :            : //----------------------------------------------
    1060                 :          0 : sal_Int64 SAL_CALL OleEmbeddedObject::getStatus( sal_Int64
    1061                 :            :     nAspect
    1062                 :            : )
    1063                 :            :         throw ( embed::WrongStateException,
    1064                 :            :                 uno::RuntimeException )
    1065                 :            : {
    1066                 :            :     // begin wrapping related part ====================
    1067                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
    1068         [ #  # ]:          0 :     if ( xWrappedObject.is() )
    1069                 :            :     {
    1070                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
    1071 [ #  # ][ #  # ]:          0 :         return xWrappedObject->getStatus( nAspect );
    1072                 :            :     }
    1073                 :            :     // end wrapping related part ====================
    1074                 :            : 
    1075         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1076         [ #  # ]:          0 :     if ( m_bDisposed )
    1077         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
    1078                 :            : 
    1079         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
    1080                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object must be in running state!\n" )),
    1081 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
    1082                 :            : 
    1083                 :          0 :     sal_Int64 nResult = 0;
    1084                 :            : 
    1085                 :            : #ifdef WNT
    1086                 :            :     if ( m_bGotStatus && m_nStatusAspect == nAspect )
    1087                 :            :         nResult = m_nStatus;
    1088                 :            :     else if ( m_pOleComponent )
    1089                 :            :     {
    1090                 :            : 
    1091                 :            :         m_nStatus = m_pOleComponent->GetMiscStatus( nAspect );
    1092                 :            :         m_nStatusAspect = nAspect;
    1093                 :            :         m_bGotStatus = sal_True;
    1094                 :            :         nResult = m_nStatus;
    1095                 :            :     }
    1096                 :            : #endif
    1097                 :            : 
    1098                 :            :     // this implementation needs size to be provided after object loading/creating to work in optimal way
    1099         [ #  # ]:          0 :     return ( nResult | embed::EmbedMisc::EMBED_NEEDSSIZEONLOAD );
    1100                 :            : }
    1101                 :            : 
    1102                 :            : //----------------------------------------------
    1103                 :          0 : void SAL_CALL OleEmbeddedObject::setContainerName( const ::rtl::OUString& sName )
    1104                 :            :         throw ( uno::RuntimeException )
    1105                 :            : {
    1106                 :            :     // begin wrapping related part ====================
    1107                 :          0 :     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
    1108         [ #  # ]:          0 :     if ( xWrappedObject.is() )
    1109                 :            :     {
    1110                 :            :         // the object was converted to OOo embedded object, the current implementation is now only a wrapper
    1111 [ #  # ][ #  # ]:          0 :         xWrappedObject->setContainerName( sName );
    1112                 :          0 :         return;
    1113                 :            :     }
    1114                 :            :     // end wrapping related part ====================
    1115                 :            : 
    1116         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1117         [ #  # ]:          0 :     if ( m_bDisposed )
    1118         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
    1119                 :            : 
    1120 [ #  # ][ #  # ]:          0 :     m_aContainerName = sName;
    1121                 :            : }
    1122                 :            : 
    1123                 :            : 
    1124                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10