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