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 <com/sun/star/uno/XComponentContext.hpp>
24 : #include <cppuhelper/implbase2.hxx>
25 : #include <cppuhelper/supportsservice.hxx>
26 : #include <rtl/ref.hxx>
27 : #include <toolkit/helper/mutexandbroadcasthelper.hxx>
28 : #include <toolkit/helper/servicenames.hxx>
29 :
30 : using namespace ::com::sun::star;
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::awt;
33 : using namespace ::com::sun::star::awt::tree;
34 : using namespace ::com::sun::star::lang;
35 :
36 : namespace {
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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
69 :
70 : // XComponent
71 : virtual void SAL_CALL dispose( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
72 : virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
73 : virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
74 :
75 : // XServiceInfo
76 : virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
77 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
78 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
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, 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, std::exception) SAL_OVERRIDE;
99 : virtual void SAL_CALL setDataValue( const ::com::sun::star::uno::Any& _datavalue ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
102 : virtual void SAL_CALL removeChildByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 : virtual void SAL_CALL setHasChildrenOnDemand( sal_Bool ChildrenOnDemand ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
104 : virtual void SAL_CALL setDisplayValue( const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 : virtual void SAL_CALL setNodeGraphicURL( const OUString& URL ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
106 : virtual void SAL_CALL setExpandedGraphicURL( const OUString& URL ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 : virtual void SAL_CALL setCollapsedGraphicURL( const OUString& URL ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
111 : virtual ::sal_Int32 SAL_CALL getChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
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, std::exception) SAL_OVERRIDE;
114 : virtual sal_Bool SAL_CALL hasChildrenOnDemand( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
115 : virtual ::com::sun::star::uno::Any SAL_CALL getDisplayValue( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 : virtual OUString SAL_CALL getNodeGraphicURL( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 : virtual OUString SAL_CALL getExpandedGraphicURL( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 : virtual OUString SAL_CALL getCollapsedGraphicURL( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
119 :
120 : // XServiceInfo
121 : virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
122 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
123 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
124 :
125 : static MutableTreeNode* getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException);
126 0 : Reference< XTreeNode > getReference( MutableTreeNode* pNode )
127 : {
128 0 : return Reference< XTreeNode >( pNode );
129 : }
130 :
131 : private:
132 : TreeNodeVector maChildren;
133 : Any maDisplayValue;
134 : Any maDataValue;
135 : 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 0 : MutableTreeDataModel::MutableTreeDataModel()
146 0 : : mbDisposed( false )
147 : {
148 0 : }
149 :
150 0 : MutableTreeDataModel::~MutableTreeDataModel()
151 : {
152 0 : }
153 :
154 0 : void MutableTreeDataModel::broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes )
155 : {
156 0 : ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( cppu::UnoType<XTreeDataModelListener>::get() );
157 0 : if( pIter )
158 : {
159 0 : Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
160 0 : const Sequence< Reference< XTreeNode > > aNodes( pNodes, nNodes );
161 0 : TreeDataModelEvent aEvent( xSource, aNodes, xParentNode );
162 :
163 0 : ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
164 0 : while(aListIter.hasMoreElements())
165 : {
166 0 : XTreeDataModelListener* pListener = static_cast<XTreeDataModelListener*>(aListIter.next());
167 0 : switch( eType )
168 : {
169 0 : case nodes_changed: pListener->treeNodesChanged(aEvent); break;
170 0 : case nodes_inserted: pListener->treeNodesInserted(aEvent); break;
171 0 : case nodes_removed: pListener->treeNodesRemoved(aEvent); break;
172 0 : case structure_changed: pListener->treeStructureChanged(aEvent); break;
173 : }
174 0 : }
175 : }
176 0 : }
177 :
178 0 : Reference< XMutableTreeNode > SAL_CALL MutableTreeDataModel::createNode( const Any& aValue, sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
179 : {
180 0 : return new MutableTreeNode( this, aValue, bChildrenOnDemand );
181 : }
182 :
183 0 : void SAL_CALL MutableTreeDataModel::setRoot( const Reference< XMutableTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
184 : {
185 0 : if( !xNode.is() )
186 0 : throw IllegalArgumentException();
187 :
188 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
189 0 : if( xNode != mxRootNode )
190 : {
191 0 : if( mxRootNode.is() )
192 : {
193 0 : MutableTreeNodeRef xOldImpl( dynamic_cast< MutableTreeNode* >( mxRootNode.get() ) );
194 0 : if( xOldImpl.is() )
195 0 : xOldImpl->mbIsInserted = false;
196 : }
197 :
198 0 : MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
199 0 : if( !xImpl.is() || xImpl->mbIsInserted )
200 0 : throw IllegalArgumentException();
201 :
202 0 : xImpl->mbIsInserted = true;
203 0 : mxRootNode.set(xImpl.get());
204 :
205 0 : Reference< XTreeNode > xParentNode;
206 0 : broadcast( structure_changed, xParentNode, &mxRootNode, 1 );
207 0 : }
208 0 : }
209 :
210 0 : Reference< XTreeNode > SAL_CALL MutableTreeDataModel::getRoot( ) throw (RuntimeException, std::exception)
211 : {
212 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
213 0 : return mxRootNode;
214 : }
215 :
216 0 : void SAL_CALL MutableTreeDataModel::addTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException, std::exception)
217 : {
218 0 : BrdcstHelper.addListener( cppu::UnoType<XTreeDataModelListener>::get(), xListener );
219 0 : }
220 :
221 0 : void SAL_CALL MutableTreeDataModel::removeTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException, std::exception)
222 : {
223 0 : BrdcstHelper.removeListener( cppu::UnoType<XTreeDataModelListener>::get(), xListener );
224 0 : }
225 :
226 0 : void SAL_CALL MutableTreeDataModel::dispose() throw (RuntimeException, std::exception)
227 : {
228 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
229 :
230 0 : if( !mbDisposed )
231 : {
232 0 : mbDisposed = true;
233 0 : ::com::sun::star::lang::EventObject aEvent;
234 0 : aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) );
235 0 : BrdcstHelper.aLC.disposeAndClear( aEvent );
236 0 : }
237 0 : }
238 :
239 0 : void SAL_CALL MutableTreeDataModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception)
240 : {
241 0 : BrdcstHelper.addListener( cppu::UnoType<XEventListener>::get(), xListener );
242 0 : }
243 :
244 0 : void SAL_CALL MutableTreeDataModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException, std::exception)
245 : {
246 0 : BrdcstHelper.removeListener( cppu::UnoType<XEventListener>::get(), xListener );
247 0 : }
248 :
249 0 : OUString SAL_CALL MutableTreeDataModel::getImplementationName( ) throw (RuntimeException, std::exception)
250 : {
251 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
252 0 : static const OUString aImplName( "toolkit.MutableTreeDataModel" );
253 0 : return aImplName;
254 : }
255 :
256 0 : sal_Bool SAL_CALL MutableTreeDataModel::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
257 : {
258 0 : return cppu::supportsService(this, ServiceName);
259 : }
260 :
261 0 : Sequence< OUString > SAL_CALL MutableTreeDataModel::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
262 : {
263 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
264 0 : static const OUString aServiceName( OUString::createFromAscii( szServiceName_MutableTreeDataModel ) );
265 0 : static const Sequence< OUString > aSeq( &aServiceName, 1 );
266 0 : return aSeq;
267 : }
268 :
269 0 : MutableTreeNode::MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, bool bChildrenOnDemand )
270 : : maDisplayValue( rValue )
271 : , mbHasChildrenOnDemand( bChildrenOnDemand )
272 : , mpParent( 0 )
273 : , mxModel( xModel )
274 0 : , mbIsInserted( false )
275 : {
276 0 : }
277 :
278 0 : MutableTreeNode::~MutableTreeNode()
279 : {
280 0 : TreeNodeVector::iterator aIter( maChildren.begin() );
281 0 : while( aIter != maChildren.end() )
282 0 : (*aIter++)->setParent(0);
283 0 : }
284 :
285 0 : void MutableTreeNode::setParent( MutableTreeNode* pParent )
286 : {
287 0 : mpParent = pParent;
288 0 : }
289 :
290 0 : MutableTreeNode* MutableTreeNode::getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException)
291 : {
292 0 : MutableTreeNode* pImpl = dynamic_cast< MutableTreeNode* >( xNode.get() );
293 0 : if( bThrows && !pImpl )
294 0 : implThrowIllegalArgumentException();
295 :
296 0 : return pImpl;
297 : }
298 :
299 0 : void MutableTreeNode::broadcast_changes()
300 : {
301 0 : if( mxModel.is() )
302 : {
303 0 : Reference< XTreeNode > xParent( getReference( mpParent ) );
304 0 : Reference< XTreeNode > xNode( getReference( this ) );
305 0 : mxModel->broadcast( nodes_changed, xParent, &xNode, 1 );
306 : }
307 0 : }
308 :
309 0 : void MutableTreeNode::broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew)
310 : {
311 0 : if( mxModel.is() )
312 : {
313 0 : Reference< XTreeNode > xParent( getReference( this ) );
314 0 : mxModel->broadcast( bNew ? nodes_inserted : nodes_removed, xParent, &xNode, 1 );
315 : }
316 0 : }
317 :
318 0 : Any SAL_CALL MutableTreeNode::getDataValue() throw (RuntimeException, std::exception)
319 : {
320 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
321 0 : return maDataValue;
322 : }
323 :
324 0 : void SAL_CALL MutableTreeNode::setDataValue( const Any& _datavalue ) throw (RuntimeException, std::exception)
325 : {
326 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
327 0 : maDataValue = _datavalue;
328 0 : }
329 :
330 0 : void SAL_CALL MutableTreeNode::appendChild( const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
331 : {
332 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
333 0 : Reference< XTreeNode > xNode( xChildNode.get() );
334 0 : MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
335 :
336 0 : if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
337 0 : throw IllegalArgumentException();
338 :
339 0 : maChildren.push_back( xImpl );
340 0 : xImpl->setParent(this);
341 0 : xImpl->mbIsInserted = true;
342 :
343 0 : broadcast_changes( xNode, true );
344 0 : }
345 :
346 0 : void SAL_CALL MutableTreeNode::insertChildByIndex( sal_Int32 nChildIndex, const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException, std::exception)
347 : {
348 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
349 :
350 0 : if( (nChildIndex < 0) || (nChildIndex > (sal_Int32)maChildren.size()) )
351 0 : throw IndexOutOfBoundsException();
352 :
353 0 : Reference< XTreeNode > xNode( xChildNode.get() );
354 0 : MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) );
355 0 : if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) )
356 0 : throw IllegalArgumentException();
357 :
358 0 : xImpl->mbIsInserted = true;
359 :
360 0 : TreeNodeVector::iterator aIter( maChildren.begin() );
361 0 : while( (nChildIndex-- > 0) && (aIter != maChildren.end()) )
362 0 : ++aIter;
363 :
364 0 : maChildren.insert( aIter, xImpl );
365 0 : xImpl->setParent( this );
366 :
367 0 : broadcast_changes( xNode, true );
368 0 : }
369 :
370 0 : void SAL_CALL MutableTreeNode::removeChildByIndex( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
371 : {
372 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
373 :
374 0 : if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
375 0 : throw IndexOutOfBoundsException();
376 :
377 0 : MutableTreeNodeRef xImpl;
378 :
379 0 : TreeNodeVector::iterator aIter( maChildren.begin() );
380 0 : std::advance(aIter, nChildIndex);
381 :
382 0 : xImpl = (*aIter);
383 0 : maChildren.erase( aIter );
384 :
385 0 : if( !xImpl.is() )
386 0 : throw IndexOutOfBoundsException();
387 :
388 0 : xImpl->setParent(0);
389 0 : xImpl->mbIsInserted = false;
390 :
391 0 : broadcast_changes( getReference( xImpl.get() ), false );
392 0 : }
393 :
394 0 : void SAL_CALL MutableTreeNode::setHasChildrenOnDemand( sal_Bool bChildrenOnDemand ) throw (RuntimeException, std::exception)
395 : {
396 : bool bChanged;
397 :
398 : {
399 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
400 0 : bChanged = mbHasChildrenOnDemand != bool(bChildrenOnDemand);
401 0 : mbHasChildrenOnDemand = bChildrenOnDemand;
402 : }
403 :
404 0 : if( bChanged )
405 0 : broadcast_changes();
406 0 : }
407 :
408 0 : void SAL_CALL MutableTreeNode::setDisplayValue( const Any& aValue ) throw (RuntimeException, std::exception)
409 : {
410 : {
411 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
412 0 : maDisplayValue = aValue;
413 : }
414 :
415 0 : broadcast_changes();
416 0 : }
417 :
418 0 : void SAL_CALL MutableTreeNode::setNodeGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
419 : {
420 : bool bChanged;
421 :
422 : {
423 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
424 0 : bChanged = maNodeGraphicURL != rURL;
425 0 : maNodeGraphicURL = rURL;
426 : }
427 :
428 0 : if( bChanged )
429 0 : broadcast_changes();
430 0 : }
431 :
432 0 : void SAL_CALL MutableTreeNode::setExpandedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
433 : {
434 : bool bChanged;
435 :
436 : {
437 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
438 0 : bChanged = maExpandedGraphicURL != rURL;
439 0 : maExpandedGraphicURL = rURL;
440 : }
441 :
442 0 : if( bChanged )
443 0 : broadcast_changes();
444 0 : }
445 :
446 0 : void SAL_CALL MutableTreeNode::setCollapsedGraphicURL( const OUString& rURL ) throw (RuntimeException, std::exception)
447 : {
448 : bool bChanged;
449 :
450 : {
451 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
452 0 : bChanged = maCollapsedGraphicURL != rURL;
453 0 : maCollapsedGraphicURL = rURL;
454 : }
455 :
456 0 : if( bChanged )
457 0 : broadcast_changes();
458 0 : }
459 :
460 0 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getChildAt( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException,RuntimeException, std::exception)
461 : {
462 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
463 :
464 0 : if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChildren.size()) )
465 0 : throw IndexOutOfBoundsException();
466 0 : return getReference( maChildren[nChildIndex].get() );
467 : }
468 :
469 0 : sal_Int32 SAL_CALL MutableTreeNode::getChildCount( ) throw (RuntimeException, std::exception)
470 : {
471 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
472 0 : return (sal_Int32)maChildren.size();
473 : }
474 :
475 0 : Reference< XTreeNode > SAL_CALL MutableTreeNode::getParent( ) throw (RuntimeException, std::exception)
476 : {
477 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
478 0 : return getReference( mpParent );
479 : }
480 :
481 0 : sal_Int32 SAL_CALL MutableTreeNode::getIndex( const Reference< XTreeNode >& xNode ) throw (RuntimeException, std::exception)
482 : {
483 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
484 :
485 0 : MutableTreeNodeRef xImpl( MutableTreeNode::getImplementation( xNode, false ) );
486 0 : if( xImpl.is() )
487 : {
488 0 : sal_Int32 nChildCount = maChildren.size();
489 0 : while( nChildCount-- )
490 : {
491 0 : if( maChildren[nChildCount] == xImpl )
492 0 : return nChildCount;
493 : }
494 : }
495 :
496 0 : return -1;
497 : }
498 :
499 0 : sal_Bool SAL_CALL MutableTreeNode::hasChildrenOnDemand( ) throw (RuntimeException, std::exception)
500 : {
501 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
502 0 : return mbHasChildrenOnDemand;
503 : }
504 :
505 0 : Any SAL_CALL MutableTreeNode::getDisplayValue( ) throw (RuntimeException, std::exception)
506 : {
507 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
508 0 : return maDisplayValue;
509 : }
510 :
511 0 : OUString SAL_CALL MutableTreeNode::getNodeGraphicURL( ) throw (RuntimeException, std::exception)
512 : {
513 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
514 0 : return maNodeGraphicURL;
515 : }
516 :
517 0 : OUString SAL_CALL MutableTreeNode::getExpandedGraphicURL( ) throw (RuntimeException, std::exception)
518 : {
519 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
520 0 : return maExpandedGraphicURL;
521 : }
522 :
523 0 : OUString SAL_CALL MutableTreeNode::getCollapsedGraphicURL( ) throw (RuntimeException, std::exception)
524 : {
525 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
526 0 : return maCollapsedGraphicURL;
527 : }
528 :
529 0 : OUString SAL_CALL MutableTreeNode::getImplementationName( ) throw (RuntimeException, std::exception)
530 : {
531 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
532 0 : static const OUString aImplName( "toolkit.MutableTreeNode" );
533 0 : return aImplName;
534 : }
535 :
536 0 : sal_Bool SAL_CALL MutableTreeNode::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
537 : {
538 0 : return cppu::supportsService(this, ServiceName);
539 : }
540 :
541 0 : Sequence< OUString > SAL_CALL MutableTreeNode::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
542 : {
543 0 : ::osl::Guard< ::osl::Mutex > aGuard( maMutex );
544 0 : static const OUString aServiceName( "com.sun.star.awt.tree.MutableTreeNode" );
545 0 : static const Sequence< OUString > aSeq( &aServiceName, 1 );
546 0 : return aSeq;
547 : }
548 :
549 : }
550 :
551 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
552 0 : stardiv_Toolkit_MutableTreeDataModel_get_implementation(
553 : css::uno::XComponentContext *,
554 : css::uno::Sequence<css::uno::Any> const &)
555 : {
556 0 : return cppu::acquire(new MutableTreeDataModel());
557 : }
558 :
559 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|