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