LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / component / spinbutton.cxx
blob197497671860c2a71880eafc34eb65d732cdc0d8
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 "spinbutton.hxx"
21 #include "scrollbar.hxx"
22 #include <comphelper/property.hxx>
23 #include <comphelper/streamsection.hxx>
24 #include <comphelper/basicio.hxx>
25 #include <com/sun/star/form/FormComponentType.hpp>
26 #include <property.hxx>
27 #include <services.hxx>
30 namespace frm
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::form;
36 using namespace ::com::sun::star::awt;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::io;
40 using namespace ::com::sun::star::form::binding;
43 //= OSpinButtonModel
45 OSpinButtonModel::OSpinButtonModel( const Reference<XComponentContext>& _rxFactory )
46 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, true, true, false )
47 ,m_nDefaultSpinValue( 0 )
50 m_nClassId = FormComponentType::SPINBUTTON;
51 initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE );
55 OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
56 :OBoundControlModel( _pOriginal, _rxFactory )
58 m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue;
62 OSpinButtonModel::~OSpinButtonModel( )
66 OUString SAL_CALL OSpinButtonModel::getImplementationName()
68 return "com.sun.star.comp.forms.OSpinButtonModel";
71 // note that we're passing OControlModel as "base class". This is because
72 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
73 // service, which isn't really true for us. We only derive from this class
74 // to benefit from the functionality for binding to spreadsheet cells
75 Sequence< OUString > SAL_CALL OSpinButtonModel::getSupportedServiceNames()
77 Sequence< OUString > aOwnNames { FRM_SUN_COMPONENT_SPINBUTTON, BINDABLE_INTEGER_VALUE_RANGE };
79 return ::comphelper::combineSequences(
80 getAggregateServiceNames(),
81 ::comphelper::concatSequences(
82 OControlModel::getSupportedServiceNames_Static(),
83 aOwnNames
88 css::uno::Reference< css::util::XCloneable > SAL_CALL OSpinButtonModel::createClone()
90 rtl::Reference<OSpinButtonModel> pClone = new OSpinButtonModel(this, getContext());
91 pClone->clonedFrom(this);
92 return pClone;
96 void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
98 OControlModel::describeFixedProperties( _rProps );
99 sal_Int32 nOldCount = _rProps.getLength();
100 _rProps.realloc( nOldCount + 3);
101 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
102 *pProperties++ = css::beans::Property(PROPERTY_DEFAULT_SPIN_VALUE, PROPERTY_ID_DEFAULT_SPIN_VALUE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::BOUND);
103 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
104 *pProperties++ = css::beans::Property(PROPERTY_CONTROLSOURCEPROPERTY, PROPERTY_ID_CONTROLSOURCEPROPERTY, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY | css::beans::PropertyAttribute::TRANSIENT);
105 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
109 void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
111 switch ( _nHandle )
113 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
114 _rValue <<= m_nDefaultSpinValue;
115 break;
117 default:
118 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
123 void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
125 switch ( _nHandle )
127 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
128 OSL_VERIFY( _rValue >>= m_nDefaultSpinValue );
129 resetNoBroadcast();
130 break;
132 default:
133 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
138 sal_Bool OSpinButtonModel::convertFastPropertyValue(
139 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
141 bool bModified( false );
142 switch ( _nHandle )
144 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
145 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue );
146 break;
148 default:
149 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
150 break;
152 return bModified;
156 Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
158 Any aReturn;
160 switch ( _nHandle )
162 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
163 aReturn <<= sal_Int32(0);
164 break;
166 default:
167 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
168 break;
171 return aReturn;
175 Any OSpinButtonModel::translateDbColumnToControlValue( )
177 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
178 return Any();
182 bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
184 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
185 return true;
189 Any OSpinButtonModel::getDefaultForReset() const
191 return makeAny( m_nDefaultSpinValue );
195 OUString SAL_CALL OSpinButtonModel::getServiceName()
197 return FRM_SUN_COMPONENT_SPINBUTTON;
201 void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
203 OBoundControlModel::write( _rxOutStream );
204 ::osl::MutexGuard aGuard( m_aMutex );
206 OStreamSection aSection( _rxOutStream );
208 // version
209 _rxOutStream->writeShort( 0x0001 );
211 // properties
212 _rxOutStream << m_nDefaultSpinValue;
213 writeHelpTextCompatibly( _rxOutStream );
217 void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream )
219 OBoundControlModel::read( _rxInStream );
220 ::osl::MutexGuard aGuard( m_aMutex );
222 // version
224 OStreamSection aSection( _rxInStream );
226 sal_uInt16 nVersion = _rxInStream->readShort();
227 if ( nVersion == 0x0001 )
229 _rxInStream >> m_nDefaultSpinValue;
230 readHelpTextCompatibly( _rxInStream );
232 else
233 defaultCommonProperties();
235 // here, everything in the stream section which is left will be skipped
240 Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
242 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
243 "SpinValueMin",
244 "SpinValueMax" );
248 Any OSpinButtonModel::translateControlValueToExternalValue( ) const
250 // by definition, the base class simply obtains the property value
251 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
255 Sequence< Type > OSpinButtonModel::getSupportedBindingTypes()
257 return Sequence< Type >( &cppu::UnoType<double>::get(), 1 );
260 } // namespace frm
262 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
263 com_sun_star_comp_forms_OSpinButtonModel_get_implementation(css::uno::XComponentContext* component,
264 css::uno::Sequence<css::uno::Any> const &)
266 return cppu::acquire(new frm::OSpinButtonModel(component));
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */