LCOV - code coverage report
Current view: top level - svx/source/unodraw - unoshcol.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 68 83 81.9 %
Date: 2012-08-25 Functions: 17 21 81.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50 96 52.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/document/EventObject.hpp>
      30                 :            : 
      31                 :            : #include "svx/unoshcol.hxx"
      32                 :            : #include <svx/unoprov.hxx>
      33                 :            : #include <comphelper/serviceinfohelper.hxx>
      34                 :            : 
      35                 :            : using namespace ::cppu;
      36                 :            : using namespace ::com::sun::star;
      37                 :            : using namespace ::com::sun::star::uno;
      38                 :            : using namespace ::com::sun::star::lang;
      39                 :            : using namespace ::com::sun::star::container;
      40                 :            : using namespace ::com::sun::star::drawing;
      41                 :            : 
      42                 :            : /***********************************************************************
      43                 :            : *                                                                      *
      44                 :            : ***********************************************************************/
      45                 :          8 : SvxShapeCollection::SvxShapeCollection() throw()
      46 [ +  - ][ +  - ]:          8 : : maShapeContainer( maMutex ), mrBHelper( maMutex )
                 [ +  - ]
      47                 :            : {
      48                 :          8 : }
      49                 :            : 
      50                 :            : //----------------------------------------------------------------------
      51 [ +  - ][ +  - ]:          8 : SvxShapeCollection::~SvxShapeCollection() throw()
                 [ +  - ]
      52                 :            : {
      53         [ -  + ]:         16 : }
      54                 :            : 
      55                 :            : 
      56                 :            : //----------------------------------------------------------------------
      57                 :          4 : Reference< uno::XInterface > SvxShapeCollection_NewInstance() throw()
      58                 :            : {
      59 [ +  - ][ +  - ]:          4 :     Reference< drawing::XShapes > xShapes( new SvxShapeCollection() );
      60         [ +  - ]:          4 :     Reference< uno::XInterface > xRef( xShapes, UNO_QUERY );
      61                 :          4 :     return xRef;
      62                 :            : }
      63                 :            : 
      64                 :            : // XInterface
      65                 :         82 : void SvxShapeCollection::release() throw()
      66                 :            : {
      67         [ +  - ]:         82 :     uno::Reference< uno::XInterface > x( xDelegator );
      68         [ +  - ]:         82 :     if (! x.is())
      69                 :            :     {
      70 [ +  - ][ +  + ]:         82 :         if (osl_decrementInterlockedCount( &m_refCount ) == 0)
      71                 :            :         {
      72         [ +  + ]:         16 :             if (! mrBHelper.bDisposed)
      73                 :            :             {
      74         [ +  - ]:          8 :                 uno::Reference< uno::XInterface > xHoldAlive( (uno::XWeak*)this );
      75                 :            :                 // First dispose
      76                 :            :                 try
      77                 :            :                 {
      78         [ +  - ]:          8 :                     dispose();
      79                 :            :                 }
      80         [ #  # ]:          0 :                 catch(::com::sun::star::uno::Exception&)
      81                 :            :                 {
      82                 :            :                     // release should not throw exceptions
      83                 :            :                 }
      84                 :            : 
      85                 :            :                 // only the alive ref holds the object
      86                 :            :                 OSL_ASSERT( m_refCount == 1 );
      87                 :            :                 // destroy the object if xHoldAlive decrement the refcount to 0
      88         [ #  # ]:         90 :                 return;
      89                 :            :             }
      90                 :            :         }
      91                 :            :         // restore the reference count
      92         [ +  - ]:         74 :         osl_incrementInterlockedCount( &m_refCount );
      93                 :            :     }
      94         [ +  + ]:         82 :     OWeakAggObject::release();
      95                 :            : }
      96                 :            : 
      97                 :            : // XComponent
      98                 :          8 : void SvxShapeCollection::disposing() throw()
      99                 :            : {
     100                 :          8 :     maShapeContainer.clear();
     101                 :          8 : }
     102                 :            : 
     103                 :            : // XComponent
     104                 :          8 : void SvxShapeCollection::dispose()
     105                 :            :     throw(::com::sun::star::uno::RuntimeException)
     106                 :            : {
     107                 :            :     // An frequently programming error is to release the last
     108                 :            :     // reference to this object in the disposing message.
     109                 :            :     // Make it rubust, hold a self Reference.
     110         [ +  - ]:          8 :     uno::Reference< lang::XComponent > xSelf( this );
     111                 :            : 
     112                 :            :     // Guard dispose against multible threading
     113                 :            :     // Remark: It is an error to call dispose more than once
     114                 :          8 :     sal_Bool bDoDispose = sal_False;
     115                 :            :     {
     116         [ +  - ]:          8 :     osl::MutexGuard aGuard( mrBHelper.rMutex );
     117 [ +  - ][ +  - ]:          8 :     if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
     118                 :            :     {
     119                 :            :         // only one call go into this section
     120                 :          8 :         mrBHelper.bInDispose = sal_True;
     121                 :          8 :         bDoDispose = sal_True;
     122         [ +  - ]:          8 :     }
     123                 :            :     }
     124                 :            : 
     125                 :            :     // Do not hold the mutex because we are broadcasting
     126         [ +  - ]:          8 :     if( bDoDispose )
     127                 :            :     {
     128                 :            :         // Create an event with this as sender
     129                 :            :         try
     130                 :            :         {
     131         [ +  - ]:          8 :             uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
     132         [ +  - ]:          8 :             document::EventObject aEvt;
     133         [ +  - ]:          8 :             aEvt.Source = xSource;
     134                 :            :             // inform all listeners to release this object
     135                 :            :             // The listener container are automaticly cleared
     136         [ +  - ]:          8 :             mrBHelper.aLC.disposeAndClear( aEvt );
     137                 :            :             // notify subclasses to do their dispose
     138         [ +  - ]:          8 :             disposing();
     139                 :            :         }
     140         [ #  # ]:          0 :         catch(const ::com::sun::star::uno::Exception&)
     141                 :            :         {
     142                 :            :             // catch exception and throw again but signal that
     143                 :            :             // the object was disposed. Dispose should be called
     144                 :            :             // only once.
     145                 :          0 :             mrBHelper.bDisposed = sal_True;
     146                 :          0 :             mrBHelper.bInDispose = sal_False;
     147                 :          0 :             throw;
     148                 :            :         }
     149                 :            : 
     150                 :            :         // the values bDispose and bInDisposing must set in this order.
     151                 :            :         // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
     152                 :          8 :         mrBHelper.bDisposed = sal_True;
     153                 :          8 :         mrBHelper.bInDispose = sal_False;
     154                 :            :     }
     155                 :            :     else
     156                 :            :     {
     157                 :            :         // in a multithreaded environment, it can't be avoided, that dispose is called twice.
     158                 :            :         // However this condition is traced, because it MAY indicate an error.
     159                 :            :         OSL_TRACE( "OComponentHelper::dispose() - dispose called twice" );
     160                 :          8 :     }
     161                 :          8 : }
     162                 :            : 
     163                 :            : // XComponent
     164                 :          0 : void SAL_CALL SvxShapeCollection::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
     165                 :            : {
     166                 :          0 :     mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
     167                 :          0 : }
     168                 :            : 
     169                 :            : // XComponent
     170                 :          0 : void SAL_CALL SvxShapeCollection::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
     171                 :            : {
     172                 :          0 :     mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
     173                 :          0 : }
     174                 :            : 
     175                 :            : // XShapes
     176                 :            : //----------------------------------------------------------------------
     177                 :         12 : void SAL_CALL SvxShapeCollection::add( const Reference< drawing::XShape >& xShape ) throw( uno::RuntimeException )
     178                 :            : {
     179                 :         12 :     maShapeContainer.addInterface( xShape );
     180                 :         12 : }
     181                 :            : 
     182                 :            : //----------------------------------------------------------------------
     183                 :          2 : void SAL_CALL SvxShapeCollection::remove( const uno::Reference< drawing::XShape >& xShape ) throw( uno::RuntimeException )
     184                 :            : {
     185                 :          2 :     maShapeContainer.removeInterface( xShape );
     186                 :          2 : }
     187                 :            : 
     188                 :            : //----------------------------------------------------------------------
     189                 :         28 : sal_Int32 SAL_CALL SvxShapeCollection::getCount() throw( uno::RuntimeException )
     190                 :            : {
     191                 :         28 :     return maShapeContainer.getLength();
     192                 :            : }
     193                 :            : 
     194                 :            : //----------------------------------------------------------------------
     195                 :         12 : uno::Any SAL_CALL SvxShapeCollection::getByIndex( sal_Int32 Index )
     196                 :            :     throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
     197                 :            : {
     198 [ +  - ][ +  - ]:         12 :     if( Index < 0 || Index >= getCount() )
         [ +  + ][ +  + ]
     199         [ +  - ]:          2 :         throw lang::IndexOutOfBoundsException();
     200                 :            : 
     201         [ +  - ]:         10 :     uno::Sequence< Reference< uno::XInterface> > xElements( maShapeContainer.getElements() );
     202                 :            : 
     203                 :            : 
     204 [ +  - ][ +  - ]:         12 :     return uno::makeAny( Reference< XShape>(static_cast< drawing::XShape* >( xElements.getArray()[Index].get())) );
         [ +  - ][ +  - ]
                 [ +  - ]
     205                 :            : }
     206                 :            : 
     207                 :            : // XElementAccess
     208                 :            : 
     209                 :            : //----------------------------------------------------------------------
     210                 :          2 : uno::Type SAL_CALL SvxShapeCollection::getElementType() throw( uno::RuntimeException )
     211                 :            : {
     212                 :          2 :     return ::getCppuType(( const Reference< drawing::XShape >*)0);
     213                 :            : }
     214                 :            : 
     215                 :            : //----------------------------------------------------------------------
     216                 :          2 : sal_Bool SAL_CALL SvxShapeCollection::hasElements() throw( uno::RuntimeException )
     217                 :            : {
     218                 :          2 :     return getCount() != 0;
     219                 :            : }
     220                 :            : 
     221                 :            : //----------------------------------------------------------------------
     222                 :            : // XServiceInfo
     223                 :            : //----------------------------------------------------------------------
     224                 :          2 : ::rtl::OUString SAL_CALL SvxShapeCollection::getImplementationName()
     225                 :            :     throw( uno::RuntimeException )
     226                 :            : {
     227                 :          2 :     return getImplementationName_Static();
     228                 :            : }
     229                 :            : 
     230                 :          4 : ::rtl::OUString SvxShapeCollection::getImplementationName_Static()
     231                 :            : {
     232                 :          4 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.SvxShapeCollection") );
     233                 :            : }
     234                 :            : 
     235                 :          0 : sal_Bool SAL_CALL SvxShapeCollection::supportsService( const ::rtl::OUString& ServiceName )
     236                 :            :     throw( uno::RuntimeException )
     237                 :            : {
     238                 :          0 :     return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
     239                 :            : }
     240                 :            : 
     241                 :          0 : uno::Sequence< ::rtl::OUString > SAL_CALL SvxShapeCollection::getSupportedServiceNames() throw( uno::RuntimeException )
     242                 :            : {
     243                 :          0 :     return getSupportedServiceNames_Static();
     244                 :            : }
     245                 :            : 
     246                 :          2 : uno::Sequence< ::rtl::OUString > SvxShapeCollection::getSupportedServiceNames_Static()
     247                 :            : {
     248                 :          2 :     uno::Sequence< ::rtl::OUString > aSeq(2);
     249 [ +  - ][ +  - ]:          2 :     aSeq.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Shapes") );
     250 [ +  - ][ +  - ]:          2 :     aSeq.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection") );
     251                 :          2 :     return aSeq;
     252                 :            : }
     253                 :            : 
     254                 :          2 : Reference< XInterface > SAL_CALL SvxShapeCollection_createInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& )
     255                 :            : {
     256                 :          2 :     return *( new SvxShapeCollection() );
     257                 :            : }
     258                 :            : 
     259                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10