Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "toolkit/controls/tkscrollbar.hxx"
30 : : #include "toolkit/helper/property.hxx"
31 : : #include "toolkit/helper/unopropertyarrayhelper.hxx"
32 : : #include <cppuhelper/typeprovider.hxx>
33 : :
34 : : // for introspection
35 : : #include <toolkit/awt/vclxwindows.hxx>
36 : :
37 : : //........................................................................
38 : : namespace toolkit
39 : : {
40 : : //........................................................................
41 : :
42 : : using namespace ::com::sun::star;
43 : :
44 : : //====================================================================
45 : : //= UnoControlScrollBarModel
46 : : //====================================================================
47 : : //--------------------------------------------------------------------
48 : 20 : UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
49 : 20 : :UnoControlModel( i_factory )
50 : : {
51 [ + - ][ + - ]: 20 : UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar );
[ + - ]
52 : 20 : }
53 : :
54 : : //--------------------------------------------------------------------
55 : 2 : ::rtl::OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
56 : : {
57 : 2 : return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel );
58 : : }
59 : :
60 : : //--------------------------------------------------------------------
61 : 532 : uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
62 : : {
63 [ + + + ]: 532 : switch ( nPropId )
64 : : {
65 : : case BASEPROPERTY_LIVE_SCROLL:
66 [ + - ]: 24 : return uno::makeAny( (sal_Bool)sal_False );
67 : : case BASEPROPERTY_DEFAULTCONTROL:
68 [ + - ]: 24 : return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar ) );
69 : :
70 : : default:
71 : 532 : return UnoControlModel::ImplGetDefaultValue( nPropId );
72 : : }
73 : : }
74 : :
75 : : //--------------------------------------------------------------------
76 : 3643 : ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper()
77 : : {
78 : : static UnoPropertyArrayHelper* pHelper = NULL;
79 [ + + ]: 3643 : if ( !pHelper )
80 : : {
81 [ + - ]: 4 : uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
82 [ + - ][ + - ]: 4 : pHelper = new UnoPropertyArrayHelper( aIDs );
83 : : }
84 : 3643 : return *pHelper;
85 : : }
86 : :
87 : : //--------------------------------------------------------------------
88 : 56 : uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException)
89 : : {
90 [ + + ][ + - ]: 56 : static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
[ + - ][ + - ]
[ # # ]
91 : 56 : return xInfo;
92 : : }
93 : :
94 : :
95 : : //====================================================================
96 : : //= UnoControlScrollBarModel
97 : : //====================================================================
98 : 2 : UnoScrollBarControl::UnoScrollBarControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
99 : : :UnoControlBase( i_factory )
100 [ + - ]: 2 : ,maAdjustmentListeners( *this )
101 : : {
102 : 2 : }
103 : :
104 : 2 : ::rtl::OUString UnoScrollBarControl::GetComponentServiceName()
105 : : {
106 : 2 : return ::rtl::OUString("ScrollBar");
107 : : }
108 : :
109 : : // ::com::sun::star::uno::XInterface
110 : 62 : uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
111 : : {
112 : : uno::Any aRet = ::cppu::queryInterface( rType,
113 : : (static_cast< awt::XAdjustmentListener* >(this)),
114 [ + - ]: 62 : (static_cast< awt::XScrollBar* >(this)) );
115 [ - + ][ + - ]: 62 : return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
116 : : }
117 : :
118 : : // ::com::sun::star::lang::XTypeProvider
119 [ # # ][ # # ]: 0 : IMPL_XTYPEPROVIDER_START( UnoScrollBarControl )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
120 [ # # ]: 0 : getCppuType( ( uno::Reference< awt::XAdjustmentListener>* ) NULL ),
121 [ # # ]: 0 : getCppuType( ( uno::Reference< awt::XScrollBar>* ) NULL ),
122 : : UnoControlBase::getTypes()
123 [ # # ][ # # ]: 0 : IMPL_XTYPEPROVIDER_END
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
124 : :
125 : 2 : void UnoScrollBarControl::dispose() throw(uno::RuntimeException)
126 : : {
127 [ + - ]: 2 : lang::EventObject aEvt;
128 [ + - ]: 2 : aEvt.Source = (::cppu::OWeakObject*)this;
129 [ + - ]: 2 : maAdjustmentListeners.disposeAndClear( aEvt );
130 [ + - ][ + - ]: 2 : UnoControl::dispose();
131 : 2 : }
132 : :
133 : 4 : void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException)
134 : : {
135 [ + - ]: 4 : UnoControl::createPeer( rxToolkit, rParentPeer );
136 : :
137 [ + - ][ + - ]: 4 : uno::Reference < awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
138 [ + - ][ + - ]: 4 : xScrollBar->addAdjustmentListener( this );
[ + - ]
139 : 4 : }
140 : :
141 : : // ::com::sun::star::awt::XAdjustmentListener
142 : 0 : void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException)
143 : : {
144 [ # # ]: 0 : switch ( rEvent.Type )
145 : : {
146 : : case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE:
147 : : case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE:
148 : : case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS:
149 : : {
150 [ # # ][ # # ]: 0 : uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
151 : :
152 [ # # ]: 0 : if ( xScrollBar.is() )
153 : : {
154 : 0 : uno::Any aAny;
155 [ # # ][ # # ]: 0 : aAny <<= xScrollBar->getValue();
[ # # ]
156 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_False );
157 : 0 : }
158 : : }
159 : 0 : break;
160 : : default:
161 : : {
162 : : OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
163 : :
164 : : }
165 : : }
166 : :
167 [ # # ]: 0 : if ( maAdjustmentListeners.getLength() )
168 : 0 : maAdjustmentListeners.adjustmentValueChanged( rEvent );
169 : 0 : }
170 : :
171 : : // ::com::sun::star::awt::XScrollBar
172 : 0 : void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
173 : : {
174 : 0 : maAdjustmentListeners.addInterface( l );
175 : 0 : }
176 : :
177 : 0 : void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
178 : : {
179 : 0 : maAdjustmentListeners.removeInterface( l );
180 : 0 : }
181 : :
182 : 0 : void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
183 : : {
184 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), sal_True );
185 : 0 : }
186 : :
187 : 0 : void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException)
188 : : {
189 : 0 : uno::Any aAny;
190 [ # # ]: 0 : aAny <<= nValue;
191 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_True );
192 [ # # ]: 0 : aAny <<= nVisible;
193 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, sal_True );
194 [ # # ]: 0 : aAny <<= nMax;
195 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, sal_True );
196 : 0 : }
197 : :
198 : 0 : sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException)
199 : : {
200 : 0 : sal_Int32 n = 0;
201 [ # # ]: 0 : if ( getPeer().is() )
202 : : {
203 [ # # ][ # # ]: 0 : uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
204 [ # # ][ # # ]: 0 : n = xScrollBar->getValue();
205 : : }
206 : 0 : return n;
207 : : }
208 : :
209 : 0 : void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
210 : : {
211 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), sal_True );
212 : 0 : }
213 : :
214 : 0 : sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException)
215 : : {
216 : 0 : sal_Int32 n = 0;
217 [ # # ]: 0 : if ( getPeer().is() )
218 : : {
219 [ # # ][ # # ]: 0 : uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
220 [ # # ][ # # ]: 0 : n = xScrollBar->getMaximum();
221 : : }
222 : 0 : return n;
223 : : }
224 : :
225 : 0 : void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
226 : : {
227 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), sal_True );
228 : 0 : }
229 : :
230 : 0 : sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException)
231 : : {
232 : 0 : sal_Int32 n = 0;
233 [ # # ]: 0 : if ( getPeer().is() )
234 : : {
235 [ # # ][ # # ]: 0 : uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
236 [ # # ][ # # ]: 0 : n = xScrollBar->getLineIncrement();
237 : : }
238 : 0 : return n;
239 : : }
240 : :
241 : 0 : void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
242 : : {
243 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), sal_True );
244 : 0 : }
245 : :
246 : 0 : sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException)
247 : : {
248 : 0 : sal_Int32 n = 0;
249 [ # # ]: 0 : if ( getPeer().is() )
250 : : {
251 [ # # ][ # # ]: 0 : uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
252 [ # # ][ # # ]: 0 : n = xScrollBar->getBlockIncrement();
253 : : }
254 : 0 : return n;
255 : : }
256 : :
257 : 0 : void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
258 : : {
259 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), sal_True );
260 : 0 : }
261 : :
262 : 0 : sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException)
263 : : {
264 : 0 : sal_Int32 n = 0;
265 [ # # ]: 0 : if ( getPeer().is() )
266 : : {
267 [ # # ][ # # ]: 0 : uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
268 [ # # ][ # # ]: 0 : n = xScrollBar->getVisibleSize();
269 : : }
270 : 0 : return n;
271 : : }
272 : :
273 : 0 : void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
274 : : {
275 [ # # ][ # # ]: 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), sal_True );
276 : 0 : }
277 : :
278 : 0 : sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException)
279 : : {
280 : 0 : sal_Int32 n = 0;
281 [ # # ]: 0 : if ( getPeer().is() )
282 : : {
283 [ # # ][ # # ]: 0 : uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
284 [ # # ][ # # ]: 0 : n = xScrollBar->getOrientation();
285 : : }
286 : 0 : return n;
287 : : }
288 : :
289 : :
290 : :
291 : : //........................................................................
292 : : } // namespace toolkit
293 : : //........................................................................
294 : :
295 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|