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