1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir #include "Numeric.hxx" 27cdf0e10cSrcweir #include <tools/debug.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir //......................................................................... 30cdf0e10cSrcweir namespace frm 31cdf0e10cSrcweir { 32cdf0e10cSrcweir //......................................................................... 33cdf0e10cSrcweir using namespace ::com::sun::star::uno; 34cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 35cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 36cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 37cdf0e10cSrcweir using namespace ::com::sun::star::beans; 38cdf0e10cSrcweir using namespace ::com::sun::star::container; 39cdf0e10cSrcweir using namespace ::com::sun::star::form; 40cdf0e10cSrcweir using namespace ::com::sun::star::awt; 41cdf0e10cSrcweir using namespace ::com::sun::star::io; 42cdf0e10cSrcweir using namespace ::com::sun::star::lang; 43cdf0e10cSrcweir using namespace ::com::sun::star::util; 44cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 45cdf0e10cSrcweir 46cdf0e10cSrcweir //================================================================== 47cdf0e10cSrcweir // ONumericControl 48cdf0e10cSrcweir //================================================================== 49cdf0e10cSrcweir 50cdf0e10cSrcweir //------------------------------------------------------------------ 51cdf0e10cSrcweir ONumericControl::ONumericControl(const Reference<XMultiServiceFactory>& _rxFactory) 52cdf0e10cSrcweir :OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir //------------------------------------------------------------------------------ 57cdf0e10cSrcweir StringSequence ONumericControl::getSupportedServiceNames() throw() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir StringSequence aSupported = OBoundControl::getSupportedServiceNames(); 60cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 1); 61cdf0e10cSrcweir 62cdf0e10cSrcweir ::rtl::OUString*pArray = aSupported.getArray(); 63cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_NUMERICFIELD; 64cdf0e10cSrcweir return aSupported; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir 68cdf0e10cSrcweir //------------------------------------------------------------------ 69cdf0e10cSrcweir InterfaceRef SAL_CALL ONumericControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir return *(new ONumericControl(_rxFactory)); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir //------------------------------------------------------------------------------ 75cdf0e10cSrcweir Sequence<Type> ONumericControl::_getTypes() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir return OBoundControl::_getTypes(); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir //================================================================== 81cdf0e10cSrcweir // ONumericModel 82cdf0e10cSrcweir //================================================================== 83cdf0e10cSrcweir //------------------------------------------------------------------ 84cdf0e10cSrcweir InterfaceRef SAL_CALL ONumericModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir return *(new ONumericModel(_rxFactory)); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir //------------------------------------------------------------------------------ 90cdf0e10cSrcweir Sequence<Type> ONumericModel::_getTypes() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir return OEditBaseModel::_getTypes(); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir //------------------------------------------------------------------ 96cdf0e10cSrcweir DBG_NAME( ONumericModel ) 97cdf0e10cSrcweir //------------------------------------------------------------------ 98cdf0e10cSrcweir ONumericModel::ONumericModel(const Reference<XMultiServiceFactory>& _rxFactory) 99cdf0e10cSrcweir :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD, sal_True, sal_True ) 100cdf0e10cSrcweir // use the old control name for compytibility reasons 101cdf0e10cSrcweir { 102cdf0e10cSrcweir DBG_CTOR( ONumericModel, NULL ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir m_nClassId = FormComponentType::NUMERICFIELD; 105cdf0e10cSrcweir initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir //------------------------------------------------------------------ 109cdf0e10cSrcweir ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory ) 110cdf0e10cSrcweir :OEditBaseModel( _pOriginal, _rxFactory ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir DBG_CTOR( ONumericModel, NULL ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir //------------------------------------------------------------------ 116cdf0e10cSrcweir ONumericModel::~ONumericModel() 117cdf0e10cSrcweir { 118cdf0e10cSrcweir DBG_DTOR( ONumericModel, NULL ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir // XCloneable 122cdf0e10cSrcweir //------------------------------------------------------------------------------ 123cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( ONumericModel ) 124cdf0e10cSrcweir 125cdf0e10cSrcweir // XServiceInfo 126cdf0e10cSrcweir //------------------------------------------------------------------------------ 127cdf0e10cSrcweir StringSequence ONumericModel::getSupportedServiceNames() throw() 128cdf0e10cSrcweir { 129cdf0e10cSrcweir StringSequence aSupported = OBoundControlModel::getSupportedServiceNames(); 130cdf0e10cSrcweir 131cdf0e10cSrcweir sal_Int32 nOldLen = aSupported.getLength(); 132cdf0e10cSrcweir aSupported.realloc( nOldLen + 8 ); 133cdf0e10cSrcweir ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen; 134cdf0e10cSrcweir 135cdf0e10cSrcweir *pStoreTo++ = BINDABLE_CONTROL_MODEL; 136cdf0e10cSrcweir *pStoreTo++ = DATA_AWARE_CONTROL_MODEL; 137cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_CONTROL_MODEL; 138cdf0e10cSrcweir 139cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL; 140cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL; 141cdf0e10cSrcweir 142cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD; 143cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD; 144cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATABASE_NUMERIC_FIELD; 145cdf0e10cSrcweir 146cdf0e10cSrcweir return aSupported; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir //------------------------------------------------------------------------------ 150cdf0e10cSrcweir void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const 151cdf0e10cSrcweir { 152cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel ) 153cdf0e10cSrcweir DECL_PROP3(DEFAULT_VALUE, double, BOUND, MAYBEDEFAULT, MAYBEVOID); 154cdf0e10cSrcweir DECL_PROP1(TABINDEX, sal_Int16, BOUND); 155cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir //------------------------------------------------------------------------------ 159cdf0e10cSrcweir ::rtl::OUString SAL_CALL ONumericModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir return FRM_COMPONENT_NUMERICFIELD; // old (non-sun) name for compatibility ! 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir //------------------------------------------------------------------------------ 165cdf0e10cSrcweir sal_Bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) ); 168cdf0e10cSrcweir if ( !compare( aControlValue, m_aSaveValue ) ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if ( !aControlValue.hasValue() ) 171cdf0e10cSrcweir m_xColumnUpdate->updateNull(); 172cdf0e10cSrcweir else 173cdf0e10cSrcweir { 174cdf0e10cSrcweir try 175cdf0e10cSrcweir { 176cdf0e10cSrcweir m_xColumnUpdate->updateDouble( getDouble( aControlValue ) ); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir catch(Exception&) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir return sal_False; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir m_aSaveValue = aControlValue; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir return sal_True; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir //------------------------------------------------------------------------------ 189cdf0e10cSrcweir Any ONumericModel::translateDbColumnToControlValue() 190cdf0e10cSrcweir { 191cdf0e10cSrcweir m_aSaveValue <<= (double)m_xColumn->getDouble(); 192cdf0e10cSrcweir if ( m_xColumn->wasNull() ) 193cdf0e10cSrcweir m_aSaveValue.clear(); 194cdf0e10cSrcweir 195cdf0e10cSrcweir return m_aSaveValue; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir //------------------------------------------------------------------------------ 199cdf0e10cSrcweir Any ONumericModel::getDefaultForReset() const 200cdf0e10cSrcweir { 201cdf0e10cSrcweir Any aValue; 202cdf0e10cSrcweir if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE) 203cdf0e10cSrcweir aValue = m_aDefault; 204cdf0e10cSrcweir 205cdf0e10cSrcweir return aValue; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir //------------------------------------------------------------------------------ 209cdf0e10cSrcweir void ONumericModel::resetNoBroadcast() 210cdf0e10cSrcweir { 211cdf0e10cSrcweir OEditBaseModel::resetNoBroadcast(); 212cdf0e10cSrcweir m_aSaveValue.clear(); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir //......................................................................... 216cdf0e10cSrcweir } // namespace frm 217cdf0e10cSrcweir //......................................................................... 218cdf0e10cSrcweir 219