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