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