android: Update app-specific/MIME type icons
[LibreOffice.git] / forms / source / component / Numeric.cxx
blob7ef40864787c81a5b5fc270097c8a7c2e8dbe11a
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 <tools/debug.hxx>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/form/FormComponentType.hpp>
28 namespace frm
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::sdb;
33 using namespace ::com::sun::star::sdbc;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
36 using namespace ::com::sun::star::form;
37 using namespace ::com::sun::star::awt;
38 using namespace ::com::sun::star::io;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::util;
41 using namespace ::com::sun::star::form::binding;
43 ONumericControl::ONumericControl(const Reference<XComponentContext>& _rxFactory)
44 :OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD)
49 css::uno::Sequence<OUString> ONumericControl::getSupportedServiceNames()
51 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
52 aSupported.realloc(aSupported.getLength() + 2);
54 OUString*pArray = aSupported.getArray();
55 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_NUMERICFIELD;
56 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_NUMERICFIELD;
57 return aSupported;
60 // ONumericModel
62 ONumericModel::ONumericModel(const Reference<XComponentContext>& _rxFactory)
63 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD, true, true )
64 // use the old control name for compytibility reasons
67 m_nClassId = FormComponentType::NUMERICFIELD;
68 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
72 ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
73 :OEditBaseModel( _pOriginal, _rxFactory )
78 ONumericModel::~ONumericModel()
82 // XCloneable
84 css::uno::Reference< css::util::XCloneable > SAL_CALL ONumericModel::createClone()
86 rtl::Reference<ONumericModel> pClone = new ONumericModel(this, getContext());
87 pClone->clonedFrom(this);
88 return pClone;
91 // XServiceInfo
93 css::uno::Sequence<OUString> ONumericModel::getSupportedServiceNames()
95 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
97 sal_Int32 nOldLen = aSupported.getLength();
98 aSupported.realloc( nOldLen + 9 );
99 OUString* pStoreTo = aSupported.getArray() + nOldLen;
101 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
102 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
103 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
105 *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
106 *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
108 *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD;
109 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD;
110 *pStoreTo++ = BINDABLE_DATABASE_NUMERIC_FIELD;
112 *pStoreTo++ = FRM_COMPONENT_NUMERICFIELD;
114 return aSupported;
118 void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const
120 OEditBaseModel::describeFixedProperties( _rProps );
121 sal_Int32 nOldCount = _rProps.getLength();
122 _rProps.realloc( nOldCount + 2);
123 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
124 *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);
125 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
126 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
130 OUString SAL_CALL ONumericModel::getServiceName()
132 return FRM_COMPONENT_NUMERICFIELD; // old (non-sun) name for compatibility !
136 bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
138 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
139 if ( aControlValue != m_aSaveValue )
141 if ( !aControlValue.hasValue() )
142 m_xColumnUpdate->updateNull();
143 else
147 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
149 catch(const Exception&)
151 return false;
154 m_aSaveValue = aControlValue;
156 return true;
160 Any ONumericModel::translateDbColumnToControlValue()
162 m_aSaveValue <<= m_xColumn->getDouble();
163 if ( m_xColumn->wasNull() )
164 m_aSaveValue.clear();
166 return m_aSaveValue;
170 Any ONumericModel::getDefaultForReset() const
172 Any aValue;
173 if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE)
174 aValue = m_aDefault;
176 return aValue;
180 void ONumericModel::resetNoBroadcast()
182 OEditBaseModel::resetNoBroadcast();
183 m_aSaveValue.clear();
186 } // namespace frm
188 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
189 com_sun_star_form_ONumericModel_get_implementation(css::uno::XComponentContext* component,
190 css::uno::Sequence<css::uno::Any> const &)
192 return cppu::acquire(new frm::ONumericModel(component));
195 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
196 com_sun_star_form_ONumericControl_get_implementation(css::uno::XComponentContext* component,
197 css::uno::Sequence<css::uno::Any> const &)
199 return cppu::acquire(new frm::ONumericControl(component));
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */