Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / accessibletabbarpage.cxx
blobc3d6533261eeaf862e15d9881453d7786b204b03
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 <accessibility/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 <cppuhelper/supportsservice.hxx>
26 #include <unotools/accessiblestatesethelper.hxx>
27 #include <unotools/accessiblerelationsethelper.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/settings.hxx>
30 #include <toolkit/helper/convert.hxx>
34 namespace accessibility
38 using namespace ::com::sun::star::accessibility;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star;
42 using namespace ::comphelper;
45 // class AccessibleTabBarPage
48 AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent )
49 :AccessibleTabBarBase( pTabBar )
50 ,m_nPageId( nPageId )
51 ,m_xParent( rxParent )
53 m_bEnabled = IsEnabled();
54 m_bShowing = IsShowing();
55 m_bSelected = IsSelected();
57 if ( m_pTabBar )
58 m_sPageText = m_pTabBar->GetPageText( m_nPageId );
63 AccessibleTabBarPage::~AccessibleTabBarPage()
69 bool AccessibleTabBarPage::IsEnabled()
71 OExternalLockGuard aGuard( this );
73 bool bEnabled = false;
74 if ( m_pTabBar )
75 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId );
77 return bEnabled;
82 bool AccessibleTabBarPage::IsShowing()
84 bool bShowing = false;
86 if ( m_pTabBar && m_pTabBar->IsVisible() )
87 bShowing = true;
89 return bShowing;
94 bool AccessibleTabBarPage::IsSelected()
96 bool bSelected = false;
98 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId )
99 bSelected = true;
101 return bSelected;
106 void AccessibleTabBarPage::SetEnabled( bool bEnabled )
108 if ( m_bEnabled != bEnabled )
110 Any aOldValue[2], aNewValue[2];
111 if ( m_bEnabled )
113 aOldValue[0] <<= AccessibleStateType::SENSITIVE;
114 aOldValue[1] <<= AccessibleStateType::ENABLED;
116 else
119 aNewValue[0] <<= AccessibleStateType::ENABLED;
120 aNewValue[1] <<= AccessibleStateType::SENSITIVE;
122 m_bEnabled = bEnabled;
123 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
124 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
130 void AccessibleTabBarPage::SetShowing( bool bShowing )
132 if ( m_bShowing != bShowing )
134 Any aOldValue, aNewValue;
135 if ( m_bShowing )
136 aOldValue <<= AccessibleStateType::SHOWING;
137 else
138 aNewValue <<= AccessibleStateType::SHOWING;
139 m_bShowing = bShowing;
140 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
146 void AccessibleTabBarPage::SetSelected( bool bSelected )
148 if ( m_bSelected != bSelected )
150 Any aOldValue, aNewValue;
151 if ( m_bSelected )
152 aOldValue <<= AccessibleStateType::SELECTED;
153 else
154 aNewValue <<= AccessibleStateType::SELECTED;
155 m_bSelected = bSelected;
156 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
162 void AccessibleTabBarPage::SetPageText( const OUString& sPageText )
164 if ( !m_sPageText.equals( sPageText ) )
166 Any aOldValue, aNewValue;
167 aOldValue <<= m_sPageText;
168 aNewValue <<= sPageText;
169 m_sPageText = sPageText;
170 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
176 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
178 if ( IsEnabled() )
180 rStateSet.AddState( AccessibleStateType::ENABLED );
181 rStateSet.AddState( AccessibleStateType::SENSITIVE );
184 rStateSet.AddState( AccessibleStateType::VISIBLE );
186 if ( IsShowing() )
187 rStateSet.AddState( AccessibleStateType::SHOWING );
189 rStateSet.AddState( AccessibleStateType::SELECTABLE );
191 if ( IsSelected() )
192 rStateSet.AddState( AccessibleStateType::SELECTED );
196 // OCommonAccessibleComponent
199 awt::Rectangle AccessibleTabBarPage::implGetBounds() throw (RuntimeException)
201 awt::Rectangle aBounds;
202 if ( m_pTabBar )
204 // get bounding rectangle relative to the AccessibleTabBar
205 aBounds = AWTRectangle( m_pTabBar->GetPageRect( m_nPageId ) );
207 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar
208 Reference< XAccessible > xParent = getAccessibleParent();
209 if ( xParent.is() )
211 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
212 if ( xParentComponent.is() )
214 awt::Point aParentLoc = xParentComponent->getLocation();
216 // calculate bounding rectangle relative to the AccessibleTabBarPageList
217 aBounds.X -= aParentLoc.X;
218 aBounds.Y -= aParentLoc.Y;
223 return aBounds;
227 // XInterface
230 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
233 // XTypeProvider
236 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE )
239 // XComponent
242 void AccessibleTabBarPage::disposing()
244 AccessibleTabBarBase::disposing();
245 m_sPageText.clear();
249 // XServiceInfo
252 OUString AccessibleTabBarPage::getImplementationName() throw (RuntimeException, std::exception)
254 return OUString( "com.sun.star.comp.svtools.AccessibleTabBarPage" );
259 sal_Bool AccessibleTabBarPage::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
261 return cppu::supportsService(this, rServiceName);
266 Sequence< OUString > AccessibleTabBarPage::getSupportedServiceNames() throw (RuntimeException, std::exception)
268 Sequence< OUString > aNames(1);
269 aNames[0] = "com.sun.star.awt.AccessibleTabBarPage";
270 return aNames;
274 // XAccessible
277 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( ) throw (RuntimeException, std::exception)
279 OExternalLockGuard aGuard( this );
281 return this;
285 // XAccessibleContext
288 sal_Int32 AccessibleTabBarPage::getAccessibleChildCount() throw (RuntimeException, std::exception)
290 OExternalLockGuard aGuard( this );
292 return 0;
297 Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
299 OExternalLockGuard aGuard( this );
301 if ( i < 0 || i >= getAccessibleChildCount() )
302 throw IndexOutOfBoundsException();
304 return Reference< XAccessible >();
309 Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent( ) throw (RuntimeException, std::exception)
311 OExternalLockGuard aGuard( this );
313 return m_xParent;
318 sal_Int32 AccessibleTabBarPage::getAccessibleIndexInParent( ) throw (RuntimeException, std::exception)
320 OExternalLockGuard aGuard( this );
322 sal_Int32 nIndexInParent = -1;
323 if ( m_pTabBar )
324 nIndexInParent = m_pTabBar->GetPagePos( m_nPageId );
326 return nIndexInParent;
331 sal_Int16 AccessibleTabBarPage::getAccessibleRole( ) throw (RuntimeException, std::exception)
333 OExternalLockGuard aGuard( this );
335 return AccessibleRole::PAGE_TAB;
340 OUString AccessibleTabBarPage::getAccessibleDescription( ) throw (RuntimeException, std::exception)
342 OExternalLockGuard aGuard( this );
344 OUString sDescription;
345 if ( m_pTabBar )
346 sDescription = m_pTabBar->GetHelpText( m_nPageId );
348 return sDescription;
353 OUString AccessibleTabBarPage::getAccessibleName( ) throw (RuntimeException, std::exception)
355 OExternalLockGuard aGuard( this );
357 return m_sPageText;
362 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( ) throw (RuntimeException, std::exception)
364 OExternalLockGuard aGuard( this );
366 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
367 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
368 return xSet;
373 Reference< XAccessibleStateSet > AccessibleTabBarPage::getAccessibleStateSet( ) throw (RuntimeException, std::exception)
375 OExternalLockGuard aGuard( this );
377 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
378 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
380 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
382 FillAccessibleStateSet( *pStateSetHelper );
384 else
386 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
389 return xSet;
394 Locale AccessibleTabBarPage::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
396 OExternalLockGuard aGuard( this );
398 return Application::GetSettings().GetLanguageTag().getLocale();
402 // XAccessibleComponent
405 Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException, std::exception)
407 OExternalLockGuard aGuard( this );
409 return Reference< XAccessible >();
414 void AccessibleTabBarPage::grabFocus( ) throw (RuntimeException, std::exception)
416 // no focus
421 sal_Int32 AccessibleTabBarPage::getForeground( ) throw (RuntimeException, std::exception)
423 OExternalLockGuard aGuard( this );
425 sal_Int32 nColor = 0;
426 Reference< XAccessible > xParent = getAccessibleParent();
427 if ( xParent.is() )
429 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
430 if ( xParentComp.is() )
431 nColor = xParentComp->getForeground();
434 return nColor;
439 sal_Int32 AccessibleTabBarPage::getBackground( ) throw (RuntimeException, std::exception)
441 OExternalLockGuard aGuard( this );
443 sal_Int32 nColor = 0;
444 Reference< XAccessible > xParent = getAccessibleParent();
445 if ( xParent.is() )
447 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
448 if ( xParentComp.is() )
449 nColor = xParentComp->getBackground();
452 return nColor;
456 // XAccessibleExtendedComponent
459 Reference< awt::XFont > AccessibleTabBarPage::getFont( ) throw (RuntimeException, std::exception)
461 OExternalLockGuard aGuard( this );
463 Reference< awt::XFont > xFont;
464 Reference< XAccessible > xParent = getAccessibleParent();
465 if ( xParent.is() )
467 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
468 if ( xParentComp.is() )
469 xFont = xParentComp->getFont();
472 return xFont;
477 OUString AccessibleTabBarPage::getTitledBorderText( ) throw (RuntimeException, std::exception)
479 OExternalLockGuard aGuard( this );
481 return m_sPageText;
486 OUString AccessibleTabBarPage::getToolTipText( ) throw (RuntimeException, std::exception)
488 OExternalLockGuard aGuard( this );
490 return OUString();
496 } // namespace accessibility
499 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */