LibreOffice Module accessibility (master) 1
accessibletabbar.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
21#include <svtools/tabbar.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>
33#include <o3tl/safeint.hxx>
34#include <vcl/svapp.hxx>
35#include <vcl/settings.hxx>
38
39
40namespace accessibility
41{
42
43
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;
49
50
51
52
54 :ImplInheritanceHelper( pTabBar )
55 {
56 if ( m_pTabBar )
57 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() );
58 }
59
60
62 {
63 Any aOldValue, aNewValue;
64
65 switch ( rVclWindowEvent.GetId() )
66 {
67 case VclEventId::WindowEnabled:
68 {
69 aNewValue <<= AccessibleStateType::SENSITIVE;
70 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
71 aNewValue <<= AccessibleStateType::ENABLED;
72 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
73 }
74 break;
75 case VclEventId::WindowDisabled:
76 {
77 aOldValue <<= AccessibleStateType::ENABLED;
78 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
79 aOldValue <<= AccessibleStateType::SENSITIVE;
80 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
81 }
82 break;
83 case VclEventId::WindowGetFocus:
84 {
85 aNewValue <<= AccessibleStateType::FOCUSED;
86 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
87 }
88 break;
89 case VclEventId::WindowLoseFocus:
90 {
91 aOldValue <<= AccessibleStateType::FOCUSED;
92 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
93 }
94 break;
95 case VclEventId::WindowShow:
96 {
97 aNewValue <<= AccessibleStateType::SHOWING;
98 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
99 }
100 break;
101 case VclEventId::WindowHide:
102 {
103 aOldValue <<= AccessibleStateType::SHOWING;
104 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
105 }
106 break;
107 default:
108 {
110 }
111 break;
112 }
113 }
114
115
116 void AccessibleTabBar::FillAccessibleStateSet( sal_Int64& rStateSet )
117 {
118 if ( !m_pTabBar )
119 return;
120
121 if ( m_pTabBar->IsEnabled() )
122 {
123 rStateSet |= AccessibleStateType::ENABLED;
124 rStateSet |= AccessibleStateType::SENSITIVE;
125 }
126
127 rStateSet |= AccessibleStateType::FOCUSABLE;
128
129 if ( m_pTabBar->HasFocus() )
130 rStateSet |= AccessibleStateType::FOCUSED;
131
132 rStateSet |= AccessibleStateType::VISIBLE;
133
134 if ( m_pTabBar->IsVisible() )
135 rStateSet |= AccessibleStateType::SHOWING;
136
137 if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
138 rStateSet |= AccessibleStateType::RESIZABLE;
139 }
140
141
142 // OCommonAccessibleComponent
143
144
146 {
147 awt::Rectangle aBounds;
148 if ( m_pTabBar )
149 aBounds = AWTRectangle( tools::Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) );
150
151 return aBounds;
152 }
153
154
155 // XComponent
156
157
159 {
161
162 // dispose all children
164 {
165 Reference< XComponent > xComponent( i, UNO_QUERY );
166 if ( xComponent.is() )
167 xComponent->dispose();
168 }
169 m_aAccessibleChildren.clear();
170 }
171
172
173 // XServiceInfo
174
175
177 {
178 return "com.sun.star.comp.svtools.AccessibleTabBar";
179 }
180
181
182 sal_Bool AccessibleTabBar::supportsService( const OUString& rServiceName )
183 {
184 return cppu::supportsService(this, rServiceName);
185 }
186
187
189 {
190 return { "com.sun.star.awt.AccessibleTabBar" };
191 }
192
193
194 // XAccessible
195
196
198 {
199 OExternalLockGuard aGuard( this );
200
201 return this;
202 }
203
204
205 // XAccessibleContext
206
207
209 {
210 OExternalLockGuard aGuard( this );
211
212 return m_aAccessibleChildren.size();
213 }
214
215
217 {
218 OExternalLockGuard aGuard( this );
219
220 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
221 throw IndexOutOfBoundsException();
222
224 if ( !xChild.is() )
225 {
226 if ( m_pTabBar )
227 {
228 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
229
230 if ( i < nCount )
231 {
232 vcl::Window* pChild = m_pTabBar->GetAccessibleChildWindow( static_cast<sal_uInt16>(i) );
233 if ( pChild )
234 xChild = pChild->GetAccessible();
235 }
236 else if ( i == nCount )
237 {
238 xChild = new AccessibleTabBarPageList( m_pTabBar, i );
239 }
240
241 // insert into child list
242 m_aAccessibleChildren[i] = xChild;
243 }
244 }
245
246 return xChild;
247 }
248
249
251 {
252 OExternalLockGuard aGuard( this );
253
255 if ( m_pTabBar )
256 {
257 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
258 if ( pParent )
259 xParent = pParent->GetAccessible();
260 }
261
262 return xParent;
263 }
264
265
267 {
268 OExternalLockGuard aGuard( this );
269
270 sal_Int64 nIndexInParent = -1;
271 if ( m_pTabBar )
272 {
273 vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
274 if ( pParent )
275 {
276 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
277 {
278 vcl::Window* pChild = pParent->GetAccessibleChildWindow( i );
279 if ( pChild == static_cast< vcl::Window* >( m_pTabBar ) )
280 {
281 nIndexInParent = i;
282 break;
283 }
284 }
285 }
286 }
287
288 return nIndexInParent;
289 }
290
291
293 {
294 OExternalLockGuard aGuard( this );
295
296 return AccessibleRole::PANEL;
297 }
298
299
301 {
302 OExternalLockGuard aGuard( this );
303
304 OUString sDescription;
305 if ( m_pTabBar )
306 sDescription = m_pTabBar->GetAccessibleDescription();
307
308 return sDescription;
309 }
310
311
313 {
314 OExternalLockGuard aGuard( this );
315
316 OUString sName;
317 if ( m_pTabBar )
318 sName = m_pTabBar->GetAccessibleName();
319
320 return sName;
321 }
322
323
325 {
326 OExternalLockGuard aGuard( this );
327
329 }
330
331
333 {
334 OExternalLockGuard aGuard( this );
335
336 sal_Int64 nStateSet = 0;
337
338 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
339 {
340 FillAccessibleStateSet( nStateSet );
341 }
342 else
343 {
344 nStateSet |= AccessibleStateType::DEFUNC;
345 }
346
347 return nStateSet;
348 }
349
350
352 {
353 OExternalLockGuard aGuard( this );
354
356 }
357
358
359 // XAccessibleComponent
360
361
363 {
364 OExternalLockGuard aGuard( this );
365
367 for ( size_t i = 0; i < m_aAccessibleChildren.size(); ++i )
368 {
370 if ( xAcc.is() )
371 {
372 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
373 if ( xComp.is() )
374 {
375 tools::Rectangle aRect = VCLRectangle( xComp->getBounds() );
376 Point aPos = VCLPoint( rPoint );
377 if ( aRect.Contains( aPos ) )
378 {
379 xChild = xAcc;
380 break;
381 }
382 }
383 }
384 }
385
386 return xChild;
387 }
388
389
391 {
392 OExternalLockGuard aGuard( this );
393
394 if ( m_pTabBar )
395 m_pTabBar->GrabFocus();
396 }
397
398
400 {
401 OExternalLockGuard aGuard( this );
402
403 Color nColor;
404 if ( m_pTabBar )
405 {
406 if ( m_pTabBar->IsControlForeground() )
407 nColor = m_pTabBar->GetControlForeground();
408 else
409 {
410 vcl::Font aFont;
411 if ( m_pTabBar->IsControlFont() )
412 aFont = m_pTabBar->GetControlFont();
413 else
414 aFont = m_pTabBar->GetFont();
415 nColor = aFont.GetColor();
416 }
417 }
418
419 return sal_Int32(nColor);
420 }
421
422
424 {
425 OExternalLockGuard aGuard( this );
426
427 Color nColor;
428 if ( m_pTabBar )
429 {
430 if ( m_pTabBar->IsControlBackground() )
431 nColor = m_pTabBar->GetControlBackground();
432 else
433 nColor = m_pTabBar->GetBackground().GetColor();
434 }
435
436 return sal_Int32(nColor);
437 }
438
439
440 // XAccessibleExtendedComponent
441
442
444 {
445 OExternalLockGuard aGuard( this );
446
448 if ( m_pTabBar )
449 {
450 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY );
451 if ( xDev.is() )
452 {
453 vcl::Font aFont;
454 if ( m_pTabBar->IsControlFont() )
455 aFont = m_pTabBar->GetControlFont();
456 else
457 aFont = m_pTabBar->GetFont();
458 rtl::Reference<VCLXFont> pVCLXFont = new VCLXFont;
459 pVCLXFont->Init( *xDev, aFont );
460 xFont = pVCLXFont;
461 }
462 }
463
464 return xFont;
465 }
466
467
469 {
470 OExternalLockGuard aGuard( this );
471
472 OUString sText;
473 if ( m_pTabBar )
474 sText = m_pTabBar->GetText();
475
476 return sText;
477 }
478
479
481 {
482 OExternalLockGuard aGuard( this );
483
484 OUString sText;
485 if ( m_pTabBar )
486 sText = m_pTabBar->GetQuickHelpText();
487
488 return sText;
489 }
490
491
492} // namespace accessibility
493
494
495/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LanguageTag & GetLanguageTag() const
static const AllSettings & GetSettings()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
VclEventId GetId() const
virtual void SAL_CALL disposing() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent)
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual css::awt::Rectangle implGetBounds() override
virtual OUString SAL_CALL getTitledBorderText() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual OUString SAL_CALL getToolTipText() override
virtual OUString SAL_CALL getAccessibleName() override
virtual css::uno::Reference< css::awt::XFont > SAL_CALL getFont() override
virtual sal_Int32 SAL_CALL getForeground() override
virtual OUString SAL_CALL getAccessibleDescription() override
virtual void SAL_CALL grabFocus() override
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
AccessibleChildren m_aAccessibleChildren
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual sal_Int32 SAL_CALL getBackground() override
void FillAccessibleStateSet(sal_Int64 &rStateSet)
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
bool Contains(const Point &rPOINT) const
const Color & GetColor() const
vcl::Window * GetAccessibleChildWindow(sal_uInt16 n)
sal_uInt16 GetAccessibleChildWindowCount()
css::uno::Reference< css::accessibility::XAccessible > GetAccessible(bool bCreate=true)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
int nCount
OUString sName
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
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
WinBits const WB_SIZEABLE