LCOV - code coverage report
Current view: top level - toolkit/source/controls/tree - treedatamodel.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 204 231 88.3 %
Date: 2015-06-13 12:38:46 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         414 :     static Reference< XTreeNode > getReference( MutableTreeNode* pNode )
     127             :     {
     128         414 :         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         252 : void MutableTreeDataModel::broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes )
     155             : {
     156         252 :     ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( cppu::UnoType<XTreeDataModelListener>::get() );
     157         252 :     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         252 : }
     177             : 
     178          94 : Reference< XMutableTreeNode > SAL_CALL MutableTreeDataModel::createNode( const Any& aValue, sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
     179             : {
     180          94 :     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 :     return OUString( "toolkit.MutableTreeDataModel" );
     252             : }
     253             : 
     254           0 : sal_Bool SAL_CALL MutableTreeDataModel::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
     255             : {
     256           0 :     return cppu::supportsService(this, ServiceName);
     257             : }
     258             : 
     259           0 : Sequence< OUString > SAL_CALL MutableTreeDataModel::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     260             : {
     261           0 :     Sequence< OUString > aSeq( 1 );
     262           0 :     aSeq[0] = "com.sun.star.awt.tree.MutableTreeDataModel";
     263           0 :     return aSeq;
     264             : }
     265             : 
     266          94 : MutableTreeNode::MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, bool bChildrenOnDemand )
     267             : : maDisplayValue( rValue )
     268             : , mbHasChildrenOnDemand( bChildrenOnDemand )
     269             : , mpParent( 0 )
     270             : , mxModel( xModel )
     271          94 : , mbIsInserted( false )
     272             : {
     273          94 : }
     274             : 
     275          15 : MutableTreeNode::~MutableTreeNode()
     276             : {
     277           5 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     278          10 :     while( aIter != maChildren.end() )
     279           0 :         (*aIter++)->setParent(0);
     280          10 : }
     281             : 
     282          89 : void MutableTreeNode::setParent( MutableTreeNode* pParent )
     283             : {
     284          89 :     mpParent = pParent;
     285          89 : }
     286             : 
     287           1 : MutableTreeNode* MutableTreeNode::getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException)
     288             : {
     289           1 :     MutableTreeNode* pImpl = dynamic_cast< MutableTreeNode* >( xNode.get() );
     290           1 :     if( bThrows && !pImpl )
     291           0 :         implThrowIllegalArgumentException();
     292             : 
     293           1 :     return pImpl;
     294             : }
     295             : 
     296         160 : void MutableTreeNode::broadcast_changes()
     297             : {
     298         160 :     if( mxModel.is() )
     299             :     {
     300         160 :         Reference< XTreeNode > xParent( getReference( mpParent ) );
     301         320 :         Reference< XTreeNode > xNode( getReference( this ) );
     302         320 :         mxModel->broadcast( nodes_changed, xParent, &xNode, 1 );
     303             :     }
     304         160 : }
     305             : 
     306          89 : void MutableTreeNode::broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew)
     307             : {
     308          89 :     if( mxModel.is() )
     309             :     {
     310          89 :         Reference< XTreeNode > xParent( getReference( this ) );
     311          89 :         mxModel->broadcast( bNew ? nodes_inserted : nodes_removed, xParent, &xNode, 1 );
     312             :     }
     313          89 : }
     314             : 
     315           4 : Any SAL_CALL MutableTreeNode::getDataValue() throw (RuntimeException, std::exception)
     316             : {
     317           4 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     318           4 :     return maDataValue;
     319             : }
     320             : 
     321          89 : void SAL_CALL MutableTreeNode::setDataValue( const Any& _datavalue ) throw (RuntimeException, std::exception)
     322             : {
     323          89 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     324          89 :     maDataValue = _datavalue;
     325          89 : }
     326             : 
     327          89 : void SAL_CALL MutableTreeNode::appendChild( const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
     328             : {
     329          89 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     330         178 :     Reference< XTreeNode > xNode( xChildNode.get() );
     331         178 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     332             : 
     333          89 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     334           2 :         throw IllegalArgumentException();
     335             : 
     336          87 :     maChildren.push_back( xImpl );
     337          87 :     xImpl->setParent(this);
     338          87 :     xImpl->mbIsInserted = true;
     339             : 
     340         176 :     broadcast_changes( xNode, true );
     341          87 : }
     342             : 
     343           4 : void SAL_CALL MutableTreeNode::insertChildByIndex( sal_Int32 nChildIndex, const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException, std::exception)
     344             : {
     345           4 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     346             : 
     347           4 :     if( (nChildIndex < 0) || (nChildIndex > (sal_Int32)maChildren.size()) )
     348           1 :         throw IndexOutOfBoundsException();
     349             : 
     350           6 :     Reference< XTreeNode > xNode( xChildNode.get() );
     351           6 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     352           3 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     353           2 :         throw IllegalArgumentException();
     354             : 
     355           1 :     xImpl->mbIsInserted = true;
     356             : 
     357           1 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     358           2 :     while( (nChildIndex-- > 0) && (aIter != maChildren.end()) )
     359           0 :         ++aIter;
     360             : 
     361           1 :     maChildren.insert( aIter, xImpl );
     362           1 :     xImpl->setParent( this );
     363             : 
     364           5 :     broadcast_changes( xNode, true );
     365           1 : }
     366             : 
     367           2 : void SAL_CALL MutableTreeNode::removeChildByIndex( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     368             : {
     369           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     370             : 
     371           2 :     if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
     372           1 :         throw IndexOutOfBoundsException();
     373             : 
     374           2 :     MutableTreeNodeRef xImpl;
     375             : 
     376           1 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     377           1 :     std::advance(aIter, nChildIndex);
     378             : 
     379           1 :     xImpl = (*aIter);
     380           1 :     maChildren.erase( aIter );
     381             : 
     382           1 :     if( !xImpl.is() )
     383           0 :         throw IndexOutOfBoundsException();
     384             : 
     385           1 :     xImpl->setParent(0);
     386           1 :     xImpl->mbIsInserted = false;
     387             : 
     388           3 :     broadcast_changes( getReference( xImpl.get() ), false );
     389           1 : }
     390             : 
     391           3 : void SAL_CALL MutableTreeNode::setHasChildrenOnDemand( sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
     392             : {
     393             :     bool bChanged;
     394             : 
     395             :     {
     396           3 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     397           3 :         bChanged = mbHasChildrenOnDemand != bool(bChildrenOnDemand);
     398           3 :         mbHasChildrenOnDemand = bChildrenOnDemand;
     399             :     }
     400             : 
     401           3 :     if( bChanged )
     402           2 :         broadcast_changes();
     403           3 : }
     404             : 
     405           5 : void SAL_CALL MutableTreeNode::setDisplayValue( const Any& aValue ) throw (RuntimeException, std::exception)
     406             : {
     407             :     {
     408           5 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     409           5 :         maDisplayValue = aValue;
     410             :     }
     411             : 
     412           5 :     broadcast_changes();
     413           5 : }
     414             : 
     415          31 : void SAL_CALL MutableTreeNode::setNodeGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     416             : {
     417             :     bool bChanged;
     418             : 
     419             :     {
     420          31 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     421          31 :         bChanged = maNodeGraphicURL != rURL;
     422          31 :         maNodeGraphicURL = rURL;
     423             :     }
     424             : 
     425          31 :     if( bChanged )
     426          31 :         broadcast_changes();
     427          31 : }
     428             : 
     429          61 : void SAL_CALL MutableTreeNode::setExpandedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     430             : {
     431             :     bool bChanged;
     432             : 
     433             :     {
     434          61 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     435          61 :         bChanged = maExpandedGraphicURL != rURL;
     436          61 :         maExpandedGraphicURL = rURL;
     437             :     }
     438             : 
     439          61 :     if( bChanged )
     440          61 :         broadcast_changes();
     441          61 : }
     442             : 
     443          61 : void SAL_CALL MutableTreeNode::setCollapsedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
     444             : {
     445             :     bool bChanged;
     446             : 
     447             :     {
     448          61 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     449          61 :         bChanged = maCollapsedGraphicURL != rURL;
     450          61 :         maCollapsedGraphicURL = rURL;
     451             :     }
     452             : 
     453          61 :     if( bChanged )
     454          61 :         broadcast_changes();
     455          61 : }
     456             : 
     457           3 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getChildAt( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException,RuntimeException, std::exception)
     458             : {
     459           3 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     460             : 
     461           3 :     if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
     462           0 :         throw IndexOutOfBoundsException();
     463           3 :     return getReference( maChildren[nChildIndex].get() );
     464             : }
     465             : 
     466           2 : sal_Int32 SAL_CALL MutableTreeNode::getChildCount(  ) throw (RuntimeException, std::exception)
     467             : {
     468           2 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     469           2 :     return (sal_Int32)maChildren.size();
     470             : }
     471             : 
     472           1 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getParent(  ) throw (RuntimeException, std::exception)
     473             : {
     474           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     475           1 :     return getReference( mpParent );
     476             : }
     477             : 
     478           1 : sal_Int32 SAL_CALL MutableTreeNode::getIndex( const Reference< XTreeNode >& xNode ) throw (RuntimeException, std::exception)
     479             : {
     480           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     481             : 
     482           2 :     MutableTreeNodeRef xImpl( MutableTreeNode::getImplementation( xNode, false ) );
     483           1 :     if( xImpl.is() )
     484             :     {
     485           1 :         sal_Int32 nChildCount = maChildren.size();
     486           2 :         while( nChildCount-- )
     487             :         {
     488           1 :             if( maChildren[nChildCount] == xImpl )
     489           1 :                 return nChildCount;
     490             :         }
     491             :     }
     492             : 
     493           1 :     return -1;
     494             : }
     495             : 
     496           1 : sal_Bool SAL_CALL MutableTreeNode::hasChildrenOnDemand(  ) throw (RuntimeException, std::exception)
     497             : {
     498           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     499           1 :     return mbHasChildrenOnDemand;
     500             : }
     501             : 
     502           1 : Any SAL_CALL MutableTreeNode::getDisplayValue(  ) throw (RuntimeException, std::exception)
     503             : {
     504           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     505           1 :     return maDisplayValue;
     506             : }
     507             : 
     508           1 : OUString SAL_CALL MutableTreeNode::getNodeGraphicURL(  ) throw (RuntimeException, std::exception)
     509             : {
     510           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     511           1 :     return maNodeGraphicURL;
     512             : }
     513             : 
     514           1 : OUString SAL_CALL MutableTreeNode::getExpandedGraphicURL(  ) throw (RuntimeException, std::exception)
     515             : {
     516           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     517           1 :     return maExpandedGraphicURL;
     518             : }
     519             : 
     520           1 : OUString SAL_CALL MutableTreeNode::getCollapsedGraphicURL(  ) throw (RuntimeException, std::exception)
     521             : {
     522           1 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     523           1 :     return maCollapsedGraphicURL;
     524             : }
     525             : 
     526           0 : OUString SAL_CALL MutableTreeNode::getImplementationName(  ) throw (RuntimeException, std::exception)
     527             : {
     528           0 :     return OUString( "toolkit.MutableTreeNode" );
     529             : }
     530             : 
     531           0 : sal_Bool SAL_CALL MutableTreeNode::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
     532             : {
     533           0 :     return cppu::supportsService(this, ServiceName);
     534             : }
     535             : 
     536           0 : Sequence< OUString > SAL_CALL MutableTreeNode::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     537             : {
     538           0 :     Sequence< OUString > aSeq( 1 );
     539           0 :     aSeq[0] = "com.sun.star.awt.tree.MutableTreeNode";
     540           0 :     return aSeq;
     541             : }
     542             : 
     543             : }
     544             : 
     545             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     546           2 : stardiv_Toolkit_MutableTreeDataModel_get_implementation(
     547             :     css::uno::XComponentContext *,
     548             :     css::uno::Sequence<css::uno::Any> const &)
     549             : {
     550           2 :     return cppu::acquire(new MutableTreeDataModel());
     551             : }
     552             : 
     553             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11