bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / charthelper.cxx
blob9d4c52023595d374146ad718fea98ae4f2146eb4
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 <svtools/embedhlp.hxx>
22 #include <tools/globname.hxx>
23 #include <comphelper/classids.hxx>
24 #include <com/sun/star/embed/XEmbeddedObject.hpp>
25 #include <com/sun/star/lang/XUnoTunnel.hpp>
26 #include <com/sun/star/util/XUpdatable.hpp>
27 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
31 #include <drawinglayer/geometry/viewinformation2d.hxx>
33 using namespace ::com::sun::star;
35 bool ChartHelper::IsChart(const svt::EmbeddedObjectRef& xObjRef)
37 if(!xObjRef.is())
39 return false;
42 const SvGlobalName aObjClsId(xObjRef->getClassID());
44 if(SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId
45 || SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId
46 || SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId
47 || SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId)
49 return true;
52 return false;
55 drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
56 const uno::Reference< ::frame::XModel >& rXModel,
57 basegfx::B2DRange& rRange)
59 drawinglayer::primitive2d::Primitive2DSequence aRetval;
61 if(rXModel.is())
63 try
65 const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
66 const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance(OUString::createFromAscii("com.sun.star.chart2.ChartView")), uno::UNO_QUERY_THROW);
67 const uno::Reference< util::XUpdatable > xUpdatable(xChartView, uno::UNO_QUERY_THROW);
69 if(xUpdatable.is())
71 xUpdatable->update();
73 const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
74 const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
76 if(xShapeAccess.is() && xShapeAccess->getCount())
78 const sal_Int32 nShapeCount(xShapeAccess->getCount());
79 const uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
80 const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory =
81 graphic::PrimitiveFactory2D::create( xContext );
83 const uno::Sequence< beans::PropertyValue > aParams;
84 uno::Reference< drawing::XShape > xShape;
86 for(sal_Int32 a(0); a < nShapeCount; a++)
88 xShapeAccess->getByIndex(a) >>= xShape;
90 if(xShape.is())
92 const drawinglayer::primitive2d::Primitive2DSequence aNew(
93 xPrimitiveFactory->createPrimitivesFromXShape(
94 xShape,
95 aParams));
97 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
98 aRetval,
99 aNew);
105 catch(uno::Exception&)
107 OSL_ENSURE(false, "Unexpected exception!");
110 if(aRetval.hasElements())
112 const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
114 rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D);
118 return aRetval;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */