bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / Numeric.cxx
blob2d1cb74083feebfdfdd9a6096ae8db67982fd1e6
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 <comphelper/processfactory.hxx>
23 namespace frm
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::sdb;
28 using namespace ::com::sun::star::sdbc;
29 using namespace ::com::sun::star::sdbcx;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::container;
32 using namespace ::com::sun::star::form;
33 using namespace ::com::sun::star::awt;
34 using namespace ::com::sun::star::io;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::util;
37 using namespace ::com::sun::star::form::binding;
39 ONumericControl::ONumericControl(const Reference<XComponentContext>& _rxFactory)
40 :OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD)
45 StringSequence ONumericControl::getSupportedServiceNames() throw(std::exception)
47 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
48 aSupported.realloc(aSupported.getLength() + 2);
50 OUString*pArray = aSupported.getArray();
51 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_NUMERICFIELD;
52 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_NUMERICFIELD;
53 return aSupported;
57 Sequence<Type> ONumericControl::_getTypes()
59 return OBoundControl::_getTypes();
63 // ONumericModel
65 Sequence<Type> ONumericModel::_getTypes()
67 return OEditBaseModel::_getTypes();
72 ONumericModel::ONumericModel(const Reference<XComponentContext>& _rxFactory)
73 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD, true, true )
74 // use the old control name for compytibility reasons
77 m_nClassId = FormComponentType::NUMERICFIELD;
78 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
82 ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
83 :OEditBaseModel( _pOriginal, _rxFactory )
88 ONumericModel::~ONumericModel()
92 // XCloneable
94 IMPLEMENT_DEFAULT_CLONING( ONumericModel )
96 // XServiceInfo
98 StringSequence ONumericModel::getSupportedServiceNames() throw(std::exception)
100 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
102 sal_Int32 nOldLen = aSupported.getLength();
103 aSupported.realloc( nOldLen + 9 );
104 OUString* pStoreTo = aSupported.getArray() + nOldLen;
106 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
107 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
108 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
110 *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
111 *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
113 *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD;
114 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD;
115 *pStoreTo++ = BINDABLE_DATABASE_NUMERIC_FIELD;
117 *pStoreTo++ = FRM_COMPONENT_NUMERICFIELD;
119 return aSupported;
123 void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const
125 BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
126 DECL_PROP3(DEFAULT_VALUE, double, BOUND, MAYBEDEFAULT, MAYBEVOID);
127 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
128 END_DESCRIBE_PROPERTIES();
132 OUString SAL_CALL ONumericModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
134 return OUString(FRM_COMPONENT_NUMERICFIELD); // old (non-sun) name for compatibility !
138 bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
140 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
141 if ( !compare( aControlValue, m_aSaveValue ) )
143 if ( !aControlValue.hasValue() )
144 m_xColumnUpdate->updateNull();
145 else
149 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
151 catch(const Exception&)
153 return false;
156 m_aSaveValue = aControlValue;
158 return true;
162 Any ONumericModel::translateDbColumnToControlValue()
164 m_aSaveValue <<= (double)m_xColumn->getDouble();
165 if ( m_xColumn->wasNull() )
166 m_aSaveValue.clear();
168 return m_aSaveValue;
172 Any ONumericModel::getDefaultForReset() const
174 Any aValue;
175 if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE)
176 aValue = m_aDefault;
178 return aValue;
182 void ONumericModel::resetNoBroadcast()
184 OEditBaseModel::resetNoBroadcast();
185 m_aSaveValue.clear();
188 } // namespace frm
190 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
191 com_sun_star_form_ONumericModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
192 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
194 return cppu::acquire(new frm::ONumericModel(component));
197 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
198 com_sun_star_form_ONumericControl_get_implementation(::com::sun::star::uno::XComponentContext* component,
199 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
201 return cppu::acquire(new frm::ONumericControl(component));
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */