xref: /trunk/main/accessibility/source/standard/vclxaccessiblescrollbar.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 
31 // includes --------------------------------------------------------------
32 #include <accessibility/standard/vclxaccessiblescrollbar.hxx>
33 
34 #include <toolkit/awt/vclxwindows.hxx>
35 #include <accessibility/helper/accresmgr.hxx>
36 #include <accessibility/helper/accessiblestrings.hrc>
37 
38 #include <unotools/accessiblestatesethelper.hxx>
39 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
41 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
42 #include <cppuhelper/typeprovider.hxx>
43 #include <comphelper/sequence.hxx>
44 #include <vcl/scrbar.hxx>
45 
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::awt;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::accessibility;
52 using namespace ::comphelper;
53 
54 
55 // -----------------------------------------------------------------------------
56 // VCLXAccessibleScrollBar
57 // -----------------------------------------------------------------------------
58 
59 VCLXAccessibleScrollBar::VCLXAccessibleScrollBar( VCLXWindow* pVCLWindow )
60     :VCLXAccessibleComponent( pVCLWindow )
61 {
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 VCLXAccessibleScrollBar::~VCLXAccessibleScrollBar()
67 {
68 }
69 
70 // -----------------------------------------------------------------------------
71 
72 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
73 {
74     switch ( rVclWindowEvent.GetId() )
75     {
76         case VCLEVENT_SCROLLBAR_SCROLL:
77         {
78             NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
79         }
80         break;
81         default:
82             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
83    }
84 }
85 
86 // -----------------------------------------------------------------------------
87 
88 void VCLXAccessibleScrollBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
89 {
90     VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
91 
92     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
93     if ( pVCLXScrollBar )
94     {
95         rStateSet.AddState( AccessibleStateType::FOCUSABLE );
96         if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
97             rStateSet.AddState( AccessibleStateType::HORIZONTAL );
98         else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
99             rStateSet.AddState( AccessibleStateType::VERTICAL );
100     }
101 }
102 
103 // -----------------------------------------------------------------------------
104 // XInterface
105 // -----------------------------------------------------------------------------
106 
107 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
108 
109 // -----------------------------------------------------------------------------
110 // XTypeProvider
111 // -----------------------------------------------------------------------------
112 
113 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
114 
115 // -----------------------------------------------------------------------------
116 // XServiceInfo
117 // -----------------------------------------------------------------------------
118 
119 ::rtl::OUString VCLXAccessibleScrollBar::getImplementationName() throw (RuntimeException)
120 {
121     return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleScrollBar" );
122 }
123 
124 // -----------------------------------------------------------------------------
125 
126 Sequence< ::rtl::OUString > VCLXAccessibleScrollBar::getSupportedServiceNames() throw (RuntimeException)
127 {
128     Sequence< ::rtl::OUString > aNames(1);
129     aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleScrollBar" );
130     return aNames;
131 }
132 
133 // -----------------------------------------------------------------------------
134 // XAccessibleAction
135 // -----------------------------------------------------------------------------
136 
137 sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( ) throw (RuntimeException)
138 {
139     OExternalLockGuard aGuard( this );
140 
141     return 4;
142 }
143 
144 // -----------------------------------------------------------------------------
145 
146 sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
147 {
148     OExternalLockGuard aGuard( this );
149 
150     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
151         throw IndexOutOfBoundsException();
152 
153     sal_Bool bReturn = sal_False;
154     ScrollBar* pScrollBar = static_cast< ScrollBar* >( GetWindow() );
155     if ( pScrollBar )
156     {
157         ScrollType eScrollType;
158         switch ( nIndex )
159         {
160             case 0:     eScrollType = SCROLL_LINEUP;    break;
161             case 1:     eScrollType = SCROLL_LINEDOWN;  break;
162             case 2:     eScrollType = SCROLL_PAGEUP;    break;
163             case 3:     eScrollType = SCROLL_PAGEDOWN;  break;
164             default:    eScrollType = SCROLL_DONTKNOW;  break;
165         }
166         if ( pScrollBar->DoScrollAction( eScrollType ) )
167             bReturn = sal_True;
168     }
169 
170     return bReturn;
171 }
172 
173 // -----------------------------------------------------------------------------
174 
175 ::rtl::OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
176 {
177     OExternalLockGuard aGuard( this );
178 
179     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
180         throw IndexOutOfBoundsException();
181 
182     ::rtl::OUString sDescription;
183 
184     switch ( nIndex )
185     {
186         case 0:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECLINE ) );      break;
187         case 1:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCLINE ) );      break;
188         case 2:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECBLOCK ) );     break;
189         case 3:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCBLOCK ) );     break;
190         default:                                                                                        break;
191     }
192 
193     return sDescription;
194 }
195 
196 // -----------------------------------------------------------------------------
197 
198 Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
199 {
200     OExternalLockGuard aGuard( this );
201 
202     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
203         throw IndexOutOfBoundsException();
204 
205     return Reference< XAccessibleKeyBinding >();
206 }
207 
208 // -----------------------------------------------------------------------------
209 // XAccessibleValue
210 // -----------------------------------------------------------------------------
211 
212 Any VCLXAccessibleScrollBar::getCurrentValue(  ) throw (RuntimeException)
213 {
214     OExternalLockGuard aGuard( this );
215 
216     Any aValue;
217 
218     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
219     if ( pVCLXScrollBar )
220         aValue <<= (sal_Int32) pVCLXScrollBar->getValue();
221 
222     return aValue;
223 }
224 
225 // -----------------------------------------------------------------------------
226 
227 sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
228 {
229     OExternalLockGuard aGuard( this );
230 
231     sal_Bool bReturn = sal_False;
232 
233     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
234     if ( pVCLXScrollBar )
235     {
236         sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
237         OSL_VERIFY( aNumber >>= nValue );
238         OSL_VERIFY( getMinimumValue() >>= nValueMin );
239         OSL_VERIFY( getMaximumValue() >>= nValueMax );
240 
241         if ( nValue < nValueMin )
242             nValue = nValueMin;
243         else if ( nValue > nValueMax )
244             nValue = nValueMax;
245 
246         pVCLXScrollBar->setValue( nValue );
247         bReturn = sal_True;
248     }
249 
250     return bReturn;
251 }
252 
253 // -----------------------------------------------------------------------------
254 
255 Any VCLXAccessibleScrollBar::getMaximumValue(  ) throw (RuntimeException)
256 {
257     OExternalLockGuard aGuard( this );
258 
259     Any aValue;
260 
261     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
262     if ( pVCLXScrollBar )
263         aValue <<= (sal_Int32) pVCLXScrollBar->getMaximum();
264 
265     return aValue;
266 }
267 
268 // -----------------------------------------------------------------------------
269 
270 Any VCLXAccessibleScrollBar::getMinimumValue(  ) throw (RuntimeException)
271 {
272     OExternalLockGuard aGuard( this );
273 
274     Any aValue;
275     aValue <<= (sal_Int32) 0;
276 
277     return aValue;
278 }
279 
280 // -----------------------------------------------------------------------------
281