LCOV - code coverage report
Current view: top level - toolkit/source/controls/tree - treedatamodel.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 206 237 86.9 %
Date: 2014-04-11 Functions: 39 47 83.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/awt/tree/XMutableTreeDataModel.hpp>
      21             : #include <com/sun/star/lang/XServiceInfo.hpp>
      22             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      23             : #include <com/sun/star/uno/XComponentContext.hpp>
      24             : #include <cppuhelper/implbase2.hxx>
      25             : #include <cppuhelper/supportsservice.hxx>
      26             : #include <rtl/ref.hxx>
      27             : #include <toolkit/helper/mutexandbroadcasthelper.hxx>
      28             : #include <toolkit/helper/servicenames.hxx>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::awt;
      33             : using namespace ::com::sun::star::awt::tree;
      34             : using namespace ::com::sun::star::lang;
      35             : 
      36             : namespace {
      37             : 
      38             :     enum broadcast_type { nodes_changed, nodes_inserted, nodes_removed, structure_changed };
      39             : 
      40             : class MutableTreeNode;
      41             : class MutableTreeDataModel;
      42             : 
      43             : typedef rtl::Reference< MutableTreeNode > MutableTreeNodeRef;
      44             : typedef std::vector< MutableTreeNodeRef > TreeNodeVector;
      45             : typedef rtl::Reference< MutableTreeDataModel > MutableTreeDataModelRef;
      46             : 
      47           0 : static void implThrowIllegalArgumentException() throw( IllegalArgumentException )
      48             : {
      49           0 :     throw IllegalArgumentException();
      50             : }
      51             : 
      52             : class MutableTreeDataModel : public ::cppu::WeakAggImplHelper2< XMutableTreeDataModel, XServiceInfo >,
      53             :                              public MutexAndBroadcastHelper
      54             : {
      55             : public:
      56             :     MutableTreeDataModel();
      57             :     virtual ~MutableTreeDataModel();
      58             : 
      59             :     void broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes );
      60             : 
      61             :     // XMutableTreeDataModel
      62             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode > SAL_CALL createNode( const ::com::sun::star::uno::Any& DisplayValue, sal_Bool ChildrenOnDemand ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      63             :     virtual void SAL_CALL setRoot( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode >& RootNode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      64             : 
      65             :     // XTreeDataModel
      66             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getRoot(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      67             :     virtual void SAL_CALL addTreeDataModelListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModelListener >& Listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      68             :     virtual void SAL_CALL removeTreeDataModelListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModelListener >& Listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      69             : 
      70             :     // XComponent
      71             :     virtual void SAL_CALL dispose(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      72             :     virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      73             :     virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      74             : 
      75             :     // XServiceInfo
      76             :     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      77             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      78             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      79             : 
      80             : private:
      81             :     bool mbDisposed;
      82             :     Reference< XTreeNode > mxRootNode;
      83             : };
      84             : 
      85             : class MutableTreeNode: public ::cppu::WeakAggImplHelper2< XMutableTreeNode, XServiceInfo >
      86             : {
      87             :     friend class MutableTreeDataModel;
      88             : 
      89             : public:
      90             :     MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, bool bChildrenOnDemand );
      91             :     virtual ~MutableTreeNode();
      92             : 
      93             :     void setParent( MutableTreeNode* pParent );
      94             :     void broadcast_changes();
      95             :     void broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew);
      96             : 
      97             :     // XMutableTreeNode
      98             :     virtual ::com::sun::star::uno::Any SAL_CALL getDataValue() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      99             :     virtual void SAL_CALL setDataValue( const ::com::sun::star::uno::Any& _datavalue ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     100             :     virtual void SAL_CALL appendChild( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode >& ChildNode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     101             :     virtual void SAL_CALL insertChildByIndex( ::sal_Int32 Index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode >& ChildNode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     102             :     virtual void SAL_CALL removeChildByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     103             :     virtual void SAL_CALL setHasChildrenOnDemand( sal_Bool ChildrenOnDemand ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     104             :     virtual void SAL_CALL setDisplayValue( const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     105             :     virtual void SAL_CALL setNodeGraphicURL( const OUString& URL ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     106             :     virtual void SAL_CALL setExpandedGraphicURL( const OUString& URL ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     107             :     virtual void SAL_CALL setCollapsedGraphicURL( const OUString& URL ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     108             : 
     109             :     // XTreeNode
     110             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getChildAt( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     111             :     virtual ::sal_Int32 SAL_CALL getChildCount(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     112             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     113             :     virtual ::sal_Int32 SAL_CALL getIndex( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     114             :     virtual sal_Bool SAL_CALL hasChildrenOnDemand(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     115             :     virtual ::com::sun::star::uno::Any SAL_CALL getDisplayValue(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     116             :     virtual OUString SAL_CALL getNodeGraphicURL(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     117             :     virtual OUString SAL_CALL getExpandedGraphicURL(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     118             :     virtual OUString SAL_CALL getCollapsedGraphicURL(  ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     119             : 
     120             :     // XServiceInfo
     121             :     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     122             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     123             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     124             : 
     125             :     static MutableTreeNode* getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException);
     126         501 :     Reference< XTreeNode > getReference( MutableTreeNode* pNode )
     127             :     {
     128         501 :         return Reference< XTreeNode >( pNode );
     129             :     }
     130             : 
     131             : private:
     132             :     TreeNodeVector  maChildren;
     133             :     Any maDisplayValue;
     134             :     Any maDataValue;
     135             :     bool mbHasChildrenOnDemand;
     136             :     ::osl::Mutex maMutex;
     137             :     MutableTreeNode* mpParent;
     138             :     MutableTreeDataModelRef mxModel;
     139             :     OUString maNodeGraphicURL;
     140             :     OUString maExpandedGraphicURL;
     141             :     OUString maCollapsedGraphicURL;
     142             :     bool mbIsInserted;
     143             : };
     144             : 
     145           2 : MutableTreeDataModel::MutableTreeDataModel()
     146           2 : : mbDisposed( false )
     147             : {
     148           2 : }
     149             : 
     150           0 : MutableTreeDataModel::~MutableTreeDataModel()
     151             : {
     152           0 : }
     153             : 
     154         308 : void MutableTreeDataModel::broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes )
     155             : {
     156         308 :     ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( cppu::UnoType<XTreeDataModelListener>::get() );
     157         308 :     if( pIter )
     158             :     {
     159           2 :         Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
     160           4 :         const Sequence< Reference< XTreeNode > > aNodes( pNodes, nNodes );
     161           4 :         TreeDataModelEvent aEvent( xSource, aNodes, xParentNode );
     162             : 
     163           4 :         ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
     164           7 :         while(aListIter.hasMoreElements())
     165             :         {
     166           3 :             XTreeDataModelListener* pListener = static_cast<XTreeDataModelListener*>(aListIter.next());
     167           3 :             switch( eType )
     168             :             {
     169           0 :             case nodes_changed:     pListener->treeNodesChanged(aEvent); break;
     170           0 :             case nodes_inserted:    pListener->treeNodesInserted(aEvent); break;
     171           0 :             case nodes_removed:     pListener->treeNodesRemoved(aEvent); break;
     172           3 :             case structure_changed: pListener->treeStructureChanged(aEvent); break;
     173             :             }
     174           2 :         }
     175             :     }
     176         308 : }
     177             : 
     178         119 : Reference< XMutableTreeNode > SAL_CALL MutableTreeDataModel::createNode( const Any& aValue, sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
     179             : {
     180         119 :     return new MutableTreeNode( this, aValue, bChildrenOnDemand );
     181             : }
     182             : 
     183           4 : void SAL_CALL MutableTreeDataModel::setRoot( const Reference< XMutableTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
     184             : {
     185           4 :     if( !xNode.is() )
     186           1 :         throw IllegalArgumentException();
     187             : 
     188           3 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     189           3 :     if( xNode != mxRootNode )
     190             :     {
     191           3 :         if( mxRootNode.is() )
     192             :         {
     193           2 :             MutableTreeNodeRef xOldImpl( dynamic_cast< MutableTreeNode* >( mxRootNode.get() ) );
     194           2 :             if( xOldImpl.is() )
     195           2 :                 xOldImpl->mbIsInserted = false;
     196             :         }
     197             : 
     198           3 :         MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     199           3 :         if( !xImpl.is() || xImpl->mbIsInserted )
     200           0 :             throw IllegalArgumentException();
     201             : 
     202           3 :         xImpl->mbIsInserted = true;
     203           3 :         mxRootNode.set(xImpl.get());
     204             : 
     205           6 :         Reference< XTreeNode > xParentNode;
     206           6 :         broadcast( structure_changed, xParentNode, &mxRootNode, 1 );
     207           3 :     }
     208           3 : }
     209             : 
     210           1 : Reference< XTreeNode > SAL_CALL MutableTreeDataModel::getRoot(  ) throw (RuntimeException, std::exception)
     211             : {
     212           1 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     213           1 :     return mxRootNode;
     214             : }
     215             : 
     216           2 : void SAL_CALL MutableTreeDataModel::addTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException, std::exception)
     217             : {
     218           2 :     BrdcstHelper.addListener( cppu::UnoType<XTreeDataModelListener>::get(), xListener );
     219           2 : }
     220             : 
     221           1 : void SAL_CALL MutableTreeDataModel::removeTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException, std::exception)
     222             : {
     223           1 :     BrdcstHelper.removeListener( cppu::UnoType<XTreeDataModelListener>::get(), xListener );
     224           1 : }
     225             : 
     226           1 : void SAL_CALL MutableTreeDataModel::dispose() throw (RuntimeException, std::exception)
     227             : {
     228           1 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     229             : 
     230           1 :     if( !mbDisposed )
     231             :     {
     232           1 :         mbDisposed = true;
     233           1 :         ::com::sun::star::lang::EventObject aEvent;
     234           1 :         aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) );
     235           1 :         BrdcstHelper.aLC.disposeAndClear( aEvent );
     236           1 :     }
     237           1 : }
     238             : 
     239           2 : void SAL_CALL MutableTreeDataModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception)
     240             : {
     241           2 :     BrdcstHelper.addListener( cppu::UnoType<XEventListener>::get(), xListener );
     242           2 : }
     243             : 
     244           1 : void SAL_CALL MutableTreeDataModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception)
     245             : {
     246           1 :     BrdcstHelper.removeListener( cppu::UnoType<XEventListener>::get(), xListener );
     247           1 : }
     248             : 
     249           1 : OUString SAL_CALL MutableTreeDataModel::getImplementationName(  ) throw (RuntimeException, std::exception)
     250             : {
     251           1 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     252           1 :     static const OUString aImplName( "toolkit.MutableTreeDataModel" );
     253           1 :     return aImplName;
     254             : }
     255             : 
     256           0 : sal_Bool SAL_CALL MutableTreeDataModel::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
     257             : {
     258           0 :     return cppu::supportsService(this, ServiceName);
     259             : }
     260             : 
     261           0 : Sequence< OUString > SAL_CALL MutableTreeDataModel::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     262             : {
     263           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     264           0 :     static const OUString aServiceName( OUString::createFromAscii( szServiceName_MutableTreeDataModel ) );
     265           0 :     static const Sequence< OUString > aSeq( &aServiceName, 1 );
     266           0 :     return aSeq;
     267             : }
     268             : 
     269         119 : MutableTreeNode::MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, bool bChildrenOnDemand )
     270             : : maDisplayValue( rValue )
     271             : , mbHasChildrenOnDemand( bChildrenOnDemand )
     272             : , mpParent( 0 )
     273             : , mxModel( xModel )
     274         119 : , mbIsInserted( false )
     275             : {
     276         119 : }
     277             : 
     278          15 : MutableTreeNode::~MutableTreeNode()
     279             : {
     280           5 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     281          10 :     while( aIter != maChildren.end() )
     282           0 :         (*aIter++)->setParent(0);
     283          10 : }
     284             : 
     285         114 : void MutableTreeNode::setParent( MutableTreeNode* pParent )
     286             : {
     287         114 :     mpParent = pParent;
     288         114 : }
     289             : 
     290           1 : MutableTreeNode* MutableTreeNode::getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException)
     291             : {
     292           1 :     MutableTreeNode* pImpl = dynamic_cast< MutableTreeNode* >( xNode.get() );
     293           1 :     if( bThrows && !pImpl )
     294           0 :         implThrowIllegalArgumentException();
     295             : 
     296           1 :     return pImpl;
     297             : }
     298             : 
     299         191 : void MutableTreeNode::broadcast_changes()
     300             : {
     301         191 :     if( mxModel.is() )
     302             :     {
     303         191 :         Reference< XTreeNode > xParent( getReference( mpParent ) );
     304         382 :         Reference< XTreeNode > xNode( getReference( this ) );
     305         382 :         mxModel->broadcast( nodes_changed, xParent, &xNode, 1 );
     306             :     }
     307         191 : }
     308             : 
     309         114 : void MutableTreeNode::broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew)
     310             : {
     311         114 :     if( mxModel.is() )
     312             :     {
     313         114 :         Reference< XTreeNode > xParent( getReference( this ) );
     314         114 :         mxModel->broadcast( bNew ? nodes_inserted : nodes_removed, xParent, &xNode, 1 );
     315             :     }
     316         114 : }
     317             : 
     318           4 : Any SAL_CALL MutableTreeNode::getDataValue() throw (RuntimeException, std::exception)
     319             : {
     320           4 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     321           4 :     return maDataValue;
     322             : }
     323             : 
     324         114 : void SAL_CALL MutableTreeNode::setDataValue( const Any& _datavalue ) throw (RuntimeException, std::exception)
     325             : {
     326         114 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     327         114 :     maDataValue = _datavalue;
     328         114 : }
     329             : 
     330         114 : void SAL_CALL MutableTreeNode::appendChild( const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
     331             : {
     332         114 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     333         228 :     Reference< XTreeNode > xNode( xChildNode.get() );
     334         228 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     335             : 
     336         114 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     337           2 :         throw IllegalArgumentException();
     338             : 
     339         112 :     maChildren.push_back( xImpl );
     340         112 :     xImpl->setParent(this);
     341         112 :     xImpl->mbIsInserted = true;
     342             : 
     343         226 :     broadcast_changes( xNode, true );
     344         112 : }
     345             : 
     346           4 : void SAL_CALL MutableTreeNode::insertChildByIndex( sal_Int32 nChildIndex, const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException, std::exception)
     347             : {
     348           4 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     349             : 
     350           4 :     if( (nChildIndex < 0) || (nChildIndex > (sal_Int32)maChildren.size()) )
     351           1 :         throw IndexOutOfBoundsException();
     352             : 
     353           6 :     Reference< XTreeNode > xNode( xChildNode.get() );
     354           6 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     355           3 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     356           2 :         throw IllegalArgumentException();
     357             : 
     358           1 :     xImpl->mbIsInserted = true;
     359             : 
     360           1 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     361           2 :     while( (nChildIndex-- > 0) && (aIter != maChildren.end()) )
     362           0 :         ++aIter;
     363             : 
     364           1 :     maChildren.insert( aIter, xImpl );
     365           1 :     xImpl->setParent( this );
     366             : 
     367           5 :     broadcast_changes( xNode, true );
     368           1 : }
     369             : 
     370           2 : void SAL_CALL MutableTreeNode::removeChildByIndex( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     371             : {
     372           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     373             : 
     374           2 :     if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
     375           1 :         throw IndexOutOfBoundsException();
     376             : 
     377           2 :     MutableTreeNodeRef xImpl;
     378             : 
     379           1 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     380           1 :     std::advance(aIter, nChildIndex);
     381             : 
     382           1 :     xImpl = (*aIter);
     383           1 :     maChildren.erase( aIter );
     384             : 
     385           1 :     if( !xImpl.is() )
     386           0 :         throw IndexOutOfBoundsException();
     387             : 
     388           1 :     xImpl->setParent(0);
     389           1 :     xImpl->mbIsInserted = false;
     390             : 
     391           3 :     broadcast_changes( getReference( xImpl.get() ), false );
     392           1 : }
     393             : 
     394           3 : void SAL_CALL MutableTreeNode::setHasChildrenOnDemand( sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
     395             : {
     396             :     bool bChanged;
     397             : 
     398             :     {
     399           3 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     400           3 :         bChanged = mbHasChildrenOnDemand != bool(bChildrenOnDemand);
     401           3 :         mbHasChildrenOnDemand = bChildrenOnDemand;
     402             :     }
     403             : 
     404           3 :     if( bChanged )
     405           2 :         broadcast_changes();
     406           3 : }
     407             : 
     408           5 : void SAL_CALL MutableTreeNode::setDisplayValue( const Any& aValue ) throw (RuntimeException, std::exception)
     409             : {
     410             :     {
     411           5 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     412           5 :         maDisplayValue = aValue;
     413             :     }
     414             : 
     415           5 :     broadcast_changes();
     416           5 : }
     417             : 
     418          50 : void SAL_CALL MutableTreeNode::setNodeGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     419             : {
     420             :     bool bChanged;
     421             : 
     422             :     {
     423          50 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     424          50 :         bChanged = maNodeGraphicURL != rURL;
     425          50 :         maNodeGraphicURL = rURL;
     426             :     }
     427             : 
     428          50 :     if( bChanged )
     429          50 :         broadcast_changes();
     430          50 : }
     431             : 
     432          67 : void SAL_CALL MutableTreeNode::setExpandedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     433             : {
     434             :     bool bChanged;
     435             : 
     436             :     {
     437          67 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     438          67 :         bChanged = maExpandedGraphicURL != rURL;
     439          67 :         maExpandedGraphicURL = rURL;
     440             :     }
     441             : 
     442          67 :     if( bChanged )
     443          67 :         broadcast_changes();
     444          67 : }
     445             : 
     446          67 : void SAL_CALL MutableTreeNode::setCollapsedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     447             : {
     448             :     bool bChanged;
     449             : 
     450             :     {
     451          67 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     452          67 :         bChanged = maCollapsedGraphicURL != rURL;
     453          67 :         maCollapsedGraphicURL = rURL;
     454             :     }
     455             : 
     456          67 :     if( bChanged )
     457          67 :         broadcast_changes();
     458          67 : }
     459             : 
     460           3 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getChildAt( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException,RuntimeException, std::exception)
     461             : {
     462           3 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     463             : 
     464           3 :     if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
     465           0 :         throw IndexOutOfBoundsException();
     466           3 :     return getReference( maChildren[nChildIndex].get() );
     467             : }
     468             : 
     469           2 : sal_Int32 SAL_CALL MutableTreeNode::getChildCount(  ) throw (RuntimeException, std::exception)
     470             : {
     471           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     472           2 :     return (sal_Int32)maChildren.size();
     473             : }
     474             : 
     475           1 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getParent(  ) throw (RuntimeException, std::exception)
     476             : {
     477           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     478           1 :     return getReference( mpParent );
     479             : }
     480             : 
     481           1 : sal_Int32 SAL_CALL MutableTreeNode::getIndex( const Reference< XTreeNode >& xNode ) throw (RuntimeException, std::exception)
     482             : {
     483           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     484             : 
     485           2 :     MutableTreeNodeRef xImpl( MutableTreeNode::getImplementation( xNode, false ) );
     486           1 :     if( xImpl.is() )
     487             :     {
     488           1 :         sal_Int32 nChildCount = maChildren.size();
     489           2 :         while( nChildCount-- )
     490             :         {
     491           1 :             if( maChildren[nChildCount] == xImpl )
     492           1 :                 return nChildCount;
     493             :         }
     494             :     }
     495             : 
     496           1 :     return -1;
     497             : }
     498             : 
     499           1 : sal_Bool SAL_CALL MutableTreeNode::hasChildrenOnDemand(  ) throw (RuntimeException, std::exception)
     500             : {
     501           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     502           1 :     return mbHasChildrenOnDemand;
     503             : }
     504             : 
     505           1 : Any SAL_CALL MutableTreeNode::getDisplayValue(  ) throw (RuntimeException, std::exception)
     506             : {
     507           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     508           1 :     return maDisplayValue;
     509             : }
     510             : 
     511           1 : OUString SAL_CALL MutableTreeNode::getNodeGraphicURL(  ) throw (RuntimeException, std::exception)
     512             : {
     513           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     514           1 :     return maNodeGraphicURL;
     515             : }
     516             : 
     517           1 : OUString SAL_CALL MutableTreeNode::getExpandedGraphicURL(  ) throw (RuntimeException, std::exception)
     518             : {
     519           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     520           1 :     return maExpandedGraphicURL;
     521             : }
     522             : 
     523           1 : OUString SAL_CALL MutableTreeNode::getCollapsedGraphicURL(  ) throw (RuntimeException, std::exception)
     524             : {
     525           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     526           1 :     return maCollapsedGraphicURL;
     527             : }
     528             : 
     529           0 : OUString SAL_CALL MutableTreeNode::getImplementationName(  ) throw (RuntimeException, std::exception)
     530             : {
     531           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     532           0 :     static const OUString aImplName( "toolkit.MutableTreeNode" );
     533           0 :     return aImplName;
     534             : }
     535             : 
     536           0 : sal_Bool SAL_CALL MutableTreeNode::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
     537             : {
     538           0 :     return cppu::supportsService(this, ServiceName);
     539             : }
     540             : 
     541           0 : Sequence< OUString > SAL_CALL MutableTreeNode::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     542             : {
     543           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     544           0 :     static const OUString aServiceName( "com.sun.star.awt.tree.MutableTreeNode" );
     545           0 :     static const Sequence< OUString > aSeq( &aServiceName, 1 );
     546           0 :     return aSeq;
     547             : }
     548             : 
     549             : }
     550             : 
     551             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     552           2 : stardiv_Toolkit_MutableTreeDataModel_get_implementation(
     553             :     css::uno::XComponentContext *,
     554             :     css::uno::Sequence<css::uno::Any> const &)
     555             : {
     556           2 :     return cppu::acquire(new MutableTreeDataModel());
     557             : }
     558             : 
     559             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10