Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / accessibletabbar.cxx
blob5a368d7b4629fe81e57d5ce15d74c7b165f1caa7
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/accessibletabbar.hxx>
21 #include <svtools/tabbar.hxx>
22 #include <accessibility/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 <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/awt/vclxfont.hxx>
32 #include <toolkit/helper/convert.hxx>
34 #include <vector>
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;
49 // class AccessibleTabBar
52 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar )
53 :AccessibleTabBarBase( pTabBar )
55 if ( m_pTabBar )
56 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
61 AccessibleTabBar::~AccessibleTabBar()
67 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
69 Any aOldValue, aNewValue;
71 switch ( rVclWindowEvent.GetId() )
73 case VCLEVENT_WINDOW_ENABLED:
75 aNewValue <<= AccessibleStateType::SENSITIVE;
76 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
77 aNewValue <<= AccessibleStateType::ENABLED;
78 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
80 break;
81 case VCLEVENT_WINDOW_DISABLED:
83 aOldValue <<= AccessibleStateType::ENABLED;
84 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
85 aOldValue <<= AccessibleStateType::SENSITIVE;
86 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
88 break;
89 case VCLEVENT_WINDOW_GETFOCUS:
91 aNewValue <<= AccessibleStateType::FOCUSED;
92 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
94 break;
95 case VCLEVENT_WINDOW_LOSEFOCUS:
97 aOldValue <<= AccessibleStateType::FOCUSED;
98 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
100 break;
101 case VCLEVENT_WINDOW_SHOW:
103 aNewValue <<= AccessibleStateType::SHOWING;
104 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
106 break;
107 case VCLEVENT_WINDOW_HIDE:
109 aOldValue <<= AccessibleStateType::SHOWING;
110 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
112 break;
113 default:
115 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
117 break;
123 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
125 if ( m_pTabBar )
127 if ( m_pTabBar->IsEnabled() )
129 rStateSet.AddState( AccessibleStateType::ENABLED );
130 rStateSet.AddState( AccessibleStateType::SENSITIVE );
133 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
135 if ( m_pTabBar->HasFocus() )
136 rStateSet.AddState( AccessibleStateType::FOCUSED );
138 rStateSet.AddState( AccessibleStateType::VISIBLE );
140 if ( m_pTabBar->IsVisible() )
141 rStateSet.AddState( AccessibleStateType::SHOWING );
143 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
144 rStateSet.AddState( AccessibleStateType::RESIZABLE );
149 // OCommonAccessibleComponent
152 awt::Rectangle AccessibleTabBar::implGetBounds() throw (RuntimeException)
154 awt::Rectangle aBounds;
155 if ( m_pTabBar )
156 aBounds = AWTRectangle( Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
158 return aBounds;
162 // XInterface
165 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
168 // XTypeProvider
171 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE )
174 // XComponent
177 void AccessibleTabBar::disposing()
179 AccessibleTabBarBase::disposing();
181 // dispose all children
182 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
184 Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
185 if ( xComponent.is() )
186 xComponent->dispose();
188 m_aAccessibleChildren.clear();
192 // XServiceInfo
195 OUString AccessibleTabBar::getImplementationName() throw (RuntimeException, std::exception)
197 return OUString( "com.sun.star.comp.svtools.AccessibleTabBar" );
202 sal_Bool AccessibleTabBar::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
204 return cppu::supportsService(this, rServiceName);
209 Sequence< OUString > AccessibleTabBar::getSupportedServiceNames() throw (RuntimeException, std::exception)
211 Sequence< OUString > aNames(1);
212 aNames[0] = "com.sun.star.awt.AccessibleTabBar";
213 return aNames;
217 // XAccessible
220 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( ) throw (RuntimeException, std::exception)
222 OExternalLockGuard aGuard( this );
224 return this;
228 // XAccessibleContext
231 sal_Int32 AccessibleTabBar::getAccessibleChildCount() throw (RuntimeException, std::exception)
233 OExternalLockGuard aGuard( this );
235 return m_aAccessibleChildren.size();
240 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
242 OExternalLockGuard aGuard( this );
244 if ( i < 0 || i >= getAccessibleChildCount() )
245 throw IndexOutOfBoundsException();
247 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
248 if ( !xChild.is() )
250 if ( m_pTabBar )
252 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
254 if ( i < nCount )
256 vcl::Window* pChild = m_pTabBar->GetAccessibleChildWindow( (sal_uInt16)i );
257 if ( pChild )
258 xChild = pChild->GetAccessible();
260 else if ( i == nCount )
262 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
265 // insert into child list
266 m_aAccessibleChildren[i] = xChild;
270 return xChild;
275 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( ) throw (RuntimeException, std::exception)
277 OExternalLockGuard aGuard( this );
279 Reference< XAccessible > xParent;
280 if ( m_pTabBar )
282 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
283 if ( pParent )
284 xParent = pParent->GetAccessible();
287 return xParent;
292 sal_Int32 AccessibleTabBar::getAccessibleIndexInParent( ) throw (RuntimeException, std::exception)
294 OExternalLockGuard aGuard( this );
296 sal_Int32 nIndexInParent = -1;
297 if ( m_pTabBar )
299 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
300 if ( pParent )
302 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
304 vcl::Window* pChild = pParent->GetAccessibleChildWindow( i );
305 if ( pChild == static_cast< vcl::Window* >( m_pTabBar ) )
307 nIndexInParent = i;
308 break;
314 return nIndexInParent;
319 sal_Int16 AccessibleTabBar::getAccessibleRole( ) throw (RuntimeException, std::exception)
321 OExternalLockGuard aGuard( this );
323 return AccessibleRole::PANEL;
328 OUString AccessibleTabBar::getAccessibleDescription( ) throw (RuntimeException, std::exception)
330 OExternalLockGuard aGuard( this );
332 OUString sDescription;
333 if ( m_pTabBar )
334 sDescription = m_pTabBar->GetAccessibleDescription();
336 return sDescription;
341 OUString AccessibleTabBar::getAccessibleName( ) throw (RuntimeException, std::exception)
343 OExternalLockGuard aGuard( this );
345 OUString sName;
346 if ( m_pTabBar )
347 sName = m_pTabBar->GetAccessibleName();
349 return sName;
354 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( ) throw (RuntimeException, std::exception)
356 OExternalLockGuard aGuard( this );
358 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
359 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
360 return xSet;
365 Reference< XAccessibleStateSet > AccessibleTabBar::getAccessibleStateSet( ) throw (RuntimeException, std::exception)
367 OExternalLockGuard aGuard( this );
369 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
370 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
372 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
374 FillAccessibleStateSet( *pStateSetHelper );
376 else
378 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
381 return xSet;
386 Locale AccessibleTabBar::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
388 OExternalLockGuard aGuard( this );
390 return Application::GetSettings().GetLanguageTag().getLocale();
394 // XAccessibleComponent
397 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException, std::exception)
399 OExternalLockGuard aGuard( this );
401 Reference< XAccessible > xChild;
402 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
404 Reference< XAccessible > xAcc = getAccessibleChild( i );
405 if ( xAcc.is() )
407 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
408 if ( xComp.is() )
410 Rectangle aRect = VCLRectangle( xComp->getBounds() );
411 Point aPos = VCLPoint( rPoint );
412 if ( aRect.IsInside( aPos ) )
414 xChild = xAcc;
415 break;
421 return xChild;
426 void AccessibleTabBar::grabFocus( ) throw (RuntimeException, std::exception)
428 OExternalLockGuard aGuard( this );
430 if ( m_pTabBar )
431 m_pTabBar->GrabFocus();
436 sal_Int32 AccessibleTabBar::getForeground( ) throw (RuntimeException, std::exception)
438 OExternalLockGuard aGuard( this );
440 sal_Int32 nColor = 0;
441 if ( m_pTabBar )
443 if ( m_pTabBar->IsControlForeground() )
444 nColor = m_pTabBar->GetControlForeground().GetColor();
445 else
447 vcl::Font aFont;
448 if ( m_pTabBar->IsControlFont() )
449 aFont = m_pTabBar->GetControlFont();
450 else
451 aFont = m_pTabBar->GetFont();
452 nColor = aFont.GetColor().GetColor();
456 return nColor;
461 sal_Int32 AccessibleTabBar::getBackground( ) throw (RuntimeException, std::exception)
463 OExternalLockGuard aGuard( this );
465 sal_Int32 nColor = 0;
466 if ( m_pTabBar )
468 if ( m_pTabBar->IsControlBackground() )
469 nColor = m_pTabBar->GetControlBackground().GetColor();
470 else
471 nColor = m_pTabBar->GetBackground().GetColor().GetColor();
474 return nColor;
478 // XAccessibleExtendedComponent
481 Reference< awt::XFont > AccessibleTabBar::getFont( ) throw (RuntimeException, std::exception)
483 OExternalLockGuard aGuard( this );
485 Reference< awt::XFont > xFont;
486 if ( m_pTabBar )
488 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
489 if ( xDev.is() )
491 vcl::Font aFont;
492 if ( m_pTabBar->IsControlFont() )
493 aFont = m_pTabBar->GetControlFont();
494 else
495 aFont = m_pTabBar->GetFont();
496 VCLXFont* pVCLXFont = new VCLXFont;
497 pVCLXFont->Init( *xDev.get(), aFont );
498 xFont = pVCLXFont;
502 return xFont;
507 OUString AccessibleTabBar::getTitledBorderText( ) throw (RuntimeException, std::exception)
509 OExternalLockGuard aGuard( this );
511 OUString sText;
512 if ( m_pTabBar )
513 sText = m_pTabBar->GetText();
515 return sText;
520 OUString AccessibleTabBar::getToolTipText( ) throw (RuntimeException, std::exception)
522 OExternalLockGuard aGuard( this );
524 OUString sText;
525 if ( m_pTabBar )
526 sText = m_pTabBar->GetQuickHelpText();
528 return sText;
534 } // namespace accessibility
537 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */