tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / accessibility / source / extended / accessibletabbar.cxx
blobede35977d93a6dc4736cabf9f1bb8eb492f81d60
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 <vcl/unohelp.hxx>
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;
51 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
52 :ImplInheritanceHelper( pTabBar )
54 if ( m_pTabBar )
55 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
59 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
61 Any aOldValue, aNewValue;
63 switch ( rVclWindowEvent.GetId() )
65 case VclEventId::WindowEnabled:
67 aNewValue <<= AccessibleStateType::SENSITIVE;
68 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
69 aNewValue <<= AccessibleStateType::ENABLED;
70 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
72 break;
73 case VclEventId::WindowDisabled:
75 aOldValue <<= AccessibleStateType::ENABLED;
76 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
77 aOldValue <<= AccessibleStateType::SENSITIVE;
78 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
80 break;
81 case VclEventId::WindowGetFocus:
83 aNewValue <<= AccessibleStateType::FOCUSED;
84 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
86 break;
87 case VclEventId::WindowLoseFocus:
89 aOldValue <<= AccessibleStateType::FOCUSED;
90 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
92 break;
93 case VclEventId::WindowShow:
95 aNewValue <<= AccessibleStateType::SHOWING;
96 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
98 break;
99 case VclEventId::WindowHide:
101 aOldValue <<= AccessibleStateType::SHOWING;
102 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
104 break;
105 default:
107 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
109 break;
114 void AccessibleTabBar::FillAccessibleStateSet( sal_Int64& rStateSet )
116 if ( !m_pTabBar )
117 return;
119 if ( m_pTabBar->IsEnabled() )
121 rStateSet |= AccessibleStateType::ENABLED;
122 rStateSet |= AccessibleStateType::SENSITIVE;
125 rStateSet |= AccessibleStateType::FOCUSABLE;
127 if ( m_pTabBar->HasFocus() )
128 rStateSet |= AccessibleStateType::FOCUSED;
130 rStateSet |= AccessibleStateType::VISIBLE;
132 if ( m_pTabBar->IsVisible() )
133 rStateSet |= AccessibleStateType::SHOWING;
135 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
136 rStateSet |= AccessibleStateType::RESIZABLE;
140 // OCommonAccessibleComponent
143 awt::Rectangle AccessibleTabBar::implGetBounds()
145 awt::Rectangle aBounds;
146 if ( m_pTabBar )
147 aBounds = vcl::unohelper::ConvertToAWTRect(
148 tools::Rectangle(m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel()));
150 return aBounds;
154 // XComponent
157 void AccessibleTabBar::disposing()
159 AccessibleTabBarBase::disposing();
161 // dispose all children
162 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
164 Reference< XComponent > xComponent( i, UNO_QUERY );
165 if ( xComponent.is() )
166 xComponent->dispose();
168 m_aAccessibleChildren.clear();
172 // XServiceInfo
175 OUString AccessibleTabBar::getImplementationName()
177 return u"com.sun.star.comp.svtools.AccessibleTabBar"_ustr;
181 sal_Bool AccessibleTabBar::supportsService( const OUString& rServiceName )
183 return cppu::supportsService(this, rServiceName);
187 Sequence< OUString > AccessibleTabBar::getSupportedServiceNames()
189 return { u"com.sun.star.awt.AccessibleTabBar"_ustr };
193 // XAccessible
196 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( )
198 OExternalLockGuard aGuard( this );
200 return this;
204 // XAccessibleContext
207 sal_Int64 AccessibleTabBar::getAccessibleChildCount()
209 OExternalLockGuard aGuard( this );
211 return m_aAccessibleChildren.size();
215 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int64 i )
217 OExternalLockGuard aGuard( this );
219 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
220 throw IndexOutOfBoundsException();
222 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
223 if ( !xChild.is() )
225 if ( m_pTabBar )
227 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
229 if ( i < nCount )
231 vcl::Window* pChild = m_pTabBar->GetAccessibleChildWindow( static_cast<sal_uInt16>(i) );
232 if ( pChild )
233 xChild = pChild->GetAccessible();
235 else if ( i == nCount )
237 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
240 // insert into child list
241 m_aAccessibleChildren[i] = xChild;
245 return xChild;
249 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( )
251 OExternalLockGuard aGuard( this );
253 Reference< XAccessible > xParent;
254 if ( m_pTabBar )
256 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
257 if ( pParent )
258 xParent = pParent->GetAccessible();
261 return xParent;
265 sal_Int64 AccessibleTabBar::getAccessibleIndexInParent( )
267 OExternalLockGuard aGuard( this );
269 sal_Int64 nIndexInParent = -1;
270 if ( m_pTabBar )
272 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
273 if ( pParent )
275 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
277 vcl::Window* pChild = pParent->GetAccessibleChildWindow( i );
278 if ( pChild == static_cast< vcl::Window* >( m_pTabBar ) )
280 nIndexInParent = i;
281 break;
287 return nIndexInParent;
291 sal_Int16 AccessibleTabBar::getAccessibleRole( )
293 OExternalLockGuard aGuard( this );
295 return AccessibleRole::PANEL;
298 OUString AccessibleTabBar::getAccessibleDescription( )
300 OExternalLockGuard aGuard( this );
302 if (m_pTabBar)
303 return m_pTabBar->GetAccessibleDescription();
305 return OUString();
308 OUString AccessibleTabBar::getAccessibleName( )
310 OExternalLockGuard aGuard( this );
312 if (m_pTabBar)
313 return m_pTabBar->GetAccessibleName();
315 return OUString();
318 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( )
320 OExternalLockGuard aGuard( this );
322 return new utl::AccessibleRelationSetHelper;
325 sal_Int64 AccessibleTabBar::getAccessibleStateSet( )
327 OExternalLockGuard aGuard( this );
329 sal_Int64 nStateSet = 0;
331 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
333 FillAccessibleStateSet( nStateSet );
335 else
337 nStateSet |= AccessibleStateType::DEFUNC;
340 return nStateSet;
344 Locale AccessibleTabBar::getLocale( )
346 OExternalLockGuard aGuard( this );
348 return Application::GetSettings().GetLanguageTag().getLocale();
351 // XAccessibleComponent
352 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint )
354 OExternalLockGuard aGuard( this );
356 for( sal_Int64 i = 0; i < getAccessibleChildCount(); ++i )
358 Reference< XAccessible > xAcc = getAccessibleChild( i );
359 if ( xAcc.is() )
361 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
362 if ( xComp.is() )
364 tools::Rectangle aRect = vcl::unohelper::ConvertToVCLRect(xComp->getBounds());
365 Point aPos = vcl::unohelper::ConvertToVCLPoint(rPoint);
366 if ( aRect.Contains( aPos ) )
368 return xAcc;
374 return nullptr;
377 void AccessibleTabBar::grabFocus( )
379 OExternalLockGuard aGuard( this );
381 if ( m_pTabBar )
382 m_pTabBar->GrabFocus();
386 sal_Int32 AccessibleTabBar::getForeground( )
388 OExternalLockGuard aGuard( this );
390 Color nColor;
391 if ( m_pTabBar )
393 if ( m_pTabBar->IsControlForeground() )
394 nColor = m_pTabBar->GetControlForeground();
395 else
397 vcl::Font aFont;
398 if ( m_pTabBar->IsControlFont() )
399 aFont = m_pTabBar->GetControlFont();
400 else
401 aFont = m_pTabBar->GetFont();
402 nColor = aFont.GetColor();
406 return sal_Int32(nColor);
410 sal_Int32 AccessibleTabBar::getBackground( )
412 OExternalLockGuard aGuard( this );
414 Color nColor;
415 if ( m_pTabBar )
417 if ( m_pTabBar->IsControlBackground() )
418 nColor = m_pTabBar->GetControlBackground();
419 else
420 nColor = m_pTabBar->GetBackground().GetColor();
423 return sal_Int32(nColor);
427 // XAccessibleExtendedComponent
429 OUString AccessibleTabBar::getTitledBorderText( )
431 OExternalLockGuard aGuard( this );
433 OUString sText;
434 if ( m_pTabBar )
435 sText = m_pTabBar->GetText();
437 return sText;
441 OUString AccessibleTabBar::getToolTipText( )
443 OExternalLockGuard aGuard( this );
445 OUString sText;
446 if ( m_pTabBar )
447 sText = m_pTabBar->GetQuickHelpText();
449 return sText;
453 } // namespace accessibility
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */