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