Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / svdraw / charthelper.cxx
blob764abf0d3ec9603f4369052dc2344c86f78de466
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/charthelper.hxx>
21 #include <tools/diagnose_ex.h>
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>
27 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
29 #include <drawinglayer/geometry/viewinformation2d.hxx>
30 #include <com/sun/star/chart2/XChartDocument.hpp>
31 #include <com/sun/star/drawing/FillStyle.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
34 using namespace ::com::sun::star;
36 void ChartHelper::updateChart( const uno::Reference< ::frame::XModel >& rXModel )
38 if (!rXModel.is())
39 return;
41 try
43 const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
44 const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW);
45 const uno::Reference<util::XUpdatable2> xUpdatable(xChartView, uno::UNO_QUERY_THROW);
47 xUpdatable->updateHard();
49 catch(uno::Exception&)
51 OSL_ENSURE(false, "Unexpected exception!");
55 drawinglayer::primitive2d::Primitive2DContainer ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
56 const uno::Reference< ::frame::XModel >& rXModel,
57 basegfx::B2DRange& rRange)
59 drawinglayer::primitive2d::Primitive2DContainer aRetval;
61 if (!rXModel.is())
62 return aRetval;
64 updateChart(rXModel);
66 try
68 const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
69 const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
71 if(xShapeAccess->getCount())
73 const sal_Int32 nShapeCount(xShapeAccess->getCount());
74 const uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
75 const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory =
76 graphic::PrimitiveFactory2D::create( xContext );
78 const uno::Sequence< beans::PropertyValue > aParams;
79 uno::Reference< drawing::XShape > xShape;
81 for(sal_Int32 a(0); a < nShapeCount; a++)
83 xShapeAccess->getByIndex(a) >>= xShape;
85 if(xShape.is())
87 const drawinglayer::primitive2d::Primitive2DSequence aNew(
88 xPrimitiveFactory->createPrimitivesFromXShape(
89 xShape,
90 aParams));
92 aRetval.append(aNew);
97 catch(uno::Exception&)
99 OSL_ENSURE(false, "Unexpected exception!");
102 if(!aRetval.empty())
104 const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
106 rRange = aRetval.getB2DRange(aViewInformation2D);
109 return aRetval;
112 void ChartHelper::AdaptDefaultsForChart(
113 const uno::Reference < embed::XEmbeddedObject > & xEmbObj)
115 if( !xEmbObj.is())
116 return;
118 uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
119 OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
120 if( !xChartDoc.is())
121 return;
125 if (uno::Reference< beans::XPropertySet > xPageProp = xChartDoc->getPageBackground())
127 // set background to transparent (none)
128 xPageProp->setPropertyValue("FillStyle", uno::makeAny(drawing::FillStyle_NONE));
129 // set no border
130 xPageProp->setPropertyValue("LineStyle", uno::makeAny(drawing::LineStyle_NONE));
133 catch( const uno::Exception & )
135 TOOLS_WARN_EXCEPTION("svx.svdraw", "");
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */