lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / accessibility / source / extended / accessiblelistboxentry.cxx
blob4a74477badb6fc5766aca790014c6c95f6d47c05
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 <extended/accessiblelistboxentry.hxx>
21 #include <vcl/treelistbox.hxx>
22 #include <svtools/stringtransfer.hxx>
23 #include <vcl/svlbitm.hxx>
24 #include <com/sun/star/awt/Point.hpp>
25 #include <com/sun/star/awt/Rectangle.hpp>
26 #include <com/sun/star/awt/Size.hpp>
27 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
28 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
32 #include <vcl/svapp.hxx>
33 #include <vcl/controllayout.hxx>
34 #include <vcl/settings.hxx>
35 #include <toolkit/awt/vclxwindow.hxx>
36 #include <toolkit/helper/convert.hxx>
37 #include <unotools/accessiblestatesethelper.hxx>
38 #include <unotools/accessiblerelationsethelper.hxx>
39 #include <cppuhelper/supportsservice.hxx>
40 #include <cppuhelper/typeprovider.hxx>
41 #include <comphelper/accessibleeventnotifier.hxx>
42 #include <helper/accresmgr.hxx>
43 #include <strings.hrc>
44 #include <com/sun/star/accessibility/XAccessibleValue.hpp>
45 #define ACCESSIBLE_ACTION_COUNT 1
47 namespace
49 /// @throws css::lang::IndexOutOfBoundsException
50 void checkActionIndex_Impl( sal_Int32 _nIndex )
52 if ( _nIndex < 0 || _nIndex >= ACCESSIBLE_ACTION_COUNT )
53 // only three actions
54 throw css::lang::IndexOutOfBoundsException();
59 namespace accessibility
61 // class AccessibleListBoxEntry -----------------------------------------------------
63 using namespace ::com::sun::star::accessibility;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star;
67 using namespace ::comphelper;
70 // Ctor() and Dtor()
72 AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox& _rListBox,
73 SvTreeListEntry* _pEntry,
74 const Reference< XAccessible >& _xParent ) :
76 AccessibleListBoxEntry_BASE ( m_aMutex ),
77 ListBoxAccessibleBase( _rListBox ),
79 m_pSvLBoxEntry ( _pEntry ),
80 m_nClientId ( 0 ),
81 m_aParent ( _xParent )
84 _rListBox.FillEntryPath( _pEntry, m_aEntryPath );
87 AccessibleListBoxEntry::~AccessibleListBoxEntry()
89 if ( IsAlive_Impl() )
91 // increment ref count to prevent double call of Dtor
92 osl_atomic_increment( &m_refCount );
93 dispose();
97 void AccessibleListBoxEntry::NotifyAccessibleEvent( sal_Int16 _nEventId,
98 const css::uno::Any& _aOldValue,
99 const css::uno::Any& _aNewValue )
101 Reference< uno::XInterface > xSource( *this );
102 AccessibleEventObject aEventObj( xSource, _nEventId, _aNewValue, _aOldValue );
104 if (m_nClientId)
105 comphelper::AccessibleEventNotifier::addEvent( m_nClientId, aEventObj );
109 tools::Rectangle AccessibleListBoxEntry::GetBoundingBox_Impl() const
111 tools::Rectangle aRect;
112 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
113 if ( pEntry )
115 aRect = getListBox()->GetBoundingRect( pEntry );
116 SvTreeListEntry* pParent = getListBox()->GetParent( pEntry );
117 if ( pParent )
119 // position relative to parent entry
120 Point aTopLeft = aRect.TopLeft();
121 aTopLeft -= getListBox()->GetBoundingRect( pParent ).TopLeft();
122 aRect = tools::Rectangle( aTopLeft, aRect.GetSize() );
126 return aRect;
129 tools::Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
131 tools::Rectangle aRect;
132 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
133 if ( pEntry )
135 aRect = getListBox()->GetBoundingRect( pEntry );
136 Point aTopLeft = aRect.TopLeft();
137 aTopLeft += getListBox()->GetWindowExtentsRelative( nullptr ).TopLeft();
138 aRect = tools::Rectangle( aTopLeft, aRect.GetSize() );
141 return aRect;
144 bool AccessibleListBoxEntry::IsAlive_Impl() const
146 return ( !rBHelper.bDisposed && !rBHelper.bInDispose && isAlive() );
149 bool AccessibleListBoxEntry::IsShowing_Impl() const
151 Reference< XAccessible > xParent = implGetParentAccessible( );
153 bool bShowing = false;
154 Reference< XAccessibleContext > xParentContext =
155 xParent.is() ? xParent->getAccessibleContext() : Reference< XAccessibleContext >();
156 if( xParentContext.is() )
158 Reference< XAccessibleComponent > xParentComp( xParentContext, uno::UNO_QUERY );
159 if( xParentComp.is() )
160 bShowing = GetBoundingBox_Impl().IsOver( VCLRectangle( xParentComp->getBounds() ) );
163 return bShowing;
166 tools::Rectangle AccessibleListBoxEntry::GetBoundingBox()
168 SolarMutexGuard aSolarGuard;
169 ::osl::MutexGuard aGuard( m_aMutex );
171 EnsureIsAlive();
172 return GetBoundingBox_Impl();
175 tools::Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen()
177 SolarMutexGuard aSolarGuard;
178 ::osl::MutexGuard aGuard( m_aMutex );
180 EnsureIsAlive();
181 return GetBoundingBoxOnScreen_Impl();
184 void AccessibleListBoxEntry::EnsureIsAlive() const
186 if ( !IsAlive_Impl() )
187 throw lang::DisposedException();
190 OUString AccessibleListBoxEntry::implGetText()
192 OUString sRet;
193 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
194 if ( pEntry )
195 sRet = SvTreeListBox::SearchEntryTextWithHeadTitle( pEntry );
196 return sRet;
199 Locale AccessibleListBoxEntry::implGetLocale()
201 Locale aLocale;
202 aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
204 return aLocale;
206 void AccessibleListBoxEntry::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
208 nStartIndex = 0;
209 nEndIndex = 0;
212 // XTypeProvider
215 Sequence< sal_Int8 > AccessibleListBoxEntry::getImplementationId()
217 return css::uno::Sequence<sal_Int8>();
221 // XComponent/ListBoxAccessibleBase
223 void SAL_CALL AccessibleListBoxEntry::dispose()
225 AccessibleListBoxEntry_BASE::dispose();
229 // XComponent
231 void SAL_CALL AccessibleListBoxEntry::disposing()
233 SolarMutexGuard aSolarGuard;
234 ::osl::MutexGuard aGuard( m_aMutex );
236 Reference< XAccessible > xKeepAlive( this );
238 // Send a disposing to all listeners.
239 if ( m_nClientId )
241 ::comphelper::AccessibleEventNotifier::TClientId nId = m_nClientId;
242 m_nClientId = 0;
243 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
246 // clean up
249 ListBoxAccessibleBase::disposing();
251 m_aParent.clear();
254 // XServiceInfo
256 OUString SAL_CALL AccessibleListBoxEntry::getImplementationName()
258 return OUString( "com.sun.star.comp.svtools.AccessibleTreeListBoxEntry" );
261 Sequence< OUString > SAL_CALL AccessibleListBoxEntry::getSupportedServiceNames()
263 return {"com.sun.star.accessibility.AccessibleContext",
264 "com.sun.star.accessibility.AccessibleComponent",
265 "com.sun.star.awt.AccessibleTreeListBoxEntry"};
268 sal_Bool SAL_CALL AccessibleListBoxEntry::supportsService( const OUString& _rServiceName )
270 return cppu::supportsService(this, _rServiceName);
273 // XAccessible
275 Reference< XAccessibleContext > SAL_CALL AccessibleListBoxEntry::getAccessibleContext( )
277 EnsureIsAlive();
278 return this;
281 // XAccessibleContext
283 sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleChildCount( )
285 SolarMutexGuard aSolarGuard;
286 ::osl::MutexGuard aGuard( m_aMutex );
288 EnsureIsAlive();
289 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
290 sal_Int32 nCount = 0;
291 if ( pEntry )
292 nCount = getListBox()->GetLevelChildCount( pEntry );
294 return nCount;
297 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleChild( sal_Int32 i )
299 SolarMutexGuard aSolarGuard;
300 ::osl::MutexGuard aGuard( m_aMutex );
301 EnsureIsAlive();
303 SvTreeListEntry* pEntry = GetRealChild(i);
304 if ( !pEntry )
305 throw IndexOutOfBoundsException();
307 return new AccessibleListBoxEntry( *getListBox(), pEntry, this );
311 Reference< XAccessible > AccessibleListBoxEntry::implGetParentAccessible( ) const
313 Reference< XAccessible > xParent(m_aParent);
314 if ( !xParent.is() )
316 OSL_ENSURE( m_aEntryPath.size(), "AccessibleListBoxEntry::getAccessibleParent: invalid path!" );
317 if ( m_aEntryPath.size() == 1 )
318 { // we're a top level entry
319 // -> our parent is the tree listbox itself
320 if ( getListBox() )
321 xParent = getListBox()->GetAccessible( );
323 else
324 { // we have a entry as parent -> get its accessible
326 // shorten our access path by one
327 std::deque< sal_Int32 > aParentPath( m_aEntryPath );
328 aParentPath.pop_back();
330 // get the entry for this shortened access path
331 SvTreeListEntry* pParentEntry = getListBox()->GetEntryFromPath( aParentPath );
332 OSL_ENSURE( pParentEntry, "AccessibleListBoxEntry::implGetParentAccessible: could not obtain a parent entry!" );
334 if ( pParentEntry )
335 pParentEntry = getListBox()->GetParent(pParentEntry);
336 if ( pParentEntry )
337 xParent = new AccessibleListBoxEntry( *getListBox(), pParentEntry, nullptr );
338 // note that we pass NULL here as parent-accessible:
339 // this is allowed, as the AccessibleListBoxEntry class will create its parent
340 // when needed
344 return xParent;
348 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleParent( )
350 SolarMutexGuard aSolarGuard;
351 ::osl::MutexGuard aGuard( m_aMutex );
352 EnsureIsAlive();
354 return implGetParentAccessible( );
357 sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleIndexInParent( )
359 ::osl::MutexGuard aGuard( m_aMutex );
361 OSL_ENSURE( !m_aEntryPath.empty(), "empty path" );
362 return m_aEntryPath.empty() ? -1 : m_aEntryPath.back();
365 sal_Int32 AccessibleListBoxEntry::GetRoleType()
367 sal_Int32 nCase = 0;
368 SvTreeListEntry* pEntry = getListBox()->GetEntry(0);
369 if ( pEntry )
371 if( pEntry->HasChildrenOnDemand() || getListBox()->GetChildCount(pEntry) > 0 )
373 nCase = 1;
374 return nCase;
378 bool bHasButtons = (getListBox()->GetStyle() & WB_HASBUTTONS)!=0;
379 if( !(getListBox()->GetTreeFlags() & SvTreeFlags::CHKBTN) )
381 if( bHasButtons )
382 nCase = 1;
384 else
386 if( bHasButtons )
387 nCase = 2;
388 else
389 nCase = 3;
391 return nCase;
394 sal_Int16 SAL_CALL AccessibleListBoxEntry::getAccessibleRole( )
396 SolarMutexGuard aSolarGuard;
397 ::osl::MutexGuard aGuard( m_aMutex );
399 SvTreeListBox* pBox = getListBox();
400 if(pBox)
402 SvTreeAccRoleType nType = pBox->GetAllEntriesAccessibleRoleType();
403 if( nType == SvTreeAccRoleType::TREE)
404 return AccessibleRole::TREE_ITEM;
406 SvTreeFlags treeFlag = pBox->GetTreeFlags();
407 if(treeFlag & SvTreeFlags::CHKBTN )
409 SvTreeListEntry* pEntry = pBox->GetEntryFromPath( m_aEntryPath );
410 SvButtonState eState = pBox->GetCheckButtonState( pEntry );
411 switch( eState )
413 case SvButtonState::Checked:
414 case SvButtonState::Unchecked:
415 return AccessibleRole::CHECK_BOX;
416 case SvButtonState::Tristate:
417 default:
418 return AccessibleRole::LABEL;
421 if (GetRoleType() == 0)
422 return AccessibleRole::LIST_ITEM;
423 else
424 //o is: return AccessibleRole::LABEL;
425 return AccessibleRole::TREE_ITEM;
427 return AccessibleRole::UNKNOWN;
430 OUString SAL_CALL AccessibleListBoxEntry::getAccessibleDescription( )
432 SolarMutexGuard aSolarGuard;
433 ::osl::MutexGuard aGuard( m_aMutex );
435 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
436 if( getAccessibleRole() == AccessibleRole::TREE_ITEM )
438 return getListBox()->GetEntryLongDescription( pEntry );
440 //want to cout the real column number in the list box.
441 sal_uInt16 iRealItemCount = 0;
442 sal_uInt16 iCount = 0;
443 sal_uInt16 iTotleItemCount = pEntry->ItemCount();
444 while( iCount < iTotleItemCount )
446 const SvLBoxItem& rItem = pEntry->GetItem( iCount );
447 if ( rItem.GetType() == SvLBoxItemType::String &&
448 !static_cast<const SvLBoxString&>( rItem ).GetText().isEmpty() )
450 iRealItemCount++;
452 iCount++;
454 if(iRealItemCount<=1 )
456 return OUString();
458 else
460 return SvTreeListBox::SearchEntryTextWithHeadTitle( pEntry );
464 OUString SAL_CALL AccessibleListBoxEntry::getAccessibleName( )
466 ::osl::MutexGuard aGuard( m_aMutex );
468 EnsureIsAlive();
470 OUString sRet(implGetText());
472 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
474 OUString altText = getListBox()->GetEntryAltText( pEntry );
475 if (!altText.isEmpty())
477 sRet += " " + altText;
480 return sRet;
483 Reference< XAccessibleRelationSet > SAL_CALL AccessibleListBoxEntry::getAccessibleRelationSet( )
485 Reference< XAccessibleRelationSet > xRelSet;
486 Reference< XAccessible > xParent;
487 if ( m_aEntryPath.size() > 1 ) // not a root entry
488 xParent = implGetParentAccessible();
489 if ( xParent.is() )
491 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
492 Sequence< Reference< XInterface > > aSequence { xParent };
493 pRelationSetHelper->AddRelation(
494 AccessibleRelation( AccessibleRelationType::NODE_CHILD_OF, aSequence ) );
495 xRelSet = pRelationSetHelper;
497 return xRelSet;
500 Reference< XAccessibleStateSet > SAL_CALL AccessibleListBoxEntry::getAccessibleStateSet( )
502 ::osl::MutexGuard aGuard( m_aMutex );
504 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
505 Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
507 if ( IsAlive_Impl() )
509 switch(getAccessibleRole())
511 case AccessibleRole::LABEL:
512 pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
513 pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
514 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
515 if (getListBox()->IsInplaceEditingEnabled())
516 pStateSetHelper->AddState( AccessibleStateType::EDITABLE );
517 if (IsShowing_Impl())
518 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
519 break;
520 case AccessibleRole::CHECK_BOX:
521 pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
522 pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
523 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
524 if (IsShowing_Impl())
525 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
526 break;
528 SvTreeListEntry *pEntry = getListBox()->GetEntryFromPath(m_aEntryPath);
529 if (pEntry)
530 getListBox()->FillAccessibleEntryStateSet(pEntry, *pStateSetHelper);
532 else
533 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
535 return xStateSet;
538 Locale SAL_CALL AccessibleListBoxEntry::getLocale( )
540 SolarMutexGuard aSolarGuard;
541 ::osl::MutexGuard aGuard( m_aMutex );
543 return implGetLocale();
546 // XAccessibleComponent
548 sal_Bool SAL_CALL AccessibleListBoxEntry::containsPoint( const awt::Point& rPoint )
550 return tools::Rectangle( Point(), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
553 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleAtPoint( const awt::Point& _aPoint )
555 SolarMutexGuard aSolarGuard;
556 ::osl::MutexGuard aGuard( m_aMutex );
558 EnsureIsAlive();
559 SvTreeListEntry* pEntry = getListBox()->GetEntry( VCLPoint( _aPoint ) );
560 if ( !pEntry )
561 throw RuntimeException();
563 Reference< XAccessible > xAcc;
564 AccessibleListBoxEntry* pAccEntry = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
565 tools::Rectangle aRect = pAccEntry->GetBoundingBox_Impl();
566 if ( aRect.IsInside( VCLPoint( _aPoint ) ) )
567 xAcc = pAccEntry;
568 return xAcc;
571 awt::Rectangle SAL_CALL AccessibleListBoxEntry::getBounds( )
573 return AWTRectangle( GetBoundingBox() );
576 awt::Point SAL_CALL AccessibleListBoxEntry::getLocation( )
578 return AWTPoint( GetBoundingBox().TopLeft() );
581 awt::Point SAL_CALL AccessibleListBoxEntry::getLocationOnScreen( )
583 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
586 awt::Size SAL_CALL AccessibleListBoxEntry::getSize( )
588 return AWTSize( GetBoundingBox().GetSize() );
591 void SAL_CALL AccessibleListBoxEntry::grabFocus( )
593 // do nothing, because no focus for each item
596 sal_Int32 AccessibleListBoxEntry::getForeground( )
598 SolarMutexGuard aSolarGuard;
599 ::osl::MutexGuard aGuard( m_aMutex );
601 sal_Int32 nColor = 0;
602 Reference< XAccessible > xParent = getAccessibleParent();
603 if ( xParent.is() )
605 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
606 if ( xParentComp.is() )
607 nColor = xParentComp->getForeground();
610 return nColor;
613 sal_Int32 AccessibleListBoxEntry::getBackground( )
615 SolarMutexGuard aSolarGuard;
616 ::osl::MutexGuard aGuard( m_aMutex );
618 sal_Int32 nColor = 0;
619 Reference< XAccessible > xParent = getAccessibleParent();
620 if ( xParent.is() )
622 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
623 if ( xParentComp.is() )
624 nColor = xParentComp->getBackground();
627 return nColor;
630 // XAccessibleText
633 awt::Rectangle SAL_CALL AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex )
635 SolarMutexGuard aSolarGuard;
636 ::osl::MutexGuard aGuard( m_aMutex );
638 EnsureIsAlive();
640 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
641 throw IndexOutOfBoundsException();
643 awt::Rectangle aBounds( 0, 0, 0, 0 );
644 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
645 if ( pEntry )
647 vcl::ControlLayoutData aLayoutData;
648 tools::Rectangle aItemRect = GetBoundingBox();
649 getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
650 tools::Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
651 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
652 aBounds = AWTRectangle( aCharRect );
655 return aBounds;
658 sal_Int32 SAL_CALL AccessibleListBoxEntry::getIndexAtPoint( const awt::Point& aPoint )
660 SolarMutexGuard aSolarGuard;
661 ::osl::MutexGuard aGuard( m_aMutex );
662 EnsureIsAlive();
663 if(aPoint.X==0 && aPoint.Y==0) return 0;
665 sal_Int32 nIndex = -1;
666 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
667 if ( pEntry )
669 vcl::ControlLayoutData aLayoutData;
670 tools::Rectangle aItemRect = GetBoundingBox();
671 getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
672 Point aPnt( VCLPoint( aPoint ) );
673 aPnt += aItemRect.TopLeft();
674 nIndex = aLayoutData.GetIndexForPoint( aPnt );
677 return nIndex;
680 sal_Bool SAL_CALL AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
682 SolarMutexGuard aSolarGuard;
683 ::osl::MutexGuard aGuard( m_aMutex );
684 EnsureIsAlive();
686 OUString sText = implGetText();
687 if ( ( 0 > nStartIndex ) || ( sText.getLength() <= nStartIndex )
688 || ( 0 > nEndIndex ) || ( sText.getLength() <= nEndIndex ) )
689 throw IndexOutOfBoundsException();
691 sal_Int32 nLen = nEndIndex - nStartIndex + 1;
692 ::svt::OStringTransfer::CopyString( sText.copy( nStartIndex, nLen ), getListBox() );
694 return true;
697 // XAccessibleEventBroadcaster
699 void SAL_CALL AccessibleListBoxEntry::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
701 if (xListener.is())
703 ::osl::MutexGuard aGuard( m_aMutex );
704 if (!m_nClientId)
705 m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
706 comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
710 void SAL_CALL AccessibleListBoxEntry::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
712 if (xListener.is())
714 ::osl::MutexGuard aGuard( m_aMutex );
716 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
717 if ( !nListenerCount )
719 // no listeners anymore
720 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
721 // and at least to us not firing any events anymore, in case somebody calls
722 // NotifyAccessibleEvent, again
723 sal_Int32 nId = m_nClientId;
724 m_nClientId = 0;
725 comphelper::AccessibleEventNotifier::revokeClient( nId );
731 // XAccessibleAction
733 sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleActionCount( )
735 ::osl::MutexGuard aGuard( m_aMutex );
737 // three actions supported
738 SvTreeListBox* pBox = getListBox();
739 SvTreeFlags treeFlag = pBox->GetTreeFlags();
740 bool bHasButtons = (getListBox()->GetStyle() & WB_HASBUTTONS)!=0;
741 if( (treeFlag & SvTreeFlags::CHKBTN) && !bHasButtons)
743 sal_Int16 role = getAccessibleRole();
744 if ( role == AccessibleRole::CHECK_BOX )
745 return 2;
746 else if ( role == AccessibleRole::LABEL )
747 return 0;
749 else
750 return ACCESSIBLE_ACTION_COUNT;
751 return 0;
754 sal_Bool SAL_CALL AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex )
756 SolarMutexGuard aSolarGuard;
757 ::osl::MutexGuard aGuard( m_aMutex );
759 bool bRet = false;
760 checkActionIndex_Impl( nIndex );
761 EnsureIsAlive();
763 SvTreeFlags treeFlag = getListBox()->GetTreeFlags();
764 if( nIndex == 0 && (treeFlag & SvTreeFlags::CHKBTN) )
766 if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
768 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
769 SvButtonState state = getListBox()->GetCheckButtonState( pEntry );
770 if ( state == SvButtonState::Checked )
771 getListBox()->SetCheckButtonState(pEntry, SvButtonState::Unchecked);
772 else if (state == SvButtonState::Unchecked)
773 getListBox()->SetCheckButtonState(pEntry, SvButtonState::Checked);
776 else if( (nIndex == 1 && (treeFlag & SvTreeFlags::CHKBTN) ) || (nIndex == 0) )
778 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
779 if ( pEntry )
781 if ( getListBox()->IsExpanded( pEntry ) )
782 getListBox()->Collapse( pEntry );
783 else
784 getListBox()->Expand( pEntry );
785 bRet = true;
789 return bRet;
792 OUString SAL_CALL AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex )
794 SolarMutexGuard aSolarGuard;
795 ::osl::MutexGuard aGuard( m_aMutex );
797 checkActionIndex_Impl( nIndex );
798 EnsureIsAlive();
800 // sal_Bool bHasButtons = (getListBox()->GetStyle() & WB_HASBUTTONS)!=0;
801 SvTreeListEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
802 SvButtonState state = getListBox()->GetCheckButtonState( pEntry );
803 SvTreeFlags treeFlag = getListBox()->GetTreeFlags();
804 if(nIndex == 0 && (treeFlag & SvTreeFlags::CHKBTN))
806 if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
808 if ( state == SvButtonState::Checked )
809 return OUString("UnCheck");
810 else if (state == SvButtonState::Unchecked)
811 return OUString("Check");
813 else
815 //Sometimes, a List or Tree may have both checkbox and label at the same time
816 return OUString();
818 }else if( (nIndex == 1 && (treeFlag & SvTreeFlags::CHKBTN)) || nIndex == 0 )
820 if( pEntry->HasChildren() || pEntry->HasChildrenOnDemand() )
821 return getListBox()->IsExpanded( pEntry ) ?
822 AccResId(STR_SVT_ACC_ACTION_COLLAPSE) :
823 AccResId(STR_SVT_ACC_ACTION_EXPAND);
824 return OUString();
827 throw IndexOutOfBoundsException();
830 Reference< XAccessibleKeyBinding > AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex )
832 ::osl::MutexGuard aGuard( m_aMutex );
834 Reference< XAccessibleKeyBinding > xRet;
835 checkActionIndex_Impl( nIndex );
836 // ... which key?
837 return xRet;
840 // XAccessibleSelection
842 void SAL_CALL AccessibleListBoxEntry::selectAccessibleChild( sal_Int32 nChildIndex )
844 SolarMutexGuard aSolarGuard;
845 ::osl::MutexGuard aGuard( m_aMutex );
847 EnsureIsAlive();
849 SvTreeListEntry* pEntry = GetRealChild(nChildIndex);
850 if ( !pEntry )
851 throw IndexOutOfBoundsException();
853 getListBox()->Select( pEntry );
856 sal_Bool SAL_CALL AccessibleListBoxEntry::isAccessibleChildSelected( sal_Int32 nChildIndex )
858 SolarMutexGuard aSolarGuard;
859 ::osl::MutexGuard aGuard( m_aMutex );
861 EnsureIsAlive();
863 SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
864 SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, nChildIndex );
865 if ( !pEntry )
866 throw IndexOutOfBoundsException();
868 return getListBox()->IsSelected( pEntry );
871 void SAL_CALL AccessibleListBoxEntry::clearAccessibleSelection( )
873 SolarMutexGuard aSolarGuard;
874 ::osl::MutexGuard aGuard( m_aMutex );
876 EnsureIsAlive();
878 SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
879 if ( !pParent )
880 throw RuntimeException();
881 sal_Int32 nCount = getListBox()->GetLevelChildCount( pParent );
882 for ( sal_Int32 i = 0; i < nCount; ++i )
884 SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
885 if ( getListBox()->IsSelected( pEntry ) )
886 getListBox()->Select( pEntry, false );
890 void SAL_CALL AccessibleListBoxEntry::selectAllAccessibleChildren( )
892 SolarMutexGuard aSolarGuard;
893 ::osl::MutexGuard aGuard( m_aMutex );
895 EnsureIsAlive();
897 SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
898 if ( !pParent )
899 throw RuntimeException();
900 sal_Int32 nCount = getListBox()->GetLevelChildCount( pParent );
901 for ( sal_Int32 i = 0; i < nCount; ++i )
903 SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
904 if ( !getListBox()->IsSelected( pEntry ) )
905 getListBox()->Select( pEntry );
909 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChildCount( )
911 SolarMutexGuard aSolarGuard;
912 ::osl::MutexGuard aGuard( m_aMutex );
914 EnsureIsAlive();
916 sal_Int32 i, nSelCount = 0, nCount = 0;
918 SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
919 if ( !pParent )
920 throw RuntimeException();
921 nCount = getListBox()->GetLevelChildCount( pParent );
922 for ( i = 0; i < nCount; ++i )
924 SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
925 if ( getListBox()->IsSelected( pEntry ) )
926 ++nSelCount;
929 return nSelCount;
932 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
934 SolarMutexGuard aSolarGuard;
935 ::osl::MutexGuard aGuard( m_aMutex );
937 EnsureIsAlive();
939 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
940 throw IndexOutOfBoundsException();
942 Reference< XAccessible > xChild;
943 sal_Int32 i, nSelCount = 0, nCount = 0;
945 SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
946 if ( !pParent )
947 throw RuntimeException();
948 nCount = getListBox()->GetLevelChildCount( pParent );
949 for ( i = 0; i < nCount; ++i )
951 SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, i );
952 if ( getListBox()->IsSelected( pEntry ) )
953 ++nSelCount;
955 if ( nSelCount == ( nSelectedChildIndex + 1 ) )
957 xChild = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
958 break;
962 return xChild;
965 void SAL_CALL AccessibleListBoxEntry::deselectAccessibleChild( sal_Int32 nSelectedChildIndex )
967 SolarMutexGuard aSolarGuard;
968 ::osl::MutexGuard aGuard( m_aMutex );
970 EnsureIsAlive();
972 SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
973 SvTreeListEntry* pEntry = getListBox()->GetEntry( pParent, nSelectedChildIndex );
974 if ( !pEntry )
975 throw IndexOutOfBoundsException();
977 getListBox()->Select( pEntry, false );
979 sal_Int32 SAL_CALL AccessibleListBoxEntry::getCaretPosition( )
981 return -1;
983 sal_Bool SAL_CALL AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex )
985 SolarMutexGuard aSolarGuard;
986 ::osl::MutexGuard aGuard( m_aMutex );
987 EnsureIsAlive();
989 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
990 throw IndexOutOfBoundsException();
992 return false;
994 sal_Unicode SAL_CALL AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex )
996 SolarMutexGuard aSolarGuard;
997 ::osl::MutexGuard aGuard( m_aMutex );
998 EnsureIsAlive();
999 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
1001 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleListBoxEntry::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
1003 SolarMutexGuard aSolarGuard;
1004 ::osl::MutexGuard aGuard( m_aMutex );
1005 EnsureIsAlive();
1007 OUString sText( implGetText() );
1009 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
1010 throw IndexOutOfBoundsException();
1012 return css::uno::Sequence< css::beans::PropertyValue >();
1014 sal_Int32 SAL_CALL AccessibleListBoxEntry::getCharacterCount( )
1016 SolarMutexGuard aSolarGuard;
1017 ::osl::MutexGuard aGuard( m_aMutex );
1018 EnsureIsAlive();
1019 return implGetText().getLength();
1022 OUString SAL_CALL AccessibleListBoxEntry::getSelectedText( )
1024 SolarMutexGuard aSolarGuard;
1025 ::osl::MutexGuard aGuard( m_aMutex );
1026 EnsureIsAlive();
1027 return OUString();
1029 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionStart( )
1031 SolarMutexGuard aSolarGuard;
1032 ::osl::MutexGuard aGuard( m_aMutex );
1033 EnsureIsAlive();
1034 return 0;
1036 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionEnd( )
1038 SolarMutexGuard aSolarGuard;
1039 ::osl::MutexGuard aGuard( m_aMutex );
1040 EnsureIsAlive();
1041 return 0;
1043 sal_Bool SAL_CALL AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
1045 SolarMutexGuard aSolarGuard;
1046 ::osl::MutexGuard aGuard( m_aMutex );
1047 EnsureIsAlive();
1049 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
1050 throw IndexOutOfBoundsException();
1052 return false;
1054 OUString SAL_CALL AccessibleListBoxEntry::getText( )
1056 SolarMutexGuard aSolarGuard;
1057 ::osl::MutexGuard aGuard( m_aMutex );
1058 EnsureIsAlive();
1059 return implGetText( );
1061 OUString SAL_CALL AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
1063 SolarMutexGuard aSolarGuard;
1064 ::osl::MutexGuard aGuard( m_aMutex );
1065 EnsureIsAlive();
1066 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
1068 css::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
1070 SolarMutexGuard aSolarGuard;
1071 ::osl::MutexGuard aGuard( m_aMutex );
1072 EnsureIsAlive();
1073 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
1075 css::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
1077 SolarMutexGuard aSolarGuard;
1078 ::osl::MutexGuard aGuard( m_aMutex );
1079 EnsureIsAlive();
1080 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
1082 css::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
1084 SolarMutexGuard aSolarGuard;
1085 ::osl::MutexGuard aGuard( m_aMutex );
1086 EnsureIsAlive();
1088 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
1091 // XAccessibleValue
1094 Any AccessibleListBoxEntry::getCurrentValue( )
1096 ::osl::MutexGuard aGuard( m_aMutex );
1097 Any aValue;
1098 sal_Int32 level = (static_cast<sal_Int32>(m_aEntryPath.size()) - 1);
1099 level = level < 0 ? 0: level;
1100 aValue <<= level;
1101 return aValue;
1105 sal_Bool AccessibleListBoxEntry::setCurrentValue( const Any& aNumber )
1107 ::osl::MutexGuard aGuard( m_aMutex );
1110 bool bReturn = false;
1111 SvTreeListBox* pBox = getListBox();
1112 if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
1114 SvTreeListEntry* pEntry = pBox->GetEntryFromPath( m_aEntryPath );
1115 if ( pEntry )
1117 sal_Int32 nValue(0), nValueMin(0), nValueMax(0);
1118 aNumber >>= nValue;
1119 getMinimumValue() >>= nValueMin;
1120 getMaximumValue() >>= nValueMax;
1122 if ( nValue < nValueMin )
1123 nValue = nValueMin;
1124 else if ( nValue > nValueMax )
1125 nValue = nValueMax;
1127 pBox->SetCheckButtonState(pEntry, static_cast<SvButtonState>(nValue) );
1128 bReturn = true;
1132 return bReturn;
1136 Any AccessibleListBoxEntry::getMaximumValue( )
1138 ::osl::MutexGuard aGuard( m_aMutex );
1140 Any aValue;
1141 // SvTreeListBox* pBox = getListBox();
1142 switch(getAccessibleRole())
1144 case AccessibleRole::CHECK_BOX:
1145 aValue <<= sal_Int32(1);
1146 break;
1147 case AccessibleRole::LABEL:
1148 default:
1149 break;
1152 return aValue;
1156 Any AccessibleListBoxEntry::getMinimumValue( )
1158 ::osl::MutexGuard aGuard( m_aMutex );
1160 Any aValue;
1161 // SvTreeListBox* pBox = getListBox();
1162 switch(getAccessibleRole())
1164 case AccessibleRole::CHECK_BOX:
1165 aValue <<= sal_Int32(0);
1166 break;
1167 case AccessibleRole::LABEL:
1168 default:
1169 break;
1172 return aValue;
1176 SvTreeListEntry* AccessibleListBoxEntry::GetRealChild(sal_Int32 nIndex)
1178 SvTreeListEntry* pEntry = nullptr;
1179 SvTreeListEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
1180 if (pParent)
1182 pEntry = getListBox()->GetEntry( pParent, nIndex );
1183 if ( !pEntry && getAccessibleChildCount() > 0 )
1185 getListBox()->RequestingChildren(pParent);
1186 pEntry = getListBox()->GetEntry( pParent, nIndex );
1189 return pEntry;
1192 }// namespace accessibility
1195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */