Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <classes/actiontriggerpropertyset.hxx>
31 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
32 : : #include <cppuhelper/proptypehlp.hxx>
33 : : #include <cppuhelper/typeprovider.hxx>
34 : : #include <vcl/svapp.hxx>
35 : :
36 : :
37 : : using namespace cppu;
38 : : using namespace com::sun::star::uno;
39 : : using namespace com::sun::star::beans;
40 : : using namespace com::sun::star::lang;
41 : : using namespace com::sun::star::awt;
42 : :
43 : : //struct SAL_DLLPUBLIC_IMPORT ::cppu::OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType >;
44 : :
45 : : // Handles for properties
46 : : // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
47 : : // We use an enum to define these handles, to use all numbers from 0 to nn and
48 : : // if you add someone, you don't must control this!
49 : : // But don't forget to change values of follow defines, if you do something with this enum!
50 : : enum EPROPERTIES
51 : : {
52 : : HANDLE_COMMANDURL,
53 : : HANDLE_HELPURL,
54 : : HANDLE_IMAGE,
55 : : HANDLE_SUBCONTAINER,
56 : : HANDLE_TEXT,
57 : : PROPERTYCOUNT
58 : : };
59 : :
60 : : namespace framework
61 : : {
62 : :
63 : 0 : ActionTriggerPropertySet::ActionTriggerPropertySet( const Reference< XMultiServiceFactory >& /*xServiceManager*/ )
64 : 0 : : ThreadHelpBase ( &Application::GetSolarMutex() )
65 [ # # ]: 0 : , OBroadcastHelper ( m_aLock.getShareableOslMutex() )
66 : : , OPropertySetHelper ( *(static_cast< OBroadcastHelper * >(this)))
67 : : , OWeakObject ()
68 : : , m_xBitmap ( 0 )
69 [ # # ][ # # ]: 0 : , m_xActionTriggerContainer( 0 )
[ # # ][ # # ]
70 : : {
71 : 0 : }
72 : :
73 [ # # ][ # # ]: 0 : ActionTriggerPropertySet::~ActionTriggerPropertySet()
[ # # ]
74 : : {
75 [ # # ]: 0 : }
76 : :
77 : : // XInterface
78 : 0 : Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType )
79 : : throw ( RuntimeException )
80 : : {
81 : : Any a = ::cppu::queryInterface(
82 : : aType ,
83 [ # # ]: 0 : (static_cast< XServiceInfo* >(this)));
84 : :
85 [ # # ]: 0 : if( a.hasValue() )
86 : 0 : return a;
87 : : else
88 : : {
89 [ # # ]: 0 : a = OPropertySetHelper::queryInterface( aType );
90 : :
91 [ # # ]: 0 : if( a.hasValue() )
92 : 0 : return a;
93 : : }
94 : :
95 [ # # ]: 0 : return OWeakObject::queryInterface( aType );
96 : : }
97 : :
98 : 0 : void SAL_CALL ActionTriggerPropertySet::acquire() throw ()
99 : : {
100 : 0 : OWeakObject::acquire();
101 : 0 : }
102 : :
103 : 0 : void SAL_CALL ActionTriggerPropertySet::release() throw ()
104 : : {
105 : 0 : OWeakObject::release();
106 : 0 : }
107 : :
108 : :
109 : : // XServiceInfo
110 : 0 : ::rtl::OUString SAL_CALL ActionTriggerPropertySet::getImplementationName()
111 : : throw ( RuntimeException )
112 : : {
113 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGER ));
114 : : }
115 : :
116 : 0 : sal_Bool SAL_CALL ActionTriggerPropertySet::supportsService( const ::rtl::OUString& ServiceName )
117 : : throw ( RuntimeException )
118 : : {
119 [ # # ]: 0 : if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
120 : 0 : return sal_True;
121 : :
122 : 0 : return sal_False;
123 : : }
124 : :
125 : 0 : Sequence< ::rtl::OUString > SAL_CALL ActionTriggerPropertySet::getSupportedServiceNames()
126 : : throw ( RuntimeException )
127 : : {
128 : 0 : Sequence< ::rtl::OUString > seqServiceNames( 1 );
129 [ # # ][ # # ]: 0 : seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
130 : 0 : return seqServiceNames;
131 : : }
132 : :
133 : : // XTypeProvider
134 : 0 : Sequence< Type > SAL_CALL ActionTriggerPropertySet::getTypes() throw ( RuntimeException )
135 : : {
136 : : // Optimize this method !
137 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
138 : : // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
139 : : static ::cppu::OTypeCollection* pTypeCollection = NULL ;
140 : :
141 [ # # ]: 0 : if ( pTypeCollection == NULL )
142 : : {
143 : : // Ready for multithreading; get global mutex for first call of this method only! see before
144 [ # # ][ # # ]: 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
145 : :
146 : : // Control these pointer again ... it can be, that another instance will be faster then these!
147 [ # # ]: 0 : if ( pTypeCollection == NULL )
148 : : {
149 : : // Create a static typecollection ...
150 : : static ::cppu::OTypeCollection aTypeCollection(
151 [ # # ]: 0 : ::getCppuType(( const Reference< XPropertySet >*)NULL ) ,
152 [ # # ]: 0 : ::getCppuType(( const Reference< XFastPropertySet >*)NULL ) ,
153 [ # # ]: 0 : ::getCppuType(( const Reference< XMultiPropertySet >*)NULL ) ,
154 [ # # ]: 0 : ::getCppuType(( const Reference< XServiceInfo >*)NULL ) ,
155 [ # # ][ # # ]: 0 : ::getCppuType(( const Reference< XTypeProvider >*)NULL ) ) ;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
156 : :
157 : : // ... and set his address to static pointer!
158 : 0 : pTypeCollection = &aTypeCollection ;
159 [ # # ]: 0 : }
160 : : }
161 : :
162 : 0 : return pTypeCollection->getTypes() ;
163 : : }
164 : :
165 : 0 : Sequence< sal_Int8 > SAL_CALL ActionTriggerPropertySet::getImplementationId() throw ( RuntimeException )
166 : : {
167 : : // Create one Id for all instances of this class.
168 : : // Use ethernet address to do this! (sal_True)
169 : :
170 : : // Optimize this method
171 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
172 : : // For the first call; pID is NULL - for the second call pID is different from NULL!
173 : : static ::cppu::OImplementationId* pID = NULL ;
174 : :
175 [ # # ]: 0 : if ( pID == NULL )
176 : : {
177 : : // Ready for multithreading; get global mutex for first call of this method only! see before
178 [ # # ][ # # ]: 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
179 : :
180 : : // Control these pointer again ... it can be, that another instance will be faster then these!
181 [ # # ]: 0 : if ( pID == NULL )
182 : : {
183 : : // Create a new static ID ...
184 [ # # ][ # # ]: 0 : static ::cppu::OImplementationId aID( sal_False ) ;
185 : : // ... and set his address to static pointer!
186 : 0 : pID = &aID ;
187 [ # # ]: 0 : }
188 : : }
189 : :
190 : 0 : return pID->getImplementationId() ;
191 : : }
192 : :
193 : : //---------------------------------------------------------------------------------------------------------
194 : : // OPropertySetHelper implementation
195 : : //---------------------------------------------------------------------------------------------------------
196 : :
197 : 0 : sal_Bool SAL_CALL ActionTriggerPropertySet::convertFastPropertyValue(
198 : : Any& aConvertedValue,
199 : : Any& aOldValue,
200 : : sal_Int32 nHandle,
201 : : const Any& aValue )
202 : : throw( IllegalArgumentException )
203 : : {
204 : : // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
205 : : // Return sal_True, if changed - else return sal_False.
206 : : // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
207 : : // Initialize return value with sal_False !!!
208 : : // (Handle can be invalid)
209 : 0 : sal_Bool bReturn = sal_False;
210 : :
211 [ # # # # : 0 : switch( nHandle )
# # ]
212 : : {
213 : : case HANDLE_COMMANDURL:
214 : 0 : bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue );
215 : 0 : break;
216 : :
217 : : case HANDLE_HELPURL:
218 : 0 : bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue ) ;
219 : 0 : break;
220 : :
221 : : case HANDLE_IMAGE:
222 [ # # ]: 0 : bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue ) ;
223 : 0 : break;
224 : :
225 : : case HANDLE_SUBCONTAINER:
226 [ # # ]: 0 : bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue );
227 : 0 : break;
228 : :
229 : : case HANDLE_TEXT:
230 : 0 : bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue ) ;
231 : 0 : break;
232 : : }
233 : :
234 : : // Return state of operation.
235 : 0 : return bReturn;
236 : : }
237 : :
238 : :
239 : 0 : void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
240 : : sal_Int32 nHandle, const Any& aValue )
241 : : throw( Exception )
242 : : {
243 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
[ # # ]
244 : :
245 : : // Search for right handle ... and try to set property value.
246 [ # # # # : 0 : switch( nHandle )
# # ]
247 : : {
248 : : case HANDLE_COMMANDURL:
249 : 0 : aValue >>= m_aCommandURL;
250 : 0 : break;
251 : :
252 : : case HANDLE_HELPURL:
253 : 0 : aValue >>= m_aHelpURL;
254 : 0 : break;
255 : :
256 : : case HANDLE_IMAGE:
257 [ # # ]: 0 : aValue >>= m_xBitmap;
258 : 0 : break;
259 : :
260 : : case HANDLE_SUBCONTAINER:
261 [ # # ]: 0 : aValue >>= m_xActionTriggerContainer;
262 : 0 : break;
263 : :
264 : : case HANDLE_TEXT:
265 : 0 : aValue >>= m_aText;
266 : 0 : break;
267 [ # # ]: 0 : }
268 : 0 : }
269 : :
270 : 0 : void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue(
271 : : Any& aValue, sal_Int32 nHandle ) const
272 : : {
273 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
[ # # ]
274 : :
275 : : // Search for right handle ... and try to get property value.
276 [ # # # # : 0 : switch( nHandle )
# # ]
277 : : {
278 : : case HANDLE_COMMANDURL:
279 [ # # ]: 0 : aValue <<= m_aCommandURL;
280 : 0 : break;
281 : :
282 : : case HANDLE_HELPURL:
283 [ # # ]: 0 : aValue <<= m_aHelpURL;
284 : 0 : break;
285 : :
286 : : case HANDLE_IMAGE:
287 [ # # ]: 0 : aValue <<= m_xBitmap;
288 : 0 : break;
289 : :
290 : : case HANDLE_SUBCONTAINER:
291 [ # # ]: 0 : aValue <<= m_xActionTriggerContainer;
292 : 0 : break;
293 : :
294 : : case HANDLE_TEXT:
295 [ # # ]: 0 : aValue <<= m_aText;
296 : 0 : break;
297 [ # # ]: 0 : }
298 : 0 : }
299 : :
300 : 0 : ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerPropertySet::getInfoHelper()
301 : : {
302 : : // Optimize this method !
303 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
304 : : // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
305 : : static OPropertyArrayHelper* pInfoHelper = NULL;
306 : :
307 [ # # ]: 0 : if( pInfoHelper == NULL )
308 : : {
309 : : // Ready for multithreading
310 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
[ # # ]
311 : : // Control this pointer again, another instance can be faster then these!
312 [ # # ]: 0 : if( pInfoHelper == NULL )
313 : : {
314 : : // Define static member to give structure of properties to baseclass "OPropertySetHelper".
315 : : // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
316 : : // "sal_True" say: Table is sorted by name.
317 [ # # ][ # # ]: 0 : static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
[ # # ][ # # ]
[ # # ][ # # ]
318 : 0 : pInfoHelper = &aInfoHelper;
319 [ # # ]: 0 : }
320 : : }
321 : :
322 : 0 : return (*pInfoHelper);
323 : : }
324 : :
325 : 0 : Reference< XPropertySetInfo > SAL_CALL ActionTriggerPropertySet::getPropertySetInfo()
326 : : throw ( RuntimeException )
327 : : {
328 : : // Optimize this method !
329 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
330 : : // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
331 : : static Reference< XPropertySetInfo >* pInfo = NULL ;
332 : :
333 [ # # ]: 0 : if( pInfo == NULL )
334 : : {
335 : : // Ready for multithreading
336 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
[ # # ]
337 : : // Control this pointer again, another instance can be faster then these!
338 [ # # ]: 0 : if( pInfo == NULL )
339 : : {
340 : : // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
341 : : // (Use method "getInfoHelper()".)
342 [ # # ][ # # ]: 0 : static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
[ # # ][ # # ]
[ # # ]
343 : 0 : pInfo = &xInfo;
344 [ # # ]: 0 : }
345 : : }
346 : :
347 : 0 : return (*pInfo);
348 : : }
349 : :
350 : 0 : const Sequence< Property > ActionTriggerPropertySet::impl_getStaticPropertyDescriptor()
351 : : {
352 : : const Property pActionTriggerPropertys[] =
353 : : {
354 [ # # ]: 0 : Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )), HANDLE_COMMANDURL , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ),
355 [ # # ]: 0 : Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpURL" )), HANDLE_HELPURL , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ),
356 [ # # ]: 0 : Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Image" )), HANDLE_IMAGE , ::getCppuType((Reference<XBitmap>*)0) , PropertyAttribute::TRANSIENT ),
357 [ # # ]: 0 : Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubContainer" )), HANDLE_SUBCONTAINER , ::getCppuType((::rtl::OUString*)0) , PropertyAttribute::TRANSIENT ),
358 [ # # ]: 0 : Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )), HANDLE_TEXT , ::getCppuType((Reference<XInterface>*)0) , PropertyAttribute::TRANSIENT )
359 [ # # ][ # # ]: 0 : };
[ # # ][ # # ]
[ # # ]
[ # # # # ]
360 : :
361 : : // Use it to initialize sequence!
362 [ # # ]: 0 : const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT );
363 : :
364 : : // Return "PropertyDescriptor"
365 [ # # ][ # # ]: 0 : return seqActionTriggerPropertyDescriptor ;
366 : : }
367 : :
368 : :
369 : : //******************************************************************************************************************************
370 : : // private method
371 : : //******************************************************************************************************************************
372 : 0 : sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
373 : : const ::rtl::OUString& sCurrentValue ,
374 : : const Any& aNewValue ,
375 : : Any& aOldValue ,
376 : : Any& aConvertedValue )
377 : : throw( IllegalArgumentException )
378 : : {
379 : : // Set default return value if method failed.
380 : 0 : sal_Bool bReturn = sal_False;
381 : : // Get new value from any.
382 : : // IllegalArgumentException() can be thrown!
383 : 0 : ::rtl::OUString sValue ;
384 [ # # ]: 0 : convertPropertyValue( sValue, aNewValue );
385 : :
386 : : // If value change ...
387 [ # # ]: 0 : if( sValue != sCurrentValue )
388 : : {
389 : : // ... set information of change.
390 [ # # ]: 0 : aOldValue <<= sCurrentValue ;
391 [ # # ]: 0 : aConvertedValue <<= sValue ;
392 : : // Return OK - "value will be change ..."
393 : 0 : bReturn = sal_True;
394 : : }
395 : : else
396 : : {
397 : : // ... clear information of return parameter!
398 : 0 : aOldValue.clear () ;
399 : 0 : aConvertedValue.clear () ;
400 : : // Return NOTHING - "value will not be change ..."
401 : 0 : bReturn = sal_False;
402 : : }
403 : :
404 : 0 : return bReturn;
405 : : }
406 : :
407 : :
408 : 0 : sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
409 : : const Reference< XBitmap > aCurrentValue ,
410 : : const Any& aNewValue ,
411 : : Any& aOldValue ,
412 : : Any& aConvertedValue )
413 : : throw( IllegalArgumentException )
414 : : {
415 : : // Set default return value if method failed.
416 : 0 : sal_Bool bReturn = sal_False;
417 : : // Get new value from any.
418 : : // IllegalArgumentException() can be thrown!
419 : 0 : Reference< XBitmap > aValue ;
420 [ # # ]: 0 : convertPropertyValue( aValue, aNewValue );
421 : :
422 : : // If value change ...
423 [ # # ][ # # ]: 0 : if( aValue != aCurrentValue )
424 : : {
425 : : // ... set information of change.
426 [ # # ]: 0 : aOldValue <<= aCurrentValue ;
427 [ # # ]: 0 : aConvertedValue <<= aValue ;
428 : : // Return OK - "value will be change ..."
429 : 0 : bReturn = sal_True;
430 : : }
431 : : else
432 : : {
433 : : // ... clear information of return parameter!
434 : 0 : aOldValue.clear () ;
435 : 0 : aConvertedValue.clear () ;
436 : : // Return NOTHING - "value will not be change ..."
437 : 0 : bReturn = sal_False;
438 : : }
439 : :
440 : 0 : return bReturn;
441 : : }
442 : :
443 : 0 : sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
444 : : const Reference< XInterface > aCurrentValue ,
445 : : const Any& aNewValue ,
446 : : Any& aOldValue ,
447 : : Any& aConvertedValue )
448 : : throw( IllegalArgumentException )
449 : : {
450 : : // Set default return value if method failed.
451 : 0 : sal_Bool bReturn = sal_False;
452 : : // Get new value from any.
453 : : // IllegalArgumentException() can be thrown!
454 : 0 : Reference< XInterface > aValue ;
455 [ # # ]: 0 : convertPropertyValue( aValue, aNewValue );
456 : :
457 : : // If value change ...
458 [ # # ][ # # ]: 0 : if( aValue != aCurrentValue )
459 : : {
460 : : // ... set information of change.
461 [ # # ]: 0 : aOldValue <<= aCurrentValue ;
462 [ # # ]: 0 : aConvertedValue <<= aValue ;
463 : : // Return OK - "value will be change ..."
464 : 0 : bReturn = sal_True;
465 : : }
466 : : else
467 : : {
468 : : // ... clear information of return parameter!
469 : 0 : aOldValue.clear () ;
470 : 0 : aConvertedValue.clear () ;
471 : : // Return NOTHING - "value will not be change ..."
472 : 0 : bReturn = sal_False;
473 : : }
474 : :
475 : 0 : return bReturn;
476 : : }
477 : :
478 : : }
479 : :
480 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|