10841af79SAndrew Rist /**************************************************************
2*09e0ec10Smseidel  *
30841af79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
40841af79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
50841af79SAndrew Rist  * distributed with this work for additional information
60841af79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
70841af79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
80841af79SAndrew Rist  * "License"); you may not use this file except in compliance
90841af79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*09e0ec10Smseidel  *
110841af79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*09e0ec10Smseidel  *
130841af79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
140841af79SAndrew Rist  * software distributed under the License is distributed on an
150841af79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160841af79SAndrew Rist  * KIND, either express or implied.  See the License for the
170841af79SAndrew Rist  * specific language governing permissions and limitations
180841af79SAndrew Rist  * under the License.
19*09e0ec10Smseidel  *
200841af79SAndrew Rist  *************************************************************/
210841af79SAndrew Rist 
220841af79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // includes --------------------------------------------------------------
28cdf0e10cSrcweir #include <accessibility/standard/vclxaccessibleradiobutton.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx>
31cdf0e10cSrcweir #include <accessibility/helper/accresmgr.hxx>
32cdf0e10cSrcweir #include <accessibility/helper/accessiblestrings.hrc>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
35cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
36cdf0e10cSrcweir #include <comphelper/accessiblekeybindinghelper.hxx>
37cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
38cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
39cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
41cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
42cdf0e10cSrcweir #include <comphelper/sequence.hxx>
43cdf0e10cSrcweir #include <vcl/window.hxx>
44cdf0e10cSrcweir #include <vcl/button.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using namespace ::com::sun::star;
48cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir using namespace ::com::sun::star::lang;
50cdf0e10cSrcweir using namespace ::com::sun::star::beans;
51cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
52cdf0e10cSrcweir using namespace ::comphelper;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // -----------------------------------------------------------------------------
56cdf0e10cSrcweir // VCLXAccessibleRadioButton
57cdf0e10cSrcweir // -----------------------------------------------------------------------------
58cdf0e10cSrcweir 
VCLXAccessibleRadioButton(VCLXWindow * pVCLWindow)59cdf0e10cSrcweir VCLXAccessibleRadioButton::VCLXAccessibleRadioButton( VCLXWindow* pVCLWindow )
60cdf0e10cSrcweir 	:VCLXAccessibleTextComponent( pVCLWindow )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // -----------------------------------------------------------------------------
65cdf0e10cSrcweir 
~VCLXAccessibleRadioButton()66cdf0e10cSrcweir VCLXAccessibleRadioButton::~VCLXAccessibleRadioButton()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // -----------------------------------------------------------------------------
71cdf0e10cSrcweir 
ProcessWindowEvent(const VclWindowEvent & rVclWindowEvent)72cdf0e10cSrcweir void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
73cdf0e10cSrcweir {
74*09e0ec10Smseidel 	switch ( rVclWindowEvent.GetId() )
75*09e0ec10Smseidel 	{
76cdf0e10cSrcweir 		case VCLEVENT_RADIOBUTTON_TOGGLE:
77*09e0ec10Smseidel 		{
78cdf0e10cSrcweir 			Any aOldValue;
79cdf0e10cSrcweir 			Any aNewValue;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 			VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
82cdf0e10cSrcweir 			if ( pVCLXRadioButton && pVCLXRadioButton->getState() )
83cdf0e10cSrcweir 				aNewValue <<= AccessibleStateType::CHECKED;
84cdf0e10cSrcweir 			else
85cdf0e10cSrcweir 				aOldValue <<= AccessibleStateType::CHECKED;
86cdf0e10cSrcweir 
87*09e0ec10Smseidel 			NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
88*09e0ec10Smseidel 		}
89*09e0ec10Smseidel 		break;
90cdf0e10cSrcweir 		default:
91cdf0e10cSrcweir 			VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
92*09e0ec10Smseidel 	}
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // -----------------------------------------------------------------------------
96cdf0e10cSrcweir 
FillAccessibleRelationSet(utl::AccessibleRelationSetHelper & rRelationSet)97cdf0e10cSrcweir void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
98cdf0e10cSrcweir {
99*09e0ec10Smseidel 	VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet );
100*09e0ec10Smseidel 
101*09e0ec10Smseidel 	RadioButton* pRadioButton = dynamic_cast< RadioButton* >( GetWindow() );
102*09e0ec10Smseidel 	if ( pRadioButton )
103*09e0ec10Smseidel 	{
104*09e0ec10Smseidel 		::std::vector< RadioButton* > aGroup;
105*09e0ec10Smseidel 		pRadioButton->GetRadioButtonGroup( aGroup, true );
106*09e0ec10Smseidel 		if ( !aGroup.empty() )
107*09e0ec10Smseidel 		{
108*09e0ec10Smseidel 			sal_Int32 i = 0;
109*09e0ec10Smseidel 			Sequence< Reference< XInterface > > aSequence( static_cast< sal_Int32 >( aGroup.size() ) );
110*09e0ec10Smseidel 			::std::vector< RadioButton* >::const_iterator aEndItr = aGroup.end();
111*09e0ec10Smseidel 			for ( ::std::vector< RadioButton* >::const_iterator aItr = aGroup.begin(); aItr < aEndItr; ++aItr )
112*09e0ec10Smseidel 			{
113*09e0ec10Smseidel 				aSequence[i++] = (*aItr)->GetAccessible();
114*09e0ec10Smseidel 			}
115*09e0ec10Smseidel 			rRelationSet.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, aSequence ) );
116*09e0ec10Smseidel 		}
117*09e0ec10Smseidel 	}
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // -----------------------------------------------------------------------------
121cdf0e10cSrcweir 
FillAccessibleStateSet(utl::AccessibleStateSetHelper & rStateSet)122cdf0e10cSrcweir void VCLXAccessibleRadioButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
127cdf0e10cSrcweir 	if ( pVCLXRadioButton )
128cdf0e10cSrcweir 	{
129*09e0ec10Smseidel 		rStateSet.AddState( AccessibleStateType::FOCUSABLE );
130cdf0e10cSrcweir 		if ( pVCLXRadioButton->getState() )
131*09e0ec10Smseidel 			rStateSet.AddState( AccessibleStateType::CHECKED );
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
136cdf0e10cSrcweir // XInterface
137cdf0e10cSrcweir // -----------------------------------------------------------------------------
138cdf0e10cSrcweir 
IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleRadioButton,VCLXAccessibleTextComponent,VCLXAccessibleRadioButton_BASE)139cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE )
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // -----------------------------------------------------------------------------
142cdf0e10cSrcweir // XTypeProvider
143cdf0e10cSrcweir // -----------------------------------------------------------------------------
144cdf0e10cSrcweir 
145cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE )
146cdf0e10cSrcweir 
147cdf0e10cSrcweir // -----------------------------------------------------------------------------
148cdf0e10cSrcweir // XServiceInfo
149cdf0e10cSrcweir // -----------------------------------------------------------------------------
150cdf0e10cSrcweir 
151cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleRadioButton::getImplementationName() throw (RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleRadioButton" );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // -----------------------------------------------------------------------------
157cdf0e10cSrcweir 
getSupportedServiceNames()158cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleRadioButton::getSupportedServiceNames() throw (RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aNames(1);
161cdf0e10cSrcweir 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleRadioButton" );
162cdf0e10cSrcweir 	return aNames;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // -----------------------------------------------------------------------------
166cdf0e10cSrcweir // XAccessibleAction
167cdf0e10cSrcweir // -----------------------------------------------------------------------------
168cdf0e10cSrcweir 
getAccessibleActionCount()169cdf0e10cSrcweir sal_Int32 VCLXAccessibleRadioButton::getAccessibleActionCount( ) throw (RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
172cdf0e10cSrcweir 
173*09e0ec10Smseidel 	return 1;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir // -----------------------------------------------------------------------------
177cdf0e10cSrcweir 
doAccessibleAction(sal_Int32 nIndex)178cdf0e10cSrcweir sal_Bool VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
183*09e0ec10Smseidel 		throw IndexOutOfBoundsException();
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
186cdf0e10cSrcweir 	if ( pVCLXRadioButton && !pVCLXRadioButton->getState() )
187cdf0e10cSrcweir 		pVCLXRadioButton->setState( sal_True );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	return sal_True;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir // -----------------------------------------------------------------------------
193cdf0e10cSrcweir 
getAccessibleActionDescription(sal_Int32 nIndex)194cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
199*09e0ec10Smseidel 		throw IndexOutOfBoundsException();
20021075d77SSteve Yin 	return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_SELECT ) );
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir // -----------------------------------------------------------------------------
204cdf0e10cSrcweir 
getAccessibleActionKeyBinding(sal_Int32 nIndex)205cdf0e10cSrcweir Reference< XAccessibleKeyBinding > VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
206cdf0e10cSrcweir {
207*09e0ec10Smseidel 	OExternalLockGuard aGuard( this );
208*09e0ec10Smseidel 
209*09e0ec10Smseidel 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
210*09e0ec10Smseidel 		throw IndexOutOfBoundsException();
211*09e0ec10Smseidel 
212*09e0ec10Smseidel 	OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper();
213*09e0ec10Smseidel 	Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper;
214*09e0ec10Smseidel 
215*09e0ec10Smseidel 	Window* pWindow = GetWindow();
216*09e0ec10Smseidel 	if ( pWindow )
217*09e0ec10Smseidel 	{
218*09e0ec10Smseidel 		KeyEvent aKeyEvent = pWindow->GetActivationKey();
219*09e0ec10Smseidel 		KeyCode aKeyCode = aKeyEvent.GetKeyCode();
220*09e0ec10Smseidel 		if ( aKeyCode.GetCode() != 0 )
221*09e0ec10Smseidel 		{
222*09e0ec10Smseidel 			awt::KeyStroke aKeyStroke;
223*09e0ec10Smseidel 			aKeyStroke.Modifiers = 0;
224*09e0ec10Smseidel 			if ( aKeyCode.IsShift() )
225*09e0ec10Smseidel 				aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
226*09e0ec10Smseidel 			if ( aKeyCode.IsMod1() )
227*09e0ec10Smseidel 				aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
228*09e0ec10Smseidel 			if ( aKeyCode.IsMod2() )
229*09e0ec10Smseidel 				aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
230*09e0ec10Smseidel 			if ( aKeyCode.IsMod3() )
231*09e0ec10Smseidel 				aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
232*09e0ec10Smseidel 			aKeyStroke.KeyCode = aKeyCode.GetCode();
233*09e0ec10Smseidel 			aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
234*09e0ec10Smseidel 			aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
235*09e0ec10Smseidel 			pKeyBindingHelper->AddKeyBinding( aKeyStroke );
236*09e0ec10Smseidel 		}
237*09e0ec10Smseidel 	}
238*09e0ec10Smseidel 
239*09e0ec10Smseidel 	return xKeyBinding;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir // -----------------------------------------------------------------------------
243cdf0e10cSrcweir // XAccessibleValue
244cdf0e10cSrcweir // -----------------------------------------------------------------------------
245cdf0e10cSrcweir 
getCurrentValue()246cdf0e10cSrcweir Any VCLXAccessibleRadioButton::getCurrentValue(  ) throw (RuntimeException)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	Any aValue;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
253cdf0e10cSrcweir 	if ( pVCLXRadioButton )
254cdf0e10cSrcweir 		aValue <<= (sal_Int32) pVCLXRadioButton->getState();
255*09e0ec10Smseidel 
256cdf0e10cSrcweir 	return aValue;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // -----------------------------------------------------------------------------
260cdf0e10cSrcweir 
setCurrentValue(const Any & aNumber)261cdf0e10cSrcweir sal_Bool VCLXAccessibleRadioButton::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
268cdf0e10cSrcweir 	if ( pVCLXRadioButton )
269cdf0e10cSrcweir 	{
270cdf0e10cSrcweir 		sal_Int32 nValue = 0;
271cdf0e10cSrcweir 		OSL_VERIFY( aNumber >>= nValue );
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 		if ( nValue < 0 )
274cdf0e10cSrcweir 			nValue = 0;
275cdf0e10cSrcweir 		else if ( nValue > 1 )
276cdf0e10cSrcweir 			nValue = 1;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 		pVCLXRadioButton->setState( (sal_Bool) nValue );
279cdf0e10cSrcweir 		bReturn = sal_True;
280cdf0e10cSrcweir 	}
281*09e0ec10Smseidel 
282cdf0e10cSrcweir 	return bReturn;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir // -----------------------------------------------------------------------------
286cdf0e10cSrcweir 
getMaximumValue()287cdf0e10cSrcweir Any VCLXAccessibleRadioButton::getMaximumValue(  ) throw (RuntimeException)
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 	Any aValue;
292cdf0e10cSrcweir 	aValue <<= (sal_Int32) 1;
293*09e0ec10Smseidel 
294cdf0e10cSrcweir 	return aValue;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir // -----------------------------------------------------------------------------
298cdf0e10cSrcweir 
getMinimumValue()299cdf0e10cSrcweir Any VCLXAccessibleRadioButton::getMinimumValue(  ) throw (RuntimeException)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 	Any aValue;
304cdf0e10cSrcweir 	aValue <<= (sal_Int32) 0;
305*09e0ec10Smseidel 
306cdf0e10cSrcweir 	return aValue;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir // -----------------------------------------------------------------------------
310