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 <toolkit/helper/servicenames.hxx>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <cppuhelper/typeprovider.hxx>
25 #include <cppuhelper/queryinterface.hxx>
27 #include <toolkit/awt/vclxwindows.hxx>
29 #include <helper/unopropertyarrayhelper.hxx>
35 using namespace ::com::sun::star
;
38 //= UnoControlScrollBarModel
41 UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference
< uno::XComponentContext
>& i_factory
)
42 :UnoControlModel( i_factory
)
44 UNO_CONTROL_MODEL_REGISTER_PROPERTIES
<VCLXScrollBar
>();
48 OUString
UnoControlScrollBarModel::getServiceName( )
50 return OUString::createFromAscii( szServiceName_UnoControlScrollBarModel
);
53 OUString
UnoControlScrollBarModel::getImplementationName()
55 return OUString("stardiv.Toolkit.UnoControlScrollBarModel");
58 css::uno::Sequence
<OUString
>
59 UnoControlScrollBarModel::getSupportedServiceNames()
61 auto s(UnoControlModel::getSupportedServiceNames());
62 s
.realloc(s
.getLength() + 2);
63 s
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBarModel";
64 s
[s
.getLength() - 1] = "stardiv.vcl.controlmodel.ScrollBar";
68 uno::Any
UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
72 case BASEPROPERTY_LIVE_SCROLL
:
73 return uno::makeAny( false );
74 case BASEPROPERTY_DEFAULTCONTROL
:
75 return uno::makeAny( OUString::createFromAscii( szServiceName_UnoControlScrollBar
) );
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()
101 ,maAdjustmentListeners( *this )
105 OUString
UnoScrollBarControl::GetComponentServiceName()
107 return OUString("ScrollBar");
110 // css::uno::XInterface
111 uno::Any
UnoScrollBarControl::queryAggregation( const uno::Type
& rType
)
113 uno::Any aRet
= ::cppu::queryInterface( rType
,
114 static_cast< awt::XAdjustmentListener
* >(this),
115 static_cast< awt::XScrollBar
* >(this) );
116 return (aRet
.hasValue() ? aRet
: UnoControlBase::queryAggregation( rType
));
119 IMPL_IMPLEMENTATION_ID( UnoScrollBarControl
)
121 // css::lang::XTypeProvider
122 css::uno::Sequence
< css::uno::Type
> UnoScrollBarControl::getTypes()
124 static const ::cppu::OTypeCollection
aTypeList(
125 cppu::UnoType
<css::lang::XTypeProvider
>::get(),
126 cppu::UnoType
<awt::XAdjustmentListener
>::get(),
127 cppu::UnoType
<awt::XScrollBar
>::get(),
128 UnoControlBase::getTypes()
130 return aTypeList
.getTypes();
133 void UnoScrollBarControl::dispose()
135 lang::EventObject aEvt
;
136 aEvt
.Source
= static_cast<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
)
143 UnoControl::createPeer( rxToolkit
, rParentPeer
);
145 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
146 xScrollBar
->addAdjustmentListener( this );
149 // css::awt::XAdjustmentListener
150 void UnoScrollBarControl::adjustmentValueChanged( const css::awt::AdjustmentEvent
& rEvent
)
152 switch ( rEvent
.Type
)
154 case css::awt::AdjustmentType_ADJUST_LINE
:
155 case css::awt::AdjustmentType_ADJUST_PAGE
:
156 case css::awt::AdjustmentType_ADJUST_ABS
:
158 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
160 if ( xScrollBar
.is() )
162 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::Any(xScrollBar
->getValue()), false );
168 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
173 if ( maAdjustmentListeners
.getLength() )
174 maAdjustmentListeners
.adjustmentValueChanged( rEvent
);
177 // css::awt::XScrollBar
178 void UnoScrollBarControl::addAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
> & l
)
180 maAdjustmentListeners
.addInterface( l
);
183 void UnoScrollBarControl::removeAdjustmentListener( const css::uno::Reference
< css::awt::XAdjustmentListener
> & l
)
185 maAdjustmentListeners
.removeInterface( l
);
188 void UnoScrollBarControl::setValue( sal_Int32 n
)
190 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::makeAny( n
), true );
193 void UnoScrollBarControl::setValues( sal_Int32 nValue
, sal_Int32 nVisible
, sal_Int32 nMax
)
195 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::Any(nValue
), true );
196 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::Any(nVisible
), true );
197 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::Any(nMax
), true );
200 sal_Int32
UnoScrollBarControl::getValue()
203 if ( getPeer().is() )
205 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
206 n
= xScrollBar
->getValue();
211 void UnoScrollBarControl::setMaximum( sal_Int32 n
)
213 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::makeAny( n
), true );
216 sal_Int32
UnoScrollBarControl::getMaximum()
219 if ( getPeer().is() )
221 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
222 n
= xScrollBar
->getMaximum();
227 void UnoScrollBarControl::setLineIncrement( sal_Int32 n
)
229 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT
), uno::makeAny( n
), true );
232 sal_Int32
UnoScrollBarControl::getLineIncrement()
235 if ( getPeer().is() )
237 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
238 n
= xScrollBar
->getLineIncrement();
243 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n
)
245 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT
), uno::makeAny( n
), true );
248 sal_Int32
UnoScrollBarControl::getBlockIncrement()
251 if ( getPeer().is() )
253 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
254 n
= xScrollBar
->getBlockIncrement();
259 void UnoScrollBarControl::setVisibleSize( sal_Int32 n
)
261 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::makeAny( n
), true );
264 sal_Int32
UnoScrollBarControl::getVisibleSize()
267 if ( getPeer().is() )
269 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
270 n
= xScrollBar
->getVisibleSize();
275 void UnoScrollBarControl::setOrientation( sal_Int32 n
)
277 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION
), uno::makeAny( n
), true );
280 sal_Int32
UnoScrollBarControl::getOrientation()
283 if ( getPeer().is() )
285 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
286 n
= xScrollBar
->getOrientation();
291 OUString
UnoScrollBarControl::getImplementationName()
293 return OUString("stardiv.Toolkit.UnoScrollBarControl");
296 css::uno::Sequence
<OUString
> UnoScrollBarControl::getSupportedServiceNames()
298 auto s(UnoControlBase::getSupportedServiceNames());
299 s
.realloc(s
.getLength() + 2);
300 s
[s
.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBar";
301 s
[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: */