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