LCOV - code coverage report
Current view: top level - embeddedobj/source/commonembedding - embedobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 184 286 64.3 %
Date: 2012-08-25 Functions: 15 20 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 184 595 30.9 %

           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/EmbedStates.hpp>
      30                 :            : #include <com/sun/star/embed/EmbedVerbs.hpp>
      31                 :            : #include <com/sun/star/embed/EmbedUpdateModes.hpp>
      32                 :            : #include <com/sun/star/embed/XEmbeddedClient.hpp>
      33                 :            : #include <com/sun/star/embed/XInplaceClient.hpp>
      34                 :            : #include <com/sun/star/embed/XWindowSupplier.hpp>
      35                 :            : #include <com/sun/star/embed/StateChangeInProgressException.hpp>
      36                 :            : #include <com/sun/star/embed/Aspects.hpp>
      37                 :            : 
      38                 :            : #include <com/sun/star/awt/XWindowPeer.hpp>
      39                 :            : #include <com/sun/star/util/XCloseBroadcaster.hpp>
      40                 :            : #include <com/sun/star/util/XCloseable.hpp>
      41                 :            : #include <com/sun/star/util/XModifiable.hpp>
      42                 :            : #include <com/sun/star/frame/XFrame.hpp>
      43                 :            : #include <com/sun/star/frame/XComponentLoader.hpp>
      44                 :            : #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
      45                 :            : #include <com/sun/star/frame/XModuleManager.hpp>
      46                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      47                 :            : 
      48                 :            : #include <com/sun/star/embed/EmbedMisc.hpp>
      49                 :            : 
      50                 :            : #include <rtl/logfile.hxx>
      51                 :            : 
      52                 :            : #include <targetstatecontrol.hxx>
      53                 :            : 
      54                 :            : #include "commonembobj.hxx"
      55                 :            : #include "intercept.hxx"
      56                 :            : 
      57                 :            : 
      58                 :            : using namespace ::com::sun::star;
      59                 :            : 
      60                 :         10 : awt::Rectangle GetRectangleInterception( const awt::Rectangle& aRect1, const awt::Rectangle& aRect2 )
      61                 :            : {
      62                 :         10 :     awt::Rectangle aResult;
      63                 :            : 
      64                 :            :     OSL_ENSURE( aRect1.Width >= 0 && aRect2.Width >= 0 && aRect1.Height >= 0 && aRect2.Height >= 0,
      65                 :            :                 "Offset must not be less then zero!" );
      66                 :            : 
      67         [ -  + ]:         10 :     aResult.X = aRect1.X > aRect2.X ? aRect1.X : aRect2.X;
      68         [ -  + ]:         10 :     aResult.Y = aRect1.Y > aRect2.Y ? aRect1.Y : aRect2.Y;
      69                 :            : 
      70                 :         10 :     sal_Int32 nRight1 = aRect1.X + aRect1.Width;
      71                 :         10 :     sal_Int32 nBottom1 = aRect1.Y + aRect1.Height;
      72                 :         10 :     sal_Int32 nRight2 = aRect2.X + aRect2.Width;
      73                 :         10 :     sal_Int32 nBottom2 = aRect2.Y + aRect2.Height;
      74         [ -  + ]:         10 :     aResult.Width = ( nRight1 < nRight2 ? nRight1 : nRight2 ) - aResult.X;
      75         [ -  + ]:         10 :     aResult.Height = ( nBottom1 < nBottom2 ? nBottom1 : nBottom2 ) - aResult.Y;
      76                 :            : 
      77                 :         10 :     return aResult;
      78                 :            : }
      79                 :            : 
      80                 :            : //----------------------------------------------
      81                 :          2 : sal_Int32 OCommonEmbeddedObject::ConvertVerbToState_Impl( sal_Int32 nVerb )
      82                 :            : {
      83         [ +  - ]:          4 :     for ( sal_Int32 nInd = 0; nInd < m_aVerbTable.getLength(); nInd++ )
      84         [ +  + ]:          4 :         if ( m_aVerbTable[nInd][0] == nVerb )
      85                 :          2 :             return m_aVerbTable[nInd][1];
      86                 :            : 
      87         [ #  # ]:          0 :     throw lang::IllegalArgumentException(); // TODO: unexpected verb provided
      88                 :            : }
      89                 :            : 
      90                 :            : //----------------------------------------------
      91                 :          2 : void OCommonEmbeddedObject::Deactivate()
      92                 :            : {
      93 [ +  - ][ +  - ]:          2 :     uno::Reference< util::XModifiable > xModif( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
      94                 :            : 
      95                 :            :     // no need to lock for the initialization
      96                 :          2 :     uno::Reference< embed::XEmbeddedClient > xClientSite = m_xClientSite;
      97         [ -  + ]:          2 :     if ( !xClientSite.is() )
      98         [ #  # ]:          0 :         throw embed::WrongStateException(); //TODO: client site is not set!
      99                 :            : 
     100                 :            :     // store document if it is modified
     101 [ +  - ][ +  - ]:          2 :     if ( xModif.is() && xModif->isModified() )
         [ +  - ][ +  - ]
                 [ +  - ]
     102                 :            :     {
     103                 :            :         try {
     104 [ +  - ][ +  - ]:          2 :             xClientSite->saveObject();
     105                 :            :         }
     106         [ #  # ]:          0 :         catch( const embed::ObjectSaveVetoException& )
     107                 :            :         {
     108                 :            :         }
     109      [ #  #  # ]:          0 :         catch( const uno::Exception& e )
     110                 :            :         {
     111                 :            :             throw embed::StorageWrappedTargetException(
     112                 :            :                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The client could not store the object!" )),
     113                 :            :                 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ),
     114   [ #  #  #  #  :          0 :                 uno::makeAny( e ) );
             #  #  #  # ]
     115                 :            :         }
     116                 :            :     }
     117                 :            : 
     118         [ +  - ]:          2 :     m_pDocHolder->CloseFrame();
     119                 :            : 
     120 [ +  - ][ +  - ]:          2 :     xClientSite->visibilityChanged( sal_False );
     121                 :          2 : }
     122                 :            : 
     123                 :            : //----------------------------------------------
     124                 :        806 : void OCommonEmbeddedObject::StateChangeNotification_Impl( sal_Bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState ,::osl::ResettableMutexGuard& rGuard )
     125                 :            : {
     126         [ +  - ]:        806 :     if ( m_pInterfaceContainer )
     127                 :            :     {
     128                 :            :         ::cppu::OInterfaceContainerHelper* pContainer = m_pInterfaceContainer->getContainer(
     129                 :        806 :                             ::getCppuType( ( const uno::Reference< embed::XStateChangeListener >*) NULL ) );
     130         [ +  - ]:        806 :         if ( pContainer != NULL )
     131                 :            :         {
     132 [ +  - ][ +  - ]:        806 :             lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
                 [ #  # ]
     133         [ +  - ]:        806 :             ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
     134                 :            : 
     135                 :            :             // should be locked after the method is finished successfully
     136         [ +  - ]:        806 :             rGuard.clear();
     137                 :            : 
     138         [ +  + ]:        986 :             while (pIterator.hasMoreElements())
     139                 :            :             {
     140                 :            :                 try
     141                 :            :                 {
     142         [ +  + ]:        180 :                     if ( bBeforeChange )
     143 [ +  - ][ +  - ]:         90 :                         ((embed::XStateChangeListener*)pIterator.next())->changingState( aSource, nOldState, nNewState );
     144                 :            :                     else
     145 [ +  - ][ +  - ]:         90 :                         ((embed::XStateChangeListener*)pIterator.next())->stateChanged( aSource, nOldState, nNewState );
     146                 :            :                 }
     147         [ #  # ]:          0 :                 catch( const uno::Exception& )
     148                 :            :                 {
     149                 :            :                     // even if the listener complains ignore it for now
     150                 :            :                    }
     151                 :            : 
     152         [ -  + ]:        180 :                 if ( m_bDisposed )
     153                 :        806 :                     return;
     154                 :            :             }
     155                 :            : 
     156 [ +  - ][ +  - ]:        806 :             rGuard.reset();
         [ -  + ][ +  - ]
                 [ +  - ]
     157                 :            :         }
     158                 :            :     }
     159                 :            : }
     160                 :            : 
     161                 :            : //----------------------------------------------
     162                 :        407 : void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 nNextState )
     163                 :            : {
     164                 :            :     // TODO: may be needs interaction handler to detect wherether the object state
     165                 :            :     //         can be changed even after errors
     166                 :            : 
     167         [ -  + ]:        407 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
     168                 :            :     {
     169         [ #  # ]:          0 :         if ( nNextState == embed::EmbedStates::RUNNING )
     170                 :            :         {
     171                 :            :             // after the object reaches the running state the cloned size is not necessary any more
     172                 :          0 :             m_bHasClonedSize = sal_False;
     173                 :            : 
     174         [ #  # ]:          0 :             if ( m_bIsLink )
     175                 :            :             {
     176         [ #  # ]:          0 :                 m_pDocHolder->SetComponent( LoadLink_Impl(), m_bReadOnly );
     177                 :            :             }
     178                 :            :             else
     179                 :            :             {
     180         [ #  # ]:          0 :                 uno::Reference < embed::XEmbedPersist > xPersist( static_cast < embed::XClassifiedObject* > (this), uno::UNO_QUERY );
     181         [ #  # ]:          0 :                 if ( xPersist.is() )
     182                 :            :                 {
     183                 :            :                     // in case embedded object is in loaded state the contents must
     184                 :            :                     // be stored in the related storage and the storage
     185                 :            :                     // must be created already
     186         [ #  # ]:          0 :                     if ( !m_xObjectStorage.is() )
     187         [ #  # ]:          0 :                         throw io::IOException(); //TODO: access denied
     188                 :            : 
     189 [ #  # ][ #  # ]:          0 :                     m_pDocHolder->SetComponent( LoadDocumentFromStorage_Impl(), m_bReadOnly );
     190                 :            :                 }
     191                 :            :                 else
     192                 :            :                 {
     193                 :            :                     // objects without persistence will be initialized internally
     194         [ #  # ]:          0 :                     uno::Sequence < uno::Any > aArgs(1);
     195 [ #  # ][ #  # ]:          0 :                     aArgs[0] <<= uno::Reference < embed::XEmbeddedObject >( this );
                 [ #  # ]
     196                 :            :                     uno::Reference< util::XCloseable > xDocument(
     197 [ #  # ][ #  # ]:          0 :                             m_xFactory->createInstanceWithArguments( GetDocumentServiceName(), aArgs ), uno::UNO_QUERY );
                 [ #  # ]
     198                 :            : 
     199         [ #  # ]:          0 :                     uno::Reference < container::XChild > xChild( xDocument, uno::UNO_QUERY );
     200         [ #  # ]:          0 :                     if ( xChild.is() )
     201 [ #  # ][ #  # ]:          0 :                         xChild->setParent( m_xParent );
     202                 :            : 
     203 [ #  # ][ #  # ]:          0 :                     m_pDocHolder->SetComponent( xDocument, m_bReadOnly );
     204                 :          0 :                 }
     205                 :            :             }
     206                 :            : 
     207         [ #  # ]:          0 :             if ( !m_pDocHolder->GetComponent().is() )
     208         [ #  # ]:          0 :                 throw embed::UnreachableStateException(); //TODO: can't open document
     209                 :            : 
     210                 :          0 :             m_nObjectState = nNextState;
     211                 :            :         }
     212                 :            :         else
     213                 :            :         {
     214                 :            :             OSL_FAIL( "Unacceptable state switch!\n" );
     215         [ #  # ]:          0 :             throw uno::RuntimeException(); // TODO
     216                 :            :         }
     217                 :            :     }
     218         [ +  + ]:        407 :     else if ( m_nObjectState == embed::EmbedStates::RUNNING )
     219                 :            :     {
     220         [ +  + ]:        401 :         if ( nNextState == embed::EmbedStates::LOADED )
     221                 :            :         {
     222                 :        399 :             m_nClonedMapUnit = m_pDocHolder->GetMapUnit( embed::Aspects::MSOLE_CONTENT );
     223                 :        399 :             m_bHasClonedSize = m_pDocHolder->GetExtent( embed::Aspects::MSOLE_CONTENT, &m_aClonedSize );
     224                 :            : 
     225                 :            :             // actually frame should not exist at this point
     226                 :        399 :             m_pDocHolder->CloseDocument( sal_False, sal_False );
     227                 :            : 
     228                 :        399 :             m_nObjectState = nNextState;
     229                 :            :         }
     230                 :            :         else
     231                 :            :         {
     232         [ +  - ]:          2 :             if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
     233                 :            :             {
     234         [ -  + ]:          2 :                 if ( !m_xClientSite.is() )
     235                 :            :                     throw embed::WrongStateException(
     236                 :            :                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "client site not set, yet" ) ),
     237                 :            :                         *this
     238 [ #  # ][ #  # ]:          0 :                 );
                 [ #  # ]
     239                 :            : 
     240         [ +  - ]:          2 :                 uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
     241 [ +  - ][ +  - ]:          2 :                 if ( xInplaceClient.is() && xInplaceClient->canInplaceActivate() )
         [ +  - ][ +  - ]
                 [ +  - ]
     242                 :            :                 {
     243 [ +  - ][ +  - ]:          2 :                     xInplaceClient->activatingInplace();
     244                 :            : 
     245         [ +  - ]:          2 :                     uno::Reference< embed::XWindowSupplier > xClientWindowSupplier( xInplaceClient, uno::UNO_QUERY );
     246         [ -  + ]:          2 :                     if ( !xClientWindowSupplier.is() )
     247         [ #  # ]:          0 :                         throw uno::RuntimeException(); // TODO: the inplace client implementation must support XWinSupp
     248                 :            : 
     249 [ +  - ][ +  - ]:          2 :                     m_xClientWindow = xClientWindowSupplier->getWindow();
                 [ +  - ]
     250 [ +  - ][ +  - ]:          2 :                     m_aOwnRectangle = xInplaceClient->getPlacement();
     251 [ +  - ][ +  - ]:          2 :                     m_aClipRectangle = xInplaceClient->getClipRectangle();
     252                 :          2 :                     awt::Rectangle aRectangleToShow = GetRectangleInterception( m_aOwnRectangle, m_aClipRectangle );
     253                 :            : 
     254                 :            :                     // create own window based on the client window
     255                 :            :                     // place and resize the window according to the rectangles
     256         [ +  - ]:          2 :                     uno::Reference< awt::XWindowPeer > xClientWindowPeer( m_xClientWindow, uno::UNO_QUERY );
     257         [ -  + ]:          2 :                     if ( !xClientWindowPeer.is() )
     258         [ #  # ]:          0 :                         throw uno::RuntimeException(); // TODO: the container window must support the interface
     259                 :            : 
     260                 :            :                     // dispatch provider may not be provided
     261 [ +  - ][ +  - ]:          2 :                     uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
     262         [ +  - ]:          2 :                     sal_Bool bOk = m_pDocHolder->ShowInplace( xClientWindowPeer, aRectangleToShow, xContainerDP );
     263                 :          2 :                     m_nObjectState = nNextState;
     264         [ -  + ]:          2 :                     if ( !bOk )
     265                 :            :                     {
     266         [ #  # ]:          0 :                         SwitchStateTo_Impl( embed::EmbedStates::RUNNING );
     267         [ #  # ]:          0 :                         throw embed::WrongStateException(); //TODO: can't activate inplace
     268                 :          2 :                     }
     269                 :            :                 }
     270                 :            :                 else
     271         [ #  # ]:          2 :                     throw embed::WrongStateException(); //TODO: can't activate inplace
     272                 :            :             }
     273         [ #  # ]:          0 :             else if ( nNextState == embed::EmbedStates::ACTIVE )
     274                 :            :             {
     275         [ #  # ]:          0 :                 if ( !m_xClientSite.is() )
     276         [ #  # ]:          0 :                     throw embed::WrongStateException(); //TODO: client site is not set!
     277                 :            : 
     278                 :            :                 // create frame and load document in the frame
     279                 :          0 :                 m_pDocHolder->Show();
     280                 :            : 
     281                 :          0 :                 m_xClientSite->visibilityChanged( sal_True );
     282                 :          0 :                 m_nObjectState = nNextState;
     283                 :            :             }
     284                 :            :             else
     285                 :            :             {
     286                 :            :                 OSL_FAIL( "Unacceptable state switch!\n" );
     287         [ #  # ]:          0 :                 throw uno::RuntimeException(); // TODO
     288                 :            :             }
     289                 :            :         }
     290                 :            :     }
     291         [ +  + ]:          6 :     else if ( m_nObjectState == embed::EmbedStates::INPLACE_ACTIVE )
     292                 :            :     {
     293         [ +  + ]:          4 :         if ( nNextState == embed::EmbedStates::RUNNING )
     294                 :            :         {
     295         [ +  - ]:          2 :             uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
     296         [ -  + ]:          2 :             if ( !xInplaceClient.is() )
     297         [ #  # ]:          0 :                 throw uno::RuntimeException();
     298                 :            : 
     299 [ +  - ][ +  - ]:          2 :             m_xClientSite->visibilityChanged( sal_True );
     300                 :            : 
     301 [ +  - ][ +  - ]:          2 :             xInplaceClient->deactivatedInplace();
     302         [ +  - ]:          2 :             Deactivate();
     303                 :          2 :             m_nObjectState = nNextState;
     304                 :            :         }
     305         [ +  - ]:          2 :         else if ( nNextState == embed::EmbedStates::UI_ACTIVE )
     306                 :            :         {
     307         [ +  - ]:          2 :             if ( !(m_nMiscStatus & embed::EmbedMisc::MS_EMBED_NOUIACTIVATE) )
     308                 :            :             {
     309         [ +  - ]:          2 :                 uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW );
     310                 :            :                 // TODO:
     311                 :            :                 uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM =
     312 [ +  - ][ +  - ]:          2 :                             xInplaceClient->getLayoutManager();
     313         [ +  - ]:          2 :                 if ( xContainerLM.is() )
     314                 :            :                 {
     315                 :            :                     // dispatch provider may not be provided
     316 [ +  - ][ +  - ]:          2 :                     uno::Reference< frame::XDispatchProvider > xContainerDP = xInplaceClient->getInplaceDispatchProvider();
     317                 :            : 
     318                 :            :                     // get the container module name
     319                 :          2 :                     ::rtl::OUString aModuleName;
     320                 :            :                     try
     321                 :            :                     {
     322         [ +  - ]:          2 :                         uno::Reference< embed::XComponentSupplier > xCompSupl( m_xClientSite, uno::UNO_QUERY_THROW );
     323 [ +  - ][ +  - ]:          2 :                         uno::Reference< uno::XInterface > xContDoc( xCompSupl->getComponent(), uno::UNO_QUERY_THROW );
                 [ +  - ]
     324                 :            : 
     325                 :            :                         uno::Reference< frame::XModuleManager > xManager(
     326         [ +  - ]:          2 :                             m_xFactory->createInstance(
     327                 :          2 :                                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ModuleManager" ) ) ),
     328 [ +  - ][ +  - ]:          2 :                             uno::UNO_QUERY_THROW );
                 [ +  - ]
     329                 :            : 
     330 [ +  - ][ #  # ]:          2 :                         aModuleName = xManager->identify( xContDoc );
                 [ +  - ]
     331                 :            :                     }
     332         [ #  # ]:          0 :                     catch( const uno::Exception& )
     333                 :            :                     {}
     334                 :            : 
     335                 :            :                     // if currently another object is UIactive it will be deactivated; usually this will activate the LM of
     336                 :            :                     // the container. Locking the LM will prevent flicker.
     337 [ +  - ][ +  - ]:          2 :                     xContainerLM->lock();
     338 [ +  - ][ +  - ]:          2 :                     xInplaceClient->activatingUI();
     339         [ +  - ]:          2 :                     sal_Bool bOk = m_pDocHolder->ShowUI( xContainerLM, xContainerDP, aModuleName );
     340 [ +  - ][ +  - ]:          2 :                     xContainerLM->unlock();
     341                 :            : 
     342         [ +  - ]:          2 :                     if ( bOk )
     343                 :            :                     {
     344                 :          2 :                         m_nObjectState = nNextState;
     345         [ +  - ]:          2 :                         m_pDocHolder->ResizeHatchWindow();
     346                 :            :                     }
     347                 :            :                     else
     348                 :            :                     {
     349 [ #  # ][ #  # ]:          0 :                         xInplaceClient->deactivatedUI();
     350         [ #  # ]:          0 :                         throw embed::WrongStateException(); //TODO: can't activate UI
     351                 :          2 :                     }
     352                 :            :                 }
     353                 :            :                 else
     354         [ #  # ]:          2 :                     throw embed::WrongStateException(); //TODO: can't activate UI
     355                 :            :             }
     356                 :            :         }
     357                 :            :         else
     358                 :            :         {
     359                 :            :             OSL_FAIL( "Unacceptable state switch!\n" );
     360         [ #  # ]:          0 :             throw uno::RuntimeException(); // TODO
     361                 :            :         }
     362                 :            :     }
     363         [ -  + ]:          2 :     else if ( m_nObjectState == embed::EmbedStates::ACTIVE )
     364                 :            :     {
     365         [ #  # ]:          0 :         if ( nNextState == embed::EmbedStates::RUNNING )
     366                 :            :         {
     367                 :          0 :             Deactivate();
     368                 :          0 :             m_nObjectState = nNextState;
     369                 :            :         }
     370                 :            :         else
     371                 :            :         {
     372                 :            :             OSL_FAIL( "Unacceptable state switch!\n" );
     373         [ #  # ]:          0 :             throw uno::RuntimeException(); // TODO
     374                 :            :         }
     375                 :            :     }
     376         [ +  - ]:          2 :     else if ( m_nObjectState == embed::EmbedStates::UI_ACTIVE )
     377                 :            :     {
     378         [ +  - ]:          2 :         if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
     379                 :            :         {
     380         [ +  - ]:          2 :             uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY_THROW );
     381                 :            :             uno::Reference< ::com::sun::star::frame::XLayoutManager > xContainerLM =
     382 [ +  - ][ +  - ]:          2 :                         xInplaceClient->getLayoutManager();
     383                 :            : 
     384                 :          2 :             sal_Bool bOk = sal_False;
     385         [ +  - ]:          2 :             if ( xContainerLM.is() )
     386         [ +  - ]:          2 :                    bOk = m_pDocHolder->HideUI( xContainerLM );
     387                 :            : 
     388         [ +  - ]:          2 :             if ( bOk )
     389                 :            :             {
     390                 :          2 :                 m_nObjectState = nNextState;
     391         [ +  - ]:          2 :                 m_pDocHolder->ResizeHatchWindow();
     392 [ +  - ][ +  - ]:          2 :                    xInplaceClient->deactivatedUI();
     393                 :            :             }
     394                 :            :             else
     395         [ #  # ]:          2 :                 throw embed::WrongStateException(); //TODO: can't activate UI
     396                 :            :         }
     397                 :            :     }
     398                 :            :     else
     399                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object is in unacceptable state!\n" )),
     400 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     401                 :        407 : }
     402                 :            : 
     403                 :            : //----------------------------------------------
     404                 :        403 : uno::Sequence< sal_Int32 > OCommonEmbeddedObject::GetIntermediateStatesSequence_Impl( sal_Int32 nNewState )
     405                 :            : {
     406                 :        403 :     sal_Int32 nCurInd = 0;
     407         [ +  - ]:        810 :     for ( nCurInd = 0; nCurInd < m_aAcceptedStates.getLength(); nCurInd++ )
     408         [ +  + ]:        810 :         if ( m_aAcceptedStates[nCurInd] == m_nObjectState )
     409                 :        403 :             break;
     410                 :            : 
     411         [ -  + ]:        403 :     if ( nCurInd == m_aAcceptedStates.getLength() )
     412                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object is in unacceptable state!\n" )),
     413 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     414                 :            : 
     415                 :        403 :     sal_Int32 nDestInd = 0;
     416         [ +  - ]:        411 :     for ( nDestInd = 0; nDestInd < m_aAcceptedStates.getLength(); nDestInd++ )
     417         [ +  + ]:        411 :         if ( m_aAcceptedStates[nDestInd] == nNewState )
     418                 :        403 :             break;
     419                 :            : 
     420         [ -  + ]:        403 :     if ( nDestInd == m_aAcceptedStates.getLength() )
     421                 :            :         throw embed::UnreachableStateException(
     422                 :            :             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The state either not reachable, or the object allows the state only as an intermediate one!\n" )),
     423                 :            :             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
     424                 :            :             m_nObjectState,
     425 [ #  # ][ #  # ]:          0 :             nNewState );
                 [ #  # ]
     426                 :            : 
     427                 :        403 :     return m_pIntermediateStatesSeqs[nCurInd][nDestInd];
     428                 :            : }
     429                 :            : 
     430                 :            : //----------------------------------------------
     431                 :        408 : void SAL_CALL OCommonEmbeddedObject::changeState( sal_Int32 nNewState )
     432                 :            :         throw ( embed::UnreachableStateException,
     433                 :            :                 embed::WrongStateException,
     434                 :            :                 uno::Exception,
     435                 :            :                 uno::RuntimeException )
     436                 :            : {
     437                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::changeState" );
     438                 :            : 
     439                 :        408 :     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ), uno::UNO_QUERY);
     440                 :            :     {
     441         [ +  - ]:        408 :         ::osl::ResettableMutexGuard aGuard( m_aMutex );
     442         [ -  + ]:        408 :         if ( m_bDisposed )
     443         [ #  # ]:          0 :             throw lang::DisposedException(); // TODO
     444                 :            : 
     445         [ -  + ]:        408 :         if ( m_nObjectState == -1 )
     446                 :            :             throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     447 [ #  # ][ #  # ]:          0 :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     448                 :            : 
     449                 :        408 :         sal_Int32 nOldState = m_nObjectState;
     450                 :            : 
     451         [ -  + ]:        408 :         if ( m_nTargetState != -1 )
     452                 :            :         {
     453                 :            :             // means that the object is currently trying to reach the target state
     454                 :            :             throw embed::StateChangeInProgressException( ::rtl::OUString(),
     455                 :            :                                                         uno::Reference< uno::XInterface >(),
     456         [ #  # ]:          0 :                                                         m_nTargetState );
     457                 :            :         }
     458                 :            :         else
     459                 :            :         {
     460                 :        408 :             TargetStateControl_Impl aControl( m_nTargetState, nNewState );
     461                 :            : 
     462                 :            :             // in case the object is already in requested state
     463         [ +  + ]:        408 :             if ( m_nObjectState == nNewState )
     464                 :            :             {
     465                 :            :                 // if active object is activated again, bring it's window to top
     466         [ -  + ]:          5 :                 if ( m_nObjectState == embed::EmbedStates::ACTIVE )
     467         [ #  # ]:          5 :                     m_pDocHolder->Show();
     468                 :            : 
     469                 :        408 :                 return;
     470                 :            :             }
     471                 :            : 
     472                 :            :             // retrieve sequence of states that should be passed to reach desired state
     473         [ +  - ]:        403 :             uno::Sequence< sal_Int32 > aIntermediateStates = GetIntermediateStatesSequence_Impl( nNewState );
     474                 :            : 
     475                 :            :             // notify listeners that the object is going to change the state
     476         [ +  - ]:        403 :             StateChangeNotification_Impl( sal_True, nOldState, nNewState,aGuard );
     477                 :            : 
     478                 :            :             try {
     479         [ +  + ]:        407 :                 for ( sal_Int32 nInd = 0; nInd < aIntermediateStates.getLength(); nInd++ )
     480 [ +  - ][ +  - ]:          4 :                     SwitchStateTo_Impl( aIntermediateStates[nInd] );
     481                 :            : 
     482         [ +  - ]:        403 :                 SwitchStateTo_Impl( nNewState );
     483                 :            :             }
     484         [ #  # ]:          0 :             catch( const uno::Exception& )
     485                 :            :             {
     486         [ #  # ]:          0 :                 if ( nOldState != m_nObjectState )
     487                 :            :                     // notify listeners that the object has changed the state
     488         [ #  # ]:          0 :                     StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState, aGuard );
     489                 :            : 
     490                 :          0 :                 throw;
     491 [ +  - ][ +  + ]:        408 :             }
     492                 :            :         }
     493                 :            : 
     494                 :            :         // notify listeners that the object has changed the state
     495         [ +  - ]:        408 :         StateChangeNotification_Impl( sal_False, nOldState, nNewState, aGuard );
     496                 :            : 
     497                 :            :         // let the object window be shown
     498 [ +  + ][ -  + ]:        403 :         if ( nNewState == embed::EmbedStates::UI_ACTIVE || nNewState == embed::EmbedStates::INPLACE_ACTIVE )
     499 [ +  - ][ +  - ]:        408 :             PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ) );
         [ +  - ][ +  + ]
     500                 :            :     }
     501                 :            : }
     502                 :            : 
     503                 :            : //----------------------------------------------
     504                 :          0 : uno::Sequence< sal_Int32 > SAL_CALL OCommonEmbeddedObject::getReachableStates()
     505                 :            :         throw ( embed::WrongStateException,
     506                 :            :                 uno::RuntimeException )
     507                 :            : {
     508         [ #  # ]:          0 :     if ( m_bDisposed )
     509         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     510                 :            : 
     511         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     512                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     513 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     514                 :            : 
     515                 :          0 :     return m_aAcceptedStates;
     516                 :            : }
     517                 :            : 
     518                 :            : //----------------------------------------------
     519                 :       9639 : sal_Int32 SAL_CALL OCommonEmbeddedObject::getCurrentState()
     520                 :            :         throw ( embed::WrongStateException,
     521                 :            :                 uno::RuntimeException )
     522                 :            : {
     523         [ -  + ]:       9639 :     if ( m_bDisposed )
     524         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     525                 :            : 
     526         [ -  + ]:       9639 :     if ( m_nObjectState == -1 )
     527                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     528 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     529                 :            : 
     530                 :       9639 :     return m_nObjectState;
     531                 :            : }
     532                 :            : 
     533                 :            : //----------------------------------------------
     534                 :          2 : void SAL_CALL OCommonEmbeddedObject::doVerb( sal_Int32 nVerbID )
     535                 :            :         throw ( lang::IllegalArgumentException,
     536                 :            :                 embed::WrongStateException,
     537                 :            :                 embed::UnreachableStateException,
     538                 :            :                 uno::Exception,
     539                 :            :                 uno::RuntimeException )
     540                 :            : {
     541                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::doVerb" );
     542                 :            : 
     543         [ +  - ]:          2 :     ::osl::ResettableMutexGuard aGuard( m_aMutex );
     544         [ -  + ]:          2 :     if ( m_bDisposed )
     545         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     546                 :            : 
     547         [ -  + ]:          2 :     if ( m_nObjectState == -1 )
     548                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     549 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
         [ #  # ][ #  # ]
     550                 :            : 
     551                 :            :     // for internal documents this call is just a duplicate of changeState
     552                 :          2 :     sal_Int32 nNewState = -1;
     553                 :            :     try
     554                 :            :     {
     555         [ +  - ]:          2 :         nNewState = ConvertVerbToState_Impl( nVerbID );
     556                 :            :     }
     557         [ #  # ]:          0 :     catch( const uno::Exception& )
     558                 :            :     {}
     559                 :            : 
     560         [ +  - ]:          2 :     if ( nNewState == -1 )
     561                 :            :     {
     562                 :            :         // TODO/LATER: Save Copy as... verb ( -8 ) is implemented by container
     563                 :            :         // TODO/LATER: check if the verb is a supported one and if it is produce related operation
     564                 :            :     }
     565                 :            :     else
     566                 :            :     {
     567         [ +  - ]:          2 :         aGuard.clear();
     568         [ +  - ]:          2 :         changeState( nNewState );
     569         [ +  - ]:          2 :     }
     570                 :          2 : }
     571                 :            : 
     572                 :            : //----------------------------------------------
     573                 :          0 : uno::Sequence< embed::VerbDescriptor > SAL_CALL OCommonEmbeddedObject::getSupportedVerbs()
     574                 :            :         throw ( embed::WrongStateException,
     575                 :            :                 uno::RuntimeException )
     576                 :            : {
     577         [ #  # ]:          0 :     if ( m_bDisposed )
     578         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     579                 :            : 
     580         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     581                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     582 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     583                 :            : 
     584                 :          0 :     return m_aObjectVerbs;
     585                 :            : }
     586                 :            : 
     587                 :            : //----------------------------------------------
     588                 :         22 : void SAL_CALL OCommonEmbeddedObject::setClientSite(
     589                 :            :                 const uno::Reference< embed::XEmbeddedClient >& xClient )
     590                 :            :         throw ( embed::WrongStateException,
     591                 :            :                 uno::RuntimeException )
     592                 :            : {
     593         [ +  - ]:         22 :     ::osl::MutexGuard aGuard( m_aMutex );
     594         [ -  + ]:         22 :     if ( m_bDisposed )
     595         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     596                 :            : 
     597 [ +  - ][ +  + ]:         22 :     if ( m_xClientSite != xClient)
     598                 :            :     {
     599 [ +  - ][ -  + ]:          4 :         if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING )
     600                 :            :             throw embed::WrongStateException(
     601                 :            :                                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The client site can not be set currently!\n" )),
     602 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     603                 :            : 
     604         [ +  - ]:          4 :         m_xClientSite = xClient;
     605         [ +  - ]:         22 :     }
     606                 :         22 : }
     607                 :            : 
     608                 :            : //----------------------------------------------
     609                 :        186 : uno::Reference< embed::XEmbeddedClient > SAL_CALL OCommonEmbeddedObject::getClientSite()
     610                 :            :         throw ( embed::WrongStateException,
     611                 :            :                 uno::RuntimeException )
     612                 :            : {
     613         [ -  + ]:        186 :     if ( m_bDisposed )
     614         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     615                 :            : 
     616         [ -  + ]:        186 :     if ( m_nObjectState == -1 )
     617                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     618 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     619                 :            : 
     620                 :        186 :     return m_xClientSite;
     621                 :            : }
     622                 :            : 
     623                 :            : //----------------------------------------------
     624                 :          0 : void SAL_CALL OCommonEmbeddedObject::update()
     625                 :            :         throw ( embed::WrongStateException,
     626                 :            :                 uno::Exception,
     627                 :            :                 uno::RuntimeException )
     628                 :            : {
     629         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     630         [ #  # ]:          0 :     if ( m_bDisposed )
     631         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     632                 :            : 
     633         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     634                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     635 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     636                 :            : 
     637 [ #  # ][ #  # ]:          0 :     PostEvent_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) ) );
                 [ #  # ]
     638                 :          0 : }
     639                 :            : 
     640                 :            : //----------------------------------------------
     641                 :          0 : void SAL_CALL OCommonEmbeddedObject::setUpdateMode( sal_Int32 nMode )
     642                 :            :         throw ( embed::WrongStateException,
     643                 :            :                 uno::RuntimeException )
     644                 :            : {
     645         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     646         [ #  # ]:          0 :     if ( m_bDisposed )
     647         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     648                 :            : 
     649         [ #  # ]:          0 :     if ( m_nObjectState == -1 )
     650                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The object has no persistence!\n" )),
     651 [ #  # ][ #  # ]:          0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     652                 :            : 
     653                 :            :     OSL_ENSURE( nMode == embed::EmbedUpdateModes::ALWAYS_UPDATE
     654                 :            :                     || nMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE,
     655                 :            :                 "Unknown update mode!\n" );
     656         [ #  # ]:          0 :     m_nUpdateMode = nMode;
     657                 :          0 : }
     658                 :            : 
     659                 :            : //----------------------------------------------
     660                 :       1374 : sal_Int64 SAL_CALL OCommonEmbeddedObject::getStatus( sal_Int64 )
     661                 :            :         throw ( embed::WrongStateException,
     662                 :            :                 uno::RuntimeException )
     663                 :            : {
     664         [ -  + ]:       1374 :     if ( m_bDisposed )
     665         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     666                 :            : 
     667                 :       1374 :     return m_nMiscStatus;
     668                 :            : }
     669                 :            : 
     670                 :            : //----------------------------------------------
     671                 :          0 : void SAL_CALL OCommonEmbeddedObject::setContainerName( const ::rtl::OUString& sName )
     672                 :            :         throw ( uno::RuntimeException )
     673                 :            : {
     674         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
     675         [ #  # ]:          0 :     if ( m_bDisposed )
     676         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     677                 :            : 
     678         [ #  # ]:          0 :     m_aContainerName = sName;
     679                 :          0 : }
     680                 :            : 
     681                 :       1745 : com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL OCommonEmbeddedObject::getParent() throw (::com::sun::star::uno::RuntimeException)
     682                 :            : {
     683                 :       1745 :     return m_xParent;
     684                 :            : }
     685                 :            : 
     686                 :        890 : void SAL_CALL OCommonEmbeddedObject::setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& xParent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException)
     687                 :            : {
     688                 :        890 :     m_xParent = xParent;
     689 [ +  + ][ +  - ]:        890 :     if ( m_nObjectState != -1 && m_nObjectState != embed::EmbedStates::LOADED )
     690                 :            :     {
     691 [ +  - ][ +  - ]:        885 :         uno::Reference < container::XChild > xChild( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
     692         [ +  - ]:        885 :         if ( xChild.is() )
     693 [ +  - ][ +  - ]:        885 :             xChild->setParent( xParent );
     694                 :            :     }
     695                 :        890 : }
     696                 :            : 
     697                 :            : // XDefaultSizeTransmitter
     698                 :          2 : void SAL_CALL OCommonEmbeddedObject::setDefaultSize( const ::com::sun::star::awt::Size& rSize_100TH_MM ) throw (::com::sun::star::uno::RuntimeException)
     699                 :            : {
     700                 :            :     //#i103460# charts do not necessaryly have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method
     701                 :          2 :     m_aDefaultSizeForChart_In_100TH_MM = rSize_100TH_MM;
     702                 :          2 : }
     703                 :            : 
     704                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10