1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/awt/XVclContainerPeer.hpp>
21 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <cppuhelper/implbase1.hxx>
27 #include <toolkit/controls/unocontrolcontainer.hxx>
28 #include <toolkit/helper/property.hxx>
29 #include <toolkit/helper/servicenames.hxx>
30 #include <comphelper/sequence.hxx>
32 #include <tools/debug.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/window.hxx>
38 #include <boost/shared_ptr.hpp>
39 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
41 using namespace ::com::sun::star
;
43 // ----------------------------------------------------
44 // class UnoControlHolder
45 // ----------------------------------------------------
46 struct UnoControlHolder
48 uno::Reference
< awt::XControl
> mxControl
;
52 UnoControlHolder( const OUString
& rName
, const uno::Reference
< awt::XControl
> & rControl
)
53 : mxControl( rControl
),
58 inline const OUString
& getName() const { return msName
; }
59 inline const uno::Reference
< awt::XControl
>& getControl() const { return mxControl
; }
62 class UnoControlHolderList
65 typedef sal_Int32 ControlIdentifier
;
67 typedef ::boost::shared_ptr
< UnoControlHolder
> ControlInfo
;
68 typedef ::std::map
< ControlIdentifier
, ControlInfo
> ControlMap
;
71 ControlMap maControls
;
74 UnoControlHolderList();
75 ~UnoControlHolderList();
77 /** adds a control with the given name to the list
79 the control to add. Must not be <NULL/>
81 the name of the control, or <NULL/> if an automatic name should be generated
83 the identifier of the newly added control
85 ControlIdentifier
addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
);
87 /** returns the number of controls in the list
89 inline size_t size() const { return maControls
.size(); }
91 /** determines whether or not the list is empty
93 inline bool empty() const { return maControls
.empty(); }
95 /** retrieves all controls currently in the list
97 the number of controls in the list
99 size_t getControls( uno::Sequence
< uno::Reference
< awt::XControl
> >& _out_rControls
) const;
101 /** retrieves all identifiers of all controls currently in the list
103 the number of controls in the list
105 size_t getIdentifiers( uno::Sequence
< sal_Int32
>& _out_rIdentifiers
) const;
107 /** returns the first control which is registered under the given name
109 uno::Reference
< awt::XControl
>
110 getControlForName( const OUString
& _rName
) const;
112 /** returns the identifier which a control is registered for, or -1 if the control
116 getControlIdentifier( const uno::Reference
< awt::XControl
>& _rxControl
);
118 /** retrieves the control for a given id
120 the identifier for the control
121 @param _out_rxControl
122 takes the XControl upon successful return
124 <TRUE/> if and only if a control with the given id is part of the list
126 bool getControlForIdentifier( ControlIdentifier _nIdentifier
, uno::Reference
< awt::XControl
>& _out_rxControl
) const;
128 /** removes a control from the list, given by id
130 The identifier of the control to remove.
132 void removeControlById( ControlIdentifier _nId
);
134 /** replaces a control from the list with another one
136 The identifier of the control to replace
138 the new control to put into the list
140 void replaceControlById( ControlIdentifier _nId
, const uno::Reference
< awt::XControl
>& _rxNewControl
);
145 the control to add to the container
147 pointer to the name of the control. Might be <NULL/>, in this case, a name is generated.
149 the identifier of the newly inserted control
151 ControlIdentifier
impl_addControl(
152 const uno::Reference
< awt::XControl
>& _rxControl
,
153 const OUString
* _pName
156 /** finds a free identifier
157 @throw uno::RuntimeException
158 if no free identifier can be found
160 ControlIdentifier
impl_getFreeIdentifier_throw();
162 /** finds a free name
163 @throw uno::RuntimeException
164 if no free name can be found
166 OUString
impl_getFreeName_throw();
169 //------------------------------------------------------------------------
170 UnoControlHolderList::UnoControlHolderList()
174 //------------------------------------------------------------------------
175 UnoControlHolderList::~UnoControlHolderList()
179 //------------------------------------------------------------------------
180 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
)
182 return impl_addControl( _rxControl
, _pName
);
185 //------------------------------------------------------------------------
186 size_t UnoControlHolderList::getControls( uno::Sequence
< uno::Reference
< awt::XControl
> >& _out_rControls
) const
188 _out_rControls
.realloc( maControls
.size() );
189 uno::Reference
< awt::XControl
>* pControls
= _out_rControls
.getArray();
190 for ( ControlMap::const_iterator loop
= maControls
.begin();
191 loop
!= maControls
.end();
194 *pControls
= loop
->second
->getControl();
195 return maControls
.size();
198 //------------------------------------------------------------------------
199 size_t UnoControlHolderList::getIdentifiers( uno::Sequence
< sal_Int32
>& _out_rIdentifiers
) const
201 _out_rIdentifiers
.realloc( maControls
.size() );
202 sal_Int32
* pIndentifiers
= _out_rIdentifiers
.getArray();
203 for ( ControlMap::const_iterator loop
= maControls
.begin();
204 loop
!= maControls
.end();
205 ++loop
, ++pIndentifiers
207 *pIndentifiers
= loop
->first
;
208 return maControls
.size();
211 //------------------------------------------------------------------------
212 uno::Reference
< awt::XControl
> UnoControlHolderList::getControlForName( const OUString
& _rName
) const
214 for ( ControlMap::const_iterator loop
= maControls
.begin();
215 loop
!= maControls
.end();
218 if ( loop
->second
->getName() == _rName
)
219 return loop
->second
->getControl();
220 return uno::Reference
< awt::XControl
>();
223 //------------------------------------------------------------------------
224 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::getControlIdentifier( const uno::Reference
< awt::XControl
>& _rxControl
)
226 for ( ControlMap::iterator loop
= maControls
.begin();
227 loop
!= maControls
.end();
231 if ( loop
->second
->getControl().get() == _rxControl
.get() )
237 //------------------------------------------------------------------------
238 bool UnoControlHolderList::getControlForIdentifier( UnoControlHolderList::ControlIdentifier _nIdentifier
, uno::Reference
< awt::XControl
>& _out_rxControl
) const
240 ControlMap::const_iterator pos
= maControls
.find( _nIdentifier
);
241 if ( pos
== maControls
.end() )
243 _out_rxControl
= pos
->second
->getControl();
247 //------------------------------------------------------------------------
248 void UnoControlHolderList::removeControlById( UnoControlHolderList::ControlIdentifier _nId
)
250 ControlMap::iterator pos
= maControls
.find( _nId
);
251 DBG_ASSERT( pos
!= maControls
.end(), "UnoControlHolderList::removeControlById: invalid id!" );
252 if ( pos
== maControls
.end() )
255 maControls
.erase( pos
);
258 //------------------------------------------------------------------------
259 void UnoControlHolderList::replaceControlById( ControlIdentifier _nId
, const uno::Reference
< awt::XControl
>& _rxNewControl
)
261 DBG_ASSERT( _rxNewControl
.is(), "UnoControlHolderList::replaceControlById: invalid new control!" );
263 ControlMap::iterator pos
= maControls
.find( _nId
);
264 DBG_ASSERT( pos
!= maControls
.end(), "UnoControlHolderList::replaceControlById: invalid id!" );
265 if ( pos
== maControls
.end() )
268 pos
->second
.reset( new UnoControlHolder( pos
->second
->getName(), _rxNewControl
) );
271 //------------------------------------------------------------------------
272 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::impl_addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
)
274 DBG_ASSERT( _rxControl
.is(), "UnoControlHolderList::impl_addControl: invalid control!" );
276 OUString sName
= _pName
? *_pName
: impl_getFreeName_throw();
277 sal_Int32 nId
= impl_getFreeIdentifier_throw();
279 maControls
[ nId
] = ControlInfo( new UnoControlHolder( sName
, _rxControl
) );
283 //------------------------------------------------------------------------
284 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::impl_getFreeIdentifier_throw()
286 for ( ControlIdentifier candidateId
= 0; candidateId
< ::std::numeric_limits
< ControlIdentifier
>::max(); ++candidateId
)
288 ControlMap::const_iterator existent
= maControls
.find( candidateId
);
289 if ( existent
== maControls
.end() )
292 throw uno::RuntimeException( OUString( "out of identifiers" ), NULL
);
295 //------------------------------------------------------------------------
296 OUString
UnoControlHolderList::impl_getFreeName_throw()
298 OUString
name( "control_" );
299 for ( ControlIdentifier candidateId
= 0; candidateId
< ::std::numeric_limits
< ControlIdentifier
>::max(); ++candidateId
)
301 OUString
candidateName( name
+ OUString::valueOf( candidateId
) );
302 ControlMap::const_iterator loop
= maControls
.begin();
303 for ( ; loop
!= maControls
.end(); ++loop
)
305 if ( loop
->second
->getName() == candidateName
)
308 if ( loop
== maControls
.end() )
309 return candidateName
;
311 throw uno::RuntimeException( OUString( "out of identifiers" ), NULL
);
313 // ----------------------------------------------------
314 // Function to set the controls' visibility according
315 // to the dialog's "Step" property
316 // ----------------------------------------------------
317 void implUpdateVisibility
319 sal_Int32 nDialogStep
,
320 uno::Reference
< awt::XControlContainer
> xControlContainer
323 uno::Sequence
< uno::Reference
< awt::XControl
> >
324 aCtrls
= xControlContainer
->getControls();
325 const uno::Reference
< awt::XControl
>* pCtrls
= aCtrls
.getConstArray();
326 sal_uInt32 nCtrls
= aCtrls
.getLength();
327 sal_Bool bCompleteVisible
= (nDialogStep
== 0);
328 for( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
330 uno::Reference
< awt::XControl
> xControl
= pCtrls
[ n
];
332 sal_Bool bVisible
= bCompleteVisible
;
335 uno::Reference
< awt::XControlModel
> xModel( xControl
->getModel() );
336 uno::Reference
< beans::XPropertySet
> xPSet
337 ( xModel
, uno::UNO_QUERY
);
338 uno::Reference
< beans::XPropertySetInfo
>
339 xInfo
= xPSet
->getPropertySetInfo();
340 OUString
aPropName( "Step" );
341 sal_Int32 nControlStep
= 0;
342 if ( xInfo
->hasPropertyByName( aPropName
) )
344 uno::Any aVal
= xPSet
->getPropertyValue( aPropName
);
345 aVal
>>= nControlStep
;
347 bVisible
= (nControlStep
== 0) || (nControlStep
== nDialogStep
);
350 uno::Reference
< awt::XWindow
> xWindow
351 ( xControl
, uno::UNO_QUERY
);
353 xWindow
->setVisible( bVisible
);
358 // ----------------------------------------------------
359 // class DialogStepChangedListener
360 // ----------------------------------------------------
361 typedef ::cppu::WeakImplHelper1
< beans::XPropertyChangeListener
> PropertyChangeListenerHelper
;
363 class DialogStepChangedListener
: public PropertyChangeListenerHelper
366 uno::Reference
< awt::XControlContainer
> mxControlContainer
;
369 DialogStepChangedListener( uno::Reference
< awt::XControlContainer
> xControlContainer
)
370 : mxControlContainer( xControlContainer
) {}
373 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) throw( uno::RuntimeException
);
375 // XPropertyChangeListener
376 virtual void SAL_CALL
propertyChange( const beans::PropertyChangeEvent
& evt
) throw( uno::RuntimeException
);
380 void SAL_CALL
DialogStepChangedListener::disposing( const lang::EventObject
& /*_rSource*/)
381 throw( uno::RuntimeException
)
383 mxControlContainer
.clear();
386 void SAL_CALL
DialogStepChangedListener::propertyChange( const beans::PropertyChangeEvent
& evt
)
387 throw( uno::RuntimeException
)
389 // evt.PropertyName HAS to be "Step" because we only use the listener for that
390 sal_Int32 nDialogStep
= 0;
391 evt
.NewValue
>>= nDialogStep
;
392 implUpdateVisibility( nDialogStep
, mxControlContainer
);
395 // ----------------------------------------------------
396 // class UnoControlContainer
397 // ----------------------------------------------------
398 UnoControlContainer::UnoControlContainer()
399 :UnoControlContainer_Base()
400 ,maCListeners( *this )
402 mpControls
= new UnoControlHolderList
;
405 UnoControlContainer::UnoControlContainer(const uno::Reference
< awt::XWindowPeer
>& xP
)
406 :UnoControlContainer_Base()
407 ,maCListeners( *this )
410 mbDisposePeer
= sal_False
;
411 mpControls
= new UnoControlHolderList
;
414 UnoControlContainer::~UnoControlContainer()
416 DELETEZ( mpControls
);
419 void UnoControlContainer::ImplActivateTabControllers()
421 sal_uInt32 nCount
= maTabControllers
.getLength();
422 for ( sal_uInt32 n
= 0; n
< nCount
; n
++ )
424 maTabControllers
.getArray()[n
]->setContainer( this );
425 maTabControllers
.getArray()[n
]->activateTabOrder();
430 void UnoControlContainer::dispose( ) throw(uno::RuntimeException
)
432 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
434 lang::EventObject aDisposeEvent
;
435 aDisposeEvent
.Source
= static_cast< uno::XAggregation
* >( this );
437 // Notify listeners about disposal of this Container (This is much faster if they
438 // listen on the controls and the container).
439 maDisposeListeners
.disposeAndClear( aDisposeEvent
);
440 maCListeners
.disposeAndClear( aDisposeEvent
);
443 uno::Sequence
< uno::Reference
< awt::XControl
> > aCtrls
= getControls();
444 uno::Reference
< awt::XControl
>* pCtrls
= aCtrls
.getArray();
445 uno::Reference
< awt::XControl
>* pCtrlsEnd
= pCtrls
+ aCtrls
.getLength();
447 for( ; pCtrls
< pCtrlsEnd
; ++pCtrls
)
449 removingControl( *pCtrls
);
451 (*pCtrls
)->dispose();
455 // Delete all structures
456 DELETEZ( mpControls
);
457 mpControls
= new UnoControlHolderList
;
459 UnoControlBase::dispose();
462 // lang::XEventListener
463 void UnoControlContainer::disposing( const lang::EventObject
& _rEvt
) throw(uno::RuntimeException
)
465 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
467 uno::Reference
< awt::XControl
> xControl( _rEvt
.Source
, uno::UNO_QUERY
);
469 removeControl( xControl
);
471 UnoControlBase::disposing( _rEvt
);
474 // container::XContainer
475 void UnoControlContainer::addContainerListener( const uno::Reference
< container::XContainerListener
>& rxListener
) throw(uno::RuntimeException
)
477 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
479 maCListeners
.addInterface( rxListener
);
482 void UnoControlContainer::removeContainerListener( const uno::Reference
< container::XContainerListener
>& rxListener
) throw(uno::RuntimeException
)
484 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
486 maCListeners
.removeInterface( rxListener
);
490 ::sal_Int32 SAL_CALL
UnoControlContainer::insert( const uno::Any
& _rElement
) throw (lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
492 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
494 uno::Reference
< awt::XControl
> xControl
;
495 if ( !( _rElement
>>= xControl
) || !xControl
.is() )
496 throw lang::IllegalArgumentException(
497 OUString( "Elements must support the XControl interface." ),
502 return impl_addControl( xControl
, NULL
);
505 void SAL_CALL
UnoControlContainer::removeByIdentifier( ::sal_Int32 _nIdentifier
) throw (container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
507 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
509 uno::Reference
< awt::XControl
> xControl
;
510 if ( !mpControls
->getControlForIdentifier( _nIdentifier
, xControl
) )
511 throw container::NoSuchElementException(
512 OUString( "There is no element with the given identifier." ),
516 impl_removeControl( _nIdentifier
, xControl
, NULL
);
519 void SAL_CALL
UnoControlContainer::replaceByIdentifer( ::sal_Int32 _nIdentifier
, const uno::Any
& _rElement
) throw (lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
521 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
523 uno::Reference
< awt::XControl
> xExistentControl
;
524 if ( !mpControls
->getControlForIdentifier( _nIdentifier
, xExistentControl
) )
525 throw container::NoSuchElementException(
526 OUString( "There is no element with the given identifier." ),
530 uno::Reference
< awt::XControl
> xNewControl
;
531 if ( !( _rElement
>>= xNewControl
) )
532 throw lang::IllegalArgumentException(
533 OUString( "Elements must support the XControl interface." ),
538 removingControl( xExistentControl
);
540 mpControls
->replaceControlById( _nIdentifier
, xNewControl
);
542 addingControl( xNewControl
);
544 impl_createControlPeerIfNecessary( xNewControl
);
546 if ( maCListeners
.getLength() )
548 container::ContainerEvent aEvent
;
549 aEvent
.Source
= *this;
550 aEvent
.Accessor
<<= _nIdentifier
;
551 aEvent
.Element
<<= xNewControl
;
552 aEvent
.ReplacedElement
<<= xExistentControl
;
553 maCListeners
.elementReplaced( aEvent
);
557 uno::Any SAL_CALL
UnoControlContainer::getByIdentifier( ::sal_Int32 _nIdentifier
) throw (container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
559 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
561 uno::Reference
< awt::XControl
> xControl
;
562 if ( !mpControls
->getControlForIdentifier( _nIdentifier
, xControl
) )
563 throw container::NoSuchElementException();
564 return uno::makeAny( xControl
);
567 uno::Sequence
< ::sal_Int32
> SAL_CALL
UnoControlContainer::getIdentifiers( ) throw (uno::RuntimeException
)
569 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
571 uno::Sequence
< ::sal_Int32
> aIdentifiers
;
572 mpControls
->getIdentifiers( aIdentifiers
);
576 // container::XElementAccess
577 uno::Type SAL_CALL
UnoControlContainer::getElementType( ) throw (uno::RuntimeException
)
579 return awt::XControlModel::static_type();
582 ::sal_Bool SAL_CALL
UnoControlContainer::hasElements( ) throw (uno::RuntimeException
)
584 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
585 return !mpControls
->empty();
588 // awt::XControlContainer
589 void UnoControlContainer::setStatusText( const OUString
& rStatusText
) throw(uno::RuntimeException
)
591 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
593 // Descend the parent hierarchy
594 uno::Reference
< awt::XControlContainer
> xContainer( mxContext
, uno::UNO_QUERY
);
595 if( xContainer
.is() )
596 xContainer
->setStatusText( rStatusText
);
599 uno::Sequence
< uno::Reference
< awt::XControl
> > UnoControlContainer::getControls( ) throw(uno::RuntimeException
)
601 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
602 uno::Sequence
< uno::Reference
< awt::XControl
> > aControls
;
603 mpControls
->getControls( aControls
);
607 uno::Reference
< awt::XControl
> UnoControlContainer::getControl( const OUString
& rName
) throw(uno::RuntimeException
)
609 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
610 return mpControls
->getControlForName( rName
);
613 void UnoControlContainer::addingControl( const uno::Reference
< awt::XControl
>& _rxControl
)
615 if ( _rxControl
.is() )
617 uno::Reference
< uno::XInterface
> xThis
;
618 OWeakAggObject::queryInterface( ::getCppuType( static_cast< uno::Reference
< uno::XInterface
>* >( NULL
) ) ) >>= xThis
;
620 _rxControl
->setContext( xThis
);
621 _rxControl
->addEventListener( this );
625 void UnoControlContainer::impl_createControlPeerIfNecessary( const uno::Reference
< awt::XControl
>& _rxControl
)
627 OSL_PRECOND( _rxControl
.is(), "UnoControlContainer::impl_createControlPeerIfNecessary: invalid control, this will crash!" );
629 // if the container already has a peer, then also create a peer for the control
630 uno::Reference
< awt::XWindowPeer
> xMyPeer( getPeer() );
634 _rxControl
->createPeer( NULL
, xMyPeer
);
635 ImplActivateTabControllers();
640 sal_Int32
UnoControlContainer::impl_addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
)
642 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
643 UnoControlHolderList::ControlIdentifier id
= mpControls
->addControl( _rxControl
, _pName
);
645 addingControl( _rxControl
);
647 impl_createControlPeerIfNecessary( _rxControl
);
649 if ( maCListeners
.getLength() )
651 container::ContainerEvent aEvent
;
652 aEvent
.Source
= *this;
653 _pName
? ( aEvent
.Accessor
<<= *_pName
) : ( aEvent
.Accessor
<<= (sal_Int32
)id
);
654 aEvent
.Element
<<= _rxControl
;
655 maCListeners
.elementInserted( aEvent
);
661 void UnoControlContainer::addControl( const OUString
& rName
, const uno::Reference
< awt::XControl
>& rControl
) throw(uno::RuntimeException
)
664 impl_addControl( rControl
, &rName
);
667 void UnoControlContainer::removingControl( const uno::Reference
< awt::XControl
>& _rxControl
)
669 if ( _rxControl
.is() )
671 _rxControl
->removeEventListener( this );
672 _rxControl
->setContext( NULL
);
676 void UnoControlContainer::impl_removeControl( sal_Int32 _nId
, const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pNameAccessor
)
680 uno::Reference
< awt::XControl
> xControl
;
681 bool bHas
= mpControls
->getControlForIdentifier( _nId
, xControl
);
682 DBG_ASSERT( bHas
&& xControl
== _rxControl
, "UnoControlContainer::impl_removeControl: inconsistency in the parameters!" );
685 removingControl( _rxControl
);
687 mpControls
->removeControlById( _nId
);
689 if ( maCListeners
.getLength() )
691 container::ContainerEvent aEvent
;
692 aEvent
.Source
= *this;
693 _pNameAccessor
? ( aEvent
.Accessor
<<= *_pNameAccessor
) : ( aEvent
.Accessor
<<= _nId
);
694 aEvent
.Element
<<= _rxControl
;
695 maCListeners
.elementRemoved( aEvent
);
699 void UnoControlContainer::removeControl( const uno::Reference
< awt::XControl
>& _rxControl
) throw(uno::RuntimeException
)
701 if ( _rxControl
.is() )
703 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
705 UnoControlHolderList::ControlIdentifier id
= mpControls
->getControlIdentifier( _rxControl
);
707 impl_removeControl( id
, _rxControl
, NULL
);
713 // awt::XUnoControlContainer
714 void UnoControlContainer::setTabControllers( const uno::Sequence
< uno::Reference
< awt::XTabController
> >& TabControllers
) throw(uno::RuntimeException
)
716 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
718 maTabControllers
= TabControllers
;
721 uno::Sequence
< uno::Reference
< awt::XTabController
> > UnoControlContainer::getTabControllers( ) throw(uno::RuntimeException
)
723 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
725 return maTabControllers
;
728 void UnoControlContainer::addTabController( const uno::Reference
< awt::XTabController
>& TabController
) throw(uno::RuntimeException
)
730 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
732 sal_uInt32 nCount
= maTabControllers
.getLength();
733 maTabControllers
.realloc( nCount
+ 1 );
734 maTabControllers
[ nCount
] = TabController
;
737 void UnoControlContainer::removeTabController( const uno::Reference
< awt::XTabController
>& TabController
) throw(uno::RuntimeException
)
739 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
741 sal_uInt32 nCount
= maTabControllers
.getLength();
742 const uno::Reference
< awt::XTabController
>* pLoop
= maTabControllers
.getConstArray();
743 for ( sal_uInt32 n
= 0; n
< nCount
; ++n
, ++pLoop
)
745 if( pLoop
->get() == TabController
.get() )
747 ::comphelper::removeElementAt( maTabControllers
, n
);
754 void UnoControlContainer::createPeer( const uno::Reference
< awt::XToolkit
>& rxToolkit
, const uno::Reference
< awt::XWindowPeer
>& rParent
) throw(uno::RuntimeException
)
756 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
758 if( !getPeer().is() )
760 sal_Bool bVis
= maComponentInfos
.bVisible
;
762 UnoControl::setVisible( sal_False
);
764 uno::Reference
< beans::XPropertySet
> xTmpPropSet
765 ( getModel(), uno::UNO_QUERY
);
768 UnoControl::createPeer( rxToolkit
, rParent
);
770 // Create all children's peers
771 if ( !mbCreatingCompatiblePeer
)
773 // Evaluate "Step" property
774 uno::Reference
< awt::XControlModel
> xModel( getModel() );
775 uno::Reference
< beans::XPropertySet
> xPSet
776 ( xModel
, uno::UNO_QUERY
);
777 uno::Reference
< beans::XPropertySetInfo
>
778 xInfo
= xPSet
->getPropertySetInfo();
779 OUString
aPropName( "Step" );
780 if ( xInfo
->hasPropertyByName( aPropName
) )
782 ::com::sun::star::uno::Any aVal
= xPSet
->getPropertyValue( aPropName
);
783 sal_Int32 nDialogStep
= 0;
784 aVal
>>= nDialogStep
;
785 uno::Reference
< awt::XControlContainer
> xContainer
=
786 (static_cast< awt::XControlContainer
* >(this));
787 implUpdateVisibility( nDialogStep
, xContainer
);
789 uno::Reference
< beans::XPropertyChangeListener
> xListener
=
790 (static_cast< beans::XPropertyChangeListener
* >(
791 new DialogStepChangedListener( xContainer
) ) );
792 xPSet
->addPropertyChangeListener( aPropName
, xListener
);
795 uno::Sequence
< uno::Reference
< awt::XControl
> > aCtrls
= getControls();
796 sal_uInt32 nCtrls
= aCtrls
.getLength();
797 for( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
798 aCtrls
.getArray()[n
]->createPeer( rxToolkit
, getPeer() );
800 uno::Reference
< awt::XVclContainerPeer
> xC( getPeer(), uno::UNO_QUERY
);
802 xC
->enableDialogControl( sal_True
);
803 ImplActivateTabControllers();
806 if( bVis
&& !isDesignMode() )
807 UnoControl::setVisible( sal_True
);
813 void UnoControlContainer::setVisible( sal_Bool bVisible
) throw(uno::RuntimeException
)
815 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
817 UnoControl::setVisible( bVisible
);
818 if( !mxContext
.is() && bVisible
)
819 // This is a Topwindow, thus show it automatically
820 createPeer( uno::Reference
< awt::XToolkit
> (), uno::Reference
< awt::XWindowPeer
> () );
823 void UnoControlContainer::PrepareWindowDescriptor( ::com::sun::star::awt::WindowDescriptor
& rDesc
)
825 // HACK due to the fact that we can't really use VSCROLL & HSCROLL
826 // for Dialog ( ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL
827 // has the same value as
828 // ::com::sun::star::awt::WindowAttribute::NODECORATION )
829 // For convenience in the PropBrowse using HSCROLL and VSCROLL ensures
830 // the Correct text. We exchange them here and the control knows
831 // about this hack ( it sucks badly I know )
832 if ( rDesc
.WindowAttributes
& ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL
)
834 rDesc
.WindowAttributes
&= ~::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL
;
835 rDesc
.WindowAttributes
|= ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL
;
837 if ( rDesc
.WindowAttributes
& ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL
)
839 rDesc
.WindowAttributes
&= ~::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL
;
840 rDesc
.WindowAttributes
|= ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL
;
844 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */