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