xref: /AOO41X/main/oox/source/ppt/slidepersist.cxx (revision b862c97c327d912ac6f569bb343850715f80ed9c)
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
10cdf0e10cSrcweir  *
11ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
20ca5ec200SAndrew Rist  *************************************************************/
21ca5ec200SAndrew Rist 
22ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/ppt/timenode.hxx"
25cdf0e10cSrcweir #include "oox/ppt/pptshape.hxx"
26cdf0e10cSrcweir #include "oox/ppt/slidepersist.hxx"
27cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx"
28cdf0e10cSrcweir #include "oox/drawingml/shapepropertymap.hxx"
29cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
30cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx"
31cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
34cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
35cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
37cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir using namespace ::oox::core;
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
43cdf0e10cSrcweir using namespace ::com::sun::star::container;
44cdf0e10cSrcweir using namespace ::com::sun::star::animations;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace oox { namespace ppt {
47cdf0e10cSrcweir 
SlidePersist(XmlFilterBase & rFilter,sal_Bool bMaster,sal_Bool bNotes,const::com::sun::star::uno::Reference<::com::sun::star::drawing::XDrawPage> & rxPage,oox::drawingml::ShapePtr pShapesPtr,const drawingml::TextListStylePtr & pDefaultTextStyle)48cdf0e10cSrcweir SlidePersist::SlidePersist( XmlFilterBase& rFilter, sal_Bool bMaster, sal_Bool bNotes,
49cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxPage,
50cdf0e10cSrcweir 		oox::drawingml::ShapePtr pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
51cdf0e10cSrcweir : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
52cdf0e10cSrcweir , mxPage( rxPage )
53cdf0e10cSrcweir , maShapesPtr( pShapesPtr )
54cdf0e10cSrcweir , mnLayoutValueToken( 0 )
55cdf0e10cSrcweir , mbMaster( bMaster )
56cdf0e10cSrcweir , mbNotes ( bNotes )
57cdf0e10cSrcweir , maDefaultTextStylePtr( pDefaultTextStyle )
58cdf0e10cSrcweir , maTitleTextStylePtr( new oox::drawingml::TextListStyle )
59cdf0e10cSrcweir , maBodyTextStylePtr( new oox::drawingml::TextListStyle )
60cdf0e10cSrcweir , maNotesTextStylePtr( new oox::drawingml::TextListStyle )
61cdf0e10cSrcweir , maOtherTextStylePtr( new oox::drawingml::TextListStyle )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	if ( pDefaultTextStyle )
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 	/*
66cdf0e10cSrcweir 		maTitleTextStylePtr->apply( *pDefaultTextStyle.get() );
67cdf0e10cSrcweir 		maBodyTextStylePtr->apply( *pDefaultTextStyle.get() );
68cdf0e10cSrcweir 		maNotesTextStylePtr->apply( *pDefaultTextStyle.get() );
69cdf0e10cSrcweir 	*/
70cdf0e10cSrcweir 		maOtherTextStylePtr->apply( *pDefaultTextStyle.get() );
71cdf0e10cSrcweir 	}
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
~SlidePersist()74cdf0e10cSrcweir SlidePersist::~SlidePersist()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
getLayoutFromValueToken()79cdf0e10cSrcweir sal_Int16 SlidePersist::getLayoutFromValueToken()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	sal_Int16 nLayout = 20;		// 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
82cdf0e10cSrcweir 	switch( mnLayoutValueToken )
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		case XML_blank:				nLayout = 20; break;
85cdf0e10cSrcweir 		case XML_chart:				nLayout =  2; break;
86cdf0e10cSrcweir 		case XML_chartAndTx:		nLayout =  7; break;
87cdf0e10cSrcweir 		case XML_clipArtAndTx:		nLayout =  9; break;
88cdf0e10cSrcweir 		case XML_clipArtAndVertTx:	nLayout = 24; break;
89cdf0e10cSrcweir 		case XML_fourObj:			nLayout = 18; break;
90cdf0e10cSrcweir 		case XML_obj:				nLayout = 11; break;
91cdf0e10cSrcweir 		case XML_objAndTx:			nLayout = 13; break;
92cdf0e10cSrcweir 		case XML_objOverTx:			nLayout = 14; break;
93cdf0e10cSrcweir 		case XML_tbl:				nLayout =  8; break;
94cdf0e10cSrcweir 		case XML_title:				nLayout =  0; break;
95cdf0e10cSrcweir 		case XML_titleOnly:			nLayout = 19; break;
96cdf0e10cSrcweir 		case XML_twoObj:
97cdf0e10cSrcweir 		case XML_twoColTx:			nLayout =  3; break;
98cdf0e10cSrcweir 		case XML_twoObjAndTx:		nLayout = 15; break;
99cdf0e10cSrcweir 		case XML_twoObjOverTx:		nLayout = 16; break;
100cdf0e10cSrcweir 		case XML_tx:				nLayout =  1; break;
101cdf0e10cSrcweir 		case XML_txAndChart:		nLayout =  4; break;
102cdf0e10cSrcweir 		case XML_txAndClipArt:		nLayout =  6; break;
103cdf0e10cSrcweir 		case XML_txAndMedia:		nLayout =  6; break;
104cdf0e10cSrcweir 		case XML_txAndObj:			nLayout = 10; break;
105cdf0e10cSrcweir 		case XML_txAndTwoObj:		nLayout = 12; break;
106cdf0e10cSrcweir 		case XML_txOverObj:			nLayout = 17; break;
107cdf0e10cSrcweir 		case XML_vertTitleAndTx:	nLayout = 22; break;
108cdf0e10cSrcweir 		case XML_vertTitleAndTxOverChart: nLayout = 21; break;
109cdf0e10cSrcweir 		case XML_vertTx:			nLayout = 23; break;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		case XML_twoTxTwoObj:
112cdf0e10cSrcweir 		case XML_twoObjAndObj:
113cdf0e10cSrcweir 		case XML_objTx:
114cdf0e10cSrcweir 		case XML_picTx:
115cdf0e10cSrcweir 		case XML_secHead:
116cdf0e10cSrcweir 		case XML_objOnly:
117cdf0e10cSrcweir 		case XML_objAndTwoObj:
118cdf0e10cSrcweir 		case XML_mediaAndTx:
119cdf0e10cSrcweir 		case XML_dgm:
120cdf0e10cSrcweir 		case XML_cust:
121cdf0e10cSrcweir 		default:
122cdf0e10cSrcweir 			nLayout = 20;
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 	return nLayout;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
createXShapes(XmlFilterBase & rFilterBase)127cdf0e10cSrcweir void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     applyTextStyles( rFilterBase );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	Reference< XShapes > xShapes( getPage(), UNO_QUERY );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
134cdf0e10cSrcweir 	std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
135cdf0e10cSrcweir 	while( aShapesIter != rShapes.end() )
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir         std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
138cdf0e10cSrcweir         std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
139cdf0e10cSrcweir         while( aChildIter != rChildren.end() )
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() );
142cdf0e10cSrcweir 			if ( pPPTShape )
143cdf0e10cSrcweir 				pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, 0, &getShapeMap() );
144cdf0e10cSrcweir 			else
145cdf0e10cSrcweir 				(*aChildIter)->addShape( rFilterBase, getTheme().get(), xShapes, 0, &getShapeMap() );
146cdf0e10cSrcweir 			aChildIter++;
147cdf0e10cSrcweir 		}
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
151cdf0e10cSrcweir 	if( xNodeSupplier.is() )
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
154cdf0e10cSrcweir 		if( xNode.is() && !maTimeNodeList.empty() )
155cdf0e10cSrcweir 		{
156cdf0e10cSrcweir 			SlidePersistPtr pSlidePtr( shared_from_this() );
157cdf0e10cSrcweir 			TimeNodePtr pNode(maTimeNodeList.front());
158cdf0e10cSrcweir 			OSL_ENSURE( pNode, "pNode" );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir             pNode->setNode( rFilterBase, xNode, pSlidePtr );
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
createBackground(const XmlFilterBase & rFilterBase)165cdf0e10cSrcweir void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir 	if ( mpBackgroundPropertiesPtr )
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir 		sal_Int32 nPhClr = maBackgroundColor.isUsed() ?
170cdf0e10cSrcweir             maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         ::oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
173cdf0e10cSrcweir         mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
174cdf0e10cSrcweir 		PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
setTextStyle(Reference<beans::XPropertySet> & rxPropSet,const XmlFilterBase & rFilter,oox::drawingml::TextListStylePtr & pTextListStylePtr,int nLevel)178cdf0e10cSrcweir void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter,
179cdf0e10cSrcweir 	oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
182*b862c97cSHerbert Dürr 	if( !bool(pTextParagraphPropertiesPtr) )
183cdf0e10cSrcweir 	{
184cdf0e10cSrcweir 		// no properties. return
185cdf0e10cSrcweir 		return;
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     PropertySet aPropSet( rxPropSet );
191cdf0e10cSrcweir     aPropSet.setProperties( rTextParagraphPropertyMap );
192cdf0e10cSrcweir     pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
applyTextStyles(const XmlFilterBase & rFilterBase)195cdf0e10cSrcweir void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	if ( mbMaster )
198cdf0e10cSrcweir 	{
199cdf0e10cSrcweir 		try
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir             Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
202cdf0e10cSrcweir 			Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
203cdf0e10cSrcweir 			Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 			if ( aXNameAccess.is() && aXNamed.is() )
206cdf0e10cSrcweir 			{
207cdf0e10cSrcweir 				oox::drawingml::TextListStylePtr pTextListStylePtr;
208cdf0e10cSrcweir 				rtl::OUString aStyle;
209cdf0e10cSrcweir 				rtl::OUString aFamily;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 				const rtl::OUString sOutline( RTL_CONSTASCII_USTRINGPARAM( "outline1" ) );
212cdf0e10cSrcweir 				const rtl::OUString sTitle( RTL_CONSTASCII_USTRINGPARAM( "title" ) );
213cdf0e10cSrcweir 				const rtl::OUString sStandard( RTL_CONSTASCII_USTRINGPARAM( "standard" ) );
214cdf0e10cSrcweir 				const rtl::OUString sSubtitle( RTL_CONSTASCII_USTRINGPARAM( "subtitle" ) );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 				for( int i = 0; i < 4; i++ )	// todo: aggregation of bodystyle (subtitle)
217cdf0e10cSrcweir 				{
218cdf0e10cSrcweir 					switch( i )
219cdf0e10cSrcweir 					{
220cdf0e10cSrcweir 						case 0 :	// title style
221cdf0e10cSrcweir 						{
222cdf0e10cSrcweir 							pTextListStylePtr = maTitleTextStylePtr;
223cdf0e10cSrcweir 							aStyle = sTitle;
224cdf0e10cSrcweir 							aFamily= aXNamed->getName();
225cdf0e10cSrcweir 							break;
226cdf0e10cSrcweir 						}
227cdf0e10cSrcweir 						case 1 :	// body style
228cdf0e10cSrcweir 						{
229cdf0e10cSrcweir 							pTextListStylePtr = maBodyTextStylePtr;
230cdf0e10cSrcweir 							aStyle = sOutline;
231cdf0e10cSrcweir 							aFamily= aXNamed->getName();
232cdf0e10cSrcweir 							break;
233cdf0e10cSrcweir 						}
234cdf0e10cSrcweir 						case 3 :	// notes style
235cdf0e10cSrcweir 						{
236cdf0e10cSrcweir 							pTextListStylePtr = maNotesTextStylePtr;
237cdf0e10cSrcweir 							aStyle = sTitle;
238cdf0e10cSrcweir 							aFamily= aXNamed->getName();
239cdf0e10cSrcweir 							break;
240cdf0e10cSrcweir 						}
241cdf0e10cSrcweir 						case 4 :	// standard style
242cdf0e10cSrcweir 						{
243cdf0e10cSrcweir 							pTextListStylePtr = maOtherTextStylePtr;
244cdf0e10cSrcweir 							aStyle = sStandard;
245cdf0e10cSrcweir 							aFamily = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) );
246cdf0e10cSrcweir 							break;
247cdf0e10cSrcweir 						}
248cdf0e10cSrcweir 						case 5 :	// subtitle
249cdf0e10cSrcweir 						{
250cdf0e10cSrcweir 							pTextListStylePtr = maBodyTextStylePtr;
251cdf0e10cSrcweir 							aStyle = sSubtitle;
252cdf0e10cSrcweir 							aFamily = aXNamed->getName();
253cdf0e10cSrcweir 							break;
254cdf0e10cSrcweir 						}
255cdf0e10cSrcweir 					}
256cdf0e10cSrcweir 					Reference< container::XNameAccess > xFamilies;
257cdf0e10cSrcweir 					if ( aXNameAccess->hasByName( aFamily ) )
258cdf0e10cSrcweir 					{
259cdf0e10cSrcweir 						if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
260cdf0e10cSrcweir 						{
261cdf0e10cSrcweir 							if ( xFamilies->hasByName( aStyle ) )
262cdf0e10cSrcweir 							{
263cdf0e10cSrcweir 								Reference< style::XStyle > aXStyle;
264cdf0e10cSrcweir 								if ( xFamilies->getByName( aStyle ) >>= aXStyle )
265cdf0e10cSrcweir 								{
266cdf0e10cSrcweir 									Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
267cdf0e10cSrcweir                                     setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
268cdf0e10cSrcweir                                     setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
269cdf0e10cSrcweir 									if ( i == 1 /* BodyStyle */ )
270cdf0e10cSrcweir 									{
271cdf0e10cSrcweir 										for ( int nLevel = 1; nLevel < 5; nLevel++ )
272cdf0e10cSrcweir 										{
273cdf0e10cSrcweir 											{
274cdf0e10cSrcweir 												sal_Char pOutline[ 9 ] = "outline1";
275cdf0e10cSrcweir 												pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
276cdf0e10cSrcweir 												rtl::OUString sOutlineStyle( rtl::OUString::createFromAscii( pOutline ) );
277cdf0e10cSrcweir 												if ( xFamilies->hasByName( sOutlineStyle ) )
278cdf0e10cSrcweir 												{
279cdf0e10cSrcweir 													xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
280cdf0e10cSrcweir 													if( aXStyle.is() )
281cdf0e10cSrcweir 														xPropSet = Reference< beans::XPropertySet >( aXStyle, UNO_QUERY_THROW );
282cdf0e10cSrcweir 												}
283cdf0e10cSrcweir 											}
284cdf0e10cSrcweir                                             setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
285cdf0e10cSrcweir                                             setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
286cdf0e10cSrcweir 										}
287cdf0e10cSrcweir 									}
288cdf0e10cSrcweir 								}
289cdf0e10cSrcweir 							}
290cdf0e10cSrcweir 						}
291cdf0e10cSrcweir 					}
292cdf0e10cSrcweir 				}
293cdf0e10cSrcweir 			}
294cdf0e10cSrcweir 		}
295cdf0e10cSrcweir 		catch( Exception& )
296cdf0e10cSrcweir 		{
297cdf0e10cSrcweir 		}
298cdf0e10cSrcweir 	}
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir } }
302cdf0e10cSrcweir 
303