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 <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/accessiblestatesethelper.hxx>
35 #include <unotools/accessiblerelationsethelper.hxx>
36 #include <cppuhelper/supportsservice.hxx>
37 #include <comphelper/accessibleeventnotifier.hxx>
38 #include <helper/accresmgr.hxx>
39 #include <strings.hrc>
41 #define ACCESSIBLE_ACTION_COUNT 1
45 /// @throws css::lang::IndexOutOfBoundsException
46 void checkActionIndex_Impl( sal_Int32 _nIndex
)
48 if ( _nIndex
< 0 || _nIndex
>= ACCESSIBLE_ACTION_COUNT
)
50 throw css::lang::IndexOutOfBoundsException();
55 namespace accessibility
57 // class AccessibleListBoxEntry -----------------------------------------------------
59 using namespace ::com::sun::star::accessibility
;
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star
;
63 using namespace ::comphelper
;
68 AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox
& _rListBox
,
69 SvTreeListEntry
& rEntry
,
70 AccessibleListBox
& rListBox
)
71 : AccessibleListBoxEntry_BASE( m_aMutex
)
73 , m_pTreeListBox( &_rListBox
)
74 , m_pSvLBoxEntry(&rEntry
)
76 , m_wListBox(&rListBox
)
77 , m_rListBox(rListBox
)
79 m_pTreeListBox
->AddEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
80 _rListBox
.FillEntryPath( m_pSvLBoxEntry
, m_aEntryPath
);
83 AccessibleListBoxEntry::~AccessibleListBoxEntry()
87 // increment ref count to prevent double call of Dtor
88 osl_atomic_increment( &m_refCount
);
93 IMPL_LINK( AccessibleListBoxEntry
, WindowEventListener
, VclWindowEvent
&, rEvent
, void )
95 OSL_ENSURE( rEvent
.GetWindow() , "AccessibleListBoxEntry::WindowEventListener: no event window!" );
96 OSL_ENSURE( rEvent
.GetWindow() == m_pTreeListBox
, "AccessibleListBoxEntry::WindowEventListener: where did this come from?" );
98 if ( m_pTreeListBox
== nullptr )
101 switch ( rEvent
.GetId() )
103 case VclEventId::ObjectDying
:
105 if ( m_pTreeListBox
)
106 m_pTreeListBox
->RemoveEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
107 m_pTreeListBox
= nullptr;
115 void AccessibleListBoxEntry::NotifyAccessibleEvent( sal_Int16 _nEventId
,
116 const css::uno::Any
& _aOldValue
,
117 const css::uno::Any
& _aNewValue
)
119 Reference
< uno::XInterface
> xSource( *this );
120 AccessibleEventObject
aEventObj( xSource
, _nEventId
, _aNewValue
, _aOldValue
);
123 comphelper::AccessibleEventNotifier::addEvent( m_nClientId
, aEventObj
);
127 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBox_Impl() const
129 tools::Rectangle aRect
;
130 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
133 aRect
= m_pTreeListBox
->GetBoundingRect( pEntry
);
134 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetParent( pEntry
);
137 // position relative to parent entry
138 Point aTopLeft
= aRect
.TopLeft();
139 aTopLeft
-= m_pTreeListBox
->GetBoundingRect( pParent
).TopLeft();
140 aRect
= tools::Rectangle( aTopLeft
, aRect
.GetSize() );
147 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
149 tools::Rectangle aRect
;
150 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
153 aRect
= m_pTreeListBox
->GetBoundingRect( pEntry
);
154 Point aTopLeft
= aRect
.TopLeft();
155 aTopLeft
+= m_pTreeListBox
->GetWindowExtentsRelative( nullptr ).TopLeft();
156 aRect
= tools::Rectangle( aTopLeft
, aRect
.GetSize() );
162 bool AccessibleListBoxEntry::IsAlive_Impl() const
164 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
&& (m_pTreeListBox
!= nullptr);
167 bool AccessibleListBoxEntry::IsShowing_Impl() const
169 Reference
< XAccessible
> xParent
= implGetParentAccessible( );
171 bool bShowing
= false;
172 Reference
< XAccessibleContext
> xParentContext
=
173 xParent
.is() ? xParent
->getAccessibleContext() : Reference
< XAccessibleContext
>();
174 if( xParentContext
.is() )
176 Reference
< XAccessibleComponent
> xParentComp( xParentContext
, uno::UNO_QUERY
);
177 if( xParentComp
.is() )
178 bShowing
= GetBoundingBox_Impl().Overlaps( VCLRectangle( xParentComp
->getBounds() ) );
184 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBox()
186 SolarMutexGuard aSolarGuard
;
187 ::osl::MutexGuard
aGuard( m_aMutex
);
190 return GetBoundingBox_Impl();
193 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBoxOnScreen()
195 SolarMutexGuard aSolarGuard
;
196 ::osl::MutexGuard
aGuard( m_aMutex
);
199 return GetBoundingBoxOnScreen_Impl();
202 void AccessibleListBoxEntry::EnsureIsAlive() const
204 if ( !IsAlive_Impl() )
205 throw lang::DisposedException();
208 OUString
AccessibleListBoxEntry::implGetText()
211 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
213 sRet
= SvTreeListBox::SearchEntryTextWithHeadTitle( pEntry
);
217 Locale
AccessibleListBoxEntry::implGetLocale()
219 return Application::GetSettings().GetUILanguageTag().getLocale();
221 void AccessibleListBoxEntry::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
230 Sequence
< sal_Int8
> AccessibleListBoxEntry::getImplementationId()
232 return css::uno::Sequence
<sal_Int8
>();
238 void SAL_CALL
AccessibleListBoxEntry::disposing()
240 SolarMutexGuard aSolarGuard
;
241 ::osl::MutexGuard
aGuard( m_aMutex
);
243 Reference
< XAccessible
> xKeepAlive( this );
245 // Send a disposing to all listeners.
248 ::comphelper::AccessibleEventNotifier::TClientId nId
= m_nClientId
;
250 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId
, *this );
256 if ( m_pTreeListBox
)
257 m_pTreeListBox
->RemoveEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
258 m_pTreeListBox
= nullptr;
263 OUString SAL_CALL
AccessibleListBoxEntry::getImplementationName()
265 return "com.sun.star.comp.svtools.AccessibleTreeListBoxEntry";
268 Sequence
< OUString
> SAL_CALL
AccessibleListBoxEntry::getSupportedServiceNames()
270 return {"com.sun.star.accessibility.AccessibleContext",
271 "com.sun.star.accessibility.AccessibleComponent",
272 "com.sun.star.awt.AccessibleTreeListBoxEntry"};
275 sal_Bool SAL_CALL
AccessibleListBoxEntry::supportsService( const OUString
& _rServiceName
)
277 return cppu::supportsService(this, _rServiceName
);
282 Reference
< XAccessibleContext
> SAL_CALL
AccessibleListBoxEntry::getAccessibleContext( )
288 // XAccessibleContext
290 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getAccessibleChildCount( )
292 SolarMutexGuard aSolarGuard
;
293 ::osl::MutexGuard
aGuard( m_aMutex
);
296 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
297 sal_Int32 nCount
= 0;
299 nCount
= m_pTreeListBox
->GetLevelChildCount( pEntry
);
304 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getAccessibleChild( sal_Int32 i
)
306 SolarMutexGuard aSolarGuard
;
307 ::osl::MutexGuard
aGuard( m_aMutex
);
310 SvTreeListEntry
* pEntry
= GetRealChild(i
);
312 throw IndexOutOfBoundsException();
314 uno::Reference
<XAccessible
> xListBox(m_wListBox
);
315 assert(xListBox
.is());
317 return m_rListBox
.implGetAccessible(*pEntry
);
320 Reference
< XAccessible
> AccessibleListBoxEntry::implGetParentAccessible( ) const
322 Reference
< XAccessible
> xParent
;
325 OSL_ENSURE( m_aEntryPath
.size(), "AccessibleListBoxEntry::getAccessibleParent: invalid path!" );
326 if ( m_aEntryPath
.size() == 1 )
327 { // we're a top level entry
328 // -> our parent is the tree listbox itself
329 if ( m_pTreeListBox
)
330 xParent
= m_pTreeListBox
->GetAccessible( );
333 { // we have an entry as parent -> get its accessible
335 // shorten our access path by one
336 std::deque
< sal_Int32
> aParentPath( m_aEntryPath
);
337 aParentPath
.pop_back();
339 // get the entry for this shortened access path
340 SvTreeListEntry
* pParentEntry
= m_pTreeListBox
->GetEntryFromPath( aParentPath
);
341 OSL_ENSURE( pParentEntry
, "AccessibleListBoxEntry::implGetParentAccessible: could not obtain a parent entry!" );
344 pParentEntry
= m_pTreeListBox
->GetParent(pParentEntry
);
347 uno::Reference
<XAccessible
> xListBox(m_wListBox
);
348 assert(xListBox
.is());
349 return m_rListBox
.implGetAccessible(*pParentEntry
);
350 // 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_Int32 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
;
414 SvTreeFlags treeFlag
= pBox
->GetTreeFlags();
415 if(treeFlag
& SvTreeFlags::CHKBTN
)
417 SvTreeListEntry
* pEntry
= pBox
->GetEntryFromPath( m_aEntryPath
);
418 SvButtonState eState
= pBox
->GetCheckButtonState( pEntry
);
421 case SvButtonState::Checked
:
422 case SvButtonState::Unchecked
:
423 return AccessibleRole::CHECK_BOX
;
424 case SvButtonState::Tristate
:
426 return AccessibleRole::LABEL
;
429 if (GetRoleType() == 0)
430 return AccessibleRole::LIST_ITEM
;
432 //o is: return AccessibleRole::LABEL;
433 return AccessibleRole::TREE_ITEM
;
435 return AccessibleRole::UNKNOWN
;
438 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleDescription( )
440 SolarMutexGuard aSolarGuard
;
441 ::osl::MutexGuard
aGuard( m_aMutex
);
443 if( getAccessibleRole() == AccessibleRole::TREE_ITEM
)
447 return m_pTreeListBox
->GetEntryAccessibleDescription(
448 m_pTreeListBox
->GetEntryFromPath(m_aEntryPath
));
451 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleName( )
453 ::osl::MutexGuard
aGuard( m_aMutex
);
457 return implGetText();
460 Reference
< XAccessibleRelationSet
> SAL_CALL
AccessibleListBoxEntry::getAccessibleRelationSet( )
462 Reference
< XAccessibleRelationSet
> xRelSet
;
463 Reference
< XAccessible
> xParent
;
464 if ( m_aEntryPath
.size() > 1 ) // not a root entry
465 xParent
= implGetParentAccessible();
468 rtl::Reference
<utl::AccessibleRelationSetHelper
> pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
469 Sequence
< Reference
< XInterface
> > aSequence
{ xParent
};
470 pRelationSetHelper
->AddRelation(
471 AccessibleRelation( AccessibleRelationType::NODE_CHILD_OF
, aSequence
) );
472 xRelSet
= pRelationSetHelper
;
477 Reference
< XAccessibleStateSet
> SAL_CALL
AccessibleListBoxEntry::getAccessibleStateSet( )
479 ::osl::MutexGuard
aGuard( m_aMutex
);
481 rtl::Reference
<utl::AccessibleStateSetHelper
> pStateSetHelper
= new utl::AccessibleStateSetHelper
;
483 if ( IsAlive_Impl() )
485 switch(getAccessibleRole())
487 case AccessibleRole::LABEL
:
488 pStateSetHelper
->AddState( AccessibleStateType::TRANSIENT
);
489 pStateSetHelper
->AddState( AccessibleStateType::SELECTABLE
);
490 pStateSetHelper
->AddState( AccessibleStateType::ENABLED
);
491 if (m_pTreeListBox
->IsInplaceEditingEnabled())
492 pStateSetHelper
->AddState( AccessibleStateType::EDITABLE
);
493 if (IsShowing_Impl())
494 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
496 case AccessibleRole::CHECK_BOX
:
497 pStateSetHelper
->AddState( AccessibleStateType::TRANSIENT
);
498 pStateSetHelper
->AddState( AccessibleStateType::SELECTABLE
);
499 pStateSetHelper
->AddState( AccessibleStateType::ENABLED
);
500 if (IsShowing_Impl())
501 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
504 SvTreeListEntry
*pEntry
= m_pTreeListBox
->GetEntryFromPath(m_aEntryPath
);
506 m_pTreeListBox
->FillAccessibleEntryStateSet(pEntry
, *pStateSetHelper
);
509 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
511 return pStateSetHelper
;
514 Locale SAL_CALL
AccessibleListBoxEntry::getLocale( )
516 SolarMutexGuard aSolarGuard
;
517 ::osl::MutexGuard
aGuard( m_aMutex
);
519 return implGetLocale();
522 // XAccessibleComponent
524 sal_Bool SAL_CALL
AccessibleListBoxEntry::containsPoint( const awt::Point
& rPoint
)
526 return tools::Rectangle( Point(), GetBoundingBox().GetSize() ).Contains( VCLPoint( rPoint
) );
529 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getAccessibleAtPoint( const awt::Point
& _aPoint
)
531 SolarMutexGuard aSolarGuard
;
532 ::osl::MutexGuard
aGuard( m_aMutex
);
535 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( VCLPoint( _aPoint
) );
537 throw RuntimeException();
539 Reference
< XAccessible
> xAcc
;
540 uno::Reference
<XAccessible
> xListBox(m_wListBox
);
541 assert(xListBox
.is());
542 auto pAccEntry
= m_rListBox
.implGetAccessible(*pEntry
);
543 tools::Rectangle aRect
= pAccEntry
->GetBoundingBox_Impl();
544 if ( aRect
.Contains( VCLPoint( _aPoint
) ) )
545 xAcc
= pAccEntry
.get();
549 awt::Rectangle SAL_CALL
AccessibleListBoxEntry::getBounds( )
551 return AWTRectangle( GetBoundingBox() );
554 awt::Point SAL_CALL
AccessibleListBoxEntry::getLocation( )
556 return AWTPoint( GetBoundingBox().TopLeft() );
559 awt::Point SAL_CALL
AccessibleListBoxEntry::getLocationOnScreen( )
561 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
564 awt::Size SAL_CALL
AccessibleListBoxEntry::getSize( )
566 return AWTSize( GetBoundingBox().GetSize() );
569 void SAL_CALL
AccessibleListBoxEntry::grabFocus( )
571 // do nothing, because no focus for each item
574 sal_Int32
AccessibleListBoxEntry::getForeground( )
576 SolarMutexGuard aSolarGuard
;
577 ::osl::MutexGuard
aGuard( m_aMutex
);
579 sal_Int32 nColor
= 0;
580 Reference
< XAccessible
> xParent
= getAccessibleParent();
583 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
584 if ( xParentComp
.is() )
585 nColor
= xParentComp
->getForeground();
591 sal_Int32
AccessibleListBoxEntry::getBackground( )
593 SolarMutexGuard aSolarGuard
;
594 ::osl::MutexGuard
aGuard( m_aMutex
);
596 sal_Int32 nColor
= 0;
597 Reference
< XAccessible
> xParent
= getAccessibleParent();
600 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
601 if ( xParentComp
.is() )
602 nColor
= xParentComp
->getBackground();
611 awt::Rectangle SAL_CALL
AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex
)
613 SolarMutexGuard aSolarGuard
;
614 ::osl::MutexGuard
aGuard( m_aMutex
);
618 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
619 throw IndexOutOfBoundsException();
621 awt::Rectangle
aBounds( 0, 0, 0, 0 );
622 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
625 vcl::ControlLayoutData aLayoutData
;
626 tools::Rectangle aItemRect
= GetBoundingBox();
627 m_pTreeListBox
->RecordLayoutData( &aLayoutData
, aItemRect
);
628 tools::Rectangle aCharRect
= aLayoutData
.GetCharacterBounds( nIndex
);
629 aCharRect
.Move( -aItemRect
.Left(), -aItemRect
.Top() );
630 aBounds
= AWTRectangle( aCharRect
);
636 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getIndexAtPoint( const awt::Point
& aPoint
)
638 SolarMutexGuard aSolarGuard
;
639 ::osl::MutexGuard
aGuard( m_aMutex
);
641 if(aPoint
.X
==0 && aPoint
.Y
==0) return 0;
643 sal_Int32 nIndex
= -1;
644 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
647 vcl::ControlLayoutData aLayoutData
;
648 tools::Rectangle aItemRect
= GetBoundingBox();
649 m_pTreeListBox
->RecordLayoutData( &aLayoutData
, aItemRect
);
650 Point
aPnt( VCLPoint( aPoint
) );
651 aPnt
+= aItemRect
.TopLeft();
652 nIndex
= aLayoutData
.GetIndexForPoint( aPnt
);
658 sal_Bool SAL_CALL
AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
660 SolarMutexGuard aSolarGuard
;
661 ::osl::MutexGuard
aGuard( m_aMutex
);
664 OUString sText
= implGetText();
665 if ( ( 0 > nStartIndex
) || ( sText
.getLength() <= nStartIndex
)
666 || ( 0 > nEndIndex
) || ( sText
.getLength() <= nEndIndex
) )
667 throw IndexOutOfBoundsException();
669 sal_Int32 nLen
= nEndIndex
- nStartIndex
+ 1;
670 ::svt::OStringTransfer::CopyString( sText
.copy( nStartIndex
, nLen
), m_pTreeListBox
);
675 sal_Bool SAL_CALL
AccessibleListBoxEntry::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
680 // XAccessibleEventBroadcaster
682 void SAL_CALL
AccessibleListBoxEntry::addAccessibleEventListener( const Reference
< XAccessibleEventListener
>& xListener
)
686 ::osl::MutexGuard
aGuard( m_aMutex
);
688 m_nClientId
= comphelper::AccessibleEventNotifier::registerClient( );
689 comphelper::AccessibleEventNotifier::addEventListener( m_nClientId
, xListener
);
693 void SAL_CALL
AccessibleListBoxEntry::removeAccessibleEventListener( const Reference
< XAccessibleEventListener
>& xListener
)
698 ::osl::MutexGuard
aGuard( m_aMutex
);
700 sal_Int32 nListenerCount
= comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId
, xListener
);
701 if ( !nListenerCount
)
703 // no listeners anymore
704 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
705 // and at least to us not firing any events anymore, in case somebody calls
706 // NotifyAccessibleEvent, again
707 sal_Int32 nId
= m_nClientId
;
709 comphelper::AccessibleEventNotifier::revokeClient( nId
);
716 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getAccessibleActionCount( )
718 ::osl::MutexGuard
aGuard( m_aMutex
);
720 // three actions supported
721 SvTreeFlags treeFlag
= m_pTreeListBox
->GetTreeFlags();
722 bool bHasButtons
= (m_pTreeListBox
->GetStyle() & WB_HASBUTTONS
)!=0;
723 if( (treeFlag
& SvTreeFlags::CHKBTN
) && !bHasButtons
)
725 sal_Int16 role
= getAccessibleRole();
726 if ( role
== AccessibleRole::CHECK_BOX
)
728 else if ( role
== AccessibleRole::LABEL
)
732 return ACCESSIBLE_ACTION_COUNT
;
736 sal_Bool SAL_CALL
AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex
)
738 SolarMutexGuard aSolarGuard
;
739 ::osl::MutexGuard
aGuard( m_aMutex
);
742 checkActionIndex_Impl( nIndex
);
745 SvTreeFlags treeFlag
= m_pTreeListBox
->GetTreeFlags();
746 if( nIndex
== 0 && (treeFlag
& SvTreeFlags::CHKBTN
) )
748 if(getAccessibleRole() == AccessibleRole::CHECK_BOX
)
750 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
751 SvButtonState state
= m_pTreeListBox
->GetCheckButtonState( pEntry
);
752 if ( state
== SvButtonState::Checked
)
753 m_pTreeListBox
->SetCheckButtonState(pEntry
, SvButtonState::Unchecked
);
754 else if (state
== SvButtonState::Unchecked
)
755 m_pTreeListBox
->SetCheckButtonState(pEntry
, SvButtonState::Checked
);
758 else if( (nIndex
== 1 && (treeFlag
& SvTreeFlags::CHKBTN
) ) || (nIndex
== 0) )
760 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
763 if ( m_pTreeListBox
->IsExpanded( pEntry
) )
764 m_pTreeListBox
->Collapse( pEntry
);
766 m_pTreeListBox
->Expand( pEntry
);
774 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex
)
776 SolarMutexGuard aSolarGuard
;
777 ::osl::MutexGuard
aGuard( m_aMutex
);
779 checkActionIndex_Impl( nIndex
);
782 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
783 SvButtonState state
= m_pTreeListBox
->GetCheckButtonState( pEntry
);
784 SvTreeFlags treeFlag
= m_pTreeListBox
->GetTreeFlags();
785 if(nIndex
== 0 && (treeFlag
& SvTreeFlags::CHKBTN
))
787 if(getAccessibleRole() == AccessibleRole::CHECK_BOX
)
789 if ( state
== SvButtonState::Checked
)
791 else if (state
== SvButtonState::Unchecked
)
796 //Sometimes, a List or Tree may have both checkbox and label at the same time
799 }else if( (nIndex
== 1 && (treeFlag
& SvTreeFlags::CHKBTN
)) || nIndex
== 0 )
801 if( pEntry
->HasChildren() || pEntry
->HasChildrenOnDemand() )
802 return m_pTreeListBox
->IsExpanded( pEntry
) ?
803 AccResId(STR_SVT_ACC_ACTION_COLLAPSE
) :
804 AccResId(STR_SVT_ACC_ACTION_EXPAND
);
808 throw IndexOutOfBoundsException();
811 Reference
< XAccessibleKeyBinding
> AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
813 ::osl::MutexGuard
aGuard( m_aMutex
);
815 Reference
< XAccessibleKeyBinding
> xRet
;
816 checkActionIndex_Impl( nIndex
);
821 // XAccessibleSelection
823 void SAL_CALL
AccessibleListBoxEntry::selectAccessibleChild( sal_Int32 nChildIndex
)
825 SolarMutexGuard aSolarGuard
;
826 ::osl::MutexGuard
aGuard( m_aMutex
);
830 SvTreeListEntry
* pEntry
= GetRealChild(nChildIndex
);
832 throw IndexOutOfBoundsException();
834 m_pTreeListBox
->Select( pEntry
);
837 sal_Bool SAL_CALL
AccessibleListBoxEntry::isAccessibleChildSelected( sal_Int32 nChildIndex
)
839 SolarMutexGuard aSolarGuard
;
840 ::osl::MutexGuard
aGuard( m_aMutex
);
844 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
845 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, nChildIndex
);
847 throw IndexOutOfBoundsException();
849 return m_pTreeListBox
->IsSelected( pEntry
);
852 void SAL_CALL
AccessibleListBoxEntry::clearAccessibleSelection( )
854 SolarMutexGuard aSolarGuard
;
855 ::osl::MutexGuard
aGuard( m_aMutex
);
859 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
861 throw RuntimeException();
862 sal_Int32 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
863 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
865 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
866 if ( m_pTreeListBox
->IsSelected( pEntry
) )
867 m_pTreeListBox
->Select( pEntry
, false );
871 void SAL_CALL
AccessibleListBoxEntry::selectAllAccessibleChildren( )
873 SolarMutexGuard aSolarGuard
;
874 ::osl::MutexGuard
aGuard( m_aMutex
);
878 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
880 throw RuntimeException();
881 sal_Int32 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
882 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
884 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
885 if ( !m_pTreeListBox
->IsSelected( pEntry
) )
886 m_pTreeListBox
->Select( pEntry
);
890 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getSelectedAccessibleChildCount( )
892 SolarMutexGuard aSolarGuard
;
893 ::osl::MutexGuard
aGuard( m_aMutex
);
897 sal_Int32 i
, nSelCount
= 0, nCount
= 0;
899 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
901 throw RuntimeException();
902 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
903 for ( i
= 0; i
< nCount
; ++i
)
905 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
906 if ( m_pTreeListBox
->IsSelected( pEntry
) )
913 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
915 SolarMutexGuard aSolarGuard
;
916 ::osl::MutexGuard
aGuard( m_aMutex
);
920 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
921 throw IndexOutOfBoundsException();
923 Reference
< XAccessible
> xChild
;
924 sal_Int32 i
, nSelCount
= 0, nCount
= 0;
926 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
928 throw RuntimeException();
929 nCount
= m_pTreeListBox
->GetLevelChildCount( pParent
);
930 for ( i
= 0; i
< nCount
; ++i
)
932 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, i
);
933 if ( m_pTreeListBox
->IsSelected( pEntry
) )
936 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
938 uno::Reference
<XAccessible
> xListBox(m_wListBox
);
939 assert(xListBox
.is());
940 xChild
= m_rListBox
.implGetAccessible(*pEntry
).get();
948 void SAL_CALL
AccessibleListBoxEntry::deselectAccessibleChild( sal_Int32 nSelectedChildIndex
)
950 SolarMutexGuard aSolarGuard
;
951 ::osl::MutexGuard
aGuard( m_aMutex
);
955 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
956 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( pParent
, nSelectedChildIndex
);
958 throw IndexOutOfBoundsException();
960 m_pTreeListBox
->Select( pEntry
, false );
962 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getCaretPosition( )
966 sal_Bool SAL_CALL
AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex
)
968 SolarMutexGuard aSolarGuard
;
969 ::osl::MutexGuard
aGuard( m_aMutex
);
972 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
973 throw IndexOutOfBoundsException();
977 sal_Unicode SAL_CALL
AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex
)
979 SolarMutexGuard aSolarGuard
;
980 ::osl::MutexGuard
aGuard( m_aMutex
);
982 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex
);
984 css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
AccessibleListBoxEntry::getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& )
986 SolarMutexGuard aSolarGuard
;
987 ::osl::MutexGuard
aGuard( m_aMutex
);
990 OUString
sText( implGetText() );
992 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
993 throw IndexOutOfBoundsException();
995 return css::uno::Sequence
< css::beans::PropertyValue
>();
997 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getCharacterCount( )
999 SolarMutexGuard aSolarGuard
;
1000 ::osl::MutexGuard
aGuard( m_aMutex
);
1002 return implGetText().getLength();
1005 OUString SAL_CALL
AccessibleListBoxEntry::getSelectedText( )
1007 SolarMutexGuard aSolarGuard
;
1008 ::osl::MutexGuard
aGuard( m_aMutex
);
1012 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getSelectionStart( )
1014 SolarMutexGuard aSolarGuard
;
1015 ::osl::MutexGuard
aGuard( m_aMutex
);
1019 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getSelectionEnd( )
1021 SolarMutexGuard aSolarGuard
;
1022 ::osl::MutexGuard
aGuard( m_aMutex
);
1026 sal_Bool SAL_CALL
AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
1028 SolarMutexGuard aSolarGuard
;
1029 ::osl::MutexGuard
aGuard( m_aMutex
);
1032 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
1033 throw IndexOutOfBoundsException();
1037 OUString SAL_CALL
AccessibleListBoxEntry::getText( )
1039 SolarMutexGuard aSolarGuard
;
1040 ::osl::MutexGuard
aGuard( m_aMutex
);
1042 return implGetText( );
1044 OUString SAL_CALL
AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
1046 SolarMutexGuard aSolarGuard
;
1047 ::osl::MutexGuard
aGuard( m_aMutex
);
1049 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex
, nEndIndex
);
1051 css::accessibility::TextSegment SAL_CALL
AccessibleListBoxEntry::getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
1053 SolarMutexGuard aSolarGuard
;
1054 ::osl::MutexGuard
aGuard( m_aMutex
);
1056 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
1058 css::accessibility::TextSegment SAL_CALL
AccessibleListBoxEntry::getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
1060 SolarMutexGuard aSolarGuard
;
1061 ::osl::MutexGuard
aGuard( m_aMutex
);
1063 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
1065 css::accessibility::TextSegment SAL_CALL
AccessibleListBoxEntry::getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
)
1067 SolarMutexGuard aSolarGuard
;
1068 ::osl::MutexGuard
aGuard( m_aMutex
);
1071 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
1077 Any
AccessibleListBoxEntry::getCurrentValue( )
1079 ::osl::MutexGuard
aGuard( m_aMutex
);
1081 sal_Int32 level
= static_cast<sal_Int32
>(m_aEntryPath
.size()) - 1;
1082 level
= level
< 0 ? 0: level
;
1088 sal_Bool
AccessibleListBoxEntry::setCurrentValue( const Any
& aNumber
)
1090 ::osl::MutexGuard
aGuard( m_aMutex
);
1093 bool bReturn
= false;
1094 SvTreeListBox
* pBox
= m_pTreeListBox
;
1095 if(getAccessibleRole() == AccessibleRole::CHECK_BOX
)
1097 SvTreeListEntry
* pEntry
= pBox
->GetEntryFromPath( m_aEntryPath
);
1100 sal_Int32
nValue(0), nValueMin(0), nValueMax(0);
1102 getMinimumValue() >>= nValueMin
;
1103 getMaximumValue() >>= nValueMax
;
1105 if ( nValue
< nValueMin
)
1107 else if ( nValue
> nValueMax
)
1110 pBox
->SetCheckButtonState(pEntry
, static_cast<SvButtonState
>(nValue
) );
1119 Any
AccessibleListBoxEntry::getMaximumValue( )
1121 ::osl::MutexGuard
aGuard( m_aMutex
);
1124 // SvTreeListBox* pBox = m_pTreeListBox;
1125 switch(getAccessibleRole())
1127 case AccessibleRole::CHECK_BOX
:
1128 aValue
<<= sal_Int32(1);
1130 case AccessibleRole::LABEL
:
1139 Any
AccessibleListBoxEntry::getMinimumValue( )
1141 ::osl::MutexGuard
aGuard( m_aMutex
);
1144 // SvTreeListBox* pBox = m_pTreeListBox;
1145 switch(getAccessibleRole())
1147 case AccessibleRole::CHECK_BOX
:
1148 aValue
<<= sal_Int32(0);
1150 case AccessibleRole::LABEL
:
1158 Any
AccessibleListBoxEntry::getMinimumIncrement( )
1160 ::osl::MutexGuard
aGuard( m_aMutex
);
1163 switch(getAccessibleRole())
1165 case AccessibleRole::CHECK_BOX
:
1166 aValue
<<= sal_Int32(1);
1168 case AccessibleRole::LABEL
:
1176 SvTreeListEntry
* AccessibleListBoxEntry::GetRealChild(sal_Int32 nIndex
)
1178 SvTreeListEntry
* pEntry
= nullptr;
1179 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
1182 pEntry
= m_pTreeListBox
->GetEntry( pParent
, nIndex
);
1183 if ( !pEntry
&& getAccessibleChildCount() > 0 )
1185 m_pTreeListBox
->RequestingChildren(pParent
);
1186 pEntry
= m_pTreeListBox
->GetEntry( pParent
, nIndex
);
1192 }// namespace accessibility
1195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */