LibreOffice Module forms (master) 1
Numeric.cxx
Go to the documentation of this file.
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 <services.hxx>
22#include <property.hxx>
23#include <comphelper/types.hxx>
24#include <tools/debug.hxx>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/form/FormComponentType.hpp>
27
28namespace frm
29{
30
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::sdb;
33using namespace ::com::sun::star::sdbc;
34using namespace ::com::sun::star::beans;
35using namespace ::com::sun::star::container;
36using namespace ::com::sun::star::form;
37using namespace ::com::sun::star::awt;
38using namespace ::com::sun::star::io;
39using namespace ::com::sun::star::lang;
40using namespace ::com::sun::star::util;
41using namespace ::com::sun::star::form::binding;
42
43ONumericControl::ONumericControl(const Reference<XComponentContext>& _rxFactory)
44 :OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD)
45{
46}
47
48
49css::uno::Sequence<OUString> ONumericControl::getSupportedServiceNames()
50{
51 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
52 aSupported.realloc(aSupported.getLength() + 2);
53
54 OUString*pArray = aSupported.getArray();
55 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_NUMERICFIELD;
56 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_NUMERICFIELD;
57 return aSupported;
58}
59
60// ONumericModel
61
62ONumericModel::ONumericModel(const Reference<XComponentContext>& _rxFactory)
64 // use the old control name for compytibility reasons
65{
66
67 m_nClassId = FormComponentType::NUMERICFIELD;
68 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
69}
70
71
72ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
73 :OEditBaseModel( _pOriginal, _rxFactory )
74{
75}
76
77
79{
80}
81
82// XCloneable
83
84css::uno::Reference< css::util::XCloneable > SAL_CALL ONumericModel::createClone()
85{
87 pClone->clonedFrom(this);
88 return pClone;
89}
90
91// XServiceInfo
92
93css::uno::Sequence<OUString> ONumericModel::getSupportedServiceNames()
94{
95 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
96
97 sal_Int32 nOldLen = aSupported.getLength();
98 aSupported.realloc( nOldLen + 9 );
99 OUString* pStoreTo = aSupported.getArray() + nOldLen;
100
101 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
102 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
103 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
104
107
108 *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD;
111
112 *pStoreTo++ = FRM_COMPONENT_NUMERICFIELD;
113
114 return aSupported;
115}
116
117
118void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const
119{
121 sal_Int32 nOldCount = _rProps.getLength();
122 _rProps.realloc( nOldCount + 2);
123 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
124 *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);
125 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
126 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
127}
128
129
131{
132 return FRM_COMPONENT_NUMERICFIELD; // old (non-sun) name for compatibility !
133}
134
135
137{
138 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
139 if ( aControlValue != m_aSaveValue )
140 {
141 if ( !aControlValue.hasValue() )
142 m_xColumnUpdate->updateNull();
143 else
144 {
145 try
146 {
147 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
148 }
149 catch(const Exception&)
150 {
151 return false;
152 }
153 }
154 m_aSaveValue = aControlValue;
155 }
156 return true;
157}
158
159
161{
162 m_aSaveValue <<= m_xColumn->getDouble();
163 if ( m_xColumn->wasNull() )
164 m_aSaveValue.clear();
165
166 return m_aSaveValue;
167}
168
169
171{
172 Any aValue;
173 if (m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE)
174 aValue = m_aDefault;
175
176 return aValue;
177}
178
179
181{
183 m_aSaveValue.clear();
184}
185
186} // namespace frm
187
188extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
189com_sun_star_form_ONumericModel_get_implementation(css::uno::XComponentContext* component,
190 css::uno::Sequence<css::uno::Any> const &)
191{
192 return cppu::acquire(new frm::ONumericModel(component));
193}
194
195extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
196com_sun_star_form_ONumericControl_get_implementation(css::uno::XComponentContext* component,
197 css::uno::Sequence<css::uno::Any> const &)
198{
199 return cppu::acquire(new frm::ONumericControl(component));
200}
201
202/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_ONumericControl_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Numeric.cxx:196
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_ONumericModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Numeric.cxx:189
sal_Int32 getValuePropertyAggHandle() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::sdb::XColumn > m_xColumn
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
virtual void resetNoBroadcast()
called to reset the control to some kind of default.
css::uno::Reference< css::sdb::XColumnUpdate > m_xColumnUpdate
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
css::uno::Any m_aDefault
Definition: EditBase.hxx:44
ONumericControl(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
virtual void resetNoBroadcast() override
called to reset the control to some kind of default.
Definition: Numeric.cxx:180
virtual css::uno::Any translateDbColumnToControlValue() override
translates a db column value into a control value.
Definition: Numeric.cxx:160
css::uno::Any m_aSaveValue
Definition: Numeric.hxx:32
virtual css::uno::Any getDefaultForReset() const override
returns the default which should be used when resetting the control
Definition: Numeric.cxx:170
virtual bool commitControlValueToDbColumn(bool _bPostReset) override
commits the current control value to the database column we're bound to @precond we're properly bound...
Definition: Numeric.cxx:136
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Numeric.cxx:93
virtual OUString SAL_CALL getServiceName() override
Definition: Numeric.cxx:130
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
Definition: Numeric.cxx:118
virtual ~ONumericModel() override
Definition: Numeric.cxx:78
ONumericModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: Numeric.cxx:84
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_DEFAULT_VALUE
Definition: frm_strings.hxx:88
constexpr OUStringLiteral PROPERTY_VALUE
Definition: frm_strings.hxx:32
@ Exception
double getDouble(const Any &_rAny)
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
#define PROPERTY_ID_DEFAULT_VALUE
Definition: property.hxx:110
#define PROPERTY_ID_VALUE
Definition: property.hxx:66
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
constexpr OUStringLiteral BINDABLE_DATABASE_NUMERIC_FIELD
Definition: services.hxx:173
constexpr OUStringLiteral FRM_SUN_CONTROL_NUMERICFIELD
Definition: services.hxx:161
constexpr OUStringLiteral VALIDATABLE_BINDABLE_CONTROL_MODEL
Definition: services.hxx:184
constexpr OUStringLiteral VCL_CONTROL_NUMERICFIELD
Definition: services.hxx:33
constexpr OUStringLiteral FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD
Definition: services.hxx:146
constexpr OUStringLiteral FRM_COMPONENT_NUMERICFIELD
Definition: services.hxx:80
constexpr OUStringLiteral BINDABLE_DATA_AWARE_CONTROL_MODEL
Definition: services.hxx:181
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_NUMERICFIELD
Definition: services.hxx:101
constexpr OUStringLiteral DATA_AWARE_CONTROL_MODEL
Definition: services.hxx:182
constexpr OUStringLiteral VALIDATABLE_CONTROL_MODEL
Definition: services.hxx:183
constexpr OUStringLiteral VCL_CONTROLMODEL_NUMERICFIELD
Definition: services.hxx:51
constexpr OUStringLiteral FRM_SUN_COMPONENT_NUMERICFIELD
Definition: services.hxx:126
constexpr OUStringLiteral BINDABLE_CONTROL_MODEL
Definition: services.hxx:179