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/helper/graphichelper.hxx>
31 #include "drawingml/chart/chartdrawingfragment.hxx"
32 #include "drawingml/chart/chartspacemodel.hxx"
33 #include "drawingml/chart/plotareaconverter.hxx"
34 #include "drawingml/chart/titleconverter.hxx"
36 using namespace ::com::sun::star
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::uno::Exception
;
39 using ::com::sun::star::uno::UNO_QUERY
;
40 using ::com::sun::star::uno::UNO_QUERY_THROW
;
41 using ::com::sun::star::uno::makeAny
;
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::beans::XPropertySet
;
52 using namespace ::com::sun::star::awt
;
53 using namespace ::com::sun::star::chart2
;
54 using namespace ::com::sun::star::chart2::data
;
55 using namespace ::com::sun::star::drawing
;
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::util
;
59 ChartSpaceConverter::ChartSpaceConverter( const ConverterRoot
& rParent
, ChartSpaceModel
& rModel
) :
60 ConverterBase
< ChartSpaceModel
>( rParent
, rModel
)
64 ChartSpaceConverter::~ChartSpaceConverter()
68 void ChartSpaceConverter::convertFromModel( const Reference
< XShapes
>& rxExternalPage
, const awt::Point
& rChartPos
)
70 if( !getChartConverter() )
73 /* create data provider (virtual function in the ChartConverter class,
74 derived converters may create an external data provider) */
75 getChartConverter()->createDataProvider( getChartDocument() );
77 // formatting of the chart background. The default fill style varies with applications.
78 PropertySet
aBackPropSet( getChartDocument()->getPageBackground() );
79 getFormatter().convertFrameFormatting( aBackPropSet
, mrModel
.mxShapeProp
, OBJECTTYPE_CHARTSPACE
);
81 bool bMSO2007Doc
= getFilter().isMSO2007Document();
82 // convert plot area (container of all chart type groups)
83 PlotAreaConverter
aPlotAreaConv( *this, mrModel
.mxPlotArea
.getOrCreate() );
84 aPlotAreaConv
.convertFromModel( mrModel
.mxView3D
.getOrCreate(bMSO2007Doc
) );
86 // plot area converter has created the diagram object
87 Reference
< XDiagram
> xDiagram
= getChartDocument()->getFirstDiagram();
89 // convert wall and floor formatting in 3D charts
90 if( xDiagram
.is() && aPlotAreaConv
.isWall3dChart() )
92 WallFloorConverter
aFloorConv( *this, mrModel
.mxFloor
.getOrCreate() );
93 aFloorConv
.convertFromModel( xDiagram
, OBJECTTYPE_FLOOR
);
95 WallFloorConverter
aWallConv( *this, mrModel
.mxBackWall
.getOrCreate() );
96 aWallConv
.convertFromModel( xDiagram
, OBJECTTYPE_WALL
);
100 if( !mrModel
.mbAutoTitleDel
) try
102 /* If the title model is missing, but the chart shows exactly one
103 series, the series title is shown as chart title. */
104 OUString aAutoTitle
= aPlotAreaConv
.getAutomaticTitle();
105 if( mrModel
.mxTitle
.is() || !aAutoTitle
.isEmpty() )
107 if( aAutoTitle
.isEmpty() )
108 aAutoTitle
= "Chart Title";
109 Reference
< XTitled
> xTitled( getChartDocument(), UNO_QUERY_THROW
);
110 TitleConverter
aTitleConv( *this, mrModel
.mxTitle
.getOrCreate() );
111 aTitleConv
.convertFromModel( xTitled
, aAutoTitle
, OBJECTTYPE_CHARTTITLE
);
119 if( xDiagram
.is() && mrModel
.mxLegend
.is() )
121 LegendConverter
aLegendConv( *this, *mrModel
.mxLegend
);
122 aLegendConv
.convertFromModel( xDiagram
);
125 // treatment of missing values
128 using namespace ::com::sun::star::chart::MissingValueTreatment
;
129 sal_Int32 nMissingValues
= LEAVE_GAP
;
130 switch( mrModel
.mnDispBlanksAs
)
132 case XML_gap
: nMissingValues
= LEAVE_GAP
; break;
133 case XML_zero
: nMissingValues
= USE_ZERO
; break;
134 case XML_span
: nMissingValues
= CONTINUE
; break;
136 PropertySet
aDiaProp( xDiagram
);
137 aDiaProp
.setProperty( PROP_MissingValueTreatment
, nMissingValues
);
140 /* Following all conversions needing the old Chart1 API that involves full
141 initialization of the chart view. */
142 namespace cssc
= ::com::sun::star::chart
;
143 Reference
< cssc::XChartDocument
> xChart1Doc( getChartDocument(), UNO_QUERY
);
144 if( xChart1Doc
.is() )
146 /* Set the IncludeHiddenCells property via the old API as only this
147 ensures that the data provider and all created sequences get this
149 PropertySet
aDiaProp( xChart1Doc
->getDiagram() );
150 aDiaProp
.setProperty( PROP_IncludeHiddenCells
, !mrModel
.mbPlotVisOnly
);
152 // plot area position and size
153 aPlotAreaConv
.convertPositionFromModel();
155 // positions of main title and all axis titles
156 convertTitlePositions();
159 // embedded drawing shapes
160 if( !mrModel
.maDrawingPath
.isEmpty() ) try
162 /* Get the internal draw page of the chart document, if no external
163 drawing page has been passed. */
164 Reference
< XShapes
> xShapes
;
165 awt::Point
aShapesOffset( 0, 0 );
166 if( rxExternalPage
.is() )
168 xShapes
= rxExternalPage
;
169 // offset for embedded shapes to move them inside the chart area
170 aShapesOffset
= rChartPos
;
174 Reference
< XDrawPageSupplier
> xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW
);
175 xShapes
.set( xDrawPageSupp
->getDrawPage(), UNO_QUERY_THROW
);
178 /* If an external drawing page is passed, all embedded shapes will be
179 inserted there (used e.g. with 'chart sheets' in spreadsheet
180 documents). In this case, all types of shapes including OLE objects
181 are supported. If the shapes are inserted into the internal chart
182 drawing page instead, it is not possible to embed OLE objects. */
183 bool bOleSupport
= rxExternalPage
.is();
185 // now, xShapes is not null anymore
186 getFilter().importFragment( new ChartDrawingFragment(
187 getFilter(), mrModel
.maDrawingPath
, xShapes
, getChartSize(), aShapesOffset
, bOleSupport
) );
194 if ( mrModel
.mbPivotChart
)
196 PropertySet
aProps( getChartDocument() );
197 aProps
.setProperty( PROP_DisableDataTableDialog
, true );
198 aProps
.setProperty( PROP_DisableComplexChartTypes
, true );
201 if(!mrModel
.maSheetPath
.isEmpty() )
203 Reference
< ::com::sun::star::chart::XChartDocument
> xChartDoc( getChartDocument(), UNO_QUERY
);
204 PropertySet
aProps( xChartDoc
->getDiagram() );
205 aProps
.setProperty( PROP_ExternalData
, uno::makeAny(mrModel
.maSheetPath
) );
210 } // namespace drawingml
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */