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 "refvaluecomponent.hxx"
30 : :
31 : : #include <tools/diagnose_ex.h>
32 : :
33 : : #include <list>
34 : :
35 : : //........................................................................
36 : : namespace frm
37 : : {
38 : : //........................................................................
39 : :
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::lang;
42 : : using namespace ::com::sun::star::beans;
43 : : using namespace ::com::sun::star::form::binding;
44 : :
45 : : //====================================================================
46 : : //=
47 : : //====================================================================
48 : : //--------------------------------------------------------------------
49 : 61 : OReferenceValueComponent::OReferenceValueComponent( const Reference< XMultiServiceFactory>& _rxFactory, const ::rtl::OUString& _rUnoControlModelTypeName, const ::rtl::OUString& _rDefault, sal_Bool _bSupportNoCheckRefValue )
50 : : :OBoundControlModel( _rxFactory, _rUnoControlModelTypeName, _rDefault, sal_False, sal_True, sal_True )
51 : : ,m_eDefaultChecked( STATE_NOCHECK )
52 : 61 : ,m_bSupportSecondRefValue( _bSupportNoCheckRefValue )
53 : : {
54 : 61 : }
55 : :
56 : : //--------------------------------------------------------------------
57 : 4 : OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent* _pOriginal, const Reference< XMultiServiceFactory>& _rxFactory )
58 : 4 : :OBoundControlModel( _pOriginal, _rxFactory )
59 : : {
60 : 4 : m_sReferenceValue = _pOriginal->m_sReferenceValue;
61 : 4 : m_sNoCheckReferenceValue = _pOriginal->m_sNoCheckReferenceValue;
62 : 4 : m_eDefaultChecked = _pOriginal->m_eDefaultChecked;
63 : 4 : m_bSupportSecondRefValue = _pOriginal->m_bSupportSecondRefValue;
64 : :
65 [ + - ]: 4 : calculateExternalValueType();
66 : 4 : }
67 : :
68 : : //--------------------------------------------------------------------
69 : 53 : OReferenceValueComponent::~OReferenceValueComponent()
70 : : {
71 [ - + ]: 53 : }
72 : :
73 : : //--------------------------------------------------------------------
74 : 4 : void OReferenceValueComponent::setReferenceValue( const ::rtl::OUString& _rRefValue )
75 : : {
76 : 4 : m_sReferenceValue = _rRefValue;
77 : 4 : calculateExternalValueType();
78 : 4 : }
79 : :
80 : : //--------------------------------------------------------------------
81 : 15470 : void SAL_CALL OReferenceValueComponent::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
82 : : {
83 [ + + + + ]: 15470 : switch ( _nHandle )
84 : : {
85 : 336 : case PROPERTY_ID_REFVALUE: _rValue <<= m_sReferenceValue; break;
86 [ + - ]: 336 : case PROPERTY_ID_DEFAULT_STATE: _rValue <<= (sal_Int16)m_eDefaultChecked; break;
87 : :
88 : : case PROPERTY_ID_UNCHECKED_REFVALUE:
89 : : OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::getFastPropertyValue: not supported!" );
90 : 336 : _rValue <<= m_sNoCheckReferenceValue;
91 : 336 : break;
92 : :
93 : : default:
94 : 14462 : OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
95 : : }
96 : 15470 : }
97 : :
98 : : //--------------------------------------------------------------------
99 : 516 : void SAL_CALL OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw (Exception)
100 : : {
101 [ + + + + ]: 516 : switch ( _nHandle )
102 : : {
103 : : case PROPERTY_ID_REFVALUE :
104 : 56 : OSL_VERIFY( _rValue >>= m_sReferenceValue );
105 : 56 : calculateExternalValueType();
106 : 56 : break;
107 : :
108 : : case PROPERTY_ID_UNCHECKED_REFVALUE:
109 : : OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::setFastPropertyValue_NoBroadcast: not supported!" );
110 : 44 : OSL_VERIFY( _rValue >>= m_sNoCheckReferenceValue );
111 : 44 : break;
112 : :
113 : : case PROPERTY_ID_DEFAULT_STATE:
114 : : {
115 : 50 : sal_Int16 nDefaultChecked( (sal_Int16)STATE_NOCHECK );
116 : 50 : OSL_VERIFY( _rValue >>= nDefaultChecked );
117 : 50 : m_eDefaultChecked = (ToggleState)nDefaultChecked;
118 [ + - ]: 50 : resetNoBroadcast();
119 : : }
120 : 50 : break;
121 : :
122 : : default:
123 : 366 : OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
124 : : }
125 : 516 : }
126 : :
127 : : //--------------------------------------------------------------------
128 : 2082 : sal_Bool SAL_CALL OReferenceValueComponent::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw (IllegalArgumentException)
129 : : {
130 : 2082 : sal_Bool bModified = sal_False;
131 [ + + + + ]: 2082 : switch ( _nHandle )
132 : : {
133 : : case PROPERTY_ID_REFVALUE:
134 : 228 : bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sReferenceValue );
135 : 228 : break;
136 : :
137 : : case PROPERTY_ID_UNCHECKED_REFVALUE:
138 : : OSL_ENSURE( m_bSupportSecondRefValue, "OReferenceValueComponent::convertFastPropertyValue: not supported!" );
139 : 216 : bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sNoCheckReferenceValue );
140 : 216 : break;
141 : :
142 : : case PROPERTY_ID_DEFAULT_STATE:
143 [ + - ]: 231 : bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_eDefaultChecked );
144 : 231 : break;
145 : :
146 : : default:
147 : 1407 : bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
148 : 1407 : break;
149 : : }
150 : 2082 : return bModified;
151 : : }
152 : :
153 : : //------------------------------------------------------------------------------
154 : 60 : Any OReferenceValueComponent::getDefaultForReset() const
155 : : {
156 [ + - ]: 60 : return makeAny( (sal_Int16)m_eDefaultChecked );
157 : : }
158 : :
159 : : //--------------------------------------------------------------------
160 : 69 : void OReferenceValueComponent::describeFixedProperties( Sequence< Property >& _rProps ) const
161 : : {
162 [ + - ]: 69 : BEGIN_DESCRIBE_PROPERTIES( m_bSupportSecondRefValue ? 3 : 2, OBoundControlModel )
163 [ + - ]: 69 : DECL_PROP1( REFVALUE, ::rtl::OUString, BOUND );
164 [ + - ]: 69 : DECL_PROP1( DEFAULT_STATE, sal_Int16, BOUND );
165 [ + - ]: 69 : if ( m_bSupportSecondRefValue )
166 : : {
167 [ + - ]: 69 : DECL_PROP1( UNCHECKED_REFVALUE, ::rtl::OUString, BOUND );
168 : : }
169 : : END_DESCRIBE_PROPERTIES();
170 : 69 : }
171 : :
172 : : //-----------------------------------------------------------------------------
173 : 43 : Sequence< Type > OReferenceValueComponent::getSupportedBindingTypes()
174 : : {
175 [ + - ]: 43 : ::std::list< Type > aTypes;
176 [ + - ][ + - ]: 43 : aTypes.push_back( ::getCppuType( static_cast< sal_Bool* >( NULL ) ) );
177 : :
178 [ + + ]: 43 : if ( !m_sReferenceValue.isEmpty() )
179 [ + - ][ + - ]: 21 : aTypes.push_front( ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ) );
180 : : // push_front, because this is the preferred type
181 : :
182 [ + - ]: 43 : Sequence< Type > aTypesRet( aTypes.size() );
183 [ + - ][ + - ]: 43 : ::std::copy( aTypes.begin(), aTypes.end(), aTypesRet.getArray() );
184 : 43 : return aTypesRet;
185 : : }
186 : :
187 : : //-----------------------------------------------------------------------------
188 : 20 : Any OReferenceValueComponent::translateExternalValueToControlValue( const Any& _rExternalValue ) const
189 : : {
190 : 20 : sal_Int16 nState = STATE_DONTKNOW;
191 : :
192 : 20 : sal_Bool bExternalState = sal_False;
193 : 20 : ::rtl::OUString sExternalValue;
194 [ + + ]: 20 : if ( _rExternalValue >>= bExternalState )
195 : : {
196 [ + - ]: 3 : nState = ::sal::static_int_cast< sal_Int16 >( bExternalState ? STATE_CHECK : STATE_NOCHECK );
197 : : }
198 [ + - ]: 17 : else if ( _rExternalValue >>= sExternalValue )
199 : : {
200 [ - + ]: 17 : if ( sExternalValue == m_sReferenceValue )
201 : 0 : nState = STATE_CHECK;
202 : : else
203 : : {
204 [ + - ][ - + ]: 17 : if ( !m_bSupportSecondRefValue || ( sExternalValue == m_sNoCheckReferenceValue ) )
[ - + ]
205 : 0 : nState = STATE_NOCHECK;
206 : : else
207 : 17 : nState = STATE_DONTKNOW;
208 : : }
209 : : }
210 [ # # ]: 0 : else if ( !_rExternalValue.hasValue() )
211 : : {
212 : 0 : nState = STATE_DONTKNOW;
213 : : }
214 : : else
215 : : {
216 : : OSL_FAIL( "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
217 : : }
218 : :
219 [ + - ]: 20 : return makeAny( nState );
220 : : }
221 : :
222 : : //-----------------------------------------------------------------------------
223 : 0 : Any OReferenceValueComponent::translateControlValueToExternalValue( ) const
224 : : {
225 : 0 : Any aExternalValue;
226 : :
227 : : try
228 : : {
229 [ # # ][ # # ]: 0 : Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
[ # # ]
230 : 0 : sal_Int16 nControlValue = STATE_DONTKNOW;
231 : 0 : aControlValue >>= nControlValue;
232 : :
233 : 0 : bool bBooleanExchange = getExternalValueType().getTypeClass() == TypeClass_BOOLEAN;
234 : 0 : bool bStringExchange = getExternalValueType().getTypeClass() == TypeClass_STRING;
235 : : OSL_ENSURE( bBooleanExchange || bStringExchange,
236 : : "OReferenceValueComponent::translateControlValueToExternalValue: unexpected value exchange type!" );
237 : :
238 [ # # # ]: 0 : switch( nControlValue )
239 : : {
240 : : case STATE_CHECK:
241 [ # # ]: 0 : if ( bBooleanExchange )
242 : : {
243 [ # # ]: 0 : aExternalValue <<= (sal_Bool)sal_True;
244 : : }
245 [ # # ]: 0 : else if ( bStringExchange )
246 : : {
247 [ # # ]: 0 : aExternalValue <<= m_sReferenceValue;
248 : : }
249 : 0 : break;
250 : :
251 : : case STATE_NOCHECK:
252 [ # # ]: 0 : if ( bBooleanExchange )
253 : : {
254 [ # # ]: 0 : aExternalValue <<= (sal_Bool)sal_False;
255 : : }
256 [ # # ]: 0 : else if ( bStringExchange )
257 : : {
258 [ # # ][ # # ]: 0 : aExternalValue <<= (m_bSupportSecondRefValue ? m_sNoCheckReferenceValue : ::rtl::OUString());
259 : : }
260 : 0 : break;
261 [ # # ]: 0 : }
262 : : }
263 [ # # ]: 0 : catch( const Exception& )
264 : : {
265 : : OSL_FAIL( "OReferenceValueComponent::translateControlValueToExternalValue: caught an exception!" );
266 : : }
267 : :
268 : 0 : return aExternalValue;
269 : : }
270 : :
271 : : //-----------------------------------------------------------------------------
272 : 46 : Any OReferenceValueComponent::translateControlValueToValidatableValue( ) const
273 : : {
274 [ - + ]: 46 : if ( !m_xAggregateSet.is() )
275 : 0 : return Any();
276 : :
277 [ + - ][ + - ]: 46 : Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
[ + - ]
278 : 46 : sal_Int16 nControlValue = STATE_DONTKNOW;
279 : 46 : aControlValue >>= nControlValue;
280 : :
281 : 46 : Any aValidatableValue;
282 [ + + + ]: 46 : switch ( nControlValue )
283 : : {
284 : : case STATE_CHECK:
285 [ + - ]: 8 : aValidatableValue <<= (sal_Bool)sal_True;
286 : 8 : break;
287 : : case STATE_NOCHECK:
288 [ + - ]: 16 : aValidatableValue <<= (sal_Bool)sal_False;
289 : 16 : break;
290 : : }
291 : 46 : return aValidatableValue;
292 : : }
293 : :
294 : : //........................................................................
295 : : } // namespace frm
296 : : //........................................................................
297 : :
298 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|