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 10cdf0e10cSrcweir * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 "CheckBox.hxx" 27cdf0e10cSrcweir #include "property.hxx" 28cdf0e10cSrcweir #ifndef _FRM_PROPERTY_HRC_ 29cdf0e10cSrcweir #include "property.hrc" 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir #include "services.hxx" 32cdf0e10cSrcweir #include <tools/debug.hxx> 33cdf0e10cSrcweir #include <comphelper/basicio.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir //......................................................................... 36cdf0e10cSrcweir namespace frm 37cdf0e10cSrcweir { 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 40cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 41cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 42cdf0e10cSrcweir using namespace ::com::sun::star::beans; 43cdf0e10cSrcweir using namespace ::com::sun::star::container; 44cdf0e10cSrcweir using namespace ::com::sun::star::form; 45cdf0e10cSrcweir using namespace ::com::sun::star::awt; 46cdf0e10cSrcweir using namespace ::com::sun::star::io; 47cdf0e10cSrcweir using namespace ::com::sun::star::lang; 48cdf0e10cSrcweir using namespace ::com::sun::star::util; 49cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 50cdf0e10cSrcweir 51cdf0e10cSrcweir //================================================================== 52cdf0e10cSrcweir //= OCheckBoxControl 53cdf0e10cSrcweir //================================================================== 54cdf0e10cSrcweir 55cdf0e10cSrcweir //------------------------------------------------------------------ 56cdf0e10cSrcweir OCheckBoxControl::OCheckBoxControl(const Reference<XMultiServiceFactory>& _rxFactory) 57cdf0e10cSrcweir :OBoundControl(_rxFactory, VCL_CONTROL_CHECKBOX) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir //------------------------------------------------------------------ 62cdf0e10cSrcweir InterfaceRef SAL_CALL OCheckBoxControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir return *(new OCheckBoxControl(_rxFactory)); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir //------------------------------------------------------------------------------ 68cdf0e10cSrcweir StringSequence SAL_CALL OCheckBoxControl::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir StringSequence aSupported = OBoundControl::getSupportedServiceNames(); 71cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 1); 72cdf0e10cSrcweir 73cdf0e10cSrcweir ::rtl::OUString* pArray = aSupported.getArray(); 74cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CHECKBOX; 75cdf0e10cSrcweir return aSupported; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir //================================================================== 79cdf0e10cSrcweir //= OCheckBoxModel 80cdf0e10cSrcweir //================================================================== 81cdf0e10cSrcweir 82cdf0e10cSrcweir //================================================================== 83cdf0e10cSrcweir InterfaceRef SAL_CALL OCheckBoxModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir return *(new OCheckBoxModel(_rxFactory)); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir //------------------------------------------------------------------ 89cdf0e10cSrcweir DBG_NAME( OCheckBoxModel ) 90cdf0e10cSrcweir //------------------------------------------------------------------ 91cdf0e10cSrcweir OCheckBoxModel::OCheckBoxModel(const Reference<XMultiServiceFactory>& _rxFactory) 92cdf0e10cSrcweir :OReferenceValueComponent( _rxFactory, VCL_CONTROLMODEL_CHECKBOX, FRM_SUN_CONTROL_CHECKBOX, sal_True ) 93cdf0e10cSrcweir // use the old control name for compytibility reasons 94cdf0e10cSrcweir { 95cdf0e10cSrcweir DBG_CTOR( OCheckBoxModel, NULL ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir m_nClassId = FormComponentType::CHECKBOX; 98cdf0e10cSrcweir initValueProperty( PROPERTY_STATE, PROPERTY_ID_STATE ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir //------------------------------------------------------------------ 102cdf0e10cSrcweir OCheckBoxModel::OCheckBoxModel( const OCheckBoxModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory ) 103cdf0e10cSrcweir :OReferenceValueComponent( _pOriginal, _rxFactory ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir DBG_CTOR( OCheckBoxModel, NULL ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir //------------------------------------------------------------------------------ 109cdf0e10cSrcweir OCheckBoxModel::~OCheckBoxModel() 110cdf0e10cSrcweir { 111cdf0e10cSrcweir DBG_DTOR( OCheckBoxModel, NULL ); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir //------------------------------------------------------------------------------ 115cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OCheckBoxModel ) 116cdf0e10cSrcweir 117cdf0e10cSrcweir // XServiceInfo 118cdf0e10cSrcweir //------------------------------------------------------------------------------ 119cdf0e10cSrcweir StringSequence SAL_CALL OCheckBoxModel::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir StringSequence aSupported = OReferenceValueComponent::getSupportedServiceNames(); 122cdf0e10cSrcweir 123cdf0e10cSrcweir sal_Int32 nOldLen = aSupported.getLength(); 124cdf0e10cSrcweir aSupported.realloc( nOldLen + 8 ); 125cdf0e10cSrcweir ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen; 126cdf0e10cSrcweir 127cdf0e10cSrcweir *pStoreTo++ = BINDABLE_CONTROL_MODEL; 128cdf0e10cSrcweir *pStoreTo++ = DATA_AWARE_CONTROL_MODEL; 129cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_CONTROL_MODEL; 130cdf0e10cSrcweir 131cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL; 132cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL; 133cdf0e10cSrcweir 134cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_CHECKBOX; 135cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CHECKBOX; 136cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATABASE_CHECK_BOX; 137cdf0e10cSrcweir 138cdf0e10cSrcweir return aSupported; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir //------------------------------------------------------------------------------ 142cdf0e10cSrcweir void OCheckBoxModel::describeFixedProperties( Sequence< Property >& _rProps ) const 143cdf0e10cSrcweir { 144cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 1, OReferenceValueComponent ) 145cdf0e10cSrcweir DECL_PROP1(TABINDEX, sal_Int16, BOUND); 146cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir //------------------------------------------------------------------------------ 150cdf0e10cSrcweir ::rtl::OUString SAL_CALL OCheckBoxModel::getServiceName() throw(RuntimeException) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir return FRM_COMPONENT_CHECKBOX; // old (non-sun) name for compatibility ! 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir //------------------------------------------------------------------------------ 156cdf0e10cSrcweir void SAL_CALL OCheckBoxModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream) 157cdf0e10cSrcweir throw(stario::IOException, RuntimeException) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir OReferenceValueComponent::write(_rxOutStream); 160cdf0e10cSrcweir 161cdf0e10cSrcweir // Version 162cdf0e10cSrcweir _rxOutStream->writeShort(0x0003); 163cdf0e10cSrcweir // Properties 164cdf0e10cSrcweir _rxOutStream << getReferenceValue(); 165cdf0e10cSrcweir _rxOutStream << (sal_Int16)getDefaultChecked(); 166cdf0e10cSrcweir writeHelpTextCompatibly(_rxOutStream); 167cdf0e10cSrcweir // from version 0x0003 : common properties 168cdf0e10cSrcweir writeCommonProperties(_rxOutStream); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir //------------------------------------------------------------------------------ 172cdf0e10cSrcweir void SAL_CALL OCheckBoxModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw(stario::IOException, RuntimeException) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir OReferenceValueComponent::read(_rxInStream); 175cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 176cdf0e10cSrcweir 177cdf0e10cSrcweir // Version 178cdf0e10cSrcweir sal_uInt16 nVersion = _rxInStream->readShort(); 179cdf0e10cSrcweir 180cdf0e10cSrcweir ::rtl::OUString sReferenceValue; 181cdf0e10cSrcweir sal_Int16 nDefaultChecked( 0 ); 182cdf0e10cSrcweir switch ( nVersion ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir case 0x0001: 185cdf0e10cSrcweir _rxInStream >> sReferenceValue; 186cdf0e10cSrcweir nDefaultChecked = _rxInStream->readShort(); 187cdf0e10cSrcweir break; 188cdf0e10cSrcweir case 0x0002: 189cdf0e10cSrcweir _rxInStream >> sReferenceValue; 190cdf0e10cSrcweir _rxInStream >> nDefaultChecked; 191cdf0e10cSrcweir readHelpTextCompatibly( _rxInStream ); 192cdf0e10cSrcweir break; 193cdf0e10cSrcweir case 0x0003: 194cdf0e10cSrcweir _rxInStream >> sReferenceValue; 195cdf0e10cSrcweir _rxInStream >> nDefaultChecked; 196cdf0e10cSrcweir readHelpTextCompatibly(_rxInStream); 197cdf0e10cSrcweir readCommonProperties(_rxInStream); 198cdf0e10cSrcweir break; 199cdf0e10cSrcweir default: 200cdf0e10cSrcweir DBG_ERROR("OCheckBoxModel::read : unknown version !"); 201cdf0e10cSrcweir defaultCommonProperties(); 202cdf0e10cSrcweir break; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir setReferenceValue( sReferenceValue ); 205cdf0e10cSrcweir setDefaultChecked( static_cast< ToggleState >( nDefaultChecked ) ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir // Nach dem Lesen die Defaultwerte anzeigen 208cdf0e10cSrcweir if ( getControlSource().getLength() ) 209cdf0e10cSrcweir // (not if we don't have a control source - the "State" property acts like it is persistent, then 210cdf0e10cSrcweir resetNoBroadcast(); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir //------------------------------------------------------------------------------ 214cdf0e10cSrcweir Any OCheckBoxModel::translateDbColumnToControlValue() 215cdf0e10cSrcweir { 216cdf0e10cSrcweir Any aValue; 217cdf0e10cSrcweir 218cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 219cdf0e10cSrcweir // Wert an ControlModel setzen 220cdf0e10cSrcweir sal_Bool bValue = m_xColumn->getBoolean(); 221cdf0e10cSrcweir if ( m_xColumn->wasNull() ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir sal_Bool bTriState = sal_True; 224cdf0e10cSrcweir if ( m_xAggregateSet.is() ) 225cdf0e10cSrcweir m_xAggregateSet->getPropertyValue( PROPERTY_TRISTATE ) >>= bTriState; 226cdf0e10cSrcweir aValue <<= (sal_Int16)( bTriState ? STATE_DONTKNOW : getDefaultChecked() ); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir else 229cdf0e10cSrcweir aValue <<= (sal_Int16)( bValue ? STATE_CHECK : STATE_NOCHECK ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir return aValue; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir //----------------------------------------------------------------------------- 235cdf0e10cSrcweir sal_Bool OCheckBoxModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir OSL_PRECOND( m_xColumnUpdate.is(), "OCheckBoxModel::commitControlValueToDbColumn: not bound!" ); 238cdf0e10cSrcweir if ( m_xColumnUpdate.is() ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) ); 241cdf0e10cSrcweir try 242cdf0e10cSrcweir { 243cdf0e10cSrcweir sal_Int16 nValue = STATE_DONTKNOW; 244cdf0e10cSrcweir aControlValue >>= nValue; 245cdf0e10cSrcweir switch (nValue) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir case STATE_DONTKNOW: 248cdf0e10cSrcweir m_xColumnUpdate->updateNull(); 249cdf0e10cSrcweir break; 250cdf0e10cSrcweir case STATE_CHECK: 251cdf0e10cSrcweir m_xColumnUpdate->updateBoolean( sal_True ); 252cdf0e10cSrcweir break; 253cdf0e10cSrcweir case STATE_NOCHECK: 254cdf0e10cSrcweir m_xColumnUpdate->updateBoolean( sal_False ); 255cdf0e10cSrcweir break; 256cdf0e10cSrcweir default: 257cdf0e10cSrcweir DBG_ERROR("OCheckBoxModel::commitControlValueToDbColumn: invalid value !"); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir catch(Exception&) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir DBG_ERROR("OCheckBoxModel::commitControlValueToDbColumn: could not commit !"); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir } 265cdf0e10cSrcweir return sal_True; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir //......................................................................... 269cdf0e10cSrcweir } 270cdf0e10cSrcweir //......................................................................... 271cdf0e10cSrcweir 272