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