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