1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/XWindowPeer.hpp>
28 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <unotools/accessiblestatesethelper.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <i18nlangtag/languagetag.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/settings.hxx>
35 #include <toolkit/awt/vclxfont.hxx>
36 #include <toolkit/helper/convert.hxx>
39 namespace accessibility
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::lang
;
46 using namespace ::com::sun::star::accessibility
;
47 using namespace ::comphelper
;
52 AccessibleTabBar::AccessibleTabBar( TabBar
* pTabBar
)
53 :AccessibleTabBarBase( pTabBar
)
56 m_aAccessibleChildren
.assign( m_pTabBar
->GetAccessibleChildWindowCount() + 1, Reference
< XAccessible
>() );
60 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
62 Any aOldValue
, aNewValue
;
64 switch ( rVclWindowEvent
.GetId() )
66 case VclEventId::WindowEnabled
:
68 aNewValue
<<= AccessibleStateType::SENSITIVE
;
69 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
70 aNewValue
<<= AccessibleStateType::ENABLED
;
71 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
74 case VclEventId::WindowDisabled
:
76 aOldValue
<<= AccessibleStateType::ENABLED
;
77 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
78 aOldValue
<<= AccessibleStateType::SENSITIVE
;
79 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
82 case VclEventId::WindowGetFocus
:
84 aNewValue
<<= AccessibleStateType::FOCUSED
;
85 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
88 case VclEventId::WindowLoseFocus
:
90 aOldValue
<<= AccessibleStateType::FOCUSED
;
91 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
94 case VclEventId::WindowShow
:
96 aNewValue
<<= AccessibleStateType::SHOWING
;
97 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
100 case VclEventId::WindowHide
:
102 aOldValue
<<= AccessibleStateType::SHOWING
;
103 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
108 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
115 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
120 if ( m_pTabBar
->IsEnabled() )
122 rStateSet
.AddState( AccessibleStateType::ENABLED
);
123 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
126 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
128 if ( m_pTabBar
->HasFocus() )
129 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
131 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
133 if ( m_pTabBar
->IsVisible() )
134 rStateSet
.AddState( AccessibleStateType::SHOWING
);
136 if ( m_pTabBar
->GetStyle() & WB_SIZEABLE
)
137 rStateSet
.AddState( AccessibleStateType::RESIZABLE
);
141 // OCommonAccessibleComponent
144 awt::Rectangle
AccessibleTabBar::implGetBounds()
146 awt::Rectangle aBounds
;
148 aBounds
= AWTRectangle( tools::Rectangle( m_pTabBar
->GetPosPixel(), m_pTabBar
->GetSizePixel() ) );
157 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar
, OAccessibleExtendedComponentHelper
, AccessibleTabBar_BASE
)
163 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar
, OAccessibleExtendedComponentHelper
, AccessibleTabBar_BASE
)
169 void AccessibleTabBar::disposing()
171 AccessibleTabBarBase::disposing();
173 // dispose all children
174 for (const Reference
<XAccessible
>& i
: m_aAccessibleChildren
)
176 Reference
< XComponent
> xComponent( i
, UNO_QUERY
);
177 if ( xComponent
.is() )
178 xComponent
->dispose();
180 m_aAccessibleChildren
.clear();
187 OUString
AccessibleTabBar::getImplementationName()
189 return "com.sun.star.comp.svtools.AccessibleTabBar";
193 sal_Bool
AccessibleTabBar::supportsService( const OUString
& rServiceName
)
195 return cppu::supportsService(this, rServiceName
);
199 Sequence
< OUString
> AccessibleTabBar::getSupportedServiceNames()
201 return { "com.sun.star.awt.AccessibleTabBar" };
208 Reference
< XAccessibleContext
> AccessibleTabBar::getAccessibleContext( )
210 OExternalLockGuard
aGuard( this );
216 // XAccessibleContext
219 sal_Int32
AccessibleTabBar::getAccessibleChildCount()
221 OExternalLockGuard
aGuard( this );
223 return m_aAccessibleChildren
.size();
227 Reference
< XAccessible
> AccessibleTabBar::getAccessibleChild( sal_Int32 i
)
229 OExternalLockGuard
aGuard( this );
231 if ( i
< 0 || i
>= static_cast<sal_Int32
>(m_aAccessibleChildren
.size()) )
232 throw IndexOutOfBoundsException();
234 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
239 sal_Int32 nCount
= m_pTabBar
->GetAccessibleChildWindowCount();
243 vcl::Window
* pChild
= m_pTabBar
->GetAccessibleChildWindow( static_cast<sal_uInt16
>(i
) );
245 xChild
= pChild
->GetAccessible();
247 else if ( i
== nCount
)
249 xChild
= new AccessibleTabBarPageList( m_pTabBar
, i
);
252 // insert into child list
253 m_aAccessibleChildren
[i
] = xChild
;
261 Reference
< XAccessible
> AccessibleTabBar::getAccessibleParent( )
263 OExternalLockGuard
aGuard( this );
265 Reference
< XAccessible
> xParent
;
268 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
270 xParent
= pParent
->GetAccessible();
277 sal_Int32
AccessibleTabBar::getAccessibleIndexInParent( )
279 OExternalLockGuard
aGuard( this );
281 sal_Int32 nIndexInParent
= -1;
284 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
287 for ( sal_uInt16 i
= 0, nCount
= pParent
->GetAccessibleChildWindowCount(); i
< nCount
; ++i
)
289 vcl::Window
* pChild
= pParent
->GetAccessibleChildWindow( i
);
290 if ( pChild
== static_cast< vcl::Window
* >( m_pTabBar
) )
299 return nIndexInParent
;
303 sal_Int16
AccessibleTabBar::getAccessibleRole( )
305 OExternalLockGuard
aGuard( this );
307 return AccessibleRole::PANEL
;
311 OUString
AccessibleTabBar::getAccessibleDescription( )
313 OExternalLockGuard
aGuard( this );
315 OUString sDescription
;
317 sDescription
= m_pTabBar
->GetAccessibleDescription();
323 OUString
AccessibleTabBar::getAccessibleName( )
325 OExternalLockGuard
aGuard( this );
329 sName
= m_pTabBar
->GetAccessibleName();
335 Reference
< XAccessibleRelationSet
> AccessibleTabBar::getAccessibleRelationSet( )
337 OExternalLockGuard
aGuard( this );
339 return new utl::AccessibleRelationSetHelper
;
343 Reference
< XAccessibleStateSet
> AccessibleTabBar::getAccessibleStateSet( )
345 OExternalLockGuard
aGuard( this );
347 rtl::Reference
<utl::AccessibleStateSetHelper
> pStateSetHelper
= new utl::AccessibleStateSetHelper
;
349 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
351 FillAccessibleStateSet( *pStateSetHelper
);
355 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
358 return pStateSetHelper
;
362 Locale
AccessibleTabBar::getLocale( )
364 OExternalLockGuard
aGuard( this );
366 return Application::GetSettings().GetLanguageTag().getLocale();
370 // XAccessibleComponent
373 Reference
< XAccessible
> AccessibleTabBar::getAccessibleAtPoint( const awt::Point
& rPoint
)
375 OExternalLockGuard
aGuard( this );
377 Reference
< XAccessible
> xChild
;
378 for ( size_t i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
380 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
383 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
386 tools::Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
387 Point aPos
= VCLPoint( rPoint
);
388 if ( aRect
.Contains( aPos
) )
401 void AccessibleTabBar::grabFocus( )
403 OExternalLockGuard
aGuard( this );
406 m_pTabBar
->GrabFocus();
410 sal_Int32
AccessibleTabBar::getForeground( )
412 OExternalLockGuard
aGuard( this );
417 if ( m_pTabBar
->IsControlForeground() )
418 nColor
= m_pTabBar
->GetControlForeground();
422 if ( m_pTabBar
->IsControlFont() )
423 aFont
= m_pTabBar
->GetControlFont();
425 aFont
= m_pTabBar
->GetFont();
426 nColor
= aFont
.GetColor();
430 return sal_Int32(nColor
);
434 sal_Int32
AccessibleTabBar::getBackground( )
436 OExternalLockGuard
aGuard( this );
441 if ( m_pTabBar
->IsControlBackground() )
442 nColor
= m_pTabBar
->GetControlBackground();
444 nColor
= m_pTabBar
->GetBackground().GetColor();
447 return sal_Int32(nColor
);
451 // XAccessibleExtendedComponent
454 Reference
< awt::XFont
> AccessibleTabBar::getFont( )
456 OExternalLockGuard
aGuard( this );
458 Reference
< awt::XFont
> xFont
;
461 Reference
< awt::XDevice
> xDev( m_pTabBar
->GetComponentInterface(), UNO_QUERY
);
465 if ( m_pTabBar
->IsControlFont() )
466 aFont
= m_pTabBar
->GetControlFont();
468 aFont
= m_pTabBar
->GetFont();
469 rtl::Reference
<VCLXFont
> pVCLXFont
= new VCLXFont
;
470 pVCLXFont
->Init( *xDev
, aFont
);
479 OUString
AccessibleTabBar::getTitledBorderText( )
481 OExternalLockGuard
aGuard( this );
485 sText
= m_pTabBar
->GetText();
491 OUString
AccessibleTabBar::getToolTipText( )
493 OExternalLockGuard
aGuard( this );
497 sText
= m_pTabBar
->GetQuickHelpText();
503 } // namespace accessibility
506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */