Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/Accessibility/AccessibleContextBase.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 <AccessibleContextBase.hxx>
21
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
22
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
23
#include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
24
#include <tools/gen.hxx>
25
#include <tools/color.hxx>
26
#include <toolkit/helper/vclunohelper.hxx>
27
#include <svl/hint.hxx>
28
#include <comphelper/sequence.hxx>
29
#include <cppuhelper/supportsservice.hxx>
30
#include <unotools/accessiblerelationsethelper.hxx>
31
#include <utility>
32
#include <vcl/unohelp.hxx>
33
#include <comphelper/accessibleeventnotifier.hxx>
34
#include <vcl/svapp.hxx>
35
36
using namespace ::com::sun::star;
37
using namespace ::com::sun::star::accessibility;
38
39
ScAccessibleContextBase::ScAccessibleContextBase(
40
                                                 uno::Reference<XAccessible> xParent,
41
                                                 const sal_Int16 aRole)
42
                                                 :
43
0
    mxParent(std::move(xParent)),
44
0
    maRole(aRole)
45
0
{
46
0
}
47
48
ScAccessibleContextBase::~ScAccessibleContextBase()
49
0
{
50
0
    if (!IsDefunc() && !rBHelper.bInDispose)
51
0
    {
52
        // increment refcount to prevent double call of dtor
53
0
        osl_atomic_increment( &m_refCount );
54
        // call dispose to inform object which have a weak reference to this object
55
0
        dispose();
56
0
    }
57
0
}
58
59
void ScAccessibleContextBase::Init()
60
0
{
61
    // hold reference to make sure that the destructor is not called
62
0
    uno::Reference< XAccessibleContext > xKeepAlive(this);
63
64
0
    msName = createAccessibleName();
65
0
    msDescription = createAccessibleDescription();
66
0
}
67
68
void SAL_CALL ScAccessibleContextBase::disposing()
69
0
{
70
0
    SolarMutexGuard aGuard;
71
72
    // hold reference to make sure that the destructor is not called
73
0
    uno::Reference< XAccessibleContext > xKeepAlive(this);
74
75
0
    OAccessible::disposing();
76
77
0
    mxParent.clear();
78
0
}
79
80
81
//=====  SfxListener  =====================================================
82
83
void ScAccessibleContextBase::Notify( SfxBroadcaster&, const SfxHint& rHint )
84
0
{
85
0
    if (rHint.GetId() == SfxHintId::Dying)
86
0
    {
87
        // it seems the Broadcaster is dying, since the view is dying
88
0
        dispose();
89
0
    }
90
0
}
91
92
// OAccessible
93
94
awt::Rectangle ScAccessibleContextBase::implGetBounds(  )
95
0
{
96
0
    return vcl::unohelper::ConvertToAWTRect(GetBoundingBox());
97
0
}
98
99
//=====  XAccessibleComponent  ================================================
100
101
awt::Point SAL_CALL ScAccessibleContextBase::getLocationOnScreen(  )
102
0
{
103
0
    SolarMutexGuard aGuard;
104
0
    ensureAlive();
105
0
    return vcl::unohelper::ConvertToAWTPoint(GetBoundingBoxOnScreen().TopLeft());
106
0
}
107
108
bool ScAccessibleContextBase::isShowing(  )
109
0
{
110
0
    SolarMutexGuard aGuard;
111
0
    ensureAlive();
112
0
    bool bShowing(false);
113
0
    if (mxParent.is())
114
0
    {
115
0
        uno::Reference<XAccessibleComponent> xParentComponent (mxParent->getAccessibleContext(), uno::UNO_QUERY);
116
0
        if (xParentComponent.is())
117
0
        {
118
0
            tools::Rectangle aParentBounds(
119
0
                vcl::unohelper::ConvertToVCLRect(xParentComponent->getBounds()));
120
0
            tools::Rectangle aBounds(vcl::unohelper::ConvertToVCLRect(getBounds()));
121
0
            bShowing = aBounds.Overlaps(aParentBounds);
122
0
        }
123
0
    }
124
0
    return bShowing;
125
0
}
126
127
bool ScAccessibleContextBase::isVisible()
128
0
{
129
0
    return true;
130
0
}
131
132
void SAL_CALL ScAccessibleContextBase::grabFocus(  )
133
0
{
134
0
    OSL_FAIL("not implemented");
135
0
}
136
137
sal_Int32 SAL_CALL ScAccessibleContextBase::getForeground(  )
138
0
{
139
0
    return sal_Int32(COL_BLACK);
140
0
}
141
142
sal_Int32 SAL_CALL ScAccessibleContextBase::getBackground(  )
143
0
{
144
0
    return sal_Int32(COL_WHITE);
145
0
}
146
147
//=====  XAccessibleContext  ==================================================
148
149
uno::Reference<XAccessible> SAL_CALL
150
       ScAccessibleContextBase::getAccessibleParent()
151
0
{
152
0
    return mxParent;
153
0
}
154
155
sal_Int16 SAL_CALL
156
    ScAccessibleContextBase::getAccessibleRole()
157
0
{
158
0
    return maRole;
159
0
}
160
161
OUString SAL_CALL
162
       ScAccessibleContextBase::getAccessibleDescription()
163
0
{
164
0
    SolarMutexGuard aGuard;
165
0
    ensureAlive();
166
0
    if (msDescription.isEmpty())
167
0
    {
168
0
        OUString sDescription(createAccessibleDescription());
169
170
0
        if (msDescription != sDescription)
171
0
        {
172
0
            const OUString sOldDescription = msDescription;
173
0
            msDescription = sDescription;
174
175
0
            CommitChange(AccessibleEventId::DESCRIPTION_CHANGED, uno::Any(sOldDescription),
176
0
                         uno::Any(sDescription));
177
0
        }
178
0
    }
179
0
    return msDescription;
180
0
}
181
182
OUString SAL_CALL
183
       ScAccessibleContextBase::getAccessibleName()
184
0
{
185
0
    SolarMutexGuard aGuard;
186
0
    ensureAlive();
187
0
    if (msName.isEmpty())
188
0
    {
189
0
        OUString sName(createAccessibleName());
190
0
        OSL_ENSURE(!sName.isEmpty(), "We should give always a name.");
191
192
0
        if (msName != sName)
193
0
        {
194
0
            const OUString sOldName = msName;
195
0
            msName = sName;
196
197
0
            CommitChange(AccessibleEventId::NAME_CHANGED, uno::Any(sOldName), uno::Any(sName));
198
0
        }
199
0
    }
200
0
    return msName;
201
0
}
202
203
uno::Reference<XAccessibleRelationSet> SAL_CALL
204
       ScAccessibleContextBase::getAccessibleRelationSet()
205
0
{
206
0
    return new utl::AccessibleRelationSetHelper();
207
0
}
208
209
sal_Int64 SAL_CALL ScAccessibleContextBase::getAccessibleStateSet()
210
0
{
211
0
    return 0;
212
0
}
213
214
lang::Locale SAL_CALL
215
       ScAccessibleContextBase::getLocale()
216
0
{
217
0
    SolarMutexGuard aGuard;
218
0
    ensureAlive();
219
0
    if (mxParent.is())
220
0
    {
221
0
        uno::Reference<XAccessibleContext> xParentContext (
222
0
            mxParent->getAccessibleContext());
223
0
        if (xParentContext.is())
224
0
            return xParentContext->getLocale ();
225
0
    }
226
227
    //  No locale and no parent.  Therefore throw exception to indicate this
228
    //  cluelessness.
229
0
    throw IllegalAccessibleComponentStateException ();
230
0
}
231
232
OUString
233
    ScAccessibleContextBase::createAccessibleDescription()
234
0
{
235
0
    OSL_FAIL("should be implemented in the abbreviated class");
236
0
    return OUString();
237
0
}
238
239
OUString ScAccessibleContextBase::createAccessibleName()
240
0
{
241
0
    OSL_FAIL("should be implemented in the abbreviated class");
242
0
    return OUString();
243
0
}
244
245
void ScAccessibleContextBase::CommitChange(const sal_Int16 nEventId, const css::uno::Any& rOldValue,
246
                                           const css::uno::Any& rNewValue, sal_Int32 nIndexHint)
247
0
{
248
0
    NotifyAccessibleEvent(nEventId, rOldValue, rNewValue, nIndexHint);
249
0
}
250
251
void ScAccessibleContextBase::CommitFocusGained()
252
0
{
253
0
    CommitChange(AccessibleEventId::STATE_CHANGED, uno::Any(),
254
0
                 uno::Any(AccessibleStateType::FOCUSED));
255
0
}
256
257
void ScAccessibleContextBase::CommitFocusLost()
258
0
{
259
0
    CommitChange(AccessibleEventId::STATE_CHANGED, uno::Any(AccessibleStateType::FOCUSED),
260
0
                 uno::Any());
261
0
}
262
263
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */