Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / accessibility / source / extended / accessibletabbarpage.cxx
blob581ee98cde763b87bc9081f3af31c46df13d8a56
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 <cppuhelper/supportsservice.hxx>
27 #include <unotools/accessiblestatesethelper.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/settings.hxx>
31 #include <toolkit/helper/convert.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;
46 // class AccessibleTabBarPage
49 AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent )
50 :AccessibleTabBarBase( pTabBar )
51 ,m_nPageId( nPageId )
52 ,m_xParent( rxParent )
54 m_bShowing = IsShowing();
55 m_bSelected = IsSelected();
57 if ( m_pTabBar )
58 m_sPageText = m_pTabBar->GetPageText( m_nPageId );
62 bool AccessibleTabBarPage::IsEnabled()
64 OExternalLockGuard aGuard( this );
66 bool bEnabled = false;
67 if ( m_pTabBar )
68 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
70 return bEnabled;
74 bool AccessibleTabBarPage::IsShowing() const
76 bool bShowing = false;
78 if ( m_pTabBar && m_pTabBar->IsVisible() )
79 bShowing = true;
81 return bShowing;
85 bool AccessibleTabBarPage::IsSelected() const
87 bool bSelected = false;
89 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
90 bSelected = true;
92 return bSelected;
96 void AccessibleTabBarPage::SetShowing( bool bShowing )
98 if ( m_bShowing != bShowing )
100 Any aOldValue, aNewValue;
101 if ( m_bShowing )
102 aOldValue <<= AccessibleStateType::SHOWING;
103 else
104 aNewValue <<= AccessibleStateType::SHOWING;
105 m_bShowing = bShowing;
106 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
111 void AccessibleTabBarPage::SetSelected( bool bSelected )
113 if ( m_bSelected != bSelected )
115 Any aOldValue, aNewValue;
116 if ( m_bSelected )
117 aOldValue <<= AccessibleStateType::SELECTED;
118 else
119 aNewValue <<= AccessibleStateType::SELECTED;
120 m_bSelected = bSelected;
121 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
126 void AccessibleTabBarPage::SetPageText( const OUString& sPageText )
128 if ( m_sPageText != sPageText )
130 Any aOldValue, aNewValue;
131 aOldValue <<= m_sPageText;
132 aNewValue <<= sPageText;
133 m_sPageText = sPageText;
134 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
139 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
141 if ( IsEnabled() )
143 rStateSet.AddState( AccessibleStateType::ENABLED );
144 rStateSet.AddState( AccessibleStateType::SENSITIVE );
147 rStateSet.AddState( AccessibleStateType::VISIBLE );
149 if ( IsShowing() )
150 rStateSet.AddState( AccessibleStateType::SHOWING );
152 rStateSet.AddState( AccessibleStateType::SELECTABLE );
154 if ( IsSelected() )
155 rStateSet.AddState( AccessibleStateType::SELECTED );
159 // OCommonAccessibleComponent
162 awt::Rectangle AccessibleTabBarPage::implGetBounds()
164 awt::Rectangle aBounds;
165 if ( m_pTabBar )
167 // get bounding rectangle relative to the AccessibleTabBar
168 aBounds = AWTRectangle( m_pTabBar->GetPageRect( m_nPageId ) );
170 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
171 Reference< XAccessible > xParent = getAccessibleParent();
172 if ( xParent.is() )
174 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
175 if ( xParentComponent.is() )
177 awt::Point aParentLoc = xParentComponent->getLocation();
179 // calculate bounding rectangle relative to the AccessibleTabBarPageList
180 aBounds.X -= aParentLoc.X;
181 aBounds.Y -= aParentLoc.Y;
186 return aBounds;
190 // XInterface
193 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage, OAccessibleExtendedComponentHelper, AccessibleTabBarPage_BASE )
196 // XTypeProvider
199 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage, OAccessibleExtendedComponentHelper, AccessibleTabBarPage_BASE )
202 // XComponent
205 void AccessibleTabBarPage::disposing()
207 AccessibleTabBarBase::disposing();
208 m_sPageText.clear();
212 // XServiceInfo
215 OUString AccessibleTabBarPage::getImplementationName()
217 return "com.sun.star.comp.svtools.AccessibleTabBarPage";
221 sal_Bool AccessibleTabBarPage::supportsService( const OUString& rServiceName )
223 return cppu::supportsService(this, rServiceName);
227 Sequence< OUString > AccessibleTabBarPage::getSupportedServiceNames()
229 return { "com.sun.star.awt.AccessibleTabBarPage" };
233 // XAccessible
236 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( )
238 OExternalLockGuard aGuard( this );
240 return this;
244 // XAccessibleContext
247 sal_Int32 AccessibleTabBarPage::getAccessibleChildCount()
249 return 0;
253 Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int32 )
255 OExternalLockGuard aGuard( this );
257 throw IndexOutOfBoundsException();
261 Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent( )
263 OExternalLockGuard aGuard( this );
265 return m_xParent;
269 sal_Int32 AccessibleTabBarPage::getAccessibleIndexInParent( )
271 OExternalLockGuard aGuard( this );
273 sal_Int32 nIndexInParent = -1;
274 if ( m_pTabBar )
275 nIndexInParent = m_pTabBar->GetPagePos( m_nPageId );
277 return nIndexInParent;
281 sal_Int16 AccessibleTabBarPage::getAccessibleRole( )
283 return AccessibleRole::PAGE_TAB;
287 OUString AccessibleTabBarPage::getAccessibleDescription( )
289 OExternalLockGuard aGuard( this );
291 OUString sDescription;
292 if ( m_pTabBar )
293 sDescription = m_pTabBar->GetHelpText( m_nPageId );
295 return sDescription;
299 OUString AccessibleTabBarPage::getAccessibleName( )
301 OExternalLockGuard aGuard( this );
303 return m_sPageText;
307 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( )
309 OExternalLockGuard aGuard( this );
311 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
312 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
313 return xSet;
317 Reference< XAccessibleStateSet > AccessibleTabBarPage::getAccessibleStateSet( )
319 OExternalLockGuard aGuard( this );
321 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
322 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
324 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
326 FillAccessibleStateSet( *pStateSetHelper );
328 else
330 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
333 return xSet;
337 Locale AccessibleTabBarPage::getLocale( )
339 OExternalLockGuard aGuard( this );
341 return Application::GetSettings().GetLanguageTag().getLocale();
345 // XAccessibleComponent
348 Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& )
350 return Reference< XAccessible >();
354 void AccessibleTabBarPage::grabFocus( )
356 // no focus
360 sal_Int32 AccessibleTabBarPage::getForeground( )
362 OExternalLockGuard aGuard( this );
364 sal_Int32 nColor = 0;
365 Reference< XAccessible > xParent = getAccessibleParent();
366 if ( xParent.is() )
368 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
369 if ( xParentComp.is() )
370 nColor = xParentComp->getForeground();
373 return nColor;
377 sal_Int32 AccessibleTabBarPage::getBackground( )
379 OExternalLockGuard aGuard( this );
381 sal_Int32 nColor = 0;
382 Reference< XAccessible > xParent = getAccessibleParent();
383 if ( xParent.is() )
385 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
386 if ( xParentComp.is() )
387 nColor = xParentComp->getBackground();
390 return nColor;
394 // XAccessibleExtendedComponent
397 Reference< awt::XFont > AccessibleTabBarPage::getFont( )
399 OExternalLockGuard aGuard( this );
401 Reference< awt::XFont > xFont;
402 Reference< XAccessible > xParent = getAccessibleParent();
403 if ( xParent.is() )
405 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
406 if ( xParentComp.is() )
407 xFont = xParentComp->getFont();
410 return xFont;
414 OUString AccessibleTabBarPage::getTitledBorderText( )
416 OExternalLockGuard aGuard( this );
418 return m_sPageText;
422 OUString AccessibleTabBarPage::getToolTipText( )
424 return OUString();
428 } // namespace accessibility
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */