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