1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: refvaluecomponent.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "refvaluecomponent.hxx"
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
38 #include <tools/diagnose_ex.h>
42 //........................................................................
45 //........................................................................
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::form::binding
;
52 //====================================================================
54 //====================================================================
55 //--------------------------------------------------------------------
56 OReferenceValueComponent::OReferenceValueComponent( const Reference
< XMultiServiceFactory
>& _rxFactory
, const ::rtl::OUString
& _rUnoControlModelTypeName
, const ::rtl::OUString
& _rDefault
, sal_Bool _bSupportNoCheckRefValue
)
57 :OBoundControlModel( _rxFactory
, _rUnoControlModelTypeName
, _rDefault
, sal_False
, sal_True
, sal_True
)
58 ,m_eDefaultChecked( STATE_NOCHECK
)
59 ,m_bSupportSecondRefValue( _bSupportNoCheckRefValue
)
63 //--------------------------------------------------------------------
64 OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent
* _pOriginal
, const Reference
< XMultiServiceFactory
>& _rxFactory
)
65 :OBoundControlModel( _pOriginal
, _rxFactory
)
67 m_sReferenceValue
= _pOriginal
->m_sReferenceValue
;
68 m_sNoCheckReferenceValue
= _pOriginal
->m_sNoCheckReferenceValue
;
69 m_eDefaultChecked
= _pOriginal
->m_eDefaultChecked
;
70 m_bSupportSecondRefValue
= _pOriginal
->m_bSupportSecondRefValue
;
72 calculateExternalValueType();
75 //--------------------------------------------------------------------
76 OReferenceValueComponent::~OReferenceValueComponent()
80 //--------------------------------------------------------------------
81 void OReferenceValueComponent::setReferenceValue( const ::rtl::OUString
& _rRefValue
)
83 m_sReferenceValue
= _rRefValue
;
84 calculateExternalValueType();
87 //--------------------------------------------------------------------
88 void SAL_CALL
OReferenceValueComponent::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
92 case PROPERTY_ID_REFVALUE
: _rValue
<<= m_sReferenceValue
; break;
93 case PROPERTY_ID_DEFAULT_STATE
: _rValue
<<= (sal_Int16
)m_eDefaultChecked
; break;
95 case PROPERTY_ID_UNCHECKED_REFVALUE
:
96 OSL_ENSURE( m_bSupportSecondRefValue
, "OReferenceValueComponent::getFastPropertyValue: not supported!" );
97 _rValue
<<= m_sNoCheckReferenceValue
;
101 OBoundControlModel::getFastPropertyValue( _rValue
, _nHandle
);
105 //--------------------------------------------------------------------
106 void SAL_CALL
OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw (Exception
)
110 case PROPERTY_ID_REFVALUE
:
111 OSL_VERIFY( _rValue
>>= m_sReferenceValue
);
112 calculateExternalValueType();
115 case PROPERTY_ID_UNCHECKED_REFVALUE
:
116 OSL_ENSURE( m_bSupportSecondRefValue
, "OReferenceValueComponent::setFastPropertyValue_NoBroadcast: not supported!" );
117 OSL_VERIFY( _rValue
>>= m_sNoCheckReferenceValue
);
120 case PROPERTY_ID_DEFAULT_STATE
:
122 sal_Int16
nDefaultChecked( (sal_Int16
)STATE_NOCHECK
);
123 OSL_VERIFY( _rValue
>>= nDefaultChecked
);
124 m_eDefaultChecked
= (ToggleState
)nDefaultChecked
;
130 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
134 //--------------------------------------------------------------------
135 sal_Bool SAL_CALL
OReferenceValueComponent::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
) throw (IllegalArgumentException
)
137 sal_Bool bModified
= sal_False
;
140 case PROPERTY_ID_REFVALUE
:
141 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_sReferenceValue
);
144 case PROPERTY_ID_UNCHECKED_REFVALUE
:
145 OSL_ENSURE( m_bSupportSecondRefValue
, "OReferenceValueComponent::convertFastPropertyValue: not supported!" );
146 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_sNoCheckReferenceValue
);
149 case PROPERTY_ID_DEFAULT_STATE
:
150 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, (sal_Int16
)m_eDefaultChecked
);
154 bModified
= OBoundControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
160 //------------------------------------------------------------------------------
161 Any
OReferenceValueComponent::getDefaultForReset() const
163 return makeAny( (sal_Int16
)m_eDefaultChecked
);
166 //--------------------------------------------------------------------
167 void OReferenceValueComponent::describeFixedProperties( Sequence
< Property
>& _rProps
) const
169 BEGIN_DESCRIBE_PROPERTIES( m_bSupportSecondRefValue
? 3 : 2, OBoundControlModel
)
170 DECL_PROP1( REFVALUE
, ::rtl::OUString
, BOUND
);
171 DECL_PROP1( DEFAULT_STATE
, sal_Int16
, BOUND
);
172 if ( m_bSupportSecondRefValue
)
174 DECL_PROP1( UNCHECKED_REFVALUE
, ::rtl::OUString
, BOUND
);
176 END_DESCRIBE_PROPERTIES();
179 //-----------------------------------------------------------------------------
180 Sequence
< Type
> OReferenceValueComponent::getSupportedBindingTypes()
182 ::std::list
< Type
> aTypes
;
183 aTypes
.push_back( ::getCppuType( static_cast< sal_Bool
* >( NULL
) ) );
185 if ( m_sReferenceValue
.getLength() )
186 aTypes
.push_front( ::getCppuType( static_cast< ::rtl::OUString
* >( NULL
) ) );
187 // push_front, because this is the preferred type
189 Sequence
< Type
> aTypesRet( aTypes
.size() );
190 ::std::copy( aTypes
.begin(), aTypes
.end(), aTypesRet
.getArray() );
194 //-----------------------------------------------------------------------------
195 Any
OReferenceValueComponent::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
197 sal_Int16 nState
= STATE_DONTKNOW
;
199 sal_Bool bExternalState
= sal_False
;
200 ::rtl::OUString sExternalValue
;
201 if ( _rExternalValue
>>= bExternalState
)
203 nState
= ::sal::static_int_cast
< sal_Int16
>( bExternalState
? STATE_CHECK
: STATE_NOCHECK
);
205 else if ( _rExternalValue
>>= sExternalValue
)
207 if ( sExternalValue
== m_sReferenceValue
)
208 nState
= STATE_CHECK
;
211 if ( !m_bSupportSecondRefValue
|| ( sExternalValue
== m_sNoCheckReferenceValue
) )
212 nState
= STATE_NOCHECK
;
214 nState
= STATE_DONTKNOW
;
217 else if ( !_rExternalValue
.hasValue() )
219 nState
= STATE_DONTKNOW
;
223 OSL_ENSURE( false, "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
226 return makeAny( nState
);
229 //-----------------------------------------------------------------------------
230 Any
OReferenceValueComponent::translateControlValueToExternalValue( ) const
236 Any
aControlValue( m_xAggregateSet
->getPropertyValue( PROPERTY_STATE
) );
237 sal_Int16 nControlValue
= STATE_DONTKNOW
;
238 aControlValue
>>= nControlValue
;
240 bool bBooleanExchange
= getExternalValueType().getTypeClass() == TypeClass_BOOLEAN
;
241 bool bStringExchange
= getExternalValueType().getTypeClass() == TypeClass_STRING
;
242 OSL_ENSURE( bBooleanExchange
|| bStringExchange
,
243 "OReferenceValueComponent::translateControlValueToExternalValue: unexpected value exchange type!" );
245 switch( nControlValue
)
248 if ( bBooleanExchange
)
250 aExternalValue
<<= (sal_Bool
)sal_True
;
252 else if ( bStringExchange
)
254 aExternalValue
<<= m_sReferenceValue
;
259 if ( bBooleanExchange
)
261 aExternalValue
<<= (sal_Bool
)sal_False
;
263 else if ( bStringExchange
)
265 aExternalValue
<<= m_bSupportSecondRefValue
? m_sNoCheckReferenceValue
: ::rtl::OUString();
270 catch( const Exception
& )
272 OSL_ENSURE( sal_False
, "OReferenceValueComponent::translateControlValueToExternalValue: caught an exception!" );
275 return aExternalValue
;
278 //-----------------------------------------------------------------------------
279 Any
OReferenceValueComponent::translateControlValueToValidatableValue( ) const
281 if ( !m_xAggregateSet
.is() )
284 Any
aControlValue( m_xAggregateSet
->getPropertyValue( PROPERTY_STATE
) );
285 sal_Int16 nControlValue
= STATE_DONTKNOW
;
286 aControlValue
>>= nControlValue
;
288 Any aValidatableValue
;
289 switch ( nControlValue
)
292 aValidatableValue
<<= (sal_Bool
)sal_True
;
295 aValidatableValue
<<= (sal_Bool
)sal_False
;
298 return aValidatableValue
;
301 //........................................................................
303 //........................................................................