1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/uno/XComponentContext.hpp>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <cppuhelper/queryinterface.hxx>
26 #include <toolkit/awt/vclxwindows.hxx>
28 #include "helper/unopropertyarrayhelper.hxx"
34 using namespace ::com::sun::star
;
37 //= UnoControlScrollBarModel
40 UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference
< uno::XComponentContext
>& i_factory
)
41 :UnoControlModel( i_factory
)
43 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar
);
47 OUString
UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
49 return OUString::createFromAscii( szServiceName_UnoControlScrollBarModel
);
52 OUString
UnoControlScrollBarModel::getImplementationName()
53 throw (css::uno::RuntimeException
, std::exception
)
55 return OUString("stardiv.Toolkit.UnoControlScrollBarModel");
58 css::uno::Sequence
<OUString
>
59 UnoControlScrollBarModel::getSupportedServiceNames()
60 throw (css::uno::RuntimeException
, std::exception
)
62 auto s(UnoControlModel::getSupportedServiceNames());
63 s
.realloc(s
.getLength() + 2);
64 s
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBarModel";
65 s
[s
.getLength() - 1] = "stardiv.vcl.controlmodel.ScrollBar";
69 uno::Any
UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
73 case BASEPROPERTY_LIVE_SCROLL
:
74 return uno::makeAny( false );
75 case BASEPROPERTY_DEFAULTCONTROL
:
76 return uno::makeAny( OUString::createFromAscii( szServiceName_UnoControlScrollBar
) );
79 return UnoControlModel::ImplGetDefaultValue( nPropId
);
84 ::cppu::IPropertyArrayHelper
& UnoControlScrollBarModel::getInfoHelper()
86 static UnoPropertyArrayHelper
* pHelper
= NULL
;
89 uno::Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
90 pHelper
= new UnoPropertyArrayHelper( aIDs
);
96 uno::Reference
< beans::XPropertySetInfo
> UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException
, std::exception
)
98 static uno::Reference
< beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
104 //= UnoControlScrollBarModel
106 UnoScrollBarControl::UnoScrollBarControl()
108 ,maAdjustmentListeners( *this )
112 OUString
UnoScrollBarControl::GetComponentServiceName()
114 return OUString("ScrollBar");
117 // ::com::sun::star::uno::XInterface
118 uno::Any
UnoScrollBarControl::queryAggregation( const uno::Type
& rType
) throw(uno::RuntimeException
, std::exception
)
120 uno::Any aRet
= ::cppu::queryInterface( rType
,
121 (static_cast< awt::XAdjustmentListener
* >(this)),
122 (static_cast< awt::XScrollBar
* >(this)) );
123 return (aRet
.hasValue() ? aRet
: UnoControlBase::queryAggregation( rType
));
126 // ::com::sun::star::lang::XTypeProvider
127 IMPL_XTYPEPROVIDER_START( UnoScrollBarControl
)
128 cppu::UnoType
<awt::XAdjustmentListener
>::get(),
129 cppu::UnoType
<awt::XScrollBar
>::get(),
130 UnoControlBase::getTypes()
131 IMPL_XTYPEPROVIDER_END
133 void UnoScrollBarControl::dispose() throw(uno::RuntimeException
, std::exception
)
135 lang::EventObject aEvt
;
136 aEvt
.Source
= (::cppu::OWeakObject
*)this;
137 maAdjustmentListeners
.disposeAndClear( aEvt
);
138 UnoControl::dispose();
141 void UnoScrollBarControl::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
) throw(uno::RuntimeException
, std::exception
)
143 UnoControl::createPeer( rxToolkit
, rParentPeer
);
145 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
146 xScrollBar
->addAdjustmentListener( this );
149 // ::com::sun::star::awt::XAdjustmentListener
150 void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
152 switch ( rEvent
.Type
)
154 case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE
:
155 case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE
:
156 case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS
:
158 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
160 if ( xScrollBar
.is() )
163 aAny
<<= xScrollBar
->getValue();
164 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), aAny
, false );
170 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
175 if ( maAdjustmentListeners
.getLength() )
176 maAdjustmentListeners
.adjustmentValueChanged( rEvent
);
179 // ::com::sun::star::awt::XScrollBar
180 void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XAdjustmentListener
> & l
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
182 maAdjustmentListeners
.addInterface( l
);
185 void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XAdjustmentListener
> & l
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
187 maAdjustmentListeners
.removeInterface( l
);
190 void UnoScrollBarControl::setValue( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
192 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::makeAny( n
), true );
195 void UnoScrollBarControl::setValues( sal_Int32 nValue
, sal_Int32 nVisible
, sal_Int32 nMax
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
199 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), aAny
, true );
201 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), aAny
, true );
203 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), aAny
, true );
206 sal_Int32
UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
209 if ( getPeer().is() )
211 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
212 n
= xScrollBar
->getValue();
217 void UnoScrollBarControl::setMaximum( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
219 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::makeAny( n
), true );
222 sal_Int32
UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
225 if ( getPeer().is() )
227 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
228 n
= xScrollBar
->getMaximum();
233 void UnoScrollBarControl::setLineIncrement( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
235 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT
), uno::makeAny( n
), true );
238 sal_Int32
UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
241 if ( getPeer().is() )
243 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
244 n
= xScrollBar
->getLineIncrement();
249 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
251 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT
), uno::makeAny( n
), true );
254 sal_Int32
UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
257 if ( getPeer().is() )
259 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
260 n
= xScrollBar
->getBlockIncrement();
265 void UnoScrollBarControl::setVisibleSize( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
267 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::makeAny( n
), true );
270 sal_Int32
UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
273 if ( getPeer().is() )
275 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
276 n
= xScrollBar
->getVisibleSize();
281 void UnoScrollBarControl::setOrientation( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
283 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION
), uno::makeAny( n
), true );
286 sal_Int32
UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
289 if ( getPeer().is() )
291 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
292 n
= xScrollBar
->getOrientation();
297 OUString
UnoScrollBarControl::getImplementationName()
298 throw (css::uno::RuntimeException
, std::exception
)
300 return OUString("stardiv.Toolkit.UnoScrollBarControl");
303 css::uno::Sequence
<OUString
> UnoScrollBarControl::getSupportedServiceNames()
304 throw (css::uno::RuntimeException
, std::exception
)
306 auto s(UnoControlBase::getSupportedServiceNames());
307 s
.realloc(s
.getLength() + 2);
308 s
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBar";
309 s
[s
.getLength() - 1] = "stardiv.vcl.control.ScrollBar";
313 } // namespace toolkit
316 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
317 stardiv_Toolkit_UnoControlScrollBarModel_get_implementation(
318 css::uno::XComponentContext
*context
,
319 css::uno::Sequence
<css::uno::Any
> const &)
321 return cppu::acquire(new toolkit::UnoControlScrollBarModel(context
));
324 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
325 stardiv_Toolkit_UnoScrollBarControl_get_implementation(
326 css::uno::XComponentContext
*,
327 css::uno::Sequence
<css::uno::Any
> const &)
329 return cppu::acquire(new toolkit::UnoScrollBarControl());
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */