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 <controls/tkscrollbar.hxx>
21 #include <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( )
49 return "stardiv.vcl.controlmodel.ScrollBar";
52 OUString
UnoControlScrollBarModel::getImplementationName()
54 return "stardiv.Toolkit.UnoControlScrollBarModel";
57 css::uno::Sequence
<OUString
>
58 UnoControlScrollBarModel::getSupportedServiceNames()
60 auto s(UnoControlModel::getSupportedServiceNames());
61 s
.realloc(s
.getLength() + 2);
62 auto ps
= s
.getArray();
63 ps
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBarModel";
64 ps
[s
.getLength() - 1] = "stardiv.vcl.controlmodel.ScrollBar";
68 uno::Any
UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
72 case BASEPROPERTY_LIVE_SCROLL
:
73 return uno::Any( false );
74 case BASEPROPERTY_DEFAULTCONTROL
:
75 return uno::Any( OUString( "stardiv.vcl.control.ScrollBar" ) );
78 return UnoControlModel::ImplGetDefaultValue( nPropId
);
83 ::cppu::IPropertyArrayHelper
& UnoControlScrollBarModel::getInfoHelper()
85 static UnoPropertyArrayHelper
aHelper( ImplGetPropertyIds() );
90 uno::Reference
< beans::XPropertySetInfo
> UnoControlScrollBarModel::getPropertySetInfo( )
92 static uno::Reference
< beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
97 //= UnoControlScrollBarModel
99 UnoScrollBarControl::UnoScrollBarControl()
100 :maAdjustmentListeners( *this )
104 OUString
UnoScrollBarControl::GetComponentServiceName() const
109 // css::uno::XInterface
110 uno::Any
UnoScrollBarControl::queryAggregation( const uno::Type
& rType
)
112 uno::Any aRet
= ::cppu::queryInterface( rType
,
113 static_cast< awt::XAdjustmentListener
* >(this),
114 static_cast< awt::XScrollBar
* >(this) );
115 return (aRet
.hasValue() ? aRet
: UnoControlBase::queryAggregation( rType
));
118 IMPL_IMPLEMENTATION_ID( UnoScrollBarControl
)
120 // css::lang::XTypeProvider
121 css::uno::Sequence
< css::uno::Type
> UnoScrollBarControl::getTypes()
123 static const ::cppu::OTypeCollection
aTypeList(
124 cppu::UnoType
<css::lang::XTypeProvider
>::get(),
125 cppu::UnoType
<awt::XAdjustmentListener
>::get(),
126 cppu::UnoType
<awt::XScrollBar
>::get(),
127 UnoControlBase::getTypes()
129 return aTypeList
.getTypes();
132 void UnoScrollBarControl::dispose()
134 lang::EventObject aEvt
;
135 aEvt
.Source
= getXWeak();
136 maAdjustmentListeners
.disposeAndClear( aEvt
);
137 UnoControl::dispose();
140 void UnoScrollBarControl::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
)
142 UnoControl::createPeer( rxToolkit
, rParentPeer
);
144 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
145 xScrollBar
->addAdjustmentListener( this );
148 // css::awt::XAdjustmentListener
149 void UnoScrollBarControl::adjustmentValueChanged( const css::awt::AdjustmentEvent
& rEvent
)
151 switch ( rEvent
.Type
)
153 case css::awt::AdjustmentType_ADJUST_LINE
:
154 case css::awt::AdjustmentType_ADJUST_PAGE
:
155 case css::awt::AdjustmentType_ADJUST_ABS
:
157 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
159 if ( xScrollBar
.is() )
161 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::Any(xScrollBar
->getValue()), false );
167 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
172 if ( maAdjustmentListeners
.getLength() )
173 maAdjustmentListeners
.adjustmentValueChanged( rEvent
);
176 // css::awt::XScrollBar
177 void UnoScrollBarControl::addAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
> & l
)
179 maAdjustmentListeners
.addInterface( l
);
182 void UnoScrollBarControl::removeAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
> & l
)
184 maAdjustmentListeners
.removeInterface( l
);
187 void UnoScrollBarControl::setValue( sal_Int32 n
)
189 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::Any( n
), true );
192 void UnoScrollBarControl::setValues( sal_Int32 nValue
, sal_Int32 nVisible
, sal_Int32 nMax
)
194 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::Any(nValue
), true );
195 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::Any(nVisible
), true );
196 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::Any(nMax
), true );
199 sal_Int32
UnoScrollBarControl::getValue()
202 if ( getPeer().is() )
204 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
205 n
= xScrollBar
->getValue();
210 void UnoScrollBarControl::setMaximum( sal_Int32 n
)
212 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::Any( n
), true );
215 sal_Int32
UnoScrollBarControl::getMaximum()
218 if ( getPeer().is() )
220 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
221 n
= xScrollBar
->getMaximum();
226 void UnoScrollBarControl::setLineIncrement( sal_Int32 n
)
228 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT
), uno::Any( n
), true );
231 sal_Int32
UnoScrollBarControl::getLineIncrement()
234 if ( getPeer().is() )
236 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
237 n
= xScrollBar
->getLineIncrement();
242 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n
)
244 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT
), uno::Any( n
), true );
247 sal_Int32
UnoScrollBarControl::getBlockIncrement()
250 if ( getPeer().is() )
252 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
253 n
= xScrollBar
->getBlockIncrement();
258 void UnoScrollBarControl::setVisibleSize( sal_Int32 n
)
260 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::Any( n
), true );
263 sal_Int32
UnoScrollBarControl::getVisibleSize()
266 if ( getPeer().is() )
268 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
269 n
= xScrollBar
->getVisibleSize();
274 void UnoScrollBarControl::setOrientation( sal_Int32 n
)
276 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION
), uno::Any( n
), true );
279 sal_Int32
UnoScrollBarControl::getOrientation()
282 if ( getPeer().is() )
284 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
285 n
= xScrollBar
->getOrientation();
290 OUString
UnoScrollBarControl::getImplementationName()
292 return "stardiv.Toolkit.UnoScrollBarControl";
295 css::uno::Sequence
<OUString
> UnoScrollBarControl::getSupportedServiceNames()
297 auto s(UnoControlBase::getSupportedServiceNames());
298 s
.realloc(s
.getLength() + 2);
299 auto ps
= s
.getArray();
300 ps
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBar";
301 ps
[s
.getLength() - 1] = "stardiv.vcl.control.ScrollBar";
305 } // namespace toolkit
308 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
309 stardiv_Toolkit_UnoControlScrollBarModel_get_implementation(
310 css::uno::XComponentContext
*context
,
311 css::uno::Sequence
<css::uno::Any
> const &)
313 return cppu::acquire(new toolkit::UnoControlScrollBarModel(context
));
316 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
317 stardiv_Toolkit_UnoScrollBarControl_get_implementation(
318 css::uno::XComponentContext
*,
319 css::uno::Sequence
<css::uno::Any
> const &)
321 return cppu::acquire(new toolkit::UnoScrollBarControl());
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */