LibreOffice Module accessibility (master) 1
vclxaccessibletabcontrol.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22
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/lang/IndexOutOfBoundsException.hpp>
28#include <o3tl/safeint.hxx>
29#include <vcl/tabctrl.hxx>
30#include <vcl/tabpage.hxx>
31#include <vcl/vclevent.hxx>
32
33#include <vector>
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::lang;
38using namespace ::com::sun::star::accessibility;
39using namespace ::comphelper;
40
41
42
43
45 :ImplInheritanceHelper( pVCLXWindow )
46{
47 m_pTabControl = GetAs<TabControl>();
48 if (!m_pTabControl)
49 return;
50 if (m_pTabControl->isDisposed())
51 {
53 return;
54 }
56}
57
58
60{
61 for (const Reference<XAccessible>& xChild : m_aAccessibleChildren)
62 {
63 if ( xChild.is() )
64 {
65 VCLXAccessibleTabPage* pVCLXAccessibleTabPage = static_cast< VCLXAccessibleTabPage* >( xChild.get() );
66 if ( pVCLXAccessibleTabPage )
67 pVCLXAccessibleTabPage->SetFocused( pVCLXAccessibleTabPage->IsFocused() );
68 }
69 }
70}
71
72
73void VCLXAccessibleTabControl::UpdateSelected( sal_Int32 i, bool bSelected )
74{
75 if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() )
76 {
78 if ( xChild.is() )
79 {
80 VCLXAccessibleTabPage* pVCLXAccessibleTabPage = static_cast< VCLXAccessibleTabPage* >( xChild.get() );
81 if ( pVCLXAccessibleTabPage )
82 pVCLXAccessibleTabPage->SetSelected( bSelected );
83 }
84 }
85}
86
87
89{
90 if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() )
91 {
93 if ( xChild.is() )
94 {
95 VCLXAccessibleTabPage* pVCLXAccessibleTabPage = static_cast< VCLXAccessibleTabPage* >( xChild.get() );
96 if ( pVCLXAccessibleTabPage )
97 pVCLXAccessibleTabPage->SetPageText( pVCLXAccessibleTabPage->GetPageText() );
98 }
99 }
100}
101
102
103void VCLXAccessibleTabControl::UpdateTabPage( sal_Int32 i, bool bNew )
104{
105 if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() )
106 {
108 if ( xChild.is() )
109 {
110 VCLXAccessibleTabPage* pVCLXAccessibleTabPage = static_cast< VCLXAccessibleTabPage* >( xChild.get() );
111 if ( pVCLXAccessibleTabPage )
112 pVCLXAccessibleTabPage->Update( bNew );
113 }
114 }
115}
116
117
119{
120 if ( i < 0 || o3tl::make_unsigned(i) > m_aAccessibleChildren.size() )
121 return;
122
123 // insert entry in child list
125
126 // send accessible child event
128 if ( xChild.is() )
129 {
130 Any aOldValue, aNewValue;
131 aNewValue <<= xChild;
132 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
133 }
134}
135
136
138{
139 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
140 return;
141
142 // get the accessible of the removed page
144
145 // remove entry in child list
147
148 // send accessible child event
149 if ( xChild.is() )
150 {
151 Any aOldValue, aNewValue;
152 aOldValue <<= xChild;
153 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
154
155 Reference< XComponent > xComponent( xChild, UNO_QUERY );
156 if ( xComponent.is() )
157 xComponent->dispose();
158 }
159}
160
161
163{
164 switch ( rVclWindowEvent.GetId() )
165 {
166 case VclEventId::TabpageActivate:
167 case VclEventId::TabpageDeactivate:
168 {
169 if ( m_pTabControl )
170 {
171 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
172 sal_uInt16 nPagePos = m_pTabControl->GetPagePos( nPageId );
174 UpdateSelected( nPagePos, rVclWindowEvent.GetId() == VclEventId::TabpageActivate );
175 }
176 }
177 break;
178 case VclEventId::TabpagePageTextChanged:
179 {
180 if ( m_pTabControl )
181 {
182 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
183 sal_uInt16 nPagePos = m_pTabControl->GetPagePos( nPageId );
184 UpdatePageText( nPagePos );
185 }
186 }
187 break;
188 case VclEventId::TabpageInserted:
189 {
190 if ( m_pTabControl )
191 {
192 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
193 sal_uInt16 nPagePos = m_pTabControl->GetPagePos( nPageId );
194 InsertChild( nPagePos );
195 }
196 }
197 break;
198 case VclEventId::TabpageRemoved:
199 {
200 if ( m_pTabControl )
201 {
202 sal_uInt16 nPageId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
203 for ( sal_Int64 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
204 {
206 if ( xChild.is() )
207 {
208 VCLXAccessibleTabPage* pVCLXAccessibleTabPage = static_cast< VCLXAccessibleTabPage* >( xChild.get() );
209 if ( pVCLXAccessibleTabPage && pVCLXAccessibleTabPage->GetPageId() == nPageId )
210 {
211 RemoveChild( i );
212 break;
213 }
214 }
215 }
216 }
217 }
218 break;
219 case VclEventId::TabpageRemovedAll:
220 {
221 for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
222 RemoveChild( i );
223 }
224 break;
225 case VclEventId::WindowGetFocus:
226 case VclEventId::WindowLoseFocus:
227 {
229 }
230 break;
231 case VclEventId::ObjectDying:
232 {
233 if ( m_pTabControl )
234 {
235 m_pTabControl = nullptr;
236
237 // dispose all tab pages
238 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
239 {
240 Reference< XComponent > xComponent( i, UNO_QUERY );
241 if ( xComponent.is() )
242 xComponent->dispose();
243 }
244 m_aAccessibleChildren.clear();
245 }
246
247 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
248 }
249 break;
250 default:
251 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
252 }
253}
254
255
257{
258 switch ( rVclWindowEvent.GetId() )
259 {
260 case VclEventId::WindowShow:
261 case VclEventId::WindowHide:
262 {
263 if ( m_pTabControl )
264 {
265 vcl::Window* pChild = static_cast< vcl::Window* >( rVclWindowEvent.GetData() );
266 if ( pChild && pChild->GetType() == WindowType::TABPAGE )
267 {
268 for ( sal_Int32 i = 0, nCount = m_pTabControl->GetPageCount(); i < nCount; ++i )
269 {
270 sal_uInt16 nPageId = m_pTabControl->GetPageId( static_cast<sal_uInt16>(i) );
271 TabPage* pTabPage = m_pTabControl->GetTabPage( nPageId );
272 if ( pTabPage == static_cast<TabPage*>(pChild) )
273 UpdateTabPage( i, rVclWindowEvent.GetId() == VclEventId::WindowShow );
274 }
275 }
276 }
277 }
278 break;
279 default:
280 VCLXAccessibleComponent::ProcessWindowChildEvent( rVclWindowEvent );
281 }
282}
283
284
286{
287 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
288
289 if ( m_pTabControl )
290 rStateSet |= AccessibleStateType::FOCUSABLE;
291}
292
293
294// XComponent
295
296
298{
299 VCLXAccessibleComponent::disposing();
300
301 if ( !m_pTabControl )
302 return;
303
304 m_pTabControl = nullptr;
305
306 // dispose all tab pages
307 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
308 {
309 Reference< XComponent > xComponent( i, UNO_QUERY );
310 if ( xComponent.is() )
311 xComponent->dispose();
312 }
313 m_aAccessibleChildren.clear();
314}
315
316
317// XServiceInfo
318
319
321{
322 return "com.sun.star.comp.toolkit.AccessibleTabControl";
323}
324
325
327{
328 return { "com.sun.star.awt.AccessibleTabControl" };
329}
330
331
332// XAccessibleContext
333
334
336{
337 OExternalLockGuard aGuard( this );
338
339 return m_aAccessibleChildren.size();
340}
341
342
344{
345 OExternalLockGuard aGuard( this );
346
347 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
348 throw IndexOutOfBoundsException();
349
350 return implGetAccessibleChild( i );
351}
352
354{
356 if ( !xChild.is() )
357 {
358 sal_uInt16 nPageId = m_pTabControl ? m_pTabControl->GetPageId(static_cast<sal_uInt16>(i)) : 0;
359 if (nPageId)
360 {
362
363 // insert into tab page list
364 m_aAccessibleChildren[i] = xChild;
365 }
366 }
367
368 return xChild;
369}
370
371
373{
374 OExternalLockGuard aGuard( this );
375
376 return AccessibleRole::PAGE_TAB_LIST;
377}
378
379
381{
382 OExternalLockGuard aGuard( this );
383
384 return OUString();
385}
386
387
388// XAccessibleSelection
389
390
392{
393 OExternalLockGuard aGuard( this );
394
395 if ( nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size() )
396 throw IndexOutOfBoundsException();
397
398 if ( m_pTabControl )
399 m_pTabControl->SelectTabPage( m_pTabControl->GetPageId( static_cast<sal_uInt16>(nChildIndex) ) );
400}
401
402
404{
405 OExternalLockGuard aGuard( this );
406
407 if ( nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size() )
408 throw IndexOutOfBoundsException();
409
410 return implIsAccessibleChildSelected( nChildIndex );
411}
412
414{
415 bool bSelected = false;
416 if ( m_pTabControl && m_pTabControl->GetCurPageId() == m_pTabControl->GetPageId( static_cast<sal_uInt16>(nChildIndex) ) )
417 bSelected = true;
418
419 return bSelected;
420}
421
422
424{
425 // This method makes no sense in a tab control, and so does nothing.
426}
427
428
430{
432}
433
434
436{
437 OExternalLockGuard aGuard( this );
438
439 return 1;
440}
441
442
444{
445 OExternalLockGuard aGuard( this );
446
447 if ( nSelectedChildIndex != 0 )
448 throw IndexOutOfBoundsException();
449
451
452 for ( std::size_t i = 0, nCount = m_aAccessibleChildren.size(); i < nCount; i++ )
453 {
455 {
456 xChild = implGetAccessibleChild( i );
457 break;
458 }
459 }
460
461 return xChild;
462}
463
464
466{
467 OExternalLockGuard aGuard( this );
468
469 if ( nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size() )
470 throw IndexOutOfBoundsException();
471
472 // This method makes no sense in a tab control, and so does nothing.
473}
474
475
476/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 nPageId
void UpdateSelected(sal_Int32 i, bool bSelected)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
bool implIsAccessibleChildSelected(sal_Int32 nChildIndex)
virtual void SAL_CALL selectAllAccessibleChildren() override
AccessibleChildren m_aAccessibleChildren
virtual void SAL_CALL deselectAccessibleChild(sal_Int64 nChildIndex) override
virtual void SAL_CALL clearAccessibleSelection() override
VCLXAccessibleTabControl(VCLXWindow *pVCLXWindow)
void UpdateTabPage(sal_Int32 i, bool bNew)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(sal_Int64 nSelectedChildIndex) override
virtual sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int64 nChildIndex) override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet) override
virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount() override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual OUString SAL_CALL getImplementationName() override
virtual void ProcessWindowChildEvent(const VclWindowEvent &rVclWindowEvent) override
virtual void SAL_CALL disposing() override
css::uno::Reference< css::accessibility::XAccessible > implGetAccessibleChild(sal_Int64 i)
virtual OUString SAL_CALL getAccessibleName() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
virtual void SAL_CALL selectAccessibleChild(sal_Int64 nChildIndex) override
void SetFocused(bool bFocused)
void SetPageText(const OUString &sPageText)
void SetSelected(bool bSelected)
sal_uInt16 GetPageId() const
void clear()
VclEventId GetId() const
void * GetData() const
WindowType GetType() const
int nCount
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
unsigned char sal_Bool