Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/vcl/source/accessibility/AccessibleBrowseBoxHeaderBar.cxx
Line
Count
Source (jump to first uncovered line)
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 <vcl/accessibility/AccessibleBrowseBoxHeaderBar.hxx>
21
#include <vcl/accessibletableprovider.hxx>
22
#include <vcl/unohelp.hxx>
23
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24
25
using ::com::sun::star::uno::Reference;
26
using ::com::sun::star::uno::Sequence;
27
using ::com::sun::star::uno::Any;
28
29
using namespace ::com::sun::star;
30
using namespace ::com::sun::star::accessibility;
31
32
33
// Ctor/Dtor/disposing --------------------------------------------------------
34
35
AccessibleBrowseBoxHeaderBar::AccessibleBrowseBoxHeaderBar(
36
        const Reference< XAccessible >& rxParent,
37
        vcl::IAccessibleTableProvider& rBrowseBox,
38
        AccessibleBrowseBoxObjType eObjType ) :
39
0
    AccessibleBrowseBoxTableBase( rxParent, rBrowseBox,eObjType )
40
0
{
41
0
    OSL_ENSURE( isRowBar() || isColumnBar(),
42
0
        "AccessibleBrowseBoxHeaderBar - invalid object type" );
43
0
}
44
45
AccessibleBrowseBoxHeaderBar::~AccessibleBrowseBoxHeaderBar()
46
0
{
47
0
}
48
49
// XAccessibleContext ---------------------------------------------------------
50
51
Reference< XAccessible > SAL_CALL
52
AccessibleBrowseBoxHeaderBar::getAccessibleChild( sal_Int64 nChildIndex )
53
0
{
54
0
    SolarMethodGuard aGuard(getMutex());
55
0
    ensureIsAlive();
56
57
0
    ensureIsValidHeaderIndex( nChildIndex );
58
0
    return implGetChild( nChildIndex, implToVCLColumnPos( nChildIndex ) );
59
0
}
60
61
sal_Int64 SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleIndexInParent()
62
0
{
63
0
    return isRowBar() ? vcl::BBINDEX_ROWHEADERBAR : vcl::BBINDEX_COLUMNHEADERBAR;
64
0
}
65
66
// XAccessibleComponent -------------------------------------------------------
67
68
Reference< XAccessible > SAL_CALL
69
AccessibleBrowseBoxHeaderBar::getAccessibleAtPoint( const awt::Point& rPoint )
70
0
{
71
0
    SolarMethodGuard aGuard(getMutex());
72
0
    ensureIsAlive();
73
74
0
    sal_Int32 nRow = 0;
75
0
    sal_uInt16 nColumnPos = 0;
76
0
    bool bConverted
77
0
        = isRowBar()
78
0
              ? mpBrowseBox->ConvertPointToRowHeader(nRow, vcl::unohelper::ConvertToVCLPoint(rPoint))
79
0
              : mpBrowseBox->ConvertPointToColumnHeader(nColumnPos,
80
0
                                                        vcl::unohelper::ConvertToVCLPoint(rPoint));
81
82
0
    return bConverted ? implGetChild( nRow, nColumnPos ) : Reference< XAccessible >();
83
0
}
84
85
void SAL_CALL AccessibleBrowseBoxHeaderBar::grabFocus()
86
0
{
87
0
    SolarMethodGuard aGuard(getMutex());
88
89
0
    ensureIsAlive();
90
    // focus on header not supported
91
0
}
92
93
// XAccessibleTable -----------------------------------------------------------
94
95
OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowDescription( sal_Int32 nRow )
96
0
{
97
0
    SolarMethodGuard aGuard(getMutex());
98
99
0
    ensureIsAlive();
100
0
    ensureIsValidRow( nRow );
101
0
    return OUString();  // no headers in headers
102
0
}
103
104
OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnDescription( sal_Int32 nColumn )
105
0
{
106
0
    SolarMethodGuard aGuard(getMutex());
107
108
0
    ensureIsAlive();
109
0
    ensureIsValidColumn( nColumn );
110
0
    return OUString();  // no headers in headers
111
0
}
112
113
Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowHeaders()
114
0
{
115
0
    SolarMethodGuard aGuard(getMutex());
116
117
0
    ensureIsAlive();
118
0
    return nullptr;        // no headers in headers
119
0
}
120
121
Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnHeaders()
122
0
{
123
0
    SolarMethodGuard aGuard(getMutex());
124
125
0
    ensureIsAlive();
126
0
    return nullptr;        // no headers in headers
127
0
}
128
129
Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleRows()
130
0
{
131
0
    SolarMethodGuard aGuard(getMutex());
132
0
    ensureIsAlive();
133
134
0
    Sequence< sal_Int32 > aSelSeq;
135
    // row of column header bar not selectable
136
0
    if( isRowBar() )
137
0
        implGetSelectedRows( aSelSeq );
138
0
    return aSelSeq;
139
0
}
140
141
Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleColumns()
142
0
{
143
0
    SolarMethodGuard aGuard(getMutex());
144
0
    ensureIsAlive();
145
146
0
    Sequence< sal_Int32 > aSelSeq;
147
    // column of row header bar ("handle column") not selectable
148
0
    if( isColumnBar() )
149
0
        implGetSelectedColumns( aSelSeq );
150
0
    return aSelSeq;
151
0
}
152
153
sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleRowSelected( sal_Int32 nRow )
154
0
{
155
0
    SolarMethodGuard aGuard(getMutex());
156
157
0
    ensureIsAlive();
158
0
    ensureIsValidRow( nRow );
159
0
    return isRowBar() && implIsRowSelected( nRow );
160
0
}
161
162
sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleColumnSelected( sal_Int32 nColumn )
163
0
{
164
0
    SolarMethodGuard aGuard(getMutex());
165
166
0
    ensureIsAlive();
167
0
    ensureIsValidColumn( nColumn );
168
0
    return isColumnBar() && implIsColumnSelected( nColumn );
169
0
}
170
171
Reference< XAccessible > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleCellAt(
172
        sal_Int32 nRow, sal_Int32 nColumn )
173
0
{
174
0
    SolarMethodGuard aGuard(getMutex());
175
176
0
    ensureIsAlive();
177
0
    ensureIsValidAddress( nRow, nColumn );
178
179
0
    return implGetChild( nRow, implToVCLColumnPos( nColumn ) );
180
0
}
181
182
sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleSelected(
183
        sal_Int32 nRow, sal_Int32 nColumn )
184
0
{
185
0
    SolarMethodGuard aGuard(getMutex());
186
0
    ensureIsAlive();
187
188
0
    ensureIsValidAddress( nRow, nColumn );
189
0
    return isRowBar() ? implIsRowSelected( nRow ) : implIsColumnSelected( nColumn );
190
0
}
191
192
// XAccessibleSelection -------------------------------------------------------
193
194
void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAccessibleChild( sal_Int64 nChildIndex )
195
0
{
196
0
    SolarMethodGuard aGuard(getMutex());
197
0
    ensureIsAlive();
198
199
0
    ensureIsValidHeaderIndex( nChildIndex );
200
0
    if( isRowBar() )
201
0
        implSelectRow( nChildIndex, true );
202
0
    else
203
0
        implSelectColumn( implToVCLColumnPos( nChildIndex ), true );
204
0
}
205
206
sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleChildSelected( sal_Int64 nChildIndex )
207
0
{
208
    // using interface methods - no mutex
209
0
    return isRowBar() ?
210
0
        isAccessibleRowSelected( nChildIndex ) :
211
0
        isAccessibleColumnSelected( nChildIndex );
212
0
}
213
214
void SAL_CALL AccessibleBrowseBoxHeaderBar::clearAccessibleSelection()
215
0
{
216
0
    SolarMethodGuard aGuard(getMutex());
217
0
    ensureIsAlive();
218
219
0
    mpBrowseBox->SetNoSelection();
220
0
}
221
222
void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAllAccessibleChildren()
223
0
{
224
0
    SolarMethodGuard aGuard(getMutex());
225
0
    ensureIsAlive();
226
227
    // no multiselection of columns possible
228
0
    if( isRowBar() )
229
0
        mpBrowseBox->SelectAll();
230
0
    else
231
0
        implSelectColumn( implToVCLColumnPos( 0 ), true );
232
0
}
233
234
sal_Int64 SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChildCount()
235
0
{
236
0
    SolarMethodGuard aGuard(getMutex());
237
0
    ensureIsAlive();
238
239
0
    return isRowBar() ? implGetSelectedRowCount() : implGetSelectedColumnCount();
240
0
}
241
242
Reference< XAccessible > SAL_CALL
243
AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
244
0
{
245
0
    SolarMethodGuard aGuard(getMutex());
246
0
    ensureIsAlive();
247
248
    // method may throw lang::IndexOutOfBoundsException
249
0
    sal_Int64 nIndex = implGetChildIndexFromSelectedIndex( nSelectedChildIndex );
250
0
    assert(nIndex < std::numeric_limits<sal_Int32>::max());
251
0
    return implGetChild( nIndex, implToVCLColumnPos( nIndex ) );
252
0
}
253
254
void SAL_CALL AccessibleBrowseBoxHeaderBar::deselectAccessibleChild(
255
        sal_Int64 nSelectedChildIndex )
