Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / accessibletabbarpagelist.cxx
blob3eb8ab324c3783fbc323f4fcb973243e09baf4e3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <comphelper/accessiblecontexthelper.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <o3tl/safeint.hxx>
30 #include <unotools/accessiblerelationsethelper.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/settings.hxx>
33 #include <toolkit/helper/convert.hxx>
34 #include <i18nlangtag/languagetag.hxx>
37 namespace accessibility
41 using namespace ::com::sun::star::accessibility;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star;
45 using namespace ::comphelper;
50 AccessibleTabBarPageList::AccessibleTabBarPageList( TabBar* pTabBar, sal_Int32 nIndexInParent )
51 :ImplInheritanceHelper( pTabBar )
52 ,m_nIndexInParent( nIndexInParent )
54 if ( m_pTabBar )
55 m_aAccessibleChildren.assign( m_pTabBar->GetPageCount(), Reference< XAccessible >() );
59 void AccessibleTabBarPageList::UpdateShowing( bool bShowing )
61 for (const Reference<XAccessible>& xChild : m_aAccessibleChildren)
63 if ( xChild.is() )
65 AccessibleTabBarPage* pAccessibleTabBarPage = static_cast< AccessibleTabBarPage* >( xChild.get() );
66 if ( pAccessibleTabBarPage )
67 pAccessibleTabBarPage->SetShowing( bShowing );
73 void AccessibleTabBarPageList::UpdateSelected( sal_Int32 i, bool bSelected )
75 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
77 if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() )
79 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
80 if ( xChild.is() )
82 AccessibleTabBarPage* pAccessibleTabBarPage = static_cast< AccessibleTabBarPage* >( xChild.get() );
83 if ( pAccessibleTabBarPage )
84 pAccessibleTabBarPage->SetSelected( bSelected );
90 void AccessibleTabBarPageList::UpdatePageText( sal_Int32 i )
92 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
93 return;
95 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
96 if ( xChild.is() )
98 AccessibleTabBarPage* pAccessibleTabBarPage = static_cast< AccessibleTabBarPage* >( xChild.get() );
99 if ( pAccessibleTabBarPage && m_pTabBar )
101 OUString sPageText = m_pTabBar->GetPageText( m_pTabBar->GetPageId( static_cast<sal_uInt16>(i) ) );
102 pAccessibleTabBarPage->SetPageText( sPageText );
108 void AccessibleTabBarPageList::InsertChild( sal_Int32 i )
110 if ( i < 0 || o3tl::make_unsigned(i) > m_aAccessibleChildren.size() )
111 return;
113 // insert entry in child list
114 m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, Reference< XAccessible >() );
116 // send accessible child event
117 Reference< XAccessible > xChild( getAccessibleChild( i ) );
118 if ( xChild.is() )
120 Any aOldValue, aNewValue;
121 aNewValue <<= xChild;
122 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
127 void AccessibleTabBarPageList::RemoveChild( sal_Int32 i )
129 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
130 return;
132 // get the accessible of the removed page
133 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
135 // remove entry in child list
136 m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
138 // send accessible child event
139 if ( xChild.is() )
141 Any aOldValue, aNewValue;
142 aOldValue <<= xChild;
143 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
145 Reference< XComponent > xComponent( xChild, UNO_QUERY );
146 if ( xComponent.is() )
147 xComponent->dispose();
152 void AccessibleTabBarPageList::MoveChild( sal_Int32 i, sal_Int32 j )
154 if ( !(i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() &&
155 j >= 0 && o3tl::make_unsigned(j) <= m_aAccessibleChildren.size()) )
156 return;
158 if ( i < j )
159 --j;
161 // get the accessible of the moved page
162 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
164 // remove entry in child list at old position
165 m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
167 // insert entry in child list at new position
168 m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + j, xChild );
172 void AccessibleTabBarPageList::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
174 switch ( rVclWindowEvent.GetId() )
176 case VclEventId::WindowEnabled:
178 Any aNewValue;
179 aNewValue <<= AccessibleStateType::SENSITIVE;
180 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, Any(), aNewValue );
181 aNewValue <<= AccessibleStateType::ENABLED;
182 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, Any(), aNewValue );
184 break;
185 case VclEventId::WindowDisabled:
187 Any aOldValue;
188 aOldValue <<= AccessibleStateType::ENABLED;
189 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, Any() );
190 aOldValue <<= AccessibleStateType::SENSITIVE;
191 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, Any() );
193 break;
194 case VclEventId::WindowShow:
196 Any aOldValue, aNewValue;
197 aNewValue <<= AccessibleStateType::SHOWING;
198 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
199 UpdateShowing( true );
201 break;
202 case VclEventId::WindowHide:
204 Any aOldValue, aNewValue;
205 aOldValue <<= AccessibleStateType::SHOWING;
206 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
207 UpdateShowing( false );
209 break;
210 case VclEventId::TabbarPageSelected:
212 // do nothing
214 break;
215 case VclEventId::TabbarPageActivated:
217 if ( m_pTabBar )
219 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
220 sal_uInt16 nPagePos = m_pTabBar->GetPagePos( nPageId );
221 UpdateSelected( nPagePos, true );
224 break;
225 case VclEventId::TabbarPageDeactivated:
227 if ( m_pTabBar )
229 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
230 sal_uInt16 nPagePos = m_pTabBar->GetPagePos( nPageId );
231 UpdateSelected( nPagePos, false );
234 break;
235 case VclEventId::TabbarPageInserted:
237 if ( m_pTabBar )
239 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
240 sal_uInt16 nPagePos = m_pTabBar->GetPagePos( nPageId );
241 InsertChild( nPagePos );
244 break;
245 case VclEventId::TabbarPageRemoved:
247 if ( m_pTabBar )
249 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
251 if ( nPageId == TabBar::PAGE_NOT_FOUND )
253 for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
254 RemoveChild( i );
256 else
258 for ( sal_Int64 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
260 Reference< XAccessible > xChild( getAccessibleChild( i ) );
261 if ( xChild.is() )
263 AccessibleTabBarPage* pAccessibleTabBarPage = static_cast< AccessibleTabBarPage* >( xChild.get() );
264 if ( pAccessibleTabBarPage && pAccessibleTabBarPage->GetPageId() == nPageId )
266 RemoveChild( i );
267 break;
274 break;
275 case VclEventId::TabbarPageMoved:
277 Pair* pPair = static_cast<Pair*>(rVclWindowEvent.GetData());
278 if ( pPair )
279 MoveChild( pPair->A(), pPair->B() );
281 break;
282 case VclEventId::TabbarPageTextChanged:
284 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
285 sal_uInt16 nPagePos = m_pTabBar->GetPagePos( nPageId );
286 UpdatePageText( nPagePos );
288 break;
289 default:
291 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
293 break;
298 void AccessibleTabBarPageList::FillAccessibleStateSet( sal_Int64& rStateSet )
300 if ( !m_pTabBar )
301 return;
303 if ( m_pTabBar->IsEnabled() )
305 rStateSet |= AccessibleStateType::ENABLED;
306 rStateSet |= AccessibleStateType::SENSITIVE;
309 rStateSet |= AccessibleStateType::VISIBLE;
311 if ( m_pTabBar->IsVisible() )
312 rStateSet |= AccessibleStateType::SHOWING;
316 // OCommonAccessibleComponent
319 awt::Rectangle AccessibleTabBarPageList::implGetBounds()
321 awt::Rectangle aBounds;
322 if ( m_pTabBar )
323 aBounds = AWTRectangle( m_pTabBar->GetPageArea() );
325 return aBounds;
329 // XComponent
332 void AccessibleTabBarPageList::disposing()
334 AccessibleTabBarBase::disposing();
336 // dispose all children
337 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
339 Reference< XComponent > xComponent( i, UNO_QUERY );
340 if ( xComponent.is() )
341 xComponent->dispose();
343 m_aAccessibleChildren.clear();
347 // XServiceInfo
350 OUString AccessibleTabBarPageList::getImplementationName()
352 return "com.sun.star.comp.svtools.AccessibleTabBarPageList";
356 sal_Bool AccessibleTabBarPageList::supportsService( const OUString& rServiceName )
358 return cppu::supportsService(this, rServiceName);
362 Sequence< OUString > AccessibleTabBarPageList::getSupportedServiceNames()
364 return { "com.sun.star.awt.AccessibleTabBarPageList" };
368 // XAccessible
371 Reference< XAccessibleContext > AccessibleTabBarPageList::getAccessibleContext( )
373 OExternalLockGuard aGuard( this );
375 return this;
379 // XAccessibleContext
382 sal_Int64 AccessibleTabBarPageList::getAccessibleChildCount()
384 OExternalLockGuard aGuard( this );
386 return m_aAccessibleChildren.size();
390 Reference< XAccessible > AccessibleTabBarPageList::getAccessibleChild( sal_Int64 i )
392 OExternalLockGuard aGuard( this );
394 if ( i < 0 || i >= getAccessibleChildCount() )
395 throw IndexOutOfBoundsException();
397 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
398 if ( !xChild.is() )
400 if ( m_pTabBar )
402 sal_uInt16 nPageId = m_pTabBar->GetPageId( static_cast<sal_uInt16>(i) );
404 xChild = new AccessibleTabBarPage( m_pTabBar, nPageId, this );
406 // insert into child list
407 m_aAccessibleChildren[i] = xChild;
411 return xChild;
415 Reference< XAccessible > AccessibleTabBarPageList::getAccessibleParent( )
417 OExternalLockGuard aGuard( this );
419 Reference< XAccessible > xParent;
420 if ( m_pTabBar )
421 xParent = m_pTabBar->GetAccessible();
423 return xParent;
427 sal_Int64 AccessibleTabBarPageList::getAccessibleIndexInParent( )
429 OExternalLockGuard aGuard( this );
431 return m_nIndexInParent;
435 sal_Int16 AccessibleTabBarPageList::getAccessibleRole( )
437 return AccessibleRole::PAGE_TAB_LIST;
441 OUString AccessibleTabBarPageList::getAccessibleDescription( )
443 return OUString();
447 OUString AccessibleTabBarPageList::getAccessibleName( )
449 return OUString();
453 Reference< XAccessibleRelationSet > AccessibleTabBarPageList::getAccessibleRelationSet( )
455 OExternalLockGuard aGuard( this );
457 return new utl::AccessibleRelationSetHelper;
461 sal_Int64 AccessibleTabBarPageList::getAccessibleStateSet( )
463 OExternalLockGuard aGuard( this );
465 sal_Int64 nStateSet = 0;
467 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
469 FillAccessibleStateSet( nStateSet );
471 else
473 nStateSet |= AccessibleStateType::DEFUNC;
476 return nStateSet;
480 Locale AccessibleTabBarPageList::getLocale( )
482 OExternalLockGuard aGuard( this );
484 return Application::GetSettings().GetLanguageTag().getLocale();
488 // XAccessibleComponent
491 Reference< XAccessible > AccessibleTabBarPageList::getAccessibleAtPoint( const awt::Point& rPoint )
493 OExternalLockGuard aGuard( this );
495 Reference< XAccessible > xChild;
496 for ( size_t i = 0; i < m_aAccessibleChildren.size(); ++i )
498 Reference< XAccessible > xAcc = getAccessibleChild( i );
499 if ( xAcc.is() )
501 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
502 if ( xComp.is() )
504 tools::Rectangle aRect = VCLRectangle( xComp->getBounds() );
505 Point aPos = VCLPoint( rPoint );
506 if ( aRect.Contains( aPos ) )
508 xChild = xAcc;
509 break;
515 return xChild;
519 void AccessibleTabBarPageList::grabFocus( )
521 // no focus
525 sal_Int32 AccessibleTabBarPageList::getForeground( )
527 OExternalLockGuard aGuard( this );
529 sal_Int32 nColor = 0;
530 Reference< XAccessible > xParent = getAccessibleParent();
531 if ( xParent.is() )
533 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
534 if ( xParentComp.is() )
535 nColor = xParentComp->getForeground();
538 return nColor;
542 sal_Int32 AccessibleTabBarPageList::getBackground( )
544 OExternalLockGuard aGuard( this );
546 sal_Int32 nColor = 0;
547 Reference< XAccessible > xParent = getAccessibleParent();
548 if ( xParent.is() )
550 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
551 if ( xParentComp.is() )
552 nColor = xParentComp->getBackground();
555 return nColor;
559 // XAccessibleExtendedComponent
562 Reference< awt::XFont > AccessibleTabBarPageList::getFont( )
564 OExternalLockGuard aGuard( this );
566 Reference< awt::XFont > xFont;
567 Reference< XAccessible > xParent = getAccessibleParent();
568 if ( xParent.is() )
570 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
571 if ( xParentComp.is() )
572 xFont = xParentComp->getFont();
575 return xFont;
579 OUString AccessibleTabBarPageList::getTitledBorderText( )
581 return OUString();
585 OUString AccessibleTabBarPageList::getToolTipText( )
587 return OUString();
591 // XAccessibleSelection
594 void AccessibleTabBarPageList::selectAccessibleChild( sal_Int64 nChildIndex )
596 OExternalLockGuard aGuard( this );
598 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
599 throw IndexOutOfBoundsException();
601 if ( m_pTabBar )
603 m_pTabBar->SetCurPageId( m_pTabBar->GetPageId( static_cast<sal_uInt16>(nChildIndex) ) );
604 m_pTabBar->PaintImmediately();
605 m_pTabBar->ActivatePage();
606 m_pTabBar->Select();
611 sal_Bool AccessibleTabBarPageList::isAccessibleChildSelected( sal_Int64 nChildIndex )
613 OExternalLockGuard aGuard( this );
615 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
616 throw IndexOutOfBoundsException();
618 bool bSelected = false;
619 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_pTabBar->GetPageId( static_cast<sal_uInt16>(nChildIndex) ) )
620 bSelected = true;
622 return bSelected;
626 void AccessibleTabBarPageList::clearAccessibleSelection( )
628 // This method makes no sense in a TabBar, and so does nothing.
632 void AccessibleTabBarPageList::selectAllAccessibleChildren( )
634 selectAccessibleChild( 0 );
638 sal_Int64 AccessibleTabBarPageList::getSelectedAccessibleChildCount( )
640 return 1;
644 Reference< XAccessible > AccessibleTabBarPageList::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
646 OExternalLockGuard aGuard( this );
648 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
649 throw IndexOutOfBoundsException();
651 Reference< XAccessible > xChild;
653 for ( sal_Int64 i = 0, j = 0, nCount = getAccessibleChildCount(); i < nCount; i++ )
655 if ( isAccessibleChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
657 xChild = getAccessibleChild( i );
658 break;
662 return xChild;
666 void AccessibleTabBarPageList::deselectAccessibleChild( sal_Int64 nChildIndex )
668 OExternalLockGuard aGuard( this );
670 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
671 throw IndexOutOfBoundsException();
673 // This method makes no sense in a TabBar, and so does nothing.
677 } // namespace accessibility
680 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */