1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "Numeric.hxx"
21 #include <services.hxx>
22 #include <property.hxx>
23 #include <comphelper/types.hxx>
24 #include <com/sun/star/form/FormComponentType.hpp>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::sdb
;
31 using namespace ::com::sun::star::sdbc
;
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
;
41 ONumericControl::ONumericControl(const Reference
<XComponentContext
>& _rxFactory
)
42 :OBoundControl(_rxFactory
, VCL_CONTROL_NUMERICFIELD
)
47 css::uno::Sequence
<OUString
> ONumericControl::getSupportedServiceNames()
49 css::uno::Sequence
<OUString
> aSupported
= OBoundControl::getSupportedServiceNames();
50 aSupported
.realloc(aSupported
.getLength() + 2);
52 OUString
*pArray
= aSupported
.getArray();
53 pArray
[aSupported
.getLength()-2] = FRM_SUN_CONTROL_NUMERICFIELD
;
54 pArray
[aSupported
.getLength()-1] = STARDIV_ONE_FORM_CONTROL_NUMERICFIELD
;
60 ONumericModel::ONumericModel(const Reference
<XComponentContext
>& _rxFactory
)
61 :OEditBaseModel( _rxFactory
, VCL_CONTROLMODEL_NUMERICFIELD
, FRM_SUN_CONTROL_NUMERICFIELD
, true, true )
62 // use the old control name for compytibility reasons
65 m_nClassId
= FormComponentType::NUMERICFIELD
;
66 initValueProperty( PROPERTY_VALUE
, PROPERTY_ID_VALUE
);
70 ONumericModel::ONumericModel( const ONumericModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
71 :OEditBaseModel( _pOriginal
, _rxFactory
)
76 ONumericModel::~ONumericModel()
82 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
ONumericModel::createClone()
84 rtl::Reference
<ONumericModel
> pClone
= new ONumericModel(this, getContext());
85 pClone
->clonedFrom(this);
91 css::uno::Sequence
<OUString
> ONumericModel::getSupportedServiceNames()
93 css::uno::Sequence
<OUString
> aSupported
= OBoundControlModel::getSupportedServiceNames();
95 sal_Int32 nOldLen
= aSupported
.getLength();
96 aSupported
.realloc( nOldLen
+ 9 );
97 OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
99 *pStoreTo
++ = BINDABLE_CONTROL_MODEL
;
100 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
101 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
103 *pStoreTo
++ = BINDABLE_DATA_AWARE_CONTROL_MODEL
;
104 *pStoreTo
++ = VALIDATABLE_BINDABLE_CONTROL_MODEL
;
106 *pStoreTo
++ = FRM_SUN_COMPONENT_NUMERICFIELD
;
107 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD
;
108 *pStoreTo
++ = BINDABLE_DATABASE_NUMERIC_FIELD
;
110 *pStoreTo
++ = FRM_COMPONENT_NUMERICFIELD
;
116 void ONumericModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
118 OEditBaseModel::describeFixedProperties( _rProps
);
119 sal_Int32 nOldCount
= _rProps
.getLength();
120 _rProps
.realloc( nOldCount
+ 2);
121 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
122 *pProperties
++ = css::beans::Property(PROPERTY_DEFAULT_VALUE
, PROPERTY_ID_DEFAULT_VALUE
, cppu::UnoType
<double>::get(), css::beans::PropertyAttribute::BOUND
| css::beans::PropertyAttribute::MAYBEDEFAULT
| css::beans::PropertyAttribute::MAYBEVOID
);
123 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
124 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
128 OUString SAL_CALL
ONumericModel::getServiceName()
130 return FRM_COMPONENT_NUMERICFIELD
; // old (non-sun) name for compatibility !
134 bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
136 Any
aControlValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
137 if ( aControlValue
!= m_aSaveValue
)
139 if ( !aControlValue
.hasValue() )
140 m_xColumnUpdate
->updateNull();
145 m_xColumnUpdate
->updateDouble( getDouble( aControlValue
) );
147 catch(const Exception
&)
152 m_aSaveValue
= aControlValue
;
158 Any
ONumericModel::translateDbColumnToControlValue()
160 m_aSaveValue
<<= m_xColumn
->getDouble();
161 if ( m_xColumn
->wasNull() )
162 m_aSaveValue
.clear();
168 Any
ONumericModel::getDefaultForReset() const
171 if (m_aDefault
.getValueType().getTypeClass() == TypeClass_DOUBLE
)
178 void ONumericModel::resetNoBroadcast()
180 OEditBaseModel::resetNoBroadcast();
181 m_aSaveValue
.clear();
186 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
187 com_sun_star_form_ONumericModel_get_implementation(css::uno::XComponentContext
* component
,
188 css::uno::Sequence
<css::uno::Any
> const &)
190 return cppu::acquire(new frm::ONumericModel(component
));
193 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
194 com_sun_star_form_ONumericControl_get_implementation(css::uno::XComponentContext
* component
,
195 css::uno::Sequence
<css::uno::Any
> const &)
197 return cppu::acquire(new frm::ONumericControl(component
));
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */