Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <accessibility/standard/vclxaccessiblebutton.hxx>
30 : : #include <accessibility/helper/accresmgr.hxx>
31 : : #include <accessibility/helper/accessiblestrings.hrc>
32 : :
33 : : #include <unotools/accessiblestatesethelper.hxx>
34 : : #include <comphelper/accessiblekeybindinghelper.hxx>
35 : : #include <com/sun/star/awt/KeyModifier.hpp>
36 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
37 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
38 : : #include <cppuhelper/typeprovider.hxx>
39 : : #include <comphelper/sequence.hxx>
40 : :
41 : : #include <vcl/button.hxx>
42 : :
43 : : using namespace ::com::sun::star;
44 : : using namespace ::com::sun::star::uno;
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 : : // VCLXAccessibleButton
53 : : // -----------------------------------------------------------------------------
54 : :
55 : 32 : VCLXAccessibleButton::VCLXAccessibleButton( VCLXWindow* pVCLWindow )
56 : 32 : :VCLXAccessibleTextComponent( pVCLWindow )
57 : : {
58 : 32 : }
59 : :
60 : : // -----------------------------------------------------------------------------
61 : :
62 : 32 : VCLXAccessibleButton::~VCLXAccessibleButton()
63 : : {
64 [ - + ]: 64 : }
65 : :
66 : : // -----------------------------------------------------------------------------
67 : :
68 : 34 : void VCLXAccessibleButton::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
69 : : {
70 [ - + ]: 34 : switch ( rVclWindowEvent.GetId() )
71 : : {
72 : : case VCLEVENT_PUSHBUTTON_TOGGLE:
73 : : {
74 : 0 : Any aOldValue;
75 : 0 : Any aNewValue;
76 : :
77 [ # # ]: 0 : PushButton* pButton = (PushButton*) GetWindow();
78 [ # # ][ # # ]: 0 : if ( pButton && pButton->GetState() == STATE_CHECK )
[ # # ]
79 [ # # ]: 0 : aNewValue <<= AccessibleStateType::CHECKED;
80 : : else
81 [ # # ]: 0 : aOldValue <<= AccessibleStateType::CHECKED;
82 : :
83 [ # # ]: 0 : NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
84 : : }
85 : 0 : break;
86 : : default:
87 : 34 : VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
88 : : }
89 : 34 : }
90 : :
91 : : // -----------------------------------------------------------------------------
92 : :
93 : 30 : void VCLXAccessibleButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
94 : : {
95 : 30 : VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
96 : :
97 : 30 : PushButton* pButton = (PushButton*) GetWindow();
98 [ + - ]: 30 : if ( pButton )
99 : : {
100 : 30 : rStateSet.AddState( AccessibleStateType::FOCUSABLE );
101 : :
102 [ - + ]: 30 : if ( pButton->GetState() == STATE_CHECK )
103 : 0 : rStateSet.AddState( AccessibleStateType::CHECKED );
104 : :
105 [ - + ]: 30 : if ( pButton->IsPressed() )
106 : 0 : rStateSet.AddState( AccessibleStateType::PRESSED );
107 : : }
108 : 30 : }
109 : :
110 : : // -----------------------------------------------------------------------------
111 : : // XInterface
112 : : // -----------------------------------------------------------------------------
113 : :
114 [ + + ][ + - ]: 1006 : IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleButton, VCLXAccessibleTextComponent, VCLXAccessibleButton_BASE )
115 : :
116 : : // -----------------------------------------------------------------------------
117 : : // XTypeProvider
118 : : // -----------------------------------------------------------------------------
119 : :
120 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleButton, VCLXAccessibleTextComponent, VCLXAccessibleButton_BASE )
[ # # ]
121 : :
122 : : // -----------------------------------------------------------------------------
123 : : // XServiceInfo
124 : : // -----------------------------------------------------------------------------
125 : :
126 : 0 : ::rtl::OUString VCLXAccessibleButton::getImplementationName() throw (RuntimeException)
127 : : {
128 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.toolkit.AccessibleButton") );
129 : : }
130 : :
131 : : // -----------------------------------------------------------------------------
132 : :
133 : 0 : Sequence< ::rtl::OUString > VCLXAccessibleButton::getSupportedServiceNames() throw (RuntimeException)
134 : : {
135 : 0 : Sequence< ::rtl::OUString > aNames(1);
136 [ # # ][ # # ]: 0 : aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleButton") );
137 : 0 : return aNames;
138 : : }
139 : :
140 : : // -----------------------------------------------------------------------------
141 : : // XAccessibleContext
142 : : // -----------------------------------------------------------------------------
143 : :
144 : 0 : ::rtl::OUString VCLXAccessibleButton::getAccessibleName( ) throw (RuntimeException)
145 : : {
146 [ # # ]: 0 : OExternalLockGuard aGuard( this );
147 : :
148 [ # # ]: 0 : ::rtl::OUString aName( VCLXAccessibleTextComponent::getAccessibleName() );
149 : 0 : sal_Int32 nLength = aName.getLength();
150 : :
151 [ # # ][ # # ]: 0 : if ( nLength >= 3 && aName.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("..."), nLength - 3 ) )
[ # # ]
152 : : {
153 [ # # ]: 0 : if ( nLength == 3 )
154 : : {
155 : : // it's a browse button
156 [ # # ]: 0 : aName = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_NAME_BROWSEBUTTON ) );
157 : : }
158 : : else
159 : : {
160 : : // remove the three trailing dots
161 : 0 : aName = aName.copy( 0, nLength - 3 );
162 : : }
163 : : }
164 [ # # ][ # # ]: 0 : else if ( nLength >= 3 && aName.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("<< "), 0 ) )
[ # # ]
165 : : {
166 : : // remove the leading symbols
167 : 0 : aName = aName.copy( 3, nLength - 3 );
168 : : }
169 [ # # ][ # # ]: 0 : else if ( nLength >= 3 && aName.matchAsciiL( RTL_CONSTASCII_STRINGPARAM(" >>"), nLength - 3 ) )
[ # # ]
170 : : {
171 : : // remove the trailing symbols
172 : 0 : aName = aName.copy( 0, nLength - 3 );
173 : : }
174 : :
175 [ # # ]: 0 : return aName;
176 : : }
177 : :
178 : : // -----------------------------------------------------------------------------
179 : : // XAccessibleAction
180 : : // -----------------------------------------------------------------------------
181 : :
182 : 6 : sal_Int32 VCLXAccessibleButton::getAccessibleActionCount( ) throw (RuntimeException)
183 : : {
184 [ + - ]: 6 : OExternalLockGuard aGuard( this );
185 : :
186 [ + - ]: 6 : return 1;
187 : : }
188 : :
189 : : // -----------------------------------------------------------------------------
190 : :
191 : 2 : sal_Bool VCLXAccessibleButton::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
192 : : {
193 [ + - ]: 2 : OExternalLockGuard aGuard( this );
194 : :
195 [ + - ][ + - ]: 2 : if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
[ - + ][ - + ]
196 [ # # ]: 0 : throw IndexOutOfBoundsException();
197 : :
198 [ + - ]: 2 : PushButton* pButton = (PushButton*) GetWindow();
199 [ + - ]: 2 : if ( pButton )
200 [ + - ]: 2 : pButton->Click();
201 : :
202 [ + - ]: 2 : return sal_True;
203 : : }
204 : :
205 : : // -----------------------------------------------------------------------------
206 : :
207 : 2 : ::rtl::OUString VCLXAccessibleButton::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
208 : : {
209 [ + - ]: 2 : OExternalLockGuard aGuard( this );
210 : :
211 [ + - ][ + - ]: 2 : if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
[ - + ][ - + ]
212 [ # # ]: 0 : throw IndexOutOfBoundsException();
213 : :
214 [ + - ][ + - ]: 2 : return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
215 : : }
216 : :
217 : : // -----------------------------------------------------------------------------
218 : :
219 : 0 : Reference< XAccessibleKeyBinding > VCLXAccessibleButton::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
220 : : {
221 [ # # ]: 0 : OExternalLockGuard aGuard( this );
222 : :
223 [ # # ][ # # ]: 0 : if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
[ # # ][ # # ]
224 [ # # ]: 0 : throw IndexOutOfBoundsException();
225 : :
226 [ # # ]: 0 : OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper();
227 [ # # ][ # # ]: 0 : Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper;
228 : :
229 [ # # ]: 0 : Window* pWindow = GetWindow();
230 [ # # ]: 0 : if ( pWindow )
231 : : {
232 [ # # ]: 0 : KeyEvent aKeyEvent = pWindow->GetActivationKey();
233 : 0 : KeyCode aKeyCode = aKeyEvent.GetKeyCode();
234 [ # # ]: 0 : if ( aKeyCode.GetCode() != 0 )
235 : : {
236 : 0 : awt::KeyStroke aKeyStroke;
237 : 0 : aKeyStroke.Modifiers = 0;
238 [ # # ]: 0 : if ( aKeyCode.IsShift() )
239 : 0 : aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
240 [ # # ]: 0 : if ( aKeyCode.IsMod1() )
241 : 0 : aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
242 [ # # ]: 0 : if ( aKeyCode.IsMod2() )
243 : 0 : aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
244 [ # # ]: 0 : if ( aKeyCode.IsMod3() )
245 : 0 : aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
246 : 0 : aKeyStroke.KeyCode = aKeyCode.GetCode();
247 : 0 : aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
248 [ # # ]: 0 : aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
249 [ # # ]: 0 : pKeyBindingHelper->AddKeyBinding( aKeyStroke );
250 : : }
251 : : }
252 : :
253 [ # # ]: 0 : return xKeyBinding;
254 : : }
255 : :
256 : : // -----------------------------------------------------------------------------
257 : : // XAccessibleValue
258 : : // -----------------------------------------------------------------------------
259 : :
260 : 0 : Any VCLXAccessibleButton::getCurrentValue( ) throw (RuntimeException)
261 : : {
262 [ # # ]: 0 : OExternalLockGuard aGuard( this );
263 : :
264 : 0 : Any aValue;
265 : :
266 [ # # ]: 0 : PushButton* pButton = (PushButton*) GetWindow();
267 [ # # ]: 0 : if ( pButton )
268 [ # # ]: 0 : aValue <<= (sal_Int32) pButton->IsPressed();
269 : :
270 [ # # ]: 0 : return aValue;
271 : : }
272 : :
273 : : // -----------------------------------------------------------------------------
274 : :
275 : 0 : sal_Bool VCLXAccessibleButton::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
276 : : {
277 [ # # ]: 0 : OExternalLockGuard aGuard( this );
278 : :
279 : 0 : sal_Bool bReturn = sal_False;
280 : :
281 [ # # ]: 0 : PushButton* pButton = (PushButton*) GetWindow();
282 [ # # ]: 0 : if ( pButton )
283 : : {
284 : 0 : sal_Int32 nValue = 0;
285 : 0 : OSL_VERIFY( aNumber >>= nValue );
286 : :
287 [ # # ]: 0 : if ( nValue < 0 )
288 : 0 : nValue = 0;
289 [ # # ]: 0 : else if ( nValue > 1 )
290 : 0 : nValue = 1;
291 : :
292 [ # # ]: 0 : pButton->SetPressed( (sal_Bool) nValue );
293 : 0 : bReturn = sal_True;
294 : : }
295 : :
296 [ # # ]: 0 : return bReturn;
297 : : }
298 : :
299 : : // -----------------------------------------------------------------------------
300 : :
301 : 0 : Any VCLXAccessibleButton::getMaximumValue( ) throw (RuntimeException)
302 : : {
303 [ # # ]: 0 : OExternalLockGuard aGuard( this );
304 : :
305 : 0 : Any aValue;
306 [ # # ]: 0 : aValue <<= (sal_Int32) 1;
307 : :
308 [ # # ]: 0 : return aValue;
309 : : }
310 : :
311 : : // -----------------------------------------------------------------------------
312 : :
313 : 0 : Any VCLXAccessibleButton::getMinimumValue( ) throw (RuntimeException)
314 : : {
315 [ # # ]: 0 : OExternalLockGuard aGuard( this );
316 : :
317 : 0 : Any aValue;
318 [ # # ]: 0 : aValue <<= (sal_Int32) 0;
319 : :
320 [ # # ]: 0 : return aValue;
321 : : }
322 : :
323 : : // -----------------------------------------------------------------------------
324 : :
325 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|