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 <accessibility/extended/accessibletabbarpagelist.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <accessibility/extended/accessibletabbarpage.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <unotools/accessiblestatesethelper.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/settings.hxx>
31 #include <toolkit/helper/convert.hxx>
35 namespace accessibility
39 using namespace ::com::sun::star::accessibility
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star
;
43 using namespace ::comphelper
;
46 // class AccessibleTabBarPageList
49 AccessibleTabBarPageList::AccessibleTabBarPageList( TabBar
* pTabBar
, sal_Int32 nIndexInParent
)
50 :AccessibleTabBarBase( pTabBar
)
51 ,m_nIndexInParent( nIndexInParent
)
54 m_aAccessibleChildren
.assign( m_pTabBar
->GetPageCount(), Reference
< XAccessible
>() );
59 AccessibleTabBarPageList::~AccessibleTabBarPageList()
65 void AccessibleTabBarPageList::UpdateEnabled( sal_Int32 i
, bool bEnabled
)
67 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
69 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
72 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
73 if ( pAccessibleTabBarPage
)
74 pAccessibleTabBarPage
->SetEnabled( bEnabled
);
81 void AccessibleTabBarPageList::UpdateShowing( bool bShowing
)
83 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
85 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
88 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
89 if ( pAccessibleTabBarPage
)
90 pAccessibleTabBarPage
->SetShowing( bShowing
);
97 void AccessibleTabBarPageList::UpdateSelected( sal_Int32 i
, bool bSelected
)
99 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, Any(), Any() );
101 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
103 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
106 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
107 if ( pAccessibleTabBarPage
)
108 pAccessibleTabBarPage
->SetSelected( bSelected
);
115 void AccessibleTabBarPageList::UpdatePageText( sal_Int32 i
)
117 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
119 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
122 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
123 if ( pAccessibleTabBarPage
)
127 OUString sPageText
= m_pTabBar
->GetPageText( m_pTabBar
->GetPageId( (sal_uInt16
)i
) );
128 pAccessibleTabBarPage
->SetPageText( sPageText
);
137 void AccessibleTabBarPageList::InsertChild( sal_Int32 i
)
139 if ( i
>= 0 && i
<= (sal_Int32
)m_aAccessibleChildren
.size() )
141 // insert entry in child list
142 m_aAccessibleChildren
.insert( m_aAccessibleChildren
.begin() + i
, Reference
< XAccessible
>() );
144 // send accessible child event
145 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
148 Any aOldValue
, aNewValue
;
149 aNewValue
<<= xChild
;
150 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
157 void AccessibleTabBarPageList::RemoveChild( sal_Int32 i
)
159 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
161 // get the accessible of the removed page
162 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
164 // remove entry in child list
165 m_aAccessibleChildren
.erase( m_aAccessibleChildren
.begin() + i
);
167 // send accessible child event
170 Any aOldValue
, aNewValue
;
171 aOldValue
<<= xChild
;
172 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
174 Reference
< XComponent
> xComponent( xChild
, UNO_QUERY
);
175 if ( xComponent
.is() )
176 xComponent
->dispose();
183 void AccessibleTabBarPageList::MoveChild( sal_Int32 i
, sal_Int32 j
)
185 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() &&
186 j
>= 0 && j
<= (sal_Int32
)m_aAccessibleChildren
.size() )
191 // get the accessible of the moved page
192 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
194 // remove entry in child list at old position
195 m_aAccessibleChildren
.erase( m_aAccessibleChildren
.begin() + i
);
197 // insert entry in child list at new position
198 m_aAccessibleChildren
.insert( m_aAccessibleChildren
.begin() + j
, xChild
);
204 void AccessibleTabBarPageList::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
206 switch ( rVclWindowEvent
.GetId() )
208 case VCLEVENT_WINDOW_ENABLED
:
211 aNewValue
<<= AccessibleStateType::SENSITIVE
;
212 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, Any(), aNewValue
);
213 aNewValue
<<= AccessibleStateType::ENABLED
;
214 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, Any(), aNewValue
);
217 case VCLEVENT_WINDOW_DISABLED
:
220 aOldValue
<<= AccessibleStateType::ENABLED
;
221 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, Any() );
222 aOldValue
<<= AccessibleStateType::SENSITIVE
;
223 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, Any() );
226 case VCLEVENT_WINDOW_SHOW
:
228 Any aOldValue
, aNewValue
;
229 aNewValue
<<= AccessibleStateType::SHOWING
;
230 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
231 UpdateShowing( true );
234 case VCLEVENT_WINDOW_HIDE
:
236 Any aOldValue
, aNewValue
;
237 aOldValue
<<= AccessibleStateType::SHOWING
;
238 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
239 UpdateShowing( false );
242 case VCLEVENT_TABBAR_PAGEENABLED
:
246 sal_uInt16 nPageId
= (sal_uInt16
)reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData());
247 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
248 UpdateEnabled( nPagePos
, true );
252 case VCLEVENT_TABBAR_PAGEDISABLED
:
256 sal_uInt16 nPageId
= (sal_uInt16
)reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData());
257 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
258 UpdateEnabled( nPagePos
, false );
262 case VCLEVENT_TABBAR_PAGESELECTED
:
267 case VCLEVENT_TABBAR_PAGEACTIVATED
:
271 sal_uInt16 nPageId
= (sal_uInt16
)reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData());
272 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
273 UpdateSelected( nPagePos
, true );
277 case VCLEVENT_TABBAR_PAGEDEACTIVATED
:
281 sal_uInt16 nPageId
= (sal_uInt16
)reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData());
282 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
283 UpdateSelected( nPagePos
, false );
287 case VCLEVENT_TABBAR_PAGEINSERTED
:
291 sal_uInt16 nPageId
= (sal_uInt16
)reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData());
292 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
293 InsertChild( nPagePos
);
297 case VCLEVENT_TABBAR_PAGEREMOVED
:
301 sal_uInt16 nPageId
= (sal_uInt16
)reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData());
303 if ( nPageId
== TabBar::PAGE_NOT_FOUND
)
305 for ( sal_Int32 i
= m_aAccessibleChildren
.size() - 1; i
>= 0; --i
)
310 for ( sal_Int32 i
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; ++i
)
312 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
315 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
316 if ( pAccessibleTabBarPage
&& pAccessibleTabBarPage
->GetPageId() == nPageId
)
327 case VCLEVENT_TABBAR_PAGEMOVED
:
329 Pair
* pPair
= static_cast<Pair
*>(rVclWindowEvent
.GetData());
331 MoveChild( pPair
->A(), pPair
->B() );
334 case VCLEVENT_TABBAR_PAGETEXTCHANGED
:
336 sal_uInt16 nPageId
= (sal_uInt16
)reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData());
337 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
338 UpdatePageText( nPagePos
);
343 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
351 void AccessibleTabBarPageList::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
355 if ( m_pTabBar
->IsEnabled() )
357 rStateSet
.AddState( AccessibleStateType::ENABLED
);
358 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
361 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
363 if ( m_pTabBar
->IsVisible() )
364 rStateSet
.AddState( AccessibleStateType::SHOWING
);
369 // OCommonAccessibleComponent
372 awt::Rectangle
AccessibleTabBarPageList::implGetBounds() throw (RuntimeException
)
374 awt::Rectangle aBounds
;
376 aBounds
= AWTRectangle( m_pTabBar
->GetPageArea() );
385 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPageList
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBarPageList_BASE
)
391 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPageList
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBarPageList_BASE
)
397 void AccessibleTabBarPageList::disposing()
399 AccessibleTabBarBase::disposing();
401 // dispose all children
402 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
404 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
405 if ( xComponent
.is() )
406 xComponent
->dispose();
408 m_aAccessibleChildren
.clear();
415 OUString
AccessibleTabBarPageList::getImplementationName() throw (RuntimeException
, std::exception
)
417 return OUString( "com.sun.star.comp.svtools.AccessibleTabBarPageList" );
422 sal_Bool
AccessibleTabBarPageList::supportsService( const OUString
& rServiceName
) throw (RuntimeException
, std::exception
)
424 return cppu::supportsService(this, rServiceName
);
429 Sequence
< OUString
> AccessibleTabBarPageList::getSupportedServiceNames() throw (RuntimeException
, std::exception
)
431 Sequence
< OUString
> aNames(1);
432 aNames
[0] = "com.sun.star.awt.AccessibleTabBarPageList";
440 Reference
< XAccessibleContext
> AccessibleTabBarPageList::getAccessibleContext( ) throw (RuntimeException
, std::exception
)
442 OExternalLockGuard
aGuard( this );
448 // XAccessibleContext
451 sal_Int32
AccessibleTabBarPageList::getAccessibleChildCount() throw (RuntimeException
, std::exception
)
453 OExternalLockGuard
aGuard( this );
455 return m_aAccessibleChildren
.size();
460 Reference
< XAccessible
> AccessibleTabBarPageList::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
462 OExternalLockGuard
aGuard( this );
464 if ( i
< 0 || i
>= getAccessibleChildCount() )
465 throw IndexOutOfBoundsException();
467 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
472 sal_uInt16 nPageId
= m_pTabBar
->GetPageId( (sal_uInt16
)i
);
474 xChild
= new AccessibleTabBarPage( m_pTabBar
, nPageId
, this );
476 // insert into child list
477 m_aAccessibleChildren
[i
] = xChild
;
486 Reference
< XAccessible
> AccessibleTabBarPageList::getAccessibleParent( ) throw (RuntimeException
, std::exception
)
488 OExternalLockGuard
aGuard( this );
490 Reference
< XAccessible
> xParent
;
492 xParent
= m_pTabBar
->GetAccessible();
499 sal_Int32
AccessibleTabBarPageList::getAccessibleIndexInParent( ) throw (RuntimeException
, std::exception
)
501 OExternalLockGuard
aGuard( this );
503 return m_nIndexInParent
;
508 sal_Int16
AccessibleTabBarPageList::getAccessibleRole( ) throw (RuntimeException
, std::exception
)
510 OExternalLockGuard
aGuard( this );
512 return AccessibleRole::PAGE_TAB_LIST
;
517 OUString
AccessibleTabBarPageList::getAccessibleDescription( ) throw (RuntimeException
, std::exception
)
519 OExternalLockGuard
aGuard( this );
526 OUString
AccessibleTabBarPageList::getAccessibleName( ) throw (RuntimeException
, std::exception
)
528 OExternalLockGuard
aGuard( this );
535 Reference
< XAccessibleRelationSet
> AccessibleTabBarPageList::getAccessibleRelationSet( ) throw (RuntimeException
, std::exception
)
537 OExternalLockGuard
aGuard( this );
539 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
540 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
546 Reference
< XAccessibleStateSet
> AccessibleTabBarPageList::getAccessibleStateSet( ) throw (RuntimeException
, std::exception
)
548 OExternalLockGuard
aGuard( this );
550 utl::AccessibleStateSetHelper
* pStateSetHelper
= new utl::AccessibleStateSetHelper
;
551 Reference
< XAccessibleStateSet
> xSet
= pStateSetHelper
;
553 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
555 FillAccessibleStateSet( *pStateSetHelper
);
559 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
567 Locale
AccessibleTabBarPageList::getLocale( ) throw (IllegalAccessibleComponentStateException
, RuntimeException
, std::exception
)
569 OExternalLockGuard
aGuard( this );
571 return Application::GetSettings().GetLanguageTag().getLocale();
575 // XAccessibleComponent
578 Reference
< XAccessible
> AccessibleTabBarPageList::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
, std::exception
)
580 OExternalLockGuard
aGuard( this );
582 Reference
< XAccessible
> xChild
;
583 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
585 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
588 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
591 Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
592 Point aPos
= VCLPoint( rPoint
);
593 if ( aRect
.IsInside( aPos
) )
607 void AccessibleTabBarPageList::grabFocus( ) throw (RuntimeException
, std::exception
)
614 sal_Int32
AccessibleTabBarPageList::getForeground( ) throw (RuntimeException
, std::exception
)
616 OExternalLockGuard
aGuard( this );
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
->getForeground();
632 sal_Int32
AccessibleTabBarPageList::getBackground( ) throw (RuntimeException
, std::exception
)
634 OExternalLockGuard
aGuard( this );
636 sal_Int32 nColor
= 0;
637 Reference
< XAccessible
> xParent
= getAccessibleParent();
640 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
641 if ( xParentComp
.is() )
642 nColor
= xParentComp
->getBackground();
649 // XAccessibleExtendedComponent
652 Reference
< awt::XFont
> AccessibleTabBarPageList::getFont( ) throw (RuntimeException
, std::exception
)
654 OExternalLockGuard
aGuard( this );
656 Reference
< awt::XFont
> xFont
;
657 Reference
< XAccessible
> xParent
= getAccessibleParent();
660 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
661 if ( xParentComp
.is() )
662 xFont
= xParentComp
->getFont();
670 OUString
AccessibleTabBarPageList::getTitledBorderText( ) throw (RuntimeException
, std::exception
)
672 OExternalLockGuard
aGuard( this );
679 OUString
AccessibleTabBarPageList::getToolTipText( ) throw (RuntimeException
, std::exception
)
681 OExternalLockGuard
aGuard( this );
687 // XAccessibleSelection
690 void AccessibleTabBarPageList::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
692 OExternalLockGuard
aGuard( this );
694 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
695 throw IndexOutOfBoundsException();
699 m_pTabBar
->SetCurPageId( m_pTabBar
->GetPageId( (sal_uInt16
)nChildIndex
) );
701 m_pTabBar
->ActivatePage();
708 sal_Bool
AccessibleTabBarPageList::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
710 OExternalLockGuard
aGuard( this );
712 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
713 throw IndexOutOfBoundsException();
715 bool bSelected
= false;
716 if ( m_pTabBar
&& m_pTabBar
->GetCurPageId() == m_pTabBar
->GetPageId( (sal_uInt16
)nChildIndex
) )
724 void AccessibleTabBarPageList::clearAccessibleSelection( ) throw (RuntimeException
, std::exception
)
726 // This method makes no sense in a TabBar, and so does nothing.
731 void AccessibleTabBarPageList::selectAllAccessibleChildren( ) throw (RuntimeException
, std::exception
)
733 OExternalLockGuard
aGuard( this );
735 selectAccessibleChild( 0 );
740 sal_Int32
AccessibleTabBarPageList::getSelectedAccessibleChildCount( ) throw (RuntimeException
, std::exception
)
742 OExternalLockGuard
aGuard( this );
749 Reference
< XAccessible
> AccessibleTabBarPageList::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
751 OExternalLockGuard
aGuard( this );
753 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
754 throw IndexOutOfBoundsException();
756 Reference
< XAccessible
> xChild
;
758 for ( sal_Int32 i
= 0, j
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; i
++ )
760 if ( isAccessibleChildSelected( i
) && ( j
++ == nSelectedChildIndex
) )
762 xChild
= getAccessibleChild( i
);
772 void AccessibleTabBarPageList::deselectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
774 OExternalLockGuard
aGuard( this );
776 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
777 throw IndexOutOfBoundsException();
779 // This method makes no sense in a TabBar, and so does nothing.
785 } // namespace accessibility
788 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */