Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / toolkit / source / controls / tkscrollbar.cxx
blobe71a74ebfa78c885ea1a5bd91cce0ec8db7ca4f4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "toolkit/controls/tkscrollbar.hxx"
21 #include "toolkit/helper/property.hxx"
22 #include "toolkit/helper/unopropertyarrayhelper.hxx"
23 #include <cppuhelper/typeprovider.hxx>
25 // for introspection
26 #include <toolkit/awt/vclxwindows.hxx>
28 //........................................................................
29 namespace toolkit
31 //........................................................................
33 using namespace ::com::sun::star;
35 //====================================================================
36 //= UnoControlScrollBarModel
37 //====================================================================
38 //--------------------------------------------------------------------
39 UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
40 :UnoControlModel( i_factory )
42 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar );
45 //--------------------------------------------------------------------
46 ::rtl::OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
48 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel );
51 //--------------------------------------------------------------------
52 uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
54 switch ( nPropId )
56 case BASEPROPERTY_LIVE_SCROLL:
57 return uno::makeAny( (sal_Bool)sal_False );
58 case BASEPROPERTY_DEFAULTCONTROL:
59 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar ) );
61 default:
62 return UnoControlModel::ImplGetDefaultValue( nPropId );
66 //--------------------------------------------------------------------
67 ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper()
69 static UnoPropertyArrayHelper* pHelper = NULL;
70 if ( !pHelper )
72 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
73 pHelper = new UnoPropertyArrayHelper( aIDs );
75 return *pHelper;
78 //--------------------------------------------------------------------
79 uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException)
81 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
82 return xInfo;
86 //====================================================================
87 //= UnoControlScrollBarModel
88 //====================================================================
89 UnoScrollBarControl::UnoScrollBarControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
90 :UnoControlBase( i_factory )
91 ,maAdjustmentListeners( *this )
95 ::rtl::OUString UnoScrollBarControl::GetComponentServiceName()
97 return ::rtl::OUString("ScrollBar");
100 // ::com::sun::star::uno::XInterface
101 uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
103 uno::Any aRet = ::cppu::queryInterface( rType,
104 (static_cast< awt::XAdjustmentListener* >(this)),
105 (static_cast< awt::XScrollBar* >(this)) );
106 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
109 // ::com::sun::star::lang::XTypeProvider
110 IMPL_XTYPEPROVIDER_START( UnoScrollBarControl )
111 getCppuType( ( uno::Reference< awt::XAdjustmentListener>* ) NULL ),
112 getCppuType( ( uno::Reference< awt::XScrollBar>* ) NULL ),
113 UnoControlBase::getTypes()
114 IMPL_XTYPEPROVIDER_END
116 void UnoScrollBarControl::dispose() throw(uno::RuntimeException)
118 lang::EventObject aEvt;
119 aEvt.Source = (::cppu::OWeakObject*)this;
120 maAdjustmentListeners.disposeAndClear( aEvt );
121 UnoControl::dispose();
124 void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException)
126 UnoControl::createPeer( rxToolkit, rParentPeer );
128 uno::Reference < awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
129 xScrollBar->addAdjustmentListener( this );
132 // ::com::sun::star::awt::XAdjustmentListener
133 void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException)
135 switch ( rEvent.Type )
137 case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE:
138 case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE:
139 case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS:
141 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
143 if ( xScrollBar.is() )
145 uno::Any aAny;
146 aAny <<= xScrollBar->getValue();
147 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_False );
150 break;
151 default:
153 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
158 if ( maAdjustmentListeners.getLength() )
159 maAdjustmentListeners.adjustmentValueChanged( rEvent );
162 // ::com::sun::star::awt::XScrollBar
163 void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
165 maAdjustmentListeners.addInterface( l );
168 void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
170 maAdjustmentListeners.removeInterface( l );
173 void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
175 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), sal_True );
178 void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException)
180 uno::Any aAny;
181 aAny <<= nValue;
182 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_True );
183 aAny <<= nVisible;
184 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, sal_True );
185 aAny <<= nMax;
186 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, sal_True );
189 sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException)
191 sal_Int32 n = 0;
192 if ( getPeer().is() )
194 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
195 n = xScrollBar->getValue();
197 return n;
200 void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
202 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), sal_True );
205 sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException)
207 sal_Int32 n = 0;
208 if ( getPeer().is() )
210 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
211 n = xScrollBar->getMaximum();
213 return n;
216 void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
218 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), sal_True );
221 sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException)
223 sal_Int32 n = 0;
224 if ( getPeer().is() )
226 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
227 n = xScrollBar->getLineIncrement();
229 return n;
232 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
234 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), sal_True );
237 sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException)
239 sal_Int32 n = 0;
240 if ( getPeer().is() )
242 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
243 n = xScrollBar->getBlockIncrement();
245 return n;
248 void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
250 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), sal_True );
253 sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException)
255 sal_Int32 n = 0;
256 if ( getPeer().is() )
258 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
259 n = xScrollBar->getVisibleSize();
261 return n;
264 void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
266 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), sal_True );
269 sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException)
271 sal_Int32 n = 0;
272 if ( getPeer().is() )
274 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
275 n = xScrollBar->getOrientation();
277 return n;
282 //........................................................................
283 } // namespace toolkit
284 //........................................................................
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */