2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-21 22:06:52 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-16 22:55:52 +00:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
#include "scrollbar.hxx"
|
|
|
|
#include <comphelper/streamsection.hxx>
|
2004-04-02 09:56:46 +00:00
|
|
|
#include <comphelper/basicio.hxx>
|
2003-12-11 11:30:16 +00:00
|
|
|
#include <rtl/math.hxx>
|
|
|
|
|
|
|
|
namespace frm
|
|
|
|
{
|
2014-02-25 18:50:02 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::form;
|
|
|
|
using namespace ::com::sun::star::awt;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::util;
|
|
|
|
using namespace ::com::sun::star::io;
|
2004-04-02 09:56:46 +00:00
|
|
|
using namespace ::com::sun::star::form::binding;
|
2003-12-11 11:30:16 +00:00
|
|
|
|
2014-02-25 18:50:02 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
//= helper
|
2014-02-25 18:50:02 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
Any translateExternalDoubleToControlIntValue(
|
2008-06-25 11:05:35 +00:00
|
|
|
const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& _rMinValueName, const OUString& _rMaxValueName )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
|
|
|
OSL_ENSURE( _rxProperties.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
|
|
|
|
|
|
|
|
sal_Int32 nControlValue( 0 );
|
2008-06-25 11:05:35 +00:00
|
|
|
double nExternalValue = 0;
|
|
|
|
if ( _rExternalValue >>= nExternalValue )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
2008-06-25 11:05:35 +00:00
|
|
|
if ( ::rtl::math::isInf( nExternalValue ) )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
2008-06-25 11:05:35 +00:00
|
|
|
// set the minimum or maximum of the scroll values
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sLimitPropertyName = ::rtl::math::isSignBitSet( nExternalValue )
|
2008-06-25 11:05:35 +00:00
|
|
|
? _rMinValueName : _rMaxValueName;
|
|
|
|
if ( _rxProperties.is() )
|
|
|
|
_rxProperties->getPropertyValue( sLimitPropertyName ) >>= nControlValue;
|
2003-12-11 11:30:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-25 11:05:35 +00:00
|
|
|
nControlValue = (sal_Int32)::rtl::math::round( nExternalValue );
|
2003-12-11 11:30:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-25 11:05:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( _rxProperties.is() )
|
|
|
|
_rxProperties->getPropertyValue( _rMinValueName ) >>= nControlValue;
|
|
|
|
}
|
2003-12-11 11:30:16 +00:00
|
|
|
|
|
|
|
return makeAny( nControlValue );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue )
|
|
|
|
{
|
|
|
|
Any aExternalDoubleValue;
|
|
|
|
sal_Int32 nScrollValue = 0;
|
|
|
|
if ( _rControlIntValue >>= nScrollValue )
|
|
|
|
aExternalDoubleValue <<= (double)nScrollValue;
|
|
|
|
else
|
|
|
|
{
|
2011-03-19 14:06:18 +01:00
|
|
|
OSL_FAIL( "translateControlIntToExternalDoubleValue: no integer scroll value!" );
|
2003-12-11 11:30:16 +00:00
|
|
|
// aExternalDoubleValue is void here, which is okay for this purpose ...
|
|
|
|
}
|
|
|
|
|
|
|
|
return aExternalDoubleValue;
|
|
|
|
}
|
|
|
|
|
2013-06-03 08:34:09 +02:00
|
|
|
OScrollBarModel::OScrollBarModel( const Reference<XComponentContext>& _rxFactory )
|
2014-05-06 12:37:38 +02:00
|
|
|
:OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, true, true, false )
|
2003-12-11 11:30:16 +00:00
|
|
|
,m_nDefaultScrollValue( 0 )
|
|
|
|
{
|
|
|
|
|
|
|
|
m_nClassId = FormComponentType::SCROLLBAR;
|
|
|
|
initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-06-03 08:34:09 +02:00
|
|
|
OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
|
2003-12-11 11:30:16 +00:00
|
|
|
:OBoundControlModel( _pOriginal, _rxFactory )
|
|
|
|
{
|
|
|
|
m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
OScrollBarModel::~OScrollBarModel( )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-27 23:27:32 +01:00
|
|
|
OUString SAL_CALL OScrollBarModel::getImplementationName() throw ( RuntimeException, std::exception )
|
|
|
|
{
|
|
|
|
return OUString( "com.sun.star.comp.forms.OScrollBarModel" );
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
// note that we're passing OControlModel as "base class". This is because
|
|
|
|
// OBoundControlModel, our real base class, claims to support the DataAwareControlModel
|
|
|
|
// service, which isn't really true for us. We only derive from this class
|
|
|
|
// to benefit from the functionality for binding to spreadsheet cells
|
2015-03-27 23:27:32 +01:00
|
|
|
Sequence< OUString > SAL_CALL OScrollBarModel::getSupportedServiceNames() throw (RuntimeException, std::exception)
|
|
|
|
{
|
|
|
|
Sequence< OUString > aOwnNames( 2 );
|
|
|
|
aOwnNames[ 0 ] = FRM_SUN_COMPONENT_SCROLLBAR;
|
|
|
|
aOwnNames[ 1 ] = BINDABLE_INTEGER_VALUE_RANGE;
|
|
|
|
|
|
|
|
return ::comphelper::combineSequences(
|
|
|
|
getAggregateServiceNames(),
|
|
|
|
::comphelper::concatSequences(
|
|
|
|
OControlModel::getSupportedServiceNames_Static(),
|
|
|
|
aOwnNames)
|
|
|
|
);
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
IMPLEMENT_DEFAULT_CLONING( OScrollBarModel )
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
void SAL_CALL OScrollBarModel::disposing()
|
|
|
|
{
|
|
|
|
OBoundControlModel::disposing();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-03-09 12:34:57 +00:00
|
|
|
void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
2004-04-02 09:56:46 +00:00
|
|
|
BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
|
2003-12-11 11:30:16 +00:00
|
|
|
DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32, BOUND );
|
|
|
|
DECL_PROP1( TABINDEX, sal_Int16, BOUND );
|
2013-04-07 12:06:47 +02:00
|
|
|
DECL_PROP2( CONTROLSOURCEPROPERTY,OUString, READONLY, TRANSIENT );
|
2004-04-02 09:56:46 +00:00
|
|
|
END_DESCRIBE_PROPERTIES();
|
2003-12-11 11:30:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
|
|
|
|
{
|
|
|
|
switch ( _nHandle )
|
|
|
|
{
|
|
|
|
case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
|
|
|
|
_rValue <<= m_nDefaultScrollValue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
|
|
|
switch ( _nHandle )
|
|
|
|
{
|
|
|
|
case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
|
|
|
|
OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
|
|
|
|
resetNoBroadcast();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
sal_Bool OScrollBarModel::convertFastPropertyValue(
|
|
|
|
Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
|
|
|
|
throw ( IllegalArgumentException )
|
|
|
|
{
|
2014-05-06 12:37:38 +02:00
|
|
|
bool bModified( false );
|
2003-12-11 11:30:16 +00:00
|
|
|
switch ( _nHandle )
|
|
|
|
{
|
|
|
|
case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
|
|
|
|
bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return bModified;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
|
|
|
|
{
|
|
|
|
Any aReturn;
|
|
|
|
|
|
|
|
switch ( _nHandle )
|
|
|
|
{
|
|
|
|
case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
|
|
|
|
aReturn <<= (sal_Int32)0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aReturn;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
Any OScrollBarModel::translateDbColumnToControlValue( )
|
|
|
|
{
|
2011-03-19 14:06:18 +01:00
|
|
|
OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
|
2003-12-11 11:30:16 +00:00
|
|
|
return Any();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-05-06 12:37:38 +02:00
|
|
|
bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
2011-03-19 14:06:18 +01:00
|
|
|
OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
|
2014-05-06 12:37:38 +02:00
|
|
|
return true;
|
2003-12-11 11:30:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
Any OScrollBarModel::getDefaultForReset() const
|
|
|
|
{
|
|
|
|
return makeAny( (sal_Int32)m_nDefaultScrollValue );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
OUString SAL_CALL OScrollBarModel::getServiceName() throw( RuntimeException, std::exception )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
2013-04-23 11:48:24 +02:00
|
|
|
return OUString(FRM_SUN_COMPONENT_SCROLLBAR);
|
2003-12-11 11:30:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2003-12-11 11:30:16 +00:00
|
|
|
void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw( IOException, RuntimeException, std::exception )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
|
|
|
OBoundControlModel::write( _rxOutStream );
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2013-05-02 10:36:43 +02:00
|
|
|
OStreamSection aSection( _rxOutStream );
|
2003-12-11 11:30:16 +00:00
|
|
|
|
|
|
|
// version
|
|
|
|
_rxOutStream->writeShort( 0x0001 );
|
|
|
|
|
|
|
|
// properties
|
|
|
|
_rxOutStream << m_nDefaultScrollValue;
|
|
|
|
writeHelpTextCompatibly( _rxOutStream );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException, std::exception )
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
|
|
|
OBoundControlModel::read( _rxInStream );
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
|
|
|
// version
|
|
|
|
{
|
2013-05-02 10:36:43 +02:00
|
|
|
OStreamSection aSection( _rxInStream );
|
2003-12-11 11:30:16 +00:00
|
|
|
|
|
|
|
sal_uInt16 nVersion = _rxInStream->readShort();
|
|
|
|
if ( nVersion == 0x0001 )
|
|
|
|
{
|
|
|
|
_rxInStream >> m_nDefaultScrollValue;
|
|
|
|
readHelpTextCompatibly( _rxInStream );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
defaultCommonProperties();
|
|
|
|
|
|
|
|
// here, everything in the stream section which is left will be skipped
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2008-06-25 11:05:35 +00:00
|
|
|
Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
2008-06-25 11:05:35 +00:00
|
|
|
return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString( "ScrollValueMin" ),
|
|
|
|
OUString( "ScrollValueMax" ) );
|
2003-12-11 11:30:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2005-03-23 10:32:19 +00:00
|
|
|
Any OScrollBarModel::translateControlValueToExternalValue( ) const
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
|
|
|
// by definition, the base class simply obtains the property value
|
|
|
|
return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2008-06-25 11:05:35 +00:00
|
|
|
Sequence< Type > OScrollBarModel::getSupportedBindingTypes()
|
2003-12-11 11:30:16 +00:00
|
|
|
{
|
2014-05-14 23:17:17 +02:00
|
|
|
return Sequence< Type >( & cppu::UnoType<double>::get(), 1 );
|
2003-12-11 11:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frm
|
2014-02-25 18:50:02 +01:00
|
|
|
|
2015-10-01 15:32:00 +02:00
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* SAL_CALL
|
|
|
|
com_sun_star_comp_forms_OScrollBarModel_get_implementation(css::uno::XComponentContext* component,
|
|
|
|
css::uno::Sequence<css::uno::Any> const &)
|
2015-02-12 14:10:24 +11:00
|
|
|
{
|
|
|
|
return cppu::acquire(new frm::OScrollBarModel(component));
|
|
|
|
}
|
2010-10-12 15:57:08 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|