Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/accessibility/AccessiblePageShape.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 <AccessiblePageShape.hxx>
21
#include <svx/AccessibleShapeInfo.hxx>
22
#include <svx/IAccessibleViewForwarder.hxx>
23
#include <comphelper/diagnose_ex.hxx>
24
#include <tools/gen.hxx>
25
#include <sal/log.hxx>
26
27
#include <com/sun/star/beans/XPropertySet.hpp>
28
#include <com/sun/star/drawing/XMasterPageTarget.hpp>
29
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30
#include <utility>
31
32
using namespace ::com::sun::star;
33
using namespace ::com::sun::star::uno;
34
using namespace ::com::sun::star::accessibility;
35
using ::com::sun::star::uno::Reference;
36
37
namespace accessibility {
38
39
AccessiblePageShape::AccessiblePageShape (
40
    uno::Reference<drawing::XDrawPage> xPage,
41
    const uno::Reference<XAccessible>& rxParent,
42
    const AccessibleShapeTreeInfo& rShapeTreeInfo)
43
0
    : AccessibleShape (AccessibleShapeInfo (nullptr, rxParent), rShapeTreeInfo),
44
0
      mxPage (std::move(xPage))
45
0
{
46
    // The main part of the initialization is done in the init method which
47
    // has to be called from this constructor's caller.
48
0
}
49
50
AccessiblePageShape::~AccessiblePageShape()
51
0
{
52
0
}
53
54
//=====  XAccessibleContext  ==================================================
55
56
sal_Int64 SAL_CALL
57
       AccessiblePageShape::getAccessibleChildCount()
58
0
{
59
0
    return 0;
60
0
}
61
62
/** Forward the request to the shape.  Return the requested shape or throw
63
    an exception for a wrong index.
64
*/
65
uno::Reference<XAccessible> SAL_CALL
66
    AccessiblePageShape::getAccessibleChild( sal_Int64 )
67
0
{
68
0
    throw lang::IndexOutOfBoundsException (u"page shape has no children"_ustr,
69
0
        static_cast<uno::XWeak*>(this));
70
0
}
71
72
// OAccessible
73
74
awt::Rectangle AccessiblePageShape::implGetBounds()
75
0
{
76
0
    awt::Rectangle aBoundingBox;
77
78
0
    if (maShapeTreeInfo.GetViewForwarder() != nullptr)
79
0
    {
80
0
        uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
81
0
        if (xSet.is())
82
0
        {
83
0
            uno::Any aValue;
84
85
0
            aValue = xSet->getPropertyValue (u"BorderLeft"_ustr);
86
0
            aValue >>= aBoundingBox.X;
87
0
            aValue = xSet->getPropertyValue (u"BorderTop"_ustr);
88
0
            aValue >>= aBoundingBox.Y;
89
90
0
            aValue = xSet->getPropertyValue (u"Width"_ustr);
91
0
            aValue >>= aBoundingBox.Width;
92
0
            aValue = xSet->getPropertyValue (u"Height"_ustr);
93
0
            aValue >>= aBoundingBox.Height;
94
0
        }
95
96
        // Transform coordinates from internal to pixel.
97
0
        ::Size aPixelSize = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
98
0
            ::Size (aBoundingBox.Width, aBoundingBox.Height));
99
0
        ::Point aPixelPosition = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
100
0
            ::Point (aBoundingBox.X, aBoundingBox.Y));
101
102
        // Clip the shape's bounding box with the bounding box of its parent.
103
0
        Reference<XAccessibleComponent> xParentComponent (
104
0
            getAccessibleParent(), uno::UNO_QUERY);
105
0
        if (xParentComponent.is())
106
0
        {
107
            // Make the coordinates relative to the parent.
108
0
            awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
109
0
            int x = aPixelPosition.getX() - aParentLocation.X;
110
0
            int y = aPixelPosition.getY() - aParentLocation.Y;
111
112
            // Clip with parent (with coordinates relative to itself).
113
0
            ::tools::Rectangle aBBox (
114
0
                x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
115
0
            awt::Size aParentSize (xParentComponent->getSize());
116
0
            ::tools::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
117
0
            aBBox = aBBox.GetIntersection (aParentBBox);
118
0
            aBoundingBox = awt::Rectangle (
119
0
                aBBox.Left(),
120
0
                aBBox.Top(),
121
0
                aBBox.getOpenWidth(),
122
0
                aBBox.getOpenHeight());
123
0
        }
124
0
        else
125
0
            aBoundingBox = awt::Rectangle (
126
0
                aPixelPosition.getX(), aPixelPosition.getY(),
127
0
                aPixelSize.getWidth(), aPixelSize.getHeight());
128
0
    }
129
130
0
    return aBoundingBox;
131
0
}
132
133
//=====  XAccessibleComponent  ================================================
134
135
sal_Int32 SAL_CALL AccessiblePageShape::getForeground()
136
0
{
137
0
    ensureAlive();
138
0
    sal_Int32 nColor (0x0ffffffL);
139
140
0
    try
141
0
    {
142
0
        uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
143
0
        if (aSet.is())
144
0
        {
145
0
            uno::Any aColor = aSet->getPropertyValue (u"LineColor"_ustr);
146
0
            aColor >>= nColor;
147
0
        }
148
0
    }
149
0
    catch (const css::beans::UnknownPropertyException&)
150
0
    {
151
        // Ignore exception and return default color.
152
0
    }
153
0
    return nColor;
154
0
}
155
156
/** Extract the background color from the Background property of the
157
    draw page or its master page.
158
*/
159
sal_Int32 SAL_CALL AccessiblePageShape::getBackground()
160
0
{
161
0
    ensureAlive();
162
0
    sal_Int32 nColor (0x01020ffL);
163
164
0
    try
165
0
    {
166
0
        uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
167
0
        if (xSet.is())
168
0
        {
169
0
            uno::Any aBGSet = xSet->getPropertyValue (u"Background"_ustr);
170
0
            Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
171
0
            if ( ! xBGSet.is())
172
0
            {
173
                // Draw page has no Background property.  Try the master
174
                // page instead.
175
0
                Reference<drawing::XMasterPageTarget> xTarget (mxPage, uno::UNO_QUERY);
176
0
                if (xTarget.is())
177
0
                {
178
0
                    xSet.set(xTarget->getMasterPage(), uno::UNO_QUERY);
179
0
                    aBGSet = xSet->getPropertyValue (u"Background"_ustr);
180
0
                    xBGSet.set(aBGSet, uno::UNO_QUERY);
181
0
                }
182
0
            }
183
            // Fetch the fill color.  Has to be extended to cope with
184
            // gradients, hashes, and bitmaps.
185
0
            if (xBGSet.is())
186
0
            {
187
0
                uno::Any aColor = xBGSet->getPropertyValue (u"FillColor"_ustr);
188
0
                aColor >>= nColor;
189
0
            }
190
0
            else
191
0
                SAL_WARN("sd", "no Background property in page");
192
0
        }
193
0
    }
194
0
    catch (const css::beans::UnknownPropertyException&)
195
0
    {
196
0
        TOOLS_WARN_EXCEPTION("sd", "caught exception due to unknown property");
197
        // Ignore exception and return default color.
198
0
    }
199
0
    return nColor;
200
0
}
201
202
// XServiceInfo
203
204
OUString SAL_CALL
205
    AccessiblePageShape::getImplementationName()
