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 "oox/drawingml/chart/chartspaceconverter.hxx"
21 :
22 : #include <com/sun/star/chart/MissingValueTreatment.hpp>
23 : #include <com/sun/star/chart/XChartDocument.hpp>
24 : #include <com/sun/star/chart2/XChartDocument.hpp>
25 : #include <com/sun/star/chart2/XTitled.hpp>
26 : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
27 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
28 : #include "oox/core/xmlfilterbase.hxx"
29 : #include "oox/drawingml/chart/chartconverter.hxx"
30 : #include "oox/drawingml/chart/chartdrawingfragment.hxx"
31 : #include "oox/drawingml/chart/chartspacemodel.hxx"
32 : #include "oox/drawingml/chart/plotareaconverter.hxx"
33 : #include "oox/drawingml/chart/titleconverter.hxx"
34 :
35 : using namespace ::com::sun::star;
36 : using ::com::sun::star::uno::Reference;
37 : using ::com::sun::star::uno::Exception;
38 : using ::com::sun::star::uno::UNO_QUERY;
39 : using ::com::sun::star::uno::UNO_QUERY_THROW;
40 : using ::com::sun::star::uno::makeAny;
41 : using ::com::sun::star::util::XNumberFormatsSupplier;
42 : using ::com::sun::star::drawing::XDrawPageSupplier;
43 : using ::com::sun::star::drawing::XShapes;
44 : using ::com::sun::star::chart2::XDiagram;
45 : using ::com::sun::star::chart2::XTitled;
46 : using ::com::sun::star::chart2::data::XDataReceiver;
47 : using ::com::sun::star::beans::XPropertySet;
48 :
49 : namespace oox {
50 : namespace drawingml {
51 : namespace chart {
52 :
53 :
54 :
55 : using namespace ::com::sun::star::awt;
56 : using namespace ::com::sun::star::chart2;
57 : using namespace ::com::sun::star::chart2::data;
58 : using namespace ::com::sun::star::drawing;
59 : using namespace ::com::sun::star::uno;
60 : using namespace ::com::sun::star::util;
61 :
62 :
63 :
64 65 : ChartSpaceConverter::ChartSpaceConverter( const ConverterRoot& rParent, ChartSpaceModel& rModel ) :
65 65 : ConverterBase< ChartSpaceModel >( rParent, rModel )
66 : {
67 65 : }
68 :
69 65 : ChartSpaceConverter::~ChartSpaceConverter()
70 : {
71 65 : }
72 :
73 65 : void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExternalPage, const awt::Point& rChartPos )
74 : {
75 65 : if( !getChartConverter() )
76 65 : return;
77 :
78 : /* create data provider (virtual function in the ChartConverter class,
79 : derived converters may create an external data provider) */
80 65 : getChartConverter()->createDataProvider( getChartDocument() );
81 :
82 : // attach number formatter of container document to data receiver
83 : try
84 : {
85 65 : Reference< XDataReceiver > xDataRec( getChartDocument(), UNO_QUERY_THROW );
86 128 : Reference< XNumberFormatsSupplier > xNumFmtSupp( getFilter().getModel(), UNO_QUERY_THROW );
87 128 : xDataRec->attachNumberFormatsSupplier( xNumFmtSupp );
88 : }
89 2 : catch( Exception& )
90 : {
91 : }
92 :
93 : // formatting of the chart background
94 65 : PropertySet aBackPropSet( getChartDocument()->getPageBackground() );
95 65 : getFormatter().convertFrameFormatting( aBackPropSet, mrModel.mxShapeProp, OBJECTTYPE_CHARTSPACE );
96 :
97 : // convert plot area (container of all chart type groups)
98 130 : PlotAreaConverter aPlotAreaConv( *this, mrModel.mxPlotArea.getOrCreate() );
99 65 : aPlotAreaConv.convertFromModel( mrModel.mxView3D.getOrCreate() );
100 :
101 : // plot area converter has created the diagram object
102 130 : Reference< XDiagram > xDiagram = getChartDocument()->getFirstDiagram();
103 :
104 : // convert wall and floor formatting in 3D charts
105 65 : if( xDiagram.is() && aPlotAreaConv.isWall3dChart() )
106 : {
107 24 : WallFloorConverter aFloorConv( *this, mrModel.mxFloor.getOrCreate() );
108 24 : aFloorConv.convertFromModel( xDiagram, OBJECTTYPE_FLOOR );
109 :
110 48 : WallFloorConverter aWallConv( *this, mrModel.mxBackWall.getOrCreate() );
111 48 : aWallConv.convertFromModel( xDiagram, OBJECTTYPE_WALL );
112 : }
113 :
114 : // chart title
115 65 : if( !mrModel.mbAutoTitleDel ) try
116 : {
117 : /* If the title model is missing, but the chart shows exactly one
118 : series, the series title is shown as chart title. */
119 61 : OUString aAutoTitle = aPlotAreaConv.getAutomaticTitle();
120 61 : if( mrModel.mxTitle.is() || !aAutoTitle.isEmpty() )
121 : {
122 36 : if( aAutoTitle.isEmpty() )
123 21 : aAutoTitle = "Chart Title";
124 36 : Reference< XTitled > xTitled( getChartDocument(), UNO_QUERY_THROW );
125 72 : TitleConverter aTitleConv( *this, mrModel.mxTitle.getOrCreate() );
126 72 : aTitleConv.convertFromModel( xTitled, aAutoTitle, OBJECTTYPE_CHARTTITLE );
127 61 : }
128 : }
129 0 : catch( Exception& )
130 : {
131 : }
132 :
133 : // legend
134 65 : if( xDiagram.is() && mrModel.mxLegend.is() )
135 : {
136 60 : LegendConverter aLegendConv( *this, *mrModel.mxLegend );
137 60 : aLegendConv.convertFromModel( xDiagram );
138 : }
139 :
140 : // treatment of missing values
141 65 : if( xDiagram.is() )
142 : {
143 : using namespace ::com::sun::star::chart::MissingValueTreatment;
144 65 : sal_Int32 nMissingValues = LEAVE_GAP;
145 65 : switch( mrModel.mnDispBlanksAs )
146 : {
147 62 : case XML_gap: nMissingValues = LEAVE_GAP; break;
148 3 : case XML_zero: nMissingValues = USE_ZERO; break;
149 0 : case XML_span: nMissingValues = CONTINUE; break;
150 : }
151 65 : PropertySet aDiaProp( xDiagram );
152 65 : aDiaProp.setProperty( PROP_MissingValueTreatment, nMissingValues );
153 : }
154 :
155 : /* Following all conversions needing the old Chart1 API that involves full
156 : initialization of the chart view. */
157 : namespace cssc = ::com::sun::star::chart;
158 65 : Reference< cssc::XChartDocument > xChart1Doc( getChartDocument(), UNO_QUERY );
159 65 : if( xChart1Doc.is() )
160 : {
161 : /* Set the IncludeHiddenCells property via the old API as only this
162 : ensures that the data provider and all created sequences get this
163 : flag correctly. */
164 65 : PropertySet aDiaProp( xChart1Doc->getDiagram() );
165 65 : aDiaProp.setProperty( PROP_IncludeHiddenCells, !mrModel.mbPlotVisOnly );
166 :
167 : // plot area position and size
168 65 : aPlotAreaConv.convertPositionFromModel();
169 :
170 : // positions of main title and all axis titles
171 65 : convertTitlePositions();
172 : }
173 :
174 : // embedded drawing shapes
175 65 : if( !mrModel.maDrawingPath.isEmpty() ) try
176 : {
177 : /* Get the internal draw page of the chart document, if no external
178 : drawing page has been passed. */
179 1 : Reference< XShapes > xShapes;
180 1 : awt::Point aShapesOffset( 0, 0 );
181 1 : if( rxExternalPage.is() )
182 : {
183 0 : xShapes = rxExternalPage;
184 : // offset for embedded shapes to move them inside the chart area
185 0 : aShapesOffset = rChartPos;
186 : }
187 : else
188 : {
189 1 : Reference< XDrawPageSupplier > xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW );
190 1 : xShapes.set( xDrawPageSupp->getDrawPage(), UNO_QUERY_THROW );
191 : }
192 :
193 : /* If an external drawing page is passed, all embedded shapes will be
194 : inserted there (used e.g. with 'chart sheets' in spreadsheet
195 : documents). In this case, all types of shapes including OLE objects
196 : are supported. If the shapes are inserted into the internal chart
197 : drawing page instead, it is not possible to embed OLE objects. */
198 1 : bool bOleSupport = rxExternalPage.is();
199 :
200 : // now, xShapes is not null anymore
201 1 : getFilter().importFragment( new ChartDrawingFragment(
202 2 : getFilter(), mrModel.maDrawingPath, xShapes, getChartSize(), aShapesOffset, bOleSupport ) );
203 : }
204 0 : catch( Exception& )
205 : {
206 : }
207 :
208 : // pivot chart
209 65 : if ( mrModel.mbPivotChart )
210 : {
211 0 : PropertySet aProps( getChartDocument() );
212 0 : aProps.setProperty( PROP_DisableDataTableDialog , true );
213 0 : aProps.setProperty( PROP_DisableComplexChartTypes , true );
214 : }
215 :
216 65 : if(!mrModel.maSheetPath.isEmpty() )
217 : {
218 46 : Reference< ::com::sun::star::chart::XChartDocument > xChartDoc( getChartDocument(), UNO_QUERY );
219 92 : PropertySet aProps( xChartDoc->getDiagram() );
220 92 : aProps.setProperty( PROP_ExternalData , uno::makeAny(mrModel.maSheetPath) );
221 130 : }
222 : }
223 :
224 :
225 :
226 : } // namespace chart
227 : } // namespace drawingml
228 177 : } // namespace oox
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|