Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/editeng/source/accessibility/AccessibleImageBullet.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 <tools/gen.hxx>
21
#include <tools/debug.hxx>
22
#include <utility>
23
#include <vcl/svapp.hxx>
24
#include <vcl/settings.hxx>
25
#include <rtl/ustring.hxx>
26
#include <com/sun/star/awt/Rectangle.hpp>
27
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28
#include <com/sun/star/accessibility/AccessibleRole.hpp>
29
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
30
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
31
#include <cppuhelper/supportsservice.hxx>
32
#include <i18nlangtag/languagetag.hxx>
33
#include <editeng/AccessibleEditableTextPara.hxx>
34
#include <editeng/eerdll.hxx>
35
36
#include <editeng/outliner.hxx>
37
#include <editeng/editrids.hrc>
38
#include <editeng/unoedsrc.hxx>
39
#include <svtools/colorcfg.hxx>
40
41
#include "AccessibleImageBullet.hxx"
42
43
using namespace ::com::sun::star;
44
using namespace ::com::sun::star::accessibility;
45
46
namespace accessibility
47
{
48
49
AccessibleImageBullet::AccessibleImageBullet(uno::Reference<XAccessible> xParent,
50
                                             sal_Int64 nIndexInParent) :
51
0
    mnParagraphIndex( 0 ),
52
0
    mnIndexInParent(nIndexInParent),
53
0
    mpEditSource( nullptr ),
54
0
    maEEOffset( 0, 0 ),
55
0
    mxParent(std::move( xParent ))
56
0
{
57
    // these are always on
58
0
    mnStateSet = AccessibleStateType::VISIBLE;
59
0
    mnStateSet |= AccessibleStateType::SHOWING;
60
0
    mnStateSet |= AccessibleStateType::ENABLED;
61
0
    mnStateSet |= AccessibleStateType::SENSITIVE;
62
0
}
63
64
sal_Int64 SAL_CALL  AccessibleImageBullet::getAccessibleChildCount()
65
0
{
66
0
    return 0;
67
0
}
68
69
uno::Reference< XAccessible > SAL_CALL  AccessibleImageBullet::getAccessibleChild( sal_Int64 )
70
0
{
71
0
    throw lang::IndexOutOfBoundsException(u"No children available"_ustr,
72
0
                                          getXWeak() );
73
0
}
74
75
uno::Reference< XAccessible > SAL_CALL  AccessibleImageBullet::getAccessibleParent()
76
0
{
77
0
    return mxParent;
78
0
}
79
80
sal_Int64 SAL_CALL  AccessibleImageBullet::getAccessibleIndexInParent()
81
0
{
82
0
    return mnIndexInParent;
83
0
}
84
85
sal_Int16 SAL_CALL  AccessibleImageBullet::getAccessibleRole()
86
0
{
87
0
    return AccessibleRole::GRAPHIC;
88
0
}
89
90
OUString SAL_CALL  AccessibleImageBullet::getAccessibleDescription()
91
0
{
92
    // Get the string from the resource for the specified id.
93
0
    return EditResId(RID_SVXSTR_A11Y_IMAGEBULLET_DESCRIPTION);
94
0
}
95
96
OUString SAL_CALL  AccessibleImageBullet::getAccessibleName()
97
0
{
98
    // Get the string from the resource for the specified id.
99
0
    return EditResId(RID_SVXSTR_A11Y_IMAGEBULLET_NAME);
100
0
}
101
102
uno::Reference< XAccessibleRelationSet > SAL_CALL AccessibleImageBullet::getAccessibleRelationSet()
103
0
{
104
    // no relations, therefore empty
105
0
    return uno::Reference< XAccessibleRelationSet >();
106
0
}
107
108
sal_Int64 SAL_CALL AccessibleImageBullet::getAccessibleStateSet()
109
0
{
110
0
    SolarMutexGuard aGuard;
111
112
    // Create a copy of the state set and return it.
113
114
0
    return mnStateSet;
115
0
}
116
117
lang::Locale SAL_CALL AccessibleImageBullet::getLocale()
118
0
{
119
0
    SolarMutexGuard aGuard;
120
121
0
    DBG_ASSERT(GetParagraphIndex() >= 0,
122
0
               "AccessibleImageBullet::getLocale: paragraph index value overflow");
123
124
    // return locale of first character in the paragraph
125
0
    return LanguageTag(GetTextForwarder().GetLanguage( GetParagraphIndex(), 0 )).getLocale();
126
0
}
127
128
uno::Reference< XAccessible > SAL_CALL AccessibleImageBullet::getAccessibleAtPoint( const awt::Point& /*aPoint*/ )
129
0
{
130
    // as we have no children, empty reference
131
0
    return uno::Reference< XAccessible >();
132
0
}
133
134
awt::Rectangle AccessibleImageBullet::implGetBounds(  )
135
0
{
136
0
    DBG_ASSERT(GetParagraphIndex() >= 0,
137
0
               "AccessibleEditableTextPara::implGetBounds: index value overflow");
138
139
0
    SvxTextForwarder& rCacheTF = GetTextForwarder();
140
0
    EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( GetParagraphIndex() );
141
0
    tools::Rectangle aParentRect = rCacheTF.GetParaBounds( GetParagraphIndex() );
142
143
0
    if( aBulletInfo.nParagraph != EE_PARA_MAX &&
144
0
        aBulletInfo.bVisible &&
145
0
        aBulletInfo.nType == SVX_NUM_BITMAP )
146
0
    {
147
0
        tools::Rectangle aRect = aBulletInfo.aBounds;
148
149
        // subtract paragraph position (bullet pos is absolute in EditEngine/Outliner)
150
0
        aRect.Move( -aParentRect.Left(), -aParentRect.Top() );
151
152
        // convert to screen coordinates
153
0
        tools::Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect,
154
0
                                                                          rCacheTF.GetMapMode(),
155
0
                                                                          GetViewForwarder() );
156
157
        // offset from shape/cell
158
0
        Point aOffset = maEEOffset;
159
160
0
        return awt::Rectangle( aScreenRect.Left() + aOffset.X(),
161
0
                               aScreenRect.Top() + aOffset.Y(),
162
0
                               aScreenRect.GetSize().Width(),
163
0
                               aScreenRect.GetSize().Height() );
164
0
    }
165
166
0
    return awt::Rectangle();
167
0
}
168
169
void SAL_CALL AccessibleImageBullet::grabFocus(  )
170
0
{
171
0
    throw uno::RuntimeException(u"Not focusable"_ustr,
172
0
                                uno::Reference< uno::XInterface >
173
0
                                ( static_cast< XAccessible* > (this) ) );   // disambiguate hierarchy
174
0
}
175
176
sal_Int32 SAL_CALL AccessibleImageBullet::getForeground(  )
177
0
{
178
    // #104444# Added to XAccessibleComponent interface
179
0
    svtools::ColorConfig aColorConfig;
180
0
    Color nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
181
0
    return static_cast<sal_Int32>(nColor);
182
0
}
183
184
sal_Int32 SAL_CALL AccessibleImageBullet::getBackground(  )
185
0
{
186
    // #104444# Added to XAccessibleComponent interface
187
0
    Color aColor( Application::GetSettings().GetStyleSettings().GetWindowColor() );
188
189
    // the background is transparent
190
0
    aColor.SetAlpha(0);
191
192
0
    return static_cast<sal_Int32>( aColor );
193
0
}
194
195
OUString SAL_CALL AccessibleImageBullet::getImplementationName()
196
0
{
197
0
    return u"AccessibleImageBullet"_ustr;
198
0
}
199
200
sal_Bool SAL_CALL AccessibleImageBullet::supportsService (const OUString& sServiceName)
201
0
{
202
203
0
    return cppu::supportsService(this, sServiceName);
204
0
}
205
206
uno::Sequence< OUString > SAL_CALL AccessibleImageBullet::getSupportedServiceNames()
207
0
{
208
0
    return { u"com.sun.star.accessibility.AccessibleContext"_ustr };
209
0
}
210
211
void AccessibleImageBullet::SetEEOffset( const Point& rOffset )
212
0
{
213
0
    maEEOffset = rOffset;
214
0
}
215
216
void SAL_CALL AccessibleImageBullet::dispose()
217
0
{
218
0
    mxParent = nullptr;
219
0
    mpEditSource = nullptr;
220
221
0
    OAccessible::dispose();
222
0
}
223
224
void AccessibleImageBullet::SetEditSource( SvxEditSource* pEditSource )
225
0
{
226
0
    mpEditSource = pEditSource;
227
228
0
    if( !mpEditSource )
229
0
    {
230
        // going defunc
231
0
        UnSetState( AccessibleStateType::SHOWING );
232
0
        UnSetState( AccessibleStateType::VISIBLE );
233
0
        SetState( AccessibleStateType::INVALID );
234
0
        SetState( AccessibleStateType::DEFUNC );
235
0
    }
236
0
}
237
238
void AccessibleImageBullet::SetState( const sal_Int64 nStateId )
239
0
{
240
0
    if( !(mnStateSet & nStateId) )
241
0
    {
242
0
        mnStateSet |= nStateId;
243
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, uno::Any(), uno::Any(nStateId));
244
0
    }
