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

Generated by: LCOV version 1.10