tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / forms / source / component / Numeric.cxx
blob201bcdbd79f1a1095b51a8230be4e8952f44a210
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/debug.hxx>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/form/FormComponentType.hpp>
28 namespace frm
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::sdb;
33 using namespace ::com::sun::star::sdbc;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::form;
36 using namespace ::com::sun::star::util;
38 ONumericControl::ONumericControl(const Reference<XComponentContext>& _rxFactory)
39 :OBoundControl(_rxFactory, VCL_CONTROL_NUMERICFIELD)
44 css::uno::Sequence<OUString> ONumericControl::getSupportedServiceNames()
46 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
47 aSupported.realloc(aSupported.getLength() + 2);
49 OUString*pArray = aSupported.getArray();
50 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_NUMERICFIELD;
51 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_NUMERICFIELD;
52 return aSupported;
55 // ONumericModel
57 ONumericModel::ONumericModel(const Reference<XComponentContext>& _rxFactory)
58 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_NUMERICFIELD, FRM_SUN_CONTROL_NUMERICFIELD, true, true )
59 // use the old control name for compatibility reasons
62 m_nClassId = FormComponentType::NUMERICFIELD;
63 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
67 ONumericModel::ONumericModel( const ONumericModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
68 :OEditBaseModel( _pOriginal, _rxFactory )
73 ONumericModel::~ONumericModel()
77 // XCloneable
79 css::uno::Reference< css::util::XCloneable > SAL_CALL ONumericModel::createClone()
81 rtl::Reference<ONumericModel> pClone = new ONumericModel(this, getContext());
82 pClone->clonedFrom(this);
83 return pClone;
86 // XServiceInfo
88 css::uno::Sequence<OUString> ONumericModel::getSupportedServiceNames()
90 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
92 sal_Int32 nOldLen = aSupported.getLength();
93 aSupported.realloc( nOldLen + 9 );
94 OUString* pStoreTo = aSupported.getArray() + nOldLen;
96 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
97 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
98 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
100 *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
101 *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
103 *pStoreTo++ = FRM_SUN_COMPONENT_NUMERICFIELD;
104 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_NUMERICFIELD;
105 *pStoreTo++ = BINDABLE_DATABASE_NUMERIC_FIELD;
107 *pStoreTo++ = FRM_COMPONENT_NUMERICFIELD;
109 return aSupported;
113 void ONumericModel::describeFixedProperties( Sequence< Property >& _rProps ) const
115 OEditBaseModel::describeFixedProperties( _rProps );
116 sal_Int32 nOldCount = _rProps.getLength();
117 _rProps.realloc( nOldCount + 2);
118 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
119 *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);
120 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
121 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
125 OUString SAL_CALL ONumericModel::getServiceName()
127 return FRM_COMPONENT_NUMERICFIELD; // old (non-sun) name for compatibility !
131 bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
133 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
134 if ( aControlValue != m_aSaveValue )
136 if ( !aControlValue.hasValue() )
137 m_xColumnUpdate->updateNull();
138 else
142 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
144 catch(const Exception&)
146 return false;
149 m_aSaveValue = std::move(aControlValue);
151 return true;
155 Any ONumericModel::translateDbColumnToControlValue()
157 m_aSaveValue <<= m_xColumn->getDouble();
158 if ( m_xColumn->wasNull() )
159 m_aSaveValue.clear();
161 return m_aSaveValue;
165 Any ONumericModel::getDefaultForReset() const
167 Any aValue;
168 if (m_aDefault.getValueTypeClass() == TypeClass_DOUBLE)
169 aValue = m_aDefault;
171 return aValue;
175 void ONumericModel::resetNoBroadcast()
177 OEditBaseModel::resetNoBroadcast();
178 m_aSaveValue.clear();
181 } // namespace frm
183 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
184 com_sun_star_form_ONumericModel_get_implementation(css::uno::XComponentContext* component,
185 css::uno::Sequence<css::uno::Any> const &)
187 return cppu::acquire(new frm::ONumericModel(component));
190 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
191 com_sun_star_form_ONumericControl_get_implementation(css::uno::XComponentContext* component,
192 css::uno::Sequence<css::uno::Any> const &)
194 return cppu::acquire(new frm::ONumericControl(component));
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */