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/diagram/datamodelcontext.hxx" 29*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 30*cdf0e10cSrcweir #include "oox/drawingml/fillpropertiesgroupcontext.hxx" 31*cdf0e10cSrcweir #include "oox/drawingml/shapepropertiescontext.hxx" 32*cdf0e10cSrcweir #include "oox/drawingml/textbodycontext.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir using namespace ::oox::core; 35*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 36*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 37*cdf0e10cSrcweir using ::rtl::OUString; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir namespace oox { namespace drawingml { 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // CL_Cxn 42*cdf0e10cSrcweir class CxnContext 43*cdf0e10cSrcweir : public ContextHandler 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir public: 46*cdf0e10cSrcweir CxnContext( ContextHandler& rParent, 47*cdf0e10cSrcweir const Reference< XFastAttributeList >& xAttribs, 48*cdf0e10cSrcweir const dgm::ConnectionPtr & pConnection ) 49*cdf0e10cSrcweir : ContextHandler( rParent ) 50*cdf0e10cSrcweir , mpConnection( pConnection ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, XML_parOf ); 53*cdf0e10cSrcweir pConnection->mnType = nType; 54*cdf0e10cSrcweir pConnection->msModelId = xAttribs->getOptionalValue( XML_modelId ); 55*cdf0e10cSrcweir pConnection->msSourceId = xAttribs->getOptionalValue( XML_srcId ); 56*cdf0e10cSrcweir pConnection->msDestId = xAttribs->getOptionalValue( XML_destId ); 57*cdf0e10cSrcweir pConnection->msPresId = xAttribs->getOptionalValue( XML_presId ); 58*cdf0e10cSrcweir pConnection->msSibTransId = xAttribs->getOptionalValue( XML_sibTransId ); 59*cdf0e10cSrcweir AttributeList attribs( xAttribs ); 60*cdf0e10cSrcweir pConnection->mnSourceOrder = attribs.getInteger( XML_srcOrd, 0 ); 61*cdf0e10cSrcweir pConnection->mnDestOrder = attribs.getInteger( XML_destOrd, 0 ); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL 65*cdf0e10cSrcweir createFastChildContext( sal_Int32 aElementToken, 66*cdf0e10cSrcweir const Reference< XFastAttributeList >& /*xAttribs*/ ) 67*cdf0e10cSrcweir throw (SAXException, RuntimeException) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir switch( aElementToken ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir case DGM_TOKEN( extLst ): 74*cdf0e10cSrcweir return xRet; 75*cdf0e10cSrcweir default: 76*cdf0e10cSrcweir break; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir if( !xRet.is() ) 79*cdf0e10cSrcweir xRet.set( this ); 80*cdf0e10cSrcweir return xRet; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir private: 83*cdf0e10cSrcweir dgm::ConnectionPtr mpConnection; 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // CT_CxnList 88*cdf0e10cSrcweir class CxnListContext 89*cdf0e10cSrcweir : public ContextHandler 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir public: 92*cdf0e10cSrcweir CxnListContext( ContextHandler& rParent, dgm::Connections & aConnections ) 93*cdf0e10cSrcweir : ContextHandler( rParent ) 94*cdf0e10cSrcweir , maConnections( aConnections ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL 98*cdf0e10cSrcweir createFastChildContext( sal_Int32 aElementToken, 99*cdf0e10cSrcweir const Reference< XFastAttributeList >& xAttribs ) 100*cdf0e10cSrcweir throw (SAXException, RuntimeException) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir switch( aElementToken ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir case DGM_TOKEN( cxn ): 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir dgm::ConnectionPtr pConnection( new dgm::Connection() ); 109*cdf0e10cSrcweir maConnections.push_back( pConnection ); 110*cdf0e10cSrcweir xRet.set( new CxnContext( *this, xAttribs, pConnection ) ); 111*cdf0e10cSrcweir break; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir default: 114*cdf0e10cSrcweir break; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir if( !xRet.is() ) 117*cdf0e10cSrcweir xRet.set( this ); 118*cdf0e10cSrcweir return xRet; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir private: 122*cdf0e10cSrcweir dgm::Connections & maConnections; 123*cdf0e10cSrcweir }; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // CL_Pt 128*cdf0e10cSrcweir class PtContext 129*cdf0e10cSrcweir : public ContextHandler 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir public: 132*cdf0e10cSrcweir PtContext( ContextHandler& rParent, 133*cdf0e10cSrcweir const Reference< XFastAttributeList >& xAttribs, 134*cdf0e10cSrcweir const dgm::PointPtr & pPoint) 135*cdf0e10cSrcweir : ContextHandler( rParent ) 136*cdf0e10cSrcweir , mpPoint( pPoint ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir mpPoint->setModelId( xAttribs->getOptionalValue( XML_modelId ) ); 139*cdf0e10cSrcweir // 140*cdf0e10cSrcweir // the default type is XML_node 141*cdf0e10cSrcweir sal_Int32 nType = xAttribs->getOptionalValueToken( XML_type, XML_node ); 142*cdf0e10cSrcweir mpPoint->setType( nType ); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // ignore the cxnId unless it is this type. See 5.15.3.1.3 in Primer 145*cdf0e10cSrcweir if( ( nType == XML_parTrans ) || ( nType == XML_sibTrans ) ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir mpPoint->setCnxId( xAttribs->getOptionalValue( XML_cxnId ) ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL 153*cdf0e10cSrcweir createFastChildContext( sal_Int32 aElementToken, 154*cdf0e10cSrcweir const Reference< XFastAttributeList >& /*xAttribs*/ ) 155*cdf0e10cSrcweir throw (SAXException, RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir switch( aElementToken ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir case DGM_TOKEN( extLst ): 162*cdf0e10cSrcweir return xRet; 163*cdf0e10cSrcweir case DGM_TOKEN( prSet ): 164*cdf0e10cSrcweir // TODO 165*cdf0e10cSrcweir // CT_ElemPropSet 166*cdf0e10cSrcweir break; 167*cdf0e10cSrcweir case DGM_TOKEN( spPr ): 168*cdf0e10cSrcweir OSL_TRACE( "shape props for point"); 169*cdf0e10cSrcweir xRet = new ShapePropertiesContext( *this, *mpPoint->getShape() ); 170*cdf0e10cSrcweir break; 171*cdf0e10cSrcweir case DGM_TOKEN( t ): 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir OSL_TRACE( "shape text body for point"); 174*cdf0e10cSrcweir TextBodyPtr xTextBody( new TextBody ); 175*cdf0e10cSrcweir mpPoint->getShape()->setTextBody( xTextBody ); 176*cdf0e10cSrcweir xRet = new TextBodyContext( *this, *xTextBody ); 177*cdf0e10cSrcweir break; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir default: 180*cdf0e10cSrcweir break; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir if( !xRet.is() ) 183*cdf0e10cSrcweir xRet.set( this ); 184*cdf0e10cSrcweir return xRet; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir private: 188*cdf0e10cSrcweir dgm::PointPtr mpPoint; 189*cdf0e10cSrcweir }; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir // CT_PtList 194*cdf0e10cSrcweir class PtListContext 195*cdf0e10cSrcweir : public ContextHandler 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir public: 198*cdf0e10cSrcweir PtListContext( ContextHandler& rParent, dgm::Points & aPoints) 199*cdf0e10cSrcweir : ContextHandler( rParent ) 200*cdf0e10cSrcweir , maPoints( aPoints ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL 204*cdf0e10cSrcweir createFastChildContext( sal_Int32 aElementToken, 205*cdf0e10cSrcweir const Reference< XFastAttributeList >& xAttribs ) 206*cdf0e10cSrcweir throw (SAXException, RuntimeException) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir switch( aElementToken ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir case DGM_TOKEN( pt ): 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir // CT_Pt 215*cdf0e10cSrcweir dgm::PointPtr pPoint( new dgm::Point() ); 216*cdf0e10cSrcweir maPoints.push_back( pPoint ); 217*cdf0e10cSrcweir xRet.set( new PtContext( *this, xAttribs, pPoint ) ); 218*cdf0e10cSrcweir break; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir default: 221*cdf0e10cSrcweir break; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir if( !xRet.is() ) 224*cdf0e10cSrcweir xRet.set( this ); 225*cdf0e10cSrcweir return xRet; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir private: 229*cdf0e10cSrcweir dgm::Points & maPoints; 230*cdf0e10cSrcweir }; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir // CT_BackgroundFormatting 233*cdf0e10cSrcweir class BackgroundFormattingContext 234*cdf0e10cSrcweir : public ContextHandler 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir public: 237*cdf0e10cSrcweir BackgroundFormattingContext( ContextHandler& rParent, DiagramDataPtr & pModel ) 238*cdf0e10cSrcweir : ContextHandler( rParent ) 239*cdf0e10cSrcweir , mpDataModel( pModel ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir OSL_ENSURE( pModel, "the data model MUST NOT be NULL" ); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir virtual Reference< XFastContextHandler > SAL_CALL 245*cdf0e10cSrcweir createFastChildContext( sal_Int32 aElementToken, 246*cdf0e10cSrcweir const Reference< XFastAttributeList >& xAttribs ) 247*cdf0e10cSrcweir throw (SAXException, RuntimeException) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir switch( aElementToken ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir case A_TOKEN( blipFill ): 254*cdf0e10cSrcweir case A_TOKEN( gradFill ): 255*cdf0e10cSrcweir case A_TOKEN( grpFill ): 256*cdf0e10cSrcweir case A_TOKEN( noFill ): 257*cdf0e10cSrcweir case A_TOKEN( pattFill ): 258*cdf0e10cSrcweir case A_TOKEN( solidFill ): 259*cdf0e10cSrcweir // EG_FillProperties 260*cdf0e10cSrcweir xRet.set( FillPropertiesContext::createFillContext( 261*cdf0e10cSrcweir *this, aElementToken, xAttribs, *mpDataModel->getFillProperties() ) ); 262*cdf0e10cSrcweir break; 263*cdf0e10cSrcweir case A_TOKEN( effectDag ): 264*cdf0e10cSrcweir case A_TOKEN( effectLst ): 265*cdf0e10cSrcweir // TODO 266*cdf0e10cSrcweir // EG_EffectProperties 267*cdf0e10cSrcweir break; 268*cdf0e10cSrcweir default: 269*cdf0e10cSrcweir break; 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir if( !xRet.is() ) 272*cdf0e10cSrcweir xRet.set( this ); 273*cdf0e10cSrcweir return xRet; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir private: 276*cdf0e10cSrcweir DiagramDataPtr mpDataModel; 277*cdf0e10cSrcweir }; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir DataModelContext::DataModelContext( ContextHandler& rParent, 282*cdf0e10cSrcweir const DiagramDataPtr & pDataModel ) 283*cdf0e10cSrcweir : ContextHandler( rParent ) 284*cdf0e10cSrcweir , mpDataModel( pDataModel ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir OSL_ENSURE( pDataModel, "Data Model must not be NULL" ); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir DataModelContext::~DataModelContext() 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir // some debug 293*cdf0e10cSrcweir mpDataModel->dump(); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir Reference< XFastContextHandler > SAL_CALL 298*cdf0e10cSrcweir DataModelContext::createFastChildContext( ::sal_Int32 aElement, 299*cdf0e10cSrcweir const Reference< XFastAttributeList >& /*xAttribs*/ ) 300*cdf0e10cSrcweir throw ( SAXException, RuntimeException) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir switch( aElement ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir case DGM_TOKEN( cxnLst ): 307*cdf0e10cSrcweir // CT_CxnList 308*cdf0e10cSrcweir xRet.set( new CxnListContext( *this, mpDataModel->getConnections() ) ); 309*cdf0e10cSrcweir break; 310*cdf0e10cSrcweir case DGM_TOKEN( ptLst ): 311*cdf0e10cSrcweir // CT_PtList 312*cdf0e10cSrcweir xRet.set( new PtListContext( *this, mpDataModel->getPoints() ) ); 313*cdf0e10cSrcweir break; 314*cdf0e10cSrcweir case DGM_TOKEN( bg ): 315*cdf0e10cSrcweir // CT_BackgroundFormatting 316*cdf0e10cSrcweir xRet.set( new BackgroundFormattingContext( *this, mpDataModel ) ); 317*cdf0e10cSrcweir break; 318*cdf0e10cSrcweir case DGM_TOKEN( whole ): 319*cdf0e10cSrcweir // CT_WholeE2oFormatting 320*cdf0e10cSrcweir // TODO 321*cdf0e10cSrcweir return xRet; 322*cdf0e10cSrcweir case DGM_TOKEN( extLst ): 323*cdf0e10cSrcweir return xRet; 324*cdf0e10cSrcweir default: 325*cdf0e10cSrcweir break; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir if( !xRet.is() ) 329*cdf0e10cSrcweir xRet.set( this ); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir return xRet; 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir } } 335