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