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 ) throw ( Exception ) 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 throw ( IllegalArgumentException ) 148 { 149 sal_Bool bModified( sal_False ); 150 switch ( _nHandle ) 151 { 152 case PROPERTY_ID_DEFAULT_SPIN_VALUE: 153 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue ); 154 break; 155 156 default: 157 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue ); 158 break; 159 } 160 return bModified; 161 } 162 163 //-------------------------------------------------------------------- 164 Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const 165 { 166 Any aReturn; 167 168 switch ( _nHandle ) 169 { 170 case PROPERTY_ID_DEFAULT_SPIN_VALUE: 171 aReturn <<= (sal_Int32)0; 172 break; 173 174 default: 175 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle ); 176 break; 177 } 178 179 return aReturn; 180 } 181 182 //------------------------------------------------------------------------------ 183 Any OSpinButtonModel::translateDbColumnToControlValue( ) 184 { 185 OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" ); 186 return Any(); 187 } 188 189 //------------------------------------------------------------------------------ 190 sal_Bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 191 { 192 OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" ); 193 return sal_True; 194 } 195 196 //------------------------------------------------------------------------------ 197 Any OSpinButtonModel::getDefaultForReset() const 198 { 199 return makeAny( (sal_Int32)m_nDefaultSpinValue ); 200 } 201 202 //-------------------------------------------------------------------- 203 ::rtl::OUString SAL_CALL OSpinButtonModel::getServiceName() throw( RuntimeException ) 204 { 205 return FRM_SUN_COMPONENT_SPINBUTTON; 206 } 207 208 //-------------------------------------------------------------------- 209 void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream ) 210 throw( IOException, RuntimeException ) 211 { 212 OBoundControlModel::write( _rxOutStream ); 213 ::osl::MutexGuard aGuard( m_aMutex ); 214 215 OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) ); 216 217 // version 218 _rxOutStream->writeShort( 0x0001 ); 219 220 // properties 221 _rxOutStream << m_nDefaultSpinValue; 222 writeHelpTextCompatibly( _rxOutStream ); 223 } 224 225 //-------------------------------------------------------------------- 226 void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException ) 227 { 228 OBoundControlModel::read( _rxInStream ); 229 ::osl::MutexGuard aGuard( m_aMutex ); 230 231 // version 232 { 233 OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) ); 234 235 sal_uInt16 nVersion = _rxInStream->readShort(); 236 if ( nVersion == 0x0001 ) 237 { 238 _rxInStream >> m_nDefaultSpinValue; 239 readHelpTextCompatibly( _rxInStream ); 240 } 241 else 242 defaultCommonProperties(); 243 244 // here, everything in the stream section which is left will be skipped 245 } 246 } 247 248 //-------------------------------------------------------------------- 249 Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const 250 { 251 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet, 252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMin" ) ), 253 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMax" ) ) ); 254 } 255 256 //-------------------------------------------------------------------- 257 Any OSpinButtonModel::translateControlValueToExternalValue( ) const 258 { 259 // by definition, the base class simply obtains the property value 260 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() ); 261 } 262 263 //-------------------------------------------------------------------- 264 Sequence< Type > OSpinButtonModel::getSupportedBindingTypes() 265 { 266 return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 ); 267 } 268 269 //........................................................................ 270 } // namespace frm 271 //........................................................................ 272