defer finding dialog parent until we need it
[LibreOffice.git] / svx / source / svdraw / charthelper.cxx
blob77ee2b06c0cb9ad5557b2ba58cf1dfa2f7b44024
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/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>
32 using namespace ::com::sun::star;
34 void ChartHelper::updateChart( const uno::Reference< ::frame::XModel >& rXModel )
36 if (!rXModel.is())
37 return;
39 try
41 const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
42 const uno::Reference< util::XUpdatable2 > xChartView(xChartFact->createInstance(u"com.sun.star.chart2.ChartView"_ustr), uno::UNO_QUERY_THROW);
44 xChartView->updateHard();
46 catch(uno::Exception&)
48 TOOLS_WARN_EXCEPTION("svx", "");
52 drawinglayer::primitive2d::Primitive2DContainer ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
53 const uno::Reference< ::frame::XModel >& rXModel,
54 basegfx::B2DRange& rRange)
56 drawinglayer::primitive2d::Primitive2DContainer aRetval;
58 if (!rXModel.is())
59 return aRetval;
61 // don't broadcast until we're finished building, more efficient
62 rXModel->lockControllers();
63 updateChart(rXModel);
64 rXModel->unlockControllers();
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::Sequence< beans::PropertyValue > aParams;
75 uno::Reference< drawing::XShape > xShape;
77 for(sal_Int32 a(0); a < nShapeCount; a++)
79 xShapeAccess->getByIndex(a) >>= xShape;
81 if(xShape.is())
83 PrimitiveFactory2D::createPrimitivesFromXShape(
84 xShape,
85 aParams,
86 aRetval);
91 catch(uno::Exception&)
93 TOOLS_WARN_EXCEPTION("svx", "");
96 if(!aRetval.empty())
98 const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
100 rRange = aRetval.getB2DRange(aViewInformation2D);
103 return aRetval;
106 void ChartHelper::AdaptDefaultsForChart(
107 const uno::Reference < embed::XEmbeddedObject > & xEmbObj)
109 if( !xEmbObj.is())
110 return;
112 uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
113 OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
114 if( !xChartDoc.is())
115 return;
119 if (uno::Reference< beans::XPropertySet > xPageProp = xChartDoc->getPageBackground())
121 // set background to transparent (none)
122 xPageProp->setPropertyValue(u"FillStyle"_ustr, uno::Any(drawing::FillStyle_NONE));
123 // set no border
124 xPageProp->setPropertyValue(u"LineStyle"_ustr, uno::Any(drawing::LineStyle_NONE));
127 catch( const uno::Exception & )
129 TOOLS_WARN_EXCEPTION("svx.svdraw", "");
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */