xref: /AOO41X/main/accessibility/source/standard/vclxaccessiblescrollbar.cxx (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
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_accessibility.hxx"
26 
27 // includes --------------------------------------------------------------
28 #include <accessibility/standard/vclxaccessiblescrollbar.hxx>
29 
30 #include <toolkit/awt/vclxwindows.hxx>
31 #include <accessibility/helper/accresmgr.hxx>
32 #include <accessibility/helper/accessiblestrings.hrc>
33 
34 #include <unotools/accessiblestatesethelper.hxx>
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
38 #include <cppuhelper/typeprovider.hxx>
39 #include <comphelper/sequence.hxx>
40 #include <vcl/scrbar.hxx>
41 
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::awt;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::accessibility;
48 using namespace ::comphelper;
49 
50 
51 // -----------------------------------------------------------------------------
52 // VCLXAccessibleScrollBar
53 // -----------------------------------------------------------------------------
54 
55 VCLXAccessibleScrollBar::VCLXAccessibleScrollBar( VCLXWindow* pVCLWindow )
56     :VCLXAccessibleComponent( pVCLWindow )
57 {
58 }
59 
60 // -----------------------------------------------------------------------------
61 
62 VCLXAccessibleScrollBar::~VCLXAccessibleScrollBar()
63 {
64 }
65 
66 // -----------------------------------------------------------------------------
67 
68 void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
69 {
70     switch ( rVclWindowEvent.GetId() )
71     {
72         case VCLEVENT_SCROLLBAR_SCROLL:
73         {
74             NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
75         }
76         break;
77         default:
78             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
79    }
80 }
81 
82 // -----------------------------------------------------------------------------
83 
84 void VCLXAccessibleScrollBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
85 {
86     VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
87 
88     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
89     if ( pVCLXScrollBar )
90     {
91         rStateSet.AddState( AccessibleStateType::FOCUSABLE );
92         if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL )
93             rStateSet.AddState( AccessibleStateType::HORIZONTAL );
94         else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL )
95             rStateSet.AddState( AccessibleStateType::VERTICAL );
96     }
97 }
98 
99 // -----------------------------------------------------------------------------
100 // XInterface
101 // -----------------------------------------------------------------------------
102 
103 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
104 
105 // -----------------------------------------------------------------------------
106 // XTypeProvider
107 // -----------------------------------------------------------------------------
108 
109 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE )
110 
111 // -----------------------------------------------------------------------------
112 // XServiceInfo
113 // -----------------------------------------------------------------------------
114 
115 ::rtl::OUString VCLXAccessibleScrollBar::getImplementationName() throw (RuntimeException)
116 {
117     return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleScrollBar" );
118 }
119 
120 // -----------------------------------------------------------------------------
121 
122 Sequence< ::rtl::OUString > VCLXAccessibleScrollBar::getSupportedServiceNames() throw (RuntimeException)
123 {
124     Sequence< ::rtl::OUString > aNames(1);
125     aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleScrollBar" );
126     return aNames;
127 }
128 
129 // -----------------------------------------------------------------------------
130 // XAccessibleAction
131 // -----------------------------------------------------------------------------
132 
133 sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( ) throw (RuntimeException)
134 {
135     OExternalLockGuard aGuard( this );
136 
137     return 4;
138 }
139 
140 // -----------------------------------------------------------------------------
141 
142 sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
143 {
144     OExternalLockGuard aGuard( this );
145 
146     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
147         throw IndexOutOfBoundsException();
148 
149     sal_Bool bReturn = sal_False;
150     ScrollBar* pScrollBar = static_cast< ScrollBar* >( GetWindow() );
151     if ( pScrollBar )
152     {
153         ScrollType eScrollType;
154         switch ( nIndex )
155         {
156             case 0:     eScrollType = SCROLL_LINEUP;    break;
157             case 1:     eScrollType = SCROLL_LINEDOWN;  break;
158             case 2:     eScrollType = SCROLL_PAGEUP;    break;
159             case 3:     eScrollType = SCROLL_PAGEDOWN;  break;
160             default:    eScrollType = SCROLL_DONTKNOW;  break;
161         }
162         if ( pScrollBar->DoScrollAction( eScrollType ) )
163             bReturn = sal_True;
164     }
165 
166     return bReturn;
167 }
168 
169 // -----------------------------------------------------------------------------
170 
171 ::rtl::OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
172 {
173     OExternalLockGuard aGuard( this );
174 
175     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
176         throw IndexOutOfBoundsException();
177 
178     ::rtl::OUString sDescription;
179 
180     switch ( nIndex )
181     {
182         case 0:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECLINE ) );      break;
183         case 1:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCLINE ) );      break;
184         case 2:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECBLOCK ) );     break;
185         case 3:     sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCBLOCK ) );     break;
186         default:                                                                                        break;
187     }
188 
189     return sDescription;
190 }
191 
192 // -----------------------------------------------------------------------------
193 
194 Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
195 {
196     OExternalLockGuard aGuard( this );
197 
198     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
199         throw IndexOutOfBoundsException();
200 
201     return Reference< XAccessibleKeyBinding >();
202 }
203 
204 // -----------------------------------------------------------------------------
205 // XAccessibleValue
206 // -----------------------------------------------------------------------------
207 
208 Any VCLXAccessibleScrollBar::getCurrentValue(  ) throw (RuntimeException)
209 {
210     OExternalLockGuard aGuard( this );
211 
212     Any aValue;
213 
214     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
215     if ( pVCLXScrollBar )
216         aValue <<= (sal_Int32) pVCLXScrollBar->getValue();
217 
218     return aValue;
219 }
220 
221 // -----------------------------------------------------------------------------
222 
223 sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
224 {
225     OExternalLockGuard aGuard( this );
226 
227     sal_Bool bReturn = sal_False;
228 
229     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
230     if ( pVCLXScrollBar )
231     {
232         sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
233         OSL_VERIFY( aNumber >>= nValue );
234         OSL_VERIFY( getMinimumValue() >>= nValueMin );
235         OSL_VERIFY( getMaximumValue() >>= nValueMax );
236 
237         if ( nValue < nValueMin )
238             nValue = nValueMin;
239         else if ( nValue > nValueMax )
240             nValue = nValueMax;
241 
242         pVCLXScrollBar->setValue( nValue );
243         bReturn = sal_True;
244     }
245 
246     return bReturn;
247 }
248 
249 // -----------------------------------------------------------------------------
250 
251 Any VCLXAccessibleScrollBar::getMaximumValue(  ) throw (RuntimeException)
252 {
253     OExternalLockGuard aGuard( this );
254 
255     Any aValue;
256 
257     VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() );
258     if ( pVCLXScrollBar )
259         aValue <<= (sal_Int32) pVCLXScrollBar->getMaximum();
260 
261     return aValue;
262 }
263 
264 // -----------------------------------------------------------------------------
265 
266 Any VCLXAccessibleScrollBar::getMinimumValue(  ) throw (RuntimeException)
267 {
268     OExternalLockGuard aGuard( this );
269 
270     Any aValue;
271     aValue <<= (sal_Int32) 0;
272 
273     return aValue;
274 }
275 
276 // -----------------------------------------------------------------------------
277