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 <com/sun/star/xml/sax/FastToken.hpp> 29*cdf0e10cSrcweir #include <com/sun/star/drawing/LineStyle.hpp> 30*cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 35*cdf0e10cSrcweir #include "oox/ppt/pptshape.hxx" 36*cdf0e10cSrcweir #include "oox/ppt/pptshapecontext.hxx" 37*cdf0e10cSrcweir #include "oox/ppt/pptshapepropertiescontext.hxx" 38*cdf0e10cSrcweir #include "oox/ppt/slidepersist.hxx" 39*cdf0e10cSrcweir #include "oox/drawingml/shapestylecontext.hxx" 40*cdf0e10cSrcweir #include "oox/drawingml/fillpropertiesgroupcontext.hxx" 41*cdf0e10cSrcweir #include "oox/drawingml/lineproperties.hxx" 42*cdf0e10cSrcweir #include "oox/drawingml/drawingmltypes.hxx" 43*cdf0e10cSrcweir #include "oox/drawingml/customshapegeometry.hxx" 44*cdf0e10cSrcweir #include "oox/drawingml/textbodycontext.hxx" 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using rtl::OUString; 47*cdf0e10cSrcweir using namespace oox::core; 48*cdf0e10cSrcweir using namespace ::com::sun::star; 49*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 50*cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 51*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 52*cdf0e10cSrcweir using namespace ::com::sun::star::text; 53*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir namespace oox { namespace ppt { 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // CT_Shape 58*cdf0e10cSrcweir PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr ) 59*cdf0e10cSrcweir : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr ) 60*cdf0e10cSrcweir , mpSlidePersistPtr( pSlidePersistPtr ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir oox::drawingml::ShapePtr aShapePtr; 67*cdf0e10cSrcweir std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); 68*cdf0e10cSrcweir while( aRevIter != rShapes.rend() ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir if ( (*aRevIter)->getSubType() == nMasterPlaceholder ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir if ( ( nSubTypeIndex == -1 ) || ( nSubTypeIndex == (*aRevIter)->getSubTypeIndex() ) ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir aShapePtr = *aRevIter; 75*cdf0e10cSrcweir break; 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren(); 79*cdf0e10cSrcweir aShapePtr = findPlaceholder( nMasterPlaceholder, nSubTypeIndex, rChildren ); 80*cdf0e10cSrcweir if ( aShapePtr.get() ) 81*cdf0e10cSrcweir break; 82*cdf0e10cSrcweir aRevIter++; 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir return aShapePtr; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder 88*cdf0e10cSrcweir oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, 89*cdf0e10cSrcweir sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, nSubTypeIndex, rShapes ); 92*cdf0e10cSrcweir return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, nSubTypeIndex, rShapes ); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir Reference< XFastContextHandler > xRet; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir switch( aElementToken ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir // nvSpPr CT_ShapeNonVisual begin 102*cdf0e10cSrcweir // case PPT_TOKEN( drElemPr ): 103*cdf0e10cSrcweir // break; 104*cdf0e10cSrcweir case PPT_TOKEN( cNvPr ): 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir AttributeList aAttribs( xAttribs ); 107*cdf0e10cSrcweir mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) ); 108*cdf0e10cSrcweir mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) ); 109*cdf0e10cSrcweir mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) ); 110*cdf0e10cSrcweir break; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir case PPT_TOKEN( ph ): 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) ); 115*cdf0e10cSrcweir mpShapePtr->setSubType( nSubType ); 116*cdf0e10cSrcweir mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() ); 117*cdf0e10cSrcweir if ( nSubType ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() ); 120*cdf0e10cSrcweir if ( pPPTShapePtr ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation(); 123*cdf0e10cSrcweir if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir // inheriting properties from placeholder objects by cloning shape 126*cdf0e10cSrcweir sal_Int32 nFirstPlaceholder = 0; 127*cdf0e10cSrcweir sal_Int32 nSecondPlaceholder = 0; 128*cdf0e10cSrcweir switch( nSubType ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir case XML_ctrTitle : // slide/layout 131*cdf0e10cSrcweir nFirstPlaceholder = XML_ctrTitle; 132*cdf0e10cSrcweir nSecondPlaceholder = XML_title; 133*cdf0e10cSrcweir break; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir case XML_subTitle : // slide/layout 136*cdf0e10cSrcweir nFirstPlaceholder = XML_subTitle; 137*cdf0e10cSrcweir nSecondPlaceholder = XML_title; 138*cdf0e10cSrcweir break; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir case XML_obj : // slide/layout 141*cdf0e10cSrcweir nFirstPlaceholder = XML_obj; 142*cdf0e10cSrcweir nSecondPlaceholder = XML_body; 143*cdf0e10cSrcweir break; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster 146*cdf0e10cSrcweir case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster 147*cdf0e10cSrcweir case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster 148*cdf0e10cSrcweir case XML_hdr : // notes/notesmaster/handoutmaster 149*cdf0e10cSrcweir case XML_body : // slide/layout/master/notes/notesmaster 150*cdf0e10cSrcweir case XML_title : // slide/layout/master/ 151*cdf0e10cSrcweir case XML_chart : // slide/layout 152*cdf0e10cSrcweir case XML_tbl : // slide/layout 153*cdf0e10cSrcweir case XML_clipArt : // slide/layout 154*cdf0e10cSrcweir case XML_dgm : // slide/layout 155*cdf0e10cSrcweir case XML_media : // slide/layout 156*cdf0e10cSrcweir case XML_sldImg : // notes/notesmaster 157*cdf0e10cSrcweir case XML_pic : // slide/layout 158*cdf0e10cSrcweir nFirstPlaceholder = nSubType; 159*cdf0e10cSrcweir default: 160*cdf0e10cSrcweir break; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir if ( nFirstPlaceholder ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir oox::drawingml::ShapePtr pPlaceholder; 165*cdf0e10cSrcweir if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree 166*cdf0e10cSrcweir pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, -1, mpSlidePersistPtr->getShapes()->getChildren() ); 167*cdf0e10cSrcweir else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() ); 170*cdf0e10cSrcweir if ( pMasterPersist.get() ) 171*cdf0e10cSrcweir pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, 172*cdf0e10cSrcweir pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir if ( pPlaceholder.get() ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir mpShapePtr->applyShapeReference( *pPlaceholder.get() ); 177*cdf0e10cSrcweir PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() ); 178*cdf0e10cSrcweir if ( pPPTShape ) 179*cdf0e10cSrcweir pPPTShape->setReferenced( sal_True ); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir break; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // nvSpPr CT_ShapeNonVisual end 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir case PPT_TOKEN( spPr ): 192*cdf0e10cSrcweir xRet = new PPTShapePropertiesContext( *this, *mpShapePtr ); 193*cdf0e10cSrcweir break; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir case PPT_TOKEN( style ): 196*cdf0e10cSrcweir xRet = new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr ); 197*cdf0e10cSrcweir break; 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir case PPT_TOKEN( txBody ): 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody ); 202*cdf0e10cSrcweir xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True ); 203*cdf0e10cSrcweir mpShapePtr->setTextBody( xTextBody ); 204*cdf0e10cSrcweir xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody ); 205*cdf0e10cSrcweir break; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir if( !xRet.is() ) 210*cdf0e10cSrcweir xRet.set( this ); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir return xRet; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir } } 217