Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <classes/actiontriggerseparatorpropertyset.hxx>
21 : #include <com/sun/star/beans/PropertyAttribute.hpp>
22 : #include <cppuhelper/proptypehlp.hxx>
23 : #include <cppuhelper/supportsservice.hxx>
24 : #include <cppuhelper/queryinterface.hxx>
25 : #include <cppuhelper/typeprovider.hxx>
26 : #include <vcl/svapp.hxx>
27 :
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;
33 :
34 : // Handles for properties
35 : // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
36 : // We use an enum to define these handles, to use all numbers from 0 to nn and
37 : // if you add someone, you don't must control this!
38 : // But don't forget to change values of follow defines, if you do something with this enum!
39 : enum EPROPERTIES
40 : {
41 : HANDLE_TYPE,
42 : PROPERTYCOUNT
43 : };
44 :
45 : namespace framework
46 : {
47 :
48 0 : ActionTriggerSeparatorPropertySet::ActionTriggerSeparatorPropertySet()
49 : : OBroadcastHelper ( m_aMutex )
50 : , OPropertySetHelper ( *(static_cast< OBroadcastHelper * >(this)) )
51 : , OWeakObject ( )
52 0 : , m_nSeparatorType( 0 )
53 : {
54 0 : }
55 :
56 0 : ActionTriggerSeparatorPropertySet::~ActionTriggerSeparatorPropertySet()
57 : {
58 0 : }
59 :
60 : // XInterface
61 0 : Any SAL_CALL ActionTriggerSeparatorPropertySet::queryInterface( const Type& aType )
62 : throw ( RuntimeException, std::exception )
63 : {
64 : Any a = ::cppu::queryInterface(
65 : aType,
66 : (static_cast< XServiceInfo* >(this)),
67 0 : (static_cast< XTypeProvider* >(this)));
68 :
69 0 : if( a.hasValue() )
70 0 : return a;
71 : else
72 : {
73 0 : a = OPropertySetHelper::queryInterface( aType );
74 :
75 0 : if( a.hasValue() )
76 0 : return a;
77 : }
78 :
79 0 : return OWeakObject::queryInterface( aType );
80 : }
81 :
82 0 : void ActionTriggerSeparatorPropertySet::acquire() throw()
83 : {
84 0 : OWeakObject::acquire();
85 0 : }
86 :
87 0 : void ActionTriggerSeparatorPropertySet::release() throw()
88 : {
89 0 : OWeakObject::release();
90 0 : }
91 :
92 : // XServiceInfo
93 0 : OUString SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationName()
94 : throw ( RuntimeException, std::exception )
95 : {
96 0 : return OUString( IMPLEMENTATIONNAME_ACTIONTRIGGERSEPARATOR );
97 : }
98 :
99 0 : sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::supportsService( const OUString& ServiceName )
100 : throw ( RuntimeException, std::exception )
101 : {
102 0 : return cppu::supportsService(this, ServiceName);
103 : }
104 :
105 0 : Sequence< OUString > SAL_CALL ActionTriggerSeparatorPropertySet::getSupportedServiceNames()
106 : throw ( RuntimeException, std::exception )
107 : {
108 0 : Sequence< OUString > seqServiceNames( 1 );
109 0 : seqServiceNames[0] = SERVICENAME_ACTIONTRIGGERSEPARATOR;
110 0 : return seqServiceNames;
111 : }
112 :
113 : // XTypeProvider
114 0 : Sequence< Type > SAL_CALL ActionTriggerSeparatorPropertySet::getTypes() throw ( RuntimeException, std::exception )
115 : {
116 : // Optimize this method !
117 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
118 : // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
119 : static ::cppu::OTypeCollection* pTypeCollection = NULL;
120 :
121 0 : if ( pTypeCollection == NULL )
122 : {
123 : // Ready for multithreading; get global mutex for first call of this method only! see before
124 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
125 :
126 : // Control these pointer again ... it can be, that another instance will be faster then these!
127 0 : if ( pTypeCollection == NULL )
128 : {
129 : // Create a static typecollection ...
130 : static ::cppu::OTypeCollection aTypeCollection(
131 0 : cppu::UnoType<XPropertySet>::get(),
132 0 : cppu::UnoType<XFastPropertySet>::get(),
133 0 : cppu::UnoType<XMultiPropertySet>::get(),
134 0 : cppu::UnoType<XServiceInfo>::get(),
135 0 : cppu::UnoType<XTypeProvider>::get());
136 :
137 : // ... and set his address to static pointer!
138 0 : pTypeCollection = &aTypeCollection;
139 0 : }
140 : }
141 :
142 0 : return pTypeCollection->getTypes();
143 : }
144 :
145 0 : Sequence< sal_Int8 > SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationId() throw ( RuntimeException, std::exception )
146 : {
147 0 : return css::uno::Sequence<sal_Int8>();
148 : }
149 :
150 0 : sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::convertFastPropertyValue(
151 : Any& aConvertedValue,
152 : Any& aOldValue,
153 : sal_Int32 nHandle,
154 : const Any& aValue )
155 : throw( IllegalArgumentException )
156 : {
157 : // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
158 : // Return sal_True, if changed - else return sal_False.
159 : // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
160 : // Initialize return value with sal_False !!!
161 : // (Handle can be invalid)
162 0 : bool bReturn = false;
163 :
164 0 : switch( nHandle )
165 : {
166 : case HANDLE_TYPE:
167 0 : bReturn = impl_tryToChangeProperty( m_nSeparatorType, aValue, aOldValue, aConvertedValue );
168 0 : break;
169 : }
170 :
171 : // Return state of operation.
172 0 : return bReturn;
173 : }
174 :
175 0 : void SAL_CALL ActionTriggerSeparatorPropertySet::setFastPropertyValue_NoBroadcast(
176 : sal_Int32 nHandle, const Any& aValue )
177 : throw( Exception, std::exception )
178 : {
179 0 : SolarMutexGuard aGuard;
180 :
181 : // Search for right handle ... and try to set property value.
182 0 : switch( nHandle )
183 : {
184 : case HANDLE_TYPE:
185 0 : aValue >>= m_nSeparatorType;
186 0 : break;
187 0 : }
188 0 : }
189 :
190 0 : void SAL_CALL ActionTriggerSeparatorPropertySet::getFastPropertyValue(
191 : Any& aValue, sal_Int32 nHandle ) const
192 : {
193 0 : SolarMutexGuard aGuard;
194 :
195 : // Search for right handle ... and try to get property value.
196 0 : switch( nHandle )
197 : {
198 : case HANDLE_TYPE:
199 0 : aValue <<= m_nSeparatorType;
200 0 : break;
201 0 : }
202 0 : }
203 :
204 0 : ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerSeparatorPropertySet::getInfoHelper()
205 : {
206 : // Optimize this method !
207 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
208 : // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
209 : static OPropertyArrayHelper* pInfoHelper = NULL;
210 :
211 0 : if( pInfoHelper == NULL )
212 : {
213 0 : SolarMutexGuard aGuard;
214 : // Control this pointer again, another instance can be faster then these!
215 0 : if( pInfoHelper == NULL )
216 : {
217 : // Define static member to give structure of properties to baseclass "OPropertySetHelper".
218 : // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
219 : // "sal_True" say: Table is sorted by name.
220 0 : static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
221 0 : pInfoHelper = &aInfoHelper;
222 0 : }
223 : }
224 :
225 0 : return (*pInfoHelper);
226 : }
227 :
228 0 : Reference< XPropertySetInfo > SAL_CALL ActionTriggerSeparatorPropertySet::getPropertySetInfo()
229 : throw ( RuntimeException, std::exception )
230 : {
231 : // Optimize this method !
232 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
233 : // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
234 : static Reference< XPropertySetInfo >* pInfo = NULL;
235 :
236 0 : if( pInfo == NULL )
237 : {
238 0 : SolarMutexGuard aGuard;
239 : // Control this pointer again, another instance can be faster then these!
240 0 : if( pInfo == NULL )
241 : {
242 : // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
243 : // (Use method "getInfoHelper()".)
244 0 : static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
245 0 : pInfo = &xInfo;
246 0 : }
247 : }
248 :
249 0 : return (*pInfo);
250 : }
251 :
252 0 : const Sequence< Property > ActionTriggerSeparatorPropertySet::impl_getStaticPropertyDescriptor()
253 : {
254 : const Property pActionTriggerPropertys[] =
255 : {
256 0 : Property( OUString( "SeparatorType" ), HANDLE_TYPE, cppu::UnoType<sal_Int16>::get(), PropertyAttribute::TRANSIENT )
257 0 : };
258 :
259 : // Use it to initialize sequence!
260 0 : const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT );
261 :
262 : // Return "PropertyDescriptor"
263 0 : return seqActionTriggerPropertyDescriptor;
264 : }
265 :
266 0 : bool ActionTriggerSeparatorPropertySet::impl_tryToChangeProperty(
267 : sal_Int16 aCurrentValue ,
268 : const Any& aNewValue ,
269 : Any& aOldValue ,
270 : Any& aConvertedValue )
271 : throw( IllegalArgumentException )
272 : {
273 : // Set default return value if method failed.
274 0 : bool bReturn = false;
275 : // Get new value from any.
276 : // IllegalArgumentException() can be thrown!
277 0 : sal_Int16 aValue = 0;
278 0 : convertPropertyValue( aValue, aNewValue );
279 :
280 : // If value change ...
281 0 : if( aValue != aCurrentValue )
282 : {
283 : // ... set information of change.
284 0 : aOldValue <<= aCurrentValue;
285 0 : aConvertedValue <<= aValue;
286 : // Return OK - "value will be change ..."
287 0 : bReturn = true;
288 : }
289 : else
290 : {
291 : // ... clear information of return parameter!
292 0 : aOldValue.clear ();
293 0 : aConvertedValue.clear ();
294 : // Return NOTHING - "value will not be change ..."
295 0 : bReturn = false;
296 : }
297 :
298 0 : return bReturn;
299 : }
300 :
301 : }
302 :
303 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|