LCOV - code coverage report
Current view: top level - toolkit/source/controls/tree - treedatamodel.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 206 237 86.9 %
Date: 2014-11-03 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        1002 :     Reference< XTreeNode > getReference( MutableTreeNode* pNode )
     127             :     {
     128        1002 :         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           4 : MutableTreeDataModel::MutableTreeDataModel()
     146           4 : : mbDisposed( false )
     147             : {
     148           4 : }
     149             : 
     150           0 : MutableTreeDataModel::~MutableTreeDataModel()
     151             : {
     152           0 : }
     153             : 
     154         616 : void MutableTreeDataModel::broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes )
     155             : {
     156         616 :     ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( cppu::UnoType<XTreeDataModelListener>::get() );
     157         616 :     if( pIter )
     158             :     {
     159           4 :         Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
     160           8 :         const Sequence< Reference< XTreeNode > > aNodes( pNodes, nNodes );
     161           8 :         TreeDataModelEvent aEvent( xSource, aNodes, xParentNode );
     162             : 
     163           8 :         ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
     164          14 :         while(aListIter.hasMoreElements())
     165             :         {
     166           6 :             XTreeDataModelListener* pListener = static_cast<XTreeDataModelListener*>(aListIter.next());
     167           6 :             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           6 :             case structure_changed: pListener->treeStructureChanged(aEvent); break;
     173             :             }
     174           4 :         }
     175             :     }
     176         616 : }
     177             : 
     178         238 : Reference< XMutableTreeNode > SAL_CALL MutableTreeDataModel::createNode( const Any& aValue, sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
     179             : {
     180         238 :     return new MutableTreeNode( this, aValue, bChildrenOnDemand );
     181             : }
     182             : 
     183           8 : void SAL_CALL MutableTreeDataModel::setRoot( const Reference< XMutableTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
     184             : {
     185           8 :     if( !xNode.is() )
     186           2 :         throw IllegalArgumentException();
     187             : 
     188           6 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     189           6 :     if( xNode != mxRootNode )
     190             :     {
     191           6 :         if( mxRootNode.is() )
     192             :         {
     193           4 :             MutableTreeNodeRef xOldImpl( dynamic_cast< MutableTreeNode* >( mxRootNode.get() ) );
     194           4 :             if( xOldImpl.is() )
     195           4 :                 xOldImpl->mbIsInserted = false;
     196             :         }
     197             : 
     198           6 :         MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     199           6 :         if( !xImpl.is() || xImpl->mbIsInserted )
     200           0 :             throw IllegalArgumentException();
     201             : 
     202           6 :         xImpl->mbIsInserted = true;
     203           6 :         mxRootNode.set(xImpl.get());
     204             : 
     205          12 :         Reference< XTreeNode > xParentNode;
     206          12 :         broadcast( structure_changed, xParentNode, &mxRootNode, 1 );
     207           6 :     }
     208           6 : }
     209             : 
     210           2 : Reference< XTreeNode > SAL_CALL MutableTreeDataModel::getRoot(  ) throw (RuntimeException, std::exception)
     211             : {
     212           2 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     213           2 :     return mxRootNode;
     214             : }
     215             : 
     216           4 : void SAL_CALL MutableTreeDataModel::addTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException, std::exception)
     217             : {
     218           4 :     BrdcstHelper.addListener( cppu::UnoType<XTreeDataModelListener>::get(), xListener );
     219           4 : }
     220             : 
     221           2 : void SAL_CALL MutableTreeDataModel::removeTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException, std::exception)
     222             : {
     223           2 :     BrdcstHelper.removeListener( cppu::UnoType<XTreeDataModelListener>::get(), xListener );
     224           2 : }
     225             : 
     226           2 : void SAL_CALL MutableTreeDataModel::dispose() throw (RuntimeException, std::exception)
     227             : {
     228           2 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     229             : 
     230           2 :     if( !mbDisposed )
     231             :     {
     232           2 :         mbDisposed = true;
     233           2 :         ::com::sun::star::lang::EventObject aEvent;
     234           2 :         aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) );
     235           2 :         BrdcstHelper.aLC.disposeAndClear( aEvent );
     236           2 :     }
     237           2 : }
     238             : 
     239           4 : void SAL_CALL MutableTreeDataModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception)
     240             : {
     241           4 :     BrdcstHelper.addListener( cppu::UnoType<XEventListener>::get(), xListener );
     242           4 : }
     243             : 
     244           2 : void SAL_CALL MutableTreeDataModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception)
     245             : {
     246           2 :     BrdcstHelper.removeListener( cppu::UnoType<XEventListener>::get(), xListener );
     247           2 : }
     248             : 
     249           2 : OUString SAL_CALL MutableTreeDataModel::getImplementationName(  ) throw (RuntimeException, std::exception)
     250             : {
     251           2 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     252           2 :     static const OUString aImplName( "toolkit.MutableTreeDataModel" );
     253           2 :     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         238 : MutableTreeNode::MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, bool bChildrenOnDemand )
     270             : : maDisplayValue( rValue )
     271             : , mbHasChildrenOnDemand( bChildrenOnDemand )
     272             : , mpParent( 0 )
     273             : , mxModel( xModel )
     274         238 : , mbIsInserted( false )
     275             : {
     276         238 : }
     277             : 
     278          30 : MutableTreeNode::~MutableTreeNode()
     279             : {
     280          10 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     281          20 :     while( aIter != maChildren.end() )
     282           0 :         (*aIter++)->setParent(0);
     283          20 : }
     284             : 
     285         228 : void MutableTreeNode::setParent( MutableTreeNode* pParent )
     286             : {
     287         228 :     mpParent = pParent;
     288         228 : }
     289             : 
     290           2 : MutableTreeNode* MutableTreeNode::getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException)
     291             : {
     292           2 :     MutableTreeNode* pImpl = dynamic_cast< MutableTreeNode* >( xNode.get() );
     293           2 :     if( bThrows && !pImpl )
     294           0 :         implThrowIllegalArgumentException();
     295             : 
     296           2 :     return pImpl;
     297             : }
     298             : 
     299         382 : void MutableTreeNode::broadcast_changes()
     300             : {
     301         382 :     if( mxModel.is() )
     302             :     {
     303         382 :         Reference< XTreeNode > xParent( getReference( mpParent ) );
     304         764 :         Reference< XTreeNode > xNode( getReference( this ) );
     305         764 :         mxModel->broadcast( nodes_changed, xParent, &xNode, 1 );
     306             :     }
     307         382 : }
     308             : 
     309         228 : void MutableTreeNode::broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew)
     310             : {
     311         228 :     if( mxModel.is() )
     312             :     {
     313         228 :         Reference< XTreeNode > xParent( getReference( this ) );
     314         228 :         mxModel->broadcast( bNew ? nodes_inserted : nodes_removed, xParent, &xNode, 1 );
     315             :     }
     316         228 : }
     317             : 
     318           8 : Any SAL_CALL MutableTreeNode::getDataValue() throw (RuntimeException, std::exception)
     319             : {
     320           8 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     321           8 :     return maDataValue;
     322             : }
     323             : 
     324         228 : void SAL_CALL MutableTreeNode::setDataValue( const Any& _datavalue ) throw (RuntimeException, std::exception)
     325             : {
     326         228 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     327         228 :     maDataValue = _datavalue;
     328         228 : }
     329             : 
     330         228 : void SAL_CALL MutableTreeNode::appendChild( const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
     331             : {
     332         228 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     333         456 :     Reference< XTreeNode > xNode( xChildNode.get() );
     334         456 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     335             : 
     336         228 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     337           4 :         throw IllegalArgumentException();
     338             : 
     339         224 :     maChildren.push_back( xImpl );
     340         224 :     xImpl->setParent(this);
     341         224 :     xImpl->mbIsInserted = true;
     342             : 
     343         452 :     broadcast_changes( xNode, true );
     344         224 : }
     345             : 
     346           8 : void SAL_CALL MutableTreeNode::insertChildByIndex( sal_Int32 nChildIndex, const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException, std::exception)
     347             : {
     348           8 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     349             : 
     350           8 :     if( (nChildIndex < 0) || (nChildIndex > (sal_Int32)maChildren.size()) )
     351           2 :         throw IndexOutOfBoundsException();
     352             : 
     353          12 :     Reference< XTreeNode > xNode( xChildNode.get() );
     354          12 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     355           6 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     356           4 :         throw IllegalArgumentException();
     357             : 
     358           2 :     xImpl->mbIsInserted = true;
     359             : 
     360           2 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     361           4 :     while( (nChildIndex-- > 0) && (aIter != maChildren.end()) )
     362           0 :         ++aIter;
     363             : 
     364           2 :     maChildren.insert( aIter, xImpl );
     365           2 :     xImpl->setParent( this );
     366             : 
     367          10 :     broadcast_changes( xNode, true );
     368           2 : }
     369             : 
     370           4 : void SAL_CALL MutableTreeNode::removeChildByIndex( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     371             : {
     372           4 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     373             : 
     374           4 :     if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
     375           2 :         throw IndexOutOfBoundsException();
     376             : 
     377           4 :     MutableTreeNodeRef xImpl;
     378             : 
     379           2 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     380           2 :     std::advance(aIter, nChildIndex);
     381             : 
     382           2 :     xImpl = (*aIter);
     383           2 :     maChildren.erase( aIter );
     384             : 
     385           2 :     if( !xImpl.is() )
     386           0 :         throw IndexOutOfBoundsException();
     387             : 
     388           2 :     xImpl->setParent(0);
     389           2 :     xImpl->mbIsInserted = false;
     390             : 
     391           6 :     broadcast_changes( getReference( xImpl.get() ), false );
     392           2 : }
     393             : 
     394           6 : void SAL_CALL MutableTreeNode::setHasChildrenOnDemand( sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
     395             : {
     396             :     bool bChanged;
     397             : 
     398             :     {
     399           6 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     400           6 :         bChanged = mbHasChildrenOnDemand != bool(bChildrenOnDemand);
     401           6 :         mbHasChildrenOnDemand = bChildrenOnDemand;
     402             :     }
     403             : 
     404           6 :     if( bChanged )
     405           4 :         broadcast_changes();
     406           6 : }
     407             : 
     408          10 : void SAL_CALL MutableTreeNode::setDisplayValue( const Any& aValue ) throw (RuntimeException, std::exception)
     409             : {
     410             :     {
     411          10 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     412          10 :         maDisplayValue = aValue;
     413             :     }
     414             : 
     415          10 :     broadcast_changes();
     416          10 : }
     417             : 
     418         100 : void SAL_CALL MutableTreeNode::setNodeGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     419             : {
     420             :     bool bChanged;
     421             : 
     422             :     {
     423         100 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     424         100 :         bChanged = maNodeGraphicURL != rURL;
     425         100 :         maNodeGraphicURL = rURL;
     426             :     }
     427             : 
     428         100 :     if( bChanged )
     429         100 :         broadcast_changes();
     430         100 : }
     431             : 
     432         134 : void SAL_CALL MutableTreeNode::setExpandedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     433             : {
     434             :     bool bChanged;
     435             : 
     436             :     {
     437         134 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     438         134 :         bChanged = maExpandedGraphicURL != rURL;
     439         134 :         maExpandedGraphicURL = rURL;
     440             :     }
     441             : 
     442         134 :     if( bChanged )
     443         134 :         broadcast_changes();
     444         134 : }
     445             : 
     446         134 : void SAL_CALL MutableTreeNode::setCollapsedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     447             : {
     448             :     bool bChanged;
     449             : 
     450             :     {
     451         134 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     452         134 :         bChanged = maCollapsedGraphicURL != rURL;
     453         134 :         maCollapsedGraphicURL = rURL;
     454             :     }
     455             : 
     456         134 :     if( bChanged )
     457         134 :         broadcast_changes();
     458         134 : }
     459             : 
     460           6 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getChildAt( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException,RuntimeException, std::exception)
     461             : {
     462           6 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     463             : 
     464           6 :     if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
     465           0 :         throw IndexOutOfBoundsException();
     466           6 :     return getReference( maChildren[nChildIndex].get() );
     467             : }
     468             : 
     469           4 : sal_Int32 SAL_CALL MutableTreeNode::getChildCount(  ) throw (RuntimeException, std::exception)
     470             : {
     471           4 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     472           4 :     return (sal_Int32)maChildren.size();
     473             : }
     474             : 
     475           2 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getParent(  ) throw (RuntimeException, std::exception)
     476             : {
     477           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     478           2 :     return getReference( mpParent );
     479             : }
     480             : 
     481           2 : sal_Int32 SAL_CALL MutableTreeNode::getIndex( const Reference< XTreeNode >& xNode ) throw (RuntimeException, std::exception)
     482             : {
     483           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     484             : 
     485           4 :     MutableTreeNodeRef xImpl( MutableTreeNode::getImplementation( xNode, false ) );
     486           2 :     if( xImpl.is() )
     487             :     {
     488           2 :         sal_Int32 nChildCount = maChildren.size();
     489           4 :         while( nChildCount-- )
     490             :         {
     491           2 :             if( maChildren[nChildCount] == xImpl )
     492           2 :                 return nChildCount;
     493             :         }
     494             :     }
     495             : 
     496           2 :     return -1;
     497             : }
     498             : 
     499           2 : sal_Bool SAL_CALL MutableTreeNode::hasChildrenOnDemand(  ) throw (RuntimeException, std::exception)
     500             : {
     501           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     502           2 :     return mbHasChildrenOnDemand;
     503             : }
     504             : 
     505           2 : Any SAL_CALL MutableTreeNode::getDisplayValue(  ) throw (RuntimeException, std::exception)
     506             : {
     507           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     508           2 :     return maDisplayValue;
     509             : }
     510             : 
     511           2 : OUString SAL_CALL MutableTreeNode::getNodeGraphicURL(  ) throw (RuntimeException, std::exception)
     512             : {
     513           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     514           2 :     return maNodeGraphicURL;
     515             : }
     516             : 
     517           2 : OUString SAL_CALL MutableTreeNode::getExpandedGraphicURL(  ) throw (RuntimeException, std::exception)
     518             : {
     519           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     520           2 :     return maExpandedGraphicURL;
     521             : }
     522             : 
     523           2 : OUString SAL_CALL MutableTreeNode::getCollapsedGraphicURL(  ) throw (RuntimeException, std::exception)
     524             : {
     525           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     526           2 :     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           4 : stardiv_Toolkit_MutableTreeDataModel_get_implementation(
     553             :     css::uno::XComponentContext *,
     554             :     css::uno::Sequence<css::uno::Any> const &)
     555             : {
     556           4 :     return cppu::acquire(new MutableTreeDataModel());
     557             : }
     558             : 
     559             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10