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