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