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 $
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>
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!
65 ActionTriggerPropertySet::ActionTriggerPropertySet( const Reference
< XMultiServiceFactory
>& /*xServiceManager*/ )
66 : ThreadHelpBase ( &Application::GetSolarMutex() )
67 , OBroadcastHelper ( m_aLock
.getShareableOslMutex() )
68 , OPropertySetHelper ( *SAL_STATIC_CAST( OBroadcastHelper
*, this ))
71 , m_xActionTriggerContainer( 0 )
75 ActionTriggerPropertySet::~ActionTriggerPropertySet()
80 Any SAL_CALL
ActionTriggerPropertySet::queryInterface( const Type
& aType
)
81 throw ( RuntimeException
)
83 Any a
= ::cppu::queryInterface(
85 SAL_STATIC_CAST( XServiceInfo
*, this ));
91 a
= OPropertySetHelper::queryInterface( aType
);
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();
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
))
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
;
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
;
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!
185 // Create a new static ID ...
186 static ::cppu::OImplementationId
aID( sal_False
) ;
187 // ... and set his address to static pointer!
192 return pID
->getImplementationId() ;
195 //---------------------------------------------------------------------------------------------------------
196 // OPropertySetHelper implementation
197 //---------------------------------------------------------------------------------------------------------
199 sal_Bool SAL_CALL
ActionTriggerPropertySet::convertFastPropertyValue(
200 Any
& aConvertedValue
,
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
;
215 case HANDLE_COMMANDURL
:
216 bReturn
= impl_tryToChangeProperty( m_aCommandURL
, aValue
, aOldValue
, aConvertedValue
);
220 bReturn
= impl_tryToChangeProperty( m_aHelpURL
, aValue
, aOldValue
, aConvertedValue
) ;
224 bReturn
= impl_tryToChangeProperty( m_xBitmap
, aValue
, aOldValue
, aConvertedValue
) ;
227 case HANDLE_SUBCONTAINER
:
228 bReturn
= impl_tryToChangeProperty( m_xActionTriggerContainer
, aValue
, aOldValue
, aConvertedValue
);
232 bReturn
= impl_tryToChangeProperty( m_aText
, aValue
, aOldValue
, aConvertedValue
) ;
236 // Return state of operation.
241 void SAL_CALL
ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
242 sal_Int32 nHandle
, const Any
& aValue
)
245 ::osl::MutexGuard
aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
247 // Search for right handle ... and try to set property value.
250 case HANDLE_COMMANDURL
:
251 aValue
>>= m_aCommandURL
;
255 aValue
>>= m_aHelpURL
;
259 aValue
>>= m_xBitmap
;
262 case HANDLE_SUBCONTAINER
:
263 aValue
>>= m_xActionTriggerContainer
;
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.
280 case HANDLE_COMMANDURL
:
281 aValue
<<= m_aCommandURL
;
285 aValue
<<= m_aHelpURL
;
289 aValue
<<= m_xBitmap
;
292 case HANDLE_SUBCONTAINER
:
293 aValue
<<= m_xActionTriggerContainer
;
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
;
337 // Ready for multithreading
338 ::osl::MutexGuard
aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
339 // Control this pointer again, another instance can be faster then these!
342 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
343 // (Use method "getInfoHelper()".)
344 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
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 //******************************************************************************************************************************
373 //******************************************************************************************************************************
374 sal_Bool
ActionTriggerPropertySet::impl_tryToChangeProperty(
375 const ::rtl::OUString
& sCurrentValue
,
376 const Any
& aNewValue
,
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 ..."
399 // ... clear information of return parameter!
401 aConvertedValue
.clear () ;
402 // Return NOTHING - "value will not be change ..."
410 sal_Bool
ActionTriggerPropertySet::impl_tryToChangeProperty(
411 const Reference
< XBitmap
> aCurrentValue
,
412 const Any
& aNewValue
,
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 ..."
435 // ... clear information of return parameter!
437 aConvertedValue
.clear () ;
438 // Return NOTHING - "value will not be change ..."
445 sal_Bool
ActionTriggerPropertySet::impl_tryToChangeProperty(
446 const Reference
< XInterface
> aCurrentValue
,
447 const Any
& aNewValue
,
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 ..."
470 // ... clear information of return parameter!
472 aConvertedValue
.clear () ;
473 // Return NOTHING - "value will not be change ..."