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/actiontriggerpropertyset.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 //struct SAL_DLLPUBLIC_IMPORT ::cppu::OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType >; 41 42 // Handles for properties 43 // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!) 44 // We use an enum to define these handles, to use all numbers from 0 to nn and 45 // if you add someone, you don't must control this! 46 // But don't forget to change values of follow defines, if you do something with this enum! 47 enum EPROPERTIES 48 { 49 HANDLE_COMMANDURL, 50 HANDLE_HELPURL, 51 HANDLE_IMAGE, 52 HANDLE_SUBCONTAINER, 53 HANDLE_TEXT, 54 PROPERTYCOUNT 55 }; 56 57 namespace framework 58 { 59 60 ActionTriggerPropertySet::ActionTriggerPropertySet( const Reference< XMultiServiceFactory >& /*xServiceManager*/ ) 61 : ThreadHelpBase ( &Application::GetSolarMutex() ) 62 , OBroadcastHelper ( m_aLock.getShareableOslMutex() ) 63 , OPropertySetHelper ( *SAL_STATIC_CAST( OBroadcastHelper *, this )) 64 , OWeakObject () 65 , m_xBitmap ( 0 ) 66 , m_xActionTriggerContainer( 0 ) 67 { 68 } 69 70 ActionTriggerPropertySet::~ActionTriggerPropertySet() 71 { 72 } 73 74 // XInterface 75 Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType ) 76 { 77 Any a = ::cppu::queryInterface( 78 aType , 79 SAL_STATIC_CAST( XServiceInfo*, this ), 80 SAL_STATIC_CAST( XTypeProvider*, this )); 81 82 if( a.hasValue() ) 83 return a; 84 else 85 { 86 a = OPropertySetHelper::queryInterface( aType ); 87 88 if( a.hasValue() ) 89 return a; 90 } 91 92 return OWeakObject::queryInterface( aType ); 93 } 94 95 void SAL_CALL ActionTriggerPropertySet::acquire() throw () 96 { 97 OWeakObject::acquire(); 98 } 99 100 void SAL_CALL ActionTriggerPropertySet::release() throw () 101 { 102 OWeakObject::release(); 103 } 104 105 106 // XServiceInfo 107 ::rtl::OUString SAL_CALL ActionTriggerPropertySet::getImplementationName() 108 { 109 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGER )); 110 } 111 112 sal_Bool SAL_CALL ActionTriggerPropertySet::supportsService( const ::rtl::OUString& ServiceName ) 113 { 114 if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGER )) 115 return sal_True; 116 117 return sal_False; 118 } 119 120 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerPropertySet::getSupportedServiceNames() 121 { 122 Sequence< ::rtl::OUString > seqServiceNames( 1 ); 123 seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER )); 124 return seqServiceNames; 125 } 126 127 // XTypeProvider 128 Sequence< Type > SAL_CALL ActionTriggerPropertySet::getTypes() 129 { 130 // Optimize this method ! 131 // We initialize a static variable only one time. And we don't must use a mutex at every call! 132 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! 133 static ::cppu::OTypeCollection* pTypeCollection = NULL ; 134 135 if ( pTypeCollection == NULL ) 136 { 137 // Ready for multithreading; get global mutex for first call of this method only! see before 138 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 139 140 // Control these pointer again ... it can be, that another instance will be faster then these! 141 if ( pTypeCollection == NULL ) 142 { 143 // Create a static typecollection ... 144 static ::cppu::OTypeCollection aTypeCollection( 145 ::getCppuType(( const Reference< XPropertySet >*)NULL ) , 146 ::getCppuType(( const Reference< XFastPropertySet >*)NULL ) , 147 ::getCppuType(( const Reference< XMultiPropertySet >*)NULL ) , 148 ::getCppuType(( const Reference< XServiceInfo >*)NULL ) , 149 ::getCppuType(( const Reference< XTypeProvider >*)NULL ) ) ; 150 151 // ... and set his address to static pointer! 152 pTypeCollection = &aTypeCollection ; 153 } 154 } 155 156 return pTypeCollection->getTypes() ; 157 } 158 159 Sequence< sal_Int8 > SAL_CALL ActionTriggerPropertySet::getImplementationId() 160 { 161 // Create one Id for all instances of this class. 162 // Use ethernet address to do this! (sal_True) 163 164 // Optimize this method 165 // We initialize a static variable only one time. And we don't must use a mutex at every call! 166 // For the first call; pID is NULL - for the second call pID is different from NULL! 167 static ::cppu::OImplementationId* pID = NULL ; 168 169 if ( pID == NULL ) 170 { 171 // Ready for multithreading; get global mutex for first call of this method only! see before 172 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 173 174 // Control these pointer again ... it can be, that another instance will be faster then these! 175 if ( pID == NULL ) 176 { 177 // Create a new static ID ... 178 static ::cppu::OImplementationId aID( sal_False ) ; 179 // ... and set his address to static pointer! 180 pID = &aID ; 181 } 182 } 183 184 return pID->getImplementationId() ; 185 } 186 187 //--------------------------------------------------------------------------------------------------------- 188 // OPropertySetHelper implementation 189 //--------------------------------------------------------------------------------------------------------- 190 191 sal_Bool SAL_CALL ActionTriggerPropertySet::convertFastPropertyValue( 192 Any& aConvertedValue, 193 Any& aOldValue, 194 sal_Int32 nHandle, 195 const Any& aValue ) 196 { 197 // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()". 198 // Return sal_True, if changed - else return sal_False. 199 // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!! 200 // Initialize return value with sal_False !!! 201 // (Handle can be invalid) 202 sal_Bool bReturn = sal_False; 203 204 switch( nHandle ) 205 { 206 case HANDLE_COMMANDURL: 207 bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue ); 208 break; 209 210 case HANDLE_HELPURL: 211 bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue ) ; 212 break; 213 214 case HANDLE_IMAGE: 215 bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue ) ; 216 break; 217 218 case HANDLE_SUBCONTAINER: 219 bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue ); 220 break; 221 222 case HANDLE_TEXT: 223 bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue ) ; 224 break; 225 } 226 227 // Return state of operation. 228 return bReturn; 229 } 230 231 232 void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast( 233 sal_Int32 nHandle, const Any& aValue ) 234 { 235 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 236 237 // Search for right handle ... and try to set property value. 238 switch( nHandle ) 239 { 240 case HANDLE_COMMANDURL: 241 aValue >>= m_aCommandURL; 242 break; 243 244 case HANDLE_HELPURL: 245 aValue >>= m_aHelpURL; 246 break; 247 248 case HANDLE_IMAGE: 249 aValue >>= m_xBitmap; 250 break; 251 252 case HANDLE_SUBCONTAINER: 253 aValue >>= m_xActionTriggerContainer; 254 break; 255 256 case HANDLE_TEXT: 257 aValue >>= m_aText; 258 break; 259 } 260 } 261 262 void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue( 263 Any& aValue, sal_Int32 nHandle ) const 264 { 265 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 266 267 // Search for right handle ... and try to get property value. 268 switch( nHandle ) 269 { 270 case HANDLE_COMMANDURL: 271 aValue <<= m_aCommandURL; 272 break; 273 274 case HANDLE_HELPURL: 275 aValue <<= m_aHelpURL; 276 break; 277 278 case HANDLE_IMAGE: 279 aValue <<= m_xBitmap; 280 break; 281 282 case HANDLE_SUBCONTAINER: 283 aValue <<= m_xActionTriggerContainer; 284 break; 285 286 case HANDLE_TEXT: 287 aValue <<= m_aText; 288 break; 289 } 290 } 291 292 ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerPropertySet::getInfoHelper() 293 { 294 // Optimize this method ! 295 // We initialize a static variable only one time. And we don't must use a mutex at every call! 296 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL! 297 static OPropertyArrayHelper* pInfoHelper = NULL; 298 299 if( pInfoHelper == NULL ) 300 { 301 // Ready for multithreading 302 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 303 // Control this pointer again, another instance can be faster then these! 304 if( pInfoHelper == NULL ) 305 { 306 // Define static member to give structure of properties to baseclass "OPropertySetHelper". 307 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable. 308 // "sal_True" say: Table is sorted by name. 309 static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True ); 310 pInfoHelper = &aInfoHelper; 311 } 312 } 313 314 return (*pInfoHelper); 315 } 316 317 Reference< XPropertySetInfo > SAL_CALL ActionTriggerPropertySet::getPropertySetInfo() 318 { 319 // Optimize this method ! 320 // We initialize a static variable only one time. And we don't must use a mutex at every call! 321 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL! 322 static Reference< XPropertySetInfo >* pInfo = NULL ; 323 324 if( pInfo == NULL ) 325 { 326 // Ready for multithreading 327 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() ); 328 // Control this pointer again, another instance can be faster then these! 329 if( pInfo == NULL ) 330 { 331 // Create structure of propertysetinfo for baseclass "OPropertySetHelper". 332 // (Use method "getInfoHelper()".) 333 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 334 pInfo = &xInfo; 335 } 336 } 337 338 return (*pInfo); 339 } 340 341 const Sequence< Property > ActionTriggerPropertySet::impl_getStaticPropertyDescriptor() 342 { 343 static const Property pActionTriggerPropertys[] = 344 { 345 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )), HANDLE_COMMANDURL , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ), 346 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpURL" )), HANDLE_HELPURL , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ), 347 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Image" )), HANDLE_IMAGE , ::getCppuType((Reference<XBitmap>*)0) , PropertyAttribute::TRANSIENT ), 348 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubContainer" )), HANDLE_SUBCONTAINER , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ), 349 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )), HANDLE_TEXT , ::getCppuType((Reference<XInterface>*)0) , PropertyAttribute::TRANSIENT ) 350 }; 351 352 // Use it to initialize sequence! 353 static const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT ); 354 355 // Return static "PropertyDescriptor" 356 return seqActionTriggerPropertyDescriptor ; 357 } 358 359 360 //****************************************************************************************************************************** 361 // private method 362 //****************************************************************************************************************************** 363 sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty( 364 const ::rtl::OUString& sCurrentValue , 365 const Any& aNewValue , 366 Any& aOldValue , 367 Any& aConvertedValue ) 368 { 369 // Set default return value if method failed. 370 sal_Bool bReturn = sal_False; 371 // Get new value from any. 372 // IllegalArgumentException() can be thrown! 373 ::rtl::OUString sValue ; 374 convertPropertyValue( sValue, aNewValue ); 375 376 // If value change ... 377 if( sValue != sCurrentValue ) 378 { 379 // ... set information of change. 380 aOldValue <<= sCurrentValue ; 381 aConvertedValue <<= sValue ; 382 // Return OK - "value will be change ..." 383 bReturn = sal_True; 384 } 385 else 386 { 387 // ... clear information of return parameter! 388 aOldValue.clear () ; 389 aConvertedValue.clear () ; 390 // Return NOTHING - "value will not be change ..." 391 bReturn = sal_False; 392 } 393 394 return bReturn; 395 } 396 397 398 sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty( 399 const Reference< XBitmap > aCurrentValue , 400 const Any& aNewValue , 401 Any& aOldValue , 402 Any& aConvertedValue ) 403 { 404 // Set default return value if method failed. 405 sal_Bool bReturn = sal_False; 406 // Get new value from any. 407 // IllegalArgumentException() can be thrown! 408 Reference< XBitmap > aValue ; 409 convertPropertyValue( aValue, aNewValue ); 410 411 // If value change ... 412 if( aValue != aCurrentValue ) 413 { 414 // ... set information of change. 415 aOldValue <<= aCurrentValue ; 416 aConvertedValue <<= aValue ; 417 // Return OK - "value will be change ..." 418 bReturn = sal_True; 419 } 420 else 421 { 422 // ... clear information of return parameter! 423 aOldValue.clear () ; 424 aConvertedValue.clear () ; 425 // Return NOTHING - "value will not be change ..." 426 bReturn = sal_False; 427 } 428 429 return bReturn; 430 } 431 432 sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty( 433 const Reference< XInterface > aCurrentValue , 434 const Any& aNewValue , 435 Any& aOldValue , 436 Any& aConvertedValue ) 437 { 438 // Set default return value if method failed. 439 sal_Bool bReturn = sal_False; 440 // Get new value from any. 441 // IllegalArgumentException() can be thrown! 442 Reference< XInterface > aValue ; 443 convertPropertyValue( aValue, aNewValue ); 444 445 // If value change ... 446 if( aValue != aCurrentValue ) 447 { 448 // ... set information of change. 449 aOldValue <<= aCurrentValue ; 450 aConvertedValue <<= aValue ; 451 // Return OK - "value will be change ..." 452 bReturn = sal_True; 453 } 454 else 455 { 456 // ... clear information of return parameter! 457 aOldValue.clear () ; 458 aConvertedValue.clear () ; 459 // Return NOTHING - "value will not be change ..." 460 bReturn = sal_False; 461 } 462 463 return bReturn; 464 } 465 466 } 467