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