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>
22 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <cppuhelper/typeprovider.hxx>
25 #include <cppuhelper/implbase1.hxx>
28 #include <toolkit/controls/unocontrolcontainer.hxx>
29 #include <toolkit/helper/property.hxx>
30 #include <toolkit/helper/servicenames.hxx>
31 #include <comphelper/sequence.hxx>
33 #include <tools/debug.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/window.hxx>
39 #include <boost/shared_ptr.hpp>
40 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
42 using namespace ::com::sun::star
;
45 // class UnoControlHolder
47 struct UnoControlHolder
49 uno::Reference
< awt::XControl
> mxControl
;
53 UnoControlHolder( const OUString
& rName
, const uno::Reference
< awt::XControl
> & rControl
)
54 : mxControl( rControl
),
59 inline const OUString
& getName() const { return msName
; }
60 inline const uno::Reference
< awt::XControl
>& getControl() const { return mxControl
; }
63 class UnoControlHolderList
66 typedef sal_Int32 ControlIdentifier
;
68 typedef ::boost::shared_ptr
< UnoControlHolder
> ControlInfo
;
69 typedef ::std::map
< ControlIdentifier
, ControlInfo
> ControlMap
;
72 ControlMap maControls
;
75 UnoControlHolderList();
76 ~UnoControlHolderList();
78 /** adds a control with the given name to the list
80 the control to add. Must not be <NULL/>
82 the name of the control, or <NULL/> if an automatic name should be generated
84 the identifier of the newly added control
86 ControlIdentifier
addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
);
88 /** determines whether or not the list is empty
90 inline bool empty() const { return maControls
.empty(); }
92 /** retrieves all controls currently in the list
94 the number of controls in the list
96 size_t getControls( uno::Sequence
< uno::Reference
< awt::XControl
> >& _out_rControls
) const;
98 /** retrieves all identifiers of all controls currently in the list
100 the number of controls in the list
102 size_t getIdentifiers( uno::Sequence
< sal_Int32
>& _out_rIdentifiers
) const;
104 /** returns the first control which is registered under the given name
106 uno::Reference
< awt::XControl
>
107 getControlForName( const OUString
& _rName
) const;
109 /** returns the identifier which a control is registered for, or -1 if the control
113 getControlIdentifier( const uno::Reference
< awt::XControl
>& _rxControl
);
115 /** retrieves the control for a given id
117 the identifier for the control
118 @param _out_rxControl
119 takes the XControl upon successful return
121 <TRUE/> if and only if a control with the given id is part of the list
123 bool getControlForIdentifier( ControlIdentifier _nIdentifier
, uno::Reference
< awt::XControl
>& _out_rxControl
) const;
125 /** removes a control from the list, given by id
127 The identifier of the control to remove.
129 void removeControlById( ControlIdentifier _nId
);
131 /** replaces a control from the list with another one
133 The identifier of the control to replace
135 the new control to put into the list
137 void replaceControlById( ControlIdentifier _nId
, const uno::Reference
< awt::XControl
>& _rxNewControl
);
142 the control to add to the container
144 pointer to the name of the control. Might be <NULL/>, in this case, a name is generated.
146 the identifier of the newly inserted control
148 ControlIdentifier
impl_addControl(
149 const uno::Reference
< awt::XControl
>& _rxControl
,
150 const OUString
* _pName
153 /** finds a free identifier
154 @throw uno::RuntimeException
155 if no free identifier can be found
157 ControlIdentifier
impl_getFreeIdentifier_throw();
159 /** finds a free name
160 @throw uno::RuntimeException
161 if no free name can be found
163 OUString
impl_getFreeName_throw();
167 UnoControlHolderList::UnoControlHolderList()
172 UnoControlHolderList::~UnoControlHolderList()
177 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
)
179 return impl_addControl( _rxControl
, _pName
);
183 size_t UnoControlHolderList::getControls( uno::Sequence
< uno::Reference
< awt::XControl
> >& _out_rControls
) const
185 _out_rControls
.realloc( maControls
.size() );
186 uno::Reference
< awt::XControl
>* pControls
= _out_rControls
.getArray();
187 for ( ControlMap::const_iterator loop
= maControls
.begin();
188 loop
!= maControls
.end();
191 *pControls
= loop
->second
->getControl();
192 return maControls
.size();
196 size_t UnoControlHolderList::getIdentifiers( uno::Sequence
< sal_Int32
>& _out_rIdentifiers
) const
198 _out_rIdentifiers
.realloc( maControls
.size() );
199 sal_Int32
* pIndentifiers
= _out_rIdentifiers
.getArray();
200 for ( ControlMap::const_iterator loop
= maControls
.begin();
201 loop
!= maControls
.end();
202 ++loop
, ++pIndentifiers
204 *pIndentifiers
= loop
->first
;
205 return maControls
.size();
209 uno::Reference
< awt::XControl
> UnoControlHolderList::getControlForName( const OUString
& _rName
) const
211 for ( ControlMap::const_iterator loop
= maControls
.begin();
212 loop
!= maControls
.end();
215 if ( loop
->second
->getName() == _rName
)
216 return loop
->second
->getControl();
217 return uno::Reference
< awt::XControl
>();
221 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::getControlIdentifier( const uno::Reference
< awt::XControl
>& _rxControl
)
223 for ( ControlMap::iterator loop
= maControls
.begin();
224 loop
!= maControls
.end();
228 if ( loop
->second
->getControl().get() == _rxControl
.get() )
235 bool UnoControlHolderList::getControlForIdentifier( UnoControlHolderList::ControlIdentifier _nIdentifier
, uno::Reference
< awt::XControl
>& _out_rxControl
) const
237 ControlMap::const_iterator pos
= maControls
.find( _nIdentifier
);
238 if ( pos
== maControls
.end() )
240 _out_rxControl
= pos
->second
->getControl();
245 void UnoControlHolderList::removeControlById( UnoControlHolderList::ControlIdentifier _nId
)
247 ControlMap::iterator pos
= maControls
.find( _nId
);
248 DBG_ASSERT( pos
!= maControls
.end(), "UnoControlHolderList::removeControlById: invalid id!" );
249 if ( pos
== maControls
.end() )
252 maControls
.erase( pos
);
256 void UnoControlHolderList::replaceControlById( ControlIdentifier _nId
, const uno::Reference
< awt::XControl
>& _rxNewControl
)
258 DBG_ASSERT( _rxNewControl
.is(), "UnoControlHolderList::replaceControlById: invalid new control!" );
260 ControlMap::iterator pos
= maControls
.find( _nId
);
261 DBG_ASSERT( pos
!= maControls
.end(), "UnoControlHolderList::replaceControlById: invalid id!" );
262 if ( pos
== maControls
.end() )
265 pos
->second
.reset( new UnoControlHolder( pos
->second
->getName(), _rxNewControl
) );
269 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::impl_addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
)
271 DBG_ASSERT( _rxControl
.is(), "UnoControlHolderList::impl_addControl: invalid control!" );
273 OUString sName
= _pName
? *_pName
: impl_getFreeName_throw();
274 sal_Int32 nId
= impl_getFreeIdentifier_throw();
276 maControls
[ nId
] = ControlInfo( new UnoControlHolder( sName
, _rxControl
) );
281 UnoControlHolderList::ControlIdentifier
UnoControlHolderList::impl_getFreeIdentifier_throw()
283 for ( ControlIdentifier candidateId
= 0; candidateId
< ::std::numeric_limits
< ControlIdentifier
>::max(); ++candidateId
)
285 ControlMap::const_iterator existent
= maControls
.find( candidateId
);
286 if ( existent
== maControls
.end() )
289 throw uno::RuntimeException("out of identifiers" );
293 OUString
UnoControlHolderList::impl_getFreeName_throw()
295 OUString
name( "control_" );
296 for ( ControlIdentifier candidateId
= 0; candidateId
< ::std::numeric_limits
< ControlIdentifier
>::max(); ++candidateId
)
298 OUString
candidateName( name
+ OUString::number( candidateId
) );
299 ControlMap::const_iterator loop
= maControls
.begin();
300 for ( ; loop
!= maControls
.end(); ++loop
)
302 if ( loop
->second
->getName() == candidateName
)
305 if ( loop
== maControls
.end() )
306 return candidateName
;
308 throw uno::RuntimeException("out of identifiers" );
311 // Function to set the controls' visibility according
312 // to the dialog's "Step" property
314 void implUpdateVisibility
316 sal_Int32 nDialogStep
,
317 uno::Reference
< awt::XControlContainer
> xControlContainer
320 uno::Sequence
< uno::Reference
< awt::XControl
> >
321 aCtrls
= xControlContainer
->getControls();
322 const uno::Reference
< awt::XControl
>* pCtrls
= aCtrls
.getConstArray();
323 sal_uInt32 nCtrls
= aCtrls
.getLength();
324 bool bCompleteVisible
= (nDialogStep
== 0);
325 for( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
327 uno::Reference
< awt::XControl
> xControl
= pCtrls
[ n
];
329 bool bVisible
= bCompleteVisible
;
332 uno::Reference
< awt::XControlModel
> xModel( xControl
->getModel() );
333 uno::Reference
< beans::XPropertySet
> xPSet
334 ( xModel
, uno::UNO_QUERY
);
335 uno::Reference
< beans::XPropertySetInfo
>
336 xInfo
= xPSet
->getPropertySetInfo();
337 OUString
aPropName( "Step" );
338 sal_Int32 nControlStep
= 0;
339 if ( xInfo
->hasPropertyByName( aPropName
) )
341 uno::Any aVal
= xPSet
->getPropertyValue( aPropName
);
342 aVal
>>= nControlStep
;
344 bVisible
= (nControlStep
== 0) || (nControlStep
== nDialogStep
);
347 uno::Reference
< awt::XWindow
> xWindow
348 ( xControl
, uno::UNO_QUERY
);
350 xWindow
->setVisible( bVisible
);
356 // class DialogStepChangedListener
358 typedef ::cppu::WeakImplHelper1
< beans::XPropertyChangeListener
> PropertyChangeListenerHelper
;
360 class DialogStepChangedListener
: public PropertyChangeListenerHelper
363 uno::Reference
< awt::XControlContainer
> mxControlContainer
;
366 DialogStepChangedListener( uno::Reference
< awt::XControlContainer
> xControlContainer
)
367 : mxControlContainer( xControlContainer
) {}
370 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) throw( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
372 // XPropertyChangeListener
373 virtual void SAL_CALL
propertyChange( const beans::PropertyChangeEvent
& evt
) throw( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
377 void SAL_CALL
DialogStepChangedListener::disposing( const lang::EventObject
& /*_rSource*/)
378 throw( uno::RuntimeException
, std::exception
)
380 mxControlContainer
.clear();
383 void SAL_CALL
DialogStepChangedListener::propertyChange( const beans::PropertyChangeEvent
& evt
)
384 throw( uno::RuntimeException
, std::exception
)
386 // evt.PropertyName HAS to be "Step" because we only use the listener for that
387 sal_Int32 nDialogStep
= 0;
388 evt
.NewValue
>>= nDialogStep
;
389 implUpdateVisibility( nDialogStep
, mxControlContainer
);
393 // class UnoControlContainer
395 UnoControlContainer::UnoControlContainer()
396 :UnoControlContainer_Base()
397 ,maCListeners( *this )
399 mpControls
= new UnoControlHolderList
;
402 UnoControlContainer::UnoControlContainer(const uno::Reference
< awt::XWindowPeer
>& xP
)
403 :UnoControlContainer_Base()
404 ,maCListeners( *this )
407 mbDisposePeer
= false;
408 mpControls
= new UnoControlHolderList
;
411 UnoControlContainer::~UnoControlContainer()
413 DELETEZ( mpControls
);
416 void UnoControlContainer::ImplActivateTabControllers()
418 sal_uInt32 nCount
= maTabControllers
.getLength();
419 for ( sal_uInt32 n
= 0; n
< nCount
; n
++ )
421 maTabControllers
.getArray()[n
]->setContainer( this );
422 maTabControllers
.getArray()[n
]->activateTabOrder();
427 void UnoControlContainer::dispose( ) throw(uno::RuntimeException
, std::exception
)
429 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
431 lang::EventObject aDisposeEvent
;
432 aDisposeEvent
.Source
= static_cast< uno::XAggregation
* >( this );
434 // Notify listeners about disposal of this Container (This is much faster if they
435 // listen on the controls and the container).
436 maDisposeListeners
.disposeAndClear( aDisposeEvent
);
437 maCListeners
.disposeAndClear( aDisposeEvent
);
440 uno::Sequence
< uno::Reference
< awt::XControl
> > aCtrls
= getControls();
441 uno::Reference
< awt::XControl
>* pCtrls
= aCtrls
.getArray();
442 uno::Reference
< awt::XControl
>* pCtrlsEnd
= pCtrls
+ aCtrls
.getLength();
444 for( ; pCtrls
< pCtrlsEnd
; ++pCtrls
)
446 removingControl( *pCtrls
);
448 (*pCtrls
)->dispose();
452 // Delete all structures
453 DELETEZ( mpControls
);
454 mpControls
= new UnoControlHolderList
;
456 UnoControlBase::dispose();
459 // lang::XEventListener
460 void UnoControlContainer::disposing( const lang::EventObject
& _rEvt
) throw(uno::RuntimeException
, std::exception
)
462 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
464 uno::Reference
< awt::XControl
> xControl( _rEvt
.Source
, uno::UNO_QUERY
);
466 removeControl( xControl
);
468 UnoControlBase::disposing( _rEvt
);
471 // container::XContainer
472 void UnoControlContainer::addContainerListener( const uno::Reference
< container::XContainerListener
>& rxListener
) throw(uno::RuntimeException
, std::exception
)
474 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
476 maCListeners
.addInterface( rxListener
);
479 void UnoControlContainer::removeContainerListener( const uno::Reference
< container::XContainerListener
>& rxListener
) throw(uno::RuntimeException
, std::exception
)
481 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
483 maCListeners
.removeInterface( rxListener
);
487 ::sal_Int32 SAL_CALL
UnoControlContainer::insert( const uno::Any
& _rElement
) throw (lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
489 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
491 uno::Reference
< awt::XControl
> xControl
;
492 if ( !( _rElement
>>= xControl
) || !xControl
.is() )
493 throw lang::IllegalArgumentException(
494 OUString( "Elements must support the XControl interface." ),
499 return impl_addControl( xControl
, NULL
);
502 void SAL_CALL
UnoControlContainer::removeByIdentifier( ::sal_Int32 _nIdentifier
) throw (container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
504 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
506 uno::Reference
< awt::XControl
> xControl
;
507 if ( !mpControls
->getControlForIdentifier( _nIdentifier
, xControl
) )
508 throw container::NoSuchElementException(
509 OUString( "There is no element with the given identifier." ),
513 impl_removeControl( _nIdentifier
, xControl
, NULL
);
516 void SAL_CALL
UnoControlContainer::replaceByIdentifer( ::sal_Int32 _nIdentifier
, const uno::Any
& _rElement
) throw (lang::IllegalArgumentException
, container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
518 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
520 uno::Reference
< awt::XControl
> xExistentControl
;
521 if ( !mpControls
->getControlForIdentifier( _nIdentifier
, xExistentControl
) )
522 throw container::NoSuchElementException(
523 OUString( "There is no element with the given identifier." ),
527 uno::Reference
< awt::XControl
> xNewControl
;
528 if ( !( _rElement
>>= xNewControl
) )
529 throw lang::IllegalArgumentException(
530 OUString( "Elements must support the XControl interface." ),
535 removingControl( xExistentControl
);
537 mpControls
->replaceControlById( _nIdentifier
, xNewControl
);
539 addingControl( xNewControl
);
541 impl_createControlPeerIfNecessary( xNewControl
);
543 if ( maCListeners
.getLength() )
545 container::ContainerEvent aEvent
;
546 aEvent
.Source
= *this;
547 aEvent
.Accessor
<<= _nIdentifier
;
548 aEvent
.Element
<<= xNewControl
;
549 aEvent
.ReplacedElement
<<= xExistentControl
;
550 maCListeners
.elementReplaced( aEvent
);
554 uno::Any SAL_CALL
UnoControlContainer::getByIdentifier( ::sal_Int32 _nIdentifier
) throw (container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
556 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
558 uno::Reference
< awt::XControl
> xControl
;
559 if ( !mpControls
->getControlForIdentifier( _nIdentifier
, xControl
) )
560 throw container::NoSuchElementException();
561 return uno::makeAny( xControl
);
564 uno::Sequence
< ::sal_Int32
> SAL_CALL
UnoControlContainer::getIdentifiers( ) throw (uno::RuntimeException
, std::exception
)
566 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
568 uno::Sequence
< ::sal_Int32
> aIdentifiers
;
569 mpControls
->getIdentifiers( aIdentifiers
);
573 // container::XElementAccess
574 uno::Type SAL_CALL
UnoControlContainer::getElementType( ) throw (uno::RuntimeException
, std::exception
)
576 return cppu::UnoType
<awt::XControlModel
>::get();
579 sal_Bool SAL_CALL
UnoControlContainer::hasElements( ) throw (uno::RuntimeException
, std::exception
)
581 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
582 return !mpControls
->empty();
585 // awt::XControlContainer
586 void UnoControlContainer::setStatusText( const OUString
& rStatusText
) throw(uno::RuntimeException
, std::exception
)
588 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
590 // Descend the parent hierarchy
591 uno::Reference
< awt::XControlContainer
> xContainer( mxContext
, uno::UNO_QUERY
);
592 if( xContainer
.is() )
593 xContainer
->setStatusText( rStatusText
);
596 uno::Sequence
< uno::Reference
< awt::XControl
> > UnoControlContainer::getControls( ) throw(uno::RuntimeException
, std::exception
)
598 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
599 uno::Sequence
< uno::Reference
< awt::XControl
> > aControls
;
600 mpControls
->getControls( aControls
);
604 uno::Reference
< awt::XControl
> UnoControlContainer::getControl( const OUString
& rName
) throw(uno::RuntimeException
, std::exception
)
606 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
607 return mpControls
->getControlForName( rName
);
610 void UnoControlContainer::addingControl( const uno::Reference
< awt::XControl
>& _rxControl
)
612 if ( _rxControl
.is() )
614 uno::Reference
< uno::XInterface
> xThis
;
615 OWeakAggObject::queryInterface( cppu::UnoType
<uno::XInterface
>::get() ) >>= xThis
;
617 _rxControl
->setContext( xThis
);
618 _rxControl
->addEventListener( this );
622 void UnoControlContainer::impl_createControlPeerIfNecessary( const uno::Reference
< awt::XControl
>& _rxControl
)
624 OSL_PRECOND( _rxControl
.is(), "UnoControlContainer::impl_createControlPeerIfNecessary: invalid control, this will crash!" );
626 // if the container already has a peer, then also create a peer for the control
627 uno::Reference
< awt::XWindowPeer
> xMyPeer( getPeer() );
631 _rxControl
->createPeer( NULL
, xMyPeer
);
632 ImplActivateTabControllers();
637 sal_Int32
UnoControlContainer::impl_addControl( const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pName
)
639 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
640 UnoControlHolderList::ControlIdentifier id
= mpControls
->addControl( _rxControl
, _pName
);
642 addingControl( _rxControl
);
644 impl_createControlPeerIfNecessary( _rxControl
);
646 if ( maCListeners
.getLength() )
648 container::ContainerEvent aEvent
;
649 aEvent
.Source
= *this;
650 _pName
? ( aEvent
.Accessor
<<= *_pName
) : ( aEvent
.Accessor
<<= (sal_Int32
)id
);
651 aEvent
.Element
<<= _rxControl
;
652 maCListeners
.elementInserted( aEvent
);
658 void UnoControlContainer::addControl( const OUString
& rName
, const uno::Reference
< awt::XControl
>& rControl
) throw(uno::RuntimeException
, std::exception
)
661 impl_addControl( rControl
, &rName
);
664 void UnoControlContainer::removingControl( const uno::Reference
< awt::XControl
>& _rxControl
)
666 if ( _rxControl
.is() )
668 _rxControl
->removeEventListener( this );
669 _rxControl
->setContext( NULL
);
673 void UnoControlContainer::impl_removeControl( sal_Int32 _nId
, const uno::Reference
< awt::XControl
>& _rxControl
, const OUString
* _pNameAccessor
)
677 uno::Reference
< awt::XControl
> xControl
;
678 bool bHas
= mpControls
->getControlForIdentifier( _nId
, xControl
);
679 DBG_ASSERT( bHas
&& xControl
== _rxControl
, "UnoControlContainer::impl_removeControl: inconsistency in the parameters!" );
682 removingControl( _rxControl
);
684 mpControls
->removeControlById( _nId
);
686 if ( maCListeners
.getLength() )
688 container::ContainerEvent aEvent
;
689 aEvent
.Source
= *this;
690 _pNameAccessor
? ( aEvent
.Accessor
<<= *_pNameAccessor
) : ( aEvent
.Accessor
<<= _nId
);
691 aEvent
.Element
<<= _rxControl
;
692 maCListeners
.elementRemoved( aEvent
);
696 void UnoControlContainer::removeControl( const uno::Reference
< awt::XControl
>& _rxControl
) throw(uno::RuntimeException
, std::exception
)
698 if ( _rxControl
.is() )
700 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
702 UnoControlHolderList::ControlIdentifier id
= mpControls
->getControlIdentifier( _rxControl
);
704 impl_removeControl( id
, _rxControl
, NULL
);
710 // awt::XUnoControlContainer
711 void UnoControlContainer::setTabControllers( const uno::Sequence
< uno::Reference
< awt::XTabController
> >& TabControllers
) throw(uno::RuntimeException
, std::exception
)
713 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
715 maTabControllers
= TabControllers
;
718 uno::Sequence
< uno::Reference
< awt::XTabController
> > UnoControlContainer::getTabControllers( ) throw(uno::RuntimeException
, std::exception
)
720 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
722 return maTabControllers
;
725 void UnoControlContainer::addTabController( const uno::Reference
< awt::XTabController
>& TabController
) throw(uno::RuntimeException
, std::exception
)
727 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
729 sal_uInt32 nCount
= maTabControllers
.getLength();
730 maTabControllers
.realloc( nCount
+ 1 );
731 maTabControllers
[ nCount
] = TabController
;
734 void UnoControlContainer::removeTabController( const uno::Reference
< awt::XTabController
>& TabController
) throw(uno::RuntimeException
, std::exception
)
736 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
738 sal_uInt32 nCount
= maTabControllers
.getLength();
739 const uno::Reference
< awt::XTabController
>* pLoop
= maTabControllers
.getConstArray();
740 for ( sal_uInt32 n
= 0; n
< nCount
; ++n
, ++pLoop
)
742 if( pLoop
->get() == TabController
.get() )
744 ::comphelper::removeElementAt( maTabControllers
, n
);
751 void UnoControlContainer::createPeer( const uno::Reference
< awt::XToolkit
>& rxToolkit
, const uno::Reference
< awt::XWindowPeer
>& rParent
) throw(uno::RuntimeException
, std::exception
)
753 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
755 if( !getPeer().is() )
757 bool bVis
= maComponentInfos
.bVisible
;
759 UnoControl::setVisible( sal_False
);
761 uno::Reference
< beans::XPropertySet
> xTmpPropSet
762 ( getModel(), uno::UNO_QUERY
);
765 UnoControl::createPeer( rxToolkit
, rParent
);
767 // Create all children's peers
768 if ( !mbCreatingCompatiblePeer
)
770 // Evaluate "Step" property
771 uno::Reference
< awt::XControlModel
> xModel( getModel() );
772 uno::Reference
< beans::XPropertySet
> xPSet
773 ( xModel
, uno::UNO_QUERY
);
774 uno::Reference
< beans::XPropertySetInfo
>
775 xInfo
= xPSet
->getPropertySetInfo();
776 OUString
aPropName( "Step" );
777 if ( xInfo
->hasPropertyByName( aPropName
) )
779 ::com::sun::star::uno::Any aVal
= xPSet
->getPropertyValue( aPropName
);
780 sal_Int32 nDialogStep
= 0;
781 aVal
>>= nDialogStep
;
782 uno::Reference
< awt::XControlContainer
> xContainer
=
783 (static_cast< awt::XControlContainer
* >(this));
784 implUpdateVisibility( nDialogStep
, xContainer
);
786 uno::Reference
< beans::XPropertyChangeListener
> xListener
=
787 (static_cast< beans::XPropertyChangeListener
* >(
788 new DialogStepChangedListener( xContainer
) ) );
789 xPSet
->addPropertyChangeListener( aPropName
, xListener
);
792 uno::Sequence
< uno::Reference
< awt::XControl
> > aCtrls
= getControls();
793 sal_uInt32 nCtrls
= aCtrls
.getLength();
794 for( sal_uInt32 n
= 0; n
< nCtrls
; n
++ )
795 aCtrls
.getArray()[n
]->createPeer( rxToolkit
, getPeer() );
797 uno::Reference
< awt::XVclContainerPeer
> xC( getPeer(), uno::UNO_QUERY
);
799 xC
->enableDialogControl( sal_True
);
800 ImplActivateTabControllers();
803 if( bVis
&& !isDesignMode() )
804 UnoControl::setVisible( sal_True
);
810 void UnoControlContainer::setVisible( sal_Bool bVisible
) throw(uno::RuntimeException
, std::exception
)
812 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
814 UnoControl::setVisible( bVisible
);
815 if( !mxContext
.is() && bVisible
)
816 // This is a Topwindow, thus show it automatically
817 createPeer( uno::Reference
< awt::XToolkit
> (), uno::Reference
< awt::XWindowPeer
> () );
820 OUString
UnoControlContainer::getImplementationName()
821 throw (css::uno::RuntimeException
, std::exception
)
823 return OUString("stardiv.Toolkit.UnoControlContainer");
826 css::uno::Sequence
<OUString
> UnoControlContainer::getSupportedServiceNames()
827 throw (css::uno::RuntimeException
, std::exception
)
829 auto s(UnoControlBase::getSupportedServiceNames());
830 s
.realloc(s
.getLength() + 2);
831 s
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlContainer";
832 s
[s
.getLength() - 1] = "stardiv.vcl.control.ControlContainer";
836 void UnoControlContainer::PrepareWindowDescriptor( ::com::sun::star::awt::WindowDescriptor
& rDesc
)
838 // HACK due to the fact that we can't really use VSCROLL & HSCROLL
839 // for Dialog ( ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL
840 // has the same value as
841 // ::com::sun::star::awt::WindowAttribute::NODECORATION )
842 // For convenience in the PropBrowse using HSCROLL and VSCROLL ensures
843 // the Correct text. We exchange them here and the control knows
844 // about this hack ( it sucks badly I know )
845 if ( rDesc
.WindowAttributes
& ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL
)
847 rDesc
.WindowAttributes
&= ~::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL
;
848 rDesc
.WindowAttributes
|= ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL
;
850 if ( rDesc
.WindowAttributes
& ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL
)
852 rDesc
.WindowAttributes
&= ~::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL
;
853 rDesc
.WindowAttributes
|= ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL
;
857 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
858 stardiv_Toolkit_UnoControlContainer_get_implementation(
859 css::uno::XComponentContext
*,
860 css::uno::Sequence
<css::uno::Any
> const &)
862 return cppu::acquire(new UnoControlContainer());
865 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */