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