xref: /aoo42x/main/oox/source/ppt/pptshapecontext.cxx (revision 4b2c1a94)
1ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ca5ec200SAndrew Rist  * distributed with this work for additional information
6ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10ca5ec200SAndrew Rist  *
11ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ca5ec200SAndrew Rist  *
13ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18ca5ec200SAndrew Rist  * under the License.
19ca5ec200SAndrew Rist  *
20ca5ec200SAndrew Rist  *************************************************************/
21ca5ec200SAndrew Rist 
22ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <com/sun/star/xml/sax/FastToken.hpp>
25cdf0e10cSrcweir #include <com/sun/star/drawing/LineStyle.hpp>
26cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
27cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
31cdf0e10cSrcweir #include "oox/ppt/pptshape.hxx"
32cdf0e10cSrcweir #include "oox/ppt/pptshapecontext.hxx"
33cdf0e10cSrcweir #include "oox/ppt/pptshapepropertiescontext.hxx"
34cdf0e10cSrcweir #include "oox/ppt/slidepersist.hxx"
35cdf0e10cSrcweir #include "oox/drawingml/shapestylecontext.hxx"
36cdf0e10cSrcweir #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
37cdf0e10cSrcweir #include "oox/drawingml/lineproperties.hxx"
38cdf0e10cSrcweir #include "oox/drawingml/drawingmltypes.hxx"
39cdf0e10cSrcweir #include "oox/drawingml/customshapegeometry.hxx"
40cdf0e10cSrcweir #include "oox/drawingml/textbodycontext.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using rtl::OUString;
43cdf0e10cSrcweir using namespace oox::core;
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
47cdf0e10cSrcweir using namespace ::com::sun::star::beans;
48cdf0e10cSrcweir using namespace ::com::sun::star::text;
49cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace oox { namespace ppt {
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // CT_Shape
PPTShapeContext(ContextHandler & rParent,const SlidePersistPtr pSlidePersistPtr,oox::drawingml::ShapePtr pMasterShapePtr,oox::drawingml::ShapePtr pShapePtr)54cdf0e10cSrcweir PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
55cdf0e10cSrcweir : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
56cdf0e10cSrcweir , mpSlidePersistPtr( pSlidePersistPtr )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
findPlaceholder(const sal_Int32 nMasterPlaceholder,sal_Int32 nSubTypeIndex,std::vector<oox::drawingml::ShapePtr> & rShapes)60cdf0e10cSrcweir oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	oox::drawingml::ShapePtr aShapePtr;
63cdf0e10cSrcweir 	std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
64cdf0e10cSrcweir 	while( aRevIter != rShapes.rend() )
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
67cdf0e10cSrcweir 		{
68cdf0e10cSrcweir 			if ( ( nSubTypeIndex == -1 ) || ( nSubTypeIndex == (*aRevIter)->getSubTypeIndex() ) )
69cdf0e10cSrcweir 			{
70cdf0e10cSrcweir 				aShapePtr = *aRevIter;
71cdf0e10cSrcweir 				break;
72cdf0e10cSrcweir 			}
73cdf0e10cSrcweir 		}
74cdf0e10cSrcweir         std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
75cdf0e10cSrcweir         aShapePtr = findPlaceholder( nMasterPlaceholder, nSubTypeIndex, rChildren );
76cdf0e10cSrcweir 		if ( aShapePtr.get() )
77cdf0e10cSrcweir 			break;
78cdf0e10cSrcweir 		aRevIter++;
79cdf0e10cSrcweir 	}
80cdf0e10cSrcweir 	return aShapePtr;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
findPlaceholder(sal_Int32 nFirstPlaceholder,sal_Int32 nSecondPlaceholder,sal_Int32 nSubTypeIndex,std::vector<oox::drawingml::ShapePtr> & rShapes)84cdf0e10cSrcweir oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
85cdf0e10cSrcweir 	sal_Int32 nSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, nSubTypeIndex, rShapes );
88cdf0e10cSrcweir 	return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, nSubTypeIndex, rShapes );
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)91cdf0e10cSrcweir Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	switch( aElementToken )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		// nvSpPr CT_ShapeNonVisual begin
98cdf0e10cSrcweir 		//	case PPT_TOKEN( drElemPr ):
99cdf0e10cSrcweir 		//		break;
100cdf0e10cSrcweir 		case PPT_TOKEN( cNvPr ):
101cdf0e10cSrcweir 		{
102cdf0e10cSrcweir 			AttributeList aAttribs( xAttribs );
103cdf0e10cSrcweir 			mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) );
104cdf0e10cSrcweir 			mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) );
105cdf0e10cSrcweir 			mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) );
106cdf0e10cSrcweir 			break;
107cdf0e10cSrcweir 		}
108cdf0e10cSrcweir 		case PPT_TOKEN( ph ):
109cdf0e10cSrcweir 		{
110cdf0e10cSrcweir 			sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) );
111cdf0e10cSrcweir 			mpShapePtr->setSubType( nSubType );
112cdf0e10cSrcweir 			mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() );
113cdf0e10cSrcweir 			if ( nSubType )
114cdf0e10cSrcweir 			{
115cdf0e10cSrcweir 				PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
116cdf0e10cSrcweir 				if ( pPPTShapePtr )
117cdf0e10cSrcweir 				{
118cdf0e10cSrcweir 					oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
119cdf0e10cSrcweir 					if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
120cdf0e10cSrcweir 					{
121cdf0e10cSrcweir 						// inheriting properties from placeholder objects by cloning shape
122cdf0e10cSrcweir 						sal_Int32 nFirstPlaceholder = 0;
123cdf0e10cSrcweir 						sal_Int32 nSecondPlaceholder = 0;
124cdf0e10cSrcweir 						switch( nSubType )
125cdf0e10cSrcweir 						{
126cdf0e10cSrcweir 							case XML_ctrTitle :		// slide/layout
127cdf0e10cSrcweir 	  							nFirstPlaceholder = XML_ctrTitle;
128cdf0e10cSrcweir   								nSecondPlaceholder = XML_title;
129cdf0e10cSrcweir   							break;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	  						case XML_subTitle :		// slide/layout
132cdf0e10cSrcweir 	  							nFirstPlaceholder = XML_subTitle;
133cdf0e10cSrcweir 	  							nSecondPlaceholder = XML_title;
134cdf0e10cSrcweir   							break;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	 						case XML_obj :			// slide/layout
137cdf0e10cSrcweir 	  							nFirstPlaceholder = XML_obj;
138cdf0e10cSrcweir 	  							nSecondPlaceholder = XML_body;
139cdf0e10cSrcweir   							break;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 							case XML_dt :			// slide/layout/master/notes/notesmaster/handoutmaster
142cdf0e10cSrcweir 	  						case XML_sldNum :		// slide/layout/master/notes/notesmaster/handoutmaster
143cdf0e10cSrcweir 	  						case XML_ftr :			// slide/layout/master/notes/notesmaster/handoutmaster
144cdf0e10cSrcweir 	  						case XML_hdr :			// notes/notesmaster/handoutmaster
145cdf0e10cSrcweir 	  						case XML_body :			// slide/layout/master/notes/notesmaster
146cdf0e10cSrcweir 	  						case XML_title :		// slide/layout/master/
147cdf0e10cSrcweir 	  						case XML_chart :		// slide/layout
148cdf0e10cSrcweir 	  						case XML_tbl :			// slide/layout
149cdf0e10cSrcweir 	  						case XML_clipArt :		// slide/layout
150cdf0e10cSrcweir 	  						case XML_dgm :			// slide/layout
151cdf0e10cSrcweir 	  						case XML_media :		// slide/layout
152cdf0e10cSrcweir 	  						case XML_sldImg :		// notes/notesmaster
153cdf0e10cSrcweir 	  						case XML_pic :			// slide/layout
154cdf0e10cSrcweir 	  							nFirstPlaceholder = nSubType;
155cdf0e10cSrcweir 	  						default:
156cdf0e10cSrcweir 	  							break;
157cdf0e10cSrcweir 						}
158cdf0e10cSrcweir   						if ( nFirstPlaceholder )
159cdf0e10cSrcweir   						{
160cdf0e10cSrcweir   							oox::drawingml::ShapePtr pPlaceholder;
161cdf0e10cSrcweir   							if ( eShapeLocation == Layout )		// for layout objects the referenced object can be found within the same shape tree
162cdf0e10cSrcweir 								pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, -1, mpSlidePersistPtr->getShapes()->getChildren() );
163cdf0e10cSrcweir   							else if ( eShapeLocation == Slide )	// normal slide shapes have to search within the corresponding master tree for referenced objects
164cdf0e10cSrcweir   							{
165cdf0e10cSrcweir   								SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
166cdf0e10cSrcweir   								if ( pMasterPersist.get() )
167*4b2c1a94SSteve Yin 								{
168*4b2c1a94SSteve Yin 									if ( mpSlidePersistPtr->isNotesPage() )
169*4b2c1a94SSteve Yin 										pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, -1, pMasterPersist->getShapes()->getChildren() );
170*4b2c1a94SSteve Yin 									else
171*4b2c1a94SSteve Yin 										pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
172*4b2c1a94SSteve Yin 										pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
173*4b2c1a94SSteve Yin 								}
174cdf0e10cSrcweir   							}
175cdf0e10cSrcweir   							if ( pPlaceholder.get() )
176cdf0e10cSrcweir   							{
177cdf0e10cSrcweir   								mpShapePtr->applyShapeReference( *pPlaceholder.get() );
178cdf0e10cSrcweir   								PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
179cdf0e10cSrcweir   								if ( pPPTShape )
180cdf0e10cSrcweir   									pPPTShape->setReferenced( sal_True );
181cdf0e10cSrcweir   							}
182cdf0e10cSrcweir   						}
183cdf0e10cSrcweir 					}
184cdf0e10cSrcweir   				}
185cdf0e10cSrcweir 
186cdf0e10cSrcweir   			}
187cdf0e10cSrcweir 	  		break;
188cdf0e10cSrcweir 		}
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 		// nvSpPr CT_ShapeNonVisual end
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 		case PPT_TOKEN( spPr ):
193cdf0e10cSrcweir 			xRet = new PPTShapePropertiesContext( *this, *mpShapePtr );
194cdf0e10cSrcweir 			break;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 		case PPT_TOKEN( style ):
197cdf0e10cSrcweir 			xRet = new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
198cdf0e10cSrcweir 			break;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 		case PPT_TOKEN( txBody ):
201cdf0e10cSrcweir 		{
202cdf0e10cSrcweir 			oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
203cdf0e10cSrcweir 			xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True );
204cdf0e10cSrcweir 			mpShapePtr->setTextBody( xTextBody );
205cdf0e10cSrcweir 			xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
206cdf0e10cSrcweir 			break;
207cdf0e10cSrcweir 		}
208cdf0e10cSrcweir 	}
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	if( !xRet.is() )
211cdf0e10cSrcweir 		xRet.set( this );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	return xRet;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
217cdf0e10cSrcweir } }
218