merge the formfield patch from ooo-build
[ooovba.git] / accessibility / source / standard / vclxaccessibletoolboxitem.cxx
blob2227c858528f8cbd5e2d89c1c967f09aaf821fe5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessibletoolboxitem.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include <accessibility/standard/vclxaccessibletoolboxitem.hxx>
34 #include <toolkit/helper/convert.hxx>
35 #include <accessibility/helper/accresmgr.hxx>
36 #include <accessibility/helper/accessiblestrings.hrc>
37 #include <com/sun/star/awt/Point.hpp>
38 #include <com/sun/star/awt/Rectangle.hpp>
39 #include <com/sun/star/awt/Size.hpp>
41 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
42 #include <com/sun/star/accessibility/AccessibleRole.hpp>
43 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
44 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
45 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
46 #include <tools/debug.hxx>
47 #include <vcl/svapp.hxx>
48 #include <vcl/toolbox.hxx>
49 #include <vcl/unohelp2.hxx>
50 #include <vcl/help.hxx>
51 #include <toolkit/awt/vclxwindow.hxx>
52 #include <toolkit/helper/externallock.hxx>
53 #include <unotools/accessiblestatesethelper.hxx>
54 #include <unotools/accessiblerelationsethelper.hxx>
55 #include <cppuhelper/typeprovider.hxx>
56 #include <comphelper/sequence.hxx>
58 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
60 // class VCLXAccessibleToolBoxItem ------------------------------------------
62 using namespace ::com::sun::star::accessibility;
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star;
67 using namespace ::comphelper;
69 DBG_NAME(VCLXAccessibleToolBoxItem)
71 // -----------------------------------------------------------------------------
72 // Ctor() and Dtor()
73 // -----------------------------------------------------------------------------
74 VCLXAccessibleToolBoxItem::VCLXAccessibleToolBoxItem( ToolBox* _pToolBox, sal_Int32 _nPos ) :
76 AccessibleTextHelper_BASE( new VCLExternalSolarLock() ),
78 m_pToolBox ( _pToolBox ),
79 m_nIndexInParent( _nPos ),
80 m_nRole ( AccessibleRole::PUSH_BUTTON ),
81 m_nItemId ( 0 ),
82 m_bHasFocus ( sal_False ),
83 m_bIsChecked ( sal_False ),
84 m_bIndeterminate( false )
87 DBG_CTOR( VCLXAccessibleToolBoxItem, NULL );
89 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) );
91 DBG_ASSERT( m_pToolBox, "invalid toolbox" );
92 m_nItemId = m_pToolBox->GetItemId( (USHORT)m_nIndexInParent );
93 m_sOldName = GetText( true );
94 m_bIsChecked = m_pToolBox->IsItemChecked( m_nItemId );
95 m_bIndeterminate = ( m_pToolBox->GetItemState( m_nItemId ) == STATE_DONTKNOW );
96 ToolBoxItemType eType = m_pToolBox->GetItemType( (USHORT)m_nIndexInParent );
97 switch ( eType )
99 case TOOLBOXITEM_BUTTON :
101 ToolBoxItemBits nBits = m_pToolBox->GetItemBits( m_nItemId );
102 if (( nBits & TIB_DROPDOWN ) == TIB_DROPDOWN)
103 m_nRole = AccessibleRole::BUTTON_DROPDOWN;
104 else if (( ( nBits & TIB_CHECKABLE ) == TIB_CHECKABLE ) ||
105 ( ( nBits & TIB_AUTOCHECK ) == TIB_AUTOCHECK ) )
106 m_nRole = AccessibleRole::TOGGLE_BUTTON;
107 else if ( m_pToolBox->GetItemWindow( m_nItemId ) )
108 m_nRole = AccessibleRole::PANEL;
109 break;
112 case TOOLBOXITEM_SPACE :
113 m_nRole = AccessibleRole::FILLER;
114 break;
116 case TOOLBOXITEM_SEPARATOR :
117 case TOOLBOXITEM_BREAK :
118 m_nRole = AccessibleRole::SEPARATOR;
119 break;
121 default:
123 DBG_ERRORFILE( "unsupported toolbox itemtype" );
127 // -----------------------------------------------------------------------------
128 VCLXAccessibleToolBoxItem::~VCLXAccessibleToolBoxItem()
130 DBG_DTOR( VCLXAccessibleToolBoxItem, NULL );
132 delete m_pExternalLock;
133 m_pExternalLock = NULL;
135 // -----------------------------------------------------------------------------
136 ::rtl::OUString VCLXAccessibleToolBoxItem::GetText( bool _bAsName )
138 ::rtl::OUString sRet;
139 // no text for separators and spaces
140 if ( m_pToolBox && m_nItemId > 0 && ( _bAsName || m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) )
142 sRet = m_pToolBox->GetItemText( m_nItemId );
143 //OJ #108243# we only read the name of the toolboxitem
145 // Window* pItemWindow = m_pToolBox->GetItemWindow( m_nItemId );
146 // if ( pItemWindow && pItemWindow->GetAccessible().is() &&
147 // pItemWindow->GetAccessible()->getAccessibleContext().is() )
148 // {
149 // ::rtl::OUString sWinText = pItemWindow->GetAccessible()->getAccessibleContext()->getAccessibleName();
150 // if ( ( sRet.getLength() > 0 ) && ( sWinText.getLength() > 0 ) )
151 // sRet += String( RTL_CONSTASCII_USTRINGPARAM( " " ) );
152 // sRet += sWinText;
153 // }
155 return sRet;
157 // -----------------------------------------------------------------------------
158 void VCLXAccessibleToolBoxItem::SetFocus( sal_Bool _bFocus )
160 if ( m_bHasFocus != _bFocus )
162 Any aOldValue;
163 Any aNewValue;
164 if ( m_bHasFocus )
165 aOldValue <<= AccessibleStateType::FOCUSED;
166 else
167 aNewValue <<= AccessibleStateType::FOCUSED;
168 m_bHasFocus = _bFocus;
169 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
172 // -----------------------------------------------------------------------------
173 void VCLXAccessibleToolBoxItem::SetChecked( sal_Bool _bCheck )
175 if ( m_bIsChecked != _bCheck )
177 Any aOldValue;
178 Any aNewValue;
179 if ( m_bIsChecked )
180 aOldValue <<= AccessibleStateType::CHECKED;
181 else
182 aNewValue <<= AccessibleStateType::CHECKED;
183 m_bIsChecked = _bCheck;
184 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
187 // -----------------------------------------------------------------------------
188 void VCLXAccessibleToolBoxItem::SetIndeterminate( bool _bIndeterminate )
190 if ( m_bIndeterminate != _bIndeterminate )
192 Any aOldValue, aNewValue;
193 if ( m_bIndeterminate )
194 aOldValue <<= AccessibleStateType::INDETERMINATE;
195 else
196 aNewValue <<= AccessibleStateType::INDETERMINATE;
197 m_bIndeterminate = _bIndeterminate;
198 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
201 // -----------------------------------------------------------------------------
202 void VCLXAccessibleToolBoxItem::NameChanged()
204 ::rtl::OUString sNewName = implGetText();
205 if ( sNewName != m_sOldName )
207 Any aOldValue, aNewValue;
208 aOldValue <<= m_sOldName;
209 // save new name as old name for next change
210 m_sOldName = sNewName;
211 aNewValue <<= m_sOldName;
212 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
215 // -----------------------------------------------------------------------------
216 void VCLXAccessibleToolBoxItem::SetChild( const Reference< XAccessible >& _xChild )
218 m_xChild = _xChild;
220 // -----------------------------------------------------------------------------
221 void VCLXAccessibleToolBoxItem::NotifyChildEvent( const Reference< XAccessible >& _xChild, bool _bShow )
223 Any aOld = _bShow ? Any() : makeAny( _xChild );
224 Any aNew = _bShow ? makeAny( _xChild ) : Any();
225 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOld, aNew );
227 // -----------------------------------------------------------------------------
228 void VCLXAccessibleToolBoxItem::ToggleEnableState()
230 Any aOldValue[2], aNewValue[2];
231 if ( m_pToolBox->IsItemEnabled( m_nItemId ) )
233 aNewValue[0] <<= AccessibleStateType::SENSITIVE;
234 aNewValue[1] <<= AccessibleStateType::ENABLED;
236 else
238 aOldValue[0] <<= AccessibleStateType::ENABLED;
239 aOldValue[1] <<= AccessibleStateType::SENSITIVE;
242 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
243 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
245 // -----------------------------------------------------------------------------
246 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::implGetBounds( ) throw (RuntimeException)
248 awt::Rectangle aRect;
249 if ( m_pToolBox )
250 aRect = AWTRectangle( m_pToolBox->GetItemPosRect( (USHORT)m_nIndexInParent ) );
252 return aRect;
254 // -----------------------------------------------------------------------------
255 ::rtl::OUString VCLXAccessibleToolBoxItem::implGetText()
257 return GetText (true);
259 // -----------------------------------------------------------------------------
260 Locale VCLXAccessibleToolBoxItem::implGetLocale()
262 return Application::GetSettings().GetUILocale();
264 // -----------------------------------------------------------------------------
265 void VCLXAccessibleToolBoxItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
267 nStartIndex = 0;
268 nEndIndex = 0;
270 // -----------------------------------------------------------------------------
271 // XInterface
272 // -----------------------------------------------------------------------------
273 IMPLEMENT_FORWARD_REFCOUNT( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE )
274 Any SAL_CALL VCLXAccessibleToolBoxItem::queryInterface( const Type& _rType ) throw (RuntimeException)
276 // --> PB 2004-09-03 #i33611# - toolbox buttons without text don't support XAccessibleText
277 if ( _rType == ::getCppuType( ( const Reference< XAccessibleText >* ) 0 )
278 && ( !m_pToolBox || m_pToolBox->GetButtonType() == BUTTON_SYMBOL ) )
279 return Any();
280 // <--
282 ::com::sun::star::uno::Any aReturn = AccessibleTextHelper_BASE::queryInterface( _rType );
283 if ( !aReturn.hasValue() )
284 aReturn = VCLXAccessibleToolBoxItem_BASE::queryInterface( _rType );
285 return aReturn;
287 // -----------------------------------------------------------------------------
288 // XTypeProvider
289 // -----------------------------------------------------------------------------
290 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE, VCLXAccessibleToolBoxItem_BASE )
291 // -----------------------------------------------------------------------------
292 // XComponent
293 // -----------------------------------------------------------------------------
294 void SAL_CALL VCLXAccessibleToolBoxItem::disposing()
296 AccessibleTextHelper_BASE::disposing();
297 m_pToolBox = NULL;
299 // -----------------------------------------------------------------------------
300 // XServiceInfo
301 // -----------------------------------------------------------------------------
302 ::rtl::OUString VCLXAccessibleToolBoxItem::getImplementationName() throw (RuntimeException)
304 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleToolBoxItem" );
306 // -----------------------------------------------------------------------------
307 sal_Bool VCLXAccessibleToolBoxItem::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
309 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
310 const ::rtl::OUString* pNames = aNames.getConstArray();
311 const ::rtl::OUString* pEnd = pNames + aNames.getLength();
312 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
315 return pNames != pEnd;
317 // -----------------------------------------------------------------------------
318 Sequence< ::rtl::OUString > VCLXAccessibleToolBoxItem::getSupportedServiceNames() throw (RuntimeException)
320 Sequence< ::rtl::OUString > aNames(4);
321 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleContext" );
322 aNames[1] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleComponent" );
323 aNames[2] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleExtendedComponent" );
324 aNames[3] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleToolBoxItem" );
325 return aNames;
327 // -----------------------------------------------------------------------------
328 // XAccessible
329 // -----------------------------------------------------------------------------
330 Reference< XAccessibleContext > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleContext( ) throw (RuntimeException)
332 return this;
334 // -----------------------------------------------------------------------------
335 // XAccessibleContext
336 // -----------------------------------------------------------------------------
337 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChildCount( ) throw (RuntimeException)
339 OContextEntryGuard aGuard( this );
341 return m_xChild.is() ? 1 : 0;
343 // -----------------------------------------------------------------------------
344 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, com::sun::star::lang::IndexOutOfBoundsException)
346 OContextEntryGuard aGuard( this );
348 // no child -> so index is out of bounds
349 if ( !m_xChild.is() || i != 0 )
350 throw IndexOutOfBoundsException();
352 return m_xChild;
354 // -----------------------------------------------------------------------------
355 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleParent( ) throw (RuntimeException)
357 OContextEntryGuard aGuard( this );
359 return m_pToolBox->GetAccessible();
361 // -----------------------------------------------------------------------------
362 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleIndexInParent( ) throw (RuntimeException)
364 OContextEntryGuard aGuard( this );
366 return m_nIndexInParent;
368 // -----------------------------------------------------------------------------
369 sal_Int16 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRole( ) throw (RuntimeException)
371 OContextEntryGuard aGuard( this );
373 return m_nRole;
375 // -----------------------------------------------------------------------------
376 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleDescription( ) throw (RuntimeException)
378 OExternalLockGuard aGuard( this );
380 ::rtl::OUString sDescription;
381 if ( m_pToolBox )
382 sDescription = m_pToolBox->GetHelpText( m_nItemId );
384 return sDescription;
386 // -----------------------------------------------------------------------------
387 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleName( ) throw (RuntimeException)
389 OExternalLockGuard aGuard( this );
391 // entry text == accessible name
392 return GetText( true );
394 // -----------------------------------------------------------------------------
395 Reference< XAccessibleRelationSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRelationSet( ) throw (RuntimeException)
397 OContextEntryGuard aGuard( this );
399 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
400 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
401 return xSet;
403 // -----------------------------------------------------------------------------
404 Reference< XAccessibleStateSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleStateSet( ) throw (RuntimeException)
406 OExternalLockGuard aGuard( this );
408 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
409 Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
411 if ( m_pToolBox && !rBHelper.bDisposed && !rBHelper.bInDispose )
413 pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
414 if ( m_bIsChecked )
415 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
416 if ( m_bIndeterminate )
417 pStateSetHelper->AddState( AccessibleStateType::INDETERMINATE );
418 if ( m_pToolBox->IsItemEnabled( m_nItemId ) )
420 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
421 pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
423 if ( m_pToolBox->IsItemVisible( m_nItemId ) )
424 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
425 if ( m_pToolBox->IsItemReallyVisible( m_nItemId ) )
426 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
427 if ( m_bHasFocus )
428 pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
430 else
431 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
433 return xStateSet;
435 // -----------------------------------------------------------------------------
436 // XAccessibleText
437 // -----------------------------------------------------------------------------
438 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getCaretPosition() throw (RuntimeException)
440 return -1;
442 // -----------------------------------------------------------------------------
443 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
445 OExternalLockGuard aGuard( this );
447 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
448 throw IndexOutOfBoundsException();
450 return sal_False;
452 // -----------------------------------------------------------------------------
453 Sequence< PropertyValue > SAL_CALL VCLXAccessibleToolBoxItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& ) throw (IndexOutOfBoundsException, RuntimeException)
455 OExternalLockGuard aGuard( this );
457 ::rtl::OUString sText( implGetText() );
459 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
460 throw IndexOutOfBoundsException();
462 return Sequence< PropertyValue >();
464 // -----------------------------------------------------------------------------
465 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
467 OExternalLockGuard aGuard( this );
469 ::rtl::OUString sText( implGetText() );
471 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
472 throw IndexOutOfBoundsException();
474 awt::Rectangle aBounds( 0, 0, 0, 0 );
475 if ( m_pToolBox && m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) // symbol buttons have no character bounds
477 Rectangle aCharRect = m_pToolBox->GetCharacterBounds( m_nItemId, nIndex );
478 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
479 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
480 aBounds = AWTRectangle( aCharRect );
483 return aBounds;
485 // -----------------------------------------------------------------------------
486 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
488 OExternalLockGuard aGuard( this );
490 sal_Int32 nIndex = -1;
491 if ( m_pToolBox && m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) // symbol buttons have no character bounds
493 sal_uInt16 nItemId = 0;
494 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
495 Point aPnt( VCLPoint( aPoint ) );
496 aPnt += aItemRect.TopLeft();
497 sal_Int32 nIdx = m_pToolBox->GetIndexForPoint( aPnt, nItemId );
498 if ( nIdx != -1 && nItemId == m_nItemId )
499 nIndex = nIdx;
502 return nIndex;
504 // -----------------------------------------------------------------------------
505 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
507 OExternalLockGuard aGuard( this );
509 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
510 throw IndexOutOfBoundsException();
512 return sal_False;
514 // -----------------------------------------------------------------------------
515 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
517 OExternalLockGuard aGuard( this );
519 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
520 throw IndexOutOfBoundsException();
522 sal_Bool bReturn = sal_False;
524 if ( m_pToolBox )
526 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pToolBox->GetClipboard();
527 if ( xClipboard.is() )
529 ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) );
531 ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
532 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
533 xClipboard->setContents( pDataObj, NULL );
535 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
536 if( xFlushableClipboard.is() )
537 xFlushableClipboard->flushClipboard();
539 Application::AcquireSolarMutex( nRef );
541 bReturn = sal_True;
545 return bReturn;
547 // -----------------------------------------------------------------------------
548 // XAccessibleComponent
549 // -----------------------------------------------------------------------------
550 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
552 return Reference< XAccessible >();
554 // -----------------------------------------------------------------------------
555 void SAL_CALL VCLXAccessibleToolBoxItem::grabFocus( ) throw (RuntimeException)
557 Reference< XAccessible > xParent(getAccessibleParent());
559 if( xParent.is() )
561 Reference< XAccessibleSelection > rxAccessibleSelection(xParent->getAccessibleContext(), UNO_QUERY);
563 if ( rxAccessibleSelection.is() )
565 rxAccessibleSelection -> selectAccessibleChild ( getAccessibleIndexInParent() );
569 // -----------------------------------------------------------------------------
570 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getForeground( ) throw (RuntimeException)
572 OExternalLockGuard aGuard( this );
574 sal_Int32 nColor = 0;
575 if ( m_pToolBox )
576 nColor = m_pToolBox->GetControlForeground().GetColor();
578 return nColor;
580 // -----------------------------------------------------------------------------
581 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getBackground( ) throw (RuntimeException)
583 OExternalLockGuard aGuard( this );
585 sal_Int32 nColor = 0;
586 if ( m_pToolBox )
587 nColor = m_pToolBox->GetControlBackground().GetColor();
589 return nColor;
591 // -----------------------------------------------------------------------------
592 // XAccessibleExtendedComponent
593 // -----------------------------------------------------------------------------
594 Reference< awt::XFont > SAL_CALL VCLXAccessibleToolBoxItem::getFont( ) throw (RuntimeException)
596 return uno::Reference< awt::XFont >();
598 // -----------------------------------------------------------------------------
599 awt::FontDescriptor SAL_CALL VCLXAccessibleToolBoxItem::getFontMetrics( const Reference< awt::XFont >& xFont ) throw (RuntimeException)
601 return xFont->getFontDescriptor();
603 // -----------------------------------------------------------------------------
604 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getTitledBorderText( ) throw (RuntimeException)
606 OExternalLockGuard aGuard( this );
608 ::rtl::OUString sRet;
609 if ( m_pToolBox )
610 sRet = m_pToolBox->GetItemText( m_nItemId );
612 return sRet;
614 // -----------------------------------------------------------------------------
615 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getToolTipText( ) throw (RuntimeException)
617 OExternalLockGuard aGuard( this );
619 ::rtl::OUString sRet;
620 if ( m_pToolBox )
622 if ( Help::IsExtHelpEnabled() )
623 sRet = m_pToolBox->GetHelpText( m_nItemId );
624 else
625 sRet = m_pToolBox->GetQuickHelpText( m_nItemId );
626 if ( !sRet.getLength() )
627 // no help text set, so use item text
628 sRet = m_pToolBox->GetItemText( m_nItemId );
630 return sRet;
632 // -----------------------------------------------------------------------------
633 // XAccessibleAction
634 // -----------------------------------------------------------------------------
635 sal_Int32 VCLXAccessibleToolBoxItem::getAccessibleActionCount( ) throw (RuntimeException)
637 // only one action -> "Click"
638 return 1;
640 // -----------------------------------------------------------------------------
641 sal_Bool VCLXAccessibleToolBoxItem::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
643 OExternalLockGuard aGuard( this );
645 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
646 throw IndexOutOfBoundsException();
648 if ( m_pToolBox )
649 m_pToolBox->TriggerItem( m_nItemId );
651 return sal_True;
653 // -----------------------------------------------------------------------------
654 ::rtl::OUString VCLXAccessibleToolBoxItem::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
656 OExternalLockGuard aGuard( this );
658 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
659 throw IndexOutOfBoundsException();
661 return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
663 // -----------------------------------------------------------------------------
664 Reference< XAccessibleKeyBinding > VCLXAccessibleToolBoxItem::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
666 OContextEntryGuard aGuard( this );
668 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
669 throw IndexOutOfBoundsException();
671 return Reference< XAccessibleKeyBinding >();
673 // -----------------------------------------------------------------------------
674 // XAccessibleValue
675 // -----------------------------------------------------------------------------
676 Any VCLXAccessibleToolBoxItem::getCurrentValue( ) throw (RuntimeException)
678 OExternalLockGuard aGuard( this );
680 Any aValue;
681 if ( m_pToolBox )
682 aValue <<= (sal_Int32)m_pToolBox->IsItemChecked( m_nItemId );
684 return aValue;
686 // -----------------------------------------------------------------------------
687 sal_Bool VCLXAccessibleToolBoxItem::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
689 OExternalLockGuard aGuard( this );
691 sal_Bool bReturn = sal_False;
693 if ( m_pToolBox )
695 sal_Int32 nValue = 0;
696 OSL_VERIFY( aNumber >>= nValue );
698 if ( nValue < 0 )
699 nValue = 0;
700 else if ( nValue > 1 )
701 nValue = 1;
703 m_pToolBox->CheckItem( m_nItemId, (BOOL) nValue );
704 bReturn = sal_True;
707 return bReturn;
709 // -----------------------------------------------------------------------------
710 Any VCLXAccessibleToolBoxItem::getMaximumValue( ) throw (RuntimeException)
712 return makeAny((sal_Int32)1);
714 // -----------------------------------------------------------------------------
715 Any VCLXAccessibleToolBoxItem::getMinimumValue( ) throw (RuntimeException)
717 return makeAny((sal_Int32)0);
719 // -----------------------------------------------------------------------------