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 "oox/drawingml/chart/chartspaceconverter.hxx"
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"
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
;
53 // ============================================================================
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
;
62 // ============================================================================
64 ChartSpaceConverter::ChartSpaceConverter( const ConverterRoot
& rParent
, ChartSpaceModel
& rModel
) :
65 ConverterBase
< ChartSpaceModel
>( rParent
, rModel
)
69 ChartSpaceConverter::~ChartSpaceConverter()
73 void ChartSpaceConverter::convertFromModel( const Reference
< XShapes
>& rxExternalPage
, const awt::Point
& rChartPos
)
75 if( !getChartConverter() )
78 /* create data provider (virtual function in the ChartConverter class,
79 derived converters may create an external data provider) */
80 getChartConverter()->createDataProvider( getChartDocument() );
82 // attach number formatter of container document to data receiver
85 Reference
< XDataReceiver
> xDataRec( getChartDocument(), UNO_QUERY_THROW
);
86 Reference
< XNumberFormatsSupplier
> xNumFmtSupp( getFilter().getModel(), UNO_QUERY_THROW
);
87 xDataRec
->attachNumberFormatsSupplier( xNumFmtSupp
);
93 // formatting of the chart background
94 PropertySet
aBackPropSet( getChartDocument()->getPageBackground() );
95 getFormatter().convertFrameFormatting( aBackPropSet
, mrModel
.mxShapeProp
, OBJECTTYPE_CHARTSPACE
);
97 // convert plot area (container of all chart type groups)
98 PlotAreaConverter
aPlotAreaConv( *this, mrModel
.mxPlotArea
.getOrCreate() );
99 aPlotAreaConv
.convertFromModel( mrModel
.mxView3D
.getOrCreate() );
101 // plot area converter has created the diagram object
102 Reference
< XDiagram
> xDiagram
= getChartDocument()->getFirstDiagram();
104 // convert wall and floor formatting in 3D charts
105 if( xDiagram
.is() && aPlotAreaConv
.isWall3dChart() )
107 WallFloorConverter
aFloorConv( *this, mrModel
.mxFloor
.getOrCreate() );
108 aFloorConv
.convertFromModel( xDiagram
, OBJECTTYPE_FLOOR
);
110 WallFloorConverter
aWallConv( *this, mrModel
.mxBackWall
.getOrCreate() );
111 aWallConv
.convertFromModel( xDiagram
, OBJECTTYPE_WALL
);
115 if( !mrModel
.mbAutoTitleDel
) try
117 /* If the title model is missing, but the chart shows exactly one
118 series, the series title is shown as chart title. */
119 OUString aAutoTitle
= aPlotAreaConv
.getAutomaticTitle();
120 if( mrModel
.mxTitle
.is() || !aAutoTitle
.isEmpty() )
122 if( aAutoTitle
.isEmpty() )
123 aAutoTitle
= "Chart Title";
124 Reference
< XTitled
> xTitled( getChartDocument(), UNO_QUERY_THROW
);
125 TitleConverter
aTitleConv( *this, mrModel
.mxTitle
.getOrCreate() );
126 aTitleConv
.convertFromModel( xTitled
, aAutoTitle
, OBJECTTYPE_CHARTTITLE
);
134 if( xDiagram
.is() && mrModel
.mxLegend
.is() )
136 LegendConverter
aLegendConv( *this, *mrModel
.mxLegend
);
137 aLegendConv
.convertFromModel( xDiagram
);
140 // treatment of missing values
143 using namespace ::com::sun::star::chart::MissingValueTreatment
;
144 sal_Int32 nMissingValues
= LEAVE_GAP
;
145 switch( mrModel
.mnDispBlanksAs
)
147 case XML_gap
: nMissingValues
= LEAVE_GAP
; break;
148 case XML_zero
: nMissingValues
= USE_ZERO
; break;
149 case XML_span
: nMissingValues
= CONTINUE
; break;
151 PropertySet
aDiaProp( xDiagram
);
152 aDiaProp
.setProperty( PROP_MissingValueTreatment
, nMissingValues
);
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 Reference
< cssc::XChartDocument
> xChart1Doc( getChartDocument(), UNO_QUERY
);
159 if( xChart1Doc
.is() )
161 /* Set the IncludeHiddenCells property via the old API as only this
162 ensures that the data provider and all created sequences get this
164 PropertySet
aDiaProp( xChart1Doc
->getDiagram() );
165 aDiaProp
.setProperty( PROP_IncludeHiddenCells
, !mrModel
.mbPlotVisOnly
);
167 // plot area position and size
168 aPlotAreaConv
.convertPositionFromModel();
170 // positions of main title and all axis titles
171 convertTitlePositions();
174 // embedded drawing shapes
175 if( !mrModel
.maDrawingPath
.isEmpty() ) try
177 /* Get the internal draw page of the chart document, if no external
178 drawing page has been passed. */
179 Reference
< XShapes
> xShapes
;
180 awt::Point
aShapesOffset( 0, 0 );
181 if( rxExternalPage
.is() )
183 xShapes
= rxExternalPage
;
184 // offset for embedded shapes to move them inside the chart area
185 aShapesOffset
= rChartPos
;
189 Reference
< XDrawPageSupplier
> xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW
);
190 xShapes
.set( xDrawPageSupp
->getDrawPage(), UNO_QUERY_THROW
);
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 bool bOleSupport
= rxExternalPage
.is();
200 // now, xShapes is not null anymore
201 getFilter().importFragment( new ChartDrawingFragment(
202 getFilter(), mrModel
.maDrawingPath
, xShapes
, getChartSize(), aShapesOffset
, bOleSupport
) );
209 if ( mrModel
.mbPivotChart
)
211 PropertySet
aProps( getChartDocument() );
212 aProps
.setProperty( PROP_DisableDataTableDialog
, true );
213 aProps
.setProperty( PROP_DisableComplexChartTypes
, true );
217 // ============================================================================
220 } // namespace drawingml
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */