Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / accessiblelistboxentry.cxx
blobf456844b8ee8b0c1340b16b4b6f99ecdb718106b
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 <extended/accessiblelistbox.hxx>
22 #include <vcl/toolkit/treelistbox.hxx>
23 #include <svtools/stringtransfer.hxx>
24 #include <vcl/toolkit/svlbitm.hxx>
25 #include <com/sun/star/awt/Rectangle.hpp>
26 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <i18nlangtag/languagetag.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/settings.hxx>
33 #include <toolkit/helper/convert.hxx>
34 #include <unotools/accessiblerelationsethelper.hxx>
35 #include <cppuhelper/supportsservice.hxx>
36 #include <comphelper/accessibleeventnotifier.hxx>
37 #include <helper/accresmgr.hxx>
38 #include <strings.hrc>
40 #define ACCESSIBLE_ACTION_COUNT 1
42 namespace
44 /// @throws css::lang::IndexOutOfBoundsException
45 void checkActionIndex_Impl( sal_Int32 _nIndex )
47 if ( _nIndex < 0 || _nIndex >= ACCESSIBLE_ACTION_COUNT )
48 // only three actions
49 throw css::lang::IndexOutOfBoundsException();
54 namespace accessibility
56 // class AccessibleListBoxEntry -----------------------------------------------------
58 using namespace ::com::sun::star::accessibility;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star;
62 using namespace ::comphelper;
65 // Ctor() and Dtor()
67 AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox& _rListBox,
68 SvTreeListEntry& rEntry,
69 AccessibleListBox & rListBox)
70 : AccessibleListBoxEntry_BASE( m_aMutex )
72 , m_pTreeListBox( &_rListBox )
73 , m_pSvLBoxEntry(&rEntry)
74 , m_nClientId( 0 )
75 , m_wListBox(&rListBox)
76 , m_rListBox(rListBox)
78 m_pTreeListBox->AddEventListener( LINK( this, AccessibleListBoxEntry, WindowEventListener ) );
79 _rListBox.FillEntryPath( m_pSvLBoxEntry, m_aEntryPath );
82 AccessibleListBoxEntry::~AccessibleListBoxEntry()
84 if ( IsAlive_Impl() )
86 // increment ref count to prevent double call of Dtor
87 osl_atomic_increment( &m_refCount );
88 dispose();
92 IMPL_LINK( AccessibleListBoxEntry, WindowEventListener, VclWindowEvent&, rEvent, void )
94 OSL_ENSURE( rEvent.GetWindow() , "AccessibleListBoxEntry::WindowEventListener: no event window!" );
95 OSL_ENSURE( rEvent.GetWindow() == m_pTreeListBox, "AccessibleListBoxEntry::WindowEventListener: where did this come from?" );
97 if ( m_pTreeListBox == nullptr )
98 return;
100 switch ( rEvent.GetId() )
102 case VclEventId::ObjectDying :
104 if ( m_pTreeListBox )
105 m_pTreeListBox->RemoveEventListener( LINK( this, AccessibleListBoxEntry, WindowEventListener ) );
106 m_pTreeListBox = nullptr;
107 dispose();
108 break;
110 default: break;
114 void AccessibleListBoxEntry::NotifyAccessibleEvent( sal_Int16 _nEventId,
115 const css::uno::Any& _aOldValue,
116 const css::uno::Any& _aNewValue )
118 Reference< uno::XInterface > xSource( *this );
119 AccessibleEventObject aEventObj( xSource, _nEventId, _aNewValue, _aOldValue, -1 );
121 if (m_nClientId)
122 comphelper::AccessibleEventNotifier::addEvent( m_nClientId, aEventObj );
126 tools::Rectangle AccessibleListBoxEntry::GetBoundingBox_Impl() const
128 tools::Rectangle aRect;
129 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
130 if ( pEntry )
132 aRect = m_pTreeListBox->GetBoundingRect( pEntry );
133 SvTreeListEntry* pParent = m_pTreeListBox->GetParent( pEntry );
134 if ( pParent )
136 // position relative to parent entry
137 Point aTopLeft = aRect.TopLeft();
138 aTopLeft -= m_pTreeListBox->GetBoundingRect( pParent ).TopLeft();
139 aRect = tools::Rectangle( aTopLeft, aRect.GetSize() );
143 return aRect;
146 tools::Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
148 tools::Rectangle aRect;
149 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
150 if ( pEntry )
152 aRect = m_pTreeListBox->GetBoundingRect( pEntry );
153 Point aTopLeft = aRect.TopLeft();
154 aTopLeft += m_pTreeListBox->GetWindowExtentsRelative( nullptr ).TopLeft();
155 aRect = tools::Rectangle( aTopLeft, aRect.GetSize() );
158 return aRect;
161 bool AccessibleListBoxEntry::IsAlive_Impl() const
163 return !rBHelper.bDisposed && !rBHelper.bInDispose && (m_pTreeListBox != nullptr);
166 bool AccessibleListBoxEntry::IsShowing_Impl() const
168 Reference< XAccessible > xParent = implGetParentAccessible( );
170 bool bShowing = false;
171 Reference< XAccessibleContext > xParentContext =
172 xParent.is() ? xParent->getAccessibleContext() : Reference< XAccessibleContext >();
173 if( xParentContext.is() )
175 Reference< XAccessibleComponent > xParentComp( xParentContext, uno::UNO_QUERY );
176 if( xParentComp.is() )
177 bShowing = GetBoundingBox_Impl().Overlaps( VCLRectangle( xParentComp->getBounds() ) );
180 return bShowing;
183 tools::Rectangle AccessibleListBoxEntry::GetBoundingBox()
185 SolarMutexGuard aSolarGuard;
186 ::osl::MutexGuard aGuard( m_aMutex );
188 EnsureIsAlive();
189 return GetBoundingBox_Impl();
192 tools::Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen()
194 SolarMutexGuard aSolarGuard;
195 ::osl::MutexGuard aGuard( m_aMutex );
197 EnsureIsAlive();
198 return GetBoundingBoxOnScreen_Impl();
201 void AccessibleListBoxEntry::EnsureIsAlive() const
203 if ( !IsAlive_Impl() )
204 throw lang::DisposedException();
207 OUString AccessibleListBoxEntry::implGetText()
209 OUString sRet;
210 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
211 if ( pEntry )
212 sRet = SvTreeListBox::SearchEntryTextWithHeadTitle( pEntry );
213 return sRet;
216 Locale AccessibleListBoxEntry::implGetLocale()
218 return Application::GetSettings().GetUILanguageTag().getLocale();
220 void AccessibleListBoxEntry::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
222 nStartIndex = 0;
223 nEndIndex = 0;
226 // XTypeProvider
229 Sequence< sal_Int8 > AccessibleListBoxEntry::getImplementationId()
231 return css::uno::Sequence<sal_Int8>();
235 // XComponent
237 void SAL_CALL AccessibleListBoxEntry::disposing()
239 SolarMutexGuard aSolarGuard;
240 ::osl::MutexGuard aGuard( m_aMutex );
242 Reference< XAccessible > xKeepAlive( this );
244 // Send a disposing to all listeners.
245 if ( m_nClientId )
247 ::comphelper::AccessibleEventNotifier::TClientId nId = m_nClientId;
248 m_nClientId = 0;
249 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
252 // clean up
253 m_wListBox.clear();
255 if ( m_pTreeListBox )
256 m_pTreeListBox->RemoveEventListener( LINK( this, AccessibleListBoxEntry, WindowEventListener ) );
257 m_pTreeListBox = nullptr;
260 // XServiceInfo
262 OUString SAL_CALL AccessibleListBoxEntry::getImplementationName()
264 return "com.sun.star.comp.svtools.AccessibleTreeListBoxEntry";
267 Sequence< OUString > SAL_CALL AccessibleListBoxEntry::getSupportedServiceNames()
269 return {"com.sun.star.accessibility.AccessibleContext",
270 "com.sun.star.accessibility.AccessibleComponent",
271 "com.sun.star.awt.AccessibleTreeListBoxEntry"};
274 sal_Bool SAL_CALL AccessibleListBoxEntry::supportsService( const OUString& _rServiceName )
276 return cppu::supportsService(this, _rServiceName);
279 // XAccessible
281 Reference< XAccessibleContext > SAL_CALL AccessibleListBoxEntry::getAccessibleContext( )
283 EnsureIsAlive();
284 return this;
287 // XAccessibleContext
289 sal_Int64 SAL_CALL AccessibleListBoxEntry::getAccessibleChildCount( )
291 SolarMutexGuard aSolarGuard;
292 ::osl::MutexGuard aGuard( m_aMutex );
294 EnsureIsAlive();
295 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
296 sal_Int32 nCount = 0;
297 if ( pEntry )
298 nCount = m_pTreeListBox->GetLevelChildCount( pEntry );
300 return nCount;
303 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleChild( sal_Int64 i )
305 SolarMutexGuard aSolarGuard;
306 ::osl::MutexGuard aGuard( m_aMutex );
307 EnsureIsAlive();
309 SvTreeListEntry* pEntry = GetRealChild(i);
310 if ( !pEntry )
311 throw IndexOutOfBoundsException();
313 uno::Reference<XAccessible> xListBox(m_wListBox);
314 assert(xListBox.is());
316 return m_rListBox.implGetAccessible(*pEntry);
319 Reference< XAccessible > AccessibleListBoxEntry::implGetParentAccessible( ) const
321 Reference< XAccessible > xParent;
322 if ( !xParent.is() )
324 assert( m_aEntryPath.size() ); // invalid path
325 if ( m_aEntryPath.size() == 1 )
326 { // we're a top level entry
327 // -> our parent is the tree listbox itself
328 if ( m_pTreeListBox )
329 xParent = m_pTreeListBox->GetAccessible( );
331 else
332 { // we have an entry as parent -> get its accessible
334 // shorten our access path by one
335 std::deque< sal_Int32 > aParentPath( m_aEntryPath );
336 aParentPath.pop_back();
338 // get the entry for this shortened access path
339 SvTreeListEntry* pParentEntry = m_pTreeListBox->GetEntryFromPath( aParentPath );
340 OSL_ENSURE( pParentEntry, "AccessibleListBoxEntry::implGetParentAccessible: could not obtain a parent entry!" );
342 if ( pParentEntry )
343 pParentEntry = m_pTreeListBox->GetParent(pParentEntry);
344 if ( pParentEntry )
346 uno::Reference<XAccessible> xListBox(m_wListBox);
347 assert(xListBox.is());
348 return m_rListBox.implGetAccessible(*pParentEntry);
349 // the AccessibleListBoxEntry class will create its parent
350 // when needed
355 return xParent;
359 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleParent( )
361 SolarMutexGuard aSolarGuard;
362 ::osl::MutexGuard aGuard( m_aMutex );
363 EnsureIsAlive();
365 return implGetParentAccessible( );
368 sal_Int64 SAL_CALL AccessibleListBoxEntry::getAccessibleIndexInParent( )
370 ::osl::MutexGuard aGuard( m_aMutex );
372 OSL_ENSURE( !m_aEntryPath.empty(), "empty path" );
373 return m_aEntryPath.empty() ? -1 : m_aEntryPath.back();
376 sal_Int32 AccessibleListBoxEntry::GetRoleType() const
378 sal_Int32 nCase = 0;
379 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry(0);
380 if ( pEntry )
382 if( pEntry->HasChildrenOnDemand() || m_pTreeListBox->GetChildCount(pEntry) > 0 )
384 nCase = 1;
385 return nCase;
389 bool bHasButtons = (m_pTreeListBox->GetStyle() & WB_HASBUTTONS)!=0;
390 if( !(m_pTreeListBox->GetTreeFlags() & SvTreeFlags::CHKBTN) )
392 if( bHasButtons )
393 nCase = 1;
395 else
397 if( bHasButtons )
398 nCase = 2;
399 else
400 nCase = 3;
402 return nCase;
405 sal_Int16 SAL_CALL AccessibleListBoxEntry::getAccessibleRole( )
407 SolarMutexGuard aSolarGuard;
408 ::osl::MutexGuard aGuard( m_aMutex );
410 SvTreeListBox* pBox = m_pTreeListBox;
411 if(!pBox)
412 return AccessibleRole::UNKNOWN;
414 SvTreeFlags treeFlag = pBox->GetTreeFlags();
415 if(treeFlag & SvTreeFlags::CHKBTN )
417 SvTreeListEntry* pEntry = pBox->GetEntryFromPath( m_aEntryPath );
418 SvButtonState eState = pBox->GetCheckButtonState( pEntry );
419 switch( eState )
421 case SvButtonState::Checked:
422 case SvButtonState::Unchecked:
423 return AccessibleRole::CHECK_BOX;
424 case SvButtonState::Tristate:
425 default:
426 return AccessibleRole::LABEL;
429 if (GetRoleType() == 0)
430 return AccessibleRole::LIST_ITEM;
431 else
432 //o is: return AccessibleRole::LABEL;
433 return AccessibleRole::TREE_ITEM;
436 OUString SAL_CALL AccessibleListBoxEntry::getAccessibleDescription( )
438 SolarMutexGuard aSolarGuard;
439 ::osl::MutexGuard aGuard( m_aMutex );
441 if( getAccessibleRole() == AccessibleRole::TREE_ITEM )
443 return OUString();
445 return m_pTreeListBox->GetEntryAccessibleDescription(
446 m_pTreeListBox->GetEntryFromPath(m_aEntryPath));
449 OUString SAL_CALL AccessibleListBoxEntry::getAccessibleName( )
451 ::osl::MutexGuard aGuard( m_aMutex );
453 EnsureIsAlive();
455 return implGetText();
458 Reference< XAccessibleRelationSet > SAL_CALL AccessibleListBoxEntry::getAccessibleRelationSet( )
460 Reference< XAccessibleRelationSet > xRelSet;
461 Reference< XAccessible > xParent;
462 if ( m_aEntryPath.size() > 1 ) // not a root entry
463 xParent = implGetParentAccessible();
464 if ( xParent.is() )
466 rtl::Reference<utl::AccessibleRelationSetHelper> pRelationSetHelper = new utl::AccessibleRelationSetHelper;
467 Sequence< Reference< XInterface > > aSequence { xParent };
468 pRelationSetHelper->AddRelation(
469 AccessibleRelation( AccessibleRelationType::NODE_CHILD_OF, aSequence ) );
470 xRelSet = pRelationSetHelper;
472 return xRelSet;
475 sal_Int64 SAL_CALL AccessibleListBoxEntry::getAccessibleStateSet( )
477 ::osl::MutexGuard aGuard( m_aMutex );
479 sal_Int64 nStateSet = 0;
481 if ( IsAlive_Impl() )
483 switch(getAccessibleRole())
485 case AccessibleRole::LABEL:
486 nStateSet |= AccessibleStateType::TRANSIENT;
487 nStateSet |= AccessibleStateType::SELECTABLE;
488 nStateSet |= AccessibleStateType::ENABLED;
489 if (m_pTreeListBox->IsInplaceEditingEnabled())
490 nStateSet |= AccessibleStateType::EDITABLE;
491 if (IsShowing_Impl())
492 nStateSet |= AccessibleStateType::SHOWING;
493 break;
494 case AccessibleRole::CHECK_BOX:
495 nStateSet |= AccessibleStateType::TRANSIENT;
496 nStateSet |= AccessibleStateType::SELECTABLE;
497 nStateSet |= AccessibleStateType::ENABLED;
498 if (IsShowing_Impl())
499 nStateSet |= AccessibleStateType::SHOWING;
500 break;
502 SvTreeListEntry *pEntry = m_pTreeListBox->GetEntryFromPath(m_aEntryPath);
503 if (pEntry)
504 m_pTreeListBox->FillAccessibleEntryStateSet(pEntry, nStateSet);
506 else
507 nStateSet |= AccessibleStateType::DEFUNC;
509 return nStateSet;
512 Locale SAL_CALL AccessibleListBoxEntry::getLocale( )
514 SolarMutexGuard aSolarGuard;
515 ::osl::MutexGuard aGuard( m_aMutex );
517 return implGetLocale();
520 // XAccessibleComponent
522 sal_Bool SAL_CALL AccessibleListBoxEntry::containsPoint( const awt::Point& rPoint )
524 return tools::Rectangle( Point(), GetBoundingBox().GetSize() ).Contains( VCLPoint( rPoint ) );
527 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleAtPoint( const awt::Point& _aPoint )
529 SolarMutexGuard aSolarGuard;
530 ::osl::MutexGuard aGuard( m_aMutex );
532 EnsureIsAlive();
533 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry( VCLPoint( _aPoint ) );
534 if ( !pEntry )
535 throw RuntimeException("AccessibleListBoxEntry::getAccessibleAtPoint - pEntry cannot be empty!");
537 Reference< XAccessible > xAcc;
538 uno::Reference<XAccessible> xListBox(m_wListBox);
539 assert(xListBox.is());
540 auto pAccEntry = m_rListBox.implGetAccessible(*pEntry);
541 tools::Rectangle aRect = pAccEntry->GetBoundingBox_Impl();
542 if ( aRect.Contains( VCLPoint( _aPoint ) ) )
543 xAcc = pAccEntry.get();
544 return xAcc;
547 awt::Rectangle SAL_CALL AccessibleListBoxEntry::getBounds( )
549 return AWTRectangle( GetBoundingBox() );
552 awt::Point SAL_CALL AccessibleListBoxEntry::getLocation( )
554 return AWTPoint( GetBoundingBox().TopLeft() );
557 awt::Point SAL_CALL AccessibleListBoxEntry::getLocationOnScreen( )
559 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
562 awt::Size SAL_CALL AccessibleListBoxEntry::getSize( )
564 return AWTSize( GetBoundingBox().GetSize() );
567 void SAL_CALL AccessibleListBoxEntry::grabFocus( )
569 // do nothing, because no focus for each item
572 sal_Int32 AccessibleListBoxEntry::getForeground( )
574 SolarMutexGuard aSolarGuard;
575 ::osl::MutexGuard aGuard( m_aMutex );
577 sal_Int32 nColor = 0;
578 Reference< XAccessible > xParent = getAccessibleParent();
579 if ( xParent.is() )
581 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
582 if ( xParentComp.is() )
583 nColor = xParentComp->getForeground();
586 return nColor;
589 sal_Int32 AccessibleListBoxEntry::getBackground( )
591 SolarMutexGuard aSolarGuard;
592 ::osl::MutexGuard aGuard( m_aMutex );
594 sal_Int32 nColor = 0;
595 Reference< XAccessible > xParent = getAccessibleParent();
596 if ( xParent.is() )
598 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
599 if ( xParentComp.is() )
600 nColor = xParentComp->getBackground();
603 return nColor;
606 // XAccessibleText
609 awt::Rectangle SAL_CALL AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex )
611 SolarMutexGuard aSolarGuard;
612 ::osl::MutexGuard aGuard( m_aMutex );
614 EnsureIsAlive();
616 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
617 throw IndexOutOfBoundsException();
619 awt::Rectangle aBounds( 0, 0, 0, 0 );
620 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
621 if ( pEntry )
623 vcl::ControlLayoutData aLayoutData;
624 tools::Rectangle aItemRect = GetBoundingBox();
625 m_pTreeListBox->RecordLayoutData( &aLayoutData, aItemRect );
626 tools::Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
627 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
628 aBounds = AWTRectangle( aCharRect );
631 return aBounds;
634 sal_Int32 SAL_CALL AccessibleListBoxEntry::getIndexAtPoint( const awt::Point& aPoint )
636 SolarMutexGuard aSolarGuard;
637 ::osl::MutexGuard aGuard( m_aMutex );
638 EnsureIsAlive();
639 if(aPoint.X==0 && aPoint.Y==0) return 0;
641 sal_Int32 nIndex = -1;
642 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
643 if ( pEntry )
645 vcl::ControlLayoutData aLayoutData;
646 tools::Rectangle aItemRect = GetBoundingBox();
647 m_pTreeListBox->RecordLayoutData( &aLayoutData, aItemRect );
648 Point aPnt( VCLPoint( aPoint ) );
649 aPnt += aItemRect.TopLeft();
650 nIndex = aLayoutData.GetIndexForPoint( aPnt );
653 return nIndex;
656 sal_Bool SAL_CALL AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
658 SolarMutexGuard aSolarGuard;
659 ::osl::MutexGuard aGuard( m_aMutex );
660 EnsureIsAlive();
662 OUString sText = implGetText();
663 if ( ( 0 > nStartIndex ) || ( sText.getLength() <= nStartIndex )
664 || ( 0 > nEndIndex ) || ( sText.getLength() <= nEndIndex ) )
665 throw IndexOutOfBoundsException();
667 sal_Int32 nLen = nEndIndex - nStartIndex + 1;
668 ::svt::OStringTransfer::CopyString( sText.copy( nStartIndex, nLen ), m_pTreeListBox );
670 return true;
673 sal_Bool SAL_CALL AccessibleListBoxEntry::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
675 return false;
678 // XAccessibleEventBroadcaster
680 void SAL_CALL AccessibleListBoxEntry::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
682 if (xListener.is())
684 ::osl::MutexGuard aGuard( m_aMutex );
685 if (!m_nClientId)
686 m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
687 comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
691 void SAL_CALL AccessibleListBoxEntry::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
693 if (!xListener.is())
694 return;
696 ::osl::MutexGuard aGuard( m_aMutex );
698 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
699 if ( !nListenerCount )
701 // no listeners anymore
702 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
703 // and at least to us not firing any events anymore, in case somebody calls
704 // NotifyAccessibleEvent, again
705 sal_Int32 nId = m_nClientId;
706 m_nClientId = 0;
707 comphelper::AccessibleEventNotifier::revokeClient( nId );
712 // XAccessibleAction
714 sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleActionCount( )
716 ::osl::MutexGuard aGuard( m_aMutex );
718 // three actions supported
719 SvTreeFlags treeFlag = m_pTreeListBox->GetTreeFlags();
720 bool bHasButtons = (m_pTreeListBox->GetStyle() & WB_HASBUTTONS)!=0;
721 if( (treeFlag & SvTreeFlags::CHKBTN) && !bHasButtons)
723 sal_Int16 role = getAccessibleRole();
724 if ( role == AccessibleRole::CHECK_BOX )
725 return 2;
726 else if ( role == AccessibleRole::LABEL )
727 return 0;
729 else
730 return ACCESSIBLE_ACTION_COUNT;
731 return 0;
734 sal_Bool SAL_CALL AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex )
736 SolarMutexGuard aSolarGuard;
737 ::osl::MutexGuard aGuard( m_aMutex );
739 bool bRet = false;
740 checkActionIndex_Impl( nIndex );
741 EnsureIsAlive();
743 SvTreeFlags treeFlag = m_pTreeListBox->GetTreeFlags();
744 if( nIndex == 0 && (treeFlag & SvTreeFlags::CHKBTN) )
746 if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
748 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
749 SvButtonState state = m_pTreeListBox->GetCheckButtonState( pEntry );
750 if ( state == SvButtonState::Checked )
751 m_pTreeListBox->SetCheckButtonState(pEntry, SvButtonState::Unchecked);
752 else if (state == SvButtonState::Unchecked)
753 m_pTreeListBox->SetCheckButtonState(pEntry, SvButtonState::Checked);
756 else if( (nIndex == 1 && (treeFlag & SvTreeFlags::CHKBTN) ) || (nIndex == 0) )
758 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
759 if ( pEntry )
761 if ( m_pTreeListBox->IsExpanded( pEntry ) )
762 m_pTreeListBox->Collapse( pEntry );
763 else
764 m_pTreeListBox->Expand( pEntry );
765 bRet = true;
769 return bRet;
772 OUString SAL_CALL AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex )
774 SolarMutexGuard aSolarGuard;
775 ::osl::MutexGuard aGuard( m_aMutex );
777 checkActionIndex_Impl( nIndex );
778 EnsureIsAlive();
780 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
781 SvButtonState state = m_pTreeListBox->GetCheckButtonState( pEntry );
782 SvTreeFlags treeFlag = m_pTreeListBox->GetTreeFlags();
783 if(nIndex == 0 && (treeFlag & SvTreeFlags::CHKBTN))
785 if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
787 if ( state == SvButtonState::Checked )
788 return "UnCheck";
789 else if (state == SvButtonState::Unchecked)
790 return "Check";
792 else
794 //Sometimes, a List or Tree may have both checkbox and label at the same time
795 return OUString();
798 else if( (nIndex == 1 && (treeFlag & SvTreeFlags::CHKBTN)) || nIndex == 0 )
800 if( pEntry && (pEntry->HasChildren() || pEntry->HasChildrenOnDemand()) )
801 return m_pTreeListBox->IsExpanded( pEntry ) ?
802 AccResId(STR_SVT_ACC_ACTION_COLLAPSE) :
803 AccResId(STR_SVT_ACC_ACTION_EXPAND);
804 return OUString();
807 throw IndexOutOfBoundsException();
810 Reference< XAccessibleKeyBinding > AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex )
812 Reference< XAccessibleKeyBinding > xRet;
813 checkActionIndex_Impl( nIndex );
814 // ... which key?
815 return xRet;
818 // XAccessibleSelection
820 void SAL_CALL AccessibleListBoxEntry::selectAccessibleChild( sal_Int64 nChildIndex )
822 SolarMutexGuard aSolarGuard;
823 ::osl::MutexGuard aGuard( m_aMutex );
825 EnsureIsAlive();
827 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
828 throw IndexOutOfBoundsException();
830 SvTreeListEntry* pEntry = GetRealChild(nChildIndex);
831 if ( !pEntry )
832 throw IndexOutOfBoundsException();
834 m_pTreeListBox->Select( pEntry );
837 sal_Bool SAL_CALL AccessibleListBoxEntry::isAccessibleChildSelected( sal_Int64 nChildIndex )
839 SolarMutexGuard aSolarGuard;
840 ::osl::MutexGuard aGuard( m_aMutex );
842 EnsureIsAlive();
844 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
845 throw IndexOutOfBoundsException();
847 SvTreeListEntry* pParent = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
848 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry( pParent, nChildIndex );
849 if ( !pEntry )
850 throw IndexOutOfBoundsException();
852 return m_pTreeListBox->IsSelected( pEntry );
855 void SAL_CALL AccessibleListBoxEntry::clearAccessibleSelection( )
857 SolarMutexGuard aSolarGuard;
858 ::osl::MutexGuard aGuard( m_aMutex );
860 EnsureIsAlive();
862 SvTreeListEntry* pParent = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
863 if ( !pParent )
864 throw RuntimeException("AccessibleListBoxEntry::clearAccessibleSelection - pParent cannot be empty!");
865 sal_Int32 nCount = m_pTreeListBox->GetLevelChildCount( pParent );
866 for ( sal_Int32 i = 0; i < nCount; ++i )
868 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry( pParent, i );
869 if ( m_pTreeListBox->IsSelected( pEntry ) )
870 m_pTreeListBox->Select( pEntry, false );
874 void SAL_CALL AccessibleListBoxEntry::selectAllAccessibleChildren( )
876 SolarMutexGuard aSolarGuard;
877 ::osl::MutexGuard aGuard( m_aMutex );
879 EnsureIsAlive();
881 SvTreeListEntry* pParent = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
882 if ( !pParent )
883 throw RuntimeException("AccessibleListBoxEntry::selectAllAccessibleChildren - pParent cannot be empty!");
884 sal_Int32 nCount = m_pTreeListBox->GetLevelChildCount( pParent );
885 for ( sal_Int32 i = 0; i < nCount; ++i )
887 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry( pParent, i );
888 if ( !m_pTreeListBox->IsSelected( pEntry ) )
889 m_pTreeListBox->Select( pEntry );
893 sal_Int64 SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChildCount( )
895 SolarMutexGuard aSolarGuard;
896 ::osl::MutexGuard aGuard( m_aMutex );
898 EnsureIsAlive();
900 sal_Int64 nSelCount = 0;
902 SvTreeListEntry* pParent = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
903 if ( !pParent )
904 throw RuntimeException("AccessibleListBoxEntry::getSelectedAccessibleChildCount - pParent cannot be empty!");
905 sal_Int32 nCount = m_pTreeListBox->GetLevelChildCount( pParent );
906 for (sal_Int32 i = 0; i < nCount; ++i )
908 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry( pParent, i );
909 if ( m_pTreeListBox->IsSelected( pEntry ) )
910 ++nSelCount;
913 return nSelCount;
916 Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
918 SolarMutexGuard aSolarGuard;
919 ::osl::MutexGuard aGuard( m_aMutex );
921 EnsureIsAlive();
923 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
924 throw IndexOutOfBoundsException();
926 Reference< XAccessible > xChild;
927 sal_Int64 nSelCount = 0;
929 SvTreeListEntry* pParent = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
930 if ( !pParent )
931 throw RuntimeException("AccessibleListBoxEntry::getSelectedAccessibleChild - pParent cannot be empty!");
932 sal_Int32 nCount = m_pTreeListBox->GetLevelChildCount( pParent );
933 for (sal_Int32 i = 0; i < nCount; ++i )
935 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry( pParent, i );
936 if ( m_pTreeListBox->IsSelected( pEntry ) )
937 ++nSelCount;
939 if ( nSelCount == ( nSelectedChildIndex + 1 ) )
941 uno::Reference<XAccessible> xListBox(m_wListBox);
942 assert(xListBox.is());
943 xChild = m_rListBox.implGetAccessible(*pEntry).get();
944 break;
948 return xChild;
951 void SAL_CALL AccessibleListBoxEntry::deselectAccessibleChild( sal_Int64 nSelectedChildIndex )
953 SolarMutexGuard aSolarGuard;
954 ::osl::MutexGuard aGuard( m_aMutex );
956 EnsureIsAlive();
958 if (nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount())
959 throw IndexOutOfBoundsException();
961 SvTreeListEntry* pParent = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
962 SvTreeListEntry* pEntry = m_pTreeListBox->GetEntry( pParent, nSelectedChildIndex );
963 if ( !pEntry )
964 throw IndexOutOfBoundsException();
966 m_pTreeListBox->Select( pEntry, false );
968 sal_Int32 SAL_CALL AccessibleListBoxEntry::getCaretPosition( )
970 return -1;
972 sal_Bool SAL_CALL AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex )
974 SolarMutexGuard aSolarGuard;
975 ::osl::MutexGuard aGuard( m_aMutex );
976 EnsureIsAlive();
978 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
979 throw IndexOutOfBoundsException();
981 return false;
983 sal_Unicode SAL_CALL AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex )
985 SolarMutexGuard aSolarGuard;
986 ::osl::MutexGuard aGuard( m_aMutex );
987 EnsureIsAlive();
988 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
990 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleListBoxEntry::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
992 SolarMutexGuard aSolarGuard;
993 ::osl::MutexGuard aGuard( m_aMutex );
994 EnsureIsAlive();
996 OUString sText( implGetText() );
998 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
999 throw IndexOutOfBoundsException();
1001 return css::uno::Sequence< css::beans::PropertyValue >();
1003 sal_Int32 SAL_CALL AccessibleListBoxEntry::getCharacterCount( )
1005 SolarMutexGuard aSolarGuard;
1006 ::osl::MutexGuard aGuard( m_aMutex );
1007 EnsureIsAlive();
1008 return implGetText().getLength();
1011 OUString SAL_CALL AccessibleListBoxEntry::getSelectedText( )
1013 SolarMutexGuard aSolarGuard;
1014 ::osl::MutexGuard aGuard( m_aMutex );
1015 EnsureIsAlive();
1016 return OUString();
1018 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionStart( )
1020 SolarMutexGuard aSolarGuard;
1021 ::osl::MutexGuard aGuard( m_aMutex );
1022 EnsureIsAlive();
1023 return 0;
1025 sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionEnd( )
1027 SolarMutexGuard aSolarGuard;
1028 ::osl::MutexGuard aGuard( m_aMutex );
1029 EnsureIsAlive();
1030 return 0;
1032 sal_Bool SAL_CALL AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
1034 SolarMutexGuard aSolarGuard;
1035 ::osl::MutexGuard aGuard( m_aMutex );
1036 EnsureIsAlive();
1038 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
1039 throw IndexOutOfBoundsException();
1041 return false;
1043 OUString SAL_CALL AccessibleListBoxEntry::getText( )
1045 SolarMutexGuard aSolarGuard;
1046 ::osl::MutexGuard aGuard( m_aMutex );
1047 EnsureIsAlive();
1048 return implGetText( );
1050 OUString SAL_CALL AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
1052 SolarMutexGuard aSolarGuard;
1053 ::osl::MutexGuard aGuard( m_aMutex );
1054 EnsureIsAlive();
1055 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
1057 css::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
1059 SolarMutexGuard aSolarGuard;
1060 ::osl::MutexGuard aGuard( m_aMutex );
1061 EnsureIsAlive();
1062 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
1064 css::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
1066 SolarMutexGuard aSolarGuard;
1067 ::osl::MutexGuard aGuard( m_aMutex );
1068 EnsureIsAlive();
1069 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
1071 css::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
1073 SolarMutexGuard aSolarGuard;
1074 ::osl::MutexGuard aGuard( m_aMutex );
1075 EnsureIsAlive();
1077 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
1080 // XAccessibleValue
1083 Any AccessibleListBoxEntry::getCurrentValue( )
1085 ::osl::MutexGuard aGuard( m_aMutex );
1086 Any aValue;
1087 sal_Int32 level = static_cast<sal_Int32>(m_aEntryPath.size()) - 1;
1088 level = level < 0 ? 0: level;
1089 aValue <<= level;
1090 return aValue;
1094 sal_Bool AccessibleListBoxEntry::setCurrentValue( const Any& aNumber )
1096 ::osl::MutexGuard aGuard( m_aMutex );
1099 bool bReturn = false;
1100 SvTreeListBox* pBox = m_pTreeListBox;
1101 if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
1103 SvTreeListEntry* pEntry = pBox->GetEntryFromPath( m_aEntryPath );
1104 if ( pEntry )
1106 sal_Int32 nValue(0), nValueMin(0), nValueMax(0);
1107 aNumber >>= nValue;
1108 getMinimumValue() >>= nValueMin;
1109 getMaximumValue() >>= nValueMax;
1111 if ( nValue < nValueMin )
1112 nValue = nValueMin;
1113 else if ( nValue > nValueMax )
1114 nValue = nValueMax;
1116 pBox->SetCheckButtonState(pEntry, static_cast<SvButtonState>(nValue) );
1117 bReturn = true;
1121 return bReturn;
1125 Any AccessibleListBoxEntry::getMaximumValue( )
1127 ::osl::MutexGuard aGuard( m_aMutex );
1129 Any aValue;
1130 // SvTreeListBox* pBox = m_pTreeListBox;
1131 switch(getAccessibleRole())
1133 case AccessibleRole::CHECK_BOX:
1134 aValue <<= sal_Int32(1);
1135 break;
1136 case AccessibleRole::LABEL:
1137 default:
1138 break;
1141 return aValue;
1145 Any AccessibleListBoxEntry::getMinimumValue( )
1147 ::osl::MutexGuard aGuard( m_aMutex );
1149 Any aValue;
1150 // SvTreeListBox* pBox = m_pTreeListBox;
1151 switch(getAccessibleRole())
1153 case AccessibleRole::CHECK_BOX:
1154 aValue <<= sal_Int32(0);
1155 break;
1156 case AccessibleRole::LABEL:
1157 default:
1158 break;
1161 return aValue;
1164 Any AccessibleListBoxEntry::getMinimumIncrement( )
1166 ::osl::MutexGuard aGuard( m_aMutex );
1168 Any aValue;
1169 switch(getAccessibleRole())
1171 case AccessibleRole::CHECK_BOX:
1172 aValue <<= sal_Int32(1);
1173 break;
1174 case AccessibleRole::LABEL:
1175 default:
1176 break;
1179 return aValue;
1182 SvTreeListEntry* AccessibleListBoxEntry::GetRealChild(sal_Int32 nIndex)
1184 SvTreeListEntry* pEntry = nullptr;
1185 SvTreeListEntry* pParent = m_pTreeListBox->GetEntryFromPath( m_aEntryPath );
1186 if (pParent)
1188 pEntry = m_pTreeListBox->GetEntry( pParent, nIndex );
1189 if ( !pEntry && getAccessibleChildCount() > 0 )
1191 m_pTreeListBox->RequestingChildren(pParent);
1192 pEntry = m_pTreeListBox->GetEntry( pParent, nIndex );
1195 return pEntry;
1198 }// namespace accessibility
1201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */