lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / accessibility / source / extended / accessibletabbar.cxx
blobf4b111698abf5aa44adab096bc5ec8a5abd13cf5
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/accessibletabbar.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <extended/accessibletabbarpagelist.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/awt/vclxfont.hxx>
33 #include <toolkit/helper/convert.hxx>
35 #include <vector>
38 namespace accessibility
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::accessibility;
46 using namespace ::comphelper;
49 // class AccessibleTabBar
52 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
53 :AccessibleTabBarBase( pTabBar )
55 if ( m_pTabBar )
56 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
60 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
62 Any aOldValue, aNewValue;
64 switch ( rVclWindowEvent.GetId() )
66 case VclEventId::WindowEnabled:
68 aNewValue <<= AccessibleStateType::SENSITIVE;
69 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
70 aNewValue <<= AccessibleStateType::ENABLED;
71 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
73 break;
74 case VclEventId::WindowDisabled:
76 aOldValue <<= AccessibleStateType::ENABLED;
77 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
78 aOldValue <<= AccessibleStateType::SENSITIVE;
79 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
81 break;
82 case VclEventId::WindowGetFocus:
84 aNewValue <<= AccessibleStateType::FOCUSED;
85 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
87 break;
88 case VclEventId::WindowLoseFocus:
90 aOldValue <<= AccessibleStateType::FOCUSED;
91 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
93 break;
94 case VclEventId::WindowShow:
96 aNewValue <<= AccessibleStateType::SHOWING;
97 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
99 break;
100 case VclEventId::WindowHide:
102 aOldValue <<= AccessibleStateType::SHOWING;
103 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
105 break;
106 default:
108 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
110 break;
115 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
117 if ( m_pTabBar )
119 if ( m_pTabBar->IsEnabled() )
121 rStateSet.AddState( AccessibleStateType::ENABLED );
122 rStateSet.AddState( AccessibleStateType::SENSITIVE );
125 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
127 if ( m_pTabBar->HasFocus() )
128 rStateSet.AddState( AccessibleStateType::FOCUSED );
130 rStateSet.AddState( AccessibleStateType::VISIBLE );
132 if ( m_pTabBar->IsVisible() )
133 rStateSet.AddState( AccessibleStateType::SHOWING );
135 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
136 rStateSet.AddState( AccessibleStateType::RESIZABLE );
141 // OCommonAccessibleComponent
144 awt::Rectangle AccessibleTabBar::implGetBounds()
146 awt::Rectangle aBounds;
147 if ( m_pTabBar )
148 aBounds = AWTRectangle( tools::Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
150 return aBounds;
154 // XInterface
157 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar, OAccessibleExtendedComponentHelper, AccessibleTabBar_BASE )
160 // XTypeProvider
163 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar, OAccessibleExtendedComponentHelper, AccessibleTabBar_BASE )
166 // XComponent
169 void AccessibleTabBar::disposing()
171 AccessibleTabBarBase::disposing();
173 // dispose all children
174 for (Reference<XAccessible>& i : m_aAccessibleChildren)
176 Reference< XComponent > xComponent( i, UNO_QUERY );
177 if ( xComponent.is() )
178 xComponent->dispose();
180 m_aAccessibleChildren.clear();
184 // XServiceInfo
187 OUString AccessibleTabBar::getImplementationName()
189 return OUString( "com.sun.star.comp.svtools.AccessibleTabBar" );
193 sal_Bool AccessibleTabBar::supportsService( const OUString& rServiceName )
195 return cppu::supportsService(this, rServiceName);
199 Sequence< OUString > AccessibleTabBar::getSupportedServiceNames()
201 return { "com.sun.star.awt.AccessibleTabBar" };
205 // XAccessible
208 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( )
210 OExternalLockGuard aGuard( this );
212 return this;
216 // XAccessibleContext
219 sal_Int32 AccessibleTabBar::getAccessibleChildCount()
221 OExternalLockGuard aGuard( this );
223 return m_aAccessibleChildren.size();
227 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int32 i )
229 OExternalLockGuard aGuard( this );
231 if ( i < 0 || i >= static_cast<sal_Int32>(m_aAccessibleChildren.size()) )
232 throw IndexOutOfBoundsException();
234 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
235 if ( !xChild.is() )
237 if ( m_pTabBar )
239 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
241 if ( i < nCount )
243 vcl::Window* pChild = m_pTabBar->GetAccessibleChildWindow( static_cast<sal_uInt16>(i) );
244 if ( pChild )
245 xChild = pChild->GetAccessible();
247 else if ( i == nCount )
249 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
252 // insert into child list
253 m_aAccessibleChildren[i] = xChild;
257 return xChild;
261 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( )
263 OExternalLockGuard aGuard( this );
265 Reference< XAccessible > xParent;
266 if ( m_pTabBar )
268 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
269 if ( pParent )
270 xParent = pParent->GetAccessible();
273 return xParent;
277 sal_Int32 AccessibleTabBar::getAccessibleIndexInParent( )
279 OExternalLockGuard aGuard( this );
281 sal_Int32 nIndexInParent = -1;
282 if ( m_pTabBar )
284 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
285 if ( pParent )
287 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
289 vcl::Window* pChild = pParent->GetAccessibleChildWindow( i );
290 if ( pChild == static_cast< vcl::Window* >( m_pTabBar ) )
292 nIndexInParent = i;
293 break;
299 return nIndexInParent;
303 sal_Int16 AccessibleTabBar::getAccessibleRole( )
305 OExternalLockGuard aGuard( this );
307 return AccessibleRole::PANEL;
311 OUString AccessibleTabBar::getAccessibleDescription( )
313 OExternalLockGuard aGuard( this );
315 OUString sDescription;
316 if ( m_pTabBar )
317 sDescription = m_pTabBar->GetAccessibleDescription();
319 return sDescription;
323 OUString AccessibleTabBar::getAccessibleName( )
325 OExternalLockGuard aGuard( this );
327 OUString sName;
328 if ( m_pTabBar )
329 sName = m_pTabBar->GetAccessibleName();
331 return sName;
335 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( )
337 OExternalLockGuard aGuard( this );
339 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
340 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
341 return xSet;
345 Reference< XAccessibleStateSet > AccessibleTabBar::getAccessibleStateSet( )
347 OExternalLockGuard aGuard( this );
349 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
350 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
352 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
354 FillAccessibleStateSet( *pStateSetHelper );
356 else
358 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
361 return xSet;
365 Locale AccessibleTabBar::getLocale( )
367 OExternalLockGuard aGuard( this );
369 return Application::GetSettings().GetLanguageTag().getLocale();
373 // XAccessibleComponent
376 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint )
378 OExternalLockGuard aGuard( this );
380 Reference< XAccessible > xChild;
381 for ( size_t i = 0; i < m_aAccessibleChildren.size(); ++i )
383 Reference< XAccessible > xAcc = getAccessibleChild( i );
384 if ( xAcc.is() )
386 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
387 if ( xComp.is() )
389 tools::Rectangle aRect = VCLRectangle( xComp->getBounds() );
390 Point aPos = VCLPoint( rPoint );
391 if ( aRect.IsInside( aPos ) )
393 xChild = xAcc;
394 break;
400 return xChild;
404 void AccessibleTabBar::grabFocus( )
406 OExternalLockGuard aGuard( this );
408 if ( m_pTabBar )
409 m_pTabBar->GrabFocus();
413 sal_Int32 AccessibleTabBar::getForeground( )
415 OExternalLockGuard aGuard( this );
417 Color nColor;
418 if ( m_pTabBar )
420 if ( m_pTabBar->IsControlForeground() )
421 nColor = m_pTabBar->GetControlForeground();
422 else
424 vcl::Font aFont;
425 if ( m_pTabBar->IsControlFont() )
426 aFont = m_pTabBar->GetControlFont();
427 else
428 aFont = m_pTabBar->GetFont();
429 nColor = aFont.GetColor();
433 return sal_Int32(nColor);
437 sal_Int32 AccessibleTabBar::getBackground( )
439 OExternalLockGuard aGuard( this );
441 Color nColor;
442 if ( m_pTabBar )
444 if ( m_pTabBar->IsControlBackground() )
445 nColor = m_pTabBar->GetControlBackground();
446 else
447 nColor = m_pTabBar->GetBackground().GetColor();
450 return sal_Int32(nColor);
454 // XAccessibleExtendedComponent
457 Reference< awt::XFont > AccessibleTabBar::getFont( )
459 OExternalLockGuard aGuard( this );
461 Reference< awt::XFont > xFont;
462 if ( m_pTabBar )
464 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
465 if ( xDev.is() )
467 vcl::Font aFont;
468 if ( m_pTabBar->IsControlFont() )
469 aFont = m_pTabBar->GetControlFont();
470 else
471 aFont = m_pTabBar->GetFont();
472 VCLXFont* pVCLXFont = new VCLXFont;
473 pVCLXFont->Init( *xDev.get(), aFont );
474 xFont = pVCLXFont;
478 return xFont;
482 OUString AccessibleTabBar::getTitledBorderText( )
484 OExternalLockGuard aGuard( this );
486 OUString sText;
487 if ( m_pTabBar )
488 sText = m_pTabBar->GetText();
490 return sText;
494 OUString AccessibleTabBar::getToolTipText( )
496 OExternalLockGuard aGuard( this );
498 OUString sText;
499 if ( m_pTabBar )
500 sText = m_pTabBar->GetQuickHelpText();
502 return sText;
506 } // namespace accessibility
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */