update credits
[LibreOffice.git] / toolkit / source / controls / unocontrol.cxx
blob6daf050551507be7ad40217f0d509e288460575d
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 <boost/noncopyable.hpp>
23 #include <com/sun/star/awt/XControlContainer.hpp>
24 #include <com/sun/star/awt/WindowAttribute.hpp>
25 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
26 #include <com/sun/star/awt/PosSize.hpp>
27 #include <com/sun/star/beans/PropertyValue.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 { 0, 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: private boost::noncopyable
100 private:
101 VCLXWindow* m_pLockWindow;
103 public:
104 inline VclListenerLock( VCLXWindow* _pLockWindow )
105 :m_pLockWindow( _pLockWindow )
107 if ( m_pLockWindow )
108 m_pLockWindow->suspendVclEventListening( );
110 inline ~VclListenerLock( )
112 if ( m_pLockWindow )
113 m_pLockWindow->resumeVclEventListening( );
117 typedef ::std::map< OUString, sal_Int32 > MapString2Int;
118 struct UnoControl_Data
120 MapString2Int aSuspendedPropertyNotifications;
121 /// true if and only if our model has a property ResourceResolver
122 bool bLocalizationSupport;
124 UnoControl_Data()
125 :aSuspendedPropertyNotifications()
126 ,bLocalizationSupport( false )
131 UnoControl::UnoControl() :
132 maDisposeListeners( *this )
133 , maWindowListeners( *this )
134 , maFocusListeners( *this )
135 , maKeyListeners( *this )
136 , maMouseListeners( *this )
137 , maMouseMotionListeners( *this )
138 , maPaintListeners( *this )
139 , maModeChangeListeners( GetMutex() )
140 , mpData( new UnoControl_Data )
142 mbDisposePeer = true;
143 mbRefeshingPeer = false;
144 mbCreatingPeer = false;
145 mbCreatingCompatiblePeer = false;
146 mbDesignMode = false;
149 UnoControl::~UnoControl()
151 DELETEZ( mpData );
154 OUString UnoControl::GetComponentServiceName()
156 return OUString();
159 Reference< XWindowPeer > UnoControl::ImplGetCompatiblePeer( bool bAcceptExistingPeer )
161 DBG_ASSERT( !mbCreatingCompatiblePeer, "ImplGetCompatiblePeer - rekursive?" );
163 mbCreatingCompatiblePeer = true;
165 Reference< XWindowPeer > xCompatiblePeer;
167 if ( bAcceptExistingPeer )
168 xCompatiblePeer = getPeer();
170 if ( !xCompatiblePeer.is() )
172 // Create the pair as invisible
173 bool bVis = maComponentInfos.bVisible;
174 if( bVis )
175 maComponentInfos.bVisible = false;
177 Reference< XWindowPeer > xCurrentPeer = getPeer();
178 setPeer( NULL );
180 // queryInterface ourself, to allow aggregation
181 Reference< XControl > xMe;
182 OWeakAggObject::queryInterface( cppu::UnoType<decltype(xMe)>::get() ) >>= xMe;
184 vcl::Window* pParentWindow( NULL );
186 SolarMutexGuard aGuard;
187 pParentWindow = dynamic_cast< vcl::Window* >( Application::GetDefaultDevice() );
188 ENSURE_OR_THROW( pParentWindow != NULL, "could obtain a default parent window!" );
192 xMe->createPeer( NULL, pParentWindow->GetComponentInterface( true ) );
194 catch( const Exception& )
196 mbCreatingCompatiblePeer = false;
197 throw;
199 xCompatiblePeer = getPeer();
200 setPeer( xCurrentPeer );
202 if ( xCompatiblePeer.is() && mxGraphics.is() )
204 Reference< XView > xPeerView( xCompatiblePeer, UNO_QUERY );
205 if ( xPeerView.is() )
206 xPeerView->setGraphics( mxGraphics );
209 if( bVis )
210 maComponentInfos.bVisible = true;
213 mbCreatingCompatiblePeer = false;
215 return xCompatiblePeer;
218 bool UnoControl::ImplCheckLocalize( OUString& _rPossiblyLocalizable )
220 if ( !mpData->bLocalizationSupport
221 || ( _rPossiblyLocalizable.isEmpty() )
222 || ( _rPossiblyLocalizable[0] != '&' )
223 // TODO: make this reasonable. At the moment, everything which by accident starts with a & is considered
224 // localizable, which is probably wrong.
226 return false;
230 Reference< XPropertySet > xPropSet( mxModel, UNO_QUERY_THROW );
231 Reference< resource::XStringResourceResolver > xStringResourceResolver(
232 xPropSet->getPropertyValue("ResourceResolver"),
233 UNO_QUERY
235 if ( xStringResourceResolver.is() )
237 OUString aLocalizationKey( _rPossiblyLocalizable.copy( 1 ) );
238 _rPossiblyLocalizable = xStringResourceResolver->resolveString( aLocalizationKey );
239 return true;
242 catch( const Exception& )
244 DBG_UNHANDLED_EXCEPTION();
246 return false;
249 void UnoControl::ImplSetPeerProperty( const OUString& rPropName, const Any& rVal )
251 // since a change made in propertiesChange, we can't be sure that this is called with an valid getPeer(),
252 // this assumption may be false in some (seldom) multi-threading scenarios (cause propertiesChange
253 // releases our mutex before calling here in)
254 // That's why this additional check
256 if ( mxVclWindowPeer.is() )
258 Any aConvertedValue( rVal );
260 if ( mpData->bLocalizationSupport )
262 // We now support a mapping for language dependent properties. This is the
263 // central method to implement it.
264 if( rPropName == "Text" ||
265 rPropName == "Label" ||
266 rPropName == "Title" ||
267 rPropName == "HelpText" ||
268 rPropName == "CurrencySymbol" ||
269 rPropName == "StringItemList" )
271 OUString aValue;
272 uno::Sequence< OUString > aSeqValue;
273 if ( aConvertedValue >>= aValue )
275 if ( ImplCheckLocalize( aValue ) )
276 aConvertedValue <<= aValue;
278 else if ( aConvertedValue >>= aSeqValue )
280 for ( sal_Int32 i = 0; i < aSeqValue.getLength(); i++ )
281 ImplCheckLocalize( aSeqValue[i] );
282 aConvertedValue <<= aSeqValue;
287 mxVclWindowPeer->setProperty( rPropName, aConvertedValue );
291 void UnoControl::PrepareWindowDescriptor( WindowDescriptor& )
295 Reference< XWindow > UnoControl::getParentPeer() const
297 Reference< XWindow > xPeer;
298 if( mxContext.is() )
300 Reference< XControl > xContComp( mxContext, UNO_QUERY );
301 if ( xContComp.is() )
303 Reference< XWindowPeer > xP = xContComp->getPeer();
304 if ( xP.is() )
305 xPeer.set( xP, UNO_QUERY );
308 return xPeer;
311 void UnoControl::updateFromModel()
313 // Read default properties and hand over to peer
314 if( getPeer().is() )
316 Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
317 if( xPropSet.is() )
319 Sequence< OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
320 xPropSet->firePropertiesChangeEvent( aNames, this );
326 // XTypeProvider
327 IMPL_IMPLEMENTATION_ID( UnoControl )
329 void
330 UnoControl::DisposeAccessibleContext(Reference<XComponent> const& xContextComp)
332 if (xContextComp.is())
336 xContextComp->removeEventListener( this );
337 xContextComp->dispose();
339 catch( const Exception& )
341 OSL_FAIL( "UnoControl::disposeAccessibleContext: could not dispose my AccessibleContext!" );
346 void UnoControl::dispose( ) throw(RuntimeException, std::exception)
348 Reference< XWindowPeer > xPeer;
349 Reference<XComponent> xAccessibleComp;
351 ::osl::MutexGuard aGuard( GetMutex() );
352 if( mbDisposePeer )
354 xPeer = mxPeer;
356 setPeer( NULL );
357 xAccessibleComp.set(maAccessibleContext, UNO_QUERY);
358 maAccessibleContext.clear();
360 if( xPeer.is() )
362 xPeer->dispose();
365 // dispose our AccessibleContext - without Mutex locked
366 DisposeAccessibleContext(xAccessibleComp);
368 EventObject aDisposeEvent;
369 aDisposeEvent.Source = static_cast< XAggregation* >( this );
371 maDisposeListeners.disposeAndClear( aDisposeEvent );
372 maWindowListeners.disposeAndClear( aDisposeEvent );
373 maFocusListeners.disposeAndClear( aDisposeEvent );
374 maKeyListeners.disposeAndClear( aDisposeEvent );
375 maMouseListeners.disposeAndClear( aDisposeEvent );
376 maMouseMotionListeners.disposeAndClear( aDisposeEvent );
377 maPaintListeners.disposeAndClear( aDisposeEvent );
378 maModeChangeListeners.disposeAndClear( aDisposeEvent );
380 // release Model again
381 setModel( Reference< XControlModel > () );
382 setContext( Reference< XInterface > () );
385 void UnoControl::addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException, std::exception)
387 ::osl::MutexGuard aGuard( GetMutex() );
389 maDisposeListeners.addInterface( rxListener );
392 void UnoControl::removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException, std::exception)
394 ::osl::MutexGuard aGuard( GetMutex() );
396 maDisposeListeners.removeInterface( rxListener );
399 bool UnoControl::requiresNewPeer( const OUString& /* _rPropertyName */ ) const
401 return false;
404 // XPropertiesChangeListener
405 void UnoControl::propertiesChange( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException, std::exception)
407 Sequence< PropertyChangeEvent > aEvents( rEvents );
409 ::osl::MutexGuard aGuard( GetMutex() );
411 if ( !mpData->aSuspendedPropertyNotifications.empty() )
413 // strip the property which we are currently updating (somewhere up the stack)
414 PropertyChangeEvent* pEvents = aEvents.getArray();
415 PropertyChangeEvent* pEventsEnd = pEvents + aEvents.getLength();
416 for ( ; pEvents < pEventsEnd; )
417 if ( mpData->aSuspendedPropertyNotifications.find( pEvents->PropertyName ) != mpData->aSuspendedPropertyNotifications.end() )
419 if ( pEvents != pEventsEnd )
420 ::std::copy( pEvents + 1, pEventsEnd, pEvents );
421 --pEventsEnd;
423 else
424 ++pEvents;
425 aEvents.realloc( pEventsEnd - aEvents.getConstArray() );
427 if ( !aEvents.getLength() )
428 return;
432 ImplModelPropertiesChanged( aEvents );
435 void UnoControl::ImplLockPropertyChangeNotification( const OUString& rPropertyName, bool bLock )
437 MapString2Int::iterator pos = mpData->aSuspendedPropertyNotifications.find( rPropertyName );
438 if ( bLock )
440 if ( pos == mpData->aSuspendedPropertyNotifications.end() )
441 pos = mpData->aSuspendedPropertyNotifications.insert( MapString2Int::value_type( rPropertyName, 0 ) ).first;
442 ++pos->second;
444 else
446 OSL_ENSURE( pos != mpData->aSuspendedPropertyNotifications.end(), "UnoControl::ImplLockPropertyChangeNotification: property not locked!" );
447 if ( pos != mpData->aSuspendedPropertyNotifications.end() )
449 OSL_ENSURE( pos->second > 0, "UnoControl::ImplLockPropertyChangeNotification: invalid suspension counter!" );
450 if ( 0 == --pos->second )
451 mpData->aSuspendedPropertyNotifications.erase( pos );
456 void UnoControl::ImplLockPropertyChangeNotifications( const Sequence< OUString >& rPropertyNames, bool bLock )
458 for ( const OUString* pPropertyName = rPropertyNames.getConstArray();
459 pPropertyName != rPropertyNames.getConstArray() + rPropertyNames.getLength();
460 ++pPropertyName
462 ImplLockPropertyChangeNotification( *pPropertyName, bLock );
465 void UnoControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents )
467 ::osl::ClearableGuard< ::osl::Mutex > aGuard( GetMutex() );
469 if( getPeer().is() )
471 std::vector< PropertyValue > aPeerPropertiesToSet;
472 sal_Int32 nIndependentPos = 0;
473 bool bResourceResolverSet( false );
474 // position where to insert the independent properties into aPeerPropertiesToSet,
475 // dependent ones are inserted at the end of the vector
477 bool bNeedNewPeer = false;
478 // some properties require a re-creation of the peer, 'cause they can't be changed on the fly
480 Reference< XControlModel > xOwnModel( getModel(), UNO_QUERY );
481 // our own model for comparison
482 Reference< XPropertySet > xPS( xOwnModel, UNO_QUERY );
483 Reference< XPropertySetInfo > xPSI( xPS->getPropertySetInfo(), UNO_QUERY );
484 OSL_ENSURE( xPSI.is(), "UnoControl::ImplModelPropertiesChanged: should have property set meta data!" );
486 const PropertyChangeEvent* pEvents = rEvents.getConstArray();
488 sal_Int32 nLen = rEvents.getLength();
489 aPeerPropertiesToSet.reserve(nLen);
491 for( sal_Int32 i = 0; i < nLen; ++i, ++pEvents )
493 Reference< XControlModel > xModel( pEvents->Source, UNO_QUERY );
494 bool bOwnModel = xModel.get() == xOwnModel.get();
495 if ( !bOwnModel )
496 continue;
498 // Detect changes on our resource resolver which invalidates
499 // automatically some language dependent properties.
500 if ( pEvents->PropertyName == "ResourceResolver" )
502 Reference< resource::XStringResourceResolver > xStrResolver;
503 if ( pEvents->NewValue >>= xStrResolver )
504 bResourceResolverSet = xStrResolver.is();
507 sal_uInt16 nPType = GetPropertyId( pEvents->PropertyName );
508 if ( mbDesignMode && mbDisposePeer && !mbRefeshingPeer && !mbCreatingPeer )
510 // if we're in design mode, then some properties can change which
511 // require creating a *new* peer (since these properties cannot
512 // be switched at existing peers)
513 if ( nPType )
514 bNeedNewPeer = ( nPType == BASEPROPERTY_BORDER )
515 || ( nPType == BASEPROPERTY_MULTILINE )
516 || ( nPType == BASEPROPERTY_DROPDOWN )
517 || ( nPType == BASEPROPERTY_HSCROLL )
518 || ( nPType == BASEPROPERTY_VSCROLL )
519 || ( nPType == BASEPROPERTY_AUTOHSCROLL )
520 || ( nPType == BASEPROPERTY_AUTOVSCROLL )
521 || ( nPType == BASEPROPERTY_ORIENTATION )
522 || ( nPType == BASEPROPERTY_SPIN )
523 || ( nPType == BASEPROPERTY_ALIGN )
524 || ( nPType == BASEPROPERTY_PAINTTRANSPARENT );
525 else
526 bNeedNewPeer = requiresNewPeer( pEvents->PropertyName );
528 if ( bNeedNewPeer )
529 break;
532 if ( nPType && ( nLen > 1 ) && DoesDependOnOthers( nPType ) )
534 // Add properties with dependencies on other properties last
535 // since they're dependent on properties added later (such as
536 // VALUE dependency on VALUEMIN/MAX)
537 aPeerPropertiesToSet.push_back(PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
539 else
541 if ( bResourceResolverSet )
543 // The resource resolver property change should be one of the first ones.
544 // All language dependent properties are dependent on this property.
545 // As BASEPROPERTY_NATIVE_WIDGET_LOOK is not dependent on resource
546 // resolver. We don't need to handle a special order for these two props.
547 aPeerPropertiesToSet.insert(
548 aPeerPropertiesToSet.begin(),
549 PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
550 ++nIndependentPos;
552 else if ( nPType == BASEPROPERTY_NATIVE_WIDGET_LOOK )
554 // since *a lot* of other properties might be overruled by this one, we need
555 // a special handling:
556 // NativeWidgetLook needs to be set first: If it is set to ON, all other
557 // properties describing the look (e.g. BackgroundColor) are ignored, anyway.
558 // If it is switched OFF, then we need to do it first because else it will
559 // overrule other look-related properties, and re-initialize them from system
560 // defaults.
561 aPeerPropertiesToSet.insert(
562 aPeerPropertiesToSet.begin(),
563 PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
564 ++nIndependentPos;
566 else
568 aPeerPropertiesToSet.insert(aPeerPropertiesToSet.begin() + nIndependentPos,
569 PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
570 ++nIndependentPos;
575 Reference< XWindow > xParent = getParentPeer();
576 Reference< XControl > xThis( (XAggregation*)(::cppu::OWeakAggObject*)this, UNO_QUERY );
577 // call createPeer via a interface got from queryInterface, so the aggregating class can intercept it
579 DBG_ASSERT( !bNeedNewPeer || xParent.is(), "Need new peer, but don't have a parent!" );
581 // Check if we have to update language dependent properties
582 if ( !bNeedNewPeer && bResourceResolverSet )
584 // Add language dependent properties into the peer property set.
585 // Our resource resolver has been changed and we must be sure
586 // that language dependent props use the new resolver.
587 const LanguageDependentProp* pLangDepProp = aLanguageDependentProp;
588 while ( pLangDepProp->pPropName != 0 )
590 bool bMustBeInserted( true );
591 for ( sal_uInt32 i = 0; i < aPeerPropertiesToSet.size(); i++ )
593 if ( aPeerPropertiesToSet[i].Name.equalsAsciiL(
594 pLangDepProp->pPropName, pLangDepProp->nPropNameLength ))
596 bMustBeInserted = false;
597 break;
601 if ( bMustBeInserted )
603 // Add language dependent props at the end
604 OUString aPropName( OUString::createFromAscii( pLangDepProp->pPropName ));
605 if ( xPSI.is() && xPSI->hasPropertyByName( aPropName ) )
607 aPeerPropertiesToSet.push_back(
608 PropertyValue( aPropName, 0, xPS->getPropertyValue( aPropName ), PropertyState_DIRECT_VALUE ) );
612 ++pLangDepProp;
615 aGuard.clear();
617 // clear the guard before creating a new peer - as usual, our peer implementations use the SolarMutex
619 if (bNeedNewPeer && xParent.is())
621 SolarMutexGuard aVclGuard;
622 // and now this is the final withdrawal:
623 // I have no other idea than locking the SolarMutex here ....
624 // I really hate the fact that VCL is not theadsafe ....
626 // Doesn't work for Container!
627 getPeer()->dispose();
628 mxPeer.clear();
629 mxVclWindowPeer = NULL;
630 mbRefeshingPeer = true;
631 Reference< XWindowPeer > xP( xParent, UNO_QUERY );
632 xThis->createPeer( Reference< XToolkit > (), xP );
633 mbRefeshingPeer = false;
634 aPeerPropertiesToSet.clear();
637 // lock the multiplexing of VCL events to our UNO listeners
638 // this is for compatibility reasons: in OOo 1.0.x, changes which were done at the
639 // model did not cause the listeners of the controls/peers to be called
640 // Since the implementations for the listeners changed a lot towards 1.1, this
641 // would not be the case anymore, if we would not do this listener-lock below
642 // #i14703#
643 VCLXWindow* pPeer;
645 SolarMutexGuard g;
646 vcl::Window* pVclPeer = VCLUnoHelper::GetWindow( getPeer() );
647 pPeer = pVclPeer ? pVclPeer->GetWindowPeer() : NULL;
649 VclListenerLock aNoVclEventMultiplexing( pPeer );
651 // setting peer properties may result in an attempt to acquire the solar mutex, 'cause the peers
652 // usually don't have an own mutex but use the SolarMutex instead.
653 // To prevent deadlocks resulting from this, we do this without our own mutex locked
654 std::vector< PropertyValue >::iterator aEnd = aPeerPropertiesToSet.end();
655 for ( std::vector< PropertyValue >::iterator aLoop = aPeerPropertiesToSet.begin();
656 aLoop != aEnd;
657 ++aLoop
660 ImplSetPeerProperty( aLoop->Name, aLoop->Value );
665 void UnoControl::disposing( const EventObject& rEvt ) throw(RuntimeException, std::exception)
667 ::osl::ClearableMutexGuard aGuard( GetMutex() );
668 // do not compare differing types in case of multible inheritance
670 if ( maAccessibleContext.get() == rEvt.Source )
672 // just in case the context is disposed, but not released - ensure that we do not re-use it in the future
673 maAccessibleContext = NULL;
675 else if( mxModel.get() == Reference< XControlModel >(rEvt.Source,UNO_QUERY).get() )
677 // #62337# if the model dies, it does not make sense for us to live ...
678 Reference< XControl > xThis = this;
680 aGuard.clear();
681 xThis->dispose();
683 DBG_ASSERT( !mxModel.is(), "UnoControl::disposing: invalid dispose behaviour!" );
684 mxModel.clear();
689 void SAL_CALL UnoControl::setOutputSize( const awt::Size& aSize ) throw (RuntimeException, std::exception)
691 Reference< XWindow2 > xPeerWindow;
693 ::osl::MutexGuard aGuard( GetMutex() );
694 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
697 if ( xPeerWindow.is() )
698 xPeerWindow->setOutputSize( aSize );
701 namespace
703 template < typename RETVALTYPE, typename DEFAULTTYPE >
704 RETVALTYPE lcl_askPeer( const uno::Reference< awt::XWindowPeer >& _rxPeer, RETVALTYPE (SAL_CALL XWindow2::*_pMethod)(), DEFAULTTYPE _aDefault )
706 RETVALTYPE aReturn( _aDefault );
708 Reference< XWindow2 > xPeerWindow( _rxPeer, UNO_QUERY );
709 if ( xPeerWindow.is() )
710 aReturn = (xPeerWindow.get()->*_pMethod)();
712 return aReturn;
716 awt::Size SAL_CALL UnoControl::getOutputSize( ) throw (RuntimeException, std::exception)
718 return lcl_askPeer( getPeer(), &XWindow2::getOutputSize, awt::Size() );
721 sal_Bool SAL_CALL UnoControl::isVisible( ) throw (RuntimeException, std::exception)
723 return lcl_askPeer( getPeer(), &XWindow2::isVisible, maComponentInfos.bVisible );
726 sal_Bool SAL_CALL UnoControl::isActive( ) throw (RuntimeException, std::exception)
728 return lcl_askPeer( getPeer(), &XWindow2::isActive, sal_False );
731 sal_Bool SAL_CALL UnoControl::isEnabled( ) throw (RuntimeException, std::exception)
733 return lcl_askPeer( getPeer(), &XWindow2::isEnabled, maComponentInfos.bEnable );
736 sal_Bool SAL_CALL UnoControl::hasFocus( ) throw (RuntimeException, std::exception)
738 return lcl_askPeer( getPeer(), &XWindow2::hasFocus, sal_False );
741 // XWindow
742 void UnoControl::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw(RuntimeException, std::exception)
744 Reference< XWindow > xWindow;
746 ::osl::MutexGuard aGuard( GetMutex() );
748 if ( Flags & awt::PosSize::X )
749 maComponentInfos.nX = X;
750 if ( Flags & awt::PosSize::Y )
751 maComponentInfos.nY = Y;
752 if ( Flags & awt::PosSize::WIDTH )
753 maComponentInfos.nWidth = Width;
754 if ( Flags & awt::PosSize::HEIGHT )
755 maComponentInfos.nHeight = Height;
756 maComponentInfos.nFlags |= Flags;
758 xWindow.set(getPeer(), css::uno::UNO_QUERY);
761 if( xWindow.is() )
762 xWindow->setPosSize( X, Y, Width, Height, Flags );
765 awt::Rectangle UnoControl::getPosSize( ) throw(RuntimeException, std::exception)
767 awt::Rectangle aRect( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight);
768 Reference< XWindow > xWindow;
771 ::osl::MutexGuard aGuard( GetMutex() );
772 xWindow.set(getPeer(), css::uno::UNO_QUERY);
775 if( xWindow.is() )
776 aRect = xWindow->getPosSize();
777 return aRect;
780 void UnoControl::setVisible( sal_Bool bVisible ) throw(RuntimeException, std::exception)
782 Reference< XWindow > xWindow;
784 ::osl::MutexGuard aGuard( GetMutex() );
786 // Visible status is handled by View
787 maComponentInfos.bVisible = bVisible;
788 xWindow.set(getPeer(), css::uno::UNO_QUERY);
790 if ( xWindow.is() )
791 xWindow->setVisible( bVisible );
794 void UnoControl::setEnable( sal_Bool bEnable ) throw(RuntimeException, std::exception)
796 Reference< XWindow > xWindow;
798 ::osl::MutexGuard aGuard( GetMutex() );
800 // Enable status is handled by View
801 maComponentInfos.bEnable = bEnable;
802 xWindow.set(getPeer(), css::uno::UNO_QUERY);
804 if ( xWindow.is() )
805 xWindow->setEnable( bEnable );
808 void UnoControl::setFocus( ) throw(RuntimeException, std::exception)
810 Reference< XWindow > xWindow;
812 ::osl::MutexGuard aGuard( GetMutex() );
813 xWindow.set(getPeer(), css::uno::UNO_QUERY);
815 if ( xWindow.is() )
816 xWindow->setFocus();
819 void UnoControl::addWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException, std::exception)
821 Reference< XWindow > xPeerWindow;
823 ::osl::MutexGuard aGuard( GetMutex() );
824 maWindowListeners.addInterface( rxListener );
825 if ( maWindowListeners.getLength() == 1 )
826 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
828 if ( xPeerWindow.is() )
829 xPeerWindow->addWindowListener( &maWindowListeners );
832 void UnoControl::removeWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException, std::exception)
834 Reference< XWindow > xPeerWindow;
836 ::osl::MutexGuard aGuard( GetMutex() );
837 if ( maWindowListeners.getLength() == 1 )
838 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
839 maWindowListeners.removeInterface( rxListener );
841 if ( xPeerWindow.is() )
842 xPeerWindow->removeWindowListener( &maWindowListeners );
845 void UnoControl::addFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException, std::exception)
847 Reference< XWindow > xPeerWindow;
849 ::osl::MutexGuard aGuard( GetMutex() );
850 maFocusListeners.addInterface( rxListener );
851 if ( maFocusListeners.getLength() == 1 )
852 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
854 if ( xPeerWindow.is() )
855 xPeerWindow->addFocusListener( &maFocusListeners );
858 void UnoControl::removeFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException, std::exception)
860 Reference< XWindow > xPeerWindow;
862 ::osl::MutexGuard aGuard( GetMutex() );
863 if ( maFocusListeners.getLength() == 1 )
864 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
865 maFocusListeners.removeInterface( rxListener );
867 if ( xPeerWindow.is() )
868 xPeerWindow->removeFocusListener( &maFocusListeners );
871 void UnoControl::addKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException, std::exception)
873 Reference< XWindow > xPeerWindow;
875 ::osl::MutexGuard aGuard( GetMutex() );
876 maKeyListeners.addInterface( rxListener );
877 if ( maKeyListeners.getLength() == 1 )
878 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
880 if ( xPeerWindow.is() )
881 xPeerWindow->addKeyListener( &maKeyListeners);
884 void UnoControl::removeKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException, std::exception)
886 Reference< XWindow > xPeerWindow;
888 ::osl::MutexGuard aGuard( GetMutex() );
889 if ( maKeyListeners.getLength() == 1 )
890 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
891 maKeyListeners.removeInterface( rxListener );
893 if ( xPeerWindow.is() )
894 xPeerWindow->removeKeyListener( &maKeyListeners);
897 void UnoControl::addMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException, std::exception)
899 Reference< XWindow > xPeerWindow;
901 ::osl::MutexGuard aGuard( GetMutex() );
902 maMouseListeners.addInterface( rxListener );
903 if ( maMouseListeners.getLength() == 1 )
904 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
906 if ( xPeerWindow.is() )
907 xPeerWindow->addMouseListener( &maMouseListeners);
910 void UnoControl::removeMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException, std::exception)
912 Reference< XWindow > xPeerWindow;
914 ::osl::MutexGuard aGuard( GetMutex() );
915 if ( maMouseListeners.getLength() == 1 )
916 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
917 maMouseListeners.removeInterface( rxListener );
919 if ( xPeerWindow.is() )
920 xPeerWindow->removeMouseListener( &maMouseListeners );
923 void UnoControl::addMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException, std::exception)
925 Reference< XWindow > xPeerWindow;
927 ::osl::MutexGuard aGuard( GetMutex() );
928 maMouseMotionListeners.addInterface( rxListener );
929 if ( maMouseMotionListeners.getLength() == 1 )
930 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
932 if ( xPeerWindow.is() )
933 xPeerWindow->addMouseMotionListener( &maMouseMotionListeners);
936 void UnoControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException, std::exception)
938 Reference< XWindow > xPeerWindow;
940 ::osl::MutexGuard aGuard( GetMutex() );
941 if ( maMouseMotionListeners.getLength() == 1 )
942 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
943 maMouseMotionListeners.removeInterface( rxListener );
945 if ( xPeerWindow.is() )
946 xPeerWindow->removeMouseMotionListener( &maMouseMotionListeners );
949 void UnoControl::addPaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException, std::exception)
951 Reference< XWindow > xPeerWindow;
953 ::osl::MutexGuard aGuard( GetMutex() );
954 maPaintListeners.addInterface( rxListener );
955 if ( maPaintListeners.getLength() == 1 )
956 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
958 if ( xPeerWindow.is() )
959 xPeerWindow->addPaintListener( &maPaintListeners);
962 void UnoControl::removePaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException, std::exception)
964 Reference< XWindow > xPeerWindow;
966 ::osl::MutexGuard aGuard( GetMutex() );
967 if ( maPaintListeners.getLength() == 1 )
968 xPeerWindow.set(getPeer(), css::uno::UNO_QUERY);
969 maPaintListeners.removeInterface( rxListener );
971 if ( xPeerWindow.is() )
972 xPeerWindow->removePaintListener( &maPaintListeners );
975 // XView
976 sal_Bool UnoControl::setGraphics( const Reference< XGraphics >& rDevice ) throw(RuntimeException, std::exception)
978 Reference< XView > xView;
980 ::osl::MutexGuard aGuard( GetMutex() );
982 mxGraphics = rDevice;
983 xView.set(getPeer(), css::uno::UNO_QUERY);
985 return xView.is() ? xView->setGraphics( rDevice ) : sal_True;
988 Reference< XGraphics > UnoControl::getGraphics( ) throw(RuntimeException, std::exception)
990 return mxGraphics;
993 awt::Size UnoControl::getSize( ) throw(RuntimeException, std::exception)
995 ::osl::MutexGuard aGuard( GetMutex() );
996 return awt::Size( maComponentInfos.nWidth, maComponentInfos.nHeight );
999 void UnoControl::draw( sal_Int32 x, sal_Int32 y ) throw(RuntimeException, std::exception)
1001 Reference< XWindowPeer > xDrawPeer;
1002 Reference< XView > xDrawPeerView;
1004 bool bDisposeDrawPeer( false );
1006 ::osl::MutexGuard aGuard( GetMutex() );
1008 xDrawPeer = ImplGetCompatiblePeer( true );
1009 bDisposeDrawPeer = xDrawPeer.is() && ( xDrawPeer != getPeer() );
1011 xDrawPeerView.set( xDrawPeer, UNO_QUERY );
1012 DBG_ASSERT( xDrawPeerView.is(), "UnoControl::draw: no peer!" );
1015 if ( xDrawPeerView.is() )
1017 Reference< XVclWindowPeer > xWindowPeer;
1018 xWindowPeer.set( xDrawPeer, UNO_QUERY );
1019 if ( xWindowPeer.is() )
1020 xWindowPeer->setDesignMode( mbDesignMode );
1021 xDrawPeerView->draw( x, y );
1024 if ( bDisposeDrawPeer )
1025 xDrawPeer->dispose();
1028 void UnoControl::setZoom( float fZoomX, float fZoomY ) throw(RuntimeException, std::exception)
1030 Reference< XView > xView;
1032 ::osl::MutexGuard aGuard( GetMutex() );
1034 maComponentInfos.nZoomX = fZoomX;
1035 maComponentInfos.nZoomY = fZoomY;
1037 xView.set(getPeer(), css::uno::UNO_QUERY);
1039 if ( xView.is() )
1040 xView->setZoom( fZoomX, fZoomY );
1043 // XControl
1044 void UnoControl::setContext( const Reference< XInterface >& rxContext ) throw(RuntimeException, std::exception)
1046 ::osl::MutexGuard aGuard( GetMutex() );
1048 mxContext = rxContext;
1051 Reference< XInterface > UnoControl::getContext( ) throw(RuntimeException, std::exception)
1053 ::osl::MutexGuard aGuard( GetMutex() );
1055 return mxContext;
1058 void UnoControl::peerCreated()
1060 Reference< XWindow > xWindow( getPeer(), UNO_QUERY );
1061 if ( !xWindow.is() )
1062 return;
1064 if ( maWindowListeners.getLength() )
1065 xWindow->addWindowListener( &maWindowListeners );
1067 if ( maFocusListeners.getLength() )
1068 xWindow->addFocusListener( &maFocusListeners );
1070 if ( maKeyListeners.getLength() )
1071 xWindow->addKeyListener( &maKeyListeners );
1073 if ( maMouseListeners.getLength() )
1074 xWindow->addMouseListener( &maMouseListeners );
1076 if ( maMouseMotionListeners.getLength() )
1077 xWindow->addMouseMotionListener( &maMouseMotionListeners );
1079 if ( maPaintListeners.getLength() )
1080 xWindow->addPaintListener( &maPaintListeners );
1083 void UnoControl::createPeer( const Reference< XToolkit >& rxToolkit, const Reference< XWindowPeer >& rParentPeer ) throw(RuntimeException, std::exception)
1085 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1086 if ( !mxModel.is() )
1088 RuntimeException aException;
1089 aException.Message = "createPeer: no model!";
1090 aException.Context = (XAggregation*)(::cppu::OWeakAggObject*)this;
1091 throw( aException );
1094 if( !getPeer().is() )
1096 mbCreatingPeer = true;
1098 WindowClass eType;
1099 Reference< XToolkit > xToolkit = rxToolkit;
1100 if( rParentPeer.is() && mxContext.is() )
1102 // kein TopWindow
1103 if ( !xToolkit.is() )
1104 xToolkit = rParentPeer->getToolkit();
1105 Any aAny = OWeakAggObject::queryInterface( cppu::UnoType<XControlContainer>::get());
1106 Reference< XControlContainer > xC;
1107 aAny >>= xC;
1108 if( xC.is() )
1109 // It's a container
1110 eType = WindowClass_CONTAINER;
1111 else
1112 eType = WindowClass_SIMPLE;
1114 else
1115 { // This is only correct for Top Window
1116 if( rParentPeer.is() )
1118 if ( !xToolkit.is() )
1119 xToolkit = rParentPeer->getToolkit();
1120 eType = WindowClass_CONTAINER;
1122 else
1124 if ( !xToolkit.is() )
1125 xToolkit = VCLUnoHelper::CreateToolkit();
1126 eType = WindowClass_TOP;
1129 WindowDescriptor aDescr;
1130 aDescr.Type = eType;
1131 aDescr.WindowServiceName = GetComponentServiceName();
1132 aDescr.Parent = rParentPeer;
1133 aDescr.Bounds = getPosSize();
1134 aDescr.WindowAttributes = 0;
1136 // Border
1137 Reference< XPropertySet > xPSet( mxModel, UNO_QUERY );
1138 Reference< XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
1140 Any aVal;
1141 OUString aPropName = GetPropertyName( BASEPROPERTY_BORDER );
1142 if ( xInfo->hasPropertyByName( aPropName ) )
1144 aVal = xPSet->getPropertyValue( aPropName );
1145 sal_Int16 n = sal_Int16();
1146 if ( aVal >>= n )
1148 if ( n )
1149 aDescr.WindowAttributes |= WindowAttribute::BORDER;
1150 else
1151 aDescr.WindowAttributes |= VclWindowPeerAttribute::NOBORDER;
1155 // DESKTOP_AS_PARENT
1156 if ( aDescr.Type == WindowClass_TOP )
1158 aPropName = GetPropertyName( BASEPROPERTY_DESKTOP_AS_PARENT );
1159 if ( xInfo->hasPropertyByName( aPropName ) )
1161 aVal = xPSet->getPropertyValue( aPropName );
1162 bool b = bool();
1163 if ( ( aVal >>= b ) && b)
1164 aDescr.ParentIndex = -1;
1167 // Moveable
1168 aPropName = GetPropertyName( BASEPROPERTY_MOVEABLE );
1169 if ( xInfo->hasPropertyByName( aPropName ) )
1171 aVal = xPSet->getPropertyValue( aPropName );
1172 bool b = bool();
1173 if ( ( aVal >>= b ) && b)
1174 aDescr.WindowAttributes |= WindowAttribute::MOVEABLE;
1177 // Closeable
1178 aPropName = GetPropertyName( BASEPROPERTY_CLOSEABLE );
1179 if ( xInfo->hasPropertyByName( aPropName ) )
1181 aVal = xPSet->getPropertyValue( aPropName );
1182 bool b = bool();
1183 if ( ( aVal >>= b ) && b)
1184 aDescr.WindowAttributes |= WindowAttribute::CLOSEABLE;
1187 // Dropdown
1188 aPropName = GetPropertyName( BASEPROPERTY_DROPDOWN );
1189 if ( xInfo->hasPropertyByName( aPropName ) )
1191 aVal = xPSet->getPropertyValue( aPropName );
1192 bool b = bool();
1193 if ( ( aVal >>= b ) && b)
1194 aDescr.WindowAttributes |= VclWindowPeerAttribute::DROPDOWN;
1197 // Spin
1198 aPropName = GetPropertyName( BASEPROPERTY_SPIN );
1199 if ( xInfo->hasPropertyByName( aPropName ) )
1201 aVal = xPSet->getPropertyValue( aPropName );
1202 bool b = bool();
1203 if ( ( aVal >>= b ) && b)
1204 aDescr.WindowAttributes |= VclWindowPeerAttribute::SPIN;
1207 // HScroll
1208 aPropName = GetPropertyName( BASEPROPERTY_HSCROLL );
1209 if ( xInfo->hasPropertyByName( aPropName ) )
1211 aVal = xPSet->getPropertyValue( aPropName );
1212 bool b = bool();
1213 if ( ( aVal >>= b ) && b)
1214 aDescr.WindowAttributes |= VclWindowPeerAttribute::HSCROLL;
1217 // VScroll
1218 aPropName = GetPropertyName( BASEPROPERTY_VSCROLL );
1219 if ( xInfo->hasPropertyByName( aPropName ) )
1221 aVal = xPSet->getPropertyValue( aPropName );
1222 bool b = bool();
1223 if ( ( aVal >>= b ) && b)
1224 aDescr.WindowAttributes |= VclWindowPeerAttribute::VSCROLL;
1227 // AutoHScroll
1228 aPropName = GetPropertyName( BASEPROPERTY_AUTOHSCROLL );
1229 if ( xInfo->hasPropertyByName( aPropName ) )
1231 aVal = xPSet->getPropertyValue( aPropName );
1232 bool b = bool();
1233 if ( ( aVal >>= b ) && b)
1234 aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOHSCROLL;
1237 // AutoVScroll
1238 aPropName = GetPropertyName( BASEPROPERTY_AUTOVSCROLL );
1239 if ( xInfo->hasPropertyByName( aPropName ) )
1241 aVal = xPSet->getPropertyValue( aPropName );
1242 bool b = bool();
1243 if ( ( aVal >>= b ) && b)
1244 aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOVSCROLL;
1247 //added for issue79712
1248 //NoLabel
1249 aPropName = GetPropertyName( BASEPROPERTY_NOLABEL );
1250 if ( xInfo->hasPropertyByName( aPropName ) )
1252 aVal = xPSet->getPropertyValue( aPropName );
1253 bool b = bool();
1254 if ( ( aVal >>=b ) && b )
1255 aDescr.WindowAttributes |= VclWindowPeerAttribute::NOLABEL;
1257 //issue79712 ends
1259 // Align
1260 aPropName = GetPropertyName( BASEPROPERTY_ALIGN );
1261 if ( xInfo->hasPropertyByName( aPropName ) )
1263 aVal = xPSet->getPropertyValue( aPropName );
1264 sal_Int16 n = sal_Int16();
1265 if ( aVal >>= n )
1267 if ( n == PROPERTY_ALIGN_LEFT )
1268 aDescr.WindowAttributes |= VclWindowPeerAttribute::LEFT;
1269 else if ( n == PROPERTY_ALIGN_CENTER )
1270 aDescr.WindowAttributes |= VclWindowPeerAttribute::CENTER;
1271 else
1272 aDescr.WindowAttributes |= VclWindowPeerAttribute::RIGHT;
1276 // Allow derivates to manipulate attributes
1277 PrepareWindowDescriptor(aDescr);
1279 // create the peer
1280 setPeer( xToolkit->createWindow( aDescr ) );
1282 // release the mutex guard (and work with copies of our members)
1283 // this is necessary as our peer may lock the SolarMutex (actually, all currently known peers do), so calling
1284 // into the peer with our own mutex locked may cause deadlocks
1285 // (We _really_ need peers which do not use the SolarMutex. It's really pissing me off that from time to
1286 // time deadlocks pop up because the low-level components like our peers use a mutex which usually
1287 // is locked at the top of the stack (it protects the global message looping). This is always dangerous, and
1288 // can not always be solved by tampering with other mutexes.
1289 // Unfortunately, the VCL used in the peers is not threadsafe, and by definition needs a locked SolarMutex.)
1290 // 82300 - 12/21/00 - FS
1291 UnoControlComponentInfos aComponentInfos(maComponentInfos);
1292 bool bDesignMode(mbDesignMode);
1294 Reference< XGraphics > xGraphics( mxGraphics );
1295 Reference< XView > xView ( getPeer(), UNO_QUERY_THROW );
1296 Reference< XWindow > xWindow ( getPeer(), UNO_QUERY_THROW );
1298 aGuard.clear();
1300 // the updateFromModel is done without a locked mutex, too.
1301 // The reason is that the only thing this method does is firing property changes, and this in general has
1302 // to be done without locked mutexes (as every notification to external listeners).
1303 // 82300 - 12/21/00 - FS
1304 updateFromModel();
1306 xView->setZoom( aComponentInfos.nZoomX, aComponentInfos.nZoomY );
1308 setPosSize( aComponentInfos.nX, aComponentInfos.nY, aComponentInfos.nWidth, aComponentInfos.nHeight, aComponentInfos.nFlags );
1310 if( aComponentInfos.bVisible && !bDesignMode )
1311 // Show only after setting the data
1312 xWindow->setVisible( aComponentInfos.bVisible );
1314 if( !aComponentInfos.bEnable )
1315 xWindow->setEnable( aComponentInfos.bEnable );
1317 xView->setGraphics( xGraphics );
1319 peerCreated();
1321 mbCreatingPeer = false;
1325 Reference< XWindowPeer > UnoControl::getPeer() throw(RuntimeException, std::exception)
1327 ::osl::MutexGuard aGuard( GetMutex() );
1328 return mxPeer;
1331 sal_Bool UnoControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException, std::exception)
1333 ::osl::MutexGuard aGuard( GetMutex() );
1335 Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
1337 // query for the XPropertiesChangeListener - our delegator is allowed to overwrite this interface
1338 Reference< XPropertiesChangeListener > xListener;
1339 queryInterface( cppu::UnoType<decltype(xListener)>::get() ) >>= xListener;
1341 if( xPropSet.is() )
1342 xPropSet->removePropertiesChangeListener( xListener );
1344 mpData->bLocalizationSupport = false;
1345 mxModel = rxModel;
1347 if( mxModel.is() )
1351 xPropSet.set( mxModel, UNO_QUERY_THROW );
1352 Reference< XPropertySetInfo > xPSI( xPropSet->getPropertySetInfo(), UNO_SET_THROW );
1354 Sequence< OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
1355 xPropSet->addPropertiesChangeListener( aNames, xListener );
1357 mpData->bLocalizationSupport = xPSI->hasPropertyByName("ResourceResolver");
1359 catch( const Exception& )
1361 DBG_UNHANDLED_EXCEPTION();
1362 mxModel.clear();
1366 return mxModel.is();
1369 Reference< XControlModel > UnoControl::getModel( ) throw(RuntimeException, std::exception)
1371 return mxModel;
1374 Reference< XView > UnoControl::getView( ) throw(RuntimeException, std::exception)
1376 return static_cast< XView* >( this );
1379 void UnoControl::setDesignMode( sal_Bool bOn ) throw(RuntimeException, std::exception)
1381 ModeChangeEvent aModeChangeEvent;
1383 Reference< XWindow > xWindow;
1384 Reference<XComponent> xAccessibleComp;
1386 ::osl::MutexGuard aGuard( GetMutex() );
1387 if ( bool(bOn) == mbDesignMode )
1388 return;
1390 // remember this
1391 mbDesignMode = bOn;
1392 xWindow.set(getPeer(), css::uno::UNO_QUERY);
1394 xAccessibleComp.set(maAccessibleContext, UNO_QUERY);
1395 maAccessibleContext.clear();
1397 aModeChangeEvent.Source = *this;
1398 aModeChangeEvent.NewMode = mbDesignMode ? OUString("design") : OUString("alive" );
1401 // dispose current AccessibleContext, if we have one - without Mutex lock
1402 // (changing the design mode implies having a new implementation for this context,
1403 // so the old one must be declared DEFUNC)
1404 DisposeAccessibleContext(xAccessibleComp);
1406 // adjust the visibility of our window
1407 if ( xWindow.is() )
1408 xWindow->setVisible( !bOn );
1410 // and notify our mode listeners
1411 maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent );
1414 sal_Bool UnoControl::isDesignMode( ) throw(RuntimeException, std::exception)
1416 return mbDesignMode;
1419 sal_Bool UnoControl::isTransparent( ) throw(RuntimeException, std::exception)
1421 return sal_False;
1424 // XServiceInfo
1425 OUString UnoControl::getImplementationName( ) throw(RuntimeException, std::exception)
1427 OSL_FAIL( "This method should be overridden!" );
1428 return OUString();
1431 sal_Bool UnoControl::supportsService( const OUString& rServiceName ) throw(RuntimeException, std::exception)
1433 return cppu::supportsService(this, rServiceName);
1436 Sequence< OUString > UnoControl::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
1438 OUString sName( "com.sun.star.awt.UnoControl" );
1439 return Sequence< OUString >( &sName, 1 );
1443 Reference< XAccessibleContext > SAL_CALL UnoControl::getAccessibleContext( ) throw (RuntimeException, std::exception)
1445 // creation of the context will certainly require the SolarMutex ...
1446 SolarMutexGuard aSolarGuard;
1447 ::osl::MutexGuard aGuard( GetMutex() );
1449 Reference< XAccessibleContext > xCurrentContext( maAccessibleContext.get(), UNO_QUERY );
1450 if ( !xCurrentContext.is() )
1452 if ( !mbDesignMode )
1453 { // in alive mode, use the AccessibleContext of the peer
1454 Reference< XAccessible > xPeerAcc( getPeer(), UNO_QUERY );
1455 if ( xPeerAcc.is() )
1456 xCurrentContext = xPeerAcc->getAccessibleContext( );
1458 else
1459 // in design mode, use a fallback
1460 xCurrentContext = ::toolkit::OAccessibleControlContext::create( this );
1462 DBG_ASSERT( xCurrentContext.is(), "UnoControl::getAccessibleContext: invalid context (invalid peer?)!" );
1463 maAccessibleContext = xCurrentContext;
1465 // get notified when the context is disposed
1466 Reference< XComponent > xContextComp( xCurrentContext, UNO_QUERY );
1467 if ( xContextComp.is() )
1468 xContextComp->addEventListener( this );
1469 // In an ideal world, this is not necessary - there the object would be released as soon as it has been
1470 // disposed, and thus our weak reference would be empty, too.
1471 // But 'til this ideal world comes (means 'til we do never have any refcount/lifetime bugs anymore), we
1472 // need to listen for disposal and reset our weak reference then.
1475 return xCurrentContext;
1478 void SAL_CALL UnoControl::addModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException, std::exception)
1480 ::osl::MutexGuard aGuard( GetMutex() );
1481 maModeChangeListeners.addInterface( _rxListener );
1484 void SAL_CALL UnoControl::removeModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException, std::exception)
1486 ::osl::MutexGuard aGuard( GetMutex() );
1487 maModeChangeListeners.removeInterface( _rxListener );
1490 void SAL_CALL UnoControl::addModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException, std::exception)
1492 throw NoSupportException( );
1495 void SAL_CALL UnoControl::removeModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException, std::exception)
1497 throw NoSupportException( );
1501 awt::Point SAL_CALL UnoControl::convertPointToLogic( const awt::Point& i_Point, ::sal_Int16 i_TargetUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1503 Reference< XUnitConversion > xPeerConversion;
1505 ::osl::MutexGuard aGuard( GetMutex() );
1506 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1508 if ( xPeerConversion.is() )
1509 return xPeerConversion->convertPointToLogic( i_Point, i_TargetUnit );
1510 return awt::Point( );
1514 awt::Point SAL_CALL UnoControl::convertPointToPixel( const awt::Point& i_Point, ::sal_Int16 i_SourceUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1516 Reference< XUnitConversion > xPeerConversion;
1518 ::osl::MutexGuard aGuard( GetMutex() );
1519 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1521 if ( xPeerConversion.is() )
1522 return xPeerConversion->convertPointToPixel( i_Point, i_SourceUnit );
1523 return awt::Point( );
1527 awt::Size SAL_CALL UnoControl::convertSizeToLogic( const awt::Size& i_Size, ::sal_Int16 i_TargetUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1529 Reference< XUnitConversion > xPeerConversion;
1531 ::osl::MutexGuard aGuard( GetMutex() );
1532 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1534 if ( xPeerConversion.is() )
1535 return xPeerConversion->convertSizeToLogic( i_Size, i_TargetUnit );
1536 return awt::Size( );
1540 awt::Size SAL_CALL UnoControl::convertSizeToPixel( const awt::Size& i_Size, ::sal_Int16 i_SourceUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1542 Reference< XUnitConversion > xPeerConversion;
1544 ::osl::MutexGuard aGuard( GetMutex() );
1545 xPeerConversion.set(getPeer(), css::uno::UNO_QUERY);
1547 if ( xPeerConversion.is() )
1548 return xPeerConversion->convertSizeToPixel( i_Size, i_SourceUnit );
1549 return awt::Size( );
1553 uno::Reference< awt::XStyleSettings > SAL_CALL UnoControl::getStyleSettings() throw (RuntimeException, std::exception)
1555 Reference< awt::XStyleSettingsSupplier > xPeerSupplier;
1557 ::osl::MutexGuard aGuard( GetMutex() );
1558 xPeerSupplier.set(getPeer(), css::uno::UNO_QUERY);
1560 if ( xPeerSupplier.is() )
1561 return xPeerSupplier->getStyleSettings();
1562 return NULL;
1565 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */