1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
22 #include <tools/diagnose_ex.h>
26 //........................................................................
29 //........................................................................
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::form::binding
;
36 //====================================================================
38 //====================================================================
39 //--------------------------------------------------------------------
40 OReferenceValueComponent::OReferenceValueComponent( const Reference
< XMultiServiceFactory
>& _rxFactory
, const OUString
& _rUnoControlModelTypeName
, const OUString
& _rDefault
, sal_Bool _bSupportNoCheckRefValue
)
41 :OBoundControlModel( _rxFactory
, _rUnoControlModelTypeName
, _rDefault
, sal_False
, sal_True
, sal_True
)
42 ,m_eDefaultChecked( STATE_NOCHECK
)
43 ,m_bSupportSecondRefValue( _bSupportNoCheckRefValue
)
47 //--------------------------------------------------------------------
48 OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent
* _pOriginal
, const Reference
< XMultiServiceFactory
>& _rxFactory
)
49 :OBoundControlModel( _pOriginal
, _rxFactory
)
51 m_sReferenceValue
= _pOriginal
->m_sReferenceValue
;
52 m_sNoCheckReferenceValue
= _pOriginal
->m_sNoCheckReferenceValue
;
53 m_eDefaultChecked
= _pOriginal
->m_eDefaultChecked
;
54 m_bSupportSecondRefValue
= _pOriginal
->m_bSupportSecondRefValue
;
56 calculateExternalValueType();
59 //--------------------------------------------------------------------
60 OReferenceValueComponent::~OReferenceValueComponent()
64 //--------------------------------------------------------------------
65 void OReferenceValueComponent::setReferenceValue( const OUString
& _rRefValue
)
67 m_sReferenceValue
= _rRefValue
;
68 calculateExternalValueType();
71 //--------------------------------------------------------------------
72 void SAL_CALL
OReferenceValueComponent::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
76 case PROPERTY_ID_REFVALUE
: _rValue
<<= m_sReferenceValue
; break;
77 case PROPERTY_ID_DEFAULT_STATE
: _rValue
<<= (sal_Int16
)m_eDefaultChecked
; break;
79 case PROPERTY_ID_UNCHECKED_REFVALUE
:
80 OSL_ENSURE( m_bSupportSecondRefValue
, "OReferenceValueComponent::getFastPropertyValue: not supported!" );
81 _rValue
<<= m_sNoCheckReferenceValue
;
85 OBoundControlModel::getFastPropertyValue( _rValue
, _nHandle
);
89 //--------------------------------------------------------------------
90 void SAL_CALL
OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw (Exception
)
94 case PROPERTY_ID_REFVALUE
:
95 OSL_VERIFY( _rValue
>>= m_sReferenceValue
);
96 calculateExternalValueType();
99 case PROPERTY_ID_UNCHECKED_REFVALUE
:
100 OSL_ENSURE( m_bSupportSecondRefValue
, "OReferenceValueComponent::setFastPropertyValue_NoBroadcast: not supported!" );
101 OSL_VERIFY( _rValue
>>= m_sNoCheckReferenceValue
);
104 case PROPERTY_ID_DEFAULT_STATE
:
106 sal_Int16
nDefaultChecked( (sal_Int16
)STATE_NOCHECK
);
107 OSL_VERIFY( _rValue
>>= nDefaultChecked
);
108 m_eDefaultChecked
= (ToggleState
)nDefaultChecked
;
114 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
118 //--------------------------------------------------------------------
119 sal_Bool SAL_CALL
OReferenceValueComponent::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
) throw (IllegalArgumentException
)
121 sal_Bool bModified
= sal_False
;
124 case PROPERTY_ID_REFVALUE
:
125 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_sReferenceValue
);
128 case PROPERTY_ID_UNCHECKED_REFVALUE
:
129 OSL_ENSURE( m_bSupportSecondRefValue
, "OReferenceValueComponent::convertFastPropertyValue: not supported!" );
130 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_sNoCheckReferenceValue
);
133 case PROPERTY_ID_DEFAULT_STATE
:
134 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_eDefaultChecked
);
138 bModified
= OBoundControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
144 //------------------------------------------------------------------------------
145 Any
OReferenceValueComponent::getDefaultForReset() const
147 return makeAny( (sal_Int16
)m_eDefaultChecked
);
150 //--------------------------------------------------------------------
151 void OReferenceValueComponent::describeFixedProperties( Sequence
< Property
>& _rProps
) const
153 BEGIN_DESCRIBE_PROPERTIES( m_bSupportSecondRefValue
? 3 : 2, OBoundControlModel
)
154 DECL_PROP1( REFVALUE
, OUString
, BOUND
);
155 DECL_PROP1( DEFAULT_STATE
, sal_Int16
, BOUND
);
156 if ( m_bSupportSecondRefValue
)
158 DECL_PROP1( UNCHECKED_REFVALUE
, OUString
, BOUND
);
160 END_DESCRIBE_PROPERTIES();
163 //-----------------------------------------------------------------------------
164 Sequence
< Type
> OReferenceValueComponent::getSupportedBindingTypes()
166 ::std::list
< Type
> aTypes
;
167 aTypes
.push_back( ::getCppuType( static_cast< sal_Bool
* >( NULL
) ) );
169 if ( !m_sReferenceValue
.isEmpty() )
170 aTypes
.push_front( ::getCppuType( static_cast< OUString
* >( NULL
) ) );
171 // push_front, because this is the preferred type
173 Sequence
< Type
> aTypesRet( aTypes
.size() );
174 ::std::copy( aTypes
.begin(), aTypes
.end(), aTypesRet
.getArray() );
178 //-----------------------------------------------------------------------------
179 Any
OReferenceValueComponent::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
181 sal_Int16 nState
= STATE_DONTKNOW
;
183 sal_Bool bExternalState
= sal_False
;
184 OUString sExternalValue
;
185 if ( _rExternalValue
>>= bExternalState
)
187 nState
= ::sal::static_int_cast
< sal_Int16
>( bExternalState
? STATE_CHECK
: STATE_NOCHECK
);
189 else if ( _rExternalValue
>>= sExternalValue
)
191 if ( sExternalValue
== m_sReferenceValue
)
192 nState
= STATE_CHECK
;
195 if ( !m_bSupportSecondRefValue
|| ( sExternalValue
== m_sNoCheckReferenceValue
) )
196 nState
= STATE_NOCHECK
;
198 nState
= STATE_DONTKNOW
;
201 else if ( !_rExternalValue
.hasValue() )
203 nState
= STATE_DONTKNOW
;
207 OSL_FAIL( "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
210 return makeAny( nState
);
213 //-----------------------------------------------------------------------------
214 Any
OReferenceValueComponent::translateControlValueToExternalValue( ) const
220 Any
aControlValue( m_xAggregateSet
->getPropertyValue( PROPERTY_STATE
) );
221 sal_Int16 nControlValue
= STATE_DONTKNOW
;
222 aControlValue
>>= nControlValue
;
224 bool bBooleanExchange
= getExternalValueType().getTypeClass() == TypeClass_BOOLEAN
;
225 bool bStringExchange
= getExternalValueType().getTypeClass() == TypeClass_STRING
;
226 OSL_ENSURE( bBooleanExchange
|| bStringExchange
,
227 "OReferenceValueComponent::translateControlValueToExternalValue: unexpected value exchange type!" );
229 switch( nControlValue
)
232 if ( bBooleanExchange
)
234 aExternalValue
<<= (sal_Bool
)sal_True
;
236 else if ( bStringExchange
)
238 aExternalValue
<<= m_sReferenceValue
;
243 if ( bBooleanExchange
)
245 aExternalValue
<<= (sal_Bool
)sal_False
;
247 else if ( bStringExchange
)
249 aExternalValue
<<= (m_bSupportSecondRefValue
? m_sNoCheckReferenceValue
: OUString());
254 catch( const Exception
& )
256 OSL_FAIL( "OReferenceValueComponent::translateControlValueToExternalValue: caught an exception!" );
259 return aExternalValue
;
262 //-----------------------------------------------------------------------------
263 Any
OReferenceValueComponent::translateControlValueToValidatableValue( ) const
265 if ( !m_xAggregateSet
.is() )
268 Any
aControlValue( m_xAggregateSet
->getPropertyValue( PROPERTY_STATE
) );
269 sal_Int16 nControlValue
= STATE_DONTKNOW
;
270 aControlValue
>>= nControlValue
;
272 Any aValidatableValue
;
273 switch ( nControlValue
)
276 aValidatableValue
<<= (sal_Bool
)sal_True
;
279 aValidatableValue
<<= (sal_Bool
)sal_False
;
282 return aValidatableValue
;
285 //........................................................................
287 //........................................................................
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */