/src/libreoffice/framework/source/fwe/classes/actiontriggerpropertyset.cxx
Line | Count | Source |
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/actiontriggerpropertyset.hxx> |
21 | | #include <com/sun/star/beans/PropertyAttribute.hpp> |
22 | | #include <cppuhelper/proptypehlp.hxx> |
23 | | #include <cppuhelper/queryinterface.hxx> |
24 | | #include <cppuhelper/supportsservice.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 | | //struct SAL_DLLPUBLIC_IMPORT ::cppu::OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType >; |
35 | | |
36 | | namespace { |
37 | | |
38 | | // Handles for properties |
39 | | // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!) |
40 | | // We use an enum to define these handles, to use all numbers from 0 to nn and |
41 | | // if you add someone, you don't must control this! |
42 | | // But don't forget to change values of follow defines, if you do something with this enum! |
43 | | enum EPROPERTIES |
44 | | { |
45 | | HANDLE_COMMANDURL, |
46 | | HANDLE_HELPURL, |
47 | | HANDLE_IMAGE, |
48 | | HANDLE_SUBCONTAINER, |
49 | | HANDLE_TEXT, |
50 | | PROPERTYCOUNT |
51 | | }; |
52 | | |
53 | | } |
54 | | |
55 | | namespace framework |
56 | | { |
57 | | |
58 | | ActionTriggerPropertySet::ActionTriggerPropertySet() |
59 | 0 | : OBroadcastHelper ( m_aMutex ) |
60 | 0 | , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) ) |
61 | 0 | { |
62 | 0 | } |
63 | | |
64 | | ActionTriggerPropertySet::~ActionTriggerPropertySet() |
65 | 0 | { |
66 | 0 | } |
67 | | |
68 | | // XInterface |
69 | | Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType ) |
70 | 0 | { |
71 | 0 | Any a = ::cppu::queryInterface( |
72 | 0 | aType, |
73 | 0 | static_cast< XServiceInfo* >(this), |
74 | 0 | static_cast< XTypeProvider* >(this)); |
75 | |
|
76 | 0 | if( a.hasValue() ) |
77 | 0 | return a; |
78 | 0 | else |
79 | 0 | { |
80 | 0 | a = OPropertySetHelper::queryInterface( aType ); |
81 | |
|
82 | 0 | if( a.hasValue() ) |
83 | 0 | return a; |
84 | 0 | } |
85 | | |
86 | 0 | return OWeakObject::queryInterface( aType ); |
87 | 0 | } |
88 | | |
89 | | void SAL_CALL ActionTriggerPropertySet::acquire() noexcept |
90 | 0 | { |
91 | 0 | OWeakObject::acquire(); |
92 | 0 | } |
93 | | |
94 | | void SAL_CALL ActionTriggerPropertySet::release() noexcept |
95 | 0 | { |
96 | 0 | OWeakObject::release(); |
97 | 0 | } |
98 | | |
99 | | // XServiceInfo |
100 | | OUString SAL_CALL ActionTriggerPropertySet::getImplementationName() |
101 | 0 | { |
102 | 0 | return IMPLEMENTATIONNAME_ACTIONTRIGGER; |
103 | 0 | } |
104 | | |
105 | | sal_Bool SAL_CALL ActionTriggerPropertySet::supportsService( const OUString& ServiceName ) |
106 | 0 | { |
107 | 0 | return cppu::supportsService(this, ServiceName); |
108 | 0 | } |
109 | | |
110 | | Sequence< OUString > SAL_CALL ActionTriggerPropertySet::getSupportedServiceNames() |
111 | 0 | { |
112 | 0 | Sequence<OUString> seqServiceNames { SERVICENAME_ACTIONTRIGGER }; |
113 | 0 | return seqServiceNames; |
114 | 0 | } |
115 | | |
116 | | // XTypeProvider |
117 | | Sequence< Type > SAL_CALL ActionTriggerPropertySet::getTypes() |
118 | 0 | { |
119 | | // Create a static typecollection ... |
120 | 0 | static ::cppu::OTypeCollection ourTypeCollection( |
121 | 0 | cppu::UnoType<XPropertySet>::get(), |
122 | 0 | cppu::UnoType<XFastPropertySet>::get(), |
123 | 0 | cppu::UnoType<XMultiPropertySet>::get(), |
124 | 0 | cppu::UnoType<XServiceInfo>::get(), |
125 | 0 | cppu::UnoType<XTypeProvider>::get()); |
126 | | |
127 | |
|
128 | 0 | return ourTypeCollection.getTypes(); |
129 | 0 | } |
130 | | |
131 | | Sequence< sal_Int8 > SAL_CALL ActionTriggerPropertySet::getImplementationId() |
132 | 0 | { |
133 | 0 | return css::uno::Sequence<sal_Int8>(); |
134 | 0 | } |
135 | | |
136 | | sal_Bool SAL_CALL ActionTriggerPropertySet::convertFastPropertyValue( |
137 | | Any& aConvertedValue, |
138 | | Any& aOldValue, |
139 | | sal_Int32 nHandle, |
140 | | const Any& aValue ) |
141 | 0 | { |
142 | | // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()". |
143 | | // Return sal_True, if changed - else return sal_False. |
144 | | // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!! |
145 | | // Initialize return value with sal_False !!! |
146 | | // (Handle can be invalid) |
147 | 0 | bool bReturn = false; |
148 | |
|
149 | 0 | switch( nHandle ) |
150 | 0 | { |
151 | 0 | case HANDLE_COMMANDURL: |
152 | 0 | bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue ); |
153 | 0 | break; |
154 | | |
155 | 0 | case HANDLE_HELPURL: |
156 | 0 | bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue ); |
157 | 0 | break; |
158 | | |
159 | 0 | case HANDLE_IMAGE: |
160 | 0 | bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue ); |
161 | 0 | break; |
162 | | |
163 | 0 | case HANDLE_SUBCONTAINER: |
164 | 0 | bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue ); |
165 | 0 | break; |
166 | | |
167 | 0 | case HANDLE_TEXT: |
168 | 0 | bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue ); |
169 | 0 | break; |
170 | 0 | } |
171 | | |
172 | | // Return state of operation. |
173 | 0 | return bReturn; |
174 | 0 | } |
175 | | |
176 | | void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast( |
177 | | sal_Int32 nHandle, const Any& aValue ) |
178 | 0 | { |
179 | 0 | SolarMutexGuard aGuard; |
180 | | |
181 | | // Search for right handle ... and try to set property value. |
182 | 0 | switch( nHandle ) |
183 | 0 | { |
184 | 0 | case HANDLE_COMMANDURL: |
185 | 0 | aValue >>= m_aCommandURL; |
186 | 0 | break; |
187 | | |
188 | 0 | case HANDLE_HELPURL: |
189 | 0 | aValue >>= m_aHelpURL; |
190 | 0 | break; |
191 | | |
192 | 0 | case HANDLE_IMAGE: |
193 | 0 | aValue >>= m_xBitmap; |
194 | 0 | break; |
195 | | |
196 | 0 | case HANDLE_SUBCONTAINER: |
197 | 0 | aValue >>= m_xActionTriggerContainer; |
198 | 0 | break; |
199 | | |
200 | 0 | case HANDLE_TEXT: |
201 | 0 | aValue >>= m_aText; |
202 | 0 | break; |
203 | 0 | } |
204 | 0 | } |
205 | | |
206 | | void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue( |
207 | | Any& aValue, sal_Int32 nHandle ) const |
208 | 0 | { |
209 | 0 | SolarMutexGuard aGuard; |
210 | | |
211 | | // Search for right handle ... and try to get property value. |
212 | 0 | switch( nHandle ) |
213 | 0 | { |
214 | 0 | case HANDLE_COMMANDURL: |
215 | 0 | aValue <<= m_aCommandURL; |
216 | 0 | break; |
217 | | |
218 | 0 | case HANDLE_HELPURL: |
219 | 0 | aValue <<= m_aHelpURL; |
220 | 0 | break; |
221 | | |
222 | 0 | case HANDLE_IMAGE: |
223 | 0 | aValue <<= m_xBitmap; |
224 | 0 | break; |
225 | | |
226 | 0 | case HANDLE_SUBCONTAINER: |
227 | 0 | aValue <<= m_xActionTriggerContainer; |
228 | 0 | break; |
229 | | |
230 | 0 | case HANDLE_TEXT: |
231 | 0 | aValue <<= m_aText; |
232 | 0 | break; |
233 | 0 | } |
234 | 0 | } |
235 | | |
236 | | ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerPropertySet::getInfoHelper() |
237 | 0 | { |
238 | | // Define static member to give structure of properties to baseclass "OPropertySetHelper". |
239 | | // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable. |
240 | | // "true" say: Table is sorted by name. |
241 | 0 | static OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true ); |
242 | |
|
243 | 0 | return ourInfoHelper; |
244 | 0 | } |
245 | | |
246 | | Reference< XPropertySetInfo > SAL_CALL ActionTriggerPropertySet::getPropertySetInfo() |
247 | 0 | { |
248 | | // Create structure of propertysetinfo for baseclass "OPropertySetHelper". |
249 | | // (Use method "getInfoHelper()".) |
250 | 0 | static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); |
251 | |
|
252 | 0 | return xInfo; |
253 | 0 | } |
254 | | |
255 | | Sequence< Property > ActionTriggerPropertySet::impl_getStaticPropertyDescriptor() |
256 | 0 | { |
257 | 0 | return |
258 | 0 | { |
259 | 0 | Property( u"CommandURL"_ustr , HANDLE_COMMANDURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ), |
260 | 0 | Property( u"HelpURL"_ustr , HANDLE_HELPURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ), |
261 | 0 | Property( u"Image"_ustr , HANDLE_IMAGE , cppu::UnoType<XBitmap>::get(), PropertyAttribute::TRANSIENT ), |
262 | 0 | Property( u"SubContainer"_ustr , HANDLE_SUBCONTAINER , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ), |
263 | 0 | Property( u"Text"_ustr , HANDLE_TEXT , cppu::UnoType<XInterface>::get(), PropertyAttribute::TRANSIENT ) |
264 | 0 | }; |
265 | 0 | } |
266 | | |
267 | | // static |
268 | | bool ActionTriggerPropertySet::impl_tryToChangeProperty( |
269 | | const OUString& sCurrentValue , |
270 | | const Any& aNewValue , |
271 | | Any& aOldValue , |
272 | | Any& aConvertedValue ) |
273 | 0 | { |
274 | | // Set default return value if method failed. |
275 | 0 | bool bReturn = false; |
276 | | // Get new value from any. |
277 | | // IllegalArgumentException() can be thrown! |
278 | 0 | OUString sValue; |
279 | 0 | convertPropertyValue( sValue, aNewValue ); |
280 | | |
281 | | // If value change ... |
282 | 0 | if( sValue != sCurrentValue ) |
283 | 0 | { |
284 | | // ... set information of change. |
285 | 0 | aOldValue <<= sCurrentValue; |
286 | 0 | aConvertedValue <<= sValue; |
287 | | // Return OK - "value will be change ..." |
288 | 0 | bReturn = true; |
289 | 0 | } |
290 | 0 | else |
291 | 0 | { |
292 | | // ... clear information of return parameter! |
293 | 0 | aOldValue.clear (); |
294 | 0 | aConvertedValue.clear (); |
295 | | // Return NOTHING - "value will not be change ..." |
296 | 0 | bReturn = false; |
297 | 0 | } |
298 | |
|
299 | 0 | return bReturn; |
300 | 0 | } |
301 | | |
302 | | // static |
303 | | bool ActionTriggerPropertySet::impl_tryToChangeProperty( |
304 | | const Reference< XBitmap >& aCurrentValue , |
305 | | const Any& aNewValue , |
306 | | Any& aOldValue , |
307 | | Any& aConvertedValue ) |
308 | 0 | { |
309 | | // Set default return value if method failed. |
310 | 0 | bool bReturn = false; |
311 | | // Get new value from any. |
312 | | // IllegalArgumentException() can be thrown! |
313 | 0 | Reference< XBitmap > aValue; |
314 | 0 | convertPropertyValue( aValue, aNewValue ); |
315 | | |
316 | | // If value change ... |
317 | 0 | if( aValue != aCurrentValue ) |
318 | 0 | { |
319 | | // ... set information of change. |
320 | 0 | aOldValue <<= aCurrentValue; |
321 | 0 | aConvertedValue <<= aValue; |
322 | | // Return OK - "value will be change ..." |
323 | 0 | bReturn = true; |
324 | 0 | } |
325 | 0 | else |
326 | 0 | { |
327 | | // ... clear information of return parameter! |
328 | 0 | aOldValue.clear (); |
329 | 0 | aConvertedValue.clear (); |
330 | | // Return NOTHING - "value will not be change ..." |
331 | 0 | bReturn = false; |
332 | 0 | } |
333 | |
|
334 | 0 | return bReturn; |
335 | 0 | } |
336 | | |
337 | | // static |
338 | | bool ActionTriggerPropertySet::impl_tryToChangeProperty( |
339 | | const Reference< XInterface >& aCurrentValue , |
340 | | const Any& aNewValue , |
341 | | Any& aOldValue , |
342 | | Any& aConvertedValue ) |
343 | 0 | { |
344 | | // Set default return value if method failed. |
345 | 0 | bool bReturn = false; |
346 | | // Get new value from any. |
347 | | // IllegalArgumentException() can be thrown! |
348 | 0 | Reference< XInterface > aValue; |
349 | 0 | convertPropertyValue( aValue, aNewValue ); |
350 | | |
351 | | // If value change ... |
352 | 0 | if( aValue != aCurrentValue ) |
353 | 0 | { |
354 | | // ... set information of change. |
355 | 0 | aOldValue <<= aCurrentValue; |
356 | 0 | aConvertedValue <<= aValue; |
357 | | // Return OK - "value will be change ..." |
358 | 0 | bReturn = true; |
359 | 0 | } |
360 | 0 | else |
361 | 0 | { |
362 | | // ... clear information of return parameter! |
363 | 0 | aOldValue.clear (); |
364 | 0 | aConvertedValue.clear (); |
365 | | // Return NOTHING - "value will not be change ..." |
366 | 0 | bReturn = false; |
367 | 0 | } |
368 | |
|
369 | 0 | return bReturn; |
370 | 0 | } |
371 | | |
372 | | } |
373 | | |
374 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |