1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 #include <classes/actiontriggerpropertyset.hxx>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <cppuhelper/proptypehlp.hxx>
34 #include <cppuhelper/typeprovider.hxx>
35 #include <vcl/svapp.hxx>
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star::beans
;
41 using namespace com::sun::star::lang
;
42 using namespace com::sun::star::awt
;
44 // Handles for properties
45 // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
46 // We use an enum to define these handles, to use all numbers from 0 to nn and
47 // if you add someone, you don't must control this!
48 // But don't forget to change values of follow defines, if you do something with this enum!
62 ActionTriggerPropertySet::ActionTriggerPropertySet( const Reference
< XMultiServiceFactory
>& /*xServiceManager*/ )
63 : ThreadHelpBase ( &Application::GetSolarMutex() )
64 , OBroadcastHelper ( m_aLock
.getShareableOslMutex() )
65 , OPropertySetHelper ( *SAL_STATIC_CAST( OBroadcastHelper
*, this ))
68 , m_xActionTriggerContainer( 0 )
72 ActionTriggerPropertySet::~ActionTriggerPropertySet()
77 Any SAL_CALL
ActionTriggerPropertySet::queryInterface( const Type
& aType
)
78 throw ( RuntimeException
)
80 Any a
= ::cppu::queryInterface(
82 SAL_STATIC_CAST( XServiceInfo
*, this ));
88 a
= OPropertySetHelper::queryInterface( aType
);
94 return OWeakObject::queryInterface( aType
);
97 void SAL_CALL
ActionTriggerPropertySet::acquire() throw ()
99 OWeakObject::acquire();
102 void SAL_CALL
ActionTriggerPropertySet::release() throw ()
104 OWeakObject::release();
109 ::rtl::OUString SAL_CALL
ActionTriggerPropertySet::getImplementationName()
110 throw ( RuntimeException
)
112 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGER
));
115 sal_Bool SAL_CALL
ActionTriggerPropertySet::supportsService( const ::rtl::OUString
& ServiceName
)
116 throw ( RuntimeException
)
118 if ( ServiceName
.equalsAscii( SERVICENAME_ACTIONTRIGGER
))
124 Sequence
< ::rtl::OUString
> SAL_CALL
ActionTriggerPropertySet::getSupportedServiceNames()
125 throw ( RuntimeException
)
127 Sequence
< ::rtl::OUString
> seqServiceNames( 1 );
128 seqServiceNames
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER
));
129 return seqServiceNames
;
133 Sequence
< Type
> SAL_CALL
ActionTriggerPropertySet::getTypes() throw ( RuntimeException
)
135 // Optimize this method !
136 // We initialize a static variable only one time. And we don't must use a mutex at every call!
137 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
138 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
140 if ( pTypeCollection
== NULL
)
142 // Ready for multithreading; get global mutex for first call of this method only! see before
143 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
145 // Control these pointer again ... it can be, that another instance will be faster then these!
146 if ( pTypeCollection
== NULL
)
148 // Create a static typecollection ...
149 static ::cppu::OTypeCollection
aTypeCollection(
150 ::getCppuType(( const Reference
< XPropertySet
>*)NULL
) ,
151 ::getCppuType(( const Reference
< XFastPropertySet
>*)NULL
) ,
152 ::getCppuType(( const Reference
< XMultiPropertySet
>*)NULL
) ,
153 ::getCppuType(( const Reference
< XServiceInfo
>*)NULL
) ,
154 ::getCppuType(( const Reference
< XTypeProvider
>*)NULL
) ) ;
156 // ... and set his address to static pointer!
157 pTypeCollection
= &aTypeCollection
;
161 return pTypeCollection
->getTypes() ;
164 Sequence
< sal_Int8
> SAL_CALL
ActionTriggerPropertySet::getImplementationId() throw ( RuntimeException
)
166 // Create one Id for all instances of this class.
167 // Use ethernet address to do this! (sal_True)
169 // Optimize this method
170 // We initialize a static variable only one time. And we don't must use a mutex at every call!
171 // For the first call; pID is NULL - for the second call pID is different from NULL!
172 static ::cppu::OImplementationId
* pID
= NULL
;
176 // Ready for multithreading; get global mutex for first call of this method only! see before
177 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
179 // Control these pointer again ... it can be, that another instance will be faster then these!
182 // Create a new static ID ...
183 static ::cppu::OImplementationId
aID( sal_False
) ;
184 // ... and set his address to static pointer!
189 return pID
->getImplementationId() ;
192 //---------------------------------------------------------------------------------------------------------
193 // OPropertySetHelper implementation
194 //---------------------------------------------------------------------------------------------------------
196 sal_Bool SAL_CALL
ActionTriggerPropertySet::convertFastPropertyValue(
197 Any
& aConvertedValue
,
201 throw( IllegalArgumentException
)
203 // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
204 // Return TRUE, if changed - else return FALSE.
205 // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
206 // Initialize return value with FALSE !!!
207 // (Handle can be invalid)
208 sal_Bool bReturn
= sal_False
;
212 case HANDLE_COMMANDURL
:
213 bReturn
= impl_tryToChangeProperty( m_aCommandURL
, aValue
, aOldValue
, aConvertedValue
);
217 bReturn
= impl_tryToChangeProperty( m_aHelpURL
, aValue
, aOldValue
, aConvertedValue
) ;
221 bReturn
= impl_tryToChangeProperty( m_xBitmap
, aValue
, aOldValue
, aConvertedValue
) ;
224 case HANDLE_SUBCONTAINER
:
225 bReturn
= impl_tryToChangeProperty( m_xActionTriggerContainer
, aValue
, aOldValue
, aConvertedValue
);
229 bReturn
= impl_tryToChangeProperty( m_aText
, aValue
, aOldValue
, aConvertedValue
) ;
233 // Return state of operation.
238 void SAL_CALL
ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
239 sal_Int32 nHandle
, const Any
& aValue
)
242 ::osl::MutexGuard
aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
244 // Search for right handle ... and try to set property value.
247 case HANDLE_COMMANDURL
:
248 aValue
>>= m_aCommandURL
;
252 aValue
>>= m_aHelpURL
;
256 aValue
>>= m_xBitmap
;
259 case HANDLE_SUBCONTAINER
:
260 aValue
>>= m_xActionTriggerContainer
;
269 void SAL_CALL
ActionTriggerPropertySet::getFastPropertyValue(
270 Any
& aValue
, sal_Int32 nHandle
) const
272 ::osl::MutexGuard
aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
274 // Search for right handle ... and try to get property value.
277 case HANDLE_COMMANDURL
:
278 aValue
<<= m_aCommandURL
;
282 aValue
<<= m_aHelpURL
;
286 aValue
<<= m_xBitmap
;
289 case HANDLE_SUBCONTAINER
:
290 aValue
<<= m_xActionTriggerContainer
;
299 ::cppu::IPropertyArrayHelper
& SAL_CALL
ActionTriggerPropertySet::getInfoHelper()
301 // Optimize this method !
302 // We initialize a static variable only one time. And we don't must use a mutex at every call!
303 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
304 static OPropertyArrayHelper
* pInfoHelper
= NULL
;
306 if( pInfoHelper
== NULL
)
308 // Ready for multithreading
309 ::osl::MutexGuard
aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
310 // Control this pointer again, another instance can be faster then these!
311 if( pInfoHelper
== NULL
)
313 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
314 // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
315 // "sal_True" say: Table is sorted by name.
316 static OPropertyArrayHelper
aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True
);
317 pInfoHelper
= &aInfoHelper
;
321 return (*pInfoHelper
);
324 Reference
< XPropertySetInfo
> SAL_CALL
ActionTriggerPropertySet::getPropertySetInfo()
325 throw ( RuntimeException
)
327 // Optimize this method !
328 // We initialize a static variable only one time. And we don't must use a mutex at every call!
329 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
330 static Reference
< XPropertySetInfo
>* pInfo
= NULL
;
334 // Ready for multithreading
335 ::osl::MutexGuard
aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
336 // Control this pointer again, another instance can be faster then these!
339 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
340 // (Use method "getInfoHelper()".)
341 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
349 const Sequence
< Property
> ActionTriggerPropertySet::impl_getStaticPropertyDescriptor()
351 static const Property pActionTriggerPropertys
[] =
353 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )), HANDLE_COMMANDURL
, ::getCppuType((::rtl::OUString
*)0) , PropertyAttribute::TRANSIENT
),
354 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpURL" )), HANDLE_HELPURL
, ::getCppuType((::rtl::OUString
*)0) , PropertyAttribute::TRANSIENT
),
355 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Image" )), HANDLE_IMAGE
, ::getCppuType((Reference
<XBitmap
>*)0) , PropertyAttribute::TRANSIENT
),
356 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubContainer" )), HANDLE_SUBCONTAINER
, ::getCppuType((::rtl::OUString
*)0) , PropertyAttribute::TRANSIENT
),
357 Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )), HANDLE_TEXT
, ::getCppuType((Reference
<XInterface
>*)0) , PropertyAttribute::TRANSIENT
)
360 // Use it to initialize sequence!
361 static const Sequence
< Property
> seqActionTriggerPropertyDescriptor( pActionTriggerPropertys
, PROPERTYCOUNT
);
363 // Return static "PropertyDescriptor"
364 return seqActionTriggerPropertyDescriptor
;
368 //******************************************************************************************************************************
370 //******************************************************************************************************************************
371 sal_Bool
ActionTriggerPropertySet::impl_tryToChangeProperty(
372 const ::rtl::OUString
& sCurrentValue
,
373 const Any
& aNewValue
,
375 Any
& aConvertedValue
)
376 throw( IllegalArgumentException
)
378 // Set default return value if method failed.
379 sal_Bool bReturn
= sal_False
;
380 // Get new value from any.
381 // IllegalArgumentException() can be thrown!
382 ::rtl::OUString sValue
;
383 convertPropertyValue( sValue
, aNewValue
);
385 // If value change ...
386 if( sValue
!= sCurrentValue
)
388 // ... set information of change.
389 aOldValue
<<= sCurrentValue
;
390 aConvertedValue
<<= sValue
;
391 // Return OK - "value will be change ..."
396 // ... clear information of return parameter!
398 aConvertedValue
.clear () ;
399 // Return NOTHING - "value will not be change ..."
407 sal_Bool
ActionTriggerPropertySet::impl_tryToChangeProperty(
408 const Reference
< XBitmap
> aCurrentValue
,
409 const Any
& aNewValue
,
411 Any
& aConvertedValue
)
412 throw( IllegalArgumentException
)
414 // Set default return value if method failed.
415 sal_Bool bReturn
= sal_False
;
416 // Get new value from any.
417 // IllegalArgumentException() can be thrown!
418 Reference
< XBitmap
> aValue
;
419 convertPropertyValue( aValue
, aNewValue
);
421 // If value change ...
422 if( aValue
!= aCurrentValue
)
424 // ... set information of change.
425 aOldValue
<<= aCurrentValue
;
426 aConvertedValue
<<= aValue
;
427 // Return OK - "value will be change ..."
432 // ... clear information of return parameter!
434 aConvertedValue
.clear () ;
435 // Return NOTHING - "value will not be change ..."
442 sal_Bool
ActionTriggerPropertySet::impl_tryToChangeProperty(
443 const Reference
< XInterface
> aCurrentValue
,
444 const Any
& aNewValue
,
446 Any
& aConvertedValue
)
447 throw( IllegalArgumentException
)
449 // Set default return value if method failed.
450 sal_Bool bReturn
= sal_False
;
451 // Get new value from any.
452 // IllegalArgumentException() can be thrown!
453 Reference
< XInterface
> aValue
;
454 convertPropertyValue( aValue
, aNewValue
);
456 // If value change ...
457 if( aValue
!= aCurrentValue
)
459 // ... set information of change.
460 aOldValue
<<= aCurrentValue
;
461 aConvertedValue
<<= aValue
;
462 // Return OK - "value will be change ..."
467 // ... clear information of return parameter!
469 aConvertedValue
.clear () ;
470 // Return NOTHING - "value will not be change ..."