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/standard/vclxaccessibletabcontrol.hxx>
21 #include <accessibility/standard/vclxaccessibletabpage.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 <unotools/accessiblestatesethelper.hxx>
27 #include <vcl/tabctrl.hxx>
28 #include <vcl/tabpage.hxx>
32 using namespace ::com::sun::star
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::accessibility
;
36 using namespace ::comphelper
;
39 // ----------------------------------------------------
40 // class VCLXAccessibleTabControl
41 // ----------------------------------------------------
43 VCLXAccessibleTabControl::VCLXAccessibleTabControl( VCLXWindow
* pVCLXWindow
)
44 :VCLXAccessibleComponent( pVCLXWindow
)
46 m_pTabControl
= static_cast< TabControl
* >( GetWindow() );
49 m_aAccessibleChildren
.assign( m_pTabControl
->GetPageCount(), Reference
< XAccessible
>() );
52 // -----------------------------------------------------------------------------
54 VCLXAccessibleTabControl::~VCLXAccessibleTabControl()
58 // -----------------------------------------------------------------------------
60 void VCLXAccessibleTabControl::UpdateFocused()
62 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
64 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
67 VCLXAccessibleTabPage
* pVCLXAccessibleTabPage
= static_cast< VCLXAccessibleTabPage
* >( xChild
.get() );
68 if ( pVCLXAccessibleTabPage
)
69 pVCLXAccessibleTabPage
->SetFocused( pVCLXAccessibleTabPage
->IsFocused() );
74 // -----------------------------------------------------------------------------
76 void VCLXAccessibleTabControl::UpdateSelected( sal_Int32 i
, bool bSelected
)
78 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, Any(), Any() );
80 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
82 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
85 VCLXAccessibleTabPage
* pVCLXAccessibleTabPage
= static_cast< VCLXAccessibleTabPage
* >( xChild
.get() );
86 if ( pVCLXAccessibleTabPage
)
87 pVCLXAccessibleTabPage
->SetSelected( bSelected
);
92 // -----------------------------------------------------------------------------
94 void VCLXAccessibleTabControl::UpdatePageText( sal_Int32 i
)
96 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
98 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
101 VCLXAccessibleTabPage
* pVCLXAccessibleTabPage
= static_cast< VCLXAccessibleTabPage
* >( xChild
.get() );
102 if ( pVCLXAccessibleTabPage
)
103 pVCLXAccessibleTabPage
->SetPageText( pVCLXAccessibleTabPage
->GetPageText() );
108 // -----------------------------------------------------------------------------
110 void VCLXAccessibleTabControl::UpdateTabPage( sal_Int32 i
, bool bNew
)
112 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
114 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
117 VCLXAccessibleTabPage
* pVCLXAccessibleTabPage
= static_cast< VCLXAccessibleTabPage
* >( xChild
.get() );
118 if ( pVCLXAccessibleTabPage
)
119 pVCLXAccessibleTabPage
->Update( bNew
);
124 // -----------------------------------------------------------------------------
126 void VCLXAccessibleTabControl::InsertChild( sal_Int32 i
)
128 if ( i
>= 0 && i
<= (sal_Int32
)m_aAccessibleChildren
.size() )
130 // insert entry in child list
131 m_aAccessibleChildren
.insert( m_aAccessibleChildren
.begin() + i
, Reference
< XAccessible
>() );
133 // send accessible child event
134 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
137 Any aOldValue
, aNewValue
;
138 aNewValue
<<= xChild
;
139 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
144 // -----------------------------------------------------------------------------
146 void VCLXAccessibleTabControl::RemoveChild( sal_Int32 i
)
148 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
150 // get the accessible of the removed page
151 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
153 // remove entry in child list
154 m_aAccessibleChildren
.erase( m_aAccessibleChildren
.begin() + i
);
156 // send accessible child event
159 Any aOldValue
, aNewValue
;
160 aOldValue
<<= xChild
;
161 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
163 Reference
< XComponent
> xComponent( xChild
, UNO_QUERY
);
164 if ( xComponent
.is() )
165 xComponent
->dispose();
170 // -----------------------------------------------------------------------------
172 void VCLXAccessibleTabControl::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
174 switch ( rVclWindowEvent
.GetId() )
176 case VCLEVENT_TABPAGE_ACTIVATE
:
177 case VCLEVENT_TABPAGE_DEACTIVATE
:
181 sal_uInt16 nPageId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
182 sal_uInt16 nPagePos
= m_pTabControl
->GetPagePos( nPageId
);
184 UpdateSelected( nPagePos
, rVclWindowEvent
.GetId() == VCLEVENT_TABPAGE_ACTIVATE
);
188 case VCLEVENT_TABPAGE_PAGETEXTCHANGED
:
192 sal_uInt16 nPageId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
193 sal_uInt16 nPagePos
= m_pTabControl
->GetPagePos( nPageId
);
194 UpdatePageText( nPagePos
);
198 case VCLEVENT_TABPAGE_INSERTED
:
202 sal_uInt16 nPageId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
203 sal_uInt16 nPagePos
= m_pTabControl
->GetPagePos( nPageId
);
204 InsertChild( nPagePos
);
208 case VCLEVENT_TABPAGE_REMOVED
:
212 sal_uInt16 nPageId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
213 for ( sal_Int32 i
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; ++i
)
215 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
218 VCLXAccessibleTabPage
* pVCLXAccessibleTabPage
= static_cast< VCLXAccessibleTabPage
* >( xChild
.get() );
219 if ( pVCLXAccessibleTabPage
&& pVCLXAccessibleTabPage
->GetPageId() == nPageId
)
229 case VCLEVENT_TABPAGE_REMOVEDALL
:
231 for ( sal_Int32 i
= m_aAccessibleChildren
.size() - 1; i
>= 0; --i
)
235 case VCLEVENT_WINDOW_GETFOCUS
:
236 case VCLEVENT_WINDOW_LOSEFOCUS
:
241 case VCLEVENT_OBJECT_DYING
:
245 m_pTabControl
= NULL
;
247 // dispose all tab pages
248 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
250 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
251 if ( xComponent
.is() )
252 xComponent
->dispose();
254 m_aAccessibleChildren
.clear();
257 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
261 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
265 // -----------------------------------------------------------------------------
267 void VCLXAccessibleTabControl::ProcessWindowChildEvent( const VclWindowEvent
& rVclWindowEvent
)
269 switch ( rVclWindowEvent
.GetId() )
271 case VCLEVENT_WINDOW_SHOW
:
272 case VCLEVENT_WINDOW_HIDE
:
276 Window
* pChild
= static_cast< Window
* >( rVclWindowEvent
.GetData() );
277 if ( pChild
&& pChild
->GetType() == WINDOW_TABPAGE
)
279 for ( sal_Int32 i
= 0, nCount
= m_pTabControl
->GetPageCount(); i
< nCount
; ++i
)
281 sal_uInt16 nPageId
= m_pTabControl
->GetPageId( (sal_uInt16
)i
);
282 TabPage
* pTabPage
= m_pTabControl
->GetTabPage( nPageId
);
283 if ( pTabPage
== (TabPage
*) pChild
)
284 UpdateTabPage( i
, rVclWindowEvent
.GetId() == VCLEVENT_WINDOW_SHOW
);
291 VCLXAccessibleComponent::ProcessWindowChildEvent( rVclWindowEvent
);
296 // -----------------------------------------------------------------------------
298 void VCLXAccessibleTabControl::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
300 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
303 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
306 // -----------------------------------------------------------------------------
308 // -----------------------------------------------------------------------------
310 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleTabControl
, VCLXAccessibleComponent
, VCLXAccessibleTabControl_BASE
)
312 // -----------------------------------------------------------------------------
314 // -----------------------------------------------------------------------------
316 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleTabControl
, VCLXAccessibleComponent
, VCLXAccessibleTabControl_BASE
)
318 // -----------------------------------------------------------------------------
320 // -----------------------------------------------------------------------------
322 void VCLXAccessibleTabControl::disposing()
324 VCLXAccessibleComponent::disposing();
328 m_pTabControl
= NULL
;
330 // dispose all tab pages
331 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
333 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
334 if ( xComponent
.is() )
335 xComponent
->dispose();
337 m_aAccessibleChildren
.clear();
341 // -----------------------------------------------------------------------------
343 // -----------------------------------------------------------------------------
345 OUString
VCLXAccessibleTabControl::getImplementationName() throw (RuntimeException
)
347 return OUString( "com.sun.star.comp.toolkit.AccessibleTabControl" );
350 // -----------------------------------------------------------------------------
352 Sequence
< OUString
> VCLXAccessibleTabControl::getSupportedServiceNames() throw (RuntimeException
)
354 Sequence
< OUString
> aNames(1);
355 aNames
[0] = "com.sun.star.awt.AccessibleTabControl";
359 // -----------------------------------------------------------------------------
360 // XAccessibleContext
361 // -----------------------------------------------------------------------------
363 sal_Int32
VCLXAccessibleTabControl::getAccessibleChildCount() throw (RuntimeException
)
365 OExternalLockGuard
aGuard( this );
367 return m_aAccessibleChildren
.size();
370 // -----------------------------------------------------------------------------
372 Reference
< XAccessible
> VCLXAccessibleTabControl::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
374 OExternalLockGuard
aGuard( this );
376 if ( i
< 0 || i
>= getAccessibleChildCount() )
377 throw IndexOutOfBoundsException();
379 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
384 sal_uInt16 nPageId
= m_pTabControl
->GetPageId( (sal_uInt16
)i
);
386 xChild
= new VCLXAccessibleTabPage( m_pTabControl
, nPageId
);
388 // insert into tab page list
389 m_aAccessibleChildren
[i
] = xChild
;
396 // -----------------------------------------------------------------------------
398 sal_Int16
VCLXAccessibleTabControl::getAccessibleRole( ) throw (RuntimeException
)
400 OExternalLockGuard
aGuard( this );
402 return AccessibleRole::PAGE_TAB_LIST
;
405 // -----------------------------------------------------------------------------
407 OUString
VCLXAccessibleTabControl::getAccessibleName( ) throw (RuntimeException
)
409 OExternalLockGuard
aGuard( this );
414 // -----------------------------------------------------------------------------
415 // XAccessibleSelection
416 // -----------------------------------------------------------------------------
418 void VCLXAccessibleTabControl::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
420 OExternalLockGuard
aGuard( this );
422 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
423 throw IndexOutOfBoundsException();
426 m_pTabControl
->SelectTabPage( m_pTabControl
->GetPageId( (sal_uInt16
)nChildIndex
) );
429 // -----------------------------------------------------------------------------
431 sal_Bool
VCLXAccessibleTabControl::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
433 OExternalLockGuard
aGuard( this );
435 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
436 throw IndexOutOfBoundsException();
438 sal_Bool bSelected
= sal_False
;
439 if ( m_pTabControl
&& m_pTabControl
->GetCurPageId() == m_pTabControl
->GetPageId( (sal_uInt16
)nChildIndex
) )
440 bSelected
= sal_True
;
445 // -----------------------------------------------------------------------------
447 void VCLXAccessibleTabControl::clearAccessibleSelection( ) throw (RuntimeException
)
449 // This method makes no sense in a tab control, and so does nothing.
452 // -----------------------------------------------------------------------------
454 void VCLXAccessibleTabControl::selectAllAccessibleChildren( ) throw (RuntimeException
)
456 OExternalLockGuard
aGuard( this );
458 selectAccessibleChild( 0 );
461 // -----------------------------------------------------------------------------
463 sal_Int32
VCLXAccessibleTabControl::getSelectedAccessibleChildCount( ) throw (RuntimeException
)
465 OExternalLockGuard
aGuard( this );
470 // -----------------------------------------------------------------------------
472 Reference
< XAccessible
> VCLXAccessibleTabControl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
474 OExternalLockGuard
aGuard( this );
476 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
477 throw IndexOutOfBoundsException();
479 Reference
< XAccessible
> xChild
;
481 for ( sal_Int32 i
= 0, j
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; i
++ )
483 if ( isAccessibleChildSelected( i
) && ( j
++ == nSelectedChildIndex
) )
485 xChild
= getAccessibleChild( i
);
493 // -----------------------------------------------------------------------------
495 void VCLXAccessibleTabControl::deselectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
497 OExternalLockGuard
aGuard( this );
499 if ( nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount() )
500 throw IndexOutOfBoundsException();
502 // This method makes no sense in a tab control, and so does nothing.
505 // -----------------------------------------------------------------------------
507 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */