nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / component / refvaluecomponent.cxx
blob559d3bd86543af2a5d5eb06836d793d7f8443410
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "refvaluecomponent.hxx"
21 #include <property.hxx>
23 #include <comphelper/property.hxx>
24 #include <tools/diagnose_ex.h>
26 #include <vector>
29 namespace frm
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::form::binding;
39 //=
42 OReferenceValueComponent::OReferenceValueComponent( const Reference< XComponentContext >& _rxFactory, const OUString& _rUnoControlModelTypeName, const OUString& _rDefault )
43 :OBoundControlModel( _rxFactory, _rUnoControlModelTypeName, _rDefault, false, true, true )
44 ,m_eDefaultChecked( TRISTATE_FALSE )
49 OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent* _pOriginal, const Reference< XComponentContext>& _rxFactory )
50 :OBoundControlModel( _pOriginal, _rxFactory )
52 m_sReferenceValue = _pOriginal->m_sReferenceValue;
53 m_sNoCheckReferenceValue = _pOriginal->m_sNoCheckReferenceValue;
54 m_eDefaultChecked = _pOriginal->m_eDefaultChecked;
56 calculateExternalValueType();
60 OReferenceValueComponent::~OReferenceValueComponent()
65 void OReferenceValueComponent::setReferenceValue( const OUString& _rRefValue )
67 m_sReferenceValue = _rRefValue;
68 calculateExternalValueType();
72 void SAL_CALL OReferenceValueComponent::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
74 switch ( _nHandle )
76 case PROPERTY_ID_REFVALUE: _rValue <<= m_sReferenceValue; break;
77 case PROPERTY_ID_DEFAULT_STATE: _rValue <<= static_cast<sal_Int16>(m_eDefaultChecked); break;
79 case PROPERTY_ID_UNCHECKED_REFVALUE:
80 _rValue <<= m_sNoCheckReferenceValue;
81 break;
83 default:
84 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
89 void SAL_CALL OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
91 switch ( _nHandle )
93 case PROPERTY_ID_REFVALUE :
94 OSL_VERIFY( _rValue >>= m_sReferenceValue );
95 calculateExternalValueType();
96 break;
98 case PROPERTY_ID_UNCHECKED_REFVALUE:
99 OSL_VERIFY( _rValue >>= m_sNoCheckReferenceValue );
100 break;
102 case PROPERTY_ID_DEFAULT_STATE:
104 sal_Int16 nDefaultChecked;
105 if (!(_rValue >>= nDefaultChecked) || nDefaultChecked < 0
106 || nDefaultChecked > 2)
108 throw css::lang::IllegalArgumentException(
109 ("DefaultState property value must be a SHORT in the range"
110 " 0--2"),
111 css::uno::Reference<css::uno::XInterface>(), -1);
113 m_eDefaultChecked = static_cast<ToggleState>(nDefaultChecked);
114 resetNoBroadcast();
116 break;
118 default:
119 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
124 sal_Bool SAL_CALL OReferenceValueComponent::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
126 bool bModified = false;
127 switch ( _nHandle )
129 case PROPERTY_ID_REFVALUE:
130 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sReferenceValue );
131 break;
133 case PROPERTY_ID_UNCHECKED_REFVALUE:
134 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sNoCheckReferenceValue );
135 break;
137 case PROPERTY_ID_DEFAULT_STATE:
138 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, static_cast<sal_Int16>(m_eDefaultChecked) );
139 break;
141 default:
142 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
143 break;
145 return bModified;
149 Any OReferenceValueComponent::getDefaultForReset() const
151 return makeAny( static_cast<sal_Int16>(m_eDefaultChecked) );
155 void OReferenceValueComponent::describeFixedProperties( Sequence< Property >& _rProps ) const
157 BEGIN_DESCRIBE_PROPERTIES( 3, OBoundControlModel )
158 DECL_PROP1( REFVALUE, OUString, BOUND );
159 DECL_PROP1( DEFAULT_STATE, sal_Int16, BOUND );
160 DECL_PROP1( UNCHECKED_REFVALUE, OUString, BOUND );
161 END_DESCRIBE_PROPERTIES();
165 Sequence< Type > OReferenceValueComponent::getSupportedBindingTypes()
167 ::std::vector< Type > aTypes;
169 if ( !m_sReferenceValue.isEmpty() )
170 aTypes.push_back( cppu::UnoType<OUString>::get() );
172 aTypes.push_back( cppu::UnoType<sal_Bool>::get() );
174 return comphelper::containerToSequence(aTypes);
178 Any OReferenceValueComponent::translateExternalValueToControlValue( const Any& _rExternalValue ) const
180 sal_Int16 nState = TRISTATE_INDET;
182 bool bExternalState = false;
183 OUString sExternalValue;
184 if ( _rExternalValue >>= bExternalState )
186 nState = ::sal::static_int_cast< sal_Int16 >( bExternalState ? TRISTATE_TRUE : TRISTATE_FALSE );
188 else if ( _rExternalValue >>= sExternalValue )
190 if ( sExternalValue == m_sReferenceValue )
191 nState = TRISTATE_TRUE;
192 else
194 if ( sExternalValue == m_sNoCheckReferenceValue )
195 nState = TRISTATE_FALSE;
196 else
197 nState = TRISTATE_INDET;
200 else if ( !_rExternalValue.hasValue() )
202 nState = TRISTATE_INDET;
204 else
206 OSL_FAIL( "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
209 return makeAny( nState );
213 Any OReferenceValueComponent::translateControlValueToExternalValue( ) const
215 Any aExternalValue;
219 Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
220 sal_Int16 nControlValue = TRISTATE_INDET;
221 aControlValue >>= nControlValue;
223 bool bBooleanExchange = getExternalValueType().getTypeClass() == TypeClass_BOOLEAN;
224 bool bStringExchange = getExternalValueType().getTypeClass() == TypeClass_STRING;
225 OSL_ENSURE( bBooleanExchange || bStringExchange,
226 "OReferenceValueComponent::translateControlValueToExternalValue: unexpected value exchange type!" );
228 switch( nControlValue )
230 case TRISTATE_TRUE:
231 if ( bBooleanExchange )
233 aExternalValue <<= true;
235 else if ( bStringExchange )
237 aExternalValue <<= m_sReferenceValue;
239 break;
241 case TRISTATE_FALSE:
242 if ( bBooleanExchange )
244 aExternalValue <<= false;
246 else if ( bStringExchange )
248 aExternalValue <<= m_sNoCheckReferenceValue;
250 break;
253 catch( const Exception& )
255 TOOLS_WARN_EXCEPTION( "forms.component", "OReferenceValueComponent::translateControlValueToExternalValue" );
258 return aExternalValue;
262 Any OReferenceValueComponent::translateControlValueToValidatableValue( ) const
264 if ( !m_xAggregateSet.is() )
265 return Any();
267 Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
268 sal_Int16 nControlValue = TRISTATE_INDET;
269 aControlValue >>= nControlValue;
271 Any aValidatableValue;
272 switch ( nControlValue )
274 case TRISTATE_TRUE:
275 aValidatableValue <<= true;
276 break;
277 case TRISTATE_FALSE:
278 aValidatableValue <<= false;
279 break;
281 return aValidatableValue;
285 } // namespace frm
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */