Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include <boost/noncopyable.hpp>
23 : #include <com/sun/star/awt/XControlContainer.hpp>
24 : #include <com/sun/star/awt/WindowAttribute.hpp>
25 : #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
26 : #include <com/sun/star/awt/PosSize.hpp>
27 : #include <com/sun/star/beans/PropertyValue.hpp>
28 : #include <com/sun/star/resource/XStringResourceResolver.hpp>
29 : #include <toolkit/controls/unocontrol.hxx>
30 : #include <toolkit/helper/vclunohelper.hxx>
31 : #include <cppuhelper/supportsservice.hxx>
32 : #include <cppuhelper/typeprovider.hxx>
33 : #include <rtl/uuid.h>
34 : #include <osl/mutex.hxx>
35 : #include <tools/date.hxx>
36 : #include <tools/debug.hxx>
37 : #include <tools/diagnose_ex.h>
38 : #include <vcl/svapp.hxx>
39 : #include <vcl/wrkwin.hxx>
40 : #include <comphelper/processfactory.hxx>
41 : #include <toolkit/helper/property.hxx>
42 : #include <toolkit/helper/servicenames.hxx>
43 : #include <toolkit/awt/vclxwindow.hxx>
44 : #include <toolkit/controls/accessiblecontrolcontext.hxx>
45 : #include <comphelper/container.hxx>
46 :
47 : #include <algorithm>
48 : #include <map>
49 : #include <set>
50 : #include <vector>
51 :
52 : using namespace ::com::sun::star;
53 : using namespace ::com::sun::star::uno;
54 : using namespace ::com::sun::star::awt;
55 : using namespace ::com::sun::star::beans;
56 : using namespace ::com::sun::star::lang;
57 : using namespace ::com::sun::star::util;
58 :
59 : using ::com::sun::star::accessibility::XAccessibleContext;
60 : using ::com::sun::star::accessibility::XAccessible;
61 :
62 : struct LanguageDependentProp
63 : {
64 : const char* pPropName;
65 : sal_Int32 nPropNameLength;
66 : };
67 :
68 : static const LanguageDependentProp aLanguageDependentProp[] =
69 : {
70 : { "Text", 4 },
71 : { "Label", 5 },
72 : { "Title", 5 },
73 : { "HelpText", 8 },
74 : { "CurrencySymbol", 14 },
75 : { "StringItemList", 14 },
76 : { 0, 0 }
77 : };
78 :
79 0 : static Sequence< OUString> lcl_ImplGetPropertyNames( const Reference< XMultiPropertySet > & rxModel )
80 : {
81 0 : Sequence< OUString> aNames;
82 0 : Reference< XPropertySetInfo > xPSInf = rxModel->getPropertySetInfo();
83 : DBG_ASSERT( xPSInf.is(), "UpdateFromModel: No PropertySetInfo!" );
84 0 : if ( xPSInf.is() )
85 : {
86 0 : Sequence< Property> aProps = xPSInf->getProperties();
87 0 : sal_Int32 nLen = aProps.getLength();
88 0 : aNames = Sequence< OUString>( nLen );
89 0 : OUString* pNames = aNames.getArray();
90 0 : const Property* pProps = aProps.getConstArray();
91 0 : for ( sal_Int32 n = 0; n < nLen; ++n, ++pProps, ++pNames)
92 0 : *pNames = pProps->Name;
93 : }
94 0 : return aNames;
95 : }
96 :
97 :
98 : class VclListenerLock: private boost::noncopyable
99 : {
100 : private:
101 : VCLXWindow* m_pLockWindow;
102 :
103 : public:
104 0 : inline VclListenerLock( VCLXWindow* _pLockWindow )
105 0 : :m_pLockWindow( _pLockWindow )
106 : {
107 0 : if ( m_pLockWindow )
108 0 : m_pLockWindow->suspendVclEventListening( );
109 0 : }
110 0 : inline ~VclListenerLock( )
111 : {
112 0 : if ( m_pLockWindow )
113 0 : m_pLockWindow->resumeVclEventListening( );
114 0 : }
115 : };
116 :
117 : typedef ::std::map< OUString, sal_Int32 > MapString2Int;
118 0 : struct UnoControl_Data
119 : {
120 : MapString2Int aSuspendedPropertyNotifications;
121 : /// true if and only if our model has a property ResourceResolver
122 : bool bLocalizationSupport;
123 :
124 0 : UnoControl_Data()
125 : :aSuspendedPropertyNotifications()
126 0 : ,bLocalizationSupport( false )
127 : {
128 0 : }
129 : };
130 :
131 0 : UnoControl::UnoControl() :
132 : maDisposeListeners( *this )
133 : , maWindowListeners( *this )
134 : , maFocusListeners( *this )
135 : , maKeyListeners( *this )
136 : , maMouseListeners( *this )
137 : , maMouseMotionListeners( *this )
138 : , maPaintListeners( *this )
139 0 : , maModeChangeListeners( GetMutex() )
140 0 : , mpData( new UnoControl_Data )
141 : {
142 0 : mbDisposePeer = true;
143 0 : mbRefeshingPeer = false;
144 0 : mbCreatingPeer = false;
145 0 : mbCreatingCompatiblePeer = false;
146 0 : mbDesignMode = false;
147 0 : }
148 :
149 0 : UnoControl::~UnoControl()
150 : {
151 0 : DELETEZ( mpData );
152 0 : }
153 :
154 0 : OUString UnoControl::GetComponentServiceName()
155 : {
156 0 : return OUString();
157 : }
158 :
159 0 : Reference< XWindowPeer > UnoControl::ImplGetCompatiblePeer( bool bAcceptExistingPeer )
160 : {
161 : DBG_ASSERT( !mbCreatingCompatiblePeer, "ImplGetCompatiblePeer - rekursive?" );
162 :
163 0 : mbCreatingCompatiblePeer = true;
164 :
165 0 : Reference< XWindowPeer > xCompatiblePeer;
166 :
167 0 : if ( bAcceptExistingPeer )
168 0 : xCompatiblePeer = getPeer();
169 :
170 0 : if ( !xCompatiblePeer.is() )
171 : {
172 : // Create the pair as invisible
173 0 : bool bVis = maComponentInfos.bVisible;
174 0 : if( bVis )
175 0 : maComponentInfos.bVisible = false;
176 :
177 0 : Reference< XWindowPeer > xCurrentPeer = getPeer();
178 0 : setPeer( NULL );
179 :
180 : // queryInterface ourself, to allow aggregation
181 0 : Reference< XControl > xMe;
182 0 : OWeakAggObject::queryInterface( ::getCppuType( &xMe ) ) >>= xMe;
183 :
184 0 : Window* pParentWindow( NULL );
185 : {
186 0 : SolarMutexGuard aGuard;
187 0 : pParentWindow = dynamic_cast< Window* >( Application::GetDefaultDevice() );
188 0 : ENSURE_OR_THROW( pParentWindow != NULL, "could obtain a default parent window!" );
189 : }
190 : try
191 : {
192 0 : xMe->createPeer( NULL, pParentWindow->GetComponentInterface( sal_True ) );
193 : }
194 0 : catch( const Exception& )
195 : {
196 0 : mbCreatingCompatiblePeer = false;
197 0 : throw;
198 : }
199 0 : xCompatiblePeer = getPeer();
200 0 : setPeer( xCurrentPeer );
201 :
202 0 : if ( xCompatiblePeer.is() && mxGraphics.is() )
203 : {
204 0 : Reference< XView > xPeerView( xCompatiblePeer, UNO_QUERY );
205 0 : if ( xPeerView.is() )
206 0 : xPeerView->setGraphics( mxGraphics );
207 : }
208 :
209 0 : if( bVis )
210 0 : maComponentInfos.bVisible = true;
211 : }
212 :
213 0 : mbCreatingCompatiblePeer = false;
214 :
215 0 : return xCompatiblePeer;
216 : }
217 :
218 0 : bool UnoControl::ImplCheckLocalize( OUString& _rPossiblyLocalizable )
219 : {
220 0 : if ( !mpData->bLocalizationSupport
221 0 : || ( _rPossiblyLocalizable.isEmpty() )
222 0 : || ( _rPossiblyLocalizable[0] != '&' )
223 : // TODO: make this reasonable. At the moment, everything which by accident starts with a & is considered
224 : // localizable, which is probably wrong.
225 : )
226 0 : return false;
227 :
228 : try
229 : {
230 0 : Reference< XPropertySet > xPropSet( mxModel, UNO_QUERY_THROW );
231 : Reference< resource::XStringResourceResolver > xStringResourceResolver(
232 0 : xPropSet->getPropertyValue("ResourceResolver"),
233 : UNO_QUERY
234 0 : );
235 0 : if ( xStringResourceResolver.is() )
236 : {
237 0 : OUString aLocalizationKey( _rPossiblyLocalizable.copy( 1 ) );
238 0 : _rPossiblyLocalizable = xStringResourceResolver->resolveString( aLocalizationKey );
239 0 : return true;
240 0 : }
241 : }
242 0 : catch( const Exception& )
243 : {
244 : DBG_UNHANDLED_EXCEPTION();
245 : }
246 0 : return false;
247 : }
248 :
249 0 : void UnoControl::ImplSetPeerProperty( const OUString& rPropName, const Any& rVal )
250 : {
251 : // since a change made in propertiesChange, we can't be sure that this is called with an valid getPeer(),
252 : // this assumption may be false in some (seldom) multi-threading scenarios (cause propertiesChange
253 : // releases our mutex before calling here in)
254 : // That's why this additional check
255 :
256 0 : if ( mxVclWindowPeer.is() )
257 : {
258 0 : Any aConvertedValue( rVal );
259 :
260 0 : if ( mpData->bLocalizationSupport )
261 : {
262 : // We now support a mapping for language dependent properties. This is the
263 : // central method to implement it.
264 0 : if( rPropName == "Text" ||
265 0 : rPropName == "Label" ||
266 0 : rPropName == "Title" ||
267 0 : rPropName == "HelpText" ||
268 0 : rPropName == "CurrencySymbol" ||
269 0 : rPropName == "StringItemList" )
270 : {
271 0 : OUString aValue;
272 0 : uno::Sequence< OUString > aSeqValue;
273 0 : if ( aConvertedValue >>= aValue )
274 : {
275 0 : if ( ImplCheckLocalize( aValue ) )
276 0 : aConvertedValue <<= aValue;
277 : }
278 0 : else if ( aConvertedValue >>= aSeqValue )
279 : {
280 0 : for ( sal_Int32 i = 0; i < aSeqValue.getLength(); i++ )
281 0 : ImplCheckLocalize( aSeqValue[i] );
282 0 : aConvertedValue <<= aSeqValue;
283 0 : }
284 : }
285 : }
286 :
287 0 : mxVclWindowPeer->setProperty( rPropName, aConvertedValue );
288 : }
289 0 : }
290 :
291 0 : void UnoControl::PrepareWindowDescriptor( WindowDescriptor& )
292 : {
293 0 : }
294 :
295 0 : Reference< XWindow > UnoControl::getParentPeer() const
296 : {
297 0 : Reference< XWindow > xPeer;
298 0 : if( mxContext.is() )
299 : {
300 0 : Reference< XControl > xContComp( mxContext, UNO_QUERY );
301 0 : if ( xContComp.is() )
302 : {
303 0 : Reference< XWindowPeer > xP = xContComp->getPeer();
304 0 : if ( xP.is() )
305 0 : xPeer.set( xP, UNO_QUERY );
306 0 : }
307 : }
308 0 : return xPeer;
309 : }
310 :
311 0 : void UnoControl::updateFromModel()
312 : {
313 : // Read default properties and hand over to peer
314 0 : if( getPeer().is() )
315 : {
316 0 : Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
317 0 : if( xPropSet.is() )
318 : {
319 0 : Sequence< OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
320 0 : xPropSet->firePropertiesChangeEvent( aNames, this );
321 0 : }
322 : }
323 0 : }
324 :
325 :
326 : // XTypeProvider
327 0 : IMPL_IMPLEMENTATION_ID( UnoControl )
328 :
329 : void
330 0 : UnoControl::DisposeAccessibleContext(Reference<XComponent> const& xContextComp)
331 : {
332 0 : if (xContextComp.is())
333 : {
334 : try
335 : {
336 0 : xContextComp->removeEventListener( this );
337 0 : xContextComp->dispose();
338 : }
339 0 : catch( const Exception& )
340 : {
341 : OSL_FAIL( "UnoControl::disposeAccessibleContext: could not dispose my AccessibleContext!" );
342 : }
343 : }
344 0 : }
345 :
346 0 : void UnoControl::dispose( ) throw(RuntimeException, std::exception)
347 : {
348 0 : Reference< XWindowPeer > xPeer;
349 0 : Reference<XComponent> xAccessibleComp;
350 : {
351 0 : ::osl::MutexGuard aGuard( GetMutex() );
352 0 : if( mbDisposePeer )
353 : {
354 0 : xPeer = mxPeer;
355 : }
356 0 : setPeer( NULL );
357 0 : xAccessibleComp.set(maAccessibleContext, UNO_QUERY);
358 0 : maAccessibleContext.clear();
359 : }
360 0 : if( xPeer.is() )
361 : {
362 0 : xPeer->dispose();
363 : }
364 :
365 : // dispose our AccessibleContext - without Mutex locked
366 0 : DisposeAccessibleContext(xAccessibleComp);
367 :
368 0 : EventObject aDisposeEvent;
369 0 : aDisposeEvent.Source = static_cast< XAggregation* >( this );
370 :
371 0 : maDisposeListeners.disposeAndClear( aDisposeEvent );
372 0 : maWindowListeners.disposeAndClear( aDisposeEvent );
373 0 : maFocusListeners.disposeAndClear( aDisposeEvent );
374 0 : maKeyListeners.disposeAndClear( aDisposeEvent );
375 0 : maMouseListeners.disposeAndClear( aDisposeEvent );
376 0 : maMouseMotionListeners.disposeAndClear( aDisposeEvent );
377 0 : maPaintListeners.disposeAndClear( aDisposeEvent );
378 0 : maModeChangeListeners.disposeAndClear( aDisposeEvent );
379 :
380 : // release Model again
381 0 : setModel( Reference< XControlModel > () );
382 0 : setContext( Reference< XInterface > () );
383 0 : }
384 :
385 0 : void UnoControl::addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException, std::exception)
386 : {
387 0 : ::osl::MutexGuard aGuard( GetMutex() );
388 :
389 0 : maDisposeListeners.addInterface( rxListener );
390 0 : }
391 :
392 0 : void UnoControl::removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException, std::exception)
393 : {
394 0 : ::osl::MutexGuard aGuard( GetMutex() );
395 :
396 0 : maDisposeListeners.removeInterface( rxListener );
397 0 : }
398 :
399 0 : bool UnoControl::requiresNewPeer( const OUString& /* _rPropertyName */ ) const
400 : {
401 0 : return false;
402 : }
403 :
404 : // XPropertiesChangeListener
405 0 : void UnoControl::propertiesChange( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException, std::exception)
406 : {
407 0 : Sequence< PropertyChangeEvent > aEvents( rEvents );
408 : {
409 0 : ::osl::MutexGuard aGuard( GetMutex() );
410 :
411 0 : if ( !mpData->aSuspendedPropertyNotifications.empty() )
412 : {
413 : // strip the property which we are currently updating (somewhere up the stack)
414 0 : PropertyChangeEvent* pEvents = aEvents.getArray();
415 0 : PropertyChangeEvent* pEventsEnd = pEvents + aEvents.getLength();
416 0 : for ( ; pEvents < pEventsEnd; )
417 0 : if ( mpData->aSuspendedPropertyNotifications.find( pEvents->PropertyName ) != mpData->aSuspendedPropertyNotifications.end() )
418 : {
419 0 : if ( pEvents != pEventsEnd )
420 0 : ::std::copy( pEvents + 1, pEventsEnd, pEvents );
421 0 : --pEventsEnd;
422 : }
423 : else
424 0 : ++pEvents;
425 0 : aEvents.realloc( pEventsEnd - aEvents.getConstArray() );
426 :
427 0 : if ( !aEvents.getLength() )
428 0 : return;
429 0 : }
430 : }
431 :
432 0 : ImplModelPropertiesChanged( aEvents );
433 : }
434 :
435 0 : void UnoControl::ImplLockPropertyChangeNotification( const OUString& rPropertyName, bool bLock )
436 : {
437 0 : MapString2Int::iterator pos = mpData->aSuspendedPropertyNotifications.find( rPropertyName );
438 0 : if ( bLock )
439 : {
440 0 : if ( pos == mpData->aSuspendedPropertyNotifications.end() )
441 0 : pos = mpData->aSuspendedPropertyNotifications.insert( MapString2Int::value_type( rPropertyName, 0 ) ).first;
442 0 : ++pos->second;
443 : }
444 : else
445 : {
446 : OSL_ENSURE( pos != mpData->aSuspendedPropertyNotifications.end(), "UnoControl::ImplLockPropertyChangeNotification: property not locked!" );
447 0 : if ( pos != mpData->aSuspendedPropertyNotifications.end() )
448 : {
449 : OSL_ENSURE( pos->second > 0, "UnoControl::ImplLockPropertyChangeNotification: invalid suspension counter!" );
450 0 : if ( 0 == --pos->second )
451 0 : mpData->aSuspendedPropertyNotifications.erase( pos );
452 : }
453 : }
454 0 : }
455 :
456 0 : void UnoControl::ImplLockPropertyChangeNotifications( const Sequence< OUString >& rPropertyNames, bool bLock )
457 : {
458 0 : for ( const OUString* pPropertyName = rPropertyNames.getConstArray();
459 0 : pPropertyName != rPropertyNames.getConstArray() + rPropertyNames.getLength();
460 : ++pPropertyName
461 : )
462 0 : ImplLockPropertyChangeNotification( *pPropertyName, bLock );
463 0 : }
464 :
465 0 : void UnoControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents )
466 : {
467 0 : ::osl::ClearableGuard< ::osl::Mutex > aGuard( GetMutex() );
468 :
469 0 : if( getPeer().is() )
470 : {
471 0 : std::vector< PropertyValue > aPeerPropertiesToSet;
472 0 : sal_Int32 nIndependentPos = 0;
473 0 : bool bResourceResolverSet( false );
474 : // position where to insert the independent properties into aPeerPropertiesToSet,
475 : // dependent ones are inserted at the end of the vector
476 :
477 0 : bool bNeedNewPeer = false;
478 : // some properties require a re-creation of the peer, 'cause they can't be changed on the fly
479 :
480 0 : Reference< XControlModel > xOwnModel( getModel(), UNO_QUERY );
481 : // our own model for comparison
482 0 : Reference< XPropertySet > xPS( xOwnModel, UNO_QUERY );
483 0 : Reference< XPropertySetInfo > xPSI( xPS->getPropertySetInfo(), UNO_QUERY );
484 : OSL_ENSURE( xPSI.is(), "UnoControl::ImplModelPropertiesChanged: should have property set meta data!" );
485 :
486 0 : const PropertyChangeEvent* pEvents = rEvents.getConstArray();
487 :
488 0 : sal_Int32 nLen = rEvents.getLength();
489 0 : aPeerPropertiesToSet.reserve(nLen);
490 :
491 0 : for( sal_Int32 i = 0; i < nLen; ++i, ++pEvents )
492 : {
493 0 : Reference< XControlModel > xModel( pEvents->Source, UNO_QUERY );
494 0 : bool bOwnModel = xModel.get() == xOwnModel.get();
495 0 : if ( !bOwnModel )
496 0 : continue;
497 :
498 : // Detect changes on our resource resolver which invalidates
499 : // automatically some language dependent properties.
500 0 : if ( pEvents->PropertyName == "ResourceResolver" )
501 : {
502 0 : Reference< resource::XStringResourceResolver > xStrResolver;
503 0 : if ( pEvents->NewValue >>= xStrResolver )
504 0 : bResourceResolverSet = xStrResolver.is();
505 : }
506 :
507 0 : sal_uInt16 nPType = GetPropertyId( pEvents->PropertyName );
508 0 : if ( mbDesignMode && mbDisposePeer && !mbRefeshingPeer && !mbCreatingPeer )
509 : {
510 : // if we're in design mode, then some properties can change which
511 : // require creating a *new* peer (since these properties cannot
512 : // be switched at existing peers)
513 0 : if ( nPType )
514 : bNeedNewPeer = ( nPType == BASEPROPERTY_BORDER )
515 0 : || ( nPType == BASEPROPERTY_MULTILINE )
516 0 : || ( nPType == BASEPROPERTY_DROPDOWN )
517 0 : || ( nPType == BASEPROPERTY_HSCROLL )
518 0 : || ( nPType == BASEPROPERTY_VSCROLL )
519 0 : || ( nPType == BASEPROPERTY_AUTOHSCROLL )
520 0 : || ( nPType == BASEPROPERTY_AUTOVSCROLL )
521 0 : || ( nPType == BASEPROPERTY_ORIENTATION )
522 0 : || ( nPType == BASEPROPERTY_SPIN )
523 0 : || ( nPType == BASEPROPERTY_ALIGN )
524 0 : || ( nPType == BASEPROPERTY_PAINTTRANSPARENT );
525 : else
526 0 : bNeedNewPeer = requiresNewPeer( pEvents->PropertyName );
527 :
528 0 : if ( bNeedNewPeer )
529 0 : break;
530 : }
531 :
532 0 : if ( nPType && ( nLen > 1 ) && DoesDependOnOthers( nPType ) )
533 : {
534 : // Add properties with dependencies on other properties last
535 : // since they're dependent on properties added later (such as
536 : // VALUE dependency on VALUEMIN/MAX)
537 0 : aPeerPropertiesToSet.push_back(PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
538 : }
539 : else
540 : {
541 0 : if ( bResourceResolverSet )
542 : {
543 : // The resource resolver property change should be one of the first ones.
544 : // All language dependent properties are dependent on this property.
545 : // As BASEPROPERTY_NATIVE_WIDGET_LOOK is not dependent on resource
546 : // resolver. We don't need to handle a special order for these two props.
547 : aPeerPropertiesToSet.insert(
548 : aPeerPropertiesToSet.begin(),
549 0 : PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
550 0 : ++nIndependentPos;
551 : }
552 0 : else if ( nPType == BASEPROPERTY_NATIVE_WIDGET_LOOK )
553 : {
554 : // since *a lot* of other properties might be overruled by this one, we need
555 : // a special handling:
556 : // NativeWidgetLook needs to be set first: If it is set to ON, all other
557 : // properties describing the look (e.g. BackgroundColor) are ignored, anyway.
558 : // If it is switched OFF, then we need to do it first because else it will
559 : // overrule other look-related properties, and re-initialize them from system
560 : // defaults.
561 : aPeerPropertiesToSet.insert(
562 : aPeerPropertiesToSet.begin(),
563 0 : PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) );
564 0 : ++nIndependentPos;
565 : }
566 : else
567 : {
568 : aPeerPropertiesToSet.insert(aPeerPropertiesToSet.begin() + nIndependentPos,
569 0 : PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE));
570 0 : ++nIndependentPos;
571 : }
572 : }
573 0 : }
574 :
575 0 : Reference< XWindow > xParent = getParentPeer();
576 0 : Reference< XControl > xThis( (XAggregation*)(::cppu::OWeakAggObject*)this, UNO_QUERY );
577 : // call createPeer via a interface got from queryInterface, so the aggregating class can intercept it
578 :
579 : DBG_ASSERT( !bNeedNewPeer || xParent.is(), "Need new peer, but don't have a parent!" );
580 :
581 : // Check if we have to update language dependent properties
582 0 : if ( !bNeedNewPeer && bResourceResolverSet )
583 : {
584 : // Add language dependent properties into the peer property set.
585 : // Our resource resolver has been changed and we must be sure
586 : // that language dependent props use the new resolver.
587 0 : const LanguageDependentProp* pLangDepProp = aLanguageDependentProp;
588 0 : while ( pLangDepProp->pPropName != 0 )
589 : {
590 0 : bool bMustBeInserted( true );
591 0 : for ( sal_uInt32 i = 0; i < aPeerPropertiesToSet.size(); i++ )
592 : {
593 0 : if ( aPeerPropertiesToSet[i].Name.equalsAsciiL(
594 0 : pLangDepProp->pPropName, pLangDepProp->nPropNameLength ))
595 : {
596 0 : bMustBeInserted = false;
597 0 : break;
598 : }
599 : }
600 :
601 0 : if ( bMustBeInserted )
602 : {
603 : // Add language dependent props at the end
604 0 : OUString aPropName( OUString::createFromAscii( pLangDepProp->pPropName ));
605 0 : if ( xPSI.is() && xPSI->hasPropertyByName( aPropName ) )
606 : {
607 : aPeerPropertiesToSet.push_back(
608 0 : PropertyValue( aPropName, 0, xPS->getPropertyValue( aPropName ), PropertyState_DIRECT_VALUE ) );
609 0 : }
610 : }
611 :
612 0 : ++pLangDepProp;
613 : }
614 : }
615 0 : aGuard.clear();
616 :
617 : // clear the guard before creating a new peer - as usual, our peer implementations use the SolarMutex
618 :
619 0 : if (bNeedNewPeer && xParent.is())
620 : {
621 0 : SolarMutexGuard aVclGuard;
622 : // and now this is the final withdrawal:
623 : // I have no other idea than locking the SolarMutex here ....
624 : // I really hate the fact that VCL is not theadsafe ....
625 :
626 : // Doesn't work for Container!
627 0 : getPeer()->dispose();
628 0 : mxPeer.clear();
629 0 : mxVclWindowPeer = NULL;
630 0 : mbRefeshingPeer = true;
631 0 : Reference< XWindowPeer > xP( xParent, UNO_QUERY );
632 0 : xThis->createPeer( Reference< XToolkit > (), xP );
633 0 : mbRefeshingPeer = false;
634 0 : aPeerPropertiesToSet.clear();
635 : }
636 :
637 : // lock the multiplexing of VCL events to our UNO listeners
638 : // this is for compatibility reasons: in OOo 1.0.x, changes which were done at the
639 : // model did not cause the listeners of the controls/peers to be called
640 : // Since the implementations for the listeners changed a lot towards 1.1, this
641 : // would not be the case anymore, if we would not do this listener-lock below
642 : // #i14703#
643 0 : Window* pVclPeer = VCLUnoHelper::GetWindow( getPeer() );
644 0 : VCLXWindow* pPeer = pVclPeer ? pVclPeer->GetWindowPeer() : NULL;
645 0 : VclListenerLock aNoVclEventMultiplexing( pPeer );
646 :
647 : // setting peer properties may result in an attemp to acquire the solar mutex, 'cause the peers
648 : // usually don't have an own mutex but use the SolarMutex instead.
649 : // To prevent deadlocks resulting from this, we do this without our own mutex locked
650 0 : std::vector< PropertyValue >::iterator aEnd = aPeerPropertiesToSet.end();
651 0 : for ( std::vector< PropertyValue >::iterator aLoop = aPeerPropertiesToSet.begin();
652 : aLoop != aEnd;
653 : ++aLoop
654 : )
655 : {
656 0 : ImplSetPeerProperty( aLoop->Name, aLoop->Value );
657 0 : }
658 0 : }
659 0 : }
660 :
661 0 : void UnoControl::disposing( const EventObject& rEvt ) throw(RuntimeException, std::exception)
662 : {
663 0 : ::osl::ClearableMutexGuard aGuard( GetMutex() );
664 : // do not compare differing types in case of multible inheritance
665 :
666 0 : if ( maAccessibleContext.get() == rEvt.Source )
667 : {
668 : // just in case the context is disposed, but not released - ensure that we do not re-use it in the future
669 0 : maAccessibleContext = NULL;
670 : }
671 0 : else if( mxModel.get() == Reference< XControlModel >(rEvt.Source,UNO_QUERY).get() )
672 : {
673 : // #62337# if the model dies, it does not make sense for us to live ...
674 0 : Reference< XControl > xThis = this;
675 :
676 0 : aGuard.clear();
677 0 : xThis->dispose();
678 :
679 : DBG_ASSERT( !mxModel.is(), "UnoControl::disposing: invalid dispose behaviour!" );
680 0 : mxModel.clear();
681 0 : }
682 0 : }
683 :
684 :
685 0 : void SAL_CALL UnoControl::setOutputSize( const awt::Size& aSize ) throw (RuntimeException, std::exception)
686 : {
687 0 : Reference< XWindow2 > xPeerWindow;
688 : {
689 0 : ::osl::MutexGuard aGuard( GetMutex() );
690 0 : xPeerWindow = xPeerWindow.query( getPeer() );
691 : }
692 :
693 0 : if ( xPeerWindow.is() )
694 0 : xPeerWindow->setOutputSize( aSize );
695 0 : }
696 :
697 : namespace
698 : {
699 : template < typename RETVALTYPE, typename DEFAULTTYPE >
700 0 : RETVALTYPE lcl_askPeer( const uno::Reference< awt::XWindowPeer >& _rxPeer, RETVALTYPE (SAL_CALL XWindow2::*_pMethod)(), DEFAULTTYPE _aDefault )
701 : {
702 0 : RETVALTYPE aReturn( _aDefault );
703 :
704 0 : Reference< XWindow2 > xPeerWindow( _rxPeer, UNO_QUERY );
705 0 : if ( xPeerWindow.is() )
706 0 : aReturn = (xPeerWindow.get()->*_pMethod)();
707 :
708 0 : return aReturn;
709 : }
710 : }
711 :
712 0 : awt::Size SAL_CALL UnoControl::getOutputSize( ) throw (RuntimeException, std::exception)
713 : {
714 0 : return lcl_askPeer( getPeer(), &XWindow2::getOutputSize, awt::Size() );
715 : }
716 :
717 0 : sal_Bool SAL_CALL UnoControl::isVisible( ) throw (RuntimeException, std::exception)
718 : {
719 0 : return lcl_askPeer( getPeer(), &XWindow2::isVisible, maComponentInfos.bVisible );
720 : }
721 :
722 0 : sal_Bool SAL_CALL UnoControl::isActive( ) throw (RuntimeException, std::exception)
723 : {
724 0 : return lcl_askPeer( getPeer(), &XWindow2::isActive, sal_False );
725 : }
726 :
727 0 : sal_Bool SAL_CALL UnoControl::isEnabled( ) throw (RuntimeException, std::exception)
728 : {
729 0 : return lcl_askPeer( getPeer(), &XWindow2::isEnabled, maComponentInfos.bEnable );
730 : }
731 :
732 0 : sal_Bool SAL_CALL UnoControl::hasFocus( ) throw (RuntimeException, std::exception)
733 : {
734 0 : return lcl_askPeer( getPeer(), &XWindow2::hasFocus, sal_False );
735 : }
736 :
737 : // XWindow
738 0 : void UnoControl::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw(RuntimeException, std::exception)
739 : {
740 0 : Reference< XWindow > xWindow;
741 : {
742 0 : ::osl::MutexGuard aGuard( GetMutex() );
743 :
744 0 : if ( Flags & awt::PosSize::X )
745 0 : maComponentInfos.nX = X;
746 0 : if ( Flags & awt::PosSize::Y )
747 0 : maComponentInfos.nY = Y;
748 0 : if ( Flags & awt::PosSize::WIDTH )
749 0 : maComponentInfos.nWidth = Width;
750 0 : if ( Flags & awt::PosSize::HEIGHT )
751 0 : maComponentInfos.nHeight = Height;
752 0 : maComponentInfos.nFlags |= Flags;
753 :
754 0 : xWindow = xWindow.query( getPeer() );
755 : }
756 :
757 0 : if( xWindow.is() )
758 0 : xWindow->setPosSize( X, Y, Width, Height, Flags );
759 0 : }
760 :
761 0 : awt::Rectangle UnoControl::getPosSize( ) throw(RuntimeException, std::exception)
762 : {
763 0 : awt::Rectangle aRect( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight);
764 0 : Reference< XWindow > xWindow;
765 :
766 : {
767 0 : ::osl::MutexGuard aGuard( GetMutex() );
768 0 : xWindow = xWindow.query( getPeer() );
769 : }
770 :
771 0 : if( xWindow.is() )
772 0 : aRect = xWindow->getPosSize();
773 0 : return aRect;
774 : }
775 :
776 0 : void UnoControl::setVisible( sal_Bool bVisible ) throw(RuntimeException, std::exception)
777 : {
778 0 : Reference< XWindow > xWindow;
779 : {
780 0 : ::osl::MutexGuard aGuard( GetMutex() );
781 :
782 : // Visible status is handled by View
783 0 : maComponentInfos.bVisible = bVisible;
784 0 : xWindow = xWindow.query( getPeer() );
785 : }
786 0 : if ( xWindow.is() )
787 0 : xWindow->setVisible( bVisible );
788 0 : }
789 :
790 0 : void UnoControl::setEnable( sal_Bool bEnable ) throw(RuntimeException, std::exception)
791 : {
792 0 : Reference< XWindow > xWindow;
793 : {
794 0 : ::osl::MutexGuard aGuard( GetMutex() );
795 :
796 : // Enable status is handled by View
797 0 : maComponentInfos.bEnable = bEnable;
798 0 : xWindow = xWindow.query( getPeer() );
799 : }
800 0 : if ( xWindow.is() )
801 0 : xWindow->setEnable( bEnable );
802 0 : }
803 :
804 0 : void UnoControl::setFocus( ) throw(RuntimeException, std::exception)
805 : {
806 0 : Reference< XWindow > xWindow;
807 : {
808 0 : ::osl::MutexGuard aGuard( GetMutex() );
809 0 : xWindow = xWindow.query( getPeer() );
810 : }
811 0 : if ( xWindow.is() )
812 0 : xWindow->setFocus();
813 0 : }
814 :
815 0 : void UnoControl::addWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException, std::exception)
816 : {
817 0 : Reference< XWindow > xPeerWindow;
818 : {
819 0 : ::osl::MutexGuard aGuard( GetMutex() );
820 0 : maWindowListeners.addInterface( rxListener );
821 0 : if ( maWindowListeners.getLength() == 1 )
822 0 : xPeerWindow = xPeerWindow.query( getPeer() );
823 : }
824 0 : if ( xPeerWindow.is() )
825 0 : xPeerWindow->addWindowListener( &maWindowListeners );
826 0 : }
827 :
828 0 : void UnoControl::removeWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException, std::exception)
829 : {
830 0 : Reference< XWindow > xPeerWindow;
831 : {
832 0 : ::osl::MutexGuard aGuard( GetMutex() );
833 0 : if ( maWindowListeners.getLength() == 1 )
834 0 : xPeerWindow = xPeerWindow.query( getPeer() );
835 0 : maWindowListeners.removeInterface( rxListener );
836 : }
837 0 : if ( xPeerWindow.is() )
838 0 : xPeerWindow->removeWindowListener( &maWindowListeners );
839 0 : }
840 :
841 0 : void UnoControl::addFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException, std::exception)
842 : {
843 0 : Reference< XWindow > xPeerWindow;
844 : {
845 0 : ::osl::MutexGuard aGuard( GetMutex() );
846 0 : maFocusListeners.addInterface( rxListener );
847 0 : if ( maFocusListeners.getLength() == 1 )
848 0 : xPeerWindow = xPeerWindow.query( getPeer() );
849 : }
850 0 : if ( xPeerWindow.is() )
851 0 : xPeerWindow->addFocusListener( &maFocusListeners );
852 0 : }
853 :
854 0 : void UnoControl::removeFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException, std::exception)
855 : {
856 0 : Reference< XWindow > xPeerWindow;
857 : {
858 0 : ::osl::MutexGuard aGuard( GetMutex() );
859 0 : if ( maFocusListeners.getLength() == 1 )
860 0 : xPeerWindow = xPeerWindow.query( getPeer() );
861 0 : maFocusListeners.removeInterface( rxListener );
862 : }
863 0 : if ( xPeerWindow.is() )
864 0 : xPeerWindow->removeFocusListener( &maFocusListeners );
865 0 : }
866 :
867 0 : void UnoControl::addKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException, std::exception)
868 : {
869 0 : Reference< XWindow > xPeerWindow;
870 : {
871 0 : ::osl::MutexGuard aGuard( GetMutex() );
872 0 : maKeyListeners.addInterface( rxListener );
873 0 : if ( maKeyListeners.getLength() == 1 )
874 0 : xPeerWindow = xPeerWindow.query( getPeer() );
875 : }
876 0 : if ( xPeerWindow.is() )
877 0 : xPeerWindow->addKeyListener( &maKeyListeners);
878 0 : }
879 :
880 0 : void UnoControl::removeKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException, std::exception)
881 : {
882 0 : Reference< XWindow > xPeerWindow;
883 : {
884 0 : ::osl::MutexGuard aGuard( GetMutex() );
885 0 : if ( maKeyListeners.getLength() == 1 )
886 0 : xPeerWindow = xPeerWindow.query( getPeer() );
887 0 : maKeyListeners.removeInterface( rxListener );
888 : }
889 0 : if ( xPeerWindow.is() )
890 0 : xPeerWindow->removeKeyListener( &maKeyListeners);
891 0 : }
892 :
893 0 : void UnoControl::addMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException, std::exception)
894 : {
895 0 : Reference< XWindow > xPeerWindow;
896 : {
897 0 : ::osl::MutexGuard aGuard( GetMutex() );
898 0 : maMouseListeners.addInterface( rxListener );
899 0 : if ( maMouseListeners.getLength() == 1 )
900 0 : xPeerWindow = xPeerWindow.query( getPeer() );
901 : }
902 0 : if ( xPeerWindow.is() )
903 0 : xPeerWindow->addMouseListener( &maMouseListeners);
904 0 : }
905 :
906 0 : void UnoControl::removeMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException, std::exception)
907 : {
908 0 : Reference< XWindow > xPeerWindow;
909 : {
910 0 : ::osl::MutexGuard aGuard( GetMutex() );
911 0 : if ( maMouseListeners.getLength() == 1 )
912 0 : xPeerWindow = xPeerWindow.query( getPeer() );
913 0 : maMouseListeners.removeInterface( rxListener );
914 : }
915 0 : if ( xPeerWindow.is() )
916 0 : xPeerWindow->removeMouseListener( &maMouseListeners );
917 0 : }
918 :
919 0 : void UnoControl::addMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException, std::exception)
920 : {
921 0 : Reference< XWindow > xPeerWindow;
922 : {
923 0 : ::osl::MutexGuard aGuard( GetMutex() );
924 0 : maMouseMotionListeners.addInterface( rxListener );
925 0 : if ( maMouseMotionListeners.getLength() == 1 )
926 0 : xPeerWindow = xPeerWindow.query( getPeer() );
927 : }
928 0 : if ( xPeerWindow.is() )
929 0 : xPeerWindow->addMouseMotionListener( &maMouseMotionListeners);
930 0 : }
931 :
932 0 : void UnoControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException, std::exception)
933 : {
934 0 : Reference< XWindow > xPeerWindow;
935 : {
936 0 : ::osl::MutexGuard aGuard( GetMutex() );
937 0 : if ( maMouseMotionListeners.getLength() == 1 )
938 0 : xPeerWindow = xPeerWindow.query( getPeer() );
939 0 : maMouseMotionListeners.removeInterface( rxListener );
940 : }
941 0 : if ( xPeerWindow.is() )
942 0 : xPeerWindow->removeMouseMotionListener( &maMouseMotionListeners );
943 0 : }
944 :
945 0 : void UnoControl::addPaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException, std::exception)
946 : {
947 0 : Reference< XWindow > xPeerWindow;
948 : {
949 0 : ::osl::MutexGuard aGuard( GetMutex() );
950 0 : maPaintListeners.addInterface( rxListener );
951 0 : if ( maPaintListeners.getLength() == 1 )
952 0 : xPeerWindow = xPeerWindow.query( getPeer() );
953 : }
954 0 : if ( xPeerWindow.is() )
955 0 : xPeerWindow->addPaintListener( &maPaintListeners);
956 0 : }
957 :
958 0 : void UnoControl::removePaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException, std::exception)
959 : {
960 0 : Reference< XWindow > xPeerWindow;
961 : {
962 0 : ::osl::MutexGuard aGuard( GetMutex() );
963 0 : if ( maPaintListeners.getLength() == 1 )
964 0 : xPeerWindow = xPeerWindow.query( getPeer() );
965 0 : maPaintListeners.removeInterface( rxListener );
966 : }
967 0 : if ( xPeerWindow.is() )
968 0 : xPeerWindow->removePaintListener( &maPaintListeners );
969 0 : }
970 :
971 : // XView
972 0 : sal_Bool UnoControl::setGraphics( const Reference< XGraphics >& rDevice ) throw(RuntimeException, std::exception)
973 : {
974 0 : Reference< XView > xView;
975 : {
976 0 : ::osl::MutexGuard aGuard( GetMutex() );
977 :
978 0 : mxGraphics = rDevice;
979 0 : xView = xView.query( getPeer() );
980 : }
981 0 : return xView.is() ? xView->setGraphics( rDevice ) : sal_True;
982 : }
983 :
984 0 : Reference< XGraphics > UnoControl::getGraphics( ) throw(RuntimeException, std::exception)
985 : {
986 0 : return mxGraphics;
987 : }
988 :
989 0 : awt::Size UnoControl::getSize( ) throw(RuntimeException, std::exception)
990 : {
991 0 : ::osl::MutexGuard aGuard( GetMutex() );
992 0 : return awt::Size( maComponentInfos.nWidth, maComponentInfos.nHeight );
993 : }
994 :
995 0 : void UnoControl::draw( sal_Int32 x, sal_Int32 y ) throw(RuntimeException, std::exception)
996 : {
997 0 : Reference< XWindowPeer > xDrawPeer;
998 0 : Reference< XView > xDrawPeerView;
999 :
1000 0 : bool bDisposeDrawPeer( false );
1001 : {
1002 0 : ::osl::MutexGuard aGuard( GetMutex() );
1003 :
1004 0 : xDrawPeer = ImplGetCompatiblePeer( true );
1005 0 : bDisposeDrawPeer = xDrawPeer.is() && ( xDrawPeer != getPeer() );
1006 :
1007 0 : xDrawPeerView.set( xDrawPeer, UNO_QUERY );
1008 0 : DBG_ASSERT( xDrawPeerView.is(), "UnoControl::draw: no peer!" );
1009 : }
1010 :
1011 0 : if ( xDrawPeerView.is() )
1012 : {
1013 0 : Reference< XVclWindowPeer > xWindowPeer;
1014 0 : xWindowPeer.set( xDrawPeer, UNO_QUERY );
1015 0 : if ( xWindowPeer.is() )
1016 0 : xWindowPeer->setDesignMode( mbDesignMode );
1017 0 : xDrawPeerView->draw( x, y );
1018 : }
1019 :
1020 0 : if ( bDisposeDrawPeer )
1021 0 : xDrawPeer->dispose();
1022 0 : }
1023 :
1024 0 : void UnoControl::setZoom( float fZoomX, float fZoomY ) throw(RuntimeException, std::exception)
1025 : {
1026 0 : Reference< XView > xView;
1027 : {
1028 0 : ::osl::MutexGuard aGuard( GetMutex() );
1029 :
1030 0 : maComponentInfos.nZoomX = fZoomX;
1031 0 : maComponentInfos.nZoomY = fZoomY;
1032 :
1033 0 : xView = xView.query( getPeer() );
1034 : }
1035 0 : if ( xView.is() )
1036 0 : xView->setZoom( fZoomX, fZoomY );
1037 0 : }
1038 :
1039 : // XControl
1040 0 : void UnoControl::setContext( const Reference< XInterface >& rxContext ) throw(RuntimeException, std::exception)
1041 : {
1042 0 : ::osl::MutexGuard aGuard( GetMutex() );
1043 :
1044 0 : mxContext = rxContext;
1045 0 : }
1046 :
1047 0 : Reference< XInterface > UnoControl::getContext( ) throw(RuntimeException, std::exception)
1048 : {
1049 0 : ::osl::MutexGuard aGuard( GetMutex() );
1050 :
1051 0 : return mxContext;
1052 : }
1053 :
1054 0 : void UnoControl::peerCreated()
1055 : {
1056 0 : Reference< XWindow > xWindow( getPeer(), UNO_QUERY );
1057 0 : if ( !xWindow.is() )
1058 0 : return;
1059 :
1060 0 : if ( maWindowListeners.getLength() )
1061 0 : xWindow->addWindowListener( &maWindowListeners );
1062 :
1063 0 : if ( maFocusListeners.getLength() )
1064 0 : xWindow->addFocusListener( &maFocusListeners );
1065 :
1066 0 : if ( maKeyListeners.getLength() )
1067 0 : xWindow->addKeyListener( &maKeyListeners );
1068 :
1069 0 : if ( maMouseListeners.getLength() )
1070 0 : xWindow->addMouseListener( &maMouseListeners );
1071 :
1072 0 : if ( maMouseMotionListeners.getLength() )
1073 0 : xWindow->addMouseMotionListener( &maMouseMotionListeners );
1074 :
1075 0 : if ( maPaintListeners.getLength() )
1076 0 : xWindow->addPaintListener( &maPaintListeners );
1077 : }
1078 :
1079 0 : void UnoControl::createPeer( const Reference< XToolkit >& rxToolkit, const Reference< XWindowPeer >& rParentPeer ) throw(RuntimeException, std::exception)
1080 : {
1081 0 : ::osl::ClearableMutexGuard aGuard( GetMutex() );
1082 0 : if ( !mxModel.is() )
1083 : {
1084 0 : RuntimeException aException;
1085 0 : aException.Message = "createPeer: no model!";
1086 0 : aException.Context = (XAggregation*)(::cppu::OWeakAggObject*)this;
1087 0 : throw( aException );
1088 : }
1089 :
1090 0 : if( !getPeer().is() )
1091 : {
1092 0 : mbCreatingPeer = true;
1093 :
1094 : WindowClass eType;
1095 0 : Reference< XToolkit > xToolkit = rxToolkit;
1096 0 : if( rParentPeer.is() && mxContext.is() )
1097 : {
1098 : // kein TopWindow
1099 0 : if ( !xToolkit.is() )
1100 0 : xToolkit = rParentPeer->getToolkit();
1101 0 : Any aAny = OWeakAggObject::queryInterface( ::getCppuType((const Reference< XControlContainer>*)0) );
1102 0 : Reference< XControlContainer > xC;
1103 0 : aAny >>= xC;
1104 0 : if( xC.is() )
1105 : // It's a container
1106 0 : eType = WindowClass_CONTAINER;
1107 : else
1108 0 : eType = WindowClass_SIMPLE;
1109 : }
1110 : else
1111 : { // This is only correct for Top Window
1112 0 : if( rParentPeer.is() )
1113 : {
1114 0 : if ( !xToolkit.is() )
1115 0 : xToolkit = rParentPeer->getToolkit();
1116 0 : eType = WindowClass_CONTAINER;
1117 : }
1118 : else
1119 : {
1120 0 : if ( !xToolkit.is() )
1121 0 : xToolkit = VCLUnoHelper::CreateToolkit();
1122 0 : eType = WindowClass_TOP;
1123 : }
1124 : }
1125 0 : WindowDescriptor aDescr;
1126 0 : aDescr.Type = eType;
1127 0 : aDescr.WindowServiceName = GetComponentServiceName();
1128 0 : aDescr.Parent = rParentPeer;
1129 0 : aDescr.Bounds = getPosSize();
1130 0 : aDescr.WindowAttributes = 0;
1131 :
1132 : // Border
1133 0 : Reference< XPropertySet > xPSet( mxModel, UNO_QUERY );
1134 0 : Reference< XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
1135 :
1136 0 : Any aVal;
1137 0 : OUString aPropName = GetPropertyName( BASEPROPERTY_BORDER );
1138 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1139 : {
1140 0 : aVal = xPSet->getPropertyValue( aPropName );
1141 0 : sal_Int16 n = sal_Int16();
1142 0 : if ( aVal >>= n )
1143 : {
1144 0 : if ( n )
1145 0 : aDescr.WindowAttributes |= WindowAttribute::BORDER;
1146 : else
1147 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::NOBORDER;
1148 : }
1149 : }
1150 :
1151 : // DESKTOP_AS_PARENT
1152 0 : if ( aDescr.Type == WindowClass_TOP )
1153 : {
1154 0 : aPropName = GetPropertyName( BASEPROPERTY_DESKTOP_AS_PARENT );
1155 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1156 : {
1157 0 : aVal = xPSet->getPropertyValue( aPropName );
1158 0 : bool b = bool();
1159 0 : if ( ( aVal >>= b ) && b)
1160 0 : aDescr.ParentIndex = -1;
1161 : }
1162 : }
1163 : // Moveable
1164 0 : aPropName = GetPropertyName( BASEPROPERTY_MOVEABLE );
1165 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1166 : {
1167 0 : aVal = xPSet->getPropertyValue( aPropName );
1168 0 : bool b = bool();
1169 0 : if ( ( aVal >>= b ) && b)
1170 0 : aDescr.WindowAttributes |= WindowAttribute::MOVEABLE;
1171 : }
1172 :
1173 : // Closeable
1174 0 : aPropName = GetPropertyName( BASEPROPERTY_CLOSEABLE );
1175 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1176 : {
1177 0 : aVal = xPSet->getPropertyValue( aPropName );
1178 0 : bool b = bool();
1179 0 : if ( ( aVal >>= b ) && b)
1180 0 : aDescr.WindowAttributes |= WindowAttribute::CLOSEABLE;
1181 : }
1182 :
1183 : // Dropdown
1184 0 : aPropName = GetPropertyName( BASEPROPERTY_DROPDOWN );
1185 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1186 : {
1187 0 : aVal = xPSet->getPropertyValue( aPropName );
1188 0 : bool b = bool();
1189 0 : if ( ( aVal >>= b ) && b)
1190 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::DROPDOWN;
1191 : }
1192 :
1193 : // Spin
1194 0 : aPropName = GetPropertyName( BASEPROPERTY_SPIN );
1195 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1196 : {
1197 0 : aVal = xPSet->getPropertyValue( aPropName );
1198 0 : bool b = bool();
1199 0 : if ( ( aVal >>= b ) && b)
1200 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::SPIN;
1201 : }
1202 :
1203 : // HScroll
1204 0 : aPropName = GetPropertyName( BASEPROPERTY_HSCROLL );
1205 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1206 : {
1207 0 : aVal = xPSet->getPropertyValue( aPropName );
1208 0 : bool b = bool();
1209 0 : if ( ( aVal >>= b ) && b)
1210 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::HSCROLL;
1211 : }
1212 :
1213 : // VScroll
1214 0 : aPropName = GetPropertyName( BASEPROPERTY_VSCROLL );
1215 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1216 : {
1217 0 : aVal = xPSet->getPropertyValue( aPropName );
1218 0 : bool b = bool();
1219 0 : if ( ( aVal >>= b ) && b)
1220 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::VSCROLL;
1221 : }
1222 :
1223 : // AutoHScroll
1224 0 : aPropName = GetPropertyName( BASEPROPERTY_AUTOHSCROLL );
1225 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1226 : {
1227 0 : aVal = xPSet->getPropertyValue( aPropName );
1228 0 : bool b = bool();
1229 0 : if ( ( aVal >>= b ) && b)
1230 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOHSCROLL;
1231 : }
1232 :
1233 : // AutoVScroll
1234 0 : aPropName = GetPropertyName( BASEPROPERTY_AUTOVSCROLL );
1235 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1236 : {
1237 0 : aVal = xPSet->getPropertyValue( aPropName );
1238 0 : bool b = bool();
1239 0 : if ( ( aVal >>= b ) && b)
1240 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOVSCROLL;
1241 : }
1242 :
1243 : //added for issue79712
1244 : //NoLabel
1245 0 : aPropName = GetPropertyName( BASEPROPERTY_NOLABEL );
1246 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1247 : {
1248 0 : aVal = xPSet->getPropertyValue( aPropName );
1249 0 : bool b = bool();
1250 0 : if ( ( aVal >>=b ) && b )
1251 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::NOLABEL;
1252 : }
1253 : //issue79712 ends
1254 :
1255 : // Align
1256 0 : aPropName = GetPropertyName( BASEPROPERTY_ALIGN );
1257 0 : if ( xInfo->hasPropertyByName( aPropName ) )
1258 : {
1259 0 : aVal = xPSet->getPropertyValue( aPropName );
1260 0 : sal_Int16 n = sal_Int16();
1261 0 : if ( aVal >>= n )
1262 : {
1263 0 : if ( n == PROPERTY_ALIGN_LEFT )
1264 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::LEFT;
1265 0 : else if ( n == PROPERTY_ALIGN_CENTER )
1266 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::CENTER;
1267 : else
1268 0 : aDescr.WindowAttributes |= VclWindowPeerAttribute::RIGHT;
1269 : }
1270 : }
1271 :
1272 : // Allow derivates to manipulate attributes
1273 0 : PrepareWindowDescriptor(aDescr);
1274 :
1275 : // create the peer
1276 0 : setPeer( xToolkit->createWindow( aDescr ) );
1277 :
1278 : // release the mutex guard (and work with copies of our members)
1279 : // this is necessary as our peer may lock the SolarMutex (actually, all currently known peers do), so calling
1280 : // into the peer with our own mutex locked may cause deadlocks
1281 : // (We _really_ need peers which do not use the SolarMutex. It's really pissing me off that from time to
1282 : // time deadlocks pop up because the low-level components like our peers use a mutex which ususally
1283 : // is locked at the top of the stack (it protects the global message looping). This is always dangerous, and
1284 : // can not always be solved by tampering with other mutexes.
1285 : // Unfortunately, the VCL used in the peers is not threadsafe, and by definition needs a locked SolarMutex.)
1286 : // 82300 - 12/21/00 - FS
1287 0 : UnoControlComponentInfos aComponentInfos(maComponentInfos);
1288 0 : bool bDesignMode(mbDesignMode);
1289 :
1290 0 : Reference< XGraphics > xGraphics( mxGraphics );
1291 0 : Reference< XView > xView ( getPeer(), UNO_QUERY_THROW );
1292 0 : Reference< XWindow > xWindow ( getPeer(), UNO_QUERY_THROW );
1293 :
1294 0 : aGuard.clear();
1295 :
1296 : // the updateFromModel is done without a locked mutex, too.
1297 : // The reason is that the only thing this method does is firing property changes, and this in general has
1298 : // to be done without locked mutexes (as every notification to external listeners).
1299 : // 82300 - 12/21/00 - FS
1300 0 : updateFromModel();
1301 :
1302 0 : xView->setZoom( aComponentInfos.nZoomX, aComponentInfos.nZoomY );
1303 :
1304 0 : setPosSize( aComponentInfos.nX, aComponentInfos.nY, aComponentInfos.nWidth, aComponentInfos.nHeight, aComponentInfos.nFlags );
1305 :
1306 0 : if( aComponentInfos.bVisible && !bDesignMode )
1307 : // Show only after setting the data
1308 0 : xWindow->setVisible( aComponentInfos.bVisible );
1309 :
1310 0 : if( !aComponentInfos.bEnable )
1311 0 : xWindow->setEnable( aComponentInfos.bEnable );
1312 :
1313 0 : xView->setGraphics( xGraphics );
1314 :
1315 0 : peerCreated();
1316 :
1317 0 : mbCreatingPeer = false;
1318 0 : }
1319 0 : }
1320 :
1321 0 : Reference< XWindowPeer > UnoControl::getPeer() throw(RuntimeException, std::exception)
1322 : {
1323 0 : ::osl::MutexGuard aGuard( GetMutex() );
1324 0 : return mxPeer;
1325 : }
1326 :
1327 0 : sal_Bool UnoControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException, std::exception)
1328 : {
1329 0 : ::osl::MutexGuard aGuard( GetMutex() );
1330 :
1331 0 : Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY );
1332 :
1333 : // query for the XPropertiesChangeListener - our delegator is allowed to overwrite this interface
1334 0 : Reference< XPropertiesChangeListener > xListener;
1335 0 : queryInterface( ::getCppuType( &xListener ) ) >>= xListener;
1336 :
1337 0 : if( xPropSet.is() )
1338 0 : xPropSet->removePropertiesChangeListener( xListener );
1339 :
1340 0 : mpData->bLocalizationSupport = false;
1341 0 : mxModel = rxModel;
1342 :
1343 0 : if( mxModel.is() )
1344 : {
1345 : try
1346 : {
1347 0 : xPropSet.set( mxModel, UNO_QUERY_THROW );
1348 0 : Reference< XPropertySetInfo > xPSI( xPropSet->getPropertySetInfo(), UNO_SET_THROW );
1349 :
1350 0 : Sequence< OUString> aNames = lcl_ImplGetPropertyNames( xPropSet );
1351 0 : xPropSet->addPropertiesChangeListener( aNames, xListener );
1352 :
1353 0 : mpData->bLocalizationSupport = xPSI->hasPropertyByName("ResourceResolver");
1354 : }
1355 0 : catch( const Exception& )
1356 : {
1357 : DBG_UNHANDLED_EXCEPTION();
1358 0 : mxModel.clear();
1359 : }
1360 : }
1361 :
1362 0 : return mxModel.is();
1363 : }
1364 :
1365 0 : Reference< XControlModel > UnoControl::getModel( ) throw(RuntimeException, std::exception)
1366 : {
1367 0 : return mxModel;
1368 : }
1369 :
1370 0 : Reference< XView > UnoControl::getView( ) throw(RuntimeException, std::exception)
1371 : {
1372 0 : return static_cast< XView* >( this );
1373 : }
1374 :
1375 0 : void UnoControl::setDesignMode( sal_Bool bOn ) throw(RuntimeException, std::exception)
1376 : {
1377 0 : ModeChangeEvent aModeChangeEvent;
1378 :
1379 0 : Reference< XWindow > xWindow;
1380 0 : Reference<XComponent> xAccessibleComp;
1381 : {
1382 0 : ::osl::MutexGuard aGuard( GetMutex() );
1383 0 : if ( bool(bOn) == mbDesignMode )
1384 0 : return;
1385 :
1386 : // remember this
1387 0 : mbDesignMode = bOn;
1388 0 : xWindow = xWindow.query( getPeer() );
1389 :
1390 0 : xAccessibleComp.set(maAccessibleContext, UNO_QUERY);
1391 0 : maAccessibleContext.clear();
1392 :
1393 0 : aModeChangeEvent.Source = *this;
1394 0 : aModeChangeEvent.NewMode = mbDesignMode ? OUString("design") : OUString("alive" );
1395 : }
1396 :
1397 : // dispose current AccessibleContext, if we have one - without Mutex lock
1398 : // (changing the design mode implies having a new implementation for this context,
1399 : // so the old one must be declared DEFUNC)
1400 0 : DisposeAccessibleContext(xAccessibleComp);
1401 :
1402 : // adjust the visibility of our window
1403 0 : if ( xWindow.is() )
1404 0 : xWindow->setVisible( !bOn );
1405 :
1406 : // and notify our mode listeners
1407 0 : maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent );
1408 : }
1409 :
1410 0 : sal_Bool UnoControl::isDesignMode( ) throw(RuntimeException, std::exception)
1411 : {
1412 0 : return mbDesignMode;
1413 : }
1414 :
1415 0 : sal_Bool UnoControl::isTransparent( ) throw(RuntimeException, std::exception)
1416 : {
1417 0 : return sal_False;
1418 : }
1419 :
1420 : // XServiceInfo
1421 0 : OUString UnoControl::getImplementationName( ) throw(RuntimeException, std::exception)
1422 : {
1423 : OSL_FAIL( "This method should be overloaded!" );
1424 0 : return OUString();
1425 : }
1426 :
1427 0 : sal_Bool UnoControl::supportsService( const OUString& rServiceName ) throw(RuntimeException, std::exception)
1428 : {
1429 0 : return cppu::supportsService(this, rServiceName);
1430 : }
1431 :
1432 0 : Sequence< OUString > UnoControl::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
1433 : {
1434 0 : OUString sName( "com.sun.star.awt.UnoControl" );
1435 0 : return Sequence< OUString >( &sName, 1 );
1436 : }
1437 :
1438 :
1439 0 : Reference< XAccessibleContext > SAL_CALL UnoControl::getAccessibleContext( ) throw (RuntimeException, std::exception)
1440 : {
1441 : // creation of the context will certainly require the SolarMutex ...
1442 0 : SolarMutexGuard aSolarGuard;
1443 0 : ::osl::MutexGuard aGuard( GetMutex() );
1444 :
1445 0 : Reference< XAccessibleContext > xCurrentContext( maAccessibleContext.get(), UNO_QUERY );
1446 0 : if ( !xCurrentContext.is() )
1447 : {
1448 0 : if ( !mbDesignMode )
1449 : { // in alive mode, use the AccessibleContext of the peer
1450 0 : Reference< XAccessible > xPeerAcc( getPeer(), UNO_QUERY );
1451 0 : if ( xPeerAcc.is() )
1452 0 : xCurrentContext = xPeerAcc->getAccessibleContext( );
1453 : }
1454 : else
1455 : // in design mode, use a fallback
1456 0 : xCurrentContext = ::toolkit::OAccessibleControlContext::create( this );
1457 :
1458 : DBG_ASSERT( xCurrentContext.is(), "UnoControl::getAccessibleContext: invalid context (invalid peer?)!" );
1459 0 : maAccessibleContext = xCurrentContext;
1460 :
1461 : // get notified when the context is disposed
1462 0 : Reference< XComponent > xContextComp( xCurrentContext, UNO_QUERY );
1463 0 : if ( xContextComp.is() )
1464 0 : xContextComp->addEventListener( this );
1465 : // In an ideal world, this is not necessary - there the object would be released as soon as it has been
1466 : // disposed, and thus our weak reference would be empty, too.
1467 : // But 'til this ideal world comes (means 'til we do never have any refcount/lifetime bugs anymore), we
1468 : // need to listen for disposal and reset our weak reference then.
1469 : }
1470 :
1471 0 : return xCurrentContext;
1472 : }
1473 :
1474 0 : void SAL_CALL UnoControl::addModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException, std::exception)
1475 : {
1476 0 : ::osl::MutexGuard aGuard( GetMutex() );
1477 0 : maModeChangeListeners.addInterface( _rxListener );
1478 0 : }
1479 :
1480 0 : void SAL_CALL UnoControl::removeModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException, std::exception)
1481 : {
1482 0 : ::osl::MutexGuard aGuard( GetMutex() );
1483 0 : maModeChangeListeners.removeInterface( _rxListener );
1484 0 : }
1485 :
1486 0 : void SAL_CALL UnoControl::addModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException, std::exception)
1487 : {
1488 0 : throw NoSupportException( );
1489 : }
1490 :
1491 0 : void SAL_CALL UnoControl::removeModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException, std::exception)
1492 : {
1493 0 : throw NoSupportException( );
1494 : }
1495 :
1496 :
1497 0 : awt::Point SAL_CALL UnoControl::convertPointToLogic( const awt::Point& i_Point, ::sal_Int16 i_TargetUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1498 : {
1499 0 : Reference< XUnitConversion > xPeerConversion;
1500 : {
1501 0 : ::osl::MutexGuard aGuard( GetMutex() );
1502 0 : xPeerConversion = xPeerConversion.query( getPeer() );
1503 : }
1504 0 : if ( xPeerConversion.is() )
1505 0 : return xPeerConversion->convertPointToLogic( i_Point, i_TargetUnit );
1506 0 : return awt::Point( );
1507 : }
1508 :
1509 :
1510 0 : awt::Point SAL_CALL UnoControl::convertPointToPixel( const awt::Point& i_Point, ::sal_Int16 i_SourceUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1511 : {
1512 0 : Reference< XUnitConversion > xPeerConversion;
1513 : {
1514 0 : ::osl::MutexGuard aGuard( GetMutex() );
1515 0 : xPeerConversion = xPeerConversion.query( getPeer() );
1516 : }
1517 0 : if ( xPeerConversion.is() )
1518 0 : return xPeerConversion->convertPointToPixel( i_Point, i_SourceUnit );
1519 0 : return awt::Point( );
1520 : }
1521 :
1522 :
1523 0 : awt::Size SAL_CALL UnoControl::convertSizeToLogic( const awt::Size& i_Size, ::sal_Int16 i_TargetUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1524 : {
1525 0 : Reference< XUnitConversion > xPeerConversion;
1526 : {
1527 0 : ::osl::MutexGuard aGuard( GetMutex() );
1528 0 : xPeerConversion = xPeerConversion.query( getPeer() );
1529 : }
1530 0 : if ( xPeerConversion.is() )
1531 0 : return xPeerConversion->convertSizeToLogic( i_Size, i_TargetUnit );
1532 0 : return awt::Size( );
1533 : }
1534 :
1535 :
1536 0 : awt::Size SAL_CALL UnoControl::convertSizeToPixel( const awt::Size& i_Size, ::sal_Int16 i_SourceUnit ) throw (IllegalArgumentException, RuntimeException, std::exception)
1537 : {
1538 0 : Reference< XUnitConversion > xPeerConversion;
1539 : {
1540 0 : ::osl::MutexGuard aGuard( GetMutex() );
1541 0 : xPeerConversion = xPeerConversion.query( getPeer() );
1542 : }
1543 0 : if ( xPeerConversion.is() )
1544 0 : return xPeerConversion->convertSizeToPixel( i_Size, i_SourceUnit );
1545 0 : return awt::Size( );
1546 : }
1547 :
1548 :
1549 0 : uno::Reference< awt::XStyleSettings > SAL_CALL UnoControl::getStyleSettings() throw (RuntimeException, std::exception)
1550 : {
1551 0 : Reference< awt::XStyleSettingsSupplier > xPeerSupplier;
1552 : {
1553 0 : ::osl::MutexGuard aGuard( GetMutex() );
1554 0 : xPeerSupplier = xPeerSupplier.query( getPeer() );
1555 : }
1556 0 : if ( xPeerSupplier.is() )
1557 0 : return xPeerSupplier->getStyleSettings();
1558 0 : return NULL;
1559 : }
1560 :
1561 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|