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