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