2003-12-11 10:56:28 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-09 12:14:14 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
2005-09-09 12:14:14 +00:00
|
|
|
* $RCSfile: vclxspinbutton.cxx,v $
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
2006-09-16 11:14:58 +00:00
|
|
|
* $Revision: 1.6 $
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
2006-09-16 11:14:58 +00:00
|
|
|
* last change: $Author: obo $ $Date: 2006-09-16 12:14:58 $
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
2005-09-09 12:14:14 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-09 12:14:14 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
2005-09-09 12:14:14 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
2005-09-09 12:14:14 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
2005-09-09 12:14:14 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2003-12-11 10:56:28 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 11:14:58 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_toolkit.hxx"
|
|
|
|
|
2003-12-11 10:56:28 +00:00
|
|
|
#ifndef TOOLKIT_AWT_VCLXSPINBUTTON_HXX
|
|
|
|
#include "toolkit/awt/vclxspinbutton.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _TOOLKIT_HELPER_PROPERTY_HXX_
|
|
|
|
#include "toolkit/helper/property.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_AWT_SCROLLBARORIENTATION_HPP_
|
|
|
|
#include <com/sun/star/awt/ScrollBarOrientation.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _SV_SPIN_HXX
|
|
|
|
#include <vcl/spin.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace toolkit
|
|
|
|
{
|
|
|
|
void setButtonLikeFaceColor( Window* _pWindow, const ::com::sun::star::uno::Any& _rColorValue );
|
|
|
|
::com::sun::star::uno::Any getButtonLikeFaceColor( const Window* _pWindow );
|
|
|
|
}
|
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
namespace toolkit
|
|
|
|
{
|
|
|
|
//........................................................................
|
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::awt;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void lcl_modifyStyle( Window* _pWindow, WinBits _nStyleBits, sal_Bool _bShouldBePresent )
|
|
|
|
{
|
|
|
|
WinBits nStyle = _pWindow->GetStyle();
|
|
|
|
if ( _bShouldBePresent )
|
|
|
|
nStyle |= _nStyleBits;
|
|
|
|
else
|
|
|
|
nStyle &= ~_nStyleBits;
|
|
|
|
_pWindow->SetStyle( nStyle );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
//= VCLXSpinButton
|
|
|
|
//====================================================================
|
|
|
|
DBG_NAME( VCLXSpinButton )
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
VCLXSpinButton::VCLXSpinButton()
|
|
|
|
:maAdjustmentListeners( *this )
|
|
|
|
{
|
|
|
|
DBG_CTOR( VCLXSpinButton, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
VCLXSpinButton::~VCLXSpinButton()
|
|
|
|
{
|
|
|
|
DBG_DTOR( VCLXSpinButton, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
::vos::OGuard aGuard( GetMutex() );
|
|
|
|
|
|
|
|
EventObject aDisposeEvent;
|
|
|
|
aDisposeEvent.Source = *this;
|
|
|
|
maAdjustmentListeners.disposeAndClear( aDisposeEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
VCLXWindow::dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
if ( listener.is() )
|
|
|
|
maAdjustmentListeners.addInterface( listener );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
if ( listener.is() )
|
|
|
|
maAdjustmentListeners.removeInterface( listener );
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
typedef void (SpinButton::*SetSpinButtonValue) (long);
|
|
|
|
typedef long (SpinButton::*GetSpinButtonValue) (void) const;
|
|
|
|
|
|
|
|
//................................................................
|
|
|
|
void lcl_setSpinButtonValue( ::vos::IMutex& _rMutex, Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
|
|
|
|
{
|
|
|
|
::vos::OGuard aGuard( _rMutex );
|
|
|
|
|
|
|
|
SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
|
|
|
|
if ( pSpinButton )
|
|
|
|
(pSpinButton->*_pSetter)( _nValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
//................................................................
|
|
|
|
sal_Int32 lcl_getSpinButtonValue( ::vos::IMutex& _rMutex, const Window* _pWindow, GetSpinButtonValue _pGetter )
|
|
|
|
{
|
|
|
|
::vos::OGuard aGuard( _rMutex );
|
|
|
|
|
|
|
|
sal_Int32 nValue = 0;
|
|
|
|
|
|
|
|
const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow );
|
|
|
|
if ( pSpinButton )
|
|
|
|
nValue = (pSpinButton->*_pGetter)( );
|
|
|
|
return nValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValue, n );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
::vos::OGuard aGuard( GetMutex() );
|
|
|
|
|
|
|
|
setMinimum( minValue );
|
|
|
|
setMaximum( maxValue );
|
|
|
|
setValue( currentValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL VCLXSpinButton::getValue( ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValue );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMin, minValue );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMax, maxValue );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMin );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMax );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValueStep, spinIncrement );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( ) throw (RuntimeException)
|
|
|
|
{
|
2004-03-09 11:29:33 +00:00
|
|
|
return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValueStep );
|
2003-12-11 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
|
|
|
|
{
|
|
|
|
::vos::OGuard aGuard( GetMutex() );
|
|
|
|
|
|
|
|
lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
|
|
|
|
? ScrollBarOrientation::HORIZONTAL
|
|
|
|
: ScrollBarOrientation::VERTICAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
|
|
|
|
{
|
|
|
|
::vos::OClearableGuard aGuard( GetMutex() );
|
|
|
|
Reference< XSpinValue > xKeepAlive( this );
|
|
|
|
SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() );
|
|
|
|
if ( !pSpinButton )
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch ( _rVclWindowEvent.GetId() )
|
|
|
|
{
|
|
|
|
case VCLEVENT_SPINBUTTON_UP:
|
|
|
|
case VCLEVENT_SPINBUTTON_DOWN:
|
|
|
|
if ( maAdjustmentListeners.getLength() )
|
|
|
|
{
|
|
|
|
AdjustmentEvent aEvent;
|
|
|
|
aEvent.Source = *this;
|
|
|
|
aEvent.Value = pSpinButton->GetValue();
|
|
|
|
|
|
|
|
aGuard.clear();
|
|
|
|
maAdjustmentListeners.adjustmentValueChanged( aEvent );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
xKeepAlive.clear();
|
|
|
|
aGuard.clear();
|
|
|
|
VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void SAL_CALL VCLXSpinButton::setProperty( const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
::vos::OGuard aGuard( GetMutex() );
|
|
|
|
|
|
|
|
sal_Int32 nValue = 0;
|
|
|
|
sal_Bool bIsLongValue = ( Value >>= nValue );
|
|
|
|
|
|
|
|
if ( GetWindow() )
|
|
|
|
{
|
|
|
|
sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
|
|
|
|
switch ( nPropertyId )
|
|
|
|
{
|
|
|
|
case BASEPROPERTY_BACKGROUNDCOLOR:
|
|
|
|
// the default implementation of the base class doesn't work here, since our
|
|
|
|
// interpretation for this property is slightly different
|
|
|
|
setButtonLikeFaceColor( GetWindow(), Value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPINVALUE:
|
|
|
|
if ( bIsLongValue )
|
|
|
|
setValue( nValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPINVALUE_MIN:
|
|
|
|
if ( bIsLongValue )
|
|
|
|
setMinimum( nValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPINVALUE_MAX:
|
|
|
|
if ( bIsLongValue )
|
|
|
|
setMaximum( nValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPININCREMENT:
|
|
|
|
if ( bIsLongValue )
|
|
|
|
setSpinIncrement( nValue );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_ORIENTATION:
|
|
|
|
if ( bIsLongValue )
|
|
|
|
lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
VCLXWindow::setProperty( PropertyName, Value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
Any SAL_CALL VCLXSpinButton::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
::vos::OGuard aGuard( GetMutex() );
|
|
|
|
|
|
|
|
Any aReturn;
|
|
|
|
|
|
|
|
if ( GetWindow() )
|
|
|
|
{
|
|
|
|
sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
|
|
|
|
switch ( nPropertyId )
|
|
|
|
{
|
|
|
|
case BASEPROPERTY_BACKGROUNDCOLOR:
|
|
|
|
// the default implementation of the base class doesn't work here, since our
|
|
|
|
// interpretation for this property is slightly different
|
|
|
|
aReturn = getButtonLikeFaceColor( GetWindow() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPINVALUE:
|
|
|
|
aReturn <<= (sal_Int32)getValue( );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPINVALUE_MIN:
|
|
|
|
aReturn <<= (sal_Int32)getMinimum( );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPINVALUE_MAX:
|
|
|
|
aReturn <<= (sal_Int32)getMaximum( );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_SPININCREMENT:
|
|
|
|
aReturn <<= (sal_Int32)getSpinIncrement( );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BASEPROPERTY_ORIENTATION:
|
|
|
|
aReturn <<= (sal_Int32)
|
|
|
|
( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
|
|
|
|
? ScrollBarOrientation::HORIZONTAL
|
|
|
|
: ScrollBarOrientation::VERTICAL
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
aReturn = VCLXWindow::getProperty( PropertyName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
} // namespace toolkit
|
|
|
|
//........................................................................
|