1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_forms.hxx" 30*cdf0e10cSrcweir #include "CheckBox.hxx" 31*cdf0e10cSrcweir #include "property.hxx" 32*cdf0e10cSrcweir #ifndef _FRM_PROPERTY_HRC_ 33*cdf0e10cSrcweir #include "property.hrc" 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir #include "services.hxx" 36*cdf0e10cSrcweir #include <tools/debug.hxx> 37*cdf0e10cSrcweir #include <comphelper/basicio.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir //......................................................................... 40*cdf0e10cSrcweir namespace frm 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 44*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 45*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 46*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 47*cdf0e10cSrcweir using namespace ::com::sun::star::container; 48*cdf0e10cSrcweir using namespace ::com::sun::star::form; 49*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 50*cdf0e10cSrcweir using namespace ::com::sun::star::io; 51*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52*cdf0e10cSrcweir using namespace ::com::sun::star::util; 53*cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir //================================================================== 56*cdf0e10cSrcweir //= OCheckBoxControl 57*cdf0e10cSrcweir //================================================================== 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir //------------------------------------------------------------------ 60*cdf0e10cSrcweir OCheckBoxControl::OCheckBoxControl(const Reference<XMultiServiceFactory>& _rxFactory) 61*cdf0e10cSrcweir :OBoundControl(_rxFactory, VCL_CONTROL_CHECKBOX) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //------------------------------------------------------------------ 66*cdf0e10cSrcweir InterfaceRef SAL_CALL OCheckBoxControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir return *(new OCheckBoxControl(_rxFactory)); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir //------------------------------------------------------------------------------ 72*cdf0e10cSrcweir StringSequence SAL_CALL OCheckBoxControl::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir StringSequence aSupported = OBoundControl::getSupportedServiceNames(); 75*cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 1); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir ::rtl::OUString* pArray = aSupported.getArray(); 78*cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CHECKBOX; 79*cdf0e10cSrcweir return aSupported; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //================================================================== 83*cdf0e10cSrcweir //= OCheckBoxModel 84*cdf0e10cSrcweir //================================================================== 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //================================================================== 87*cdf0e10cSrcweir InterfaceRef SAL_CALL OCheckBoxModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) throw (RuntimeException) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir return *(new OCheckBoxModel(_rxFactory)); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir //------------------------------------------------------------------ 93*cdf0e10cSrcweir DBG_NAME( OCheckBoxModel ) 94*cdf0e10cSrcweir //------------------------------------------------------------------ 95*cdf0e10cSrcweir OCheckBoxModel::OCheckBoxModel(const Reference<XMultiServiceFactory>& _rxFactory) 96*cdf0e10cSrcweir :OReferenceValueComponent( _rxFactory, VCL_CONTROLMODEL_CHECKBOX, FRM_SUN_CONTROL_CHECKBOX, sal_True ) 97*cdf0e10cSrcweir // use the old control name for compytibility reasons 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir DBG_CTOR( OCheckBoxModel, NULL ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir m_nClassId = FormComponentType::CHECKBOX; 102*cdf0e10cSrcweir initValueProperty( PROPERTY_STATE, PROPERTY_ID_STATE ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir //------------------------------------------------------------------ 106*cdf0e10cSrcweir OCheckBoxModel::OCheckBoxModel( const OCheckBoxModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory ) 107*cdf0e10cSrcweir :OReferenceValueComponent( _pOriginal, _rxFactory ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir DBG_CTOR( OCheckBoxModel, NULL ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir //------------------------------------------------------------------------------ 113*cdf0e10cSrcweir OCheckBoxModel::~OCheckBoxModel() 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir DBG_DTOR( OCheckBoxModel, NULL ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir //------------------------------------------------------------------------------ 119*cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OCheckBoxModel ) 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // XServiceInfo 122*cdf0e10cSrcweir //------------------------------------------------------------------------------ 123*cdf0e10cSrcweir StringSequence SAL_CALL OCheckBoxModel::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir StringSequence aSupported = OReferenceValueComponent::getSupportedServiceNames(); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir sal_Int32 nOldLen = aSupported.getLength(); 128*cdf0e10cSrcweir aSupported.realloc( nOldLen + 8 ); 129*cdf0e10cSrcweir ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir *pStoreTo++ = BINDABLE_CONTROL_MODEL; 132*cdf0e10cSrcweir *pStoreTo++ = DATA_AWARE_CONTROL_MODEL; 133*cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_CONTROL_MODEL; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL; 136*cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_CHECKBOX; 139*cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CHECKBOX; 140*cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATABASE_CHECK_BOX; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir return aSupported; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir //------------------------------------------------------------------------------ 146*cdf0e10cSrcweir void OCheckBoxModel::describeFixedProperties( Sequence< Property >& _rProps ) const 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 1, OReferenceValueComponent ) 149*cdf0e10cSrcweir DECL_PROP1(TABINDEX, sal_Int16, BOUND); 150*cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir //------------------------------------------------------------------------------ 154*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OCheckBoxModel::getServiceName() throw(RuntimeException) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir return FRM_COMPONENT_CHECKBOX; // old (non-sun) name for compatibility ! 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir //------------------------------------------------------------------------------ 160*cdf0e10cSrcweir void SAL_CALL OCheckBoxModel::write(const Reference<stario::XObjectOutputStream>& _rxOutStream) 161*cdf0e10cSrcweir throw(stario::IOException, RuntimeException) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir OReferenceValueComponent::write(_rxOutStream); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // Version 166*cdf0e10cSrcweir _rxOutStream->writeShort(0x0003); 167*cdf0e10cSrcweir // Properties 168*cdf0e10cSrcweir _rxOutStream << getReferenceValue(); 169*cdf0e10cSrcweir _rxOutStream << (sal_Int16)getDefaultChecked(); 170*cdf0e10cSrcweir writeHelpTextCompatibly(_rxOutStream); 171*cdf0e10cSrcweir // from version 0x0003 : common properties 172*cdf0e10cSrcweir writeCommonProperties(_rxOutStream); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir //------------------------------------------------------------------------------ 176*cdf0e10cSrcweir void SAL_CALL OCheckBoxModel::read(const Reference<stario::XObjectInputStream>& _rxInStream) throw(stario::IOException, RuntimeException) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir OReferenceValueComponent::read(_rxInStream); 179*cdf0e10cSrcweir osl::MutexGuard aGuard(m_aMutex); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // Version 182*cdf0e10cSrcweir sal_uInt16 nVersion = _rxInStream->readShort(); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir ::rtl::OUString sReferenceValue; 185*cdf0e10cSrcweir sal_Int16 nDefaultChecked( 0 ); 186*cdf0e10cSrcweir switch ( nVersion ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir case 0x0001: 189*cdf0e10cSrcweir _rxInStream >> sReferenceValue; 190*cdf0e10cSrcweir nDefaultChecked = _rxInStream->readShort(); 191*cdf0e10cSrcweir break; 192*cdf0e10cSrcweir case 0x0002: 193*cdf0e10cSrcweir _rxInStream >> sReferenceValue; 194*cdf0e10cSrcweir _rxInStream >> nDefaultChecked; 195*cdf0e10cSrcweir readHelpTextCompatibly( _rxInStream ); 196*cdf0e10cSrcweir break; 197*cdf0e10cSrcweir case 0x0003: 198*cdf0e10cSrcweir _rxInStream >> sReferenceValue; 199*cdf0e10cSrcweir _rxInStream >> nDefaultChecked; 200*cdf0e10cSrcweir readHelpTextCompatibly(_rxInStream); 201*cdf0e10cSrcweir readCommonProperties(_rxInStream); 202*cdf0e10cSrcweir break; 203*cdf0e10cSrcweir default: 204*cdf0e10cSrcweir DBG_ERROR("OCheckBoxModel::read : unknown version !"); 205*cdf0e10cSrcweir defaultCommonProperties(); 206*cdf0e10cSrcweir break; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir setReferenceValue( sReferenceValue ); 209*cdf0e10cSrcweir setDefaultChecked( static_cast< ToggleState >( nDefaultChecked ) ); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // Nach dem Lesen die Defaultwerte anzeigen 212*cdf0e10cSrcweir if ( getControlSource().getLength() ) 213*cdf0e10cSrcweir // (not if we don't have a control source - the "State" property acts like it is persistent, then 214*cdf0e10cSrcweir resetNoBroadcast(); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir //------------------------------------------------------------------------------ 218*cdf0e10cSrcweir Any OCheckBoxModel::translateDbColumnToControlValue() 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir Any aValue; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////// 223*cdf0e10cSrcweir // Wert an ControlModel setzen 224*cdf0e10cSrcweir sal_Bool bValue = m_xColumn->getBoolean(); 225*cdf0e10cSrcweir if ( m_xColumn->wasNull() ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir sal_Bool bTriState = sal_True; 228*cdf0e10cSrcweir if ( m_xAggregateSet.is() ) 229*cdf0e10cSrcweir m_xAggregateSet->getPropertyValue( PROPERTY_TRISTATE ) >>= bTriState; 230*cdf0e10cSrcweir aValue <<= (sal_Int16)( bTriState ? STATE_DONTKNOW : getDefaultChecked() ); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir else 233*cdf0e10cSrcweir aValue <<= (sal_Int16)( bValue ? STATE_CHECK : STATE_NOCHECK ); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir return aValue; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir //----------------------------------------------------------------------------- 239*cdf0e10cSrcweir sal_Bool OCheckBoxModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir OSL_PRECOND( m_xColumnUpdate.is(), "OCheckBoxModel::commitControlValueToDbColumn: not bound!" ); 242*cdf0e10cSrcweir if ( m_xColumnUpdate.is() ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) ); 245*cdf0e10cSrcweir try 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir sal_Int16 nValue = STATE_DONTKNOW; 248*cdf0e10cSrcweir aControlValue >>= nValue; 249*cdf0e10cSrcweir switch (nValue) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir case STATE_DONTKNOW: 252*cdf0e10cSrcweir m_xColumnUpdate->updateNull(); 253*cdf0e10cSrcweir break; 254*cdf0e10cSrcweir case STATE_CHECK: 255*cdf0e10cSrcweir m_xColumnUpdate->updateBoolean( sal_True ); 256*cdf0e10cSrcweir break; 257*cdf0e10cSrcweir case STATE_NOCHECK: 258*cdf0e10cSrcweir m_xColumnUpdate->updateBoolean( sal_False ); 259*cdf0e10cSrcweir break; 260*cdf0e10cSrcweir default: 261*cdf0e10cSrcweir DBG_ERROR("OCheckBoxModel::commitControlValueToDbColumn: invalid value !"); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir catch(Exception&) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir DBG_ERROR("OCheckBoxModel::commitControlValueToDbColumn: could not commit !"); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir return sal_True; 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir //......................................................................... 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir //......................................................................... 275*cdf0e10cSrcweir 276