LibreOffice Module forms (master) 1
spinbutton.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 "spinbutton.hxx"
21#include "scrollbar.hxx"
25#include <tools/debug.hxx>
26#include <com/sun/star/beans/PropertyAttribute.hpp>
27#include <com/sun/star/form/FormComponentType.hpp>
28#include <property.hxx>
29#include <services.hxx>
30
31
32namespace frm
33{
34
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::form;
38 using namespace ::com::sun::star::awt;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::util;
41 using namespace ::com::sun::star::io;
42 using namespace ::com::sun::star::form::binding;
43
44
45 //= OSpinButtonModel
46
47 OSpinButtonModel::OSpinButtonModel( const Reference<XComponentContext>& _rxFactory )
48 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, true, true, false )
49 ,m_nDefaultSpinValue( 0 )
50 {
51
52 m_nClassId = FormComponentType::SPINBUTTON;
53 initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE );
54 }
55
56
57 OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
58 :OBoundControlModel( _pOriginal, _rxFactory )
59 {
60 m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue;
61 }
62
63
64 OSpinButtonModel::~OSpinButtonModel( )
65 {
66 }
67
68 OUString SAL_CALL OSpinButtonModel::getImplementationName()
69 {
70 return "com.sun.star.comp.forms.OSpinButtonModel";
71 }
72
73 // note that we're passing OControlModel as "base class". This is because
74 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
75 // service, which isn't really true for us. We only derive from this class
76 // to benefit from the functionality for binding to spreadsheet cells
77 Sequence< OUString > SAL_CALL OSpinButtonModel::getSupportedServiceNames()
78 {
79 Sequence< OUString > aOwnNames { FRM_SUN_COMPONENT_SPINBUTTON, BINDABLE_INTEGER_VALUE_RANGE };
80
81 return ::comphelper::combineSequences(
82 getAggregateServiceNames(),
83 ::comphelper::concatSequences(
84 OControlModel::getSupportedServiceNames_Static(),
85 aOwnNames
86 )
87 );
88 }
89
90 css::uno::Reference< css::util::XCloneable > SAL_CALL OSpinButtonModel::createClone()
91{
92 rtl::Reference<OSpinButtonModel> pClone = new OSpinButtonModel(this, getContext());
93 pClone->clonedFrom(this);
94 return pClone;
95}
96
97
98 void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
99 {
100 OControlModel::describeFixedProperties( _rProps );
101 sal_Int32 nOldCount = _rProps.getLength();
102 _rProps.realloc( nOldCount + 3);
103 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
104 *pProperties++ = css::beans::Property(PROPERTY_DEFAULT_SPIN_VALUE, PROPERTY_ID_DEFAULT_SPIN_VALUE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::BOUND);
105 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
106 *pProperties++ = css::beans::Property(PROPERTY_CONTROLSOURCEPROPERTY, PROPERTY_ID_CONTROLSOURCEPROPERTY, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY | css::beans::PropertyAttribute::TRANSIENT);
107 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
108 }
109
110
111 void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
112 {
113 switch ( _nHandle )
114 {
116 _rValue <<= m_nDefaultSpinValue;
117 break;
118
119 default:
120 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
121 }
122 }
123
124
125 void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
126 {
127 switch ( _nHandle )
128 {
130 OSL_VERIFY( _rValue >>= m_nDefaultSpinValue );
131 resetNoBroadcast();
132 break;
133
134 default:
135 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
136 }
137 }
138
139
140 sal_Bool OSpinButtonModel::convertFastPropertyValue(
141 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
142 {
143 bool bModified( false );
144 switch ( _nHandle )
145 {
147 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue );
148 break;
149
150 default:
151 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
152 break;
153 }
154 return bModified;
155 }
156
157
158 Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
159 {
160 Any aReturn;
161
162 switch ( _nHandle )
163 {
165 aReturn <<= sal_Int32(0);
166 break;
167
168 default:
169 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
170 break;
171 }
172
173 return aReturn;
174 }
175
176
177 Any OSpinButtonModel::translateDbColumnToControlValue( )
178 {
179 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
180 return Any();
181 }
182
183
184 bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
185 {
186 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
187 return true;
188 }
189
190
191 Any OSpinButtonModel::getDefaultForReset() const
192 {
193 return Any( m_nDefaultSpinValue );
194 }
195
196
197 OUString SAL_CALL OSpinButtonModel::getServiceName()
198 {
200 }
201
202
203 void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
204 {
205 OBoundControlModel::write( _rxOutStream );
206 ::osl::MutexGuard aGuard( m_aMutex );
207
208 OStreamSection aSection( _rxOutStream );
209
210 // version
211 _rxOutStream->writeShort( 0x0001 );
212
213 // properties
214 _rxOutStream << m_nDefaultSpinValue;
215 writeHelpTextCompatibly( _rxOutStream );
216 }
217
218
219 void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream )
220 {
221 OBoundControlModel::read( _rxInStream );
222 ::osl::MutexGuard aGuard( m_aMutex );
223
224 // version
225 {
226 OStreamSection aSection( _rxInStream );
227
228 sal_uInt16 nVersion = _rxInStream->readShort();
229 if ( nVersion == 0x0001 )
230 {
231 _rxInStream >> m_nDefaultSpinValue;
232 readHelpTextCompatibly( _rxInStream );
233 }
234 else
235 defaultCommonProperties();
236
237 // here, everything in the stream section which is left will be skipped
238 }
239 }
240
241
242 Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
243 {
244 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
245 "SpinValueMin",
246 "SpinValueMax" );
247 }
248
249
250 Any OSpinButtonModel::translateControlValueToExternalValue( ) const
251 {
252 // by definition, the base class simply obtains the property value
253 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
254 }
255
256
257 Sequence< Type > OSpinButtonModel::getSupportedBindingTypes()
258 {
259 return Sequence< Type >( &cppu::UnoType<double>::get(), 1 );
260 }
261
262} // namespace frm
263
264extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
266 css::uno::Sequence<css::uno::Any> const &)
267{
268 return cppu::acquire(new frm::OSpinButtonModel(component));
269}
270
271/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OSpinButtonModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
#define DBG_ASSERT(sCon, aError)
sal_Int16 nVersion
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_DEFAULT_SPIN_VALUE
constexpr OUStringLiteral PROPERTY_SPIN_VALUE
constexpr OUStringLiteral PROPERTY_CONTROLSOURCEPROPERTY
std::mutex m_aMutex
bool tryPropertyValue(Any &_rConvertedValue, Any &_rOldValue, const Any &_rValueToSet, const Any &_rCurrentValue, const Type &_rExpectedType)
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
Any translateControlIntToExternalDoubleValue(const Any &_rControlIntValue)
Definition: scrollbar.cxx:79
Any translateExternalDoubleToControlIntValue(const Any &_rExternalValue, const Reference< XPropertySet > &_rxProperties, const OUString &_rMinValueName, const OUString &_rMaxValueName)
Definition: scrollbar.cxx:46
#define PROPERTY_ID_CONTROLSOURCEPROPERTY
Definition: property.hxx:241
#define PROPERTY_ID_DEFAULT_SPIN_VALUE
Definition: property.hxx:251
#define PROPERTY_ID_SPIN_VALUE
Definition: property.hxx:253
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
constexpr OUStringLiteral VCL_CONTROLMODEL_SPINBUTTON
Definition: services.hxx:59
constexpr OUStringLiteral FRM_SUN_COMPONENT_SPINBUTTON
Definition: services.hxx:132
constexpr OUStringLiteral VCL_CONTROL_SPINBUTTON
Definition: services.hxx:60
constexpr OUStringLiteral BINDABLE_INTEGER_VALUE_RANGE
Definition: services.hxx:180
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_forms_OSpinButtonModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: spinbutton.cxx:265
unsigned char sal_Bool