16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
196d739b60SAndrew Rist  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
226d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <classes/actiontriggerseparatorpropertyset.hxx>
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
29cdf0e10cSrcweir #include <cppuhelper/proptypehlp.hxx>
30cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace cppu;
35cdf0e10cSrcweir using namespace com::sun::star::uno;
36cdf0e10cSrcweir using namespace com::sun::star::beans;
37cdf0e10cSrcweir using namespace com::sun::star::lang;
38cdf0e10cSrcweir using namespace com::sun::star::awt;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // Handles for properties
41cdf0e10cSrcweir // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
42cdf0e10cSrcweir // We use an enum to define these handles, to use all numbers from 0 to nn and
43cdf0e10cSrcweir // if you add someone, you don't must control this!
44cdf0e10cSrcweir // But don't forget to change values of follow defines, if you do something with this enum!
45cdf0e10cSrcweir enum EPROPERTIES
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	HANDLE_TYPE,
48cdf0e10cSrcweir 	PROPERTYCOUNT
49cdf0e10cSrcweir };
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace framework
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 
ActionTriggerSeparatorPropertySet(const Reference<XMultiServiceFactory> &)54cdf0e10cSrcweir ActionTriggerSeparatorPropertySet::ActionTriggerSeparatorPropertySet( const Reference< XMultiServiceFactory >& /*ServiceManager*/ )
55cdf0e10cSrcweir         :   ThreadHelpBase          ( &Application::GetSolarMutex()                     )
56cdf0e10cSrcweir         ,   OBroadcastHelper        ( m_aLock.getShareableOslMutex()                    )
57cdf0e10cSrcweir 		,	OPropertySetHelper		( *SAL_STATIC_CAST( OBroadcastHelper *, this )		)
58cdf0e10cSrcweir 		,	OWeakObject				(													)
59cdf0e10cSrcweir 		,	m_nSeparatorType( 0 )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
~ActionTriggerSeparatorPropertySet()63cdf0e10cSrcweir ActionTriggerSeparatorPropertySet::~ActionTriggerSeparatorPropertySet()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // XInterface
queryInterface(const Type & aType)68cdf0e10cSrcweir Any SAL_CALL ActionTriggerSeparatorPropertySet::queryInterface( const Type& aType )
69cdf0e10cSrcweir throw ( RuntimeException )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	Any a = ::cppu::queryInterface(
72cdf0e10cSrcweir 				aType ,
73*5b6a8715SAriel Constenla-Haile 				SAL_STATIC_CAST( XServiceInfo*, this ),
74*5b6a8715SAriel Constenla-Haile 				SAL_STATIC_CAST( XTypeProvider*,  this ));
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	if( a.hasValue() )
77cdf0e10cSrcweir 		return a;
78cdf0e10cSrcweir 	else
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		a = OPropertySetHelper::queryInterface( aType );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 		if( a.hasValue() )
83cdf0e10cSrcweir 			return a;
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	return OWeakObject::queryInterface( aType );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
acquire()89cdf0e10cSrcweir void ActionTriggerSeparatorPropertySet::acquire() throw()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	OWeakObject::acquire();
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
release()94cdf0e10cSrcweir void ActionTriggerSeparatorPropertySet::release() throw()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	OWeakObject::release();
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir // XServiceInfo
getImplementationName()100cdf0e10cSrcweir ::rtl::OUString SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationName()
101cdf0e10cSrcweir throw ( RuntimeException )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGERSEPARATOR ));
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
supportsService(const::rtl::OUString & ServiceName)106cdf0e10cSrcweir sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::supportsService( const ::rtl::OUString& ServiceName )
107cdf0e10cSrcweir throw ( RuntimeException )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGERSEPARATOR ))
110cdf0e10cSrcweir 		return sal_True;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	return sal_False;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
getSupportedServiceNames()115cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ActionTriggerSeparatorPropertySet::getSupportedServiceNames()
116cdf0e10cSrcweir throw ( RuntimeException )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     Sequence< ::rtl::OUString > seqServiceNames( 1 );
119cdf0e10cSrcweir 	seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR ));
120cdf0e10cSrcweir 	return seqServiceNames;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir // XTypeProvider
getTypes()124cdf0e10cSrcweir Sequence< Type > SAL_CALL ActionTriggerSeparatorPropertySet::getTypes() throw ( RuntimeException )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	// Optimize this method !
127cdf0e10cSrcweir 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
128cdf0e10cSrcweir 	// For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
129cdf0e10cSrcweir 	static ::cppu::OTypeCollection* pTypeCollection = NULL ;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	if ( pTypeCollection == NULL )
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		// Ready for multithreading; get global mutex for first call of this method only! see before
134cdf0e10cSrcweir 		osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 		// Control these pointer again ... it can be, that another instance will be faster then these!
137cdf0e10cSrcweir 		if ( pTypeCollection == NULL )
138cdf0e10cSrcweir 		{
139cdf0e10cSrcweir 			// Create a static typecollection ...
140cdf0e10cSrcweir 			static ::cppu::OTypeCollection aTypeCollection(
141cdf0e10cSrcweir 						::getCppuType(( const Reference< XPropertySet			>*)NULL ) ,
142cdf0e10cSrcweir 						::getCppuType(( const Reference< XFastPropertySet		>*)NULL	) ,
143cdf0e10cSrcweir 						::getCppuType(( const Reference< XMultiPropertySet		>*)NULL	) ,
144cdf0e10cSrcweir 						::getCppuType(( const Reference< XServiceInfo			>*)NULL ) ,
145cdf0e10cSrcweir 						::getCppuType(( const Reference< XTypeProvider			>*)NULL ) ) ;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 			// ... and set his address to static pointer!
148cdf0e10cSrcweir 			pTypeCollection = &aTypeCollection ;
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	return pTypeCollection->getTypes() ;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
getImplementationId()155cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationId() throw ( RuntimeException )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir 	// Create one Id for all instances of this class.
158cdf0e10cSrcweir 	// Use ethernet address to do this! (sal_True)
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	// Optimize this method
161cdf0e10cSrcweir 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
162cdf0e10cSrcweir 	// For the first call; pID is NULL - for the second call pID is different from NULL!
163cdf0e10cSrcweir 	static ::cppu::OImplementationId* pID = NULL ;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	if ( pID == NULL )
166cdf0e10cSrcweir 	{
167cdf0e10cSrcweir 		// Ready for multithreading; get global mutex for first call of this method only! see before
168cdf0e10cSrcweir 		osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 		// Control these pointer again ... it can be, that another instance will be faster then these!
171cdf0e10cSrcweir 		if ( pID == NULL )
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			// Create a new static ID ...
174cdf0e10cSrcweir 			static ::cppu::OImplementationId aID( sal_False ) ;
175cdf0e10cSrcweir 			// ... and set his address to static pointer!
176cdf0e10cSrcweir 			pID = &aID ;
177cdf0e10cSrcweir 		}
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	return pID->getImplementationId() ;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
184cdf0e10cSrcweir //	OPropertySetHelper implementation
185cdf0e10cSrcweir //---------------------------------------------------------------------------------------------------------
186cdf0e10cSrcweir 
convertFastPropertyValue(Any & aConvertedValue,Any & aOldValue,sal_Int32 nHandle,const Any & aValue)187cdf0e10cSrcweir sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::convertFastPropertyValue(
188cdf0e10cSrcweir 	Any&		aConvertedValue,
189cdf0e10cSrcweir 	Any&		aOldValue,
190cdf0e10cSrcweir 	sal_Int32	nHandle,
191cdf0e10cSrcweir 	const Any&	aValue	)
192cdf0e10cSrcweir throw( IllegalArgumentException )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	//	Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
195cdf0e10cSrcweir 	//	Return sal_True, if changed - else return sal_False.
196cdf0e10cSrcweir 	//	Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
197cdf0e10cSrcweir 	//	Initialize return value with sal_False !!!
198cdf0e10cSrcweir 	//	(Handle can be invalid)
199cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	switch( nHandle )
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		case HANDLE_TYPE:
204cdf0e10cSrcweir 			bReturn = impl_tryToChangeProperty( m_nSeparatorType, aValue, aOldValue, aConvertedValue );
205cdf0e10cSrcweir 			break;
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	// Return state of operation.
209cdf0e10cSrcweir 	return bReturn;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & aValue)213cdf0e10cSrcweir void SAL_CALL ActionTriggerSeparatorPropertySet::setFastPropertyValue_NoBroadcast(
214cdf0e10cSrcweir 	sal_Int32 nHandle, const Any& aValue )
215cdf0e10cSrcweir throw( Exception )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	// Search for right handle ... and try to set property value.
220cdf0e10cSrcweir 	switch( nHandle )
221cdf0e10cSrcweir 	{
222cdf0e10cSrcweir 		case HANDLE_TYPE:
223cdf0e10cSrcweir 			aValue >>= m_nSeparatorType;
224cdf0e10cSrcweir 			break;
225cdf0e10cSrcweir 	}
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
getFastPropertyValue(Any & aValue,sal_Int32 nHandle) const228cdf0e10cSrcweir void SAL_CALL ActionTriggerSeparatorPropertySet::getFastPropertyValue(
229cdf0e10cSrcweir 	Any& aValue, sal_Int32 nHandle ) const
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	// Search for right handle ... and try to get property value.
234cdf0e10cSrcweir 	switch( nHandle )
235cdf0e10cSrcweir 	{
236cdf0e10cSrcweir 		case HANDLE_TYPE:
237cdf0e10cSrcweir 			aValue <<= m_nSeparatorType;
238cdf0e10cSrcweir 			break;
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
getInfoHelper()242cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerSeparatorPropertySet::getInfoHelper()
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	// Optimize this method !
245cdf0e10cSrcweir 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
246cdf0e10cSrcweir 	// For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
247cdf0e10cSrcweir 	static OPropertyArrayHelper* pInfoHelper = NULL;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	if( pInfoHelper == NULL )
250cdf0e10cSrcweir 	{
251cdf0e10cSrcweir 		// Ready for multithreading
252cdf0e10cSrcweir         ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
253cdf0e10cSrcweir 		// Control this pointer again, another instance can be faster then these!
254cdf0e10cSrcweir 		if( pInfoHelper == NULL )
255cdf0e10cSrcweir 		{
256cdf0e10cSrcweir 			// Define static member to give structure of properties to baseclass "OPropertySetHelper".
257cdf0e10cSrcweir 			// "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
258cdf0e10cSrcweir 			// "sal_True" say: Table is sorted by name.
259cdf0e10cSrcweir 			static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
260cdf0e10cSrcweir 			pInfoHelper = &aInfoHelper;
261cdf0e10cSrcweir 		}
262cdf0e10cSrcweir 	}
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 	return (*pInfoHelper);
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
getPropertySetInfo()267cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL ActionTriggerSeparatorPropertySet::getPropertySetInfo()
268cdf0e10cSrcweir throw ( RuntimeException )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir 	// Optimize this method !
271cdf0e10cSrcweir 	// We initialize a static variable only one time. And we don't must use a mutex at every call!
272cdf0e10cSrcweir 	// For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
273cdf0e10cSrcweir 	static Reference< XPropertySetInfo >* pInfo = NULL ;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 	if( pInfo == NULL )
276cdf0e10cSrcweir 	{
277cdf0e10cSrcweir 		// Ready for multithreading
278cdf0e10cSrcweir         ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
279cdf0e10cSrcweir 		// Control this pointer again, another instance can be faster then these!
280cdf0e10cSrcweir 		if( pInfo == NULL )
281cdf0e10cSrcweir 		{
282cdf0e10cSrcweir 			// Create structure of propertysetinfo for baseclass "OPropertySetHelper".
283cdf0e10cSrcweir 			// (Use method "getInfoHelper()".)
284cdf0e10cSrcweir 			static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
285cdf0e10cSrcweir 			pInfo = &xInfo;
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 	}
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	return (*pInfo);
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
impl_getStaticPropertyDescriptor()292cdf0e10cSrcweir const Sequence< Property > ActionTriggerSeparatorPropertySet::impl_getStaticPropertyDescriptor()
293cdf0e10cSrcweir {
294cdf0e10cSrcweir 	static const Property pActionTriggerPropertys[] =
295cdf0e10cSrcweir 	{
296cdf0e10cSrcweir 		Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SeparatorType" )), HANDLE_TYPE, ::getCppuType((sal_Int16*)0), PropertyAttribute::TRANSIENT )
297cdf0e10cSrcweir 	};
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	// Use it to initialize sequence!
300cdf0e10cSrcweir 	static const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	// Return static "PropertyDescriptor"
303cdf0e10cSrcweir 	return seqActionTriggerPropertyDescriptor ;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
307cdf0e10cSrcweir //******************************************************************************************************************************
308cdf0e10cSrcweir //	private method
309cdf0e10cSrcweir //******************************************************************************************************************************
impl_tryToChangeProperty(sal_Int16 aCurrentValue,const Any & aNewValue,Any & aOldValue,Any & aConvertedValue)310cdf0e10cSrcweir sal_Bool ActionTriggerSeparatorPropertySet::impl_tryToChangeProperty(
311cdf0e10cSrcweir 	sal_Int16			aCurrentValue	,
312cdf0e10cSrcweir 	const	Any&		aNewValue		,
313cdf0e10cSrcweir 	Any&				aOldValue		,
314cdf0e10cSrcweir 	Any&				aConvertedValue	)
315cdf0e10cSrcweir throw( IllegalArgumentException )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	// Set default return value if method failed.
318cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
319cdf0e10cSrcweir 	// Get new value from any.
320cdf0e10cSrcweir 	// IllegalArgumentException() can be thrown!
321cdf0e10cSrcweir 	sal_Int16 aValue = 0;
322cdf0e10cSrcweir 	convertPropertyValue( aValue, aNewValue );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 	// If value change ...
325cdf0e10cSrcweir 	if( aValue != aCurrentValue )
326cdf0e10cSrcweir 	{
327cdf0e10cSrcweir 		// ... set information of change.
328cdf0e10cSrcweir 		aOldValue		<<= aCurrentValue	;
329cdf0e10cSrcweir 		aConvertedValue	<<= aValue			;
330cdf0e10cSrcweir 		// Return OK - "value will be change ..."
331cdf0e10cSrcweir 		bReturn = sal_True;
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir 	else
334cdf0e10cSrcweir 	{
335cdf0e10cSrcweir 		// ... clear information of return parameter!
336cdf0e10cSrcweir 		aOldValue.clear			() ;
337cdf0e10cSrcweir 		aConvertedValue.clear	() ;
338cdf0e10cSrcweir 		// Return NOTHING - "value will not be change ..."
339cdf0e10cSrcweir 		bReturn = sal_False;
340cdf0e10cSrcweir 	}
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	return bReturn;
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347