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/unopropertyarrayhelper.hxx"
23 #include <cppuhelper/typeprovider.hxx>
26 #include <toolkit/awt/vclxwindows.hxx>
28 //........................................................................
31 //........................................................................
33 using namespace ::com::sun::star
;
35 //====================================================================
36 //= UnoControlScrollBarModel
37 //====================================================================
38 //--------------------------------------------------------------------
39 UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference
< lang::XMultiServiceFactory
>& i_factory
)
40 :UnoControlModel( i_factory
)
42 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar
);
45 //--------------------------------------------------------------------
46 ::rtl::OUString
UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException
)
48 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel
);
51 //--------------------------------------------------------------------
52 uno::Any
UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
56 case BASEPROPERTY_LIVE_SCROLL
:
57 return uno::makeAny( (sal_Bool
)sal_False
);
58 case BASEPROPERTY_DEFAULTCONTROL
:
59 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar
) );
62 return UnoControlModel::ImplGetDefaultValue( nPropId
);
66 //--------------------------------------------------------------------
67 ::cppu::IPropertyArrayHelper
& UnoControlScrollBarModel::getInfoHelper()
69 static UnoPropertyArrayHelper
* pHelper
= NULL
;
72 uno::Sequence
<sal_Int32
> aIDs
= ImplGetPropertyIds();
73 pHelper
= new UnoPropertyArrayHelper( aIDs
);
78 //--------------------------------------------------------------------
79 uno::Reference
< beans::XPropertySetInfo
> UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException
)
81 static uno::Reference
< beans::XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
86 //====================================================================
87 //= UnoControlScrollBarModel
88 //====================================================================
89 UnoScrollBarControl::UnoScrollBarControl( const uno::Reference
< lang::XMultiServiceFactory
>& i_factory
)
90 :UnoControlBase( i_factory
)
91 ,maAdjustmentListeners( *this )
95 ::rtl::OUString
UnoScrollBarControl::GetComponentServiceName()
97 return ::rtl::OUString("ScrollBar");
100 // ::com::sun::star::uno::XInterface
101 uno::Any
UnoScrollBarControl::queryAggregation( const uno::Type
& rType
) throw(uno::RuntimeException
)
103 uno::Any aRet
= ::cppu::queryInterface( rType
,
104 (static_cast< awt::XAdjustmentListener
* >(this)),
105 (static_cast< awt::XScrollBar
* >(this)) );
106 return (aRet
.hasValue() ? aRet
: UnoControlBase::queryAggregation( rType
));
109 // ::com::sun::star::lang::XTypeProvider
110 IMPL_XTYPEPROVIDER_START( UnoScrollBarControl
)
111 getCppuType( ( uno::Reference
< awt::XAdjustmentListener
>* ) NULL
),
112 getCppuType( ( uno::Reference
< awt::XScrollBar
>* ) NULL
),
113 UnoControlBase::getTypes()
114 IMPL_XTYPEPROVIDER_END
116 void UnoScrollBarControl::dispose() throw(uno::RuntimeException
)
118 lang::EventObject aEvt
;
119 aEvt
.Source
= (::cppu::OWeakObject
*)this;
120 maAdjustmentListeners
.disposeAndClear( aEvt
);
121 UnoControl::dispose();
124 void UnoScrollBarControl::createPeer( const uno::Reference
< awt::XToolkit
> & rxToolkit
, const uno::Reference
< awt::XWindowPeer
> & rParentPeer
) throw(uno::RuntimeException
)
126 UnoControl::createPeer( rxToolkit
, rParentPeer
);
128 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
129 xScrollBar
->addAdjustmentListener( this );
132 // ::com::sun::star::awt::XAdjustmentListener
133 void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
)
135 switch ( rEvent
.Type
)
137 case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE
:
138 case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE
:
139 case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS
:
141 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
143 if ( xScrollBar
.is() )
146 aAny
<<= xScrollBar
->getValue();
147 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), aAny
, sal_False
);
153 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
158 if ( maAdjustmentListeners
.getLength() )
159 maAdjustmentListeners
.adjustmentValueChanged( rEvent
);
162 // ::com::sun::star::awt::XScrollBar
163 void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XAdjustmentListener
> & l
) throw(::com::sun::star::uno::RuntimeException
)
165 maAdjustmentListeners
.addInterface( l
);
168 void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XAdjustmentListener
> & l
) throw(::com::sun::star::uno::RuntimeException
)
170 maAdjustmentListeners
.removeInterface( l
);
173 void UnoScrollBarControl::setValue( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
)
175 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), uno::makeAny( n
), sal_True
);
178 void UnoScrollBarControl::setValues( sal_Int32 nValue
, sal_Int32 nVisible
, sal_Int32 nMax
) throw(::com::sun::star::uno::RuntimeException
)
182 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE
), aAny
, sal_True
);
184 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), aAny
, sal_True
);
186 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), aAny
, sal_True
);
189 sal_Int32
UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException
)
192 if ( getPeer().is() )
194 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
195 n
= xScrollBar
->getValue();
200 void UnoScrollBarControl::setMaximum( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
)
202 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX
), uno::makeAny( n
), sal_True
);
205 sal_Int32
UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException
)
208 if ( getPeer().is() )
210 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
211 n
= xScrollBar
->getMaximum();
216 void UnoScrollBarControl::setLineIncrement( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
)
218 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT
), uno::makeAny( n
), sal_True
);
221 sal_Int32
UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException
)
224 if ( getPeer().is() )
226 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
227 n
= xScrollBar
->getLineIncrement();
232 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
)
234 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT
), uno::makeAny( n
), sal_True
);
237 sal_Int32
UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException
)
240 if ( getPeer().is() )
242 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
243 n
= xScrollBar
->getBlockIncrement();
248 void UnoScrollBarControl::setVisibleSize( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
)
250 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE
), uno::makeAny( n
), sal_True
);
253 sal_Int32
UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException
)
256 if ( getPeer().is() )
258 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
259 n
= xScrollBar
->getVisibleSize();
264 void UnoScrollBarControl::setOrientation( sal_Int32 n
) throw(::com::sun::star::uno::RuntimeException
)
266 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION
), uno::makeAny( n
), sal_True
);
269 sal_Int32
UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException
)
272 if ( getPeer().is() )
274 uno::Reference
< awt::XScrollBar
> xScrollBar( getPeer(), uno::UNO_QUERY
);
275 n
= xScrollBar
->getOrientation();
282 //........................................................................
283 } // namespace toolkit
284 //........................................................................
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */