Avoid potential negative array index access to cached text.
[LibreOffice.git] / framework / source / fwe / classes / actiontriggerseparatorpropertyset.cxx
blob104d765f5ca35a28f746e5b29b81dc51714deee1
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/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>
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 namespace {
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
43 HANDLE_TYPE,
44 PROPERTYCOUNT
49 namespace framework
52 ActionTriggerSeparatorPropertySet::ActionTriggerSeparatorPropertySet()
53 : OBroadcastHelper ( m_aMutex )
54 , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) )
55 , m_nSeparatorType( 0 )
59 ActionTriggerSeparatorPropertySet::~ActionTriggerSeparatorPropertySet()
63 // XInterface
64 Any SAL_CALL ActionTriggerSeparatorPropertySet::queryInterface( const Type& aType )
66 Any a = ::cppu::queryInterface(
67 aType,
68 static_cast< XServiceInfo* >(this),
69 static_cast< XTypeProvider* >(this));
71 if( a.hasValue() )
72 return a;
73 else
75 a = OPropertySetHelper::queryInterface( aType );
77 if( a.hasValue() )
78 return a;
81 return OWeakObject::queryInterface( aType );
84 void ActionTriggerSeparatorPropertySet::acquire() noexcept
86 OWeakObject::acquire();
89 void ActionTriggerSeparatorPropertySet::release() noexcept
91 OWeakObject::release();
94 // XServiceInfo
95 OUString SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationName()
97 return IMPLEMENTATIONNAME_ACTIONTRIGGERSEPARATOR;
100 sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::supportsService( const OUString& ServiceName )
102 return cppu::supportsService(this, ServiceName);
105 Sequence< OUString > SAL_CALL ActionTriggerSeparatorPropertySet::getSupportedServiceNames()
107 Sequence<OUString> seqServiceNames { SERVICENAME_ACTIONTRIGGERSEPARATOR };
108 return seqServiceNames;
111 // XTypeProvider
112 Sequence< Type > SAL_CALL ActionTriggerSeparatorPropertySet::getTypes()
114 // Create a static typecollection ...
115 static ::cppu::OTypeCollection ourTypeCollection(
116 cppu::UnoType<XPropertySet>::get(),
117 cppu::UnoType<XFastPropertySet>::get(),
118 cppu::UnoType<XMultiPropertySet>::get(),
119 cppu::UnoType<XServiceInfo>::get(),
120 cppu::UnoType<XTypeProvider>::get());
122 return ourTypeCollection.getTypes();
125 Sequence< sal_Int8 > SAL_CALL ActionTriggerSeparatorPropertySet::getImplementationId()
127 return css::uno::Sequence<sal_Int8>();
130 sal_Bool SAL_CALL ActionTriggerSeparatorPropertySet::convertFastPropertyValue(
131 Any& aConvertedValue,
132 Any& aOldValue,
133 sal_Int32 nHandle,
134 const Any& aValue )
136 // Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
137 // Return sal_True, if changed - else return sal_False.
138 // Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
139 // Initialize return value with sal_False !!!
140 // (Handle can be invalid)
141 bool bReturn = false;
143 switch( nHandle )
145 case HANDLE_TYPE:
146 bReturn = impl_tryToChangeProperty( m_nSeparatorType, aValue, aOldValue, aConvertedValue );
147 break;
150 // Return state of operation.
151 return bReturn;
154 void SAL_CALL ActionTriggerSeparatorPropertySet::setFastPropertyValue_NoBroadcast(
155 sal_Int32 nHandle, const Any& aValue )
157 SolarMutexGuard aGuard;
159 // Search for right handle ... and try to set property value.
160 switch( nHandle )
162 case HANDLE_TYPE:
163 aValue >>= m_nSeparatorType;
164 break;
168 void SAL_CALL ActionTriggerSeparatorPropertySet::getFastPropertyValue(
169 Any& aValue, sal_Int32 nHandle ) const
171 SolarMutexGuard aGuard;
173 // Search for right handle ... and try to get property value.
174 switch( nHandle )
176 case HANDLE_TYPE:
177 aValue <<= m_nSeparatorType;
178 break;
182 ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerSeparatorPropertySet::getInfoHelper()
184 // Define static member to give structure of properties to baseclass "OPropertySetHelper".
185 // "impl_getStaticPropertyDescriptor" is a non exported and static function, who will define a static propertytable.
186 // "true" indicates: Table is sorted by name.
187 static OPropertyArrayHelper ourInfoHelper( impl_getStaticPropertyDescriptor(), true );
189 return ourInfoHelper;
192 Reference< XPropertySetInfo > SAL_CALL ActionTriggerSeparatorPropertySet::getPropertySetInfo()
194 // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
195 // (Use method "getInfoHelper()".)
196 static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
198 return xInfo;
201 Sequence< Property > ActionTriggerSeparatorPropertySet::impl_getStaticPropertyDescriptor()
203 return
205 Property( "SeparatorType", HANDLE_TYPE, cppu::UnoType<sal_Int16>::get(), PropertyAttribute::TRANSIENT )
209 bool ActionTriggerSeparatorPropertySet::impl_tryToChangeProperty(
210 sal_Int16 aCurrentValue ,
211 const Any& aNewValue ,
212 Any& aOldValue ,
213 Any& aConvertedValue )
215 // Set default return value if method failed.
216 bool bReturn = false;
217 // Get new value from any.
218 // IllegalArgumentException() can be thrown!
219 sal_Int16 aValue = 0;
220 convertPropertyValue( aValue, aNewValue );
222 // If value change ...
223 if( aValue != aCurrentValue )
225 // ... set information of change.
226 aOldValue <<= aCurrentValue;
227 aConvertedValue <<= aValue;
228 // Return OK - "value will be change ..."
229 bReturn = true;
231 else
233 // ... clear information of return parameter!
234 aOldValue.clear ();
235 aConvertedValue.clear ();
236 // Return NOTHING - "value will not be change ..."
237 bReturn = false;
240 return bReturn;
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */