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