xref: /AOO41X/main/forms/source/component/Numeric.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_forms.hxx"
30*cdf0e10cSrcweir #include "Numeric.hxx"
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir //.........................................................................
34*cdf0e10cSrcweir namespace frm
35*cdf0e10cSrcweir {
36*cdf0e10cSrcweir //.........................................................................
37*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
39*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
40*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
41*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
42*cdf0e10cSrcweir using namespace ::com::sun::star::container;
43*cdf0e10cSrcweir using namespace ::com::sun::star::form;
44*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
45*cdf0e10cSrcweir using namespace ::com::sun::star::io;
46*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
47*cdf0e10cSrcweir using namespace ::com::sun::star::util;
48*cdf0e10cSrcweir using namespace ::com::sun::star::form::binding;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir //==================================================================
51*cdf0e10cSrcweir // ONumericControl
52*cdf0e10cSrcweir //==================================================================
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir //------------------------------------------------------------------
55*cdf0e10cSrcweir ONumericControl::ONumericControl(const Reference<XMultiServiceFactory>& _rxFactory)
56*cdf0e10cSrcweir 	:OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD)
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir //------------------------------------------------------------------------------
61*cdf0e10cSrcweir StringSequence ONumericControl::getSupportedServiceNames() throw()
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 	StringSequence aSupported = OBoundControl::getSupportedServiceNames();
64*cdf0e10cSrcweir 	aSupported.realloc(aSupported.getLength() + 1);
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 	::rtl::OUString*pArray = aSupported.getArray();
67*cdf0e10cSrcweir 	pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_NUMERICFIELD;
68*cdf0e10cSrcweir 	return aSupported;
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir //------------------------------------------------------------------
73*cdf0e10cSrcweir InterfaceRef SAL_CALL ONumericControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	return *(new ONumericControl(_rxFactory));
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //------------------------------------------------------------------------------
79*cdf0e10cSrcweir Sequence<Type> ONumericControl::_getTypes()
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	return OBoundControl::_getTypes();
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir //==================================================================
85*cdf0e10cSrcweir // ONumericModel
86*cdf0e10cSrcweir //==================================================================
87*cdf0e10cSrcweir //------------------------------------------------------------------
88*cdf0e10cSrcweir InterfaceRef SAL_CALL ONumericModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	return *(new ONumericModel(_rxFactory));
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir //------------------------------------------------------------------------------
94*cdf0e10cSrcweir Sequence<Type> ONumericModel::_getTypes()
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir 	return OEditBaseModel::_getTypes();
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir //------------------------------------------------------------------
100*cdf0e10cSrcweir DBG_NAME( ONumericModel )
101*cdf0e10cSrcweir //------------------------------------------------------------------
102*cdf0e10cSrcweir ONumericModel::ONumericModel(const Reference<XMultiServiceFactory>& _rxFactory)
103*cdf0e10cSrcweir 				:OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD, sal_True, sal_True )
104*cdf0e10cSrcweir 									// use the old control name for compytibility reasons
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	DBG_CTOR( ONumericModel, NULL );
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	m_nClassId = FormComponentType::NUMERICFIELD;
109*cdf0e10cSrcweir 	initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir //------------------------------------------------------------------
113*cdf0e10cSrcweir ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
114*cdf0e10cSrcweir 	:OEditBaseModel( _pOriginal, _rxFactory )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	DBG_CTOR( ONumericModel, NULL );
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir //------------------------------------------------------------------
120*cdf0e10cSrcweir ONumericModel::~ONumericModel()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	DBG_DTOR( ONumericModel, NULL );
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir // XCloneable
126*cdf0e10cSrcweir //------------------------------------------------------------------------------
127*cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( ONumericModel )
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir // XServiceInfo
130*cdf0e10cSrcweir //------------------------------------------------------------------------------
131*cdf0e10cSrcweir StringSequence ONumericModel::getSupportedServiceNames() throw()
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     sal_Int32 nOldLen = aSupported.getLength();
136*cdf0e10cSrcweir 	aSupported.realloc( nOldLen + 8 );
137*cdf0e10cSrcweir 	::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
140*cdf0e10cSrcweir     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
141*cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
144*cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD;
147*cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD;
148*cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATABASE_NUMERIC_FIELD;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	return aSupported;
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir //------------------------------------------------------------------------------
154*cdf0e10cSrcweir void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir 	BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
157*cdf0e10cSrcweir 		DECL_PROP3(DEFAULT_VALUE,	double,				BOUND, MAYBEDEFAULT, MAYBEVOID);
158*cdf0e10cSrcweir 		DECL_PROP1(TABINDEX,		sal_Int16,			BOUND);
159*cdf0e10cSrcweir 	END_DESCRIBE_PROPERTIES();
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir //------------------------------------------------------------------------------
163*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ONumericModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir 	return FRM_COMPONENT_NUMERICFIELD;	// old (non-sun) name for compatibility !
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir //------------------------------------------------------------------------------
169*cdf0e10cSrcweir sal_Bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir 	Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
172*cdf0e10cSrcweir 	if ( !compare( aControlValue, m_aSaveValue ) )
173*cdf0e10cSrcweir 	{
174*cdf0e10cSrcweir 		if ( !aControlValue.hasValue() )
175*cdf0e10cSrcweir 			m_xColumnUpdate->updateNull();
176*cdf0e10cSrcweir 		else
177*cdf0e10cSrcweir 		{
178*cdf0e10cSrcweir 			try
179*cdf0e10cSrcweir 			{
180*cdf0e10cSrcweir 				m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
181*cdf0e10cSrcweir 			}
182*cdf0e10cSrcweir 			catch(Exception&)
183*cdf0e10cSrcweir 			{
184*cdf0e10cSrcweir 				return sal_False;
185*cdf0e10cSrcweir 			}
186*cdf0e10cSrcweir 		}
187*cdf0e10cSrcweir 		m_aSaveValue = aControlValue;
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 	return sal_True;
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir //------------------------------------------------------------------------------
193*cdf0e10cSrcweir Any ONumericModel::translateDbColumnToControlValue()
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	m_aSaveValue <<= (double)m_xColumn->getDouble();
196*cdf0e10cSrcweir 	if ( m_xColumn->wasNull() )
197*cdf0e10cSrcweir 		m_aSaveValue.clear();
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     return m_aSaveValue;
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir //------------------------------------------------------------------------------
203*cdf0e10cSrcweir Any ONumericModel::getDefaultForReset() const
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir 	Any aValue;
206*cdf0e10cSrcweir 	if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE)
207*cdf0e10cSrcweir 		aValue = m_aDefault;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir     return aValue;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir //------------------------------------------------------------------------------
213*cdf0e10cSrcweir void ONumericModel::resetNoBroadcast()
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir     OEditBaseModel::resetNoBroadcast();
216*cdf0e10cSrcweir     m_aSaveValue.clear();
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir //.........................................................................
220*cdf0e10cSrcweir }	// namespace frm
221*cdf0e10cSrcweir //.........................................................................
222*cdf0e10cSrcweir 
223