245
0
}
246
247
void AccessibleImageBullet::UnSetState( const sal_Int64 nStateId )
248
0
{
249
0
    if( mnStateSet & nStateId )
250
0
    {
251
0
        mnStateSet &= ~nStateId;
252
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, uno::Any(nStateId), uno::Any());
253
0
    }
254
0
}
255
256
257
void AccessibleImageBullet::SetParagraphIndex( sal_Int32 nIndex )
258
0
{
259
0
    uno::Any aOldDesc;
260
0
    uno::Any aOldName;
261
262
0
    try
263
0
    {
264
0
        aOldDesc <<= getAccessibleDescription();
265
0
        aOldName <<= getAccessibleName();
266
0
    }
267
0
    catch( const uno::Exception& ) {} // optional behaviour
268
269
0
    sal_Int32 nOldIndex = mnParagraphIndex;
270
271
0
    mnParagraphIndex = nIndex;
272
273
0
    try
274
0
    {
275
0
        if( nOldIndex != nIndex )
276
0
        {
277
            // index and therefore description changed
278
0
            NotifyAccessibleEvent(AccessibleEventId::DESCRIPTION_CHANGED, aOldDesc, uno::Any(getAccessibleDescription()));
279
0
            NotifyAccessibleEvent(AccessibleEventId::NAME_CHANGED, aOldName, uno::Any(getAccessibleName()));
280
0
        }
281
0
    }
282
0
    catch( const uno::Exception& ) {} // optional behaviour
283
0
}
284
285
286
SvxEditSource& AccessibleImageBullet::GetEditSource() const
287
0
{
288
0
    if( !mpEditSource )
289
0
        throw uno::RuntimeException(u"No edit source, object is defunct"_ustr,
290
0
                                    cppu::getXWeak
291
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
292
0
    return *mpEditSource;
293
0
}
294
295
SvxTextForwarder& AccessibleImageBullet::GetTextForwarder() const
296
0
{
297
0
    SvxEditSource& rEditSource = GetEditSource();
298
0
    SvxTextForwarder* pTextForwarder = rEditSource.GetTextForwarder();
299
300
0
    if( !pTextForwarder )
301
0
        throw uno::RuntimeException(u"Unable to fetch text forwarder, object is defunct"_ustr,
302
0
                                    cppu::getXWeak
303
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
304
305
0
    if( !pTextForwarder->IsValid() )
306
0
        throw uno::RuntimeException(u"Text forwarder is invalid, object is defunct"_ustr,
307
0
                                    cppu::getXWeak
308
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
309
0
    return *pTextForwarder;
310
0
}
311
312
SvxViewForwarder& AccessibleImageBullet::GetViewForwarder() const
313
0
{
314
0
    SvxEditSource& rEditSource = GetEditSource();
315
0
    SvxViewForwarder* pViewForwarder = rEditSource.GetViewForwarder();
316
317
0
    if( !pViewForwarder )
318
0
    {
319
0
        throw uno::RuntimeException(u"Unable to fetch view forwarder, object is defunct"_ustr,
320
0
                                    cppu::getXWeak
321
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
322
0
    }
323
324
0
    if( !pViewForwarder->IsValid() )
325
0
        throw uno::RuntimeException(u"View forwarder is invalid, object is defunct"_ustr,
326
0
                                    cppu::getXWeak
327
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) ); // disambiguate hierarchy
328
0
    return *pViewForwarder;
329
0
}
330
331
332
} // end of namespace accessibility
333
334
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */