LCOV - code coverage report
Current view: top level - libreoffice/svx/source/unodraw - unoshcol.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 83 0.0 %
Date: 2012-12-27 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10