Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / accessibletabbar.cxx
blob518d068d65ba603a4da5f763fc5d0d746ae10acc
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/awt/XDevice.hpp>
27 #include <com/sun/star/awt/XVclWindowPeer.hpp>
28 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <comphelper/accessiblecontexthelper.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <i18nlangtag/languagetag.hxx>
33 #include <o3tl/safeint.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/settings.hxx>
36 #include <toolkit/awt/vclxfont.hxx>
37 #include <toolkit/helper/convert.hxx>
40 namespace accessibility
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::accessibility;
48 using namespace ::comphelper;
53 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
54 :ImplInheritanceHelper( pTabBar )
56 if ( m_pTabBar )
57 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
61 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
63 Any aOldValue, aNewValue;
65 switch ( rVclWindowEvent.GetId() )
67 case VclEventId::WindowEnabled:
69 aNewValue <<= AccessibleStateType::SENSITIVE;
70 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
71 aNewValue <<= AccessibleStateType::ENABLED;
72 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
74 break;
75 case VclEventId::WindowDisabled:
77 aOldValue <<= AccessibleStateType::ENABLED;
78 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
79 aOldValue <<= AccessibleStateType::SENSITIVE;
80 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
82 break;
83 case VclEventId::WindowGetFocus:
85 aNewValue <<= AccessibleStateType::FOCUSED;
86 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
88 break;
89 case VclEventId::WindowLoseFocus:
91 aOldValue <<= AccessibleStateType::FOCUSED;
92 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
94 break;
95 case VclEventId::WindowShow:
97 aNewValue <<= AccessibleStateType::SHOWING;
98 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
100 break;
101 case VclEventId::WindowHide:
103 aOldValue <<= AccessibleStateType::SHOWING;
104 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
106 break;
107 default:
109 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
111 break;
116 void AccessibleTabBar::FillAccessibleStateSet( sal_Int64& rStateSet )
118 if ( !m_pTabBar )
119 return;
121 if ( m_pTabBar->IsEnabled() )
123 rStateSet |= AccessibleStateType::ENABLED;
124 rStateSet |= AccessibleStateType::SENSITIVE;
127 rStateSet |= AccessibleStateType::FOCUSABLE;
129 if ( m_pTabBar->HasFocus() )
130 rStateSet |= AccessibleStateType::FOCUSED;
132 rStateSet |= AccessibleStateType::VISIBLE;
134 if ( m_pTabBar->IsVisible() )
135 rStateSet |= AccessibleStateType::SHOWING;
137 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
138 rStateSet |= AccessibleStateType::RESIZABLE;
142 // OCommonAccessibleComponent
145 awt::Rectangle AccessibleTabBar::implGetBounds()
147 awt::Rectangle aBounds;
148 if ( m_pTabBar )
149 aBounds = AWTRectangle( tools::Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
151 return aBounds;
155 // XComponent
158 void AccessibleTabBar::disposing()
160 AccessibleTabBarBase::disposing();
162 // dispose all children
163 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
165 Reference< XComponent > xComponent( i, UNO_QUERY );
166 if ( xComponent.is() )
167 xComponent->dispose();
169 m_aAccessibleChildren.clear();
173 // XServiceInfo
176 OUString AccessibleTabBar::getImplementationName()
178 return "com.sun.star.comp.svtools.AccessibleTabBar";
182 sal_Bool AccessibleTabBar::supportsService( const OUString& rServiceName )
184 return cppu::supportsService(this, rServiceName);
188 Sequence< OUString > AccessibleTabBar::getSupportedServiceNames()
190 return { "com.sun.star.awt.AccessibleTabBar" };
194 // XAccessible
197 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( )
199 OExternalLockGuard aGuard( this );
201 return this;
205 // XAccessibleContext
208 sal_Int64 AccessibleTabBar::getAccessibleChildCount()
210 OExternalLockGuard aGuard( this );
212 return m_aAccessibleChildren.size();
216 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int64 i )
218 OExternalLockGuard aGuard( this );
220 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
221 throw IndexOutOfBoundsException();
223 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
224 if ( !xChild.is() )
226 if ( m_pTabBar )
228 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
230 if ( i < nCount )
232 vcl::Window* pChild = m_pTabBar->GetAccessibleChildWindow( static_cast<sal_uInt16>(i) );
233 if ( pChild )
234 xChild = pChild->GetAccessible();
236 else if ( i == nCount )
238 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
241 // insert into child list
242 m_aAccessibleChildren[i] = xChild;
246 return xChild;
250 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( )
252 OExternalLockGuard aGuard( this );
254 Reference< XAccessible > xParent;
255 if ( m_pTabBar )
257 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
258 if ( pParent )
259 xParent = pParent->GetAccessible();
262 return xParent;
266 sal_Int64 AccessibleTabBar::getAccessibleIndexInParent( )
268 OExternalLockGuard aGuard( this );
270 sal_Int64 nIndexInParent = -1;
271 if ( m_pTabBar )
273 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
274 if ( pParent )
276 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
278 vcl::Window* pChild = pParent->GetAccessibleChildWindow( i );
279 if ( pChild == static_cast< vcl::Window* >( m_pTabBar ) )
281 nIndexInParent = i;
282 break;
288 return nIndexInParent;
292 sal_Int16 AccessibleTabBar::getAccessibleRole( )
294 OExternalLockGuard aGuard( this );
296 return AccessibleRole::PANEL;
300 OUString AccessibleTabBar::getAccessibleDescription( )
302 OExternalLockGuard aGuard( this );
304 OUString sDescription;
305 if ( m_pTabBar )
306 sDescription = m_pTabBar->GetAccessibleDescription();
308 return sDescription;
312 OUString AccessibleTabBar::getAccessibleName( )
314 OExternalLockGuard aGuard( this );
316 OUString sName;
317 if ( m_pTabBar )
318 sName = m_pTabBar->GetAccessibleName();
320 return sName;
324 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( )
326 OExternalLockGuard aGuard( this );
328 return new utl::AccessibleRelationSetHelper;
332 sal_Int64 AccessibleTabBar::getAccessibleStateSet( )
334 OExternalLockGuard aGuard( this );
336 sal_Int64 nStateSet = 0;
338 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
340 FillAccessibleStateSet( nStateSet );
342 else
344 nStateSet |= AccessibleStateType::DEFUNC;
347 return nStateSet;
351 Locale AccessibleTabBar::getLocale( )
353 OExternalLockGuard aGuard( this );
355 return Application::GetSettings().GetLanguageTag().getLocale();
359 // XAccessibleComponent
362 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint )
364 OExternalLockGuard aGuard( this );
366 Reference< XAccessible > xChild;
367 for ( size_t i = 0; i < m_aAccessibleChildren.size(); ++i )
369 Reference< XAccessible > xAcc = getAccessibleChild( i );
370 if ( xAcc.is() )
372 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
373 if ( xComp.is() )
375 tools::Rectangle aRect = VCLRectangle( xComp->getBounds() );
376 Point aPos = VCLPoint( rPoint );
377 if ( aRect.Contains( aPos ) )
379 xChild = xAcc;
380 break;
386 return xChild;
390 void AccessibleTabBar::grabFocus( )
392 OExternalLockGuard aGuard( this );
394 if ( m_pTabBar )
395 m_pTabBar->GrabFocus();
399 sal_Int32 AccessibleTabBar::getForeground( )
401 OExternalLockGuard aGuard( this );
403 Color nColor;
404 if ( m_pTabBar )
406 if ( m_pTabBar->IsControlForeground() )
407 nColor = m_pTabBar->GetControlForeground();
408 else
410 vcl::Font aFont;
411 if ( m_pTabBar->IsControlFont() )
412 aFont = m_pTabBar->GetControlFont();
413 else
414 aFont = m_pTabBar->GetFont();
415 nColor = aFont.GetColor();
419 return sal_Int32(nColor);
423 sal_Int32 AccessibleTabBar::getBackground( )
425 OExternalLockGuard aGuard( this );
427 Color nColor;
428 if ( m_pTabBar )
430 if ( m_pTabBar->IsControlBackground() )
431 nColor = m_pTabBar->GetControlBackground();
432 else
433 nColor = m_pTabBar->GetBackground().GetColor();
436 return sal_Int32(nColor);
440 // XAccessibleExtendedComponent
443 Reference< awt::XFont > AccessibleTabBar::getFont( )
445 OExternalLockGuard aGuard( this );
447 Reference< awt::XFont > xFont;
448 if ( m_pTabBar )
450 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
451 if ( xDev.is() )
453 vcl::Font aFont;
454 if ( m_pTabBar->IsControlFont() )
455 aFont = m_pTabBar->GetControlFont();
456 else
457 aFont = m_pTabBar->GetFont();
458 rtl::Reference<VCLXFont> pVCLXFont = new VCLXFont;
459 pVCLXFont->Init( *xDev, aFont );
460 xFont = pVCLXFont;
464 return xFont;
468 OUString AccessibleTabBar::getTitledBorderText( )
470 OExternalLockGuard aGuard( this );
472 OUString sText;
473 if ( m_pTabBar )
474 sText = m_pTabBar->GetText();
476 return sText;
480 OUString AccessibleTabBar::getToolTipText( )
482 OExternalLockGuard aGuard( this );
484 OUString sText;
485 if ( m_pTabBar )
486 sText = m_pTabBar->GetQuickHelpText();
488 return sText;
492 } // namespace accessibility
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */