1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/toolkit/svlbitm.hxx>
24 #include <com/sun/star/awt/Rectangle.hpp>
25 #include <com/sun/star/accessibility/AccessibleEventId.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/datatransfer/clipboard/XClipboard.hpp>
30 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
31 #include <i18nlangtag/languagetag.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/settings.hxx>
34 #include <vcl/unohelp.hxx>
35 #include <vcl/unohelp2.hxx>
36 #include <unotools/accessiblerelationsethelper.hxx>
37 #include <cppuhelper/supportsservice.hxx>
38 #include <comphelper/accessibleeventnotifier.hxx>
39 #include <helper/accresmgr.hxx>
40 #include <strings.hrc>
42 namespace accessibility
44 // class AccessibleListBoxEntry -----------------------------------------------------
46 using namespace ::com::sun::star::accessibility
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star
;
50 using namespace ::comphelper
;
55 AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox
& _rListBox
,
56 SvTreeListEntry
& rEntry
,
57 AccessibleListBox
& rListBox
)
58 : AccessibleListBoxEntry_BASE( m_aMutex
)
60 , m_pTreeListBox( &_rListBox
)
61 , m_pSvLBoxEntry(&rEntry
)
63 , m_wListBox(&rListBox
)
65 m_pTreeListBox
->AddEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
66 _rListBox
.FillEntryPath( m_pSvLBoxEntry
, m_aEntryPath
);
69 AccessibleListBoxEntry::~AccessibleListBoxEntry()
73 // increment ref count to prevent double call of Dtor
74 osl_atomic_increment( &m_refCount
);
79 IMPL_LINK( AccessibleListBoxEntry
, WindowEventListener
, VclWindowEvent
&, rEvent
, void )
81 OSL_ENSURE( rEvent
.GetWindow() , "AccessibleListBoxEntry::WindowEventListener: no event window!" );
82 OSL_ENSURE( rEvent
.GetWindow() == m_pTreeListBox
, "AccessibleListBoxEntry::WindowEventListener: where did this come from?" );
84 if ( m_pTreeListBox
== nullptr )
87 switch ( rEvent
.GetId() )
89 case VclEventId::CheckboxToggle
:
91 // assert this object is represented as a checkbox on a11y layer (LABEL role is used for
92 // SvButtonState::Tristate, s. AccessibleListBoxEntry::getAccessibleRole)
93 assert(getAccessibleRole() == AccessibleRole::CHECK_BOX
94 || getAccessibleRole() == AccessibleRole::LABEL
);
97 if (getAccessibleStateSet() & AccessibleStateType::CHECKED
)
98 aNewValue
<<= AccessibleStateType::CHECKED
;
100 aOldValue
<<= AccessibleStateType::CHECKED
;
102 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
105 case VclEventId::ObjectDying
:
107 if ( m_pTreeListBox
)
108 m_pTreeListBox
->RemoveEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
109 m_pTreeListBox
= nullptr;
117 void AccessibleListBoxEntry::NotifyAccessibleEvent( sal_Int16 _nEventId
,
118 const css::uno::Any
& _aOldValue
,
119 const css::uno::Any
& _aNewValue
)
121 Reference
< uno::XInterface
> xSource( *this );
122 AccessibleEventObject
aEventObj( xSource
, _nEventId
, _aNewValue
, _aOldValue
, -1 );
125 comphelper::AccessibleEventNotifier::addEvent( m_nClientId
, aEventObj
);
129 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBox_Impl() const
131 tools::Rectangle aRect
;
132 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
135 aRect
= m_pTreeListBox
->GetBoundingRect( pEntry
);
136 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetParent( pEntry
);
139 // position relative to parent entry
140 Point aTopLeft
= aRect
.TopLeft();
141 aTopLeft
-= m_pTreeListBox
->GetBoundingRect( pParent
).TopLeft();
142 aRect
= tools::Rectangle( aTopLeft
, aRect
.GetSize() );
149 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
151 tools::Rectangle aRect
;
152 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
155 aRect
= m_pTreeListBox
->GetBoundingRect( pEntry
);
156 Point aTopLeft
= aRect
.TopLeft();
157 aTopLeft
+= Point(m_pTreeListBox
->GetWindowExtentsAbsolute().TopLeft());
158 aRect
= tools::Rectangle( aTopLeft
, aRect
.GetSize() );
164 bool AccessibleListBoxEntry::IsAlive_Impl() const
166 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
&& (m_pTreeListBox
!= nullptr);
169 bool AccessibleListBoxEntry::IsShowing_Impl() const
171 Reference
< XAccessible
> xParent
= implGetParentAccessible( );
173 bool bShowing
= false;
174 Reference
< XAccessibleContext
> xParentContext
=
175 xParent
.is() ? xParent
->getAccessibleContext() : Reference
< XAccessibleContext
>();
176 if( xParentContext
.is() )
178 Reference
< XAccessibleComponent
> xParentComp( xParentContext
, uno::UNO_QUERY
);
179 if( xParentComp
.is() )
180 bShowing
= GetBoundingBox_Impl().Overlaps(
181 vcl::unohelper::ConvertToVCLRect(xParentComp
->getBounds()));
187 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBox()
189 SolarMutexGuard aSolarGuard
;
190 ::osl::MutexGuard
aGuard( m_aMutex
);
193 return GetBoundingBox_Impl();
196 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBoxOnScreen()
198 SolarMutexGuard aSolarGuard
;
199 ::osl::MutexGuard
aGuard( m_aMutex
);
202 return GetBoundingBoxOnScreen_Impl();
205 void AccessibleListBoxEntry::CheckActionIndex(sal_Int32 nIndex
)
207 if (nIndex
< 0 || nIndex
>= getAccessibleActionCount())
208 throw css::lang::IndexOutOfBoundsException();
211 void AccessibleListBoxEntry::EnsureIsAlive() const
213 if ( !IsAlive_Impl() )
214 throw lang::DisposedException();
217 OUString
AccessibleListBoxEntry::implGetText()
219 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
221 return SvTreeListBox::SearchEntryTextWithHeadTitle(pEntry
);
225 Locale
AccessibleListBoxEntry::implGetLocale()
227 return Application::GetSettings().GetUILanguageTag().getLocale();
229 void AccessibleListBoxEntry::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
236 Sequence
< sal_Int8
> AccessibleListBoxEntry::getImplementationId()
238 return css::uno::Sequence
<sal_Int8
>();
244 void SAL_CALL
AccessibleListBoxEntry::disposing()
246 SolarMutexGuard aSolarGuard
;
247 ::osl::MutexGuard
aGuard( m_aMutex
);
249 Reference
< XAccessible
> xKeepAlive( this );
251 // Send a disposing to all listeners.
254 ::comphelper::AccessibleEventNotifier::TClientId nId
= m_nClientId
;
256 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId
, *this );
262 if ( m_pTreeListBox
)
263 m_pTreeListBox
->RemoveEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
264 m_pTreeListBox
= nullptr;
269 OUString SAL_CALL
AccessibleListBoxEntry::getImplementationName()
271 return u
"com.sun.star.comp.svtools.AccessibleTreeListBoxEntry"_ustr
;
274 Sequence
< OUString
> SAL_CALL
AccessibleListBoxEntry::getSupportedServiceNames()
276 return {u
"com.sun.star.accessibility.AccessibleContext"_ustr
,
277 u
"com.sun.star.accessibility.AccessibleComponent"_ustr
,
278 u
"com.sun.star.awt.AccessibleTreeListBoxEntry"_ustr
};
281 sal_Bool SAL_CALL
AccessibleListBoxEntry::supportsService( const OUString
& _rServiceName
)
283 return cppu::supportsService(this, _rServiceName
);
288 Reference
< XAccessibleContext
> SAL_CALL
AccessibleListBoxEntry::getAccessibleContext( )
294 // XAccessibleContext
296 sal_Int64 SAL_CALL
AccessibleListBoxEntry::getAccessibleChildCount( )
298 SolarMutexGuard aSolarGuard
;
299 ::osl::MutexGuard
aGuard( m_aMutex
);
302 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
303 sal_Int32 nCount
= 0;
305 nCount
= m_pTreeListBox
->GetLevelChildCount( pEntry
);
310 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getAccessibleChild( sal_Int64 i
)
312 SolarMutexGuard aSolarGuard
;
313 ::osl::MutexGuard
aGuard( m_aMutex
);
316 SvTreeListEntry
* pEntry
= GetRealChild(i
);
318 throw IndexOutOfBoundsException();
320 rtl::Reference
<AccessibleListBox
> xListBox(m_wListBox
);
321 assert(xListBox
.is());
323 return xListBox
->implGetAccessible(*pEntry
);
326 Reference
< XAccessible
> AccessibleListBoxEntry::implGetParentAccessible( ) const
328 Reference
< XAccessible
> xParent
;
329 assert( m_aEntryPath
.size() ); // invalid path
330 if ( m_aEntryPath
.size() == 1 )
331 { // we're a top level entry
332 // -> our parent is the tree listbox itself
333 if ( m_pTreeListBox
)
334 xParent
= m_pTreeListBox
->GetAccessible( );
337 { // we have an entry as parent -> get its accessible
339 // shorten our access path by one
340 std::deque
< sal_Int32
> aParentPath( m_aEntryPath
);
341 aParentPath
.pop_back();
343 // get the entry for this shortened access path
344 SvTreeListEntry
* pParentEntry
= m_pTreeListBox
->GetEntryFromPath( aParentPath
);
345 assert(pParentEntry
&& "AccessibleListBoxEntry::implGetParentAccessible: could not obtain a parent entry!");
348 rtl::Reference
<AccessibleListBox
> xListBox(m_wListBox
);
349 assert(xListBox
.is());
350 return xListBox
->implGetAccessible(*pParentEntry
);
351 // the AccessibleListBoxEntry class will create its parent
360 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getAccessibleParent( )
362 SolarMutexGuard aSolarGuard
;
363 ::osl::MutexGuard
aGuard( m_aMutex
);
366 return implGetParentAccessible( );
369 sal_Int64 SAL_CALL
AccessibleListBoxEntry::getAccessibleIndexInParent( )
371 ::osl::MutexGuard
aGuard( m_aMutex
);
373 OSL_ENSURE( !m_aEntryPath
.empty(), "empty path" );
374 return m_aEntryPath
.empty() ? -1 : m_aEntryPath
.back();
377 sal_Int32
AccessibleListBoxEntry::GetRoleType() const
380 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry(0);
383 if( pEntry
->HasChildrenOnDemand() || m_pTreeListBox
->GetChildCount(pEntry
) > 0 )
390 bool bHasButtons
= (m_pTreeListBox
->GetStyle() & WB_HASBUTTONS
)!=0;
391 if( !(m_pTreeListBox
->GetTreeFlags() & SvTreeFlags::CHKBTN
) )
406 sal_Int16 SAL_CALL
AccessibleListBoxEntry::getAccessibleRole( )
408 SolarMutexGuard aSolarGuard
;
409 ::osl::MutexGuard
aGuard( m_aMutex
);
411 SvTreeListBox
* pBox
= m_pTreeListBox
;
413 return AccessibleRole::UNKNOWN
;
415 SvTreeFlags treeFlag
= pBox
->GetTreeFlags();
416 if(treeFlag
& SvTreeFlags::CHKBTN
)
418 SvTreeListEntry
* pEntry
= pBox
->GetEntryFromPath( m_aEntryPath
);
419 SvButtonState eState
= pBox
->GetCheckButtonState( pEntry
);
422 case SvButtonState::Checked
:
423 case SvButtonState::Unchecked
:
424 return AccessibleRole::CHECK_BOX
;
425 case SvButtonState::Tristate
:
427 return AccessibleRole::LABEL
;
430 if (GetRoleType() == 0)
431 return AccessibleRole::LIST_ITEM
;
433 //o is: return AccessibleRole::LABEL;
434 return AccessibleRole::TREE_ITEM
;
437 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleDescription( )
439 SolarMutexGuard aSolarGuard
;
440 ::osl::MutexGuard
aGuard( m_aMutex
);
442 if( getAccessibleRole() == AccessibleRole::TREE_ITEM
)
446 return m_pTreeListBox
->GetEntryAccessibleDescription(
447 m_pTreeListBox
->GetEntryFromPath(m_aEntryPath
));
450 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleName( )
452 ::osl::MutexGuard
aGuard( m_aMutex
);
456 return implGetText();
459 Reference
< XAccessibleRelationSet
> SAL_CALL
AccessibleListBoxEntry::getAccessibleRelationSet( )
461 Reference
< XAccessibleRelationSet
> xRelSet
;
462 Reference
< XAccessible
> xParent
;
463 if ( m_aEntryPath
.size() > 1 ) // not a root entry
464 xParent
= implGetParentAccessible();
467 rtl::Reference
<utl::AccessibleRelationSetHelper
> pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
468 Sequence
<Reference
<XAccessible
>> aSequence
{ xParent
};
469 pRelationSetHelper
->AddRelation(
470 AccessibleRelation( AccessibleRelationType_NODE_CHILD_OF
, aSequence
) );
471 xRelSet
= pRelationSetHelper
;
476 sal_Int64 SAL_CALL
AccessibleListBoxEntry::getAccessibleStateSet( )
478 ::osl::MutexGuard
aGuard( m_aMutex
);
480 sal_Int64 nStateSet
= 0;
482 if ( IsAlive_Impl() )
484 switch(getAccessibleRole())
486 case AccessibleRole::LABEL
:
487 nStateSet
|= AccessibleStateType::TRANSIENT
;
488 nStateSet
|= AccessibleStateType::SELECTABLE
;
489 nStateSet
|= AccessibleStateType::ENABLED
;
490 if (m_pTreeListBox
->IsInplaceEditingEnabled())
491 nStateSet
|= AccessibleStateType::EDITABLE
;
492 if (IsShowing_Impl())
493 nStateSet
|= AccessibleStateType::SHOWING
;
495 case AccessibleRole::CHECK_BOX
:
496 nStateSet
|= AccessibleStateType::TRANSIENT
;
497 nStateSet
|= AccessibleStateType::SELECTABLE
;
498 nStateSet
|= AccessibleStateType::ENABLED
;
499 if (IsShowing_Impl())
500 nStateSet
|= AccessibleStateType::SHOWING
;
503 SvTreeListEntry
*pEntry
= m_pTreeListBox
->GetEntryFromPath(m_aEntryPath
);
505 m_pTreeListBox
->FillAccessibleEntryStateSet(pEntry
, nStateSet
);
508 nStateSet
|= AccessibleStateType::DEFUNC
;
513 Locale SAL_CALL
AccessibleListBoxEntry::getLocale( )
515 SolarMutexGuard aSolarGuard
;
516 ::osl::MutexGuard
aGuard( m_aMutex
);
518 return implGetLocale();
521 // XAccessibleComponent
523 sal_Bool SAL_CALL
AccessibleListBoxEntry::containsPoint( const awt::Point
& rPoint
)
525 return tools::Rectangle(Point(), GetBoundingBox().GetSize())
526 .Contains(vcl::unohelper::ConvertToVCLPoint(rPoint
));
529 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getAccessibleAtPoint( const awt::Point
& _aPoint
)
531 SolarMutexGuard aSolarGuard
;
532 ::osl::MutexGuard
aGuard( m_aMutex
);
535 SvTreeListEntry
* pEntry
536 = m_pTreeListBox
->GetEntry(vcl::unohelper::ConvertToVCLPoint(_aPoint
));
538 throw RuntimeException(u
"AccessibleListBoxEntry::getAccessibleAtPoint - pEntry cannot be empty!"_ustr
);
540 Reference
< XAccessible
> xAcc
;
541 rtl::Reference
<AccessibleListBox
> xListBox(m_wListBox
);
542 assert(xListBox
.is());
543 auto pAccEntry
= xListBox
->implGetAccessible(*pEntry
);
544 tools::Rectangle aRect
= pAccEntry
->GetBoundingBox_Impl();
545 if (aRect
.Contains(vcl::unohelper::ConvertToVCLPoint(_aPoint
)))
546 xAcc
= pAccEntry
.get();
550 awt::Rectangle SAL_CALL
AccessibleListBoxEntry::getBounds( )
552 return vcl::unohelper::ConvertToAWTRect(GetBoundingBox());
555 awt::Point SAL_CALL
AccessibleListBoxEntry::getLocation( )
557 return vcl::unohelper::ConvertToAWTPoint(GetBoundingBox().TopLeft());
560 awt::Point SAL_CALL
AccessibleListBoxEntry::getLocationOnScreen( )
562 return vcl::unohelper::ConvertToAWTPoint(GetBoundingBoxOnScreen().TopLeft());
565 awt::Size SAL_CALL
AccessibleListBoxEntry::getSize( )
567 return vcl::unohelper::ConvertToAWTSize(GetBoundingBox().GetSize());
570 void SAL_CALL
AccessibleListBoxEntry::grabFocus( )
572 // do nothing, because no focus for each item
575 sal_Int32
AccessibleListBoxEntry::getForeground( )
577 SolarMutexGuard aSolarGuard
;
578 ::osl::MutexGuard
aGuard( m_aMutex
);
580 sal_Int32 nColor
= 0;
581 Reference
< XAccessible
> xParent
= getAccessibleParent();
584 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
585 if ( xParentComp
.is() )
586 nColor
= xParentComp
->getForeground();
592 sal_Int32
AccessibleListBoxEntry::getBackground( )
594 SolarMutexGuard aSolarGuard
;
595 ::osl::MutexGuard
aGuard( m_aMutex
);
597 sal_Int32 nColor
= 0;
598 Reference
< XAccessible
> xParent
= getAccessibleParent();
601 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
602 if ( xParentComp
.is() )
603 nColor
= xParentComp
->getBackground();
612 awt::Rectangle SAL_CALL
AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex
)
614 SolarMutexGuard aSolarGuard
;
615 ::osl::MutexGuard
aGuard( m_aMutex
);
619 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
620 throw IndexOutOfBoundsException();
622 awt::Rectangle
aBounds( 0, 0, 0, 0 );
623 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
626 vcl::ControlLayoutData aLayoutData
;
627 tools::Rectangle aItemRect
= GetBoundingBox();
628 m_pTreeListBox
->RecordLayoutData( &aLayoutData
, aItemRect
);
629 tools::Rectangle aCharRect
= aLayoutData
.GetCharacterBounds( nIndex
);
630 aCharRect
.Move( -aItemRect
.Left(), -aItemRect
.Top() );
631 aBounds
= vcl::unohelper::ConvertToAWTRect(aCharRect
);
637 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getIndexAtPoint( const awt::Point
& aPoint
)
639 SolarMutexGuard aSolarGuard
;
640 ::osl::MutexGuard
aGuard( m_aMutex
);
642 if(aPoint
.X
==0 && aPoint
.Y
==0) return 0;
644 sal_Int32 nIndex
= -1;
645 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
648 vcl::ControlLayoutData aLayoutData
;
649 tools::Rectangle aItemRect
= GetBoundingBox();
650 m_pTreeListBox
->RecordLayoutData( &aLayoutData
, aItemRect
);
651 Point
aPnt(vcl::unohelper::ConvertToVCLPoint(aPoint
));
652 aPnt
+= aItemRect
.TopLeft();
653 nIndex
= aLayoutData
.GetIndexForPoint( aPnt
);
659 sal_Bool SAL_CALL
AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
661 SolarMutexGuard aSolarGuard
;
662 ::osl::MutexGuard
aGuard( m_aMutex
);
665 OUString sText
= implGetText();
666 if ( ( 0 > nStartIndex
) || ( sText
.getLength() <= nStartIndex
)
667 || ( 0 > nEndIndex
) || ( sText
.getLength() <= nEndIndex
) )
668 throw IndexOutOfBoundsException();
673 sal_Int32 nLen
= nEndIndex
- nStartIndex
+ 1;
674 css::uno::Reference
<css::datatransfer::clipboard::XClipboard
> xClipBoard
= m_pTreeListBox
->GetClipboard();
675 vcl::unohelper::TextDataObject::CopyStringTo(sText
.copy(nStartIndex
, nLen
), xClipBoard
);
680 sal_Bool SAL_CALL
AccessibleListBoxEntry::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
685 // XAccessibleEventBroadcaster
687 void SAL_CALL
AccessibleListBoxEntry::addAccessibleEventListener( const Reference
< XAccessibleEventListener
>& xListener
)
691 ::osl::MutexGuard
aGuard( m_aMutex
);
693 m_nClientId
= comphelper::AccessibleEventNotifier::registerClient( );
694 comphelper::AccessibleEventNotifier::addEventListener( m_nClientId
, xListener
);
698 void SAL_CALL
AccessibleListBoxEntry::removeAccessibleEventListener( const Reference
< XAccessibleEventListener
>& xListener
)
703 ::osl::MutexGuard
aGuard( m_aMutex
);
705 sal_Int32 nListenerCount
= comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId
, xListener
);
706 if ( !nListenerCount
)
708 // no listeners anymore
709 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
710 // and at least to us not firing any events anymore, in case somebody calls
711 // NotifyAccessibleEvent, again
712 sal_Int32 nId
= m_nClientId
;
714 comphelper::AccessibleEventNotifier::revokeClient( nId
);
721 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getAccessibleActionCount( )
723 ::osl::MutexGuard
aGuard( m_aMutex
);
725 // three actions supported
726 SvTreeFlags treeFlag
= m_pTreeListBox
->GetTreeFlags();
727 bool bHasButtons
= (m_pTreeListBox
->GetStyle() & WB_HASBUTTONS
)!=0;
728 if( (treeFlag
& SvTreeFlags::CHKBTN
) && !bHasButtons
)
730 sal_Int16 role
= getAccessibleRole();
731 if ( role
== AccessibleRole::CHECK_BOX
)
733 else if ( role
== AccessibleRole::LABEL
)
741 sal_Bool SAL_CALL
AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex
)
743 SolarMutexGuard aSolarGuard
;
744 ::osl::MutexGuard
aGuard( m_aMutex
);
747 CheckActionIndex(nIndex
);
750 SvTreeFlags treeFlag
= m_pTreeListBox
->GetTreeFlags();
751 if( nIndex
== 0 && (treeFlag
& SvTreeFlags::CHKBTN
) )
753 if(getAccessibleRole() == AccessibleRole::CHECK_BOX
)
755 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
756 SvButtonState state
= m_pTreeListBox
->GetCheckButtonState( pEntry
);
757 if ( state
== SvButtonState::Checked
)
758 m_pTreeListBox
->SetCheckButtonState(pEntry
, SvButtonState::Unchecked
);
759 else if (state
== SvButtonState::Unchecked
)
760 m_pTreeListBox
->SetCheckButtonState(pEntry
, SvButtonState::Checked
);
763 else if( (nIndex
== 1 && (treeFlag
& SvTreeFlags::CHKBTN
) ) || (nIndex
== 0) )
765 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
768 if ( m_pTreeListBox
->IsExpanded( pEntry
) )
769 m_pTreeListBox
->Collapse( pEntry
);
771 m_pTreeListBox
->Expand( pEntry
);
779 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex
)
781 SolarMutexGuard aSolarGuard
;
782 ::osl::MutexGuard
aGuard( m_aMutex
);
784 CheckActionIndex(nIndex
);
787 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
788 SvButtonState state
= m_pTreeListBox
->GetCheckButtonState( pEntry
);
789 SvTreeFlags treeFlag
= m_pTreeListBox
->GetTreeFlags();
790 if(nIndex
== 0 && (treeFlag
& SvTreeFlags::CHKBTN
))
792 if(getAccessibleRole() == AccessibleRole::CHECK_BOX
)
794 if ( state
== SvButtonState::Checked
)
795 return u
"UnCheck"_ustr
;
796 else if (state
== SvButtonState::Unchecked
)
797 return u
"Check"_ustr
;
801 //Sometimes, a List or Tree may have both checkbox and label at the same time
805 else if( (nIndex
== 1 && (treeFlag
& SvTreeFlags::CHKBTN
)) || nIndex
== 0 )
807 if( pEntry
&& (pEntry
->HasChildren() || pEntry
->HasChildrenOnDemand()) )
808 return m_pTreeListBox
->IsExpanded( pEntry
) ?
809 AccResId(STR_SVT_ACC_ACTION_COLLAPSE
) :
810 AccResId(STR_SVT_ACC_ACTION_EXPAND
);
814 throw IndexOutOfBoundsException();
817 Reference
< XAccessibleKeyBinding
> AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
819 Reference
< XAccessibleKeyBinding
> xRet
;
820 CheckActionIndex(nIndex
);
825 // XAccessibleSelection
827 void SAL_CALL
AccessibleListBoxEntry::selectAccessibleChild( sal_Int64 nChildIndex
)
829 SolarMutexGuard aSolarGuard
;
830 ::osl::MutexGuard
aGuard( m_aMutex
);
834 if (nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount())
835 throw IndexOutOfBoundsException();
837 SvTreeListEntry
* pEntry
= GetRealChild(nChildIndex
);
839 throw IndexOutOfBoundsException();
841 m_pTreeListBox
->Select( pEntry
);
844 sal_Bool SAL_CALL
AccessibleListBoxEntry::isAccessibleChildSelected( sal_Int64 nChildIndex
)
846 SolarMutexGuard aSolarGuard
;
847 ::osl::MutexGuard
aGuard( m_aMutex
);
851 if (nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount())
852 throw IndexOutOfBoundsException();
854 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
855 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, nChildIndex
);
857 throw IndexOutOfBoundsException();
859 return m_pTreeListBox
->IsSelected( pEntry
);
862 void SAL_CALL
AccessibleListBoxEntry::clearAccessibleSelection( )
864 SolarMutexGuard aSolarGuard
;
865 ::osl::MutexGuard
aGuard( m_aMutex
);
869 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
871 throw RuntimeException(u
"AccessibleListBoxEntry::clearAccessibleSelection - pParent cannot be empty!"_ustr
);
872 sal_Int32 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
873 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
875 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
876 if ( m_pTreeListBox
->IsSelected( pEntry
) )
877 m_pTreeListBox
->Select( pEntry
, false );
881 void SAL_CALL
AccessibleListBoxEntry::selectAllAccessibleChildren( )
883 SolarMutexGuard aSolarGuard
;
884 ::osl::MutexGuard
aGuard( m_aMutex
);
888 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
890 throw RuntimeException(u
"AccessibleListBoxEntry::selectAllAccessibleChildren - pParent cannot be empty!"_ustr
);
891 sal_Int32 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
892 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
894 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
895 if ( !m_pTreeListBox
->IsSelected( pEntry
) )
896 m_pTreeListBox
->Select( pEntry
);
900 sal_Int64 SAL_CALL
AccessibleListBoxEntry::getSelectedAccessibleChildCount( )
902 SolarMutexGuard aSolarGuard
;
903 ::osl::MutexGuard
aGuard( m_aMutex
);
907 sal_Int64 nSelCount
= 0;
909 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
911 throw RuntimeException(u
"AccessibleListBoxEntry::getSelectedAccessibleChildCount - pParent cannot be empty!"_ustr
);
912 sal_Int32 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
913 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
915 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
916 if ( m_pTreeListBox
->IsSelected( pEntry
) )
923 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex
)
925 SolarMutexGuard aSolarGuard
;
926 ::osl::MutexGuard
aGuard( m_aMutex
);
930 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
931 throw IndexOutOfBoundsException();
933 Reference
< XAccessible
> xChild
;
934 sal_Int64 nSelCount
= 0;
936 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
938 throw RuntimeException(u
"AccessibleListBoxEntry::getSelectedAccessibleChild - pParent cannot be empty!"_ustr
);
939 sal_Int32 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
940 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
942 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
943 if ( m_pTreeListBox
->IsSelected( pEntry
) )
946 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
948 rtl::Reference
<AccessibleListBox
> xListBox(m_wListBox
);
949 assert(xListBox
.is());
950 xChild
= xListBox
->implGetAccessible(*pEntry
).get();
958 void SAL_CALL
AccessibleListBoxEntry::deselectAccessibleChild( sal_Int64 nSelectedChildIndex
)
960 SolarMutexGuard aSolarGuard
;
961 ::osl::MutexGuard
aGuard( m_aMutex
);
965 if (nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getAccessibleChildCount())
966 throw IndexOutOfBoundsException();
968 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
969 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, nSelectedChildIndex
);
971 throw IndexOutOfBoundsException();
973 m_pTreeListBox
->Select( pEntry
, false );
975 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getCaretPosition( )
979 sal_Bool SAL_CALL
AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex
)
981 SolarMutexGuard aSolarGuard
;
982 ::osl::MutexGuard
aGuard( m_aMutex
);
985 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
986 throw IndexOutOfBoundsException();
990 sal_Unicode SAL_CALL
AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex
)
992 SolarMutexGuard aSolarGuard
;
993 ::osl::MutexGuard
aGuard( m_aMutex
);
995 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex
);
997 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
AccessibleListBoxEntry::getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& )
999 SolarMutexGuard aSolarGuard
;
1000 ::osl::MutexGuard
aGuard( m_aMutex
);
1003 OUString
sText( implGetText() );
1005 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
1006 throw IndexOutOfBoundsException();
1008 return css::uno::Sequence
< css::beans::PropertyValue
>();
1010 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getCharacterCount( )
1012 SolarMutexGuard aSolarGuard
;
1013 ::osl::MutexGuard
aGuard( m_aMutex
);
1015 return implGetText().getLength();
1018 OUString SAL_CALL
AccessibleListBoxEntry::getSelectedText( )
1020 SolarMutexGuard aSolarGuard
;
1021 ::osl::MutexGuard
aGuard( m_aMutex
);
1025 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getSelectionStart( )
1027 SolarMutexGuard aSolarGuard
;
1028 ::osl::MutexGuard
aGuard( m_aMutex
);
1032 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getSelectionEnd( )
1034 SolarMutexGuard aSolarGuard
;
1035 ::osl::MutexGuard
aGuard( m_aMutex
);
1039 sal_Bool SAL_CALL
AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
1041 SolarMutexGuard aSolarGuard
;
1042 ::osl::MutexGuard
aGuard( m_aMutex
);
1045 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
1046 throw IndexOutOfBoundsException();
1050 OUString SAL_CALL
AccessibleListBoxEntry::getText( )
1052 SolarMutexGuard aSolarGuard
;
1053 ::osl::MutexGuard
aGuard( m_aMutex
);
1055 return implGetText( );
1057 OUString SAL_CALL
AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
1059 SolarMutexGuard aSolarGuard
;
1060 ::osl::MutexGuard
aGuard( m_aMutex
);
1062 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
1064 css::accessibility::TextSegment SAL_CALL
AccessibleListBoxEntry::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
1066 SolarMutexGuard aSolarGuard
;
1067 ::osl::MutexGuard
aGuard( m_aMutex
);
1069 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
1071 css::accessibility::TextSegment SAL_CALL
AccessibleListBoxEntry::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
1073 SolarMutexGuard aSolarGuard
;
1074 ::osl::MutexGuard
aGuard( m_aMutex
);
1076 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
1078 css::accessibility::TextSegment SAL_CALL
AccessibleListBoxEntry::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
1080 SolarMutexGuard aSolarGuard
;
1081 ::osl::MutexGuard
aGuard( m_aMutex
);
1084 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
1090 Any
AccessibleListBoxEntry::getCurrentValue( )
1092 ::osl::MutexGuard
aGuard( m_aMutex
);
1094 sal_Int32 level
= static_cast<sal_Int32
>(m_aEntryPath
.size()) - 1;
1095 level
= level
< 0 ? 0: level
;
1101 sal_Bool
AccessibleListBoxEntry::setCurrentValue( const Any
& aNumber
)
1103 ::osl::MutexGuard
aGuard( m_aMutex
);
1106 bool bReturn
= false;
1107 SvTreeListBox
* pBox
= m_pTreeListBox
;
1108 if(getAccessibleRole() == AccessibleRole::CHECK_BOX
)
1110 SvTreeListEntry
* pEntry
= pBox
->GetEntryFromPath( m_aEntryPath
);
1113 sal_Int32
nValue(0), nValueMin(0), nValueMax(0);
1115 getMinimumValue() >>= nValueMin
;
1116 getMaximumValue() >>= nValueMax
;
1118 if ( nValue
< nValueMin
)
1120 else if ( nValue
> nValueMax
)
1123 pBox
->SetCheckButtonState(pEntry
, static_cast<SvButtonState
>(nValue
) );
1132 Any
AccessibleListBoxEntry::getMaximumValue( )
1134 ::osl::MutexGuard
aGuard( m_aMutex
);
1137 // SvTreeListBox* pBox = m_pTreeListBox;
1138 switch(getAccessibleRole())
1140 case AccessibleRole::CHECK_BOX
:
1141 aValue
<<= sal_Int32(1);
1143 case AccessibleRole::LABEL
:
1152 Any
AccessibleListBoxEntry::getMinimumValue( )
1154 ::osl::MutexGuard
aGuard( m_aMutex
);
1157 // SvTreeListBox* pBox = m_pTreeListBox;
1158 switch(getAccessibleRole())
1160 case AccessibleRole::CHECK_BOX
:
1161 aValue
<<= sal_Int32(0);
1163 case AccessibleRole::LABEL
:
1171 Any
AccessibleListBoxEntry::getMinimumIncrement( )
1173 ::osl::MutexGuard
aGuard( m_aMutex
);
1176 switch(getAccessibleRole())
1178 case AccessibleRole::CHECK_BOX
:
1179 aValue
<<= sal_Int32(1);
1181 case AccessibleRole::LABEL
:
1189 SvTreeListEntry
* AccessibleListBoxEntry::GetRealChild(sal_Int32 nIndex
)
1191 SvTreeListEntry
* pEntry
= nullptr;
1192 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
1195 pEntry
= m_pTreeListBox
->GetEntry( pParent
, nIndex
);
1196 if ( !pEntry
&& getAccessibleChildCount() > 0 )
1198 m_pTreeListBox
->RequestingChildren(pParent
);
1199 pEntry
= m_pTreeListBox
->GetEntry( pParent
, nIndex
);
1205 }// namespace accessibility
1208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */