LCOV - code coverage report
Current view: top level - embeddedobj/source/commonembedding - miscobj.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 202 293 68.9 %
Date: 2014-04-11 Functions: 17 24 70.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <commonembobj.hxx>
      21             : #include <com/sun/star/embed/EmbedStates.hpp>
      22             : #include <com/sun/star/embed/EmbedVerbs.hpp>
      23             : #include <com/sun/star/embed/XStorage.hpp>
      24             : #include <com/sun/star/embed/EmbedUpdateModes.hpp>
      25             : #include <com/sun/star/embed/XInplaceClient.hpp>
      26             : #include <com/sun/star/lang/DisposedException.hpp>
      27             : #include <com/sun/star/beans/NamedValue.hpp>
      28             : 
      29             : #include <cppuhelper/typeprovider.hxx>
      30             : #include <cppuhelper/interfacecontainer.h>
      31             : #include <comphelper/mimeconfighelper.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : 
      34             : #include "closepreventer.hxx"
      35             : #include "intercept.hxx"
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : 
      40             : uno::Sequence< beans::PropertyValue > GetValuableArgs_Impl( const uno::Sequence< beans::PropertyValue >& aMedDescr,
      41             :                                                             sal_Bool bCanUseDocumentBaseURL );
      42             : 
      43             : 
      44         470 : OCommonEmbeddedObject::OCommonEmbeddedObject( const uno::Reference< uno::XComponentContext >& rxContext,
      45             :                                                 const uno::Sequence< beans::NamedValue >& aObjProps )
      46             : : m_pDocHolder( NULL )
      47             : , m_pInterfaceContainer( NULL )
      48             : , m_bReadOnly( sal_False )
      49             : , m_bDisposed( sal_False )
      50             : , m_bClosed( sal_False )
      51             : , m_nObjectState( -1 )
      52             : , m_nTargetState( -1 )
      53             : , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE )
      54             : , m_xContext( rxContext )
      55             : , m_nMiscStatus( 0 )
      56             : , m_bEmbeddedScriptSupport( sal_True )
      57             : , m_bDocumentRecoverySupport( sal_True )
      58             : , m_bWaitSaveCompleted( sal_False )
      59             : , m_bIsLink( sal_False )
      60             : , m_bLinkHasPassword( sal_False )
      61             : , m_bHasClonedSize( sal_False )
      62         470 : , m_nClonedMapUnit( 0 )
      63             : {
      64         470 :     CommonInit_Impl( aObjProps );
      65         470 : }
      66             : 
      67             : 
      68           0 : OCommonEmbeddedObject::OCommonEmbeddedObject(
      69             :         const uno::Reference< uno::XComponentContext >& rxContext,
      70             :         const uno::Sequence< beans::NamedValue >& aObjProps,
      71             :         const uno::Sequence< beans::PropertyValue >& aMediaDescr,
      72             :         const uno::Sequence< beans::PropertyValue >& aObjectDescr )
      73             : : m_pDocHolder( NULL )
      74             : , m_pInterfaceContainer( NULL )
      75             : , m_bReadOnly( sal_False )
      76             : , m_bDisposed( sal_False )
      77             : , m_bClosed( sal_False )
      78             : , m_nObjectState( embed::EmbedStates::LOADED )
      79             : , m_nTargetState( -1 )
      80             : , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE )
      81             : , m_xContext( rxContext )
      82             : , m_nMiscStatus( 0 )
      83             : , m_bEmbeddedScriptSupport( sal_True )
      84             : , m_bDocumentRecoverySupport( sal_True )
      85             : , m_bWaitSaveCompleted( sal_False )
      86             : , m_bIsLink( sal_True )
      87             : , m_bLinkHasPassword( sal_False )
      88             : , m_bHasClonedSize( sal_False )
      89           0 : , m_nClonedMapUnit( 0 )
      90             : {
      91             :     // linked object has no own persistence so it is in loaded state starting from creation
      92           0 :     LinkInit_Impl( aObjProps, aMediaDescr, aObjectDescr );
      93           0 : }
      94             : 
      95             : 
      96         470 : void OCommonEmbeddedObject::CommonInit_Impl( const uno::Sequence< beans::NamedValue >& aObjectProps )
      97             : {
      98             :     OSL_ENSURE( m_xContext.is(), "No ServiceFactory is provided!\n" );
      99         470 :     if ( !m_xContext.is() )
     100           0 :         throw uno::RuntimeException();
     101             : 
     102         470 :     m_pDocHolder = new DocumentHolder( m_xContext, this );
     103         470 :     m_pDocHolder->acquire();
     104             : 
     105             :     // parse configuration entries
     106             :     // TODO/LATER: in future UI names can be also provided here
     107        3278 :     for ( sal_Int32 nInd = 0; nInd < aObjectProps.getLength(); nInd++ )
     108             :     {
     109        2808 :         if ( aObjectProps[nInd].Name == "ClassID" )
     110         470 :             aObjectProps[nInd].Value >>= m_aClassID;
     111        2338 :         else if ( aObjectProps[nInd].Name == "ObjectDocumentServiceName" )
     112         467 :             aObjectProps[nInd].Value >>= m_aDocServiceName;
     113        1871 :         else if ( aObjectProps[nInd].Name == "ObjectDocumentFilterName" )
     114         467 :             aObjectProps[nInd].Value >>= m_aPresetFilterName;
     115        1404 :         else if ( aObjectProps[nInd].Name == "ObjectMiscStatus" )
     116         467 :             aObjectProps[nInd].Value >>= m_nMiscStatus;
     117         937 :         else if ( aObjectProps[nInd].Name == "ObjectVerbs" )
     118         467 :             aObjectProps[nInd].Value >>= m_aObjectVerbs;
     119             :     }
     120             : 
     121         470 :     if ( m_aClassID.getLength() != 16 /*|| !m_aDocServiceName.getLength()*/ )
     122           0 :         throw uno::RuntimeException(); // something goes really wrong
     123             : 
     124             :     // accepted states
     125         470 :     m_aAcceptedStates.realloc( NUM_SUPPORTED_STATES );
     126             : 
     127         470 :     m_aAcceptedStates[0] = embed::EmbedStates::LOADED;
     128         470 :     m_aAcceptedStates[1] = embed::EmbedStates::RUNNING;
     129         470 :     m_aAcceptedStates[2] = embed::EmbedStates::INPLACE_ACTIVE;
     130         470 :     m_aAcceptedStates[3] = embed::EmbedStates::UI_ACTIVE;
     131         470 :     m_aAcceptedStates[4] = embed::EmbedStates::ACTIVE;
     132             : 
     133             : 
     134             :     // intermediate states
     135             :     // In the following table the first index points to starting state,
     136             :     // the second one to the target state, and the sequence referenced by
     137             :     // first two indexes contains intermediate states, that should be
     138             :     // passed by object to reach the target state.
     139             :     // If the sequence is empty that means that indirect switch from start
     140             :     // state to the target state is forbidden, only if direct switch is possible
     141             :     // the state can be reached.
     142             : 
     143         470 :     m_pIntermediateStatesSeqs[0][2].realloc( 1 );
     144         470 :     m_pIntermediateStatesSeqs[0][2][0] = embed::EmbedStates::RUNNING;
     145             : 
     146         470 :     m_pIntermediateStatesSeqs[0][3].realloc( 2 );
     147         470 :     m_pIntermediateStatesSeqs[0][3][0] = embed::EmbedStates::RUNNING;
     148         470 :     m_pIntermediateStatesSeqs[0][3][1] = embed::EmbedStates::INPLACE_ACTIVE;
     149             : 
     150         470 :     m_pIntermediateStatesSeqs[0][4].realloc( 1 );
     151         470 :     m_pIntermediateStatesSeqs[0][4][0] = embed::EmbedStates::RUNNING;
     152             : 
     153         470 :     m_pIntermediateStatesSeqs[1][3].realloc( 1 );
     154         470 :     m_pIntermediateStatesSeqs[1][3][0] = embed::EmbedStates::INPLACE_ACTIVE;
     155             : 
     156         470 :     m_pIntermediateStatesSeqs[2][0].realloc( 1 );
     157         470 :     m_pIntermediateStatesSeqs[2][0][0] = embed::EmbedStates::RUNNING;
     158             : 
     159         470 :     m_pIntermediateStatesSeqs[3][0].realloc( 2 );
     160         470 :     m_pIntermediateStatesSeqs[3][0][0] = embed::EmbedStates::INPLACE_ACTIVE;
     161         470 :     m_pIntermediateStatesSeqs[3][0][1] = embed::EmbedStates::RUNNING;
     162             : 
     163         470 :     m_pIntermediateStatesSeqs[3][1].realloc( 1 );
     164         470 :     m_pIntermediateStatesSeqs[3][1][0] = embed::EmbedStates::INPLACE_ACTIVE;
     165             : 
     166         470 :     m_pIntermediateStatesSeqs[4][0].realloc( 1 );
     167         470 :     m_pIntermediateStatesSeqs[4][0][0] = embed::EmbedStates::RUNNING;
     168             : 
     169             :     // verbs table
     170         470 :     sal_Int32 nVerbTableSize = 0;
     171        3574 :     for ( sal_Int32 nVerbInd = 0; nVerbInd < m_aObjectVerbs.getLength(); nVerbInd++ )
     172             :     {
     173        3104 :         if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_PRIMARY )
     174             :         {
     175         467 :             m_aVerbTable.realloc( ++nVerbTableSize );
     176         467 :             m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
     177         467 :             m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
     178         467 :             m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::UI_ACTIVE;
     179             :         }
     180        2637 :         else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_SHOW )
     181             :         {
     182         467 :             m_aVerbTable.realloc( ++nVerbTableSize );
     183         467 :             m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
     184         467 :             m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
     185         467 :             m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::UI_ACTIVE;
     186             :         }
     187        2170 :         else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_OPEN )
     188             :         {
     189         466 :             m_aVerbTable.realloc( ++nVerbTableSize );
     190         466 :             m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
     191         466 :             m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
     192         466 :             m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::ACTIVE;
     193             :         }
     194        1704 :         else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE )
     195             :         {
     196         467 :             m_aVerbTable.realloc( ++nVerbTableSize );
     197         467 :             m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
     198         467 :             m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
     199         467 :             m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::INPLACE_ACTIVE;
     200             :         }
     201        1237 :         else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE )
     202             :         {
     203         466 :             m_aVerbTable.realloc( ++nVerbTableSize );
     204         466 :             m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
     205         466 :             m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
     206         466 :             m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::UI_ACTIVE;
     207             :         }
     208         771 :         else if ( m_aObjectVerbs[nVerbInd].VerbID == embed::EmbedVerbs::MS_OLEVERB_HIDE )
     209             :         {
     210         466 :             m_aVerbTable.realloc( ++nVerbTableSize );
     211         466 :             m_aVerbTable[nVerbTableSize - 1].realloc( 2 );
     212         466 :             m_aVerbTable[nVerbTableSize - 1][0] = m_aObjectVerbs[nVerbInd].VerbID;
     213         466 :             m_aVerbTable[nVerbTableSize - 1][1] = embed::EmbedStates::RUNNING;
     214             :         }
     215             :     }
     216         470 : }
     217             : 
     218             : 
     219           0 : void OCommonEmbeddedObject::LinkInit_Impl(
     220             :                                 const uno::Sequence< beans::NamedValue >& aObjectProps,
     221             :                                 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
     222             :                                 const uno::Sequence< beans::PropertyValue >& aObjectDescr )
     223             : {
     224             :     // setPersistance has no effect on own links, so the complete initialization must be done here
     225             : 
     226           0 :     for ( sal_Int32 nInd = 0; nInd < aMediaDescr.getLength(); nInd++ )
     227           0 :         if ( aMediaDescr[nInd].Name == "URL" )
     228           0 :             aMediaDescr[nInd].Value >>= m_aLinkURL;
     229           0 :         else if ( aMediaDescr[nInd].Name == "FilterName" )
     230           0 :             aMediaDescr[nInd].Value >>= m_aLinkFilterName;
     231             : 
     232             :     OSL_ENSURE( m_aLinkURL.getLength() && m_aLinkFilterName.getLength(), "Filter and URL must be provided!\n" );
     233             : 
     234           0 :     m_bReadOnly = sal_True;
     235           0 :     if ( m_aLinkFilterName.getLength() )
     236             :     {
     237           0 :         ::comphelper::MimeConfigurationHelper aHelper( m_xContext );
     238           0 :         OUString aExportFilterName = aHelper.GetExportFilterFromImportFilter( m_aLinkFilterName );
     239           0 :         m_bReadOnly = !( aExportFilterName.equals( m_aLinkFilterName ) );
     240             :     }
     241             : 
     242           0 :     m_aDocMediaDescriptor = GetValuableArgs_Impl( aMediaDescr, sal_False );
     243             : 
     244           0 :     uno::Reference< frame::XDispatchProviderInterceptor > xDispatchInterceptor;
     245           0 :     for ( sal_Int32 nObjInd = 0; nObjInd < aObjectDescr.getLength(); nObjInd++ )
     246           0 :         if ( aObjectDescr[nObjInd].Name == "OutplaceDispatchInterceptor" )
     247             :         {
     248           0 :             aObjectDescr[nObjInd].Value >>= xDispatchInterceptor;
     249           0 :             break;
     250             :         }
     251           0 :         else if ( aObjectDescr[nObjInd].Name == "Parent" )
     252             :         {
     253           0 :             aObjectDescr[nObjInd].Value >>= m_xParent;
     254             :         }
     255             : 
     256           0 :     CommonInit_Impl( aObjectProps );
     257             : 
     258           0 :     if ( xDispatchInterceptor.is() )
     259           0 :         m_pDocHolder->SetOutplaceDispatchInterceptor( xDispatchInterceptor );
     260           0 : }
     261             : 
     262             : 
     263        1388 : OCommonEmbeddedObject::~OCommonEmbeddedObject()
     264             : {
     265         464 :     if ( m_pInterfaceContainer || m_pDocHolder )
     266             :     {
     267         464 :         m_refCount++;
     268             :         try {
     269         464 :             lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
     270             : 
     271         464 :             if ( m_pInterfaceContainer )
     272             :             {
     273         456 :                 m_pInterfaceContainer->disposeAndClear( aSource );
     274             : 
     275         456 :                 delete m_pInterfaceContainer;
     276         456 :                 m_pInterfaceContainer = NULL;
     277         464 :             }
     278           0 :         } catch( const uno::Exception& ) {}
     279             : 
     280             :         try {
     281         464 :             if ( m_pDocHolder )
     282             :             {
     283           8 :                 m_pDocHolder->CloseFrame();
     284             :                 try {
     285           8 :                     m_pDocHolder->CloseDocument( sal_True, sal_True );
     286           0 :                 } catch ( const uno::Exception& ) {}
     287           8 :                 m_pDocHolder->FreeOffice();
     288             : 
     289           8 :                 m_pDocHolder->release();
     290           8 :                 m_pDocHolder = NULL;
     291             :             }
     292           0 :         } catch( const uno::Exception& ) {}
     293             :     }
     294         924 : }
     295             : 
     296             : 
     297           0 : void OCommonEmbeddedObject::requestPositioning( const awt::Rectangle& aRect )
     298             : {
     299             :     // the method is called in case object is inplace active and the object window was resized
     300             : 
     301             :     OSL_ENSURE( m_xClientSite.is(), "The client site must be set for inplace active object!\n" );
     302           0 :     if ( m_xClientSite.is() )
     303             :     {
     304           0 :         uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, uno::UNO_QUERY );
     305             : 
     306             :         OSL_ENSURE( xInplaceClient.is(), "The client site must support XInplaceClient to allow inplace activation!\n" );
     307           0 :         if ( xInplaceClient.is() )
     308             :         {
     309             :             try {
     310           0 :                 xInplaceClient->changedPlacement( aRect );
     311             :             }
     312           0 :             catch( const uno::Exception& )
     313             :             {
     314             :                 OSL_FAIL( "Exception on request to resize!\n" );
     315             :             }
     316           0 :         }
     317             :     }
     318           0 : }
     319             : 
     320             : 
     321        7060 : void OCommonEmbeddedObject::PostEvent_Impl( const OUString& aEventName )
     322             : {
     323        7060 :     if ( m_pInterfaceContainer )
     324             :     {
     325             :         ::cppu::OInterfaceContainerHelper* pIC = m_pInterfaceContainer->getContainer(
     326        5949 :                                             ::getCppuType((const uno::Reference< document::XEventListener >*)0) );
     327        5949 :         if( pIC )
     328             :         {
     329        5949 :             document::EventObject aEvent;
     330        5949 :             aEvent.EventName = aEventName;
     331        5949 :             aEvent.Source = uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) );
     332             :             // For now all the events are sent as object events
     333             :             // aEvent.Source = ( xSource.is() ? xSource
     334             :             //                       : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
     335       11898 :             ::cppu::OInterfaceIteratorHelper aIt( *pIC );
     336       21062 :             while( aIt.hasMoreElements() )
     337             :             {
     338             :                 try
     339             :                 {
     340        9164 :                     ((document::XEventListener *)aIt.next())->notifyEvent( aEvent );
     341             :                 }
     342           0 :                 catch( const uno::RuntimeException& )
     343             :                 {
     344           0 :                     aIt.remove();
     345             :                 }
     346             : 
     347             :                 // the listener could dispose the object.
     348        9164 :                 if ( m_bDisposed )
     349        7060 :                     return;
     350        5949 :             }
     351             :         }
     352             :     }
     353             : }
     354             : 
     355             : 
     356       13188 : uno::Any SAL_CALL OCommonEmbeddedObject::queryInterface( const uno::Type& rType )
     357             :         throw( uno::RuntimeException, std::exception )
     358             : {
     359       13188 :     uno::Any aReturn;
     360             : 
     361       13188 :     if ( rType == ::getCppuType( (uno::Reference< embed::XEmbeddedObject > const *)0 ))
     362             :     {
     363         458 :         void * p = static_cast< embed::XEmbeddedObject * >( this );
     364         458 :         return uno::Any( &p, rType );
     365             :     }
     366             :     else
     367       25460 :         aReturn <<= ::cppu::queryInterface(
     368             :                     rType,
     369             :                     static_cast< embed::XInplaceObject* >( this ),
     370             :                     static_cast< embed::XVisualObject* >( this ),
     371             :                     static_cast< embed::XCommonEmbedPersist* >( static_cast< embed::XEmbedPersist* >( this ) ),
     372             :                     static_cast< embed::XEmbedPersist* >( this ),
     373             :                     static_cast< embed::XLinkageSupport* >( this ),
     374             :                     static_cast< embed::XStateChangeBroadcaster* >( this ),
     375             :                     static_cast< embed::XClassifiedObject* >( this ),
     376             :                     static_cast< embed::XComponentSupplier* >( this ),
     377             :                     static_cast< util::XCloseable* >( this ),
     378             :                     static_cast< container::XChild* >( this ),
     379             :                     static_cast< chart2::XDefaultSizeTransmitter* >( this ),
     380       12730 :                     static_cast< document::XEventBroadcaster* >( this ) );
     381             : 
     382       12730 :     if ( aReturn.hasValue() )
     383        9471 :         return aReturn;
     384             :     else
     385        3259 :         return ::cppu::OWeakObject::queryInterface( rType ) ;
     386             : 
     387             : }
     388             : 
     389             : 
     390       63821 : void SAL_CALL OCommonEmbeddedObject::acquire()
     391             :         throw()
     392             : {
     393       63821 :     ::cppu::OWeakObject::acquire() ;
     394       63821 : }
     395             : 
     396             : 
     397       63809 : void SAL_CALL OCommonEmbeddedObject::release()
     398             :         throw()
     399             : {
     400       63809 :     ::cppu::OWeakObject::release() ;
     401       63809 : }
     402             : 
     403             : 
     404           0 : uno::Sequence< uno::Type > SAL_CALL OCommonEmbeddedObject::getTypes()
     405             :         throw( uno::RuntimeException )
     406             : {
     407             :     static ::cppu::OTypeCollection* pTypeCollection = NULL;
     408             : 
     409           0 :     if ( !pTypeCollection )
     410             :     {
     411           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     412           0 :         if ( !pTypeCollection )
     413             :         {
     414           0 :             if ( m_bIsLink )
     415             :             {
     416             :                 static ::cppu::OTypeCollection aTypeCollection(
     417           0 :                                             ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
     418           0 :                                             ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
     419           0 :                                             ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ),
     420           0 :                                             ::getCppuType( (const uno::Reference< embed::XCommonEmbedPersist >*)NULL ),
     421           0 :                                             ::getCppuType( (const uno::Reference< container::XChild >*)NULL ),
     422           0 :                                             ::getCppuType( (const uno::Reference< embed::XLinkageSupport >*)NULL ) );
     423             : 
     424           0 :                 pTypeCollection = &aTypeCollection ;
     425             :             }
     426             :             else
     427             :             {
     428             :                    static ::cppu::OTypeCollection aTypeCollection(
     429           0 :                                             ::getCppuType( (const uno::Reference< lang::XTypeProvider >*)NULL ),
     430           0 :                                             ::getCppuType( (const uno::Reference< embed::XEmbeddedObject >*)NULL ),
     431           0 :                                             ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ),
     432           0 :                                             ::getCppuType( (const uno::Reference< embed::XCommonEmbedPersist >*)NULL ),
     433           0 :                                             ::getCppuType( (const uno::Reference< container::XChild >*)NULL ),
     434           0 :                                             ::getCppuType( (const uno::Reference< embed::XEmbedPersist >*)NULL ) );
     435             : 
     436           0 :                 pTypeCollection = &aTypeCollection ;
     437             :             }
     438           0 :         }
     439             :     }
     440             : 
     441           0 :     return pTypeCollection->getTypes() ;
     442             : 
     443             : }
     444             : 
     445             : 
     446           0 : uno::Sequence< sal_Int8 > SAL_CALL OCommonEmbeddedObject::getImplementationId()
     447             :         throw( uno::RuntimeException )
     448             : {
     449           0 :     return css::uno::Sequence<sal_Int8>();
     450             : }
     451             : 
     452             : 
     453        7181 : uno::Sequence< sal_Int8 > SAL_CALL OCommonEmbeddedObject::getClassID()
     454             :         throw ( uno::RuntimeException, std::exception )
     455             : {
     456        7181 :     if ( m_bDisposed )
     457           0 :         throw lang::DisposedException();
     458             : 
     459        7181 :     return m_aClassID;
     460             : }
     461             : 
     462             : 
     463           0 : OUString SAL_CALL OCommonEmbeddedObject::getClassName()
     464             :         throw ( uno::RuntimeException, std::exception )
     465             : {
     466           0 :     if ( m_bDisposed )
     467           0 :         throw lang::DisposedException();
     468             : 
     469           0 :     return m_aClassName;
     470             : }
     471             : 
     472             : 
     473           0 : void SAL_CALL OCommonEmbeddedObject::setClassInfo(
     474             :                 const uno::Sequence< sal_Int8 >& /*aClassID*/, const OUString& /*aClassName*/ )
     475             :         throw ( lang::NoSupportException,
     476             :                 uno::RuntimeException, std::exception )
     477             : {
     478             :     // the object class info can not be changed explicitly
     479           0 :     throw lang::NoSupportException(); //TODO:
     480             : }
     481             : 
     482             : 
     483        6253 : uno::Reference< util::XCloseable > SAL_CALL OCommonEmbeddedObject::getComponent()
     484             :         throw ( uno::RuntimeException, std::exception )
     485             : {
     486        6253 :     ::osl::MutexGuard aGuard( m_aMutex );
     487        6253 :     if ( m_bDisposed )
     488           0 :         throw lang::DisposedException(); // TODO
     489             : 
     490             :     // add an exception
     491        6253 :     if ( m_nObjectState == -1 )
     492             :     {
     493             :         // the object is still not loaded
     494             :         throw uno::RuntimeException( OUString( "Can't store object without persistence!\n" ),
     495           0 :                                         uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
     496             :     }
     497             : 
     498        6253 :     return uno::Reference< util::XCloseable >( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
     499             : }
     500             : 
     501             : 
     502        1504 : void SAL_CALL OCommonEmbeddedObject::addStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener )
     503             :     throw ( uno::RuntimeException, std::exception )
     504             : {
     505        1504 :     ::osl::MutexGuard aGuard( m_aMutex );
     506        1504 :     if ( m_bDisposed )
     507           0 :         throw lang::DisposedException(); // TODO
     508             : 
     509        1504 :     if ( !m_pInterfaceContainer )
     510         462 :         m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
     511             : 
     512        1504 :     m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< embed::XStateChangeListener >*)0 ),
     513        3008 :                                                         xListener );
     514        1504 : }
     515             : 
     516             : 
     517        1492 : void SAL_CALL OCommonEmbeddedObject::removeStateChangeListener(
     518             :                     const uno::Reference< embed::XStateChangeListener >& xListener )
     519             :     throw (uno::RuntimeException, std::exception)
     520             : {
     521        1492 :     ::osl::MutexGuard aGuard( m_aMutex );
     522        1492 :     if ( m_pInterfaceContainer )
     523        1492 :         m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< embed::XStateChangeListener >*)0 ),
     524        2984 :                                                 xListener );
     525        1492 : }
     526             : 
     527             : 
     528        1251 : void SAL_CALL OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership )
     529             :     throw ( util::CloseVetoException,
     530             :             uno::RuntimeException, std::exception )
     531             : {
     532        1251 :     ::osl::MutexGuard aGuard( m_aMutex );
     533        1251 :     if ( m_bClosed )
     534         649 :         throw lang::DisposedException(); // TODO
     535             : 
     536        1204 :     uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) );
     537        1204 :     lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
     538             : 
     539         602 :     if ( m_pInterfaceContainer )
     540             :     {
     541             :         ::cppu::OInterfaceContainerHelper* pContainer =
     542         602 :             m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
     543         602 :         if ( pContainer != NULL )
     544             :         {
     545         602 :             ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
     546        1204 :             while (pIterator.hasMoreElements())
     547             :             {
     548             :                 try
     549             :                 {
     550         146 :                     ((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership );
     551             :                 }
     552           0 :                 catch( const uno::RuntimeException& )
     553             :                 {
     554           0 :                     pIterator.remove();
     555             :                 }
     556         602 :             }
     557             :         }
     558             : 
     559             :         pContainer = m_pInterfaceContainer->getContainer(
     560         456 :                                     ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
     561         456 :         if ( pContainer != NULL )
     562             :         {
     563         456 :             ::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer);
     564         912 :             while (pCloseIterator.hasMoreElements())
     565             :             {
     566             :                 try
     567             :                 {
     568           0 :                     ((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource );
     569             :                 }
     570           0 :                 catch( const uno::RuntimeException& )
     571             :                 {
     572           0 :                     pCloseIterator.remove();
     573             :                 }
     574         456 :             }
     575             :         }
     576             : 
     577         456 :         m_pInterfaceContainer->disposeAndClear( aSource );
     578             :     }
     579             : 
     580         456 :     m_bDisposed = sal_True; // the object is disposed now for outside
     581             : 
     582             :     // it is possible that the document can not be closed, in this case if the argument is false
     583             :     // the exception will be thrown otherwise in addition to exception the object must register itself
     584             :     // as termination listener and listen for document events
     585             : 
     586         456 :     if ( m_pDocHolder )
     587             :     {
     588         456 :         m_pDocHolder->CloseFrame();
     589             : 
     590             :         try {
     591         456 :             m_pDocHolder->CloseDocument( bDeliverOwnership, bDeliverOwnership );
     592             :         }
     593           0 :         catch( const uno::Exception& )
     594             :         {
     595           0 :             if ( bDeliverOwnership )
     596             :             {
     597           0 :                 m_pDocHolder->release();
     598           0 :                 m_pDocHolder = NULL;
     599           0 :                 m_bClosed = sal_True;
     600             :             }
     601             : 
     602           0 :             throw;
     603             :         }
     604             : 
     605         456 :         m_pDocHolder->FreeOffice();
     606             : 
     607         456 :         m_pDocHolder->release();
     608         456 :         m_pDocHolder = NULL;
     609             :     }
     610             : 
     611             :     // TODO: for now the storage will be disposed by the object, but after the document
     612             :     // will use the storage, the storage will be disposed by the document and recreated by the object
     613         456 :     if ( m_xObjectStorage.is() )
     614             :     {
     615         452 :         uno::Reference< lang::XComponent > xComp( m_xObjectStorage, uno::UNO_QUERY );
     616             :         OSL_ENSURE( xComp.is(), "Storage does not support XComponent!\n" );
     617             : 
     618         452 :         if ( xComp.is() )
     619             :         {
     620             :             try {
     621         452 :                 xComp->dispose();
     622           0 :             } catch ( const uno::Exception& ) {}
     623             :         }
     624             : 
     625         452 :         m_xObjectStorage.clear();
     626         452 :         m_xRecoveryStorage.clear();
     627             :     }
     628             : 
     629        1707 :     m_bClosed = sal_True; // the closing succeeded
     630         456 : }
     631             : 
     632             : 
     633         974 : void SAL_CALL OCommonEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener )
     634             :     throw ( uno::RuntimeException, std::exception )
     635             : {
     636         974 :     ::osl::MutexGuard aGuard( m_aMutex );
     637         974 :     if ( m_bDisposed )
     638           0 :         throw lang::DisposedException(); // TODO
     639             : 
     640         974 :     if ( !m_pInterfaceContainer )
     641           0 :         m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
     642             : 
     643         974 :     m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ), xListener );
     644         974 : }
     645             : 
     646             : 
     647         968 : void SAL_CALL OCommonEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener )
     648             :     throw (uno::RuntimeException, std::exception)
     649             : {
     650         968 :     ::osl::MutexGuard aGuard( m_aMutex );
     651         968 :     if ( m_pInterfaceContainer )
     652         968 :         m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ),
     653        1936 :                                                 xListener );
     654         968 : }
     655             : 
     656             : 
     657        1142 : void SAL_CALL OCommonEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener )
     658             :         throw ( uno::RuntimeException, std::exception )
     659             : {
     660        1142 :     ::osl::MutexGuard aGuard( m_aMutex );
     661        1142 :     if ( m_bDisposed )
     662           0 :         throw lang::DisposedException(); // TODO
     663             : 
     664        1142 :     if ( !m_pInterfaceContainer )
     665           0 :         m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
     666             : 
     667        1142 :     m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ), xListener );
     668        1142 : }
     669             : 
     670             : 
     671        1130 : void SAL_CALL OCommonEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener )
     672             :         throw ( uno::RuntimeException, std::exception )
     673             : {
     674        1130 :     ::osl::MutexGuard aGuard( m_aMutex );
     675        1130 :     if ( m_pInterfaceContainer )
     676        1130 :         m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ),
     677        2260 :                                                 xListener );
     678        1130 : }
     679             : 
     680             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10