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 "oox/ppt/pptshape.hxx" 29 #include "oox/core/xmlfilterbase.hxx" 30 #include "oox/drawingml/textbody.hxx" 31 32 #include <com/sun/star/container/XNamed.hpp> 33 #include <com/sun/star/beans/XMultiPropertySet.hpp> 34 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35 #include <com/sun/star/drawing/HomogenMatrix3.hpp> 36 #include <com/sun/star/text/XText.hpp> 37 #include <basegfx/matrix/b2dhommatrix.hxx> 38 #include "oox/ppt/slidepersist.hxx" 39 40 using rtl::OUString; 41 using namespace ::oox::core; 42 using namespace ::oox::drawingml; 43 using namespace ::com::sun::star; 44 using namespace ::com::sun::star::awt; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::beans; 47 using namespace ::com::sun::star::frame; 48 using namespace ::com::sun::star::text; 49 using namespace ::com::sun::star::drawing; 50 51 namespace oox { namespace ppt { 52 53 PPTShape::PPTShape( const oox::ppt::ShapeLocation eShapeLocation, const sal_Char* pServiceName ) 54 : Shape( pServiceName ) 55 , meShapeLocation( eShapeLocation ) 56 , mbReferenced( sal_False ) 57 { 58 } 59 60 PPTShape::~PPTShape() 61 { 62 } 63 64 void PPTShape::addShape( 65 oox::core::XmlFilterBase& rFilterBase, 66 const SlidePersist& rSlidePersist, 67 const oox::drawingml::Theme* pTheme, 68 const Reference< XShapes >& rxShapes, 69 const awt::Rectangle* pShapeRect, 70 ::oox::drawingml::ShapeIdMap* pShapeMap ) 71 { 72 // only placeholder from layout are being inserted 73 if ( mnSubType && ( meShapeLocation == Master ) ) 74 return; 75 try 76 { 77 rtl::OUString sServiceName( msServiceName ); 78 if( sServiceName.getLength() ) 79 { 80 oox::drawingml::TextListStylePtr aMasterTextListStyle; 81 Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW ); 82 sal_Bool bClearText = sal_False; 83 84 if ( sServiceName != OUString::createFromAscii( "com.sun.star.drawing.GraphicObjectShape" ) ) 85 { 86 switch( mnSubType ) 87 { 88 case XML_ctrTitle : 89 case XML_title : 90 { 91 const rtl::OUString sTitleShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.TitleTextShape" ) ); 92 sServiceName = sTitleShapeService; 93 aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getTitleTextStyle() : rSlidePersist.getTitleTextStyle(); 94 } 95 break; 96 case XML_subTitle : 97 { 98 if ( ( meShapeLocation == Master ) || ( meShapeLocation == Layout ) ) 99 sServiceName = rtl::OUString(); 100 else { 101 const rtl::OUString sTitleShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.SubtitleShape" ) ); 102 sServiceName = sTitleShapeService; 103 aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getTitleTextStyle() : rSlidePersist.getTitleTextStyle(); 104 } 105 } 106 break; 107 case XML_obj : 108 { 109 const rtl::OUString sOutlinerShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.OutlinerShape" ) ); 110 sServiceName = sOutlinerShapeService; 111 aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getBodyTextStyle() : rSlidePersist.getBodyTextStyle(); 112 } 113 break; 114 case XML_body : 115 { 116 const rtl::OUString sNotesShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.NotesShape" ) ); 117 const rtl::OUString sOutlinerShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.OutlinerShape" ) ); 118 if ( rSlidePersist.isNotesPage() ) 119 { 120 sServiceName = sNotesShapeService; 121 aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getNotesTextStyle() : rSlidePersist.getNotesTextStyle(); 122 } 123 else 124 { 125 sServiceName = sOutlinerShapeService; 126 aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getBodyTextStyle() : rSlidePersist.getBodyTextStyle(); 127 } 128 } 129 break; 130 case XML_dt : 131 { 132 const rtl::OUString sDateTimeShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.DateTimeShape" ) ); 133 sServiceName = sDateTimeShapeService; 134 bClearText = sal_True; 135 } 136 break; 137 case XML_hdr : 138 { 139 const rtl::OUString sHeaderShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.HeaderShape" ) ); 140 sServiceName = sHeaderShapeService; 141 bClearText = sal_True; 142 } 143 break; 144 case XML_ftr : 145 { 146 const rtl::OUString sFooterShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.FooterShape" ) ); 147 sServiceName = sFooterShapeService; 148 bClearText = sal_True; 149 } 150 break; 151 case XML_sldNum : 152 { 153 const rtl::OUString sSlideNumberShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.SlideNumberShape" ) ); 154 sServiceName = sSlideNumberShapeService; 155 bClearText = sal_True; 156 } 157 break; 158 case XML_sldImg : 159 { 160 const rtl::OUString sPageShapeService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PageShape" ) ); 161 sServiceName = sPageShapeService; 162 } 163 break; 164 165 default: 166 break; 167 } 168 } 169 170 /* 171 // use placeholder index if possible 172 if( mnSubType && getSubTypeIndex() && rSlidePersist.getMasterPersist().get() ) { 173 oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex(), rSlidePersist.getMasterPersist()->getShapes()->getChildren() ); 174 if( pPlaceholder.get() && pPlaceholder->getTextBody() ) { 175 TextListStylePtr pNewTextListStyle ( new TextListStyle() ); 176 177 pNewTextListStyle->apply( pPlaceholder->getTextBody()->getTextListStyle() ); 178 if( pPlaceholder->getMasterTextListStyle().get() ) 179 pNewTextListStyle->apply( *pPlaceholder->getMasterTextListStyle() ); 180 181 aMasterTextListStyle = pNewTextListStyle; 182 } 183 } 184 */ 185 if ( sServiceName.getLength() ) 186 { 187 if ( !aMasterTextListStyle.get() ) 188 aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getOtherTextStyle() : rSlidePersist.getOtherTextStyle(); 189 setMasterTextListStyle( aMasterTextListStyle ); 190 191 Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, pShapeRect, bClearText ) ); 192 if ( !rSlidePersist.isMasterPage() && rSlidePersist.getPage().is() && ( (sal_Int32)mnSubType == XML_title ) ) 193 { 194 try 195 { 196 rtl::OUString aTitleText; 197 Reference< XTextRange > xText( xShape, UNO_QUERY_THROW ); 198 aTitleText = xText->getString(); 199 if ( aTitleText.getLength() && ( aTitleText.getLength() < 64 ) ) // just a magic value, but we don't want to set slide names which are too long 200 { 201 Reference< container::XNamed > xName( rSlidePersist.getPage(), UNO_QUERY_THROW ); 202 xName->setName( aTitleText ); 203 } 204 } 205 catch( uno::Exception& ) 206 { 207 208 } 209 } 210 if( pShapeMap && msId.getLength() ) 211 { 212 (*pShapeMap)[ msId ] = shared_from_this(); 213 } 214 215 // if this is a group shape, we have to add also each child shape 216 Reference< XShapes > xShapes( xShape, UNO_QUERY ); 217 if ( xShapes.is() ) 218 addChildren( rFilterBase, *this, pTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap ); 219 } 220 } 221 } 222 catch( const Exception& ) 223 { 224 } 225 } 226 227 void PPTShape::applyShapeReference( const oox::drawingml::Shape& rReferencedShape ) 228 { 229 Shape::applyShapeReference( rReferencedShape ); 230 } 231 232 oox::drawingml::ShapePtr PPTShape::findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes ) 233 { 234 oox::drawingml::ShapePtr aShapePtr; 235 std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); 236 while( aRevIter != rShapes.rend() ) 237 { 238 if ( (*aRevIter)->getSubType() == nMasterPlaceholder ) 239 { 240 aShapePtr = *aRevIter; 241 break; 242 } 243 std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren(); 244 aShapePtr = findPlaceholder( nMasterPlaceholder, rChildren ); 245 if ( aShapePtr.get() ) 246 break; 247 aRevIter++; 248 } 249 return aShapePtr; 250 } 251 252 oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes ) 253 { 254 oox::drawingml::ShapePtr aShapePtr; 255 std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); 256 while( aRevIter != rShapes.rend() ) 257 { 258 if ( (*aRevIter)->getSubTypeIndex() == nIdx ) 259 { 260 aShapePtr = *aRevIter; 261 break; 262 } 263 std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren(); 264 aShapePtr = findPlaceholderByIndex( nIdx, rChildren ); 265 if ( aShapePtr.get() ) 266 break; 267 aRevIter++; 268 } 269 return aShapePtr; 270 } 271 272 // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder 273 oox::drawingml::ShapePtr PPTShape::findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes ) 274 { 275 oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, rShapes ); 276 return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, rShapes ); 277 } 278 279 } } 280