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: vclxaccessiblebutton.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/vclxaccessiblebutton.hxx>
36 #include <accessibility/helper/accresmgr.hxx>
37 #include <accessibility/helper/accessiblestrings.hrc>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <comphelper/accessiblekeybindinghelper.hxx>
41 #include <com/sun/star/awt/KeyModifier.hpp>
42 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
44 #include <cppuhelper/typeprovider.hxx>
45 #include <comphelper/sequence.hxx>
47 #include <vcl/button.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::beans
;
53 using namespace ::com::sun::star::accessibility
;
54 using namespace ::comphelper
;
57 // -----------------------------------------------------------------------------
58 // VCLXAccessibleButton
59 // -----------------------------------------------------------------------------
61 VCLXAccessibleButton::VCLXAccessibleButton( VCLXWindow
* pVCLWindow
)
62 :VCLXAccessibleTextComponent( pVCLWindow
)
66 // -----------------------------------------------------------------------------
68 VCLXAccessibleButton::~VCLXAccessibleButton()
72 // -----------------------------------------------------------------------------
74 void VCLXAccessibleButton::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
76 switch ( rVclWindowEvent
.GetId() )
78 case VCLEVENT_PUSHBUTTON_TOGGLE
:
83 PushButton
* pButton
= (PushButton
*) GetWindow();
84 if ( pButton
&& pButton
->GetState() == STATE_CHECK
)
85 aNewValue
<<= AccessibleStateType::CHECKED
;
87 aOldValue
<<= AccessibleStateType::CHECKED
;
89 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
93 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
97 // -----------------------------------------------------------------------------
99 void VCLXAccessibleButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
101 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
103 PushButton
* pButton
= (PushButton
*) GetWindow();
106 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
108 if ( pButton
->GetState() == STATE_CHECK
)
109 rStateSet
.AddState( AccessibleStateType::CHECKED
);
111 if ( pButton
->IsPressed() )
112 rStateSet
.AddState( AccessibleStateType::PRESSED
);
116 // -----------------------------------------------------------------------------
118 // -----------------------------------------------------------------------------
120 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleButton
, VCLXAccessibleTextComponent
, VCLXAccessibleButton_BASE
)
122 // -----------------------------------------------------------------------------
124 // -----------------------------------------------------------------------------
126 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleButton
, VCLXAccessibleTextComponent
, VCLXAccessibleButton_BASE
)
128 // -----------------------------------------------------------------------------
130 // -----------------------------------------------------------------------------
132 ::rtl::OUString
VCLXAccessibleButton::getImplementationName() throw (RuntimeException
)
134 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleButton" );
137 // -----------------------------------------------------------------------------
139 Sequence
< ::rtl::OUString
> VCLXAccessibleButton::getSupportedServiceNames() throw (RuntimeException
)
141 Sequence
< ::rtl::OUString
> aNames(1);
142 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleButton" );
146 // -----------------------------------------------------------------------------
147 // XAccessibleContext
148 // -----------------------------------------------------------------------------
150 ::rtl::OUString
VCLXAccessibleButton::getAccessibleName( ) throw (RuntimeException
)
152 OExternalLockGuard
aGuard( this );
154 ::rtl::OUString
aName( VCLXAccessibleTextComponent::getAccessibleName() );
155 sal_Int32 nLength
= aName
.getLength();
157 if ( nLength
>= 3 && aName
.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("..."), nLength
- 3 ) )
161 // it's a browse button
162 aName
= ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_NAME_BROWSEBUTTON
) );
166 // remove the three trailing dots
167 aName
= aName
.copy( 0, nLength
- 3 );
170 else if ( nLength
>= 3 && aName
.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("<< "), 0 ) )
172 // remove the leading symbols
173 aName
= aName
.copy( 3, nLength
- 3 );
175 else if ( nLength
>= 3 && aName
.matchAsciiL( RTL_CONSTASCII_STRINGPARAM(" >>"), nLength
- 3 ) )
177 // remove the trailing symbols
178 aName
= aName
.copy( 0, nLength
- 3 );
184 // -----------------------------------------------------------------------------
186 // -----------------------------------------------------------------------------
188 sal_Int32
VCLXAccessibleButton::getAccessibleActionCount( ) throw (RuntimeException
)
190 OExternalLockGuard
aGuard( this );
195 // -----------------------------------------------------------------------------
197 sal_Bool
VCLXAccessibleButton::doAccessibleAction ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
199 OExternalLockGuard
aGuard( this );
201 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
202 throw IndexOutOfBoundsException();
204 PushButton
* pButton
= (PushButton
*) GetWindow();
211 // -----------------------------------------------------------------------------
213 ::rtl::OUString
VCLXAccessibleButton::getAccessibleActionDescription ( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
215 OExternalLockGuard
aGuard( this );
217 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
218 throw IndexOutOfBoundsException();
220 return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK
) );
223 // -----------------------------------------------------------------------------
225 Reference
< XAccessibleKeyBinding
> VCLXAccessibleButton::getAccessibleActionKeyBinding( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
227 OExternalLockGuard
aGuard( this );
229 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
230 throw IndexOutOfBoundsException();
232 OAccessibleKeyBindingHelper
* pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
233 Reference
< XAccessibleKeyBinding
> xKeyBinding
= pKeyBindingHelper
;
235 Window
* pWindow
= GetWindow();
238 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
239 KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
240 if ( aKeyCode
.GetCode() != 0 )
242 awt::KeyStroke aKeyStroke
;
243 aKeyStroke
.Modifiers
= 0;
244 if ( aKeyCode
.IsShift() )
245 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
246 if ( aKeyCode
.IsMod1() )
247 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
248 if ( aKeyCode
.IsMod2() )
249 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
250 if ( aKeyCode
.IsMod3() )
251 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
252 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
253 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
254 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
255 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
262 // -----------------------------------------------------------------------------
264 // -----------------------------------------------------------------------------
266 Any
VCLXAccessibleButton::getCurrentValue( ) throw (RuntimeException
)
268 OExternalLockGuard
aGuard( this );
272 PushButton
* pButton
= (PushButton
*) GetWindow();
274 aValue
<<= (sal_Int32
) pButton
->IsPressed();
279 // -----------------------------------------------------------------------------
281 sal_Bool
VCLXAccessibleButton::setCurrentValue( const Any
& aNumber
) throw (RuntimeException
)
283 OExternalLockGuard
aGuard( this );
285 sal_Bool bReturn
= sal_False
;
287 PushButton
* pButton
= (PushButton
*) GetWindow();
290 sal_Int32 nValue
= 0;
291 OSL_VERIFY( aNumber
>>= nValue
);
295 else if ( nValue
> 1 )
298 pButton
->SetPressed( (BOOL
) nValue
);
305 // -----------------------------------------------------------------------------
307 Any
VCLXAccessibleButton::getMaximumValue( ) throw (RuntimeException
)
309 OExternalLockGuard
aGuard( this );
312 aValue
<<= (sal_Int32
) 1;
317 // -----------------------------------------------------------------------------
319 Any
VCLXAccessibleButton::getMinimumValue( ) throw (RuntimeException
)
321 OExternalLockGuard
aGuard( this );
324 aValue
<<= (sal_Int32
) 0;
329 // -----------------------------------------------------------------------------