Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/accessibility/svxpixelctlaccessiblecontext.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 <com/sun/star/accessibility/AccessibleRole.hpp>
21
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
22
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
23
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24
#include <toolkit/helper/vclunohelper.hxx>
25
#include <utility>
26
#include <vcl/svapp.hxx>
27
#include <vcl/settings.hxx>
28
#include <vcl/unohelp.hxx>
29
#include <osl/mutex.hxx>
30
#include <tools/debug.hxx>
31
#include <tools/gen.hxx>
32
33
#include <svx/dlgctrl.hxx>
34
35
#include <svxpixelctlaccessiblecontext.hxx>
36
37
using namespace ::cppu;
38
using namespace ::osl;
39
using namespace ::com::sun::star;
40
using namespace ::com::sun::star::uno;
41
using namespace ::com::sun::star::accessibility;
42
43
SvxPixelCtlAccessible::SvxPixelCtlAccessible(SvxPixelCtl* pControl)
44
0
    : mpPixelCtl(pControl)
45
0
{
46
0
}
47
48
SvxPixelCtlAccessible::~SvxPixelCtlAccessible()
49
0
{
50
0
    ensureDisposed();
51
0
}
52
53
sal_Int64 SvxPixelCtlAccessible::getAccessibleChildCount(  )
54
0
{
55
0
    return SvxPixelCtl::GetSquares();
56
0
}
57
uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int64 i )
58
0
{
59
0
    ::osl::MutexGuard   aGuard( m_aMutex );
60
0
    if ( i < 0 || i >= getAccessibleChildCount())
61
0
        throw lang::IndexOutOfBoundsException();
62
0
    if (!mpPixelCtl)
63
0
        return nullptr;
64
0
    rtl::Reference< SvxPixelCtlAccessibleChild > xChild = CreateChild(i, mpPixelCtl->IndexToPoint(i));
65
0
    return xChild;
66
0
}
67
68
uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent(  )
69
0
{
70
0
    ::osl::MutexGuard   aGuard( m_aMutex );
71
0
    if (mpPixelCtl)
72
0
        return mpPixelCtl->getAccessibleParent();
73
0
    return uno::Reference<css::accessibility::XAccessible>();
74
0
}
75
76
sal_Int16 SvxPixelCtlAccessible::getAccessibleRole(  )
77
0
{
78
0
    return AccessibleRole::LIST;
79
0
}
80
81
OUString SvxPixelCtlAccessible::getAccessibleDescription(  )
82
0
{
83
84
0
    ::osl::MutexGuard   aGuard( m_aMutex );
85
0
    return mpPixelCtl ? mpPixelCtl->GetAccessibleDescription() : u""_ustr;
86
0
}
87
88
OUString SvxPixelCtlAccessible::getAccessibleName(  )
89
0
{
90
0
    ::osl::MutexGuard   aGuard( m_aMutex );
91
0
    return mpPixelCtl ? mpPixelCtl->GetAccessibleName() : u""_ustr;
92
0
}
93
94
Reference< XAccessibleRelationSet > SAL_CALL SvxPixelCtlAccessible::getAccessibleRelationSet()
95
0
{
96
0
    if (mpPixelCtl)
97
0
        return mpPixelCtl->get_accessible_relation_set();
98
0
    return uno::Reference<css::accessibility::XAccessibleRelationSet>();
99
0
}
100
101
sal_Int64 SvxPixelCtlAccessible::getAccessibleStateSet(  )
102
0
{
103
0
    ::osl::MutexGuard   aGuard( m_aMutex );
104
0
    sal_Int64 nStateSet = 0;
105
106
0
    if (mpPixelCtl)
107
0
    {
108
0
        nStateSet |=
109
0
            AccessibleStateType::FOCUSABLE |
110
0
            AccessibleStateType::SELECTABLE |
111
0
            AccessibleStateType::SHOWING |
112
0
            AccessibleStateType::VISIBLE |
113
0
            AccessibleStateType::OPAQUE;
114
0
        if (mpPixelCtl->IsEnabled())
115
0
            nStateSet |= AccessibleStateType::ENABLED;
116
0
        if (mpPixelCtl->HasFocus())
117
0
            nStateSet |= AccessibleStateType::FOCUSED;
118
0
        nStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
119
0
    }
120
121
0
    return nStateSet;
122
0
}
123
124
uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
125
        const awt::Point& rPoint)
126
0
{
127
0
    ::osl::MutexGuard   aGuard( m_aMutex );
128
129
0
    if (!mpPixelCtl)
130
0
        return nullptr;
131
0
    tools::Long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
132
0
    rtl::Reference< SvxPixelCtlAccessibleChild > xRet = CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
133
134
0
    return xRet;
135
0
}
136
137
awt::Rectangle SvxPixelCtlAccessible::implGetBounds()
138
0
{
139
0
    ::osl::MutexGuard   aGuard( m_aMutex );
140
141
0
    awt::Rectangle aRet;
142
143
0
    if (mpPixelCtl)
144
0
    {
145
0
        const Point   aOutPos;
146
0
        Size          aOutSize(mpPixelCtl->GetOutputSizePixel());
147
148
0
        aRet.X = aOutPos.X();
149
0
        aRet.Y = aOutPos.Y();
150
0
        aRet.Width = aOutSize.Width();
151
0
        aRet.Height = aOutSize.Height();
152
0
    }
153
154
0
    return aRet;
155
0
}
156
157
void SvxPixelCtlAccessible::grabFocus(  )
158
0
{
159
0
    ::osl::MutexGuard   aGuard( m_aMutex );
160
0
    if (mpPixelCtl)
161
0
        mpPixelCtl->GrabFocus();
162
0
}
163
164
sal_Int32 SvxPixelCtlAccessible::getForeground(  )
165
0
{
166
0
    ::osl::MutexGuard   aGuard( m_aMutex );
167
168
    //see SvxPixelCtl::Paint
169
0
    const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
170
0
    return sal_Int32(rStyles.GetLabelTextColor());
171
0
}
172
173
sal_Int32 SvxPixelCtlAccessible::getBackground(  )
174
0
{
175
0
    ::osl::MutexGuard   aGuard( m_aMutex );
176
177
    //see SvxPixelCtl::Paint
178
0
    const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
179
0
    return sal_Int32(rStyles.GetDialogColor());
180
0
}
181
182
void SvxPixelCtlAccessible::implSelect(sal_Int64 nChildIndex, bool bSelect)
183
0
{
184
0
    ::osl::MutexGuard   aGuard( m_aMutex );
185
186
0
    if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
187
0
        throw lang::IndexOutOfBoundsException();
188
189
0
    if (!mpPixelCtl)
190
0
        return;
191
192
0
    tools::Long nIndex = mpPixelCtl->ShowPosition(mpPixelCtl->IndexToPoint(nChildIndex));
193
0
    NotifyChild(nIndex, bSelect, false);
194
0
}
195
196
bool SvxPixelCtlAccessible::implIsSelected(sal_Int64 nChildIndex)
197
0
{
198
0
    ::osl::MutexGuard   aGuard( m_aMutex );
199
200
0
    if (!mpPixelCtl)
201
0
        return false;
202
203
0
    return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
204
0
}
205
206
void SAL_CALL SvxPixelCtlAccessible::disposing()
207
0
{
208
0
    ::osl::MutexGuard aGuard(m_aMutex);
209
0
    OAccessibleSelectionHelper::disposing();
210
0
    m_xCurChild.clear();
211
0
    mpPixelCtl = nullptr;
212
0
}
213
214
void SvxPixelCtlAccessible::NotifyChild(tools::Long nIndex,bool bSelect ,bool bCheck)
215
0
{
216
0
    DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
217
218
0
    rtl::Reference<SvxPixelCtlAccessibleChild> pChild = m_xCurChild;
219
0
    if (pChild && pChild->getAccessibleIndexInParent() == nIndex )
220
0
    {
221
0
        if (bSelect)
222
0
        {
223
0
            pChild->SelectChild(true);
224
0
        }
225
0
        if (bCheck)
226
0
        {
227
0
            pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
228
0
            pChild->CheckChild();
229
0
        }
230
0
        return;
231
0
    }
232
0
    rtl::Reference<SvxPixelCtlAccessibleChild> xNewChild = CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
233
0
    DBG_ASSERT(xNewChild,"Child Must be Valid");
234
235
0
    Any aNewValue,aOldValue;
236
0
    aNewValue <<= uno::Reference<XAccessible>(xNewChild);
237
0
    NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
238
239
0
    if (bSelect)
240
0
    {
241
0
        if (pChild)
242
0
        {
243
0
            pChild->SelectChild(false);
244
0
        }
245
0
        xNewChild->SelectChild(true);
246
0
    }
247
0
    if (bCheck)
248
0
    {
249
0
        xNewChild->CheckChild();
250
0
    }
251
0
    m_xCurChild = std::move(xNewChild);
252
0
}
253
254
rtl::Reference<SvxPixelCtlAccessibleChild> SvxPixelCtlAccessible::CreateChild (tools::Long nIndex,Point mPoint)
255
0
{
256
0
    bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
257
0
    Size size(mpPixelCtl->GetWidth() / SvxPixelCtl::GetLineCount(), mpPixelCtl->GetHeight() / SvxPixelCtl::GetLineCount());
258
0
    rtl::Reference<SvxPixelCtlAccessibleChild> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
259
0
                bPixelColorOrBG,
260
0
                tools::Rectangle(mPoint,size),
261
0
                this,
262
0
                nIndex);
263
264
0
    return xChild;
265
0
}
266
267
void SvxPixelCtlAccessibleChild::CheckChild()
268
0
{
269
0
    Any aChecked;
270
0
    aChecked <<= AccessibleStateType::CHECKED;
271
272
0
    if (m_bPixelColorOrBG)//Current Child State
273
0
    {
274
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
275
0
    }
276
0
    else
277
0
    {
278
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
279
0
    }
280
0
}
281
282
void SvxPixelCtlAccessibleChild::SelectChild( bool bSelect)
283
0
{
284
0
    Any aSelected;
285
0
    aSelected <<= AccessibleStateType::SELECTED;
286
287
0
    if (bSelect)
288
0
    {
289
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
290
0
    }
291
0
    else
292
0
    {
293
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
294
0
    }
295
0
}
296
297
SvxPixelCtlAccessibleChild::SvxPixelCtlAccessibleChild( SvxPixelCtl& rWindow, bool bPixelColorOrBG,
298
    const tools::Rectangle& rBoundingBox, rtl::Reference<SvxPixelCtlAccessible> xParent,
299
    tools::Long nIndexInParent)
300
0
    : mrParentWindow( rWindow )
301
0
    , mxParent(std::move(xParent))
302
0
    , m_bPixelColorOrBG(bPixelColorOrBG)
303
0
    , maBoundingBox( rBoundingBox )
304
0
    , mnIndexInParent( nIndexInParent )
305
0
{
306
0
}
307
308
SvxPixelCtlAccessibleChild::~SvxPixelCtlAccessibleChild()
309
0
{
310
0
    ensureDisposed();
311
0
}
312
313
uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
314
0
{
315
0
    return uno::Reference< XAccessible >();
316
0
}
317
318
void SAL_CALL SvxPixelCtlAccessibleChild::grabFocus()
319
0
{
320
0
}
321
322
sal_Int32 SvxPixelCtlAccessibleChild::getForeground()
323
0
{
324
0
    ::osl::MutexGuard   aGuard( m_aMutex );
325
0
    return mxParent.is() ? mxParent->getForeground() : -1;
326
0
}
327
328
sal_Int32 SvxPixelCtlAccessibleChild::getBackground()
329
0
{
330
0
    ::osl::MutexGuard   aGuard( m_aMutex );
331
0
    return mxParent.is() ? mxParent->getBackground() : -1;
332
0
}
333
334
// XAccessibleContext
335
sal_Int64 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChildCount()
336
0
{
337
0
    return 0;
338
0
}
339
340
uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int64 )
341
0
{
342
0
    throw lang::IndexOutOfBoundsException();
343
0
}
344
345
uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
346
0
{
347
0
    return mxParent;
348
0
}
349
350
sal_Int16 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRole()
351
0
{
352
0
    return AccessibleRole::CHECK_BOX;
353
0
}
354
355
OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleDescription()
356
0
{
357
0
    ::osl::MutexGuard   aGuard( m_aMutex );
358
359
0
    return  GetName();
360
0
}
361
362
OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleName()
363
0
{
364
0
    ::osl::MutexGuard   aGuard( m_aMutex );
365
0
    return  GetName();
366
0
}
367
368
/** Return empty uno::Reference to indicate that the relation set is not
369
    supported.
370
*/
371
uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
372
0
{
373
0
    return uno::Reference< XAccessibleRelationSet >();
374
0
}
375
376
sal_Int64 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet()
377
0
{
378
0
    ::osl::MutexGuard                       aGuard( m_aMutex );
379
0
    sal_Int64 nStateSet = 0;
380
381
0
    if (!rBHelper.bDisposed)
382
0
    {
383
0
        nStateSet |= AccessibleStateType::TRANSIENT;
384
0
        nStateSet |= AccessibleStateType::ENABLED;
385
0
        nStateSet |= AccessibleStateType::OPAQUE;
386
0
        nStateSet |= AccessibleStateType::SELECTABLE;
387
0
        nStateSet |= AccessibleStateType::SHOWING;
388
0
        nStateSet |= AccessibleStateType::VISIBLE;
389
390
0
        tools::Long nIndex = mrParentWindow.GetFocusPosIndex();
391
0
        if ( nIndex == mnIndexInParent)
392
0
        {
393
0
            nStateSet |= AccessibleStateType::SELECTED;
394
0
        }
395
0
        if (mrParentWindow.GetBitmapPixel(sal_uInt16(mnIndexInParent)))
396
0
        {
397
0
            nStateSet |= AccessibleStateType::CHECKED;
398
0
        }
399
0
    }
400
0
    else
401
0
        nStateSet |= AccessibleStateType::DEFUNC;
402
403
0
    return nStateSet;
404
0
}
405
406
void SAL_CALL SvxPixelCtlAccessibleChild::disposing()
407
0
{
408
0
    OAccessible::disposing();
409
0
    mxParent.clear();
410
0
}
411
412
awt::Rectangle SvxPixelCtlAccessibleChild::implGetBounds()
413
0
{
414
    // no guard necessary, because no one changes maBoundingBox after creating it
415
0
    return vcl::unohelper::ConvertToAWTRect(maBoundingBox);
416
0
}
417
418
OUString SvxPixelCtlAccessibleChild::GetName() const
419
0
{
420
0
    sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
421
0
    sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
422
423
0
    OUString str = "("
424
0
                 + OUString::number(nXIndex)
425
0
                 + ","
426
0
                 + OUString::number(nYIndex)
427
0
                 + ")";
428
0
    return str;
429
0
}
430
431
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */