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