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 10cdf0e10cSrcweir * 11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20*ca5ec200SAndrew Rist *************************************************************/ 21*ca5ec200SAndrew Rist 22*ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "oox/drawingml/graphicshapecontext.hxx" 25cdf0e10cSrcweir #include <osl/diagnose.h> 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "oox/drawingml/fillpropertiesgroupcontext.hxx" 28cdf0e10cSrcweir #include "oox/drawingml/customshapeproperties.hxx" 29cdf0e10cSrcweir #include "oox/drawingml/diagram/diagramfragmenthandler.hxx" 30cdf0e10cSrcweir #include "oox/drawingml/table/tablecontext.hxx" 31cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx" 32cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 33cdf0e10cSrcweir #include "oox/helper/graphichelper.hxx" 34cdf0e10cSrcweir #include "oox/helper/propertyset.hxx" 35cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx" 36cdf0e10cSrcweir #include "oox/vml/vmlshape.hxx" 37cdf0e10cSrcweir #include "oox/vml/vmlshapecontainer.hxx" 38cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx" 39cdf0e10cSrcweir #include "oox/drawingml/transform2dcontext.hxx" 40cdf0e10cSrcweir 41cdf0e10cSrcweir using ::rtl::OUString; 42cdf0e10cSrcweir using namespace ::com::sun::star; 43cdf0e10cSrcweir using namespace ::com::sun::star::io; 44cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45cdf0e10cSrcweir using namespace ::com::sun::star::lang; 46cdf0e10cSrcweir using namespace ::com::sun::star::beans; 47cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 48cdf0e10cSrcweir using namespace ::oox::core; 49cdf0e10cSrcweir 50cdf0e10cSrcweir namespace oox { 51cdf0e10cSrcweir namespace drawingml { 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ============================================================================ 54cdf0e10cSrcweir // CT_Picture 55cdf0e10cSrcweir 56cdf0e10cSrcweir GraphicShapeContext::GraphicShapeContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr ) 57cdf0e10cSrcweir : ShapeContext( rParent, pMasterShapePtr, pShapePtr ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir Reference< XFastContextHandler > GraphicShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 64cdf0e10cSrcweir 65cdf0e10cSrcweir switch( getBaseToken( aElementToken ) ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir // CT_ShapeProperties 68cdf0e10cSrcweir case XML_xfrm: 69cdf0e10cSrcweir xRet.set( new Transform2DContext( *this, xAttribs, *mpShapePtr ) ); 70cdf0e10cSrcweir break; 71cdf0e10cSrcweir case XML_blipFill: 72cdf0e10cSrcweir xRet.set( new BlipFillContext( *this, xAttribs, mpShapePtr->getGraphicProperties().maBlipProps ) ); 73cdf0e10cSrcweir break; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir if ((getNamespace( aElementToken ) == NMSP_vml) && mpShapePtr) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir mpShapePtr->setServiceName("com.sun.star.drawing.CustomShape"); 79cdf0e10cSrcweir CustomShapePropertiesPtr pCstmShpProps 80cdf0e10cSrcweir (mpShapePtr->getCustomShapeProperties()); 81cdf0e10cSrcweir 82cdf0e10cSrcweir sal_uInt32 nType = getBaseToken( aElementToken ); 83cdf0e10cSrcweir OUString sType(GetShapeType(nType)); 84cdf0e10cSrcweir 85cdf0e10cSrcweir if (sType.getLength() > 0) 86cdf0e10cSrcweir pCstmShpProps->setShapePresetType(sType); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir if( !xRet.is() ) 90cdf0e10cSrcweir xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir return xRet; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir // ============================================================================ 96cdf0e10cSrcweir // CT_GraphicalObjectFrameContext 97cdf0e10cSrcweir 98cdf0e10cSrcweir GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) : 99cdf0e10cSrcweir ShapeContext( rParent, pMasterShapePtr, pShapePtr ), 100cdf0e10cSrcweir mbEmbedShapesInChart( bEmbedShapesInChart ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir Reference< XFastContextHandler > GraphicalObjectFrameContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 107cdf0e10cSrcweir 108cdf0e10cSrcweir switch( getBaseToken( aElementToken ) ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir // CT_ShapeProperties 111cdf0e10cSrcweir case XML_nvGraphicFramePr: // CT_GraphicalObjectFrameNonVisual 112cdf0e10cSrcweir break; 113cdf0e10cSrcweir case XML_xfrm: // CT_Transform2D 114cdf0e10cSrcweir xRet.set( new Transform2DContext( *this, xAttribs, *mpShapePtr ) ); 115cdf0e10cSrcweir break; 116cdf0e10cSrcweir case XML_graphic: // CT_GraphicalObject 117cdf0e10cSrcweir xRet.set( this ); 118cdf0e10cSrcweir break; 119cdf0e10cSrcweir 120cdf0e10cSrcweir case XML_graphicData : // CT_GraphicalObjectData 121cdf0e10cSrcweir { 122cdf0e10cSrcweir OUString sUri( xAttribs->getOptionalValue( XML_uri ) ); 123cdf0e10cSrcweir if ( sUri.equalsAscii( "http://schemas.openxmlformats.org/presentationml/2006/ole" ) ) 124cdf0e10cSrcweir xRet.set( new OleObjectGraphicDataContext( *this, mpShapePtr ) ); 125cdf0e10cSrcweir else if ( sUri.equalsAscii( "http://schemas.openxmlformats.org/drawingml/2006/diagram" ) ) 126cdf0e10cSrcweir xRet.set( new DiagramGraphicDataContext( *this, mpShapePtr ) ); 127cdf0e10cSrcweir else if ( sUri.equalsAscii( "http://schemas.openxmlformats.org/drawingml/2006/chart" ) ) 128cdf0e10cSrcweir xRet.set( new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart ) ); 129cdf0e10cSrcweir else if ( sUri.compareToAscii( "http://schemas.openxmlformats.org/drawingml/2006/table" ) == 0 ) 130cdf0e10cSrcweir xRet.set( new table::TableContext( *this, mpShapePtr ) ); 131cdf0e10cSrcweir else 132cdf0e10cSrcweir { 133cdf0e10cSrcweir OSL_TRACE( "OOX: Ignore graphicsData of %s", OUSTRING_TO_CSTR( sUri ) ); 134cdf0e10cSrcweir return xRet; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir break; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir if( !xRet.is() ) 140cdf0e10cSrcweir xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) ); 141cdf0e10cSrcweir 142cdf0e10cSrcweir return xRet; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir // ============================================================================ 146cdf0e10cSrcweir 147cdf0e10cSrcweir OleObjectGraphicDataContext::OleObjectGraphicDataContext( ContextHandler& rParent, ShapePtr xShape ) : 148cdf0e10cSrcweir ShapeContext( rParent, ShapePtr(), xShape ), 149cdf0e10cSrcweir mrOleObjectInfo( xShape->setOleObjectType() ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir OleObjectGraphicDataContext::~OleObjectGraphicDataContext() 154cdf0e10cSrcweir { 155cdf0e10cSrcweir /* Register the OLE shape at the VML drawing, this prevents that the 156cdf0e10cSrcweir related VML shape converts the OLE object by itself. */ 157cdf0e10cSrcweir if( mrOleObjectInfo.maShapeId.getLength() > 0 ) 158cdf0e10cSrcweir if( ::oox::vml::Drawing* pVmlDrawing = getFilter().getVmlDrawing() ) 159cdf0e10cSrcweir pVmlDrawing->registerOleObject( mrOleObjectInfo ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir Reference< XFastContextHandler > OleObjectGraphicDataContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 165cdf0e10cSrcweir AttributeList aAttribs( xAttribs ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir switch( nElement ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir case PPT_TOKEN( oleObj ): 170cdf0e10cSrcweir { 171cdf0e10cSrcweir mrOleObjectInfo.maShapeId = aAttribs.getXString( XML_spid, OUString() ); 172cdf0e10cSrcweir const Relation* pRelation = getRelations().getRelationFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) ); 173cdf0e10cSrcweir OSL_ENSURE( pRelation, "OleObjectGraphicDataContext::createFastChildContext - missing relation for OLE object" ); 174cdf0e10cSrcweir if( pRelation ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir mrOleObjectInfo.mbLinked = pRelation->mbExternal; 177cdf0e10cSrcweir if( pRelation->mbExternal ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir mrOleObjectInfo.maTargetLink = getFilter().getAbsoluteUrl( pRelation->maTarget ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir else 182cdf0e10cSrcweir { 183cdf0e10cSrcweir OUString aFragmentPath = getFragmentPathFromRelation( *pRelation ); 184cdf0e10cSrcweir if( aFragmentPath.getLength() > 0 ) 185cdf0e10cSrcweir getFilter().importBinaryData( mrOleObjectInfo.maEmbeddedData, aFragmentPath ); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir mrOleObjectInfo.maName = aAttribs.getXString( XML_name, OUString() ); 189cdf0e10cSrcweir mrOleObjectInfo.maProgId = aAttribs.getXString( XML_progId, OUString() ); 190cdf0e10cSrcweir mrOleObjectInfo.mbShowAsIcon = aAttribs.getBool( XML_showAsIcon, false ); 191cdf0e10cSrcweir xRet.set( this ); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir break; 194cdf0e10cSrcweir 195cdf0e10cSrcweir case PPT_TOKEN( embed ): 196cdf0e10cSrcweir OSL_ENSURE( !mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" ); 197cdf0e10cSrcweir break; 198cdf0e10cSrcweir 199cdf0e10cSrcweir case PPT_TOKEN( link ): 200cdf0e10cSrcweir OSL_ENSURE( mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" ); 201cdf0e10cSrcweir mrOleObjectInfo.mbAutoUpdate = aAttribs.getBool( XML_updateAutomatic, false ); 202cdf0e10cSrcweir break; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir return xRet; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir // ============================================================================ 208cdf0e10cSrcweir 209cdf0e10cSrcweir DiagramGraphicDataContext::DiagramGraphicDataContext( ContextHandler& rParent, ShapePtr pShapePtr ) 210cdf0e10cSrcweir : ShapeContext( rParent, ShapePtr(), pShapePtr ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir pShapePtr->setDiagramType(); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir DiagramGraphicDataContext::~DiagramGraphicDataContext() 216cdf0e10cSrcweir { 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir DiagramPtr DiagramGraphicDataContext::loadDiagram() 220cdf0e10cSrcweir { 221cdf0e10cSrcweir DiagramPtr pDiagram( new Diagram() ); 222cdf0e10cSrcweir XmlFilterBase& rFilter = getFilter(); 223cdf0e10cSrcweir 224cdf0e10cSrcweir // data 225cdf0e10cSrcweir OUString sDmPath = getFragmentPathFromRelId( msDm ); 226cdf0e10cSrcweir if( sDmPath.getLength() > 0 ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir DiagramDataPtr pData( new DiagramData() ); 229cdf0e10cSrcweir pDiagram->setData( pData ); 230cdf0e10cSrcweir rFilter.importFragment( new DiagramDataFragmentHandler( rFilter, sDmPath, pData ) ); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir // layout 233cdf0e10cSrcweir OUString sLoPath = getFragmentPathFromRelId( msLo ); 234cdf0e10cSrcweir if( sLoPath.getLength() > 0 ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir DiagramLayoutPtr pLayout( new DiagramLayout() ); 237cdf0e10cSrcweir pDiagram->setLayout( pLayout ); 238cdf0e10cSrcweir rFilter.importFragment( new DiagramLayoutFragmentHandler( rFilter, sLoPath, pLayout ) ); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir // style 241cdf0e10cSrcweir OUString sQsPath = getFragmentPathFromRelId( msQs ); 242cdf0e10cSrcweir if( sQsPath.getLength() > 0 ) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir DiagramQStylesPtr pStyles( new DiagramQStyles() ); 245cdf0e10cSrcweir pDiagram->setQStyles( pStyles ); 246cdf0e10cSrcweir rFilter.importFragment( new DiagramQStylesFragmentHandler( rFilter, sQsPath, pStyles ) ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir // colors 249cdf0e10cSrcweir OUString sCsPath = getFragmentPathFromRelId( msCs ); 250cdf0e10cSrcweir if( sCsPath.getLength() > 0 ) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir DiagramColorsPtr pColors( new DiagramColors() ); 253cdf0e10cSrcweir pDiagram->setColors( pColors ); 254cdf0e10cSrcweir rFilter.importFragment( new DiagramColorsFragmentHandler( rFilter, sCsPath, pColors ) ) ; 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir return pDiagram; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir 261cdf0e10cSrcweir Reference< XFastContextHandler > DiagramGraphicDataContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) 262cdf0e10cSrcweir throw (SAXException, RuntimeException) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 265cdf0e10cSrcweir 266cdf0e10cSrcweir switch( aElementToken ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir case DGM_TOKEN( relIds ): 269cdf0e10cSrcweir { 270cdf0e10cSrcweir msDm = xAttribs->getOptionalValue( R_TOKEN( dm ) ); 271cdf0e10cSrcweir msLo = xAttribs->getOptionalValue( R_TOKEN( lo ) ); 272cdf0e10cSrcweir msQs = xAttribs->getOptionalValue( R_TOKEN( qs ) ); 273cdf0e10cSrcweir msCs = xAttribs->getOptionalValue( R_TOKEN( cs ) ); 274cdf0e10cSrcweir DiagramPtr pDiagram = loadDiagram(); 275cdf0e10cSrcweir pDiagram->addTo( mpShapePtr ); 276cdf0e10cSrcweir OSL_TRACE("diagram added shape %s of type %s", OUSTRING_TO_CSTR( mpShapePtr->getName() ), 277cdf0e10cSrcweir OUSTRING_TO_CSTR( mpShapePtr->getServiceName() ) ); 278cdf0e10cSrcweir break; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir default: 281cdf0e10cSrcweir break; 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir if( !xRet.is() ) 285cdf0e10cSrcweir xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) ); 286cdf0e10cSrcweir 287cdf0e10cSrcweir return xRet; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir // ============================================================================ 291cdf0e10cSrcweir 292cdf0e10cSrcweir ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) : 293cdf0e10cSrcweir ShapeContext( rParent, ShapePtr(), rxShape ), 294cdf0e10cSrcweir mrChartShapeInfo( rxShape->setChartType( bEmbedShapes ) ) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir Reference< XFastContextHandler > ChartGraphicDataContext::createFastChildContext( ::sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) 299cdf0e10cSrcweir throw (SAXException, RuntimeException) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir if( nElement == C_TOKEN( chart ) ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir AttributeList aAttribs( rxAttribs ); 304cdf0e10cSrcweir mrChartShapeInfo.maFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) ); 305cdf0e10cSrcweir } 306cdf0e10cSrcweir return 0; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir // ============================================================================ 310cdf0e10cSrcweir 311cdf0e10cSrcweir } // namespace drawingml 312cdf0e10cSrcweir } // namespace oox 313cdf0e10cSrcweir 314