LCOV - code coverage report
Current view: top level - libreoffice/toolkit/source/controls/tree - treedatamodel.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 240 0.0 %
Date: 2012-12-27 Functions: 0 47 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/awt/tree/XMutableTreeDataModel.hpp>
      21             : #include <com/sun/star/lang/XServiceInfo.hpp>
      22             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      23             : #include <cppuhelper/implbase2.hxx>
      24             : #include <cppuhelper/implbase3.hxx>
      25             : #include <rtl/ref.hxx>
      26             : #include <toolkit/helper/mutexandbroadcasthelper.hxx>
      27             : #include <toolkit/helper/servicenames.hxx>
      28             : 
      29             : using ::rtl::OUString;
      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 toolkit
      37             : {
      38             : 
      39             :     enum broadcast_type { nodes_changed, nodes_inserted, nodes_removed, structure_changed };
      40             : 
      41             : class MutableTreeNode;
      42             : class MutableTreeDataModel;
      43             : 
      44             : typedef rtl::Reference< MutableTreeNode > MutableTreeNodeRef;
      45             : typedef std::vector< MutableTreeNodeRef > TreeNodeVector;
      46             : typedef rtl::Reference< MutableTreeDataModel > MutableTreeDataModelRef;
      47             : 
      48           0 : static void implThrowIllegalArgumentException() throw( IllegalArgumentException )
      49             : {
      50           0 :     throw IllegalArgumentException();
      51             : }
      52             : 
      53             : class MutableTreeDataModel : public ::cppu::WeakAggImplHelper2< XMutableTreeDataModel, XServiceInfo >,
      54             :                              public MutexAndBroadcastHelper
      55             : {
      56             : public:
      57             :     MutableTreeDataModel();
      58             :     virtual ~MutableTreeDataModel();
      59             : 
      60             :     void broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes );
      61             : 
      62             :     // XMutableTreeDataModel
      63             :     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);
      64             :     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);
      65             : 
      66             :     // XTreeDataModel
      67             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getRoot(  ) throw (::com::sun::star::uno::RuntimeException);
      68             :     virtual void SAL_CALL addTreeDataModelListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModelListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
      69             :     virtual void SAL_CALL removeTreeDataModelListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModelListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
      70             : 
      71             :     // XComponent
      72             :     virtual void SAL_CALL dispose(  ) throw (RuntimeException);
      73             :     virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException);
      74             :     virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException);
      75             : 
      76             :     // XServiceInfo
      77             :     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
      78             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
      79             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
      80             : 
      81             : private:
      82             :     bool mbDisposed;
      83             :     Reference< XTreeNode > mxRootNode;
      84             : };
      85             : 
      86             : class MutableTreeNode: public ::cppu::WeakAggImplHelper2< XMutableTreeNode, XServiceInfo >
      87             : {
      88             :     friend class MutableTreeDataModel;
      89             : 
      90             : public:
      91             :     MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, sal_Bool bChildrenOnDemand );
      92             :     virtual ~MutableTreeNode();
      93             : 
      94             :     void setParent( MutableTreeNode* pParent );
      95             :     void broadcast_changes();
      96             :     void broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew);
      97             : 
      98             :     // XMutableTreeNode
      99             :     virtual ::com::sun::star::uno::Any SAL_CALL getDataValue() throw (::com::sun::star::uno::RuntimeException);
     100             :     virtual void SAL_CALL setDataValue( const ::com::sun::star::uno::Any& _datavalue ) throw (::com::sun::star::uno::RuntimeException);
     101             :     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);
     102             :     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);
     103             :     virtual void SAL_CALL removeChildByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
     104             :     virtual void SAL_CALL setHasChildrenOnDemand( ::sal_Bool ChildrenOnDemand ) throw (::com::sun::star::uno::RuntimeException);
     105             :     virtual void SAL_CALL setDisplayValue( const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::uno::RuntimeException);
     106             :     virtual void SAL_CALL setNodeGraphicURL( const ::rtl::OUString& URL ) throw (::com::sun::star::uno::RuntimeException);
     107             :     virtual void SAL_CALL setExpandedGraphicURL( const ::rtl::OUString& URL ) throw (::com::sun::star::uno::RuntimeException);
     108             :     virtual void SAL_CALL setCollapsedGraphicURL( const ::rtl::OUString& URL ) throw (::com::sun::star::uno::RuntimeException);
     109             : 
     110             :     // XTreeNode
     111             :     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);
     112             :     virtual ::sal_Int32 SAL_CALL getChildCount(  ) throw (::com::sun::star::uno::RuntimeException);
     113             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException);
     114             :     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);
     115             :     virtual ::sal_Bool SAL_CALL hasChildrenOnDemand(  ) throw (::com::sun::star::uno::RuntimeException);
     116             :     virtual ::com::sun::star::uno::Any SAL_CALL getDisplayValue(  ) throw (::com::sun::star::uno::RuntimeException);
     117             :     virtual ::rtl::OUString SAL_CALL getNodeGraphicURL(  ) throw (::com::sun::star::uno::RuntimeException);
     118             :     virtual ::rtl::OUString SAL_CALL getExpandedGraphicURL(  ) throw (::com::sun::star::uno::RuntimeException);
     119             :     virtual ::rtl::OUString SAL_CALL getCollapsedGraphicURL(  ) throw (::com::sun::star::uno::RuntimeException);
     120             : 
     121             :     // XServiceInfo
     122             :     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
     123             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
     124             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
     125             : 
     126             :     static MutableTreeNode* getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException);
     127           0 :     Reference< XTreeNode > getReference( MutableTreeNode* pNode )
     128             :     {
     129           0 :         return Reference< XTreeNode >( pNode );
     130             :     }
     131             : 
     132             : private:
     133             :     TreeNodeVector  maChildren;
     134             :     Any maDisplayValue;
     135             :     Any maDataValue;
     136             :     sal_Bool mbHasChildrenOnDemand;
     137             :     ::osl::Mutex maMutex;
     138             :     MutableTreeNode* mpParent;
     139             :     MutableTreeDataModelRef mxModel;
     140             :     OUString maNodeGraphicURL;
     141             :     OUString maExpandedGraphicURL;
     142             :     OUString maCollapsedGraphicURL;
     143             :     bool mbIsInserted;
     144             : };
     145             : 
     146             : ///////////////////////////////////////////////////////////////////////
     147             : // class MutableTreeDataModel
     148             : ///////////////////////////////////////////////////////////////////////
     149             : 
     150           0 : MutableTreeDataModel::MutableTreeDataModel()
     151           0 : : mbDisposed( false )
     152             : {
     153           0 : }
     154             : 
     155             : //---------------------------------------------------------------------
     156             : 
     157           0 : MutableTreeDataModel::~MutableTreeDataModel()
     158             : {
     159           0 : }
     160             : 
     161             : //---------------------------------------------------------------------
     162             : 
     163           0 : void MutableTreeDataModel::broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes )
     164             : {
     165           0 :     ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XTreeDataModelListener::static_type() );
     166           0 :     if( pIter )
     167             :     {
     168           0 :         Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
     169           0 :         const Sequence< Reference< XTreeNode > > aNodes( pNodes, nNodes );
     170           0 :         TreeDataModelEvent aEvent( xSource, aNodes, xParentNode );
     171             : 
     172           0 :         ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
     173           0 :         while(aListIter.hasMoreElements())
     174             :         {
     175           0 :             XTreeDataModelListener* pListener = static_cast<XTreeDataModelListener*>(aListIter.next());
     176           0 :             switch( eType )
     177             :             {
     178           0 :             case nodes_changed:     pListener->treeNodesChanged(aEvent); break;
     179           0 :             case nodes_inserted:    pListener->treeNodesInserted(aEvent); break;
     180           0 :             case nodes_removed:     pListener->treeNodesRemoved(aEvent); break;
     181           0 :             case structure_changed: pListener->treeStructureChanged(aEvent); break;
     182             :             }
     183           0 :         }
     184             :     }
     185           0 : }
     186             : 
     187             : //---------------------------------------------------------------------
     188             : // XMutableTreeDataModel
     189             : //---------------------------------------------------------------------
     190             : 
     191           0 : Reference< XMutableTreeNode > SAL_CALL MutableTreeDataModel::createNode( const Any& aValue, sal_Bool bChildrenOnDemand ) throw (RuntimeException)
     192             : {
     193           0 :     return new MutableTreeNode( this, aValue, bChildrenOnDemand );
     194             : }
     195             : 
     196             : //---------------------------------------------------------------------
     197             : 
     198           0 : void SAL_CALL MutableTreeDataModel::setRoot( const Reference< XMutableTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException)
     199             : {
     200           0 :     if( !xNode.is() )
     201           0 :         throw IllegalArgumentException();
     202             : 
     203           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     204           0 :     if( xNode != mxRootNode )
     205             :     {
     206           0 :         if( mxRootNode.is() )
     207             :         {
     208           0 :             MutableTreeNodeRef xOldImpl( dynamic_cast< MutableTreeNode* >( mxRootNode.get() ) );
     209           0 :             if( xOldImpl.is() )
     210           0 :                 xOldImpl->mbIsInserted = false;
     211             :         }
     212             : 
     213           0 :         MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     214           0 :         if( !xImpl.is() || xImpl->mbIsInserted )
     215           0 :             throw IllegalArgumentException();
     216             : 
     217           0 :         xImpl->mbIsInserted = true;
     218           0 :         mxRootNode.set(xImpl.get());
     219             : 
     220           0 :         Reference< XTreeNode > xParentNode;
     221           0 :         broadcast( structure_changed, xParentNode, &mxRootNode, 1 );
     222           0 :     }
     223           0 : }
     224             : 
     225             : //---------------------------------------------------------------------
     226             : // XTreeDataModel
     227             : //---------------------------------------------------------------------
     228             : 
     229           0 : Reference< XTreeNode > SAL_CALL MutableTreeDataModel::getRoot(  ) throw (RuntimeException)
     230             : {
     231           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     232           0 :     return mxRootNode;
     233             : }
     234             : 
     235             : //---------------------------------------------------------------------
     236             : 
     237           0 : void SAL_CALL MutableTreeDataModel::addTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException)
     238             : {
     239           0 :     BrdcstHelper.addListener( XTreeDataModelListener::static_type(), xListener );
     240           0 : }
     241             : 
     242             : //---------------------------------------------------------------------
     243             : 
     244           0 : void SAL_CALL MutableTreeDataModel::removeTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException)
     245             : {
     246           0 :     BrdcstHelper.removeListener( XTreeDataModelListener::static_type(), xListener );
     247           0 : }
     248             : 
     249             : //---------------------------------------------------------------------
     250             : // XComponent
     251             : //---------------------------------------------------------------------
     252             : 
     253           0 : void SAL_CALL MutableTreeDataModel::dispose() throw (RuntimeException)
     254             : {
     255           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     256             : 
     257           0 :     if( !mbDisposed )
     258             :     {
     259           0 :         mbDisposed = true;
     260           0 :         ::com::sun::star::lang::EventObject aEvent;
     261           0 :         aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) );
     262           0 :         BrdcstHelper.aLC.disposeAndClear( aEvent );
     263           0 :     }
     264           0 : }
     265             : 
     266             : //---------------------------------------------------------------------
     267             : 
     268           0 : void SAL_CALL MutableTreeDataModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
     269             : {
     270           0 :     BrdcstHelper.addListener( XEventListener::static_type(), xListener );
     271           0 : }
     272             : 
     273             : //---------------------------------------------------------------------
     274             : 
     275           0 : void SAL_CALL MutableTreeDataModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
     276             : {
     277           0 :     BrdcstHelper.removeListener( XEventListener::static_type(), xListener );
     278           0 : }
     279             : 
     280             : //---------------------------------------------------------------------
     281             : // XServiceInfo
     282             : //---------------------------------------------------------------------
     283             : 
     284           0 : OUString SAL_CALL MutableTreeDataModel::getImplementationName(  ) throw (RuntimeException)
     285             : {
     286           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     287           0 :     static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.MutableTreeDataModel" ) );
     288           0 :     return aImplName;
     289             : }
     290             : 
     291             : //---------------------------------------------------------------------
     292             : 
     293           0 : sal_Bool SAL_CALL MutableTreeDataModel::supportsService( const OUString& ServiceName ) throw (RuntimeException)
     294             : {
     295           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     296           0 :     return ServiceName.equalsAscii( szServiceName_MutableTreeDataModel );
     297             : }
     298             : 
     299             : //---------------------------------------------------------------------
     300             : 
     301           0 : Sequence< OUString > SAL_CALL MutableTreeDataModel::getSupportedServiceNames(  ) throw (RuntimeException)
     302             : {
     303           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     304           0 :     static const OUString aServiceName( OUString::createFromAscii( szServiceName_MutableTreeDataModel ) );
     305           0 :     static const Sequence< OUString > aSeq( &aServiceName, 1 );
     306           0 :     return aSeq;
     307             : }
     308             : 
     309             : ///////////////////////////////////////////////////////////////////////
     310             : // class MutabelTreeNode
     311             : ///////////////////////////////////////////////////////////////////////
     312             : 
     313           0 : MutableTreeNode::MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, sal_Bool bChildrenOnDemand )
     314             : : maDisplayValue( rValue )
     315             : , mbHasChildrenOnDemand( bChildrenOnDemand )
     316             : , mpParent( 0 )
     317             : , mxModel( xModel )
     318           0 : , mbIsInserted( false )
     319             : {
     320           0 : }
     321             : 
     322             : //---------------------------------------------------------------------
     323             : 
     324           0 : MutableTreeNode::~MutableTreeNode()
     325             : {
     326           0 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     327           0 :     while( aIter != maChildren.end() )
     328           0 :         (*aIter++)->setParent(0);
     329           0 : }
     330             : 
     331             : //---------------------------------------------------------------------
     332             : 
     333           0 : void MutableTreeNode::setParent( MutableTreeNode* pParent )
     334             : {
     335           0 :     mpParent = pParent;
     336           0 : }
     337             : 
     338             : //---------------------------------------------------------------------
     339             : 
     340           0 : MutableTreeNode* MutableTreeNode::getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException)
     341             : {
     342           0 :     MutableTreeNode* pImpl = dynamic_cast< MutableTreeNode* >( xNode.get() );
     343           0 :     if( bThrows && !pImpl )
     344           0 :         implThrowIllegalArgumentException();
     345             : 
     346           0 :     return pImpl;
     347             : }
     348             : 
     349             : //---------------------------------------------------------------------
     350             : 
     351           0 : void MutableTreeNode::broadcast_changes()
     352             : {
     353           0 :     if( mxModel.is() )
     354             :     {
     355           0 :         Reference< XTreeNode > xParent( getReference( mpParent ) );
     356           0 :         Reference< XTreeNode > xNode( getReference( this ) );
     357           0 :         mxModel->broadcast( nodes_changed, xParent, &xNode, 1 );
     358             :     }
     359           0 : }
     360             : 
     361             : //---------------------------------------------------------------------
     362             : 
     363           0 : void MutableTreeNode::broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew)
     364             : {
     365           0 :     if( mxModel.is() )
     366             :     {
     367           0 :         Reference< XTreeNode > xParent( getReference( this ) );
     368           0 :         mxModel->broadcast( bNew ? nodes_inserted : nodes_removed, xParent, &xNode, 1 );
     369             :     }
     370           0 : }
     371             : 
     372             : //---------------------------------------------------------------------
     373             : // XMutableTreeNode
     374             : //---------------------------------------------------------------------
     375             : 
     376           0 : Any SAL_CALL MutableTreeNode::getDataValue() throw (RuntimeException)
     377             : {
     378           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     379           0 :     return maDataValue;
     380             : }
     381             : 
     382             : //---------------------------------------------------------------------
     383             : 
     384           0 : void SAL_CALL MutableTreeNode::setDataValue( const Any& _datavalue ) throw (RuntimeException)
     385             : {
     386           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     387           0 :     maDataValue = _datavalue;
     388           0 : }
     389             : 
     390             : //---------------------------------------------------------------------
     391             : 
     392           0 : void SAL_CALL MutableTreeNode::appendChild( const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, RuntimeException)
     393             : {
     394           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     395           0 :     Reference< XTreeNode > xNode( xChildNode.get() );
     396           0 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     397             : 
     398           0 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     399           0 :         throw IllegalArgumentException();
     400             : 
     401           0 :     maChildren.push_back( xImpl );
     402           0 :     xImpl->setParent(this);
     403           0 :     xImpl->mbIsInserted = true;
     404             : 
     405           0 :     broadcast_changes( xNode, true );
     406           0 : }
     407             : 
     408             : //---------------------------------------------------------------------
     409             : 
     410           0 : void SAL_CALL MutableTreeNode::insertChildByIndex( sal_Int32 nChildIndex, const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException)
     411             : {
     412           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     413             : 
     414           0 :     if( (nChildIndex < 0) || (nChildIndex > (sal_Int32)maChildren.size()) )
     415           0 :         throw IndexOutOfBoundsException();
     416             : 
     417           0 :     Reference< XTreeNode > xNode( xChildNode.get() );
     418           0 :     MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
     419           0 :     if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
     420           0 :         throw IllegalArgumentException();
     421             : 
     422           0 :     xImpl->mbIsInserted = true;
     423             : 
     424           0 :     TreeNodeVector::iterator aIter( maChildren.begin() );
     425           0 :     while( (nChildIndex-- > 0) && (aIter != maChildren.end()) )
     426           0 :         aIter++;
     427             : 
     428           0 :     maChildren.insert( aIter, xImpl );
     429           0 :     xImpl->setParent( this );
     430             : 
     431           0 :     broadcast_changes( xNode, true );
     432           0 : }
     433             : 
     434             : //---------------------------------------------------------------------
     435             : 
     436           0 : void SAL_CALL MutableTreeNode::removeChildByIndex( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     437             : {
     438           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     439             : 
     440           0 :     MutableTreeNodeRef xImpl;
     441             : 
     442           0 :     if( (nChildIndex >= 0) && (nChildIndex < (sal_Int32)maChildren.size()) )
     443             :     {
     444           0 :         TreeNodeVector::iterator aIter( maChildren.begin() );
     445           0 :         while( nChildIndex-- && (aIter != maChildren.end()) )
     446           0 :             aIter++;
     447             : 
     448           0 :         if( aIter != maChildren.end() )
     449             :         {
     450           0 :             xImpl = (*aIter);
     451           0 :             maChildren.erase( aIter );
     452             :         }
     453             :     }
     454             : 
     455           0 :     if( !xImpl.is() )
     456           0 :         throw IndexOutOfBoundsException();
     457             : 
     458           0 :     xImpl->setParent(0);
     459           0 :     xImpl->mbIsInserted = false;
     460             : 
     461           0 :     broadcast_changes( getReference( xImpl.get() ), false );
     462           0 : }
     463             : 
     464             : //---------------------------------------------------------------------
     465             : 
     466           0 : void SAL_CALL MutableTreeNode::setHasChildrenOnDemand( sal_Bool bChildrenOnDemand ) throw (RuntimeException)
     467             : {
     468             :     bool bChanged;
     469             : 
     470             :     {
     471           0 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     472           0 :         bChanged = mbHasChildrenOnDemand != bChildrenOnDemand;
     473           0 :         mbHasChildrenOnDemand = bChildrenOnDemand;
     474             :     }
     475             : 
     476           0 :     if( bChanged )
     477           0 :         broadcast_changes();
     478           0 : }
     479             : 
     480             : //---------------------------------------------------------------------
     481             : 
     482           0 : void SAL_CALL MutableTreeNode::setDisplayValue( const Any& aValue ) throw (RuntimeException)
     483             : {
     484             :     {
     485           0 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     486           0 :         maDisplayValue = aValue;
     487             :     }
     488             : 
     489           0 :     broadcast_changes();
     490           0 : }
     491             : 
     492             : //---------------------------------------------------------------------
     493             : 
     494           0 : void SAL_CALL MutableTreeNode::setNodeGraphicURL( const OUString& rURL ) throw (RuntimeException)
     495             : {
     496             :     bool bChanged;
     497             : 
     498             :     {
     499           0 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     500           0 :         bChanged = maNodeGraphicURL != rURL;
     501           0 :         maNodeGraphicURL = rURL;
     502             :     }
     503             : 
     504           0 :     if( bChanged )
     505           0 :         broadcast_changes();
     506           0 : }
     507             : 
     508             : //---------------------------------------------------------------------
     509             : 
     510           0 : void SAL_CALL MutableTreeNode::setExpandedGraphicURL( const OUString& rURL ) throw (RuntimeException)
     511             : {
     512             :     bool bChanged;
     513             : 
     514             :     {
     515           0 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     516           0 :         bChanged = maExpandedGraphicURL != rURL;
     517           0 :         maExpandedGraphicURL = rURL;
     518             :     }
     519             : 
     520           0 :     if( bChanged )
     521           0 :         broadcast_changes();
     522           0 : }
     523             : 
     524             : //---------------------------------------------------------------------
     525             : 
     526           0 : void SAL_CALL MutableTreeNode::setCollapsedGraphicURL( const OUString& rURL ) throw (RuntimeException)
     527             : {
     528             :     bool bChanged;
     529             : 
     530             :     {
     531           0 :         ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     532           0 :         bChanged = maCollapsedGraphicURL != rURL;
     533           0 :         maCollapsedGraphicURL = rURL;
     534             :     }
     535             : 
     536           0 :     if( bChanged )
     537           0 :         broadcast_changes();
     538           0 : }
     539             : 
     540             : //---------------------------------------------------------------------
     541             : // XTreeNode
     542             : //---------------------------------------------------------------------
     543             : 
     544           0 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getChildAt( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException,RuntimeException)
     545             : {
     546           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     547             : 
     548           0 :     if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
     549           0 :         throw IndexOutOfBoundsException();
     550           0 :     return getReference( maChildren[nChildIndex].get() );
     551             : }
     552             : 
     553             : //---------------------------------------------------------------------
     554             : 
     555           0 : sal_Int32 SAL_CALL MutableTreeNode::getChildCount(  ) throw (RuntimeException)
     556             : {
     557           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     558           0 :     return (sal_Int32)maChildren.size();
     559             : }
     560             : 
     561             : //---------------------------------------------------------------------
     562             : 
     563           0 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getParent(  ) throw (RuntimeException)
     564             : {
     565           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     566           0 :     return getReference( mpParent );
     567             : }
     568             : 
     569             : //---------------------------------------------------------------------
     570             : 
     571           0 : sal_Int32 SAL_CALL MutableTreeNode::getIndex( const Reference< XTreeNode >& xNode ) throw (RuntimeException)
     572             : {
     573           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     574             : 
     575           0 :     MutableTreeNodeRef xImpl( MutableTreeNode::getImplementation( xNode, false ) );
     576           0 :     if( xImpl.is() )
     577             :     {
     578           0 :         sal_Int32 nChildCount = maChildren.size();
     579           0 :         while( nChildCount-- )
     580             :         {
     581           0 :             if( maChildren[nChildCount] == xImpl )
     582           0 :                 return nChildCount;
     583             :         }
     584             :     }
     585             : 
     586           0 :     return -1;
     587             : }
     588             : 
     589             : //---------------------------------------------------------------------
     590             : 
     591           0 : sal_Bool SAL_CALL MutableTreeNode::hasChildrenOnDemand(  ) throw (RuntimeException)
     592             : {
     593           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     594           0 :     return mbHasChildrenOnDemand;
     595             : }
     596             : 
     597             : //---------------------------------------------------------------------
     598             : 
     599           0 : Any SAL_CALL MutableTreeNode::getDisplayValue(  ) throw (RuntimeException)
     600             : {
     601           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     602           0 :     return maDisplayValue;
     603             : }
     604             : 
     605             : //---------------------------------------------------------------------
     606             : 
     607           0 : OUString SAL_CALL MutableTreeNode::getNodeGraphicURL(  ) throw (RuntimeException)
     608             : {
     609           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     610           0 :     return maNodeGraphicURL;
     611             : }
     612             : 
     613             : //---------------------------------------------------------------------
     614             : 
     615           0 : OUString SAL_CALL MutableTreeNode::getExpandedGraphicURL(  ) throw (RuntimeException)
     616             : {
     617           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     618           0 :     return maExpandedGraphicURL;
     619             : }
     620             : 
     621             : //---------------------------------------------------------------------
     622             : 
     623           0 : OUString SAL_CALL MutableTreeNode::getCollapsedGraphicURL(  ) throw (RuntimeException)
     624             : {
     625           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     626           0 :     return maCollapsedGraphicURL;
     627             : }
     628             : 
     629             : //---------------------------------------------------------------------
     630             : // XServiceInfo
     631             : //---------------------------------------------------------------------
     632             : 
     633           0 : OUString SAL_CALL MutableTreeNode::getImplementationName(  ) throw (RuntimeException)
     634             : {
     635           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     636           0 :     static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.MutableTreeNode" ) );
     637           0 :     return aImplName;
     638             : }
     639             : 
     640             : //---------------------------------------------------------------------
     641             : 
     642           0 : sal_Bool SAL_CALL MutableTreeNode::supportsService( const OUString& ServiceName ) throw (RuntimeException)
     643             : {
     644           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     645           0 :     return ServiceName == "com.sun.star.awt.tree.MutableTreeNode";
     646             : }
     647             : 
     648             : //---------------------------------------------------------------------
     649             : 
     650           0 : Sequence< OUString > SAL_CALL MutableTreeNode::getSupportedServiceNames(  ) throw (RuntimeException)
     651             : {
     652           0 :     ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
     653           0 :     static const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.tree.MutableTreeNode" ) );
     654           0 :     static const Sequence< OUString > aSeq( &aServiceName, 1 );
     655           0 :     return aSeq;
     656             : }
     657             : 
     658             : }
     659             : 
     660           0 : Reference< XInterface > SAL_CALL MutableTreeDataModel_CreateInstance( const Reference< XMultiServiceFactory >& )
     661             : {
     662           0 :     return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::MutableTreeDataModel );
     663             : }
     664             : 
     665             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10