1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/awt/XControlContainer.hpp>
21 #include <com/sun/star/awt/WindowAttribute.hpp>
22 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
23 #include <com/sun/star/awt/PosSize.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/resource/XStringResourceResolver.hpp>
26 #include <toolkit/controls/unocontrol.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <cppuhelper/typeprovider.hxx>
30 #include <osl/mutex.hxx>
31 #include <tools/date.hxx>
32 #include <tools/debug.hxx>
33 #include <tools/diagnose_ex.h>
34 #include <vcl/svapp.hxx>
35 #include <vcl/wrkwin.hxx>
36 #include <comphelper/stl_types.hxx>
37 #include <comphelper/processfactory.hxx>
38 #include <toolkit/helper/property.hxx>
39 #include <toolkit/helper/servicenames.hxx>
40 #include <toolkit/awt/vclxwindow.hxx>
41 #include <toolkit/controls/accessiblecontrolcontext.hxx>
42 #include <comphelper/container.hxx>
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::awt
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::util
;
55 using ::com::sun::star::accessibility::XAccessibleContext
;
56 using ::com::sun::star::accessibility::XAccessible
;
58 struct LanguageDependentProp
60 const char* pPropName
;
61 sal_Int32 nPropNameLength
;
64 static const LanguageDependentProp aLanguageDependentProp
[] =
70 { "CurrencySymbol", 14 },
71 { "StringItemList", 14 },
75 static Sequence
< OUString
> lcl_ImplGetPropertyNames( const Reference
< XMultiPropertySet
> & rxModel
)
77 Sequence
< OUString
> aNames
;
78 Reference
< XPropertySetInfo
> xPSInf
= rxModel
->getPropertySetInfo();
79 DBG_ASSERT( xPSInf
.is(), "UpdateFromModel: No PropertySetInfo!" );
82 Sequence
< Property
> aProps
= xPSInf
->getProperties();
83 sal_Int32 nLen
= aProps
.getLength();
84 aNames
= Sequence
< OUString
>( nLen
);
85 OUString
* pNames
= aNames
.getArray();
86 const Property
* pProps
= aProps
.getConstArray();
87 for ( sal_Int32 n
= 0; n
< nLen
; ++n
, ++pProps
, ++pNames
)
88 *pNames
= pProps
->Name
;
93 // ====================================================
97 VCLXWindow
* m_pLockWindow
;
100 inline VclListenerLock( VCLXWindow
* _pLockWindow
)
101 :m_pLockWindow( _pLockWindow
)
104 m_pLockWindow
->suspendVclEventListening( );
106 inline ~VclListenerLock( )
109 m_pLockWindow
->resumeVclEventListening( );
113 VclListenerLock(); // never implemented
114 VclListenerLock( const VclListenerLock
& ); // never implemented
115 VclListenerLock
& operator=( const VclListenerLock
& ); // never implemented
118 typedef ::std::map
< OUString
, sal_Int32
> MapString2Int
;
119 struct UnoControl_Data
121 MapString2Int aSuspendedPropertyNotifications
;
122 /// true if and only if our model has a property ResourceResolver
123 bool bLocalizationSupport
;
126 :aSuspendedPropertyNotifications()
127 ,bLocalizationSupport( false )
132 // ----------------------------------------------------
134 // ----------------------------------------------------
135 DBG_NAME( UnoControl
)
136 UnoControl::UnoControl() :
137 maDisposeListeners( *this )
138 , maWindowListeners( *this )
139 , maFocusListeners( *this )
140 , maKeyListeners( *this )
141 , maMouseListeners( *this )
142 , maMouseMotionListeners( *this )
143 , maPaintListeners( *this )
144 , maModeChangeListeners( GetMutex() )
145 , mpData( new UnoControl_Data
)
147 DBG_CTOR( UnoControl
, NULL
);
148 mbDisposePeer
= sal_True
;
149 mbRefeshingPeer
= sal_False
;
150 mbCreatingPeer
= sal_False
;
151 mbCreatingCompatiblePeer
= sal_False
;
152 mbDesignMode
= sal_False
;
155 UnoControl::~UnoControl()
158 DBG_DTOR( UnoControl
, NULL
);
161 OUString
UnoControl::GetComponentServiceName()
166 Reference
< XWindowPeer
> UnoControl::ImplGetCompatiblePeer( sal_Bool bAcceptExistingPeer
)
168 DBG_ASSERT( !mbCreatingCompatiblePeer
, "ImplGetCompatiblePeer - rekursive?" );
170 mbCreatingCompatiblePeer
= sal_True
;
172 Reference
< XWindowPeer
> xCompatiblePeer
;
174 if ( bAcceptExistingPeer
)
175 xCompatiblePeer
= getPeer();
177 if ( !xCompatiblePeer
.is() )
179 // Create the pair as invisible
180 sal_Bool bVis
= maComponentInfos
.bVisible
;
182 maComponentInfos
.bVisible
= sal_False
;
184 Reference
< XWindowPeer
> xCurrentPeer
= getPeer();
187 // queryInterface ourself, to allow aggregation
188 Reference
< XControl
> xMe
;
189 OWeakAggObject::queryInterface( ::getCppuType( &xMe
) ) >>= xMe
;
191 Window
* pParentWindow( NULL
);
193 SolarMutexGuard aGuard
;
194 pParentWindow
= dynamic_cast< Window
* >( Application::GetDefaultDevice() );
195 ENSURE_OR_THROW( pParentWindow
!= NULL
, "could obtain a default parent window!" );
199 xMe
->createPeer( NULL
, pParentWindow
->GetComponentInterface( sal_True
) );
201 catch( const Exception
& )
203 mbCreatingCompatiblePeer
= sal_False
;
206 xCompatiblePeer
= getPeer();
207 setPeer( xCurrentPeer
);
209 if ( xCompatiblePeer
.is() && mxGraphics
.is() )
211 Reference
< XView
> xPeerView( xCompatiblePeer
, UNO_QUERY
);
212 if ( xPeerView
.is() )
213 xPeerView
->setGraphics( mxGraphics
);
217 maComponentInfos
.bVisible
= sal_True
;
220 mbCreatingCompatiblePeer
= sal_False
;
222 return xCompatiblePeer
;
225 bool UnoControl::ImplCheckLocalize( OUString
& _rPossiblyLocalizable
)
227 if ( !mpData
->bLocalizationSupport
228 || ( _rPossiblyLocalizable
.isEmpty() )
229 || ( _rPossiblyLocalizable
[0] != '&' )
230 // TODO: make this reasonable. At the moment, everything which by accident starts with a & is considered
231 // localizable, which is probably wrong.
237 Reference
< XPropertySet
> xPropSet( mxModel
, UNO_QUERY_THROW
);
238 Reference
< resource::XStringResourceResolver
> xStringResourceResolver(
239 xPropSet
->getPropertyValue( OUString( "ResourceResolver" ) ),
242 if ( xStringResourceResolver
.is() )
244 OUString
aLocalizationKey( _rPossiblyLocalizable
.copy( 1 ) );
245 _rPossiblyLocalizable
= xStringResourceResolver
->resolveString( aLocalizationKey
);
249 catch( const Exception
& )
251 DBG_UNHANDLED_EXCEPTION();
256 void UnoControl::ImplSetPeerProperty( const OUString
& rPropName
, const Any
& rVal
)
258 // since a change made in propertiesChange, we can't be sure that this is called with an valid getPeer(),
259 // this assumption may be false in some (seldom) multi-threading scenarios (cause propertiesChange
260 // releases our mutex before calling here in)
261 // That's why this additional check
263 if ( mxVclWindowPeer
.is() )
265 Any
aConvertedValue( rVal
);
267 if ( mpData
->bLocalizationSupport
)
269 // We now support a mapping for language dependent properties. This is the
270 // central method to implement it.
271 if (( rPropName
.equalsAsciiL( "Text", 4 )) ||
272 ( rPropName
.equalsAsciiL( "Label", 5 )) ||
273 ( rPropName
.equalsAsciiL( "Title", 5 )) ||
274 ( rPropName
.equalsAsciiL( "HelpText", 8 )) ||
275 ( rPropName
.equalsAsciiL( "CurrencySymbol", 14 )) ||
276 ( rPropName
.equalsAsciiL( "StringItemList", 14 )) )
279 uno::Sequence
< OUString
> aSeqValue
;
280 if ( aConvertedValue
>>= aValue
)
282 if ( ImplCheckLocalize( aValue
) )
283 aConvertedValue
<<= aValue
;
285 else if ( aConvertedValue
>>= aSeqValue
)
287 for ( sal_Int32 i
= 0; i
< aSeqValue
.getLength(); i
++ )
288 ImplCheckLocalize( aSeqValue
[i
] );
289 aConvertedValue
<<= aSeqValue
;
294 mxVclWindowPeer
->setProperty( rPropName
, aConvertedValue
);
298 void UnoControl::PrepareWindowDescriptor( WindowDescriptor
& )
302 Reference
< XWindow
> UnoControl::getParentPeer() const
304 Reference
< XWindow
> xPeer
;
307 Reference
< XControl
> xContComp( mxContext
, UNO_QUERY
);
308 if ( xContComp
.is() )
310 Reference
< XWindowPeer
> xP
= xContComp
->getPeer();
312 xPeer
.set( xP
, UNO_QUERY
);
318 void UnoControl::updateFromModel()
320 // Read default properties and hand over to peer
323 Reference
< XMultiPropertySet
> xPropSet( mxModel
, UNO_QUERY
);
326 Sequence
< OUString
> aNames
= lcl_ImplGetPropertyNames( xPropSet
);
327 xPropSet
->firePropertiesChangeEvent( aNames
, this );
334 IMPL_IMPLEMENTATION_ID( UnoControl
)
336 void UnoControl::disposeAccessibleContext()
338 Reference
< XComponent
> xContextComp( maAccessibleContext
.get(), UNO_QUERY
);
339 if ( xContextComp
.is() )
341 maAccessibleContext
= NULL
;
344 xContextComp
->removeEventListener( this );
345 xContextComp
->dispose();
347 catch( const Exception
& )
349 OSL_FAIL( "UnoControl::disposeAccessibleContext: could not dispose my AccessibleContext!" );
354 void UnoControl::dispose( ) throw(RuntimeException
)
356 Reference
< XWindowPeer
> xPeer
;
358 ::osl::MutexGuard
aGuard( GetMutex() );
370 // dispose and release our AccessibleContext
371 disposeAccessibleContext();
373 EventObject aDisposeEvent
;
374 aDisposeEvent
.Source
= static_cast< XAggregation
* >( this );
376 maDisposeListeners
.disposeAndClear( aDisposeEvent
);
377 maWindowListeners
.disposeAndClear( aDisposeEvent
);
378 maFocusListeners
.disposeAndClear( aDisposeEvent
);
379 maKeyListeners
.disposeAndClear( aDisposeEvent
);
380 maMouseListeners
.disposeAndClear( aDisposeEvent
);
381 maMouseMotionListeners
.disposeAndClear( aDisposeEvent
);
382 maPaintListeners
.disposeAndClear( aDisposeEvent
);
383 maModeChangeListeners
.disposeAndClear( aDisposeEvent
);
385 // release Model again
386 setModel( Reference
< XControlModel
> () );
387 setContext( Reference
< XInterface
> () );
390 void UnoControl::addEventListener( const Reference
< XEventListener
>& rxListener
) throw(RuntimeException
)
392 ::osl::MutexGuard
aGuard( GetMutex() );
394 maDisposeListeners
.addInterface( rxListener
);
397 void UnoControl::removeEventListener( const Reference
< XEventListener
>& rxListener
) throw(RuntimeException
)
399 ::osl::MutexGuard
aGuard( GetMutex() );
401 maDisposeListeners
.removeInterface( rxListener
);
404 sal_Bool
UnoControl::requiresNewPeer( const OUString
& /* _rPropertyName */ ) const
409 // XPropertiesChangeListener
410 void UnoControl::propertiesChange( const Sequence
< PropertyChangeEvent
>& rEvents
) throw(RuntimeException
)
412 Sequence
< PropertyChangeEvent
> aEvents( rEvents
);
414 ::osl::MutexGuard
aGuard( GetMutex() );
416 if ( !mpData
->aSuspendedPropertyNotifications
.empty() )
418 // strip the property which we are currently updating (somewhere up the stack)
419 PropertyChangeEvent
* pEvents
= aEvents
.getArray();
420 PropertyChangeEvent
* pEventsEnd
= pEvents
+ aEvents
.getLength();
421 for ( ; pEvents
< pEventsEnd
; )
422 if ( mpData
->aSuspendedPropertyNotifications
.find( pEvents
->PropertyName
) != mpData
->aSuspendedPropertyNotifications
.end() )
424 if ( pEvents
!= pEventsEnd
)
425 ::std::copy( pEvents
+ 1, pEventsEnd
, pEvents
);
430 aEvents
.realloc( pEventsEnd
- aEvents
.getConstArray() );
432 if ( !aEvents
.getLength() )
437 ImplModelPropertiesChanged( aEvents
);
440 void UnoControl::ImplLockPropertyChangeNotification( const OUString
& rPropertyName
, bool bLock
)
442 MapString2Int::iterator pos
= mpData
->aSuspendedPropertyNotifications
.find( rPropertyName
);
445 if ( pos
== mpData
->aSuspendedPropertyNotifications
.end() )
446 pos
= mpData
->aSuspendedPropertyNotifications
.insert( MapString2Int::value_type( rPropertyName
, 0 ) ).first
;
451 OSL_ENSURE( pos
!= mpData
->aSuspendedPropertyNotifications
.end(), "UnoControl::ImplLockPropertyChangeNotification: property not locked!" );
452 if ( pos
!= mpData
->aSuspendedPropertyNotifications
.end() )
454 OSL_ENSURE( pos
->second
> 0, "UnoControl::ImplLockPropertyChangeNotification: invalid suspension counter!" );
455 if ( 0 == --pos
->second
)
456 mpData
->aSuspendedPropertyNotifications
.erase( pos
);
461 void UnoControl::ImplLockPropertyChangeNotifications( const Sequence
< OUString
>& rPropertyNames
, bool bLock
)
463 for ( const OUString
* pPropertyName
= rPropertyNames
.getConstArray();
464 pPropertyName
!= rPropertyNames
.getConstArray() + rPropertyNames
.getLength();
467 ImplLockPropertyChangeNotification( *pPropertyName
, bLock
);
470 void UnoControl::ImplModelPropertiesChanged( const Sequence
< PropertyChangeEvent
>& rEvents
)
472 ::osl::ClearableGuard
< ::osl::Mutex
> aGuard( GetMutex() );
476 std::vector
< PropertyValue
> aPeerPropertiesToSet
;
477 sal_Int32 nIndependentPos
= 0;
478 bool bResourceResolverSet( false );
479 // position where to insert the independent properties into aPeerPropertiesToSet,
480 // dependent ones are inserted at the end of the vector
482 sal_Bool bNeedNewPeer
= sal_False
;
483 // some properties require a re-creation of the peer, 'cause they can't be changed on the fly
485 Reference
< XControlModel
> xOwnModel( getModel(), UNO_QUERY
);
486 // our own model for comparison
487 Reference
< XPropertySet
> xPS( xOwnModel
, UNO_QUERY
);
488 Reference
< XPropertySetInfo
> xPSI( xPS
->getPropertySetInfo(), UNO_QUERY
);
489 OSL_ENSURE( xPSI
.is(), "UnoControl::ImplModelPropertiesChanged: should have property set meta data!" );
491 const PropertyChangeEvent
* pEvents
= rEvents
.getConstArray();
493 sal_Int32 nLen
= rEvents
.getLength();
494 aPeerPropertiesToSet
.reserve(nLen
);
496 for( sal_Int32 i
= 0; i
< nLen
; ++i
, ++pEvents
)
498 Reference
< XControlModel
> xModel( pEvents
->Source
, UNO_QUERY
);
499 sal_Bool bOwnModel
= xModel
.get() == xOwnModel
.get();
503 // Detect changes on our resource resolver which invalidates
504 // automatically some language dependent properties.
505 if ( pEvents
->PropertyName
.equalsAsciiL( "ResourceResolver", 16 ))
507 Reference
< resource::XStringResourceResolver
> xStrResolver
;
508 if ( pEvents
->NewValue
>>= xStrResolver
)
509 bResourceResolverSet
= xStrResolver
.is();
512 sal_uInt16 nPType
= GetPropertyId( pEvents
->PropertyName
);
513 if ( mbDesignMode
&& mbDisposePeer
&& !mbRefeshingPeer
&& !mbCreatingPeer
)
515 // if we're in design mode, then some properties can change which
516 // require creating a *new* peer (since these properties cannot
517 // be switched at existing peers)
519 bNeedNewPeer
= ( nPType
== BASEPROPERTY_BORDER
)
520 || ( nPType
== BASEPROPERTY_MULTILINE
)
521 || ( nPType
== BASEPROPERTY_DROPDOWN
)
522 || ( nPType
== BASEPROPERTY_HSCROLL
)
523 || ( nPType
== BASEPROPERTY_VSCROLL
)
524 || ( nPType
== BASEPROPERTY_AUTOHSCROLL
)
525 || ( nPType
== BASEPROPERTY_AUTOVSCROLL
)
526 || ( nPType
== BASEPROPERTY_ORIENTATION
)
527 || ( nPType
== BASEPROPERTY_SPIN
)
528 || ( nPType
== BASEPROPERTY_ALIGN
)
529 || ( nPType
== BASEPROPERTY_PAINTTRANSPARENT
);
531 bNeedNewPeer
= requiresNewPeer( pEvents
->PropertyName
);
537 if ( nPType
&& ( nLen
> 1 ) && DoesDependOnOthers( nPType
) )
539 // Add properties with dependencies on other properties last
540 // since they're dependent on properties added later (such as
541 // VALUE dependency on VALUEMIN/MAX)
542 aPeerPropertiesToSet
.push_back(PropertyValue(pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
));
546 if ( bResourceResolverSet
)
548 // The resource resolver property change should be one of the first ones.
549 // All language dependent properties are dependent on this property.
550 // As BASEPROPERTY_NATIVE_WIDGET_LOOK is not dependent on resource
551 // resolver. We don't need to handle a special order for these two props.
552 aPeerPropertiesToSet
.insert(
553 aPeerPropertiesToSet
.begin(),
554 PropertyValue( pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
) );
557 else if ( nPType
== BASEPROPERTY_NATIVE_WIDGET_LOOK
)
559 // since *a lot* of other properties might be overruled by this one, we need
560 // a special handling:
561 // NativeWidgetLook needs to be set first: If it is set to ON, all other
562 // properties describing the look (e.g. BackgroundColor) are ignored, anyway.
563 // If it is switched OFF, then we need to do it first because else it will
564 // overrule other look-related properties, and re-initialize them from system
566 aPeerPropertiesToSet
.insert(
567 aPeerPropertiesToSet
.begin(),
568 PropertyValue( pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
) );
573 aPeerPropertiesToSet
.insert(aPeerPropertiesToSet
.begin() + nIndependentPos
,
574 PropertyValue(pEvents
->PropertyName
, 0, pEvents
->NewValue
, PropertyState_DIRECT_VALUE
));
580 Reference
< XWindow
> xParent
= getParentPeer();
581 Reference
< XControl
> xThis( (XAggregation
*)(::cppu::OWeakAggObject
*)this, UNO_QUERY
);
582 // call createPeer via a interface got from queryInterface, so the aggregating class can intercept it
584 DBG_ASSERT( !bNeedNewPeer
|| xParent
.is(), "Need new peer, but don't have a parent!" );
586 // Check if we have to update language dependent properties
587 if ( !bNeedNewPeer
&& bResourceResolverSet
)
589 // Add language dependent properties into the peer property set.
590 // Our resource resolver has been changed and we must be sure
591 // that language dependent props use the new resolver.
592 const LanguageDependentProp
* pLangDepProp
= aLanguageDependentProp
;
593 while ( pLangDepProp
->pPropName
!= 0 )
595 bool bMustBeInserted( true );
596 for ( sal_uInt32 i
= 0; i
< aPeerPropertiesToSet
.size(); i
++ )
598 if ( aPeerPropertiesToSet
[i
].Name
.equalsAsciiL(
599 pLangDepProp
->pPropName
, pLangDepProp
->nPropNameLength
))
601 bMustBeInserted
= false;
606 if ( bMustBeInserted
)
608 // Add language dependent props at the end
609 OUString
aPropName( OUString::createFromAscii( pLangDepProp
->pPropName
));
610 if ( xPSI
.is() && xPSI
->hasPropertyByName( aPropName
) )
612 aPeerPropertiesToSet
.push_back(
613 PropertyValue( aPropName
, 0, xPS
->getPropertyValue( aPropName
), PropertyState_DIRECT_VALUE
) );
622 // clear the guard before creating a new peer - as usual, our peer implementations use the SolarMutex
624 if (bNeedNewPeer
&& xParent
.is())
626 SolarMutexGuard aVclGuard
;
627 // and now this is the final withdrawal:
628 // I have no other idea than locking the SolarMutex here ....
629 // I really hate the fact that VCL is not theadsafe ....
631 // Doesn't work for Container!
632 getPeer()->dispose();
634 mxVclWindowPeer
= NULL
;
635 mbRefeshingPeer
= sal_True
;
636 Reference
< XWindowPeer
> xP( xParent
, UNO_QUERY
);
637 xThis
->createPeer( Reference
< XToolkit
> (), xP
);
638 mbRefeshingPeer
= sal_False
;
639 aPeerPropertiesToSet
.clear();
642 // lock the multiplexing of VCL events to our UNO listeners
643 // this is for compatibility reasons: in OOo 1.0.x, changes which were done at the
644 // model did not cause the listeners of the controls/peers to be called
645 // Since the implementations for the listeners changed a lot towards 1.1, this
646 // would not be the case anymore, if we would not do this listener-lock below
648 Window
* pVclPeer
= VCLUnoHelper::GetWindow( getPeer() );
649 VCLXWindow
* pPeer
= pVclPeer
? pVclPeer
->GetWindowPeer() : NULL
;
650 VclListenerLock
aNoVclEventMultiplexing( pPeer
);
652 // setting peer properties may result in an attemp to acquire the solar mutex, 'cause the peers
653 // usually don't have an own mutex but use the SolarMutex instead.
654 // To prevent deadlocks resulting from this, we do this without our own mutex locked
655 std::vector
< PropertyValue
>::iterator aEnd
= aPeerPropertiesToSet
.end();
656 for ( std::vector
< PropertyValue
>::iterator aLoop
= aPeerPropertiesToSet
.begin();
661 ImplSetPeerProperty( aLoop
->Name
, aLoop
->Value
);
666 void UnoControl::disposing( const EventObject
& rEvt
) throw(RuntimeException
)
668 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
669 // do not compare differing types in case of multible inheritance
671 if ( maAccessibleContext
.get() == rEvt
.Source
)
673 // just in case the context is disposed, but not released - ensure that we do not re-use it in the future
674 maAccessibleContext
= NULL
;
676 else if( mxModel
.get() == Reference
< XControlModel
>(rEvt
.Source
,UNO_QUERY
).get() )
678 // #62337# if the model dies, it does not make sense for us to live ...
679 Reference
< XControl
> xThis
= this;
684 DBG_ASSERT( !mxModel
.is(), "UnoControl::disposing: invalid dispose behaviour!" );
690 void SAL_CALL
UnoControl::setOutputSize( const awt::Size
& aSize
) throw (RuntimeException
)
692 Reference
< XWindow2
> xPeerWindow
;
694 ::osl::MutexGuard
aGuard( GetMutex() );
695 xPeerWindow
= xPeerWindow
.query( getPeer() );
698 if ( xPeerWindow
.is() )
699 xPeerWindow
->setOutputSize( aSize
);
704 template < typename RETVALTYPE
>
705 RETVALTYPE
lcl_askPeer( const uno::Reference
< awt::XWindowPeer
>& _rxPeer
, RETVALTYPE (SAL_CALL
XWindow2::*_pMethod
)(), RETVALTYPE _aDefault
)
707 RETVALTYPE
aReturn( _aDefault
);
709 Reference
< XWindow2
> xPeerWindow( _rxPeer
, UNO_QUERY
);
710 if ( xPeerWindow
.is() )
711 aReturn
= (xPeerWindow
.get()->*_pMethod
)();
717 awt::Size SAL_CALL
UnoControl::getOutputSize( ) throw (RuntimeException
)
719 return lcl_askPeer( getPeer(), &XWindow2::getOutputSize
, awt::Size() );
722 ::sal_Bool SAL_CALL
UnoControl::isVisible( ) throw (RuntimeException
)
724 return lcl_askPeer( getPeer(), &XWindow2::isVisible
, maComponentInfos
.bVisible
);
727 ::sal_Bool SAL_CALL
UnoControl::isActive( ) throw (RuntimeException
)
729 return lcl_askPeer( getPeer(), &XWindow2::isActive
, sal_False
);
732 ::sal_Bool SAL_CALL
UnoControl::isEnabled( ) throw (RuntimeException
)
734 return lcl_askPeer( getPeer(), &XWindow2::isEnabled
, maComponentInfos
.bEnable
);
737 ::sal_Bool SAL_CALL
UnoControl::hasFocus( ) throw (RuntimeException
)
739 return lcl_askPeer( getPeer(), &XWindow2::hasFocus
, sal_False
);
743 void UnoControl::setPosSize( sal_Int32 X
, sal_Int32 Y
, sal_Int32 Width
, sal_Int32 Height
, sal_Int16 Flags
) throw(RuntimeException
)
745 Reference
< XWindow
> xWindow
;
747 ::osl::MutexGuard
aGuard( GetMutex() );
749 if ( Flags
& awt::PosSize::X
)
750 maComponentInfos
.nX
= X
;
751 if ( Flags
& awt::PosSize::Y
)
752 maComponentInfos
.nY
= Y
;
753 if ( Flags
& awt::PosSize::WIDTH
)
754 maComponentInfos
.nWidth
= Width
;
755 if ( Flags
& awt::PosSize::HEIGHT
)
756 maComponentInfos
.nHeight
= Height
;
757 maComponentInfos
.nFlags
|= Flags
;
759 xWindow
= xWindow
.query( getPeer() );
763 xWindow
->setPosSize( X
, Y
, Width
, Height
, Flags
);
766 awt::Rectangle
UnoControl::getPosSize( ) throw(RuntimeException
)
768 awt::Rectangle
aRect( maComponentInfos
.nX
, maComponentInfos
.nY
, maComponentInfos
.nWidth
, maComponentInfos
.nHeight
);
769 Reference
< XWindow
> xWindow
;
772 ::osl::MutexGuard
aGuard( GetMutex() );
773 xWindow
= xWindow
.query( getPeer() );
777 aRect
= xWindow
->getPosSize();
781 void UnoControl::setVisible( sal_Bool bVisible
) throw(RuntimeException
)
783 Reference
< XWindow
> xWindow
;
785 ::osl::MutexGuard
aGuard( GetMutex() );
787 // Visible status is handled by View
788 maComponentInfos
.bVisible
= bVisible
;
789 xWindow
= xWindow
.query( getPeer() );
792 xWindow
->setVisible( bVisible
);
795 void UnoControl::setEnable( sal_Bool bEnable
) throw(RuntimeException
)
797 Reference
< XWindow
> xWindow
;
799 ::osl::MutexGuard
aGuard( GetMutex() );
801 // Enable status is handled by View
802 maComponentInfos
.bEnable
= bEnable
;
803 xWindow
= xWindow
.query( getPeer() );
806 xWindow
->setEnable( bEnable
);
809 void UnoControl::setFocus( ) throw(RuntimeException
)
811 Reference
< XWindow
> xWindow
;
813 ::osl::MutexGuard
aGuard( GetMutex() );
814 xWindow
= xWindow
.query( getPeer() );
820 void UnoControl::addWindowListener( const Reference
< XWindowListener
>& rxListener
) throw(RuntimeException
)
822 Reference
< XWindow
> xPeerWindow
;
824 ::osl::MutexGuard
aGuard( GetMutex() );
825 maWindowListeners
.addInterface( rxListener
);
826 if ( maWindowListeners
.getLength() == 1 )
827 xPeerWindow
= xPeerWindow
.query( getPeer() );
829 if ( xPeerWindow
.is() )
830 xPeerWindow
->addWindowListener( &maWindowListeners
);
833 void UnoControl::removeWindowListener( const Reference
< XWindowListener
>& rxListener
) throw(RuntimeException
)
835 Reference
< XWindow
> xPeerWindow
;
837 ::osl::MutexGuard
aGuard( GetMutex() );
838 if ( maWindowListeners
.getLength() == 1 )
839 xPeerWindow
= xPeerWindow
.query( getPeer() );
840 maWindowListeners
.removeInterface( rxListener
);
842 if ( xPeerWindow
.is() )
843 xPeerWindow
->removeWindowListener( &maWindowListeners
);
846 void UnoControl::addFocusListener( const Reference
< XFocusListener
>& rxListener
) throw(RuntimeException
)
848 Reference
< XWindow
> xPeerWindow
;
850 ::osl::MutexGuard
aGuard( GetMutex() );
851 maFocusListeners
.addInterface( rxListener
);
852 if ( maFocusListeners
.getLength() == 1 )
853 xPeerWindow
= xPeerWindow
.query( getPeer() );
855 if ( xPeerWindow
.is() )
856 xPeerWindow
->addFocusListener( &maFocusListeners
);
859 void UnoControl::removeFocusListener( const Reference
< XFocusListener
>& rxListener
) throw(RuntimeException
)
861 Reference
< XWindow
> xPeerWindow
;
863 ::osl::MutexGuard
aGuard( GetMutex() );
864 if ( maFocusListeners
.getLength() == 1 )
865 xPeerWindow
= xPeerWindow
.query( getPeer() );
866 maFocusListeners
.removeInterface( rxListener
);
868 if ( xPeerWindow
.is() )
869 xPeerWindow
->removeFocusListener( &maFocusListeners
);
872 void UnoControl::addKeyListener( const Reference
< XKeyListener
>& rxListener
) throw(RuntimeException
)
874 Reference
< XWindow
> xPeerWindow
;
876 ::osl::MutexGuard
aGuard( GetMutex() );
877 maKeyListeners
.addInterface( rxListener
);
878 if ( maKeyListeners
.getLength() == 1 )
879 xPeerWindow
= xPeerWindow
.query( getPeer() );
881 if ( xPeerWindow
.is() )
882 xPeerWindow
->addKeyListener( &maKeyListeners
);
885 void UnoControl::removeKeyListener( const Reference
< XKeyListener
>& rxListener
) throw(RuntimeException
)
887 Reference
< XWindow
> xPeerWindow
;
889 ::osl::MutexGuard
aGuard( GetMutex() );
890 if ( maKeyListeners
.getLength() == 1 )
891 xPeerWindow
= xPeerWindow
.query( getPeer() );
892 maKeyListeners
.removeInterface( rxListener
);
894 if ( xPeerWindow
.is() )
895 xPeerWindow
->removeKeyListener( &maKeyListeners
);
898 void UnoControl::addMouseListener( const Reference
< XMouseListener
>& rxListener
) throw(RuntimeException
)
900 Reference
< XWindow
> xPeerWindow
;
902 ::osl::MutexGuard
aGuard( GetMutex() );
903 maMouseListeners
.addInterface( rxListener
);
904 if ( maMouseListeners
.getLength() == 1 )
905 xPeerWindow
= xPeerWindow
.query( getPeer() );
907 if ( xPeerWindow
.is() )
908 xPeerWindow
->addMouseListener( &maMouseListeners
);
911 void UnoControl::removeMouseListener( const Reference
< XMouseListener
>& rxListener
) throw(RuntimeException
)
913 Reference
< XWindow
> xPeerWindow
;
915 ::osl::MutexGuard
aGuard( GetMutex() );
916 if ( maMouseListeners
.getLength() == 1 )
917 xPeerWindow
= xPeerWindow
.query( getPeer() );
918 maMouseListeners
.removeInterface( rxListener
);
920 if ( xPeerWindow
.is() )
921 xPeerWindow
->removeMouseListener( &maMouseListeners
);
924 void UnoControl::addMouseMotionListener( const Reference
< XMouseMotionListener
>& rxListener
) throw(RuntimeException
)
926 Reference
< XWindow
> xPeerWindow
;
928 ::osl::MutexGuard
aGuard( GetMutex() );
929 maMouseMotionListeners
.addInterface( rxListener
);
930 if ( maMouseMotionListeners
.getLength() == 1 )
931 xPeerWindow
= xPeerWindow
.query( getPeer() );
933 if ( xPeerWindow
.is() )
934 xPeerWindow
->addMouseMotionListener( &maMouseMotionListeners
);
937 void UnoControl::removeMouseMotionListener( const Reference
< XMouseMotionListener
>& rxListener
) throw(RuntimeException
)
939 Reference
< XWindow
> xPeerWindow
;
941 ::osl::MutexGuard
aGuard( GetMutex() );
942 if ( maMouseMotionListeners
.getLength() == 1 )
943 xPeerWindow
= xPeerWindow
.query( getPeer() );
944 maMouseMotionListeners
.removeInterface( rxListener
);
946 if ( xPeerWindow
.is() )
947 xPeerWindow
->removeMouseMotionListener( &maMouseMotionListeners
);
950 void UnoControl::addPaintListener( const Reference
< XPaintListener
>& rxListener
) throw(RuntimeException
)
952 Reference
< XWindow
> xPeerWindow
;
954 ::osl::MutexGuard
aGuard( GetMutex() );
955 maPaintListeners
.addInterface( rxListener
);
956 if ( maPaintListeners
.getLength() == 1 )
957 xPeerWindow
= xPeerWindow
.query( getPeer() );
959 if ( xPeerWindow
.is() )
960 xPeerWindow
->addPaintListener( &maPaintListeners
);
963 void UnoControl::removePaintListener( const Reference
< XPaintListener
>& rxListener
) throw(RuntimeException
)
965 Reference
< XWindow
> xPeerWindow
;
967 ::osl::MutexGuard
aGuard( GetMutex() );
968 if ( maPaintListeners
.getLength() == 1 )
969 xPeerWindow
= xPeerWindow
.query( getPeer() );
970 maPaintListeners
.removeInterface( rxListener
);
972 if ( xPeerWindow
.is() )
973 xPeerWindow
->removePaintListener( &maPaintListeners
);
977 sal_Bool
UnoControl::setGraphics( const Reference
< XGraphics
>& rDevice
) throw(RuntimeException
)
979 Reference
< XView
> xView
;
981 ::osl::MutexGuard
aGuard( GetMutex() );
983 mxGraphics
= rDevice
;
984 xView
= xView
.query( getPeer() );
986 return xView
.is() ? xView
->setGraphics( rDevice
) : sal_True
;
989 Reference
< XGraphics
> UnoControl::getGraphics( ) throw(RuntimeException
)
994 awt::Size
UnoControl::getSize( ) throw(RuntimeException
)
996 ::osl::MutexGuard
aGuard( GetMutex() );
997 return awt::Size( maComponentInfos
.nWidth
, maComponentInfos
.nHeight
);
1000 void UnoControl::draw( sal_Int32 x
, sal_Int32 y
) throw(RuntimeException
)
1002 Reference
< XWindowPeer
> xDrawPeer
;
1003 Reference
< XView
> xDrawPeerView
;
1005 bool bDisposeDrawPeer( false );
1007 ::osl::MutexGuard
aGuard( GetMutex() );
1009 xDrawPeer
= ImplGetCompatiblePeer( sal_True
);
1010 bDisposeDrawPeer
= xDrawPeer
.is() && ( xDrawPeer
!= getPeer() );
1012 xDrawPeerView
.set( xDrawPeer
, UNO_QUERY
);
1013 DBG_ASSERT( xDrawPeerView
.is(), "UnoControl::draw: no peer!" );
1016 if ( xDrawPeerView
.is() )
1018 Reference
< XVclWindowPeer
> xWindowPeer
;
1019 xWindowPeer
.set( xDrawPeer
, UNO_QUERY
);
1020 if ( xWindowPeer
.is() )
1021 xWindowPeer
->setDesignMode( mbDesignMode
);
1022 xDrawPeerView
->draw( x
, y
);
1025 if ( bDisposeDrawPeer
)
1026 xDrawPeer
->dispose();
1029 void UnoControl::setZoom( float fZoomX
, float fZoomY
) throw(RuntimeException
)
1031 Reference
< XView
> xView
;
1033 ::osl::MutexGuard
aGuard( GetMutex() );
1035 maComponentInfos
.nZoomX
= fZoomX
;
1036 maComponentInfos
.nZoomY
= fZoomY
;
1038 xView
= xView
.query( getPeer() );
1041 xView
->setZoom( fZoomX
, fZoomY
);
1045 void UnoControl::setContext( const Reference
< XInterface
>& rxContext
) throw(RuntimeException
)
1047 ::osl::MutexGuard
aGuard( GetMutex() );
1049 mxContext
= rxContext
;
1052 Reference
< XInterface
> UnoControl::getContext( ) throw(RuntimeException
)
1054 ::osl::MutexGuard
aGuard( GetMutex() );
1059 void UnoControl::peerCreated()
1061 Reference
< XWindow
> xWindow( getPeer(), UNO_QUERY
);
1062 if ( !xWindow
.is() )
1065 if ( maWindowListeners
.getLength() )
1066 xWindow
->addWindowListener( &maWindowListeners
);
1068 if ( maFocusListeners
.getLength() )
1069 xWindow
->addFocusListener( &maFocusListeners
);
1071 if ( maKeyListeners
.getLength() )
1072 xWindow
->addKeyListener( &maKeyListeners
);
1074 if ( maMouseListeners
.getLength() )
1075 xWindow
->addMouseListener( &maMouseListeners
);
1077 if ( maMouseMotionListeners
.getLength() )
1078 xWindow
->addMouseMotionListener( &maMouseMotionListeners
);
1080 if ( maPaintListeners
.getLength() )
1081 xWindow
->addPaintListener( &maPaintListeners
);
1084 void UnoControl::createPeer( const Reference
< XToolkit
>& rxToolkit
, const Reference
< XWindowPeer
>& rParentPeer
) throw(RuntimeException
)
1086 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
1087 if ( !mxModel
.is() )
1089 RuntimeException aException
;
1090 aException
.Message
= OUString("createPeer: no model!");
1091 aException
.Context
= (XAggregation
*)(::cppu::OWeakAggObject
*)this;
1092 throw( aException
);
1095 if( !getPeer().is() )
1097 mbCreatingPeer
= sal_True
;
1100 Reference
< XToolkit
> xToolkit
= rxToolkit
;
1101 if( rParentPeer
.is() && mxContext
.is() )
1104 if ( !xToolkit
.is() )
1105 xToolkit
= rParentPeer
->getToolkit();
1106 Any aAny
= OWeakAggObject::queryInterface( ::getCppuType((const Reference
< XControlContainer
>*)0) );
1107 Reference
< XControlContainer
> xC
;
1111 eType
= WindowClass_CONTAINER
;
1113 eType
= WindowClass_SIMPLE
;
1116 { // This is only correct for Top Window
1117 if( rParentPeer
.is() )
1119 if ( !xToolkit
.is() )
1120 xToolkit
= rParentPeer
->getToolkit();
1121 eType
= WindowClass_CONTAINER
;
1125 if ( !xToolkit
.is() )
1126 xToolkit
= VCLUnoHelper::CreateToolkit();
1127 eType
= WindowClass_TOP
;
1130 WindowDescriptor aDescr
;
1131 aDescr
.Type
= eType
;
1132 aDescr
.WindowServiceName
= GetComponentServiceName();
1133 aDescr
.Parent
= rParentPeer
;
1134 aDescr
.Bounds
= getPosSize();
1135 aDescr
.WindowAttributes
= 0;
1138 Reference
< XPropertySet
> xPSet( mxModel
, UNO_QUERY
);
1139 Reference
< XPropertySetInfo
> xInfo
= xPSet
->getPropertySetInfo();
1142 OUString aPropName
= GetPropertyName( BASEPROPERTY_BORDER
);
1143 if ( xInfo
->hasPropertyByName( aPropName
) )
1145 aVal
= xPSet
->getPropertyValue( aPropName
);
1146 sal_Int16 n
= sal_Int16();
1150 aDescr
.WindowAttributes
|= WindowAttribute::BORDER
;
1152 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::NOBORDER
;
1156 // DESKTOP_AS_PARENT
1157 if ( aDescr
.Type
== WindowClass_TOP
)
1159 aPropName
= GetPropertyName( BASEPROPERTY_DESKTOP_AS_PARENT
);
1160 if ( xInfo
->hasPropertyByName( aPropName
) )
1162 aVal
= xPSet
->getPropertyValue( aPropName
);
1163 sal_Bool b
= sal_Bool();
1164 if ( ( aVal
>>= b
) && b
)
1165 aDescr
.ParentIndex
= -1;
1169 aPropName
= GetPropertyName( BASEPROPERTY_MOVEABLE
);
1170 if ( xInfo
->hasPropertyByName( aPropName
) )
1172 aVal
= xPSet
->getPropertyValue( aPropName
);
1173 sal_Bool b
= sal_Bool();
1174 if ( ( aVal
>>= b
) && b
)
1175 aDescr
.WindowAttributes
|= WindowAttribute::MOVEABLE
;
1179 aPropName
= GetPropertyName( BASEPROPERTY_CLOSEABLE
);
1180 if ( xInfo
->hasPropertyByName( aPropName
) )
1182 aVal
= xPSet
->getPropertyValue( aPropName
);
1183 sal_Bool b
= sal_Bool();
1184 if ( ( aVal
>>= b
) && b
)
1185 aDescr
.WindowAttributes
|= WindowAttribute::CLOSEABLE
;
1189 aPropName
= GetPropertyName( BASEPROPERTY_DROPDOWN
);
1190 if ( xInfo
->hasPropertyByName( aPropName
) )
1192 aVal
= xPSet
->getPropertyValue( aPropName
);
1193 sal_Bool b
= sal_Bool();
1194 if ( ( aVal
>>= b
) && b
)
1195 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::DROPDOWN
;
1199 aPropName
= GetPropertyName( BASEPROPERTY_SPIN
);
1200 if ( xInfo
->hasPropertyByName( aPropName
) )
1202 aVal
= xPSet
->getPropertyValue( aPropName
);
1203 sal_Bool b
= sal_Bool();
1204 if ( ( aVal
>>= b
) && b
)
1205 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::SPIN
;
1209 aPropName
= GetPropertyName( BASEPROPERTY_HSCROLL
);
1210 if ( xInfo
->hasPropertyByName( aPropName
) )
1212 aVal
= xPSet
->getPropertyValue( aPropName
);
1213 sal_Bool b
= sal_Bool();
1214 if ( ( aVal
>>= b
) && b
)
1215 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::HSCROLL
;
1219 aPropName
= GetPropertyName( BASEPROPERTY_VSCROLL
);
1220 if ( xInfo
->hasPropertyByName( aPropName
) )
1222 aVal
= xPSet
->getPropertyValue( aPropName
);
1223 sal_Bool b
= sal_Bool();
1224 if ( ( aVal
>>= b
) && b
)
1225 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::VSCROLL
;
1229 aPropName
= GetPropertyName( BASEPROPERTY_AUTOHSCROLL
);
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::AUTOHSCROLL
;
1239 aPropName
= GetPropertyName( BASEPROPERTY_AUTOVSCROLL
);
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::AUTOVSCROLL
;
1248 //added for issue79712
1250 aPropName
= GetPropertyName( BASEPROPERTY_NOLABEL
);
1251 if ( xInfo
->hasPropertyByName( aPropName
) )
1253 aVal
= xPSet
->getPropertyValue( aPropName
);
1254 sal_Bool b
= sal_Bool();
1255 if ( ( aVal
>>=b
) && b
)
1256 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::NOLABEL
;
1261 aPropName
= GetPropertyName( BASEPROPERTY_ALIGN
);
1262 if ( xInfo
->hasPropertyByName( aPropName
) )
1264 aVal
= xPSet
->getPropertyValue( aPropName
);
1265 sal_Int16 n
= sal_Int16();
1268 if ( n
== PROPERTY_ALIGN_LEFT
)
1269 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::LEFT
;
1270 else if ( n
== PROPERTY_ALIGN_CENTER
)
1271 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::CENTER
;
1273 aDescr
.WindowAttributes
|= VclWindowPeerAttribute::RIGHT
;
1277 // Allow derivates to manipulate attributes
1278 PrepareWindowDescriptor(aDescr
);
1281 setPeer( xToolkit
->createWindow( aDescr
) );
1283 // release the mutex guard (and work with copies of our members)
1284 // this is necessary as our peer may lock the SolarMutex (actually, all currently known peers do), so calling
1285 // into the peer with our own mutex locked may cause deadlocks
1286 // (We _really_ need peers which do not use the SolarMutex. It's really pissing me off that from time to
1287 // time deadlocks pop up because the low-level components like our peers use a mutex which ususally
1288 // is locked at the top of the stack (it protects the global message looping). This is always dangerous, and
1289 // can not always be solved by tampering with other mutexes.
1290 // Unfortunately, the VCL used in the peers is not threadsafe, and by definition needs a locked SolarMutex.)
1291 // 82300 - 12/21/00 - FS
1292 UnoControlComponentInfos
aComponentInfos(maComponentInfos
);
1293 sal_Bool
bDesignMode(mbDesignMode
);
1295 Reference
< XGraphics
> xGraphics( mxGraphics
);
1296 Reference
< XView
> xView ( getPeer(), UNO_QUERY_THROW
);
1297 Reference
< XWindow
> xWindow ( getPeer(), UNO_QUERY_THROW
);
1301 // the updateFromModel is done without a locked mutex, too.
1302 // The reason is that the only thing this method does is firing property changes, and this in general has
1303 // to be done without locked mutexes (as every notification to external listeners).
1304 // 82300 - 12/21/00 - FS
1307 xView
->setZoom( aComponentInfos
.nZoomX
, aComponentInfos
.nZoomY
);
1309 setPosSize( aComponentInfos
.nX
, aComponentInfos
.nY
, aComponentInfos
.nWidth
, aComponentInfos
.nHeight
, aComponentInfos
.nFlags
);
1311 if( aComponentInfos
.bVisible
&& !bDesignMode
)
1312 // Show only after setting the data
1313 xWindow
->setVisible( aComponentInfos
.bVisible
);
1315 if( !aComponentInfos
.bEnable
)
1316 xWindow
->setEnable( aComponentInfos
.bEnable
);
1318 xView
->setGraphics( xGraphics
);
1322 mbCreatingPeer
= sal_False
;
1326 Reference
< XWindowPeer
> UnoControl::getPeer() throw(RuntimeException
)
1328 ::osl::MutexGuard
aGuard( GetMutex() );
1332 sal_Bool
UnoControl::setModel( const Reference
< XControlModel
>& rxModel
) throw(RuntimeException
)
1334 ::osl::MutexGuard
aGuard( GetMutex() );
1336 Reference
< XMultiPropertySet
> xPropSet( mxModel
, UNO_QUERY
);
1338 // query for the XPropertiesChangeListener - our delegator is allowed to overwrite this interface
1339 Reference
< XPropertiesChangeListener
> xListener
;
1340 queryInterface( ::getCppuType( &xListener
) ) >>= xListener
;
1343 xPropSet
->removePropertiesChangeListener( xListener
);
1345 mpData
->bLocalizationSupport
= false;
1352 xPropSet
.set( mxModel
, UNO_QUERY_THROW
);
1353 Reference
< XPropertySetInfo
> xPSI( xPropSet
->getPropertySetInfo(), UNO_SET_THROW
);
1355 Sequence
< OUString
> aNames
= lcl_ImplGetPropertyNames( xPropSet
);
1356 xPropSet
->addPropertiesChangeListener( aNames
, xListener
);
1358 mpData
->bLocalizationSupport
= xPSI
->hasPropertyByName( OUString( "ResourceResolver" ) );
1360 catch( const Exception
& )
1362 DBG_UNHANDLED_EXCEPTION();
1367 return mxModel
.is();
1370 Reference
< XControlModel
> UnoControl::getModel( ) throw(RuntimeException
)
1375 Reference
< XView
> UnoControl::getView( ) throw(RuntimeException
)
1377 return static_cast< XView
* >( this );
1380 void UnoControl::setDesignMode( sal_Bool bOn
) throw(RuntimeException
)
1382 ModeChangeEvent aModeChangeEvent
;
1384 Reference
< XWindow
> xWindow
;
1386 ::osl::MutexGuard
aGuard( GetMutex() );
1387 if ( bOn
== mbDesignMode
)
1392 xWindow
= xWindow
.query( getPeer() );
1393 // dispose our current AccessibleContext, if we have one
1394 // (changing the design mode implies having a new implementation for this context,
1395 // so the old one must be declared DEFUNC)
1396 disposeAccessibleContext();
1398 aModeChangeEvent
.Source
= *this;
1399 aModeChangeEvent
.NewMode
= mbDesignMode
? OUString("design") : OUString("alive" );
1402 // ajust the visibility of our window
1404 xWindow
->setVisible( !bOn
);
1406 // and notify our mode listeners
1407 maModeChangeListeners
.notifyEach( &XModeChangeListener::modeChanged
, aModeChangeEvent
);
1410 sal_Bool
UnoControl::isDesignMode( ) throw(RuntimeException
)
1412 return mbDesignMode
;
1415 sal_Bool
UnoControl::isTransparent( ) throw(RuntimeException
)
1421 OUString
UnoControl::getImplementationName( ) throw(RuntimeException
)
1423 OSL_FAIL( "This method should be overloaded!" );
1427 sal_Bool
UnoControl::supportsService( const OUString
& rServiceName
) throw(RuntimeException
)
1429 ::osl::MutexGuard
aGuard( GetMutex() );
1431 Sequence
< OUString
> aSNL
= getSupportedServiceNames();
1432 const OUString
* pArray
= aSNL
.getConstArray();
1433 const OUString
* pArrayEnd
= aSNL
.getConstArray() + aSNL
.getLength();
1434 for (; pArray
!= pArrayEnd
; ++pArray
)
1435 if( *pArray
== rServiceName
)
1438 return pArray
!= pArrayEnd
;
1441 Sequence
< OUString
> UnoControl::getSupportedServiceNames( ) throw(RuntimeException
)
1443 OUString
sName( "com.sun.star.awt.UnoControl" );
1444 return Sequence
< OUString
>( &sName
, 1 );
1447 // ------------------------------------------------------------------------
1448 Reference
< XAccessibleContext
> SAL_CALL
UnoControl::getAccessibleContext( ) throw (RuntimeException
)
1450 // creation of the context will certainly require the SolarMutex ...
1451 SolarMutexGuard aSolarGuard
;
1452 ::osl::MutexGuard
aGuard( GetMutex() );
1454 Reference
< XAccessibleContext
> xCurrentContext( maAccessibleContext
.get(), UNO_QUERY
);
1455 if ( !xCurrentContext
.is() )
1457 if ( !mbDesignMode
)
1458 { // in alive mode, use the AccessibleContext of the peer
1459 Reference
< XAccessible
> xPeerAcc( getPeer(), UNO_QUERY
);
1460 if ( xPeerAcc
.is() )
1461 xCurrentContext
= xPeerAcc
->getAccessibleContext( );
1464 // in design mode, use a fallback
1465 xCurrentContext
= ::toolkit::OAccessibleControlContext::create( this );
1467 DBG_ASSERT( xCurrentContext
.is(), "UnoControl::getAccessibleContext: invalid context (invalid peer?)!" );
1468 maAccessibleContext
= xCurrentContext
;
1470 // get notified when the context is disposed
1471 Reference
< XComponent
> xContextComp( xCurrentContext
, UNO_QUERY
);
1472 if ( xContextComp
.is() )
1473 xContextComp
->addEventListener( this );
1474 // In an ideal world, this is not necessary - there the object would be released as soon as it has been
1475 // disposed, and thus our weak reference would be empty, too.
1476 // But 'til this ideal world comes (means 'til we do never have any refcount/lifetime bugs anymore), we
1477 // need to listen for disposal and reset our weak reference then.
1480 return xCurrentContext
;
1483 void SAL_CALL
UnoControl::addModeChangeListener( const Reference
< XModeChangeListener
>& _rxListener
) throw (RuntimeException
)
1485 ::osl::MutexGuard
aGuard( GetMutex() );
1486 maModeChangeListeners
.addInterface( _rxListener
);
1489 void SAL_CALL
UnoControl::removeModeChangeListener( const Reference
< XModeChangeListener
>& _rxListener
) throw (RuntimeException
)
1491 ::osl::MutexGuard
aGuard( GetMutex() );
1492 maModeChangeListeners
.removeInterface( _rxListener
);
1495 void SAL_CALL
UnoControl::addModeChangeApproveListener( const Reference
< XModeChangeApproveListener
>& ) throw (NoSupportException
, RuntimeException
)
1497 throw NoSupportException( );
1500 void SAL_CALL
UnoControl::removeModeChangeApproveListener( const Reference
< XModeChangeApproveListener
>& ) throw (NoSupportException
, RuntimeException
)
1502 throw NoSupportException( );
1505 //----------------------------------------------------------------------------------------------------------------------
1506 awt::Point SAL_CALL
UnoControl::convertPointToLogic( const awt::Point
& i_Point
, ::sal_Int16 i_TargetUnit
) throw (IllegalArgumentException
, RuntimeException
)
1508 Reference
< XUnitConversion
> xPeerConversion
;
1510 ::osl::MutexGuard
aGuard( GetMutex() );
1511 xPeerConversion
= xPeerConversion
.query( getPeer() );
1513 if ( xPeerConversion
.is() )
1514 return xPeerConversion
->convertPointToLogic( i_Point
, i_TargetUnit
);
1515 return awt::Point( );
1518 //----------------------------------------------------------------------------------------------------------------------
1519 awt::Point SAL_CALL
UnoControl::convertPointToPixel( const awt::Point
& i_Point
, ::sal_Int16 i_SourceUnit
) throw (IllegalArgumentException
, RuntimeException
)
1521 Reference
< XUnitConversion
> xPeerConversion
;
1523 ::osl::MutexGuard
aGuard( GetMutex() );
1524 xPeerConversion
= xPeerConversion
.query( getPeer() );
1526 if ( xPeerConversion
.is() )
1527 return xPeerConversion
->convertPointToPixel( i_Point
, i_SourceUnit
);
1528 return awt::Point( );
1531 //----------------------------------------------------------------------------------------------------------------------
1532 awt::Size SAL_CALL
UnoControl::convertSizeToLogic( const awt::Size
& i_Size
, ::sal_Int16 i_TargetUnit
) throw (IllegalArgumentException
, RuntimeException
)
1534 Reference
< XUnitConversion
> xPeerConversion
;
1536 ::osl::MutexGuard
aGuard( GetMutex() );
1537 xPeerConversion
= xPeerConversion
.query( getPeer() );
1539 if ( xPeerConversion
.is() )
1540 return xPeerConversion
->convertSizeToLogic( i_Size
, i_TargetUnit
);
1541 return awt::Size( );
1544 //----------------------------------------------------------------------------------------------------------------------
1545 awt::Size SAL_CALL
UnoControl::convertSizeToPixel( const awt::Size
& i_Size
, ::sal_Int16 i_SourceUnit
) throw (IllegalArgumentException
, RuntimeException
)
1547 Reference
< XUnitConversion
> xPeerConversion
;
1549 ::osl::MutexGuard
aGuard( GetMutex() );
1550 xPeerConversion
= xPeerConversion
.query( getPeer() );
1552 if ( xPeerConversion
.is() )
1553 return xPeerConversion
->convertSizeToPixel( i_Size
, i_SourceUnit
);
1554 return awt::Size( );
1557 //----------------------------------------------------------------------------------------------------------------------
1558 uno::Reference
< awt::XStyleSettings
> SAL_CALL
UnoControl::getStyleSettings() throw (RuntimeException
)
1560 Reference
< awt::XStyleSettingsSupplier
> xPeerSupplier
;
1562 ::osl::MutexGuard
aGuard( GetMutex() );
1563 xPeerSupplier
= xPeerSupplier
.query( getPeer() );
1565 if ( xPeerSupplier
.is() )
1566 return xPeerSupplier
->getStyleSettings();
1570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */