Bump version to 24.04.3.4
[LibreOffice.git] / svx / source / svdraw / charthelper.cxx
blob2c75be5d27d6a7da5f85c9513634479becdf286b
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 <comphelper/diagnose_ex.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>
27 #include <drawinglayer/geometry/viewinformation2d.hxx>
28 #include <com/sun/star/chart2/XChartDocument.hpp>
29 #include <com/sun/star/drawing/FillStyle.hpp>
30 #include <com/sun/star/drawing/LineStyle.hpp>
31 #include <sdr/primitive2d/primitivefactory2d.hxx>
33 using namespace ::com::sun::star;
35 void ChartHelper::updateChart( const uno::Reference< ::frame::XModel >& rXModel )
37 if (!rXModel.is())
38 return;
40 try
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);
45 xChartView->updateHard();
47 catch(uno::Exception&)
49 TOOLS_WARN_EXCEPTION("svx", "");
53 drawinglayer::primitive2d::Primitive2DContainer ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
54 const uno::Reference< ::frame::XModel >& rXModel,
55 basegfx::B2DRange& rRange)
57 drawinglayer::primitive2d::Primitive2DContainer aRetval;
59 if (!rXModel.is())
60 return aRetval;
62 // don't broadcast until we're finished building, more efficient
63 rXModel->lockControllers();
64 updateChart(rXModel);
65 rXModel->unlockControllers();
67 try
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);
72 if(xShapeAccess->getCount())
74 const sal_Int32 nShapeCount(xShapeAccess->getCount());
75 const uno::Sequence< beans::PropertyValue > aParams;
76 uno::Reference< drawing::XShape > xShape;
78 for(sal_Int32 a(0); a < nShapeCount; a++)
80 xShapeAccess->getByIndex(a) >>= xShape;
82 if(xShape.is())
84 PrimitiveFactory2D::createPrimitivesFromXShape(
85 xShape,
86 aParams,
87 aRetval);
92 catch(uno::Exception&)
94 TOOLS_WARN_EXCEPTION("svx", "");
97 if(!aRetval.empty())
99 const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
101 rRange = aRetval.getB2DRange(aViewInformation2D);
104 return aRetval;
107 void ChartHelper::AdaptDefaultsForChart(
108 const uno::Reference < embed::XEmbeddedObject > & xEmbObj)
110 if( !xEmbObj.is())
111 return;
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;
120 if (uno::Reference< beans::XPropertySet > xPageProp = xChartDoc->getPageBackground())
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));
128 catch( const uno::Exception & )
130 TOOLS_WARN_EXCEPTION("svx.svdraw", "");
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */