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/accessibletabbarpagelist.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <unotools/accessiblestatesethelper.hxx>
29 #include <unotools/accessiblerelationsethelper.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
32 #include <toolkit/helper/convert.hxx>
33 #include <i18nlangtag/languagetag.hxx>
36 namespace accessibility
40 using namespace ::com::sun::star::accessibility
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star
;
44 using namespace ::comphelper
;
49 AccessibleTabBarPageList::AccessibleTabBarPageList( TabBar
* pTabBar
, sal_Int32 nIndexInParent
)
50 :AccessibleTabBarBase( pTabBar
)
51 ,m_nIndexInParent( nIndexInParent
)
54 m_aAccessibleChildren
.assign( m_pTabBar
->GetPageCount(), Reference
< XAccessible
>() );
58 void AccessibleTabBarPageList::UpdateShowing( bool bShowing
)
60 for (const Reference
<XAccessible
>& xChild
: m_aAccessibleChildren
)
64 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
65 if ( pAccessibleTabBarPage
)
66 pAccessibleTabBarPage
->SetShowing( bShowing
);
72 void AccessibleTabBarPageList::UpdateSelected( sal_Int32 i
, bool bSelected
)
74 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, Any(), Any() );
76 if ( i
>= 0 && i
< static_cast<sal_Int32
>(m_aAccessibleChildren
.size()) )
78 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
81 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
82 if ( pAccessibleTabBarPage
)
83 pAccessibleTabBarPage
->SetSelected( bSelected
);
89 void AccessibleTabBarPageList::UpdatePageText( sal_Int32 i
)
91 if ( i
< 0 || i
>= static_cast<sal_Int32
>(m_aAccessibleChildren
.size()) )
94 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
97 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
98 if ( pAccessibleTabBarPage
&& m_pTabBar
)
100 OUString sPageText
= m_pTabBar
->GetPageText( m_pTabBar
->GetPageId( static_cast<sal_uInt16
>(i
) ) );
101 pAccessibleTabBarPage
->SetPageText( sPageText
);
107 void AccessibleTabBarPageList::InsertChild( sal_Int32 i
)
109 if ( i
< 0 || i
> static_cast<sal_Int32
>(m_aAccessibleChildren
.size()) )
112 // insert entry in child list
113 m_aAccessibleChildren
.insert( m_aAccessibleChildren
.begin() + i
, Reference
< XAccessible
>() );
115 // send accessible child event
116 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
119 Any aOldValue
, aNewValue
;
120 aNewValue
<<= xChild
;
121 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
126 void AccessibleTabBarPageList::RemoveChild( sal_Int32 i
)
128 if ( i
< 0 || i
>= static_cast<sal_Int32
>(m_aAccessibleChildren
.size()) )
131 // get the accessible of the removed page
132 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
134 // remove entry in child list
135 m_aAccessibleChildren
.erase( m_aAccessibleChildren
.begin() + i
);
137 // send accessible child event
140 Any aOldValue
, aNewValue
;
141 aOldValue
<<= xChild
;
142 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
144 Reference
< XComponent
> xComponent( xChild
, UNO_QUERY
);
145 if ( xComponent
.is() )
146 xComponent
->dispose();
151 void AccessibleTabBarPageList::MoveChild( sal_Int32 i
, sal_Int32 j
)
153 if ( !(i
>= 0 && i
< static_cast<sal_Int32
>(m_aAccessibleChildren
.size()) &&
154 j
>= 0 && j
<= static_cast<sal_Int32
>(m_aAccessibleChildren
.size())) )
160 // get the accessible of the moved page
161 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
163 // remove entry in child list at old position
164 m_aAccessibleChildren
.erase( m_aAccessibleChildren
.begin() + i
);
166 // insert entry in child list at new position
167 m_aAccessibleChildren
.insert( m_aAccessibleChildren
.begin() + j
, xChild
);
171 void AccessibleTabBarPageList::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
173 switch ( rVclWindowEvent
.GetId() )
175 case VclEventId::WindowEnabled
:
178 aNewValue
<<= AccessibleStateType::SENSITIVE
;
179 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, Any(), aNewValue
);
180 aNewValue
<<= AccessibleStateType::ENABLED
;
181 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, Any(), aNewValue
);
184 case VclEventId::WindowDisabled
:
187 aOldValue
<<= AccessibleStateType::ENABLED
;
188 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, Any() );
189 aOldValue
<<= AccessibleStateType::SENSITIVE
;
190 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, Any() );
193 case VclEventId::WindowShow
:
195 Any aOldValue
, aNewValue
;
196 aNewValue
<<= AccessibleStateType::SHOWING
;
197 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
198 UpdateShowing( true );
201 case VclEventId::WindowHide
:
203 Any aOldValue
, aNewValue
;
204 aOldValue
<<= AccessibleStateType::SHOWING
;
205 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
206 UpdateShowing( false );
209 case VclEventId::TabbarPageSelected
:
214 case VclEventId::TabbarPageActivated
:
218 sal_uInt16 nPageId
= static_cast<sal_uInt16
>(reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData()));
219 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
220 UpdateSelected( nPagePos
, true );
224 case VclEventId::TabbarPageDeactivated
:
228 sal_uInt16 nPageId
= static_cast<sal_uInt16
>(reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData()));
229 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
230 UpdateSelected( nPagePos
, false );
234 case VclEventId::TabbarPageInserted
:
238 sal_uInt16 nPageId
= static_cast<sal_uInt16
>(reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData()));
239 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
240 InsertChild( nPagePos
);
244 case VclEventId::TabbarPageRemoved
:
248 sal_uInt16 nPageId
= static_cast<sal_uInt16
>(reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData()));
250 if ( nPageId
== TabBar::PAGE_NOT_FOUND
)
252 for ( sal_Int32 i
= m_aAccessibleChildren
.size() - 1; i
>= 0; --i
)
257 for ( sal_Int32 i
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; ++i
)
259 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
262 AccessibleTabBarPage
* pAccessibleTabBarPage
= static_cast< AccessibleTabBarPage
* >( xChild
.get() );
263 if ( pAccessibleTabBarPage
&& pAccessibleTabBarPage
->GetPageId() == nPageId
)
274 case VclEventId::TabbarPageMoved
:
276 Pair
* pPair
= static_cast<Pair
*>(rVclWindowEvent
.GetData());
278 MoveChild( pPair
->A(), pPair
->B() );
281 case VclEventId::TabbarPageTextChanged
:
283 sal_uInt16 nPageId
= static_cast<sal_uInt16
>(reinterpret_cast<sal_IntPtr
>(rVclWindowEvent
.GetData()));
284 sal_uInt16 nPagePos
= m_pTabBar
->GetPagePos( nPageId
);
285 UpdatePageText( nPagePos
);
290 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
297 void AccessibleTabBarPageList::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
302 if ( m_pTabBar
->IsEnabled() )
304 rStateSet
.AddState( AccessibleStateType::ENABLED
);
305 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
308 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
310 if ( m_pTabBar
->IsVisible() )
311 rStateSet
.AddState( AccessibleStateType::SHOWING
);
315 // OCommonAccessibleComponent
318 awt::Rectangle
AccessibleTabBarPageList::implGetBounds()
320 awt::Rectangle aBounds
;
322 aBounds
= AWTRectangle( m_pTabBar
->GetPageArea() );
331 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPageList
, OAccessibleExtendedComponentHelper
, AccessibleTabBarPageList_BASE
)
337 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPageList
, OAccessibleExtendedComponentHelper
, AccessibleTabBarPageList_BASE
)
343 void AccessibleTabBarPageList::disposing()
345 AccessibleTabBarBase::disposing();
347 // dispose all children
348 for (const Reference
<XAccessible
>& i
: m_aAccessibleChildren
)
350 Reference
< XComponent
> xComponent( i
, UNO_QUERY
);
351 if ( xComponent
.is() )
352 xComponent
->dispose();
354 m_aAccessibleChildren
.clear();
361 OUString
AccessibleTabBarPageList::getImplementationName()
363 return "com.sun.star.comp.svtools.AccessibleTabBarPageList";
367 sal_Bool
AccessibleTabBarPageList::supportsService( const OUString
& rServiceName
)
369 return cppu::supportsService(this, rServiceName
);
373 Sequence
< OUString
> AccessibleTabBarPageList::getSupportedServiceNames()
375 return { "com.sun.star.awt.AccessibleTabBarPageList" };
382 Reference
< XAccessibleContext
> AccessibleTabBarPageList::getAccessibleContext( )
384 OExternalLockGuard
aGuard( this );
390 // XAccessibleContext
393 sal_Int32
AccessibleTabBarPageList::getAccessibleChildCount()
395 OExternalLockGuard
aGuard( this );
397 return m_aAccessibleChildren
.size();
401 Reference
< XAccessible
> AccessibleTabBarPageList::getAccessibleChild( sal_Int32 i
)
403 OExternalLockGuard
aGuard( this );
405 if ( i
< 0 || i
>= getAccessibleChildCount() )
406 throw IndexOutOfBoundsException();
408 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
413 sal_uInt16 nPageId
= m_pTabBar
->GetPageId( static_cast<sal_uInt16
>(i
) );
415 xChild
= new AccessibleTabBarPage( m_pTabBar
, nPageId
, this );
417 // insert into child list
418 m_aAccessibleChildren
[i
] = xChild
;
426 Reference
< XAccessible
> AccessibleTabBarPageList::getAccessibleParent( )
428 OExternalLockGuard
aGuard( this );
430 Reference
< XAccessible
> xParent
;
432 xParent
= m_pTabBar
->GetAccessible();
438 sal_Int32
AccessibleTabBarPageList::getAccessibleIndexInParent( )
440 OExternalLockGuard
aGuard( this );
442 return m_nIndexInParent
;
446 sal_Int16
AccessibleTabBarPageList::getAccessibleRole( )
448 return AccessibleRole::PAGE_TAB_LIST
;
452 OUString
AccessibleTabBarPageList::getAccessibleDescription( )
458 OUString
AccessibleTabBarPageList::getAccessibleName( )
464 Reference
< XAccessibleRelationSet
> AccessibleTabBarPageList::getAccessibleRelationSet( )
466 OExternalLockGuard
aGuard( this );
468 return new utl::AccessibleRelationSetHelper
;
472 Reference
< XAccessibleStateSet
> AccessibleTabBarPageList::getAccessibleStateSet( )
474 OExternalLockGuard
aGuard( this );
476 rtl::Reference
<utl::AccessibleStateSetHelper
> pStateSetHelper
= new utl::AccessibleStateSetHelper
;
478 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
480 FillAccessibleStateSet( *pStateSetHelper
);
484 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
487 return pStateSetHelper
;
491 Locale
AccessibleTabBarPageList::getLocale( )
493 OExternalLockGuard
aGuard( this );
495 return Application::GetSettings().GetLanguageTag().getLocale();
499 // XAccessibleComponent
502 Reference
< XAccessible
> AccessibleTabBarPageList::getAccessibleAtPoint( const awt::Point
& rPoint
)
504 OExternalLockGuard
aGuard( this );
506 Reference
< XAccessible
> xChild
;
507 for ( size_t i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
509 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
512 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
515 tools::Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
516 Point aPos
= VCLPoint( rPoint
);
517 if ( aRect
.Contains( aPos
) )
530 void AccessibleTabBarPageList::grabFocus( )
536 sal_Int32
AccessibleTabBarPageList::getForeground( )
538 OExternalLockGuard
aGuard( this );
540 sal_Int32 nColor
= 0;
541 Reference
< XAccessible
> xParent
= getAccessibleParent();
544 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
545 if ( xParentComp
.is() )
546 nColor
= xParentComp
->getForeground();
553 sal_Int32
AccessibleTabBarPageList::getBackground( )
555 OExternalLockGuard
aGuard( this );
557 sal_Int32 nColor
= 0;
558 Reference
< XAccessible
> xParent
= getAccessibleParent();
561 Reference
< XAccessibleComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
562 if ( xParentComp
.is() )
563 nColor
= xParentComp
->getBackground();
570 // XAccessibleExtendedComponent
573 Reference
< awt::XFont
> AccessibleTabBarPageList::getFont( )
575 OExternalLockGuard
aGuard( this );
577 Reference
< awt::XFont
> xFont
;
578 Reference
< XAccessible
> xParent
= getAccessibleParent();
581 Reference
< XAccessibleExtendedComponent
> xParentComp( xParent
->getAccessibleContext(), UNO_QUERY
);
582 if ( xParentComp
.is() )
583 xFont
= xParentComp
->getFont();
590 OUString
AccessibleTabBarPageList::getTitledBorderText( )
596 OUString
AccessibleTabBarPageList::getToolTipText( )
602 // XAccessibleSelection
605 void AccessibleTabBarPageList::selectAccessibleChild( sal_Int32 nChildIndex
)
607 OExternalLockGuard
aGuard( this );
609 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
610 throw IndexOutOfBoundsException();
614 m_pTabBar
->SetCurPageId( m_pTabBar
->GetPageId( static_cast<sal_uInt16
>(nChildIndex
) ) );
615 m_pTabBar
->PaintImmediately();
616 m_pTabBar
->ActivatePage();
622 sal_Bool
AccessibleTabBarPageList::isAccessibleChildSelected( sal_Int32 nChildIndex
)
624 OExternalLockGuard
aGuard( this );
626 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
627 throw IndexOutOfBoundsException();
629 bool bSelected
= false;
630 if ( m_pTabBar
&& m_pTabBar
->GetCurPageId() == m_pTabBar
->GetPageId( static_cast<sal_uInt16
>(nChildIndex
) ) )
637 void AccessibleTabBarPageList::clearAccessibleSelection( )
639 // This method makes no sense in a TabBar, and so does nothing.
643 void AccessibleTabBarPageList::selectAllAccessibleChildren( )
645 selectAccessibleChild( 0 );
649 sal_Int32
AccessibleTabBarPageList::getSelectedAccessibleChildCount( )
655 Reference
< XAccessible
> AccessibleTabBarPageList::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
657 OExternalLockGuard
aGuard( this );
659 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
660 throw IndexOutOfBoundsException();
662 Reference
< XAccessible
> xChild
;
664 for ( sal_Int32 i
= 0, j
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; i
++ )
666 if ( isAccessibleChildSelected( i
) && ( j
++ == nSelectedChildIndex
) )
668 xChild
= getAccessibleChild( i
);
677 void AccessibleTabBarPageList::deselectAccessibleChild( sal_Int32 nChildIndex
)
679 OExternalLockGuard
aGuard( this );
681 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
682 throw IndexOutOfBoundsException();
684 // This method makes no sense in a TabBar, and so does nothing.
688 } // namespace accessibility
691 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */