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