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/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
44 /// @throws css::lang::IndexOutOfBoundsException
45 void checkActionIndex_Impl( sal_Int32 _nIndex
)
47 if ( _nIndex
< 0 || _nIndex
>= ACCESSIBLE_ACTION_COUNT
)
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
;
67 AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox
& _rListBox
,
68 SvTreeListEntry
& rEntry
,
69 AccessibleListBox
& rListBox
)
70 : AccessibleListBoxEntry_BASE( m_aMutex
)
72 , m_pTreeListBox( &_rListBox
)
73 , m_pSvLBoxEntry(&rEntry
)
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()
86 // increment ref count to prevent double call of Dtor
87 osl_atomic_increment( &m_refCount
);
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 )
100 switch ( rEvent
.GetId() )
102 case VclEventId::ObjectDying
:
104 if ( m_pTreeListBox
)
105 m_pTreeListBox
->RemoveEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
106 m_pTreeListBox
= nullptr;
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 );
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
);
132 aRect
= m_pTreeListBox
->GetBoundingRect( pEntry
);
133 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetParent( pEntry
);
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() );
146 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
148 tools::Rectangle aRect
;
149 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
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() );
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() ) );
183 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBox()
185 SolarMutexGuard aSolarGuard
;
186 ::osl::MutexGuard
aGuard( m_aMutex
);
189 return GetBoundingBox_Impl();
192 tools::Rectangle
AccessibleListBoxEntry::GetBoundingBoxOnScreen()
194 SolarMutexGuard aSolarGuard
;
195 ::osl::MutexGuard
aGuard( m_aMutex
);
198 return GetBoundingBoxOnScreen_Impl();
201 void AccessibleListBoxEntry::EnsureIsAlive() const
203 if ( !IsAlive_Impl() )
204 throw lang::DisposedException();
207 OUString
AccessibleListBoxEntry::implGetText()
210 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
212 sRet
= SvTreeListBox::SearchEntryTextWithHeadTitle( pEntry
);
216 Locale
AccessibleListBoxEntry::implGetLocale()
218 return Application::GetSettings().GetUILanguageTag().getLocale();
220 void AccessibleListBoxEntry::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
229 Sequence
< sal_Int8
> AccessibleListBoxEntry::getImplementationId()
231 return css::uno::Sequence
<sal_Int8
>();
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.
247 ::comphelper::AccessibleEventNotifier::TClientId nId
= m_nClientId
;
249 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId
, *this );
255 if ( m_pTreeListBox
)
256 m_pTreeListBox
->RemoveEventListener( LINK( this, AccessibleListBoxEntry
, WindowEventListener
) );
257 m_pTreeListBox
= nullptr;
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
);
281 Reference
< XAccessibleContext
> SAL_CALL
AccessibleListBoxEntry::getAccessibleContext( )
287 // XAccessibleContext
289 sal_Int64 SAL_CALL
AccessibleListBoxEntry::getAccessibleChildCount( )
291 SolarMutexGuard aSolarGuard
;
292 ::osl::MutexGuard
aGuard( m_aMutex
);
295 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
296 sal_Int32 nCount
= 0;
298 nCount
= m_pTreeListBox
->GetLevelChildCount( pEntry
);
303 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getAccessibleChild( sal_Int64 i
)
305 SolarMutexGuard aSolarGuard
;
306 ::osl::MutexGuard
aGuard( m_aMutex
);
309 SvTreeListEntry
* pEntry
= GetRealChild(i
);
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
;
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( );
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!" );
343 pParentEntry
= m_pTreeListBox
->GetParent(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
359 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getAccessibleParent( )
361 SolarMutexGuard aSolarGuard
;
362 ::osl::MutexGuard
aGuard( m_aMutex
);
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
379 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry(0);
382 if( pEntry
->HasChildrenOnDemand() || m_pTreeListBox
->GetChildCount(pEntry
) > 0 )
389 bool bHasButtons
= (m_pTreeListBox
->GetStyle() & WB_HASBUTTONS
)!=0;
390 if( !(m_pTreeListBox
->GetTreeFlags() & SvTreeFlags::CHKBTN
) )
405 sal_Int16 SAL_CALL
AccessibleListBoxEntry::getAccessibleRole( )
407 SolarMutexGuard aSolarGuard
;
408 ::osl::MutexGuard
aGuard( m_aMutex
);
410 SvTreeListBox
* pBox
= m_pTreeListBox
;
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
);
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
;
436 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleDescription( )
438 SolarMutexGuard aSolarGuard
;
439 ::osl::MutexGuard
aGuard( m_aMutex
);
441 if( getAccessibleRole() == AccessibleRole::TREE_ITEM
)
445 return m_pTreeListBox
->GetEntryAccessibleDescription(
446 m_pTreeListBox
->GetEntryFromPath(m_aEntryPath
));
449 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleName( )
451 ::osl::MutexGuard
aGuard( m_aMutex
);
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();
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
;
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
;
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
;
502 SvTreeListEntry
*pEntry
= m_pTreeListBox
->GetEntryFromPath(m_aEntryPath
);
504 m_pTreeListBox
->FillAccessibleEntryStateSet(pEntry
, nStateSet
);
507 nStateSet
|= AccessibleStateType::DEFUNC
;
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
);
533 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntry( VCLPoint( _aPoint
) );
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();
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();
581 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
582 if ( xParentComp
.is() )
583 nColor
= xParentComp
->getForeground();
589 sal_Int32
AccessibleListBoxEntry::getBackground( )
591 SolarMutexGuard aSolarGuard
;
592 ::osl::MutexGuard
aGuard( m_aMutex
);
594 sal_Int32 nColor
= 0;
595 Reference
< XAccessible
> xParent
= getAccessibleParent();
598 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
599 if ( xParentComp
.is() )
600 nColor
= xParentComp
->getBackground();
609 awt::Rectangle SAL_CALL
AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex
)
611 SolarMutexGuard aSolarGuard
;
612 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
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
);
634 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getIndexAtPoint( const awt::Point
& aPoint
)
636 SolarMutexGuard aSolarGuard
;
637 ::osl::MutexGuard
aGuard( m_aMutex
);
639 if(aPoint
.X
==0 && aPoint
.Y
==0) return 0;
641 sal_Int32 nIndex
= -1;
642 SvTreeListEntry
* pEntry
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
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
);
656 sal_Bool SAL_CALL
AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
658 SolarMutexGuard aSolarGuard
;
659 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
673 sal_Bool SAL_CALL
AccessibleListBoxEntry::scrollSubstringTo( sal_Int32
, sal_Int32
, AccessibleScrollType
)
678 // XAccessibleEventBroadcaster
680 void SAL_CALL
AccessibleListBoxEntry::addAccessibleEventListener( const Reference
< XAccessibleEventListener
>& xListener
)
684 ::osl::MutexGuard
aGuard( m_aMutex
);
686 m_nClientId
= comphelper::AccessibleEventNotifier::registerClient( );
687 comphelper::AccessibleEventNotifier::addEventListener( m_nClientId
, xListener
);
691 void SAL_CALL
AccessibleListBoxEntry::removeAccessibleEventListener( const Reference
< XAccessibleEventListener
>& xListener
)
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
;
707 comphelper::AccessibleEventNotifier::revokeClient( nId
);
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
)
726 else if ( role
== AccessibleRole::LABEL
)
730 return ACCESSIBLE_ACTION_COUNT
;
734 sal_Bool SAL_CALL
AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex
)
736 SolarMutexGuard aSolarGuard
;
737 ::osl::MutexGuard
aGuard( m_aMutex
);
740 checkActionIndex_Impl( nIndex
);
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
);
761 if ( m_pTreeListBox
->IsExpanded( pEntry
) )
762 m_pTreeListBox
->Collapse( pEntry
);
764 m_pTreeListBox
->Expand( pEntry
);
772 OUString SAL_CALL
AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex
)
774 SolarMutexGuard aSolarGuard
;
775 ::osl::MutexGuard
aGuard( m_aMutex
);
777 checkActionIndex_Impl( nIndex
);
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
)
789 else if (state
== SvButtonState::Unchecked
)
794 //Sometimes, a List or Tree may have both checkbox and label at the same time
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
);
807 throw IndexOutOfBoundsException();
810 Reference
< XAccessibleKeyBinding
> AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
812 Reference
< XAccessibleKeyBinding
> xRet
;
813 checkActionIndex_Impl( nIndex
);
818 // XAccessibleSelection
820 void SAL_CALL
AccessibleListBoxEntry::selectAccessibleChild( sal_Int64 nChildIndex
)
822 SolarMutexGuard aSolarGuard
;
823 ::osl::MutexGuard
aGuard( m_aMutex
);
827 if (nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount())
828 throw IndexOutOfBoundsException();
830 SvTreeListEntry
* pEntry
= GetRealChild(nChildIndex
);
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
);
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
);
850 throw IndexOutOfBoundsException();
852 return m_pTreeListBox
->IsSelected( pEntry
);
855 void SAL_CALL
AccessibleListBoxEntry::clearAccessibleSelection( )
857 SolarMutexGuard aSolarGuard
;
858 ::osl::MutexGuard
aGuard( m_aMutex
);
862 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
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
);
881 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
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
);
900 sal_Int64 nSelCount
= 0;
902 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
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
) )
916 Reference
< XAccessible
> SAL_CALL
AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex
)
918 SolarMutexGuard aSolarGuard
;
919 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
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
) )
939 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
941 uno::Reference
<XAccessible
> xListBox(m_wListBox
);
942 assert(xListBox
.is());
943 xChild
= m_rListBox
.implGetAccessible(*pEntry
).get();
951 void SAL_CALL
AccessibleListBoxEntry::deselectAccessibleChild( sal_Int64 nSelectedChildIndex
)
953 SolarMutexGuard aSolarGuard
;
954 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
964 throw IndexOutOfBoundsException();
966 m_pTreeListBox
->Select( pEntry
, false );
968 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getCaretPosition( )
972 sal_Bool SAL_CALL
AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex
)
974 SolarMutexGuard aSolarGuard
;
975 ::osl::MutexGuard
aGuard( m_aMutex
);
978 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
979 throw IndexOutOfBoundsException();
983 sal_Unicode SAL_CALL
AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex
)
985 SolarMutexGuard aSolarGuard
;
986 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
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
);
1008 return implGetText().getLength();
1011 OUString SAL_CALL
AccessibleListBoxEntry::getSelectedText( )
1013 SolarMutexGuard aSolarGuard
;
1014 ::osl::MutexGuard
aGuard( m_aMutex
);
1018 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getSelectionStart( )
1020 SolarMutexGuard aSolarGuard
;
1021 ::osl::MutexGuard
aGuard( m_aMutex
);
1025 sal_Int32 SAL_CALL
AccessibleListBoxEntry::getSelectionEnd( )
1027 SolarMutexGuard aSolarGuard
;
1028 ::osl::MutexGuard
aGuard( m_aMutex
);
1032 sal_Bool SAL_CALL
AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
1034 SolarMutexGuard aSolarGuard
;
1035 ::osl::MutexGuard
aGuard( m_aMutex
);
1038 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
1039 throw IndexOutOfBoundsException();
1043 OUString SAL_CALL
AccessibleListBoxEntry::getText( )
1045 SolarMutexGuard aSolarGuard
;
1046 ::osl::MutexGuard
aGuard( m_aMutex
);
1048 return implGetText( );
1050 OUString SAL_CALL
AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
)
1052 SolarMutexGuard aSolarGuard
;
1053 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
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
);
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
);
1077 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
1083 Any
AccessibleListBoxEntry::getCurrentValue( )
1085 ::osl::MutexGuard
aGuard( m_aMutex
);
1087 sal_Int32 level
= static_cast<sal_Int32
>(m_aEntryPath
.size()) - 1;
1088 level
= level
< 0 ? 0: level
;
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
);
1106 sal_Int32
nValue(0), nValueMin(0), nValueMax(0);
1108 getMinimumValue() >>= nValueMin
;
1109 getMaximumValue() >>= nValueMax
;
1111 if ( nValue
< nValueMin
)
1113 else if ( nValue
> nValueMax
)
1116 pBox
->SetCheckButtonState(pEntry
, static_cast<SvButtonState
>(nValue
) );
1125 Any
AccessibleListBoxEntry::getMaximumValue( )
1127 ::osl::MutexGuard
aGuard( m_aMutex
);
1130 // SvTreeListBox* pBox = m_pTreeListBox;
1131 switch(getAccessibleRole())
1133 case AccessibleRole::CHECK_BOX
:
1134 aValue
<<= sal_Int32(1);
1136 case AccessibleRole::LABEL
:
1145 Any
AccessibleListBoxEntry::getMinimumValue( )
1147 ::osl::MutexGuard
aGuard( m_aMutex
);
1150 // SvTreeListBox* pBox = m_pTreeListBox;
1151 switch(getAccessibleRole())
1153 case AccessibleRole::CHECK_BOX
:
1154 aValue
<<= sal_Int32(0);
1156 case AccessibleRole::LABEL
:
1164 Any
AccessibleListBoxEntry::getMinimumIncrement( )
1166 ::osl::MutexGuard
aGuard( m_aMutex
);
1169 switch(getAccessibleRole())
1171 case AccessibleRole::CHECK_BOX
:
1172 aValue
<<= sal_Int32(1);
1174 case AccessibleRole::LABEL
:
1182 SvTreeListEntry
* AccessibleListBoxEntry::GetRealChild(sal_Int32 nIndex
)
1184 SvTreeListEntry
* pEntry
= nullptr;
1185 SvTreeListEntry
* pParent
= m_pTreeListBox
->GetEntryFromPath( m_aEntryPath
);
1188 pEntry
= m_pTreeListBox
->GetEntry( pParent
, nIndex
);
1189 if ( !pEntry
&& getAccessibleChildCount() > 0 )
1191 m_pTreeListBox
->RequestingChildren(pParent
);
1192 pEntry
= m_pTreeListBox
->GetEntry( pParent
, nIndex
);
1198 }// namespace accessibility
1201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */