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