Avoid potential negative array index access to cached text.
[LibreOffice.git] / toolkit / source / controls / unocontrolcontainer.cxx
blob1610f36629e16f772bd6689b87e40bce3a99a60e
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/XPropertySet.hpp>
22 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
23 #include <com/sun/star/container/NoSuchElementException.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <cppuhelper/implbase.hxx>
28 #include <controls/unocontrolcontainer.hxx>
29 #include <comphelper/sequence.hxx>
31 #include <tools/debug.hxx>
33 #include <limits>
34 #include <map>
35 #include <memory>
36 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
37 #include <utility>
39 using namespace ::com::sun::star;
43 namespace {
45 struct UnoControlHolder
47 uno::Reference< awt::XControl > mxControl;
48 OUString msName;
50 public:
51 UnoControlHolder( OUString aName, uno::Reference< awt::XControl > xControl )
52 : mxControl(std::move( xControl )),
53 msName(std::move( aName ))
57 const OUString& getName() const { return msName; }
58 const uno::Reference< awt::XControl >& getControl() const { return mxControl; }
63 class UnoControlHolderList
65 public:
66 typedef sal_Int32 ControlIdentifier;
67 private:
68 typedef std::shared_ptr< UnoControlHolder > ControlInfo;
69 typedef ::std::map< ControlIdentifier, ControlInfo > ControlMap;
71 private:
72 ControlMap maControls;
74 public:
75 UnoControlHolderList();
77 /** adds a control with the given name to the list
78 @param _rxControl
79 the control to add. Must not be <NULL/>
80 @param _pBName
81 the name of the control, or <NULL/> if an automatic name should be generated
82 @return
83 the identifier of the newly added control
85 ControlIdentifier addControl( const uno::Reference< awt::XControl >& _rxControl, const OUString* _pName );
87 /** determines whether or not the list is empty
89 bool empty() const { return maControls.empty(); }
91 /** retrieves all controls currently in the list
93 void getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const;
95 /** retrieves all identifiers of all controls currently in the list
97 void getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const;
99 /** returns the first control which is registered under the given name
101 uno::Reference< awt::XControl >
102 getControlForName( const OUString& _rName ) const;
104 /** returns the identifier which a control is registered for, or -1 if the control
105 isn't registered
107 ControlIdentifier
108 getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl );
110 /** retrieves the control for a given id
111 @param _nIdentifier
112 the identifier for the control
113 @param _out_rxControl
114 takes the XControl upon successful return
115 @return
116 <TRUE/> if and only if a control with the given id is part of the list
118 bool getControlForIdentifier( ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const;
120 /** removes a control from the list, given by id
121 @param _nId
122 The identifier of the control to remove.
124 void removeControlById( ControlIdentifier _nId );
126 /** replaces a control from the list with another one
127 @param _nId
128 The identifier of the control to replace
129 @param _rxNewControl
130 the new control to put into the list
132 void replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl );
134 private:
135 /** adds a control
136 @param _rxControl
137 the control to add to the container
138 @param _pName
139 pointer to the name of the control. Might be <NULL/>, in this case, a name is generated.
140 @return
141 the identifier of the newly inserted control
143 ControlIdentifier impl_addControl(
144 const uno::Reference< awt::XControl >& _rxControl,
145 const OUString* _pName
148 /** finds a free identifier
149 @throw uno::RuntimeException
150 if no free identifier can be found
152 ControlIdentifier impl_getFreeIdentifier_throw();
154 /** finds a free name
155 @throw uno::RuntimeException
156 if no free name can be found
158 OUString impl_getFreeName_throw();
162 UnoControlHolderList::UnoControlHolderList()
167 UnoControlHolderList::ControlIdentifier UnoControlHolderList::addControl( const uno::Reference< awt::XControl >& _rxControl, const OUString* _pName )
169 return impl_addControl( _rxControl, _pName );
173 void UnoControlHolderList::getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const
175 _out_rControls.realloc( maControls.size() );
176 uno::Reference< awt::XControl >* pControls = _out_rControls.getArray();
177 for (const auto& rEntry : maControls)
179 *pControls = rEntry.second->getControl();
180 ++pControls;
185 void UnoControlHolderList::getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const
187 _out_rIdentifiers.realloc( maControls.size() );
188 sal_Int32* pIdentifiers = _out_rIdentifiers.getArray();
189 for (const auto& rEntry : maControls)
191 *pIdentifiers = rEntry.first;
192 ++pIdentifiers;
197 uno::Reference< awt::XControl > UnoControlHolderList::getControlForName( const OUString& _rName ) const
199 auto loop = std::find_if(maControls.begin(), maControls.end(),
200 [&_rName](const ControlMap::value_type& rEntry) { return rEntry.second->getName() == _rName; });
201 if (loop != maControls.end())
202 return loop->second->getControl();
203 return uno::Reference< awt::XControl >();
207 UnoControlHolderList::ControlIdentifier UnoControlHolderList::getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl )
209 auto loop = std::find_if(maControls.begin(), maControls.end(),
210 [&_rxControl](const ControlMap::value_type& rEntry) { return rEntry.second->getControl().get() == _rxControl.get(); });
211 if (loop != maControls.end())
212 return loop->first;
213 return -1;
217 bool UnoControlHolderList::getControlForIdentifier( UnoControlHolderList::ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const
219 ControlMap::const_iterator pos = maControls.find( _nIdentifier );
220 if ( pos == maControls.end() )
221 return false;
222 _out_rxControl = pos->second->getControl();
223 return true;
227 void UnoControlHolderList::removeControlById( UnoControlHolderList::ControlIdentifier _nId )
229 ControlMap::iterator pos = maControls.find( _nId );
230 DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::removeControlById: invalid id!" );
231 if ( pos == maControls.end() )
232 return;
234 maControls.erase( pos );
238 void UnoControlHolderList::replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl )
240 DBG_ASSERT( _rxNewControl.is(), "UnoControlHolderList::replaceControlById: invalid new control!" );
242 ControlMap::iterator pos = maControls.find( _nId );
243 DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::replaceControlById: invalid id!" );
244 if ( pos == maControls.end() )
245 return;
247 pos->second = std::make_shared<UnoControlHolder>( pos->second->getName(), _rxNewControl );
251 UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const OUString* _pName )
253 DBG_ASSERT( _rxControl.is(), "UnoControlHolderList::impl_addControl: invalid control!" );
255 OUString sName = _pName ? *_pName : impl_getFreeName_throw();
256 sal_Int32 nId = impl_getFreeIdentifier_throw();
258 maControls[ nId ] = std::make_shared<UnoControlHolder>( sName, _rxControl );
259 return nId;
263 UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_getFreeIdentifier_throw()
265 for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
267 ControlMap::const_iterator existent = maControls.find( candidateId );
268 if ( existent == maControls.end() )
269 return candidateId;
271 throw uno::RuntimeException("out of identifiers" );
275 OUString UnoControlHolderList::impl_getFreeName_throw()
277 for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId )
279 OUString candidateName( "control_" + OUString::number( candidateId ) );
280 if ( std::none_of(maControls.begin(), maControls.end(),
281 [&candidateName](const ControlMap::value_type& rEntry) { return rEntry.second->getName() == candidateName; }) )
282 return candidateName;
284 throw uno::RuntimeException("out of identifiers" );
287 // Function to set the controls' visibility according
288 // to the dialog's "Step" property
290 static void implUpdateVisibility
292 sal_Int32 nDialogStep,
293 const uno::Reference< awt::XControlContainer >& xControlContainer
296 const uno::Sequence< uno::Reference< awt::XControl > >
297 aCtrls = xControlContainer->getControls();
298 bool bCompleteVisible = (nDialogStep == 0);
299 for( const uno::Reference< awt::XControl >& xControl : aCtrls )
301 bool bVisible = bCompleteVisible;
302 if( !bVisible )
304 uno::Reference< awt::XControlModel > xModel( xControl->getModel() );
305 uno::Reference< beans::XPropertySet > xPSet
306 ( xModel, uno::UNO_QUERY );
307 uno::Reference< beans::XPropertySetInfo >
308 xInfo = xPSet->getPropertySetInfo();
309 OUString aPropName( "Step" );
310 sal_Int32 nControlStep = 0;
311 if ( xInfo->hasPropertyByName( aPropName ) )
313 uno::Any aVal = xPSet->getPropertyValue( aPropName );
314 aVal >>= nControlStep;
316 bVisible = (nControlStep == 0) || (nControlStep == nDialogStep);
319 uno::Reference< awt::XWindow> xWindow
320 ( xControl, uno::UNO_QUERY );
321 if( xWindow.is() )
322 xWindow->setVisible( bVisible );
328 typedef ::cppu::WeakImplHelper< beans::XPropertyChangeListener > PropertyChangeListenerHelper;
330 namespace {
332 class DialogStepChangedListener: public PropertyChangeListenerHelper
334 private:
335 uno::Reference< awt::XControlContainer > mxControlContainer;
337 public:
338 explicit DialogStepChangedListener( uno::Reference< awt::XControlContainer > xControlContainer )
339 : mxControlContainer(std::move( xControlContainer )) {}
341 // XEventListener
342 virtual void SAL_CALL disposing( const lang::EventObject& Source ) override;
344 // XPropertyChangeListener
345 virtual void SAL_CALL propertyChange( const beans::PropertyChangeEvent& evt ) override;
351 void SAL_CALL DialogStepChangedListener::disposing( const lang::EventObject& /*_rSource*/)
353 mxControlContainer.clear();
356 void SAL_CALL DialogStepChangedListener::propertyChange( const beans::PropertyChangeEvent& evt )
358 // evt.PropertyName HAS to be "Step" because we only use the listener for that
359 sal_Int32 nDialogStep = 0;
360 evt.NewValue >>= nDialogStep;
361 implUpdateVisibility( nDialogStep, mxControlContainer );
366 UnoControlContainer::UnoControlContainer()
367 :maCListeners( *this )
369 mpControls.reset(new UnoControlHolderList);
372 UnoControlContainer::UnoControlContainer(const uno::Reference< awt::XVclWindowPeer >& xP )
373 :maCListeners( *this )
375 setPeer( xP );
376 mbDisposePeer = false;
377 mpControls.reset(new UnoControlHolderList);
380 UnoControlContainer::~UnoControlContainer()
384 void UnoControlContainer::ImplActivateTabControllers()
386 for ( auto& rTabController : asNonConstRange(maTabControllers) )
388 rTabController->setContainer( this );
389 rTabController->activateTabOrder();
393 // lang::XComponent
394 void UnoControlContainer::dispose( )
396 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
398 lang::EventObject aDisposeEvent;
399 aDisposeEvent.Source = static_cast< uno::XAggregation* >( this );
401 // Notify listeners about disposal of this Container (This is much faster if they
402 // listen on the controls and the container).
403 maDisposeListeners.disposeAndClear( aDisposeEvent );
404 maCListeners.disposeAndClear( aDisposeEvent );
407 const uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
409 for( uno::Reference< awt::XControl > const & control : aCtrls )
411 removingControl( control );
412 // Delete control
413 control->dispose();
417 // Delete all structures
418 mpControls.reset(new UnoControlHolderList);
420 UnoControlBase::dispose();
423 // lang::XEventListener
424 void UnoControlContainer::disposing( const lang::EventObject& _rEvt )
426 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
428 uno::Reference< awt::XControl > xControl( _rEvt.Source, uno::UNO_QUERY );
429 if ( xControl.is() )
430 removeControl( xControl );
432 UnoControlBase::disposing( _rEvt );
435 // container::XContainer
436 void UnoControlContainer::addContainerListener( const uno::Reference< container::XContainerListener >& rxListener )
438 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
440 maCListeners.addInterface( rxListener );
443 void UnoControlContainer::removeContainerListener( const uno::Reference< container::XContainerListener >& rxListener )
445 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
447 maCListeners.removeInterface( rxListener );
451 ::sal_Int32 SAL_CALL UnoControlContainer::insert( const uno::Any& _rElement )
453 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
455 uno::Reference< awt::XControl > xControl;
456 if ( !( _rElement >>= xControl ) || !xControl.is() )
457 throw lang::IllegalArgumentException(
458 "Elements must support the XControl interface.",
459 *this,
463 return impl_addControl( xControl );
466 void SAL_CALL UnoControlContainer::removeByIdentifier( ::sal_Int32 _nIdentifier )
468 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
470 uno::Reference< awt::XControl > xControl;
471 if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
472 throw container::NoSuchElementException(
473 "There is no element with the given identifier.",
474 *this
477 impl_removeControl( _nIdentifier, xControl );
480 void SAL_CALL UnoControlContainer::replaceByIdentifer( ::sal_Int32 _nIdentifier, const uno::Any& _rElement )
482 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
484 uno::Reference< awt::XControl > xExistentControl;
485 if ( !mpControls->getControlForIdentifier( _nIdentifier, xExistentControl ) )
486 throw container::NoSuchElementException(
487 "There is no element with the given identifier.",
488 *this
491 uno::Reference< awt::XControl > xNewControl;
492 if ( !( _rElement >>= xNewControl ) )
493 throw lang::IllegalArgumentException(
494 "Elements must support the XControl interface.",
495 *this,
499 removingControl( xExistentControl );
501 mpControls->replaceControlById( _nIdentifier, xNewControl );
503 addingControl( xNewControl );
505 impl_createControlPeerIfNecessary( xNewControl );
507 if ( maCListeners.getLength() )
509 container::ContainerEvent aEvent;
510 aEvent.Source = *this;
511 aEvent.Accessor <<= _nIdentifier;
512 aEvent.Element <<= xNewControl;
513 aEvent.ReplacedElement <<= xExistentControl;
514 maCListeners.elementReplaced( aEvent );
518 uno::Any SAL_CALL UnoControlContainer::getByIdentifier( ::sal_Int32 _nIdentifier )
520 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
522 uno::Reference< awt::XControl > xControl;
523 if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) )
524 throw container::NoSuchElementException();
525 return uno::Any( xControl );
528 uno::Sequence< ::sal_Int32 > SAL_CALL UnoControlContainer::getIdentifiers( )
530 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
532 uno::Sequence< ::sal_Int32 > aIdentifiers;
533 mpControls->getIdentifiers( aIdentifiers );
534 return aIdentifiers;
537 // container::XElementAccess
538 uno::Type SAL_CALL UnoControlContainer::getElementType( )
540 return cppu::UnoType<awt::XControlModel>::get();
543 sal_Bool SAL_CALL UnoControlContainer::hasElements( )
545 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
546 return !mpControls->empty();
549 // awt::XControlContainer
550 void UnoControlContainer::setStatusText( const OUString& rStatusText )
552 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
554 // Descend the parent hierarchy
555 uno::Reference< awt::XControlContainer > xContainer( mxContext, uno::UNO_QUERY );
556 if( xContainer.is() )
557 xContainer->setStatusText( rStatusText );
560 uno::Sequence< uno::Reference< awt::XControl > > UnoControlContainer::getControls( )
562 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
563 uno::Sequence< uno::Reference< awt::XControl > > aControls;
564 mpControls->getControls( aControls );
565 return aControls;
568 uno::Reference< awt::XControl > UnoControlContainer::getControl( const OUString& rName )
570 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
571 return mpControls->getControlForName( rName );
574 void UnoControlContainer::addingControl( const uno::Reference< awt::XControl >& _rxControl )
576 if ( _rxControl.is() )
578 uno::Reference< uno::XInterface > xThis;
579 OWeakAggObject::queryInterface( cppu::UnoType<uno::XInterface>::get() ) >>= xThis;
581 _rxControl->setContext( xThis );
582 _rxControl->addEventListener( this );
586 void UnoControlContainer::impl_createControlPeerIfNecessary( const uno::Reference< awt::XControl >& _rxControl )
588 OSL_PRECOND( _rxControl.is(), "UnoControlContainer::impl_createControlPeerIfNecessary: invalid control, this will crash!" );
590 // if the container already has a peer, then also create a peer for the control
591 uno::Reference< awt::XWindowPeer > xMyPeer( getPeer() );
593 if( xMyPeer.is() )
595 _rxControl->createPeer( nullptr, xMyPeer );
596 ImplActivateTabControllers();
601 sal_Int32 UnoControlContainer::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const OUString* _pName )
603 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
604 UnoControlHolderList::ControlIdentifier id = mpControls->addControl( _rxControl, _pName );
606 addingControl( _rxControl );
608 impl_createControlPeerIfNecessary( _rxControl );
610 if ( maCListeners.getLength() )
612 container::ContainerEvent aEvent;
613 aEvent.Source = *this;
614 if (_pName)
615 aEvent.Accessor <<= *_pName;
616 else
617 aEvent.Accessor <<= static_cast<sal_Int32>(id);
618 aEvent.Element <<= _rxControl;
619 maCListeners.elementInserted( aEvent );
622 return id;
625 void UnoControlContainer::addControl( const OUString& rName, const uno::Reference< awt::XControl >& rControl )
627 if ( rControl.is() )
628 impl_addControl( rControl, &rName );
631 void UnoControlContainer::removingControl( const uno::Reference< awt::XControl >& _rxControl )
633 if ( _rxControl.is() )
635 _rxControl->removeEventListener( this );
636 _rxControl->setContext( nullptr );
640 void UnoControlContainer::impl_removeControl( sal_Int32 _nId, const uno::Reference< awt::XControl >& _rxControl )
642 #ifdef DBG_UTIL
644 uno::Reference< awt::XControl > xControl;
645 bool bHas = mpControls->getControlForIdentifier( _nId, xControl );
646 DBG_ASSERT( bHas && xControl == _rxControl, "UnoControlContainer::impl_removeControl: inconsistency in the parameters!" );
648 #endif
649 removingControl( _rxControl );
651 mpControls->removeControlById( _nId );
653 if ( maCListeners.getLength() )
655 container::ContainerEvent aEvent;
656 aEvent.Source = *this;
657 aEvent.Accessor <<= _nId;
658 aEvent.Element <<= _rxControl;
659 maCListeners.elementRemoved( aEvent );
663 void UnoControlContainer::removeControl( const uno::Reference< awt::XControl >& _rxControl )
665 if ( _rxControl.is() )
667 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
669 UnoControlHolderList::ControlIdentifier id = mpControls->getControlIdentifier( _rxControl );
670 if ( id != -1 )
671 impl_removeControl( id, _rxControl );
676 // awt::XUnoControlContainer
677 void UnoControlContainer::setTabControllers( const uno::Sequence< uno::Reference< awt::XTabController > >& TabControllers )
679 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
681 maTabControllers = TabControllers;
684 uno::Sequence< uno::Reference< awt::XTabController > > UnoControlContainer::getTabControllers( )
686 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
688 return maTabControllers;
691 void UnoControlContainer::addTabController( const uno::Reference< awt::XTabController >& TabController )
693 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
695 sal_uInt32 nCount = maTabControllers.getLength();
696 maTabControllers.realloc( nCount + 1 );
697 maTabControllers.getArray()[ nCount ] = TabController;
700 void UnoControlContainer::removeTabController( const uno::Reference< awt::XTabController >& TabController )
702 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
704 auto pTabController = std::find_if(std::cbegin(maTabControllers), std::cend(maTabControllers),
705 [&TabController](const uno::Reference< awt::XTabController >& rTabController) {
706 return rTabController.get() == TabController.get(); });
707 if (pTabController != std::cend(maTabControllers))
709 auto n = static_cast<sal_Int32>(std::distance(std::cbegin(maTabControllers), pTabController));
710 ::comphelper::removeElementAt( maTabControllers, n );
714 // awt::XControl
715 void UnoControlContainer::createPeer( const uno::Reference< awt::XToolkit >& rxToolkit, const uno::Reference< awt::XWindowPeer >& rParent )
717 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
719 if( getPeer().is() )
720 return;
722 bool bVis = maComponentInfos.bVisible;
723 if( bVis )
724 UnoControl::setVisible( false );
726 // Create a new peer
727 UnoControl::createPeer( rxToolkit, rParent );
729 // Create all children's peers
730 if ( !mbCreatingCompatiblePeer )
732 // Evaluate "Step" property
733 uno::Reference< awt::XControlModel > xModel( getModel() );
734 uno::Reference< beans::XPropertySet > xPSet
735 ( xModel, uno::UNO_QUERY );
736 uno::Reference< beans::XPropertySetInfo >
737 xInfo = xPSet->getPropertySetInfo();
738 OUString aPropName( "Step" );
739 if ( xInfo->hasPropertyByName( aPropName ) )
741 css::uno::Any aVal = xPSet->getPropertyValue( aPropName );
742 sal_Int32 nDialogStep = 0;
743 aVal >>= nDialogStep;
744 uno::Reference< awt::XControlContainer > xContainer =
745 static_cast< awt::XControlContainer* >(this);
746 implUpdateVisibility( nDialogStep, xContainer );
748 uno::Reference< beans::XPropertyChangeListener > xListener =
749 new DialogStepChangedListener(xContainer);
750 xPSet->addPropertyChangeListener( aPropName, xListener );
753 uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
754 for( auto& rCtrl : asNonConstRange(aCtrls) )
755 rCtrl->createPeer( rxToolkit, getPeer() );
757 uno::Reference< awt::XVclContainerPeer > xC( getPeer(), uno::UNO_QUERY );
758 if ( xC.is() )
759 xC->enableDialogControl( true );
760 ImplActivateTabControllers();
763 if( bVis && !isDesignMode() )
764 UnoControl::setVisible( true );
768 // awt::XWindow
769 void UnoControlContainer::setVisible( sal_Bool bVisible )
771 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
773 UnoControl::setVisible( bVisible );
774 if( !mxContext.is() && bVisible )
775 // This is a Topwindow, thus show it automatically
776 createPeer( uno::Reference< awt::XToolkit > (), uno::Reference< awt::XWindowPeer > () );
779 OUString UnoControlContainer::getImplementationName()
781 return "stardiv.Toolkit.UnoControlContainer";
784 css::uno::Sequence<OUString> UnoControlContainer::getSupportedServiceNames()
786 auto s(UnoControlBase::getSupportedServiceNames());
787 s.realloc(s.getLength() + 2);
788 auto ps = s.getArray();
789 ps[s.getLength() - 2] = "com.sun.star.awt.UnoControlContainer";
790 ps[s.getLength() - 1] = "stardiv.vcl.control.ControlContainer";
791 return s;
794 void UnoControlContainer::PrepareWindowDescriptor( css::awt::WindowDescriptor& rDesc )
796 // HACK due to the fact that we can't really use VSCROLL & HSCROLL
797 // for Dialog ( css::awt::VclWindowPeerAttribute::VSCROLL
798 // has the same value as
799 // css::awt::WindowAttribute::NODECORATION )
800 // For convenience in the PropBrowse using HSCROLL and VSCROLL ensures
801 // the Correct text. We exchange them here and the control knows
802 // about this hack ( it sucks badly I know )
803 if ( rDesc.WindowAttributes & css::awt::VclWindowPeerAttribute::VSCROLL )
805 rDesc.WindowAttributes &= ~css::awt::VclWindowPeerAttribute::VSCROLL;
806 rDesc.WindowAttributes |= css::awt::VclWindowPeerAttribute::AUTOVSCROLL;
808 if ( rDesc.WindowAttributes & css::awt::VclWindowPeerAttribute::HSCROLL )
810 rDesc.WindowAttributes &= ~css::awt::VclWindowPeerAttribute::HSCROLL;
811 rDesc.WindowAttributes |= css::awt::VclWindowPeerAttribute::AUTOHSCROLL;
815 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
816 stardiv_Toolkit_UnoControlContainer_get_implementation(
817 css::uno::XComponentContext *,
818 css::uno::Sequence<css::uno::Any> const &)
820 return cppu::acquire(new UnoControlContainer());
823 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */