Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/svdraw/charthelper.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 <svx/charthelper.hxx>
21
#include <comphelper/diagnose_ex.hxx>
22
#include <com/sun/star/embed/XEmbeddedObject.hpp>
23
#include <com/sun/star/util/XUpdatable2.hpp>
24
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
25
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
26
#include <drawinglayer/geometry/viewinformation2d.hxx>
27
#include <com/sun/star/chart2/XChartDocument.hpp>
28
#include <com/sun/star/drawing/FillStyle.hpp>
29
#include <com/sun/star/drawing/LineStyle.hpp>
30
#include <sdr/primitive2d/primitivefactory2d.hxx>
31
32
using namespace ::com::sun::star;
33
34
void ChartHelper::updateChart( const uno::Reference< ::frame::XModel >& rXModel )
35
0
{
36
0
    if (!rXModel.is())
37
0
        return;
38
39
0
    try
40
0
    {
41
0
        const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
42
0
        const uno::Reference< util::XUpdatable2 > xChartView(xChartFact->createInstance(u"com.sun.star.chart2.ChartView"_ustr), uno::UNO_QUERY_THROW);
43
44
0
        xChartView->updateHard();
45
0
    }
46
0
    catch(uno::Exception&)
47
0
    {
48
0
        TOOLS_WARN_EXCEPTION("svx", "");
49
0
    }
50
0
}
51
52
drawinglayer::primitive2d::Primitive2DContainer ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
53
    const uno::Reference< ::frame::XModel >& rXModel,
54
    basegfx::B2DRange& rRange)
55
0
{
56
0
    drawinglayer::primitive2d::Primitive2DContainer aRetval;
57
58
0
    if (!rXModel.is())
59
0
        return aRetval;
60
61
    // don't broadcast until we're finished building, more efficient
62
0
    rXModel->lockControllers();
63
0
    updateChart(rXModel);
64
0
    rXModel->unlockControllers();
65
66
0
    try
67
0
    {
68
0
        const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
69
0
        const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
70
71
0
        if(xShapeAccess->getCount())
72
0
        {
73
0
            const sal_Int32 nShapeCount(xShapeAccess->getCount());
74
0
            const uno::Sequence< beans::PropertyValue > aParams;
75
0
            uno::Reference< drawing::XShape > xShape;
76
77
0
            for(sal_Int32 a(0); a < nShapeCount; a++)
78
0
            {
79
0
                xShapeAccess->getByIndex(a) >>= xShape;
80
81
0
                if(xShape.is())
82
0
                {
83
0
                    PrimitiveFactory2D::createPrimitivesFromXShape(
84
0
                        xShape,
85
0
                        aParams,
86
0
                        aRetval);
87
0
                }
88
0
            }
89
0
        }
90
0
    }
91
0
    catch(uno::Exception&)
92
0
    {
93
0
        TOOLS_WARN_EXCEPTION("svx", "");
94
0
    }
95
96
0
    if(!aRetval.empty())
97
0
    {
98
0
        const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
99
100
0
        rRange = aRetval.getB2DRange(aViewInformation2D);
101
0
    }
102
103
0
    return aRetval;
104
0
}
105
106
void ChartHelper::AdaptDefaultsForChart(
107
    const uno::Reference < embed::XEmbeddedObject > & xEmbObj)
108
0
{
109
0
    if( !xEmbObj.is())
110
0
        return;
111
112
0
    uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
113
0
    OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
114
0
    if( !xChartDoc.is())
115
0
        return;
116
117
0
    try
118
0
    {
119
0
        if (uno::Reference< beans::XPropertySet > xPageProp = xChartDoc->getPageBackground())
120
0
        {
121
            // set background to transparent (none)
122
0
            xPageProp->setPropertyValue(u"FillStyle"_ustr, uno::Any(drawing::FillStyle_NONE));
123
            // set no border
124
0
            xPageProp->setPropertyValue(u"LineStyle"_ustr, uno::Any(drawing::LineStyle_NONE));
125
0
        }
126
0
    }
127
0
    catch( const uno::Exception & )
128
0
    {
129
0
        TOOLS_WARN_EXCEPTION("svx.svdraw", "");
130
0
    }
131
0
}
132
133
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */