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/XVclWindowPeer.hpp>
28 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <comphelper/accessiblecontexthelper.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <i18nlangtag/languagetag.hxx>
33 #include <o3tl/safeint.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/settings.hxx>
36 #include <toolkit/awt/vclxfont.hxx>
37 #include <toolkit/helper/convert.hxx>
40 namespace accessibility
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::accessibility
;
48 using namespace ::comphelper
;
53 AccessibleTabBar::AccessibleTabBar( TabBar
* pTabBar
)
54 :ImplInheritanceHelper( pTabBar
)
57 m_aAccessibleChildren
.assign( m_pTabBar
->GetAccessibleChildWindowCount() + 1, Reference
< XAccessible
>() );
61 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
63 Any aOldValue
, aNewValue
;
65 switch ( rVclWindowEvent
.GetId() )
67 case VclEventId::WindowEnabled
:
69 aNewValue
<<= AccessibleStateType::SENSITIVE
;
70 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
71 aNewValue
<<= AccessibleStateType::ENABLED
;
72 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
75 case VclEventId::WindowDisabled
:
77 aOldValue
<<= AccessibleStateType::ENABLED
;
78 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
79 aOldValue
<<= AccessibleStateType::SENSITIVE
;
80 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
83 case VclEventId::WindowGetFocus
:
85 aNewValue
<<= AccessibleStateType::FOCUSED
;
86 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
89 case VclEventId::WindowLoseFocus
:
91 aOldValue
<<= AccessibleStateType::FOCUSED
;
92 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
95 case VclEventId::WindowShow
:
97 aNewValue
<<= AccessibleStateType::SHOWING
;
98 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
101 case VclEventId::WindowHide
:
103 aOldValue
<<= AccessibleStateType::SHOWING
;
104 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
109 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
116 void AccessibleTabBar::FillAccessibleStateSet( sal_Int64
& rStateSet
)
121 if ( m_pTabBar
->IsEnabled() )
123 rStateSet
|= AccessibleStateType::ENABLED
;
124 rStateSet
|= AccessibleStateType::SENSITIVE
;
127 rStateSet
|= AccessibleStateType::FOCUSABLE
;
129 if ( m_pTabBar
->HasFocus() )
130 rStateSet
|= AccessibleStateType::FOCUSED
;
132 rStateSet
|= AccessibleStateType::VISIBLE
;
134 if ( m_pTabBar
->IsVisible() )
135 rStateSet
|= AccessibleStateType::SHOWING
;
137 if ( m_pTabBar
->GetStyle() & WB_SIZEABLE
)
138 rStateSet
|= AccessibleStateType::RESIZABLE
;
142 // OCommonAccessibleComponent
145 awt::Rectangle
AccessibleTabBar::implGetBounds()
147 awt::Rectangle aBounds
;
149 aBounds
= AWTRectangle( tools::Rectangle( m_pTabBar
->GetPosPixel(), m_pTabBar
->GetSizePixel() ) );
158 void AccessibleTabBar::disposing()
160 AccessibleTabBarBase::disposing();
162 // dispose all children
163 for (const Reference
<XAccessible
>& i
: m_aAccessibleChildren
)
165 Reference
< XComponent
> xComponent( i
, UNO_QUERY
);
166 if ( xComponent
.is() )
167 xComponent
->dispose();
169 m_aAccessibleChildren
.clear();
176 OUString
AccessibleTabBar::getImplementationName()
178 return "com.sun.star.comp.svtools.AccessibleTabBar";
182 sal_Bool
AccessibleTabBar::supportsService( const OUString
& rServiceName
)
184 return cppu::supportsService(this, rServiceName
);
188 Sequence
< OUString
> AccessibleTabBar::getSupportedServiceNames()
190 return { "com.sun.star.awt.AccessibleTabBar" };
197 Reference
< XAccessibleContext
> AccessibleTabBar::getAccessibleContext( )
199 OExternalLockGuard
aGuard( this );
205 // XAccessibleContext
208 sal_Int64
AccessibleTabBar::getAccessibleChildCount()
210 OExternalLockGuard
aGuard( this );
212 return m_aAccessibleChildren
.size();
216 Reference
< XAccessible
> AccessibleTabBar::getAccessibleChild( sal_Int64 i
)
218 OExternalLockGuard
aGuard( this );
220 if ( i
< 0 || o3tl::make_unsigned(i
) >= m_aAccessibleChildren
.size() )
221 throw IndexOutOfBoundsException();
223 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
228 sal_Int32 nCount
= m_pTabBar
->GetAccessibleChildWindowCount();
232 vcl::Window
* pChild
= m_pTabBar
->GetAccessibleChildWindow( static_cast<sal_uInt16
>(i
) );
234 xChild
= pChild
->GetAccessible();
236 else if ( i
== nCount
)
238 xChild
= new AccessibleTabBarPageList( m_pTabBar
, i
);
241 // insert into child list
242 m_aAccessibleChildren
[i
] = xChild
;
250 Reference
< XAccessible
> AccessibleTabBar::getAccessibleParent( )
252 OExternalLockGuard
aGuard( this );
254 Reference
< XAccessible
> xParent
;
257 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
259 xParent
= pParent
->GetAccessible();
266 sal_Int64
AccessibleTabBar::getAccessibleIndexInParent( )
268 OExternalLockGuard
aGuard( this );
270 sal_Int64 nIndexInParent
= -1;
273 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
276 for ( sal_uInt16 i
= 0, nCount
= pParent
->GetAccessibleChildWindowCount(); i
< nCount
; ++i
)
278 vcl::Window
* pChild
= pParent
->GetAccessibleChildWindow( i
);
279 if ( pChild
== static_cast< vcl::Window
* >( m_pTabBar
) )
288 return nIndexInParent
;
292 sal_Int16
AccessibleTabBar::getAccessibleRole( )
294 OExternalLockGuard
aGuard( this );
296 return AccessibleRole::PANEL
;
300 OUString
AccessibleTabBar::getAccessibleDescription( )
302 OExternalLockGuard
aGuard( this );
304 OUString sDescription
;
306 sDescription
= m_pTabBar
->GetAccessibleDescription();
312 OUString
AccessibleTabBar::getAccessibleName( )
314 OExternalLockGuard
aGuard( this );
318 sName
= m_pTabBar
->GetAccessibleName();
324 Reference
< XAccessibleRelationSet
> AccessibleTabBar::getAccessibleRelationSet( )
326 OExternalLockGuard
aGuard( this );
328 return new utl::AccessibleRelationSetHelper
;
332 sal_Int64
AccessibleTabBar::getAccessibleStateSet( )
334 OExternalLockGuard
aGuard( this );
336 sal_Int64 nStateSet
= 0;
338 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
340 FillAccessibleStateSet( nStateSet
);
344 nStateSet
|= AccessibleStateType::DEFUNC
;
351 Locale
AccessibleTabBar::getLocale( )
353 OExternalLockGuard
aGuard( this );
355 return Application::GetSettings().GetLanguageTag().getLocale();
359 // XAccessibleComponent
362 Reference
< XAccessible
> AccessibleTabBar::getAccessibleAtPoint( const awt::Point
& rPoint
)
364 OExternalLockGuard
aGuard( this );
366 Reference
< XAccessible
> xChild
;
367 for ( size_t i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
369 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
372 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
375 tools::Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
376 Point aPos
= VCLPoint( rPoint
);
377 if ( aRect
.Contains( aPos
) )
390 void AccessibleTabBar::grabFocus( )
392 OExternalLockGuard
aGuard( this );
395 m_pTabBar
->GrabFocus();
399 sal_Int32
AccessibleTabBar::getForeground( )
401 OExternalLockGuard
aGuard( this );
406 if ( m_pTabBar
->IsControlForeground() )
407 nColor
= m_pTabBar
->GetControlForeground();
411 if ( m_pTabBar
->IsControlFont() )
412 aFont
= m_pTabBar
->GetControlFont();
414 aFont
= m_pTabBar
->GetFont();
415 nColor
= aFont
.GetColor();
419 return sal_Int32(nColor
);
423 sal_Int32
AccessibleTabBar::getBackground( )
425 OExternalLockGuard
aGuard( this );
430 if ( m_pTabBar
->IsControlBackground() )
431 nColor
= m_pTabBar
->GetControlBackground();
433 nColor
= m_pTabBar
->GetBackground().GetColor();
436 return sal_Int32(nColor
);
440 // XAccessibleExtendedComponent
443 Reference
< awt::XFont
> AccessibleTabBar::getFont( )
445 OExternalLockGuard
aGuard( this );
447 Reference
< awt::XFont
> xFont
;
450 Reference
< awt::XDevice
> xDev( m_pTabBar
->GetComponentInterface(), UNO_QUERY
);
454 if ( m_pTabBar
->IsControlFont() )
455 aFont
= m_pTabBar
->GetControlFont();
457 aFont
= m_pTabBar
->GetFont();
458 rtl::Reference
<VCLXFont
> pVCLXFont
= new VCLXFont
;
459 pVCLXFont
->Init( *xDev
, aFont
);
468 OUString
AccessibleTabBar::getTitledBorderText( )
470 OExternalLockGuard
aGuard( this );
474 sText
= m_pTabBar
->GetText();
480 OUString
AccessibleTabBar::getToolTipText( )
482 OExternalLockGuard
aGuard( this );
486 sText
= m_pTabBar
->GetQuickHelpText();
492 } // namespace accessibility
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */