Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/accessibility/AccessibleBrowseBoxTableCell.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
21
#include <vcl/accessibility/AccessibleBrowseBoxTableCell.hxx>
22
23
#include <vcl/accessibletableprovider.hxx>
24
#include <vcl/unohelp.hxx>
25
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
26
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27
28
namespace
29
{
30
    /// @throws css::lang::IndexOutOfBoundsException
31
    void checkIndex_Impl( sal_Int32 _nIndex, std::u16string_view _sText )
32
0
    {
33
0
        if ( _nIndex >= static_cast<sal_Int32>(_sText.size()) )
34
0
            throw css::lang::IndexOutOfBoundsException();
35
0
    }
36
37
    sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount )
38
0
    {
39
0
        return _nRow * _nColumnCount + _nColumn;
40
0
    }
41
}
42
using namespace ::com::sun::star::lang;
43
using namespace comphelper;
44
using namespace ::com::sun::star::uno;
45
using ::com::sun::star::accessibility::XAccessible;
46
using namespace ::com::sun::star::accessibility;
47
48
49
// implementation of a table cell
50
OUString AccessibleBrowseBoxTableCell::implGetText()
51
0
{
52
0
    return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
53
0
}
54
55
css::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale()
56
0
{
57
0
    return mpBrowseBox->GetAccessible()->getLocale();
58
0
}
59
60
void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
61
0
{
62
0
    nStartIndex = 0;
63
0
    nEndIndex = 0;
64
0
}
65
66
AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(
67
    const Reference<XAccessible>& _rxParent, vcl::IAccessibleTableProvider& _rBrowseBox,
68
    sal_Int32 _nRowPos, sal_uInt16 _nColPos)
69
0
    : ImplInheritanceHelper(_rxParent, _rBrowseBox, nullptr, _nRowPos, _nColPos)
70
0
{
71
0
    sal_Int32 nIndex = getIndex_Impl( _nRowPos, _nColPos, _rBrowseBox.GetColumnCount() );
72
0
    setAccessibleName( _rBrowseBox.GetAccessibleObjectName( AccessibleBrowseBoxObjType::TableCell, nIndex ) );
73
0
    setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( AccessibleBrowseBoxObjType::TableCell, nIndex ) );
74
    // Need to register as event listener
75
0
    Reference< XComponent > xComponent(_rxParent, UNO_QUERY);
76
0
    if( xComponent.is() )
77
0
        xComponent->addEventListener(static_cast< XEventListener *> (this));
78
0
}
79
80
css::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex )
81
0
{
82
0
    SolarMethodGuard aGuard(getMutex());
83
0
    ensureIsAlive();
84
85
0
    css::awt::Rectangle aRect;
86
87
0
    if ( mpBrowseBox )
88
0
    {
89
0
        if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
90
0
            throw IndexOutOfBoundsException();
91
92
0
        aRect = vcl::unohelper::ConvertToAWTRect(
93
0
            mpBrowseBox->GetFieldCharacterBounds(getRowPos(), getColumnPos(), nIndex));
94
0
    }
95
96
0
    return aRect;
97
0
}
98
99
sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const css::awt::Point& _aPoint )
100
0
{
101
    //! TODO CTL bidi
102
    // OSL_FAIL("Need to be done by base class!");
103
0
    SolarMethodGuard aGuard(getMutex());
104
0
    ensureIsAlive();
105
106
0
    return mpBrowseBox->GetFieldIndexAtPoint(getRowPos(), getColumnPos(),
107
0
                                             vcl::unohelper::ConvertToVCLPoint(_aPoint));
108
0
}
109
110
/** @return
111
        The name of this class.
112
*/
113
OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName()
114
0
{
115
0
    return u"com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell"_ustr;
116
0
}
117
118
/** @return  The count of visible children. */
119
sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount()
120
0
{
121
0
    return 0;
122
0
}
123
124
/** @return  The XAccessible interface of the specified child. */
125
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
126
    AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int64 )
127
0
{
128
0
    throw css::lang::IndexOutOfBoundsException();
129
0
}
130
131
/** Return a bitset of states of the current object.
132
*/
133
sal_Int64 AccessibleBrowseBoxTableCell::implCreateStateSet()
134
0
{
135
0
    SolarMethodGuard aGuard(getMutex());
136
137
0
    sal_Int64 nStateSet = 0;
138
139
0
    if( isAlive() )
140
0
    {
141
        // SHOWING done with mxParent
142
0
        if( implIsShowing() )
143
0
            nStateSet |= AccessibleStateType::SHOWING;
144
145
0
        mpBrowseBox->FillAccessibleStateSetForCell( nStateSet, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
146
0
    }
147
0
    else
148
0
        nStateSet |= AccessibleStateType::DEFUNC;
149
150
0
    return nStateSet;
151
0
}
152
153
// XAccessibleContext -----------------------------------------------------
154
155
sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
156
0
{
157
0
    SolarMethodGuard aGuard(getMutex());
158
0
    ensureIsAlive();
159
160
0
    return (static_cast<sal_Int64>(getRowPos()) * static_cast<sal_Int64>(mpBrowseBox->GetColumnCount())) + getColumnPos();
161
0
}
162
163
sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition(  )
164
0
{
165
0
    return -1;
166
0
}
167
168
sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex )
169
0
{
170
0
    SolarMethodGuard aGuard(getMutex());
171
0
    ensureIsAlive();
172
173
0
    if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
174
0
        throw IndexOutOfBoundsException();
175
176
0
    return false;
177
0
}
178
sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex )
179
0
{
180
0
    SolarMethodGuard aGuard(getMutex());
181
0
    ensureIsAlive();
182
183
0
    return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
184
0
}
185
css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
186
0
{
187
0
    SolarMethodGuard aGuard(getMutex());
188
0
    ensureIsAlive();
189
190
0
    OUString sText( implGetText() );
191
192
0
    if ( !implIsValidIndex( nIndex, sText.getLength() ) )
193
0
        throw IndexOutOfBoundsException();
194
195
0
    return css::uno::Sequence< css::beans::PropertyValue >();
196
0
}
197
sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount(  )
198
0
{
199
0
    SolarMethodGuard aGuard(getMutex());
200
0
    ensureIsAlive();
201
202
0
    return implGetText().getLength();
203
0
}
204
205
OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText(  )
206
0
{
207
0
    SolarMethodGuard aGuard(getMutex());
208
0
    ensureIsAlive();
209
210
0
    return OCommonAccessibleText::getSelectedText(  );
211
0
}
212
sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart(  )
213
0
{
214
0
    SolarMethodGuard aGuard(getMutex());
215
0
    ensureIsAlive();
216
217
0
    return OCommonAccessibleText::getSelectionStart(  );
218
0
}
219
sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd(  )
220
0
{
221
0
    SolarMethodGuard aGuard(getMutex());
222
0
    ensureIsAlive();
223
224
0
    return OCommonAccessibleText::getSelectionEnd(  );
225
0
}
226
sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
227
0
{
228
0
    SolarMethodGuard aGuard(getMutex());
229
0
    ensureIsAlive();
230
231
0
    if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
232
0
        throw IndexOutOfBoundsException();
233
234
0
    return false;
235
0
}
236
OUString SAL_CALL AccessibleBrowseBoxTableCell::getText(  )
237
0
{
238
0
    SolarMethodGuard aGuard(getMutex());
239
0
    ensureIsAlive();
240
241
0
    return implGetText(  );
242
0
}
243
OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
244
0
{
245
0
    SolarMethodGuard aGuard(getMutex());
246
0
    ensureIsAlive();
247
248
0
    return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
249
0
}
250
css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
251
0
{
252
0
    SolarMethodGuard aGuard(getMutex());
253
0
    ensureIsAlive();
254
255
0
    return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
256
0
}
257
css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
258
0
{
259
0
    SolarMethodGuard aGuard(getMutex());
260
0
    ensureIsAlive();
261
262
0
    return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
263
0
}
264
css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
265
0
{
266
0
    SolarMethodGuard aGuard(getMutex());
267
0
    ensureIsAlive();
268
269
0
    return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
270
0
}
271
sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
272
0
{
273
0
    SolarMethodGuard aGuard(getMutex());
274
0
    ensureIsAlive();
275
276
0
    OUString sText = implGetText();
277
0
    checkIndex_Impl( nStartIndex, sText );
278
0
    checkIndex_Impl( nEndIndex, sText );
279
280
    //!!! don't know how to put a string into the clipboard
281
0
    return false;
282
0
}
283
sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
284
0
{
285
0
    return false;
286
0
}
287
void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource )
288
0
{
289
0
        if ( _rSource.Source == mxParent )
290
0
        {
291
0
            dispose();
292
0
        }
293
0
}
294
295
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */