Update ooo320-m1
[ooovba.git] / framework / source / classes / actiontriggerpropertyset.cxx
blob6a7231685af0fba6e8711723af668c9d9622d2ca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: actiontriggerpropertyset.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include <classes/actiontriggerpropertyset.hxx>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <cppuhelper/proptypehlp.hxx>
37 #include <cppuhelper/typeprovider.hxx>
38 #include <vcl/svapp.hxx>
41 using namespace cppu;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::lang;
45 using namespace com::sun::star::awt;
47 // Handles for properties
48 // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
49 // We use an enum to define these handles, to use all numbers from 0 to nn and
50 // if you add someone, you don't must control this!
51 // But don't forget to change values of follow defines, if you do something with this enum!
52 enum EPROPERTIES
54 HANDLE_COMMANDURL,
55 HANDLE_HELPURL,
56 HANDLE_IMAGE,
57 HANDLE_SUBCONTAINER,
58 HANDLE_TEXT,
59 PROPERTYCOUNT
62 namespace framework
65 ActionTriggerPropertySet::ActionTriggerPropertySet( const Reference< XMultiServiceFactory >& /*xServiceManager*/ )
66 : ThreadHelpBase ( &Application::GetSolarMutex() )
67 , OBroadcastHelper ( m_aLock.getShareableOslMutex() )
68 , OPropertySetHelper ( *SAL_STATIC_CAST( OBroadcastHelper *, this ))
69 , OWeakObject ()
70 , m_xBitmap ( 0 )
71 , m_xActionTriggerContainer( 0 )
75 ActionTriggerPropertySet::~ActionTriggerPropertySet()
79 // XInterface
80 Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType )
81 throw ( RuntimeException )
83 Any a = ::cppu::queryInterface(
84 aType ,
85 SAL_STATIC_CAST( XServiceInfo*, this ));
87 if( a.hasValue() )
88 return a;
89 else
91 a = OPropertySetHelper::queryInterface( aType );
93 if( a.hasValue() )
94 return a;
97 return OWeakObject::queryInterface( aType );
100 void SAL_CALL ActionTriggerPropertySet::acquire() throw ()
102 OWeakObject::acquire();
105 void SAL_CALL ActionTriggerPropertySet::release() throw ()
107 OWeakObject::release();
111 // XServiceInfo
112 ::rtl::OUString SAL_CALL ActionTriggerPropertySet::getImplementationName()
113 throw ( RuntimeException )
115 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGER ));
118 sal_Bool SAL_CALL ActionTriggerPropertySet::supportsService( const ::rtl::OUString& ServiceName )
119 throw ( RuntimeException )
121 if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
122 return sal_True;
124 return sal_False;
127 Sequence< ::rtl::OUString > SAL_CALL ActionTriggerPropertySet::getSupportedServiceNames()
128 throw ( RuntimeException )
130 Sequence< ::rtl::OUString > seqServiceNames( 1 );
131 seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
132 return seqServiceNames;
135 // XTypeProvider
136 Sequence< Type > SAL_CALL ActionTriggerPropertySet::getTypes() throw ( RuntimeException )
138 // Optimize this method !
139 // We initialize a static variable only one time. And we don't must use a mutex at every call!
140 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
141 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
143 if ( pTypeCollection == NULL )
145 // Ready for multithreading; get global mutex for first call of this method only! see before
146 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
148 // Control these pointer again ... it can be, that another instance will be faster then these!
149 if ( pTypeCollection == NULL )
151 // Create a static typecollection ...
152 static ::cppu::OTypeCollection aTypeCollection(
153 ::getCppuType(( const Reference< XPropertySet >*)NULL ) ,
154 ::getCppuType(( const Reference< XFastPropertySet >*)NULL ) ,
155 ::getCppuType(( const Reference< XMultiPropertySet >*)NULL ) ,
156 ::getCppuType(( const Reference< XServiceInfo >*)NULL ) ,
157 ::getCppuType(( const Reference< XTypeProvider >*)NULL ) ) ;
159 // ... and set his address to static pointer!
160 pTypeCollection = &aTypeCollection ;
164 return pTypeCollection->getTypes() ;
167 Sequence< sal_Int8 > SAL_CALL ActionTriggerPropertySet::getImplementationId() throw ( RuntimeException )
169 // Create one Id for all instances of this class.
170 // Use ethernet address to do this! (sal_True)
172 // Optimize this method
173 // We initialize a static variable only one time. And we don't must use a mutex at every call!
174 // For the first call; pID is NULL - for the second call pID is different from NULL!
175 static ::cppu::OImplementationId* pID = NULL ;
177 if ( pID == NULL )
179 // Ready for multithreading; get global mutex for first call of this method only! see before
180 osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
182 // Control these pointer again ... it can be, that another instance will be faster then these!
183 if ( pID == NULL )
185 // Create a new static ID ...
186 static ::cppu::OImplementationId aID( sal_False ) ;
187 // ... and set his address to static pointer!
188 pID = &aID ;
192 return pID->getImplementationId() ;
195 //---------------------------------------------------------------------------------------------------------
196 // OPropertySetHelper implementation
197 //---------------------------------------------------------------------------------------------------------
199 sal_Bool SAL_CALL ActionTriggerPropertySet::convertFastPropertyValue(
200 Any& aConvertedValue,
201 Any& aOldValue,
202 sal_Int32 nHandle,
203 const Any& aValue )
204 throw( IllegalArgumentException )
206 // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
207 // Return TRUE, if changed - else return FALSE.
208 // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
209 // Initialize return value with FALSE !!!
210 // (Handle can be invalid)
211 sal_Bool bReturn = sal_False;
213 switch( nHandle )
215 case HANDLE_COMMANDURL:
216 bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue );
217 break;
219 case HANDLE_HELPURL:
220 bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue ) ;
221 break;
223 case HANDLE_IMAGE:
224 bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue ) ;
225 break;
227 case HANDLE_SUBCONTAINER:
228 bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue );
229 break;
231 case HANDLE_TEXT:
232 bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue ) ;
233 break;
236 // Return state of operation.
237 return bReturn;
241 void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
242 sal_Int32 nHandle, const Any& aValue )
243 throw( Exception )
245 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
247 // Search for right handle ... and try to set property value.
248 switch( nHandle )
250 case HANDLE_COMMANDURL:
251 aValue >>= m_aCommandURL;
252 break;
254 case HANDLE_HELPURL:
255 aValue >>= m_aHelpURL;
256 break;
258 case HANDLE_IMAGE:
259 aValue >>= m_xBitmap;
260 break;
262 case HANDLE_SUBCONTAINER:
263 aValue >>= m_xActionTriggerContainer;
264 break;
266 case HANDLE_TEXT:
267 aValue >>= m_aText;
268 break;
272 void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue(
273 Any& aValue, sal_Int32 nHandle ) const
275 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
277 // Search for right handle ... and try to get property value.
278 switch( nHandle )
280 case HANDLE_COMMANDURL:
281 aValue <<= m_aCommandURL;
282 break;
284 case HANDLE_HELPURL:
285 aValue <<= m_aHelpURL;
286 break;
288 case HANDLE_IMAGE:
289 aValue <<= m_xBitmap;
290 break;
292 case HANDLE_SUBCONTAINER:
293 aValue <<= m_xActionTriggerContainer;
294 break;
296 case HANDLE_TEXT:
297 aValue <<= m_aText;
298 break;
302 ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerPropertySet::getInfoHelper()
304 // Optimize this method !
305 // We initialize a static variable only one time. And we don't must use a mutex at every call!
306 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
307 static OPropertyArrayHelper* pInfoHelper = NULL;
309 if( pInfoHelper == NULL )
311 // Ready for multithreading
312 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
313 // Control this pointer again, another instance can be faster then these!
314 if( pInfoHelper == NULL )
316 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
317 // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
318 // "sal_True" say: Table is sorted by name.
319 static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
320 pInfoHelper = &aInfoHelper;
324 return (*pInfoHelper);
327 Reference< XPropertySetInfo > SAL_CALL ActionTriggerPropertySet::getPropertySetInfo()
328 throw ( RuntimeException )
330 // Optimize this method !
331 // We initialize a static variable only one time. And we don't must use a mutex at every call!
332 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
333 static Reference< XPropertySetInfo >* pInfo = NULL ;
335 if( pInfo == NULL )
337 // Ready for multithreading
338 ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
339 // Control this pointer again, another instance can be faster then these!
340 if( pInfo == NULL )
342 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
343 // (Use method "getInfoHelper()".)
344 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
345 pInfo = &xInfo;
349 return (*pInfo);
352 const Sequence< Property > ActionTriggerPropertySet::impl_getStaticPropertyDescriptor()
354 static const Property pActionTriggerPropertys[] =
356 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )), HANDLE_COMMANDURL , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ),
357 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpURL" )), HANDLE_HELPURL , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ),
358 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Image" )), HANDLE_IMAGE , ::getCppuType((Reference<XBitmap>*)0) , PropertyAttribute::TRANSIENT ),
359 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubContainer" )), HANDLE_SUBCONTAINER , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ),
360 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )), HANDLE_TEXT , ::getCppuType((Reference<XInterface>*)0) , PropertyAttribute::TRANSIENT )
363 // Use it to initialize sequence!
364 static const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT );
366 // Return static "PropertyDescriptor"
367 return seqActionTriggerPropertyDescriptor ;
371 //******************************************************************************************************************************
372 // private method
373 //******************************************************************************************************************************
374 sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
375 const ::rtl::OUString& sCurrentValue ,
376 const Any& aNewValue ,
377 Any& aOldValue ,
378 Any& aConvertedValue )
379 throw( IllegalArgumentException )
381 // Set default return value if method failed.
382 sal_Bool bReturn = sal_False;
383 // Get new value from any.
384 // IllegalArgumentException() can be thrown!
385 ::rtl::OUString sValue ;
386 convertPropertyValue( sValue, aNewValue );
388 // If value change ...
389 if( sValue != sCurrentValue )
391 // ... set information of change.
392 aOldValue <<= sCurrentValue ;
393 aConvertedValue <<= sValue ;
394 // Return OK - "value will be change ..."
395 bReturn = sal_True;
397 else
399 // ... clear information of return parameter!
400 aOldValue.clear () ;
401 aConvertedValue.clear () ;
402 // Return NOTHING - "value will not be change ..."
403 bReturn = sal_False;
406 return bReturn;
410 sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
411 const Reference< XBitmap > aCurrentValue ,
412 const Any& aNewValue ,
413 Any& aOldValue ,
414 Any& aConvertedValue )
415 throw( IllegalArgumentException )
417 // Set default return value if method failed.
418 sal_Bool bReturn = sal_False;
419 // Get new value from any.
420 // IllegalArgumentException() can be thrown!
421 Reference< XBitmap > aValue ;
422 convertPropertyValue( aValue, aNewValue );
424 // If value change ...
425 if( aValue != aCurrentValue )
427 // ... set information of change.
428 aOldValue <<= aCurrentValue ;
429 aConvertedValue <<= aValue ;
430 // Return OK - "value will be change ..."
431 bReturn = sal_True;
433 else
435 // ... clear information of return parameter!
436 aOldValue.clear () ;
437 aConvertedValue.clear () ;
438 // Return NOTHING - "value will not be change ..."
439 bReturn = sal_False;
442 return bReturn;
445 sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
446 const Reference< XInterface > aCurrentValue ,
447 const Any& aNewValue ,
448 Any& aOldValue ,
449 Any& aConvertedValue )
450 throw( IllegalArgumentException )
452 // Set default return value if method failed.
453 sal_Bool bReturn = sal_False;
454 // Get new value from any.
455 // IllegalArgumentException() can be thrown!
456 Reference< XInterface > aValue ;
457 convertPropertyValue( aValue, aNewValue );
459 // If value change ...
460 if( aValue != aCurrentValue )
462 // ... set information of change.
463 aOldValue <<= aCurrentValue ;
464 aConvertedValue <<= aValue ;
465 // Return OK - "value will be change ..."
466 bReturn = sal_True;
468 else
470 // ... clear information of return parameter!
471 aOldValue.clear () ;
472 aConvertedValue.clear () ;
473 // Return NOTHING - "value will not be change ..."
474 bReturn = sal_False;
477 return bReturn;