update dev300-m58
[ooovba.git] / toolkit / source / controls / unocontrolcontainer.cxx
blob188e99e6cbda906d40d18521e0be957aeac71116
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocontrolcontainer.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
35 #include <com/sun/star/awt/XVclContainerPeer.hpp>
36 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
38 #include <cppuhelper/typeprovider.hxx>
39 #include <cppuhelper/implbase1.hxx>
40 #include <rtl/memory.h>
41 #include <rtl/uuid.h>
43 #include <toolkit/controls/unocontrolcontainer.hxx>
44 #include <toolkit/helper/property.hxx>
45 #include <toolkit/helper/servicenames.hxx>
46 #include <comphelper/sequence.hxx>
48 #include <tools/debug.hxx>
49 #include <tools/list.hxx>
50 #include <vcl/svapp.hxx>
51 #include <vcl/window.hxx>
53 #include <limits>
54 #include <map>
55 #include <boost/shared_ptr.hpp>
57 using namespace ::com::sun::star;
59 extern WorkWindow* lcl_GetDefaultWindow();
61 // ----------------------------------------------------
62 // class UnoControlHolder
63 // ----------------------------------------------------
64 struct UnoControlHolder
66 uno::Reference< awt::XControl > mxControl;
67 ::rtl::OUString msName;
69 public:
70 UnoControlHolder( const ::rtl::OUString& rName, const uno::Reference< awt::XControl > & rControl )
71 : mxControl( rControl ),
72 msName( rName )
76 inline const ::rtl::OUString& getName() const { return msName; }
77 inline const uno::Reference< awt::XControl >& getControl() const { return mxControl; }
80 //DECLARE_LIST( UnoControlHolderList, UnoControlHolder* );
82 class UnoControlHolderList
84 public:
85 typedef sal_Int32 ControlIdentifier;
86 private:
87 typedef ::boost::shared_ptr< UnoControlHolder > ControlInfo;
88 typedef ::std::map< ControlIdentifier, ControlInfo > ControlMap;
90 private:
91 ControlMap maControls;
93 public:
94 UnoControlHolderList();
95 ~UnoControlHolderList();
97 /** adds a control with the given name to the list
98 @param _rxControl
99 the control to add. Must not be <NULL/>
100 @param _pBName
101 the name of the control, or <NULL/> if an automatic name should be generated
102 @return
103 the identifier of the newly added control
105 ControlIdentifier addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName );
107 /** returns the number of controls in the list
109 inline size_t size() const { return maControls.size(); }
111 /** determines whether or not the list is empty
113 inline bool empty() const { return maControls.empty(); }
115 /** retrieves all controls currently in the list
116 @return
117 the number of controls in the list
119 size_t getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const;
121 /** retrieves all identifiers of all controls currently in the list
122 @return
123 the number of controls in the list
125 size_t getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const;
127 /** returns the first control which is registered under the given name
129 uno::Reference< awt::XControl >
130 getControlForName( const ::rtl::OUString& _rName ) const;
132 /** returns the identifier which a control is registered for, or -1 if the control
133 isn't registered
135 ControlIdentifier
136 getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl );
138 /** retrieves the control for a given id
139 @param _nIdentifier
140 the identifier for the control
141 @param _out_rxControl
142 takes the XControl upon successful return
143 @return
144 <TRUE/> if and only if a control with the given id is part of the list
146 bool getControlForIdentifier( ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const;
148 /** removes a control from the list, given by id
149 @param _nId
150 The identifier of the control to remove.
152 void removeControlById( ControlIdentifier _nId );
154 /** replaces a control from the list with another one
155 @param _nId
156 The identifier of the control to replace
157 @param _rxNewControl
158 the new control to put into the list
160 void replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl );
162 private:
163 /** adds a control
164 @param _rxControl
165 the control to add to the container
166 @param _pName
167 pointer to the name of the control. Might be <NULL/>, in this case, a name is generated.
168 @return
169 the identifier of the newly inserted control
171 ControlIdentifier impl_addControl(
172 const uno::Reference< awt::XControl >& _rxControl,
173 const ::rtl::OUString* _pName
176 /** finds a free identifier
177 @throw uno::RuntimeException
178 if no free identifier can be found
180 ControlIdentifier impl_getFreeIdentifier_throw();
182 /** finds a free name
183 @throw uno::RuntimeException
184 if no free name can be found
186 ::rtl::OUString impl_getFreeName_throw();
189 //------------------------------------------------------------------------
190 UnoControlHolderList::UnoControlHolderList()
194 //------------------------------------------------------------------------
195 UnoControlHolderList::~UnoControlHolderList()
199 //------------------------------------------------------------------------
200 UnoControlHolderList::ControlIdentifier UnoControlHolderList::addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName )
202 return impl_addControl( _rxControl, _pName );
205 //------------------------------------------------------------------------
206 size_t UnoControlHolderList::getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const
208 _out_rControls.realloc( maControls.size() );
209 uno::Reference< awt::XControl >* pControls = _out_rControls.getArray();
210 for ( ControlMap::const_iterator loop = maControls.begin();
211 loop != maControls.end();
212 ++loop, ++pControls
214 *pControls = loop->second->getControl();
215 return maControls.size();
218 //------------------------------------------------------------------------
219 size_t UnoControlHolderList::getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const
221 _out_rIdentifiers.realloc( maControls.size() );
222 sal_Int32* pIndentifiers = _out_rIdentifiers.getArray();
223 for ( ControlMap::const_iterator loop = maControls.begin();
224 loop != maControls.end();
225 ++loop, ++pIndentifiers
227 *pIndentifiers = loop->first;
228 return maControls.size();
231 //------------------------------------------------------------------------
232 uno::Reference< awt::XControl > UnoControlHolderList::getControlForName( const ::rtl::OUString& _rName ) const
234 for ( ControlMap::const_iterator loop = maControls.begin();
235 loop != maControls.end();
236 ++loop
238 if ( loop->second->getName() == _rName )
239 return loop->second->getControl();
240 return uno::Reference< awt::XControl >();
243 //------------------------------------------------------------------------
244 UnoControlHolderList::ControlIdentifier UnoControlHolderList::getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl )
246 for ( ControlMap::iterator loop = maControls.begin();
247 loop != maControls.end();
248 ++loop
251 if ( loop->second->getControl().get() == _rxControl.get() )
252 return loop->first;
254 return -1;
257 //------------------------------------------------------------------------
258 bool UnoControlHolderList::getControlForIdentifier( UnoControlHolderList::ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const
260 ControlMap::const_iterator pos = maControls.find( _nIdentifier );
261 if ( pos == maControls.end() )
262 return false;
263 _out_rxControl = pos->second->getControl();
264 return true;
267 //------------------------------------------------------------------------
268 void UnoControlHolderList::removeControlById( UnoControlHolderList::ControlIdentifier _nId )
270 ControlMap::iterator pos = maControls.find( _nId );
271 DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::removeControlById: invalid id!" );
272 if ( pos == maControls.end() )
273 return;
275 maControls.erase( pos );
278 //------------------------------------------------------------------------
279 void UnoControlHolderList::replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl )
281 DBG_ASSERT( _rxNewControl.is(), "UnoControlHolderList::replaceControlById: invalid new control!" );
283 ControlMap::iterator pos = maControls.find( _nId );
284 DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::replaceControlById: invalid id!" );
285 if ( pos == maControls.end() )
286 return;
288 pos->second.reset( new UnoControlHolder( pos->second->getName(), _rxNewControl ) );
291 //------------------------------------------------------------------------
292 UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName )
294 DBG_ASSERT( _rxControl.is(), "UnoControlHolderList::impl_addControl: invalid control!" );
296 ::rtl::OUString sName = _pName ? *_pName : impl_getFreeName_throw();
297 sal_Int32 nId = impl_getFreeIdentifier_throw();
299 maControls[ nId ] = ControlInfo( new UnoControlHolder( sName, _rxControl ) );
300 return nId;
303 //------------------------------------------------------------------------
304 UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_getFreeIdentifier_throw()
306 for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
308 ControlMap::const_iterator existent = maControls.find( candidateId );
309 if ( existent == maControls.end() )
310 return candidateId;
312 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "out of identifiers" ) ), NULL );
315 //------------------------------------------------------------------------
316 ::rtl::OUString UnoControlHolderList::impl_getFreeName_throw()
318 ::rtl::OUString name( RTL_CONSTASCII_USTRINGPARAM( "control_" ) );
319 for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
321 ::rtl::OUString candidateName( name + ::rtl::OUString::valueOf( candidateId ) );
322 ControlMap::const_iterator loop = maControls.begin();
323 for ( ; loop != maControls.end(); ++loop )
325 if ( loop->second->getName() == candidateName )
326 break;
328 if ( loop == maControls.end() )
329 return candidateName;
331 throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "out of identifiers" ) ), NULL );
333 // ----------------------------------------------------
334 // Function to set the controls' visibility according
335 // to the dialog's "Step" property
336 // ----------------------------------------------------
337 void implUpdateVisibility
339 sal_Int32 nDialogStep,
340 uno::Reference< awt::XControlContainer > xControlContainer
343 uno::Sequence< uno::Reference< awt::XControl > >
344 aCtrls = xControlContainer->getControls();
345 const uno::Reference< awt::XControl >* pCtrls = aCtrls.getConstArray();
346 sal_uInt32 nCtrls = aCtrls.getLength();
347 sal_Bool bCompleteVisible = (nDialogStep == 0);
348 for( sal_uInt32 n = 0; n < nCtrls; n++ )
350 uno::Reference< awt::XControl > xControl = pCtrls[ n ];
352 sal_Bool bVisible = bCompleteVisible;
353 if( !bVisible )
355 uno::Reference< awt::XControlModel > xModel( xControl->getModel() );
356 uno::Reference< beans::XPropertySet > xPSet
357 ( xModel, uno::UNO_QUERY );
358 uno::Reference< beans::XPropertySetInfo >
359 xInfo = xPSet->getPropertySetInfo();
360 ::rtl::OUString aPropName(RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
361 sal_Int32 nControlStep = 0;
362 if ( xInfo->hasPropertyByName( aPropName ) )
364 uno::Any aVal = xPSet->getPropertyValue( aPropName );
365 aVal >>= nControlStep;
367 bVisible = (nControlStep == 0) || (nControlStep == nDialogStep);
370 uno::Reference< awt::XWindow> xWindow
371 ( xControl, uno::UNO_QUERY );
372 if( xWindow.is() )
373 xWindow->setVisible( bVisible );
378 // ----------------------------------------------------
379 // class DialogStepChangedListener
380 // ----------------------------------------------------
381 typedef ::cppu::WeakImplHelper1< beans::XPropertyChangeListener > PropertyChangeListenerHelper;
383 class DialogStepChangedListener: public PropertyChangeListenerHelper
385 private:
386 uno::Reference< awt::XControlContainer > mxControlContainer;
388 public:
389 DialogStepChangedListener( uno::Reference< awt::XControlContainer > xControlContainer )
390 : mxControlContainer( xControlContainer ) {}
392 // XEventListener
393 virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw( uno::RuntimeException);
395 // XPropertyChangeListener
396 virtual void SAL_CALL propertyChange( const beans::PropertyChangeEvent& evt ) throw( uno::RuntimeException);
400 void SAL_CALL DialogStepChangedListener::disposing( const lang::EventObject& /*_rSource*/)
401 throw( uno::RuntimeException)
403 mxControlContainer.clear();
406 void SAL_CALL DialogStepChangedListener::propertyChange( const beans::PropertyChangeEvent& evt )
407 throw( uno::RuntimeException)
409 // evt.PropertyName HAS to be "Step" because we only use the listener for that
410 sal_Int32 nDialogStep = 0;
411 evt.NewValue >>= nDialogStep;
412 implUpdateVisibility( nDialogStep, mxControlContainer );
415 // ----------------------------------------------------
416 // class UnoControlContainer
417 // ----------------------------------------------------
418 UnoControlContainer::UnoControlContainer() : maCListeners( *this )
420 mpControls = new UnoControlHolderList;
423 UnoControlContainer::UnoControlContainer( uno::Reference< awt::XWindowPeer > xP )
424 : maCListeners( *this )
426 setPeer( xP );
427 mbDisposePeer = sal_False;
428 mpControls = new UnoControlHolderList;
431 UnoControlContainer::~UnoControlContainer()
433 DELETEZ( mpControls );
436 void UnoControlContainer::ImplActivateTabControllers()
438 sal_uInt32 nCount = maTabControllers.getLength();
439 for ( sal_uInt32 n = 0; n < nCount; n++ )
441 maTabControllers.getArray()[n]->setContainer( this );
442 maTabControllers.getArray()[n]->activateTabOrder();
446 // lang::XComponent
447 void UnoControlContainer::dispose( ) throw(uno::RuntimeException)
449 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
451 lang::EventObject aDisposeEvent;
452 aDisposeEvent.Source = static_cast< uno::XAggregation* >( this );
454 // DG: zuerst der Welt mitteilen, dass der Container wegfliegt. Dieses ist um einiges
455 // schneller wenn die Welt sowohl an den Controls als auch am Container horcht
456 maDisposeListeners.disposeAndClear( aDisposeEvent );
457 maCListeners.disposeAndClear( aDisposeEvent );
460 uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
461 uno::Reference< awt::XControl >* pCtrls = aCtrls.getArray();
462 uno::Reference< awt::XControl >* pCtrlsEnd = pCtrls + aCtrls.getLength();
464 for( ; pCtrls < pCtrlsEnd; ++pCtrls )
466 removingControl( *pCtrls );
467 // Control wegwerfen
468 (*pCtrls)->dispose();
472 // alle Strukturen entfernen
473 DELETEZ( mpControls );
474 mpControls = new UnoControlHolderList;
476 UnoControlBase::dispose();
479 // lang::XEventListener
480 void UnoControlContainer::disposing( const lang::EventObject& _rEvt ) throw(uno::RuntimeException)
482 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
484 uno::Reference< awt::XControl > xControl( _rEvt.Source, uno::UNO_QUERY );
485 if ( xControl.is() )
486 removeControl( xControl );
488 UnoControlBase::disposing( _rEvt );
491 // container::XContainer
492 void UnoControlContainer::addContainerListener( const uno::Reference< container::XContainerListener >& rxListener ) throw(uno::RuntimeException)
494 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
496 maCListeners.addInterface( rxListener );
499 void UnoControlContainer::removeContainerListener( const uno::Reference< container::XContainerListener >& rxListener ) throw(uno::RuntimeException)
501 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
503 maCListeners.removeInterface( rxListener );
507 ::sal_Int32 SAL_CALL UnoControlContainer::insert( const uno::Any& _rElement ) throw (lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
509 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
511 uno::Reference< awt::XControl > xControl;
512 if ( !( _rElement >>= xControl ) || !xControl.is() )
513 throw lang::IllegalArgumentException(
514 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Elements must support the XControl interface." ) ),
515 *this,
519 return impl_addControl( xControl, NULL );
522 void SAL_CALL UnoControlContainer::removeByIdentifier( ::sal_Int32 _nIdentifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
524 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
526 uno::Reference< awt::XControl > xControl;
527 if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
528 throw container::NoSuchElementException(
529 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "There is no element with the given identifier." ) ),
530 *this
533 impl_removeControl( _nIdentifier, xControl, NULL );
536 void SAL_CALL UnoControlContainer::replaceByIdentifer( ::sal_Int32 _nIdentifier, const uno::Any& _rElement ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
538 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
540 uno::Reference< awt::XControl > xExistentControl;
541 if ( !mpControls->getControlForIdentifier( _nIdentifier, xExistentControl ) )
542 throw container::NoSuchElementException(
543 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "There is no element with the given identifier." ) ),
544 *this
547 uno::Reference< awt::XControl > xNewControl;
548 if ( !( _rElement >>= xNewControl ) )
549 throw lang::IllegalArgumentException(
550 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Elements must support the XControl interface." ) ),
551 *this,
555 removingControl( xExistentControl );
557 mpControls->replaceControlById( _nIdentifier, xNewControl );
559 addingControl( xNewControl );
561 impl_createControlPeerIfNecessary( xNewControl );
563 if ( maCListeners.getLength() )
565 container::ContainerEvent aEvent;
566 aEvent.Source = *this;
567 aEvent.Accessor <<= _nIdentifier;
568 aEvent.Element <<= xNewControl;
569 aEvent.ReplacedElement <<= xExistentControl;
570 maCListeners.elementReplaced( aEvent );
574 uno::Any SAL_CALL UnoControlContainer::getByIdentifier( ::sal_Int32 _nIdentifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
576 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
578 uno::Reference< awt::XControl > xControl;
579 if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
580 throw container::NoSuchElementException();
581 return uno::makeAny( xControl );
584 uno::Sequence< ::sal_Int32 > SAL_CALL UnoControlContainer::getIdentifiers( ) throw (uno::RuntimeException)
586 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
588 uno::Sequence< ::sal_Int32 > aIdentifiers;
589 mpControls->getIdentifiers( aIdentifiers );
590 return aIdentifiers;
593 // container::XElementAccess
594 uno::Type SAL_CALL UnoControlContainer::getElementType( ) throw (uno::RuntimeException)
596 return awt::XControlModel::static_type();
599 ::sal_Bool SAL_CALL UnoControlContainer::hasElements( ) throw (uno::RuntimeException)
601 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
602 return !mpControls->empty();
605 // awt::XControlContainer
606 void UnoControlContainer::setStatusText( const ::rtl::OUString& rStatusText ) throw(uno::RuntimeException)
608 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
610 // In der Parenthierarchie nach unten gehen
611 uno::Reference< awt::XControlContainer > xContainer( mxContext, uno::UNO_QUERY );
612 if( xContainer.is() )
613 xContainer->setStatusText( rStatusText );
616 uno::Sequence< uno::Reference< awt::XControl > > UnoControlContainer::getControls( ) throw(uno::RuntimeException)
618 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
619 uno::Sequence< uno::Reference< awt::XControl > > aControls;
620 mpControls->getControls( aControls );
621 return aControls;
624 uno::Reference< awt::XControl > UnoControlContainer::getControl( const ::rtl::OUString& rName ) throw(uno::RuntimeException)
626 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
627 return mpControls->getControlForName( rName );
630 void UnoControlContainer::addingControl( const uno::Reference< awt::XControl >& _rxControl )
632 if ( _rxControl.is() )
634 uno::Reference< uno::XInterface > xThis;
635 OWeakAggObject::queryInterface( ::getCppuType( static_cast< uno::Reference< uno::XInterface >* >( NULL ) ) ) >>= xThis;
637 _rxControl->setContext( xThis );
638 _rxControl->addEventListener( this );
642 void UnoControlContainer::impl_createControlPeerIfNecessary( const uno::Reference< awt::XControl >& _rxControl )
644 OSL_PRECOND( _rxControl.is(), "UnoControlContainer::impl_createControlPeerIfNecessary: invalid control, this will crash!" );
646 // if the container already has a peer, then also create a peer for the control
647 uno::Reference< awt::XWindowPeer > xMyPeer( getPeer() );
649 if( xMyPeer.is() )
651 _rxControl->createPeer( NULL, xMyPeer );
652 ImplActivateTabControllers();
657 sal_Int32 UnoControlContainer::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName )
659 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
660 UnoControlHolderList::ControlIdentifier id = mpControls->addControl( _rxControl, _pName );
662 addingControl( _rxControl );
664 impl_createControlPeerIfNecessary( _rxControl );
666 if ( maCListeners.getLength() )
668 container::ContainerEvent aEvent;
669 aEvent.Source = *this;
670 _pName ? ( aEvent.Accessor <<= *_pName ) : ( aEvent.Accessor <<= (sal_Int32)id );
671 aEvent.Element <<= _rxControl;
672 maCListeners.elementInserted( aEvent );
675 return id;
678 void UnoControlContainer::addControl( const ::rtl::OUString& rName, const uno::Reference< awt::XControl >& rControl ) throw(uno::RuntimeException)
680 if ( rControl.is() )
681 impl_addControl( rControl, &rName );
684 void UnoControlContainer::removingControl( const uno::Reference< awt::XControl >& _rxControl )
686 if ( _rxControl.is() )
688 _rxControl->removeEventListener( this );
689 _rxControl->setContext( NULL );
693 void UnoControlContainer::impl_removeControl( sal_Int32 _nId, const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pNameAccessor )
695 #ifdef DBG_UTIL
697 uno::Reference< awt::XControl > xControl;
698 bool bHas = mpControls->getControlForIdentifier( _nId, xControl );
699 DBG_ASSERT( bHas && xControl == _rxControl, "UnoControlContainer::impl_removeControl: inconsistency in the parameters!" );
701 #endif
702 removingControl( _rxControl );
704 mpControls->removeControlById( _nId );
706 if ( maCListeners.getLength() )
708 container::ContainerEvent aEvent;
709 aEvent.Source = *this;
710 _pNameAccessor ? ( aEvent.Accessor <<= *_pNameAccessor ) : ( aEvent.Accessor <<= _nId );
711 aEvent.Element <<= _rxControl;
712 maCListeners.elementRemoved( aEvent );
716 void UnoControlContainer::removeControl( const uno::Reference< awt::XControl >& _rxControl ) throw(uno::RuntimeException)
718 if ( _rxControl.is() )
720 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
722 UnoControlHolderList::ControlIdentifier id = mpControls->getControlIdentifier( _rxControl );
723 if ( id != -1 )
724 impl_removeControl( id, _rxControl, NULL );
730 // awt::XUnoControlContainer
731 void UnoControlContainer::setTabControllers( const uno::Sequence< uno::Reference< awt::XTabController > >& TabControllers ) throw(uno::RuntimeException)
733 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
735 maTabControllers = TabControllers;
738 uno::Sequence< uno::Reference< awt::XTabController > > UnoControlContainer::getTabControllers( ) throw(uno::RuntimeException)
740 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
742 return maTabControllers;
745 void UnoControlContainer::addTabController( const uno::Reference< awt::XTabController >& TabController ) throw(uno::RuntimeException)
747 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
749 sal_uInt32 nCount = maTabControllers.getLength();
750 maTabControllers.realloc( nCount + 1 );
751 maTabControllers[ nCount ] = TabController;
754 void UnoControlContainer::removeTabController( const uno::Reference< awt::XTabController >& TabController ) throw(uno::RuntimeException)
756 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
758 sal_uInt32 nCount = maTabControllers.getLength();
759 const uno::Reference< awt::XTabController >* pLoop = maTabControllers.getConstArray();
760 for ( sal_uInt32 n = 0; n < nCount; ++n, ++pLoop )
762 if( pLoop->get() == TabController.get() )
764 ::comphelper::removeElementAt( maTabControllers, n );
765 break;
770 // awt::XControl
771 void UnoControlContainer::createPeer( const uno::Reference< awt::XToolkit >& rxToolkit, const uno::Reference< awt::XWindowPeer >& rParent ) throw(uno::RuntimeException)
773 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
775 if( !getPeer().is() )
777 sal_Bool bVis = maComponentInfos.bVisible;
778 if( bVis )
779 UnoControl::setVisible( sal_False );
780 // eigenes Peer erzeugen
781 UnoControl::createPeer( rxToolkit, rParent );
783 // alle Peers der Childs erzeugen
784 if ( !mbCreatingCompatiblePeer )
786 // Evaluate "Step" property
787 uno::Reference< awt::XControlModel > xModel( getModel() );
788 uno::Reference< beans::XPropertySet > xPSet
789 ( xModel, uno::UNO_QUERY );
790 uno::Reference< beans::XPropertySetInfo >
791 xInfo = xPSet->getPropertySetInfo();
792 ::rtl::OUString aPropName(RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
793 if ( xInfo->hasPropertyByName( aPropName ) )
795 ::com::sun::star::uno::Any aVal = xPSet->getPropertyValue( aPropName );
796 sal_Int32 nDialogStep = 0;
797 aVal >>= nDialogStep;
798 uno::Reference< awt::XControlContainer > xContainer =
799 SAL_STATIC_CAST( awt::XControlContainer*, this );
800 implUpdateVisibility( nDialogStep, xContainer );
802 uno::Reference< beans::XPropertyChangeListener > xListener =
803 SAL_STATIC_CAST( beans::XPropertyChangeListener*,
804 new DialogStepChangedListener( xContainer ) );
805 xPSet->addPropertyChangeListener( aPropName, xListener );
808 uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
809 sal_uInt32 nCtrls = aCtrls.getLength();
810 for( sal_uInt32 n = 0; n < nCtrls; n++ )
811 aCtrls.getArray()[n]->createPeer( rxToolkit, getPeer() );
813 uno::Reference< awt::XVclContainerPeer > xC( getPeer(), uno::UNO_QUERY );
815 xC->enableDialogControl( sal_True );
816 ImplActivateTabControllers();
819 if( bVis && !isDesignMode() )
820 UnoControl::setVisible( sal_True );
825 // awt::XWindow
826 void UnoControlContainer::setVisible( sal_Bool bVisible ) throw(uno::RuntimeException)
828 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
830 UnoControl::setVisible( bVisible );
831 if( !mxContext.is() && bVisible )
832 // Es ist ein TopWindow, also automatisch anzeigen
833 createPeer( uno::Reference< awt::XToolkit > (), uno::Reference< awt::XWindowPeer > () );