tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / accessibility / source / extended / accessibletabbarpage.cxx
blobf2de152f871f95336e1c43bebeb3e7692591b47c
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/accessibletabbarpage.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <comphelper/accessiblecontexthelper.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/settings.hxx>
31 #include <vcl/unohelp.hxx>
32 #include <i18nlangtag/languagetag.hxx>
35 namespace accessibility
39 using namespace ::com::sun::star::accessibility;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star;
43 using namespace ::comphelper;
48 AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent )
49 :ImplInheritanceHelper( pTabBar )
50 ,m_nPageId( nPageId )
51 ,m_xParent( rxParent )
53 m_bShowing = IsShowing();
54 m_bSelected = IsSelected();
56 if ( m_pTabBar )
57 m_sPageText = m_pTabBar->GetPageText( m_nPageId );
61 bool AccessibleTabBarPage::IsEnabled()
63 OExternalLockGuard aGuard( this );
65 bool bEnabled = false;
66 if ( m_pTabBar )
67 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
69 return bEnabled;
73 bool AccessibleTabBarPage::IsShowing() const
75 bool bShowing = false;
77 if ( m_pTabBar && m_pTabBar->IsVisible() )
78 bShowing = true;
80 return bShowing;
84 bool AccessibleTabBarPage::IsSelected() const
86 bool bSelected = false;
88 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
89 bSelected = true;
91 return bSelected;
95 void AccessibleTabBarPage::SetShowing( bool bShowing )
97 if ( m_bShowing != bShowing )
99 Any aOldValue, aNewValue;
100 if ( m_bShowing )
101 aOldValue <<= AccessibleStateType::SHOWING;
102 else
103 aNewValue <<= AccessibleStateType::SHOWING;
104 m_bShowing = bShowing;
105 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
110 void AccessibleTabBarPage::SetSelected( bool bSelected )
112 if ( m_bSelected != bSelected )
114 Any aOldValue, aNewValue;
115 if ( m_bSelected )
116 aOldValue <<= AccessibleStateType::SELECTED;
117 else
118 aNewValue <<= AccessibleStateType::SELECTED;
119 m_bSelected = bSelected;
120 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
125 void AccessibleTabBarPage::SetPageText( const OUString& sPageText )
127 if ( m_sPageText != sPageText )
129 Any aOldValue, aNewValue;
130 aOldValue <<= m_sPageText;
131 aNewValue <<= sPageText;
132 m_sPageText = sPageText;
133 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
138 void AccessibleTabBarPage::FillAccessibleStateSet( sal_Int64& rStateSet )
140 if ( IsEnabled() )
142 rStateSet |= AccessibleStateType::ENABLED;
143 rStateSet |= AccessibleStateType::SENSITIVE;
146 rStateSet |= AccessibleStateType::VISIBLE;
148 if ( IsShowing() )
149 rStateSet |= AccessibleStateType::SHOWING;
151 rStateSet |= AccessibleStateType::SELECTABLE;
153 if ( IsSelected() )
154 rStateSet |= AccessibleStateType::SELECTED;
158 // OCommonAccessibleComponent
161 awt::Rectangle AccessibleTabBarPage::implGetBounds()
163 awt::Rectangle aBounds;
164 if ( m_pTabBar )
166 // get bounding rectangle relative to the AccessibleTabBar
167 aBounds = vcl::unohelper::ConvertToAWTRect(m_pTabBar->GetPageRect(m_nPageId));
169 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
170 Reference< XAccessible > xParent = getAccessibleParent();
171 if ( xParent.is() )
173 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
174 if ( xParentComponent.is() )
176 awt::Point aParentLoc = xParentComponent->getLocation();
178 // calculate bounding rectangle relative to the AccessibleTabBarPageList
179 aBounds.X -= aParentLoc.X;
180 aBounds.Y -= aParentLoc.Y;
185 return aBounds;
189 // XComponent
192 void AccessibleTabBarPage::disposing()
194 AccessibleTabBarBase::disposing();
195 m_sPageText.clear();
199 // XServiceInfo
202 OUString AccessibleTabBarPage::getImplementationName()
204 return u"com.sun.star.comp.svtools.AccessibleTabBarPage"_ustr;
208 sal_Bool AccessibleTabBarPage::supportsService( const OUString& rServiceName )
210 return cppu::supportsService(this, rServiceName);
214 Sequence< OUString > AccessibleTabBarPage::getSupportedServiceNames()
216 return { u"com.sun.star.awt.AccessibleTabBarPage"_ustr };
220 // XAccessible
223 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( )
225 OExternalLockGuard aGuard( this );
227 return this;
231 // XAccessibleContext
234 sal_Int64 AccessibleTabBarPage::getAccessibleChildCount()
236 return 0;
240 Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int64 )
242 OExternalLockGuard aGuard( this );
244 throw IndexOutOfBoundsException();
248 Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent( )
250 OExternalLockGuard aGuard( this );
252 return m_xParent;
256 sal_Int64 AccessibleTabBarPage::getAccessibleIndexInParent( )
258 OExternalLockGuard aGuard( this );
260 sal_Int64 nIndexInParent = -1;
261 if ( m_pTabBar )
262 nIndexInParent = m_pTabBar->GetPagePos( m_nPageId );
264 return nIndexInParent;
267 sal_Int16 AccessibleTabBarPage::getAccessibleRole( )
269 return AccessibleRole::PAGE_TAB;
272 OUString AccessibleTabBarPage::getAccessibleDescription( )
274 OExternalLockGuard aGuard( this );
276 if (m_pTabBar)
277 return m_pTabBar->GetHelpText(m_nPageId);
279 return OUString();
282 OUString AccessibleTabBarPage::getAccessibleName( )
284 OExternalLockGuard aGuard( this );
286 return m_sPageText;
289 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( )
291 OExternalLockGuard aGuard( this );
293 return new utl::AccessibleRelationSetHelper;
296 sal_Int64 AccessibleTabBarPage::getAccessibleStateSet( )
298 OExternalLockGuard aGuard( this );
300 sal_Int64 nStateSet = 0;
302 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
304 FillAccessibleStateSet( nStateSet );
306 else
308 nStateSet |= AccessibleStateType::DEFUNC;
311 return nStateSet;
315 Locale AccessibleTabBarPage::getLocale( )
317 OExternalLockGuard aGuard( this );
319 return Application::GetSettings().GetLanguageTag().getLocale();
323 // XAccessibleComponent
326 Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& )
328 return Reference< XAccessible >();
332 void AccessibleTabBarPage::grabFocus( )
334 // no focus
338 sal_Int32 AccessibleTabBarPage::getForeground( )
340 OExternalLockGuard aGuard( this );
342 sal_Int32 nColor = 0;
343 Reference< XAccessible > xParent = getAccessibleParent();
344 if ( xParent.is() )
346 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
347 if ( xParentComp.is() )
348 nColor = xParentComp->getForeground();
351 return nColor;
355 sal_Int32 AccessibleTabBarPage::getBackground( )
357 OExternalLockGuard aGuard( this );
359 sal_Int32 nColor = 0;
360 Reference< XAccessible > xParent = getAccessibleParent();
361 if ( xParent.is() )
363 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
364 if ( xParentComp.is() )
365 nColor = xParentComp->getBackground();
368 return nColor;
372 // XAccessibleExtendedComponent
374 OUString AccessibleTabBarPage::getTitledBorderText( )
376 OExternalLockGuard aGuard( this );
378 return m_sPageText;
382 OUString AccessibleTabBarPage::getToolTipText( )
384 return OUString();
388 } // namespace accessibility
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */