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