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