Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/control/thumbnailviewacc.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 "thumbnailviewacc.hxx"
21
#include "thumbnailviewitemacc.hxx"
22
23
#include <comphelper/servicehelper.hxx>
24
#include <sfx2/thumbnailview.hxx>
25
#include <sfx2/thumbnailviewitem.hxx>
26
#include <vcl/svapp.hxx>
27
#include <vcl/settings.hxx>
28
#include <sal/log.hxx>
29
#include <tools/debug.hxx>
30
#include <comphelper/diagnose_ex.hxx>
31
32
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
33
#include <com/sun/star/accessibility/AccessibleRole.hpp>
34
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
35
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
36
37
using namespace ::com::sun::star;
38
39
ThumbnailViewAcc::ThumbnailViewAcc(ThumbnailView* pThumbnailView)
40
0
    : mpThumbnailView(pThumbnailView)
41
0
{
42
0
}
43
44
ThumbnailViewAcc::~ThumbnailViewAcc()
45
0
{
46
0
}
47
48
sal_Int64 SAL_CALL ThumbnailViewAcc::getAccessibleChildCount()
49
0
{
50
0
    const SolarMutexGuard aSolarGuard;
51
0
    ThrowIfDisposed();
52
53
0
    return mpThumbnailView->ImplGetVisibleItemCount();
54
0
}
55
56
uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleChild( sal_Int64 i )
57
0
{
58
0
    ThrowIfDisposed();
59
0
    const SolarMutexGuard aSolarGuard;
60
61
0
    if (i < 0 || i >= getAccessibleChildCount())
62
0
        throw lang::IndexOutOfBoundsException();
63
64
0
    ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i));
65
66
0
    if( !pItem )
67
0
        throw lang::IndexOutOfBoundsException();
68
69
0
    rtl::Reference< ThumbnailViewItemAcc >  xRet = pItem->GetAccessible();
70
0
    return xRet;
71
0
}
72
73
uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleParent()
74
0
{
75
0
    ThrowIfDisposed();
76
0
    const SolarMutexGuard aSolarGuard;
77
0
    return mpThumbnailView->GetDrawingArea()->get_accessible_parent();
78
0
}
79
80
sal_Int16 SAL_CALL ThumbnailViewAcc::getAccessibleRole()
81
0
{
82
0
    ThrowIfDisposed();
83
    // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
84
    // always if the role is LIST, we need a different role in this case
85
0
    return accessibility::AccessibleRole::LIST;
86
0
}
87
88
OUString SAL_CALL ThumbnailViewAcc::getAccessibleDescription()
89
0
{
90
0
    ThrowIfDisposed();
91
0
    return u"ThumbnailView"_ustr;
92
0
}
93
94
OUString SAL_CALL ThumbnailViewAcc::getAccessibleName()
95
0
{
96
0
    ThrowIfDisposed();
97
0
    const SolarMutexGuard aSolarGuard;
98
0
    OUString              aRet;
99
100
0
    if (mpThumbnailView)
101
0
    {
102
0
        aRet = mpThumbnailView->GetAccessibleName();
103
0
    }
104
105
0
    return aRet;
106
0
}
107
108
uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewAcc::getAccessibleRelationSet()
109
0
{
110
0
    ThrowIfDisposed();
111
0
    return uno::Reference< accessibility::XAccessibleRelationSet >();
112
0
}
113
114
sal_Int64 SAL_CALL ThumbnailViewAcc::getAccessibleStateSet()
115
0
{
116
0
    ThrowIfDisposed();
117
0
    sal_Int64 nStateSet = 0;
118
119
    // Set some states.
120
0
    nStateSet |= accessibility::AccessibleStateType::ENABLED;
121
0
    nStateSet |= accessibility::AccessibleStateType::SENSITIVE;
122
0
    nStateSet |= accessibility::AccessibleStateType::SHOWING;
123
0
    nStateSet |= accessibility::AccessibleStateType::VISIBLE;
124
0
    nStateSet |= accessibility::AccessibleStateType::MANAGES_DESCENDANTS;
125
0
    nStateSet |= accessibility::AccessibleStateType::FOCUSABLE;
126
127
0
    return nStateSet;
128
0
}
129
130
lang::Locale SAL_CALL ThumbnailViewAcc::getLocale()
131
0
{
132
0
    ThrowIfDisposed();
133
0
    const SolarMutexGuard aSolarGuard;
134
0
    uno::Reference< accessibility::XAccessible >    xParent( getAccessibleParent() );
135
0
    lang::Locale                                    aRet( u""_ustr, u""_ustr, u""_ustr );
136
137
0
    if( xParent.is() )
138
0
    {
139
0
        uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
140
141
0
        if( xParentContext.is() )
142
0
            aRet = xParentContext->getLocale ();
143
0
    }
144
145
0
    return aRet;
146
0
}
147
148
uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleAtPoint( const awt::Point& aPoint )
149
0
{
150
0
    ThrowIfDisposed();
151
0
    const SolarMutexGuard aSolarGuard;
152
153
0
    const sal_uInt16 nItemId = mpThumbnailView->GetItemId(Point(aPoint.X, aPoint.Y));
154
0
    if ( !nItemId )
155
0
        return nullptr;
156
157
0
    const size_t nItemPos = mpThumbnailView->GetItemPos(nItemId);
158
0
    if( THUMBNAILVIEW_ITEM_NONEITEM == nItemPos )
159
0
        return nullptr;
160
161
0
    ThumbnailViewItem* const pItem = mpThumbnailView->mFilteredItemList[nItemPos];
162
0
    rtl::Reference<ThumbnailViewItemAcc> xRet = pItem->GetAccessible();
163
164
0
    return xRet;
165
0
}
166
167
awt::Rectangle ThumbnailViewAcc::implGetBounds()
168
0
{
169
0
    const Point         aOutPos;
170
0
    const Size aOutSize(mpThumbnailView->GetOutputSizePixel());
171
0
    awt::Rectangle      aRet;
172
173
0
    aRet.X = aOutPos.X();
174
0
    aRet.Y = aOutPos.Y();
175
0
    aRet.Width = aOutSize.Width();
176
0
    aRet.Height = aOutSize.Height();
177
178
0
    return aRet;
179
0
}
180
181
void SAL_CALL ThumbnailViewAcc::grabFocus()
182
0
{
183
0
    ThrowIfDisposed();
184
0
    const SolarMutexGuard aSolarGuard;
185
0
    mpThumbnailView->GrabFocus();
186
0
}
187
188
sal_Int32 SAL_CALL ThumbnailViewAcc::getForeground(  )
189
0
{
190
0
    ThrowIfDisposed();
191
0
    Color nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor();
192
0
    return static_cast<sal_Int32>(nColor);
193
0
}
194
195
sal_Int32 SAL_CALL ThumbnailViewAcc::getBackground(  )
196
0
{
197
0
    ThrowIfDisposed();
198
0
    Color nColor = Application::GetSettings().GetStyleSettings().GetWindowColor();
199
0
    return static_cast<sal_Int32>(nColor);
200
0
}
201
202
void SAL_CALL ThumbnailViewAcc::selectAccessibleChild( sal_Int64 nChildIndex )
203
0
{
204
0
    ThrowIfDisposed();
205
0
    const SolarMutexGuard aSolarGuard;
206
207
0
    if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
208
0
        throw lang::IndexOutOfBoundsException();
209
210
0
    ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
211
212
0
    if(pItem == nullptr)
213
0
        throw lang::IndexOutOfBoundsException();
214
215
0
    mpThumbnailView->SelectItem(pItem->mnId);
216
0
}
217
218
sal_Bool SAL_CALL ThumbnailViewAcc::isAccessibleChildSelected( sal_Int64 nChildIndex )
219
0
{
220
0
    ThrowIfDisposed();
221
0
    const SolarMutexGuard aSolarGuard;
222
223
0
    if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
224
0
        throw lang::IndexOutOfBoundsException();
225
226
0
    ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
227
228
0
    if (pItem == nullptr)
229
0
        throw lang::IndexOutOfBoundsException();
230
231
0
    return mpThumbnailView->IsItemSelected(pItem->mnId);
232
0
}
233
234
void SAL_CALL ThumbnailViewAcc::clearAccessibleSelection()
235
0
{
236
0
    ThrowIfDisposed();
237
0
}
238
239
void SAL_CALL ThumbnailViewAcc::selectAllAccessibleChildren()
240
0
{
241
0
    ThrowIfDisposed();
242
    // unsupported due to single selection only
243
0
}
244
245
sal_Int64 SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChildCount()
246
0
{
247
0
    ThrowIfDisposed();
248
0
    const SolarMutexGuard aSolarGuard;
249
0
    sal_Int64 nRet = 0;
250
251
0
    for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
252
0
    {
253
0
        ThumbnailViewItem* pItem = getItem (i);
254
255
0
        if (pItem && mpThumbnailView->IsItemSelected(pItem->mnId))
256
0
            ++nRet;
257
0
    }
258
259
0
    return nRet;
260
0
}
261
262
uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
263
0
{
264
0
    ThrowIfDisposed();
265
0
    const SolarMutexGuard aSolarGuard;
266
0
    rtl::Reference< ThumbnailViewItemAcc > xRet;
267
268
0
    for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
269
0
    {
270
0
        ThumbnailViewItem* pItem = getItem(i);
271
272
0
        if (pItem && mpThumbnailView->IsItemSelected(pItem->mnId)
273
0
            && (nSelectedChildIndex == static_cast<sal_Int32>(nSel++)))
274
0
            xRet = pItem->GetAccessible();
275
0
    }
276
277
0
    return xRet;
278
0
}
279
280
void SAL_CALL ThumbnailViewAcc::deselectAccessibleChild( sal_Int64 nChildIndex)
281
0
{
282
0
    ThrowIfDisposed();
283
0
    const SolarMutexGuard aSolarGuard;
284
285
0
    if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
286
0
        throw lang::IndexOutOfBoundsException();
287
288
    // Because of the single selection we can reset the whole selection when
289
    // the specified child is currently selected.
290
//FIXME TODO    if (isAccessibleChildSelected(nChildIndex))
291
//FIXME TODO        ;
292
0
}
293
294
sal_uInt16 ThumbnailViewAcc::getItemCount() const
295
0
{
296
0
    return mpThumbnailView->ImplGetVisibleItemCount();
297
0
}
298
299
ThumbnailViewItem* ThumbnailViewAcc::getItem (sal_uInt16 nIndex) const
300
0
{
301
0
    return mpThumbnailView->ImplGetVisibleItem(nIndex);
302
0
}
303
304
void ThumbnailViewAcc::ThrowIfDisposed()
305
0
{
306
0
    ensureAlive();
307
308
0
    DBG_ASSERT (mpThumbnailView!=nullptr, "ValueSetAcc not disposed but mpThumbnailView == NULL");
309
0
}
310
311
void ThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
312
0
{
313
0
    NotifyAccessibleEvent(nEventId, rOldValue, rNewValue);
314
0
}
315
316
bool ThumbnailViewAcc::HasAccessibleListeners() const
317
0
{
318
0
    return OAccessible::hasAccessibleListeners();
319
0
}
320
321
void ThumbnailViewAcc::GetFocus()
322
0
{
323
    // Broadcast the state change.
324
0
    css::uno::Any aOldState, aNewState;
325
0
    aNewState <<= css::accessibility::AccessibleStateType::FOCUSED;
326
0
    FireAccessibleEvent(
327
0
        css::accessibility::AccessibleEventId::STATE_CHANGED,
328
0
        aOldState, aNewState);
329
0
}
330
331
void ThumbnailViewAcc::LoseFocus()
332
0
{
333
    // Broadcast the state change.
334
0
    css::uno::Any aOldState, aNewState;
335
0
    aOldState <<= css::accessibility::AccessibleStateType::FOCUSED;
336
0
    FireAccessibleEvent(
337
0
        css::accessibility::AccessibleEventId::STATE_CHANGED,
338
0
        aOldState, aNewState);
339
0
}
340
341
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */