1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
26
27 #include <toolkit/awt/vclxwindows.hxx>
28
29 #include <helper/unopropertyarrayhelper.hxx>
30
31 namespace toolkit
32 {
33
34
35 using namespace ::com::sun::star;
36
37
38 //= UnoControlScrollBarModel
39
40
UnoControlScrollBarModel(const uno::Reference<uno::XComponentContext> & i_factory)41 UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference< uno::XComponentContext >& i_factory )
42 :UnoControlModel( i_factory )
43 {
44 UNO_CONTROL_MODEL_REGISTER_PROPERTIES<VCLXScrollBar>();
45 }
46
47
getServiceName()48 OUString UnoControlScrollBarModel::getServiceName( )
49 {
50 return OUString::createFromAscii( szServiceName_UnoControlScrollBarModel );
51 }
52
getImplementationName()53 OUString UnoControlScrollBarModel::getImplementationName()
54 {
55 return "stardiv.Toolkit.UnoControlScrollBarModel";
56 }
57
58 css::uno::Sequence<OUString>
getSupportedServiceNames()59 UnoControlScrollBarModel::getSupportedServiceNames()
60 {
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";
65 return s;
66 }
67
ImplGetDefaultValue(sal_uInt16 nPropId) const68 uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
69 {
70 switch ( nPropId )
71 {
72 case BASEPROPERTY_LIVE_SCROLL:
73 return uno::makeAny( false );
74 case BASEPROPERTY_DEFAULTCONTROL:
75 return uno::makeAny( OUString::createFromAscii( szServiceName_UnoControlScrollBar ) );
76
77 default:
78 return UnoControlModel::ImplGetDefaultValue( nPropId );
79 }
80 }
81
82
getInfoHelper()83 ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper()
84 {
85 static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() );
86 return aHelper;
87 }
88
89
getPropertySetInfo()90 uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo( )
91 {
92 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
93 return xInfo;
94 }
95
96
97 //= UnoControlScrollBarModel
98
UnoScrollBarControl()99 UnoScrollBarControl::UnoScrollBarControl()
100 :UnoControlBase()
101 ,maAdjustmentListeners( *this )
102 {
103 }
104
GetComponentServiceName()105 OUString UnoScrollBarControl::GetComponentServiceName()
106 {
107 return "ScrollBar";
108 }
109
110 // css::uno::XInterface
queryAggregation(const uno::Type & rType)111 uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType )
112 {
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 ));
117 }
118
IMPL_IMPLEMENTATION_ID(UnoScrollBarControl)119 IMPL_IMPLEMENTATION_ID( UnoScrollBarControl )
120
121 // css::lang::XTypeProvider
122 css::uno::Sequence< css::uno::Type > UnoScrollBarControl::getTypes()
123 {
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()
129 );
130 return aTypeList.getTypes();
131 }
132
dispose()133 void UnoScrollBarControl::dispose()
134 {
135 lang::EventObject aEvt;
136 aEvt.Source = static_cast<cppu::OWeakObject*>(this);
137 maAdjustmentListeners.disposeAndClear( aEvt );
138 UnoControl::dispose();
139 }
140
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)141 void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer )
142 {
143 UnoControl::createPeer( rxToolkit, rParentPeer );
144
145 uno::Reference < awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
146 xScrollBar->addAdjustmentListener( this );
147 }
148
149 // css::awt::XAdjustmentListener
adjustmentValueChanged(const css::awt::AdjustmentEvent & rEvent)150 void UnoScrollBarControl::adjustmentValueChanged( const css::awt::AdjustmentEvent& rEvent )
151 {
152 switch ( rEvent.Type )
153 {
154 case css::awt::AdjustmentType_ADJUST_LINE:
155 case css::awt::AdjustmentType_ADJUST_PAGE:
156 case css::awt::AdjustmentType_ADJUST_ABS:
157 {
158 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
159
160 if ( xScrollBar.is() )
161 {
162 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::Any(xScrollBar->getValue()), false );
163 }
164 }
165 break;
166 default:
167 {
168 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
169
170 }
171 }
172
173 if ( maAdjustmentListeners.getLength() )
174 maAdjustmentListeners.adjustmentValueChanged( rEvent );
175 }
176
177 // css::awt::XScrollBar
addAdjustmentListener(const css::uno::Reference<css::awt::XAdjustmentListener> & l)178 void UnoScrollBarControl::addAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener > & l )
179 {
180 maAdjustmentListeners.addInterface( l );
181 }
182
removeAdjustmentListener(const css::uno::Reference<css::awt::XAdjustmentListener> & l)183 void UnoScrollBarControl::removeAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener > & l )
184 {
185 maAdjustmentListeners.removeInterface( l );
186 }
187
setValue(sal_Int32 n)188 void UnoScrollBarControl::setValue( sal_Int32 n )
189 {
190 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), true );
191 }
192
setValues(sal_Int32 nValue,sal_Int32 nVisible,sal_Int32 nMax)193 void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax )
194 {
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 );
198 }
199
getValue()200 sal_Int32 UnoScrollBarControl::getValue()
201 {
202 sal_Int32 n = 0;
203 if ( getPeer().is() )
204 {
205 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
206 n = xScrollBar->getValue();
207 }
208 return n;
209 }
210
setMaximum(sal_Int32 n)211 void UnoScrollBarControl::setMaximum( sal_Int32 n )
212 {
213 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), true );
214 }
215
getMaximum()216 sal_Int32 UnoScrollBarControl::getMaximum()
217 {
218 sal_Int32 n = 0;
219 if ( getPeer().is() )
220 {
221 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
222 n = xScrollBar->getMaximum();
223 }
224 return n;
225 }
226
setLineIncrement(sal_Int32 n)227 void UnoScrollBarControl::setLineIncrement( sal_Int32 n )
228 {
229 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), true );
230 }
231
getLineIncrement()232 sal_Int32 UnoScrollBarControl::getLineIncrement()
233 {
234 sal_Int32 n = 0;
235 if ( getPeer().is() )
236 {
237 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
238 n = xScrollBar->getLineIncrement();
239 }
240 return n;
241 }
242
setBlockIncrement(sal_Int32 n)243 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n )
244 {
245 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), true );
246 }
247
getBlockIncrement()248 sal_Int32 UnoScrollBarControl::getBlockIncrement()
249 {
250 sal_Int32 n = 0;
251 if ( getPeer().is() )
252 {
253 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
254 n = xScrollBar->getBlockIncrement();
255 }
256 return n;
257 }
258
setVisibleSize(sal_Int32 n)259 void UnoScrollBarControl::setVisibleSize( sal_Int32 n )
260 {
261 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), true );
262 }
263
getVisibleSize()264 sal_Int32 UnoScrollBarControl::getVisibleSize()
265 {
266 sal_Int32 n = 0;
267 if ( getPeer().is() )
268 {
269 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
270 n = xScrollBar->getVisibleSize();
271 }
272 return n;
273 }
274
setOrientation(sal_Int32 n)275 void UnoScrollBarControl::setOrientation( sal_Int32 n )
276 {
277 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), true );
278 }
279
getOrientation()280 sal_Int32 UnoScrollBarControl::getOrientation()
281 {
282 sal_Int32 n = 0;
283 if ( getPeer().is() )
284 {
285 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
286 n = xScrollBar->getOrientation();
287 }
288 return n;
289 }
290
getImplementationName()291 OUString UnoScrollBarControl::getImplementationName()
292 {
293 return "stardiv.Toolkit.UnoScrollBarControl";
294 }
295
getSupportedServiceNames()296 css::uno::Sequence<OUString> UnoScrollBarControl::getSupportedServiceNames()
297 {
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";
302 return s;
303 }
304
305 } // namespace toolkit
306
307
308 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
stardiv_Toolkit_UnoControlScrollBarModel_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)309 stardiv_Toolkit_UnoControlScrollBarModel_get_implementation(
310 css::uno::XComponentContext *context,
311 css::uno::Sequence<css::uno::Any> const &)
312 {
313 return cppu::acquire(new toolkit::UnoControlScrollBarModel(context));
314 }
315
316 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
stardiv_Toolkit_UnoScrollBarControl_get_implementation(css::uno::XComponentContext *,css::uno::Sequence<css::uno::Any> const &)317 stardiv_Toolkit_UnoScrollBarControl_get_implementation(
318 css::uno::XComponentContext *,
319 css::uno::Sequence<css::uno::Any> const &)
320 {
321 return cppu::acquire(new toolkit::UnoScrollBarControl());
322 }
323
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
325