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