Avoid potential negative array index access to cached text.
[LibreOffice.git] / framework / source / fwe / classes / actiontriggerpropertyset.cxx
blob4592174df5ad0279a3738065495974b3fefbcb9b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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;
34 //struct SAL_DLLPUBLIC_IMPORT ::cppu::OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType >;
36 namespace {
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
45 HANDLE_COMMANDURL,
46 HANDLE_HELPURL,
47 HANDLE_IMAGE,
48 HANDLE_SUBCONTAINER,
49 HANDLE_TEXT,
50 PROPERTYCOUNT
55 namespace framework
58 ActionTriggerPropertySet::ActionTriggerPropertySet()
59 : OBroadcastHelper ( m_aMutex )
60 , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) )
64 ActionTriggerPropertySet::~ActionTriggerPropertySet()
68 // XInterface
69 Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType )
71 Any a = ::cppu::queryInterface(
72 aType,
73 static_cast< XServiceInfo* >(this),
74 static_cast< XTypeProvider* >(this));
76 if( a.hasValue() )
77 return a;
78 else
80 a = OPropertySetHelper::queryInterface( aType );
82 if( a.hasValue() )
83 return a;
86 return OWeakObject::queryInterface( aType );
89 void SAL_CALL ActionTriggerPropertySet::acquire() noexcept
91 OWeakObject::acquire();
94 void SAL_CALL ActionTriggerPropertySet::release() noexcept
96 OWeakObject::release();
99 // XServiceInfo
100 OUString SAL_CALL ActionTriggerPropertySet::getImplementationName()
102 return IMPLEMENTATIONNAME_ACTIONTRIGGER;
105 sal_Bool SAL_CALL ActionTriggerPropertySet::supportsService( const OUString& ServiceName )
107 return cppu::supportsService(this, ServiceName);
110 Sequence< OUString > SAL_CALL ActionTriggerPropertySet::getSupportedServiceNames()
112 Sequence<OUString> seqServiceNames { SERVICENAME_ACTIONTRIGGER };
113 return seqServiceNames;
116 // XTypeProvider
117 Sequence< Type > SAL_CALL ActionTriggerPropertySet::getTypes()
119 // Create a static typecollection ...
120 static ::cppu::OTypeCollection ourTypeCollection(
121 cppu::UnoType<XPropertySet>::get(),
122 cppu::UnoType<XFastPropertySet>::get(),
123 cppu::UnoType<XMultiPropertySet>::get(),
124 cppu::UnoType<XServiceInfo>::get(),
125 cppu::UnoType<XTypeProvider>::get());
128 return ourTypeCollection.getTypes();
131 Sequence< sal_Int8 > SAL_CALL ActionTriggerPropertySet::getImplementationId()
133 return css::uno::Sequence<sal_Int8>();
136 sal_Bool SAL_CALL ActionTriggerPropertySet::convertFastPropertyValue(
137 Any& aConvertedValue,
138 Any& aOldValue,
139 sal_Int32 nHandle,
140 const Any& aValue )
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 bool bReturn = false;
149 switch( nHandle )
151 case HANDLE_COMMANDURL:
152 bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue );
153 break;
155 case HANDLE_HELPURL:
156 bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue );
157 break;
159 case HANDLE_IMAGE:
160 bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue );
161 break;
163 case HANDLE_SUBCONTAINER:
164 bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue );
165 break;
167 case HANDLE_TEXT:
168 bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue );
169 break;
172 // Return state of operation.
173 return bReturn;
176 void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
177 sal_Int32 nHandle, const Any& aValue )
179 SolarMutexGuard aGuard;
181 // Search for right handle ... and try to set property value.
182 switch( nHandle )
184 case HANDLE_COMMANDURL:
185 aValue >>= m_aCommandURL;
186 break;
188 case HANDLE_HELPURL:
189 aValue >>= m_aHelpURL;
190 break;
192 case HANDLE_IMAGE:
193 aValue >>= m_xBitmap;
194 break;
196 case HANDLE_SUBCONTAINER:
197 aValue >>= m_xActionTriggerContainer;
198 break;
200 case HANDLE_TEXT:
201 aValue >>= m_aText;
202 break;
206 void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue(
207 Any& aValue, sal_Int32 nHandle ) const
209 SolarMutexGuard aGuard;
211 // Search for right handle ... and try to get property value.
212 switch( nHandle )
214 case HANDLE_COMMANDURL:
215 aValue <<= m_aCommandURL;
216 break;
218 case HANDLE_HELPURL:
219 aValue <<= m_aHelpURL;
220 break;
222 case HANDLE_IMAGE:
223 aValue <<= m_xBitmap;
224 break;
226 case HANDLE_SUBCONTAINER:
227 aValue <<= m_xActionTriggerContainer;
228 break;
230 case HANDLE_TEXT:
231 aValue <<= m_aText;
232 break;
236 ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerPropertySet::getInfoHelper()
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 static OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true );
243 return ourInfoHelper;
246 Reference< XPropertySetInfo > SAL_CALL ActionTriggerPropertySet::getPropertySetInfo()
248 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
249 // (Use method "getInfoHelper()".)
250 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
252 return xInfo;
255 Sequence< Property > ActionTriggerPropertySet::impl_getStaticPropertyDescriptor()
257 return
259 Property( "CommandURL" , HANDLE_COMMANDURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
260 Property( "HelpURL" , HANDLE_HELPURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
261 Property( "Image" , HANDLE_IMAGE , cppu::UnoType<XBitmap>::get(), PropertyAttribute::TRANSIENT ),
262 Property( "SubContainer" , HANDLE_SUBCONTAINER , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
263 Property( "Text" , HANDLE_TEXT , cppu::UnoType<XInterface>::get(), PropertyAttribute::TRANSIENT )
267 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
268 const OUString& sCurrentValue ,
269 const Any& aNewValue ,
270 Any& aOldValue ,
271 Any& aConvertedValue )
273 // Set default return value if method failed.
274 bool bReturn = false;
275 // Get new value from any.
276 // IllegalArgumentException() can be thrown!
277 OUString sValue;
278 convertPropertyValue( sValue, aNewValue );
280 // If value change ...
281 if( sValue != sCurrentValue )
283 // ... set information of change.
284 aOldValue <<= sCurrentValue;
285 aConvertedValue <<= sValue;
286 // Return OK - "value will be change ..."
287 bReturn = true;
289 else
291 // ... clear information of return parameter!
292 aOldValue.clear ();
293 aConvertedValue.clear ();
294 // Return NOTHING - "value will not be change ..."
295 bReturn = false;
298 return bReturn;
301 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
302 const Reference< XBitmap >& aCurrentValue ,
303 const Any& aNewValue ,
304 Any& aOldValue ,
305 Any& aConvertedValue )
307 // Set default return value if method failed.
308 bool bReturn = false;
309 // Get new value from any.
310 // IllegalArgumentException() can be thrown!
311 Reference< XBitmap > aValue;
312 convertPropertyValue( aValue, aNewValue );
314 // If value change ...
315 if( aValue != aCurrentValue )
317 // ... set information of change.
318 aOldValue <<= aCurrentValue;
319 aConvertedValue <<= aValue;
320 // Return OK - "value will be change ..."
321 bReturn = true;
323 else
325 // ... clear information of return parameter!
326 aOldValue.clear ();
327 aConvertedValue.clear ();
328 // Return NOTHING - "value will not be change ..."
329 bReturn = false;
332 return bReturn;
335 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
336 const Reference< XInterface >& aCurrentValue ,
337 const Any& aNewValue ,
338 Any& aOldValue ,
339 Any& aConvertedValue )
341 // Set default return value if method failed.
342 bool bReturn = false;
343 // Get new value from any.
344 // IllegalArgumentException() can be thrown!
345 Reference< XInterface > aValue;
346 convertPropertyValue( aValue, aNewValue );
348 // If value change ...
349 if( aValue != aCurrentValue )
351 // ... set information of change.
352 aOldValue <<= aCurrentValue;
353 aConvertedValue <<= aValue;
354 // Return OK - "value will be change ..."
355 bReturn = true;
357 else
359 // ... clear information of return parameter!
360 aOldValue.clear ();
361 aConvertedValue.clear ();
362 // Return NOTHING - "value will not be change ..."
363 bReturn = false;
366 return bReturn;
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */