LibreOffice Module forms (master) 1
refvaluecomponent.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "refvaluecomponent.hxx"
21#include <property.hxx>
22
24#include <tools/debug.hxx>
26
27#include <com/sun/star/beans/PropertyAttribute.hpp>
28
29#include <vector>
30
31
32namespace frm
33{
34
35
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;
40
41
42 //=
43
44
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 )
48 {
49 }
50
51
52 OReferenceValueComponent::OReferenceValueComponent( const OReferenceValueComponent* _pOriginal, const Reference< XComponentContext>& _rxFactory )
53 :OBoundControlModel( _pOriginal, _rxFactory )
54 {
55 m_sReferenceValue = _pOriginal->m_sReferenceValue;
56 m_sNoCheckReferenceValue = _pOriginal->m_sNoCheckReferenceValue;
57 m_eDefaultChecked = _pOriginal->m_eDefaultChecked;
58
59 calculateExternalValueType();
60 }
61
62
63 OReferenceValueComponent::~OReferenceValueComponent()
64 {
65 }
66
67
68 void OReferenceValueComponent::setReferenceValue( const OUString& _rRefValue )
69 {
70 m_sReferenceValue = _rRefValue;
71 calculateExternalValueType();
72 }
73
74
75 void SAL_CALL OReferenceValueComponent::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
76 {
77 switch ( _nHandle )
78 {
79 case PROPERTY_ID_REFVALUE: _rValue <<= m_sReferenceValue; break;
80 case PROPERTY_ID_DEFAULT_STATE: _rValue <<= static_cast<sal_Int16>(m_eDefaultChecked); break;
81
83 _rValue <<= m_sNoCheckReferenceValue;
84 break;
85
86 default:
87 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
88 }
89 }
90
91
92 void SAL_CALL OReferenceValueComponent::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
93 {
94 switch ( _nHandle )
95 {
97 OSL_VERIFY( _rValue >>= m_sReferenceValue );
98 calculateExternalValueType();
99 break;
100
102 OSL_VERIFY( _rValue >>= m_sNoCheckReferenceValue );
103 break;
104
106 {
107 sal_Int16 nDefaultChecked;
108 if (!(_rValue >>= nDefaultChecked) || nDefaultChecked < 0
109 || nDefaultChecked > 2)
110 {
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);
115 }
116 m_eDefaultChecked = static_cast<ToggleState>(nDefaultChecked);
117 resetNoBroadcast();
118 }
119 break;
120
121 default:
122 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
123 }
124 }
125
126
127 sal_Bool SAL_CALL OReferenceValueComponent::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
128 {
129 bool bModified = false;
130 switch ( _nHandle )
131 {
133 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sReferenceValue );
134 break;
135
137 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_sNoCheckReferenceValue );
138 break;
139
141 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, static_cast<sal_Int16>(m_eDefaultChecked) );
142 break;
143
144 default:
145 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
146 break;
147 }
148 return bModified;
149 }
150
151
152 Any OReferenceValueComponent::getDefaultForReset() const
153 {
154 return Any( static_cast<sal_Int16>(m_eDefaultChecked) );
155 }
156
157
158 void OReferenceValueComponent::describeFixedProperties( Sequence< Property >& _rProps ) const
159 {
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 ?");
168 }
169
170
171 Sequence< Type > OReferenceValueComponent::getSupportedBindingTypes()
172 {
173 ::std::vector< Type > aTypes;
174
175 if ( !m_sReferenceValue.isEmpty() )
177
179
181 }
182
183
184 Any OReferenceValueComponent::translateExternalValueToControlValue( const Any& _rExternalValue ) const
185 {
186 sal_Int16 nState = TRISTATE_INDET;
187
188 bool bExternalState = false;
189 OUString sExternalValue;
190 if ( _rExternalValue >>= bExternalState )
191 {
192 nState = ::sal::static_int_cast< sal_Int16 >( bExternalState ? TRISTATE_TRUE : TRISTATE_FALSE );
193 }
194 else if ( _rExternalValue >>= sExternalValue )
195 {
196 if ( sExternalValue == m_sReferenceValue )
198 else
199 {
200 if ( sExternalValue == m_sNoCheckReferenceValue )
202 else
204 }
205 }
206 else if ( !_rExternalValue.hasValue() )
207 {
209 }
210 else
211 {
212 OSL_FAIL( "OReferenceValueComponent::translateExternalValueToControlValue: unexpected value type!" );
213 }
214
215 return Any( nState );
216 }
217
218
219 Any OReferenceValueComponent::translateControlValueToExternalValue( ) const
220 {
221 Any aExternalValue;
222
223 try
224 {
225 Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
226 sal_Int16 nControlValue = TRISTATE_INDET;
227 aControlValue >>= nControlValue;
228
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!" );
233
234 switch( nControlValue )
235 {
236 case TRISTATE_TRUE:
237 if ( bBooleanExchange )
238 {
239 aExternalValue <<= true;
240 }
241 else if ( bStringExchange )
242 {
243 aExternalValue <<= m_sReferenceValue;
244 }
245 break;
246
247 case TRISTATE_FALSE:
248 if ( bBooleanExchange )
249 {
250 aExternalValue <<= false;
251 }
252 else if ( bStringExchange )
253 {
254 aExternalValue <<= m_sNoCheckReferenceValue;
255 }
256 break;
257 }
258 }
259 catch( const Exception& )
260 {
261 TOOLS_WARN_EXCEPTION( "forms.component", "OReferenceValueComponent::translateControlValueToExternalValue" );
262 }
263
264 return aExternalValue;
265 }
266
267
268 Any OReferenceValueComponent::translateControlValueToValidatableValue( ) const
269 {
270 if ( !m_xAggregateSet.is() )
271 return Any();
272
273 Any aControlValue( m_xAggregateSet->getPropertyValue( PROPERTY_STATE ) );
274 sal_Int16 nControlValue = TRISTATE_INDET;
275 aControlValue >>= nControlValue;
276
277 Any aValidatableValue;
278 switch ( nControlValue )
279 {
280 case TRISTATE_TRUE:
281 aValidatableValue <<= true;
282 break;
283 case TRISTATE_FALSE:
284 aValidatableValue <<= false;
285 break;
286 }
287 return aValidatableValue;
288 }
289
290
291} // namespace frm
292
293
294/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OReferenceValueComponent(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory, const OUString &_rUnoControlModelTypeName, const OUString &_rDefault)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
sal_Int32 nState
constexpr OUStringLiteral PROPERTY_REFVALUE
Definition: frm_strings.hxx:92
constexpr OUStringLiteral PROPERTY_STATE
Definition: frm_strings.hxx:58
constexpr OUStringLiteral PROPERTY_DEFAULT_STATE
Definition: frm_strings.hxx:65
constexpr OUStringLiteral PROPERTY_UNCHECKED_REFVALUE
Definition: frm_strings.hxx:93
TRISTATE_FALSE
TRISTATE_INDET
TRISTATE_TRUE
sal_Int16 nControlValue
@ Exception
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool tryPropertyValue(Any &_rConvertedValue, Any &_rOldValue, const Any &_rValueToSet, const Any &_rCurrentValue, const Type &_rExpectedType)
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
ToggleState
Definition: togglestate.hxx:27
@ TRISTATE_FALSE
Definition: togglestate.hxx:27
#define PROPERTY_ID_DEFAULT_STATE
Definition: property.hxx:112
#define PROPERTY_ID_UNCHECKED_REFVALUE
Definition: property.hxx:100
#define PROPERTY_ID_REFVALUE
Definition: property.hxx:104
unsigned char sal_Bool
const SvXMLTokenMapEntry aTypes[]