Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svtools/source/control/accessibletabbar.cxx
Line
Count
Source
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
20
#include "accessibletabbar.hxx"
21
#include "accessibletabbarpagelist.hxx"
22
23
#include <svtools/tabbar.hxx>
24
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
25
#include <com/sun/star/accessibility/AccessibleRole.hpp>
26
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
27
#include <com/sun/star/awt/XDevice.hpp>
28
#include <com/sun/star/awt/XVclWindowPeer.hpp>
29
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30
#include <comphelper/accessiblecontexthelper.hxx>
31
#include <cppuhelper/supportsservice.hxx>
32
#include <unotools/accessiblerelationsethelper.hxx>
33
#include <i18nlangtag/languagetag.hxx>
34
#include <o3tl/safeint.hxx>
35
#include <vcl/svapp.hxx>
36
#include <vcl/settings.hxx>
37
#include <vcl/unohelp.hxx>
38
#include <vcl/vclevent.hxx>
39
40
namespace accessibility
41
{
42
43
using namespace ::com::sun::star;
44
using namespace ::com::sun::star::uno;
45
using namespace ::com::sun::star::lang;
46
using namespace ::com::sun::star::accessibility;
47
using namespace ::comphelper;
48
49
AccessibleTabBar::AccessibleTabBar(TabBar* pTabBar)
50
0
    : AccessibleTabBarBase(pTabBar)
51
0
{
52
0
    if ( m_pTabBar )
53
0
        m_aAccessibleChildren.assign(m_pTabBar->GetAccessibleChildWindowCount() + 1, {});
54
0
}
55
56
57
void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
58
0
{
59
0
    Any aOldValue, aNewValue;
60
61
0
    switch ( rVclWindowEvent.GetId() )
62
0
    {
63
0
        case VclEventId::WindowEnabled:
64
0
        {
65
0
            aNewValue <<= AccessibleStateType::SENSITIVE;
66
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
67
0
            aNewValue <<= AccessibleStateType::ENABLED;
68
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
69
0
        }
70
0
        break;
71
0
        case VclEventId::WindowDisabled:
72
0
        {
73
0
            aOldValue <<= AccessibleStateType::ENABLED;
74
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
75
0
            aOldValue <<= AccessibleStateType::SENSITIVE;
76
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
77
0
        }
78
0
        break;
79
0
        case VclEventId::WindowGetFocus:
80
0
        {
81
0
            aNewValue <<= AccessibleStateType::FOCUSED;
82
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
83
0
        }
84
0
        break;
85
0
        case VclEventId::WindowLoseFocus:
86
0
        {
87
0
            aOldValue <<= AccessibleStateType::FOCUSED;
88
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
89
0
        }
90
0
        break;
91
0
        case VclEventId::WindowShow:
92
0
        {
93
0
            aNewValue <<= AccessibleStateType::SHOWING;
94
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
95
0
        }
96
0
        break;
97
0
        case VclEventId::WindowHide:
98
0
        {
99
0
            aOldValue <<= AccessibleStateType::SHOWING;
100
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
101
0
        }
102
0
        break;
103
0
        default:
104
0
        {
105
0
            AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent );
106
0
        }
107
0
        break;
108
0
    }
109
0
}
110
111
112
void AccessibleTabBar::FillAccessibleStateSet( sal_Int64& rStateSet )
113
0
{
114
0
    if ( !m_pTabBar )
115
0
        return;
116
117
0
    if ( m_pTabBar->IsEnabled() )
118
0
    {
119
0
        rStateSet |= AccessibleStateType::ENABLED;
120
0
        rStateSet |= AccessibleStateType::SENSITIVE;
121
0
    }
122
123
0
    rStateSet |= AccessibleStateType::FOCUSABLE;
124
125
0
    if ( m_pTabBar->HasFocus() )
126
0
        rStateSet |= AccessibleStateType::FOCUSED;
127
128
0
    rStateSet |= AccessibleStateType::VISIBLE;
129
130
0
    if ( m_pTabBar->IsVisible() )
131
0
        rStateSet |= AccessibleStateType::SHOWING;
132
133
0
    if ( m_pTabBar->GetStyle() & WB_SIZEABLE )
134
0
        rStateSet |= AccessibleStateType::RESIZABLE;
135
0
}
136
137
// OAccessible
138
139
awt::Rectangle AccessibleTabBar::implGetBounds()
140
0
{
141
0
    awt::Rectangle aBounds;
142
0
    if ( m_pTabBar )
143
0
        aBounds = vcl::unohelper::ConvertToAWTRect(
144
0
            tools::Rectangle(m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel()));
145
146
0
    return aBounds;
147
0
}
148
149
150
// XComponent
151
152
153
void AccessibleTabBar::disposing()
154
0
{
155
0
    AccessibleTabBarBase::disposing();
156
157
    // dispose all children
158
0
    for (const rtl::Reference<comphelper::OAccessible>& pChild : m_aAccessibleChildren)
159
0
    {
160
0
        if (pChild.is())
161
0
            pChild->dispose();
162
0
    }
163
0
    m_aAccessibleChildren.clear();
164
0
}
165
166
// XAccessibleContext
167
168
169
sal_Int64 AccessibleTabBar::getAccessibleChildCount()
170
0
{
171
0
    OExternalLockGuard aGuard( this );
172
173
0
    return m_aAccessibleChildren.size();
174
0
}
175
176
177
Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int64 i )
178
0
{
179
0
    OExternalLockGuard aGuard( this );
180
181
0
    if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
182
0
        throw IndexOutOfBoundsException();
183
184
0
    rtl::Reference<comphelper::OAccessible> pChild = m_aAccessibleChildren[i];
185
0
    if (!pChild.is())
186
0
    {
187
0
        if ( m_pTabBar )
188
0
        {
189
0
            sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount();
190
191
0
            if ( i < nCount )
192
0
            {
193
0
                vcl::Window* pChildWin
194
0
                    = m_pTabBar->GetAccessibleChildWindow(static_cast<sal_uInt16>(i));
195
0
                if (pChildWin)
196
0
                    pChild = pChildWin->GetAccessible();
197
0
            }
198
0
            else if ( i == nCount )
199
0
            {
200
0
                pChild = new AccessibleTabBarPageList(m_pTabBar, i);
201
0
            }
202
203
            // insert into child list
204
0
            m_aAccessibleChildren[i] = pChild;
205
0
        }
206
0
    }
207
208
0
    return pChild;
209
0
}
210
211
212
Reference< XAccessible > AccessibleTabBar::getAccessibleParent(  )
213
0
{
214
0
    OExternalLockGuard aGuard( this );
215
216
0
    Reference< XAccessible > xParent;
217
0
    if ( m_pTabBar )
218
0
        xParent = m_pTabBar->GetAccessibleParent();
219
220
0
    return xParent;
221
0
}
222
223
224
sal_Int64 AccessibleTabBar::getAccessibleIndexInParent(  )
225
0
{
226
0
    OExternalLockGuard aGuard( this );
227
228
0
    sal_Int64 nIndexInParent = -1;
229
0
    if ( m_pTabBar )
230
0
    {
231
0
        vcl::Window* pParent = m_pTabBar->GetAccessibleParentWindow();
232
0
        if ( pParent )
233
0
        {
234
0
            for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i )
235
0
            {
236
0
                vcl::Window* pChild = pParent->GetAccessibleChildWindow( i );
237
0
                if ( pChild == static_cast< vcl::Window* >( m_pTabBar ) )
238
0
                {
239
0
                    nIndexInParent = i;
240
0
                    break;
241
0
                }
242
0
            }
243
0
        }
244
0
    }
