fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwe / classes / actiontriggerpropertyset.cxx
blobae27ab137b958bcaf89eb1ac8853372d224adf50
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
28 using namespace cppu;
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!
41 enum EPROPERTIES
43 HANDLE_COMMANDURL,
44 HANDLE_HELPURL,
45 HANDLE_IMAGE,
46 HANDLE_SUBCONTAINER,
47 HANDLE_TEXT,
48 PROPERTYCOUNT
51 namespace framework
54 ActionTriggerPropertySet::ActionTriggerPropertySet()
55 : OBroadcastHelper ( m_aMutex )
56 , OPropertySetHelper ( *(static_cast< OBroadcastHelper * >(this)))
57 , OWeakObject ()
58 , m_xBitmap ( 0 )
59 , m_xActionTriggerContainer( 0 )
63 ActionTriggerPropertySet::~ActionTriggerPropertySet()
67 // XInterface
68 Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType )
69 throw ( RuntimeException, std::exception )
71 Any a = ::cppu::queryInterface(
72 aType,
73 (static_cast< XServiceInfo* >(this)),
74 (static_cast< XTypeProvider* >(this)));
76 if( a.hasValue() )
77 return a;
78 else
80 a = OPropertySetHelper::queryInterface( aType );
82 if( a.hasValue() )
83 return a;
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();
99 // XServiceInfo
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;
120 // XTypeProvider
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,
159 Any& aOldValue,
160 sal_Int32 nHandle,
161 const Any& aValue )
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;
171 switch( nHandle )
173 case HANDLE_COMMANDURL:
174 bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue );
175 break;
177 case HANDLE_HELPURL:
178 bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue );
179 break;
181 case HANDLE_IMAGE:
182 bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue );
183 break;
185 case HANDLE_SUBCONTAINER:
186 bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue );
187 break;
189 case HANDLE_TEXT:
190 bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue );
191 break;
194 // Return state of operation.
195 return bReturn;
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.
205 switch( nHandle )
207 case HANDLE_COMMANDURL:
208 aValue >>= m_aCommandURL;
209 break;
211 case HANDLE_HELPURL:
212 aValue >>= m_aHelpURL;
213 break;
215 case HANDLE_IMAGE:
216 aValue >>= m_xBitmap;
217 break;
219 case HANDLE_SUBCONTAINER:
220 aValue >>= m_xActionTriggerContainer;
221 break;
223 case HANDLE_TEXT:
224 aValue >>= m_aText;
225 break;
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.
235 switch( nHandle )
237 case HANDLE_COMMANDURL:
238 aValue <<= m_aCommandURL;
239 break;
241 case HANDLE_HELPURL:
242 aValue <<= m_aHelpURL;
243 break;
245 case HANDLE_IMAGE:
246 aValue <<= m_xBitmap;
247 break;
249 case HANDLE_SUBCONTAINER:
250 aValue <<= m_xActionTriggerContainer;
251 break;
253 case HANDLE_TEXT:
254 aValue <<= m_aText;
255 break;
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;
291 if( pInfo == NULL )
293 SolarMutexGuard aGuard;
294 // Control this pointer again, another instance can be faster then these!
295 if( pInfo == NULL )
297 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
298 // (Use method "getInfoHelper()".)
299 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
300 pInfo = &xInfo;
304 return (*pInfo);
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 ,
328 Any& aOldValue ,
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!
336 OUString sValue;
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 ..."
346 bReturn = true;
348 else
350 // ... clear information of return parameter!
351 aOldValue.clear ();
352 aConvertedValue.clear ();
353 // Return NOTHING - "value will not be change ..."
354 bReturn = false;
357 return bReturn;
360 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
361 const Reference< XBitmap > aCurrentValue ,
362 const Any& aNewValue ,
363 Any& aOldValue ,
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 ..."
381 bReturn = true;
383 else
385 // ... clear information of return parameter!
386 aOldValue.clear ();
387 aConvertedValue.clear ();
388 // Return NOTHING - "value will not be change ..."
389 bReturn = false;
392 return bReturn;
395 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
396 const Reference< XInterface > aCurrentValue ,
397 const Any& aNewValue ,
398 Any& aOldValue ,
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 ..."
416 bReturn = true;
418 else
420 // ... clear information of return parameter!
421 aOldValue.clear ();
422 aConvertedValue.clear ();
423 // Return NOTHING - "value will not be change ..."
424 bReturn = false;
427 return bReturn;
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */