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 <accessibility/standard/vclxaccessiblescrollbar.hxx>
22 #include <toolkit/awt/vclxwindows.hxx>
23 #include <accessibility/helper/accresmgr.hxx>
24 #include <accessibility/helper/accessiblestrings.hrc>
26 #include <unotools/accessiblestatesethelper.hxx>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <vcl/scrbar.hxx>
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::awt
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::accessibility
;
40 using namespace ::comphelper
;
42 // -----------------------------------------------------------------------------
43 // VCLXAccessibleScrollBar
44 // -----------------------------------------------------------------------------
46 VCLXAccessibleScrollBar::VCLXAccessibleScrollBar( VCLXWindow
* pVCLWindow
)
47 :VCLXAccessibleComponent( pVCLWindow
)
51 // -----------------------------------------------------------------------------
53 VCLXAccessibleScrollBar::~VCLXAccessibleScrollBar()
57 // -----------------------------------------------------------------------------
59 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
61 switch ( rVclWindowEvent
.GetId() )
63 case VCLEVENT_SCROLLBAR_SCROLL
:
65 NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED
, Any(), Any() );
69 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
73 // -----------------------------------------------------------------------------
75 void VCLXAccessibleScrollBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
77 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
79 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
82 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
83 if ( pVCLXScrollBar
->getOrientation() == ScrollBarOrientation::HORIZONTAL
)
84 rStateSet
.AddState( AccessibleStateType::HORIZONTAL
);
85 else if ( pVCLXScrollBar
->getOrientation() == ScrollBarOrientation::VERTICAL
)
86 rStateSet
.AddState( AccessibleStateType::VERTICAL
);
90 // -----------------------------------------------------------------------------
92 // -----------------------------------------------------------------------------
94 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleScrollBar
, VCLXAccessibleComponent
, VCLXAccessibleScrollBar_BASE
)
96 // -----------------------------------------------------------------------------
98 // -----------------------------------------------------------------------------
100 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleScrollBar
, VCLXAccessibleComponent
, VCLXAccessibleScrollBar_BASE
)
102 // -----------------------------------------------------------------------------
104 // -----------------------------------------------------------------------------
106 OUString
VCLXAccessibleScrollBar::getImplementationName() throw (RuntimeException
)
108 return OUString( "com.sun.star.comp.toolkit.AccessibleScrollBar" );
111 // -----------------------------------------------------------------------------
113 Sequence
< OUString
> VCLXAccessibleScrollBar::getSupportedServiceNames() throw (RuntimeException
)
115 Sequence
< OUString
> aNames(1);
116 aNames
[0] = "com.sun.star.awt.AccessibleScrollBar";
120 // -----------------------------------------------------------------------------
122 // -----------------------------------------------------------------------------
124 sal_Int32
VCLXAccessibleScrollBar::getAccessibleActionCount( ) throw (RuntimeException
)
126 OExternalLockGuard
aGuard( this );
131 // -----------------------------------------------------------------------------
133 sal_Bool
VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
135 OExternalLockGuard
aGuard( this );
137 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
138 throw IndexOutOfBoundsException();
140 sal_Bool bReturn
= sal_False
;
141 ScrollBar
* pScrollBar
= static_cast< ScrollBar
* >( GetWindow() );
144 ScrollType eScrollType
;
147 case 0: eScrollType
= SCROLL_LINEUP
; break;
148 case 1: eScrollType
= SCROLL_LINEDOWN
; break;
149 case 2: eScrollType
= SCROLL_PAGEUP
; break;
150 case 3: eScrollType
= SCROLL_PAGEDOWN
; break;
151 default: eScrollType
= SCROLL_DONTKNOW
; break;
153 if ( pScrollBar
->DoScrollAction( eScrollType
) )
160 // -----------------------------------------------------------------------------
162 OUString
VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
164 OExternalLockGuard
aGuard( this );
166 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
167 throw IndexOutOfBoundsException();
169 OUString sDescription
;
173 case 0: sDescription
= OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECLINE
) ); break;
174 case 1: sDescription
= OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCLINE
) ); break;
175 case 2: sDescription
= OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECBLOCK
) ); break;
176 case 3: sDescription
= OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCBLOCK
) ); break;
183 // -----------------------------------------------------------------------------
185 Reference
< XAccessibleKeyBinding
> VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
187 OExternalLockGuard
aGuard( this );
189 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
190 throw IndexOutOfBoundsException();
192 return Reference
< XAccessibleKeyBinding
>();
195 // -----------------------------------------------------------------------------
197 // -----------------------------------------------------------------------------
199 Any
VCLXAccessibleScrollBar::getCurrentValue( ) throw (RuntimeException
)
201 OExternalLockGuard
aGuard( this );
205 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
206 if ( pVCLXScrollBar
)
207 aValue
<<= (sal_Int32
) pVCLXScrollBar
->getValue();
212 // -----------------------------------------------------------------------------
214 sal_Bool
VCLXAccessibleScrollBar::setCurrentValue( const Any
& aNumber
) throw (RuntimeException
)
216 OExternalLockGuard
aGuard( this );
218 sal_Bool bReturn
= sal_False
;
220 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
221 if ( pVCLXScrollBar
)
223 sal_Int32 nValue
= 0, nValueMin
= 0, nValueMax
= 0;
224 OSL_VERIFY( aNumber
>>= nValue
);
225 OSL_VERIFY( getMinimumValue() >>= nValueMin
);
226 OSL_VERIFY( getMaximumValue() >>= nValueMax
);
228 if ( nValue
< nValueMin
)
230 else if ( nValue
> nValueMax
)
233 pVCLXScrollBar
->setValue( nValue
);
240 // -----------------------------------------------------------------------------
242 Any
VCLXAccessibleScrollBar::getMaximumValue( ) throw (RuntimeException
)
244 OExternalLockGuard
aGuard( this );
248 VCLXScrollBar
* pVCLXScrollBar
= static_cast< VCLXScrollBar
* >( GetVCLXWindow() );
249 if ( pVCLXScrollBar
)
250 aValue
<<= (sal_Int32
) pVCLXScrollBar
->getMaximum();
255 // -----------------------------------------------------------------------------
257 Any
VCLXAccessibleScrollBar::getMinimumValue( ) throw (RuntimeException
)
259 OExternalLockGuard
aGuard( this );
262 aValue
<<= (sal_Int32
) 0;
267 // -----------------------------------------------------------------------------
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */