LibreOffice Module forms (master) 1
scrollbar.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 "scrollbar.hxx"
21#include <property.hxx>
22#include <services.hxx>
26#include <rtl/math.hxx>
27#include <tools/debug.hxx>
28#include <com/sun/star/beans/PropertyAttribute.hpp>
29#include <com/sun/star/form/FormComponentType.hpp>
30
31namespace frm
32{
33
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::form;
37 using namespace ::com::sun::star::awt;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::util;
40 using namespace ::com::sun::star::io;
41 using namespace ::com::sun::star::form::binding;
42
43
44 //= helper
45
47 const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
48 const OUString& _rMinValueName, const OUString& _rMaxValueName )
49 {
50 OSL_ENSURE( _rxProperties.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
51
52 sal_Int32 nControlValue( 0 );
53 double nExternalValue = 0;
54 if ( _rExternalValue >>= nExternalValue )
55 {
56 if ( std::isinf( nExternalValue ) )
57 {
58 // set the minimum or maximum of the scroll values
59 OUString sLimitPropertyName = std::signbit( nExternalValue )
60 ? _rMinValueName : _rMaxValueName;
61 if ( _rxProperties.is() )
62 _rxProperties->getPropertyValue( sLimitPropertyName ) >>= nControlValue;
63 }
64 else
65 {
66 nControlValue = static_cast<sal_Int32>(::rtl::math::round( nExternalValue ));
67 }
68 }
69 else
70 {
71 if ( _rxProperties.is() )
72 _rxProperties->getPropertyValue( _rMinValueName ) >>= nControlValue;
73 }
74
75 return Any( nControlValue );
76 }
77
78
79 Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue )
80 {
81 Any aExternalDoubleValue;
82 sal_Int32 nScrollValue = 0;
83 if ( _rControlIntValue >>= nScrollValue )
84 aExternalDoubleValue <<= static_cast<double>(nScrollValue);
85 else
86 {
87 OSL_FAIL( "translateControlIntToExternalDoubleValue: no integer scroll value!" );
88 // aExternalDoubleValue is void here, which is okay for this purpose ...
89 }
90
91 return aExternalDoubleValue;
92 }
93
94 OScrollBarModel::OScrollBarModel( const Reference<XComponentContext>& _rxFactory )
95 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, true, true, false )
96 ,m_nDefaultScrollValue( 0 )
97 {
98
99 m_nClassId = FormComponentType::SCROLLBAR;
101 }
102
103
104 OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
105 :OBoundControlModel( _pOriginal, _rxFactory )
106 {
107 m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
108 }
109
110
111 OScrollBarModel::~OScrollBarModel( )
112 {
113 }
114
115 OUString SAL_CALL OScrollBarModel::getImplementationName()
116 {
117 return "com.sun.star.comp.forms.OScrollBarModel";
118 }
119
120 // note that we're passing OControlModel as "base class". This is because
121 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
122 // service, which isn't really true for us. We only derive from this class
123 // to benefit from the functionality for binding to spreadsheet cells
124 Sequence< OUString > SAL_CALL OScrollBarModel::getSupportedServiceNames()
125 {
126 Sequence< OUString > aOwnNames { FRM_SUN_COMPONENT_SCROLLBAR, BINDABLE_INTEGER_VALUE_RANGE };
127
128 return ::comphelper::combineSequences(
129 getAggregateServiceNames(),
130 ::comphelper::concatSequences(
131 OControlModel::getSupportedServiceNames_Static(),
132 aOwnNames)
133 );
134 }
135
136 css::uno::Reference< css::util::XCloneable > SAL_CALL OScrollBarModel::createClone()
137{
138 rtl::Reference<OScrollBarModel> pClone = new OScrollBarModel(this, getContext());
139 pClone->clonedFrom(this);
140 return pClone;
141}
142
143
144 void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
145 {
146 OControlModel::describeFixedProperties( _rProps );
147 sal_Int32 nOldCount = _rProps.getLength();
148 _rProps.realloc( nOldCount + 3);
149 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
150 *pProperties++ = css::beans::Property(PROPERTY_DEFAULT_SCROLL_VALUE, PROPERTY_ID_DEFAULT_SCROLL_VALUE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::BOUND);
151 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
152 *pProperties++ = css::beans::Property(PROPERTY_CONTROLSOURCEPROPERTY, PROPERTY_ID_CONTROLSOURCEPROPERTY, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY | css::beans::PropertyAttribute::TRANSIENT);
153 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
154 }
155
156
157 void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
158 {
159 switch ( _nHandle )
160 {
162 _rValue <<= m_nDefaultScrollValue;
163 break;
164
165 default:
166 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
167 }
168 }
169
170
171 void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
172 {
173 switch ( _nHandle )
174 {
176 OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
177 resetNoBroadcast();
178 break;
179
180 default:
181 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
182 }
183 }
184
185
186 sal_Bool OScrollBarModel::convertFastPropertyValue(
187 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
188 {
189 bool bModified( false );
190 switch ( _nHandle )
191 {
193 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
194 break;
195
196 default:
197 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
198 break;
199 }
200 return bModified;
201 }
202
203
204 Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
205 {
206 Any aReturn;
207
208 switch ( _nHandle )
209 {
211 aReturn <<= sal_Int32(0);
212 break;
213
214 default:
215 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
216 break;
217 }
218
219 return aReturn;
220 }
221
222
223 Any OScrollBarModel::translateDbColumnToControlValue( )
224 {
225 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
226 return Any();
227 }
228
229
230 bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
231 {
232 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
233 return true;
234 }
235
236
237 Any OScrollBarModel::getDefaultForReset() const
238 {
239 return Any( m_nDefaultScrollValue );
240 }
241
242
243 OUString SAL_CALL OScrollBarModel::getServiceName()
244 {
246 }
247
248
249 void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
250 {
251 OBoundControlModel::write( _rxOutStream );
252 ::osl::MutexGuard aGuard( m_aMutex );
253
254 OStreamSection aSection( _rxOutStream );
255
256 // version
257 _rxOutStream->writeShort( 0x0001 );
258
259 // properties
260 _rxOutStream << m_nDefaultScrollValue;
261 writeHelpTextCompatibly( _rxOutStream );
262 }
263
264
265 void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream )
266 {
267 OBoundControlModel::read( _rxInStream );
268 ::osl::MutexGuard aGuard( m_aMutex );
269
270 // version
271 {
272 OStreamSection aSection( _rxInStream );
273
274 sal_uInt16 nVersion = _rxInStream->readShort();
275 if ( nVersion == 0x0001 )
276 {
277 _rxInStream >> m_nDefaultScrollValue;
278 readHelpTextCompatibly( _rxInStream );
279 }
280 else
281 defaultCommonProperties();
282
283 // here, everything in the stream section which is left will be skipped
284 }
285 }
286
287
288 Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
289 {
290 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
291 "ScrollValueMin",
292 "ScrollValueMax" );
293 }
294
295
296 Any OScrollBarModel::translateControlValueToExternalValue( ) const
297 {
298 // by definition, the base class simply obtains the property value
299 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
300 }
301
302
303 Sequence< Type > OScrollBarModel::getSupportedBindingTypes()
304 {
305 return Sequence< Type >( & cppu::UnoType<double>::get(), 1 );
306 }
307
308} // namespace frm
309
310extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
312 css::uno::Sequence<css::uno::Any> const &)
313{
314 return cppu::acquire(new frm::OScrollBarModel(component));
315}
316
317/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OScrollBarModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
#define DBG_ASSERT(sCon, aError)
sal_Int16 nVersion
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_SCROLL_VALUE
constexpr OUStringLiteral PROPERTY_DEFAULT_SCROLL_VALUE
constexpr OUStringLiteral PROPERTY_CONTROLSOURCEPROPERTY
sal_Int16 nControlValue
std::mutex m_aMutex
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
Any translateControlIntToExternalDoubleValue(const Any &_rControlIntValue)
Definition: scrollbar.cxx:79
Any translateExternalDoubleToControlIntValue(const Any &_rExternalValue, const Reference< XPropertySet > &_rxProperties, const OUString &_rMinValueName, const OUString &_rMaxValueName)
Definition: scrollbar.cxx:46
#define PROPERTY_ID_CONTROLSOURCEPROPERTY
Definition: property.hxx:241
#define PROPERTY_ID_DEFAULT_SCROLL_VALUE
Definition: property.hxx:250
#define PROPERTY_ID_SCROLL_VALUE
Definition: property.hxx:252
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_forms_OScrollBarModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: scrollbar.cxx:311
constexpr OUStringLiteral FRM_SUN_COMPONENT_SCROLLBAR
Definition: services.hxx:131
constexpr OUStringLiteral VCL_CONTROLMODEL_SCROLLBAR
Definition: services.hxx:57
constexpr OUStringLiteral VCL_CONTROL_SCROLLBAR
Definition: services.hxx:58
constexpr OUStringLiteral BINDABLE_INTEGER_VALUE_RANGE
Definition: services.hxx:180
unsigned char sal_Bool