Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / standard / vclxaccessibletoolboxitem.cxx
blob719df9c1730c68195d34bbeab50099faff15a9f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <accessibility/standard/vclxaccessibletoolboxitem.hxx>
21 #include <toolkit/helper/convert.hxx>
22 #include <accessibility/helper/accresmgr.hxx>
23 #include <accessibility/helper/accessiblestrings.hrc>
24 #include <com/sun/star/awt/Point.hpp>
25 #include <com/sun/star/awt/Rectangle.hpp>
26 #include <com/sun/star/awt/Size.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
32 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
33 #include <cppuhelper/supportsservice.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/toolbox.hxx>
36 #include <vcl/unohelp2.hxx>
37 #include <vcl/help.hxx>
38 #include <vcl/settings.hxx>
39 #include <toolkit/awt/vclxwindow.hxx>
40 #include <toolkit/helper/externallock.hxx>
41 #include <unotools/accessiblestatesethelper.hxx>
42 #include <unotools/accessiblerelationsethelper.hxx>
43 #include <cppuhelper/typeprovider.hxx>
44 #include <comphelper/sequence.hxx>
46 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
48 // class VCLXAccessibleToolBoxItem ------------------------------------------
50 using namespace ::com::sun::star::accessibility;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star;
55 using namespace ::comphelper;
58 // Ctor() and Dtor()
60 VCLXAccessibleToolBoxItem::VCLXAccessibleToolBoxItem( ToolBox* _pToolBox, sal_Int32 _nPos ) :
62 AccessibleTextHelper_BASE( new VCLExternalSolarLock() ),
64 m_pToolBox ( _pToolBox ),
65 m_nIndexInParent( _nPos ),
66 m_nRole ( AccessibleRole::PUSH_BUTTON ),
67 m_nItemId ( 0 ),
68 m_bHasFocus ( false ),
69 m_bIsChecked ( false ),
70 m_bIndeterminate( false )
73 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) );
75 OSL_ENSURE( m_pToolBox, "invalid toolbox" );
76 m_nItemId = m_pToolBox->GetItemId( (sal_uInt16)m_nIndexInParent );
77 m_sOldName = GetText( true );
78 m_bIsChecked = m_pToolBox->IsItemChecked( m_nItemId );
79 m_bIndeterminate = ( m_pToolBox->GetItemState( m_nItemId ) == TRISTATE_INDET );
80 ToolBoxItemType eType = m_pToolBox->GetItemType( (sal_uInt16)m_nIndexInParent );
81 switch ( eType )
83 case ToolBoxItemType::BUTTON :
85 ToolBoxItemBits nBits = m_pToolBox->GetItemBits( m_nItemId );
86 if (
87 (( nBits & ToolBoxItemBits::DROPDOWN ) == ToolBoxItemBits::DROPDOWN) ||
88 (( nBits & ToolBoxItemBits::DROPDOWNONLY ) == ToolBoxItemBits::DROPDOWNONLY)
90 m_nRole = AccessibleRole::BUTTON_DROPDOWN;
91 else if (
92 ( ( nBits & ToolBoxItemBits::CHECKABLE ) == ToolBoxItemBits::CHECKABLE ) ||
93 ( ( nBits & ToolBoxItemBits::RADIOCHECK ) == ToolBoxItemBits::RADIOCHECK ) ||
94 ( ( nBits & ToolBoxItemBits::AUTOCHECK ) == ToolBoxItemBits::AUTOCHECK )
96 m_nRole = AccessibleRole::TOGGLE_BUTTON;
97 else if ( m_pToolBox->GetItemWindow( m_nItemId ) )
98 m_nRole = AccessibleRole::PANEL;
99 break;
102 case ToolBoxItemType::SPACE :
103 m_nRole = AccessibleRole::FILLER;
104 break;
106 case ToolBoxItemType::SEPARATOR :
107 case ToolBoxItemType::BREAK :
108 m_nRole = AccessibleRole::SEPARATOR;
109 break;
111 default:
113 SAL_WARN( "accessibility", "unsupported toolbox itemtype" );
118 VCLXAccessibleToolBoxItem::~VCLXAccessibleToolBoxItem()
120 delete m_pExternalLock;
121 m_pExternalLock = NULL;
124 OUString VCLXAccessibleToolBoxItem::GetText( bool _bAsName )
126 OUString sRet;
127 // no text for separators and spaces
128 if ( m_pToolBox && m_nItemId > 0 && ( _bAsName || m_pToolBox->GetButtonType() != ButtonType::SYMBOLONLY ) )
130 sRet = m_pToolBox->GetItemText( m_nItemId );
131 if (sRet.isEmpty())
133 sRet = m_pToolBox->GetQuickHelpText( m_nItemId );
134 if (sRet.isEmpty())
136 vcl::Window* pItemWindow = m_pToolBox->GetItemWindow( m_nItemId );
137 if ( m_nRole == AccessibleRole::PANEL && pItemWindow && pItemWindow->GetAccessible().is() &&
138 pItemWindow->GetAccessible()->getAccessibleContext().is() )
140 OUString sWinText = pItemWindow->GetAccessible()->getAccessibleContext()->getAccessibleName();
141 if (!sWinText.isEmpty())
142 sRet = sWinText;
148 return sRet;
151 void VCLXAccessibleToolBoxItem::SetFocus( bool _bFocus )
153 if ( m_bHasFocus != _bFocus )
155 Any aOldValue;
156 Any aNewValue;
157 if ( m_bHasFocus )
158 aOldValue <<= AccessibleStateType::FOCUSED;
159 else
160 aNewValue <<= AccessibleStateType::FOCUSED;
161 m_bHasFocus = _bFocus;
162 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
166 void VCLXAccessibleToolBoxItem::SetChecked( bool _bCheck )
168 if( m_nRole == AccessibleRole::PANEL)
169 return;
170 if ( m_bIsChecked != _bCheck )
172 Any aOldValue;
173 Any aNewValue;
174 if ( m_bIsChecked )
175 aOldValue <<= AccessibleStateType::CHECKED;
176 else
177 aNewValue <<= AccessibleStateType::CHECKED;
178 m_bIsChecked = _bCheck;
179 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
183 void VCLXAccessibleToolBoxItem::SetIndeterminate( bool _bIndeterminate )
185 if ( m_bIndeterminate != _bIndeterminate )
187 Any aOldValue, aNewValue;
188 if ( m_bIndeterminate )
189 aOldValue <<= AccessibleStateType::INDETERMINATE;
190 else
191 aNewValue <<= AccessibleStateType::INDETERMINATE;
192 m_bIndeterminate = _bIndeterminate;
193 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
197 void VCLXAccessibleToolBoxItem::NameChanged()
199 OUString sNewName = implGetText();
200 if ( sNewName != m_sOldName )
202 Any aOldValue, aNewValue;
203 aOldValue <<= m_sOldName;
204 // save new name as old name for next change
205 m_sOldName = sNewName;
206 aNewValue <<= m_sOldName;
207 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
211 void VCLXAccessibleToolBoxItem::SetChild( const Reference< XAccessible >& _xChild )
213 m_xChild = _xChild;
216 void VCLXAccessibleToolBoxItem::NotifyChildEvent( const Reference< XAccessible >& _xChild, bool _bShow )
218 Any aOld = _bShow ? Any() : makeAny( _xChild );
219 Any aNew = _bShow ? makeAny( _xChild ) : Any();
220 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOld, aNew );
223 void VCLXAccessibleToolBoxItem::ToggleEnableState()
225 Any aOldValue[2], aNewValue[2];
226 if ( m_pToolBox->IsItemEnabled( m_nItemId ) )
228 aNewValue[0] <<= AccessibleStateType::SENSITIVE;
229 aNewValue[1] <<= AccessibleStateType::ENABLED;
231 else
233 aOldValue[0] <<= AccessibleStateType::ENABLED;
234 aOldValue[1] <<= AccessibleStateType::SENSITIVE;
237 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
238 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
241 awt::Rectangle VCLXAccessibleToolBoxItem::implGetBounds( ) throw (RuntimeException)
243 awt::Rectangle aRect;
244 if ( m_pToolBox )
245 aRect = AWTRectangle( m_pToolBox->GetItemPosRect( (sal_uInt16)m_nIndexInParent ) );
247 return aRect;
250 OUString VCLXAccessibleToolBoxItem::implGetText()
252 return GetText (true);
255 Locale VCLXAccessibleToolBoxItem::implGetLocale()
257 return Application::GetSettings().GetUILanguageTag().getLocale();
260 void VCLXAccessibleToolBoxItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
262 nStartIndex = 0;
263 nEndIndex = 0;
266 // XInterface
268 IMPLEMENT_FORWARD_REFCOUNT( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE )
269 Any SAL_CALL VCLXAccessibleToolBoxItem::queryInterface( const Type& _rType ) throw (RuntimeException, std::exception)
271 // #i33611# - toolbox buttons without text don't support XAccessibleText
272 if ( _rType == cppu::UnoType<XAccessibleText>::get()
273 && ( !m_pToolBox || m_pToolBox->GetButtonType() == ButtonType::SYMBOLONLY ) )
274 return Any();
276 ::com::sun::star::uno::Any aReturn = AccessibleTextHelper_BASE::queryInterface( _rType );
277 if ( !aReturn.hasValue() )
278 aReturn = VCLXAccessibleToolBoxItem_BASE::queryInterface( _rType );
279 return aReturn;
282 // XTypeProvider
284 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE, VCLXAccessibleToolBoxItem_BASE )
286 // XComponent
288 void SAL_CALL VCLXAccessibleToolBoxItem::disposing()
290 AccessibleTextHelper_BASE::disposing();
291 m_pToolBox = NULL;
294 // XServiceInfo
296 OUString VCLXAccessibleToolBoxItem::getImplementationName() throw (RuntimeException, std::exception)
298 return OUString( "com.sun.star.comp.toolkit.AccessibleToolBoxItem" );
301 sal_Bool VCLXAccessibleToolBoxItem::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
303 return cppu::supportsService(this, rServiceName);
306 Sequence< OUString > VCLXAccessibleToolBoxItem::getSupportedServiceNames() throw (RuntimeException, std::exception)
308 Sequence< OUString > aNames(4);
309 aNames[0] = "com.sun.star.accessibility.AccessibleContext";
310 aNames[1] = "com.sun.star.accessibility.AccessibleComponent";
311 aNames[2] = "com.sun.star.accessibility.AccessibleExtendedComponent";
312 aNames[3] = "com.sun.star.accessibility.AccessibleToolBoxItem";
313 return aNames;
316 // XAccessible
318 Reference< XAccessibleContext > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleContext( ) throw (RuntimeException, std::exception)
320 return this;
323 // XAccessibleContext
325 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChildCount( ) throw (RuntimeException, std::exception)
327 OContextEntryGuard aGuard( this );
329 return m_xChild.is() ? 1 : 0;
332 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, com::sun::star::lang::IndexOutOfBoundsException, std::exception)
334 OContextEntryGuard aGuard( this );
336 // no child -> so index is out of bounds
337 if ( !m_xChild.is() || i != 0 )
338 throw IndexOutOfBoundsException();
340 return m_xChild;
343 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleParent( ) throw (RuntimeException, std::exception)
345 OContextEntryGuard aGuard( this );
347 return m_pToolBox->GetAccessible();
350 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleIndexInParent( ) throw (RuntimeException, std::exception)
352 OContextEntryGuard aGuard( this );
354 return m_nIndexInParent;
357 sal_Int16 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRole( ) throw (RuntimeException, std::exception)
359 OContextEntryGuard aGuard( this );
361 return m_nRole;
364 OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleDescription( ) throw (RuntimeException, std::exception)
366 OExternalLockGuard aGuard( this );
368 if (m_nRole == AccessibleRole::PANEL && getAccessibleChildCount() > 0)
370 return TK_RES_STRING( RID_STR_ACC_PANEL_DESCRIPTION );
372 else
374 OUString sDescription;
375 if ( m_pToolBox )
376 sDescription = m_pToolBox->GetHelpText( m_nItemId );
377 return sDescription;
381 OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleName( ) throw (RuntimeException, std::exception)
383 OExternalLockGuard aGuard( this );
385 // entry text == accessible name
386 return GetText( true );
389 Reference< XAccessibleRelationSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRelationSet( ) throw (RuntimeException, std::exception)
391 OContextEntryGuard aGuard( this );
393 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
394 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
395 return xSet;
398 Reference< XAccessibleStateSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleStateSet( ) throw (RuntimeException, std::exception)
400 OExternalLockGuard aGuard( this );
402 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
403 Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
405 if ( m_pToolBox && !rBHelper.bDisposed && !rBHelper.bInDispose )
407 pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
408 if ( m_bIsChecked && m_nRole != AccessibleRole::PANEL )
409 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
410 if ( m_bIndeterminate )
411 pStateSetHelper->AddState( AccessibleStateType::INDETERMINATE );
412 if ( m_pToolBox->IsEnabled() && m_pToolBox->IsItemEnabled( m_nItemId ) )
414 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
415 pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
417 if ( m_pToolBox->IsItemVisible( m_nItemId ) )
418 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
419 if ( m_pToolBox->IsItemReallyVisible( m_nItemId ) )
420 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
421 if ( m_bHasFocus )
422 pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
424 else
425 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
427 return xStateSet;
430 // XAccessibleText
432 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getCaretPosition() throw (RuntimeException, std::exception)
434 return -1;
437 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
439 OExternalLockGuard aGuard( this );
441 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
442 throw IndexOutOfBoundsException();
444 return false;
447 Sequence< PropertyValue > SAL_CALL VCLXAccessibleToolBoxItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
449 OExternalLockGuard aGuard( this );
451 OUString sText( implGetText() );
453 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
454 throw IndexOutOfBoundsException();
456 return Sequence< PropertyValue >();
459 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
461 OExternalLockGuard aGuard( this );
463 OUString sText( implGetText() );
465 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
466 throw IndexOutOfBoundsException();
468 awt::Rectangle aBounds( 0, 0, 0, 0 );
469 if ( m_pToolBox && m_pToolBox->GetButtonType() != ButtonType::SYMBOLONLY ) // symbol buttons have no character bounds
471 Rectangle aCharRect = m_pToolBox->GetCharacterBounds( m_nItemId, nIndex );
472 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
473 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
474 aBounds = AWTRectangle( aCharRect );
477 return aBounds;
480 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException, std::exception)
482 OExternalLockGuard aGuard( this );
484 sal_Int32 nIndex = -1;
485 if ( m_pToolBox && m_pToolBox->GetButtonType() != ButtonType::SYMBOLONLY ) // symbol buttons have no character bounds
487 sal_uInt16 nItemId = 0;
488 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
489 Point aPnt( VCLPoint( aPoint ) );
490 aPnt += aItemRect.TopLeft();
491 sal_Int32 nIdx = m_pToolBox->GetIndexForPoint( aPnt, nItemId );
492 if ( nIdx != -1 && nItemId == m_nItemId )
493 nIndex = nIdx;
496 return nIndex;
499 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
501 OExternalLockGuard aGuard( this );
503 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
504 throw IndexOutOfBoundsException();
506 return false;
509 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
511 OExternalLockGuard aGuard( this );
513 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
514 throw IndexOutOfBoundsException();
516 bool bReturn = false;
518 if ( m_pToolBox )
520 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pToolBox->GetClipboard();
521 if ( xClipboard.is() )
523 OUString sText( getTextRange( nStartIndex, nEndIndex ) );
525 vcl::unohelper::TextDataObject* pDataObj = new vcl::unohelper::TextDataObject( sText );
527 SolarMutexReleaser aReleaser;
528 xClipboard->setContents( pDataObj, NULL );
530 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
531 if( xFlushableClipboard.is() )
532 xFlushableClipboard->flushClipboard();
534 bReturn = true;
538 return bReturn;
541 // XAccessibleComponent
543 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException, std::exception)
545 return Reference< XAccessible >();
548 void SAL_CALL VCLXAccessibleToolBoxItem::grabFocus( ) throw (RuntimeException, std::exception)
550 Reference< XAccessible > xParent(getAccessibleParent());
552 if( xParent.is() )
554 Reference< XAccessibleSelection > rxAccessibleSelection(xParent->getAccessibleContext(), UNO_QUERY);
556 if ( rxAccessibleSelection.is() )
558 rxAccessibleSelection -> selectAccessibleChild ( getAccessibleIndexInParent() );
563 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getForeground( ) throw (RuntimeException, std::exception)
565 OExternalLockGuard aGuard( this );
567 sal_Int32 nColor = 0;
568 if ( m_pToolBox )
569 nColor = m_pToolBox->GetControlForeground().GetColor();
571 return nColor;
574 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getBackground( ) throw (RuntimeException, std::exception)
576 OExternalLockGuard aGuard( this );
578 sal_Int32 nColor = 0;
579 if ( m_pToolBox )
580 nColor = m_pToolBox->GetControlBackground().GetColor();
582 return nColor;
585 // XAccessibleExtendedComponent
586 Reference< awt::XFont > SAL_CALL VCLXAccessibleToolBoxItem::getFont( ) throw (RuntimeException, std::exception)
588 return uno::Reference< awt::XFont >();
591 OUString SAL_CALL VCLXAccessibleToolBoxItem::getTitledBorderText( ) throw (RuntimeException, std::exception)
593 OExternalLockGuard aGuard( this );
595 OUString sRet;
596 if ( m_pToolBox )
597 sRet = m_pToolBox->GetItemText( m_nItemId );
599 return sRet;
602 OUString SAL_CALL VCLXAccessibleToolBoxItem::getToolTipText( ) throw (RuntimeException, std::exception)
604 OExternalLockGuard aGuard( this );
606 OUString sRet;
607 if ( m_pToolBox )
609 if ( Help::IsExtHelpEnabled() )
610 sRet = m_pToolBox->GetHelpText( m_nItemId );
611 else
612 sRet = m_pToolBox->GetQuickHelpText( m_nItemId );
613 if ( sRet.isEmpty() )
614 // no help text set, so use item text
615 sRet = m_pToolBox->GetItemText( m_nItemId );
617 return sRet;
620 // XAccessibleAction
622 sal_Int32 VCLXAccessibleToolBoxItem::getAccessibleActionCount( ) throw (RuntimeException, std::exception)
624 // only one action -> "Click"
625 return 1;
628 sal_Bool VCLXAccessibleToolBoxItem::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
630 OExternalLockGuard aGuard( this );
632 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
633 throw IndexOutOfBoundsException();
635 if ( m_pToolBox )
636 m_pToolBox->TriggerItem( m_nItemId );
638 return true;
641 OUString VCLXAccessibleToolBoxItem::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
643 OExternalLockGuard aGuard( this );
645 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
646 throw IndexOutOfBoundsException();
648 return OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
651 Reference< XAccessibleKeyBinding > VCLXAccessibleToolBoxItem::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
653 OContextEntryGuard aGuard( this );
655 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
656 throw IndexOutOfBoundsException();
658 return Reference< XAccessibleKeyBinding >();
661 // XAccessibleValue
663 Any VCLXAccessibleToolBoxItem::getCurrentValue( ) throw (RuntimeException, std::exception)
665 OExternalLockGuard aGuard( this );
667 Any aValue;
668 if ( m_pToolBox )
669 aValue <<= (sal_Int32)m_pToolBox->IsItemChecked( m_nItemId );
671 if( m_nRole == AccessibleRole::PANEL )
672 aValue <<= (sal_Int32)0;
673 return aValue;
676 sal_Bool VCLXAccessibleToolBoxItem::setCurrentValue( const Any& aNumber ) throw (RuntimeException, std::exception)
678 OExternalLockGuard aGuard( this );
680 bool bReturn = false;
682 if ( m_pToolBox )
684 sal_Int32 nValue = 0;
685 OSL_VERIFY( aNumber >>= nValue );
687 if ( nValue < 0 )
688 nValue = 0;
689 else if ( nValue > 1 )
690 nValue = 1;
692 m_pToolBox->CheckItem( m_nItemId, nValue == 1 );
693 bReturn = true;
696 return bReturn;
699 Any VCLXAccessibleToolBoxItem::getMaximumValue( ) throw (RuntimeException, std::exception)
701 return makeAny((sal_Int32)1);
704 Any VCLXAccessibleToolBoxItem::getMinimumValue( ) throw (RuntimeException, std::exception)
706 return makeAny((sal_Int32)0);
711 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */