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 <standard/vclxaccessiblebutton.hxx>
21 #include <helper/accresmgr.hxx>
22 #include <strings.hrc>
24 #include <unotools/accessiblestatesethelper.hxx>
25 #include <comphelper/accessiblekeybindinghelper.hxx>
26 #include <com/sun/star/awt/KeyModifier.hpp>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <strings.hxx>
32 #include <vcl/button.hxx>
33 #include <vcl/event.hxx>
34 #include <vcl/vclevent.hxx>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::beans
;
40 using namespace ::com::sun::star::accessibility
;
41 using namespace ::comphelper
;
44 // VCLXAccessibleButton
47 void VCLXAccessibleButton::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
49 switch ( rVclWindowEvent
.GetId() )
51 case VclEventId::PushbuttonToggle
:
56 VclPtr
< PushButton
> pButton
= GetAs
< PushButton
>();
57 if ( pButton
&& pButton
->GetState() == TRISTATE_TRUE
)
58 aNewValue
<<= AccessibleStateType::CHECKED
;
60 aOldValue
<<= AccessibleStateType::CHECKED
;
62 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
66 VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent
);
71 void VCLXAccessibleButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
73 VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet
);
75 VclPtr
< PushButton
> pButton
= GetAs
< PushButton
>();
78 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
80 if ( pButton
->GetState() == TRISTATE_TRUE
)
81 rStateSet
.AddState( AccessibleStateType::CHECKED
);
83 if ( pButton
->IsPressed() )
84 rStateSet
.AddState( AccessibleStateType::PRESSED
);
86 // IA2 CWS: if the button has a popup menu, it should has the state EXPANDABLE
87 if( pButton
->GetType() == WindowType::MENUBUTTON
)
89 rStateSet
.AddState( AccessibleStateType::EXPANDABLE
);
91 if( pButton
->GetStyle() & WB_DEFBUTTON
)
93 rStateSet
.AddState( AccessibleStateType::DEFAULT
);
102 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleButton
, VCLXAccessibleTextComponent
, VCLXAccessibleButton_BASE
)
108 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleButton
, VCLXAccessibleTextComponent
, VCLXAccessibleButton_BASE
)
114 OUString
VCLXAccessibleButton::getImplementationName()
116 return "com.sun.star.comp.toolkit.AccessibleButton";
120 Sequence
< OUString
> VCLXAccessibleButton::getSupportedServiceNames()
122 return { "com.sun.star.awt.AccessibleButton" };
126 // XAccessibleContext
129 OUString
VCLXAccessibleButton::getAccessibleName( )
131 OUString
aName( VCLXAccessibleTextComponent::getAccessibleName() );
132 sal_Int32 nLength
= aName
.getLength();
134 if ( nLength
>= 3 && aName
.match( "...", nLength
- 3 ) )
138 // it's a browse button
139 aName
= AccResId( RID_STR_ACC_NAME_BROWSEBUTTON
);
143 // remove the three trailing dots
144 aName
= aName
.copy( 0, nLength
- 3 );
147 else if ( nLength
>= 3 && aName
.match( "<< ", 0 ) )
149 // remove the leading symbols
150 aName
= aName
.copy( 3, nLength
- 3 );
152 else if ( nLength
>= 3 && aName
.match( " >>", nLength
- 3 ) )
154 // remove the trailing symbols
155 aName
= aName
.copy( 0, nLength
- 3 );
165 sal_Int32
VCLXAccessibleButton::getAccessibleActionCount( )
167 OExternalLockGuard
aGuard( this );
173 sal_Bool
VCLXAccessibleButton::doAccessibleAction ( sal_Int32 nIndex
)
175 OExternalLockGuard
aGuard( this );
178 throw IndexOutOfBoundsException();
180 VclPtr
< PushButton
> pButton
= GetAs
< PushButton
>();
188 OUString
VCLXAccessibleButton::getAccessibleActionDescription ( sal_Int32 nIndex
)
190 OExternalLockGuard
aGuard( this );
193 throw IndexOutOfBoundsException();
195 return RID_STR_ACC_ACTION_CLICK
;
199 Reference
< XAccessibleKeyBinding
> VCLXAccessibleButton::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
201 OExternalLockGuard
aGuard( this );
204 throw IndexOutOfBoundsException();
206 OAccessibleKeyBindingHelper
* pKeyBindingHelper
= new OAccessibleKeyBindingHelper();
207 Reference
< XAccessibleKeyBinding
> xKeyBinding
= pKeyBindingHelper
;
209 VclPtr
<vcl::Window
> pWindow
= GetWindow();
212 KeyEvent aKeyEvent
= pWindow
->GetActivationKey();
213 vcl::KeyCode aKeyCode
= aKeyEvent
.GetKeyCode();
214 if ( aKeyCode
.GetCode() != 0 )
216 awt::KeyStroke aKeyStroke
;
217 aKeyStroke
.Modifiers
= 0;
218 if ( aKeyCode
.IsShift() )
219 aKeyStroke
.Modifiers
|= awt::KeyModifier::SHIFT
;
220 if ( aKeyCode
.IsMod1() )
221 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD1
;
222 if ( aKeyCode
.IsMod2() )
223 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD2
;
224 if ( aKeyCode
.IsMod3() )
225 aKeyStroke
.Modifiers
|= awt::KeyModifier::MOD3
;
226 aKeyStroke
.KeyCode
= aKeyCode
.GetCode();
227 aKeyStroke
.KeyChar
= aKeyEvent
.GetCharCode();
228 aKeyStroke
.KeyFunc
= static_cast< sal_Int16
>( aKeyCode
.GetFunction() );
229 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
240 Any
VCLXAccessibleButton::getCurrentValue( )
242 OExternalLockGuard
aGuard( this );
246 VclPtr
< PushButton
> pButton
= GetAs
< PushButton
>();
248 aValue
<<= static_cast<sal_Int32
>(pButton
->IsPressed());
254 sal_Bool
VCLXAccessibleButton::setCurrentValue( const Any
& aNumber
)
256 OExternalLockGuard
aGuard( this );
258 bool bReturn
= false;
260 VclPtr
< PushButton
> pButton
= GetAs
< PushButton
>();
263 sal_Int32 nValue
= 0;
264 OSL_VERIFY( aNumber
>>= nValue
);
268 else if ( nValue
> 1 )
271 pButton
->SetPressed( nValue
== 1 );
279 Any
VCLXAccessibleButton::getMaximumValue( )
281 OExternalLockGuard
aGuard( this );
284 aValue
<<= sal_Int32(1);
290 Any
VCLXAccessibleButton::getMinimumValue( )
292 OExternalLockGuard
aGuard( this );
295 aValue
<<= sal_Int32(0);
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */