1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "spinbutton.hxx"
21 #include <comphelper/streamsection.hxx>
22 #include <comphelper/basicio.hxx>
24 //--------------------------------------------------------------------------
25 extern "C" void SAL_CALL
createRegistryInfo_OSpinButtonModel()
27 static ::frm::OMultiInstanceAutoRegistration
< ::frm::OSpinButtonModel
> aRegisterModel
;
30 //........................................................................
33 //........................................................................
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::form
;
38 using namespace ::com::sun::star::awt
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::util
;
41 using namespace ::com::sun::star::io
;
42 using namespace ::com::sun::star::form::binding
;
44 //====================================================================
46 //====================================================================
47 // implemented elsewhere
48 Any
translateExternalDoubleToControlIntValue(
49 const Any
& _rExternalValue
, const Reference
< XPropertySet
>& _rxProperties
,
50 const OUString
& _rMinValueName
, const OUString
& _rMaxValueName
);
51 Any
translateControlIntToExternalDoubleValue( const Any
& _rControlIntValue
);
53 //====================================================================
55 //====================================================================
56 //--------------------------------------------------------------------
57 DBG_NAME( OSpinButtonModel
)
58 //--------------------------------------------------------------------
59 OSpinButtonModel::OSpinButtonModel( const Reference
<XMultiServiceFactory
>& _rxFactory
)
60 :OBoundControlModel( _rxFactory
, VCL_CONTROLMODEL_SPINBUTTON
, VCL_CONTROL_SPINBUTTON
, sal_True
, sal_True
, sal_False
)
61 ,m_nDefaultSpinValue( 0 )
63 DBG_CTOR( OSpinButtonModel
, NULL
);
65 m_nClassId
= FormComponentType::SPINBUTTON
;
66 initValueProperty( PROPERTY_SPIN_VALUE
, PROPERTY_ID_SPIN_VALUE
);
69 //--------------------------------------------------------------------
70 OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel
* _pOriginal
, const Reference
< XMultiServiceFactory
>& _rxFactory
)
71 :OBoundControlModel( _pOriginal
, _rxFactory
)
73 DBG_CTOR( OSpinButtonModel
, NULL
);
74 m_nDefaultSpinValue
= _pOriginal
->m_nDefaultSpinValue
;
77 //--------------------------------------------------------------------
78 OSpinButtonModel::~OSpinButtonModel( )
80 DBG_DTOR( OSpinButtonModel
, NULL
);
83 //--------------------------------------------------------------------
84 IMPLEMENT_SERVICE_REGISTRATION_2( OSpinButtonModel
, OControlModel
, FRM_SUN_COMPONENT_SPINBUTTON
, BINDABLE_INTEGER_VALUE_RANGE
)
85 // note that we're passing OControlModel as "base class". This is because
86 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
87 // service, which isn't really true for us. We only derive from this class
88 // to benefit from the functionality for binding to spreadsheet cells
90 //------------------------------------------------------------------------------
91 IMPLEMENT_DEFAULT_CLONING( OSpinButtonModel
)
93 //------------------------------------------------------------------------------
94 void SAL_CALL
OSpinButtonModel::disposing()
96 OBoundControlModel::disposing();
99 //--------------------------------------------------------------------
100 void OSpinButtonModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
102 BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel
)
103 DECL_PROP1( DEFAULT_SPIN_VALUE
, sal_Int32
, BOUND
);
104 DECL_PROP1( TABINDEX
, sal_Int16
, BOUND
);
105 DECL_PROP2( CONTROLSOURCEPROPERTY
,OUString
, READONLY
, TRANSIENT
);
106 END_DESCRIBE_PROPERTIES();
109 //------------------------------------------------------------------------------
110 void OSpinButtonModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
114 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
115 _rValue
<<= m_nDefaultSpinValue
;
119 OBoundControlModel::getFastPropertyValue( _rValue
, _nHandle
);
123 //------------------------------------------------------------------------------
124 void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw ( Exception
)
128 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
129 OSL_VERIFY( _rValue
>>= m_nDefaultSpinValue
);
134 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
138 //------------------------------------------------------------------------------
139 sal_Bool
OSpinButtonModel::convertFastPropertyValue(
140 Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
)
141 throw ( IllegalArgumentException
)
143 sal_Bool
bModified( sal_False
);
146 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
147 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nDefaultSpinValue
);
151 bModified
= OBoundControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
157 //--------------------------------------------------------------------
158 Any
OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
164 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
165 aReturn
<<= (sal_Int32
)0;
169 aReturn
= OBoundControlModel::getPropertyDefaultByHandle( _nHandle
);
176 //------------------------------------------------------------------------------
177 Any
OSpinButtonModel::translateDbColumnToControlValue( )
179 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
183 //------------------------------------------------------------------------------
184 sal_Bool
OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
186 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
190 //------------------------------------------------------------------------------
191 Any
OSpinButtonModel::getDefaultForReset() const
193 return makeAny( (sal_Int32
)m_nDefaultSpinValue
);
196 //--------------------------------------------------------------------
197 OUString SAL_CALL
OSpinButtonModel::getServiceName() throw( RuntimeException
)
199 return OUString(FRM_SUN_COMPONENT_SPINBUTTON
);
202 //--------------------------------------------------------------------
203 void SAL_CALL
OSpinButtonModel::write( const Reference
< XObjectOutputStream
>& _rxOutStream
)
204 throw( IOException
, RuntimeException
)
206 OBoundControlModel::write( _rxOutStream
);
207 ::osl::MutexGuard
aGuard( m_aMutex
);
209 OStreamSection
aSection( Reference
< XDataOutputStream
>( _rxOutStream
, UNO_QUERY
) );
212 _rxOutStream
->writeShort( 0x0001 );
215 _rxOutStream
<< m_nDefaultSpinValue
;
216 writeHelpTextCompatibly( _rxOutStream
);
219 //--------------------------------------------------------------------
220 void SAL_CALL
OSpinButtonModel::read( const Reference
< XObjectInputStream
>& _rxInStream
) throw( IOException
, RuntimeException
)
222 OBoundControlModel::read( _rxInStream
);
223 ::osl::MutexGuard
aGuard( m_aMutex
);
227 OStreamSection
aSection( Reference
< XDataInputStream
>( _rxInStream
, UNO_QUERY
) );
229 sal_uInt16 nVersion
= _rxInStream
->readShort();
230 if ( nVersion
== 0x0001 )
232 _rxInStream
>> m_nDefaultSpinValue
;
233 readHelpTextCompatibly( _rxInStream
);
236 defaultCommonProperties();
238 // here, everything in the stream section which is left will be skipped
242 //--------------------------------------------------------------------
243 Any
OSpinButtonModel::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
245 return translateExternalDoubleToControlIntValue( _rExternalValue
, m_xAggregateSet
,
246 OUString( "SpinValueMin" ),
247 OUString( "SpinValueMax" ) );
250 //--------------------------------------------------------------------
251 Any
OSpinButtonModel::translateControlValueToExternalValue( ) const
253 // by definition, the base class simply obtains the property value
254 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
257 //--------------------------------------------------------------------
258 Sequence
< Type
> OSpinButtonModel::getSupportedBindingTypes()
260 return Sequence
< Type
>( &::getCppuType( static_cast< double* >( NULL
) ), 1 );
263 //........................................................................
265 //........................................................................
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */