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