Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
36 :
37 : using namespace ::com::sun::star;
38 :
39 2440 : bool ChartHelper::isGL3DDiagram( const css::uno::Reference<css::chart2::XDiagram>& xDiagram )
40 : {
41 2440 : uno::Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, uno::UNO_QUERY);
42 :
43 2440 : if (!xCooSysContainer.is())
44 151 : return false;
45 :
46 4578 : uno::Sequence< uno::Reference<chart2::XCoordinateSystem> > aCooSysList = xCooSysContainer->getCoordinateSystems();
47 4575 : for (sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS)
48 : {
49 2286 : uno::Reference<chart2::XCoordinateSystem> xCooSys = aCooSysList[nCS];
50 :
51 : //iterate through all chart types in the current coordinate system
52 4572 : uno::Reference<chart2::XChartTypeContainer> xChartTypeContainer(xCooSys, uno::UNO_QUERY);
53 : OSL_ASSERT( xChartTypeContainer.is());
54 2286 : if( !xChartTypeContainer.is() )
55 0 : continue;
56 :
57 4572 : uno::Sequence< uno::Reference<chart2::XChartType> > aChartTypeList = xChartTypeContainer->getChartTypes();
58 4614 : for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
59 : {
60 2328 : uno::Reference<chart2::XChartType> xChartType = aChartTypeList[nT];
61 4656 : OUString aChartType = xChartType->getChartType();
62 2328 : if( aChartType == "com.sun.star.chart2.GL3DBarChartType" )
63 0 : return true;
64 2328 : }
65 2286 : }
66 :
67 4729 : return false;
68 : }
69 :
70 216 : void ChartHelper::updateChart( const uno::Reference< ::frame::XModel >& rXModel, bool bHardUpdate )
71 : {
72 216 : if (!rXModel.is())
73 216 : return;
74 :
75 : try
76 : {
77 216 : const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
78 432 : const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW);
79 432 : const uno::Reference<util::XUpdatable2> xUpdatable(xChartView, uno::UNO_QUERY_THROW);
80 :
81 216 : if (xUpdatable.is())
82 : {
83 216 : if (bHardUpdate)
84 216 : xUpdatable->updateHard();
85 : else
86 0 : xUpdatable->updateSoft();
87 216 : }
88 : }
89 0 : catch(uno::Exception&)
90 : {
91 : OSL_ENSURE(false, "Unexpected exception!");
92 : }
93 : }
94 :
95 216 : drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
96 : const uno::Reference< ::frame::XModel >& rXModel,
97 : basegfx::B2DRange& rRange)
98 : {
99 216 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
100 :
101 216 : if (!rXModel.is())
102 0 : return aRetval;
103 :
104 216 : updateChart(rXModel, true);
105 :
106 : try
107 : {
108 216 : const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
109 432 : const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
110 :
111 216 : if(xShapeAccess.is() && xShapeAccess->getCount())
112 : {
113 216 : const sal_Int32 nShapeCount(xShapeAccess->getCount());
114 216 : const uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
115 : const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory =
116 428 : graphic::PrimitiveFactory2D::create( xContext );
117 :
118 424 : const uno::Sequence< beans::PropertyValue > aParams;
119 424 : uno::Reference< drawing::XShape > xShape;
120 :
121 424 : for(sal_Int32 a(0); a < nShapeCount; a++)
122 : {
123 212 : xShapeAccess->getByIndex(a) >>= xShape;
124 :
125 212 : if(xShape.is())
126 : {
127 : const drawinglayer::primitive2d::Primitive2DSequence aNew(
128 212 : xPrimitiveFactory->createPrimitivesFromXShape(
129 : xShape,
130 212 : aParams));
131 :
132 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
133 : aRetval,
134 212 : aNew);
135 : }
136 216 : }
137 216 : }
138 : }
139 4 : catch(uno::Exception&)
140 : {
141 : OSL_ENSURE(false, "Unexpected exception!");
142 : }
143 :
144 216 : if(aRetval.hasElements())
145 : {
146 212 : const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
147 :
148 212 : rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D);
149 : }
150 :
151 216 : return aRetval;
152 : }
153 :
154 0 : void ChartHelper::AdaptDefaultsForChart(
155 : const uno::Reference < embed::XEmbeddedObject > & xEmbObj,
156 : bool /* bNoFillStyle */,
157 : bool /* bNoLineStyle */)
158 : {
159 0 : if( xEmbObj.is())
160 : {
161 0 : uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
162 : OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
163 0 : if( !xChartDoc.is())
164 0 : return;
165 :
166 : try
167 : {
168 : // set background to transparent (none)
169 0 : uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground());
170 0 : if( xPageProp.is())
171 0 : xPageProp->setPropertyValue( "FillStyle",
172 0 : uno::makeAny( drawing::FillStyle_NONE ));
173 : // set no border
174 0 : if( xPageProp.is())
175 0 : xPageProp->setPropertyValue( "LineStyle",
176 0 : uno::makeAny( drawing::LineStyle_NONE ));
177 : }
178 0 : catch( const uno::Exception & )
179 : {
180 : OSL_FAIL( "Exception caught in AdaptDefaultsForChart" );
181 0 : }
182 : }
183 : }
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|