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