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