206
0
{
207
0
    ensureAlive();
208
0
    return u"AccessiblePageShape"_ustr;
209
0
}
210
211
css::uno::Sequence< OUString> SAL_CALL
212
    AccessiblePageShape::getSupportedServiceNames()
213
0
{
214
0
    ensureAlive();
215
0
    return AccessibleShape::getSupportedServiceNames();
216
0
}
217
218
//=====  XComponent  ==========================================================
219
220
void AccessiblePageShape::dispose()
221
0
{
222
    // Cleanup.
223
0
    mxShape = nullptr;
224
225
    // Call base classes.
226
0
    AccessibleContextBase::dispose ();
227
0
}
228
229
//=====  protected internal  ==================================================
230
231
OUString
232
    AccessiblePageShape::CreateAccessibleBaseName()
233
0
{
234
0
    return u"PageShape"_ustr;
235
0
}
236
237
OUString
238
    AccessiblePageShape::CreateAccessibleName()
239
0
{
240
0
    Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
241
242
    // Get name of the current slide.
243
0
    OUString sCurrentSlideName;
244
0
    try
245
0
    {
246
0
        if (xPageProperties.is())
247
0
        {
248
0
            xPageProperties->getPropertyValue( u"LinkDisplayName"_ustr ) >>= sCurrentSlideName;
249
0
        }
250
0
    }
251
0
    catch (const beans::UnknownPropertyException&)
252
0
    {
253
0
    }
254
255
0
    return CreateAccessibleBaseName()+": "+sCurrentSlideName;
256
0
}
257
258
} // end of namespace accessibility
259
260
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */