Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / toolkit / source / controls / unocontrolcontainer.cxx
blobe1b0a5a13eb65fa107584499d5887f77e3374087
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/container/NoSuchElementException.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <cppuhelper/typeprovider.hxx>
26 #include <cppuhelper/implbase.hxx>
27 #include <rtl/uuid.h>
29 #include <toolkit/controls/unocontrolcontainer.hxx>
30 #include <toolkit/helper/property.hxx>
31 #include <toolkit/helper/servicenames.hxx>
32 #include <comphelper/sequence.hxx>
34 #include <tools/debug.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/window.hxx>
38 #include <limits>
39 #include <map>
40 #include <memory>
41 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
43 using namespace ::com::sun::star;
46 // class UnoControlHolder
48 struct UnoControlHolder
50 uno::Reference< awt::XControl > mxControl;
51 OUString msName;
53 public:
54 UnoControlHolder( const OUString& rName, const uno::Reference< awt::XControl > & rControl )
55 : mxControl( rControl ),
56 msName( rName )
60 const OUString& getName() const { return msName; }
61 const uno::Reference< awt::XControl >& getControl() const { return mxControl; }
64 class UnoControlHolderList
66 public:
67 typedef sal_Int32 ControlIdentifier;
68 private:
69 typedef std::shared_ptr< UnoControlHolder > ControlInfo;
70 typedef ::std::map< ControlIdentifier, ControlInfo > ControlMap;
72 private:
73 ControlMap maControls;
75 public:
76 UnoControlHolderList();
78 /** adds a control with the given name to the list
79 @param _rxControl
80 the control to add. Must not be <NULL/>
81 @param _pBName
82 the name of the control, or <NULL/> if an automatic name should be generated
83 @return
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 bool empty() const { return maControls.empty(); }
92 /** retrieves all controls currently in the list
94 void getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const;
96 /** retrieves all identifiers of all controls currently in the list
98 void getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const;
100 /** returns the first control which is registered under the given name
102 uno::Reference< awt::XControl >
103 getControlForName( const OUString& _rName ) const;
105 /** returns the identifier which a control is registered for, or -1 if the control
106 isn't registered
108 ControlIdentifier
109 getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl );
111 /** retrieves the control for a given id
112 @param _nIdentifier
113 the identifier for the control
114 @param _out_rxControl
115 takes the XControl upon successful return
116 @return
117 <TRUE/> if and only if a control with the given id is part of the list
119 bool getControlForIdentifier( ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const;
121 /** removes a control from the list, given by id
122 @param _nId
123 The identifier of the control to remove.
125 void removeControlById( ControlIdentifier _nId );
127 /** replaces a control from the list with another one
128 @param _nId
129 The identifier of the control to replace
130 @param _rxNewControl
131 the new control to put into the list
133 void replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl );
135 private:
136 /** adds a control
137 @param _rxControl
138 the control to add to the container
139 @param _pName
140 pointer to the name of the control. Might be <NULL/>, in this case, a name is generated.
141 @return
142 the identifier of the newly inserted control
144 ControlIdentifier impl_addControl(
145 const uno::Reference< awt::XControl >& _rxControl,
146 const OUString* _pName
149 /** finds a free identifier
150 @throw uno::RuntimeException
151 if no free identifier can be found
153 ControlIdentifier impl_getFreeIdentifier_throw();
155 /** finds a free name
156 @throw uno::RuntimeException
157 if no free name can be found
159 OUString impl_getFreeName_throw();
163 UnoControlHolderList::UnoControlHolderList()
168 UnoControlHolderList::ControlIdentifier UnoControlHolderList::addControl( const uno::Reference< awt::XControl >& _rxControl, const OUString* _pName )
170 return impl_addControl( _rxControl, _pName );
174 void UnoControlHolderList::getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const
176 _out_rControls.realloc( maControls.size() );
177 uno::Reference< awt::XControl >* pControls = _out_rControls.getArray();
178 for ( ControlMap::const_iterator loop = maControls.begin();
179 loop != maControls.end();
180 ++loop, ++pControls
182 *pControls = loop->second->getControl();
186 void UnoControlHolderList::getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const
188 _out_rIdentifiers.realloc( maControls.size() );
189 sal_Int32* pIndentifiers = _out_rIdentifiers.getArray();
190 for ( ControlMap::const_iterator loop = maControls.begin();
191 loop != maControls.end();
192 ++loop, ++pIndentifiers
194 *pIndentifiers = loop->first;
198 uno::Reference< awt::XControl > UnoControlHolderList::getControlForName( const OUString& _rName ) const
200 for ( ControlMap::const_iterator loop = maControls.begin();
201 loop != maControls.end();
202 ++loop
204 if ( loop->second->getName() == _rName )
205 return loop->second->getControl();
206 return uno::Reference< awt::XControl >();
210 UnoControlHolderList::ControlIdentifier UnoControlHolderList::getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl )
212 for ( ControlMap::iterator loop = maControls.begin();
213 loop != maControls.end();
214 ++loop
217 if ( loop->second->getControl().get() == _rxControl.get() )
218 return loop->first;
220 return -1;
224 bool UnoControlHolderList::getControlForIdentifier( UnoControlHolderList::ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const
226 ControlMap::const_iterator pos = maControls.find( _nIdentifier );
227 if ( pos == maControls.end() )
228 return false;
229 _out_rxControl = pos->second->getControl();
230 return true;
234 void UnoControlHolderList::removeControlById( UnoControlHolderList::ControlIdentifier _nId )
236 ControlMap::iterator pos = maControls.find( _nId );
237 DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::removeControlById: invalid id!" );
238 if ( pos == maControls.end() )
239 return;
241 maControls.erase( pos );
245 void UnoControlHolderList::replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl )
247 DBG_ASSERT( _rxNewControl.is(), "UnoControlHolderList::replaceControlById: invalid new control!" );
249 ControlMap::iterator pos = maControls.find( _nId );
250 DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::replaceControlById: invalid id!" );
251 if ( pos == maControls.end() )
252 return;
254 pos->second.reset( new UnoControlHolder( pos->second->getName(), _rxNewControl ) );
258 UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const OUString* _pName )
260 DBG_ASSERT( _rxControl.is(), "UnoControlHolderList::impl_addControl: invalid control!" );
262 OUString sName = _pName ? *_pName : impl_getFreeName_throw();
263 sal_Int32 nId = impl_getFreeIdentifier_throw();
265 maControls[ nId ] = std::make_shared<UnoControlHolder>( sName, _rxControl );
266 return nId;
270 UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_getFreeIdentifier_throw()
272 for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
274 ControlMap::const_iterator existent = maControls.find( candidateId );
275 if ( existent == maControls.end() )
276 return candidateId;
278 throw uno::RuntimeException("out of identifiers" );
282 OUString UnoControlHolderList::impl_getFreeName_throw()
284 OUString name( "control_" );
285 for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
287 OUString candidateName( name + OUString::number( candidateId ) );
288 ControlMap::const_iterator loop = maControls.begin();
289 for ( ; loop != maControls.end(); ++loop )
291 if ( loop->second->getName() == candidateName )
292 break;
294 if ( loop == maControls.end() )
295 return candidateName;
297 throw uno::RuntimeException("out of identifiers" );
300 // Function to set the controls' visibility according
301 // to the dialog's "Step" property
303 void implUpdateVisibility
305 sal_Int32 nDialogStep,
306 const uno::Reference< awt::XControlContainer >& xControlContainer
309 uno::Sequence< uno::Reference< awt::XControl > >
310 aCtrls = xControlContainer->getControls();
311 const uno::Reference< awt::XControl >* pCtrls = aCtrls.getConstArray();
312 sal_uInt32 nCtrls = aCtrls.getLength();
313 bool bCompleteVisible = (nDialogStep == 0);
314 for( sal_uInt32 n = 0; n < nCtrls; n++ )
316 uno::Reference< awt::XControl > xControl = pCtrls[ n ];
318 bool bVisible = bCompleteVisible;
319 if( !bVisible )
321 uno::Reference< awt::XControlModel > xModel( xControl->getModel() );
322 uno::Reference< beans::XPropertySet > xPSet
323 ( xModel, uno::UNO_QUERY );
324 uno::Reference< beans::XPropertySetInfo >
325 xInfo = xPSet->getPropertySetInfo();
326 OUString aPropName( "Step" );
327 sal_Int32 nControlStep = 0;
328 if ( xInfo->hasPropertyByName( aPropName ) )
330 uno::Any aVal = xPSet->getPropertyValue( aPropName );
331 aVal >>= nControlStep;
333 bVisible = (nControlStep == 0) || (nControlStep == nDialogStep);
336 uno::Reference< awt::XWindow> xWindow
337 ( xControl, uno::UNO_QUERY );
338 if( xWindow.is() )
339 xWindow->setVisible( bVisible );
344 // class DialogStepChangedListener
346 typedef ::cppu::WeakImplHelper< beans::XPropertyChangeListener > PropertyChangeListenerHelper;
348 class DialogStepChangedListener: public PropertyChangeListenerHelper
350 private:
351 uno::Reference< awt::XControlContainer > mxControlContainer;
353 public:
354 explicit DialogStepChangedListener( uno::Reference< awt::XControlContainer > const & xControlContainer )
355 : mxControlContainer( xControlContainer ) {}
357 // XEventListener
358 virtual void SAL_CALL disposing( const lang::EventObject& Source ) override;
360 // XPropertyChangeListener
361 virtual void SAL_CALL propertyChange( const beans::PropertyChangeEvent& evt ) override;
365 void SAL_CALL DialogStepChangedListener::disposing( const lang::EventObject& /*_rSource*/)
367 mxControlContainer.clear();
370 void SAL_CALL DialogStepChangedListener::propertyChange( const beans::PropertyChangeEvent& evt )
372 // evt.PropertyName HAS to be "Step" because we only use the listener for that
373 sal_Int32 nDialogStep = 0;
374 evt.NewValue >>= nDialogStep;
375 implUpdateVisibility( nDialogStep, mxControlContainer );
379 // class UnoControlContainer
381 UnoControlContainer::UnoControlContainer()
382 :UnoControlContainer_Base()
383 ,maCListeners( *this )
385 mpControls = new UnoControlHolderList;
388 UnoControlContainer::UnoControlContainer(const uno::Reference< awt::XWindowPeer >& xP )
389 :UnoControlContainer_Base()
390 ,maCListeners( *this )
392 setPeer( xP );
393 mbDisposePeer = false;
394 mpControls = new UnoControlHolderList;
397 UnoControlContainer::~UnoControlContainer()
399 DELETEZ( mpControls );
402 void UnoControlContainer::ImplActivateTabControllers()
404 sal_uInt32 nCount = maTabControllers.getLength();
405 for ( sal_uInt32 n = 0; n < nCount; n++ )
407 maTabControllers.getArray()[n]->setContainer( this );
408 maTabControllers.getArray()[n]->activateTabOrder();
412 // lang::XComponent
413 void UnoControlContainer::dispose( )
415 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
417 lang::EventObject aDisposeEvent;
418 aDisposeEvent.Source = static_cast< uno::XAggregation* >( this );
420 // Notify listeners about disposal of this Container (This is much faster if they
421 // listen on the controls and the container).
422 maDisposeListeners.disposeAndClear( aDisposeEvent );
423 maCListeners.disposeAndClear( aDisposeEvent );
426 uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
427 uno::Reference< awt::XControl >* pCtrls = aCtrls.getArray();
428 uno::Reference< awt::XControl >* pCtrlsEnd = pCtrls + aCtrls.getLength();
430 for( ; pCtrls < pCtrlsEnd; ++pCtrls )
432 removingControl( *pCtrls );
433 // Delete control
434 (*pCtrls)->dispose();
438 // Delete all structures
439 DELETEZ( mpControls );
440 mpControls = new UnoControlHolderList;
442 UnoControlBase::dispose();
445 // lang::XEventListener
446 void UnoControlContainer::disposing( const lang::EventObject& _rEvt )
448 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
450 uno::Reference< awt::XControl > xControl( _rEvt.Source, uno::UNO_QUERY );
451 if ( xControl.is() )
452 removeControl( xControl );
454 UnoControlBase::disposing( _rEvt );
457 // container::XContainer
458 void UnoControlContainer::addContainerListener( const uno::Reference< container::XContainerListener >& rxListener )
460 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
462 maCListeners.addInterface( rxListener );
465 void UnoControlContainer::removeContainerListener( const uno::Reference< container::XContainerListener >& rxListener )
467 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
469 maCListeners.removeInterface( rxListener );
473 ::sal_Int32 SAL_CALL UnoControlContainer::insert( const uno::Any& _rElement )
475 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
477 uno::Reference< awt::XControl > xControl;
478 if ( !( _rElement >>= xControl ) || !xControl.is() )
479 throw lang::IllegalArgumentException(
480 "Elements must support the XControl interface.",
481 *this,
485 return impl_addControl( xControl );
488 void SAL_CALL UnoControlContainer::removeByIdentifier( ::sal_Int32 _nIdentifier )
490 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
492 uno::Reference< awt::XControl > xControl;
493 if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
494 throw container::NoSuchElementException(
495 "There is no element with the given identifier.",
496 *this
499 impl_removeControl( _nIdentifier, xControl );
502 void SAL_CALL UnoControlContainer::replaceByIdentifer( ::sal_Int32 _nIdentifier, const uno::Any& _rElement )
504 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
506 uno::Reference< awt::XControl > xExistentControl;
507 if ( !mpControls->getControlForIdentifier( _nIdentifier, xExistentControl ) )
508 throw container::NoSuchElementException(
509 "There is no element with the given identifier.",
510 *this
513 uno::Reference< awt::XControl > xNewControl;
514 if ( !( _rElement >>= xNewControl ) )
515 throw lang::IllegalArgumentException(
516 "Elements must support the XControl interface.",
517 *this,
521 removingControl( xExistentControl );
523 mpControls->replaceControlById( _nIdentifier, xNewControl );
525 addingControl( xNewControl );
527 impl_createControlPeerIfNecessary( xNewControl );
529 if ( maCListeners.getLength() )
531 container::ContainerEvent aEvent;
532 aEvent.Source = *this;
533 aEvent.Accessor <<= _nIdentifier;
534 aEvent.Element <<= xNewControl;
535 aEvent.ReplacedElement <<= xExistentControl;
536 maCListeners.elementReplaced( aEvent );
540 uno::Any SAL_CALL UnoControlContainer::getByIdentifier( ::sal_Int32 _nIdentifier )
542 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
544 uno::Reference< awt::XControl > xControl;
545 if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
546 throw container::NoSuchElementException();
547 return uno::makeAny( xControl );
550 uno::Sequence< ::sal_Int32 > SAL_CALL UnoControlContainer::getIdentifiers( )
552 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
554 uno::Sequence< ::sal_Int32 > aIdentifiers;
555 mpControls->getIdentifiers( aIdentifiers );
556 return aIdentifiers;
559 // container::XElementAccess
560 uno::Type SAL_CALL UnoControlContainer::getElementType( )
562 return cppu::UnoType<awt::XControlModel>::get();
565 sal_Bool SAL_CALL UnoControlContainer::hasElements( )
567 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
568 return !mpControls->empty();
571 // awt::XControlContainer
572 void UnoControlContainer::setStatusText( const OUString& rStatusText )
574 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
576 // Descend the parent hierarchy
577 uno::Reference< awt::XControlContainer > xContainer( mxContext, uno::UNO_QUERY );
578 if( xContainer.is() )
579 xContainer->setStatusText( rStatusText );
582 uno::Sequence< uno::Reference< awt::XControl > > UnoControlContainer::getControls( )
584 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
585 uno::Sequence< uno::Reference< awt::XControl > > aControls;
586 mpControls->getControls( aControls );
587 return aControls;
590 uno::Reference< awt::XControl > UnoControlContainer::getControl( const OUString& rName )
592 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
593 return mpControls->getControlForName( rName );
596 void UnoControlContainer::addingControl( const uno::Reference< awt::XControl >& _rxControl )
598 if ( _rxControl.is() )
600 uno::Reference< uno::XInterface > xThis;
601 OWeakAggObject::queryInterface( cppu::UnoType<uno::XInterface>::get() ) >>= xThis;
603 _rxControl->setContext( xThis );
604 _rxControl->addEventListener( this );
608 void UnoControlContainer::impl_createControlPeerIfNecessary( const uno::Reference< awt::XControl >& _rxControl )
610 OSL_PRECOND( _rxControl.is(), "UnoControlContainer::impl_createControlPeerIfNecessary: invalid control, this will crash!" );
612 // if the container already has a peer, then also create a peer for the control
613 uno::Reference< awt::XWindowPeer > xMyPeer( getPeer() );
615 if( xMyPeer.is() )
617 _rxControl->createPeer( nullptr, xMyPeer );
618 ImplActivateTabControllers();
623 sal_Int32 UnoControlContainer::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const OUString* _pName )
625 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
626 UnoControlHolderList::ControlIdentifier id = mpControls->addControl( _rxControl, _pName );
628 addingControl( _rxControl );
630 impl_createControlPeerIfNecessary( _rxControl );
632 if ( maCListeners.getLength() )
634 container::ContainerEvent aEvent;
635 aEvent.Source = *this;
636 _pName ? ( aEvent.Accessor <<= *_pName ) : ( aEvent.Accessor <<= (sal_Int32)id );
637 aEvent.Element <<= _rxControl;
638 maCListeners.elementInserted( aEvent );
641 return id;
644 void UnoControlContainer::addControl( const OUString& rName, const uno::Reference< awt::XControl >& rControl )
646 if ( rControl.is() )
647 impl_addControl( rControl, &rName );
650 void UnoControlContainer::removingControl( const uno::Reference< awt::XControl >& _rxControl )
652 if ( _rxControl.is() )
654 _rxControl->removeEventListener( this );
655 _rxControl->setContext( nullptr );
659 void UnoControlContainer::impl_removeControl( sal_Int32 _nId, const uno::Reference< awt::XControl >& _rxControl )
661 #ifdef DBG_UTIL
663 uno::Reference< awt::XControl > xControl;
664 bool bHas = mpControls->getControlForIdentifier( _nId, xControl );
665 DBG_ASSERT( bHas && xControl == _rxControl, "UnoControlContainer::impl_removeControl: inconsistency in the parameters!" );
667 #endif
668 removingControl( _rxControl );
670 mpControls->removeControlById( _nId );
672 if ( maCListeners.getLength() )
674 container::ContainerEvent aEvent;
675 aEvent.Source = *this;
676 aEvent.Accessor <<= _nId;
677 aEvent.Element <<= _rxControl;
678 maCListeners.elementRemoved( aEvent );
682 void UnoControlContainer::removeControl( const uno::Reference< awt::XControl >& _rxControl )
684 if ( _rxControl.is() )
686 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
688 UnoControlHolderList::ControlIdentifier id = mpControls->getControlIdentifier( _rxControl );
689 if ( id != -1 )
690 impl_removeControl( id, _rxControl );
695 // awt::XUnoControlContainer
696 void UnoControlContainer::setTabControllers( const uno::Sequence< uno::Reference< awt::XTabController > >& TabControllers )
698 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
700 maTabControllers = TabControllers;
703 uno::Sequence< uno::Reference< awt::XTabController > > UnoControlContainer::getTabControllers( )
705 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
707 return maTabControllers;
710 void UnoControlContainer::addTabController( const uno::Reference< awt::XTabController >& TabController )
712 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
714 sal_uInt32 nCount = maTabControllers.getLength();
715 maTabControllers.realloc( nCount + 1 );
716 maTabControllers[ nCount ] = TabController;
719 void UnoControlContainer::removeTabController( const uno::Reference< awt::XTabController >& TabController )
721 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
723 sal_uInt32 nCount = maTabControllers.getLength();
724 const uno::Reference< awt::XTabController >* pLoop = maTabControllers.getConstArray();
725 for ( sal_uInt32 n = 0; n < nCount; ++n, ++pLoop )
727 if( pLoop->get() == TabController.get() )
729 ::comphelper::removeElementAt( maTabControllers, n );
730 break;
735 // awt::XControl
736 void UnoControlContainer::createPeer( const uno::Reference< awt::XToolkit >& rxToolkit, const uno::Reference< awt::XWindowPeer >& rParent )
738 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
740 if( !getPeer().is() )
742 bool bVis = maComponentInfos.bVisible;
743 if( bVis )
744 UnoControl::setVisible( false );
746 // Create a new peer
747 UnoControl::createPeer( rxToolkit, rParent );
749 // Create all children's peers
750 if ( !mbCreatingCompatiblePeer )
752 // Evaluate "Step" property
753 uno::Reference< awt::XControlModel > xModel( getModel() );
754 uno::Reference< beans::XPropertySet > xPSet
755 ( xModel, uno::UNO_QUERY );
756 uno::Reference< beans::XPropertySetInfo >
757 xInfo = xPSet->getPropertySetInfo();
758 OUString aPropName( "Step" );
759 if ( xInfo->hasPropertyByName( aPropName ) )
761 css::uno::Any aVal = xPSet->getPropertyValue( aPropName );
762 sal_Int32 nDialogStep = 0;
763 aVal >>= nDialogStep;
764 uno::Reference< awt::XControlContainer > xContainer =
765 (static_cast< awt::XControlContainer* >(this));
766 implUpdateVisibility( nDialogStep, xContainer );
768 uno::Reference< beans::XPropertyChangeListener > xListener =
769 (static_cast< beans::XPropertyChangeListener* >(
770 new DialogStepChangedListener( xContainer ) ) );
771 xPSet->addPropertyChangeListener( aPropName, xListener );
774 uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
775 sal_uInt32 nCtrls = aCtrls.getLength();
776 for( sal_uInt32 n = 0; n < nCtrls; n++ )
777 aCtrls.getArray()[n]->createPeer( rxToolkit, getPeer() );
779 uno::Reference< awt::XVclContainerPeer > xC( getPeer(), uno::UNO_QUERY );
780 if ( xC.is() )
781 xC->enableDialogControl( true );
782 ImplActivateTabControllers();
785 if( bVis && !isDesignMode() )
786 UnoControl::setVisible( true );
791 // awt::XWindow
792 void UnoControlContainer::setVisible( sal_Bool bVisible )
794 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
796 UnoControl::setVisible( bVisible );
797 if( !mxContext.is() && bVisible )
798 // This is a Topwindow, thus show it automatically
799 createPeer( uno::Reference< awt::XToolkit > (), uno::Reference< awt::XWindowPeer > () );
802 OUString UnoControlContainer::getImplementationName()
804 return OUString("stardiv.Toolkit.UnoControlContainer");
807 css::uno::Sequence<OUString> UnoControlContainer::getSupportedServiceNames()
809 auto s(UnoControlBase::getSupportedServiceNames());
810 s.realloc(s.getLength() + 2);
811 s[s.getLength() - 2] = "com.sun.star.awt.UnoControlContainer";
812 s[s.getLength() - 1] = "stardiv.vcl.control.ControlContainer";
813 return s;
816 void UnoControlContainer::PrepareWindowDescriptor( css::awt::WindowDescriptor& rDesc )
818 // HACK due to the fact that we can't really use VSCROLL & HSCROLL
819 // for Dialog ( css::awt::VclWindowPeerAttribute::VSCROLL
820 // has the same value as
821 // css::awt::WindowAttribute::NODECORATION )
822 // For convenience in the PropBrowse using HSCROLL and VSCROLL ensures
823 // the Correct text. We exchange them here and the control knows
824 // about this hack ( it sucks badly I know )
825 if ( rDesc.WindowAttributes & css::awt::VclWindowPeerAttribute::VSCROLL )
827 rDesc.WindowAttributes &= ~css::awt::VclWindowPeerAttribute::VSCROLL;
828 rDesc.WindowAttributes |= css::awt::VclWindowPeerAttribute::AUTOVSCROLL;
830 if ( rDesc.WindowAttributes & css::awt::VclWindowPeerAttribute::HSCROLL )
832 rDesc.WindowAttributes &= ~css::awt::VclWindowPeerAttribute::HSCROLL;
833 rDesc.WindowAttributes |= css::awt::VclWindowPeerAttribute::AUTOHSCROLL;
837 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
838 stardiv_Toolkit_UnoControlContainer_get_implementation(
839 css::uno::XComponentContext *,
840 css::uno::Sequence<css::uno::Any> const &)
842 return cppu::acquire(new UnoControlContainer());
845 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */