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