Coverage Report

Created: 2026-10-14 09:33

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, getXWeak());
172
0
}
173
174
sal_Int32 SAL_CALL AccessibleImageBullet::getForeground(  )
175
0
{
176
    // #104444# Added to XAccessibleComponent interface
177
0
    svtools::ColorConfig aColorConfig;
178
0
    Color nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
179
0
    return static_cast<sal_Int32>(nColor);
180
0
}
181
182
sal_Int32 SAL_CALL AccessibleImageBullet::getBackground(  )
183
0
{
184
    // #104444# Added to XAccessibleComponent interface
185
0
    Color aColor( Application::GetSettings().GetStyleSettings().GetWindowColor() );
186
187
    // the background is transparent
188
0
    aColor.SetAlpha(0);
189
190
0
    return static_cast<sal_Int32>( aColor );
191
0
}
192
193
void AccessibleImageBullet::SetEEOffset( const Point& rOffset )
194
0
{
195
0
    maEEOffset = rOffset;
196
0
}
197
198
void SAL_CALL AccessibleImageBullet::dispose()
199
0
{
200
0
    mxParent = nullptr;
201
0
    mpEditSource = nullptr;
202
203
0
    OAccessible::dispose();
204
0
}
205
206
void AccessibleImageBullet::SetEditSource( SvxEditSource* pEditSource )
207
0
{
208
0
    mpEditSource = pEditSource;
209
210
0
    if( !mpEditSource )
211
0
    {
212
        // going defunct
213
0
        UnSetState( AccessibleStateType::SHOWING );
214
0
        UnSetState( AccessibleStateType::VISIBLE );
215
0
        SetState( AccessibleStateType::INVALID );
216
0
        SetState( AccessibleStateType::DEFUNC );
217
0
    }
218
0
}
219
220
void AccessibleImageBullet::SetState( const sal_Int64 nStateId )
221
0
{
222
0
    if( !(mnStateSet & nStateId) )
223
0
    {
224
0
        mnStateSet |= nStateId;
225
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, uno::Any(), uno::Any(nStateId));
226
0
    }
227
0
}
228
229
void AccessibleImageBullet::UnSetState( const sal_Int64 nStateId )
230
0
{
231
0
    if( mnStateSet & nStateId )
232
0
    {
233
0
        mnStateSet &= ~nStateId;
234
0
        NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, uno::Any(nStateId), uno::Any());
235
0
    }
236
0
}
237
238
239
void AccessibleImageBullet::SetParagraphIndex( sal_Int32 nIndex )
240
0
{
241
0
    uno::Any aOldDesc;
242
0
    uno::Any aOldName;
243
244
0
    try
245
0
    {
246
0
        aOldDesc <<= getAccessibleDescription();
247
0
        aOldName <<= getAccessibleName();
248
0
    }
249
0
    catch( const uno::Exception& ) {} // optional behaviour
250
251
0
    sal_Int32 nOldIndex = mnParagraphIndex;
252
253
0
    mnParagraphIndex = nIndex;
254
255
0
    try
256
0
    {
257
0
        if( nOldIndex != nIndex )
258
0
        {
259
            // index and therefore description changed
260
0
            NotifyAccessibleEvent(AccessibleEventId::DESCRIPTION_CHANGED, aOldDesc, uno::Any(getAccessibleDescription()));
261
0
            NotifyAccessibleEvent(AccessibleEventId::NAME_CHANGED, aOldName, uno::Any(getAccessibleName()));
262
0
        }
263
0
    }
264
0
    catch( const uno::Exception& ) {} // optional behaviour
265
0
}
266
267
268
SvxEditSource& AccessibleImageBullet::GetEditSource() const
269
0
{
270
0
    if( !mpEditSource )
271
0
        throw uno::RuntimeException(u"No edit source, object is defunct"_ustr,
272
0
                                    cppu::getXWeak
273
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
274
0
    return *mpEditSource;
275
0
}
276
277
SvxTextForwarder& AccessibleImageBullet::GetTextForwarder() const
278
0
{
279
0
    SvxEditSource& rEditSource = GetEditSource();
280
0
    SvxTextForwarder* pTextForwarder = rEditSource.GetTextForwarder();
281
282
0
    if( !pTextForwarder )
283
0
        throw uno::RuntimeException(u"Unable to fetch text forwarder, object is defunct"_ustr,
284
0
                                    cppu::getXWeak
285
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
286
287
0
    if( !pTextForwarder->IsValid() )
288
0
        throw uno::RuntimeException(u"Text forwarder is invalid, object is defunct"_ustr,
289
0
                                    cppu::getXWeak
290
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
291
0
    return *pTextForwarder;
292
0
}
293
294
SvxViewForwarder& AccessibleImageBullet::GetViewForwarder() const
295
0
{
296
0
    SvxEditSource& rEditSource = GetEditSource();
297
0
    SvxViewForwarder* pViewForwarder = rEditSource.GetViewForwarder();
298
299
0
    if( !pViewForwarder )
300
0
    {
301
0
        throw uno::RuntimeException(u"Unable to fetch view forwarder, object is defunct"_ustr,
302
0
                                    cppu::getXWeak
303
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) );  // disambiguate hierarchy
304
0
    }
305
306
0
    if( !pViewForwarder->IsValid() )
307
0
        throw uno::RuntimeException(u"View forwarder is invalid, object is defunct"_ustr,
308
0
                                    cppu::getXWeak
309
0
                                      ( const_cast< AccessibleImageBullet* > (this) ) ); // disambiguate hierarchy
310
0
    return *pViewForwarder;
311
0
}
312
313
314
} // end of namespace accessibility
315
316
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */