bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / component / Numeric.cxx
blobac4542ec1845416cd67567b6c644f56a4a60e75a
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 <tools/debug.hxx>
23 //.........................................................................
24 namespace frm
26 //.........................................................................
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::sdb;
29 using namespace ::com::sun::star::sdbc;
30 using namespace ::com::sun::star::sdbcx;
31 using namespace ::com::sun::star::beans;
32 using namespace ::com::sun::star::container;
33 using namespace ::com::sun::star::form;
34 using namespace ::com::sun::star::awt;
35 using namespace ::com::sun::star::io;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::util;
38 using namespace ::com::sun::star::form::binding;
40 //==================================================================
41 // ONumericControl
42 //==================================================================
44 //------------------------------------------------------------------
45 ONumericControl::ONumericControl(const Reference<XMultiServiceFactory>& _rxFactory)
46 :OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD)
50 //------------------------------------------------------------------------------
51 StringSequence ONumericControl::getSupportedServiceNames() throw()
53 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
54 aSupported.realloc(aSupported.getLength() + 1);
56 OUString*pArray = aSupported.getArray();
57 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_NUMERICFIELD;
58 return aSupported;
62 //------------------------------------------------------------------
63 InterfaceRef SAL_CALL ONumericControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
65 return *(new ONumericControl(_rxFactory));
68 //------------------------------------------------------------------------------
69 Sequence<Type> ONumericControl::_getTypes()
71 return OBoundControl::_getTypes();
74 //==================================================================
75 // ONumericModel
76 //==================================================================
77 //------------------------------------------------------------------
78 InterfaceRef SAL_CALL ONumericModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
80 return *(new ONumericModel(_rxFactory));
83 //------------------------------------------------------------------------------
84 Sequence<Type> ONumericModel::_getTypes()
86 return OEditBaseModel::_getTypes();
89 //------------------------------------------------------------------
90 DBG_NAME( ONumericModel )
91 //------------------------------------------------------------------
92 ONumericModel::ONumericModel(const Reference<XMultiServiceFactory>& _rxFactory)
93 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD, sal_True, sal_True )
94 // use the old control name for compytibility reasons
96 DBG_CTOR( ONumericModel, NULL );
98 m_nClassId = FormComponentType::NUMERICFIELD;
99 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
102 //------------------------------------------------------------------
103 ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
104 :OEditBaseModel( _pOriginal, _rxFactory )
106 DBG_CTOR( ONumericModel, NULL );
109 //------------------------------------------------------------------
110 ONumericModel::~ONumericModel()
112 DBG_DTOR( ONumericModel, NULL );
115 // XCloneable
116 //------------------------------------------------------------------------------
117 IMPLEMENT_DEFAULT_CLONING( ONumericModel )
119 // XServiceInfo
120 //------------------------------------------------------------------------------
121 StringSequence ONumericModel::getSupportedServiceNames() throw()
123 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
125 sal_Int32 nOldLen = aSupported.getLength();
126 aSupported.realloc( nOldLen + 8 );
127 OUString* pStoreTo = aSupported.getArray() + nOldLen;
129 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
130 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
131 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
133 *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
134 *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
136 *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD;
137 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD;
138 *pStoreTo++ = BINDABLE_DATABASE_NUMERIC_FIELD;
140 return aSupported;
143 //------------------------------------------------------------------------------
144 void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const
146 BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
147 DECL_PROP3(DEFAULT_VALUE, double, BOUND, MAYBEDEFAULT, MAYBEVOID);
148 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
149 END_DESCRIBE_PROPERTIES();
152 //------------------------------------------------------------------------------
153 OUString SAL_CALL ONumericModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
155 return OUString(FRM_COMPONENT_NUMERICFIELD); // old (non-sun) name for compatibility !
158 //------------------------------------------------------------------------------
159 sal_Bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
161 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
162 if ( !compare( aControlValue, m_aSaveValue ) )
164 if ( !aControlValue.hasValue() )
165 m_xColumnUpdate->updateNull();
166 else
170 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
172 catch(const Exception&)
174 return sal_False;
177 m_aSaveValue = aControlValue;
179 return sal_True;
182 //------------------------------------------------------------------------------
183 Any ONumericModel::translateDbColumnToControlValue()
185 m_aSaveValue <<= (double)m_xColumn->getDouble();
186 if ( m_xColumn->wasNull() )
187 m_aSaveValue.clear();
189 return m_aSaveValue;
192 //------------------------------------------------------------------------------
193 Any ONumericModel::getDefaultForReset() const
195 Any aValue;
196 if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE)
197 aValue = m_aDefault;
199 return aValue;
202 //------------------------------------------------------------------------------
203 void ONumericModel::resetNoBroadcast()
205 OEditBaseModel::resetNoBroadcast();
206 m_aSaveValue.clear();
209 //.........................................................................
210 } // namespace frm
211 //.........................................................................
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */