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 "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/drawing/XDrawPageSupplier.hpp>
27 #include <com/sun/star/drawing/FillStyle.hpp>
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "oox/drawingml/chart/chartconverter.hxx"
30 #include <oox/token/namespaces.hxx>
31 #include <oox/token/properties.hxx>
32 #include <oox/token/tokens.hxx>
33 #include <oox/helper/graphichelper.hxx>
34 #include "drawingml/chart/chartdrawingfragment.hxx"
35 #include "drawingml/chart/chartspacemodel.hxx"
36 #include "drawingml/chart/plotareaconverter.hxx"
37 #include "drawingml/chart/titleconverter.hxx"
39 using namespace ::com::sun::star
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::Exception
;
42 using ::com::sun::star::uno::UNO_QUERY
;
43 using ::com::sun::star::uno::UNO_QUERY_THROW
;
44 using ::com::sun::star::uno::makeAny
;
45 using ::com::sun::star::drawing::XDrawPageSupplier
;
46 using ::com::sun::star::drawing::XShapes
;
47 using ::com::sun::star::chart2::XDiagram
;
48 using ::com::sun::star::chart2::XTitled
;
54 using namespace ::com::sun::star::awt
;
55 using namespace ::com::sun::star::chart2
;
56 using namespace ::com::sun::star::chart2::data
;
57 using namespace ::com::sun::star::drawing
;
58 using namespace ::com::sun::star::uno
;
59 using namespace ::com::sun::star::util
;
61 ChartSpaceConverter::ChartSpaceConverter( const ConverterRoot
& rParent
, ChartSpaceModel
& rModel
) :
62 ConverterBase
< ChartSpaceModel
>( rParent
, rModel
)
66 ChartSpaceConverter::~ChartSpaceConverter()
70 void ChartSpaceConverter::convertFromModel( const Reference
< XShapes
>& rxExternalPage
, const awt::Point
& rChartPos
)
72 /* create data provider (virtual function in the ChartConverter class,
73 derived converters may create an external data provider) */
74 getChartConverter().createDataProvider( getChartDocument() );
76 // formatting of the chart background. The default fill style varies with applications.
77 PropertySet
aBackPropSet( getChartDocument()->getPageBackground() );
78 getFormatter().convertFrameFormatting( aBackPropSet
, mrModel
.mxShapeProp
, OBJECTTYPE_CHARTSPACE
);
80 bool bMSO2007Doc
= getFilter().isMSO2007Document();
81 // convert plot area (container of all chart type groups)
82 PlotAreaConverter
aPlotAreaConv( *this, mrModel
.mxPlotArea
.getOrCreate() );
83 aPlotAreaConv
.convertFromModel( mrModel
.mxView3D
.getOrCreate(bMSO2007Doc
) );
85 // plot area converter has created the diagram object
86 Reference
< XDiagram
> xDiagram
= getChartDocument()->getFirstDiagram();
88 // convert wall and floor formatting in 3D charts
89 if( xDiagram
.is() && aPlotAreaConv
.isWall3dChart() )
91 WallFloorConverter
aFloorConv( *this, mrModel
.mxFloor
.getOrCreate() );
92 aFloorConv
.convertFromModel( xDiagram
, OBJECTTYPE_FLOOR
);
94 WallFloorConverter
aWallConv( *this, mrModel
.mxBackWall
.getOrCreate() );
95 aWallConv
.convertFromModel( xDiagram
, OBJECTTYPE_WALL
);
99 if( !mrModel
.mbAutoTitleDel
) try
101 /* If the title model is missing, but the chart shows exactly one
102 series, the series title is shown as chart title. */
103 OUString aAutoTitle
= aPlotAreaConv
.getAutomaticTitle();
104 if( mrModel
.mxTitle
.is() || !aAutoTitle
.isEmpty() )
106 if( aAutoTitle
.isEmpty() )
107 aAutoTitle
= "Chart Title";
108 Reference
< XTitled
> xTitled( getChartDocument(), UNO_QUERY_THROW
);
109 TitleConverter
aTitleConv( *this, mrModel
.mxTitle
.getOrCreate() );
110 aTitleConv
.convertFromModel( xTitled
, aAutoTitle
, OBJECTTYPE_CHARTTITLE
);
118 if( xDiagram
.is() && mrModel
.mxLegend
.is() )
120 LegendConverter
aLegendConv( *this, *mrModel
.mxLegend
);
121 aLegendConv
.convertFromModel( xDiagram
);
124 // treatment of missing values
127 using namespace ::com::sun::star::chart::MissingValueTreatment
;
128 sal_Int32 nMissingValues
= LEAVE_GAP
;
129 switch( mrModel
.mnDispBlanksAs
)
131 case XML_gap
: nMissingValues
= LEAVE_GAP
; break;
132 case XML_zero
: nMissingValues
= USE_ZERO
; break;
133 case XML_span
: nMissingValues
= CONTINUE
; break;
135 PropertySet
aDiaProp( xDiagram
);
136 aDiaProp
.setProperty( PROP_MissingValueTreatment
, nMissingValues
);
139 /* Following all conversions needing the old Chart1 API that involves full
140 initialization of the chart view. */
141 namespace cssc
= ::com::sun::star::chart
;
142 Reference
< cssc::XChartDocument
> xChart1Doc( getChartDocument(), UNO_QUERY
);
143 if( xChart1Doc
.is() )
145 /* Set the IncludeHiddenCells property via the old API as only this
146 ensures that the data provider and all created sequences get this
148 PropertySet
aDiaProp( xChart1Doc
->getDiagram() );
149 aDiaProp
.setProperty( PROP_IncludeHiddenCells
, !mrModel
.mbPlotVisOnly
);
151 // plot area position and size
152 aPlotAreaConv
.convertPositionFromModel();
154 // positions of main title and all axis titles
155 convertTitlePositions();
158 // embedded drawing shapes
159 if( !mrModel
.maDrawingPath
.isEmpty() ) try
161 /* Get the internal draw page of the chart document, if no external
162 drawing page has been passed. */
163 Reference
< XShapes
> xShapes
;
164 awt::Point
aShapesOffset( 0, 0 );
165 if( rxExternalPage
.is() )
167 xShapes
= rxExternalPage
;
168 // offset for embedded shapes to move them inside the chart area
169 aShapesOffset
= rChartPos
;
173 Reference
< XDrawPageSupplier
> xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW
);
174 xShapes
.set( xDrawPageSupp
->getDrawPage(), UNO_QUERY_THROW
);
177 /* If an external drawing page is passed, all embedded shapes will be
178 inserted there (used e.g. with 'chart sheets' in spreadsheet
179 documents). In this case, all types of shapes including OLE objects
180 are supported. If the shapes are inserted into the internal chart
181 drawing page instead, it is not possible to embed OLE objects. */
182 bool bOleSupport
= rxExternalPage
.is();
184 // now, xShapes is not null anymore
185 getFilter().importFragment( new ChartDrawingFragment(
186 getFilter(), mrModel
.maDrawingPath
, xShapes
, getChartSize(), aShapesOffset
, bOleSupport
) );
193 if ( mrModel
.mbPivotChart
)
195 PropertySet
aProps( getChartDocument() );
196 aProps
.setProperty( PROP_DisableDataTableDialog
, true );
197 aProps
.setProperty( PROP_DisableComplexChartTypes
, true );
200 if(!mrModel
.maSheetPath
.isEmpty() )
202 Reference
< css::chart::XChartDocument
> xChartDoc( getChartDocument(), UNO_QUERY
);
203 PropertySet
aProps( xChartDoc
->getDiagram() );
204 aProps
.setProperty( PROP_ExternalData
, uno::makeAny(mrModel
.maSheetPath
) );
209 } // namespace drawingml
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */