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