1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessiblescrollbar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
34 // includes --------------------------------------------------------------
35 #include <accessibility/standard/vclxaccessiblescrollbar.hxx>
37 #include <toolkit/awt/vclxwindows.hxx>
38 #include <accessibility/helper/accresmgr.hxx>
39 #include <accessibility/helper/accessiblestrings.hrc>
41 #include <unotools/accessiblestatesethelper.hxx>
42 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
44 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
45 #include <cppuhelper/typeprovider.hxx>
46 #include <comphelper/sequence.hxx>
47 #include <vcl/scrbar.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::awt
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::accessibility
;
55 using namespace ::comphelper
;
58 // -----------------------------------------------------------------------------
59 // VCLXAccessibleScrollBar
60 // -----------------------------------------------------------------------------
62 VCLXAccessibleScrollBar::VCLXAccessibleScrollBar( VCLXWindow
* pVCLWindow
)
63 :VCLXAccessibleComponent( pVCLWindow
)
67 // -----------------------------------------------------------------------------
69 VCLXAccessibleScrollBar::~VCLXAccessibleScrollBar()
73 // -----------------------------------------------------------------------------
75 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
77 switch ( rVclWindowEvent
.GetId() )
79 case VCLEVENT_SCROLLBAR_SCROLL
:
81 NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED
, Any(), Any() );
85 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
89 // -----------------------------------------------------------------------------
91 void VCLXAccessibleScrollBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
93 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
95 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
98 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
99 if ( pVCLXScrollBar
->getOrientation() == ScrollBarOrientation::HORIZONTAL
)
100 rStateSet
.AddState( AccessibleStateType::HORIZONTAL
);
101 else if ( pVCLXScrollBar
->getOrientation() == ScrollBarOrientation::VERTICAL
)
102 rStateSet
.AddState( AccessibleStateType::VERTICAL
);
106 // -----------------------------------------------------------------------------
108 // -----------------------------------------------------------------------------
110 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleScrollBar
, VCLXAccessibleComponent
, VCLXAccessibleScrollBar_BASE
)
112 // -----------------------------------------------------------------------------
114 // -----------------------------------------------------------------------------
116 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleScrollBar
, VCLXAccessibleComponent
, VCLXAccessibleScrollBar_BASE
)
118 // -----------------------------------------------------------------------------
120 // -----------------------------------------------------------------------------
122 ::rtl::OUString
VCLXAccessibleScrollBar::getImplementationName() throw (RuntimeException
)
124 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleScrollBar" );
127 // -----------------------------------------------------------------------------
129 Sequence
< ::rtl::OUString
> VCLXAccessibleScrollBar::getSupportedServiceNames() throw (RuntimeException
)
131 Sequence
< ::rtl::OUString
> aNames(1);
132 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleScrollBar" );
136 // -----------------------------------------------------------------------------
138 // -----------------------------------------------------------------------------
140 sal_Int32
VCLXAccessibleScrollBar::getAccessibleActionCount( ) throw (RuntimeException
)
142 OExternalLockGuard
aGuard( this );
147 // -----------------------------------------------------------------------------
149 sal_Bool
VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
151 OExternalLockGuard
aGuard( this );
153 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
154 throw IndexOutOfBoundsException();
156 sal_Bool bReturn
= sal_False
;
157 ScrollBar
* pScrollBar
= static_cast< ScrollBar
* >( GetWindow() );
160 ScrollType eScrollType
;
163 case 0: eScrollType
= SCROLL_LINEUP
; break;
164 case 1: eScrollType
= SCROLL_LINEDOWN
; break;
165 case 2: eScrollType
= SCROLL_PAGEUP
; break;
166 case 3: eScrollType
= SCROLL_PAGEDOWN
; break;
167 default: eScrollType
= SCROLL_DONTKNOW
; break;
169 if ( pScrollBar
->DoScrollAction( eScrollType
) )
176 // -----------------------------------------------------------------------------
178 ::rtl::OUString
VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
180 OExternalLockGuard
aGuard( this );
182 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
183 throw IndexOutOfBoundsException();
185 ::rtl::OUString sDescription
;
189 case 0: sDescription
= ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECLINE
) ); break;
190 case 1: sDescription
= ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCLINE
) ); break;
191 case 2: sDescription
= ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECBLOCK
) ); break;
192 case 3: sDescription
= ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCBLOCK
) ); break;
199 // -----------------------------------------------------------------------------
201 Reference
< XAccessibleKeyBinding
> VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
203 OExternalLockGuard
aGuard( this );
205 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
206 throw IndexOutOfBoundsException();
208 return Reference
< XAccessibleKeyBinding
>();
211 // -----------------------------------------------------------------------------
213 // -----------------------------------------------------------------------------
215 Any
VCLXAccessibleScrollBar::getCurrentValue( ) throw (RuntimeException
)
217 OExternalLockGuard
aGuard( this );
221 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
222 if ( pVCLXScrollBar
)
223 aValue
<<= (sal_Int32
) pVCLXScrollBar
->getValue();
228 // -----------------------------------------------------------------------------
230 sal_Bool
VCLXAccessibleScrollBar::setCurrentValue( const Any
& aNumber
) throw (RuntimeException
)
232 OExternalLockGuard
aGuard( this );
234 sal_Bool bReturn
= sal_False
;
236 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
237 if ( pVCLXScrollBar
)
239 sal_Int32 nValue
= 0, nValueMin
= 0, nValueMax
= 0;
240 OSL_VERIFY( aNumber
>>= nValue
);
241 OSL_VERIFY( getMinimumValue() >>= nValueMin
);
242 OSL_VERIFY( getMaximumValue() >>= nValueMax
);
244 if ( nValue
< nValueMin
)
246 else if ( nValue
> nValueMax
)
249 pVCLXScrollBar
->setValue( nValue
);
256 // -----------------------------------------------------------------------------
258 Any
VCLXAccessibleScrollBar::getMaximumValue( ) throw (RuntimeException
)
260 OExternalLockGuard
aGuard( this );
264 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
265 if ( pVCLXScrollBar
)
266 aValue
<<= (sal_Int32
) pVCLXScrollBar
->getMaximum();
271 // -----------------------------------------------------------------------------
273 Any
VCLXAccessibleScrollBar::getMinimumValue( ) throw (RuntimeException
)
275 OExternalLockGuard
aGuard( this );
278 aValue
<<= (sal_Int32
) 0;
283 // -----------------------------------------------------------------------------