bump product version to 7.6.3.2-android
[LibreOffice.git] / forms / source / component / refvaluecomponent.cxx
blobb0ff7e3803bed25610c035c8fba452e3572ab4b0
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/debug.hxx>
25 #include <comphelper/diagnose_ex.hxx>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <vector>
32 namespace frm
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::form::binding;
42 //=
45 OReferenceValueComponent::OReferenceValueComponent( const Reference< XComponentContext >& _rxFactory, const OUString& _rUnoControlModelTypeName, const OUString& _rDefault )
46 :OBoundControlModel( _rxFactory, _rUnoControlModelTypeName, _rDefault, false, true, true )
47 ,m_eDefaultChecked( TRISTATE_FALSE )
52 OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent* _pOriginal, const Reference< XComponentContext>& _rxFactory )
53 :OBoundControlModel( _pOriginal, _rxFactory )
55 m_sReferenceValue = _pOriginal->m_sReferenceValue;
56 m_sNoCheckReferenceValue = _pOriginal->m_sNoCheckReferenceValue;
57 m_eDefaultChecked = _pOriginal->m_eDefaultChecked;
59 calculateExternalValueType();
63 OReferenceValueComponent::~OReferenceValueComponent()
68 void OReferenceValueComponent::setReferenceValue( const OUString& _rRefValue )
70 m_sReferenceValue = _rRefValue;
71 calculateExternalValueType();
75 void SAL_CALL OReferenceValueComponent::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
77 switch ( _nHandle )
79 case PROPERTY_ID_REFVALUE: _rValue <<= m_sReferenceValue; break;
80 case PROPERTY_ID_DEFAULT_STATE: _rValue <<= static_cast<sal_Int16>(m_eDefaultChecked); break;
82 case PROPERTY_ID_UNCHECKED_REFVALUE:
83 _rValue <<= m_sNoCheckReferenceValue;
84 break;
86 default:
87 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
92 void SAL_CALL OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
94 switch ( _nHandle )
96 case PROPERTY_ID_REFVALUE :
97 OSL_VERIFY( _rValue >>= m_sReferenceValue );
98 calculateExternalValueType();
99 break;
101 case PROPERTY_ID_UNCHECKED_REFVALUE:
102 OSL_VERIFY( _rValue >>= m_sNoCheckReferenceValue );
103 break;
105 case PROPERTY_ID_DEFAULT_STATE:
107 sal_Int16 nDefaultChecked;
108 if (!(_rValue >>= nDefaultChecked) || nDefaultChecked < 0
109 || nDefaultChecked > 2)
111 throw css::lang::IllegalArgumentException(
112 ("DefaultState property value must be a SHORT in the range"
113 " 0--2"),
114 css::uno::Reference<css::uno::XInterface>(), -1);
116 m_eDefaultChecked = static_cast<ToggleState>(nDefaultChecked);
117 resetNoBroadcast();
119 break;
121 default:
122 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
127 sal_Bool SAL_CALL OReferenceValueComponent::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
129 bool bModified = false;
130 switch ( _nHandle )
132 case PROPERTY_ID_REFVALUE:
133 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sReferenceValue );
134 break;
136 case PROPERTY_ID_UNCHECKED_REFVALUE:
137 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sNoCheckReferenceValue );
138 break;
140 case PROPERTY_ID_DEFAULT_STATE:
141 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, static_cast<sal_Int16>(m_eDefaultChecked) );
142 break;
144 default:
145 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
146 break;
148 return bModified;
152 Any OReferenceValueComponent::getDefaultForReset() const
154 return Any( static_cast<sal_Int16>(m_eDefaultChecked) );
158 void OReferenceValueComponent::describeFixedProperties( Sequence< Property >& _rProps ) const
160 OBoundControlModel::describeFixedProperties( _rProps );
161 sal_Int32 nOldCount = _rProps.getLength();
162 _rProps.realloc( nOldCount + 3);
163 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
164 *pProperties++ = css::beans::Property(PROPERTY_REFVALUE, PROPERTY_ID_REFVALUE, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND);
165 *pProperties++ = css::beans::Property(PROPERTY_DEFAULT_STATE, PROPERTY_ID_DEFAULT_STATE, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
166 *pProperties++ = css::beans::Property(PROPERTY_UNCHECKED_REFVALUE, PROPERTY_ID_UNCHECKED_REFVALUE, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND);
167 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
171 Sequence< Type > OReferenceValueComponent::getSupportedBindingTypes()
173 ::std::vector< Type > aTypes;
175 if ( !m_sReferenceValue.isEmpty() )
176 aTypes.push_back( cppu::UnoType<OUString>::get() );
178 aTypes.push_back( cppu::UnoType<sal_Bool>::get() );
180 return comphelper::containerToSequence(aTypes);
184 Any OReferenceValueComponent::translateExternalValueToControlValue( const Any& _rExternalValue ) const
186 sal_Int16 nState = TRISTATE_INDET;
188 bool bExternalState = false;
189 OUString sExternalValue;
190 if ( _rExternalValue >>= bExternalState )
192 nState = ::sal::static_int_cast< sal_Int16 >( bExternalState ? TRISTATE_TRUE : TRISTATE_FALSE );
194 else if ( _rExternalValue >>= sExternalValue )
196 if ( sExternalValue == m_sReferenceValue )
197 nState = TRISTATE_TRUE;
198 else
200 if ( sExternalValue == m_sNoCheckReferenceValue )
201 nState = TRISTATE_FALSE;
202 else
203 nState = TRISTATE_INDET;
206 else if ( !_rExternalValue.hasValue() )
208 nState = TRISTATE_INDET;
210 else
212 OSL_FAIL( "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
215 return Any( nState );
219 Any OReferenceValueComponent::translateControlValueToExternalValue( ) const
221 Any aExternalValue;
225 Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
226 sal_Int16 nControlValue = TRISTATE_INDET;
227 aControlValue >>= nControlValue;
229 bool bBooleanExchange = getExternalValueType().getTypeClass() == TypeClass_BOOLEAN;
230 bool bStringExchange = getExternalValueType().getTypeClass() == TypeClass_STRING;
231 OSL_ENSURE( bBooleanExchange || bStringExchange,
232 "OReferenceValueComponent::translateControlValueToExternalValue: unexpected value exchange type!" );
234 switch( nControlValue )
236 case TRISTATE_TRUE:
237 if ( bBooleanExchange )
239 aExternalValue <<= true;
241 else if ( bStringExchange )
243 aExternalValue <<= m_sReferenceValue;
245 break;
247 case TRISTATE_FALSE:
248 if ( bBooleanExchange )
250 aExternalValue <<= false;
252 else if ( bStringExchange )
254 aExternalValue <<= m_sNoCheckReferenceValue;
256 break;
259 catch( const Exception& )
261 TOOLS_WARN_EXCEPTION( "forms.component", "OReferenceValueComponent::translateControlValueToExternalValue" );
264 return aExternalValue;
268 Any OReferenceValueComponent::translateControlValueToValidatableValue( ) const
270 if ( !m_xAggregateSet.is() )
271 return Any();
273 Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
274 sal_Int16 nControlValue = TRISTATE_INDET;
275 aControlValue >>= nControlValue;
277 Any aValidatableValue;
278 switch ( nControlValue )
280 case TRISTATE_TRUE:
281 aValidatableValue <<= true;
282 break;
283 case TRISTATE_FALSE:
284 aValidatableValue <<= false;
285 break;
287 return aValidatableValue;
291 } // namespace frm
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */