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