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/XVclContainerPeer.hpp>
30 : : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
31 : :
32 : : #include <cppuhelper/typeprovider.hxx>
33 : : #include <cppuhelper/implbase1.hxx>
34 : : #include <rtl/memory.h>
35 : : #include <rtl/uuid.h>
36 : :
37 : : #include <toolkit/controls/unocontrolcontainer.hxx>
38 : : #include <toolkit/helper/property.hxx>
39 : : #include <toolkit/helper/servicenames.hxx>
40 : : #include <comphelper/sequence.hxx>
41 : :
42 : : #include <tools/debug.hxx>
43 : : #include <vcl/svapp.hxx>
44 : : #include <vcl/window.hxx>
45 : :
46 : : #include <limits>
47 : : #include <map>
48 : : #include <boost/shared_ptr.hpp>
49 : :
50 : : using namespace ::com::sun::star;
51 : :
52 : : extern WorkWindow* lcl_GetDefaultWindow();
53 : :
54 : : // ----------------------------------------------------
55 : : // class UnoControlHolder
56 : : // ----------------------------------------------------
57 : 370 : struct UnoControlHolder
58 : : {
59 : : uno::Reference< awt::XControl > mxControl;
60 : : ::rtl::OUString msName;
61 : :
62 : : public:
63 : 385 : UnoControlHolder( const ::rtl::OUString& rName, const uno::Reference< awt::XControl > & rControl )
64 : : : mxControl( rControl ),
65 : 385 : msName( rName )
66 : : {
67 : 385 : }
68 : :
69 : 8 : inline const ::rtl::OUString& getName() const { return msName; }
70 : 550 : inline const uno::Reference< awt::XControl >& getControl() const { return mxControl; }
71 : : };
72 : :
73 : : class UnoControlHolderList
74 : : {
75 : : public:
76 : : typedef sal_Int32 ControlIdentifier;
77 : : private:
78 : : typedef ::boost::shared_ptr< UnoControlHolder > ControlInfo;
79 : : typedef ::std::map< ControlIdentifier, ControlInfo > ControlMap;
80 : :
81 : : private:
82 : : ControlMap maControls;
83 : :
84 : : public:
85 : : UnoControlHolderList();
86 : : ~UnoControlHolderList();
87 : :
88 : : /** adds a control with the given name to the list
89 : : @param _rxControl
90 : : the control to add. Must not be <NULL/>
91 : : @param _pBName
92 : : the name of the control, or <NULL/> if an automatic name should be generated
93 : : @return
94 : : the identifier of the newly added control
95 : : */
96 : : ControlIdentifier addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName );
97 : :
98 : : /** returns the number of controls in the list
99 : : */
100 : : inline size_t size() const { return maControls.size(); }
101 : :
102 : : /** determines whether or not the list is empty
103 : : */
104 : 0 : inline bool empty() const { return maControls.empty(); }
105 : :
106 : : /** retrieves all controls currently in the list
107 : : @return
108 : : the number of controls in the list
109 : : */
110 : : size_t getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const;
111 : :
112 : : /** retrieves all identifiers of all controls currently in the list
113 : : @return
114 : : the number of controls in the list
115 : : */
116 : : size_t getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const;
117 : :
118 : : /** returns the first control which is registered under the given name
119 : : */
120 : : uno::Reference< awt::XControl >
121 : : getControlForName( const ::rtl::OUString& _rName ) const;
122 : :
123 : : /** returns the identifier which a control is registered for, or -1 if the control
124 : : isn't registered
125 : : */
126 : : ControlIdentifier
127 : : getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl );
128 : :
129 : : /** retrieves the control for a given id
130 : : @param _nIdentifier
131 : : the identifier for the control
132 : : @param _out_rxControl
133 : : takes the XControl upon successful return
134 : : @return
135 : : <TRUE/> if and only if a control with the given id is part of the list
136 : : */
137 : : bool getControlForIdentifier( ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const;
138 : :
139 : : /** removes a control from the list, given by id
140 : : @param _nId
141 : : The identifier of the control to remove.
142 : : */
143 : : void removeControlById( ControlIdentifier _nId );
144 : :
145 : : /** replaces a control from the list with another one
146 : : @param _nId
147 : : The identifier of the control to replace
148 : : @param _rxNewControl
149 : : the new control to put into the list
150 : : */
151 : : void replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl );
152 : :
153 : : private:
154 : : /** adds a control
155 : : @param _rxControl
156 : : the control to add to the container
157 : : @param _pName
158 : : pointer to the name of the control. Might be <NULL/>, in this case, a name is generated.
159 : : @return
160 : : the identifier of the newly inserted control
161 : : */
162 : : ControlIdentifier impl_addControl(
163 : : const uno::Reference< awt::XControl >& _rxControl,
164 : : const ::rtl::OUString* _pName
165 : : );
166 : :
167 : : /** finds a free identifier
168 : : @throw uno::RuntimeException
169 : : if no free identifier can be found
170 : : */
171 : : ControlIdentifier impl_getFreeIdentifier_throw();
172 : :
173 : : /** finds a free name
174 : : @throw uno::RuntimeException
175 : : if no free name can be found
176 : : */
177 : : ::rtl::OUString impl_getFreeName_throw();
178 : : };
179 : :
180 : : //------------------------------------------------------------------------
181 : 1313 : UnoControlHolderList::UnoControlHolderList()
182 : : {
183 : 1313 : }
184 : :
185 : : //------------------------------------------------------------------------
186 : 1294 : UnoControlHolderList::~UnoControlHolderList()
187 : : {
188 : 1294 : }
189 : :
190 : : //------------------------------------------------------------------------
191 : 385 : UnoControlHolderList::ControlIdentifier UnoControlHolderList::addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName )
192 : : {
193 : 385 : return impl_addControl( _rxControl, _pName );
194 : : }
195 : :
196 : : //------------------------------------------------------------------------
197 : 710 : size_t UnoControlHolderList::getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const
198 : : {
199 : 710 : _out_rControls.realloc( maControls.size() );
200 : 710 : uno::Reference< awt::XControl >* pControls = _out_rControls.getArray();
201 [ + + ]: 1608 : for ( ControlMap::const_iterator loop = maControls.begin();
202 : 804 : loop != maControls.end();
203 : : ++loop, ++pControls
204 : : )
205 [ + - ]: 94 : *pControls = loop->second->getControl();
206 : 710 : return maControls.size();
207 : : }
208 : :
209 : : //------------------------------------------------------------------------
210 : 0 : size_t UnoControlHolderList::getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const
211 : : {
212 : 0 : _out_rIdentifiers.realloc( maControls.size() );
213 : 0 : sal_Int32* pIndentifiers = _out_rIdentifiers.getArray();
214 [ # # ]: 0 : for ( ControlMap::const_iterator loop = maControls.begin();
215 : 0 : loop != maControls.end();
216 : : ++loop, ++pIndentifiers
217 : : )
218 : 0 : *pIndentifiers = loop->first;
219 : 0 : return maControls.size();
220 : : }
221 : :
222 : : //------------------------------------------------------------------------
223 : 8 : uno::Reference< awt::XControl > UnoControlHolderList::getControlForName( const ::rtl::OUString& _rName ) const
224 : : {
225 [ + + ]: 20 : for ( ControlMap::const_iterator loop = maControls.begin();
226 : 10 : loop != maControls.end();
227 : : ++loop
228 : : )
229 [ + + ]: 8 : if ( loop->second->getName() == _rName )
230 : 6 : return loop->second->getControl();
231 : 8 : return uno::Reference< awt::XControl >();
232 : : }
233 : :
234 : : //------------------------------------------------------------------------
235 : 346 : UnoControlHolderList::ControlIdentifier UnoControlHolderList::getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl )
236 : : {
237 [ + + ]: 904 : for ( ControlMap::iterator loop = maControls.begin();
238 : 452 : loop != maControls.end();
239 : : ++loop
240 : : )
241 : : {
242 [ + - ][ + - ]: 450 : if ( loop->second->getControl().get() == _rxControl.get() )
[ + + ]
243 : 344 : return loop->first;
244 : : }
245 : 346 : return -1;
246 : : }
247 : :
248 : : //------------------------------------------------------------------------
249 : 0 : bool UnoControlHolderList::getControlForIdentifier( UnoControlHolderList::ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const
250 : : {
251 [ # # ]: 0 : ControlMap::const_iterator pos = maControls.find( _nIdentifier );
252 [ # # ]: 0 : if ( pos == maControls.end() )
253 : 0 : return false;
254 [ # # ]: 0 : _out_rxControl = pos->second->getControl();
255 : 0 : return true;
256 : : }
257 : :
258 : : //------------------------------------------------------------------------
259 : 344 : void UnoControlHolderList::removeControlById( UnoControlHolderList::ControlIdentifier _nId )
260 : : {
261 [ + - ]: 344 : ControlMap::iterator pos = maControls.find( _nId );
262 : : DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::removeControlById: invalid id!" );
263 [ + - ]: 344 : if ( pos == maControls.end() )
264 : 344 : return;
265 : :
266 [ + - ]: 344 : maControls.erase( pos );
267 : : }
268 : :
269 : : //------------------------------------------------------------------------
270 : 0 : void UnoControlHolderList::replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl )
271 : : {
272 : : DBG_ASSERT( _rxNewControl.is(), "UnoControlHolderList::replaceControlById: invalid new control!" );
273 : :
274 [ # # ]: 0 : ControlMap::iterator pos = maControls.find( _nId );
275 : : DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::replaceControlById: invalid id!" );
276 [ # # ]: 0 : if ( pos == maControls.end() )
277 : 0 : return;
278 : :
279 [ # # ][ # # ]: 0 : pos->second.reset( new UnoControlHolder( pos->second->getName(), _rxNewControl ) );
[ # # ]
280 : : }
281 : :
282 : : //------------------------------------------------------------------------
283 : 385 : UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName )
284 : : {
285 : : DBG_ASSERT( _rxControl.is(), "UnoControlHolderList::impl_addControl: invalid control!" );
286 : :
287 [ + - ][ # # ]: 385 : ::rtl::OUString sName = _pName ? *_pName : impl_getFreeName_throw();
288 [ + - ]: 385 : sal_Int32 nId = impl_getFreeIdentifier_throw();
289 : :
290 [ + - ][ + - ]: 385 : maControls[ nId ] = ControlInfo( new UnoControlHolder( sName, _rxControl ) );
[ + - ][ + - ]
[ + - ][ + - ]
291 : 385 : return nId;
292 : : }
293 : :
294 : : //------------------------------------------------------------------------
295 : 385 : UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_getFreeIdentifier_throw()
296 : : {
297 [ + - ]: 529 : for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
298 : : {
299 [ + - ]: 529 : ControlMap::const_iterator existent = maControls.find( candidateId );
300 [ + + ]: 529 : if ( existent == maControls.end() )
301 : 385 : return candidateId;
302 : : }
303 [ # # ][ # # ]: 0 : throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "out of identifiers" ) ), NULL );
[ # # ]
304 : : }
305 : :
306 : : //------------------------------------------------------------------------
307 : 0 : ::rtl::OUString UnoControlHolderList::impl_getFreeName_throw()
308 : : {
309 [ # # ]: 0 : ::rtl::OUString name( RTL_CONSTASCII_USTRINGPARAM( "control_" ) );
310 [ # # ]: 0 : for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
311 : : {
312 : 0 : ::rtl::OUString candidateName( name + ::rtl::OUString::valueOf( candidateId ) );
313 : 0 : ControlMap::const_iterator loop = maControls.begin();
314 [ # # ]: 0 : for ( ; loop != maControls.end(); ++loop )
315 : : {
316 [ # # ]: 0 : if ( loop->second->getName() == candidateName )
317 : 0 : break;
318 : : }
319 [ # # ]: 0 : if ( loop == maControls.end() )
320 : 0 : return candidateName;
321 [ # # ]: 0 : }
322 [ # # ][ # # ]: 0 : throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "out of identifiers" ) ), NULL );
[ # # ]
323 : : }
324 : : // ----------------------------------------------------
325 : : // Function to set the controls' visibility according
326 : : // to the dialog's "Step" property
327 : : // ----------------------------------------------------
328 : 2 : void implUpdateVisibility
329 : : (
330 : : sal_Int32 nDialogStep,
331 : : uno::Reference< awt::XControlContainer > xControlContainer
332 : : )
333 : : {
334 : : uno::Sequence< uno::Reference< awt::XControl > >
335 [ + - ][ + - ]: 2 : aCtrls = xControlContainer->getControls();
336 : 2 : const uno::Reference< awt::XControl >* pCtrls = aCtrls.getConstArray();
337 : 2 : sal_uInt32 nCtrls = aCtrls.getLength();
338 : 2 : sal_Bool bCompleteVisible = (nDialogStep == 0);
339 [ + + ]: 4 : for( sal_uInt32 n = 0; n < nCtrls; n++ )
340 : : {
341 : 2 : uno::Reference< awt::XControl > xControl = pCtrls[ n ];
342 : :
343 : 2 : sal_Bool bVisible = bCompleteVisible;
344 [ - + ]: 2 : if( !bVisible )
345 : : {
346 [ # # ][ # # ]: 0 : uno::Reference< awt::XControlModel > xModel( xControl->getModel() );
347 : : uno::Reference< beans::XPropertySet > xPSet
348 [ # # ]: 0 : ( xModel, uno::UNO_QUERY );
349 : : uno::Reference< beans::XPropertySetInfo >
350 [ # # ][ # # ]: 0 : xInfo = xPSet->getPropertySetInfo();
351 [ # # ]: 0 : ::rtl::OUString aPropName(RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
352 : 0 : sal_Int32 nControlStep = 0;
353 [ # # ][ # # ]: 0 : if ( xInfo->hasPropertyByName( aPropName ) )
[ # # ]
354 : : {
355 [ # # ][ # # ]: 0 : uno::Any aVal = xPSet->getPropertyValue( aPropName );
356 : 0 : aVal >>= nControlStep;
357 : : }
358 [ # # ][ # # ]: 0 : bVisible = (nControlStep == 0) || (nControlStep == nDialogStep);
359 : : }
360 : :
361 : : uno::Reference< awt::XWindow> xWindow
362 [ + - ]: 2 : ( xControl, uno::UNO_QUERY );
363 [ + - ]: 2 : if( xWindow.is() )
364 [ + - ][ + - ]: 2 : xWindow->setVisible( bVisible );
365 [ + - ]: 4 : }
366 : 2 : }
367 : :
368 : :
369 : : // ----------------------------------------------------
370 : : // class DialogStepChangedListener
371 : : // ----------------------------------------------------
372 : : typedef ::cppu::WeakImplHelper1< beans::XPropertyChangeListener > PropertyChangeListenerHelper;
373 : :
374 [ # # ]: 0 : class DialogStepChangedListener: public PropertyChangeListenerHelper
375 : : {
376 : : private:
377 : : uno::Reference< awt::XControlContainer > mxControlContainer;
378 : :
379 : : public:
380 : 2 : DialogStepChangedListener( uno::Reference< awt::XControlContainer > xControlContainer )
381 : 2 : : mxControlContainer( xControlContainer ) {}
382 : :
383 : : // XEventListener
384 : : virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw( uno::RuntimeException);
385 : :
386 : : // XPropertyChangeListener
387 : : virtual void SAL_CALL propertyChange( const beans::PropertyChangeEvent& evt ) throw( uno::RuntimeException);
388 : :
389 : : };
390 : :
391 : 0 : void SAL_CALL DialogStepChangedListener::disposing( const lang::EventObject& /*_rSource*/)
392 : : throw( uno::RuntimeException)
393 : : {
394 : 0 : mxControlContainer.clear();
395 : 0 : }
396 : :
397 : 0 : void SAL_CALL DialogStepChangedListener::propertyChange( const beans::PropertyChangeEvent& evt )
398 : : throw( uno::RuntimeException)
399 : : {
400 : : // evt.PropertyName HAS to be "Step" because we only use the listener for that
401 : 0 : sal_Int32 nDialogStep = 0;
402 : 0 : evt.NewValue >>= nDialogStep;
403 [ # # ]: 0 : implUpdateVisibility( nDialogStep, mxControlContainer );
404 : 0 : }
405 : :
406 : : // ----------------------------------------------------
407 : : // class UnoControlContainer
408 : : // ----------------------------------------------------
409 : 27 : UnoControlContainer::UnoControlContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory )
410 : : :UnoControlContainer_Base( i_factory )
411 [ + - ][ + - ]: 27 : ,maCListeners( *this )
412 : : {
413 [ + - ][ + - ]: 27 : mpControls = new UnoControlHolderList;
414 : 27 : }
415 : :
416 : 638 : UnoControlContainer::UnoControlContainer( const uno::Reference< lang::XMultiServiceFactory >& i_factory, const uno::Reference< awt::XWindowPeer >& xP )
417 : : :UnoControlContainer_Base( i_factory )
418 [ + - ][ + - ]: 638 : ,maCListeners( *this )
419 : : {
420 [ + - ]: 638 : setPeer( xP );
421 : 638 : mbDisposePeer = sal_False;
422 [ + - ][ + - ]: 638 : mpControls = new UnoControlHolderList;
423 : 638 : }
424 : :
425 [ + - ][ + - ]: 646 : UnoControlContainer::~UnoControlContainer()
426 : : {
427 [ + - ]: 646 : DELETEZ( mpControls );
428 [ - + ]: 1292 : }
429 : :
430 : 342 : void UnoControlContainer::ImplActivateTabControllers()
431 : : {
432 : 342 : sal_uInt32 nCount = maTabControllers.getLength();
433 [ + + ]: 344 : for ( sal_uInt32 n = 0; n < nCount; n++ )
434 : : {
435 [ + - ]: 2 : maTabControllers.getArray()[n]->setContainer( this );
436 : 2 : maTabControllers.getArray()[n]->activateTabOrder();
437 : : }
438 : 342 : }
439 : :
440 : : // lang::XComponent
441 : 648 : void UnoControlContainer::dispose( ) throw(uno::RuntimeException)
442 : : {
443 [ + - ]: 648 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
444 : :
445 [ + - ]: 648 : lang::EventObject aDisposeEvent;
446 [ + - ]: 648 : aDisposeEvent.Source = static_cast< uno::XAggregation* >( this );
447 : :
448 : : // Notify listeners about disposal of this Container (This is much faster if they
449 : : // listen on the controls and the container).
450 [ + - ]: 648 : maDisposeListeners.disposeAndClear( aDisposeEvent );
451 [ + - ]: 648 : maCListeners.disposeAndClear( aDisposeEvent );
452 : :
453 : :
454 [ + - ]: 648 : uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
455 [ + - ]: 648 : uno::Reference< awt::XControl >* pCtrls = aCtrls.getArray();
456 : 648 : uno::Reference< awt::XControl >* pCtrlsEnd = pCtrls + aCtrls.getLength();
457 : :
458 [ + + ]: 674 : for( ; pCtrls < pCtrlsEnd; ++pCtrls )
459 : : {
460 [ + - ]: 26 : removingControl( *pCtrls );
461 : : // Delete control
462 [ + - ][ + - ]: 26 : (*pCtrls)->dispose();
463 : : }
464 : :
465 : :
466 : : // Delete all structures
467 [ + - ]: 648 : DELETEZ( mpControls );
468 [ + - ][ + - ]: 648 : mpControls = new UnoControlHolderList;
469 : :
470 [ + - ][ + - ]: 648 : UnoControlBase::dispose();
[ + - ][ + - ]
471 : 648 : }
472 : :
473 : : // lang::XEventListener
474 : 328 : void UnoControlContainer::disposing( const lang::EventObject& _rEvt ) throw(uno::RuntimeException)
475 : : {
476 [ + - ]: 328 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
477 : :
478 [ + - ]: 328 : uno::Reference< awt::XControl > xControl( _rEvt.Source, uno::UNO_QUERY );
479 [ + + ]: 328 : if ( xControl.is() )
480 [ + - ]: 324 : removeControl( xControl );
481 : :
482 [ + - ][ + - ]: 328 : UnoControlBase::disposing( _rEvt );
483 : 328 : }
484 : :
485 : : // container::XContainer
486 : 462 : void UnoControlContainer::addContainerListener( const uno::Reference< container::XContainerListener >& rxListener ) throw(uno::RuntimeException)
487 : : {
488 [ + - ]: 462 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
489 : :
490 [ + - ][ + - ]: 462 : maCListeners.addInterface( rxListener );
491 : 462 : }
492 : :
493 : 445 : void UnoControlContainer::removeContainerListener( const uno::Reference< container::XContainerListener >& rxListener ) throw(uno::RuntimeException)
494 : : {
495 [ + - ]: 445 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
496 : :
497 [ + - ][ + - ]: 445 : maCListeners.removeInterface( rxListener );
498 : 445 : }
499 : :
500 : :
501 : 0 : ::sal_Int32 SAL_CALL UnoControlContainer::insert( const uno::Any& _rElement ) throw (lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
502 : : {
503 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
504 : :
505 : 0 : uno::Reference< awt::XControl > xControl;
506 [ # # ][ # # ]: 0 : if ( !( _rElement >>= xControl ) || !xControl.is() )
[ # # ][ # # ]
507 : : throw lang::IllegalArgumentException(
508 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Elements must support the XControl interface." ) ),
509 : : *this,
510 : : 1
511 [ # # ][ # # ]: 0 : );
[ # # ]
512 : :
513 [ # # ][ # # ]: 0 : return impl_addControl( xControl, NULL );
514 : : }
515 : :
516 : 0 : void SAL_CALL UnoControlContainer::removeByIdentifier( ::sal_Int32 _nIdentifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
517 : : {
518 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
519 : :
520 : 0 : uno::Reference< awt::XControl > xControl;
521 [ # # ][ # # ]: 0 : if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
522 : : throw container::NoSuchElementException(
523 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "There is no element with the given identifier." ) ),
524 : : *this
525 [ # # ][ # # ]: 0 : );
[ # # ]
526 : :
527 [ # # ][ # # ]: 0 : impl_removeControl( _nIdentifier, xControl, NULL );
528 : 0 : }
529 : :
530 : 0 : void SAL_CALL UnoControlContainer::replaceByIdentifer( ::sal_Int32 _nIdentifier, const uno::Any& _rElement ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
531 : : {
532 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
533 : :
534 : 0 : uno::Reference< awt::XControl > xExistentControl;
535 [ # # ][ # # ]: 0 : if ( !mpControls->getControlForIdentifier( _nIdentifier, xExistentControl ) )
536 : : throw container::NoSuchElementException(
537 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "There is no element with the given identifier." ) ),
538 : : *this
539 [ # # ][ # # ]: 0 : );
[ # # ]
540 : :
541 : 0 : uno::Reference< awt::XControl > xNewControl;
542 [ # # ][ # # ]: 0 : if ( !( _rElement >>= xNewControl ) )
543 : : throw lang::IllegalArgumentException(
544 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Elements must support the XControl interface." ) ),
545 : : *this,
546 : : 1
547 [ # # ][ # # ]: 0 : );
[ # # ]
548 : :
549 [ # # ]: 0 : removingControl( xExistentControl );
550 : :
551 [ # # ]: 0 : mpControls->replaceControlById( _nIdentifier, xNewControl );
552 : :
553 [ # # ]: 0 : addingControl( xNewControl );
554 : :
555 [ # # ]: 0 : impl_createControlPeerIfNecessary( xNewControl );
556 : :
557 [ # # ][ # # ]: 0 : if ( maCListeners.getLength() )
558 : : {
559 [ # # ]: 0 : container::ContainerEvent aEvent;
560 [ # # ][ # # ]: 0 : aEvent.Source = *this;
561 [ # # ]: 0 : aEvent.Accessor <<= _nIdentifier;
562 [ # # ]: 0 : aEvent.Element <<= xNewControl;
563 [ # # ]: 0 : aEvent.ReplacedElement <<= xExistentControl;
564 [ # # ][ # # ]: 0 : maCListeners.elementReplaced( aEvent );
565 [ # # ]: 0 : }
566 : 0 : }
567 : :
568 : 0 : uno::Any SAL_CALL UnoControlContainer::getByIdentifier( ::sal_Int32 _nIdentifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
569 : : {
570 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
571 : :
572 : 0 : uno::Reference< awt::XControl > xControl;
573 [ # # ][ # # ]: 0 : if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
574 [ # # ]: 0 : throw container::NoSuchElementException();
575 [ # # ][ # # ]: 0 : return uno::makeAny( xControl );
576 : : }
577 : :
578 : 0 : uno::Sequence< ::sal_Int32 > SAL_CALL UnoControlContainer::getIdentifiers( ) throw (uno::RuntimeException)
579 : : {
580 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
581 : :
582 [ # # ]: 0 : uno::Sequence< ::sal_Int32 > aIdentifiers;
583 [ # # ]: 0 : mpControls->getIdentifiers( aIdentifiers );
584 [ # # ]: 0 : return aIdentifiers;
585 : : }
586 : :
587 : : // container::XElementAccess
588 : 0 : uno::Type SAL_CALL UnoControlContainer::getElementType( ) throw (uno::RuntimeException)
589 : : {
590 : 0 : return awt::XControlModel::static_type();
591 : : }
592 : :
593 : 0 : ::sal_Bool SAL_CALL UnoControlContainer::hasElements( ) throw (uno::RuntimeException)
594 : : {
595 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
596 [ # # ]: 0 : return !mpControls->empty();
597 : : }
598 : :
599 : : // awt::XControlContainer
600 : 2 : void UnoControlContainer::setStatusText( const ::rtl::OUString& rStatusText ) throw(uno::RuntimeException)
601 : : {
602 [ + - ]: 2 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
603 : :
604 : : // Descend the parent hierarchy
605 [ + - ]: 2 : uno::Reference< awt::XControlContainer > xContainer( mxContext, uno::UNO_QUERY );
606 [ - + ]: 2 : if( xContainer.is() )
607 [ # # ][ # # ]: 2 : xContainer->setStatusText( rStatusText );
[ + - ]
608 : 2 : }
609 : :
610 : 710 : uno::Sequence< uno::Reference< awt::XControl > > UnoControlContainer::getControls( ) throw(uno::RuntimeException)
611 : : {
612 [ + - ]: 710 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
613 [ + - ]: 710 : uno::Sequence< uno::Reference< awt::XControl > > aControls;
614 [ + - ]: 710 : mpControls->getControls( aControls );
615 [ + - ]: 710 : return aControls;
616 : : }
617 : :
618 : 8 : uno::Reference< awt::XControl > UnoControlContainer::getControl( const ::rtl::OUString& rName ) throw(uno::RuntimeException)
619 : : {
620 [ + - ]: 8 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
621 [ + - ][ + - ]: 8 : return mpControls->getControlForName( rName );
622 : : }
623 : :
624 : 385 : void UnoControlContainer::addingControl( const uno::Reference< awt::XControl >& _rxControl )
625 : : {
626 [ + - ]: 385 : if ( _rxControl.is() )
627 : : {
628 : 385 : uno::Reference< uno::XInterface > xThis;
629 [ + - ][ + - ]: 385 : OWeakAggObject::queryInterface( ::getCppuType( static_cast< uno::Reference< uno::XInterface >* >( NULL ) ) ) >>= xThis;
[ + - ]
630 : :
631 [ + - ][ + - ]: 385 : _rxControl->setContext( xThis );
632 [ + - ][ + - ]: 385 : _rxControl->addEventListener( this );
[ + - ]
633 : : }
634 : 385 : }
635 : :
636 : 385 : void UnoControlContainer::impl_createControlPeerIfNecessary( const uno::Reference< awt::XControl >& _rxControl )
637 : : {
638 : : OSL_PRECOND( _rxControl.is(), "UnoControlContainer::impl_createControlPeerIfNecessary: invalid control, this will crash!" );
639 : :
640 : : // if the container already has a peer, then also create a peer for the control
641 [ + - ]: 385 : uno::Reference< awt::XWindowPeer > xMyPeer( getPeer() );
642 : :
643 [ + + ]: 385 : if( xMyPeer.is() )
644 : : {
645 [ + - ][ + - ]: 340 : _rxControl->createPeer( NULL, xMyPeer );
[ + - ]
646 [ + - ]: 340 : ImplActivateTabControllers();
647 : 385 : }
648 : :
649 : 385 : }
650 : :
651 : 385 : sal_Int32 UnoControlContainer::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName )
652 : : {
653 [ + - ]: 385 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
654 [ + - ]: 385 : UnoControlHolderList::ControlIdentifier id = mpControls->addControl( _rxControl, _pName );
655 : :
656 [ + - ]: 385 : addingControl( _rxControl );
657 : :
658 [ + - ]: 385 : impl_createControlPeerIfNecessary( _rxControl );
659 : :
660 [ + - ][ + + ]: 385 : if ( maCListeners.getLength() )
661 : : {
662 [ + - ]: 117 : container::ContainerEvent aEvent;
663 [ + - ][ + - ]: 117 : aEvent.Source = *this;
664 [ + - ][ # # ]: 117 : _pName ? ( aEvent.Accessor <<= *_pName ) : ( aEvent.Accessor <<= (sal_Int32)id );
[ - + ][ # # ]
[ + - ]
665 [ + - ]: 117 : aEvent.Element <<= _rxControl;
666 [ + - ][ + - ]: 117 : maCListeners.elementInserted( aEvent );
667 : : }
668 : :
669 [ + - ]: 385 : return id;
670 : : }
671 : :
672 : 387 : void UnoControlContainer::addControl( const ::rtl::OUString& rName, const uno::Reference< awt::XControl >& rControl ) throw(uno::RuntimeException)
673 : : {
674 [ + + ]: 387 : if ( rControl.is() )
675 : 385 : impl_addControl( rControl, &rName );
676 : 387 : }
677 : :
678 : 370 : void UnoControlContainer::removingControl( const uno::Reference< awt::XControl >& _rxControl )
679 : : {
680 [ + - ]: 370 : if ( _rxControl.is() )
681 : : {
682 [ + - ]: 370 : _rxControl->removeEventListener( this );
683 [ + - ]: 370 : _rxControl->setContext( NULL );
684 : : }
685 : 370 : }
686 : :
687 : 344 : void UnoControlContainer::impl_removeControl( sal_Int32 _nId, const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pNameAccessor )
688 : : {
689 : : #ifdef DBG_UTIL
690 : : {
691 : : uno::Reference< awt::XControl > xControl;
692 : : bool bHas = mpControls->getControlForIdentifier( _nId, xControl );
693 : : DBG_ASSERT( bHas && xControl == _rxControl, "UnoControlContainer::impl_removeControl: inconsistency in the parameters!" );
694 : : }
695 : : #endif
696 : 344 : removingControl( _rxControl );
697 : :
698 : 344 : mpControls->removeControlById( _nId );
699 : :
700 [ + + ]: 344 : if ( maCListeners.getLength() )
701 : : {
702 [ + - ]: 102 : container::ContainerEvent aEvent;
703 [ + - ][ + - ]: 102 : aEvent.Source = *this;
704 [ # # ][ + - ]: 102 : _pNameAccessor ? ( aEvent.Accessor <<= *_pNameAccessor ) : ( aEvent.Accessor <<= _nId );
[ - + ]
705 [ + - ]: 102 : aEvent.Element <<= _rxControl;
706 [ + - ][ + - ]: 102 : maCListeners.elementRemoved( aEvent );
707 : : }
708 : 344 : }
709 : :
710 : 346 : void UnoControlContainer::removeControl( const uno::Reference< awt::XControl >& _rxControl ) throw(uno::RuntimeException)
711 : : {
712 [ + - ]: 346 : if ( _rxControl.is() )
713 : : {
714 [ + - ]: 346 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
715 : :
716 [ + - ]: 346 : UnoControlHolderList::ControlIdentifier id = mpControls->getControlIdentifier( _rxControl );
717 [ + + ]: 346 : if ( id != -1 )
718 [ + - ][ + - ]: 346 : impl_removeControl( id, _rxControl, NULL );
719 : : }
720 : 346 : }
721 : :
722 : :
723 : :
724 : : // awt::XUnoControlContainer
725 : 2 : void UnoControlContainer::setTabControllers( const uno::Sequence< uno::Reference< awt::XTabController > >& TabControllers ) throw(uno::RuntimeException)
726 : : {
727 [ + - ]: 2 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
728 : :
729 [ + - ][ + - ]: 2 : maTabControllers = TabControllers;
730 : 2 : }
731 : :
732 : 14 : uno::Sequence< uno::Reference< awt::XTabController > > UnoControlContainer::getTabControllers( ) throw(uno::RuntimeException)
733 : : {
734 [ + - ]: 14 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
735 : :
736 [ + - ][ + - ]: 14 : return maTabControllers;
737 : : }
738 : :
739 : 12 : void UnoControlContainer::addTabController( const uno::Reference< awt::XTabController >& TabController ) throw(uno::RuntimeException)
740 : : {
741 [ + - ]: 12 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
742 : :
743 : 12 : sal_uInt32 nCount = maTabControllers.getLength();
744 [ + - ]: 12 : maTabControllers.realloc( nCount + 1 );
745 [ + - ][ + - ]: 12 : maTabControllers[ nCount ] = TabController;
[ + - ]
746 : 12 : }
747 : :
748 : 8 : void UnoControlContainer::removeTabController( const uno::Reference< awt::XTabController >& TabController ) throw(uno::RuntimeException)
749 : : {
750 [ + - ]: 8 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
751 : :
752 : 8 : sal_uInt32 nCount = maTabControllers.getLength();
753 : 8 : const uno::Reference< awt::XTabController >* pLoop = maTabControllers.getConstArray();
754 [ + + ]: 8 : for ( sal_uInt32 n = 0; n < nCount; ++n, ++pLoop )
755 : : {
756 [ + - ][ + - ]: 6 : if( pLoop->get() == TabController.get() )
[ + - ]
757 : : {
758 [ + - ]: 6 : ::comphelper::removeElementAt( maTabControllers, n );
759 : 6 : break;
760 : : }
761 [ + - ]: 8 : }
762 : 8 : }
763 : :
764 : : // awt::XControl
765 : 638 : void UnoControlContainer::createPeer( const uno::Reference< awt::XToolkit >& rxToolkit, const uno::Reference< awt::XWindowPeer >& rParent ) throw(uno::RuntimeException)
766 : : {
767 [ + - ]: 638 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
768 : :
769 [ + - ][ + + ]: 638 : if( !getPeer().is() )
770 : : {
771 : 2 : sal_Bool bVis = maComponentInfos.bVisible;
772 [ + - ]: 2 : if( bVis )
773 [ + - ]: 2 : UnoControl::setVisible( sal_False );
774 : : // Create a new peer
775 [ + - ]: 2 : UnoControl::createPeer( rxToolkit, rParent );
776 : :
777 : : // Create all children's peers
778 [ + - ]: 2 : if ( !mbCreatingCompatiblePeer )
779 : : {
780 : : // Evaluate "Step" property
781 [ + - ]: 2 : uno::Reference< awt::XControlModel > xModel( getModel() );
782 : : uno::Reference< beans::XPropertySet > xPSet
783 [ + - ]: 2 : ( xModel, uno::UNO_QUERY );
784 : : uno::Reference< beans::XPropertySetInfo >
785 [ + - ][ + - ]: 2 : xInfo = xPSet->getPropertySetInfo();
786 [ + - ]: 2 : ::rtl::OUString aPropName(RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
787 [ + - ][ + - ]: 2 : if ( xInfo->hasPropertyByName( aPropName ) )
[ + - ]
788 : : {
789 [ + - ][ + - ]: 2 : ::com::sun::star::uno::Any aVal = xPSet->getPropertyValue( aPropName );
790 : 2 : sal_Int32 nDialogStep = 0;
791 : 2 : aVal >>= nDialogStep;
792 : : uno::Reference< awt::XControlContainer > xContainer =
793 [ + - ]: 2 : (static_cast< awt::XControlContainer* >(this));
794 [ + - ]: 2 : implUpdateVisibility( nDialogStep, xContainer );
795 : :
796 : : uno::Reference< beans::XPropertyChangeListener > xListener =
797 : : (static_cast< beans::XPropertyChangeListener* >(
798 [ + - ][ + - ]: 2 : new DialogStepChangedListener( xContainer ) ) );
[ + - ]
799 [ + - ][ + - ]: 2 : xPSet->addPropertyChangeListener( aPropName, xListener );
800 : : }
801 : :
802 [ + - ]: 2 : uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
803 : 2 : sal_uInt32 nCtrls = aCtrls.getLength();
804 [ + + ]: 4 : for( sal_uInt32 n = 0; n < nCtrls; n++ )
805 [ + - ][ + - ]: 2 : aCtrls.getArray()[n]->createPeer( rxToolkit, getPeer() );
[ + - ][ + - ]
806 : :
807 [ + - ][ + - ]: 2 : uno::Reference< awt::XVclContainerPeer > xC( getPeer(), uno::UNO_QUERY );
808 [ + - ]: 2 : if ( xC.is() )
809 [ + - ][ + - ]: 2 : xC->enableDialogControl( sal_True );
810 [ + - ][ + - ]: 2 : ImplActivateTabControllers();
811 : : }
812 : :
813 [ + - ][ + - ]: 2 : if( bVis && !isDesignMode() )
[ + - ][ + - ]
814 [ + - ]: 2 : UnoControl::setVisible( sal_True );
815 [ + - ]: 638 : }
816 : 638 : }
817 : :
818 : :
819 : : // awt::XWindow
820 : 2 : void UnoControlContainer::setVisible( sal_Bool bVisible ) throw(uno::RuntimeException)
821 : : {
822 [ + - ]: 2 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
823 : :
824 [ + - ]: 2 : UnoControl::setVisible( bVisible );
825 [ + - ][ + - ]: 2 : if( !mxContext.is() && bVisible )
[ + - ]
826 : : // This is a Topwindow, thus show it automatically
827 [ + - ][ + - ]: 2 : createPeer( uno::Reference< awt::XToolkit > (), uno::Reference< awt::XWindowPeer > () );
828 : 2 : }
829 : :
830 : :
831 : :
832 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|