1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <com/sun/star/xml/sax/FastToken.hpp> 29 #include <com/sun/star/drawing/LineStyle.hpp> 30 #include <com/sun/star/beans/XMultiPropertySet.hpp> 31 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32 #include <com/sun/star/container/XNamed.hpp> 33 34 #include "oox/helper/attributelist.hxx" 35 #include "oox/ppt/pptshape.hxx" 36 #include "oox/ppt/pptshapecontext.hxx" 37 #include "oox/ppt/pptshapepropertiescontext.hxx" 38 #include "oox/ppt/slidepersist.hxx" 39 #include "oox/drawingml/shapestylecontext.hxx" 40 #include "oox/drawingml/fillpropertiesgroupcontext.hxx" 41 #include "oox/drawingml/lineproperties.hxx" 42 #include "oox/drawingml/drawingmltypes.hxx" 43 #include "oox/drawingml/customshapegeometry.hxx" 44 #include "oox/drawingml/textbodycontext.hxx" 45 46 using rtl::OUString; 47 using namespace oox::core; 48 using namespace ::com::sun::star; 49 using namespace ::com::sun::star::uno; 50 using namespace ::com::sun::star::drawing; 51 using namespace ::com::sun::star::beans; 52 using namespace ::com::sun::star::text; 53 using namespace ::com::sun::star::xml::sax; 54 55 namespace oox { namespace ppt { 56 57 // CT_Shape 58 PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr ) 59 : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr ) 60 , mpSlidePersistPtr( pSlidePersistPtr ) 61 { 62 } 63 64 oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes ) 65 { 66 oox::drawingml::ShapePtr aShapePtr; 67 std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); 68 while( aRevIter != rShapes.rend() ) 69 { 70 if ( (*aRevIter)->getSubType() == nMasterPlaceholder ) 71 { 72 if ( ( nSubTypeIndex == -1 ) || ( nSubTypeIndex == (*aRevIter)->getSubTypeIndex() ) ) 73 { 74 aShapePtr = *aRevIter; 75 break; 76 } 77 } 78 std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren(); 79 aShapePtr = findPlaceholder( nMasterPlaceholder, nSubTypeIndex, rChildren ); 80 if ( aShapePtr.get() ) 81 break; 82 aRevIter++; 83 } 84 return aShapePtr; 85 } 86 87 // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder 88 oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, 89 sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes ) 90 { 91 oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, nSubTypeIndex, rShapes ); 92 return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, nSubTypeIndex, rShapes ); 93 } 94 95 Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) 96 { 97 Reference< XFastContextHandler > xRet; 98 99 switch( aElementToken ) 100 { 101 // nvSpPr CT_ShapeNonVisual begin 102 // case PPT_TOKEN( drElemPr ): 103 // break; 104 case PPT_TOKEN( cNvPr ): 105 { 106 AttributeList aAttribs( xAttribs ); 107 mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) ); 108 mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) ); 109 mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) ); 110 break; 111 } 112 case PPT_TOKEN( ph ): 113 { 114 sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) ); 115 mpShapePtr->setSubType( nSubType ); 116 mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() ); 117 if ( nSubType ) 118 { 119 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() ); 120 if ( pPPTShapePtr ) 121 { 122 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation(); 123 if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) 124 { 125 // inheriting properties from placeholder objects by cloning shape 126 sal_Int32 nFirstPlaceholder = 0; 127 sal_Int32 nSecondPlaceholder = 0; 128 switch( nSubType ) 129 { 130 case XML_ctrTitle : // slide/layout 131 nFirstPlaceholder = XML_ctrTitle; 132 nSecondPlaceholder = XML_title; 133 break; 134 135 case XML_subTitle : // slide/layout 136 nFirstPlaceholder = XML_subTitle; 137 nSecondPlaceholder = XML_title; 138 break; 139 140 case XML_obj : // slide/layout 141 nFirstPlaceholder = XML_obj; 142 nSecondPlaceholder = XML_body; 143 break; 144 145 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster 146 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster 147 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster 148 case XML_hdr : // notes/notesmaster/handoutmaster 149 case XML_body : // slide/layout/master/notes/notesmaster 150 case XML_title : // slide/layout/master/ 151 case XML_chart : // slide/layout 152 case XML_tbl : // slide/layout 153 case XML_clipArt : // slide/layout 154 case XML_dgm : // slide/layout 155 case XML_media : // slide/layout 156 case XML_sldImg : // notes/notesmaster 157 case XML_pic : // slide/layout 158 nFirstPlaceholder = nSubType; 159 default: 160 break; 161 } 162 if ( nFirstPlaceholder ) 163 { 164 oox::drawingml::ShapePtr pPlaceholder; 165 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree 166 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, -1, mpSlidePersistPtr->getShapes()->getChildren() ); 167 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects 168 { 169 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() ); 170 if ( pMasterPersist.get() ) 171 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, 172 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() ); 173 } 174 if ( pPlaceholder.get() ) 175 { 176 mpShapePtr->applyShapeReference( *pPlaceholder.get() ); 177 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() ); 178 if ( pPPTShape ) 179 pPPTShape->setReferenced( sal_True ); 180 } 181 } 182 } 183 } 184 185 } 186 break; 187 } 188 189 // nvSpPr CT_ShapeNonVisual end 190 191 case PPT_TOKEN( spPr ): 192 xRet = new PPTShapePropertiesContext( *this, *mpShapePtr ); 193 break; 194 195 case PPT_TOKEN( style ): 196 xRet = new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr ); 197 break; 198 199 case PPT_TOKEN( txBody ): 200 { 201 oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody ); 202 xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True ); 203 mpShapePtr->setTextBody( xTextBody ); 204 xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody ); 205 break; 206 } 207 } 208 209 if( !xRet.is() ) 210 xRet.set( this ); 211 212 return xRet; 213 } 214 215 216 } } 217