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