update dev300-m58
[ooovba.git] / toolkit / source / controls / tkscrollbar.cxx
blobfce32746b7e16c90aeb3c5878ee78d7d84ba3eb4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tkscrollbar.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include "toolkit/controls/tkscrollbar.hxx"
34 #include "toolkit/helper/property.hxx"
35 #include "toolkit/helper/unopropertyarrayhelper.hxx"
36 #include <cppuhelper/typeprovider.hxx>
37 #include <tools/debug.hxx>
39 // for introspection
40 #include <toolkit/awt/vclxwindows.hxx>
42 //........................................................................
43 namespace toolkit
45 //........................................................................
47 using namespace ::com::sun::star;
49 //====================================================================
50 //= UnoControlScrollBarModel
51 //====================================================================
52 //--------------------------------------------------------------------
53 UnoControlScrollBarModel::UnoControlScrollBarModel()
55 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar );
58 //--------------------------------------------------------------------
59 ::rtl::OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
61 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel );
64 //--------------------------------------------------------------------
65 uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
67 switch ( nPropId )
69 case BASEPROPERTY_LIVE_SCROLL:
70 return uno::makeAny( (sal_Bool)sal_False );
71 case BASEPROPERTY_DEFAULTCONTROL:
72 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar ) );
74 default:
75 return UnoControlModel::ImplGetDefaultValue( nPropId );
79 //--------------------------------------------------------------------
80 ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper()
82 static UnoPropertyArrayHelper* pHelper = NULL;
83 if ( !pHelper )
85 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
86 pHelper = new UnoPropertyArrayHelper( aIDs );
88 return *pHelper;
91 //--------------------------------------------------------------------
92 uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException)
94 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
95 return xInfo;
99 //====================================================================
100 //= UnoControlScrollBarModel
101 //====================================================================
102 UnoScrollBarControl::UnoScrollBarControl()
103 : maAdjustmentListeners( *this )
107 ::rtl::OUString UnoScrollBarControl::GetComponentServiceName()
109 return ::rtl::OUString::createFromAscii( "ScrollBar" );
112 // ::com::sun::star::uno::XInterface
113 uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
115 uno::Any aRet = ::cppu::queryInterface( rType,
116 SAL_STATIC_CAST( awt::XAdjustmentListener*, this ),
117 SAL_STATIC_CAST( awt::XScrollBar*, this ) );
118 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
121 // ::com::sun::star::lang::XTypeProvider
122 IMPL_XTYPEPROVIDER_START( UnoScrollBarControl )
123 getCppuType( ( uno::Reference< awt::XAdjustmentListener>* ) NULL ),
124 getCppuType( ( uno::Reference< awt::XScrollBar>* ) NULL ),
125 UnoControlBase::getTypes()
126 IMPL_XTYPEPROVIDER_END
128 void UnoScrollBarControl::dispose() throw(uno::RuntimeException)
130 lang::EventObject aEvt;
131 aEvt.Source = (::cppu::OWeakObject*)this;
132 maAdjustmentListeners.disposeAndClear( aEvt );
133 UnoControl::dispose();
136 void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException)
138 UnoControl::createPeer( rxToolkit, rParentPeer );
140 uno::Reference < awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
141 xScrollBar->addAdjustmentListener( this );
144 // ::com::sun::star::awt::XAdjustmentListener
145 void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException)
147 switch ( rEvent.Type )
149 case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE:
150 case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE:
151 case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS:
153 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
155 if ( xScrollBar.is() )
157 uno::Any aAny;
158 aAny <<= xScrollBar->getValue();
159 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_False );
162 break;
163 default:
165 DBG_ERROR( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
170 if ( maAdjustmentListeners.getLength() )
171 maAdjustmentListeners.adjustmentValueChanged( rEvent );
174 // ::com::sun::star::awt::XScrollBar
175 void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
177 maAdjustmentListeners.addInterface( l );
180 void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
182 maAdjustmentListeners.removeInterface( l );
185 void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
187 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), sal_True );
190 void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException)
192 uno::Any aAny;
193 aAny <<= nValue;
194 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_True );
195 aAny <<= nVisible;
196 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, sal_True );
197 aAny <<= nMax;
198 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, sal_True );
201 sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException)
203 sal_Int32 n = 0;
204 if ( getPeer().is() )
206 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
207 n = xScrollBar->getValue();
209 return n;
212 void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
214 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), sal_True );
217 sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException)
219 sal_Int32 n = 0;
220 if ( getPeer().is() )
222 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
223 n = xScrollBar->getMaximum();
225 return n;
228 void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
230 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), sal_True );
233 sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException)
235 sal_Int32 n = 0;
236 if ( getPeer().is() )
238 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
239 n = xScrollBar->getLineIncrement();
241 return n;
244 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
246 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), sal_True );
249 sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException)
251 sal_Int32 n = 0;
252 if ( getPeer().is() )
254 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
255 n = xScrollBar->getBlockIncrement();
257 return n;
260 void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
262 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), sal_True );
265 sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException)
267 sal_Int32 n = 0;
268 if ( getPeer().is() )
270 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
271 n = xScrollBar->getVisibleSize();
273 return n;
276 void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
278 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), sal_True );
281 sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException)
283 sal_Int32 n = 0;
284 if ( getPeer().is() )
286 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
287 n = xScrollBar->getOrientation();
289 return n;
294 //........................................................................
295 } // namespace toolkit
296 //........................................................................