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/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 : // Handles for properties
37 : // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
38 : // We use an enum to define these handles, to use all numbers from 0 to nn and
39 : // if you add someone, you don't must control this!
40 : // But don't forget to change values of follow defines, if you do something with this enum!
41 : enum EPROPERTIES
42 : {
43 : HANDLE_COMMANDURL,
44 : HANDLE_HELPURL,
45 : HANDLE_IMAGE,
46 : HANDLE_SUBCONTAINER,
47 : HANDLE_TEXT,
48 : PROPERTYCOUNT
49 : };
50 :
51 : namespace framework
52 : {
53 :
54 0 : ActionTriggerPropertySet::ActionTriggerPropertySet()
55 : : OBroadcastHelper ( m_aMutex )
56 : , OPropertySetHelper ( *(static_cast< OBroadcastHelper * >(this)))
57 : , OWeakObject ()
58 : , m_xBitmap ( 0 )
59 0 : , m_xActionTriggerContainer( 0 )
60 : {
61 0 : }
62 :
63 0 : ActionTriggerPropertySet::~ActionTriggerPropertySet()
64 : {
65 0 : }
66 :
67 : // XInterface
68 0 : Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType )
69 : throw ( RuntimeException, std::exception )
70 : {
71 : Any a = ::cppu::queryInterface(
72 : aType,
73 : (static_cast< XServiceInfo* >(this)),
74 0 : (static_cast< XTypeProvider* >(this)));
75 :
76 0 : if( a.hasValue() )
77 0 : return a;
78 : else
79 : {
80 0 : a = OPropertySetHelper::queryInterface( aType );
81 :
82 0 : if( a.hasValue() )
83 0 : return a;
84 : }
85 :
86 0 : return OWeakObject::queryInterface( aType );
87 : }
88 :
89 0 : void SAL_CALL ActionTriggerPropertySet::acquire() throw ()
90 : {
91 0 : OWeakObject::acquire();
92 0 : }
93 :
94 0 : void SAL_CALL ActionTriggerPropertySet::release() throw ()
95 : {
96 0 : OWeakObject::release();
97 0 : }
98 :
99 : // XServiceInfo
100 0 : OUString SAL_CALL ActionTriggerPropertySet::getImplementationName()
101 : throw ( RuntimeException, std::exception )
102 : {
103 0 : return OUString( IMPLEMENTATIONNAME_ACTIONTRIGGER );
104 : }
105 :
106 0 : sal_Bool SAL_CALL ActionTriggerPropertySet::supportsService( const OUString& ServiceName )
107 : throw ( RuntimeException, std::exception )
108 : {
109 0 : return cppu::supportsService(this, ServiceName);
110 : }
111 :
112 0 : Sequence< OUString > SAL_CALL ActionTriggerPropertySet::getSupportedServiceNames()
113 : throw ( RuntimeException, std::exception )
114 : {
115 0 : Sequence< OUString > seqServiceNames( 1 );
116 0 : seqServiceNames[0] = SERVICENAME_ACTIONTRIGGER;
117 0 : return seqServiceNames;
118 : }
119 :
120 : // XTypeProvider
121 0 : Sequence< Type > SAL_CALL ActionTriggerPropertySet::getTypes() throw ( RuntimeException, std::exception )
122 : {
123 : // Optimize this method !
124 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
125 : // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
126 : static ::cppu::OTypeCollection* pTypeCollection = NULL;
127 :
128 0 : if ( pTypeCollection == NULL )
129 : {
130 : // Ready for multithreading; get global mutex for first call of this method only! see before
131 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
132 :
133 : // Control these pointer again ... it can be, that another instance will be faster then these!
134 0 : if ( pTypeCollection == NULL )
135 : {
136 : // Create a static typecollection ...
137 : static ::cppu::OTypeCollection aTypeCollection(
138 0 : cppu::UnoType<XPropertySet>::get(),
139 0 : cppu::UnoType<XFastPropertySet>::get(),
140 0 : cppu::UnoType<XMultiPropertySet>::get(),
141 0 : cppu::UnoType<XServiceInfo>::get(),
142 0 : cppu::UnoType<XTypeProvider>::get());
143 :
144 : // ... and set his address to static pointer!
145 0 : pTypeCollection = &aTypeCollection;
146 0 : }
147 : }
148 :
149 0 : return pTypeCollection->getTypes();
150 : }
151 :
152 0 : Sequence< sal_Int8 > SAL_CALL ActionTriggerPropertySet::getImplementationId() throw ( RuntimeException, std::exception )
153 : {
154 0 : return css::uno::Sequence<sal_Int8>();
155 : }
156 :
157 0 : sal_Bool SAL_CALL ActionTriggerPropertySet::convertFastPropertyValue(
158 : Any& aConvertedValue,
159 : Any& aOldValue,
160 : sal_Int32 nHandle,
161 : const Any& aValue )
162 : throw( IllegalArgumentException )
163 : {
164 : // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
165 : // Return sal_True, if changed - else return sal_False.
166 : // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
167 : // Initialize return value with sal_False !!!
168 : // (Handle can be invalid)
169 0 : bool bReturn = false;
170 :
171 0 : switch( nHandle )
172 : {
173 : case HANDLE_COMMANDURL:
174 0 : bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue );
175 0 : break;
176 :
177 : case HANDLE_HELPURL:
178 0 : bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue );
179 0 : break;
180 :
181 : case HANDLE_IMAGE:
182 0 : bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue );
183 0 : break;
184 :
185 : case HANDLE_SUBCONTAINER:
186 0 : bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue );
187 0 : break;
188 :
189 : case HANDLE_TEXT:
190 0 : bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue );
191 0 : break;
192 : }
193 :
194 : // Return state of operation.
195 0 : return bReturn;
196 : }
197 :
198 0 : void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
199 : sal_Int32 nHandle, const Any& aValue )
200 : throw( Exception, std::exception )
201 : {
202 0 : SolarMutexGuard aGuard;
203 :
204 : // Search for right handle ... and try to set property value.
205 0 : switch( nHandle )
206 : {
207 : case HANDLE_COMMANDURL:
208 0 : aValue >>= m_aCommandURL;
209 0 : break;
210 :
211 : case HANDLE_HELPURL:
212 0 : aValue >>= m_aHelpURL;
213 0 : break;
214 :
215 : case HANDLE_IMAGE:
216 0 : aValue >>= m_xBitmap;
217 0 : break;
218 :
219 : case HANDLE_SUBCONTAINER:
220 0 : aValue >>= m_xActionTriggerContainer;
221 0 : break;
222 :
223 : case HANDLE_TEXT:
224 0 : aValue >>= m_aText;
225 0 : break;
226 0 : }
227 0 : }
228 :
229 0 : void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue(
230 : Any& aValue, sal_Int32 nHandle ) const
231 : {
232 0 : SolarMutexGuard aGuard;
233 :
234 : // Search for right handle ... and try to get property value.
235 0 : switch( nHandle )
236 : {
237 : case HANDLE_COMMANDURL:
238 0 : aValue <<= m_aCommandURL;
239 0 : break;
240 :
241 : case HANDLE_HELPURL:
242 0 : aValue <<= m_aHelpURL;
243 0 : break;
244 :
245 : case HANDLE_IMAGE:
246 0 : aValue <<= m_xBitmap;
247 0 : break;
248 :
249 : case HANDLE_SUBCONTAINER:
250 0 : aValue <<= m_xActionTriggerContainer;
251 0 : break;
252 :
253 : case HANDLE_TEXT:
254 0 : aValue <<= m_aText;
255 0 : break;
256 0 : }
257 0 : }
258 :
259 0 : ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerPropertySet::getInfoHelper()
260 : {
261 : // Optimize this method !
262 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
263 : // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
264 : static OPropertyArrayHelper* pInfoHelper = NULL;
265 :
266 0 : if( pInfoHelper == NULL )
267 : {
268 0 : SolarMutexGuard aGuard;
269 : // Control this pointer again, another instance can be faster then these!
270 0 : if( pInfoHelper == NULL )
271 : {
272 : // Define static member to give structure of properties to baseclass "OPropertySetHelper".
273 : // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
274 : // "sal_True" say: Table is sorted by name.
275 0 : static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
276 0 : pInfoHelper = &aInfoHelper;
277 0 : }
278 : }
279 :
280 0 : return (*pInfoHelper);
281 : }
282 :
283 0 : Reference< XPropertySetInfo > SAL_CALL ActionTriggerPropertySet::getPropertySetInfo()
284 : throw ( RuntimeException, std::exception )
285 : {
286 : // Optimize this method !
287 : // We initialize a static variable only one time. And we don't must use a mutex at every call!
288 : // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
289 : static Reference< XPropertySetInfo >* pInfo = NULL;
290 :
291 0 : if( pInfo == NULL )
292 : {
293 0 : SolarMutexGuard aGuard;
294 : // Control this pointer again, another instance can be faster then these!
295 0 : if( pInfo == NULL )
296 : {
297 : // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
298 : // (Use method "getInfoHelper()".)
299 0 : static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
300 0 : pInfo = &xInfo;
301 0 : }
302 : }
303 :
304 0 : return (*pInfo);
305 : }
306 :
307 0 : const Sequence< Property > ActionTriggerPropertySet::impl_getStaticPropertyDescriptor()
308 : {
309 : const Property pActionTriggerPropertys[] =
310 : {
311 0 : Property( OUString( "CommandURL" ), HANDLE_COMMANDURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
312 0 : Property( OUString( "HelpURL" ), HANDLE_HELPURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
313 0 : Property( OUString( "Image" ), HANDLE_IMAGE , cppu::UnoType<XBitmap>::get(), PropertyAttribute::TRANSIENT ),
314 0 : Property( OUString( "SubContainer" ), HANDLE_SUBCONTAINER , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
315 0 : Property( OUString( "Text" ), HANDLE_TEXT , cppu::UnoType<XInterface>::get(), PropertyAttribute::TRANSIENT )
316 0 : };
317 :
318 : // Use it to initialize sequence!
319 0 : const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT );
320 :
321 : // Return "PropertyDescriptor"
322 0 : return seqActionTriggerPropertyDescriptor;
323 : }
324 :
325 0 : bool ActionTriggerPropertySet::impl_tryToChangeProperty(
326 : const OUString& sCurrentValue ,
327 : const Any& aNewValue ,
328 : Any& aOldValue ,
329 : Any& aConvertedValue )
330 : throw( IllegalArgumentException )
331 : {
332 : // Set default return value if method failed.
333 0 : bool bReturn = false;
334 : // Get new value from any.
335 : // IllegalArgumentException() can be thrown!
336 0 : OUString sValue;
337 0 : convertPropertyValue( sValue, aNewValue );
338 :
339 : // If value change ...
340 0 : if( sValue != sCurrentValue )
341 : {
342 : // ... set information of change.
343 0 : aOldValue <<= sCurrentValue;
344 0 : aConvertedValue <<= sValue;
345 : // Return OK - "value will be change ..."
346 0 : bReturn = true;
347 : }
348 : else
349 : {
350 : // ... clear information of return parameter!
351 0 : aOldValue.clear ();
352 0 : aConvertedValue.clear ();
353 : // Return NOTHING - "value will not be change ..."
354 0 : bReturn = false;
355 : }
356 :
357 0 : return bReturn;
358 : }
359 :
360 0 : bool ActionTriggerPropertySet::impl_tryToChangeProperty(
361 : const Reference< XBitmap > aCurrentValue ,
362 : const Any& aNewValue ,
363 : Any& aOldValue ,
364 : Any& aConvertedValue )
365 : throw( IllegalArgumentException )
366 : {
367 : // Set default return value if method failed.
368 0 : bool bReturn = false;
369 : // Get new value from any.
370 : // IllegalArgumentException() can be thrown!
371 0 : Reference< XBitmap > aValue;
372 0 : convertPropertyValue( aValue, aNewValue );
373 :
374 : // If value change ...
375 0 : if( aValue != aCurrentValue )
376 : {
377 : // ... set information of change.
378 0 : aOldValue <<= aCurrentValue;
379 0 : aConvertedValue <<= aValue;
380 : // Return OK - "value will be change ..."
381 0 : bReturn = true;
382 : }
383 : else
384 : {
385 : // ... clear information of return parameter!
386 0 : aOldValue.clear ();
387 0 : aConvertedValue.clear ();
388 : // Return NOTHING - "value will not be change ..."
389 0 : bReturn = false;
390 : }
391 :
392 0 : return bReturn;
393 : }
394 :
395 0 : bool ActionTriggerPropertySet::impl_tryToChangeProperty(
396 : const Reference< XInterface > aCurrentValue ,
397 : const Any& aNewValue ,
398 : Any& aOldValue ,
399 : Any& aConvertedValue )
400 : throw( IllegalArgumentException )
401 : {
402 : // Set default return value if method failed.
403 0 : bool bReturn = false;
404 : // Get new value from any.
405 : // IllegalArgumentException() can be thrown!
406 0 : Reference< XInterface > aValue;
407 0 : convertPropertyValue( aValue, aNewValue );
408 :
409 : // If value change ...
410 0 : if( aValue != aCurrentValue )
411 : {
412 : // ... set information of change.
413 0 : aOldValue <<= aCurrentValue;
414 0 : aConvertedValue <<= aValue;
415 : // Return OK - "value will be change ..."
416 0 : bReturn = true;
417 : }
418 : else
419 : {
420 : // ... clear information of return parameter!
421 0 : aOldValue.clear ();
422 0 : aConvertedValue.clear ();
423 : // Return NOTHING - "value will not be change ..."
424 0 : bReturn = false;
425 : }
426 :
427 0 : return bReturn;
428 : }
429 :
430 : }
431 :
432 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|