xref: /AOO41X/main/toolkit/source/controls/tkscrollbar.cxx (revision b0724fc6948542b2496e16ea247f985ee5987cfe)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 #include "toolkit/controls/tkscrollbar.hxx"
27 #include "toolkit/helper/property.hxx"
28 #include "toolkit/helper/unopropertyarrayhelper.hxx"
29 #include <cppuhelper/typeprovider.hxx>
30 #include <tools/debug.hxx>
31 
32 // for introspection
33 #include <toolkit/awt/vclxwindows.hxx>
34 
35 //........................................................................
36 namespace toolkit
37 {
38 //........................................................................
39 
40     using namespace ::com::sun::star;
41 
42     //====================================================================
43     //= UnoControlScrollBarModel
44     //====================================================================
45     //--------------------------------------------------------------------
UnoControlScrollBarModel(const uno::Reference<lang::XMultiServiceFactory> & i_factory)46     UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
47         :UnoControlModel( i_factory )
48     {
49         UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar );
50     }
51 
52     //--------------------------------------------------------------------
getServiceName()53     ::rtl::OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
54     {
55         return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel );
56     }
57 
58     //--------------------------------------------------------------------
ImplGetDefaultValue(sal_uInt16 nPropId) const59     uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
60     {
61         switch ( nPropId )
62         {
63         case BASEPROPERTY_LIVE_SCROLL:
64             return uno::makeAny( (sal_Bool)sal_False );
65         case BASEPROPERTY_DEFAULTCONTROL:
66             return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar ) );
67 
68         default:
69             return UnoControlModel::ImplGetDefaultValue( nPropId );
70         }
71     }
72 
73     //--------------------------------------------------------------------
getInfoHelper()74     ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper()
75     {
76         static UnoPropertyArrayHelper* pHelper = NULL;
77         if ( !pHelper )
78         {
79             uno::Sequence<sal_Int32>    aIDs = ImplGetPropertyIds();
80             pHelper = new UnoPropertyArrayHelper( aIDs );
81         }
82         return *pHelper;
83     }
84 
85     //--------------------------------------------------------------------
getPropertySetInfo()86     uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo(  ) throw(uno::RuntimeException)
87     {
88         static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
89         return xInfo;
90     }
91 
92 
93     //====================================================================
94     //= UnoControlScrollBarModel
95     //====================================================================
UnoScrollBarControl(const uno::Reference<lang::XMultiServiceFactory> & i_factory)96     UnoScrollBarControl::UnoScrollBarControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
97         :UnoControlBase( i_factory )
98         ,maAdjustmentListeners( *this )
99     {
100     }
101 
GetComponentServiceName()102     ::rtl::OUString UnoScrollBarControl::GetComponentServiceName()
103     {
104         return ::rtl::OUString::createFromAscii( "ScrollBar" );
105     }
106 
107     // ::com::sun::star::uno::XInterface
queryAggregation(const uno::Type & rType)108     uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
109     {
110         uno::Any aRet = ::cppu::queryInterface( rType,
111                                             SAL_STATIC_CAST( awt::XAdjustmentListener*, this ),
112                                             SAL_STATIC_CAST( awt::XScrollBar*, this ) );
113         return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
114     }
115 
116     // ::com::sun::star::lang::XTypeProvider
117     IMPL_XTYPEPROVIDER_START( UnoScrollBarControl )
118         getCppuType( ( uno::Reference< awt::XAdjustmentListener>* ) NULL ),
119         getCppuType( ( uno::Reference< awt::XScrollBar>* ) NULL ),
120         UnoControlBase::getTypes()
121     IMPL_XTYPEPROVIDER_END
122 
123     void UnoScrollBarControl::dispose() throw(uno::RuntimeException)
124     {
125         lang::EventObject aEvt;
126         aEvt.Source = (::cppu::OWeakObject*)this;
127         maAdjustmentListeners.disposeAndClear( aEvt );
128         UnoControl::dispose();
129     }
130 
createPeer(const uno::Reference<awt::XToolkit> & rxToolkit,const uno::Reference<awt::XWindowPeer> & rParentPeer)131     void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer >  & rParentPeer ) throw(uno::RuntimeException)
132     {
133         UnoControl::createPeer( rxToolkit, rParentPeer );
134 
135         uno::Reference < awt::XScrollBar >  xScrollBar( getPeer(), uno::UNO_QUERY );
136         xScrollBar->addAdjustmentListener( this );
137     }
138 
139     // ::com::sun::star::awt::XAdjustmentListener
adjustmentValueChanged(const::com::sun::star::awt::AdjustmentEvent & rEvent)140     void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException)
141     {
142         switch ( rEvent.Type )
143         {
144             case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE:
145             case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE:
146             case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS:
147             {
148                 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
149 
150                 if ( xScrollBar.is() )
151                 {
152                     uno::Any aAny;
153                     aAny <<= xScrollBar->getValue();
154                     ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_False );
155                 }
156             }
157             break;
158             default:
159             {
160                 DBG_ERROR( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
161 
162             }
163         }
164 
165         if ( maAdjustmentListeners.getLength() )
166             maAdjustmentListeners.adjustmentValueChanged( rEvent );
167     }
168 
169     // ::com::sun::star::awt::XScrollBar
addAdjustmentListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XAdjustmentListener> & l)170     void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
171     {
172         maAdjustmentListeners.addInterface( l );
173     }
174 
removeAdjustmentListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XAdjustmentListener> & l)175     void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException)
176     {
177         maAdjustmentListeners.removeInterface( l );
178     }
179 
setValue(sal_Int32 n)180     void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
181     {
182         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), sal_True );
183     }
184 
setValues(sal_Int32 nValue,sal_Int32 nVisible,sal_Int32 nMax)185     void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException)
186     {
187         uno::Any aAny;
188         aAny <<= nValue;
189         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_True );
190         aAny <<= nVisible;
191         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, sal_True );
192         aAny <<= nMax;
193         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, sal_True );
194     }
195 
getValue()196     sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException)
197     {
198         sal_Int32 n = 0;
199         if ( getPeer().is() )
200         {
201             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
202             n = xScrollBar->getValue();
203         }
204         return n;
205     }
206 
setMaximum(sal_Int32 n)207     void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
208     {
209         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), sal_True );
210     }
211 
getMaximum()212     sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException)
213     {
214         sal_Int32 n = 0;
215         if ( getPeer().is() )
216         {
217             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
218             n = xScrollBar->getMaximum();
219         }
220         return n;
221     }
222 
setLineIncrement(sal_Int32 n)223     void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
224     {
225         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), sal_True );
226     }
227 
getLineIncrement()228     sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException)
229     {
230         sal_Int32 n = 0;
231         if ( getPeer().is() )
232         {
233             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
234             n = xScrollBar->getLineIncrement();
235         }
236         return n;
237     }
238 
setBlockIncrement(sal_Int32 n)239     void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
240     {
241         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), sal_True );
242     }
243 
getBlockIncrement()244     sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException)
245     {
246         sal_Int32 n = 0;
247         if ( getPeer().is() )
248         {
249             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
250             n = xScrollBar->getBlockIncrement();
251         }
252         return n;
253     }
254 
setVisibleSize(sal_Int32 n)255     void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
256     {
257         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), sal_True );
258     }
259 
getVisibleSize()260     sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException)
261     {
262         sal_Int32 n = 0;
263         if ( getPeer().is() )
264         {
265             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
266             n = xScrollBar->getVisibleSize();
267         }
268         return n;
269     }
270 
setOrientation(sal_Int32 n)271     void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException)
272     {
273         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), sal_True );
274     }
275 
getOrientation()276     sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException)
277     {
278         sal_Int32 n = 0;
279         if ( getPeer().is() )
280         {
281             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
282             n = xScrollBar->getOrientation();
283         }
284         return n;
285     }
286 
287 
288 
289 //........................................................................
290 }  // namespace toolkit
291 //........................................................................
292 
293