Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / toolkit / source / controls / unocontrol.cxx
blob3233f71081c2cd4b2733e35c3bc990dc09f636f3
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 <sal/config.h>
22 #include <com/sun/star/awt/XControlContainer.hpp>
23 #include <com/sun/star/awt/WindowAttribute.hpp>
24 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
25 #include <com/sun/star/awt/PosSize.hpp>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/lang/NoSupportException.hpp>
28 #include <com/sun/star/resource/XStringResourceResolver.hpp>
29 #include <toolkit/controls/unocontrol.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <cppuhelper/typeprovider.hxx>
33 #include <rtl/uuid.h>
34 #include <osl/mutex.hxx>
35 #include <tools/date.hxx>
36 #include <tools/debug.hxx>
37 #include <tools/diagnose_ex.h>
38 #include <vcl/svapp.hxx>
39 #include <vcl/wrkwin.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <toolkit/helper/property.hxx>
42 #include <toolkit/helper/servicenames.hxx>
43 #include <toolkit/awt/vclxwindow.hxx>
44 #include <toolkit/controls/accessiblecontrolcontext.hxx>
45 #include <comphelper/container.hxx>
47 #include <algorithm>
48 #include <map>
49 #include <set>
50 #include <vector>
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::awt;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::util;
59 using ::com::sun::star::accessibility::XAccessibleContext;
60 using ::com::sun::star::accessibility::XAccessible;
62 struct LanguageDependentProp
64 const char* pPropName;
65 sal_Int32 nPropNameLength;
68 static const LanguageDependentProp aLanguageDependentProp[] =
70 { "Text", 4 },
71 { "Label", 5 },
72 { "Title", 5 },
73 { "HelpText", 8 },
74 { "CurrencySymbol", 14 },
75 { "StringItemList", 14 },
76 { nullptr, 0 }
79 static Sequence< OUString> lcl_ImplGetPropertyNames( const Reference< XMultiPropertySet > & rxModel )
81 Sequence< OUString> aNames;
82 Reference< XPropertySetInfo > xPSInf = rxModel->getPropertySetInfo();
83 DBG_ASSERT( xPSInf.is(), "UpdateFromModel: No PropertySetInfo!" );
84 if ( xPSInf.is() )
86 Sequence< Property> aProps = xPSInf->getProperties();
87 sal_Int32 nLen = aProps.getLength();
88 aNames = Sequence< OUString>( nLen );
89 OUString* pNames = aNames.getArray();
90 const Property* pProps = aProps.getConstArray();
91 for ( sal_Int32 n = 0; n < nLen; ++n, ++pProps, ++pNames)
92 *pNames = pProps->Name;
94 return aNames;
98 class VclListenerLock
100 private:
101 VCLXWindow* m_pLockWindow;
103 public:
104 explicit VclListenerLock( VCLXWindow* _pLockWindow )
105 : m_pLockWindow( _pLockWindow )
107 if ( m_pLockWindow )
108 m_pLockWindow->suspendVclEventListening( );
110 ~VclListenerLock()
112 if ( m_pLockWindow )
113 m_pLockWindow->resumeVclEventListening( );
115 VclListenerLock(const VclListenerLock&) = delete;
116 VclListenerLock& operator=(const VclListenerLock&) = delete;
119 typedef ::std::map< OUString, sal_Int32 > MapString2Int;
120 struct UnoControl_Data
122 MapString2Int aSuspendedPropertyNotifications;
123 /// true if and only if our model has a property ResourceResolver
124 bool bLocalizationSupport;
126 UnoControl_Data()
127 :aSuspendedPropertyNotifications()
128 ,bLocalizationSupport( false )
133 UnoControl::UnoControl() :
134 maDisposeListeners( *this )
135 , maWindowListeners( *this )
136 , maFocusListeners( *this )
137 , maKeyListeners( *this )
138 , maMouseListeners( *this )
139 , maMouseMotionListeners( *this )
140 , maPaintListeners( *this )
141 , maModeChangeListeners( GetMutex() )
142 , mpData( new UnoControl_Data )
144 mbDisposePeer = true;
145 mbRefeshingPeer = false;
146 mbCreatingPeer = false;
147 mbCreatingCompatiblePeer = false;
148 mbDesignMode = false;
151 UnoControl::~UnoControl()
153 DELETEZ( mpData );
156 OUString UnoControl::GetComponentServiceName()
158 return OUString();
161 Reference< XWindowPeer > UnoControl::ImplGetCompatiblePeer()
163 DBG_ASSERT( !mbCreatingCompatiblePeer, "ImplGetCompatiblePeer - rekursive?" );
165 mbCreatingCompatiblePeer = true;
167 Reference< XWindowPeer > xCompatiblePeer = getPeer();
169 if ( !xCompatiblePeer.is() )
171 // Create the pair as invisible
172 bool bVis = maComponentInfos.bVisible;
173 if( bVis )
174 maComponentInfos.bVisible = false;
176 Reference< XWindowPeer > xCurrentPeer = getPeer();
177 setPeer( nullptr );
179 // queryInterface ourself, to allow aggregation
180 Reference< XControl > xMe;
181 OWeakAggObject::queryInterface( cppu::UnoType<decltype(xMe)>::get() ) >>= xMe;
183 vcl::Window* pParentWindow( nullptr );
185 SolarMutexGuard aGuard;
186 pParentWindow = dynamic_cast< vcl::Window* >( Application::GetDefaultDevice() );
187 ENSURE_OR_THROW( pParentWindow != nullptr, "could obtain a default parent window!" );
191 xMe->createPeer( nullptr, pParentWindow->GetComponentInterface() );
193 catch( const Exception& )
195 mbCreatingCompatiblePeer = false;
196 throw;
198 xCompatiblePeer = getPeer();
199 setPeer( xCurrentPeer );
201 if ( xCompatiblePeer.is() && mxGraphics.is() )
203 Reference< XView > xPeerView( xCompatiblePeer, UNO_QUERY );
204 if ( xPeerView.is() )
205 xPeerView->setGraphics( mxGraphics );
208 if( bVis )
209 maComponentInfos.bVisible = true;
212 mbCreatingCompatiblePeer = false;
214 return xCompatiblePeer;
217 bool UnoControl::ImplCheckLocalize( OUString& _rPossiblyLocalizable )
219 if ( !mpData->bLocalizationSupport
220 || ( _rPossiblyLocalizable.isEmpty() )
221 || ( _rPossiblyLocalizable[0] != '&' )
222 // TODO: make this reasonable. At the moment, everything which by accident starts with a & is considered
223 // localizable, which is probably wrong.
225 return false;
229 Reference< XPropertySet > xPropSet( mxModel, UNO_QUERY_THROW );
230 Reference< resource::XStringResourceResolver > xStringResourceResolver(
231 xPropSet->getPropertyValue("ResourceResolver"),
232 UNO_QUERY
234 if ( xStringResourceResolver.is() )
236 OUString aLocalizationKey( _rPossiblyLocalizable.copy( 1 ) );
237 _rPossiblyLocalizable = xStringResourceResolver->resolveString( aLocalizationKey );
238 return true;
241 catch( const Exception& )
243 DBG_UNHANDLED_EXCEPTION();
245 return false;
248 void UnoControl::ImplSetPeerProperty( const OUString& rPropName, const Any& rVal )
250 // since a change made in propertiesChange, we can't be sure that this is called with an valid getPeer(),
251 // this assumption may be false in some (seldom) multi-threading scenarios (cause propertiesChange
252 // releases our mutex before calling here in)
253 // That's why this additional check
255 if ( mxVclWindowPeer.is() )
257 Any aConvertedValue( rVal );
259 if ( mpData->bLocalizationSupport )
261 // We now support a mapping for language dependent properties. This is the
262 // central method to implement it.
263 if( rPropName == "Text" ||
264 rPropName == "Label" ||
265 rPropName == "Title" ||
266 rPropName == "HelpText" ||
267 rPropName == "CurrencySymbol" ||
268 rPropName == "StringItemList" )
270 OUString aValue;
271 uno::Sequence< OUString > aSeqValue;
272 if ( aConvertedValue >>= aValue )
274 if ( ImplCheckLocalize( aValue ) )
275 aConvertedValue <<= aValue;
277 else if ( aConvertedValue >>= aSeqValue )
279 for ( sal_Int32 i = 0; i < aSeqValue.getLength(); i++ )
280 ImplCheckLocalize( aSeqValue[i] );
281 aConvertedValue <<= aSeqValue;
286 mxVclWindowPeer->setProperty( rPropName, aConvertedValue );
290 void UnoControl::PrepareWindowDescriptor( WindowDescriptor& )
294 Reference< XWindow > UnoControl::getParentPeer() const
296 Reference< XWindow > xPeer;
297 if( mxContext.is() )
299 Reference< XControl > xContComp( mxContext, UNO_QUERY );
300 if ( xContComp.is() )
302 Reference< XWindowPeer > xP = xContComp->getPeer();
303 if ( xP.is() )
304 xPeer.set( xP, UNO_QUERY );
307 return xPeer;
310 void UnoControl::updateFromModel()
312 // Read default properties and hand over to peer
313 if( getPeer().is() )
315 Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
316 if( xPropSet.is() )
318 Sequence< OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
319 xPropSet->firePropertiesChangeEvent( aNames, this );
325 // XTypeProvider
326 IMPL_IMPLEMENTATION_ID( UnoControl )
328 void
329 UnoControl::DisposeAccessibleContext(Reference<XComponent> const& xContextComp)
331 if (xContextComp.is())
335 xContextComp->removeEventListener( this );
336 xContextComp->dispose();
338 catch( const Exception& )
340 OSL_FAIL( "UnoControl::disposeAccessibleContext: could not dispose my AccessibleContext!" );
345 void UnoControl::dispose( )
347 Reference< XWindowPeer > xPeer;
348 Reference<XComponent> xAccessibleComp;
350 ::osl::MutexGuard aGuard( GetMutex() );
351 if( mbDisposePeer )
353 xPeer = mxPeer;
355 setPeer( nullptr );
356 xAccessibleComp.set(maAccessibleContext, UNO_QUERY);
357 maAccessibleContext.clear();
359 if( xPeer.is() )
361 xPeer->dispose();
364 // dispose our AccessibleContext - without Mutex locked
365 DisposeAccessibleContext(xAccessibleComp);
367 EventObject aDisposeEvent;
368 aDisposeEvent.Source = static_cast< XAggregation* >( this );
370 maDisposeListeners.disposeAndClear( aDisposeEvent );
371 maWindowListeners.disposeAndClear( aDisposeEvent );
372 maFocusListeners.disposeAndClear( aDisposeEvent );
373 maKeyListeners.disposeAndClear( aDisposeEvent );
374 maMouseListeners.disposeAndClear( aDisposeEvent );
375 maMouseMotionListeners.disposeAndClear( aDisposeEvent );
376 maPaintListeners.disposeAndClear( aDisposeEvent );
377 maModeChangeListeners.disposeAndClear( aDisposeEvent );
379 // release Model again
380 setModel( Reference< XControlModel > () );
381 setContext( Reference< XInterface > () );
384 void UnoControl::addEventListener( const Reference< XEventListener >& rxListener )
386 ::osl::MutexGuard aGuard( GetMutex() );
388 maDisposeListeners.addInterface( rxListener );
391 void UnoControl::removeEventListener( const Reference< XEventListener >& rxListener )
393 ::osl::MutexGuard aGuard( GetMutex() );
395 maDisposeListeners.removeInterface( rxListener );
398 bool UnoControl::requiresNewPeer( const OUString& /* _rPropertyName */ ) const
400 return false;
403 // XPropertiesChangeListener
404 void UnoControl::propertiesChange( const Sequence< PropertyChangeEvent >& rEvents )
406 Sequence< PropertyChangeEvent > aEvents( rEvents );
408 ::osl::MutexGuard aGuard( GetMutex() );
410 if ( !mpData->aSuspendedPropertyNotifications.empty() )
412 // strip the property which we are currently updating (somewhere up the stack)
413 PropertyChangeEvent* pEvents = aEvents.getArray();
414 PropertyChangeEvent* pEventsEnd = pEvents + aEvents.getLength();
415 for ( ; pEvents < pEventsEnd; )
416 if ( mpData->aSuspendedPropertyNotifications.find( pEvents->PropertyName ) != mpData->aSuspendedPropertyNotifications.end() )
418 if ( pEvents != pEventsEnd )
419 ::std::copy( pEvents + 1, pEventsEnd, pEvents );
420 --pEventsEnd;
422 else
423 ++pEvents;
424 aEvents.realloc( pEventsEnd - aEvents.getConstArray() );
426 if ( !aEvents.getLength() )
427 return;
431 ImplModelPropertiesChanged( aEvents );
434 void UnoControl::ImplLockPropertyChangeNotification( const OUString& rPropertyName, bool bLock )
436 MapString2Int::iterator pos = mpData->aSuspendedPropertyNotifications.find( rPropertyName );
437 if ( bLock )
439 if ( pos == mpData->aSuspendedPropertyNotifications.end() )
440 pos = mpData->aSuspendedPropertyNotifications.insert( MapString2Int::value_type( rPropertyName, 0 ) ).first;
441 ++pos->second;
443 else
445 OSL_ENSURE( pos != mpData->aSuspendedPropertyNotifications.end(), "UnoControl::ImplLockPropertyChangeNotification: property not locked!" );
446 if ( pos != mpData->aSuspendedPropertyNotifications.end() )
448 OSL_ENSURE( pos->second > 0, "UnoControl::ImplLockPropertyChangeNotification: invalid suspension counter!" );
449 if ( 0 == --pos->second )
450 mpData->aSuspendedPropertyNotifications.erase( pos );
455 void UnoControl::ImplLockPropertyChangeNotifications( const Sequence< OUString >& rPropertyNames, bool bLock )
457 for ( const OUString* pPropertyName = rPropertyNames.getConstArray();
458 pPropertyName != rPropertyNames.getConstArray() + rPropertyNames.getLength();
459 ++pPropertyName
461 ImplLockPropertyChangeNotification( *pPropertyName, bLock );
464 void UnoControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents )
466 ::osl::ClearableGuard< ::osl::Mutex > aGuard( GetMutex() );
468 if( getPeer().is() )
470 std::vector< PropertyValue > aPeerPropertiesToSet;
471 sal_Int32 nIndependentPos = 0;
472 bool bResourceResolverSet( false );
473 // position where to insert the independent properties into aPeerPropertiesToSet,
474 // dependent ones are inserted at the end of the vector
476 bool bNeedNewPeer = false;
477 // some properties require a re-creation of the peer, 'cause they can't be changed on the fly
479 Reference< XControlModel > xOwnModel( getModel(), UNO_QUERY );
480 // our own model for comparison
481 Reference< XPropertySet > xPS( xOwnModel, UNO_QUERY );
482 Reference< XPropertySetInfo > xPSI( xPS->getPropertySetInfo(), UNO_QUERY );
483 OSL_ENSURE( xPSI.is(), "UnoControl::ImplModelPropertiesChanged: should have property set meta data!" );
485 const PropertyChangeEvent* pEvents = rEvents.getConstArray();
487 sal_Int32 nLen = rEvents.getLength();
488 aPeerPropertiesToSet.reserve(nLen);
490 for( sal_Int32 i = 0; i < nLen; ++i, ++pEvents )
492 Reference< XControlModel > xModel( pEvents->Source, UNO_QUERY );
493 bool bOwnModel = xModel.get() == xOwnModel.get();
494 if ( !bOwnModel )
495 continue;
497 // Detect changes on our resource resolver which invalidates
498 // automatically some language dependent properties.
499 if ( pEvents->PropertyName == "ResourceResolver" )
501 Reference< resource::XStringResourceResolver > xStrResolver;
502 if ( pEvents->NewValue >>= xStrResolver )
503 bResourceResolverSet = xStrResolver.is();
506 sal_uInt16 nPType = GetPropertyId( pEvents->PropertyName );
507 if ( mbDesignMode && mbDisposePeer && !mbRefeshingPeer && !mbCreatingPeer )
509 // if we're in design mode, then some properties can change which
510 // require creating a *new* peer (since these properties cannot
511 // be switched at existing peers)
512 if ( nPType )
513 bNeedNewPeer = ( nPType == BASEPROPERTY_BORDER )
514 || ( nPType == BASEPROPERTY_MULTILINE )
515 || ( nPType == BASEPROPERTY_DROPDOWN )
516 || ( nPType == BASEPROPERTY_HSCROLL )
517 || ( nPType == BASEPROPERTY_VSCROLL )
518 || ( nPType == BASEPROPERTY_AUTOHSCROLL )
519 || ( nPType == BASEPROPERTY_AUTOVSCROLL )
520 || ( nPType == BASEPROPERTY_ORIENTATION )
521 || ( nPType == BASEPROPERTY_SPIN )
522 || ( nPType == BASEPROPERTY_ALIGN )
523 || ( nPType == BASEPROPERTY_PAINTTRANSPARENT );
524 else
525 bNeedNewPeer = requiresNewPeer( pEvents->PropertyName );
527 if ( bNeedNewPeer )
528 break;
531 if ( nPType && ( nLen > 1 ) && DoesDependOnOthers( nPType ) )
533 // Add properties with dependencies on other properties last
534 // since they're dependent on properties added later (such as
535 // VALUE dependency on VALUEMIN/MAX)
536 aPeerPropertiesToSet.push_back(PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
538 else
540 if ( bResourceResolverSet )
542 // The resource resolver property change should be one of the first ones.
543 // All language dependent properties are dependent on this property.
544 // As BASEPROPERTY_NATIVE_WIDGET_LOOK is not dependent on resource
545 // resolver. We don't need to handle a special order for these two props.
546 aPeerPropertiesToSet.insert(
547 aPeerPropertiesToSet.begin(),
548 PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
549 ++nIndependentPos;
551 else if ( nPType == BASEPROPERTY_NATIVE_WIDGET_LOOK )
553 // since *a lot* of other properties might be overruled by this one, we need
554 // a special handling:
555 // NativeWidgetLook needs to be set first: If it is set to ON, all other
556 // properties describing the look (e.g. BackgroundColor) are ignored, anyway.
557 // If it is switched OFF, then we need to do it first because else it will
558 // overrule other look-related properties, and re-initialize them from system
559 // defaults.
560 aPeerPropertiesToSet.insert(
561 aPeerPropertiesToSet.begin(),
562 PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
563 ++nIndependentPos;
565 else
567 aPeerPropertiesToSet.insert(aPeerPropertiesToSet.begin() + nIndependentPos,
568 PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
569 ++nIndependentPos;
574 Reference< XWindow > xParent = getParentPeer();
575 Reference< XControl > xThis( static_cast<XAggregation*>(static_cast<cppu::OWeakAggObject*>(this)), UNO_QUERY );
576 // call createPeer via a interface got from queryInterface, so the aggregating class can intercept it
578 DBG_ASSERT( !bNeedNewPeer || xParent.is(), "Need new peer, but don't have a parent!" );
580 // Check if we have to update language dependent properties
581 if ( !bNeedNewPeer && bResourceResolverSet )
583 // Add language dependent properties into the peer property set.
584 // Our resource resolver has been changed and we must be sure
585 // that language dependent props use the new resolver.
586 const LanguageDependentProp* pLangDepProp = aLanguageDependentProp;
587 while ( pLangDepProp->pPropName != nullptr )
589 bool bMustBeInserted( true );
590 for (PropertyValue & i : aPeerPropertiesToSet)
592 if ( i.Name.equalsAsciiL(
593 pLangDepProp->pPropName, pLangDepProp->nPropNameLength ))
595 bMustBeInserted = false;
596 break;
600 if ( bMustBeInserted )
602 // Add language dependent props at the end
603 OUString aPropName( OUString::createFromAscii( pLangDepProp->pPropName ));
604 if ( xPSI.is() && xPSI->hasPropertyByName( aPropName ) )
606 aPeerPropertiesToSet.push_back(
607 PropertyValue( aPropName, 0, xPS->getPropertyValue( aPropName ), PropertyState_DIRECT_VALUE ) );
611 ++pLangDepProp;
614 aGuard.clear();
616 // clear the guard before creating a new peer - as usual, our peer implementations use the SolarMutex
618 if (bNeedNewPeer && xParent.is())
620 SolarMutexGuard aVclGuard;
621 // and now this is the final withdrawal:
622 // I have no other idea than locking the SolarMutex here....
623 // I really hate the fact that VCL is not threadsafe....
625 // Doesn't work for Container!
626 getPeer()->dispose();
627 mxPeer.clear();
628 mxVclWindowPeer = nullptr;
629 mbRefeshingPeer = true;
630 Reference< XWindowPeer > xP( xParent, UNO_QUERY );
631 xThis->createPeer( Reference< XToolkit > (), xP );
632 mbRefeshingPeer = false;
633 aPeerPropertiesToSet.clear();
636 // lock the multiplexing of VCL events to our UNO listeners
637 // this is for compatibility reasons: in OOo 1.0.x, changes which were done at the
638 // model did not cause the listeners of the controls/peers to be called
639 // Since the implementations for the listeners changed a lot towards 1.1, this
640 // would not be the case anymore, if we would not do this listener-lock below
641 // #i14703#
642 VCLXWindow* pPeer;
644 SolarMutexGuard g;
645 VclPtr<vcl::Window> pVclPeer = VCLUnoHelper::GetWindow( getPeer() );
646 pPeer = pVclPeer ? pVclPeer->GetWindowPeer() : nullptr;
648 VclListenerLock aNoVclEventMultiplexing( pPeer );
650 // setting peer properties may result in an attempt to acquire the solar mutex, 'cause the peers
651 // usually don't have an own mutex but use the SolarMutex instead.
652 // To prevent deadlocks resulting from this, we do this without our own mutex locked
653 std::vector< PropertyValue >::iterator aEnd = aPeerPropertiesToSet.end();
654 for ( std::vector< PropertyValue >::iterator aLoop = aPeerPropertiesToSet.begin();
655 aLoop != aEnd;
656 ++aLoop
659 ImplSetPeerProperty( aLoop->Name, aLoop->Value );
664 void UnoControl::disposing( const EventObject& rEvt )
666 ::osl::ClearableMutexGuard aGuard( GetMutex() );
667 // do not compare differing types in case of multiple inheritance
669 if ( maAccessibleContext.get() == rEvt.Source )
671 // just in case the context is disposed, but not released - ensure that we do not re-use it in the future
672 maAccessibleContext = nullptr;
674 else if( mxModel.get() == Reference< XControlModel >(rEvt.Source,UNO_QUERY).get() )
676 // #62337# if the model dies, it does not make sense for us to live ...
677 Reference< XControl > xThis = this;
679 aGuard.clear();
680 xThis->dispose();
682 DBG_ASSERT( !mxModel.is(), "UnoControl::disposing: invalid dispose behaviour!" );
683 mxModel.clear();
688 void SAL_CALL UnoControl::setOutputSize( const awt::Size& aSize )
690 Reference< XWindow2 > xPeerWindow;
692 ::osl::MutexGuard aGuard( GetMutex() );
693 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
696 if ( xPeerWindow.is() )
697 xPeerWindow->setOutputSize( aSize );
700 namespace
702 template < typename RETVALTYPE, typename DEFAULTTYPE >
703 RETVALTYPE lcl_askPeer( const uno::Reference< awt::XWindowPeer >& _rxPeer, RETVALTYPE (SAL_CALL XWindow2::*_pMethod)(), DEFAULTTYPE _aDefault )
705 RETVALTYPE aReturn( _aDefault );
707 Reference< XWindow2 > xPeerWindow( _rxPeer, UNO_QUERY );
708 if ( xPeerWindow.is() )
709 aReturn = (xPeerWindow.get()->*_pMethod)();
711 return aReturn;
715 awt::Size SAL_CALL UnoControl::getOutputSize( )
717 return lcl_askPeer( getPeer(), &XWindow2::getOutputSize, awt::Size() );
720 sal_Bool SAL_CALL UnoControl::isVisible( )
722 return lcl_askPeer( getPeer(), &XWindow2::isVisible, maComponentInfos.bVisible );
725 sal_Bool SAL_CALL UnoControl::isActive( )
727 return lcl_askPeer( getPeer(), &XWindow2::isActive, false );
730 sal_Bool SAL_CALL UnoControl::isEnabled( )
732 return lcl_askPeer( getPeer(), &XWindow2::isEnabled, maComponentInfos.bEnable );
735 sal_Bool SAL_CALL UnoControl::hasFocus( )
737 return lcl_askPeer( getPeer(), &XWindow2::hasFocus, false );
740 // XWindow
741 void UnoControl::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags )
743 Reference< XWindow > xWindow;
745 ::osl::MutexGuard aGuard( GetMutex() );
747 if ( Flags & awt::PosSize::X )
748 maComponentInfos.nX = X;
749 if ( Flags & awt::PosSize::Y )
750 maComponentInfos.nY = Y;
751 if ( Flags & awt::PosSize::WIDTH )
752 maComponentInfos.nWidth = Width;
753 if ( Flags & awt::PosSize::HEIGHT )
754 maComponentInfos.nHeight = Height;
755 maComponentInfos.nFlags |= Flags;
757 xWindow.set(getPeer(), css::uno::UNO_QUERY);
760 if( xWindow.is() )
761 xWindow->setPosSize( X, Y, Width, Height, Flags );
764 awt::Rectangle UnoControl::getPosSize( )
766 awt::Rectangle aRect( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight);
767 Reference< XWindow > xWindow;
770 ::osl::MutexGuard aGuard( GetMutex() );
771 xWindow.set(getPeer(), css::uno::UNO_QUERY);
774 if( xWindow.is() )
775 aRect = xWindow->getPosSize();
776 return aRect;
779 void UnoControl::setVisible( sal_Bool bVisible )
781 Reference< XWindow > xWindow;
783 ::osl::MutexGuard aGuard( GetMutex() );
785 // Visible status is handled by View
786 maComponentInfos.bVisible = bVisible;
787 xWindow.set(getPeer(), css::uno::UNO_QUERY);
789 if ( xWindow.is() )
790 xWindow->setVisible( bVisible );
793 void UnoControl::setEnable( sal_Bool bEnable )
795 Reference< XWindow > xWindow;
797 ::osl::MutexGuard aGuard( GetMutex() );
799 // Enable status is handled by View
800 maComponentInfos.bEnable = bEnable;
801 xWindow.set(getPeer(), css::uno::UNO_QUERY);
803 if ( xWindow.is() )
804 xWindow->setEnable( bEnable );
807 void UnoControl::setFocus( )
809 Reference< XWindow > xWindow;
811 ::osl::MutexGuard aGuard( GetMutex() );
812 xWindow.set(getPeer(), css::uno::UNO_QUERY);
814 if ( xWindow.is() )
815 xWindow->setFocus();
818 void UnoControl::addWindowListener( const Reference< XWindowListener >& rxListener )
820 Reference< XWindow > xPeerWindow;
822 ::osl::MutexGuard aGuard( GetMutex() );
823 maWindowListeners.addInterface( rxListener );
824 if ( maWindowListeners.getLength() == 1 )
825 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
827 if ( xPeerWindow.is() )
828 xPeerWindow->addWindowListener( &maWindowListeners );
831 void UnoControl::removeWindowListener( const Reference< XWindowListener >& rxListener )
833 Reference< XWindow > xPeerWindow;
835 ::osl::MutexGuard aGuard( GetMutex() );
836 if ( maWindowListeners.getLength() == 1 )
837 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
838 maWindowListeners.removeInterface( rxListener );
840 if ( xPeerWindow.is() )
841 xPeerWindow->removeWindowListener( &maWindowListeners );
844 void UnoControl::addFocusListener( const Reference< XFocusListener >& rxListener )
846 Reference< XWindow > xPeerWindow;
848 ::osl::MutexGuard aGuard( GetMutex() );
849 maFocusListeners.addInterface( rxListener );
850 if ( maFocusListeners.getLength() == 1 )
851 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
853 if ( xPeerWindow.is() )
854 xPeerWindow->addFocusListener( &maFocusListeners );
857 void UnoControl::removeFocusListener( const Reference< XFocusListener >& rxListener )
859 Reference< XWindow > xPeerWindow;
861 ::osl::MutexGuard aGuard( GetMutex() );
862 if ( maFocusListeners.getLength() == 1 )
863 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
864 maFocusListeners.removeInterface( rxListener );
866 if ( xPeerWindow.is() )
867 xPeerWindow->removeFocusListener( &maFocusListeners );
870 void UnoControl::addKeyListener( const Reference< XKeyListener >& rxListener )
872 Reference< XWindow > xPeerWindow;
874 ::osl::MutexGuard aGuard( GetMutex() );
875 maKeyListeners.addInterface( rxListener );
876 if ( maKeyListeners.getLength() == 1 )
877 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
879 if ( xPeerWindow.is() )
880 xPeerWindow->addKeyListener( &maKeyListeners);
883 void UnoControl::removeKeyListener( const Reference< XKeyListener >& rxListener )
885 Reference< XWindow > xPeerWindow;
887 ::osl::MutexGuard aGuard( GetMutex() );
888 if ( maKeyListeners.getLength() == 1 )
889 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
890 maKeyListeners.removeInterface( rxListener );
892 if ( xPeerWindow.is() )
893 xPeerWindow->removeKeyListener( &maKeyListeners);
896 void UnoControl::addMouseListener( const Reference< XMouseListener >& rxListener )
898 Reference< XWindow > xPeerWindow;
900 ::osl::MutexGuard aGuard( GetMutex() );
901 maMouseListeners.addInterface( rxListener );
902 if ( maMouseListeners.getLength() == 1 )
903 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
905 if ( xPeerWindow.is() )
906 xPeerWindow->addMouseListener( &maMouseListeners);
909 void UnoControl::removeMouseListener( const Reference< XMouseListener >& rxListener )
911 Reference< XWindow > xPeerWindow;
913 ::osl::MutexGuard aGuard( GetMutex() );
914 if ( maMouseListeners.getLength() == 1 )
915 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
916 maMouseListeners.removeInterface( rxListener );
918 if ( xPeerWindow.is() )
919 xPeerWindow->removeMouseListener( &maMouseListeners );
922 void UnoControl::addMouseMotionListener( const Reference< XMouseMotionListener >& rxListener )
924 Reference< XWindow > xPeerWindow;
926 ::osl::MutexGuard aGuard( GetMutex() );
927 maMouseMotionListeners.addInterface( rxListener );
928 if ( maMouseMotionListeners.getLength() == 1 )
929 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
931 if ( xPeerWindow.is() )
932 xPeerWindow->addMouseMotionListener( &maMouseMotionListeners);
935 void UnoControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& rxListener )
937 Reference< XWindow > xPeerWindow;
939 ::osl::MutexGuard aGuard( GetMutex() );
940 if ( maMouseMotionListeners.getLength() == 1 )
941 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
942 maMouseMotionListeners.removeInterface( rxListener );
944 if ( xPeerWindow.is() )
945 xPeerWindow->removeMouseMotionListener( &maMouseMotionListeners );
948 void UnoControl::addPaintListener( const Reference< XPaintListener >& rxListener )
950 Reference< XWindow > xPeerWindow;
952 ::osl::MutexGuard aGuard( GetMutex() );
953 maPaintListeners.addInterface( rxListener );
954 if ( maPaintListeners.getLength() == 1 )
955 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
957 if ( xPeerWindow.is() )
958 xPeerWindow->addPaintListener( &maPaintListeners);
961 void UnoControl::removePaintListener( const Reference< XPaintListener >& rxListener )
963 Reference< XWindow > xPeerWindow;
965 ::osl::MutexGuard aGuard( GetMutex() );
966 if ( maPaintListeners.getLength() == 1 )
967 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
968 maPaintListeners.removeInterface( rxListener );
970 if ( xPeerWindow.is() )
971 xPeerWindow->removePaintListener( &maPaintListeners );
974 // XView
975 sal_Bool UnoControl::setGraphics( const Reference< XGraphics >& rDevice )
977 Reference< XView > xView;
979 ::osl::MutexGuard aGuard( GetMutex() );
981 mxGraphics = rDevice;
982 xView.set(getPeer(), css::uno::UNO_QUERY);
984 return !xView.is() || xView->setGraphics( rDevice );
987 Reference< XGraphics > UnoControl::getGraphics( )
989 return mxGraphics;
992 awt::Size UnoControl::getSize( )
994 ::osl::MutexGuard aGuard( GetMutex() );
995 return awt::Size( maComponentInfos.nWidth, maComponentInfos.nHeight );
998 void UnoControl::draw( sal_Int32 x, sal_Int32 y )
1000 Reference< XWindowPeer > xDrawPeer;
1001 Reference< XView > xDrawPeerView;
1003 bool bDisposeDrawPeer( false );
1005 ::osl::MutexGuard aGuard( GetMutex() );
1007 xDrawPeer = ImplGetCompatiblePeer();
1008 bDisposeDrawPeer = xDrawPeer.is() && ( xDrawPeer != getPeer() );
1010 xDrawPeerView.set( xDrawPeer, UNO_QUERY );
1011 DBG_ASSERT( xDrawPeerView.is(), "UnoControl::draw: no peer!" );
1014 if ( xDrawPeerView.is() )
1016 Reference< XVclWindowPeer > xWindowPeer;
1017 xWindowPeer.set( xDrawPeer, UNO_QUERY );
1018 if ( xWindowPeer.is() )
1019 xWindowPeer->setDesignMode( mbDesignMode );
1020 xDrawPeerView->draw( x, y );
1023 if ( bDisposeDrawPeer )
1024 xDrawPeer->dispose();
1027 void UnoControl::setZoom( float fZoomX, float fZoomY )
1029 Reference< XView > xView;
1031 ::osl::MutexGuard aGuard( GetMutex() );
1033 maComponentInfos.nZoomX = fZoomX;
1034 maComponentInfos.nZoomY = fZoomY;
1036 xView.set(getPeer(), css::uno::UNO_QUERY);
1038 if ( xView.is() )
1039 xView->setZoom( fZoomX, fZoomY );
1042 // XControl
1043 void UnoControl::setContext( const Reference< XInterface >& rxContext )
1045 ::osl::MutexGuard aGuard( GetMutex() );
1047 mxContext = rxContext;
1050 Reference< XInterface > UnoControl::getContext( )
1052 ::osl::MutexGuard aGuard( GetMutex() );
1054 return mxContext;
1057 void UnoControl::peerCreated()
1059 Reference< XWindow > xWindow( getPeer(), UNO_QUERY );
1060 if ( !xWindow.is() )
1061 return;
1063 if ( maWindowListeners.getLength() )
1064 xWindow->addWindowListener( &maWindowListeners );
1066 if ( maFocusListeners.getLength() )
1067 xWindow->addFocusListener( &maFocusListeners );
1069 if ( maKeyListeners.getLength() )
1070 xWindow->addKeyListener( &maKeyListeners );
1072 if ( maMouseListeners.getLength() )
1073 xWindow->addMouseListener( &maMouseListeners );
1075 if ( maMouseMotionListeners.getLength() )
1076 xWindow->addMouseMotionListener( &maMouseMotionListeners );
1078 if ( maPaintListeners.getLength() )
1079 xWindow->addPaintListener( &maPaintListeners );
1082 void UnoControl::createPeer( const Reference< XToolkit >& rxToolkit, const Reference< XWindowPeer >& rParentPeer )
1084 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1085 if ( !mxModel.is() )
1087 RuntimeException aException;
1088 aException.Message = "createPeer: no model!";
1089 aException.Context = static_cast<XAggregation*>(static_cast<cppu::OWeakAggObject*>(this));
1090 throw( aException );
1093 if( !getPeer().is() )
1095 mbCreatingPeer = true;
1097 WindowClass eType;
1098 Reference< XToolkit > xToolkit = rxToolkit;
1099 if( rParentPeer.is() && mxContext.is() )
1101 // kein TopWindow
1102 if ( !xToolkit.is() )
1103 xToolkit = rParentPeer->getToolkit();
1104 Any aAny = OWeakAggObject::queryInterface( cppu::UnoType<XControlContainer>::get());
1105 Reference< XControlContainer > xC;
1106 aAny >>= xC;
1107 if( xC.is() )
1108 // It's a container
1109 eType = WindowClass_CONTAINER;
1110 else
1111 eType = WindowClass_SIMPLE;
1113 else
1114 { // This is only correct for Top Window
1115 if( rParentPeer.is() )
1117 if ( !xToolkit.is() )
1118 xToolkit = rParentPeer->getToolkit();
1119 eType = WindowClass_CONTAINER;
1121 else
1123 if ( !xToolkit.is() )
1124 xToolkit = VCLUnoHelper::CreateToolkit();
1125 eType = WindowClass_TOP;
1128 WindowDescriptor aDescr;
1129 aDescr.Type = eType;
1130 aDescr.WindowServiceName = GetComponentServiceName();
1131 aDescr.Parent = rParentPeer;
1132 aDescr.Bounds = getPosSize();
1133 aDescr.WindowAttributes = 0;
1135 // Border
1136 Reference< XPropertySet > xPSet( mxModel, UNO_QUERY );
1137 Reference< XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
1139 Any aVal;
1140 OUString aPropName = GetPropertyName( BASEPROPERTY_BORDER );
1141 if ( xInfo->hasPropertyByName( aPropName ) )
1143 aVal = xPSet->getPropertyValue( aPropName );
1144 sal_Int16 n = sal_Int16();
1145 if ( aVal >>= n )
1147 if ( n )
1148 aDescr.WindowAttributes |= WindowAttribute::BORDER;
1149 else
1150 aDescr.WindowAttributes |= VclWindowPeerAttribute::NOBORDER;
1154 // DESKTOP_AS_PARENT
1155 if ( aDescr.Type == WindowClass_TOP )
1157 aPropName = GetPropertyName( BASEPROPERTY_DESKTOP_AS_PARENT );
1158 if ( xInfo->hasPropertyByName( aPropName ) )
1160 aVal = xPSet->getPropertyValue( aPropName );
1161 bool b = bool();
1162 if ( ( aVal >>= b ) && b)
1163 aDescr.ParentIndex = -1;
1166 // Moveable
1167 aPropName = GetPropertyName( BASEPROPERTY_MOVEABLE );
1168 if ( xInfo->hasPropertyByName( aPropName ) )
1170 aVal = xPSet->getPropertyValue( aPropName );
1171 bool b = bool();
1172 if ( ( aVal >>= b ) && b)
1173 aDescr.WindowAttributes |= WindowAttribute::MOVEABLE;
1176 // Closeable
1177 aPropName = GetPropertyName( BASEPROPERTY_CLOSEABLE );
1178 if ( xInfo->hasPropertyByName( aPropName ) )
1180 aVal = xPSet->getPropertyValue( aPropName );
1181 bool b = bool();
1182 if ( ( aVal >>= b ) && b)
1183 aDescr.WindowAttributes |= WindowAttribute::CLOSEABLE;
1186 // Dropdown
1187 aPropName = GetPropertyName( BASEPROPERTY_DROPDOWN );
1188 if ( xInfo->hasPropertyByName( aPropName ) )
1190 aVal = xPSet->getPropertyValue( aPropName );
1191 bool b = bool();
1192 if ( ( aVal >>= b ) && b)
1193 aDescr.WindowAttributes |= VclWindowPeerAttribute::DROPDOWN;
1196 // Spin
1197 aPropName = GetPropertyName( BASEPROPERTY_SPIN );
1198 if ( xInfo->hasPropertyByName( aPropName ) )
1200 aVal = xPSet->getPropertyValue( aPropName );
1201 bool b = bool();
1202 if ( ( aVal >>= b ) && b)
1203 aDescr.WindowAttributes |= VclWindowPeerAttribute::SPIN;
1206 // HScroll
1207 aPropName = GetPropertyName( BASEPROPERTY_HSCROLL );
1208 if ( xInfo->hasPropertyByName( aPropName ) )
1210 aVal = xPSet->getPropertyValue( aPropName );
1211 bool b = bool();
1212 if ( ( aVal >>= b ) && b)
1213 aDescr.WindowAttributes |= VclWindowPeerAttribute::HSCROLL;
1216 // VScroll
1217 aPropName = GetPropertyName( BASEPROPERTY_VSCROLL );
1218 if ( xInfo->hasPropertyByName( aPropName ) )
1220 aVal = xPSet->getPropertyValue( aPropName );
1221 bool b = bool();
1222 if ( ( aVal >>= b ) && b)
1223 aDescr.WindowAttributes |= VclWindowPeerAttribute::VSCROLL;
1226 // AutoHScroll
1227 aPropName = GetPropertyName( BASEPROPERTY_AUTOHSCROLL );
1228 if ( xInfo->hasPropertyByName( aPropName ) )
1230 aVal = xPSet->getPropertyValue( aPropName );
1231 bool b = bool();
1232 if ( ( aVal >>= b ) && b)
1233 aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOHSCROLL;
1236 // AutoVScroll
1237 aPropName = GetPropertyName( BASEPROPERTY_AUTOVSCROLL );
1238 if ( xInfo->hasPropertyByName( aPropName ) )
1240 aVal = xPSet->getPropertyValue( aPropName );
1241 bool b = bool();
1242 if ( ( aVal >>= b ) && b)
1243 aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOVSCROLL;
1246 //added for issue79712
1247 //NoLabel
1248 aPropName = GetPropertyName( BASEPROPERTY_NOLABEL );
1249 if ( xInfo->hasPropertyByName( aPropName ) )
1251 aVal = xPSet->getPropertyValue( aPropName );
1252 bool b = bool();
1253 if ( ( aVal >>=b ) && b )
1254 aDescr.WindowAttributes |= VclWindowPeerAttribute::NOLABEL;
1256 //issue79712 ends
1258 // Align
1259 aPropName = GetPropertyName( BASEPROPERTY_ALIGN );
1260 if ( xInfo->hasPropertyByName( aPropName ) )
1262 aVal = xPSet->getPropertyValue( aPropName );
1263 sal_Int16 n = sal_Int16();
1264 if ( aVal >>= n )
1266 if ( n == PROPERTY_ALIGN_LEFT )
1267 aDescr.WindowAttributes |= VclWindowPeerAttribute::LEFT;
1268 else if ( n == PROPERTY_ALIGN_CENTER )
1269 aDescr.WindowAttributes |= VclWindowPeerAttribute::CENTER;
1270 else
1271 aDescr.WindowAttributes |= VclWindowPeerAttribute::RIGHT;
1275 // Allow derivates to manipulate attributes
1276 PrepareWindowDescriptor(aDescr);
1278 // create the peer
1279 setPeer( xToolkit->createWindow( aDescr ) );
1281 // release the mutex guard (and work with copies of our members)
1282 // this is necessary as our peer may lock the SolarMutex (actually, all currently known peers do), so calling
1283 // into the peer with our own mutex locked may cause deadlocks
1284 // (We _really_ need peers which do not use the SolarMutex. It's really pissing me off that from time to
1285 // time deadlocks pop up because the low-level components like our peers use a mutex which usually
1286 // is locked at the top of the stack (it protects the global message looping). This is always dangerous, and
1287 // can not always be solved by tampering with other mutexes.
1288 // Unfortunately, the VCL used in the peers is not threadsafe, and by definition needs a locked SolarMutex.)
1289 // 82300 - 12/21/00 - FS
1290 UnoControlComponentInfos aComponentInfos(maComponentInfos);
1291 bool bDesignMode(mbDesignMode);
1293 Reference< XGraphics > xGraphics( mxGraphics );
1294 Reference< XView > xView ( getPeer(), UNO_QUERY_THROW );
1295 Reference< XWindow > xWindow ( getPeer(), UNO_QUERY_THROW );
1297 aGuard.clear();
1299 // the updateFromModel is done without a locked mutex, too.
1300 // The reason is that the only thing this method does is firing property changes, and this in general has
1301 // to be done without locked mutexes (as every notification to external listeners).
1302 // 82300 - 12/21/00 - FS
1303 updateFromModel();
1305 xView->setZoom( aComponentInfos.nZoomX, aComponentInfos.nZoomY );
1307 setPosSize( aComponentInfos.nX, aComponentInfos.nY, aComponentInfos.nWidth, aComponentInfos.nHeight, aComponentInfos.nFlags );
1309 if( aComponentInfos.bVisible && !bDesignMode )
1310 // Show only after setting the data
1311 xWindow->setVisible( aComponentInfos.bVisible );
1313 if( !aComponentInfos.bEnable )
1314 xWindow->setEnable( aComponentInfos.bEnable );
1316 xView->setGraphics( xGraphics );
1318 peerCreated();
1320 mbCreatingPeer = false;
1324 Reference< XWindowPeer > UnoControl::getPeer()
1326 ::osl::MutexGuard aGuard( GetMutex() );
1327 return mxPeer;
1330 sal_Bool UnoControl::setModel( const Reference< XControlModel >& rxModel )
1332 ::osl::MutexGuard aGuard( GetMutex() );
1334 Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
1336 // query for the XPropertiesChangeListener - our delegator is allowed to overwrite this interface
1337 Reference< XPropertiesChangeListener > xListener;
1338 queryInterface( cppu::UnoType<decltype(xListener)>::get() ) >>= xListener;
1340 if( xPropSet.is() )
1341 xPropSet->removePropertiesChangeListener( xListener );
1343 mpData->bLocalizationSupport = false;
1344 mxModel = rxModel;
1346 if( mxModel.is() )
1350 xPropSet.set( mxModel, UNO_QUERY_THROW );
1351 Reference< XPropertySetInfo > xPSI( xPropSet->getPropertySetInfo(), UNO_SET_THROW );
1353 Sequence< OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
1354 xPropSet->addPropertiesChangeListener( aNames, xListener );
1356 mpData->bLocalizationSupport = xPSI->hasPropertyByName("ResourceResolver");
1358 catch( const Exception& )
1360 DBG_UNHANDLED_EXCEPTION();
1361 mxModel.clear();
1365 return mxModel.is();
1368 Reference< XControlModel > UnoControl::getModel( )
1370 return mxModel;
1373 Reference< XView > UnoControl::getView( )
1375 return static_cast< XView* >( this );
1378 void UnoControl::setDesignMode( sal_Bool bOn )
1380 ModeChangeEvent aModeChangeEvent;
1382 Reference< XWindow > xWindow;
1383 Reference<XComponent> xAccessibleComp;
1385 ::osl::MutexGuard aGuard( GetMutex() );
1386 if ( bool(bOn) == mbDesignMode )
1387 return;
1389 // remember this
1390 mbDesignMode = bOn;
1391 xWindow.set(getPeer(), css::uno::UNO_QUERY);
1393 xAccessibleComp.set(maAccessibleContext, UNO_QUERY);
1394 maAccessibleContext.clear();
1396 aModeChangeEvent.Source = *this;
1397 aModeChangeEvent.NewMode = mbDesignMode ? OUString("design") : OUString("alive" );
1400 // dispose current AccessibleContext, if we have one - without Mutex lock
1401 // (changing the design mode implies having a new implementation for this context,
1402 // so the old one must be declared DEFUNC)
1403 DisposeAccessibleContext(xAccessibleComp);
1405 // adjust the visibility of our window
1406 if ( xWindow.is() )
1407 xWindow->setVisible( !bOn );
1409 // and notify our mode listeners
1410 maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent );
1413 sal_Bool UnoControl::isDesignMode( )
1415 return mbDesignMode;
1418 sal_Bool UnoControl::isTransparent( )
1420 return false;
1423 // XServiceInfo
1424 OUString UnoControl::getImplementationName( )
1426 OSL_FAIL( "This method should be overridden!" );
1427 return OUString();
1430 sal_Bool UnoControl::supportsService( const OUString& rServiceName )
1432 return cppu::supportsService(this, rServiceName);
1435 Sequence< OUString > UnoControl::getSupportedServiceNames( )
1437 OUString sName( "com.sun.star.awt.UnoControl" );
1438 return Sequence< OUString >( &sName, 1 );
1442 Reference< XAccessibleContext > SAL_CALL UnoControl::getAccessibleContext( )
1444 // creation of the context will certainly require the SolarMutex ...
1445 SolarMutexGuard aSolarGuard;
1446 ::osl::MutexGuard aGuard( GetMutex() );
1448 Reference< XAccessibleContext > xCurrentContext( maAccessibleContext.get(), UNO_QUERY );
1449 if ( !xCurrentContext.is() )
1451 if ( !mbDesignMode )
1452 { // in alive mode, use the AccessibleContext of the peer
1453 Reference< XAccessible > xPeerAcc( getPeer(), UNO_QUERY );
1454 if ( xPeerAcc.is() )
1455 xCurrentContext = xPeerAcc->getAccessibleContext( );
1457 else
1458 // in design mode, use a fallback
1459 xCurrentContext = ::toolkit::OAccessibleControlContext::create( this );
1461 DBG_ASSERT( xCurrentContext.is(), "UnoControl::getAccessibleContext: invalid context (invalid peer?)!" );
1462 maAccessibleContext = xCurrentContext;
1464 // get notified when the context is disposed
1465 Reference< XComponent > xContextComp( xCurrentContext, UNO_QUERY );
1466 if ( xContextComp.is() )
1467 xContextComp->addEventListener( this );
1468 // In an ideal world, this is not necessary - there the object would be released as soon as it has been
1469 // disposed, and thus our weak reference would be empty, too.
1470 // But 'til this ideal world comes (means 'til we do never have any refcount/lifetime bugs anymore), we
1471 // need to listen for disposal and reset our weak reference then.
1474 return xCurrentContext;
1477 void SAL_CALL UnoControl::addModeChangeListener( const Reference< XModeChangeListener >& _rxListener )
1479 ::osl::MutexGuard aGuard( GetMutex() );
1480 maModeChangeListeners.addInterface( _rxListener );
1483 void SAL_CALL UnoControl::removeModeChangeListener( const Reference< XModeChangeListener >& _rxListener )
1485 ::osl::MutexGuard aGuard( GetMutex() );
1486 maModeChangeListeners.removeInterface( _rxListener );
1489 void SAL_CALL UnoControl::addModeChangeApproveListener( const Reference< XModeChangeApproveListener >& )
1491 throw NoSupportException( );
1494 void SAL_CALL UnoControl::removeModeChangeApproveListener( const Reference< XModeChangeApproveListener >& )
1496 throw NoSupportException( );
1500 awt::Point SAL_CALL UnoControl::convertPointToLogic( const awt::Point& i_Point, ::sal_Int16 i_TargetUnit )
1502 Reference< XUnitConversion > xPeerConversion;
1504 ::osl::MutexGuard aGuard( GetMutex() );
1505 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1507 if ( xPeerConversion.is() )
1508 return xPeerConversion->convertPointToLogic( i_Point, i_TargetUnit );
1509 return awt::Point( );
1513 awt::Point SAL_CALL UnoControl::convertPointToPixel( const awt::Point& i_Point, ::sal_Int16 i_SourceUnit )
1515 Reference< XUnitConversion > xPeerConversion;
1517 ::osl::MutexGuard aGuard( GetMutex() );
1518 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1520 if ( xPeerConversion.is() )
1521 return xPeerConversion->convertPointToPixel( i_Point, i_SourceUnit );
1522 return awt::Point( );
1526 awt::Size SAL_CALL UnoControl::convertSizeToLogic( const awt::Size& i_Size, ::sal_Int16 i_TargetUnit )
1528 Reference< XUnitConversion > xPeerConversion;
1530 ::osl::MutexGuard aGuard( GetMutex() );
1531 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1533 if ( xPeerConversion.is() )
1534 return xPeerConversion->convertSizeToLogic( i_Size, i_TargetUnit );
1535 return awt::Size( );
1539 awt::Size SAL_CALL UnoControl::convertSizeToPixel( const awt::Size& i_Size, ::sal_Int16 i_SourceUnit )
1541 Reference< XUnitConversion > xPeerConversion;
1543 ::osl::MutexGuard aGuard( GetMutex() );
1544 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1546 if ( xPeerConversion.is() )
1547 return xPeerConversion->convertSizeToPixel( i_Size, i_SourceUnit );
1548 return awt::Size( );
1552 uno::Reference< awt::XStyleSettings > SAL_CALL UnoControl::getStyleSettings()
1554 Reference< awt::XStyleSettingsSupplier > xPeerSupplier;
1556 ::osl::MutexGuard aGuard( GetMutex() );
1557 xPeerSupplier.set(getPeer(), css::uno::UNO_QUERY);
1559 if ( xPeerSupplier.is() )
1560 return xPeerSupplier->getStyleSettings();
1561 return nullptr;
1564 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */