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 <vcl/unohelp.hxx>
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
;
51 AccessibleTabBar::AccessibleTabBar( TabBar
* pTabBar
)
52 :ImplInheritanceHelper( pTabBar
)
55 m_aAccessibleChildren
.assign( m_pTabBar
->GetAccessibleChildWindowCount() + 1, Reference
< XAccessible
>() );
59 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
61 Any aOldValue
, aNewValue
;
63 switch ( rVclWindowEvent
.GetId() )
65 case VclEventId::WindowEnabled
:
67 aNewValue
<<= AccessibleStateType::SENSITIVE
;
68 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
69 aNewValue
<<= AccessibleStateType::ENABLED
;
70 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
73 case VclEventId::WindowDisabled
:
75 aOldValue
<<= AccessibleStateType::ENABLED
;
76 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
77 aOldValue
<<= AccessibleStateType::SENSITIVE
;
78 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
81 case VclEventId::WindowGetFocus
:
83 aNewValue
<<= AccessibleStateType::FOCUSED
;
84 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
87 case VclEventId::WindowLoseFocus
:
89 aOldValue
<<= AccessibleStateType::FOCUSED
;
90 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
93 case VclEventId::WindowShow
:
95 aNewValue
<<= AccessibleStateType::SHOWING
;
96 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
99 case VclEventId::WindowHide
:
101 aOldValue
<<= AccessibleStateType::SHOWING
;
102 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
107 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
114 void AccessibleTabBar::FillAccessibleStateSet( sal_Int64
& rStateSet
)
119 if ( m_pTabBar
->IsEnabled() )
121 rStateSet
|= AccessibleStateType::ENABLED
;
122 rStateSet
|= AccessibleStateType::SENSITIVE
;
125 rStateSet
|= AccessibleStateType::FOCUSABLE
;
127 if ( m_pTabBar
->HasFocus() )
128 rStateSet
|= AccessibleStateType::FOCUSED
;
130 rStateSet
|= AccessibleStateType::VISIBLE
;
132 if ( m_pTabBar
->IsVisible() )
133 rStateSet
|= AccessibleStateType::SHOWING
;
135 if ( m_pTabBar
->GetStyle() & WB_SIZEABLE
)
136 rStateSet
|= AccessibleStateType::RESIZABLE
;
140 // OCommonAccessibleComponent
143 awt::Rectangle
AccessibleTabBar::implGetBounds()
145 awt::Rectangle aBounds
;
147 aBounds
= vcl::unohelper::ConvertToAWTRect(
148 tools::Rectangle(m_pTabBar
->GetPosPixel(), m_pTabBar
->GetSizePixel()));
157 void AccessibleTabBar::disposing()
159 AccessibleTabBarBase::disposing();
161 // dispose all children
162 for (const Reference
<XAccessible
>& i
: m_aAccessibleChildren
)
164 Reference
< XComponent
> xComponent( i
, UNO_QUERY
);
165 if ( xComponent
.is() )
166 xComponent
->dispose();
168 m_aAccessibleChildren
.clear();
175 OUString
AccessibleTabBar::getImplementationName()
177 return u
"com.sun.star.comp.svtools.AccessibleTabBar"_ustr
;
181 sal_Bool
AccessibleTabBar::supportsService( const OUString
& rServiceName
)
183 return cppu::supportsService(this, rServiceName
);
187 Sequence
< OUString
> AccessibleTabBar::getSupportedServiceNames()
189 return { u
"com.sun.star.awt.AccessibleTabBar"_ustr
};
196 Reference
< XAccessibleContext
> AccessibleTabBar::getAccessibleContext( )
198 OExternalLockGuard
aGuard( this );
204 // XAccessibleContext
207 sal_Int64
AccessibleTabBar::getAccessibleChildCount()
209 OExternalLockGuard
aGuard( this );
211 return m_aAccessibleChildren
.size();
215 Reference
< XAccessible
> AccessibleTabBar::getAccessibleChild( sal_Int64 i
)
217 OExternalLockGuard
aGuard( this );
219 if ( i
< 0 || o3tl::make_unsigned(i
) >= m_aAccessibleChildren
.size() )
220 throw IndexOutOfBoundsException();
222 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
227 sal_Int32 nCount
= m_pTabBar
->GetAccessibleChildWindowCount();
231 vcl::Window
* pChild
= m_pTabBar
->GetAccessibleChildWindow( static_cast<sal_uInt16
>(i
) );
233 xChild
= pChild
->GetAccessible();
235 else if ( i
== nCount
)
237 xChild
= new AccessibleTabBarPageList( m_pTabBar
, i
);
240 // insert into child list
241 m_aAccessibleChildren
[i
] = xChild
;
249 Reference
< XAccessible
> AccessibleTabBar::getAccessibleParent( )
251 OExternalLockGuard
aGuard( this );
253 Reference
< XAccessible
> xParent
;
256 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
258 xParent
= pParent
->GetAccessible();
265 sal_Int64
AccessibleTabBar::getAccessibleIndexInParent( )
267 OExternalLockGuard
aGuard( this );
269 sal_Int64 nIndexInParent
= -1;
272 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
275 for ( sal_uInt16 i
= 0, nCount
= pParent
->GetAccessibleChildWindowCount(); i
< nCount
; ++i
)
277 vcl::Window
* pChild
= pParent
->GetAccessibleChildWindow( i
);
278 if ( pChild
== static_cast< vcl::Window
* >( m_pTabBar
) )
287 return nIndexInParent
;
291 sal_Int16
AccessibleTabBar::getAccessibleRole( )
293 OExternalLockGuard
aGuard( this );
295 return AccessibleRole::PANEL
;
298 OUString
AccessibleTabBar::getAccessibleDescription( )
300 OExternalLockGuard
aGuard( this );
303 return m_pTabBar
->GetAccessibleDescription();
308 OUString
AccessibleTabBar::getAccessibleName( )
310 OExternalLockGuard
aGuard( this );
313 return m_pTabBar
->GetAccessibleName();
318 Reference
< XAccessibleRelationSet
> AccessibleTabBar::getAccessibleRelationSet( )
320 OExternalLockGuard
aGuard( this );
322 return new utl::AccessibleRelationSetHelper
;
325 sal_Int64
AccessibleTabBar::getAccessibleStateSet( )
327 OExternalLockGuard
aGuard( this );
329 sal_Int64 nStateSet
= 0;
331 if ( !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
)
333 FillAccessibleStateSet( nStateSet
);
337 nStateSet
|= AccessibleStateType::DEFUNC
;
344 Locale
AccessibleTabBar::getLocale( )
346 OExternalLockGuard
aGuard( this );
348 return Application::GetSettings().GetLanguageTag().getLocale();
351 // XAccessibleComponent
352 Reference
< XAccessible
> AccessibleTabBar::getAccessibleAtPoint( const awt::Point
& rPoint
)
354 OExternalLockGuard
aGuard( this );
356 for( sal_Int64 i
= 0; i
< getAccessibleChildCount(); ++i
)
358 Reference
< XAccessible
> xAcc
= getAccessibleChild( i
);
361 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
364 tools::Rectangle aRect
= vcl::unohelper::ConvertToVCLRect(xComp
->getBounds());
365 Point aPos
= vcl::unohelper::ConvertToVCLPoint(rPoint
);
366 if ( aRect
.Contains( aPos
) )
377 void AccessibleTabBar::grabFocus( )
379 OExternalLockGuard
aGuard( this );
382 m_pTabBar
->GrabFocus();
386 sal_Int32
AccessibleTabBar::getForeground( )
388 OExternalLockGuard
aGuard( this );
393 if ( m_pTabBar
->IsControlForeground() )
394 nColor
= m_pTabBar
->GetControlForeground();
398 if ( m_pTabBar
->IsControlFont() )
399 aFont
= m_pTabBar
->GetControlFont();
401 aFont
= m_pTabBar
->GetFont();
402 nColor
= aFont
.GetColor();
406 return sal_Int32(nColor
);
410 sal_Int32
AccessibleTabBar::getBackground( )
412 OExternalLockGuard
aGuard( this );
417 if ( m_pTabBar
->IsControlBackground() )
418 nColor
= m_pTabBar
->GetControlBackground();
420 nColor
= m_pTabBar
->GetBackground().GetColor();
423 return sal_Int32(nColor
);
427 // XAccessibleExtendedComponent
429 OUString
AccessibleTabBar::getTitledBorderText( )
431 OExternalLockGuard
aGuard( this );
435 sText
= m_pTabBar
->GetText();
441 OUString
AccessibleTabBar::getToolTipText( )
443 OExternalLockGuard
aGuard( this );
447 sText
= m_pTabBar
->GetQuickHelpText();
453 } // namespace accessibility
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */