Get the style color and number just once
[LibreOffice.git] / framework / source / fwe / classes / actiontriggerpropertyset.cxx
blob3959fa7f386b09e0a9fd0b885f58d2818f5769ed
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( u"CommandURL"_ustr , HANDLE_COMMANDURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
260 Property( u"HelpURL"_ustr , HANDLE_HELPURL , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
261 Property( u"Image"_ustr , HANDLE_IMAGE , cppu::UnoType<XBitmap>::get(), PropertyAttribute::TRANSIENT ),
262 Property( u"SubContainer"_ustr , HANDLE_SUBCONTAINER , cppu::UnoType<OUString>::get(), PropertyAttribute::TRANSIENT ),
263 Property( u"Text"_ustr , HANDLE_TEXT , cppu::UnoType<XInterface>::get(), PropertyAttribute::TRANSIENT )
267 // static
268 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
269 const OUString& sCurrentValue ,
270 const Any& aNewValue ,
271 Any& aOldValue ,
272 Any& aConvertedValue )
274 // Set default return value if method failed.
275 bool bReturn = false;
276 // Get new value from any.
277 // IllegalArgumentException() can be thrown!
278 OUString sValue;
279 convertPropertyValue( sValue, aNewValue );
281 // If value change ...
282 if( sValue != sCurrentValue )
284 // ... set information of change.
285 aOldValue <<= sCurrentValue;
286 aConvertedValue <<= sValue;
287 // Return OK - "value will be change ..."
288 bReturn = true;
290 else
292 // ... clear information of return parameter!
293 aOldValue.clear ();
294 aConvertedValue.clear ();
295 // Return NOTHING - "value will not be change ..."
296 bReturn = false;
299 return bReturn;
302 // static
303 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
304 const Reference< XBitmap >& aCurrentValue ,
305 const Any& aNewValue ,
306 Any& aOldValue ,
307 Any& aConvertedValue )
309 // Set default return value if method failed.
310 bool bReturn = false;
311 // Get new value from any.
312 // IllegalArgumentException() can be thrown!
313 Reference< XBitmap > aValue;
314 convertPropertyValue( aValue, aNewValue );
316 // If value change ...
317 if( aValue != aCurrentValue )
319 // ... set information of change.
320 aOldValue <<= aCurrentValue;
321 aConvertedValue <<= aValue;
322 // Return OK - "value will be change ..."
323 bReturn = true;
325 else
327 // ... clear information of return parameter!
328 aOldValue.clear ();
329 aConvertedValue.clear ();
330 // Return NOTHING - "value will not be change ..."
331 bReturn = false;
334 return bReturn;
337 // static
338 bool ActionTriggerPropertySet::impl_tryToChangeProperty(
339 const Reference< XInterface >& aCurrentValue ,
340 const Any& aNewValue ,
341 Any& aOldValue ,
342 Any& aConvertedValue )
344 // Set default return value if method failed.
345 bool bReturn = false;
346 // Get new value from any.
347 // IllegalArgumentException() can be thrown!
348 Reference< XInterface > aValue;
349 convertPropertyValue( aValue, aNewValue );
351 // If value change ...
352 if( aValue != aCurrentValue )
354 // ... set information of change.
355 aOldValue <<= aCurrentValue;
356 aConvertedValue <<= aValue;
357 // Return OK - "value will be change ..."
358 bReturn = true;
360 else
362 // ... clear information of return parameter!
363 aOldValue.clear ();
364 aConvertedValue.clear ();
365 // Return NOTHING - "value will not be change ..."
366 bReturn = false;
369 return bReturn;
374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */