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 "CheckBox.hxx"
21 #include "property.hxx"
22 #include "property.hrc"
23 #include "services.hxx"
24 #include <tools/debug.hxx>
25 #include <comphelper/basicio.hxx>
27 //.........................................................................
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::sdb
;
32 using namespace ::com::sun::star::sdbc
;
33 using namespace ::com::sun::star::sdbcx
;
34 using namespace ::com::sun::star::beans
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::com::sun::star::form
;
37 using namespace ::com::sun::star::awt
;
38 using namespace ::com::sun::star::io
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::util
;
41 using namespace ::com::sun::star::form::binding
;
43 //==================================================================
45 //==================================================================
47 //------------------------------------------------------------------
48 OCheckBoxControl::OCheckBoxControl(const Reference
<XMultiServiceFactory
>& _rxFactory
)
49 :OBoundControl(_rxFactory
, VCL_CONTROL_CHECKBOX
)
53 //------------------------------------------------------------------
54 InterfaceRef SAL_CALL
OCheckBoxControl_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
) throw (RuntimeException
)
56 return *(new OCheckBoxControl(_rxFactory
));
59 //------------------------------------------------------------------------------
60 StringSequence SAL_CALL
OCheckBoxControl::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
)
62 StringSequence aSupported
= OBoundControl::getSupportedServiceNames();
63 aSupported
.realloc(aSupported
.getLength() + 1);
65 OUString
* pArray
= aSupported
.getArray();
66 pArray
[aSupported
.getLength()-1] = FRM_SUN_CONTROL_CHECKBOX
;
70 //==================================================================
72 //==================================================================
74 //==================================================================
75 InterfaceRef SAL_CALL
OCheckBoxModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
) throw (RuntimeException
)
77 return *(new OCheckBoxModel(_rxFactory
));
80 //------------------------------------------------------------------
81 DBG_NAME( OCheckBoxModel
)
82 //------------------------------------------------------------------
83 OCheckBoxModel::OCheckBoxModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
84 :OReferenceValueComponent( _rxFactory
, VCL_CONTROLMODEL_CHECKBOX
, FRM_SUN_CONTROL_CHECKBOX
, sal_True
)
85 // use the old control name for compytibility reasons
87 DBG_CTOR( OCheckBoxModel
, NULL
);
89 m_nClassId
= FormComponentType::CHECKBOX
;
90 initValueProperty( PROPERTY_STATE
, PROPERTY_ID_STATE
);
93 //------------------------------------------------------------------
94 OCheckBoxModel::OCheckBoxModel( const OCheckBoxModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
95 :OReferenceValueComponent( _pOriginal
, _rxFactory
)
97 DBG_CTOR( OCheckBoxModel
, NULL
);
100 //------------------------------------------------------------------------------
101 OCheckBoxModel::~OCheckBoxModel()
103 DBG_DTOR( OCheckBoxModel
, NULL
);
106 //------------------------------------------------------------------------------
107 IMPLEMENT_DEFAULT_CLONING( OCheckBoxModel
)
110 //------------------------------------------------------------------------------
111 StringSequence SAL_CALL
OCheckBoxModel::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
)
113 StringSequence aSupported
= OReferenceValueComponent::getSupportedServiceNames();
115 sal_Int32 nOldLen
= aSupported
.getLength();
116 aSupported
.realloc( nOldLen
+ 8 );
117 OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
119 *pStoreTo
++ = BINDABLE_CONTROL_MODEL
;
120 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
121 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
123 *pStoreTo
++ = BINDABLE_DATA_AWARE_CONTROL_MODEL
;
124 *pStoreTo
++ = VALIDATABLE_BINDABLE_CONTROL_MODEL
;
126 *pStoreTo
++ = FRM_SUN_COMPONENT_CHECKBOX
;
127 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_CHECKBOX
;
128 *pStoreTo
++ = BINDABLE_DATABASE_CHECK_BOX
;
133 //------------------------------------------------------------------------------
134 void OCheckBoxModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
136 BEGIN_DESCRIBE_PROPERTIES( 1, OReferenceValueComponent
)
137 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
138 END_DESCRIBE_PROPERTIES();
141 //------------------------------------------------------------------------------
142 OUString SAL_CALL
OCheckBoxModel::getServiceName() throw(RuntimeException
)
144 return OUString(FRM_COMPONENT_CHECKBOX
); // old (non-sun) name for compatibility !
147 //------------------------------------------------------------------------------
148 void SAL_CALL
OCheckBoxModel::write(const Reference
<stario::XObjectOutputStream
>& _rxOutStream
)
149 throw(stario::IOException
, RuntimeException
)
151 OReferenceValueComponent::write(_rxOutStream
);
154 _rxOutStream
->writeShort(0x0003);
156 _rxOutStream
<< getReferenceValue();
157 _rxOutStream
<< (sal_Int16
)getDefaultChecked();
158 writeHelpTextCompatibly(_rxOutStream
);
159 // from version 0x0003 : common properties
160 writeCommonProperties(_rxOutStream
);
163 //------------------------------------------------------------------------------
164 void SAL_CALL
OCheckBoxModel::read(const Reference
<stario::XObjectInputStream
>& _rxInStream
) throw(stario::IOException
, RuntimeException
)
166 OReferenceValueComponent::read(_rxInStream
);
167 osl::MutexGuard
aGuard(m_aMutex
);
170 sal_uInt16 nVersion
= _rxInStream
->readShort();
172 OUString sReferenceValue
;
173 sal_Int16
nDefaultChecked( 0 );
177 _rxInStream
>> sReferenceValue
;
178 nDefaultChecked
= _rxInStream
->readShort();
181 _rxInStream
>> sReferenceValue
;
182 _rxInStream
>> nDefaultChecked
;
183 readHelpTextCompatibly( _rxInStream
);
186 _rxInStream
>> sReferenceValue
;
187 _rxInStream
>> nDefaultChecked
;
188 readHelpTextCompatibly(_rxInStream
);
189 readCommonProperties(_rxInStream
);
192 OSL_FAIL("OCheckBoxModel::read : unknown version !");
193 defaultCommonProperties();
196 setReferenceValue( sReferenceValue
);
197 setDefaultChecked( static_cast< ToggleState
>( nDefaultChecked
) );
199 // After reading in, display the default values
200 if ( !getControlSource().isEmpty() )
201 // (not if we don't have a control source - the "State" property acts like it is persistent, then
205 //------------------------------------------------------------------------------
206 Any
OCheckBoxModel::translateDbColumnToControlValue()
210 //////////////////////////////////////////////////////////////////
211 // Set value in ControlModel
212 sal_Bool bValue
= m_xColumn
->getBoolean();
213 if ( m_xColumn
->wasNull() )
215 sal_Bool bTriState
= sal_True
;
216 if ( m_xAggregateSet
.is() )
217 m_xAggregateSet
->getPropertyValue( PROPERTY_TRISTATE
) >>= bTriState
;
218 aValue
<<= (sal_Int16
)( bTriState
? STATE_DONTKNOW
: getDefaultChecked() );
221 aValue
<<= (sal_Int16
)( bValue
? STATE_CHECK
: STATE_NOCHECK
);
226 //-----------------------------------------------------------------------------
227 sal_Bool
OCheckBoxModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
229 OSL_PRECOND( m_xColumnUpdate
.is(), "OCheckBoxModel::commitControlValueToDbColumn: not bound!" );
230 if ( m_xColumnUpdate
.is() )
232 Any
aControlValue( m_xAggregateSet
->getPropertyValue( PROPERTY_STATE
) );
235 sal_Int16 nValue
= STATE_DONTKNOW
;
236 aControlValue
>>= nValue
;
240 m_xColumnUpdate
->updateNull();
243 m_xColumnUpdate
->updateBoolean( sal_True
);
246 m_xColumnUpdate
->updateBoolean( sal_False
);
249 OSL_FAIL("OCheckBoxModel::commitControlValueToDbColumn: invalid value !");
252 catch(const Exception
&)
254 OSL_FAIL("OCheckBoxModel::commitControlValueToDbColumn: could not commit !");
260 //.........................................................................
262 //.........................................................................
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */