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 #include <accessibility/standard/vclxaccessiblemenuitem.hxx>
31*cdf0e10cSrcweir #include <accessibility/helper/accresmgr.hxx>
32*cdf0e10cSrcweir #include <accessibility/helper/accessiblestrings.hrc>
33*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
34*cdf0e10cSrcweir #include <accessibility/helper/characterattributeshelper.hxx>
35*cdf0e10cSrcweir #include <comphelper/accessiblekeybindinghelper.hxx>
36*cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
42*cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
43*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
44*cdf0e10cSrcweir #include <vcl/svapp.hxx>
45*cdf0e10cSrcweir #include <vcl/window.hxx>
46*cdf0e10cSrcweir #include <vcl/menu.hxx>
47*cdf0e10cSrcweir #include <vcl/unohelp2.hxx>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <memory>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
53*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
54*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
55*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
56*cdf0e10cSrcweir using namespace ::com::sun::star;
57*cdf0e10cSrcweir using namespace ::comphelper;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // -----------------------------------------------------------------------------
61*cdf0e10cSrcweir // class VCLXAccessibleMenuItem
62*cdf0e10cSrcweir // -----------------------------------------------------------------------------
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir VCLXAccessibleMenuItem::VCLXAccessibleMenuItem( Menu* pParent, sal_uInt16 nItemPos, Menu* pMenu )
65*cdf0e10cSrcweir 	:OAccessibleMenuItemComponent( pParent, nItemPos, pMenu )
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir // -----------------------------------------------------------------------------
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir VCLXAccessibleMenuItem::~VCLXAccessibleMenuItem()
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // -----------------------------------------------------------------------------
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsFocused()
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     return IsHighlighted();
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir // -----------------------------------------------------------------------------
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsSelected()
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     return IsHighlighted();
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir // -----------------------------------------------------------------------------
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsChecked()
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir 	sal_Bool bChecked = sal_False;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	if ( m_pParent )
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 		sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos );
98*cdf0e10cSrcweir 		if ( m_pParent->IsItemChecked( nItemId ) )
99*cdf0e10cSrcweir 			bChecked = sal_True;
100*cdf0e10cSrcweir 	}
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	return bChecked;
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir // -----------------------------------------------------------------------------
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::IsHighlighted()
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir 	sal_Bool bHighlighted = sal_False;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     if ( m_pParent && m_pParent->IsHighlighted( m_nItemPos ) )
112*cdf0e10cSrcweir         bHighlighted = sal_True;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	return bHighlighted;
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir // -----------------------------------------------------------------------------
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir void VCLXAccessibleMenuItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir     OAccessibleMenuItemComponent::FillAccessibleStateSet( rStateSet );
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     rStateSet.AddState( AccessibleStateType::FOCUSABLE );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     if ( IsFocused() )
126*cdf0e10cSrcweir         rStateSet.AddState( AccessibleStateType::FOCUSED );
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     rStateSet.AddState( AccessibleStateType::SELECTABLE );
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     if ( IsSelected() )
131*cdf0e10cSrcweir         rStateSet.AddState( AccessibleStateType::SELECTED );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     if ( IsChecked() )
134*cdf0e10cSrcweir         rStateSet.AddState( AccessibleStateType::CHECKED );
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir // -----------------------------------------------------------------------------
138*cdf0e10cSrcweir // OCommonAccessibleText
139*cdf0e10cSrcweir // -----------------------------------------------------------------------------
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::implGetText()
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir 	return m_sItemText;
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir // -----------------------------------------------------------------------------
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir Locale VCLXAccessibleMenuItem::implGetLocale()
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir 	return Application::GetSettings().GetLocale();
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir // -----------------------------------------------------------------------------
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir void VCLXAccessibleMenuItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	nStartIndex = 0;
158*cdf0e10cSrcweir 	nEndIndex = 0;
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir // -----------------------------------------------------------------------------
162*cdf0e10cSrcweir // XInterface
163*cdf0e10cSrcweir // -----------------------------------------------------------------------------
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenuItem, OAccessibleMenuItemComponent, VCLXAccessibleMenuItem_BASE )
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir // -----------------------------------------------------------------------------
168*cdf0e10cSrcweir // XTypeProvider
169*cdf0e10cSrcweir // -----------------------------------------------------------------------------
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenuItem, OAccessibleMenuItemComponent, VCLXAccessibleMenuItem_BASE )
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir // -----------------------------------------------------------------------------
174*cdf0e10cSrcweir // XServiceInfo
175*cdf0e10cSrcweir // -----------------------------------------------------------------------------
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getImplementationName() throw (RuntimeException)
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleMenuItem" );
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir // -----------------------------------------------------------------------------
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleMenuItem::getSupportedServiceNames() throw (RuntimeException)
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aNames(1);
187*cdf0e10cSrcweir 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleMenuItem" );
188*cdf0e10cSrcweir 	return aNames;
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir // -----------------------------------------------------------------------------
192*cdf0e10cSrcweir // XAccessibleContext
193*cdf0e10cSrcweir // -----------------------------------------------------------------------------
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir sal_Int16 VCLXAccessibleMenuItem::getAccessibleRole(  ) throw (RuntimeException)
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	return AccessibleRole::MENU_ITEM;
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir // -----------------------------------------------------------------------------
203*cdf0e10cSrcweir // XAccessibleText
204*cdf0e10cSrcweir // -----------------------------------------------------------------------------
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getCaretPosition() throw (RuntimeException)
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	return -1;
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir // -----------------------------------------------------------------------------
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
221*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	return sal_False;
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir // -----------------------------------------------------------------------------
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir sal_Unicode VCLXAccessibleMenuItem::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	return OCommonAccessibleText::getCharacter( nIndex );
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir // -----------------------------------------------------------------------------
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir Sequence< PropertyValue > VCLXAccessibleMenuItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException)
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 	Sequence< PropertyValue > aValues;
242*cdf0e10cSrcweir 	::rtl::OUString sText( implGetText() );
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
245*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	Font aFont = Application::GetSettings().GetStyleSettings().GetMenuFont();
248*cdf0e10cSrcweir 	sal_Int32 nBackColor = getBackground();
249*cdf0e10cSrcweir 	sal_Int32 nColor = getForeground();
250*cdf0e10cSrcweir     ::std::auto_ptr< CharacterAttributesHelper > pHelper( new CharacterAttributesHelper( aFont, nBackColor, nColor ) );
251*cdf0e10cSrcweir     aValues = pHelper->GetCharacterAttributes( aRequestedAttributes );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     return aValues;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir // -----------------------------------------------------------------------------
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir awt::Rectangle VCLXAccessibleMenuItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
263*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	awt::Rectangle aBounds( 0, 0, 0, 0 );
266*cdf0e10cSrcweir 	if ( m_pParent )
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 		sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos );
269*cdf0e10cSrcweir 		Rectangle aItemRect = m_pParent->GetBoundingRectangle( m_nItemPos );
270*cdf0e10cSrcweir 		Rectangle aCharRect = m_pParent->GetCharacterBounds( nItemId, nIndex );
271*cdf0e10cSrcweir 		aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
272*cdf0e10cSrcweir 		aBounds = AWTRectangle( aCharRect );
273*cdf0e10cSrcweir 	}
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 	return aBounds;
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir // -----------------------------------------------------------------------------
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getCharacterCount() throw (RuntimeException)
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	return OCommonAccessibleText::getCharacterCount();
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir // -----------------------------------------------------------------------------
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 	sal_Int32 nIndex = -1;
294*cdf0e10cSrcweir 	if ( m_pParent )
295*cdf0e10cSrcweir 	{
296*cdf0e10cSrcweir 		sal_uInt16 nItemId = 0;
297*cdf0e10cSrcweir 		Rectangle aItemRect = m_pParent->GetBoundingRectangle( m_nItemPos );
298*cdf0e10cSrcweir 		Point aPnt( VCLPoint( aPoint ) );
299*cdf0e10cSrcweir 		aPnt += aItemRect.TopLeft();
300*cdf0e10cSrcweir 		sal_Int32 nI = m_pParent->GetIndexForPoint( aPnt, nItemId );
301*cdf0e10cSrcweir 		if ( nI != -1 && m_pParent->GetItemId( m_nItemPos ) == nItemId )
302*cdf0e10cSrcweir 			nIndex = nI;
303*cdf0e10cSrcweir 	}
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	return nIndex;
306*cdf0e10cSrcweir }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir // -----------------------------------------------------------------------------
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getSelectedText() throw (RuntimeException)
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	return OCommonAccessibleText::getSelectedText();
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir // -----------------------------------------------------------------------------
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getSelectionStart() throw (RuntimeException)
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 	return OCommonAccessibleText::getSelectionStart();
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir // -----------------------------------------------------------------------------
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getSelectionEnd() throw (RuntimeException)
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 	return OCommonAccessibleText::getSelectionEnd();
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir // -----------------------------------------------------------------------------
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
342*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 	return sal_False;
345*cdf0e10cSrcweir }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir // -----------------------------------------------------------------------------
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getText() throw (RuntimeException)
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 	return OCommonAccessibleText::getText();
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir // -----------------------------------------------------------------------------
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 	return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir // -----------------------------------------------------------------------------
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleMenuItem::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 	return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
372*cdf0e10cSrcweir }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir // -----------------------------------------------------------------------------
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleMenuItem::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir 	return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir // -----------------------------------------------------------------------------
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir ::com::sun::star::accessibility::TextSegment VCLXAccessibleMenuItem::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 	return OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir // -----------------------------------------------------------------------------
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 	if ( m_pParent )
401*cdf0e10cSrcweir 	{
402*cdf0e10cSrcweir 		Window* pWindow = m_pParent->GetWindow();
403*cdf0e10cSrcweir 		if ( pWindow )
404*cdf0e10cSrcweir 		{
405*cdf0e10cSrcweir 			Reference< datatransfer::clipboard::XClipboard > xClipboard = pWindow->GetClipboard();
406*cdf0e10cSrcweir 			if ( xClipboard.is() )
407*cdf0e10cSrcweir 			{
408*cdf0e10cSrcweir 				::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) );
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 				::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
411*cdf0e10cSrcweir 				const sal_uInt32 nRef = Application::ReleaseSolarMutex();
412*cdf0e10cSrcweir 				xClipboard->setContents( pDataObj, NULL );
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir 				Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
415*cdf0e10cSrcweir 				if( xFlushableClipboard.is() )
416*cdf0e10cSrcweir 					xFlushableClipboard->flushClipboard();
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 				Application::AcquireSolarMutex( nRef );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 				bReturn = sal_True;
421*cdf0e10cSrcweir 			}
422*cdf0e10cSrcweir 		}
423*cdf0e10cSrcweir 	}
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 	return bReturn;
426*cdf0e10cSrcweir }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir // -----------------------------------------------------------------------------
429*cdf0e10cSrcweir // XAccessibleAction
430*cdf0e10cSrcweir // -----------------------------------------------------------------------------
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuItem::getAccessibleActionCount( ) throw (RuntimeException)
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 	return 1;
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir // -----------------------------------------------------------------------------
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
446*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	Click();
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 	return sal_True;
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir // -----------------------------------------------------------------------------
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuItem::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
460*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 	return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir // -----------------------------------------------------------------------------
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir Reference< XAccessibleKeyBinding > VCLXAccessibleMenuItem::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
468*cdf0e10cSrcweir {
469*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 	if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
472*cdf0e10cSrcweir         throw IndexOutOfBoundsException();
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 	OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper();
475*cdf0e10cSrcweir 	Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper;
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 	if ( m_pParent )
478*cdf0e10cSrcweir 	{
479*cdf0e10cSrcweir 		// create auto mnemonics
480*cdf0e10cSrcweir 		if ( Application::GetSettings().GetStyleSettings().GetAutoMnemonic() && !( m_pParent->GetMenuFlags() & MENU_FLAG_NOAUTOMNEMONICS ) )
481*cdf0e10cSrcweir 			m_pParent->CreateAutoMnemonics();
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir 		// activation key
484*cdf0e10cSrcweir 		KeyEvent aKeyEvent = m_pParent->GetActivationKey( m_pParent->GetItemId( m_nItemPos ) );
485*cdf0e10cSrcweir 		KeyCode aKeyCode = aKeyEvent.GetKeyCode();
486*cdf0e10cSrcweir 		Sequence< awt::KeyStroke > aSeq1(1);
487*cdf0e10cSrcweir 		aSeq1[0].Modifiers = 0;
488*cdf0e10cSrcweir 		Reference< XAccessible > xParent( getAccessibleParent() );
489*cdf0e10cSrcweir 		if ( xParent.is() )
490*cdf0e10cSrcweir 		{
491*cdf0e10cSrcweir 			Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
492*cdf0e10cSrcweir 			if ( xParentContext.is() && xParentContext->getAccessibleRole() == AccessibleRole::MENU_BAR )
493*cdf0e10cSrcweir 				aSeq1[0].Modifiers |= awt::KeyModifier::MOD2;
494*cdf0e10cSrcweir 		}
495*cdf0e10cSrcweir 		aSeq1[0].KeyCode = aKeyCode.GetCode();
496*cdf0e10cSrcweir 		aSeq1[0].KeyChar = aKeyEvent.GetCharCode();
497*cdf0e10cSrcweir         aSeq1[0].KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
498*cdf0e10cSrcweir 		pKeyBindingHelper->AddKeyBinding( aSeq1 );
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 		// complete menu activation key sequence
501*cdf0e10cSrcweir 		Sequence< awt::KeyStroke > aSeq;
502*cdf0e10cSrcweir 		if ( xParent.is() )
503*cdf0e10cSrcweir 		{
504*cdf0e10cSrcweir 			Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
505*cdf0e10cSrcweir 			if ( xParentContext.is() && xParentContext->getAccessibleRole() == AccessibleRole::MENU )
506*cdf0e10cSrcweir 			{
507*cdf0e10cSrcweir 				Reference< XAccessibleAction > xAction( xParentContext, UNO_QUERY );
508*cdf0e10cSrcweir 				if ( xAction.is() && xAction->getAccessibleActionCount() > 0 )
509*cdf0e10cSrcweir 				{
510*cdf0e10cSrcweir 					Reference< XAccessibleKeyBinding > xKeyB( xAction->getAccessibleActionKeyBinding( 0 ) );
511*cdf0e10cSrcweir 					if ( xKeyB.is() && xKeyB->getAccessibleKeyBindingCount() > 1 )
512*cdf0e10cSrcweir 						aSeq = xKeyB->getAccessibleKeyBinding( 1 );
513*cdf0e10cSrcweir 				}
514*cdf0e10cSrcweir 			}
515*cdf0e10cSrcweir 		}
516*cdf0e10cSrcweir 		Sequence< awt::KeyStroke > aSeq2 = ::comphelper::concatSequences( aSeq, aSeq1 );
517*cdf0e10cSrcweir 		pKeyBindingHelper->AddKeyBinding( aSeq2 );
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir         // accelerator key
520*cdf0e10cSrcweir         KeyCode aAccelKeyCode = m_pParent->GetAccelKey( m_pParent->GetItemId( m_nItemPos ) );
521*cdf0e10cSrcweir         if ( aAccelKeyCode.GetCode() != 0 )
522*cdf0e10cSrcweir         {
523*cdf0e10cSrcweir             Sequence< awt::KeyStroke > aSeq3(1);
524*cdf0e10cSrcweir             aSeq3[0].Modifiers = 0;
525*cdf0e10cSrcweir             if ( aAccelKeyCode.IsShift() )
526*cdf0e10cSrcweir                 aSeq3[0].Modifiers |= awt::KeyModifier::SHIFT;
527*cdf0e10cSrcweir             if ( aAccelKeyCode.IsMod1() )
528*cdf0e10cSrcweir                 aSeq3[0].Modifiers |= awt::KeyModifier::MOD1;
529*cdf0e10cSrcweir             if ( aAccelKeyCode.IsMod2() )
530*cdf0e10cSrcweir                 aSeq3[0].Modifiers |= awt::KeyModifier::MOD2;
531*cdf0e10cSrcweir             if ( aAccelKeyCode.IsMod3() )
532*cdf0e10cSrcweir                 aSeq3[0].Modifiers |= awt::KeyModifier::MOD3;
533*cdf0e10cSrcweir             aSeq3[0].KeyCode = aAccelKeyCode.GetCode();
534*cdf0e10cSrcweir             aSeq3[0].KeyFunc = static_cast< sal_Int16 >( aAccelKeyCode.GetFunction() );
535*cdf0e10cSrcweir             pKeyBindingHelper->AddKeyBinding( aSeq3 );
536*cdf0e10cSrcweir         }
537*cdf0e10cSrcweir 	}
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 	return xKeyBinding;
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir // -----------------------------------------------------------------------------
543*cdf0e10cSrcweir // XAccessibleValue
544*cdf0e10cSrcweir // -----------------------------------------------------------------------------
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir Any VCLXAccessibleMenuItem::getCurrentValue(  ) throw (RuntimeException)
547*cdf0e10cSrcweir {
548*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir 	Any aValue;
551*cdf0e10cSrcweir 	if ( IsSelected() )
552*cdf0e10cSrcweir 		aValue <<= (sal_Int32) 1;
553*cdf0e10cSrcweir 	else
554*cdf0e10cSrcweir 		aValue <<= (sal_Int32) 0;
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 	return aValue;
557*cdf0e10cSrcweir }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir // -----------------------------------------------------------------------------
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuItem::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
566*cdf0e10cSrcweir 	sal_Int32 nValue = 0;
567*cdf0e10cSrcweir 	OSL_VERIFY( aNumber >>= nValue );
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir 	if ( nValue <= 0 )
570*cdf0e10cSrcweir 	{
571*cdf0e10cSrcweir 		DeSelect();
572*cdf0e10cSrcweir 		bReturn = sal_True;
573*cdf0e10cSrcweir 	}
574*cdf0e10cSrcweir 	else if ( nValue >= 1 )
575*cdf0e10cSrcweir 	{
576*cdf0e10cSrcweir 		Select();
577*cdf0e10cSrcweir 		bReturn = sal_True;
578*cdf0e10cSrcweir 	}
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 	return bReturn;
581*cdf0e10cSrcweir }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir // -----------------------------------------------------------------------------
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir Any VCLXAccessibleMenuItem::getMaximumValue(  ) throw (RuntimeException)
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 	Any aValue;
590*cdf0e10cSrcweir 	aValue <<= (sal_Int32) 1;
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 	return aValue;
593*cdf0e10cSrcweir }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir // -----------------------------------------------------------------------------
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir Any VCLXAccessibleMenuItem::getMinimumValue(  ) throw (RuntimeException)
598*cdf0e10cSrcweir {
599*cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir 	Any aValue;
602*cdf0e10cSrcweir 	aValue <<= (sal_Int32) 0;
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 	return aValue;
605*cdf0e10cSrcweir }
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir // -----------------------------------------------------------------------------
608