1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 30*cdf0e10cSrcweir #include "toolkit/controls/tkscrollbar.hxx" 31*cdf0e10cSrcweir #include "toolkit/helper/property.hxx" 32*cdf0e10cSrcweir #include "toolkit/helper/unopropertyarrayhelper.hxx" 33*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir // for introspection 37*cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir //........................................................................ 40*cdf0e10cSrcweir namespace toolkit 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir //........................................................................ 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using namespace ::com::sun::star; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //==================================================================== 47*cdf0e10cSrcweir //= UnoControlScrollBarModel 48*cdf0e10cSrcweir //==================================================================== 49*cdf0e10cSrcweir //-------------------------------------------------------------------- 50*cdf0e10cSrcweir UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference< lang::XMultiServiceFactory >& i_factory ) 51*cdf0e10cSrcweir :UnoControlModel( i_factory ) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar ); 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //-------------------------------------------------------------------- 57*cdf0e10cSrcweir ::rtl::OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel ); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir //-------------------------------------------------------------------- 63*cdf0e10cSrcweir uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir switch ( nPropId ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir case BASEPROPERTY_LIVE_SCROLL: 68*cdf0e10cSrcweir return uno::makeAny( (sal_Bool)sal_False ); 69*cdf0e10cSrcweir case BASEPROPERTY_DEFAULTCONTROL: 70*cdf0e10cSrcweir return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar ) ); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir default: 73*cdf0e10cSrcweir return UnoControlModel::ImplGetDefaultValue( nPropId ); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //-------------------------------------------------------------------- 78*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper() 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir static UnoPropertyArrayHelper* pHelper = NULL; 81*cdf0e10cSrcweir if ( !pHelper ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 84*cdf0e10cSrcweir pHelper = new UnoPropertyArrayHelper( aIDs ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir return *pHelper; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //-------------------------------------------------------------------- 90*cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 93*cdf0e10cSrcweir return xInfo; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //==================================================================== 98*cdf0e10cSrcweir //= UnoControlScrollBarModel 99*cdf0e10cSrcweir //==================================================================== 100*cdf0e10cSrcweir UnoScrollBarControl::UnoScrollBarControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory ) 101*cdf0e10cSrcweir :UnoControlBase( i_factory ) 102*cdf0e10cSrcweir ,maAdjustmentListeners( *this ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir ::rtl::OUString UnoScrollBarControl::GetComponentServiceName() 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "ScrollBar" ); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // ::com::sun::star::uno::XInterface 112*cdf0e10cSrcweir uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir uno::Any aRet = ::cppu::queryInterface( rType, 115*cdf0e10cSrcweir SAL_STATIC_CAST( awt::XAdjustmentListener*, this ), 116*cdf0e10cSrcweir SAL_STATIC_CAST( awt::XScrollBar*, this ) ); 117*cdf0e10cSrcweir return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // ::com::sun::star::lang::XTypeProvider 121*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_START( UnoScrollBarControl ) 122*cdf0e10cSrcweir getCppuType( ( uno::Reference< awt::XAdjustmentListener>* ) NULL ), 123*cdf0e10cSrcweir getCppuType( ( uno::Reference< awt::XScrollBar>* ) NULL ), 124*cdf0e10cSrcweir UnoControlBase::getTypes() 125*cdf0e10cSrcweir IMPL_XTYPEPROVIDER_END 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir void UnoScrollBarControl::dispose() throw(uno::RuntimeException) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir lang::EventObject aEvt; 130*cdf0e10cSrcweir aEvt.Source = (::cppu::OWeakObject*)this; 131*cdf0e10cSrcweir maAdjustmentListeners.disposeAndClear( aEvt ); 132*cdf0e10cSrcweir UnoControl::dispose(); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir UnoControl::createPeer( rxToolkit, rParentPeer ); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir uno::Reference < awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 140*cdf0e10cSrcweir xScrollBar->addAdjustmentListener( this ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // ::com::sun::star::awt::XAdjustmentListener 144*cdf0e10cSrcweir void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir switch ( rEvent.Type ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE: 149*cdf0e10cSrcweir case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE: 150*cdf0e10cSrcweir case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS: 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir if ( xScrollBar.is() ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir uno::Any aAny; 157*cdf0e10cSrcweir aAny <<= xScrollBar->getValue(); 158*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_False ); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir break; 162*cdf0e10cSrcweir default: 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir DBG_ERROR( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir if ( maAdjustmentListeners.getLength() ) 170*cdf0e10cSrcweir maAdjustmentListeners.adjustmentValueChanged( rEvent ); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir // ::com::sun::star::awt::XScrollBar 174*cdf0e10cSrcweir void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir maAdjustmentListeners.addInterface( l ); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir maAdjustmentListeners.removeInterface( l ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), sal_True ); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir uno::Any aAny; 192*cdf0e10cSrcweir aAny <<= nValue; 193*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_True ); 194*cdf0e10cSrcweir aAny <<= nVisible; 195*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, sal_True ); 196*cdf0e10cSrcweir aAny <<= nMax; 197*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, sal_True ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir sal_Int32 n = 0; 203*cdf0e10cSrcweir if ( getPeer().is() ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 206*cdf0e10cSrcweir n = xScrollBar->getValue(); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir return n; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), sal_True ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir sal_Int32 n = 0; 219*cdf0e10cSrcweir if ( getPeer().is() ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 222*cdf0e10cSrcweir n = xScrollBar->getMaximum(); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir return n; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), sal_True ); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir sal_Int32 n = 0; 235*cdf0e10cSrcweir if ( getPeer().is() ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 238*cdf0e10cSrcweir n = xScrollBar->getLineIncrement(); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir return n; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), sal_True ); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir sal_Int32 n = 0; 251*cdf0e10cSrcweir if ( getPeer().is() ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 254*cdf0e10cSrcweir n = xScrollBar->getBlockIncrement(); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir return n; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), sal_True ); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir sal_Int32 n = 0; 267*cdf0e10cSrcweir if ( getPeer().is() ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 270*cdf0e10cSrcweir n = xScrollBar->getVisibleSize(); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir return n; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), sal_True ); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir sal_Int32 n = 0; 283*cdf0e10cSrcweir if ( getPeer().is() ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 286*cdf0e10cSrcweir n = xScrollBar->getOrientation(); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir return n; 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir //........................................................................ 294*cdf0e10cSrcweir } // namespace toolkit 295*cdf0e10cSrcweir //........................................................................ 296*cdf0e10cSrcweir 297