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 <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>
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
)
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
);
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
);
89 case VCLEVENT_WINDOW_GETFOCUS
:
91 aNewValue
<<= AccessibleStateType::FOCUSED
;
92 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
95 case VCLEVENT_WINDOW_LOSEFOCUS
:
97 aOldValue
<<= AccessibleStateType::FOCUSED
;
98 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
101 case VCLEVENT_WINDOW_SHOW
:
103 aNewValue
<<= AccessibleStateType::SHOWING
;
104 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
107 case VCLEVENT_WINDOW_HIDE
:
109 aOldValue
<<= AccessibleStateType::SHOWING
;
110 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
115 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent
);
123 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
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
;
156 aBounds
= AWTRectangle( Rectangle( m_pTabBar
->GetPosPixel(), m_pTabBar
->GetSizePixel() ) );
165 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBar_BASE
)
171 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar
, AccessibleExtendedComponentHelper_BASE
, AccessibleTabBar_BASE
)
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();
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";
220 Reference
< XAccessibleContext
> AccessibleTabBar::getAccessibleContext( ) throw (RuntimeException
, std::exception
)
222 OExternalLockGuard
aGuard( 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
];
252 sal_Int32 nCount
= m_pTabBar
->GetAccessibleChildWindowCount();
256 vcl::Window
* pChild
= m_pTabBar
->GetAccessibleChildWindow( (sal_uInt16
)i
);
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
;
275 Reference
< XAccessible
> AccessibleTabBar::getAccessibleParent( ) throw (RuntimeException
, std::exception
)
277 OExternalLockGuard
aGuard( this );
279 Reference
< XAccessible
> xParent
;
282 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
284 xParent
= pParent
->GetAccessible();
292 sal_Int32
AccessibleTabBar::getAccessibleIndexInParent( ) throw (RuntimeException
, std::exception
)
294 OExternalLockGuard
aGuard( this );
296 sal_Int32 nIndexInParent
= -1;
299 vcl::Window
* pParent
= m_pTabBar
->GetAccessibleParentWindow();
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
) )
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
;
334 sDescription
= m_pTabBar
->GetAccessibleDescription();
341 OUString
AccessibleTabBar::getAccessibleName( ) throw (RuntimeException
, std::exception
)
343 OExternalLockGuard
aGuard( this );
347 sName
= m_pTabBar
->GetAccessibleName();
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
;
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
);
378 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
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
);
407 Reference
< XAccessibleComponent
> xComp( xAcc
->getAccessibleContext(), UNO_QUERY
);
410 Rectangle aRect
= VCLRectangle( xComp
->getBounds() );
411 Point aPos
= VCLPoint( rPoint
);
412 if ( aRect
.IsInside( aPos
) )
426 void AccessibleTabBar::grabFocus( ) throw (RuntimeException
, std::exception
)
428 OExternalLockGuard
aGuard( this );
431 m_pTabBar
->GrabFocus();
436 sal_Int32
AccessibleTabBar::getForeground( ) throw (RuntimeException
, std::exception
)
438 OExternalLockGuard
aGuard( this );
440 sal_Int32 nColor
= 0;
443 if ( m_pTabBar
->IsControlForeground() )
444 nColor
= m_pTabBar
->GetControlForeground().GetColor();
448 if ( m_pTabBar
->IsControlFont() )
449 aFont
= m_pTabBar
->GetControlFont();
451 aFont
= m_pTabBar
->GetFont();
452 nColor
= aFont
.GetColor().GetColor();
461 sal_Int32
AccessibleTabBar::getBackground( ) throw (RuntimeException
, std::exception
)
463 OExternalLockGuard
aGuard( this );
465 sal_Int32 nColor
= 0;
468 if ( m_pTabBar
->IsControlBackground() )
469 nColor
= m_pTabBar
->GetControlBackground().GetColor();
471 nColor
= m_pTabBar
->GetBackground().GetColor().GetColor();
478 // XAccessibleExtendedComponent
481 Reference
< awt::XFont
> AccessibleTabBar::getFont( ) throw (RuntimeException
, std::exception
)
483 OExternalLockGuard
aGuard( this );
485 Reference
< awt::XFont
> xFont
;
488 Reference
< awt::XDevice
> xDev( m_pTabBar
->GetComponentInterface(), UNO_QUERY
);
492 if ( m_pTabBar
->IsControlFont() )
493 aFont
= m_pTabBar
->GetControlFont();
495 aFont
= m_pTabBar
->GetFont();
496 VCLXFont
* pVCLXFont
= new VCLXFont
;
497 pVCLXFont
->Init( *xDev
.get(), aFont
);
507 OUString
AccessibleTabBar::getTitledBorderText( ) throw (RuntimeException
, std::exception
)
509 OExternalLockGuard
aGuard( this );
513 sText
= m_pTabBar
->GetText();
520 OUString
AccessibleTabBar::getToolTipText( ) throw (RuntimeException
, std::exception
)
522 OExternalLockGuard
aGuard( this );
526 sText
= m_pTabBar
->GetQuickHelpText();
534 } // namespace accessibility
537 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */