Update ooo320-m1
[ooovba.git] / accessibility / source / extended / accessiblelistboxentry.cxx
blob151283c5c7dc88a80caba51f2d2aeceedc3c0aa6
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: accessiblelistboxentry.cxx,v $
10 * $Revision: 1.4 $
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/extended/accessiblelistboxentry.hxx"
34 #include <svtools/svtreebx.hxx>
35 #include <svtools/stringtransfer.hxx>
36 #include <com/sun/star/awt/Point.hpp>
37 #include <com/sun/star/awt/Rectangle.hpp>
38 #include <com/sun/star/awt/Size.hpp>
39 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
41 #include <com/sun/star/accessibility/AccessibleRole.hpp>
42 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43 #include <tools/debug.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/controllayout.hxx>
46 #include <toolkit/awt/vclxwindow.hxx>
47 #include <toolkit/helper/convert.hxx>
48 #include <unotools/accessiblestatesethelper.hxx>
49 #include <unotools/accessiblerelationsethelper.hxx>
50 #include <cppuhelper/typeprovider.hxx>
51 #include <comphelper/sequence.hxx>
52 #include <comphelper/accessibleeventnotifier.hxx>
53 #include <toolkit/helper/vclunohelper.hxx>
55 #define ACCESSIBLE_ACTION_COUNT 1
57 namespace
59 void checkActionIndex_Impl( sal_Int32 _nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
61 if ( _nIndex < 0 || _nIndex >= ACCESSIBLE_ACTION_COUNT )
62 // only three actions
63 throw ::com::sun::star::lang::IndexOutOfBoundsException();
67 //........................................................................
68 namespace accessibility
70 //........................................................................
71 // class ALBSolarGuard ---------------------------------------------------------
73 /** Aquire the solar mutex. */
74 class ALBSolarGuard : public ::vos::OGuard
76 public:
77 inline ALBSolarGuard() : ::vos::OGuard( Application::GetSolarMutex() ) {}
80 // class AccessibleListBoxEntry -----------------------------------------------------
82 using namespace ::com::sun::star::accessibility;
83 using namespace ::com::sun::star::uno;
84 using namespace ::com::sun::star::lang;
85 using namespace ::com::sun::star;
87 DBG_NAME(AccessibleListBoxEntry)
89 // -----------------------------------------------------------------------------
90 // Ctor() and Dtor()
91 // -----------------------------------------------------------------------------
92 AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox& _rListBox,
93 SvLBoxEntry* _pEntry,
94 const Reference< XAccessible >& _xParent ) :
96 AccessibleListBoxEntry_BASE ( m_aMutex ),
97 ListBoxAccessibleBase( _rListBox ),
99 m_nClientId ( 0 ),
100 m_aParent ( _xParent )
103 DBG_CTOR( AccessibleListBoxEntry, NULL );
105 _rListBox.FillEntryPath( _pEntry, m_aEntryPath );
107 // -----------------------------------------------------------------------------
108 AccessibleListBoxEntry::~AccessibleListBoxEntry()
110 DBG_DTOR( AccessibleListBoxEntry, NULL );
112 if ( IsAlive_Impl() )
114 // increment ref count to prevent double call of Dtor
115 osl_incrementInterlockedCount( &m_refCount );
116 dispose();
120 // -----------------------------------------------------------------------------
121 Rectangle AccessibleListBoxEntry::GetBoundingBox_Impl() const
123 Rectangle aRect;
124 SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
125 if ( pEntry )
127 aRect = getListBox()->GetBoundingRect( pEntry );
128 SvLBoxEntry* pParent = getListBox()->GetParent( pEntry );
129 if ( pParent )
131 // position relative to parent entry
132 Point aTopLeft = aRect.TopLeft();
133 aTopLeft -= getListBox()->GetBoundingRect( pParent ).TopLeft();
134 aRect = Rectangle( aTopLeft, aRect.GetSize() );
138 return aRect;
140 // -----------------------------------------------------------------------------
141 Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
143 Rectangle aRect;
144 SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
145 if ( pEntry )
147 aRect = getListBox()->GetBoundingRect( pEntry );
148 Point aTopLeft = aRect.TopLeft();
149 aTopLeft += getListBox()->GetWindowExtentsRelative( NULL ).TopLeft();
150 aRect = Rectangle( aTopLeft, aRect.GetSize() );
153 return aRect;
155 // -----------------------------------------------------------------------------
156 sal_Bool AccessibleListBoxEntry::IsAlive_Impl() const
158 return ( !rBHelper.bDisposed && !rBHelper.bInDispose && isAlive() );
160 // -----------------------------------------------------------------------------
161 sal_Bool AccessibleListBoxEntry::IsShowing_Impl() const
163 Reference< XAccessible > xParent = implGetParentAccessible( );
165 sal_Bool bShowing = sal_False;
166 Reference< XAccessibleContext > m_xParentContext =
167 xParent.is() ? xParent->getAccessibleContext() : Reference< XAccessibleContext >();
168 if( m_xParentContext.is() )
170 Reference< XAccessibleComponent > xParentComp( m_xParentContext, uno::UNO_QUERY );
171 if( xParentComp.is() )
172 bShowing = GetBoundingBox_Impl().IsOver( VCLRectangle( xParentComp->getBounds() ) );
175 return bShowing;
177 // -----------------------------------------------------------------------------
178 Rectangle AccessibleListBoxEntry::GetBoundingBox() throw ( lang::DisposedException )
180 ALBSolarGuard aSolarGuard;
181 ::osl::MutexGuard aGuard( m_aMutex );
183 EnsureIsAlive();
184 return GetBoundingBox_Impl();
186 // -----------------------------------------------------------------------------
187 Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen() throw ( lang::DisposedException )
189 ALBSolarGuard aSolarGuard;
190 ::osl::MutexGuard aGuard( m_aMutex );
192 EnsureIsAlive();
193 return GetBoundingBoxOnScreen_Impl();
195 // -----------------------------------------------------------------------------
196 void AccessibleListBoxEntry::EnsureIsAlive() const throw ( lang::DisposedException )
198 if ( !IsAlive_Impl() )
199 throw lang::DisposedException();
201 // -----------------------------------------------------------------------------
202 ::rtl::OUString AccessibleListBoxEntry::implGetText()
204 ::rtl::OUString sRet;
205 SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
206 if ( pEntry )
207 sRet = getListBox()->SearchEntryText( pEntry );
208 return sRet;
210 // -----------------------------------------------------------------------------
211 Locale AccessibleListBoxEntry::implGetLocale()
213 Locale aLocale;
214 aLocale = Application::GetSettings().GetUILocale();
216 return aLocale;
218 void AccessibleListBoxEntry::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
220 nStartIndex = 0;
221 nEndIndex = 0;
223 // -----------------------------------------------------------------------------
224 // XTypeProvider
225 // -----------------------------------------------------------------------------
226 // -----------------------------------------------------------------------------
227 Sequence< sal_Int8 > AccessibleListBoxEntry::getImplementationId() throw (RuntimeException)
229 static ::cppu::OImplementationId* pId = NULL;
231 if ( !pId )
233 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
235 if ( !pId )
237 static ::cppu::OImplementationId aId;
238 pId = &aId;
241 return pId->getImplementationId();
244 // -----------------------------------------------------------------------------
245 // XComponent/ListBoxAccessibleBase
246 // -----------------------------------------------------------------------------
247 void SAL_CALL AccessibleListBoxEntry::dispose() throw ( uno::RuntimeException )
249 AccessibleListBoxEntry_BASE::dispose();
252 // -----------------------------------------------------------------------------
253 // XComponent
254 // -----------------------------------------------------------------------------
255 void SAL_CALL AccessibleListBoxEntry::disposing()
257 ALBSolarGuard();
258 ::osl::MutexGuard aGuard( m_aMutex );
260 Reference< XAccessible > xKeepAlive( this );
262 // Send a disposing to all listeners.
263 if ( m_nClientId )
265 ::comphelper::AccessibleEventNotifier::TClientId nId = m_nClientId;
266 m_nClientId = 0;
267 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
270 // clean up
273 ListBoxAccessibleBase::disposing();
275 m_aParent = WeakReference< XAccessible >();
277 // -----------------------------------------------------------------------------
278 // XServiceInfo
279 // -----------------------------------------------------------------------------
280 ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getImplementationName() throw(RuntimeException)
282 return getImplementationName_Static();
284 // -----------------------------------------------------------------------------
285 Sequence< ::rtl::OUString > SAL_CALL AccessibleListBoxEntry::getSupportedServiceNames() throw(RuntimeException)
287 return getSupportedServiceNames_Static();
289 // -----------------------------------------------------------------------------
290 sal_Bool SAL_CALL AccessibleListBoxEntry::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
292 Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
293 const ::rtl::OUString* pSupported = aSupported.getConstArray();
294 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
295 for ( ; pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported )
298 return pSupported != pEnd;
300 // -----------------------------------------------------------------------------
301 // XServiceInfo - static methods
302 // -----------------------------------------------------------------------------
303 Sequence< ::rtl::OUString > AccessibleListBoxEntry::getSupportedServiceNames_Static(void) throw( RuntimeException )
305 Sequence< ::rtl::OUString > aSupported(3);
306 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleContext") );
307 aSupported[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleComponent") );
308 aSupported[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleTreeListBoxEntry") );
309 return aSupported;
311 // -----------------------------------------------------------------------------
312 ::rtl::OUString AccessibleListBoxEntry::getImplementationName_Static(void) throw( RuntimeException )
314 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.svtools.AccessibleTreeListBoxEntry") );
316 // -----------------------------------------------------------------------------
317 // XAccessible
318 // -----------------------------------------------------------------------------
319 Reference< XAccessibleContext > SAL_CALL AccessibleListBoxEntry::getAccessibleContext( ) throw (RuntimeException)
321 EnsureIsAlive();
322 return this;
324 // -----------------------------------------------------------------------------
325 // XAccessibleContext
326 // -----------------------------------------------------------------------------
327 sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleChildCount( ) throw (RuntimeException)
329 ALBSolarGuard aSolarGuard;
330 ::osl::MutexGuard aGuard( m_aMutex );
332 EnsureIsAlive();
333 SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
334 sal_Int32 nCount = 0;
335 if ( pEntry )
336 nCount = getListBox()->GetLevelChildCount( pEntry );
338 return nCount;
340 // -----------------------------------------------------------------------------
341 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
343 ALBSolarGuard aSolarGuard;
344 ::osl::MutexGuard aGuard( m_aMutex );
345 EnsureIsAlive();
347 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
348 SvLBoxEntry* pEntry = pParent ? getListBox()->GetEntry( pParent, i ) : NULL;
349 if ( !pEntry )
350 throw IndexOutOfBoundsException();
352 return new AccessibleListBoxEntry( *getListBox(), pEntry, this );
355 // -----------------------------------------------------------------------------
356 Reference< XAccessible > AccessibleListBoxEntry::implGetParentAccessible( ) const
358 Reference< XAccessible > xParent = (Reference< XAccessible >)m_aParent;
359 if ( !xParent.is() )
361 DBG_ASSERT( m_aEntryPath.size(), "AccessibleListBoxEntry::getAccessibleParent: invalid path!" );
362 if ( 1 == m_aEntryPath.size() )
363 { // we're a top level entry
364 // -> our parent is the tree listbox itself
365 if ( getListBox() )
366 xParent = getListBox()->GetAccessible( );
368 else
369 { // we have a entry as parent -> get it's accessible
371 // shorten our access path by one
372 ::std::deque< sal_Int32 > aParentPath( m_aEntryPath );
373 aParentPath.pop_back();
375 // get the entry for this shortened access path
376 SvLBoxEntry* pParentEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
377 DBG_ASSERT( pParentEntry, "AccessibleListBoxEntry::implGetParentAccessible: could not obtain a parent entry!" );
379 if ( pParentEntry )
380 xParent = new AccessibleListBoxEntry( *getListBox(), pParentEntry, NULL );
381 // note that we pass NULL here as parent-accessible:
382 // this is allowed, as the AccessibleListBoxEntry class will create it's parent
383 // when needed
387 return xParent;
390 // -----------------------------------------------------------------------------
391 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleParent( ) throw (RuntimeException)
393 ALBSolarGuard aSolarGuard;
394 ::osl::MutexGuard aGuard( m_aMutex );
395 EnsureIsAlive();
397 return implGetParentAccessible( );
399 // -----------------------------------------------------------------------------
400 sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleIndexInParent( ) throw (RuntimeException)
402 ::osl::MutexGuard aGuard( m_aMutex );
404 DBG_ASSERT( !m_aEntryPath.empty(), "empty path" );
405 return m_aEntryPath.empty() ? -1 : m_aEntryPath.back();
407 // -----------------------------------------------------------------------------
408 sal_Int16 SAL_CALL AccessibleListBoxEntry::getAccessibleRole( ) throw (RuntimeException)
410 return AccessibleRole::LABEL;
412 // -----------------------------------------------------------------------------
413 ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getAccessibleDescription( ) throw (RuntimeException)
415 // no description for every item
416 return ::rtl::OUString();
418 // -----------------------------------------------------------------------------
419 ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getAccessibleName( ) throw (RuntimeException)
421 ::osl::MutexGuard aGuard( m_aMutex );
423 EnsureIsAlive();
424 return implGetText();
426 // -----------------------------------------------------------------------------
427 Reference< XAccessibleRelationSet > SAL_CALL AccessibleListBoxEntry::getAccessibleRelationSet( ) throw (RuntimeException)
429 Reference< XAccessibleRelationSet > xRelSet;
430 Reference< XAccessible > xParent;
431 if ( m_aEntryPath.size() > 1 ) // not a root entry
432 xParent = implGetParentAccessible();
433 if ( xParent.is() )
435 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
436 Sequence< Reference< XInterface > > aSequence(1);
437 aSequence[0] = xParent;
438 pRelationSetHelper->AddRelation(
439 AccessibleRelation( AccessibleRelationType::NODE_CHILD_OF, aSequence ) );
440 xRelSet = pRelationSetHelper;
442 return xRelSet;
444 // -----------------------------------------------------------------------------
445 Reference< XAccessibleStateSet > SAL_CALL AccessibleListBoxEntry::getAccessibleStateSet( ) throw (RuntimeException)
447 ::osl::MutexGuard aGuard( m_aMutex );
449 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
450 Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
452 if ( IsAlive_Impl() )
454 pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
455 pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
456 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
457 pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
458 if ( getListBox()->IsInplaceEditingEnabled() )
459 pStateSetHelper->AddState( AccessibleStateType::EDITABLE );
460 if ( IsShowing_Impl() )
461 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
462 getListBox()->FillAccessibleEntryStateSet(
463 getListBox()->GetEntryFromPath( m_aEntryPath ), *pStateSetHelper );
465 else
466 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
468 return xStateSet;
470 // -----------------------------------------------------------------------------
471 Locale SAL_CALL AccessibleListBoxEntry::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
473 ALBSolarGuard aSolarGuard;
474 ::osl::MutexGuard aGuard( m_aMutex );
476 return implGetLocale();
478 // -----------------------------------------------------------------------------
479 // XAccessibleComponent
480 // -----------------------------------------------------------------------------
481 sal_Bool SAL_CALL AccessibleListBoxEntry::containsPoint( const awt::Point& rPoint ) throw (RuntimeException)
483 return Rectangle( Point(), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
485 // -----------------------------------------------------------------------------
486 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (RuntimeException)
488 ALBSolarGuard aSolarGuard;
489 ::osl::MutexGuard aGuard( m_aMutex );
491 EnsureIsAlive();
492 SvLBoxEntry* pEntry = getListBox()->GetEntry( VCLPoint( _aPoint ) );
493 if ( !pEntry )
494 throw RuntimeException();
496 Reference< XAccessible > xAcc;
497 AccessibleListBoxEntry* pAccEntry = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
498 Rectangle aRect = pAccEntry->GetBoundingBox_Impl();
499 if ( aRect.IsInside( VCLPoint( _aPoint ) ) )
500 xAcc = pAccEntry;
501 return xAcc;
503 // -----------------------------------------------------------------------------
504 awt::Rectangle SAL_CALL AccessibleListBoxEntry::getBounds( ) throw (RuntimeException)
506 return AWTRectangle( GetBoundingBox() );
508 // -----------------------------------------------------------------------------
509 awt::Point SAL_CALL AccessibleListBoxEntry::getLocation( ) throw (RuntimeException)
511 return AWTPoint( GetBoundingBox().TopLeft() );
513 // -----------------------------------------------------------------------------
514 awt::Point SAL_CALL AccessibleListBoxEntry::getLocationOnScreen( ) throw (RuntimeException)
516 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
518 // -----------------------------------------------------------------------------
519 awt::Size SAL_CALL AccessibleListBoxEntry::getSize( ) throw (RuntimeException)
521 return AWTSize( GetBoundingBox().GetSize() );
523 // -----------------------------------------------------------------------------
524 void SAL_CALL AccessibleListBoxEntry::grabFocus( ) throw (RuntimeException)
526 // do nothing, because no focus for each item
528 // -----------------------------------------------------------------------------
529 sal_Int32 AccessibleListBoxEntry::getForeground( ) throw (RuntimeException)
531 ALBSolarGuard aSolarGuard;
532 ::osl::MutexGuard aGuard( m_aMutex );
534 sal_Int32 nColor = 0;
535 Reference< XAccessible > xParent = getAccessibleParent();
536 if ( xParent.is() )
538 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
539 if ( xParentComp.is() )
540 nColor = xParentComp->getForeground();
543 return nColor;
545 // -----------------------------------------------------------------------------
546 sal_Int32 AccessibleListBoxEntry::getBackground( ) throw (RuntimeException)
548 ALBSolarGuard aSolarGuard;
549 ::osl::MutexGuard aGuard( m_aMutex );
551 sal_Int32 nColor = 0;
552 Reference< XAccessible > xParent = getAccessibleParent();
553 if ( xParent.is() )
555 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
556 if ( xParentComp.is() )
557 nColor = xParentComp->getBackground();
560 return nColor;
562 // -----------------------------------------------------------------------------
563 // XAccessibleText
564 // -----------------------------------------------------------------------------
565 // -----------------------------------------------------------------------------
566 awt::Rectangle SAL_CALL AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
568 ALBSolarGuard aSolarGuard;
569 ::osl::MutexGuard aGuard( m_aMutex );
571 EnsureIsAlive();
573 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
574 throw IndexOutOfBoundsException();
576 awt::Rectangle aBounds( 0, 0, 0, 0 );
577 SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
578 if ( pEntry )
580 ::vcl::ControlLayoutData aLayoutData;
581 Rectangle aItemRect = GetBoundingBox();
582 getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
583 Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
584 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
585 aBounds = AWTRectangle( aCharRect );
588 return aBounds;
590 // -----------------------------------------------------------------------------
591 sal_Int32 SAL_CALL AccessibleListBoxEntry::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
593 ALBSolarGuard aSolarGuard;
594 ::osl::MutexGuard aGuard( m_aMutex );
595 EnsureIsAlive();
597 sal_Int32 nIndex = -1;
598 SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
599 if ( pEntry )
601 ::vcl::ControlLayoutData aLayoutData;
602 Rectangle aItemRect = GetBoundingBox();
603 getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
604 Point aPnt( VCLPoint( aPoint ) );
605 aPnt += aItemRect.TopLeft();
606 nIndex = aLayoutData.GetIndexForPoint( aPnt );
609 return nIndex;
611 // -----------------------------------------------------------------------------
612 sal_Bool SAL_CALL AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
614 ALBSolarGuard aSolarGuard;
615 ::osl::MutexGuard aGuard( m_aMutex );
616 EnsureIsAlive();
618 String sText = getText();
619 if ( ( 0 > nStartIndex ) || ( sText.Len() <= nStartIndex )
620 || ( 0 > nEndIndex ) || ( sText.Len() <= nEndIndex ) )
621 throw IndexOutOfBoundsException();
623 sal_Int32 nLen = nEndIndex - nStartIndex + 1;
624 ::svt::OStringTransfer::CopyString( sText.Copy( (USHORT)nStartIndex, (USHORT)nLen ), getListBox() );
626 return sal_True;
628 // -----------------------------------------------------------------------------
629 // XAccessibleEventBroadcaster
630 // -----------------------------------------------------------------------------
631 void SAL_CALL AccessibleListBoxEntry::addEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
633 if (xListener.is())
635 ::osl::MutexGuard aGuard( m_aMutex );
636 if (!m_nClientId)
637 m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
638 comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
641 // -----------------------------------------------------------------------------
642 void SAL_CALL AccessibleListBoxEntry::removeEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
644 if (xListener.is())
646 ::osl::MutexGuard aGuard( m_aMutex );
648 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
649 if ( !nListenerCount )
651 // no listeners anymore
652 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
653 // and at least to us not firing any events anymore, in case somebody calls
654 // NotifyAccessibleEvent, again
655 sal_Int32 nId = m_nClientId;
656 m_nClientId = 0;
657 comphelper::AccessibleEventNotifier::revokeClient( nId );
662 // -----------------------------------------------------------------------------
663 // XAccessibleAction
664 // -----------------------------------------------------------------------------
665 sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleActionCount( ) throw (RuntimeException)
667 ::osl::MutexGuard aGuard( m_aMutex );
669 // three actions supported
670 return ACCESSIBLE_ACTION_COUNT;
672 // -----------------------------------------------------------------------------
673 sal_Bool SAL_CALL AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
675 ALBSolarGuard aSolarGuard;
676 ::osl::MutexGuard aGuard( m_aMutex );
678 sal_Bool bRet = sal_False;
679 checkActionIndex_Impl( nIndex );
680 EnsureIsAlive();
682 SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
683 if ( pEntry )
685 if ( getListBox()->IsExpanded( pEntry ) )
686 getListBox()->Collapse( pEntry );
687 else
688 getListBox()->Expand( pEntry );
689 bRet = sal_True;
692 return bRet;
694 // -----------------------------------------------------------------------------
695 ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
697 ALBSolarGuard aSolarGuard;
698 ::osl::MutexGuard aGuard( m_aMutex );
700 checkActionIndex_Impl( nIndex );
701 EnsureIsAlive();
703 static const ::rtl::OUString sActionDesc( RTL_CONSTASCII_USTRINGPARAM( "toggleExpand" ) );
704 return sActionDesc;
706 // -----------------------------------------------------------------------------
707 Reference< XAccessibleKeyBinding > AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
709 ::osl::MutexGuard aGuard( m_aMutex );
711 Reference< XAccessibleKeyBinding > xRet;
712 checkActionIndex_Impl( nIndex );
713 // ... which key?
714 return xRet;
716 // -----------------------------------------------------------------------------
717 // XAccessibleSelection
718 // -----------------------------------------------------------------------------
719 void SAL_CALL AccessibleListBoxEntry::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
721 ALBSolarGuard aSolarGuard;
722 ::osl::MutexGuard aGuard( m_aMutex );
724 EnsureIsAlive();
726 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
727 SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, nChildIndex );
728 if ( !pEntry )
729 throw IndexOutOfBoundsException();
731 getListBox()->Select( pEntry, TRUE );
733 // -----------------------------------------------------------------------------
734 sal_Bool SAL_CALL AccessibleListBoxEntry::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
736 ALBSolarGuard aSolarGuard;
737 ::osl::MutexGuard aGuard( m_aMutex );
739 EnsureIsAlive();
741 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
742 SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, nChildIndex );
743 if ( !pEntry )
744 throw IndexOutOfBoundsException();
746 return getListBox()->IsSelected( pEntry );
748 // -----------------------------------------------------------------------------
749 void SAL_CALL AccessibleListBoxEntry::clearAccessibleSelection( ) throw (RuntimeException)
751 ALBSolarGuard aSolarGuard;
752 ::osl::MutexGuard aGuard( m_aMutex );
754 EnsureIsAlive();
756 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
757 if ( !pParent )
758 throw RuntimeException();
759 sal_Int32 i, nCount = 0;
760 nCount = getListBox()->GetLevelChildCount( pParent );
761 for ( i = 0; i < nCount; ++i )
763 SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
764 if ( getListBox()->IsSelected( pEntry ) )
765 getListBox()->Select( pEntry, FALSE );
768 // -----------------------------------------------------------------------------
769 void SAL_CALL AccessibleListBoxEntry::selectAllAccessibleChildren( ) throw (RuntimeException)
771 ALBSolarGuard aSolarGuard;
772 ::osl::MutexGuard aGuard( m_aMutex );
774 EnsureIsAlive();
776 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
777 if ( !pParent )
778 throw RuntimeException();
779 sal_Int32 i, nCount = 0;
780 nCount = getListBox()->GetLevelChildCount( pParent );
781 for ( i = 0; i < nCount; ++i )
783 SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
784 if ( !getListBox()->IsSelected( pEntry ) )
785 getListBox()->Select( pEntry, TRUE );
788 // -----------------------------------------------------------------------------
789 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChildCount( ) throw (RuntimeException)
791 ALBSolarGuard aSolarGuard;
792 ::osl::MutexGuard aGuard( m_aMutex );
794 EnsureIsAlive();
796 sal_Int32 i, nSelCount = 0, nCount = 0;
798 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
799 if ( !pParent )
800 throw RuntimeException();
801 nCount = getListBox()->GetLevelChildCount( pParent );
802 for ( i = 0; i < nCount; ++i )
804 SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
805 if ( getListBox()->IsSelected( pEntry ) )
806 ++nSelCount;
809 return nSelCount;
811 // -----------------------------------------------------------------------------
812 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
814 ALBSolarGuard aSolarGuard;
815 ::osl::MutexGuard aGuard( m_aMutex );
817 EnsureIsAlive();
819 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
820 throw IndexOutOfBoundsException();
822 Reference< XAccessible > xChild;
823 sal_Int32 i, nSelCount = 0, nCount = 0;
825 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
826 if ( !pParent )
827 throw RuntimeException();
828 nCount = getListBox()->GetLevelChildCount( pParent );
829 for ( i = 0; i < nCount; ++i )
831 SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
832 if ( getListBox()->IsSelected( pEntry ) )
833 ++nSelCount;
835 if ( nSelCount == ( nSelectedChildIndex + 1 ) )
837 xChild = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
838 break;
842 return xChild;
844 // -----------------------------------------------------------------------------
845 void SAL_CALL AccessibleListBoxEntry::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
847 ALBSolarGuard aSolarGuard;
848 ::osl::MutexGuard aGuard( m_aMutex );
850 EnsureIsAlive();
852 SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
853 SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, nSelectedChildIndex );
854 if ( !pEntry )
855 throw IndexOutOfBoundsException();
857 getListBox()->Select( pEntry, FALSE );
859 sal_Int32 SAL_CALL AccessibleListBoxEntry::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException)
861 return -1;
863 sal_Bool SAL_CALL AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
865 ALBSolarGuard aSolarGuard;
866 ::osl::MutexGuard aGuard( m_aMutex );
867 EnsureIsAlive();
869 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
870 throw IndexOutOfBoundsException();
872 return sal_False;
874 sal_Unicode SAL_CALL AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
876 ALBSolarGuard aSolarGuard;
877 ::osl::MutexGuard aGuard( m_aMutex );
878 EnsureIsAlive();
879 return OCommonAccessibleText::getCharacter( nIndex );
881 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleListBoxEntry::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
883 ALBSolarGuard aSolarGuard;
884 ::osl::MutexGuard aGuard( m_aMutex );
885 EnsureIsAlive();
887 ::rtl::OUString sText( implGetText() );
889 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
890 throw IndexOutOfBoundsException();
892 return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
894 sal_Int32 SAL_CALL AccessibleListBoxEntry::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException)
896 ALBSolarGuard aSolarGuard;
897 ::osl::MutexGuard aGuard( m_aMutex );
898 EnsureIsAlive();
899 return OCommonAccessibleText::getCharacterCount( );
902 ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException)
904 ALBSolarGuard aSolarGuard;
905 ::osl::MutexGuard aGuard( m_aMutex );
906 EnsureIsAlive();
907 return OCommonAccessibleText::getSelectedText( );
909 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException)
911 ALBSolarGuard aSolarGuard;
912 ::osl::MutexGuard aGuard( m_aMutex );
913 EnsureIsAlive();
914 return OCommonAccessibleText::getSelectionStart( );
916 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException)
918 ALBSolarGuard aSolarGuard;
919 ::osl::MutexGuard aGuard( m_aMutex );
920 EnsureIsAlive();
921 return OCommonAccessibleText::getSelectionEnd( );
923 sal_Bool SAL_CALL AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
925 ALBSolarGuard aSolarGuard;
926 ::osl::MutexGuard aGuard( m_aMutex );
927 EnsureIsAlive();
929 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
930 throw IndexOutOfBoundsException();
932 return sal_False;
934 ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getText( ) throw (::com::sun::star::uno::RuntimeException)
936 ALBSolarGuard aSolarGuard;
937 ::osl::MutexGuard aGuard( m_aMutex );
938 EnsureIsAlive();
939 return OCommonAccessibleText::getText( );
941 ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
943 ALBSolarGuard aSolarGuard;
944 ::osl::MutexGuard aGuard( m_aMutex );
945 EnsureIsAlive();
946 return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
948 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
950 ALBSolarGuard aSolarGuard;
951 ::osl::MutexGuard aGuard( m_aMutex );
952 EnsureIsAlive();
953 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
955 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
957 ALBSolarGuard aSolarGuard;
958 ::osl::MutexGuard aGuard( m_aMutex );
959 EnsureIsAlive();
960 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
962 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
964 ALBSolarGuard aSolarGuard;
965 ::osl::MutexGuard aGuard( m_aMutex );
966 EnsureIsAlive();
968 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
970 //........................................................................
971 }// namespace accessibility
972 //........................................................................