256
0
{
257
0
    SolarMethodGuard aGuard(getMutex());
258
0
    ensureIsAlive();
259
260
    // method may throw lang::IndexOutOfBoundsException
261
0
    if ( isAccessibleChildSelected(nSelectedChildIndex) )
262
0
    {
263
0
        if( isRowBar() )
264
0
            implSelectRow( nSelectedChildIndex, false );
265
0
        else
266
0
            implSelectColumn( implToVCLColumnPos( nSelectedChildIndex ), false );
267
0
    }
268
0
}
269
270
// XInterface -----------------------------------------------------------------
271
272
Any SAL_CALL AccessibleBrowseBoxHeaderBar::queryInterface( const uno::Type& rType )
273
0
{
274
0
    Any aAny( AccessibleBrowseBoxTableBase::queryInterface( rType ) );
275
0
    return aAny.hasValue() ?
276
0
        aAny : AccessibleBrowseBoxHeaderBarImplHelper::queryInterface( rType );
277
0
}
278
279
void SAL_CALL AccessibleBrowseBoxHeaderBar::acquire() noexcept
280
0
{
281
0
    AccessibleBrowseBoxTableBase::acquire();
282
0
}
283
284
void SAL_CALL AccessibleBrowseBoxHeaderBar::release() noexcept
285
0
{
286
0
    AccessibleBrowseBoxTableBase::release();
287
0
}
288
289
// XServiceInfo ---------------------------------------------------------------
290
291
OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationName()
292
0
{
293
0
    return u"com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderBar"_ustr;
294
0
}
295
296
// internal virtual methods ---------------------------------------------------
297
298
tools::Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBox()
299
0
{
300
0
    return mpBrowseBox->calcHeaderRect(isColumnBar());
301
0
}
302
303
sal_Int32 AccessibleBrowseBoxHeaderBar::implGetRowCount() const
304
0
{
305
    // column header bar: only 1 row
306
0
    return isRowBar() ? AccessibleBrowseBoxTableBase::implGetRowCount() : 1;
307
0
}
308
309
sal_Int32 AccessibleBrowseBoxHeaderBar::implGetColumnCount() const
310
0
{
311
    // row header bar ("handle column"): only 1 column
312
0
    return isColumnBar() ? AccessibleBrowseBoxTableBase::implGetColumnCount() : 1;
313
0
}
314
315
// internal helper methods ----------------------------------------------------
316
317
Reference< XAccessible > AccessibleBrowseBoxHeaderBar::implGetChild(
318
        sal_Int32 nRow, sal_uInt16 nColumnPos )
319
0
{
320
0
    return isRowBar() ?
321
0
        mpBrowseBox->CreateAccessibleRowHeader( nRow ) :
322
0
        mpBrowseBox->CreateAccessibleColumnHeader( nColumnPos );
323
0
}
324
325
sal_Int64 AccessibleBrowseBoxHeaderBar::implGetChildIndexFromSelectedIndex(
326
        sal_Int64 nSelectedChildIndex )
327
0
{
328
0
    Sequence< sal_Int32 > aSelSeq;
329
0
    if( isRowBar() )
330
0
        implGetSelectedRows( aSelSeq );
331
0
    else
332
0
        implGetSelectedColumns( aSelSeq );
333
334
0
    if( (nSelectedChildIndex < 0) || (nSelectedChildIndex >= aSelSeq.getLength()) )
335
0
        throw lang::IndexOutOfBoundsException();
336
337
0
    return aSelSeq[ nSelectedChildIndex ];
338
0
}
339
340
void AccessibleBrowseBoxHeaderBar::ensureIsValidHeaderIndex( sal_Int32 nIndex )
341
0
{
342
0
    if( isRowBar() )
343
0
        ensureIsValidRow( nIndex );
344
0
    else
345
0
        ensureIsValidColumn( nIndex );
346
0
}
347
348
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */