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