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