1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/globname.hxx>
22 #include <comphelper/classids.hxx>
23 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
24 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
25 #include <com/sun/star/embed/XEmbeddedObject.hpp>
26 #include <com/sun/star/lang/XUnoTunnel.hpp>
27 #include <com/sun/star/util/XUpdatable2.hpp>
28 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <comphelper/processfactory.hxx>
31 #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
32 #include <drawinglayer/geometry/viewinformation2d.hxx>
33 #include <com/sun/star/chart2/XChartDocument.hpp>
34 #include <com/sun/star/drawing/FillStyle.hpp>
35 #include <com/sun/star/drawing/LineStyle.hpp>
37 using namespace ::com::sun::star
;
39 bool ChartHelper::isGL3DDiagram( const css::uno::Reference
<css::chart2::XDiagram
>& xDiagram
)
41 uno::Reference
<chart2::XCoordinateSystemContainer
> xCooSysContainer(xDiagram
, uno::UNO_QUERY
);
43 if (!xCooSysContainer
.is())
46 uno::Sequence
< uno::Reference
<chart2::XCoordinateSystem
> > aCooSysList
= xCooSysContainer
->getCoordinateSystems();
47 for (sal_Int32 nCS
= 0; nCS
< aCooSysList
.getLength(); ++nCS
)
49 uno::Reference
<chart2::XCoordinateSystem
> xCooSys
= aCooSysList
[nCS
];
51 //iterate through all chart types in the current coordinate system
52 uno::Reference
<chart2::XChartTypeContainer
> xChartTypeContainer(xCooSys
, uno::UNO_QUERY
);
53 OSL_ASSERT( xChartTypeContainer
.is());
54 if( !xChartTypeContainer
.is() )
57 uno::Sequence
< uno::Reference
<chart2::XChartType
> > aChartTypeList
= xChartTypeContainer
->getChartTypes();
58 for( sal_Int32 nT
= 0; nT
< aChartTypeList
.getLength(); ++nT
)
60 uno::Reference
<chart2::XChartType
> xChartType
= aChartTypeList
[nT
];
61 OUString aChartType
= xChartType
->getChartType();
62 if( aChartType
== "com.sun.star.chart2.GL3DBarChartType" )
70 void ChartHelper::updateChart( const uno::Reference
< ::frame::XModel
>& rXModel
, bool bHardUpdate
)
77 const uno::Reference
< lang::XMultiServiceFactory
> xChartFact(rXModel
, uno::UNO_QUERY_THROW
);
78 const uno::Reference
< lang::XUnoTunnel
> xChartView(xChartFact
->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW
);
79 const uno::Reference
<util::XUpdatable2
> xUpdatable(xChartView
, uno::UNO_QUERY_THROW
);
84 xUpdatable
->updateHard();
86 xUpdatable
->updateSoft();
89 catch(uno::Exception
&)
91 OSL_ENSURE(false, "Unexpected exception!");
95 drawinglayer::primitive2d::Primitive2DSequence
ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
96 const uno::Reference
< ::frame::XModel
>& rXModel
,
97 basegfx::B2DRange
& rRange
)
99 drawinglayer::primitive2d::Primitive2DSequence aRetval
;
104 updateChart(rXModel
, true);
108 const uno::Reference
< drawing::XDrawPageSupplier
> xDrawPageSupplier(rXModel
, uno::UNO_QUERY_THROW
);
109 const uno::Reference
< container::XIndexAccess
> xShapeAccess(xDrawPageSupplier
->getDrawPage(), uno::UNO_QUERY_THROW
);
111 if(xShapeAccess
.is() && xShapeAccess
->getCount())
113 const sal_Int32
nShapeCount(xShapeAccess
->getCount());
114 const uno::Reference
< uno::XComponentContext
> xContext(::comphelper::getProcessComponentContext());
115 const uno::Reference
< graphic::XPrimitiveFactory2D
> xPrimitiveFactory
=
116 graphic::PrimitiveFactory2D::create( xContext
);
118 const uno::Sequence
< beans::PropertyValue
> aParams
;
119 uno::Reference
< drawing::XShape
> xShape
;
121 for(sal_Int32
a(0); a
< nShapeCount
; a
++)
123 xShapeAccess
->getByIndex(a
) >>= xShape
;
127 const drawinglayer::primitive2d::Primitive2DSequence
aNew(
128 xPrimitiveFactory
->createPrimitivesFromXShape(
132 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
139 catch(uno::Exception
&)
141 OSL_ENSURE(false, "Unexpected exception!");
144 if(aRetval
.hasElements())
146 const drawinglayer::geometry::ViewInformation2D aViewInformation2D
;
148 rRange
= drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval
, aViewInformation2D
);
154 void ChartHelper::AdaptDefaultsForChart(
155 const uno::Reference
< embed::XEmbeddedObject
> & xEmbObj
,
156 bool /* bNoFillStyle */,
157 bool /* bNoLineStyle */)
161 uno::Reference
< chart2::XChartDocument
> xChartDoc( xEmbObj
->getComponent(), uno::UNO_QUERY
);
162 OSL_ENSURE( xChartDoc
.is(), "Trying to set chart property to non-chart OLE" );
168 // set background to transparent (none)
169 uno::Reference
< beans::XPropertySet
> xPageProp( xChartDoc
->getPageBackground());
171 xPageProp
->setPropertyValue( "FillStyle",
172 uno::makeAny( drawing::FillStyle_NONE
));
175 xPageProp
->setPropertyValue( "LineStyle",
176 uno::makeAny( drawing::LineStyle_NONE
));
178 catch( const uno::Exception
& )
180 OSL_FAIL( "Exception caught in AdaptDefaultsForChart" );
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */