Files
libreoffice/toolkit/source/controls/tkspinbutton.cxx

353 lines
14 KiB
C++
Raw Normal View History

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: tkspinbutton.cxx,v $
* $Revision: 1.6 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_toolkit.hxx"
#include "toolkit/controls/tkspinbutton.hxx"
#include "toolkit/helper/property.hxx"
#include "toolkit/helper/unopropertyarrayhelper.hxx"
#include <com/sun/star/awt/ScrollBarOrientation.hpp>
#include <cppuhelper/typeprovider.hxx>
#include <tools/debug.hxx>
//........................................................................
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;
//====================================================================
//= UnoSpinButtonModel
//====================================================================
//--------------------------------------------------------------------
UnoSpinButtonModel::UnoSpinButtonModel()
{
ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
ImplRegisterProperty( BASEPROPERTY_BORDER );
ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
ImplRegisterProperty( BASEPROPERTY_ENABLED );
ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
ImplRegisterProperty( BASEPROPERTY_HELPURL );
ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
ImplRegisterProperty( BASEPROPERTY_REPEAT );
ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR );
ImplRegisterProperty( BASEPROPERTY_SPINVALUE );
ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN );
ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX );
ImplRegisterProperty( BASEPROPERTY_SPININCREMENT );
ImplRegisterProperty( BASEPROPERTY_TABSTOP );
CWS-TOOLING: integrate CWS rtlcontrols 2008-12-11 21:08:49 +0100 fs r265367 : CONTEXT_WRITING_MODE is transient 2008-12-11 21:08:00 +0100 fs r265365 : REGISTER_PROP_3 2008-12-11 20:53:44 +0100 fs r265362 : ContextWritingMode is not MAYBEVOID 2008-12-11 15:29:08 +0100 fs r265315 : prevent a deadlock during complex.dbaccess.DatabaseDocument test 2008-12-11 15:01:13 +0100 fs r265304 : manual RESYNC to m37 2008-12-10 20:04:38 +0100 pl r265230 : #i30631# fix a snafu in mirroring 2008-12-10 19:14:45 +0100 pl r265229 : #i30631# rework PaintToDevice for RTL controls 2008-12-05 10:19:13 +0100 fs r264893 : #i10000# ImplInitSettings => ImplInitWindow (ImplInitSettings clashed with base classes ImplInitSettings on unxsols4) 2008-12-03 12:55:24 +0100 fs r264768 : #i100000# 2008-12-03 07:11:48 +0100 fs r264741 : #i10000# 2008-12-02 10:37:51 +0100 fs r264670 : CWS-TOOLING: rebase CWS rtlcontrols to trunk@264325 (milestone: DEV300:m36) 2008-12-02 09:27:50 +0100 fs r264660 : merge from trunk 2008-11-25 10:28:36 +0100 ama r264277 : Fix #i94572# 2008-11-24 11:46:48 +0100 fs r264218 : #i30631# proper context writing mode 2008-11-24 09:38:04 +0100 fs r264204 : #i30631# (approved by PL) 2008-11-24 09:35:47 +0100 fs r264203 : #i30631# Context/WritingMode 2008-11-24 09:33:36 +0100 fs r264202 : #i30631# Context/WritingMode 2008-11-24 09:31:53 +0100 fs r264200 : #i30631# RTL 2008-11-19 08:51:48 +0100 fs r263963 : #i10000# 2008-11-18 20:58:11 +0100 fs r263878 : #i10000# 2008-11-18 15:30:44 +0100 fs r263778 : migrate the CWS from CVS to SVN the CVS changes contained in this change set are the ones between the following two CVS tags: CWS_DEV300_RTLCONTROLS_ANCHOR CWS_DEV300_RTLCONTROLS_PRE_MIGRATION 2008-11-18 12:29:04 +0100 ama r263762 : Fix #i94572#: Context direction for drawing objects 2008-11-18 12:25:50 +0100 ama r263761 : Fix #i94572#: Context direction for drawing objects 2008-11-18 12:02:30 +0100 ama r263759 : Fix #i94572#: Context direction for drawing objects
2008-12-16 13:30:53 +00:00
ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
}
//--------------------------------------------------------------------
::rtl::OUString UnoSpinButtonModel::getServiceName( ) throw (RuntimeException)
{
return ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
}
//--------------------------------------------------------------------
Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
{
switch ( nPropId )
{
case BASEPROPERTY_DEFAULTCONTROL:
return makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl ) );
case BASEPROPERTY_BORDER:
return makeAny( (sal_Int16) 0 );
case BASEPROPERTY_REPEAT:
return makeAny( (sal_Bool)sal_True );
default:
return UnoControlModel::ImplGetDefaultValue( nPropId );
}
}
//--------------------------------------------------------------------
::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper()
{
static UnoPropertyArrayHelper* pHelper = NULL;
if ( !pHelper )
{
Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
pHelper = new UnoPropertyArrayHelper( aIDs );
}
return *pHelper;
}
//--------------------------------------------------------------------
Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo( ) throw(RuntimeException)
{
static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
return xInfo;
}
//--------------------------------------------------------------------
::rtl::OUString SAL_CALL UnoSpinButtonModel::getImplementationName( ) throw(RuntimeException)
{
return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonModel" ) );
}
//--------------------------------------------------------------------
Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames() throw(RuntimeException)
{
Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() );
aServices.realloc( aServices.getLength() + 1 );
aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel );
return aServices;
}
//====================================================================
//= UnoSpinButtonControl
//====================================================================
//--------------------------------------------------------------------
UnoSpinButtonControl::UnoSpinButtonControl()
:maAdjustmentListeners( *this )
{
}
//--------------------------------------------------------------------
::rtl::OUString UnoSpinButtonControl::GetComponentServiceName()
{
return ::rtl::OUString::createFromAscii( "SpinButton" );
}
//--------------------------------------------------------------------
Any UnoSpinButtonControl::queryAggregation( const Type & rType ) throw(RuntimeException)
{
Any aRet = UnoControlBase::queryAggregation( rType );
if ( !aRet.hasValue() )
aRet = UnoSpinButtonControl_Base::queryInterface( rType );
return aRet;
}
//--------------------------------------------------------------------
IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base )
//--------------------------------------------------------------------
void UnoSpinButtonControl::dispose() throw(RuntimeException)
{
::osl::ClearableMutexGuard aGuard( GetMutex() );
if ( maAdjustmentListeners.getLength() )
{
Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
if ( xSpinnable.is() )
xSpinnable->removeAdjustmentListener( this );
EventObject aDisposeEvent;
aDisposeEvent.Source = *this;
aGuard.clear();
maAdjustmentListeners.disposeAndClear( aDisposeEvent );
}
UnoControl::dispose();
}
//--------------------------------------------------------------------
::rtl::OUString SAL_CALL UnoSpinButtonControl::getImplementationName( ) throw(RuntimeException)
{
return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonControl" ) );
}
//--------------------------------------------------------------------
Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames() throw(RuntimeException)
{
Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() );
aServices.realloc( aServices.getLength() + 1 );
aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl );
return aServices;
}
//--------------------------------------------------------------------
void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
{
UnoControl::createPeer( rxToolkit, rParentPeer );
Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
if ( xSpinnable.is() )
xSpinnable->addAdjustmentListener( this );
}
//--------------------------------------------------------------------
void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent ) throw(RuntimeException)
{
switch ( rEvent.Type )
{
case AdjustmentType_ADJUST_LINE:
case AdjustmentType_ADJUST_PAGE:
case AdjustmentType_ADJUST_ABS:
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( rEvent.Value ), sal_False );
break;
default:
DBG_ERROR( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
}
if ( maAdjustmentListeners.getLength() )
{
AdjustmentEvent aEvent( rEvent );
aEvent.Source = *this;
maAdjustmentListeners.adjustmentValueChanged( aEvent );
}
}
//--------------------------------------------------------------------
void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
maAdjustmentListeners.addInterface( listener );
}
//--------------------------------------------------------------------
void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
maAdjustmentListeners.removeInterface( listener );
}
//--------------------------------------------------------------------
void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value ) throw (RuntimeException)
{
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( value ), sal_True );
}
//--------------------------------------------------------------------
void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException)
{
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( currentValue ), sal_True );
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL UnoSpinButtonControl::getValue( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
sal_Int32 nValue = 0;
Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
if ( xSpinnable.is() )
nValue = xSpinnable->getValue();
return nValue;
}
//--------------------------------------------------------------------
void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue ) throw (RuntimeException)
{
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True );
}
//--------------------------------------------------------------------
void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue ) throw (RuntimeException)
{
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True );
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
sal_Int32 nMin = 0;
Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
if ( xSpinnable.is() )
nMin = xSpinnable->getMinimum();
return nMin;
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
sal_Int32 nMax = 0;
Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
if ( xSpinnable.is() )
nMax = xSpinnable->getMaximum();
return nMax;
}
//--------------------------------------------------------------------
void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException)
{
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), makeAny( spinIncrement ), sal_True );
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
sal_Int32 nIncrement = 0;
Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
if ( xSpinnable.is() )
nIncrement = xSpinnable->getSpinIncrement();
return nIncrement;
}
//--------------------------------------------------------------------
void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException)
{
ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), makeAny( orientation ), sal_True );
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL;
Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
if ( xSpinnable.is() )
nOrientation = xSpinnable->getOrientation();
return nOrientation;
}
//........................................................................
} // namespace toolkit
//........................................................................