LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / component / Numeric.cxx
blob41dea5c47e29a10a7dd29f2136b69fedba76d398
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 "Numeric.hxx"
21 #include <services.hxx>
22 #include <property.hxx>
23 #include <comphelper/types.hxx>
24 #include <com/sun/star/form/FormComponentType.hpp>
26 namespace frm
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::sdb;
31 using namespace ::com::sun::star::sdbc;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::form;
35 using namespace ::com::sun::star::awt;
36 using namespace ::com::sun::star::io;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::form::binding;
41 ONumericControl::ONumericControl(const Reference<XComponentContext>& _rxFactory)
42 :OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD)
47 css::uno::Sequence<OUString> ONumericControl::getSupportedServiceNames()
49 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
50 aSupported.realloc(aSupported.getLength() + 2);
52 OUString*pArray = aSupported.getArray();
53 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_NUMERICFIELD;
54 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_NUMERICFIELD;
55 return aSupported;
58 // ONumericModel
60 ONumericModel::ONumericModel(const Reference<XComponentContext>& _rxFactory)
61 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD, true, true )
62 // use the old control name for compytibility reasons
65 m_nClassId = FormComponentType::NUMERICFIELD;
66 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
70 ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
71 :OEditBaseModel( _pOriginal, _rxFactory )
76 ONumericModel::~ONumericModel()
80 // XCloneable
82 css::uno::Reference< css::util::XCloneable > SAL_CALL ONumericModel::createClone()
84 rtl::Reference<ONumericModel> pClone = new ONumericModel(this, getContext());
85 pClone->clonedFrom(this);
86 return pClone;
89 // XServiceInfo
91 css::uno::Sequence<OUString> ONumericModel::getSupportedServiceNames()
93 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
95 sal_Int32 nOldLen = aSupported.getLength();
96 aSupported.realloc( nOldLen + 9 );
97 OUString* pStoreTo = aSupported.getArray() + nOldLen;
99 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
100 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
101 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
103 *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
104 *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
106 *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD;
107 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD;
108 *pStoreTo++ = BINDABLE_DATABASE_NUMERIC_FIELD;
110 *pStoreTo++ = FRM_COMPONENT_NUMERICFIELD;
112 return aSupported;
116 void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const
118 OEditBaseModel::describeFixedProperties( _rProps );
119 sal_Int32 nOldCount = _rProps.getLength();
120 _rProps.realloc( nOldCount + 2);
121 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
122 *pProperties++ = css::beans::Property(PROPERTY_DEFAULT_VALUE, PROPERTY_ID_DEFAULT_VALUE, cppu::UnoType<double>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT | css::beans::PropertyAttribute::MAYBEVOID);
123 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
124 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
128 OUString SAL_CALL ONumericModel::getServiceName()
130 return FRM_COMPONENT_NUMERICFIELD; // old (non-sun) name for compatibility !
134 bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
136 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
137 if ( aControlValue != m_aSaveValue )
139 if ( !aControlValue.hasValue() )
140 m_xColumnUpdate->updateNull();
141 else
145 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
147 catch(const Exception&)
149 return false;
152 m_aSaveValue = aControlValue;
154 return true;
158 Any ONumericModel::translateDbColumnToControlValue()
160 m_aSaveValue <<= m_xColumn->getDouble();
161 if ( m_xColumn->wasNull() )
162 m_aSaveValue.clear();
164 return m_aSaveValue;
168 Any ONumericModel::getDefaultForReset() const
170 Any aValue;
171 if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE)
172 aValue = m_aDefault;
174 return aValue;
178 void ONumericModel::resetNoBroadcast()
180 OEditBaseModel::resetNoBroadcast();
181 m_aSaveValue.clear();
184 } // namespace frm
186 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
187 com_sun_star_form_ONumericModel_get_implementation(css::uno::XComponentContext* component,
188 css::uno::Sequence<css::uno::Any> const &)
190 return cppu::acquire(new frm::ONumericModel(component));
193 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
194 com_sun_star_form_ONumericControl_get_implementation(css::uno::XComponentContext* component,
195 css::uno::Sequence<css::uno::Any> const &)
197 return cppu::acquire(new frm::ONumericControl(component));
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */