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