LCOV - code coverage report
Current view: top level - forms/source/misc - InterfaceContainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 416 595 69.9 %
Date: 2012-08-25 Functions: 57 72 79.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 467 1278 36.5 %

           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                 :            : 
      30                 :            : #include "frm_resource.hrc"
      31                 :            : #include "frm_resource.hxx"
      32                 :            : #include "InterfaceContainer.hxx"
      33                 :            : #include "componenttools.hxx"
      34                 :            : #include "property.hrc"
      35                 :            : #include "services.hxx"
      36                 :            : 
      37                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      38                 :            : #include <com/sun/star/container/XNamed.hpp>
      39                 :            : #include <com/sun/star/io/WrongFormatException.hpp>
      40                 :            : #include <com/sun/star/io/XMarkableStream.hpp>
      41                 :            : #include <com/sun/star/lang/XComponent.hpp>
      42                 :            : #include <com/sun/star/util/XCloneable.hpp>
      43                 :            : #include <com/sun/star/form/XForm.hpp>
      44                 :            : 
      45                 :            : #include <comphelper/container.hxx>
      46                 :            : #include <comphelper/enumhelper.hxx>
      47                 :            : #include <comphelper/eventattachermgr.hxx>
      48                 :            : #include <comphelper/property.hxx>
      49                 :            : #include <comphelper/sequence.hxx>
      50                 :            : #include <comphelper/types.hxx>
      51                 :            : #include <cppuhelper/exc_hlp.hxx>
      52                 :            : #include <cppuhelper/queryinterface.hxx>
      53                 :            : #include <rtl/logfile.hxx>
      54                 :            : #include <tools/debug.hxx>
      55                 :            : #include <tools/diagnose_ex.h>
      56                 :            : 
      57                 :            : #include <algorithm>
      58                 :            : #include <memory>
      59                 :            : 
      60                 :            : //.........................................................................
      61                 :            : #include <com/sun/star/frame/XModel.hpp>
      62                 :            : #include <com/sun/star/document/XCodeNameQuery.hpp>
      63                 :            : #include <ooo/vba/XVBAToOOEventDescGen.hpp>
      64                 :            : #include <comphelper/processfactory.hxx>
      65                 :            : 
      66                 :            : namespace frm
      67                 :            : {
      68                 :            : //.........................................................................
      69                 :            : 
      70                 :            : using namespace ::com::sun::star::frame;
      71                 :            : using namespace ::com::sun::star::lang;
      72                 :            : using namespace ::com::sun::star::uno;
      73                 :            : using namespace ::com::sun::star::beans;
      74                 :            : using namespace ::com::sun::star::document;
      75                 :            : using namespace ::com::sun::star::container;
      76                 :            : using namespace ::com::sun::star::script;
      77                 :            : using namespace ::com::sun::star::io;
      78                 :            : using namespace ::com::sun::star::form;
      79                 :            : using namespace ::com::sun::star::util;
      80                 :            : 
      81                 :            : namespace
      82                 :            : {
      83                 :            :     //---------------------------------------------------------------------
      84                 :          0 :     static void lcl_throwIllegalArgumentException()
      85                 :            :     {
      86         [ #  # ]:          0 :         throw IllegalArgumentException();
      87                 :            :     }
      88                 :            : }
      89                 :            : 
      90                 :            : bool
      91                 :         18 : lcl_hasVbaEvents( const Sequence< ScriptEventDescriptor >& sEvents  )
      92                 :            : {
      93                 :         18 :     const ScriptEventDescriptor* pDesc = sEvents.getConstArray();
      94                 :         18 :     const ScriptEventDescriptor* pEnd = ( pDesc + sEvents.getLength() );
      95         [ +  + ]:         28 :     for ( ; pDesc != pEnd; ++pDesc )
      96                 :            :     {
      97         [ -  + ]:         10 :         if ( pDesc->ScriptType == "VBAInterop" )
      98                 :          0 :             return true;
      99                 :            :     }
     100                 :         18 :     return false;
     101                 :            : }
     102                 :            : 
     103                 :            : Sequence< ScriptEventDescriptor >
     104                 :          0 : lcl_stripVbaEvents( const Sequence< ScriptEventDescriptor >& sEvents )
     105                 :            : {
     106                 :          0 :     Sequence< ScriptEventDescriptor > sStripped( sEvents.getLength() );
     107                 :            : 
     108                 :          0 :     const ScriptEventDescriptor* pDesc = sEvents.getConstArray();
     109                 :          0 :     const ScriptEventDescriptor* pEnd = ( pDesc + sEvents.getLength() );
     110                 :          0 :     sal_Int32 nCopied = 0;
     111         [ #  # ]:          0 :     for ( ; pDesc != pEnd; ++pDesc )
     112                 :            :     {
     113         [ #  # ]:          0 :         if ( pDesc->ScriptType != "VBAInterop" )
     114                 :            :         {
     115         [ #  # ]:          0 :             sStripped[ nCopied++ ] = *pDesc;
     116                 :            :         }
     117                 :            :     }
     118         [ #  # ]:          0 :     if ( nCopied )
     119         [ #  # ]:          0 :         sStripped.realloc( nCopied );
     120                 :          0 :     return sStripped;
     121                 :            : }
     122                 :            : 
     123                 :        502 : void OInterfaceContainer::impl_addVbEvents_nolck_nothrow(  const sal_Int32 i_nIndex )
     124                 :            : {
     125                 :            :     // we are dealing with form controls
     126                 :            :     try
     127                 :            :     {
     128                 :            :         do
     129                 :            :         {
     130 [ +  - ][ +  - ]:        502 :             Reference< XModel > xDoc( getXModel( static_cast< XContainer *> ( this ) ) );
     131         [ +  + ]:        502 :             if ( !xDoc.is() )
     132                 :            :                 break;
     133                 :            : 
     134         [ +  - ]:        499 :             Reference< XMultiServiceFactory > xDocFac( xDoc, UNO_QUERY_THROW );
     135 [ +  - ][ +  - ]:        499 :             Reference< XCodeNameQuery > xNameQuery( xDocFac->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooo.vba.VBACodeNameProvider") ) ), UNO_QUERY );
         [ +  + ][ +  - ]
     136         [ +  + ]:        489 :             if ( !xNameQuery.is() )
     137                 :            :                 break;
     138                 :            : 
     139         [ +  - ]:          2 :             ::osl::MutexGuard aGuard( m_rMutex );
     140 [ +  - ][ +  - ]:          2 :             bool hasVBABindings = lcl_hasVbaEvents( m_xEventAttacher->getScriptEvents( i_nIndex ) );
         [ +  - ][ +  - ]
     141         [ -  + ]:          2 :             if ( hasVBABindings )
     142                 :            :                 break;
     143                 :            : 
     144 [ +  - ][ +  - ]:          2 :             Reference< XInterface > xElement( getByIndex( i_nIndex ) , UNO_QUERY_THROW );
     145         [ +  - ]:          2 :             Reference< XForm > xElementAsForm( xElement, UNO_QUERY );
     146         [ -  + ]:          2 :             if ( xElementAsForm.is() )
     147                 :            :                 break;
     148                 :            : 
     149                 :            :             // Try getting the code name from the container first (faster),
     150                 :            :             // then from the element if that fails (slower).
     151         [ +  - ]:          2 :             Reference<XInterface> xThis = static_cast<XContainer*>(this);
     152 [ +  - ][ +  - ]:          2 :             rtl::OUString sCodeName = xNameQuery->getCodeNameForContainer(xThis);
     153         [ -  + ]:          2 :             if (sCodeName.isEmpty())
     154 [ #  # ][ #  # ]:          0 :                 sCodeName = xNameQuery->getCodeNameForObject(xElement);
     155                 :            : 
     156         [ +  - ]:          2 :             Reference< XPropertySet > xProps( xElement, UNO_QUERY_THROW );
     157                 :          2 :             ::rtl::OUString sServiceName;
     158 [ +  - ][ +  - ]:          2 :             xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultControl") ) ) >>= sServiceName;
                 [ +  - ]
     159                 :            : 
     160 [ +  - ][ +  - ]:          2 :             Reference< ooo::vba::XVBAToOOEventDescGen > xDescSupplier( m_xServiceFactory->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooo.vba.VBAToOOEventDesc") ) ), UNO_QUERY_THROW );
         [ -  + ][ +  - ]
     161 [ #  # ][ #  # ]:          0 :             Reference< XInterface > xInterface = m_xServiceFactory->createInstance( sServiceName );
     162 [ #  # ][ #  # ]:          0 :             Sequence< ScriptEventDescriptor > vbaEvents = xDescSupplier->getEventDescriptions( xInterface, sCodeName );
     163                 :            :             // register the vba script events
     164 [ #  # ][ #  # ]:          0 :             m_xEventAttacher->registerScriptEvents( i_nIndex, vbaEvents );
     165                 :            : 
     166         [ #  # ]:          0 :             Reference< XComponent > xComponent( xInterface, UNO_QUERY );
     167         [ #  # ]:          0 :             if ( xComponent.is() )
     168                 :            :             {
     169 [ #  # ][ #  # ]:          0 :                 xComponent->dispose();
     170 [ #  # ][ #  # ]:        502 :             }
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ +  - ][ -  + ]
              [ -  +  + ]
     171                 :            :         }
     172                 :            :         while ( false );
     173                 :            :     }
     174                 :         10 :     catch ( const ServiceNotRegisteredException& )
     175                 :            :     {
     176                 :            :         // silence this, not all document types support the ooo.vba.VBACodeNameProvider service
     177                 :            :     }
     178                 :          2 :     catch( const Exception& )
     179                 :            :     {
     180                 :            :         DBG_UNHANDLED_EXCEPTION();
     181                 :            :     }
     182                 :            : 
     183                 :        502 : }
     184                 :            : //==================================================================
     185                 :            : //= ElementDescription
     186                 :            : //==================================================================
     187                 :            : //------------------------------------------------------------------
     188                 :        934 : ElementDescription::ElementDescription( )
     189                 :            : {
     190                 :        934 : }
     191                 :            : 
     192                 :            : //------------------------------------------------------------------
     193                 :        934 : ElementDescription::~ElementDescription()
     194                 :            : {
     195         [ -  + ]:       1752 : }
     196                 :            : 
     197                 :            : //==================================================================
     198                 :            : //= OInterfaceContainer
     199                 :            : //==================================================================
     200                 :            : //------------------------------------------------------------------
     201                 :        638 : OInterfaceContainer::OInterfaceContainer(
     202                 :            :                 const Reference<XMultiServiceFactory>& _rxFactory,
     203                 :            :                 ::osl::Mutex& _rMutex,
     204                 :            :                 const Type& _rElementType)
     205                 :            :     :OInterfaceContainer_BASE()
     206                 :            :     ,m_rMutex(_rMutex)
     207                 :            :     ,m_aContainerListeners(_rMutex)
     208                 :            :     ,m_aElementType(_rElementType)
     209 [ +  - ][ +  - ]:        638 :     ,m_xServiceFactory(_rxFactory)
                 [ +  - ]
     210                 :            : {
     211         [ +  - ]:        638 :     impl_createEventAttacher_nothrow();
     212                 :        638 : }
     213                 :            : 
     214                 :            : //------------------------------------------------------------------------------
     215                 :          0 : OInterfaceContainer::OInterfaceContainer( ::osl::Mutex& _rMutex, const OInterfaceContainer& _cloneSource )
     216                 :            :     :OInterfaceContainer_BASE()
     217                 :            :     ,m_rMutex( _rMutex )
     218                 :            :     ,m_aContainerListeners( _rMutex )
     219                 :            :     ,m_aElementType( _cloneSource.m_aElementType )
     220 [ #  # ][ #  # ]:          0 :     ,m_xServiceFactory( _cloneSource.m_xServiceFactory )
                 [ #  # ]
     221                 :            : {
     222         [ #  # ]:          0 :     impl_createEventAttacher_nothrow();
     223                 :          0 : }
     224                 :            : 
     225                 :            : //------------------------------------------------------------------------------
     226                 :          0 : void OInterfaceContainer::clonedFrom( const OInterfaceContainer& _cloneSource )
     227                 :            : {
     228                 :            :     try
     229                 :            :     {
     230         [ #  # ]:          0 :         const Reference< XIndexAccess > xSourceHierarchy( const_cast< OInterfaceContainer* >( &_cloneSource ) );
     231 [ #  # ][ #  # ]:          0 :         const sal_Int32 nCount = xSourceHierarchy->getCount();
     232         [ #  # ]:          0 :         for ( sal_Int32 i=0; i<nCount; ++i )
     233                 :            :         {
     234 [ #  # ][ #  # ]:          0 :             Reference< XCloneable > xCloneable( xSourceHierarchy->getByIndex( i ), UNO_QUERY_THROW );
                 [ #  # ]
     235 [ #  # ][ #  # ]:          0 :             Reference< XInterface > xClone( xCloneable->createClone() );
     236 [ #  # ][ #  # ]:          0 :             insertByIndex( i, makeAny( xClone ) );
     237                 :          0 :         }
     238                 :            :     }
     239         [ #  # ]:          0 :     catch( const Exception& )
     240                 :            :     {
     241                 :            :         throw WrappedTargetException(
     242                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Could not clone the given interface hierarchy." ) ),
     243                 :            :             static_cast< XIndexContainer* >( const_cast< OInterfaceContainer* >( &_cloneSource ) ),
     244                 :            :             ::cppu::getCaughtException()
     245   [ #  #  #  #  :          0 :         );
             #  #  #  # ]
     246                 :            :     }
     247                 :          0 : }
     248                 :            : 
     249                 :            : //------------------------------------------------------------------------------
     250                 :        638 : void OInterfaceContainer::impl_createEventAttacher_nothrow()
     251                 :            : {
     252                 :            :     try
     253                 :            :     {
     254 [ +  - ][ +  - ]:        638 :         m_xEventAttacher.set( ::comphelper::createEventAttacherManager( m_xServiceFactory ), UNO_SET_THROW );
                 [ #  # ]
     255                 :            :     }
     256                 :          0 :     catch( const Exception& )
     257                 :            :     {
     258                 :            :         DBG_UNHANDLED_EXCEPTION();
     259                 :            :     }
     260                 :        638 : }
     261                 :            : 
     262                 :            : //------------------------------------------------------------------------------
     263 [ +  - ][ +  - ]:        616 : OInterfaceContainer::~OInterfaceContainer()
     264                 :            : {
     265         [ -  + ]:        616 : }
     266                 :            : 
     267                 :            : //------------------------------------------------------------------------------
     268                 :        619 : void OInterfaceContainer::disposing()
     269                 :            : {
     270                 :            :     // dispose all elements
     271         [ +  + ]:       1034 :     for (sal_Int32 i = m_aItems.size(); i > 0; --i)
     272                 :            :     {
     273         [ +  - ]:        415 :         Reference<XPropertySet>  xSet(m_aItems[i - 1], UNO_QUERY);
     274         [ +  - ]:        415 :         if (xSet.is())
     275 [ +  - ][ +  - ]:        415 :             xSet->removePropertyChangeListener(PROPERTY_NAME, this);
         [ +  - ][ +  - ]
     276                 :            : 
     277                 :            :         // revoke event knittings
     278         [ +  - ]:        415 :         if ( m_xEventAttacher.is() )
     279                 :            :         {
     280         [ +  - ]:        415 :             Reference< XInterface > xIfc( xSet, UNO_QUERY );
     281 [ +  - ][ +  - ]:        415 :             m_xEventAttacher->detach( i - 1, xIfc );
     282 [ +  - ][ +  - ]:        415 :             m_xEventAttacher->removeEntry( i - 1 );
     283                 :            :         }
     284                 :            : 
     285         [ +  - ]:        415 :         Reference<XComponent>  xComponent(xSet, UNO_QUERY);
     286         [ +  - ]:        415 :         if (xComponent.is())
     287 [ +  - ][ +  - ]:        415 :             xComponent->dispose();
     288                 :        415 :     }
     289         [ +  - ]:        619 :     m_aMap.clear();
     290                 :        619 :     m_aItems.clear();
     291                 :            : 
     292 [ +  - ][ +  - ]:        619 :     EventObject aEvt(static_cast<XContainer*>(this));
     293 [ +  - ][ +  - ]:        619 :     m_aContainerListeners.disposeAndClear(aEvt);
     294                 :        619 : }
     295                 :            : 
     296                 :            : // XPersistObject
     297                 :            : //------------------------------------------------------------------------------
     298                 :            : namespace
     299                 :            : {
     300                 :            :     //..........................................................................
     301                 :          2 :     void lcl_saveEvents( ::std::vector< Sequence< ScriptEventDescriptor > >& _rSave,
     302                 :            :         const Reference< XEventAttacherManager >& _rxManager, const sal_Int32 _nItemCount )
     303                 :            :     {
     304                 :            :         OSL_ENSURE( _rxManager.is(), "lcl_saveEvents: invalid event attacher manager!" );
     305         [ -  + ]:          2 :         if ( !_rxManager.is() )
     306                 :          2 :             return;
     307                 :            : 
     308                 :            :         // reserve the space needed
     309                 :          2 :         _rSave.reserve( _nItemCount );
     310                 :            : 
     311                 :            :         // copy the events
     312         [ +  + ]:          6 :         for (sal_Int32 i=0; i<_nItemCount; ++i)
     313         [ +  - ]:          4 :             _rSave.push_back(_rxManager->getScriptEvents( i ));
     314                 :            :     }
     315                 :            : 
     316                 :            :     //..........................................................................
     317                 :          2 :     void lcl_restoreEvents( const ::std::vector< Sequence< ScriptEventDescriptor > >& _rSave,
     318                 :            :         const Reference< XEventAttacherManager >& _rxManager )
     319                 :            :     {
     320                 :            :         OSL_ENSURE( _rxManager.is(), "lcl_restoreEvents: invalid event attacher manager!" );
     321         [ +  - ]:          2 :         if ( !_rxManager.is() )
     322                 :          2 :             return;
     323                 :            : 
     324                 :          2 :         ::std::vector< Sequence< ScriptEventDescriptor > >::const_iterator aLoop = _rSave.begin();
     325                 :          2 :         ::std::vector< Sequence< ScriptEventDescriptor > >::const_iterator aEnd = _rSave.end();
     326 [ +  - ][ +  + ]:          6 :         for ( sal_Int32 i=0; aLoop != aEnd; ++aLoop, ++i )
     327                 :            :         {
     328 [ +  - ][ +  - ]:          4 :             _rxManager->revokeScriptEvents( i );
     329 [ +  - ][ +  - ]:          4 :             _rxManager->registerScriptEvents( i, *aLoop );
     330                 :            :         }
     331                 :            :     }
     332                 :            : }
     333                 :            : 
     334                 :            : //------------------------------------------------------------------------------
     335                 :          2 : void SAL_CALL OInterfaceContainer::writeEvents(const Reference<XObjectOutputStream>& _rxOutStream)
     336                 :            : {
     337                 :            :     // We're writing a document in SO 5.2 format (or even from earlier versions)
     338                 :            :     // -> convert the events from the new runtime format to the format of the 5.2 files
     339                 :            :     // but before, remember the current script events set for our children
     340         [ +  - ]:          2 :     ::std::vector< Sequence< ScriptEventDescriptor > > aSave;
     341         [ +  - ]:          2 :     if ( m_xEventAttacher.is() )
     342         [ +  - ]:          2 :         lcl_saveEvents( aSave, m_xEventAttacher, m_aItems.size() );
     343                 :            : 
     344         [ +  - ]:          2 :     transformEvents( efVersionSO5x );
     345                 :            : 
     346                 :            :     try
     347                 :            :     {
     348         [ +  - ]:          2 :         Reference<XMarkableStream>  xMark(_rxOutStream, UNO_QUERY);
     349 [ +  - ][ +  - ]:          2 :         sal_Int32 nMark = xMark->createMark();
     350                 :            : 
     351                 :          2 :         sal_Int32 nObjLen = 0;
     352 [ +  - ][ +  - ]:          2 :         _rxOutStream->writeLong(nObjLen);
     353                 :            : 
     354         [ +  - ]:          2 :         Reference<XPersistObject>  xScripts(m_xEventAttacher, UNO_QUERY);
     355         [ +  - ]:          2 :         if (xScripts.is())
     356 [ +  - ][ +  - ]:          2 :             xScripts->write(_rxOutStream);
     357                 :            : 
     358                 :            :         // feststellen der Laenge
     359 [ +  - ][ +  - ]:          2 :         nObjLen = xMark->offsetToMark(nMark) - 4;
     360 [ +  - ][ +  - ]:          2 :         xMark->jumpToMark(nMark);
     361 [ +  - ][ +  - ]:          2 :         _rxOutStream->writeLong(nObjLen);
     362 [ +  - ][ +  - ]:          2 :         xMark->jumpToFurthest();
     363 [ +  - ][ +  - ]:          2 :         xMark->deleteMark(nMark);
     364                 :            :     }
     365         [ #  # ]:          0 :     catch( const Exception& )
     366                 :            :     {
     367                 :            :         // restore the events
     368         [ #  # ]:          0 :         if ( m_xEventAttacher.is() )
     369         [ #  # ]:          0 :             lcl_restoreEvents( aSave, m_xEventAttacher );
     370                 :          0 :         throw;
     371                 :            :     }
     372                 :            : 
     373                 :            :     // restore the events
     374         [ +  - ]:          2 :     if ( m_xEventAttacher.is() )
     375         [ +  - ]:          2 :         lcl_restoreEvents( aSave, m_xEventAttacher );
     376                 :          2 : }
     377                 :            : 
     378                 :            : //------------------------------------------------------------------------------
     379                 :            : struct TransformEventTo52Format : public ::std::unary_function< ScriptEventDescriptor, void >
     380                 :            : {
     381                 :          0 :     void operator()( ScriptEventDescriptor& _rDescriptor )
     382                 :            :     {
     383         [ #  # ]:          0 :         if ( 0 == _rDescriptor.ScriptType.compareToAscii( "StarBasic" ) )
     384                 :            :         {   // it's a starbasic macro
     385                 :          0 :             sal_Int32 nPrefixLength = _rDescriptor.ScriptCode.indexOf( ':' );
     386         [ #  # ]:          0 :             if ( 0 <= nPrefixLength )
     387                 :            :             {   // the macro name does not already contain a :
     388                 :            : #ifdef DBG_UTIL
     389                 :            :                 const ::rtl::OUString sPrefix = _rDescriptor.ScriptCode.copy( 0, nPrefixLength );
     390                 :            :                 DBG_ASSERT( 0 == sPrefix.compareToAscii( "document" )
     391                 :            :                         ||  0 == sPrefix.compareToAscii( "application" ),
     392                 :            :                         "TransformEventTo52Format: invalid (unknown) prefix!" );
     393                 :            : #endif
     394                 :            :                 // cut the prefix
     395                 :          0 :                 _rDescriptor.ScriptCode = _rDescriptor.ScriptCode.copy( nPrefixLength + 1 );
     396                 :            :             }
     397                 :            :         }
     398                 :          0 :     }
     399                 :            : };
     400                 :            : 
     401                 :            : //------------------------------------------------------------------------------
     402                 :            : struct TransformEventTo60Format : public ::std::unary_function< ScriptEventDescriptor, void >
     403                 :            : {
     404                 :          0 :     void operator()( ScriptEventDescriptor& _rDescriptor )
     405                 :            :     {
     406         [ #  # ]:          0 :         if ( 0 == _rDescriptor.ScriptType.compareToAscii( "StarBasic" ) )
     407                 :            :         {   // it's a starbasic macro
     408         [ #  # ]:          0 :             if ( _rDescriptor.ScriptCode.indexOf( ':' ) < 0 )
     409                 :            :             {   // the macro name does not already contain a :
     410                 :            :                 // -> default the type to "document"
     411         [ #  # ]:          0 :                 ::rtl::OUString sNewScriptCode( RTL_CONSTASCII_USTRINGPARAM( "document:" ) );
     412                 :          0 :                 sNewScriptCode += _rDescriptor.ScriptCode;
     413                 :          0 :                 _rDescriptor.ScriptCode = sNewScriptCode;
     414                 :            :             }
     415                 :            :         }
     416                 :          0 :     }
     417                 :            : };
     418                 :            : 
     419                 :            : //------------------------------------------------------------------------------
     420                 :          2 : void OInterfaceContainer::transformEvents( const EventFormat _eTargetFormat )
     421                 :            : {
     422                 :            :     OSL_ENSURE( m_xEventAttacher.is(), "OInterfaceContainer::transformEvents: no event attacher manager!" );
     423         [ -  + ]:          2 :     if ( !m_xEventAttacher.is() )
     424                 :          2 :         return;
     425                 :            : 
     426                 :            :     try
     427                 :            :     {
     428                 :            :         // loop through all our children
     429                 :          2 :         sal_Int32 nItems = m_aItems.size();
     430         [ +  - ]:          2 :         Sequence< ScriptEventDescriptor > aChildEvents;
     431                 :            : 
     432         [ +  + ]:          6 :         for (sal_Int32 i=0; i<nItems; ++i)
     433                 :            :         {
     434                 :            :             // get the script events for this object
     435 [ +  - ][ +  - ]:          4 :             aChildEvents = m_xEventAttacher->getScriptEvents( i );
         [ +  - ][ +  - ]
     436                 :            : 
     437         [ -  + ]:          4 :             if ( aChildEvents.getLength() )
     438                 :            :             {
     439                 :            :                 // the "iterators" for the events for this child
     440         [ #  # ]:          0 :                 ScriptEventDescriptor* pChildEvents     =                       aChildEvents.getArray();
     441                 :          0 :                 ScriptEventDescriptor* pChildEventsEnd  =   pChildEvents    +   aChildEvents.getLength();
     442                 :            : 
     443                 :            :                 // do the transformation
     444         [ #  # ]:          0 :                 if ( efVersionSO6x == _eTargetFormat )
     445         [ #  # ]:          0 :                     ::std::for_each( pChildEvents, pChildEventsEnd, TransformEventTo60Format() );
     446                 :            :                 else
     447                 :          0 :                     ::std::for_each( pChildEvents, pChildEventsEnd, TransformEventTo52Format() );
     448                 :            : 
     449                 :            :                 // revoke the script events
     450 [ #  # ][ #  # ]:          0 :                 m_xEventAttacher->revokeScriptEvents( i );
     451                 :            :                 // and re-register them
     452 [ #  # ][ #  # ]:          0 :                 m_xEventAttacher->registerScriptEvents( i, aChildEvents );
     453                 :            :             }
     454 [ +  - ][ #  # ]:          2 :         }
     455                 :            :     }
     456                 :          0 :     catch( const Exception& )
     457                 :            :     {
     458                 :            :         DBG_UNHANDLED_EXCEPTION();
     459                 :            :     }
     460                 :            : }
     461                 :            : 
     462                 :            : //------------------------------------------------------------------------------
     463                 :          0 : void SAL_CALL OInterfaceContainer::readEvents(const Reference<XObjectInputStream>& _rxInStream)
     464                 :            : {
     465         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_rMutex );
     466                 :            : 
     467                 :            :     // Scripting Info lesen
     468         [ #  # ]:          0 :     Reference<XMarkableStream>  xMark(_rxInStream, UNO_QUERY);
     469 [ #  # ][ #  # ]:          0 :     sal_Int32 nObjLen = _rxInStream->readLong();
     470         [ #  # ]:          0 :     if (nObjLen)
     471                 :            :     {
     472 [ #  # ][ #  # ]:          0 :         sal_Int32 nMark = xMark->createMark();
     473         [ #  # ]:          0 :         Reference<XPersistObject>  xObj(m_xEventAttacher, UNO_QUERY);
     474         [ #  # ]:          0 :         if (xObj.is())
     475 [ #  # ][ #  # ]:          0 :             xObj->read(_rxInStream);
     476 [ #  # ][ #  # ]:          0 :         xMark->jumpToMark(nMark);
     477 [ #  # ][ #  # ]:          0 :         _rxInStream->skipBytes(nObjLen);
     478 [ #  # ][ #  # ]:          0 :         xMark->deleteMark(nMark);
     479                 :            :     }
     480                 :            : 
     481                 :            :     // Attachement lesen
     482         [ #  # ]:          0 :     if ( m_xEventAttacher.is() )
     483                 :            :     {
     484         [ #  # ]:          0 :         OInterfaceArray::const_iterator aAttach = m_aItems.begin();
     485         [ #  # ]:          0 :         OInterfaceArray::const_iterator aAttachEnd = m_aItems.end();
     486 [ #  # ][ #  # ]:          0 :         for ( sal_Int32 i=0; aAttach != aAttachEnd; ++aAttach, ++i )
     487                 :            :         {
     488         [ #  # ]:          0 :             Reference< XInterface > xAsIFace( *aAttach, UNO_QUERY );    // important to normalize this ....
     489         [ #  # ]:          0 :             Reference< XPropertySet > xAsSet( xAsIFace, UNO_QUERY );
     490 [ #  # ][ #  # ]:          0 :             m_xEventAttacher->attach( i, xAsIFace, makeAny( xAsSet ) );
                 [ #  # ]
     491                 :          0 :         }
     492         [ #  # ]:          0 :     }
     493                 :          0 : }
     494                 :            : 
     495                 :            : //------------------------------------------------------------------------------
     496                 :          0 : void SAL_CALL OInterfaceContainer::write( const Reference< XObjectOutputStream >& _rxOutStream ) throw(IOException, RuntimeException)
     497                 :            : {
     498         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_rMutex );
     499                 :          0 :     sal_Int32 nLen = m_aItems.size();
     500                 :            : 
     501                 :            :     // schreiben der laenge
     502 [ #  # ][ #  # ]:          0 :     _rxOutStream->writeLong(nLen);
     503                 :            : 
     504         [ #  # ]:          0 :     if (nLen)
     505                 :            :     {
     506                 :            :         // 1. Version
     507 [ #  # ][ #  # ]:          0 :         _rxOutStream->writeShort(0x0001);
     508                 :            : 
     509                 :            :         // 2. Objekte
     510         [ #  # ]:          0 :         for (sal_Int32 i = 0; i < nLen; i++)
     511                 :            :         {
     512         [ #  # ]:          0 :             Reference<XPersistObject>  xObj(m_aItems[i], UNO_QUERY);
     513         [ #  # ]:          0 :             if (xObj.is())
     514 [ #  # ][ #  # ]:          0 :                 _rxOutStream->writeObject(xObj);
     515                 :            :             else
     516                 :            :             {
     517                 :            :                 // ::com::sun::star::chaos::Error
     518                 :            :             }
     519                 :          0 :         }
     520                 :            : 
     521                 :            :         // 3. Scripts
     522         [ #  # ]:          0 :         writeEvents(_rxOutStream);
     523         [ #  # ]:          0 :     }
     524                 :          0 : }
     525                 :            : 
     526                 :            : //------------------------------------------------------------------------------
     527                 :            : namespace
     528                 :            : {
     529                 :          0 :     Reference< XPersistObject > lcl_createPlaceHolder( const Reference< XMultiServiceFactory >& _rxORB )
     530                 :            :     {
     531 [ #  # ][ #  # ]:          0 :         Reference< XPersistObject > xObject( _rxORB->createInstance( FRM_COMPONENT_HIDDENCONTROL ), UNO_QUERY );
     532                 :            :         DBG_ASSERT( xObject.is(), "lcl_createPlaceHolder: could not create a substitute for the unknown object!" );
     533         [ #  # ]:          0 :         if ( xObject.is() )
     534                 :            :         {
     535                 :            :             // set some properties describing what we did
     536         [ #  # ]:          0 :             Reference< XPropertySet > xObjProps( xObject, UNO_QUERY );
     537         [ #  # ]:          0 :             if ( xObject.is()  )
     538                 :            :             {
     539                 :            :                 try
     540                 :            :                 {
     541 [ #  # ][ #  # ]:          0 :                     xObjProps->setPropertyValue( PROPERTY_NAME, makeAny( FRM_RES_STRING( RID_STR_CONTROL_SUBSTITUTED_NAME ) ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     542 [ #  # ][ #  # ]:          0 :                     xObjProps->setPropertyValue( PROPERTY_TAG, makeAny( FRM_RES_STRING( RID_STR_CONTROL_SUBSTITUTED_EPXPLAIN ) ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     543                 :            :                 }
     544         [ #  # ]:          0 :                 catch(const Exception&)
     545                 :            :                 {
     546                 :            :                 }
     547                 :          0 :             }
     548                 :            :         }
     549                 :          0 :         return xObject;
     550                 :            :     }
     551                 :            : }
     552                 :            : 
     553                 :            : //------------------------------------------------------------------------------
     554                 :          0 : void SAL_CALL OInterfaceContainer::read( const Reference< XObjectInputStream >& _rxInStream ) throw(IOException, RuntimeException)
     555                 :            : {
     556         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_rMutex );
     557                 :            : 
     558                 :            :     // after ::read the object is expected to be in the state it was when ::write was called, so we have
     559                 :            :     // to empty ourself here
     560 [ #  # ][ #  # ]:          0 :     while (getCount())
     561         [ #  # ]:          0 :         removeByIndex(0);
     562                 :            : 
     563                 :            :     // Schreibt nur in Abhaengigkeit der Laenge
     564 [ #  # ][ #  # ]:          0 :     sal_Int32 nLen = _rxInStream->readLong();
     565                 :            : 
     566         [ #  # ]:          0 :     if (nLen)
     567                 :            :     {
     568                 :            :         // 1. Version
     569 [ #  # ][ #  # ]:          0 :         sal_uInt16 nVersion = _rxInStream->readShort(); (void)nVersion;
     570                 :            : 
     571                 :            :         // 2. Objekte
     572         [ #  # ]:          0 :         for (sal_Int32 i = 0; i < nLen; i++)
     573                 :            :         {
     574                 :          0 :             Reference<XPersistObject>  xObj;
     575                 :            :             try
     576                 :            :             {
     577 [ #  # ][ #  # ]:          0 :                 xObj = _rxInStream->readObject();
                 [ #  # ]
     578                 :            :             }
     579         [ #  # ]:          0 :             catch(const WrongFormatException&)
     580                 :            :             {
     581                 :            :                 // the object could not be read
     582                 :            :                 // create a object (so the readEvents below will assign the events to the right controls)
     583   [ #  #  #  # ]:          0 :                 xObj = lcl_createPlaceHolder( m_xServiceFactory );
     584         [ #  # ]:          0 :                 if ( !xObj.is() )
     585                 :            :                     // couldn't handle it
     586                 :          0 :                     throw;
     587                 :            :             }
     588      [ #  #  # ]:          0 :             catch(const Exception&)
     589                 :            :             {
     590                 :            :                 // unsere Map leeren
     591         [ #  # ]:          0 :                 while (!m_aItems.empty())
     592         [ #  # ]:          0 :                     removeElementsNoEvents(0);
     593                 :            : 
     594                 :            :                 // und die Exception nach aussen
     595                 :          0 :                 throw;
     596                 :            :             }
     597                 :            : 
     598         [ #  # ]:          0 :             if ( xObj.is() )
     599                 :            :             {
     600         [ #  # ]:          0 :                 Reference< XPropertySet > xElement( xObj, UNO_QUERY );
     601                 :            :                 try
     602                 :            :                 {
     603                 :            :                     implInsert(
     604                 :          0 :                         m_aItems.size(),    // position
     605                 :            :                         xElement,           // element to insert
     606                 :            :                         sal_False,          // no event attacher manager handling
     607                 :            :                         NULL,               // not yet approved - let implInsert do it
     608                 :            :                         sal_True            // fire the event
     609         [ #  # ]:          0 :                     );
     610                 :            :                 }
     611   [ #  #  #  # ]:          0 :                 catch( const Exception& )
     612                 :            :                 {
     613                 :            :                     OSL_FAIL( "OInterfaceContainerHelper::read: reading succeeded, but not inserting!" );
     614                 :            :                     // create a placeholder
     615   [ #  #  #  #  :          0 :                     xElement = xElement.query( lcl_createPlaceHolder( m_xServiceFactory ) );
                   #  # ]
     616         [ #  # ]:          0 :                     if ( !xElement.is() )
     617                 :            :                         // couldn't handle it
     618                 :          0 :                         throw;
     619                 :            :                     // insert the placeholder
     620         [ #  # ]:          0 :                     implInsert( m_aItems.size(), xElement, sal_False, NULL, sal_True );
     621                 :          0 :                 }
     622                 :            :             }
     623                 :          0 :         }
     624                 :            : 
     625         [ #  # ]:          0 :         readEvents(_rxInStream);
     626                 :            :     }
     627                 :            :     else
     628                 :            :     {
     629                 :            :         try
     630                 :            :         {
     631 [ #  # ][ #  # ]:          0 :             m_xEventAttacher = ::comphelper::createEventAttacherManager( m_xServiceFactory );
                 [ #  # ]
     632                 :            :             OSL_ENSURE( m_xEventAttacher.is(), "OInterfaceContainer::read: could not create an event attacher manager!" );
     633                 :            :         }
     634         [ #  # ]:          0 :         catch( const Exception& )
     635                 :            :         {
     636                 :            :             DBG_UNHANDLED_EXCEPTION();
     637                 :            :         }
     638         [ #  # ]:          0 :     }
     639                 :          0 : }
     640                 :            : 
     641                 :            : // XContainer
     642                 :            : //------------------------------------------------------------------------------
     643                 :       1464 : void SAL_CALL OInterfaceContainer::addContainerListener(const Reference<XContainerListener>& _rxListener) throw( RuntimeException )
     644                 :            : {
     645                 :       1464 :     m_aContainerListeners.addInterface(_rxListener);
     646                 :       1464 : }
     647                 :            : 
     648                 :            : //------------------------------------------------------------------------------
     649                 :       1168 : void SAL_CALL OInterfaceContainer::removeContainerListener(const Reference<XContainerListener>& _rxListener) throw( RuntimeException )
     650                 :            : {
     651                 :       1168 :     m_aContainerListeners.removeInterface(_rxListener);
     652                 :       1168 : }
     653                 :            : 
     654                 :            : // XEventListener
     655                 :            : //------------------------------------------------------------------------------
     656                 :         98 : void SAL_CALL OInterfaceContainer::disposing(const EventObject& _rSource) throw( RuntimeException )
     657                 :            : {
     658         [ +  - ]:         98 :     ::osl::MutexGuard aGuard( m_rMutex );
     659                 :            : 
     660         [ +  - ]:         98 :     Reference< XInterface > xSource( _rSource.Source, UNO_QUERY );
     661                 :            :         // normalized source
     662                 :            : 
     663                 :         98 :     OInterfaceArray::iterator j;
     664 [ +  - ][ +  + ]:        576 :     for ( j = m_aItems.begin(); j != m_aItems.end(); ++j )
     665                 :            :     {
     666                 :            :         DBG_ASSERT( j->get() == Reference< XInterface >( *j, UNO_QUERY ).get(),
     667                 :            :             "OInterfaceContainer::disposing: vector element not normalized!" );
     668                 :            : 
     669 [ +  - ][ +  - ]:        544 :         if ( xSource.get() == j->get() )
                 [ +  + ]
     670                 :            :             // found the element
     671                 :         66 :             break;
     672                 :            :     }
     673                 :            : 
     674 [ +  - ][ +  + ]:         98 :     if ( m_aItems.end() != j )
     675                 :            :     {
     676         [ +  - ]:         66 :         m_aItems.erase(j);
     677                 :            : 
     678                 :            :         // look up in, and erase from, m_aMap, too
     679         [ +  - ]:         66 :         OInterfaceMap::iterator i = m_aMap.begin();
     680 [ +  - ][ +  - ]:        430 :         while ( i != m_aMap.end() )
     681                 :            :         {
     682                 :            :             DBG_ASSERT( i->second.get() == Reference< XInterface >( i->second, UNO_QUERY ).get(),
     683                 :            :                 "OInterfaceContainer::disposing: map element not normalized!" );
     684                 :            : 
     685 [ +  - ][ +  - ]:        364 :             if ( i->second.get() == xSource.get() )
         [ +  - ][ +  + ]
     686                 :            :             {
     687                 :            :                 // found it
     688         [ +  - ]:         66 :                 m_aMap.erase(i);
     689                 :         66 :                 break;
     690                 :            :             }
     691                 :            : 
     692                 :        298 :             ++i;
     693                 :            : 
     694                 :            :             DBG_ASSERT( i != m_aMap.end(), "OInterfaceContainer::disposing: inconsistency: the element was in m_aItems, but not in m_aMap!" );
     695                 :            :         }
     696         [ +  - ]:         98 :     }
     697                 :         98 : }
     698                 :            : 
     699                 :            : // XPropertyChangeListener
     700                 :            : //------------------------------------------------------------------------------
     701                 :        465 : void OInterfaceContainer::propertyChange(const PropertyChangeEvent& evt)
     702                 :            : throw (::com::sun::star::uno::RuntimeException) {
     703         [ +  - ]:        465 :     if (evt.PropertyName == PROPERTY_NAME)
     704                 :            :     {
     705         [ +  - ]:        465 :         ::osl::MutexGuard aGuard( m_rMutex );
     706                 :            :         OInterfaceMap::iterator i = ::std::find(m_aMap.begin(), m_aMap.end(),
     707 [ +  - ][ +  - ]:        465 :             ::std::pair<const ::rtl::OUString, InterfaceRef >(::comphelper::getString(evt.OldValue),evt.Source));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     708 [ +  - ][ +  - ]:        465 :         if (i != m_aMap.end())
     709                 :            :         {
     710         [ +  - ]:        465 :             InterfaceRef  xCorrectType((*i).second);
     711         [ +  - ]:        465 :             m_aMap.erase(i);
     712 [ +  - ][ +  - ]:        465 :             m_aMap.insert(::std::pair<const ::rtl::OUString, InterfaceRef >(::comphelper::getString(evt.NewValue),xCorrectType));
         [ +  - ][ +  - ]
     713         [ +  - ]:        465 :         }
     714                 :            :     }
     715                 :        465 : }
     716                 :            : 
     717                 :            : // XElementAccess
     718                 :            : //------------------------------------------------------------------------------
     719                 :        346 : sal_Bool SAL_CALL OInterfaceContainer::hasElements() throw( RuntimeException )
     720                 :            : {
     721                 :        346 :     return !m_aMap.empty();
     722                 :            : }
     723                 :            : 
     724                 :            : //------------------------------------------------------------------------------
     725                 :          2 : Type SAL_CALL OInterfaceContainer::getElementType() throw(RuntimeException)
     726                 :            : {
     727                 :          2 :     return m_aElementType;
     728                 :            : }
     729                 :            : 
     730                 :            : // XEnumerationAccess
     731                 :            : //------------------------------------------------------------------------------
     732                 :          2 : Reference<XEnumeration> SAL_CALL OInterfaceContainer::createEnumeration() throw( RuntimeException )
     733                 :            : {
     734         [ +  - ]:          2 :     ::osl::MutexGuard aGuard( m_rMutex );
     735 [ +  - ][ +  - ]:          2 :     return new ::comphelper::OEnumerationByIndex(static_cast<XIndexAccess*>(this));
         [ +  - ][ +  - ]
                 [ +  - ]
     736                 :            : }
     737                 :            : 
     738                 :            : // XNameAccess
     739                 :            : //------------------------------------------------------------------------------
     740                 :         20 : Any SAL_CALL OInterfaceContainer::getByName( const ::rtl::OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
     741                 :            : {
     742                 :            :     ::std::pair <OInterfaceMap::iterator,
     743         [ +  - ]:         20 :           OInterfaceMap::iterator> aPair = m_aMap.equal_range(_rName);
     744                 :            : 
     745         [ +  + ]:         20 :     if (aPair.first == aPair.second)
     746         [ +  - ]:          2 :         throw NoSuchElementException();
     747                 :            : 
     748 [ +  - ][ +  - ]:         18 :     return (*aPair.first).second->queryInterface( m_aElementType );
                 [ +  - ]
     749                 :            : }
     750                 :            : 
     751                 :            : //------------------------------------------------------------------------------
     752                 :         22 : StringSequence SAL_CALL OInterfaceContainer::getElementNames() throw(RuntimeException)
     753                 :            : {
     754                 :         22 :     StringSequence aNameList(m_aItems.size());
     755         [ +  - ]:         22 :     ::rtl::OUString* pStringArray = aNameList.getArray();
     756                 :            : 
     757 [ +  - ][ +  - ]:         66 :     for (OInterfaceMap::const_iterator i = m_aMap.begin(); i != m_aMap.end(); ++i, ++pStringArray)
                 [ +  + ]
     758                 :            :     {
     759         [ +  - ]:         44 :         *pStringArray = (*i).first;
     760                 :            :     }
     761                 :         22 :     return aNameList;
     762                 :            : }
     763                 :            : 
     764                 :            : //------------------------------------------------------------------------------
     765                 :        527 : sal_Bool SAL_CALL OInterfaceContainer::hasByName( const ::rtl::OUString& _rName ) throw(RuntimeException)
     766                 :            : {
     767                 :            :     ::std::pair <OInterfaceMap::iterator,
     768         [ +  - ]:        527 :           OInterfaceMap::iterator> aPair = m_aMap.equal_range(_rName);
     769                 :        527 :     return aPair.first != aPair.second;
     770                 :            : }
     771                 :            : 
     772                 :            : // XIndexAccess
     773                 :            : //------------------------------------------------------------------------------
     774                 :       5986 : sal_Int32 OInterfaceContainer::getCount() throw( RuntimeException )
     775                 :            : {
     776                 :       5986 :     return m_aItems.size();
     777                 :            : }
     778                 :            : 
     779                 :            : //------------------------------------------------------------------------------
     780                 :       4828 : Any OInterfaceContainer::getByIndex(sal_Int32 _nIndex) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
     781                 :            : {
     782 [ +  - ][ +  + ]:       4828 :     if (_nIndex < 0 || (_nIndex >= (sal_Int32)m_aItems.size()))
                 [ +  + ]
     783         [ +  - ]:          2 :         throw IndexOutOfBoundsException();
     784                 :            : 
     785                 :       4826 :     return m_aItems[_nIndex]->queryInterface( m_aElementType );
     786                 :            : }
     787                 :            : 
     788                 :            : //------------------------------------------------------------------------------
     789                 :        928 : void OInterfaceContainer::approveNewElement( const Reference< XPropertySet >& _rxObject, ElementDescription* _pElement )
     790                 :            : {
     791                 :            :     // it has to be non-NULL
     792         [ -  + ]:        928 :     if ( !_rxObject.is() )
     793 [ #  # ][ #  # ]:          0 :         throw IllegalArgumentException(FRM_RES_STRING(RID_STR_NEED_NON_NULL_OBJECT), static_cast<XContainer*>(this), 1);
                 [ #  # ]
     794                 :            : 
     795                 :            :     // it has to support our element type interface
     796 [ +  - ][ +  - ]:        928 :     Any aCorrectType = _rxObject->queryInterface( m_aElementType );
     797         [ -  + ]:        928 :     if ( !aCorrectType.hasValue() )
     798         [ #  # ]:          0 :         lcl_throwIllegalArgumentException();
     799                 :            : 
     800                 :            :     // it has to have a "Name" property
     801 [ +  - ][ +  - ]:        928 :     if ( !hasProperty( PROPERTY_NAME, _rxObject ) )
                 [ -  + ]
     802         [ #  # ]:          0 :         lcl_throwIllegalArgumentException();
     803                 :            : 
     804                 :            :     // it has to be a child, and it must not have a parent already
     805         [ +  - ]:        928 :     Reference< XChild > xChild( _rxObject, UNO_QUERY );
     806 [ +  - ][ +  - ]:        928 :     if ( !xChild.is() || xChild->getParent().is() )
         [ +  - ][ -  + ]
                 [ +  - ]
           [ -  +  #  # ]
     807                 :            :     {
     808         [ #  # ]:          0 :         lcl_throwIllegalArgumentException();
     809                 :            :     }
     810                 :            : 
     811                 :            :     // passed all tests. cache the information we have so far
     812                 :            :     DBG_ASSERT( _pElement, "OInterfaceContainer::approveNewElement: invalid event descriptor!" );
     813         [ +  - ]:        928 :     if ( _pElement )
     814                 :            :     {
     815         [ +  - ]:        928 :         _pElement->xPropertySet = _rxObject;
     816         [ +  - ]:        928 :         _pElement->xChild = xChild;
     817                 :        928 :         _pElement->aElementTypeInterface = aCorrectType;
     818 [ +  - ][ +  - ]:        928 :         _pElement->xInterface = Reference< XInterface >( _rxObject, UNO_QUERY );    // normalized XInterface
     819                 :        928 :     }
     820                 :        928 : }
     821                 :            : 
     822                 :            : //------------------------------------------------------------------------------
     823                 :        918 : void OInterfaceContainer::implInsert(sal_Int32 _nIndex, const Reference< XPropertySet >& _rxElement,
     824                 :            :     sal_Bool _bEvents, ElementDescription* _pApprovalResult, sal_Bool _bFire ) throw( IllegalArgumentException )
     825                 :            : {
     826 [ +  + ][ +  - ]:        918 :     const bool bHandleEvents = _bEvents && m_xEventAttacher.is();
     827                 :            : 
     828                 :            :     // SYNCHRONIZED ----->
     829         [ +  - ]:        918 :     ::osl::ClearableMutexGuard aGuard( m_rMutex );
     830                 :            : 
     831                 :            :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     832                 :        918 :     ::std::auto_ptr< ElementDescription > aAutoDeleteMetaData;
     833                 :            :     SAL_WNODEPRECATED_DECLARATIONS_POP
     834                 :        918 :     ElementDescription* pElementMetaData = _pApprovalResult;
     835         [ +  + ]:        918 :     if ( !pElementMetaData )
     836                 :            :     {   // not yet approved by the caller -> do ourself
     837         [ +  - ]:        515 :         pElementMetaData = createElementMetaData();
     838                 :            :         DBG_ASSERT( pElementMetaData, "OInterfaceContainer::implInsert: createElementMetaData returned nonsense!" );
     839                 :            : 
     840                 :            :         // ensure that the meta data structure will be deleted later on
     841                 :            :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     842         [ +  - ]:        515 :         aAutoDeleteMetaData = ::std::auto_ptr< ElementDescription >( pElementMetaData );
     843                 :            :         SAL_WNODEPRECATED_DECLARATIONS_POP
     844                 :            : 
     845                 :            :         // will throw an exception if necessary
     846         [ +  + ]:        515 :         approveNewElement( _rxElement, pElementMetaData );
     847                 :            :     }
     848                 :            : 
     849                 :            : 
     850                 :            :     // approveNewElement (no matter if called here or outside) has ensure that all relevant interfaces
     851                 :            :     // exist
     852                 :            : 
     853                 :            :     // set the name, and add as change listener for the name
     854                 :        916 :     ::rtl::OUString sName;
     855 [ +  - ][ +  - ]:        916 :     _rxElement->getPropertyValue(PROPERTY_NAME) >>= sName;
                 [ +  - ]
     856 [ +  - ][ +  - ]:        916 :     _rxElement->addPropertyChangeListener(PROPERTY_NAME, this);
         [ +  - ][ +  - ]
     857                 :            : 
     858                 :            :     // insert the object into our internal structures
     859         [ -  + ]:        916 :     if (_nIndex > (sal_Int32)m_aItems.size()) // ermitteln des tatsaechlichen Indexs
     860                 :            :     {
     861                 :          0 :         _nIndex = m_aItems.size();
     862         [ #  # ]:          0 :         m_aItems.push_back( pElementMetaData->xInterface );
     863                 :            :     }
     864                 :            :     else
     865 [ +  - ][ +  - ]:        916 :         m_aItems.insert( m_aItems.begin() + _nIndex, pElementMetaData->xInterface );
     866                 :            : 
     867 [ +  - ][ +  - ]:        916 :     m_aMap.insert( ::std::pair< const ::rtl::OUString, InterfaceRef >( sName, pElementMetaData->xInterface ) );
                 [ +  - ]
     868                 :            : 
     869                 :            :     // announce ourself as parent to the new element
     870 [ +  - ][ +  - ]:        916 :     pElementMetaData->xChild->setParent(static_cast<XContainer*>(this));
                 [ +  - ]
     871                 :            : 
     872                 :            :     // handle the events
     873         [ +  + ]:        916 :     if ( bHandleEvents )
     874                 :            :     {
     875 [ +  - ][ +  - ]:        912 :         m_xEventAttacher->insertEntry(_nIndex);
     876 [ +  - ][ +  - ]:        912 :         m_xEventAttacher->attach( _nIndex, pElementMetaData->xInterface, makeAny( _rxElement ) );
                 [ +  - ]
     877                 :            :     }
     878                 :            : 
     879                 :            :     // notify derived classes
     880         [ +  - ]:        916 :     implInserted( pElementMetaData );
     881                 :            : 
     882         [ +  - ]:        916 :     aGuard.clear();
     883                 :            :     // <----- SYNCHRONIZED
     884                 :            : 
     885                 :            :     // insert faked VBA events?
     886                 :        916 :     bool bHandleVbaEvents = false;
     887                 :            :     try
     888                 :            :     {
     889 [ +  - ][ +  - ]:        916 :         _rxElement->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("GenerateVbaEvents") ) ) >>= bHandleVbaEvents;
         [ +  + ][ -  + ]
     890                 :            :     }
     891         [ +  - ]:        301 :     catch( const Exception& )
     892                 :            :     {
     893                 :            :     }
     894         [ +  + ]:        916 :     if ( bHandleVbaEvents )
     895                 :            :     {
     896         [ +  - ]:         14 :         Reference< XEventAttacherManager > xMgr ( pElementMetaData->xInterface, UNO_QUERY );
     897         [ -  + ]:         14 :         if ( xMgr.is() )
     898                 :            :         {
     899 [ #  # ][ #  # ]:          0 :             OInterfaceContainer* pIfcMgr = dynamic_cast< OInterfaceContainer* >( xMgr.get() );
     900         [ #  # ]:          0 :             sal_Int32 nLen = pIfcMgr->getCount();
     901 [ #  # ][ #  # ]:          0 :             for ( sal_Int32 i = 0; (i < nLen) && pIfcMgr ; ++i )
                 [ #  # ]
     902                 :            :             {
     903                 :            :                 // add fake events to the control at index i
     904         [ #  # ]:          0 :                 pIfcMgr->impl_addVbEvents_nolck_nothrow( i );
     905                 :            :             }
     906                 :            :         }
     907                 :            :         else
     908                 :            :         {
     909                 :            :             // add fake events to the control at index i
     910         [ +  - ]:         14 :             impl_addVbEvents_nolck_nothrow( _nIndex );
     911                 :         14 :         }
     912                 :            :     }
     913                 :            : 
     914                 :            :     // fire the notification about the change
     915         [ +  + ]:        916 :     if ( _bFire )
     916                 :            :     {
     917                 :            :         // notify listeners
     918         [ +  - ]:        912 :         ContainerEvent aEvt;
     919         [ +  - ]:        912 :         aEvt.Source   = static_cast<XContainer*>(this);
     920         [ +  - ]:        912 :         aEvt.Accessor <<= _nIndex;
     921                 :        912 :         aEvt.Element  = pElementMetaData->aElementTypeInterface;
     922                 :            : 
     923         [ +  - ]:        912 :         aGuard.clear();
     924 [ +  - ][ +  - ]:        912 :         m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvt );
     925 [ +  - ][ +  - ]:        918 :     }
     926                 :        916 : }
     927                 :            : 
     928                 :            : //------------------------------------------------------------------------------
     929                 :          0 : void OInterfaceContainer::removeElementsNoEvents(sal_Int32 nIndex)
     930                 :            : {
     931         [ #  # ]:          0 :     OInterfaceArray::iterator i = m_aItems.begin() + nIndex;
     932                 :          0 :     InterfaceRef  xElement(*i);
     933                 :            : 
     934         [ #  # ]:          0 :     OInterfaceMap::iterator j = m_aMap.begin();
     935 [ #  # ][ #  # ]:          0 :     while (j != m_aMap.end() && (*j).second != xElement) ++j;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     936                 :            : 
     937         [ #  # ]:          0 :     m_aItems.erase(i);
     938         [ #  # ]:          0 :     m_aMap.erase(j);
     939                 :            : 
     940         [ #  # ]:          0 :     Reference<XPropertySet>  xSet(xElement, UNO_QUERY);
     941         [ #  # ]:          0 :     if (xSet.is())
     942 [ #  # ][ #  # ]:          0 :         xSet->removePropertyChangeListener(PROPERTY_NAME, this);
         [ #  # ][ #  # ]
     943                 :            : 
     944         [ #  # ]:          0 :     Reference<XChild>  xChild(xElement, UNO_QUERY);
     945         [ #  # ]:          0 :     if (xChild.is())
     946 [ #  # ][ #  # ]:          0 :         xChild->setParent(InterfaceRef ());
     947                 :          0 : }
     948                 :            : 
     949                 :            : //------------------------------------------------------------------------------
     950                 :        916 : void OInterfaceContainer::implInserted( const ElementDescription* /*_pElement*/ )
     951                 :            : {
     952                 :            :     // not inrerested in
     953                 :        916 : }
     954                 :            : 
     955                 :            : //------------------------------------------------------------------------------
     956                 :        451 : void OInterfaceContainer::implRemoved( const InterfaceRef& /*_rxObject*/ )
     957                 :            : {
     958                 :            :     // not inrerested in
     959                 :        451 : }
     960                 :            : 
     961                 :            : //------------------------------------------------------------------------------
     962                 :         12 : void OInterfaceContainer::impl_replacedElement( const ContainerEvent& _rEvent, ::osl::ClearableMutexGuard& _rInstanceLock )
     963                 :            : {
     964                 :         12 :     _rInstanceLock.clear();
     965                 :         12 :     m_aContainerListeners.notifyEach( &XContainerListener::elementReplaced, _rEvent );
     966                 :         12 : }
     967                 :            : 
     968                 :            : // XIndexContainer
     969                 :            : //------------------------------------------------------------------------------
     970                 :        511 : void SAL_CALL OInterfaceContainer::insertByIndex( sal_Int32 _nIndex, const Any& _rElement ) throw(IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
     971                 :            : {
     972                 :        511 :     Reference< XPropertySet > xElement;
     973         [ +  - ]:        511 :     _rElement >>= xElement;
     974         [ +  + ]:        511 :     implInsert( _nIndex, xElement, sal_True /* event handling */ , NULL /* not yet approved */ , sal_True /* notification */ );
     975                 :        509 : }
     976                 :            : 
     977                 :            : //------------------------------------------------------------------------------
     978                 :         14 : void OInterfaceContainer::implReplaceByIndex( const sal_Int32 _nIndex, const Any& _rNewElement, ::osl::ClearableMutexGuard& _rClearBeforeNotify )
     979                 :            : {
     980                 :            :     OSL_PRECOND( ( _nIndex >= 0 ) && ( _nIndex < (sal_Int32)m_aItems.size() ), "OInterfaceContainer::implReplaceByIndex: precondition not met (index)!" );
     981                 :            : 
     982                 :            :     // approve the new object
     983                 :            :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     984         [ +  - ]:         14 :     ::std::auto_ptr< ElementDescription > aElementMetaData( createElementMetaData() );
     985                 :            :     SAL_WNODEPRECATED_DECLARATIONS_POP
     986                 :            :     DBG_ASSERT( aElementMetaData.get(), "OInterfaceContainer::implReplaceByIndex: createElementMetaData returned nonsense!" );
     987                 :            :     {
     988                 :         14 :         Reference< XPropertySet > xElementProps;
     989         [ +  - ]:         14 :         _rNewElement >>= xElementProps;
     990         [ +  + ]:         14 :         approveNewElement( xElementProps, aElementMetaData.get() );
     991                 :            :     }
     992                 :            : 
     993                 :            :     // get the old element
     994                 :         12 :     InterfaceRef  xOldElement( m_aItems[ _nIndex ] );
     995                 :            :     DBG_ASSERT( xOldElement.get() == Reference< XInterface >( xOldElement, UNO_QUERY ).get(),
     996                 :            :         "OInterfaceContainer::implReplaceByIndex: elements should be held normalized!" );
     997                 :            : 
     998                 :            :     // locate the old element in the map
     999         [ +  - ]:         12 :     OInterfaceMap::iterator j = m_aMap.begin();
    1000 [ +  - ][ +  - ]:         18 :     while ( ( j != m_aMap.end() ) && ( j->second.get() != xOldElement.get() ) )
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
                 [ +  - ]
           [ +  +  #  # ]
    1001                 :          6 :         ++j;
    1002                 :            : 
    1003                 :            :     // remove event knittings
    1004         [ +  - ]:         12 :     if ( m_xEventAttacher.is() )
    1005                 :            :     {
    1006         [ +  - ]:         12 :         InterfaceRef xNormalized( xOldElement, UNO_QUERY );
    1007 [ +  - ][ +  - ]:         12 :         m_xEventAttacher->detach( _nIndex, xNormalized );
    1008 [ +  - ][ +  - ]:         12 :         m_xEventAttacher->removeEntry( _nIndex );
    1009                 :            :     }
    1010                 :            : 
    1011                 :            :     // don't listen for property changes anymore
    1012         [ +  - ]:         12 :     Reference<XPropertySet>  xSet( xOldElement, UNO_QUERY );
    1013         [ +  - ]:         12 :     if (xSet.is())
    1014 [ +  - ][ +  - ]:         12 :         xSet->removePropertyChangeListener(PROPERTY_NAME, this);
         [ +  - ][ +  - ]
    1015                 :            : 
    1016                 :            :     // give the old element a new (void) parent
    1017         [ +  - ]:         12 :     Reference<XChild>  xChild(xOldElement, UNO_QUERY);
    1018         [ +  - ]:         12 :     if (xChild.is())
    1019 [ +  - ][ +  - ]:         12 :         xChild->setParent(InterfaceRef ());
    1020                 :            : 
    1021                 :            :     // remove the old one
    1022         [ +  - ]:         12 :     m_aMap.erase(j);
    1023                 :            : 
    1024                 :            :     // examine the new element
    1025                 :         12 :     ::rtl::OUString sName;
    1026                 :            :     DBG_ASSERT( aElementMetaData.get()->xPropertySet.is(), "OInterfaceContainer::implReplaceByIndex: what did approveNewElement do?" );
    1027                 :            : 
    1028 [ +  - ][ +  - ]:         12 :     aElementMetaData.get()->xPropertySet->getPropertyValue(PROPERTY_NAME) >>= sName;
                 [ +  - ]
    1029 [ +  - ][ +  - ]:         12 :     aElementMetaData.get()->xPropertySet->addPropertyChangeListener(PROPERTY_NAME, this);
         [ +  - ][ +  - ]
    1030                 :            : 
    1031                 :            :     // insert the new one
    1032 [ +  - ][ +  - ]:         12 :     m_aMap.insert( ::std::pair<const ::rtl::OUString, InterfaceRef  >( sName, aElementMetaData.get()->xInterface ) );
                 [ +  - ]
    1033         [ +  - ]:         12 :     m_aItems[ _nIndex ] = aElementMetaData.get()->xInterface;
    1034                 :            : 
    1035 [ +  - ][ +  - ]:         12 :     aElementMetaData.get()->xChild->setParent(static_cast<XContainer*>(this));
                 [ +  - ]
    1036                 :            : 
    1037         [ +  - ]:         12 :     if ( m_xEventAttacher.is() )
    1038                 :            :     {
    1039 [ +  - ][ +  - ]:         12 :         m_xEventAttacher->insertEntry( _nIndex );
    1040 [ +  - ][ +  - ]:         12 :         m_xEventAttacher->attach( _nIndex, aElementMetaData.get()->xInterface, makeAny( aElementMetaData.get()->xPropertySet ) );
                 [ +  - ]
    1041                 :            :     }
    1042                 :            : 
    1043         [ +  - ]:         12 :     ContainerEvent aReplaceEvent;
    1044         [ +  - ]:         12 :     aReplaceEvent.Source   = static_cast< XContainer* >( this );
    1045         [ +  - ]:         12 :     aReplaceEvent.Accessor <<= _nIndex;
    1046 [ +  - ][ +  - ]:         12 :     aReplaceEvent.Element  = aElementMetaData.get()->xInterface->queryInterface( m_aElementType );
    1047 [ +  - ][ +  - ]:         12 :     aReplaceEvent.ReplacedElement = xOldElement->queryInterface( m_aElementType );
    1048                 :            : 
    1049 [ +  - ][ +  - ]:         14 :     impl_replacedElement( aReplaceEvent, _rClearBeforeNotify );
                 [ +  - ]
    1050                 :         12 : }
    1051                 :            : 
    1052                 :            : //------------------------------------------------------------------------------
    1053                 :        461 : void OInterfaceContainer::implCheckIndex( const sal_Int32 _nIndex ) SAL_THROW( ( ::com::sun::star::lang::IndexOutOfBoundsException ) )
    1054                 :            : {
    1055 [ +  - ][ +  + ]:        461 :     if (_nIndex < 0 || _nIndex >= (sal_Int32)m_aItems.size())
                 [ +  + ]
    1056         [ +  - ]:          4 :         throw IndexOutOfBoundsException();
    1057                 :        457 : }
    1058                 :            : 
    1059                 :            : //------------------------------------------------------------------------------
    1060                 :          8 : void SAL_CALL OInterfaceContainer::replaceByIndex(sal_Int32 _nIndex, const Any& Element) throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
    1061                 :            : {
    1062         [ +  - ]:          8 :     ::osl::ClearableMutexGuard aGuard( m_rMutex );
    1063                 :            :     // check the index
    1064         [ +  + ]:          8 :     implCheckIndex( _nIndex );
    1065                 :            :     // do the replace
    1066 [ +  + ][ +  - ]:          8 :     implReplaceByIndex( _nIndex, Element, aGuard );
    1067                 :          4 : }
    1068                 :            : 
    1069                 :            : //------------------------------------------------------------------------------
    1070                 :        451 : void OInterfaceContainer::implRemoveByIndex( const sal_Int32 _nIndex, ::osl::ClearableMutexGuard& _rClearBeforeNotify )
    1071                 :            : {
    1072                 :            :     OSL_PRECOND( ( _nIndex >= 0 ) && ( _nIndex < (sal_Int32)m_aItems.size() ), "OInterfaceContainer::implRemoveByIndex: precondition not met (index)!" );
    1073                 :            : 
    1074         [ +  - ]:        451 :     OInterfaceArray::iterator i = m_aItems.begin() + _nIndex;
    1075                 :        451 :     InterfaceRef  xElement(*i);
    1076                 :            : 
    1077         [ +  - ]:        451 :     OInterfaceMap::iterator j = m_aMap.begin();
    1078 [ +  - ][ +  - ]:        613 :     while (j != m_aMap.end() && (*j).second != xElement) ++j;
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
           [ +  +  #  # ]
    1079                 :            : 
    1080         [ +  - ]:        451 :     m_aItems.erase(i);
    1081         [ +  - ]:        451 :     m_aMap.erase(j);
    1082                 :            : 
    1083                 :            :     // remove event knittings
    1084         [ +  - ]:        451 :     if ( m_xEventAttacher.is() )
    1085                 :            :     {
    1086         [ +  - ]:        451 :         InterfaceRef xNormalized( xElement, UNO_QUERY );
    1087 [ +  - ][ +  - ]:        451 :         m_xEventAttacher->detach( _nIndex, xNormalized );
    1088 [ +  - ][ +  - ]:        451 :         m_xEventAttacher->removeEntry( _nIndex );
    1089                 :            :     }
    1090                 :            : 
    1091         [ +  - ]:        451 :     Reference<XPropertySet>  xSet(xElement, UNO_QUERY);
    1092         [ +  - ]:        451 :     if (xSet.is())
    1093 [ +  - ][ +  - ]:        451 :         xSet->removePropertyChangeListener(PROPERTY_NAME, this);
         [ +  - ][ +  - ]
    1094                 :            : 
    1095         [ +  - ]:        451 :     Reference<XChild>  xChild(xElement, UNO_QUERY);
    1096         [ +  - ]:        451 :     if (xChild.is())
    1097 [ +  - ][ +  - ]:        451 :         xChild->setParent(InterfaceRef ());
    1098                 :            : 
    1099                 :            :     // notify derived classes
    1100         [ +  - ]:        451 :     implRemoved(xElement);
    1101                 :            : 
    1102                 :            :     // notify listeners
    1103         [ +  - ]:        451 :     ContainerEvent aEvt;
    1104         [ +  - ]:        451 :     aEvt.Source     = static_cast<XContainer*>(this);
    1105 [ +  - ][ +  - ]:        451 :     aEvt.Element    = xElement->queryInterface( m_aElementType );
    1106         [ +  - ]:        451 :     aEvt.Accessor   <<= _nIndex;
    1107                 :            : 
    1108         [ +  - ]:        451 :     _rClearBeforeNotify.clear();
    1109 [ +  - ][ +  - ]:        451 :     m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvt );
    1110                 :        451 : }
    1111                 :            : 
    1112                 :            : //------------------------------------------------------------------------------
    1113                 :        453 : void SAL_CALL OInterfaceContainer::removeByIndex(sal_Int32 _nIndex) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
    1114                 :            : {
    1115         [ +  - ]:        453 :     ::osl::ClearableMutexGuard aGuard( m_rMutex );
    1116                 :            :     // check the index
    1117         [ +  + ]:        453 :     implCheckIndex( _nIndex );
    1118                 :            :     // do the removal
    1119 [ +  - ][ +  - ]:        453 :     implRemoveByIndex( _nIndex, aGuard );
    1120                 :        451 : }
    1121                 :            : 
    1122                 :            : //------------------------------------------------------------------------
    1123                 :        818 : ElementDescription* OInterfaceContainer::createElementMetaData( )
    1124                 :            : {
    1125         [ +  - ]:        818 :     return new ElementDescription;
    1126                 :            : }
    1127                 :            : 
    1128                 :            : //------------------------------------------------------------------------
    1129                 :        405 : void SAL_CALL OInterfaceContainer::insertByName(const ::rtl::OUString& _rName, const Any& _rElement) throw( IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException )
    1130                 :            : {
    1131                 :        405 :     Reference< XPropertySet > xElementProps;
    1132                 :            : 
    1133                 :            :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1134         [ +  - ]:        405 :     ::std::auto_ptr< ElementDescription > aElementMetaData( createElementMetaData() );
    1135                 :            :     SAL_WNODEPRECATED_DECLARATIONS_POP
    1136                 :            :     DBG_ASSERT( aElementMetaData.get(), "OInterfaceContainer::insertByName: createElementMetaData returned nonsense!" );
    1137                 :            : 
    1138                 :            :     // ensure the correct name of the element
    1139                 :            :     try
    1140                 :            :     {
    1141         [ +  - ]:        405 :         _rElement >>= xElementProps;
    1142         [ +  + ]:        405 :         approveNewElement( xElementProps, aElementMetaData.get() );
    1143                 :            : 
    1144 [ +  - ][ +  - ]:        403 :         xElementProps->setPropertyValue( PROPERTY_NAME, makeAny( _rName ) );
         [ +  - ][ +  - ]
    1145                 :            :     }
    1146                 :          4 :     catch( const IllegalArgumentException& )
    1147                 :            :     {
    1148                 :          2 :         throw;  // allowed to leave
    1149                 :            :     }
    1150   [ -  +  -  - ]:          2 :     catch( const ElementExistException& )
    1151                 :            :     {
    1152                 :          0 :         throw;  // allowed to leave
    1153                 :            :     }
    1154         [ #  # ]:          0 :     catch( const Exception& )
    1155                 :            :     {
    1156                 :            :         OSL_FAIL( "OInterfaceContainer::insertByName: caught an exception!" );
    1157                 :            :     }
    1158 [ +  - ][ +  - ]:        405 :     implInsert( m_aItems.size(), xElementProps, sal_True, aElementMetaData.get(), sal_True );
    1159                 :        403 : }
    1160                 :            : 
    1161                 :            : //------------------------------------------------------------------------
    1162                 :          8 : void SAL_CALL OInterfaceContainer::replaceByName(const ::rtl::OUString& Name, const Any& Element) throw( IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException )
    1163                 :            : {
    1164         [ +  - ]:          8 :     ::osl::ClearableMutexGuard aGuard( m_rMutex );
    1165                 :            :     ::std::pair <OInterfaceMap::iterator,
    1166         [ +  - ]:          8 :           OInterfaceMap::iterator> aPair = m_aMap.equal_range(Name);
    1167         [ -  + ]:          8 :     if (aPair.first == aPair.second)
    1168         [ #  # ]:          0 :         throw NoSuchElementException();
    1169                 :            : 
    1170         [ -  + ]:          8 :     if (Element.getValueType().getTypeClass() != TypeClass_INTERFACE)
    1171         [ #  # ]:          0 :         lcl_throwIllegalArgumentException();
    1172                 :            : 
    1173                 :          8 :     Reference<XPropertySet> xSet;
    1174         [ +  - ]:          8 :     Element >>= xSet;
    1175         [ +  - ]:          8 :     if (xSet.is())
    1176                 :            :     {
    1177 [ +  - ][ +  - ]:          8 :         if (!hasProperty(PROPERTY_NAME, xSet))
                 [ -  + ]
    1178         [ #  # ]:          0 :             lcl_throwIllegalArgumentException();
    1179                 :            : 
    1180 [ +  - ][ +  - ]:          8 :         xSet->setPropertyValue(PROPERTY_NAME, makeAny(Name));
         [ +  - ][ +  - ]
    1181                 :            :     }
    1182                 :            : 
    1183                 :            :     // determine the element pos
    1184 [ +  - ][ +  - ]:          8 :     sal_Int32 nPos = ::std::find(m_aItems.begin(), m_aItems.end(), (*aPair.first).second) - m_aItems.begin();
                 [ +  - ]
    1185                 :            : 
    1186 [ +  - ][ +  - ]:          8 :     implReplaceByIndex( nPos, Element, aGuard );
    1187                 :          8 : }
    1188                 :            : 
    1189                 :            : //------------------------------------------------------------------------
    1190                 :          8 : void SAL_CALL OInterfaceContainer::removeByName(const ::rtl::OUString& Name) throw( NoSuchElementException, WrappedTargetException, RuntimeException )
    1191                 :            : {
    1192         [ +  - ]:          8 :     ::osl::MutexGuard aGuard( m_rMutex );
    1193                 :            :     ::std::pair <OInterfaceMap::iterator,
    1194         [ +  - ]:          8 :           OInterfaceMap::iterator> aPair = m_aMap.equal_range(Name);
    1195         [ +  + ]:          8 :     if (aPair.first == aPair.second)
    1196         [ +  - ]:          2 :         throw NoSuchElementException();
    1197                 :            : 
    1198 [ +  - ][ +  - ]:          6 :     sal_Int32 nPos = ::std::find(m_aItems.begin(), m_aItems.end(), (*aPair.first).second) - m_aItems.begin();
                 [ +  - ]
    1199 [ +  - ][ +  - ]:          8 :     removeByIndex(nPos);
    1200                 :          6 : }
    1201                 :            : 
    1202                 :            : 
    1203                 :            : // XEventAttacherManager
    1204                 :            : //------------------------------------------------------------------------
    1205                 :          4 : void SAL_CALL OInterfaceContainer::registerScriptEvent( sal_Int32 nIndex, const ScriptEventDescriptor& aScriptEvent ) throw(IllegalArgumentException, RuntimeException)
    1206                 :            : {
    1207         [ +  - ]:          4 :     ::osl::ClearableMutexGuard aGuard( m_rMutex );
    1208         [ +  - ]:          4 :     if ( m_xEventAttacher.is() )
    1209                 :            :     {
    1210 [ +  - ][ +  - ]:          4 :         m_xEventAttacher->registerScriptEvent( nIndex, aScriptEvent );
    1211         [ +  - ]:          4 :         aGuard.clear();
    1212         [ +  - ]:          4 :         impl_addVbEvents_nolck_nothrow( nIndex ); // add fake vba events
    1213         [ +  - ]:          4 :     }
    1214                 :          4 : }
    1215                 :            : 
    1216                 :            : //------------------------------------------------------------------------
    1217                 :        484 : void SAL_CALL OInterfaceContainer::registerScriptEvents( sal_Int32 nIndex, const Sequence< ScriptEventDescriptor >& aScriptEvents ) throw(IllegalArgumentException, RuntimeException)
    1218                 :            : {
    1219         [ +  - ]:        484 :     ::osl::ClearableMutexGuard aGuard( m_rMutex );
    1220         [ +  - ]:        484 :     if ( m_xEventAttacher.is() )
    1221                 :            :     {
    1222 [ +  - ][ +  - ]:        484 :         m_xEventAttacher->registerScriptEvents( nIndex, aScriptEvents );
    1223         [ +  - ]:        484 :         aGuard.clear();
    1224         [ +  - ]:        484 :         impl_addVbEvents_nolck_nothrow( nIndex ); // add fake vba events
    1225         [ +  - ]:        484 :     }
    1226                 :        484 : }
    1227                 :            : 
    1228                 :            : //------------------------------------------------------------------------
    1229                 :          2 : void SAL_CALL OInterfaceContainer::revokeScriptEvent( sal_Int32 nIndex, const ::rtl::OUString& aListenerType, const ::rtl::OUString& aEventMethod, const ::rtl::OUString& aRemoveListenerParam ) throw(IllegalArgumentException, RuntimeException)
    1230                 :            : {
    1231         [ +  - ]:          2 :     if ( m_xEventAttacher.is() )
    1232                 :          2 :         m_xEventAttacher->revokeScriptEvent( nIndex, aListenerType, aEventMethod, aRemoveListenerParam );
    1233                 :          2 : }
    1234                 :            : 
    1235                 :            : //------------------------------------------------------------------------
    1236                 :          2 : void SAL_CALL OInterfaceContainer::revokeScriptEvents( sal_Int32 nIndex ) throw(IllegalArgumentException, RuntimeException)
    1237                 :            : {
    1238         [ +  - ]:          2 :     if ( m_xEventAttacher.is() )
    1239                 :          2 :         m_xEventAttacher->revokeScriptEvents( nIndex );
    1240                 :          2 : }
    1241                 :            : 
    1242                 :            : //------------------------------------------------------------------------
    1243                 :          2 : void SAL_CALL OInterfaceContainer::insertEntry( sal_Int32 nIndex ) throw(IllegalArgumentException, RuntimeException)
    1244                 :            : {
    1245         [ +  - ]:          2 :     if ( m_xEventAttacher.is() )
    1246                 :          2 :         m_xEventAttacher->insertEntry( nIndex );
    1247                 :          2 : }
    1248                 :            : 
    1249                 :            : //------------------------------------------------------------------------
    1250                 :          2 : void SAL_CALL OInterfaceContainer::removeEntry( sal_Int32 nIndex ) throw(IllegalArgumentException, RuntimeException)
    1251                 :            : {
    1252         [ +  - ]:          2 :     if ( m_xEventAttacher.is() )
    1253                 :          2 :         m_xEventAttacher->removeEntry( nIndex );
    1254                 :          2 : }
    1255                 :            : 
    1256                 :            : //------------------------------------------------------------------------
    1257                 :         16 : Sequence< ScriptEventDescriptor > SAL_CALL OInterfaceContainer::getScriptEvents( sal_Int32 nIndex ) throw(IllegalArgumentException, RuntimeException)
    1258                 :            : {
    1259                 :         16 :     Sequence< ScriptEventDescriptor > aReturn;
    1260         [ +  - ]:         16 :     if ( m_xEventAttacher.is() )
    1261                 :            :     {
    1262 [ +  - ][ +  - ]:         16 :         aReturn = m_xEventAttacher->getScriptEvents( nIndex );
         [ +  - ][ +  - ]
    1263 [ +  - ][ -  + ]:         16 :             if ( lcl_hasVbaEvents( aReturn ) )
    1264                 :            :             {
    1265 [ #  # ][ #  # ]:          0 :                 aReturn = lcl_stripVbaEvents( aReturn );
                 [ #  # ]
    1266                 :            :             }
    1267                 :            :     }
    1268                 :         16 :     return aReturn;
    1269                 :            : }
    1270                 :            : 
    1271                 :            : //------------------------------------------------------------------------
    1272                 :        109 : void SAL_CALL OInterfaceContainer::attach( sal_Int32 nIndex, const Reference< XInterface >& xObject, const Any& aHelper ) throw(IllegalArgumentException, ServiceNotRegisteredException, RuntimeException)
    1273                 :            : {
    1274         [ +  - ]:        109 :     if ( m_xEventAttacher.is() )
    1275                 :        109 :         m_xEventAttacher->attach( nIndex, xObject, aHelper );
    1276                 :        109 : }
    1277                 :            : 
    1278                 :            : //------------------------------------------------------------------------
    1279                 :        103 : void SAL_CALL OInterfaceContainer::detach( sal_Int32 nIndex, const Reference< XInterface >& xObject ) throw(IllegalArgumentException, RuntimeException)
    1280                 :            : {
    1281         [ +  - ]:        103 :     if ( m_xEventAttacher.is() )
    1282                 :        103 :         m_xEventAttacher->detach( nIndex, xObject );
    1283                 :        103 : }
    1284                 :            : 
    1285                 :            : //------------------------------------------------------------------------
    1286                 :       1258 : void SAL_CALL OInterfaceContainer::addScriptListener( const Reference< XScriptListener >& xListener ) throw(IllegalArgumentException, RuntimeException)
    1287                 :            : {
    1288         [ +  - ]:       1258 :     if ( m_xEventAttacher.is() )
    1289                 :       1258 :         m_xEventAttacher->addScriptListener( xListener );
    1290                 :       1258 : }
    1291                 :            : 
    1292                 :            : //------------------------------------------------------------------------
    1293                 :       1226 : void SAL_CALL OInterfaceContainer::removeScriptListener( const Reference< XScriptListener >& xListener ) throw(IllegalArgumentException, RuntimeException)
    1294                 :            : {
    1295         [ +  - ]:       1226 :     if ( m_xEventAttacher.is() )
    1296                 :       1226 :         m_xEventAttacher->removeScriptListener( xListener );
    1297                 :       1226 : }
    1298                 :            : 
    1299                 :            : //==================================================================
    1300                 :            : //= OFormComponents
    1301                 :            : //==================================================================
    1302                 :            : //------------------------------------------------------------------------------
    1303                 :       9776 : Any SAL_CALL OFormComponents::queryAggregation(const Type& _rType) throw(RuntimeException)
    1304                 :            : {
    1305                 :       9776 :     Any aReturn = OFormComponents_BASE::queryInterface(_rType);
    1306         [ +  - ]:       9776 :     if (!aReturn.hasValue())
    1307                 :            :     {
    1308         [ +  - ]:       9776 :         aReturn = OInterfaceContainer::queryInterface(_rType);
    1309                 :            : 
    1310         [ +  + ]:       9776 :         if (!aReturn.hasValue())
    1311         [ +  - ]:       4279 :             aReturn = FormComponentsBase::queryAggregation(_rType);
    1312                 :            :     }
    1313                 :            : 
    1314                 :       9776 :     return aReturn;
    1315                 :            : }
    1316                 :            : 
    1317                 :            : //------------------------------------------------------------------
    1318                 :          0 : Sequence<Type> SAL_CALL OFormComponents::getTypes() throw(RuntimeException)
    1319                 :            : {
    1320 [ #  # ][ #  # ]:          0 :     return ::comphelper::concatSequences(OInterfaceContainer::getTypes(), FormComponentsBase::getTypes(), OFormComponents_BASE::getTypes());
         [ #  # ][ #  # ]
                 [ #  # ]
    1321                 :            : }
    1322                 :            : 
    1323                 :            : //------------------------------------------------------------------------------
    1324                 :        278 : OFormComponents::OFormComponents(const Reference<XMultiServiceFactory>& _rxFactory)
    1325                 :            :     :FormComponentsBase( m_aMutex )
    1326         [ +  - ]:        278 :     ,OInterfaceContainer( _rxFactory, m_aMutex, XFormComponent::static_type() )
    1327 [ +  - ][ +  - ]:        556 :     ,OFormComponents_BASE()
    1328                 :            : {
    1329                 :        278 : }
    1330                 :            : 
    1331                 :            : //------------------------------------------------------------------------------
    1332                 :          0 : OFormComponents::OFormComponents( const OFormComponents& _cloneSource )
    1333                 :            :     :FormComponentsBase( m_aMutex )
    1334                 :            :     ,OInterfaceContainer( m_aMutex, _cloneSource )
    1335 [ #  # ][ #  # ]:          0 :     ,OFormComponents_BASE()
    1336                 :            : {
    1337                 :          0 : }
    1338                 :            : 
    1339                 :            : //------------------------------------------------------------------------------
    1340 [ +  - ][ +  - ]:        271 : OFormComponents::~OFormComponents()
    1341                 :            : {
    1342         [ -  + ]:        271 :     if (!FormComponentsBase::rBHelper.bDisposed)
    1343                 :            :     {
    1344                 :          0 :         acquire();
    1345         [ #  # ]:          0 :         dispose();
    1346                 :            :     }
    1347         [ -  + ]:        271 : }
    1348                 :            : 
    1349                 :            : // OComponentHelper
    1350                 :            : //------------------------------------------------------------------------------
    1351                 :        274 : void OFormComponents::disposing()
    1352                 :            : {
    1353                 :        274 :     OInterfaceContainer::disposing();
    1354                 :        274 :     FormComponentsBase::disposing();
    1355                 :        274 :     m_xParent = NULL;
    1356                 :        274 : }
    1357                 :            : 
    1358                 :            : //XChild
    1359                 :            : //------------------------------------------------------------------------------
    1360                 :        275 : void OFormComponents::setParent(const InterfaceRef& Parent) throw( NoSupportException, RuntimeException )
    1361                 :            : {
    1362         [ +  - ]:        275 :     ::osl::MutexGuard aGuard( m_aMutex );
    1363 [ +  - ][ +  - ]:        275 :     m_xParent = Parent;
    1364                 :        275 : }
    1365                 :            : 
    1366                 :            : //------------------------------------------------------------------------------
    1367                 :       2439 : InterfaceRef OFormComponents::getParent() throw( RuntimeException )
    1368                 :            : {
    1369                 :       2439 :     return m_xParent;
    1370                 :            : }
    1371                 :            : 
    1372                 :            : //.........................................................................
    1373                 :            : }   // namespace frm
    1374                 :            : //.........................................................................
    1375                 :            : 
    1376                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10