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 :
21 : #include <treecontrol.hxx>
22 :
23 : #include <com/sun/star/awt/tree/XTreeControl.hpp>
24 : #include <com/sun/star/awt/tree/XTreeDataModel.hpp>
25 : #include <com/sun/star/view/SelectionType.hpp>
26 : #include <toolkit/helper/unopropertyarrayhelper.hxx>
27 : #include <toolkit/helper/property.hxx>
28 : #include <osl/diagnose.h>
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 : using namespace ::com::sun::star::beans;
36 : using namespace ::com::sun::star::container;
37 : using namespace ::com::sun::star::view;
38 :
39 : namespace toolkit
40 : {
41 :
42 : // class UnoTreeModel
43 :
44 0 : UnoTreeModel::UnoTreeModel( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_factory )
45 0 : :UnoControlModel( i_factory )
46 : {
47 0 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
48 0 : ImplRegisterProperty( BASEPROPERTY_BORDER );
49 0 : ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
50 0 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
51 0 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
52 0 : ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
53 0 : ImplRegisterProperty( BASEPROPERTY_FILLCOLOR );
54 0 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
55 0 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
56 0 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
57 0 : ImplRegisterProperty( BASEPROPERTY_TABSTOP );
58 0 : ImplRegisterProperty( BASEPROPERTY_TREE_SELECTIONTYPE );
59 0 : ImplRegisterProperty( BASEPROPERTY_TREE_EDITABLE );
60 0 : ImplRegisterProperty( BASEPROPERTY_TREE_DATAMODEL );
61 0 : ImplRegisterProperty( BASEPROPERTY_TREE_ROOTDISPLAYED );
62 0 : ImplRegisterProperty( BASEPROPERTY_TREE_SHOWSHANDLES );
63 0 : ImplRegisterProperty( BASEPROPERTY_TREE_SHOWSROOTHANDLES );
64 0 : ImplRegisterProperty( BASEPROPERTY_ROW_HEIGHT );
65 0 : ImplRegisterProperty( BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING );
66 0 : ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION );
67 0 : }
68 :
69 0 : UnoTreeModel::UnoTreeModel( const UnoTreeModel& rModel )
70 0 : : UnoControlModel( rModel )
71 : {
72 0 : }
73 :
74 0 : UnoControlModel* UnoTreeModel::Clone() const
75 : {
76 0 : return new UnoTreeModel( *this );
77 : }
78 :
79 0 : OUString UnoTreeModel::getServiceName() throw(RuntimeException, std::exception)
80 : {
81 0 : return OUString::createFromAscii( szServiceName_TreeControlModel );
82 : }
83 :
84 0 : Any UnoTreeModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
85 : {
86 0 : switch( nPropId )
87 : {
88 : case BASEPROPERTY_TREE_SELECTIONTYPE:
89 0 : return Any( SelectionType_NONE );
90 : case BASEPROPERTY_ROW_HEIGHT:
91 0 : return Any( sal_Int32( 0 ) );
92 : case BASEPROPERTY_TREE_DATAMODEL:
93 0 : return Any( Reference< XTreeDataModel >( 0 ) );
94 : case BASEPROPERTY_TREE_EDITABLE:
95 : case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING:
96 0 : return Any( sal_False );
97 : case BASEPROPERTY_TREE_ROOTDISPLAYED:
98 : case BASEPROPERTY_TREE_SHOWSROOTHANDLES:
99 : case BASEPROPERTY_TREE_SHOWSHANDLES:
100 0 : return Any( sal_True );
101 : case BASEPROPERTY_DEFAULTCONTROL:
102 0 : return uno::makeAny( OUString::createFromAscii( szServiceName_TreeControl ) );
103 : default:
104 0 : return UnoControlModel::ImplGetDefaultValue( nPropId );
105 : }
106 : }
107 :
108 0 : ::cppu::IPropertyArrayHelper& UnoTreeModel::getInfoHelper()
109 : {
110 : static UnoPropertyArrayHelper* pHelper = NULL;
111 0 : if ( !pHelper )
112 : {
113 0 : Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
114 0 : pHelper = new UnoPropertyArrayHelper( aIDs );
115 : }
116 0 : return *pHelper;
117 : }
118 :
119 : // XMultiPropertySet
120 0 : Reference< XPropertySetInfo > UnoTreeModel::getPropertySetInfo( ) throw(RuntimeException, std::exception)
121 : {
122 0 : static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
123 0 : return xInfo;
124 : }
125 :
126 : }
127 :
128 : namespace {
129 :
130 : typedef ::cppu::ImplInheritanceHelper1< UnoControlBase, css::awt::tree::XTreeControl > UnoTreeControl_Base;
131 0 : class UnoTreeControl : public UnoTreeControl_Base
132 : {
133 : public:
134 : UnoTreeControl();
135 : OUString GetComponentServiceName() SAL_OVERRIDE;
136 :
137 : // css::lang::XComponent
138 : void SAL_CALL dispose( ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 :
140 : // css::awt::XControl
141 : void SAL_CALL createPeer( const css::uno::Reference< css::awt::XToolkit >& Toolkit, const css::uno::Reference< css::awt::XWindowPeer >& Parent ) throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
142 :
143 : // css::view::XSelectionSupplier
144 : virtual sal_Bool SAL_CALL select( const css::uno::Any& xSelection ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
145 : virtual css::uno::Any SAL_CALL getSelection( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
146 : virtual void SAL_CALL addSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 : virtual void SAL_CALL removeSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 :
149 : // css::view::XMultiSelectionSupplier
150 : virtual sal_Bool SAL_CALL addSelection( const css::uno::Any& Selection ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 : virtual void SAL_CALL removeSelection( const css::uno::Any& Selection ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 : virtual void SAL_CALL clearSelection( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 : virtual ::sal_Int32 SAL_CALL getSelectionCount( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 : virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSelectionEnumeration( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 : virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createReverseSelectionEnumeration( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 :
157 : // css::awt::XTreeControl
158 : virtual OUString SAL_CALL getDefaultExpandedGraphicURL() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 : virtual void SAL_CALL setDefaultExpandedGraphicURL( const OUString& _defaultexpandedgraphicurl ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 : virtual OUString SAL_CALL getDefaultCollapsedGraphicURL() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 : virtual void SAL_CALL setDefaultCollapsedGraphicURL( const OUString& _defaultcollapsedgraphicurl ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
162 : virtual sal_Bool SAL_CALL isNodeExpanded( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
163 : virtual sal_Bool SAL_CALL isNodeCollapsed( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 : virtual void SAL_CALL makeNodeVisible( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::awt::tree::ExpandVetoException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 : virtual sal_Bool SAL_CALL isNodeVisible( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
166 : virtual void SAL_CALL expandNode( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::awt::tree::ExpandVetoException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
167 : virtual void SAL_CALL collapseNode( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::awt::tree::ExpandVetoException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
168 : virtual void SAL_CALL addTreeExpansionListener( const css::uno::Reference< css::awt::tree::XTreeExpansionListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
169 : virtual void SAL_CALL removeTreeExpansionListener( const css::uno::Reference< css::awt::tree::XTreeExpansionListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 : virtual css::uno::Reference< css::awt::tree::XTreeNode > SAL_CALL getNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
171 : virtual css::uno::Reference< css::awt::tree::XTreeNode > SAL_CALL getClosestNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 : virtual css::awt::Rectangle SAL_CALL getNodeRect( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 : virtual sal_Bool SAL_CALL isEditing( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
174 : virtual sal_Bool SAL_CALL stopEditing( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 : virtual void SAL_CALL cancelEditing( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 : virtual void SAL_CALL startEditingAtNode( const css::uno::Reference< css::awt::tree::XTreeNode >& Node ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 : virtual void SAL_CALL addTreeEditListener( const css::uno::Reference< css::awt::tree::XTreeEditListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
178 : virtual void SAL_CALL removeTreeEditListener( const css::uno::Reference< css::awt::tree::XTreeEditListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
179 :
180 : // css::lang::XServiceInfo
181 0 : DECLIMPL_SERVICEINFO_DERIVED( UnoTreeControl, UnoControlBase, szServiceName_TreeControl )
182 :
183 : using UnoControl::getPeer;
184 : private:
185 : TreeSelectionListenerMultiplexer maSelectionListeners;
186 : TreeExpansionListenerMultiplexer maTreeExpansionListeners;
187 : TreeEditListenerMultiplexer maTreeEditListeners;
188 : };
189 :
190 0 : UnoTreeControl::UnoTreeControl()
191 : : UnoTreeControl_Base()
192 : , maSelectionListeners( *this )
193 : , maTreeExpansionListeners( *this )
194 0 : , maTreeEditListeners( *this )
195 : {
196 0 : }
197 :
198 0 : OUString UnoTreeControl::GetComponentServiceName()
199 : {
200 0 : return OUString("Tree");
201 : }
202 :
203 :
204 : // ::com::sun::star::view::XSelectionSupplier
205 :
206 :
207 0 : sal_Bool SAL_CALL UnoTreeControl::select( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException, std::exception)
208 : {
209 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->select( rSelection );
210 : }
211 :
212 :
213 :
214 0 : Any SAL_CALL UnoTreeControl::getSelection() throw (RuntimeException, std::exception)
215 : {
216 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getSelection();
217 : }
218 :
219 :
220 :
221 0 : void SAL_CALL UnoTreeControl::addSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException, std::exception)
222 : {
223 0 : maSelectionListeners.addInterface( xListener );
224 0 : if( getPeer().is() && (maSelectionListeners.getLength() == 1) )
225 : {
226 : // maSelectionListeners acts as a proxy,
227 : // add it to the peer if this is the first listener added to that proxy
228 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
229 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addSelectionChangeListener(&maSelectionListeners);
230 : }
231 0 : }
232 :
233 :
234 :
235 0 : void SAL_CALL UnoTreeControl::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException, std::exception)
236 : {
237 0 : if( getPeer().is() && (maSelectionListeners.getLength() == 1) )
238 : {
239 : // maSelectionListeners acts as a proxy,
240 : // remove it from the peer if this is the last listener removed from that proxy
241 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
242 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeSelectionChangeListener(&maSelectionListeners);
243 : }
244 0 : maSelectionListeners.removeInterface( xListener );
245 0 : }
246 :
247 :
248 : // ::com::sun::star::view::XMultiSelectionSupplier
249 :
250 :
251 0 : sal_Bool SAL_CALL UnoTreeControl::addSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException, std::exception)
252 : {
253 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->addSelection(rSelection);
254 : }
255 :
256 :
257 :
258 0 : void SAL_CALL UnoTreeControl::removeSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException, std::exception)
259 : {
260 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
261 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeSelection(rSelection);
262 0 : }
263 :
264 :
265 :
266 0 : void SAL_CALL UnoTreeControl::clearSelection() throw (RuntimeException, std::exception)
267 : {
268 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
269 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->clearSelection();
270 0 : }
271 :
272 :
273 :
274 0 : sal_Int32 SAL_CALL UnoTreeControl::getSelectionCount() throw (RuntimeException, std::exception)
275 : {
276 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getSelectionCount();
277 : }
278 :
279 :
280 :
281 0 : Reference< XEnumeration > SAL_CALL UnoTreeControl::createSelectionEnumeration() throw (RuntimeException, std::exception)
282 : {
283 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->createSelectionEnumeration();
284 : }
285 :
286 :
287 :
288 0 : Reference< XEnumeration > SAL_CALL UnoTreeControl::createReverseSelectionEnumeration() throw (RuntimeException, std::exception)
289 : {
290 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->createReverseSelectionEnumeration();
291 : }
292 :
293 :
294 : // XTreeControl
295 :
296 :
297 0 : OUString SAL_CALL UnoTreeControl::getDefaultExpandedGraphicURL() throw (RuntimeException, std::exception)
298 : {
299 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getDefaultExpandedGraphicURL();
300 : }
301 :
302 :
303 :
304 0 : void SAL_CALL UnoTreeControl::setDefaultExpandedGraphicURL( const OUString& _defaultexpansiongraphicurl ) throw (RuntimeException, std::exception)
305 : {
306 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
307 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->setDefaultExpandedGraphicURL(_defaultexpansiongraphicurl);
308 0 : }
309 :
310 :
311 :
312 0 : OUString SAL_CALL UnoTreeControl::getDefaultCollapsedGraphicURL() throw (RuntimeException, std::exception)
313 : {
314 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getDefaultCollapsedGraphicURL();
315 : }
316 :
317 :
318 :
319 0 : void SAL_CALL UnoTreeControl::setDefaultCollapsedGraphicURL( const OUString& _defaultcollapsedgraphicurl ) throw (RuntimeException, std::exception)
320 : {
321 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
322 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->setDefaultCollapsedGraphicURL(_defaultcollapsedgraphicurl);
323 0 : }
324 :
325 :
326 :
327 0 : sal_Bool SAL_CALL UnoTreeControl::isNodeExpanded( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException, std::exception)
328 : {
329 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeExpanded(xNode);
330 : }
331 :
332 :
333 :
334 0 : sal_Bool SAL_CALL UnoTreeControl::isNodeCollapsed( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException, std::exception)
335 : {
336 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeCollapsed(xNode);
337 : }
338 :
339 :
340 :
341 0 : void SAL_CALL UnoTreeControl::makeNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException, std::exception)
342 : {
343 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
344 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->makeNodeVisible(xNode);
345 0 : }
346 :
347 :
348 :
349 0 : sal_Bool SAL_CALL UnoTreeControl::isNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException, std::exception)
350 : {
351 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeVisible(xNode);
352 : }
353 :
354 :
355 :
356 0 : void SAL_CALL UnoTreeControl::expandNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException, std::exception)
357 : {
358 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
359 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->expandNode(xNode);
360 0 : }
361 :
362 :
363 :
364 0 : void SAL_CALL UnoTreeControl::collapseNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException, std::exception)
365 : {
366 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
367 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->collapseNode(xNode);
368 0 : }
369 :
370 :
371 :
372 0 : void SAL_CALL UnoTreeControl::addTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException, std::exception)
373 : {
374 0 : maTreeExpansionListeners.addInterface( xListener );
375 0 : if( getPeer().is() && (maTreeExpansionListeners.getLength() == 1) )
376 : {
377 : // maSelectionListeners acts as a proxy,
378 : // add it to the peer if this is the first listener added to that proxy
379 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
380 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addTreeExpansionListener(&maTreeExpansionListeners);
381 : }
382 0 : }
383 :
384 :
385 :
386 0 : void SAL_CALL UnoTreeControl::removeTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException, std::exception)
387 : {
388 0 : if( getPeer().is() && (maTreeExpansionListeners.getLength() == 1) )
389 : {
390 : // maSelectionListeners acts as a proxy,
391 : // remove it from the peer if this is the last listener removed from that proxy
392 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
393 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeTreeExpansionListener(&maTreeExpansionListeners);
394 : }
395 0 : maTreeExpansionListeners.removeInterface( xListener );
396 0 : }
397 :
398 :
399 :
400 0 : Reference< XTreeNode > SAL_CALL UnoTreeControl::getNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException, std::exception)
401 : {
402 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getNodeForLocation(x,y);
403 : }
404 :
405 :
406 :
407 0 : Reference< XTreeNode > SAL_CALL UnoTreeControl::getClosestNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException, std::exception)
408 : {
409 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getClosestNodeForLocation(x,y);
410 : }
411 :
412 :
413 :
414 0 : awt::Rectangle SAL_CALL UnoTreeControl::getNodeRect( const Reference< XTreeNode >& Node ) throw (IllegalArgumentException, RuntimeException, std::exception)
415 : {
416 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getNodeRect( Node );
417 : }
418 :
419 :
420 :
421 0 : sal_Bool SAL_CALL UnoTreeControl::isEditing( ) throw (RuntimeException, std::exception)
422 : {
423 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isEditing();
424 : }
425 :
426 :
427 :
428 0 : sal_Bool SAL_CALL UnoTreeControl::stopEditing() throw (RuntimeException, std::exception)
429 : {
430 0 : return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->stopEditing();
431 : }
432 :
433 :
434 :
435 0 : void SAL_CALL UnoTreeControl::cancelEditing() throw (RuntimeException, std::exception)
436 : {
437 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
438 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->cancelEditing();
439 0 : }
440 :
441 :
442 :
443 0 : void SAL_CALL UnoTreeControl::startEditingAtNode( const Reference< XTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException, std::exception)
444 : {
445 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
446 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->startEditingAtNode(xNode);
447 0 : }
448 :
449 :
450 :
451 0 : void SAL_CALL UnoTreeControl::addTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException, std::exception)
452 : {
453 0 : maTreeEditListeners.addInterface( xListener );
454 0 : if( getPeer().is() && (maTreeEditListeners.getLength() == 1) )
455 : {
456 : // maSelectionListeners acts as a proxy,
457 : // add it to the peer if this is the first listener added to that proxy
458 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
459 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addTreeEditListener(&maTreeEditListeners);
460 : }
461 0 : }
462 :
463 :
464 :
465 0 : void SAL_CALL UnoTreeControl::removeTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException, std::exception)
466 : {
467 0 : if( getPeer().is() && (maTreeEditListeners.getLength() == 1) )
468 : {
469 : // maSelectionListeners acts as a proxy,
470 : // remove it from the peer if this is the last listener removed from that proxy
471 0 : Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer());
472 0 : Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeTreeEditListener(&maTreeEditListeners);
473 : }
474 0 : maTreeEditListeners.removeInterface( xListener );
475 0 : }
476 :
477 :
478 : // XComponent
479 :
480 :
481 0 : void SAL_CALL UnoTreeControl::dispose( ) throw(RuntimeException, std::exception)
482 : {
483 0 : lang::EventObject aEvt;
484 0 : aEvt.Source = static_cast< ::cppu::OWeakObject* >(this);
485 0 : maSelectionListeners.disposeAndClear( aEvt );
486 0 : maTreeExpansionListeners.disposeAndClear( aEvt );
487 0 : UnoControl::dispose();
488 0 : }
489 :
490 0 : void UnoTreeControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException, std::exception)
491 : {
492 0 : UnoControlBase::createPeer( rxToolkit, rParentPeer );
493 :
494 0 : Reference< XTreeControl > xTree( getPeer(), UNO_QUERY_THROW );
495 0 : if( maSelectionListeners.getLength() )
496 0 : xTree->addSelectionChangeListener( &maSelectionListeners );
497 0 : if( maTreeExpansionListeners.getLength() )
498 0 : xTree->addTreeExpansionListener( &maTreeExpansionListeners );
499 0 : }
500 :
501 : }
502 :
503 0 : void SAL_CALL TreeEditListenerMultiplexer::nodeEditing( const Reference< XTreeNode >& Node ) throw (RuntimeException, ::com::sun::star::util::VetoException, std::exception)
504 : {
505 0 : ::cppu::OInterfaceIteratorHelper aIt( *this );
506 0 : while( aIt.hasMoreElements() )
507 : {
508 0 : Reference< XTreeEditListener > xListener(static_cast< XTreeEditListener* >( aIt.next() ) );
509 : try
510 : {
511 0 : xListener->nodeEditing( Node );
512 : }
513 0 : catch( const DisposedException& e )
514 : {
515 : OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" );
516 0 : if ( e.Context == xListener || !e.Context.is() )
517 0 : aIt.remove();
518 : }
519 0 : catch( const RuntimeException& e )
520 : {
521 : (void)e;
522 : DISPLAY_EXCEPTION( TreeEditListenerMultiplexer, nodeEditing, e )
523 : }
524 0 : }
525 0 : }
526 :
527 0 : void SAL_CALL TreeEditListenerMultiplexer::nodeEdited( const Reference< XTreeNode >& Node, const OUString& NewText ) throw (RuntimeException, std::exception)
528 : {
529 0 : ::cppu::OInterfaceIteratorHelper aIt( *this );
530 0 : while( aIt.hasMoreElements() )
531 : {
532 0 : Reference< XTreeEditListener > xListener( static_cast< XTreeEditListener* >( aIt.next() ) );
533 : try
534 : {
535 0 : xListener->nodeEdited( Node, NewText );
536 : }
537 0 : catch( const DisposedException& e )
538 : {
539 : OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" );
540 0 : if ( e.Context == xListener || !e.Context.is() )
541 0 : aIt.remove();
542 : }
543 0 : catch( const RuntimeException& e )
544 : {
545 : (void)e;
546 : DISPLAY_EXCEPTION( TreeEditListenerMultiplexer, nodeEdited, e )
547 : }
548 0 : }
549 0 : }
550 :
551 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
552 0 : stardiv_Toolkit_TreeControlModel_get_implementation(
553 : css::uno::XComponentContext *context,
554 : css::uno::Sequence<css::uno::Any> const &)
555 : {
556 0 : return cppu::acquire(new toolkit::UnoTreeModel(context));
557 : }
558 :
559 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
560 0 : stardiv_Toolkit_TreeControl_get_implementation(
561 : css::uno::XComponentContext *,
562 : css::uno::Sequence<css::uno::Any> const &)
563 : {
564 0 : return cppu::acquire(new UnoTreeControl());
565 : }
566 :
567 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|