245
246
0
    return nIndexInParent;
247
0
}
248
249
250
sal_Int16 AccessibleTabBar::getAccessibleRole(  )
251
0
{
252
0
    OExternalLockGuard aGuard( this );
253
254
0
    return AccessibleRole::PANEL;
255
0
}
256
257
OUString AccessibleTabBar::getAccessibleDescription( )
258
0
{
259
0
    OExternalLockGuard aGuard( this );
260
261
0
    if (m_pTabBar)
262
0
        return m_pTabBar->GetAccessibleDescription();
263
264
0
    return OUString();
265
0
}
266
267
OUString AccessibleTabBar::getAccessibleName(  )
268
0
{
269
0
    OExternalLockGuard aGuard( this );
270
271
0
    if (m_pTabBar)
272
0
        return m_pTabBar->GetAccessibleName();
273
274
0
    return OUString();
275
0
}
276
277
Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet(  )
278
0
{
279
0
    OExternalLockGuard aGuard( this );
280
281
0
    return new utl::AccessibleRelationSetHelper;
282
0
}
283
284
sal_Int64 AccessibleTabBar::getAccessibleStateSet(  )
285
0
{
286
0
    OExternalLockGuard aGuard( this );
287
288
0
    sal_Int64 nStateSet = 0;
289
290
0
    if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
291
0
    {
292
0
        FillAccessibleStateSet( nStateSet );
293
0
    }
294
0
    else
295
0
    {
296
0
        nStateSet |= AccessibleStateType::DEFUNC;
297
0
    }
298
299
0
    return nStateSet;
300
0
}
301
302
303
Locale AccessibleTabBar::getLocale(  )
304
0
{
305
0
    OExternalLockGuard aGuard( this );
306
307
0
    return Application::GetSettings().GetLanguageTag().getLocale();
308
0
}
309
310
// XAccessibleComponent
311
Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint )
312
0
{
313
0
    OExternalLockGuard aGuard( this );
314
315
0
    for( sal_Int64 i = 0; i < getAccessibleChildCount(); ++i )
316
0
    {
317
0
        Reference< XAccessible > xAcc = getAccessibleChild( i );
318
0
        if ( xAcc.is() )
319
0
        {
320
0
            Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
321
0
            if ( xComp.is() )
322
0
            {
323
0
                tools::Rectangle aRect = vcl::unohelper::ConvertToVCLRect(xComp->getBounds());
324
0
                Point aPos = vcl::unohelper::ConvertToVCLPoint(rPoint);
325
0
                if ( aRect.Contains( aPos ) )
326
0
                {
327
0
                    return xAcc;
328
0
                }
329
0
            }
330
0
        }
331
0
    }
332
333
0
    return nullptr;
334
0
}
335
336
void AccessibleTabBar::grabFocus(  )
337
0
{
338
0
    OExternalLockGuard aGuard( this );
339
340
0
    if ( m_pTabBar )
341
0
        m_pTabBar->GrabFocus();
342
0
}
343
344
345
sal_Int32 AccessibleTabBar::getForeground(  )
346
0
{
347
0
    OExternalLockGuard aGuard( this );
348
349
0
    Color nColor;
350
0
    if ( m_pTabBar )
351
0
    {
352
0
        if ( m_pTabBar->IsControlForeground() )
353
0
            nColor = m_pTabBar->GetControlForeground();
354
0
        else
355
0
        {
356
0
            vcl::Font aFont;
357
0
            if ( m_pTabBar->IsControlFont() )
358
0
                aFont = m_pTabBar->GetControlFont();
359
0
            else
360
0
                aFont = m_pTabBar->GetFont();
361
0
            nColor = aFont.GetColor();
362
0
        }
363
0
    }
364
365
0
    return sal_Int32(nColor);
366
0
}
367
368
369
sal_Int32 AccessibleTabBar::getBackground(  )
370
0
{
371
0
    OExternalLockGuard aGuard( this );
372
373
0
    Color nColor;
374
0
    if ( m_pTabBar )
375
0
    {
376
0
        if ( m_pTabBar->IsControlBackground() )
377
0
            nColor = m_pTabBar->GetControlBackground();
378
0
        else
379
0
            nColor = m_pTabBar->GetBackground().GetColor();
380
0
    }
381
382
0
    return sal_Int32(nColor);
383
0
}
384
385
386
// XAccessibleExtendedComponent
387
388
OUString AccessibleTabBar::getTitledBorderText(  )
389
0
{
390
0
    OExternalLockGuard aGuard( this );
391
392
0
    OUString sText;
393
0
    if ( m_pTabBar )
394
0
        sText = m_pTabBar->GetText();
395
396
0
    return sText;
397
0
}
398
399
400
OUString AccessibleTabBar::getToolTipText(  )
401
0
{
402
0
    OExternalLockGuard aGuard( this );
403
404
0
    OUString sText;
405
0
    if ( m_pTabBar )
406
0
        sText = m_pTabBar->GetQuickHelpText();
407
408
0
    return sText;
409
0
}
410
411
412
}   // namespace accessibility
413
414
415
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */