1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10*6d739b60SAndrew Rist * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6d739b60SAndrew Rist * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19*6d739b60SAndrew Rist * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <classes/actiontriggerseparatorpropertyset.hxx> 28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 29cdf0e10cSrcweir #include <cppuhelper/proptypehlp.hxx> 30cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 31cdf0e10cSrcweir #include <vcl/svapp.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace cppu; 35cdf0e10cSrcweir using namespace com::sun::star::uno; 36cdf0e10cSrcweir using namespace com::sun::star::beans; 37cdf0e10cSrcweir using namespace com::sun::star::lang; 38cdf0e10cSrcweir using namespace com::sun::star::awt; 39cdf0e10cSrcweir 40cdf0e10cSrcweir // Handles for properties 41cdf0e10cSrcweir // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!) 42cdf0e10cSrcweir // We use an enum to define these handles, to use all numbers from 0 to nn and 43cdf0e10cSrcweir // if you add someone, you don't must control this! 44cdf0e10cSrcweir // But don't forget to change values of follow defines, if you do something with this enum! 45cdf0e10cSrcweir enum EPROPERTIES 46cdf0e10cSrcweir { 47cdf0e10cSrcweir HANDLE_TYPE, 48cdf0e10cSrcweir PROPERTYCOUNT 49cdf0e10cSrcweir }; 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace framework 52cdf0e10cSrcweir { 53cdf0e10cSrcweir 54cdf0e10cSrcweir ActionTriggerSeparatorPropertySet::ActionTriggerSeparatorPropertySet( const Reference< XMultiServiceFactory >& /*ServiceManager*/ ) 55cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 56cdf0e10cSrcweir , OBroadcastHelper ( m_aLock.getShareableOslMutex() ) 57cdf0e10cSrcweir , OPropertySetHelper ( *SAL_STATIC_CAST( OBroadcastHelper *, this ) ) 58cdf0e10cSrcweir , OWeakObject ( ) 59cdf0e10cSrcweir , m_nSeparatorType( 0 ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir ActionTriggerSeparatorPropertySet::~ActionTriggerSeparatorPropertySet() 64cdf0e10cSrcweir { 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir // XInterface 68cdf0e10cSrcweir Any SAL_CALL ActionTriggerSeparatorPropertySet::queryInterface( const Type& aType ) 69cdf0e10cSrcweir throw ( RuntimeException ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir Any a = ::cppu::queryInterface( 72cdf0e10cSrcweir aType , 73cdf0e10cSrcweir SAL_STATIC_CAST( XServiceInfo*, this )); 74cdf0e10cSrcweir 75cdf0e10cSrcweir if( a.hasValue() ) 76cdf0e10cSrcweir return a; 77cdf0e10cSrcweir else 78cdf0e10cSrcweir { 79cdf0e10cSrcweir a = OPropertySetHelper::queryInterface( aType ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir if( a.hasValue() ) 82cdf0e10cSrcweir return a; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir return OWeakObject::queryInterface( aType ); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir void ActionTriggerSeparatorPropertySet::acquire() throw() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir OWeakObject::acquire(); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir void ActionTriggerSeparatorPropertySet::release() throw() 94cdf0e10cSrcweir { 95cdf0e10cSrcweir OWeakObject::release(); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir // XServiceInfo 99cdf0e10cSrcweir ::rtl::OUString SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationName() 100cdf0e10cSrcweir throw ( RuntimeException ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGERSEPARATOR )); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::supportsService( const ::rtl::OUString& ServiceName ) 106cdf0e10cSrcweir throw ( RuntimeException ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR )) 109cdf0e10cSrcweir return sal_True; 110cdf0e10cSrcweir 111cdf0e10cSrcweir return sal_False; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ActionTriggerSeparatorPropertySet::getSupportedServiceNames() 115cdf0e10cSrcweir throw ( RuntimeException ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir Sequence< ::rtl::OUString > seqServiceNames( 1 ); 118cdf0e10cSrcweir seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR )); 119cdf0e10cSrcweir return seqServiceNames; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir // XTypeProvider 123cdf0e10cSrcweir Sequence< Type > SAL_CALL ActionTriggerSeparatorPropertySet::getTypes() throw ( RuntimeException ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir // Optimize this method ! 126cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 127cdf0e10cSrcweir // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! 128cdf0e10cSrcweir static ::cppu::OTypeCollection* pTypeCollection = NULL ; 129cdf0e10cSrcweir 130cdf0e10cSrcweir if ( pTypeCollection == NULL ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir // Ready for multithreading; get global mutex for first call of this method only! see before 133cdf0e10cSrcweir osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 134cdf0e10cSrcweir 135cdf0e10cSrcweir // Control these pointer again ... it can be, that another instance will be faster then these! 136cdf0e10cSrcweir if ( pTypeCollection == NULL ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir // Create a static typecollection ... 139cdf0e10cSrcweir static ::cppu::OTypeCollection aTypeCollection( 140cdf0e10cSrcweir ::getCppuType(( const Reference< XPropertySet >*)NULL ) , 141cdf0e10cSrcweir ::getCppuType(( const Reference< XFastPropertySet >*)NULL ) , 142cdf0e10cSrcweir ::getCppuType(( const Reference< XMultiPropertySet >*)NULL ) , 143cdf0e10cSrcweir ::getCppuType(( const Reference< XServiceInfo >*)NULL ) , 144cdf0e10cSrcweir ::getCppuType(( const Reference< XTypeProvider >*)NULL ) ) ; 145cdf0e10cSrcweir 146cdf0e10cSrcweir // ... and set his address to static pointer! 147cdf0e10cSrcweir pTypeCollection = &aTypeCollection ; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir return pTypeCollection->getTypes() ; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationId() throw ( RuntimeException ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir // Create one Id for all instances of this class. 157cdf0e10cSrcweir // Use ethernet address to do this! (sal_True) 158cdf0e10cSrcweir 159cdf0e10cSrcweir // Optimize this method 160cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 161cdf0e10cSrcweir // For the first call; pID is NULL - for the second call pID is different from NULL! 162cdf0e10cSrcweir static ::cppu::OImplementationId* pID = NULL ; 163cdf0e10cSrcweir 164cdf0e10cSrcweir if ( pID == NULL ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir // Ready for multithreading; get global mutex for first call of this method only! see before 167cdf0e10cSrcweir osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 168cdf0e10cSrcweir 169cdf0e10cSrcweir // Control these pointer again ... it can be, that another instance will be faster then these! 170cdf0e10cSrcweir if ( pID == NULL ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir // Create a new static ID ... 173cdf0e10cSrcweir static ::cppu::OImplementationId aID( sal_False ) ; 174cdf0e10cSrcweir // ... and set his address to static pointer! 175cdf0e10cSrcweir pID = &aID ; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir return pID->getImplementationId() ; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 183cdf0e10cSrcweir // OPropertySetHelper implementation 184cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 185cdf0e10cSrcweir 186cdf0e10cSrcweir sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::convertFastPropertyValue( 187cdf0e10cSrcweir Any& aConvertedValue, 188cdf0e10cSrcweir Any& aOldValue, 189cdf0e10cSrcweir sal_Int32 nHandle, 190cdf0e10cSrcweir const Any& aValue ) 191cdf0e10cSrcweir throw( IllegalArgumentException ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()". 194cdf0e10cSrcweir // Return sal_True, if changed - else return sal_False. 195cdf0e10cSrcweir // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!! 196cdf0e10cSrcweir // Initialize return value with sal_False !!! 197cdf0e10cSrcweir // (Handle can be invalid) 198cdf0e10cSrcweir sal_Bool bReturn = sal_False; 199cdf0e10cSrcweir 200cdf0e10cSrcweir switch( nHandle ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir case HANDLE_TYPE: 203cdf0e10cSrcweir bReturn = impl_tryToChangeProperty( m_nSeparatorType, aValue, aOldValue, aConvertedValue ); 204cdf0e10cSrcweir break; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir // Return state of operation. 208cdf0e10cSrcweir return bReturn; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir 212cdf0e10cSrcweir void SAL_CALL ActionTriggerSeparatorPropertySet::setFastPropertyValue_NoBroadcast( 213cdf0e10cSrcweir sal_Int32 nHandle, const Any& aValue ) 214cdf0e10cSrcweir throw( Exception ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir // Search for right handle ... and try to set property value. 219cdf0e10cSrcweir switch( nHandle ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir case HANDLE_TYPE: 222cdf0e10cSrcweir aValue >>= m_nSeparatorType; 223cdf0e10cSrcweir break; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir void SAL_CALL ActionTriggerSeparatorPropertySet::getFastPropertyValue( 228cdf0e10cSrcweir Any& aValue, sal_Int32 nHandle ) const 229cdf0e10cSrcweir { 230cdf0e10cSrcweir ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 231cdf0e10cSrcweir 232cdf0e10cSrcweir // Search for right handle ... and try to get property value. 233cdf0e10cSrcweir switch( nHandle ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir case HANDLE_TYPE: 236cdf0e10cSrcweir aValue <<= m_nSeparatorType; 237cdf0e10cSrcweir break; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerSeparatorPropertySet::getInfoHelper() 242cdf0e10cSrcweir { 243cdf0e10cSrcweir // Optimize this method ! 244cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 245cdf0e10cSrcweir // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL! 246cdf0e10cSrcweir static OPropertyArrayHelper* pInfoHelper = NULL; 247cdf0e10cSrcweir 248cdf0e10cSrcweir if( pInfoHelper == NULL ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir // Ready for multithreading 251cdf0e10cSrcweir ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 252cdf0e10cSrcweir // Control this pointer again, another instance can be faster then these! 253cdf0e10cSrcweir if( pInfoHelper == NULL ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir // Define static member to give structure of properties to baseclass "OPropertySetHelper". 256cdf0e10cSrcweir // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable. 257cdf0e10cSrcweir // "sal_True" say: Table is sorted by name. 258cdf0e10cSrcweir static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True ); 259cdf0e10cSrcweir pInfoHelper = &aInfoHelper; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir return (*pInfoHelper); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL ActionTriggerSeparatorPropertySet::getPropertySetInfo() 267cdf0e10cSrcweir throw ( RuntimeException ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir // Optimize this method ! 270cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 271cdf0e10cSrcweir // For the first call; pInfo is NULL - for the second call pInfo is different from NULL! 272cdf0e10cSrcweir static Reference< XPropertySetInfo >* pInfo = NULL ; 273cdf0e10cSrcweir 274cdf0e10cSrcweir if( pInfo == NULL ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir // Ready for multithreading 277cdf0e10cSrcweir ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 278cdf0e10cSrcweir // Control this pointer again, another instance can be faster then these! 279cdf0e10cSrcweir if( pInfo == NULL ) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir // Create structure of propertysetinfo for baseclass "OPropertySetHelper". 282cdf0e10cSrcweir // (Use method "getInfoHelper()".) 283cdf0e10cSrcweir static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 284cdf0e10cSrcweir pInfo = &xInfo; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir } 287cdf0e10cSrcweir 288cdf0e10cSrcweir return (*pInfo); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir const Sequence< Property > ActionTriggerSeparatorPropertySet::impl_getStaticPropertyDescriptor() 292cdf0e10cSrcweir { 293cdf0e10cSrcweir static const Property pActionTriggerPropertys[] = 294cdf0e10cSrcweir { 295cdf0e10cSrcweir Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SeparatorType" )), HANDLE_TYPE, ::getCppuType((sal_Int16*)0), PropertyAttribute::TRANSIENT ) 296cdf0e10cSrcweir }; 297cdf0e10cSrcweir 298cdf0e10cSrcweir // Use it to initialize sequence! 299cdf0e10cSrcweir static const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // Return static "PropertyDescriptor" 302cdf0e10cSrcweir return seqActionTriggerPropertyDescriptor ; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir 306cdf0e10cSrcweir //****************************************************************************************************************************** 307cdf0e10cSrcweir // private method 308cdf0e10cSrcweir //****************************************************************************************************************************** 309cdf0e10cSrcweir sal_Bool ActionTriggerSeparatorPropertySet::impl_tryToChangeProperty( 310cdf0e10cSrcweir sal_Int16 aCurrentValue , 311cdf0e10cSrcweir const Any& aNewValue , 312cdf0e10cSrcweir Any& aOldValue , 313cdf0e10cSrcweir Any& aConvertedValue ) 314cdf0e10cSrcweir throw( IllegalArgumentException ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir // Set default return value if method failed. 317cdf0e10cSrcweir sal_Bool bReturn = sal_False; 318cdf0e10cSrcweir // Get new value from any. 319cdf0e10cSrcweir // IllegalArgumentException() can be thrown! 320cdf0e10cSrcweir sal_Int16 aValue = 0; 321cdf0e10cSrcweir convertPropertyValue( aValue, aNewValue ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir // If value change ... 324cdf0e10cSrcweir if( aValue != aCurrentValue ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir // ... set information of change. 327cdf0e10cSrcweir aOldValue <<= aCurrentValue ; 328cdf0e10cSrcweir aConvertedValue <<= aValue ; 329cdf0e10cSrcweir // Return OK - "value will be change ..." 330cdf0e10cSrcweir bReturn = sal_True; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir else 333cdf0e10cSrcweir { 334cdf0e10cSrcweir // ... clear information of return parameter! 335cdf0e10cSrcweir aOldValue.clear () ; 336cdf0e10cSrcweir aConvertedValue.clear () ; 337cdf0e10cSrcweir // Return NOTHING - "value will not be change ..." 338cdf0e10cSrcweir bReturn = sal_False; 339cdf0e10cSrcweir } 340cdf0e10cSrcweir 341cdf0e10cSrcweir return bReturn; 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346