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( )
49 return OUString::createFromAscii( szServiceName_UnoControlScrollBarModel
);
52 OUString
UnoControlScrollBarModel::getImplementationName()
54 return OUString("stardiv.Toolkit.UnoControlScrollBarModel");
57 css::uno::Sequence
<OUString
>
58 UnoControlScrollBarModel::getSupportedServiceNames()
60 auto s(UnoControlModel::getSupportedServiceNames());
61 s
.realloc(s
.getLength() + 2);
62 s
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBarModel";
63 s
[s
.getLength() - 1] = "stardiv.vcl.controlmodel.ScrollBar";
67 uno::Any
UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
71 case BASEPROPERTY_LIVE_SCROLL
:
72 return uno::makeAny( false );
73 case BASEPROPERTY_DEFAULTCONTROL
:
74 return uno::makeAny( OUString::createFromAscii( szServiceName_UnoControlScrollBar
) );
77 return UnoControlModel::ImplGetDefaultValue( nPropId
);
82 ::cppu::IPropertyArrayHelper
& UnoControlScrollBarModel::getInfoHelper()
84 static UnoPropertyArrayHelper
* pHelper
= nullptr;
87 uno::Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
88 pHelper
= new UnoPropertyArrayHelper( aIDs
);
94 uno::Reference
< beans::XPropertySetInfo
> UnoControlScrollBarModel::getPropertySetInfo( )
96 static uno::Reference
< beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
101 //= UnoControlScrollBarModel
103 UnoScrollBarControl::UnoScrollBarControl()
105 ,maAdjustmentListeners( *this )
109 OUString
UnoScrollBarControl::GetComponentServiceName()
111 return OUString("ScrollBar");
114 // css::uno::XInterface
115 uno::Any
UnoScrollBarControl::queryAggregation( const uno::Type
& rType
)
117 uno::Any aRet
= ::cppu::queryInterface( rType
,
118 (static_cast< awt::XAdjustmentListener
* >(this)),
119 (static_cast< awt::XScrollBar
* >(this)) );
120 return (aRet
.hasValue() ? aRet
: UnoControlBase::queryAggregation( rType
));
123 // css::lang::XTypeProvider
124 IMPL_XTYPEPROVIDER_START( UnoScrollBarControl
)
125 cppu::UnoType
<awt::XAdjustmentListener
>::get(),
126 cppu::UnoType
<awt::XScrollBar
>::get(),
127 UnoControlBase::getTypes()
128 IMPL_XTYPEPROVIDER_END
130 void UnoScrollBarControl::dispose()
132 lang::EventObject aEvt
;
133 aEvt
.Source
= static_cast<cppu::OWeakObject
*>(this);
134 maAdjustmentListeners
.disposeAndClear( aEvt
);
135 UnoControl::dispose();
138 void UnoScrollBarControl::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
)
140 UnoControl::createPeer( rxToolkit
, rParentPeer
);
142 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
143 xScrollBar
->addAdjustmentListener( this );
146 // css::awt::XAdjustmentListener
147 void UnoScrollBarControl::adjustmentValueChanged( const css::awt::AdjustmentEvent
& rEvent
)
149 switch ( rEvent
.Type
)
151 case css::awt::AdjustmentType_ADJUST_LINE
:
152 case css::awt::AdjustmentType_ADJUST_PAGE
:
153 case css::awt::AdjustmentType_ADJUST_ABS
:
155 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
157 if ( xScrollBar
.is() )
159 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::Any(xScrollBar
->getValue()), false );
165 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
170 if ( maAdjustmentListeners
.getLength() )
171 maAdjustmentListeners
.adjustmentValueChanged( rEvent
);
174 // css::awt::XScrollBar
175 void UnoScrollBarControl::addAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
> & l
)
177 maAdjustmentListeners
.addInterface( l
);
180 void UnoScrollBarControl::removeAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
> & l
)
182 maAdjustmentListeners
.removeInterface( l
);
185 void UnoScrollBarControl::setValue( sal_Int32 n
)
187 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::makeAny( n
), true );
190 void UnoScrollBarControl::setValues( sal_Int32 nValue
, sal_Int32 nVisible
, sal_Int32 nMax
)
192 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::Any(nValue
), true );
193 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::Any(nVisible
), true );
194 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::Any(nMax
), true );
197 sal_Int32
UnoScrollBarControl::getValue()
200 if ( getPeer().is() )
202 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
203 n
= xScrollBar
->getValue();
208 void UnoScrollBarControl::setMaximum( sal_Int32 n
)
210 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::makeAny( n
), true );
213 sal_Int32
UnoScrollBarControl::getMaximum()
216 if ( getPeer().is() )
218 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
219 n
= xScrollBar
->getMaximum();
224 void UnoScrollBarControl::setLineIncrement( sal_Int32 n
)
226 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT
), uno::makeAny( n
), true );
229 sal_Int32
UnoScrollBarControl::getLineIncrement()
232 if ( getPeer().is() )
234 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
235 n
= xScrollBar
->getLineIncrement();
240 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n
)
242 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT
), uno::makeAny( n
), true );
245 sal_Int32
UnoScrollBarControl::getBlockIncrement()
248 if ( getPeer().is() )
250 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
251 n
= xScrollBar
->getBlockIncrement();
256 void UnoScrollBarControl::setVisibleSize( sal_Int32 n
)
258 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::makeAny( n
), true );
261 sal_Int32
UnoScrollBarControl::getVisibleSize()
264 if ( getPeer().is() )
266 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
267 n
= xScrollBar
->getVisibleSize();
272 void UnoScrollBarControl::setOrientation( sal_Int32 n
)
274 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION
), uno::makeAny( n
), true );
277 sal_Int32
UnoScrollBarControl::getOrientation()
280 if ( getPeer().is() )
282 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
283 n
= xScrollBar
->getOrientation();
288 OUString
UnoScrollBarControl::getImplementationName()
290 return OUString("stardiv.Toolkit.UnoScrollBarControl");
293 css::uno::Sequence
<OUString
> UnoScrollBarControl::getSupportedServiceNames()
295 auto s(UnoControlBase::getSupportedServiceNames());
296 s
.realloc(s
.getLength() + 2);
297 s
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBar";
298 s
[s
.getLength() - 1] = "stardiv.vcl.control.ScrollBar";
302 } // namespace toolkit
305 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
306 stardiv_Toolkit_UnoControlScrollBarModel_get_implementation(
307 css::uno::XComponentContext
*context
,
308 css::uno::Sequence
<css::uno::Any
> const &)
310 return cppu::acquire(new toolkit::UnoControlScrollBarModel(context
));
313 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
314 stardiv_Toolkit_UnoScrollBarControl_get_implementation(
315 css::uno::XComponentContext
*,
316 css::uno::Sequence
<css::uno::Any
> const &)
318 return cppu::acquire(new toolkit::UnoScrollBarControl());
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */