Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / accessibility / source / standard / vclxaccessibletoolboxitem.cxx
blob04889bf0f2d9dc6a43441eadbfbaa2a879eb32e0
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 <toolkit/awt/vclxwindow.hxx>
39 #include <toolkit/helper/externallock.hxx>
40 #include <unotools/accessiblestatesethelper.hxx>
41 #include <unotools/accessiblerelationsethelper.hxx>
42 #include <cppuhelper/typeprovider.hxx>
43 #include <comphelper/sequence.hxx>
45 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
47 // class VCLXAccessibleToolBoxItem ------------------------------------------
49 using namespace ::com::sun::star::accessibility;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::beans;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star;
54 using namespace ::comphelper;
56 // -----------------------------------------------------------------------------
57 // Ctor() and Dtor()
58 // -----------------------------------------------------------------------------
59 VCLXAccessibleToolBoxItem::VCLXAccessibleToolBoxItem( ToolBox* _pToolBox, sal_Int32 _nPos ) :
61 AccessibleTextHelper_BASE( new VCLExternalSolarLock() ),
63 m_pToolBox ( _pToolBox ),
64 m_nIndexInParent( _nPos ),
65 m_nRole ( AccessibleRole::PUSH_BUTTON ),
66 m_nItemId ( 0 ),
67 m_bHasFocus ( sal_False ),
68 m_bIsChecked ( sal_False ),
69 m_bIndeterminate( false )
72 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) );
74 OSL_ENSURE( m_pToolBox, "invalid toolbox" );
75 m_nItemId = m_pToolBox->GetItemId( (sal_uInt16)m_nIndexInParent );
76 m_sOldName = GetText( true );
77 m_bIsChecked = m_pToolBox->IsItemChecked( m_nItemId );
78 m_bIndeterminate = ( m_pToolBox->GetItemState( m_nItemId ) == STATE_DONTKNOW );
79 ToolBoxItemType eType = m_pToolBox->GetItemType( (sal_uInt16)m_nIndexInParent );
80 switch ( eType )
82 case TOOLBOXITEM_BUTTON :
84 ToolBoxItemBits nBits = m_pToolBox->GetItemBits( m_nItemId );
85 if (( nBits & TIB_DROPDOWN ) == TIB_DROPDOWN)
86 m_nRole = AccessibleRole::BUTTON_DROPDOWN;
87 else if (( ( nBits & TIB_CHECKABLE ) == TIB_CHECKABLE ) ||
88 ( ( nBits & TIB_AUTOCHECK ) == TIB_AUTOCHECK ) )
89 m_nRole = AccessibleRole::TOGGLE_BUTTON;
90 else if ( m_pToolBox->GetItemWindow( m_nItemId ) )
91 m_nRole = AccessibleRole::PANEL;
92 break;
95 case TOOLBOXITEM_SPACE :
96 m_nRole = AccessibleRole::FILLER;
97 break;
99 case TOOLBOXITEM_SEPARATOR :
100 case TOOLBOXITEM_BREAK :
101 m_nRole = AccessibleRole::SEPARATOR;
102 break;
104 default:
106 SAL_WARN( "accessibility", "unsupported toolbox itemtype" );
110 // -----------------------------------------------------------------------------
111 VCLXAccessibleToolBoxItem::~VCLXAccessibleToolBoxItem()
113 delete m_pExternalLock;
114 m_pExternalLock = NULL;
116 // -----------------------------------------------------------------------------
117 OUString VCLXAccessibleToolBoxItem::GetText( bool _bAsName )
119 OUString sRet;
120 // no text for separators and spaces
121 if ( m_pToolBox && m_nItemId > 0 && ( _bAsName || m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) )
123 sRet = m_pToolBox->GetItemText( m_nItemId );
125 return sRet;
127 // -----------------------------------------------------------------------------
128 void VCLXAccessibleToolBoxItem::SetFocus( sal_Bool _bFocus )
130 if ( m_bHasFocus != _bFocus )
132 Any aOldValue;
133 Any aNewValue;
134 if ( m_bHasFocus )
135 aOldValue <<= AccessibleStateType::FOCUSED;
136 else
137 aNewValue <<= AccessibleStateType::FOCUSED;
138 m_bHasFocus = _bFocus;
139 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
142 // -----------------------------------------------------------------------------
143 void VCLXAccessibleToolBoxItem::SetChecked( sal_Bool _bCheck )
145 if ( m_bIsChecked != _bCheck )
147 Any aOldValue;
148 Any aNewValue;
149 if ( m_bIsChecked )
150 aOldValue <<= AccessibleStateType::CHECKED;
151 else
152 aNewValue <<= AccessibleStateType::CHECKED;
153 m_bIsChecked = _bCheck;
154 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
157 // -----------------------------------------------------------------------------
158 void VCLXAccessibleToolBoxItem::SetIndeterminate( bool _bIndeterminate )
160 if ( m_bIndeterminate != _bIndeterminate )
162 Any aOldValue, aNewValue;
163 if ( m_bIndeterminate )
164 aOldValue <<= AccessibleStateType::INDETERMINATE;
165 else
166 aNewValue <<= AccessibleStateType::INDETERMINATE;
167 m_bIndeterminate = _bIndeterminate;
168 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
171 // -----------------------------------------------------------------------------
172 void VCLXAccessibleToolBoxItem::NameChanged()
174 OUString sNewName = implGetText();
175 if ( sNewName != m_sOldName )
177 Any aOldValue, aNewValue;
178 aOldValue <<= m_sOldName;
179 // save new name as old name for next change
180 m_sOldName = sNewName;
181 aNewValue <<= m_sOldName;
182 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
185 // -----------------------------------------------------------------------------
186 void VCLXAccessibleToolBoxItem::SetChild( const Reference< XAccessible >& _xChild )
188 m_xChild = _xChild;
190 // -----------------------------------------------------------------------------
191 void VCLXAccessibleToolBoxItem::NotifyChildEvent( const Reference< XAccessible >& _xChild, bool _bShow )
193 Any aOld = _bShow ? Any() : makeAny( _xChild );
194 Any aNew = _bShow ? makeAny( _xChild ) : Any();
195 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOld, aNew );
197 // -----------------------------------------------------------------------------
198 void VCLXAccessibleToolBoxItem::ToggleEnableState()
200 Any aOldValue[2], aNewValue[2];
201 if ( m_pToolBox->IsItemEnabled( m_nItemId ) )
203 aNewValue[0] <<= AccessibleStateType::SENSITIVE;
204 aNewValue[1] <<= AccessibleStateType::ENABLED;
206 else
208 aOldValue[0] <<= AccessibleStateType::ENABLED;
209 aOldValue[1] <<= AccessibleStateType::SENSITIVE;
212 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
213 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
215 // -----------------------------------------------------------------------------
216 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::implGetBounds( ) throw (RuntimeException)
218 awt::Rectangle aRect;
219 if ( m_pToolBox )
220 aRect = AWTRectangle( m_pToolBox->GetItemPosRect( (sal_uInt16)m_nIndexInParent ) );
222 return aRect;
224 // -----------------------------------------------------------------------------
225 OUString VCLXAccessibleToolBoxItem::implGetText()
227 return GetText (true);
229 // -----------------------------------------------------------------------------
230 Locale VCLXAccessibleToolBoxItem::implGetLocale()
232 return Application::GetSettings().GetUILanguageTag().getLocale();
234 // -----------------------------------------------------------------------------
235 void VCLXAccessibleToolBoxItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
237 nStartIndex = 0;
238 nEndIndex = 0;
240 // -----------------------------------------------------------------------------
241 // XInterface
242 // -----------------------------------------------------------------------------
243 IMPLEMENT_FORWARD_REFCOUNT( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE )
244 Any SAL_CALL VCLXAccessibleToolBoxItem::queryInterface( const Type& _rType ) throw (RuntimeException)
246 // #i33611# - toolbox buttons without text don't support XAccessibleText
247 if ( _rType == ::getCppuType( ( const Reference< XAccessibleText >* ) 0 )
248 && ( !m_pToolBox || m_pToolBox->GetButtonType() == BUTTON_SYMBOL ) )
249 return Any();
251 ::com::sun::star::uno::Any aReturn = AccessibleTextHelper_BASE::queryInterface( _rType );
252 if ( !aReturn.hasValue() )
253 aReturn = VCLXAccessibleToolBoxItem_BASE::queryInterface( _rType );
254 return aReturn;
256 // -----------------------------------------------------------------------------
257 // XTypeProvider
258 // -----------------------------------------------------------------------------
259 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE, VCLXAccessibleToolBoxItem_BASE )
260 // -----------------------------------------------------------------------------
261 // XComponent
262 // -----------------------------------------------------------------------------
263 void SAL_CALL VCLXAccessibleToolBoxItem::disposing()
265 AccessibleTextHelper_BASE::disposing();
266 m_pToolBox = NULL;
268 // -----------------------------------------------------------------------------
269 // XServiceInfo
270 // -----------------------------------------------------------------------------
271 OUString VCLXAccessibleToolBoxItem::getImplementationName() throw (RuntimeException)
273 return OUString( "com.sun.star.comp.toolkit.AccessibleToolBoxItem" );
275 // -----------------------------------------------------------------------------
276 sal_Bool VCLXAccessibleToolBoxItem::supportsService( const OUString& rServiceName ) throw (RuntimeException)
278 return cppu::supportsService(this, rServiceName);
280 // -----------------------------------------------------------------------------
281 Sequence< OUString > VCLXAccessibleToolBoxItem::getSupportedServiceNames() throw (RuntimeException)
283 Sequence< OUString > aNames(4);
284 aNames[0] = "com.sun.star.accessibility.AccessibleContext";
285 aNames[1] = "com.sun.star.accessibility.AccessibleComponent";
286 aNames[2] = "com.sun.star.accessibility.AccessibleExtendedComponent";
287 aNames[3] = "com.sun.star.accessibility.AccessibleToolBoxItem";
288 return aNames;
290 // -----------------------------------------------------------------------------
291 // XAccessible
292 // -----------------------------------------------------------------------------
293 Reference< XAccessibleContext > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleContext( ) throw (RuntimeException)
295 return this;
297 // -----------------------------------------------------------------------------
298 // XAccessibleContext
299 // -----------------------------------------------------------------------------
300 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChildCount( ) throw (RuntimeException)
302 OContextEntryGuard aGuard( this );
304 return m_xChild.is() ? 1 : 0;
306 // -----------------------------------------------------------------------------
307 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, com::sun::star::lang::IndexOutOfBoundsException)
309 OContextEntryGuard aGuard( this );
311 // no child -> so index is out of bounds
312 if ( !m_xChild.is() || i != 0 )
313 throw IndexOutOfBoundsException();
315 return m_xChild;
317 // -----------------------------------------------------------------------------
318 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleParent( ) throw (RuntimeException)
320 OContextEntryGuard aGuard( this );
322 return m_pToolBox->GetAccessible();
324 // -----------------------------------------------------------------------------
325 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleIndexInParent( ) throw (RuntimeException)
327 OContextEntryGuard aGuard( this );
329 return m_nIndexInParent;
331 // -----------------------------------------------------------------------------
332 sal_Int16 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRole( ) throw (RuntimeException)
334 OContextEntryGuard aGuard( this );
336 return m_nRole;
338 // -----------------------------------------------------------------------------
339 OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleDescription( ) throw (RuntimeException)
341 OExternalLockGuard aGuard( this );
343 OUString sDescription;
344 if ( m_pToolBox )
345 sDescription = m_pToolBox->GetHelpText( m_nItemId );
347 return sDescription;
349 // -----------------------------------------------------------------------------
350 OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleName( ) throw (RuntimeException)
352 OExternalLockGuard aGuard( this );
354 // entry text == accessible name
355 return GetText( true );
357 // -----------------------------------------------------------------------------
358 Reference< XAccessibleRelationSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRelationSet( ) throw (RuntimeException)
360 OContextEntryGuard aGuard( this );
362 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
363 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
364 return xSet;
366 // -----------------------------------------------------------------------------
367 Reference< XAccessibleStateSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleStateSet( ) throw (RuntimeException)
369 OExternalLockGuard aGuard( this );
371 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
372 Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
374 if ( m_pToolBox && !rBHelper.bDisposed && !rBHelper.bInDispose )
376 pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
377 if ( m_bIsChecked )
378 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
379 if ( m_bIndeterminate )
380 pStateSetHelper->AddState( AccessibleStateType::INDETERMINATE );
381 if ( m_pToolBox->IsItemEnabled( m_nItemId ) )
383 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
384 pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
386 if ( m_pToolBox->IsItemVisible( m_nItemId ) )
387 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
388 if ( m_pToolBox->IsItemReallyVisible( m_nItemId ) )
389 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
390 if ( m_bHasFocus )
391 pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
393 else
394 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
396 return xStateSet;
398 // -----------------------------------------------------------------------------
399 // XAccessibleText
400 // -----------------------------------------------------------------------------
401 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getCaretPosition() throw (RuntimeException)
403 return -1;
405 // -----------------------------------------------------------------------------
406 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
408 OExternalLockGuard aGuard( this );
410 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
411 throw IndexOutOfBoundsException();
413 return sal_False;
415 // -----------------------------------------------------------------------------
416 Sequence< PropertyValue > SAL_CALL VCLXAccessibleToolBoxItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& ) throw (IndexOutOfBoundsException, RuntimeException)
418 OExternalLockGuard aGuard( this );
420 OUString sText( implGetText() );
422 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
423 throw IndexOutOfBoundsException();
425 return Sequence< PropertyValue >();
427 // -----------------------------------------------------------------------------
428 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
430 OExternalLockGuard aGuard( this );
432 OUString sText( implGetText() );
434 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
435 throw IndexOutOfBoundsException();
437 awt::Rectangle aBounds( 0, 0, 0, 0 );
438 if ( m_pToolBox && m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) // symbol buttons have no character bounds
440 Rectangle aCharRect = m_pToolBox->GetCharacterBounds( m_nItemId, nIndex );
441 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
442 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
443 aBounds = AWTRectangle( aCharRect );
446 return aBounds;
448 // -----------------------------------------------------------------------------
449 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
451 OExternalLockGuard aGuard( this );
453 sal_Int32 nIndex = -1;
454 if ( m_pToolBox && m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) // symbol buttons have no character bounds
456 sal_uInt16 nItemId = 0;
457 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
458 Point aPnt( VCLPoint( aPoint ) );
459 aPnt += aItemRect.TopLeft();
460 sal_Int32 nIdx = m_pToolBox->GetIndexForPoint( aPnt, nItemId );
461 if ( nIdx != -1 && nItemId == m_nItemId )
462 nIndex = nIdx;
465 return nIndex;
467 // -----------------------------------------------------------------------------
468 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
470 OExternalLockGuard aGuard( this );
472 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
473 throw IndexOutOfBoundsException();
475 return sal_False;
477 // -----------------------------------------------------------------------------
478 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
480 OExternalLockGuard aGuard( this );
482 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
483 throw IndexOutOfBoundsException();
485 sal_Bool bReturn = sal_False;
487 if ( m_pToolBox )
489 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pToolBox->GetClipboard();
490 if ( xClipboard.is() )
492 OUString sText( getTextRange( nStartIndex, nEndIndex ) );
494 ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
495 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
496 xClipboard->setContents( pDataObj, NULL );
498 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
499 if( xFlushableClipboard.is() )
500 xFlushableClipboard->flushClipboard();
502 Application::AcquireSolarMutex( nRef );
504 bReturn = sal_True;
508 return bReturn;
510 // -----------------------------------------------------------------------------
511 // XAccessibleComponent
512 // -----------------------------------------------------------------------------
513 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
515 return Reference< XAccessible >();
517 // -----------------------------------------------------------------------------
518 void SAL_CALL VCLXAccessibleToolBoxItem::grabFocus( ) throw (RuntimeException)
520 Reference< XAccessible > xParent(getAccessibleParent());
522 if( xParent.is() )
524 Reference< XAccessibleSelection > rxAccessibleSelection(xParent->getAccessibleContext(), UNO_QUERY);
526 if ( rxAccessibleSelection.is() )
528 rxAccessibleSelection -> selectAccessibleChild ( getAccessibleIndexInParent() );
532 // -----------------------------------------------------------------------------
533 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getForeground( ) throw (RuntimeException)
535 OExternalLockGuard aGuard( this );
537 sal_Int32 nColor = 0;
538 if ( m_pToolBox )
539 nColor = m_pToolBox->GetControlForeground().GetColor();
541 return nColor;
543 // -----------------------------------------------------------------------------
544 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getBackground( ) throw (RuntimeException)
546 OExternalLockGuard aGuard( this );
548 sal_Int32 nColor = 0;
549 if ( m_pToolBox )
550 nColor = m_pToolBox->GetControlBackground().GetColor();
552 return nColor;
554 // -----------------------------------------------------------------------------
555 // XAccessibleExtendedComponent
556 // -----------------------------------------------------------------------------
557 Reference< awt::XFont > SAL_CALL VCLXAccessibleToolBoxItem::getFont( ) throw (RuntimeException)
559 return uno::Reference< awt::XFont >();
561 // -----------------------------------------------------------------------------
562 awt::FontDescriptor SAL_CALL VCLXAccessibleToolBoxItem::getFontMetrics( const Reference< awt::XFont >& xFont ) throw (RuntimeException)
564 return xFont->getFontDescriptor();
566 // -----------------------------------------------------------------------------
567 OUString SAL_CALL VCLXAccessibleToolBoxItem::getTitledBorderText( ) throw (RuntimeException)
569 OExternalLockGuard aGuard( this );
571 OUString sRet;
572 if ( m_pToolBox )
573 sRet = m_pToolBox->GetItemText( m_nItemId );
575 return sRet;
577 // -----------------------------------------------------------------------------
578 OUString SAL_CALL VCLXAccessibleToolBoxItem::getToolTipText( ) throw (RuntimeException)
580 OExternalLockGuard aGuard( this );
582 OUString sRet;
583 if ( m_pToolBox )
585 if ( Help::IsExtHelpEnabled() )
586 sRet = m_pToolBox->GetHelpText( m_nItemId );
587 else
588 sRet = m_pToolBox->GetQuickHelpText( m_nItemId );
589 if ( sRet.isEmpty() )
590 // no help text set, so use item text
591 sRet = m_pToolBox->GetItemText( m_nItemId );
593 return sRet;
595 // -----------------------------------------------------------------------------
596 // XAccessibleAction
597 // -----------------------------------------------------------------------------
598 sal_Int32 VCLXAccessibleToolBoxItem::getAccessibleActionCount( ) throw (RuntimeException)
600 // only one action -> "Click"
601 return 1;
603 // -----------------------------------------------------------------------------
604 sal_Bool VCLXAccessibleToolBoxItem::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
606 OExternalLockGuard aGuard( this );
608 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
609 throw IndexOutOfBoundsException();
611 if ( m_pToolBox )
612 m_pToolBox->TriggerItem( m_nItemId );
614 return sal_True;
616 // -----------------------------------------------------------------------------
617 OUString VCLXAccessibleToolBoxItem::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
619 OExternalLockGuard aGuard( this );
621 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
622 throw IndexOutOfBoundsException();
624 return OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
626 // -----------------------------------------------------------------------------
627 Reference< XAccessibleKeyBinding > VCLXAccessibleToolBoxItem::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
629 OContextEntryGuard aGuard( this );
631 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
632 throw IndexOutOfBoundsException();
634 return Reference< XAccessibleKeyBinding >();
636 // -----------------------------------------------------------------------------
637 // XAccessibleValue
638 // -----------------------------------------------------------------------------
639 Any VCLXAccessibleToolBoxItem::getCurrentValue( ) throw (RuntimeException)
641 OExternalLockGuard aGuard( this );
643 Any aValue;
644 if ( m_pToolBox )
645 aValue <<= (sal_Int32)m_pToolBox->IsItemChecked( m_nItemId );
647 return aValue;
649 // -----------------------------------------------------------------------------
650 sal_Bool VCLXAccessibleToolBoxItem::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
652 OExternalLockGuard aGuard( this );
654 sal_Bool bReturn = sal_False;
656 if ( m_pToolBox )
658 sal_Int32 nValue = 0;
659 OSL_VERIFY( aNumber >>= nValue );
661 if ( nValue < 0 )
662 nValue = 0;
663 else if ( nValue > 1 )
664 nValue = 1;
666 m_pToolBox->CheckItem( m_nItemId, (sal_Bool) nValue );
667 bReturn = sal_True;
670 return bReturn;
672 // -----------------------------------------------------------------------------
673 Any VCLXAccessibleToolBoxItem::getMaximumValue( ) throw (RuntimeException)
675 return makeAny((sal_Int32)1);
677 // -----------------------------------------------------------------------------
678 Any VCLXAccessibleToolBoxItem::getMinimumValue( ) throw (RuntimeException)
680 return makeAny((sal_Int32)0);
682 // -----------------------------------------------------------------------------
685 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */