update dev300-m58
[ooovba.git] / toolkit / source / controls / unocontrol.cxx
blob577b59931fb2efb92cb231632cc41e589c9302a1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocontrol.cxx,v $
10 * $Revision: 1.54.42.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include <com/sun/star/awt/XControlContainer.hpp>
34 #include <com/sun/star/awt/WindowAttribute.hpp>
35 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
36 #include <com/sun/star/awt/PosSize.hpp>
37 #ifndef _COM_SUN_STAR_LAN_XMULTISERVICEFACTORY_HPP_
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #endif
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/resource/XStringResourceResolver.hpp>
42 #include <toolkit/controls/unocontrol.hxx>
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include <cppuhelper/typeprovider.hxx>
45 #include <rtl/memory.h>
46 #include <rtl/uuid.h>
47 #include <vos/mutex.hxx>
48 #include <tools/string.hxx>
49 #include <tools/table.hxx>
50 #include <tools/date.hxx>
51 #include <tools/time.hxx>
52 #include <tools/urlobj.hxx>
53 #include <tools/debug.hxx>
54 #include <tools/diagnose_ex.h>
55 #include <vcl/svapp.hxx>
56 #include <vcl/wrkwin.hxx>
57 #include <comphelper/stl_types.hxx>
58 #include <toolkit/helper/property.hxx>
59 #include <toolkit/helper/servicenames.hxx>
60 #include <toolkit/helper/vclunohelper.hxx>
61 #include <toolkit/awt/vclxwindow.hxx>
62 #include <vcl/svapp.hxx>
63 #include <vos/mutex.hxx>
64 #include <toolkit/controls/accessiblecontrolcontext.hxx>
65 #include <comphelper/container.hxx>
67 #include <algorithm>
68 #include <set>
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::awt;
73 using namespace ::com::sun::star::beans;
74 using namespace ::com::sun::star::lang;
75 using namespace ::com::sun::star::util;
77 using ::com::sun::star::accessibility::XAccessibleContext;
78 using ::com::sun::star::accessibility::XAccessible;
80 struct LanguageDependentProp
82 const char* pPropName;
83 sal_Int32 nPropNameLength;
86 static const LanguageDependentProp aLanguageDependentProp[] =
88 { "Text", 4 },
89 { "Label", 5 },
90 { "Title", 5 },
91 { "HelpText", 8 },
92 { "CurrencySymbol", 14 },
93 { "StringItemList", 14 },
94 { 0, 0 }
97 WorkWindow* lcl_GetDefaultWindow()
99 static WorkWindow* pW = NULL;
100 if ( !pW )
102 pW = new WorkWindow( NULL, 0 );
103 pW->EnableChildTransparentMode();
105 return pW;
108 static Sequence< ::rtl::OUString> lcl_ImplGetPropertyNames( const Reference< XMultiPropertySet > & rxModel )
110 Sequence< ::rtl::OUString> aNames;
111 Reference< XPropertySetInfo > xPSInf = rxModel->getPropertySetInfo();
112 DBG_ASSERT( xPSInf.is(), "UpdateFromModel: No PropertySetInfo!" );
113 if ( xPSInf.is() )
115 Sequence< Property> aProps = xPSInf->getProperties();
116 sal_Int32 nLen = aProps.getLength();
117 aNames = Sequence< ::rtl::OUString>( nLen );
118 ::rtl::OUString* pNames = aNames.getArray();
119 const Property* pProps = aProps.getConstArray();
120 for ( sal_Int32 n = 0; n < nLen; ++n, ++pProps, ++pNames)
121 *pNames = pProps->Name;
123 return aNames;
126 // ====================================================
127 class VclListenerLock
129 private:
130 VCLXWindow* m_pLockWindow;
132 public:
133 inline VclListenerLock( VCLXWindow* _pLockWindow )
134 :m_pLockWindow( _pLockWindow )
136 if ( m_pLockWindow )
137 m_pLockWindow->suspendVclEventListening( );
139 inline ~VclListenerLock( )
141 if ( m_pLockWindow )
142 m_pLockWindow->resumeVclEventListening( );
145 private:
146 VclListenerLock(); // never implemented
147 VclListenerLock( const VclListenerLock& ); // never implemented
148 VclListenerLock& operator=( const VclListenerLock& ); // never implemented
151 typedef ::std::map< ::rtl::OUString, sal_Int32 > MapString2Int;
152 struct UnoControl_Data
154 MapString2Int aSuspendedPropertyNotifications;
155 /// true if and only if our model has a property ResourceResolver
156 bool bLocalizationSupport;
158 UnoControl_Data()
159 :aSuspendedPropertyNotifications()
160 ,bLocalizationSupport( false )
165 // ----------------------------------------------------
166 // class UnoControl
167 // ----------------------------------------------------
168 DBG_NAME( UnoControl )
169 UnoControl::UnoControl()
170 : maDisposeListeners( *this )
171 , maWindowListeners( *this )
172 , maFocusListeners( *this )
173 , maKeyListeners( *this )
174 , maMouseListeners( *this )
175 , maMouseMotionListeners( *this )
176 , maPaintListeners( *this )
177 , maModeChangeListeners( GetMutex() )
178 , mpData( new UnoControl_Data )
180 DBG_CTOR( UnoControl, NULL );
181 mbDisposePeer = sal_True;
182 mbRefeshingPeer = sal_False;
183 mbCreatingPeer = sal_False;
184 mbCreatingCompatiblePeer = sal_False;
185 mbDesignMode = sal_False;
188 UnoControl::~UnoControl()
190 DELETEZ( mpData );
191 DBG_DTOR( UnoControl, NULL );
194 ::rtl::OUString UnoControl::GetComponentServiceName()
196 return ::rtl::OUString();
199 Reference< XWindowPeer > UnoControl::ImplGetCompatiblePeer( sal_Bool bAcceptExistingPeer )
201 DBG_ASSERT( !mbCreatingCompatiblePeer, "ImplGetCompatiblePeer - rekursive?" );
203 mbCreatingCompatiblePeer = sal_True;
205 Reference< XWindowPeer > xCompatiblePeer;
207 if ( bAcceptExistingPeer )
208 xCompatiblePeer = getPeer();
210 if ( !xCompatiblePeer.is() )
212 // Peer unsichtbar erzeugen...
213 sal_Bool bVis = maComponentInfos.bVisible;
214 if( bVis )
215 maComponentInfos.bVisible = sal_False;
217 Reference< XWindowPeer > xCurrentPeer = getPeer();
218 setPeer( NULL );
220 // queryInterface ourself, to allow aggregation
221 Reference< XControl > xMe;
222 OWeakAggObject::queryInterface( ::getCppuType( &xMe ) ) >>= xMe;
224 WorkWindow* pWW;
226 osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() );
227 pWW = lcl_GetDefaultWindow();
231 xMe->createPeer( NULL, pWW->GetComponentInterface( sal_True ) );
233 catch( const Exception& )
235 mbCreatingCompatiblePeer = sal_False;
236 throw;
238 xCompatiblePeer = getPeer();
239 setPeer( xCurrentPeer );
241 if ( xCompatiblePeer.is() && mxGraphics.is() )
243 Reference< XView > xPeerView( xCompatiblePeer, UNO_QUERY );
244 if ( xPeerView.is() )
245 xPeerView->setGraphics( mxGraphics );
248 if( bVis )
249 maComponentInfos.bVisible = sal_True;
252 mbCreatingCompatiblePeer = sal_False;
254 return xCompatiblePeer;
257 bool UnoControl::ImplCheckLocalize( ::rtl::OUString& _rPossiblyLocalizable )
259 if ( !mpData->bLocalizationSupport
260 || ( _rPossiblyLocalizable.getLength() == 0 )
261 || ( _rPossiblyLocalizable[0] != '&' )
262 // TODO: make this reasonable. At the moment, everything which by accident starts with a & is considered
263 // localizable, which is probably wrong.
265 return false;
269 Reference< XPropertySet > xPropSet( mxModel, UNO_QUERY_THROW );
270 Reference< resource::XStringResourceResolver > xStringResourceResolver(
271 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" ) ) ),
272 UNO_QUERY
274 if ( xStringResourceResolver.is() )
276 ::rtl::OUString aLocalizationKey( _rPossiblyLocalizable.copy( 1 ) );
277 _rPossiblyLocalizable = xStringResourceResolver->resolveString( aLocalizationKey );
278 return true;
281 catch( const Exception& )
283 DBG_UNHANDLED_EXCEPTION();
285 return false;
288 void UnoControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const Any& rVal )
290 // since a change made in propertiesChange, we can't be sure that this is called with an valid getPeer(),
291 // this assumption may be false in some (seldom) multi-threading scenarios (cause propertiesChange
292 // releases our mutex before calling here in)
293 // That's why this additional check
295 if ( mxVclWindowPeer.is() )
297 Any aConvertedValue( rVal );
299 if ( mpData->bLocalizationSupport )
301 // We now support a mapping for language dependent properties. This is the
302 // central method to implement it.
303 if (( rPropName.equalsAsciiL( "Text", 4 )) ||
304 ( rPropName.equalsAsciiL( "Label", 5 )) ||
305 ( rPropName.equalsAsciiL( "Title", 5 )) ||
306 ( rPropName.equalsAsciiL( "HelpText", 8 )) ||
307 ( rPropName.equalsAsciiL( "CurrencySymbol", 14 )) ||
308 ( rPropName.equalsAsciiL( "StringItemList", 14 )) )
310 ::rtl::OUString aValue;
311 uno::Sequence< rtl::OUString > aSeqValue;
312 if ( aConvertedValue >>= aValue )
314 if ( ImplCheckLocalize( aValue ) )
315 aConvertedValue <<= aValue;
317 else if ( aConvertedValue >>= aSeqValue )
319 for ( sal_Int32 i = 0; i < aSeqValue.getLength(); i++ )
320 ImplCheckLocalize( aSeqValue[i] );
321 aConvertedValue <<= aSeqValue;
326 mxVclWindowPeer->setProperty( rPropName, aConvertedValue );
330 void UnoControl::PrepareWindowDescriptor( WindowDescriptor& )
334 Reference< XWindow > UnoControl::getParentPeer() const
336 Reference< XWindow > xPeer;
337 if( mxContext.is() )
339 Reference< XControl > xContComp( mxContext, UNO_QUERY );
340 if ( xContComp.is() )
342 Reference< XWindowPeer > xP = xContComp->getPeer();
343 if ( xP.is() )
344 xP->queryInterface( ::getCppuType((const Reference< XWindow >*)0) ) >>= xPeer;
347 return xPeer;
350 void UnoControl::updateFromModel()
352 // Alle standard Properties werden ausgelesen und in das Peer uebertragen
353 if( getPeer().is() )
355 Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
356 if( xPropSet.is() )
358 Sequence< ::rtl::OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
359 xPropSet->firePropertiesChangeEvent( aNames, this );
365 // XTypeProvider
366 IMPL_IMPLEMENTATION_ID( UnoControl )
368 void UnoControl::disposeAccessibleContext()
370 Reference< XComponent > xContextComp( maAccessibleContext.get(), UNO_QUERY );
371 if ( xContextComp.is() )
373 maAccessibleContext = NULL;
376 xContextComp->removeEventListener( this );
377 xContextComp->dispose();
379 catch( const Exception& )
381 DBG_ERROR( "UnoControl::disposeAccessibleContext: could not dispose my AccessibleContext!" );
386 void UnoControl::dispose( ) throw(RuntimeException)
388 Reference< XWindowPeer > xPeer;
390 ::osl::MutexGuard aGuard( GetMutex() );
391 if( mbDisposePeer )
393 xPeer = mxPeer;
395 setPeer( NULL );
397 if( xPeer.is() )
399 xPeer->dispose();
402 // dispose and release our AccessibleContext
403 disposeAccessibleContext();
405 EventObject aDisposeEvent;
406 aDisposeEvent.Source = static_cast< XAggregation* >( this );
408 maDisposeListeners.disposeAndClear( aDisposeEvent );
409 maWindowListeners.disposeAndClear( aDisposeEvent );
410 maFocusListeners.disposeAndClear( aDisposeEvent );
411 maKeyListeners.disposeAndClear( aDisposeEvent );
412 maMouseListeners.disposeAndClear( aDisposeEvent );
413 maMouseMotionListeners.disposeAndClear( aDisposeEvent );
414 maPaintListeners.disposeAndClear( aDisposeEvent );
415 maModeChangeListeners.disposeAndClear( aDisposeEvent );
417 // Model wieder freigeben
418 setModel( Reference< XControlModel > () );
419 setContext( Reference< XInterface > () );
422 void UnoControl::addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException)
424 ::osl::MutexGuard aGuard( GetMutex() );
426 maDisposeListeners.addInterface( rxListener );
429 void UnoControl::removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException)
431 ::osl::MutexGuard aGuard( GetMutex() );
433 maDisposeListeners.removeInterface( rxListener );
436 sal_Bool UnoControl::requiresNewPeer( const ::rtl::OUString& /* _rPropertyName */ ) const
438 return sal_False;
441 // XPropertiesChangeListener
442 void UnoControl::propertiesChange( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException)
444 Sequence< PropertyChangeEvent > aEvents( rEvents );
446 ::osl::MutexGuard aGuard( GetMutex() );
448 if ( !mpData->aSuspendedPropertyNotifications.empty() )
450 // strip the property which we are currently updating (somewhere up the stack)
451 PropertyChangeEvent* pEvents = aEvents.getArray();
452 PropertyChangeEvent* pEventsEnd = pEvents + aEvents.getLength();
453 for ( ; pEvents < pEventsEnd; )
454 if ( mpData->aSuspendedPropertyNotifications.find( pEvents->PropertyName ) != mpData->aSuspendedPropertyNotifications.end() )
456 if ( pEvents != pEventsEnd )
457 ::std::copy( pEvents + 1, pEventsEnd, pEvents );
458 --pEventsEnd;
460 else
461 ++pEvents;
462 aEvents.realloc( pEventsEnd - aEvents.getConstArray() );
464 if ( !aEvents.getLength() )
465 return;
469 ImplModelPropertiesChanged( aEvents );
472 void UnoControl::ImplLockPropertyChangeNotification( const ::rtl::OUString& rPropertyName, bool bLock )
474 MapString2Int::iterator pos = mpData->aSuspendedPropertyNotifications.find( rPropertyName );
475 if ( bLock )
477 if ( pos == mpData->aSuspendedPropertyNotifications.end() )
478 pos = mpData->aSuspendedPropertyNotifications.insert( MapString2Int::value_type( rPropertyName, 0 ) ).first;
479 ++pos->second;
481 else
483 OSL_ENSURE( pos != mpData->aSuspendedPropertyNotifications.end(), "UnoControl::ImplLockPropertyChangeNotification: property not locked!" );
484 if ( pos != mpData->aSuspendedPropertyNotifications.end() )
486 OSL_ENSURE( pos->second > 0, "UnoControl::ImplLockPropertyChangeNotification: invalid suspension counter!" );
487 if ( 0 == --pos->second )
488 mpData->aSuspendedPropertyNotifications.erase( pos );
493 void UnoControl::ImplLockPropertyChangeNotifications( const Sequence< ::rtl::OUString >& rPropertyNames, bool bLock )
495 for ( const ::rtl::OUString* pPropertyName = rPropertyNames.getConstArray();
496 pPropertyName != rPropertyNames.getConstArray() + rPropertyNames.getLength();
497 ++pPropertyName
499 ImplLockPropertyChangeNotification( *pPropertyName, bLock );
502 void UnoControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents )
504 ::osl::ClearableGuard< ::osl::Mutex > aGuard( GetMutex() );
506 if( getPeer().is() )
508 DECLARE_STL_VECTOR( PropertyValue, PropertyValueVector);
509 PropertyValueVector aPeerPropertiesToSet;
510 sal_Int32 nIndependentPos = 0;
511 bool bResourceResolverSet( false );
512 // position where to insert the independent properties into aPeerPropertiesToSet,
513 // dependent ones are inserted at the end of the vector
515 sal_Bool bNeedNewPeer = sal_False;
516 // some properties require a re-creation of the peer, 'cause they can't be changed on the fly
518 Reference< XControlModel > xOwnModel( getModel(), UNO_QUERY );
519 // our own model for comparison
520 Reference< XPropertySet > xPS( xOwnModel, UNO_QUERY );
521 Reference< XPropertySetInfo > xPSI( xPS->getPropertySetInfo(), UNO_QUERY );
522 OSL_ENSURE( xPSI.is(), "UnoControl::ImplModelPropertiesChanged: should have property set meta data!" );
524 const PropertyChangeEvent* pEvents = rEvents.getConstArray();
526 sal_Int32 nLen = rEvents.getLength();
527 aPeerPropertiesToSet.reserve(nLen);
529 for( sal_Int32 i = 0; i < nLen; ++i, ++pEvents )
531 Reference< XControlModel > xModel( pEvents->Source, UNO_QUERY );
532 sal_Bool bOwnModel = xModel.get() == xOwnModel.get();
533 if ( !bOwnModel )
534 continue;
536 // Detect changes on our resource resolver which invalidates
537 // automatically some language dependent properties.
538 if ( pEvents->PropertyName.equalsAsciiL( "ResourceResolver", 16 ))
540 Reference< resource::XStringResourceResolver > xStrResolver;
541 if ( pEvents->NewValue >>= xStrResolver )
542 bResourceResolverSet = xStrResolver.is();
545 sal_uInt16 nPType = GetPropertyId( pEvents->PropertyName );
546 if ( mbDesignMode && mbDisposePeer && !mbRefeshingPeer && !mbCreatingPeer )
548 // if we're in design mode, then some properties can change which
549 // require creating a *new* peer (since these properties cannot
550 // be switched at existing peers)
551 if ( nPType )
552 bNeedNewPeer = ( nPType == BASEPROPERTY_BORDER )
553 || ( nPType == BASEPROPERTY_MULTILINE )
554 || ( nPType == BASEPROPERTY_DROPDOWN )
555 || ( nPType == BASEPROPERTY_HSCROLL )
556 || ( nPType == BASEPROPERTY_VSCROLL )
557 || ( nPType == BASEPROPERTY_AUTOHSCROLL )
558 || ( nPType == BASEPROPERTY_AUTOVSCROLL )
559 || ( nPType == BASEPROPERTY_ORIENTATION )
560 || ( nPType == BASEPROPERTY_SPIN )
561 || ( nPType == BASEPROPERTY_ALIGN )
562 || ( nPType == BASEPROPERTY_PAINTTRANSPARENT );
563 else
564 bNeedNewPeer = requiresNewPeer( pEvents->PropertyName );
566 if ( bNeedNewPeer )
567 break;
570 if ( nPType && ( nLen > 1 ) && DoesDependOnOthers( nPType ) )
572 // Properties die von anderen abhaengen erst hinterher einstellen,
573 // weil sie von anderen Properties abhaengig sind, die aber erst spaeter
574 // eingestellt werden, z.B. VALUE nach VALUEMIN/MAX.
575 aPeerPropertiesToSet.push_back(PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
577 else
579 if ( bResourceResolverSet )
581 // The resource resolver property change should be one of the first ones.
582 // All language dependent properties are dependent on this property.
583 // As BASEPROPERTY_NATIVE_WIDGET_LOOK is not dependent on resource
584 // resolver. We don't need to handle a special order for these two props.
585 aPeerPropertiesToSet.insert(
586 aPeerPropertiesToSet.begin(),
587 PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
588 ++nIndependentPos;
590 else if ( nPType == BASEPROPERTY_NATIVE_WIDGET_LOOK )
592 // since *a lot* of other properties might be overruled by this one, we need
593 // a special handling:
594 // NativeWidgetLook needs to be set first: If it is set to ON, all other
595 // properties describing the look (e.g. BackgroundColor) are ignored, anyway.
596 // If it is switched OFF, then we need to do it first because else it will
597 // overrule other look-related properties, and re-initialize them from system
598 // defaults.
599 aPeerPropertiesToSet.insert(
600 aPeerPropertiesToSet.begin(),
601 PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
602 ++nIndependentPos;
604 else
606 aPeerPropertiesToSet.insert(aPeerPropertiesToSet.begin() + nIndependentPos,
607 PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
608 ++nIndependentPos;
613 Reference< XWindow > xParent = getParentPeer();
614 Reference< XControl > xThis( (XAggregation*)(::cppu::OWeakAggObject*)this, UNO_QUERY );
615 // call createPeer via a interface got from queryInterface, so the aggregating class can intercept it
617 DBG_ASSERT( !bNeedNewPeer || xParent.is(), "Need new peer, but don't have a parent!" );
619 // Check if we have to update language dependent properties
620 if ( !bNeedNewPeer && bResourceResolverSet )
622 // Add language dependent properties into the peer property set.
623 // Our resource resolver has been changed and we must be sure
624 // that language dependent props use the new resolver.
625 const LanguageDependentProp* pLangDepProp = aLanguageDependentProp;
626 while ( pLangDepProp->pPropName != 0 )
628 bool bMustBeInserted( true );
629 for ( sal_uInt32 i = 0; i < aPeerPropertiesToSet.size(); i++ )
631 if ( aPeerPropertiesToSet[i].Name.equalsAsciiL(
632 pLangDepProp->pPropName, pLangDepProp->nPropNameLength ))
634 bMustBeInserted = false;
635 break;
639 if ( bMustBeInserted )
641 // Add language dependent props at the end
642 ::rtl::OUString aPropName( ::rtl::OUString::createFromAscii( pLangDepProp->pPropName ));
643 if ( xPSI.is() && xPSI->hasPropertyByName( aPropName ) )
645 aPeerPropertiesToSet.push_back(
646 PropertyValue( aPropName, 0, xPS->getPropertyValue( aPropName ), PropertyState_DIRECT_VALUE ) );
650 ++pLangDepProp;
653 aGuard.clear();
655 // clear the guard before creating a new peer - as usual, our peer implementations use the SolarMutex
656 // #82300# - 2000-12-21 - fs@openoffice.org
657 if (bNeedNewPeer && xParent.is())
659 NAMESPACE_VOS(OGuard) aVclGuard( Application::GetSolarMutex() );
660 // and now this is the final withdrawal:
661 // With 83561, I have no other idea than locking the SolarMutex here ....
662 // I really hate the fact that VCL is not theadsafe ....
663 // #83561# - 2001-03-01 - fs@openoffice.org
665 // Funktioniert beim Container nicht!
666 getPeer()->dispose();
667 mxPeer.clear();
668 mxVclWindowPeer = NULL;
669 mbRefeshingPeer = sal_True;
670 Reference< XWindowPeer > xP( xParent, UNO_QUERY );
671 xThis->createPeer( Reference< XToolkit > (), xP );
672 mbRefeshingPeer = sal_False;
673 aPeerPropertiesToSet.clear();
676 // lock the multiplexing of VCL events to our UNO listeners
677 // this is for compatibility reasons: in OOo 1.0.x, changes which were done at the
678 // model did not cause the listeners of the controls/peers to be called
679 // Since the implementations for the listeners changed a lot towards 1.1, this
680 // would not be the case anymore, if we would not do this listener-lock below
681 // #i14703# - 2003-05-23 - fs@openoffice.org
682 Window* pVclPeer = VCLUnoHelper::GetWindow( getPeer() );
683 VCLXWindow* pPeer = pVclPeer ? pVclPeer->GetWindowPeer() : NULL;
684 VclListenerLock aNoVclEventMultiplexing( pPeer );
686 // setting peer properties may result in an attemp to acquire the solar mutex, 'cause the peers
687 // usually don't have an own mutex but use the SolarMutex instead.
688 // To prevent deadlocks resulting from this, we do this without our own mutex locked
689 // 2000-11-03 - fs@openoffice.org
690 PropertyValueVectorIterator aEnd = aPeerPropertiesToSet.end();
691 for ( PropertyValueVectorIterator aLoop = aPeerPropertiesToSet.begin();
692 aLoop != aEnd;
693 ++aLoop
696 ImplSetPeerProperty( aLoop->Name, aLoop->Value );
701 void UnoControl::disposing( const EventObject& rEvt ) throw(RuntimeException)
703 ::osl::ClearableMutexGuard aGuard( GetMutex() );
704 // bei "Multible Inheritance" nicht unterschiedliche Typen vergleichen.
706 if ( maAccessibleContext.get() == rEvt.Source )
708 // just in case the context is disposed, but not released - ensure that we do not re-use it in the future
709 maAccessibleContext = NULL;
711 else if( mxModel.get() == Reference< XControlModel >(rEvt.Source,UNO_QUERY).get() )
713 // #62337# if the model dies, it does not make sense for us to live ...
714 Reference< XControl > xThis = this;
716 aGuard.clear();
717 xThis->dispose();
719 DBG_ASSERT( !mxModel.is(), "UnoControl::disposing: invalid dispose behaviour!" );
720 mxModel.clear();
725 void SAL_CALL UnoControl::setOutputSize( const awt::Size& aSize ) throw (RuntimeException)
727 Reference< XWindow2 > xPeerWindow;
729 ::osl::MutexGuard aGuard( GetMutex() );
730 xPeerWindow = xPeerWindow.query( getPeer() );
733 if ( xPeerWindow.is() )
734 xPeerWindow->setOutputSize( aSize );
737 namespace
739 template < typename RETVALTYPE >
740 RETVALTYPE lcl_askPeer( const uno::Reference< awt::XWindowPeer >& _rxPeer, RETVALTYPE (SAL_CALL XWindow2::*_pMethod)(), RETVALTYPE _aDefault )
742 RETVALTYPE aReturn( _aDefault );
744 Reference< XWindow2 > xPeerWindow( _rxPeer, UNO_QUERY );
745 if ( xPeerWindow.is() )
746 aReturn = (xPeerWindow.get()->*_pMethod)();
748 return aReturn;
752 awt::Size SAL_CALL UnoControl::getOutputSize( ) throw (RuntimeException)
754 return lcl_askPeer( getPeer(), &XWindow2::getOutputSize, awt::Size() );
757 ::sal_Bool SAL_CALL UnoControl::isVisible( ) throw (RuntimeException)
759 return lcl_askPeer( getPeer(), &XWindow2::isVisible, maComponentInfos.bVisible );
762 ::sal_Bool SAL_CALL UnoControl::isActive( ) throw (RuntimeException)
764 return lcl_askPeer( getPeer(), &XWindow2::isActive, sal_False );
767 ::sal_Bool SAL_CALL UnoControl::isEnabled( ) throw (RuntimeException)
769 return lcl_askPeer( getPeer(), &XWindow2::isEnabled, maComponentInfos.bEnable );
772 ::sal_Bool SAL_CALL UnoControl::hasFocus( ) throw (RuntimeException)
774 return lcl_askPeer( getPeer(), &XWindow2::hasFocus, sal_False );
777 // XWindow
778 void UnoControl::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw(RuntimeException)
780 Reference< XWindow > xWindow;
782 ::osl::MutexGuard aGuard( GetMutex() );
784 if ( Flags & awt::PosSize::X )
785 maComponentInfos.nX = X;
786 if ( Flags & awt::PosSize::Y )
787 maComponentInfos.nY = Y;
788 if ( Flags & awt::PosSize::WIDTH )
789 maComponentInfos.nWidth = Width;
790 if ( Flags & awt::PosSize::HEIGHT )
791 maComponentInfos.nHeight = Height;
792 maComponentInfos.nFlags |= Flags;
794 xWindow = xWindow.query( getPeer() );
797 if( xWindow.is() )
798 xWindow->setPosSize( X, Y, Width, Height, Flags );
801 awt::Rectangle UnoControl::getPosSize( ) throw(RuntimeException)
803 awt::Rectangle aRect( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight);
804 Reference< XWindow > xWindow;
807 ::osl::MutexGuard aGuard( GetMutex() );
808 xWindow = xWindow.query( getPeer() );
811 if( xWindow.is() )
812 aRect = xWindow->getPosSize();
813 return aRect;
816 void UnoControl::setVisible( sal_Bool bVisible ) throw(RuntimeException)
818 Reference< XWindow > xWindow;
820 ::osl::MutexGuard aGuard( GetMutex() );
822 // Visible status ist Sache der View
823 maComponentInfos.bVisible = bVisible;
824 xWindow = xWindow.query( getPeer() );
826 if ( xWindow.is() )
827 xWindow->setVisible( bVisible );
830 void UnoControl::setEnable( sal_Bool bEnable ) throw(RuntimeException)
832 Reference< XWindow > xWindow;
834 ::osl::MutexGuard aGuard( GetMutex() );
836 // Enable status ist Sache der View
837 maComponentInfos.bEnable = bEnable;
838 xWindow = xWindow.query( getPeer() );
840 if ( xWindow.is() )
841 xWindow->setEnable( bEnable );
844 void UnoControl::setFocus( ) throw(RuntimeException)
846 Reference< XWindow > xWindow;
848 ::osl::MutexGuard aGuard( GetMutex() );
849 xWindow = xWindow.query( getPeer() );
851 if ( xWindow.is() )
852 xWindow->setFocus();
855 void UnoControl::addWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException)
857 Reference< XWindow > xPeerWindow;
859 ::osl::MutexGuard aGuard( GetMutex() );
860 maWindowListeners.addInterface( rxListener );
861 if ( maWindowListeners.getLength() == 1 )
862 xPeerWindow = xPeerWindow.query( getPeer() );
864 if ( xPeerWindow.is() )
865 xPeerWindow->addWindowListener( &maWindowListeners );
868 void UnoControl::removeWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException)
870 Reference< XWindow > xPeerWindow;
872 ::osl::MutexGuard aGuard( GetMutex() );
873 if ( maWindowListeners.getLength() == 1 )
874 xPeerWindow = xPeerWindow.query( getPeer() );
875 maWindowListeners.removeInterface( rxListener );
877 if ( xPeerWindow.is() )
878 xPeerWindow->removeWindowListener( &maWindowListeners );
881 void UnoControl::addFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException)
883 Reference< XWindow > xPeerWindow;
885 ::osl::MutexGuard aGuard( GetMutex() );
886 maFocusListeners.addInterface( rxListener );
887 if ( maFocusListeners.getLength() == 1 )
888 xPeerWindow = xPeerWindow.query( getPeer() );
890 if ( xPeerWindow.is() )
891 xPeerWindow->addFocusListener( &maFocusListeners );
894 void UnoControl::removeFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException)
896 Reference< XWindow > xPeerWindow;
898 ::osl::MutexGuard aGuard( GetMutex() );
899 if ( maFocusListeners.getLength() == 1 )
900 xPeerWindow = xPeerWindow.query( getPeer() );
901 maFocusListeners.removeInterface( rxListener );
903 if ( xPeerWindow.is() )
904 xPeerWindow->removeFocusListener( &maFocusListeners );
907 void UnoControl::addKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException)
909 Reference< XWindow > xPeerWindow;
911 ::osl::MutexGuard aGuard( GetMutex() );
912 maKeyListeners.addInterface( rxListener );
913 if ( maKeyListeners.getLength() == 1 )
914 xPeerWindow = xPeerWindow.query( getPeer() );
916 if ( xPeerWindow.is() )
917 xPeerWindow->addKeyListener( &maKeyListeners);
920 void UnoControl::removeKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException)
922 Reference< XWindow > xPeerWindow;
924 ::osl::MutexGuard aGuard( GetMutex() );
925 if ( maKeyListeners.getLength() == 1 )
926 xPeerWindow = xPeerWindow.query( getPeer() );
927 maKeyListeners.removeInterface( rxListener );
929 if ( xPeerWindow.is() )
930 xPeerWindow->removeKeyListener( &maKeyListeners);
933 void UnoControl::addMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException)
935 Reference< XWindow > xPeerWindow;
937 ::osl::MutexGuard aGuard( GetMutex() );
938 maMouseListeners.addInterface( rxListener );
939 if ( maMouseListeners.getLength() == 1 )
940 xPeerWindow = xPeerWindow.query( getPeer() );
942 if ( xPeerWindow.is() )
943 xPeerWindow->addMouseListener( &maMouseListeners);
946 void UnoControl::removeMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException)
948 Reference< XWindow > xPeerWindow;
950 ::osl::MutexGuard aGuard( GetMutex() );
951 if ( maMouseListeners.getLength() == 1 )
952 xPeerWindow = xPeerWindow.query( getPeer() );
953 maMouseListeners.removeInterface( rxListener );
955 if ( xPeerWindow.is() )
956 xPeerWindow->removeMouseListener( &maMouseListeners );
959 void UnoControl::addMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException)
961 Reference< XWindow > xPeerWindow;
963 ::osl::MutexGuard aGuard( GetMutex() );
964 maMouseMotionListeners.addInterface( rxListener );
965 if ( maMouseMotionListeners.getLength() == 1 )
966 xPeerWindow = xPeerWindow.query( getPeer() );
968 if ( xPeerWindow.is() )
969 xPeerWindow->addMouseMotionListener( &maMouseMotionListeners);
972 void UnoControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException)
974 Reference< XWindow > xPeerWindow;
976 ::osl::MutexGuard aGuard( GetMutex() );
977 if ( maMouseMotionListeners.getLength() == 1 )
978 xPeerWindow = xPeerWindow.query( getPeer() );
979 maMouseMotionListeners.removeInterface( rxListener );
981 if ( xPeerWindow.is() )
982 xPeerWindow->removeMouseMotionListener( &maMouseMotionListeners );
985 void UnoControl::addPaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException)
987 Reference< XWindow > xPeerWindow;
989 ::osl::MutexGuard aGuard( GetMutex() );
990 maPaintListeners.addInterface( rxListener );
991 if ( maPaintListeners.getLength() == 1 )
992 xPeerWindow = xPeerWindow.query( getPeer() );
994 if ( xPeerWindow.is() )
995 xPeerWindow->addPaintListener( &maPaintListeners);
998 void UnoControl::removePaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException)
1000 Reference< XWindow > xPeerWindow;
1002 ::osl::MutexGuard aGuard( GetMutex() );
1003 if ( maPaintListeners.getLength() == 1 )
1004 xPeerWindow = xPeerWindow.query( getPeer() );
1005 maPaintListeners.removeInterface( rxListener );
1007 if ( xPeerWindow.is() )
1008 xPeerWindow->removePaintListener( &maPaintListeners );
1011 // XView
1012 sal_Bool UnoControl::setGraphics( const Reference< XGraphics >& rDevice ) throw(RuntimeException)
1014 Reference< XView > xView;
1016 ::osl::MutexGuard aGuard( GetMutex() );
1018 mxGraphics = rDevice;
1019 xView = xView.query( getPeer() );
1021 return xView.is() ? xView->setGraphics( rDevice ) : sal_True;
1024 Reference< XGraphics > UnoControl::getGraphics( ) throw(RuntimeException)
1026 return mxGraphics;
1029 awt::Size UnoControl::getSize( ) throw(RuntimeException)
1031 ::osl::MutexGuard aGuard( GetMutex() );
1032 return awt::Size( maComponentInfos.nWidth, maComponentInfos.nHeight );
1035 void UnoControl::draw( sal_Int32 x, sal_Int32 y ) throw(RuntimeException)
1037 Reference< XWindowPeer > xDrawPeer;
1038 Reference< XView > xDrawPeerView;
1040 bool bDisposeDrawPeer( false );
1042 ::osl::MutexGuard aGuard( GetMutex() );
1044 xDrawPeer = ImplGetCompatiblePeer( sal_True );
1045 bDisposeDrawPeer = xDrawPeer.is() && ( xDrawPeer != getPeer() );
1047 xDrawPeerView.set( xDrawPeer, UNO_QUERY );
1048 DBG_ASSERT( xDrawPeerView.is(), "UnoControl::draw: no peer!" );
1051 if ( xDrawPeerView.is() )
1053 Reference< XVclWindowPeer > xWindowPeer;
1054 xWindowPeer.set( xDrawPeer, UNO_QUERY );
1055 if ( xWindowPeer.is() )
1056 xWindowPeer->setDesignMode( mbDesignMode );
1057 xDrawPeerView->draw( x, y );
1060 if ( bDisposeDrawPeer )
1061 xDrawPeer->dispose();
1064 void UnoControl::setZoom( float fZoomX, float fZoomY ) throw(RuntimeException)
1066 Reference< XView > xView;
1068 ::osl::MutexGuard aGuard( GetMutex() );
1070 maComponentInfos.nZoomX = fZoomX;
1071 maComponentInfos.nZoomY = fZoomY;
1073 xView = xView.query( getPeer() );
1075 if ( xView.is() )
1076 xView->setZoom( fZoomX, fZoomY );
1079 // XControl
1080 void UnoControl::setContext( const Reference< XInterface >& rxContext ) throw(RuntimeException)
1082 ::osl::MutexGuard aGuard( GetMutex() );
1084 mxContext = rxContext;
1087 Reference< XInterface > UnoControl::getContext( ) throw(RuntimeException)
1089 ::osl::MutexGuard aGuard( GetMutex() );
1091 return mxContext;
1094 void UnoControl::peerCreated()
1096 Reference< XWindow > xWindow( getPeer(), UNO_QUERY );
1097 if ( !xWindow.is() )
1098 return;
1100 if ( maWindowListeners.getLength() )
1101 xWindow->addWindowListener( &maWindowListeners );
1103 if ( maFocusListeners.getLength() )
1104 xWindow->addFocusListener( &maFocusListeners );
1106 if ( maKeyListeners.getLength() )
1107 xWindow->addKeyListener( &maKeyListeners );
1109 if ( maMouseListeners.getLength() )
1110 xWindow->addMouseListener( &maMouseListeners );
1112 if ( maMouseMotionListeners.getLength() )
1113 xWindow->addMouseMotionListener( &maMouseMotionListeners );
1115 if ( maPaintListeners.getLength() )
1116 xWindow->addPaintListener( &maPaintListeners );
1119 void UnoControl::createPeer( const Reference< XToolkit >& rxToolkit, const Reference< XWindowPeer >& rParentPeer ) throw(RuntimeException)
1121 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1123 if ( !mxModel.is() )
1125 RuntimeException aException;
1126 aException.Message = ::rtl::OUString::createFromAscii( "createPeer: no model!" );
1127 aException.Context = (XAggregation*)(::cppu::OWeakAggObject*)this;
1128 throw( aException );
1131 if( !getPeer().is() )
1133 mbCreatingPeer = sal_True;
1135 WindowClass eType;
1136 Reference< XToolkit > xToolkit = rxToolkit;
1137 if( rParentPeer.is() && mxContext.is() )
1139 // kein TopWindow
1140 if ( !xToolkit.is() )
1141 xToolkit = rParentPeer->getToolkit();
1142 Any aAny = OWeakAggObject::queryInterface( ::getCppuType((const Reference< XControlContainer>*)0) );
1143 Reference< XControlContainer > xC;
1144 aAny >>= xC;
1145 if( xC.is() )
1146 // Es ist ein Container
1147 eType = WindowClass_CONTAINER;
1148 else
1149 eType = WindowClass_SIMPLE;
1151 else
1152 { // Nur richtig, wenn es sich um ein Top Window handelt
1153 if( rParentPeer.is() )
1155 if ( !xToolkit.is() )
1156 xToolkit = rParentPeer->getToolkit();
1157 eType = WindowClass_CONTAINER;
1159 else
1161 if ( !xToolkit.is() )
1162 xToolkit = VCLUnoHelper::CreateToolkit();
1163 eType = WindowClass_TOP;
1166 WindowDescriptor aDescr;
1167 aDescr.Type = eType;
1168 aDescr.WindowServiceName = GetComponentServiceName();
1169 aDescr.Parent = rParentPeer;
1170 aDescr.Bounds = getPosSize();
1171 aDescr.WindowAttributes = 0;
1173 // Border
1174 Reference< XPropertySet > xPSet( mxModel, UNO_QUERY );
1175 Reference< XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
1177 Any aVal;
1178 ::rtl::OUString aPropName = GetPropertyName( BASEPROPERTY_BORDER );
1179 if ( xInfo->hasPropertyByName( aPropName ) )
1181 aVal = xPSet->getPropertyValue( aPropName );
1182 sal_Int16 n = sal_Int16();
1183 if ( aVal >>= n )
1185 if ( n )
1186 aDescr.WindowAttributes |= WindowAttribute::BORDER;
1187 else
1188 aDescr.WindowAttributes |= VclWindowPeerAttribute::NOBORDER;
1192 // DESKTOP_AS_PARENT
1193 if ( aDescr.Type == WindowClass_TOP )
1195 aPropName = GetPropertyName( BASEPROPERTY_DESKTOP_AS_PARENT );
1196 if ( xInfo->hasPropertyByName( aPropName ) )
1198 aVal = xPSet->getPropertyValue( aPropName );
1199 sal_Bool b = sal_Bool();
1200 if ( ( aVal >>= b ) && b)
1201 aDescr.ParentIndex = -1;
1204 // Moveable
1205 aPropName = GetPropertyName( BASEPROPERTY_MOVEABLE );
1206 if ( xInfo->hasPropertyByName( aPropName ) )
1208 aVal = xPSet->getPropertyValue( aPropName );
1209 sal_Bool b = sal_Bool();
1210 if ( ( aVal >>= b ) && b)
1211 aDescr.WindowAttributes |= WindowAttribute::MOVEABLE;
1214 // Closeable
1215 aPropName = GetPropertyName( BASEPROPERTY_CLOSEABLE );
1216 if ( xInfo->hasPropertyByName( aPropName ) )
1218 aVal = xPSet->getPropertyValue( aPropName );
1219 sal_Bool b = sal_Bool();
1220 if ( ( aVal >>= b ) && b)
1221 aDescr.WindowAttributes |= WindowAttribute::CLOSEABLE;
1224 // Dropdown
1225 aPropName = GetPropertyName( BASEPROPERTY_DROPDOWN );
1226 if ( xInfo->hasPropertyByName( aPropName ) )
1228 aVal = xPSet->getPropertyValue( aPropName );
1229 sal_Bool b = sal_Bool();
1230 if ( ( aVal >>= b ) && b)
1231 aDescr.WindowAttributes |= VclWindowPeerAttribute::DROPDOWN;
1234 // Spin
1235 aPropName = GetPropertyName( BASEPROPERTY_SPIN );
1236 if ( xInfo->hasPropertyByName( aPropName ) )
1238 aVal = xPSet->getPropertyValue( aPropName );
1239 sal_Bool b = sal_Bool();
1240 if ( ( aVal >>= b ) && b)
1241 aDescr.WindowAttributes |= VclWindowPeerAttribute::SPIN;
1244 // HScroll
1245 aPropName = GetPropertyName( BASEPROPERTY_HSCROLL );
1246 if ( xInfo->hasPropertyByName( aPropName ) )
1248 aVal = xPSet->getPropertyValue( aPropName );
1249 sal_Bool b = sal_Bool();
1250 if ( ( aVal >>= b ) && b)
1251 aDescr.WindowAttributes |= VclWindowPeerAttribute::HSCROLL;
1254 // VScroll
1255 aPropName = GetPropertyName( BASEPROPERTY_VSCROLL );
1256 if ( xInfo->hasPropertyByName( aPropName ) )
1258 aVal = xPSet->getPropertyValue( aPropName );
1259 sal_Bool b = sal_Bool();
1260 if ( ( aVal >>= b ) && b)
1261 aDescr.WindowAttributes |= VclWindowPeerAttribute::VSCROLL;
1264 // AutoHScroll
1265 aPropName = GetPropertyName( BASEPROPERTY_AUTOHSCROLL );
1266 if ( xInfo->hasPropertyByName( aPropName ) )
1268 aVal = xPSet->getPropertyValue( aPropName );
1269 sal_Bool b = sal_Bool();
1270 if ( ( aVal >>= b ) && b)
1271 aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOHSCROLL;
1274 // AutoVScroll
1275 aPropName = GetPropertyName( BASEPROPERTY_AUTOVSCROLL );
1276 if ( xInfo->hasPropertyByName( aPropName ) )
1278 aVal = xPSet->getPropertyValue( aPropName );
1279 sal_Bool b = sal_Bool();
1280 if ( ( aVal >>= b ) && b)
1281 aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOVSCROLL;
1284 //added for issue79712
1285 //NoLabel
1286 aPropName = GetPropertyName( BASEPROPERTY_NOLABEL );
1287 if ( xInfo->hasPropertyByName( aPropName ) )
1289 aVal = xPSet->getPropertyValue( aPropName );
1290 sal_Bool b = sal_Bool();
1291 if ( ( aVal >>=b ) && b )
1292 aDescr.WindowAttributes |= VclWindowPeerAttribute::NOLABEL;
1294 //issue79712 ends
1296 // Align
1297 aPropName = GetPropertyName( BASEPROPERTY_ALIGN );
1298 if ( xInfo->hasPropertyByName( aPropName ) )
1300 aVal = xPSet->getPropertyValue( aPropName );
1301 sal_Int16 n = sal_Int16();
1302 if ( aVal >>= n )
1304 if ( n == PROPERTY_ALIGN_LEFT )
1305 aDescr.WindowAttributes |= VclWindowPeerAttribute::LEFT;
1306 else if ( n == PROPERTY_ALIGN_CENTER )
1307 aDescr.WindowAttributes |= VclWindowPeerAttribute::CENTER;
1308 else
1309 aDescr.WindowAttributes |= VclWindowPeerAttribute::RIGHT;
1313 // Ableitungen die Moeglichkeit geben die Attribute zu manipulieren
1314 PrepareWindowDescriptor(aDescr);
1316 // create the peer
1317 setPeer( xToolkit->createWindow( aDescr ) );
1319 // release the mutex guard (and work with copies of our members)
1320 // this is necessary as our peer may lock the SolarMutex (actually, all currently known peers do), so calling
1321 // into the peer with our own mutex locked may cause deadlocks
1322 // (We _really_ need peers which do not use the SolarMutex. It's really pissing me off that from time to
1323 // time deadlocks pop up because the low-level components like our peers use a mutex which ususally
1324 // is locked at the top of the stack (it protects the global message looping). This is always dangerous, and
1325 // can not always be solved by tampering with other mutexes.
1326 // Unfortunately, the VCL used in the peers is not threadsafe, and by definition needs a locked SolarMutex.)
1327 // 82300 - 12/21/00 - FS
1328 UnoControlComponentInfos aComponentInfos(maComponentInfos);
1329 sal_Bool bDesignMode(mbDesignMode);
1331 Reference< XGraphics > xGraphics( mxGraphics );
1332 Reference< XView > xView ( getPeer(), UNO_QUERY );
1333 Reference< XWindow > xWindow ( getPeer(), UNO_QUERY );
1335 aGuard.clear();
1337 // the updateFromModel is done without a locked mutex, too.
1338 // The reason is that the only thing this method does is firing property changes, and this in general has
1339 // to be done without locked mutexes (as every notification to external listeners).
1340 // 82300 - 12/21/00 - FS
1341 updateFromModel();
1343 xView->setZoom( aComponentInfos.nZoomX, aComponentInfos.nZoomY );
1345 setPosSize( aComponentInfos.nX, aComponentInfos.nY, aComponentInfos.nWidth, aComponentInfos.nHeight, aComponentInfos.nFlags );
1347 if( aComponentInfos.bVisible && !bDesignMode )
1348 // Erst nach dem setzen der Daten anzeigen
1349 xWindow->setVisible( aComponentInfos.bVisible );
1351 if( !aComponentInfos.bEnable )
1352 xWindow->setEnable( aComponentInfos.bEnable );
1354 xView->setGraphics( xGraphics );
1356 peerCreated();
1358 mbCreatingPeer = sal_False;
1362 Reference< XWindowPeer > UnoControl::getPeer() throw(RuntimeException)
1364 ::osl::MutexGuard aGuard( GetMutex() );
1365 return mxPeer;
1368 sal_Bool UnoControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException)
1370 ::osl::MutexGuard aGuard( GetMutex() );
1372 Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
1374 // query for the XPropertiesChangeListener - our delegator is allowed to overwrite this interface
1375 Reference< XPropertiesChangeListener > xListener;
1376 queryInterface( ::getCppuType( &xListener ) ) >>= xListener;
1378 if( xPropSet.is() )
1379 xPropSet->removePropertiesChangeListener( xListener );
1381 mpData->bLocalizationSupport = false;
1382 mxModel = rxModel;
1384 if( mxModel.is() )
1388 xPropSet.set( mxModel, UNO_QUERY_THROW );
1389 Reference< XPropertySetInfo > xPSI( xPropSet->getPropertySetInfo(), UNO_SET_THROW );
1391 Sequence< ::rtl::OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
1392 xPropSet->addPropertiesChangeListener( aNames, xListener );
1394 mpData->bLocalizationSupport = xPSI->hasPropertyByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" ) ) );
1396 catch( const Exception& )
1398 DBG_UNHANDLED_EXCEPTION();
1399 mxModel.clear();
1403 return mxModel.is();
1406 Reference< XControlModel > UnoControl::getModel( ) throw(RuntimeException)
1408 return mxModel;
1411 Reference< XView > UnoControl::getView( ) throw(RuntimeException)
1413 return static_cast< XView* >( this );
1416 void UnoControl::setDesignMode( sal_Bool bOn ) throw(RuntimeException)
1418 ModeChangeEvent aModeChangeEvent;
1420 Reference< XWindow > xWindow;
1422 ::osl::MutexGuard aGuard( GetMutex() );
1423 if ( bOn == mbDesignMode )
1424 return;
1426 // remember this
1427 mbDesignMode = bOn;
1428 xWindow = xWindow.query( getPeer() );
1429 // dispose our current AccessibleContext, if we have one
1430 // (changing the design mode implies having a new implementation for this context,
1431 // so the old one must be declared DEFUNC)
1432 disposeAccessibleContext();
1434 aModeChangeEvent.Source = *this;
1435 aModeChangeEvent.NewMode = ::rtl::OUString::createFromAscii( mbDesignMode ? "design" : "alive" );
1438 // ajust the visibility of our window
1439 if ( xWindow.is() )
1440 xWindow->setVisible( !bOn );
1442 // and notify our mode listeners
1443 maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent );
1446 sal_Bool UnoControl::isDesignMode( ) throw(RuntimeException)
1448 return mbDesignMode;
1451 sal_Bool UnoControl::isTransparent( ) throw(RuntimeException)
1453 return sal_False;
1456 // XServiceInfo
1457 ::rtl::OUString UnoControl::getImplementationName( ) throw(RuntimeException)
1459 DBG_ERROR( "This method should be overloaded!" );
1460 return ::rtl::OUString();
1463 sal_Bool UnoControl::supportsService( const ::rtl::OUString& rServiceName ) throw(RuntimeException)
1465 ::osl::MutexGuard aGuard( GetMutex() );
1467 Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
1468 const ::rtl::OUString* pArray = aSNL.getConstArray();
1469 const ::rtl::OUString* pArrayEnd = aSNL.getConstArray();
1470 for (; pArray != pArrayEnd; ++pArray )
1471 if( *pArray == rServiceName )
1472 break;
1474 return pArray != pArrayEnd;
1477 Sequence< ::rtl::OUString > UnoControl::getSupportedServiceNames( ) throw(RuntimeException)
1479 ::rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControl" ) );
1480 return Sequence< ::rtl::OUString >( &sName, 1 );
1483 // ------------------------------------------------------------------------
1484 Reference< XAccessibleContext > SAL_CALL UnoControl::getAccessibleContext( ) throw (RuntimeException)
1486 // creation of the context will certainly require the SolarMutex ...
1487 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1488 ::osl::MutexGuard aGuard( GetMutex() );
1490 Reference< XAccessibleContext > xCurrentContext( maAccessibleContext.get(), UNO_QUERY );
1491 if ( !xCurrentContext.is() )
1493 if ( !mbDesignMode )
1494 { // in alive mode, use the AccessibleContext of the peer
1495 Reference< XAccessible > xPeerAcc( getPeer(), UNO_QUERY );
1496 if ( xPeerAcc.is() )
1497 xCurrentContext = xPeerAcc->getAccessibleContext( );
1499 else
1500 // in design mode, use a fallback
1501 xCurrentContext = ::toolkit::OAccessibleControlContext::create( this );
1503 DBG_ASSERT( xCurrentContext.is(), "UnoControl::getAccessibleContext: invalid context (invalid peer?)!" );
1504 maAccessibleContext = xCurrentContext;
1506 // get notified when the context is disposed
1507 Reference< XComponent > xContextComp( xCurrentContext, UNO_QUERY );
1508 if ( xContextComp.is() )
1509 xContextComp->addEventListener( this );
1510 // In an ideal world, this is not necessary - there the object would be released as soon as it has been
1511 // disposed, and thus our weak reference would be empty, too.
1512 // But 'til this ideal world comes (means 'til we do never have any refcount/lifetime bugs anymore), we
1513 // need to listen for disposal and reset our weak reference then.
1516 return xCurrentContext;
1519 void SAL_CALL UnoControl::addModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException)
1521 ::osl::MutexGuard aGuard( GetMutex() );
1522 maModeChangeListeners.addInterface( _rxListener );
1525 void SAL_CALL UnoControl::removeModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException)
1527 ::osl::MutexGuard aGuard( GetMutex() );
1528 maModeChangeListeners.removeInterface( _rxListener );
1531 void SAL_CALL UnoControl::addModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException)
1533 throw NoSupportException( );
1536 void SAL_CALL UnoControl::removeModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException)
1538 throw NoSupportException( );