1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <classes/actiontriggerpropertyset.hxx>
21 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <cppuhelper/proptypehlp.hxx>
23 #include <cppuhelper/queryinterface.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <cppuhelper/typeprovider.hxx>
26 #include <vcl/svapp.hxx>
29 using namespace com::sun::star::uno
;
30 using namespace com::sun::star::beans
;
31 using namespace com::sun::star::lang
;
32 using namespace com::sun::star::awt
;
34 //struct SAL_DLLPUBLIC_IMPORT ::cppu::OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType >;
36 // Handles for properties
37 // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
38 // We use an enum to define these handles, to use all numbers from 0 to nn and
39 // if you add someone, you don't must control this!
40 // But don't forget to change values of follow defines, if you do something with this enum!
54 ActionTriggerPropertySet::ActionTriggerPropertySet()
55 : OBroadcastHelper ( m_aMutex
)
56 , OPropertySetHelper ( *(static_cast< OBroadcastHelper
* >(this)))
59 , m_xActionTriggerContainer( 0 )
63 ActionTriggerPropertySet::~ActionTriggerPropertySet()
68 Any SAL_CALL
ActionTriggerPropertySet::queryInterface( const Type
& aType
)
69 throw ( RuntimeException
, std::exception
)
71 Any a
= ::cppu::queryInterface(
73 (static_cast< XServiceInfo
* >(this)),
74 (static_cast< XTypeProvider
* >(this)));
80 a
= OPropertySetHelper::queryInterface( aType
);
86 return OWeakObject::queryInterface( aType
);
89 void SAL_CALL
ActionTriggerPropertySet::acquire() throw ()
91 OWeakObject::acquire();
94 void SAL_CALL
ActionTriggerPropertySet::release() throw ()
96 OWeakObject::release();
100 OUString SAL_CALL
ActionTriggerPropertySet::getImplementationName()
101 throw ( RuntimeException
, std::exception
)
103 return OUString( IMPLEMENTATIONNAME_ACTIONTRIGGER
);
106 sal_Bool SAL_CALL
ActionTriggerPropertySet::supportsService( const OUString
& ServiceName
)
107 throw ( RuntimeException
, std::exception
)
109 return cppu::supportsService(this, ServiceName
);
112 Sequence
< OUString
> SAL_CALL
ActionTriggerPropertySet::getSupportedServiceNames()
113 throw ( RuntimeException
, std::exception
)
115 Sequence
< OUString
> seqServiceNames( 1 );
116 seqServiceNames
[0] = SERVICENAME_ACTIONTRIGGER
;
117 return seqServiceNames
;
121 Sequence
< Type
> SAL_CALL
ActionTriggerPropertySet::getTypes() throw ( RuntimeException
, std::exception
)
123 // Optimize this method !
124 // We initialize a static variable only one time. And we don't must use a mutex at every call!
125 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
126 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
128 if ( pTypeCollection
== NULL
)
130 // Ready for multithreading; get global mutex for first call of this method only! see before
131 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() );
133 // Control these pointer again ... it can be, that another instance will be faster then these!
134 if ( pTypeCollection
== NULL
)
136 // Create a static typecollection ...
137 static ::cppu::OTypeCollection
aTypeCollection(
138 cppu::UnoType
<XPropertySet
>::get(),
139 cppu::UnoType
<XFastPropertySet
>::get(),
140 cppu::UnoType
<XMultiPropertySet
>::get(),
141 cppu::UnoType
<XServiceInfo
>::get(),
142 cppu::UnoType
<XTypeProvider
>::get());
144 // ... and set his address to static pointer!
145 pTypeCollection
= &aTypeCollection
;
149 return pTypeCollection
->getTypes();
152 Sequence
< sal_Int8
> SAL_CALL
ActionTriggerPropertySet::getImplementationId() throw ( RuntimeException
, std::exception
)
154 return css::uno::Sequence
<sal_Int8
>();
157 sal_Bool SAL_CALL
ActionTriggerPropertySet::convertFastPropertyValue(
158 Any
& aConvertedValue
,
162 throw( IllegalArgumentException
)
164 // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
165 // Return sal_True, if changed - else return sal_False.
166 // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
167 // Initialize return value with sal_False !!!
168 // (Handle can be invalid)
169 bool bReturn
= false;
173 case HANDLE_COMMANDURL
:
174 bReturn
= impl_tryToChangeProperty( m_aCommandURL
, aValue
, aOldValue
, aConvertedValue
);
178 bReturn
= impl_tryToChangeProperty( m_aHelpURL
, aValue
, aOldValue
, aConvertedValue
);
182 bReturn
= impl_tryToChangeProperty( m_xBitmap
, aValue
, aOldValue
, aConvertedValue
);
185 case HANDLE_SUBCONTAINER
:
186 bReturn
= impl_tryToChangeProperty( m_xActionTriggerContainer
, aValue
, aOldValue
, aConvertedValue
);
190 bReturn
= impl_tryToChangeProperty( m_aText
, aValue
, aOldValue
, aConvertedValue
);
194 // Return state of operation.
198 void SAL_CALL
ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
199 sal_Int32 nHandle
, const Any
& aValue
)
200 throw( Exception
, std::exception
)
202 SolarMutexGuard aGuard
;
204 // Search for right handle ... and try to set property value.
207 case HANDLE_COMMANDURL
:
208 aValue
>>= m_aCommandURL
;
212 aValue
>>= m_aHelpURL
;
216 aValue
>>= m_xBitmap
;
219 case HANDLE_SUBCONTAINER
:
220 aValue
>>= m_xActionTriggerContainer
;
229 void SAL_CALL
ActionTriggerPropertySet::getFastPropertyValue(
230 Any
& aValue
, sal_Int32 nHandle
) const
232 SolarMutexGuard aGuard
;
234 // Search for right handle ... and try to get property value.
237 case HANDLE_COMMANDURL
:
238 aValue
<<= m_aCommandURL
;
242 aValue
<<= m_aHelpURL
;
246 aValue
<<= m_xBitmap
;
249 case HANDLE_SUBCONTAINER
:
250 aValue
<<= m_xActionTriggerContainer
;
259 ::cppu::IPropertyArrayHelper
& SAL_CALL
ActionTriggerPropertySet::getInfoHelper()
261 // Optimize this method !
262 // We initialize a static variable only one time. And we don't must use a mutex at every call!
263 // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
264 static OPropertyArrayHelper
* pInfoHelper
= NULL
;
266 if( pInfoHelper
== NULL
)
268 SolarMutexGuard aGuard
;
269 // Control this pointer again, another instance can be faster then these!
270 if( pInfoHelper
== NULL
)
272 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
273 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
274 // "sal_True" say: Table is sorted by name.
275 static OPropertyArrayHelper
aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True
);
276 pInfoHelper
= &aInfoHelper
;
280 return (*pInfoHelper
);
283 Reference
< XPropertySetInfo
> SAL_CALL
ActionTriggerPropertySet::getPropertySetInfo()
284 throw ( RuntimeException
, std::exception
)
286 // Optimize this method !
287 // We initialize a static variable only one time. And we don't must use a mutex at every call!
288 // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
289 static Reference
< XPropertySetInfo
>* pInfo
= NULL
;
293 SolarMutexGuard aGuard
;
294 // Control this pointer again, another instance can be faster then these!
297 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
298 // (Use method "getInfoHelper()".)
299 static Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
307 const Sequence
< Property
> ActionTriggerPropertySet::impl_getStaticPropertyDescriptor()
309 const Property pActionTriggerPropertys
[] =
311 Property( OUString( "CommandURL" ), HANDLE_COMMANDURL
, cppu::UnoType
<OUString
>::get(), PropertyAttribute::TRANSIENT
),
312 Property( OUString( "HelpURL" ), HANDLE_HELPURL
, cppu::UnoType
<OUString
>::get(), PropertyAttribute::TRANSIENT
),
313 Property( OUString( "Image" ), HANDLE_IMAGE
, cppu::UnoType
<XBitmap
>::get(), PropertyAttribute::TRANSIENT
),
314 Property( OUString( "SubContainer" ), HANDLE_SUBCONTAINER
, cppu::UnoType
<OUString
>::get(), PropertyAttribute::TRANSIENT
),
315 Property( OUString( "Text" ), HANDLE_TEXT
, cppu::UnoType
<XInterface
>::get(), PropertyAttribute::TRANSIENT
)
318 // Use it to initialize sequence!
319 const Sequence
< Property
> seqActionTriggerPropertyDescriptor( pActionTriggerPropertys
, PROPERTYCOUNT
);
321 // Return "PropertyDescriptor"
322 return seqActionTriggerPropertyDescriptor
;
325 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
326 const OUString
& sCurrentValue
,
327 const Any
& aNewValue
,
329 Any
& aConvertedValue
)
330 throw( IllegalArgumentException
)
332 // Set default return value if method failed.
333 bool bReturn
= false;
334 // Get new value from any.
335 // IllegalArgumentException() can be thrown!
337 convertPropertyValue( sValue
, aNewValue
);
339 // If value change ...
340 if( sValue
!= sCurrentValue
)
342 // ... set information of change.
343 aOldValue
<<= sCurrentValue
;
344 aConvertedValue
<<= sValue
;
345 // Return OK - "value will be change ..."
350 // ... clear information of return parameter!
352 aConvertedValue
.clear ();
353 // Return NOTHING - "value will not be change ..."
360 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
361 const Reference
< XBitmap
> aCurrentValue
,
362 const Any
& aNewValue
,
364 Any
& aConvertedValue
)
365 throw( IllegalArgumentException
)
367 // Set default return value if method failed.
368 bool bReturn
= false;
369 // Get new value from any.
370 // IllegalArgumentException() can be thrown!
371 Reference
< XBitmap
> aValue
;
372 convertPropertyValue( aValue
, aNewValue
);
374 // If value change ...
375 if( aValue
!= aCurrentValue
)
377 // ... set information of change.
378 aOldValue
<<= aCurrentValue
;
379 aConvertedValue
<<= aValue
;
380 // Return OK - "value will be change ..."
385 // ... clear information of return parameter!
387 aConvertedValue
.clear ();
388 // Return NOTHING - "value will not be change ..."
395 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
396 const Reference
< XInterface
> aCurrentValue
,
397 const Any
& aNewValue
,
399 Any
& aConvertedValue
)
400 throw( IllegalArgumentException
)
402 // Set default return value if method failed.
403 bool bReturn
= false;
404 // Get new value from any.
405 // IllegalArgumentException() can be thrown!
406 Reference
< XInterface
> aValue
;
407 convertPropertyValue( aValue
, aNewValue
);
409 // If value change ...
410 if( aValue
!= aCurrentValue
)
412 // ... set information of change.
413 aOldValue
<<= aCurrentValue
;
414 aConvertedValue
<<= aValue
;
415 // Return OK - "value will be change ..."
420 // ... clear information of return parameter!
422 aConvertedValue
.clear ();
423 // Return NOTHING - "value will not be change ..."
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */