1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
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>
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 <vcl/svapp.hxx>
55 #include <vcl/wrkwin.hxx>
56 #include <comphelper/stl_types.hxx>
57 #include <toolkit/helper/property.hxx>
58 #include <toolkit/helper/servicenames.hxx>
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <toolkit/awt/vclxwindow.hxx>
61 #include <vcl/svapp.hxx>
62 #include <vos/mutex.hxx>
63 #include <toolkit/controls/accessiblecontrolcontext.hxx>
64 #include <comphelper/container.hxx>
69 using namespace ::com::sun::star
;
70 using namespace ::com::sun::star::uno
;
71 using namespace ::com::sun::star::awt
;
72 using namespace ::com::sun::star::beans
;
73 using namespace ::com::sun::star::lang
;
74 using namespace ::com::sun::star::util
;
76 using ::com::sun::star::accessibility::XAccessibleContext
;
77 using ::com::sun::star::accessibility::XAccessible
;
79 struct LanguageDependentProp
81 const char* pPropName
;
82 sal_Int32 nPropNameLength
;
85 static const LanguageDependentProp aLanguageDependentProp
[] =
91 { "CurrencySymbol", 14 },
92 { "StringItemList", 14 },
96 WorkWindow
* lcl_GetDefaultWindow()
98 static WorkWindow
* pW
= NULL
;
101 pW
= new WorkWindow( NULL
, 0 );
102 pW
->EnableChildTransparentMode();
107 static Sequence
< ::rtl::OUString
> lcl_ImplGetPropertyNames( const Reference
< XMultiPropertySet
> & rxModel
)
109 Sequence
< ::rtl::OUString
> aNames
;
110 Reference
< XPropertySetInfo
> xPSInf
= rxModel
->getPropertySetInfo();
111 DBG_ASSERT( xPSInf
.is(), "UpdateFromModel: No PropertySetInfo!" );
114 Sequence
< Property
> aProps
= xPSInf
->getProperties();
115 sal_Int32 nLen
= aProps
.getLength();
116 aNames
= Sequence
< ::rtl::OUString
>( nLen
);
117 ::rtl::OUString
* pNames
= aNames
.getArray();
118 const Property
* pProps
= aProps
.getConstArray();
119 for ( sal_Int32 n
= 0; n
< nLen
; ++n
, ++pProps
, ++pNames
)
120 *pNames
= pProps
->Name
;
125 // ====================================================
126 class VclListenerLock
129 VCLXWindow
* m_pLockWindow
;
132 inline VclListenerLock( VCLXWindow
* _pLockWindow
)
133 :m_pLockWindow( _pLockWindow
)
135 // DBG_ASSERT( m_pLockWindow, "VclListenerLock::VclListenerLock: invalid window!" );
137 m_pLockWindow
->suspendVclEventListening( );
139 inline ~VclListenerLock( )
142 m_pLockWindow
->resumeVclEventListening( );
146 VclListenerLock(); // never implemented
147 VclListenerLock( const VclListenerLock
& ); // never implemented
148 VclListenerLock
& operator=( const VclListenerLock
& ); // never implemented
151 struct UnoControl_Data
153 ::std::set
< ::rtl::OUString
> aPropertyNotificationFilter
;
156 // ----------------------------------------------------
158 // ----------------------------------------------------
159 DBG_NAME( UnoControl
)
160 UnoControl::UnoControl()
161 : maDisposeListeners( *this )
162 , maWindowListeners( *this )
163 , maFocusListeners( *this )
164 , maKeyListeners( *this )
165 , maMouseListeners( *this )
166 , maMouseMotionListeners( *this )
167 , maPaintListeners( *this )
168 , maModeChangeListeners( GetMutex() )
169 , mpData( new UnoControl_Data
)
171 DBG_CTOR( UnoControl
, NULL
);
172 mbDisposePeer
= sal_True
;
173 mbRefeshingPeer
= sal_False
;
174 mbCreatingPeer
= sal_False
;
175 mbCreatingCompatiblePeer
= sal_False
;
176 mbDesignMode
= sal_False
;
179 UnoControl::~UnoControl()
182 DBG_DTOR( UnoControl
, NULL
);
185 ::rtl::OUString
UnoControl::GetComponentServiceName()
187 return ::rtl::OUString();
190 Reference
< XWindowPeer
> UnoControl::ImplGetCompatiblePeer( sal_Bool bAcceptExistingPeer
)
192 DBG_ASSERT( !mbCreatingCompatiblePeer
, "ImplGetCompatiblePeer - rekursive?" );
194 mbCreatingCompatiblePeer
= sal_True
;
196 Reference
< XWindowPeer
> xCompatiblePeer
;
198 if ( bAcceptExistingPeer
)
199 xCompatiblePeer
= getPeer();
201 if ( !xCompatiblePeer
.is() )
203 // Peer unsichtbar erzeugen...
204 sal_Bool bVis
= maComponentInfos
.bVisible
;
206 maComponentInfos
.bVisible
= sal_False
;
208 Reference
< XWindowPeer
> xCurrentPeer
= getPeer();
211 // queryInterface ourself, to allow aggregation
212 Reference
< XControl
> xMe
;
213 OWeakAggObject::queryInterface( ::getCppuType( &xMe
) ) >>= xMe
;
217 osl::Guard
< vos::IMutex
> aGuard( Application::GetSolarMutex() );
218 pWW
= lcl_GetDefaultWindow();
222 xMe
->createPeer( NULL
, pWW
->GetComponentInterface( sal_True
) );
224 catch( const Exception
& )
226 mbCreatingCompatiblePeer
= sal_False
;
229 xCompatiblePeer
= getPeer();
230 setPeer( xCurrentPeer
);
232 if ( xCompatiblePeer
.is() && mxGraphics
.is() )
234 Reference
< XView
> xPeerView( xCompatiblePeer
, UNO_QUERY
);
235 if ( xPeerView
.is() )
236 xPeerView
->setGraphics( mxGraphics
);
240 maComponentInfos
.bVisible
= sal_True
;
243 mbCreatingCompatiblePeer
= sal_False
;
245 return xCompatiblePeer
;
248 bool UnoControl::ImplMapPlaceHolder( ::rtl::OUString
& rPlaceHolder
)
250 rtl::OUString aMappedValue
;
252 Reference
< XPropertySet
> xPropSet( mxModel
, UNO_QUERY
);
256 Reference
< resource::XStringResourceResolver
> xStringResourceResolver
;
257 a
= xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" )));
258 if ( a
>>= xStringResourceResolver
)
260 if ( xStringResourceResolver
.is() )
264 rPlaceHolder
= xStringResourceResolver
->resolveString( rPlaceHolder
);
267 catch ( resource::MissingResourceException
& )
278 void UnoControl::ImplSetPeerProperty( const ::rtl::OUString
& rPropName
, const Any
& rVal
)
280 // since a change made in propertiesChange, we can't be sure that this is called with an valid getPeer(),
281 // this assumption may be false in some (seldom) multi-threading scenarios (cause propertiesChange
282 // releases our mutex before calling here in)
283 // That's why this additional check
285 if ( mxVclWindowPeer
.is() )
289 // We now support a mapping for language dependent properties. This is the
290 // central method to implement it.
291 if (( rPropName
.equalsAsciiL( "Text", 4 )) ||
292 ( rPropName
.equalsAsciiL( "Label", 5 )) ||
293 ( rPropName
.equalsAsciiL( "Title", 5 )) ||
294 ( rPropName
.equalsAsciiL( "HelpText", 8 )) ||
295 ( rPropName
.equalsAsciiL( "CurrencySymbol", 14 )) ||
296 ( rPropName
.equalsAsciiL( "StringItemList", 14 )) )
298 rtl::OUString aValue
;
299 uno::Sequence
< rtl::OUString
> aSeqValue
;
301 if ( aVal
>>= aValue
)
303 // Map single string value
304 if (( aValue
.getLength() > 0 ) &&
305 ( aValue
.compareToAscii( "&", 1 ) == 0 ))
307 // Magic symbol '&' found at first place. Interpret as a place
308 // holder identifier. Now try to map it to the real value. The
309 // magic symbol must be removed.
310 rtl::OUString
aKeyValue( aValue
.copy( 1 ));
311 if ( ImplMapPlaceHolder( aKeyValue
))
315 else if ( aVal
>>= aSeqValue
)
317 // Map sequence strings
318 for ( sal_Int32 i
= 0; i
< aSeqValue
.getLength(); i
++ )
320 aValue
= aSeqValue
[i
];
321 if (( aValue
.getLength() > 0 ) &&
322 ( aValue
.compareToAscii( "&", 1 ) == 0 ))
324 // Magic symbol '&' found at first place. Interpret as a place
325 // holder identifier. Now try to map it to the real value. The
326 // magic symbol must be removed.
327 rtl::OUString
aKeyValue( aValue
.copy( 1 ));
328 if ( ImplMapPlaceHolder( aKeyValue
))
329 aSeqValue
[i
] = aKeyValue
;
336 mxVclWindowPeer
->setProperty( rPropName
, aVal
);
340 void UnoControl::PrepareWindowDescriptor( WindowDescriptor
& )
344 Reference
< XWindow
> UnoControl::getParentPeer() const
346 Reference
< XWindow
> xPeer
;
349 Reference
< XControl
> xContComp( mxContext
, UNO_QUERY
);
350 if ( xContComp
.is() )
352 Reference
< XWindowPeer
> xP
= xContComp
->getPeer();
354 xP
->queryInterface( ::getCppuType((const Reference
< XWindow
>*)0) ) >>= xPeer
;
360 void UnoControl::updateFromModel()
362 // Alle standard Properties werden ausgelesen und in das Peer uebertragen
365 Reference
< XMultiPropertySet
> xPropSet( mxModel
, UNO_QUERY
);
368 Sequence
< ::rtl::OUString
> aNames
= lcl_ImplGetPropertyNames( xPropSet
);
369 xPropSet
->firePropertiesChangeEvent( aNames
, this );
376 IMPL_IMPLEMENTATION_ID( UnoControl
)
378 void UnoControl::disposeAccessibleContext()
380 Reference
< XComponent
> xContextComp( maAccessibleContext
.get(), UNO_QUERY
);
381 if ( xContextComp
.is() )
383 maAccessibleContext
= NULL
;
386 xContextComp
->removeEventListener( this );
387 xContextComp
->dispose();
389 catch( const Exception
& )
391 DBG_ERROR( "UnoControl::disposeAccessibleContext: could not dispose my AccessibleContext!" );
396 void UnoControl::dispose( ) throw(RuntimeException
)
398 Reference
< XWindowPeer
> xPeer
;
400 ::osl::MutexGuard
aGuard( GetMutex() );
412 // dispose and release our AccessibleContext
413 disposeAccessibleContext();
415 EventObject aDisposeEvent
;
416 aDisposeEvent
.Source
= static_cast< XAggregation
* >( this );
418 maDisposeListeners
.disposeAndClear( aDisposeEvent
);
419 maWindowListeners
.disposeAndClear( aDisposeEvent
);
420 maFocusListeners
.disposeAndClear( aDisposeEvent
);
421 maKeyListeners
.disposeAndClear( aDisposeEvent
);
422 maMouseListeners
.disposeAndClear( aDisposeEvent
);
423 maMouseMotionListeners
.disposeAndClear( aDisposeEvent
);
424 maPaintListeners
.disposeAndClear( aDisposeEvent
);
425 maModeChangeListeners
.disposeAndClear( aDisposeEvent
);
427 // Model wieder freigeben
428 setModel( Reference
< XControlModel
> () );
429 setContext( Reference
< XInterface
> () );
432 void UnoControl::addEventListener( const Reference
< XEventListener
>& rxListener
) throw(RuntimeException
)
434 ::osl::MutexGuard
aGuard( GetMutex() );
436 maDisposeListeners
.addInterface( rxListener
);
439 void UnoControl::removeEventListener( const Reference
< XEventListener
>& rxListener
) throw(RuntimeException
)
441 ::osl::MutexGuard
aGuard( GetMutex() );
443 maDisposeListeners
.removeInterface( rxListener
);
446 sal_Bool
UnoControl::requiresNewPeer( const ::rtl::OUString
& /* _rPropertyName */ ) const
451 // XPropertiesChangeListener
452 void UnoControl::propertiesChange( const Sequence
< PropertyChangeEvent
>& rEvents
) throw(RuntimeException
)
454 Sequence
< PropertyChangeEvent
> aEvents( rEvents
);
456 ::osl::MutexGuard
aGuard( GetMutex() );
458 if ( !mpData
->aPropertyNotificationFilter
.empty() )
460 // strip the property which we are currently updating (somewhere up the stack)
461 PropertyChangeEvent
* pEvents
= aEvents
.getArray();
462 PropertyChangeEvent
* pEventsEnd
= pEvents
+ aEvents
.getLength();
463 for ( ; pEvents
< pEventsEnd
; )
464 if ( mpData
->aPropertyNotificationFilter
.find( pEvents
->PropertyName
) != mpData
->aPropertyNotificationFilter
.end() )
466 if ( pEvents
!= pEventsEnd
)
467 ::std::copy( pEvents
+ 1, pEventsEnd
, pEvents
);
472 aEvents
.realloc( pEventsEnd
- aEvents
.getConstArray() );
474 if ( !aEvents
.getLength() )
479 ImplModelPropertiesChanged( aEvents
);
482 void UnoControl::ImplLockPropertyChangeNotification( const ::rtl::OUString
& rPropertyName
, bool bLock
)
486 OSL_PRECOND( mpData
->aPropertyNotificationFilter
.find( rPropertyName
) == mpData
->aPropertyNotificationFilter
.end(),
487 "UnoControl::ImplLockPropertyChangeNotification: already locked!" );
488 mpData
->aPropertyNotificationFilter
.insert( rPropertyName
);
492 OSL_PRECOND( mpData
->aPropertyNotificationFilter
.find( rPropertyName
) != mpData
->aPropertyNotificationFilter
.end(),
493 "UnoControl::ImplLockPropertyChangeNotification: not locked!" );
494 mpData
->aPropertyNotificationFilter
.erase( rPropertyName
);
498 void UnoControl::ImplLockPropertyChangeNotifications( const Sequence
< ::rtl::OUString
>& rPropertyNames
, bool bLock
)
500 for ( const ::rtl::OUString
* pPropertyName
= rPropertyNames
.getConstArray();
501 pPropertyName
!= rPropertyNames
.getConstArray() + rPropertyNames
.getLength();
504 ImplLockPropertyChangeNotification( *pPropertyName
, bLock
);
507 void UnoControl::ImplModelPropertiesChanged( const Sequence
< PropertyChangeEvent
>& rEvents
)
509 ::osl::ClearableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
513 DECLARE_STL_VECTOR( PropertyValue
, PropertyValueVector
);
514 PropertyValueVector aPeerPropertiesToSet
;
515 sal_Int32 nIndependentPos
= 0;
516 bool bResourceResolverSet( false );
517 // position where to insert the independent properties into aPeerPropertiesToSet,
518 // dependent ones are inserted at the end of the vector
520 sal_Bool bNeedNewPeer
= sal_False
;
521 // some properties require a re-creation of the peer, 'cause they can't be changed on the fly
523 Reference
< XControlModel
> xOwnModel( getModel(), UNO_QUERY
);
524 // our own model for comparison
525 Reference
< XPropertySet
> xPS( xOwnModel
, UNO_QUERY
);
526 Reference
< XPropertySetInfo
> xPSI( xPS
->getPropertySetInfo(), UNO_QUERY
);
527 OSL_ENSURE( xPSI
.is(), "UnoControl::ImplModelPropertiesChanged: should have property set meta data!" );
529 const PropertyChangeEvent
* pEvents
= rEvents
.getConstArray();
531 sal_Int32 nLen
= rEvents
.getLength();
532 aPeerPropertiesToSet
.reserve(nLen
);
534 for( sal_Int32 i
= 0; i
< nLen
; ++i
, ++pEvents
)
536 Reference
< XControlModel
> xModel( pEvents
->Source
, UNO_QUERY
);
537 sal_Bool bOwnModel
= xModel
.get() == xOwnModel
.get();
541 // Detect changes on our resource resolver which invalidates
542 // automatically some language dependent properties.
543 if ( pEvents
->PropertyName
.equalsAsciiL( "ResourceResolver", 16 ))
545 Reference
< resource::XStringResourceResolver
> xStrResolver
;
546 if ( pEvents
->NewValue
>>= xStrResolver
)
547 bResourceResolverSet
= xStrResolver
.is();
550 sal_uInt16 nPType
= GetPropertyId( pEvents
->PropertyName
);
551 if ( mbDesignMode
&& mbDisposePeer
&& !mbRefeshingPeer
&& !mbCreatingPeer
)
553 // if we're in design mode, then some properties can change which
554 // require creating a *new* peer (since these properties cannot
555 // be switched at existing peers)
557 bNeedNewPeer
= ( nPType
== BASEPROPERTY_BORDER
)
558 || ( nPType
== BASEPROPERTY_MULTILINE
)
559 || ( nPType
== BASEPROPERTY_DROPDOWN
)
560 || ( nPType
== BASEPROPERTY_HSCROLL
)
561 || ( nPType
== BASEPROPERTY_VSCROLL
)
562 || ( nPType
== BASEPROPERTY_AUTOHSCROLL
)
563 || ( nPType
== BASEPROPERTY_AUTOVSCROLL
)
564 || ( nPType
== BASEPROPERTY_ORIENTATION
)
565 || ( nPType
== BASEPROPERTY_SPIN
)
566 || ( nPType
== BASEPROPERTY_ALIGN
)
567 || ( nPType
== BASEPROPERTY_PAINTTRANSPARENT
);
569 bNeedNewPeer
= requiresNewPeer( pEvents
->PropertyName
);
575 if ( nPType
&& ( nLen
> 1 ) && DoesDependOnOthers( nPType
) )
577 // Properties die von anderen abhaengen erst hinterher einstellen,
578 // weil sie von anderen Properties abhaengig sind, die aber erst spaeter
579 // eingestellt werden, z.B. VALUE nach VALUEMIN/MAX.
580 aPeerPropertiesToSet
.push_back(PropertyValue(pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
));
584 if ( bResourceResolverSet
)
586 // The resource resolver property change should be one of the first ones.
587 // All language dependent properties are dependent on this property.
588 // As BASEPROPERTY_NATIVE_WIDGET_LOOK is not dependent on resource
589 // resolver. We don't need to handle a special order for these two props.
590 aPeerPropertiesToSet
.insert(
591 aPeerPropertiesToSet
.begin(),
592 PropertyValue( pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
) );
595 else if ( nPType
== BASEPROPERTY_NATIVE_WIDGET_LOOK
)
597 // since *a lot* of other properties might be overruled by this one, we need
598 // a special handling:
599 // NativeWidgetLook needs to be set first: If it is set to ON, all other
600 // properties describing the look (e.g. BackgroundColor) are ignored, anyway.
601 // If it is switched OFF, then we need to do it first because else it will
602 // overrule other look-related properties, and re-initialize them from system
604 aPeerPropertiesToSet
.insert(
605 aPeerPropertiesToSet
.begin(),
606 PropertyValue( pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
) );
611 aPeerPropertiesToSet
.insert(aPeerPropertiesToSet
.begin() + nIndependentPos
,
612 PropertyValue(pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
));
618 Reference
< XWindow
> xParent
= getParentPeer();
619 Reference
< XControl
> xThis( (XAggregation
*)(::cppu::OWeakAggObject
*)this, UNO_QUERY
);
620 // call createPeer via a interface got from queryInterface, so the aggregating class can intercept it
622 DBG_ASSERT( !bNeedNewPeer
|| xParent
.is(), "Need new peer, but don't have a parent!" );
624 // Check if we have to update language dependent properties
625 if ( !bNeedNewPeer
&& bResourceResolverSet
)
627 // Add language dependent properties into the peer property set.
628 // Our resource resolver has been changed and we must be sure
629 // that language dependent props use the new resolver.
630 const LanguageDependentProp
* pLangDepProp
= aLanguageDependentProp
;
631 while ( pLangDepProp
->pPropName
!= 0 )
633 bool bMustBeInserted( true );
634 for ( sal_uInt32 i
= 0; i
< aPeerPropertiesToSet
.size(); i
++ )
636 if ( aPeerPropertiesToSet
[i
].Name
.equalsAsciiL(
637 pLangDepProp
->pPropName
, pLangDepProp
->nPropNameLength
))
639 bMustBeInserted
= false;
644 if ( bMustBeInserted
)
646 // Add language dependent props at the end
647 ::rtl::OUString
aPropName( ::rtl::OUString::createFromAscii( pLangDepProp
->pPropName
));
648 if ( xPSI
.is() && xPSI
->hasPropertyByName( aPropName
) )
650 aPeerPropertiesToSet
.push_back(
651 PropertyValue( aPropName
, 0, xPS
->getPropertyValue( aPropName
), PropertyState_DIRECT_VALUE
) );
660 // clear the guard before creating a new peer - as usual, our peer implementations use the SolarMutex
661 // #82300# - 2000-12-21 - fs@openoffice.org
662 if (bNeedNewPeer
&& xParent
.is())
664 NAMESPACE_VOS(OGuard
) aVclGuard( Application::GetSolarMutex() );
665 // and now this is the final withdrawal:
666 // With 83561, I have no other idea than locking the SolarMutex here ....
667 // I really hate the fact that VCL is not theadsafe ....
668 // #83561# - 2001-03-01 - fs@openoffice.org
670 // Funktioniert beim Container nicht!
671 getPeer()->dispose();
673 mxVclWindowPeer
= NULL
;
674 mbRefeshingPeer
= sal_True
;
675 Reference
< XWindowPeer
> xP( xParent
, UNO_QUERY
);
676 xThis
->createPeer( Reference
< XToolkit
> (), xP
);
677 mbRefeshingPeer
= sal_False
;
678 aPeerPropertiesToSet
.clear();
681 // lock the multiplexing of VCL events to our UNO listeners
682 // this is for compatibility reasons: in OOo 1.0.x, changes which were done at the
683 // model did not cause the listeners of the controls/peers to be called
684 // Since the implementations for the listeners changed a lot towards 1.1, this
685 // would not be the case anymore, if we would not do this listener-lock below
686 // #i14703# - 2003-05-23 - fs@openoffice.org
687 Window
* pVclPeer
= VCLUnoHelper::GetWindow( getPeer() );
688 VCLXWindow
* pPeer
= pVclPeer
? pVclPeer
->GetWindowPeer() : NULL
;
689 VclListenerLock
aNoVclEventMultiplexing( pPeer
);
691 // setting peer properties may result in an attemp to acquire the solar mutex, 'cause the peers
692 // usually don't have an own mutex but use the SolarMutex instead.
693 // To prevent deadlocks resulting from this, we do this without our own mutex locked
694 // 2000-11-03 - fs@openoffice.org
695 PropertyValueVectorIterator aEnd
= aPeerPropertiesToSet
.end();
696 for ( PropertyValueVectorIterator aLoop
= aPeerPropertiesToSet
.begin();
701 ImplSetPeerProperty( aLoop
->Name
, aLoop
->Value
);
706 void UnoControl::disposing( const EventObject
& rEvt
) throw(RuntimeException
)
708 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
709 // bei "Multible Inheritance" nicht unterschiedliche Typen vergleichen.
711 if ( maAccessibleContext
.get() == rEvt
.Source
)
713 // just in case the context is disposed, but not released - ensure that we do not re-use it in the future
714 maAccessibleContext
= NULL
;
716 else if( mxModel
.get() == Reference
< XControlModel
>(rEvt
.Source
,UNO_QUERY
).get() )
718 // #62337# if the model dies, it does not make sense for us to live ...
719 Reference
< XControl
> xThis
= this;
724 DBG_ASSERT( !mxModel
.is(), "UnoControl::disposing: invalid dispose behaviour!" );
730 void SAL_CALL
UnoControl::setOutputSize( const awt::Size
& aSize
) throw (RuntimeException
)
732 Reference
< XWindow2
> xPeerWindow
;
734 ::osl::MutexGuard
aGuard( GetMutex() );
735 xPeerWindow
= xPeerWindow
.query( getPeer() );
738 if ( xPeerWindow
.is() )
739 xPeerWindow
->setOutputSize( aSize
);
744 template < typename RETVALTYPE
>
745 RETVALTYPE
lcl_askPeer( const uno::Reference
< awt::XWindowPeer
>& _rxPeer
, RETVALTYPE (SAL_CALL
XWindow2::*_pMethod
)(), RETVALTYPE _aDefault
)
747 RETVALTYPE
aReturn( _aDefault
);
749 Reference
< XWindow2
> xPeerWindow( _rxPeer
, UNO_QUERY
);
750 if ( xPeerWindow
.is() )
751 aReturn
= (xPeerWindow
.get()->*_pMethod
)();
757 awt::Size SAL_CALL
UnoControl::getOutputSize( ) throw (RuntimeException
)
759 return lcl_askPeer( getPeer(), &XWindow2::getOutputSize
, awt::Size() );
762 ::sal_Bool SAL_CALL
UnoControl::isVisible( ) throw (RuntimeException
)
764 return lcl_askPeer( getPeer(), &XWindow2::isVisible
, maComponentInfos
.bVisible
);
767 ::sal_Bool SAL_CALL
UnoControl::isActive( ) throw (RuntimeException
)
769 return lcl_askPeer( getPeer(), &XWindow2::isActive
, sal_False
);
772 ::sal_Bool SAL_CALL
UnoControl::isEnabled( ) throw (RuntimeException
)
774 return lcl_askPeer( getPeer(), &XWindow2::isEnabled
, maComponentInfos
.bEnable
);
777 ::sal_Bool SAL_CALL
UnoControl::hasFocus( ) throw (RuntimeException
)
779 return lcl_askPeer( getPeer(), &XWindow2::hasFocus
, sal_False
);
783 void UnoControl::setPosSize( sal_Int32 X
, sal_Int32 Y
, sal_Int32 Width
, sal_Int32 Height
, sal_Int16 Flags
) throw(RuntimeException
)
785 Reference
< XWindow
> xWindow
;
787 ::osl::MutexGuard
aGuard( GetMutex() );
789 if ( Flags
& awt::PosSize::X
)
790 maComponentInfos
.nX
= X
;
791 if ( Flags
& awt::PosSize::Y
)
792 maComponentInfos
.nY
= Y
;
793 if ( Flags
& awt::PosSize::WIDTH
)
794 maComponentInfos
.nWidth
= Width
;
795 if ( Flags
& awt::PosSize::HEIGHT
)
796 maComponentInfos
.nHeight
= Height
;
797 maComponentInfos
.nFlags
|= Flags
;
799 xWindow
= xWindow
.query( getPeer() );
803 xWindow
->setPosSize( X
, Y
, Width
, Height
, Flags
);
806 awt::Rectangle
UnoControl::getPosSize( ) throw(RuntimeException
)
808 awt::Rectangle
aRect( maComponentInfos
.nX
, maComponentInfos
.nY
, maComponentInfos
.nWidth
, maComponentInfos
.nHeight
);
809 Reference
< XWindow
> xWindow
;
812 ::osl::MutexGuard
aGuard( GetMutex() );
813 xWindow
= xWindow
.query( getPeer() );
817 aRect
= xWindow
->getPosSize();
821 void UnoControl::setVisible( sal_Bool bVisible
) throw(RuntimeException
)
823 Reference
< XWindow
> xWindow
;
825 ::osl::MutexGuard
aGuard( GetMutex() );
827 // Visible status ist Sache der View
828 maComponentInfos
.bVisible
= bVisible
;
829 xWindow
= xWindow
.query( getPeer() );
832 xWindow
->setVisible( bVisible
);
835 void UnoControl::setEnable( sal_Bool bEnable
) throw(RuntimeException
)
837 Reference
< XWindow
> xWindow
;
839 ::osl::MutexGuard
aGuard( GetMutex() );
841 // Enable status ist Sache der View
842 maComponentInfos
.bEnable
= bEnable
;
843 xWindow
= xWindow
.query( getPeer() );
846 xWindow
->setEnable( bEnable
);
849 void UnoControl::setFocus( ) throw(RuntimeException
)
851 Reference
< XWindow
> xWindow
;
853 ::osl::MutexGuard
aGuard( GetMutex() );
854 xWindow
= xWindow
.query( getPeer() );
860 void UnoControl::addWindowListener( const Reference
< XWindowListener
>& rxListener
) throw(RuntimeException
)
862 Reference
< XWindow
> xPeerWindow
;
864 ::osl::MutexGuard
aGuard( GetMutex() );
865 maWindowListeners
.addInterface( rxListener
);
866 if ( maWindowListeners
.getLength() == 1 )
867 xPeerWindow
= xPeerWindow
.query( getPeer() );
869 if ( xPeerWindow
.is() )
870 xPeerWindow
->addWindowListener( &maWindowListeners
);
873 void UnoControl::removeWindowListener( const Reference
< XWindowListener
>& rxListener
) throw(RuntimeException
)
875 Reference
< XWindow
> xPeerWindow
;
877 ::osl::MutexGuard
aGuard( GetMutex() );
878 if ( maWindowListeners
.getLength() == 1 )
879 xPeerWindow
= xPeerWindow
.query( getPeer() );
880 maWindowListeners
.removeInterface( rxListener
);
882 if ( xPeerWindow
.is() )
883 xPeerWindow
->removeWindowListener( &maWindowListeners
);
886 void UnoControl::addFocusListener( const Reference
< XFocusListener
>& rxListener
) throw(RuntimeException
)
888 Reference
< XWindow
> xPeerWindow
;
890 ::osl::MutexGuard
aGuard( GetMutex() );
891 maFocusListeners
.addInterface( rxListener
);
892 if ( maFocusListeners
.getLength() == 1 )
893 xPeerWindow
= xPeerWindow
.query( getPeer() );
895 if ( xPeerWindow
.is() )
896 xPeerWindow
->addFocusListener( &maFocusListeners
);
899 void UnoControl::removeFocusListener( const Reference
< XFocusListener
>& rxListener
) throw(RuntimeException
)
901 Reference
< XWindow
> xPeerWindow
;
903 ::osl::MutexGuard
aGuard( GetMutex() );
904 if ( maFocusListeners
.getLength() == 1 )
905 xPeerWindow
= xPeerWindow
.query( getPeer() );
906 maFocusListeners
.removeInterface( rxListener
);
908 if ( xPeerWindow
.is() )
909 xPeerWindow
->removeFocusListener( &maFocusListeners
);
912 void UnoControl::addKeyListener( const Reference
< XKeyListener
>& rxListener
) throw(RuntimeException
)
914 Reference
< XWindow
> xPeerWindow
;
916 ::osl::MutexGuard
aGuard( GetMutex() );
917 maKeyListeners
.addInterface( rxListener
);
918 if ( maKeyListeners
.getLength() == 1 )
919 xPeerWindow
= xPeerWindow
.query( getPeer() );
921 if ( xPeerWindow
.is() )
922 xPeerWindow
->addKeyListener( &maKeyListeners
);
925 void UnoControl::removeKeyListener( const Reference
< XKeyListener
>& rxListener
) throw(RuntimeException
)
927 Reference
< XWindow
> xPeerWindow
;
929 ::osl::MutexGuard
aGuard( GetMutex() );
930 if ( maKeyListeners
.getLength() == 1 )
931 xPeerWindow
= xPeerWindow
.query( getPeer() );
932 maKeyListeners
.removeInterface( rxListener
);
934 if ( xPeerWindow
.is() )
935 xPeerWindow
->removeKeyListener( &maKeyListeners
);
938 void UnoControl::addMouseListener( const Reference
< XMouseListener
>& rxListener
) throw(RuntimeException
)
940 Reference
< XWindow
> xPeerWindow
;
942 ::osl::MutexGuard
aGuard( GetMutex() );
943 maMouseListeners
.addInterface( rxListener
);
944 if ( maMouseListeners
.getLength() == 1 )
945 xPeerWindow
= xPeerWindow
.query( getPeer() );
947 if ( xPeerWindow
.is() )
948 xPeerWindow
->addMouseListener( &maMouseListeners
);
951 void UnoControl::removeMouseListener( const Reference
< XMouseListener
>& rxListener
) throw(RuntimeException
)
953 Reference
< XWindow
> xPeerWindow
;
955 ::osl::MutexGuard
aGuard( GetMutex() );
956 if ( maMouseListeners
.getLength() == 1 )
957 xPeerWindow
= xPeerWindow
.query( getPeer() );
958 maMouseListeners
.removeInterface( rxListener
);
960 if ( xPeerWindow
.is() )
961 xPeerWindow
->removeMouseListener( &maMouseListeners
);
964 void UnoControl::addMouseMotionListener( const Reference
< XMouseMotionListener
>& rxListener
) throw(RuntimeException
)
966 Reference
< XWindow
> xPeerWindow
;
968 ::osl::MutexGuard
aGuard( GetMutex() );
969 maMouseMotionListeners
.addInterface( rxListener
);
970 if ( maMouseMotionListeners
.getLength() == 1 )
971 xPeerWindow
= xPeerWindow
.query( getPeer() );
973 if ( xPeerWindow
.is() )
974 xPeerWindow
->addMouseMotionListener( &maMouseMotionListeners
);
977 void UnoControl::removeMouseMotionListener( const Reference
< XMouseMotionListener
>& rxListener
) throw(RuntimeException
)
979 Reference
< XWindow
> xPeerWindow
;
981 ::osl::MutexGuard
aGuard( GetMutex() );
982 if ( maMouseMotionListeners
.getLength() == 1 )
983 xPeerWindow
= xPeerWindow
.query( getPeer() );
984 maMouseMotionListeners
.removeInterface( rxListener
);
986 if ( xPeerWindow
.is() )
987 xPeerWindow
->removeMouseMotionListener( &maMouseMotionListeners
);
990 void UnoControl::addPaintListener( const Reference
< XPaintListener
>& rxListener
) throw(RuntimeException
)
992 Reference
< XWindow
> xPeerWindow
;
994 ::osl::MutexGuard
aGuard( GetMutex() );
995 maPaintListeners
.addInterface( rxListener
);
996 if ( maPaintListeners
.getLength() == 1 )
997 xPeerWindow
= xPeerWindow
.query( getPeer() );
999 if ( xPeerWindow
.is() )
1000 xPeerWindow
->addPaintListener( &maPaintListeners
);
1003 void UnoControl::removePaintListener( const Reference
< XPaintListener
>& rxListener
) throw(RuntimeException
)
1005 Reference
< XWindow
> xPeerWindow
;
1007 ::osl::MutexGuard
aGuard( GetMutex() );
1008 if ( maPaintListeners
.getLength() == 1 )
1009 xPeerWindow
= xPeerWindow
.query( getPeer() );
1010 maPaintListeners
.removeInterface( rxListener
);
1012 if ( xPeerWindow
.is() )
1013 xPeerWindow
->removePaintListener( &maPaintListeners
);
1017 sal_Bool
UnoControl::setGraphics( const Reference
< XGraphics
>& rDevice
) throw(RuntimeException
)
1019 Reference
< XView
> xView
;
1021 ::osl::MutexGuard
aGuard( GetMutex() );
1023 mxGraphics
= rDevice
;
1024 xView
= xView
.query( getPeer() );
1026 return xView
.is() ? xView
->setGraphics( rDevice
) : sal_True
;
1029 Reference
< XGraphics
> UnoControl::getGraphics( ) throw(RuntimeException
)
1034 awt::Size
UnoControl::getSize( ) throw(RuntimeException
)
1036 ::osl::MutexGuard
aGuard( GetMutex() );
1037 return awt::Size( maComponentInfos
.nWidth
, maComponentInfos
.nHeight
);
1040 void UnoControl::draw( sal_Int32 x
, sal_Int32 y
) throw(RuntimeException
)
1042 Reference
< XWindowPeer
> xDrawPeer
;
1043 Reference
< XView
> xDrawPeerView
;
1045 bool bDisposeDrawPeer( false );
1047 ::osl::MutexGuard
aGuard( GetMutex() );
1049 xDrawPeer
= ImplGetCompatiblePeer( sal_True
);
1050 bDisposeDrawPeer
= xDrawPeer
.is() && ( xDrawPeer
!= getPeer() );
1052 xDrawPeerView
.set( xDrawPeer
, UNO_QUERY
);
1053 DBG_ASSERT( xDrawPeerView
.is(), "UnoControl::draw: no peer!" );
1056 if ( xDrawPeerView
.is() )
1058 Reference
< XVclWindowPeer
> xWindowPeer
;
1059 xWindowPeer
.set( xDrawPeer
, UNO_QUERY
);
1060 xWindowPeer
->setDesignMode( mbDesignMode
);
1061 xDrawPeerView
->draw( x
, y
);
1064 if ( bDisposeDrawPeer
)
1065 xDrawPeer
->dispose();
1068 void UnoControl::setZoom( float fZoomX
, float fZoomY
) throw(RuntimeException
)
1070 Reference
< XView
> xView
;
1072 ::osl::MutexGuard
aGuard( GetMutex() );
1074 maComponentInfos
.nZoomX
= fZoomX
;
1075 maComponentInfos
.nZoomY
= fZoomY
;
1077 xView
= xView
.query( getPeer() );
1080 xView
->setZoom( fZoomX
, fZoomY
);
1084 void UnoControl::setContext( const Reference
< XInterface
>& rxContext
) throw(RuntimeException
)
1086 ::osl::MutexGuard
aGuard( GetMutex() );
1088 mxContext
= rxContext
;
1091 Reference
< XInterface
> UnoControl::getContext( ) throw(RuntimeException
)
1093 ::osl::MutexGuard
aGuard( GetMutex() );
1098 void UnoControl::peerCreated()
1100 Reference
< XWindow
> xWindow( getPeer(), UNO_QUERY
);
1101 if ( !xWindow
.is() )
1104 if ( maWindowListeners
.getLength() )
1105 xWindow
->addWindowListener( &maWindowListeners
);
1107 if ( maFocusListeners
.getLength() )
1108 xWindow
->addFocusListener( &maFocusListeners
);
1110 if ( maKeyListeners
.getLength() )
1111 xWindow
->addKeyListener( &maKeyListeners
);
1113 if ( maMouseListeners
.getLength() )
1114 xWindow
->addMouseListener( &maMouseListeners
);
1116 if ( maMouseMotionListeners
.getLength() )
1117 xWindow
->addMouseMotionListener( &maMouseMotionListeners
);
1119 if ( maPaintListeners
.getLength() )
1120 xWindow
->addPaintListener( &maPaintListeners
);
1123 void UnoControl::createPeer( const Reference
< XToolkit
>& rxToolkit
, const Reference
< XWindowPeer
>& rParentPeer
) throw(RuntimeException
)
1125 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
1127 if ( !mxModel
.is() )
1129 RuntimeException aException
;
1130 aException
.Message
= ::rtl::OUString::createFromAscii( "createPeer: no model!" );
1131 aException
.Context
= (XAggregation
*)(::cppu::OWeakAggObject
*)this;
1132 throw( aException
);
1135 if( !getPeer().is() )
1137 mbCreatingPeer
= sal_True
;
1140 Reference
< XToolkit
> xToolkit
= rxToolkit
;
1141 if( rParentPeer
.is() && mxContext
.is() )
1144 if ( !xToolkit
.is() )
1145 xToolkit
= rParentPeer
->getToolkit();
1146 Any aAny
= OWeakAggObject::queryInterface( ::getCppuType((const Reference
< XControlContainer
>*)0) );
1147 Reference
< XControlContainer
> xC
;
1150 // Es ist ein Container
1151 eType
= WindowClass_CONTAINER
;
1153 eType
= WindowClass_SIMPLE
;
1156 { // Nur richtig, wenn es sich um ein Top Window handelt
1157 if( rParentPeer
.is() )
1159 if ( !xToolkit
.is() )
1160 xToolkit
= rParentPeer
->getToolkit();
1161 eType
= WindowClass_CONTAINER
;
1165 if ( !xToolkit
.is() )
1166 xToolkit
= VCLUnoHelper::CreateToolkit();
1167 eType
= WindowClass_TOP
;
1170 WindowDescriptor aDescr
;
1171 aDescr
.Type
= eType
;
1172 aDescr
.WindowServiceName
= GetComponentServiceName();
1173 aDescr
.Parent
= rParentPeer
;
1174 aDescr
.Bounds
= getPosSize();
1175 aDescr
.WindowAttributes
= 0;
1178 Reference
< XPropertySet
> xPSet( mxModel
, UNO_QUERY
);
1179 Reference
< XPropertySetInfo
> xInfo
= xPSet
->getPropertySetInfo();
1182 ::rtl::OUString aPropName
= GetPropertyName( BASEPROPERTY_BORDER
);
1183 if ( xInfo
->hasPropertyByName( aPropName
) )
1185 aVal
= xPSet
->getPropertyValue( aPropName
);
1186 sal_Int16 n
= sal_Int16();
1190 aDescr
.WindowAttributes
|= WindowAttribute::BORDER
;
1192 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::NOBORDER
;
1196 // DESKTOP_AS_PARENT
1197 if ( aDescr
.Type
== WindowClass_TOP
)
1199 aPropName
= GetPropertyName( BASEPROPERTY_DESKTOP_AS_PARENT
);
1200 if ( xInfo
->hasPropertyByName( aPropName
) )
1202 aVal
= xPSet
->getPropertyValue( aPropName
);
1203 sal_Bool b
= sal_Bool();
1204 if ( ( aVal
>>= b
) && b
)
1205 aDescr
.ParentIndex
= -1;
1209 aPropName
= GetPropertyName( BASEPROPERTY_MOVEABLE
);
1210 if ( xInfo
->hasPropertyByName( aPropName
) )
1212 aVal
= xPSet
->getPropertyValue( aPropName
);
1213 sal_Bool b
= sal_Bool();
1214 if ( ( aVal
>>= b
) && b
)
1215 aDescr
.WindowAttributes
|= WindowAttribute::MOVEABLE
;
1219 aPropName
= GetPropertyName( BASEPROPERTY_CLOSEABLE
);
1220 if ( xInfo
->hasPropertyByName( aPropName
) )
1222 aVal
= xPSet
->getPropertyValue( aPropName
);
1223 sal_Bool b
= sal_Bool();
1224 if ( ( aVal
>>= b
) && b
)
1225 aDescr
.WindowAttributes
|= WindowAttribute::CLOSEABLE
;
1229 aPropName
= GetPropertyName( BASEPROPERTY_DROPDOWN
);
1230 if ( xInfo
->hasPropertyByName( aPropName
) )
1232 aVal
= xPSet
->getPropertyValue( aPropName
);
1233 sal_Bool b
= sal_Bool();
1234 if ( ( aVal
>>= b
) && b
)
1235 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::DROPDOWN
;
1239 aPropName
= GetPropertyName( BASEPROPERTY_SPIN
);
1240 if ( xInfo
->hasPropertyByName( aPropName
) )
1242 aVal
= xPSet
->getPropertyValue( aPropName
);
1243 sal_Bool b
= sal_Bool();
1244 if ( ( aVal
>>= b
) && b
)
1245 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::SPIN
;
1249 aPropName
= GetPropertyName( BASEPROPERTY_HSCROLL
);
1250 if ( xInfo
->hasPropertyByName( aPropName
) )
1252 aVal
= xPSet
->getPropertyValue( aPropName
);
1253 sal_Bool b
= sal_Bool();
1254 if ( ( aVal
>>= b
) && b
)
1255 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::HSCROLL
;
1259 aPropName
= GetPropertyName( BASEPROPERTY_VSCROLL
);
1260 if ( xInfo
->hasPropertyByName( aPropName
) )
1262 aVal
= xPSet
->getPropertyValue( aPropName
);
1263 sal_Bool b
= sal_Bool();
1264 if ( ( aVal
>>= b
) && b
)
1265 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::VSCROLL
;
1269 aPropName
= GetPropertyName( BASEPROPERTY_AUTOHSCROLL
);
1270 if ( xInfo
->hasPropertyByName( aPropName
) )
1272 aVal
= xPSet
->getPropertyValue( aPropName
);
1273 sal_Bool b
= sal_Bool();
1274 if ( ( aVal
>>= b
) && b
)
1275 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::AUTOHSCROLL
;
1279 aPropName
= GetPropertyName( BASEPROPERTY_AUTOVSCROLL
);
1280 if ( xInfo
->hasPropertyByName( aPropName
) )
1282 aVal
= xPSet
->getPropertyValue( aPropName
);
1283 sal_Bool b
= sal_Bool();
1284 if ( ( aVal
>>= b
) && b
)
1285 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::AUTOVSCROLL
;
1288 //added for issue79712
1290 aPropName
= GetPropertyName( BASEPROPERTY_NOLABEL
);
1291 if ( xInfo
->hasPropertyByName( aPropName
) )
1293 aVal
= xPSet
->getPropertyValue( aPropName
);
1294 sal_Bool b
= sal_Bool();
1295 if ( ( aVal
>>=b
) && b
)
1296 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::NOLABEL
;
1301 aPropName
= GetPropertyName( BASEPROPERTY_ENABLEVISIBLE
);
1302 if ( xInfo
->hasPropertyByName( aPropName
) )
1304 aVal
= xPSet
->getPropertyValue( aPropName
);
1305 sal_Bool b
= sal_Bool();
1306 if ( ( aVal
>>=b
) )
1307 maComponentInfos
.bVisible
= b
;
1311 aPropName
= GetPropertyName( BASEPROPERTY_ALIGN
);
1312 if ( xInfo
->hasPropertyByName( aPropName
) )
1314 aVal
= xPSet
->getPropertyValue( aPropName
);
1315 sal_Int16 n
= sal_Int16();
1318 if ( n
== PROPERTY_ALIGN_LEFT
)
1319 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::LEFT
;
1320 else if ( n
== PROPERTY_ALIGN_CENTER
)
1321 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::CENTER
;
1323 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::RIGHT
;
1327 // Ableitungen die Moeglichkeit geben die Attribute zu manipulieren
1328 PrepareWindowDescriptor(aDescr
);
1331 setPeer( xToolkit
->createWindow( aDescr
) );
1333 // release the mutex guard (and work with copies of our members)
1334 // this is necessary as our peer may lock the SolarMutex (actually, all currently known peers do), so calling
1335 // into the peer with our own mutex locked may cause deadlocks
1336 // (We _really_ need peers which do not use the SolarMutex. It's really pissing me off that from time to
1337 // time deadlocks pop up because the low-level components like our peers use a mutex which ususally
1338 // is locked at the top of the stack (it protects the global message looping). This is always dangerous, and
1339 // can not always be solved by tampering with other mutexes.
1340 // Unfortunately, the VCL used in the peers is not threadsafe, and by definition needs a locked SolarMutex.)
1341 // 82300 - 12/21/00 - FS
1342 UnoControlComponentInfos
aComponentInfos(maComponentInfos
);
1343 sal_Bool
bDesignMode(mbDesignMode
);
1345 Reference
< XGraphics
> xGraphics( mxGraphics
);
1346 Reference
< XView
> xView ( getPeer(), UNO_QUERY
);
1347 Reference
< XWindow
> xWindow ( getPeer(), UNO_QUERY
);
1351 // the updateFromModel is done without a locked mutex, too.
1352 // The reason is that the only thing this method does is firing property changes, and this in general has
1353 // to be done without locked mutexes (as every notification to external listeners).
1354 // 82300 - 12/21/00 - FS
1357 xView
->setZoom( aComponentInfos
.nZoomX
, aComponentInfos
.nZoomY
);
1359 setPosSize( aComponentInfos
.nX
, aComponentInfos
.nY
, aComponentInfos
.nWidth
, aComponentInfos
.nHeight
, aComponentInfos
.nFlags
);
1361 if( aComponentInfos
.bVisible
&& !bDesignMode
)
1362 // Erst nach dem setzen der Daten anzeigen
1363 xWindow
->setVisible( aComponentInfos
.bVisible
);
1365 if( !aComponentInfos
.bEnable
)
1366 xWindow
->setEnable( aComponentInfos
.bEnable
);
1368 xView
->setGraphics( xGraphics
);
1372 mbCreatingPeer
= sal_False
;
1376 Reference
< XWindowPeer
> UnoControl::getPeer() throw(RuntimeException
)
1378 ::osl::MutexGuard
aGuard( GetMutex() );
1382 sal_Bool
UnoControl::setModel( const Reference
< XControlModel
>& rxModel
) throw(RuntimeException
)
1384 ::osl::MutexGuard
aGuard( GetMutex() );
1386 Reference
< XMultiPropertySet
> xPropSet( mxModel
, UNO_QUERY
);
1388 // query for the XPropertiesChangeListener - our delegator is allowed to overwrite this interface
1389 Reference
< XPropertiesChangeListener
> xListener
;
1390 queryInterface( ::getCppuType( &xListener
) ) >>= xListener
;
1393 xPropSet
->removePropertiesChangeListener( xListener
);
1398 xPropSet
= Reference
< XMultiPropertySet
> ( mxModel
, UNO_QUERY
);
1401 Sequence
< ::rtl::OUString
> aNames
= lcl_ImplGetPropertyNames( xPropSet
);
1402 xPropSet
->addPropertiesChangeListener( aNames
, xListener
);
1405 return mxModel
.is();
1408 Reference
< XControlModel
> UnoControl::getModel( ) throw(RuntimeException
)
1413 Reference
< XView
> UnoControl::getView( ) throw(RuntimeException
)
1415 return static_cast< XView
* >( this );
1418 void UnoControl::setDesignMode( sal_Bool bOn
) throw(RuntimeException
)
1420 ModeChangeEvent aModeChangeEvent
;
1422 Reference
< XWindow
> xWindow
;
1424 ::osl::MutexGuard
aGuard( GetMutex() );
1425 if ( bOn
== mbDesignMode
)
1430 xWindow
= xWindow
.query( getPeer() );
1431 // dispose our current AccessibleContext, if we have one
1432 // (changing the design mode implies having a new implementation for this context,
1433 // so the old one must be declared DEFUNC)
1434 disposeAccessibleContext();
1436 aModeChangeEvent
.Source
= *this;
1437 aModeChangeEvent
.NewMode
= ::rtl::OUString::createFromAscii( mbDesignMode
? "design" : "alive" );
1440 // ajust the visibility of our window
1442 xWindow
->setVisible( !bOn
);
1444 // and notify our mode listeners
1445 maModeChangeListeners
.notifyEach( &XModeChangeListener::modeChanged
, aModeChangeEvent
);
1448 sal_Bool
UnoControl::isDesignMode( ) throw(RuntimeException
)
1450 return mbDesignMode
;
1453 sal_Bool
UnoControl::isTransparent( ) throw(RuntimeException
)
1459 ::rtl::OUString
UnoControl::getImplementationName( ) throw(RuntimeException
)
1461 DBG_ERROR( "This method should be overloaded!" );
1462 return ::rtl::OUString();
1465 sal_Bool
UnoControl::supportsService( const ::rtl::OUString
& rServiceName
) throw(RuntimeException
)
1467 ::osl::MutexGuard
aGuard( GetMutex() );
1469 Sequence
< ::rtl::OUString
> aSNL
= getSupportedServiceNames();
1470 const ::rtl::OUString
* pArray
= aSNL
.getConstArray();
1471 const ::rtl::OUString
* pArrayEnd
= aSNL
.getConstArray();
1472 for (; pArray
!= pArrayEnd
; ++pArray
)
1473 if( *pArray
== rServiceName
)
1476 return pArray
!= pArrayEnd
;
1479 Sequence
< ::rtl::OUString
> UnoControl::getSupportedServiceNames( ) throw(RuntimeException
)
1481 ::rtl::OUString
sName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControl" ) );
1482 return Sequence
< ::rtl::OUString
>( &sName
, 1 );
1485 // ------------------------------------------------------------------------
1486 Reference
< XAccessibleContext
> SAL_CALL
UnoControl::getAccessibleContext( ) throw (RuntimeException
)
1488 // creation of the context will certainly require the SolarMutex ...
1489 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
1490 ::osl::MutexGuard
aGuard( GetMutex() );
1492 Reference
< XAccessibleContext
> xCurrentContext( maAccessibleContext
.get(), UNO_QUERY
);
1493 if ( !xCurrentContext
.is() )
1495 if ( !mbDesignMode
)
1496 { // in alive mode, use the AccessibleContext of the peer
1497 Reference
< XAccessible
> xPeerAcc( getPeer(), UNO_QUERY
);
1498 if ( xPeerAcc
.is() )
1499 xCurrentContext
= xPeerAcc
->getAccessibleContext( );
1502 // in design mode, use a fallback
1503 xCurrentContext
= ::toolkit::OAccessibleControlContext::create( this );
1505 DBG_ASSERT( xCurrentContext
.is(), "UnoControl::getAccessibleContext: invalid context (invalid peer?)!" );
1506 maAccessibleContext
= xCurrentContext
;
1508 // get notified when the context is disposed
1509 Reference
< XComponent
> xContextComp( xCurrentContext
, UNO_QUERY
);
1510 if ( xContextComp
.is() )
1511 xContextComp
->addEventListener( this );
1512 // In an ideal world, this is not necessary - there the object would be released as soon as it has been
1513 // disposed, and thus our weak reference would be empty, too.
1514 // But 'til this ideal world comes (means 'til we do never have any refcount/lifetime bugs anymore), we
1515 // need to listen for disposal and reset our weak reference then.
1518 return xCurrentContext
;
1521 void SAL_CALL
UnoControl::addModeChangeListener( const Reference
< XModeChangeListener
>& _rxListener
) throw (RuntimeException
)
1523 ::osl::MutexGuard
aGuard( GetMutex() );
1524 maModeChangeListeners
.addInterface( _rxListener
);
1527 void SAL_CALL
UnoControl::removeModeChangeListener( const Reference
< XModeChangeListener
>& _rxListener
) throw (RuntimeException
)
1529 ::osl::MutexGuard
aGuard( GetMutex() );
1530 maModeChangeListeners
.removeInterface( _rxListener
);
1533 void SAL_CALL
UnoControl::addModeChangeApproveListener( const Reference
< XModeChangeApproveListener
>& ) throw (NoSupportException
, RuntimeException
)
1535 throw NoSupportException( );
1538 void SAL_CALL
UnoControl::removeModeChangeApproveListener( const Reference
< XModeChangeApproveListener
>& ) throw (NoSupportException
, RuntimeException
)
1540 throw NoSupportException( );