1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Numeric.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "Numeric.hxx"
34 #include <tools/debug.hxx>
36 //.........................................................................
39 //.........................................................................
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::sdb
;
42 using namespace ::com::sun::star::sdbc
;
43 using namespace ::com::sun::star::sdbcx
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::container
;
46 using namespace ::com::sun::star::form
;
47 using namespace ::com::sun::star::awt
;
48 using namespace ::com::sun::star::io
;
49 using namespace ::com::sun::star::lang
;
50 using namespace ::com::sun::star::util
;
51 using namespace ::com::sun::star::form::binding
;
53 //==================================================================
55 //==================================================================
57 //------------------------------------------------------------------
58 ONumericControl::ONumericControl(const Reference
<XMultiServiceFactory
>& _rxFactory
)
59 :OBoundControl(_rxFactory
, VCL_CONTROL_NUMERICFIELD
)
63 //------------------------------------------------------------------------------
64 StringSequence
ONumericControl::getSupportedServiceNames() throw()
66 StringSequence aSupported
= OBoundControl::getSupportedServiceNames();
67 aSupported
.realloc(aSupported
.getLength() + 1);
69 ::rtl::OUString
*pArray
= aSupported
.getArray();
70 pArray
[aSupported
.getLength()-1] = FRM_SUN_CONTROL_NUMERICFIELD
;
75 //------------------------------------------------------------------
76 InterfaceRef SAL_CALL
ONumericControl_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
78 return *(new ONumericControl(_rxFactory
));
81 //------------------------------------------------------------------------------
82 Sequence
<Type
> ONumericControl::_getTypes()
84 return OBoundControl::_getTypes();
87 //==================================================================
89 //==================================================================
90 //------------------------------------------------------------------
91 InterfaceRef SAL_CALL
ONumericModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
93 return *(new ONumericModel(_rxFactory
));
96 //------------------------------------------------------------------------------
97 Sequence
<Type
> ONumericModel::_getTypes()
99 return OEditBaseModel::_getTypes();
102 //------------------------------------------------------------------
103 DBG_NAME( ONumericModel
)
104 //------------------------------------------------------------------
105 ONumericModel::ONumericModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
106 :OEditBaseModel( _rxFactory
, VCL_CONTROLMODEL_NUMERICFIELD
, FRM_SUN_CONTROL_NUMERICFIELD
, sal_True
, sal_True
)
107 // use the old control name for compytibility reasons
109 DBG_CTOR( ONumericModel
, NULL
);
111 m_nClassId
= FormComponentType::NUMERICFIELD
;
112 initValueProperty( PROPERTY_VALUE
, PROPERTY_ID_VALUE
);
115 //------------------------------------------------------------------
116 ONumericModel::ONumericModel( const ONumericModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
117 :OEditBaseModel( _pOriginal
, _rxFactory
)
119 DBG_CTOR( ONumericModel
, NULL
);
122 //------------------------------------------------------------------
123 ONumericModel::~ONumericModel()
125 DBG_DTOR( ONumericModel
, NULL
);
129 //------------------------------------------------------------------------------
130 IMPLEMENT_DEFAULT_CLONING( ONumericModel
)
133 //------------------------------------------------------------------------------
134 StringSequence
ONumericModel::getSupportedServiceNames() throw()
136 StringSequence aSupported
= OBoundControlModel::getSupportedServiceNames();
138 sal_Int32 nOldLen
= aSupported
.getLength();
139 aSupported
.realloc( nOldLen
+ 8 );
140 ::rtl::OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
142 *pStoreTo
++ = BINDABLE_CONTROL_MODEL
;
143 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
144 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
146 *pStoreTo
++ = BINDABLE_DATA_AWARE_CONTROL_MODEL
;
147 *pStoreTo
++ = VALIDATABLE_BINDABLE_CONTROL_MODEL
;
149 *pStoreTo
++ = FRM_SUN_COMPONENT_NUMERICFIELD
;
150 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD
;
151 *pStoreTo
++ = BINDABLE_DATABASE_NUMERIC_FIELD
;
156 //------------------------------------------------------------------------------
157 void ONumericModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
159 BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel
)
160 DECL_PROP3(DEFAULT_VALUE
, double, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
161 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
162 END_DESCRIBE_PROPERTIES();
165 //------------------------------------------------------------------------------
166 ::rtl::OUString SAL_CALL
ONumericModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
)
168 return FRM_COMPONENT_NUMERICFIELD
; // old (non-sun) name for compatibility !
171 //------------------------------------------------------------------------------
172 sal_Bool
ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
174 Any
aControlValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
175 if ( !compare( aControlValue
, m_aSaveValue
) )
177 if ( !aControlValue
.hasValue() )
178 m_xColumnUpdate
->updateNull();
183 m_xColumnUpdate
->updateDouble( getDouble( aControlValue
) );
190 m_aSaveValue
= aControlValue
;
195 //------------------------------------------------------------------------------
196 Any
ONumericModel::translateDbColumnToControlValue()
198 m_aSaveValue
<<= (double)m_xColumn
->getDouble();
199 if ( m_xColumn
->wasNull() )
200 m_aSaveValue
.clear();
205 //------------------------------------------------------------------------------
206 Any
ONumericModel::getDefaultForReset() const
209 if (m_aDefault
.getValueType().getTypeClass() == TypeClass_DOUBLE
)
215 //.........................................................................
217 //.........................................................................