xref: /trunk/main/forms/source/component/spinbutton.cxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26 #include "spinbutton.hxx"
27 #include <comphelper/streamsection.hxx>
28 #include <comphelper/basicio.hxx>
29 
30 //--------------------------------------------------------------------------
31 extern "C" void SAL_CALL createRegistryInfo_OSpinButtonModel()
32 {
33     static ::frm::OMultiInstanceAutoRegistration< ::frm::OSpinButtonModel >   aRegisterModel;
34 }
35 
36 //........................................................................
37 namespace frm
38 {
39 //........................................................................
40 
41     using namespace ::com::sun::star::uno;
42     using namespace ::com::sun::star::beans;
43     using namespace ::com::sun::star::form;
44     using namespace ::com::sun::star::awt;
45     using namespace ::com::sun::star::lang;
46     using namespace ::com::sun::star::util;
47     using namespace ::com::sun::star::io;
48     using namespace ::com::sun::star::form::binding;
49 
50     //====================================================================
51     //= OSpinButtonModel
52     //====================================================================
53     // implemented elsewhere
54     Any translateExternalDoubleToControlIntValue(
55         const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
56         const ::rtl::OUString& _rMinValueName, const ::rtl::OUString& _rMaxValueName );
57     Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue );
58 
59     //====================================================================
60     //= OSpinButtonModel
61     //====================================================================
62     //--------------------------------------------------------------------
63     DBG_NAME( OSpinButtonModel )
64     //--------------------------------------------------------------------
65     OSpinButtonModel::OSpinButtonModel( const Reference<XMultiServiceFactory>& _rxFactory )
66         :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, sal_True, sal_True, sal_False )
67         ,m_nDefaultSpinValue( 0 )
68     {
69         DBG_CTOR( OSpinButtonModel, NULL );
70 
71         m_nClassId = FormComponentType::SPINBUTTON;
72         initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE );
73     }
74 
75     //--------------------------------------------------------------------
76     OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
77         :OBoundControlModel( _pOriginal, _rxFactory )
78     {
79         DBG_CTOR( OSpinButtonModel, NULL );
80         m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue;
81     }
82 
83     //--------------------------------------------------------------------
84     OSpinButtonModel::~OSpinButtonModel( )
85     {
86         DBG_DTOR( OSpinButtonModel, NULL );
87     }
88 
89     //--------------------------------------------------------------------
90     IMPLEMENT_SERVICE_REGISTRATION_2( OSpinButtonModel, OControlModel, FRM_SUN_COMPONENT_SPINBUTTON, BINDABLE_INTEGER_VALUE_RANGE )
91         // note that we're passing OControlModel as "base class". This is because
92         // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
93         // service, which isn't really true for us. We only derive from this class
94         // to benefit from the functionality for binding to spreadsheet cells
95 
96     //------------------------------------------------------------------------------
97     IMPLEMENT_DEFAULT_CLONING( OSpinButtonModel )
98 
99     //------------------------------------------------------------------------------
100     void SAL_CALL OSpinButtonModel::disposing()
101     {
102         OBoundControlModel::disposing();
103     }
104 
105     //--------------------------------------------------------------------
106     void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
107     {
108         BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
109             DECL_PROP1( DEFAULT_SPIN_VALUE,   sal_Int32,       BOUND );
110             DECL_PROP1( TABINDEX,             sal_Int16,       BOUND );
111             DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT );
112         END_DESCRIBE_PROPERTIES();
113     }
114 
115     //------------------------------------------------------------------------------
116     void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
117     {
118         switch ( _nHandle )
119         {
120             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
121                 _rValue <<= m_nDefaultSpinValue;
122                 break;
123 
124             default:
125                 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
126         }
127     }
128 
129     //------------------------------------------------------------------------------
130     void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
131     {
132         switch ( _nHandle )
133         {
134             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
135                 OSL_VERIFY( _rValue >>= m_nDefaultSpinValue );
136                 resetNoBroadcast();
137                 break;
138 
139             default:
140                 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
141         }
142     }
143 
144     //------------------------------------------------------------------------------
145     sal_Bool OSpinButtonModel::convertFastPropertyValue(
146                 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
147     {
148         sal_Bool bModified( sal_False );
149         switch ( _nHandle )
150         {
151             case PROPERTY_ID_DEFAULT_SPIN_VALUE:
152                 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue );
153                 break;
154 
155             default:
156                 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
157                 break;
158         }
159         return bModified;
160     }
161 
162     //--------------------------------------------------------------------
163     Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
164     {
165         Any aReturn;
166 
167         switch ( _nHandle )
168         {
169         case PROPERTY_ID_DEFAULT_SPIN_VALUE:
170             aReturn <<= (sal_Int32)0;
171             break;
172 
173         default:
174             aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
175             break;
176         }
177 
178         return aReturn;
179     }
180 
181     //------------------------------------------------------------------------------
182     Any OSpinButtonModel::translateDbColumnToControlValue( )
183     {
184         OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
185         return Any();
186     }
187 
188     //------------------------------------------------------------------------------
189     sal_Bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
190     {
191         OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
192         return sal_True;
193     }
194 
195     //------------------------------------------------------------------------------
196     Any OSpinButtonModel::getDefaultForReset() const
197     {
198         return makeAny( (sal_Int32)m_nDefaultSpinValue );
199     }
200 
201     //--------------------------------------------------------------------
202     ::rtl::OUString SAL_CALL OSpinButtonModel::getServiceName()
203     {
204         return FRM_SUN_COMPONENT_SPINBUTTON;
205     }
206 
207     //--------------------------------------------------------------------
208     void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
209     {
210         OBoundControlModel::write( _rxOutStream );
211         ::osl::MutexGuard aGuard( m_aMutex );
212 
213         OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) );
214 
215         // version
216         _rxOutStream->writeShort( 0x0001 );
217 
218         // properties
219         _rxOutStream << m_nDefaultSpinValue;
220         writeHelpTextCompatibly( _rxOutStream );
221     }
222 
223     //--------------------------------------------------------------------
224     void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream )
225     {
226         OBoundControlModel::read( _rxInStream );
227         ::osl::MutexGuard aGuard( m_aMutex );
228 
229         // version
230         {
231             OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) );
232 
233             sal_uInt16 nVersion = _rxInStream->readShort();
234             if ( nVersion == 0x0001 )
235             {
236                 _rxInStream >> m_nDefaultSpinValue;
237                 readHelpTextCompatibly( _rxInStream );
238             }
239             else
240                 defaultCommonProperties();
241 
242             // here, everything in the stream section which is left will be skipped
243         }
244     }
245 
246     //--------------------------------------------------------------------
247     Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
248     {
249         return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
250             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMin" ) ),
251             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMax" ) ) );
252     }
253 
254     //--------------------------------------------------------------------
255     Any OSpinButtonModel::translateControlValueToExternalValue( ) const
256     {
257         // by definition, the base class simply obtains the property value
258         return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
259     }
260 
261     //--------------------------------------------------------------------
262     Sequence< Type > OSpinButtonModel::getSupportedBindingTypes()
263     {
264         return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
265     }
266 
267 //........................................................................
268 }   // namespace frm
269 //........................................................................
270