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