bump product version to 5.0.4.1
[LibreOffice.git] / oox / source / ppt / slidepersist.cxx
blob82d0f9fe69ca3d6f351c07863be3880bd50bb680
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "oox/ppt/timenode.hxx"
21 #include "oox/ppt/pptshape.hxx"
22 #include "oox/ppt/slidepersist.hxx"
23 #include "oox/drawingml/fillproperties.hxx"
24 #include "oox/drawingml/shapepropertymap.hxx"
25 #include "oox/helper/propertymap.hxx"
26 #include "oox/helper/propertyset.hxx"
27 #include "oox/vml/vmldrawing.hxx"
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "drawingml/textliststyle.hxx"
30 #include "drawingml/textparagraphproperties.hxx"
32 #include <osl/diagnose.h>
34 #include <com/sun/star/style/XStyle.hpp>
35 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 #include <com/sun/star/container/XNamed.hpp>
37 #include <com/sun/star/beans/XMultiPropertySet.hpp>
38 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
40 using namespace ::com::sun::star;
41 using namespace ::oox::core;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::drawing;
44 using namespace ::com::sun::star::container;
45 using namespace ::com::sun::star::animations;
47 namespace oox { namespace ppt {
49 SlidePersist::SlidePersist( XmlFilterBase& rFilter, bool bMaster, bool bNotes,
50 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxPage,
51 oox::drawingml::ShapePtr pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
52 : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
53 , mxPage( rxPage )
54 , maShapesPtr( pShapesPtr )
55 , mnLayoutValueToken( 0 )
56 , mbMaster( bMaster )
57 , mbNotes ( bNotes )
58 , maDefaultTextStylePtr( pDefaultTextStyle )
59 , maTitleTextStylePtr( new oox::drawingml::TextListStyle )
60 , maBodyTextStylePtr( new oox::drawingml::TextListStyle )
61 , maNotesTextStylePtr( new oox::drawingml::TextListStyle )
62 , maOtherTextStylePtr( new oox::drawingml::TextListStyle )
64 #if OSL_DEBUG_LEVEL > 0
65 mxDebugPage = mxPage;
66 #endif
69 #if OSL_DEBUG_LEVEL > 0
70 ::com::sun::star::uno::WeakReference< ::com::sun::star::drawing::XDrawPage > SlidePersist::mxDebugPage;
71 #endif
73 SlidePersist::~SlidePersist()
77 sal_Int16 SlidePersist::getLayoutFromValueToken()
79 sal_Int16 nLayout = 20; // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
80 switch( mnLayoutValueToken )
82 case XML_blank: nLayout = 20; break;
83 case XML_chart: nLayout = 2; break;
84 case XML_chartAndTx: nLayout = 7; break;
85 case XML_clipArtAndTx: nLayout = 9; break;
86 case XML_clipArtAndVertTx: nLayout = 24; break;
87 case XML_fourObj: nLayout = 18; break;
88 case XML_obj: nLayout = 11; break;
89 case XML_objAndTx: nLayout = 13; break;
90 case XML_objOverTx: nLayout = 14; break;
91 case XML_tbl: nLayout = 8; break;
92 case XML_title: nLayout = 0; break;
93 case XML_titleOnly: nLayout = 19; break;
94 case XML_twoObj:
95 case XML_twoColTx: nLayout = 3; break;
96 case XML_twoObjAndTx: nLayout = 15; break;
97 case XML_twoObjOverTx: nLayout = 16; break;
98 case XML_tx: nLayout = 1; break;
99 case XML_txAndChart: nLayout = 4; break;
100 case XML_txAndClipArt: nLayout = 6; break;
101 case XML_txAndMedia: nLayout = 6; break;
102 case XML_txAndObj: nLayout = 10; break;
103 case XML_txAndTwoObj: nLayout = 12; break;
104 case XML_txOverObj: nLayout = 17; break;
105 case XML_vertTitleAndTx: nLayout = 22; break;
106 case XML_vertTitleAndTxOverChart: nLayout = 21; break;
107 case XML_vertTx: nLayout = 23; break;
109 case XML_twoTxTwoObj:
110 case XML_twoObjAndObj:
111 case XML_objTx:
112 case XML_picTx:
113 case XML_secHead:
114 case XML_objOnly:
115 case XML_objAndTwoObj:
116 case XML_mediaAndTx:
117 case XML_dgm:
118 case XML_cust:
119 default:
120 nLayout = 20;
122 return nLayout;
125 void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
127 applyTextStyles( rFilterBase );
129 Reference< XShapes > xShapes( getPage(), UNO_QUERY );
131 std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
132 const std::vector< oox::drawingml::ShapePtr >::const_iterator aShapesEnd( rShapes.end() );
133 for (std::vector< oox::drawingml::ShapePtr >::const_iterator aShapesIter( rShapes.begin() );
134 aShapesIter != aShapesEnd ; ++aShapesIter)
136 std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter)->getChildren() );
137 const std::vector< oox::drawingml::ShapePtr >::const_iterator aChildEnd( rChildren.end() );
138 for (std::vector< oox::drawingml::ShapePtr >::const_iterator aChildIter( rChildren.begin() );
139 aChildIter != aChildEnd ; ++aChildIter)
141 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() );
142 basegfx::B2DHomMatrix aTransformation;
143 if ( pPPTShape )
144 pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, 0, &getShapeMap() );
145 else
146 (*aChildIter)->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), 0, &getShapeMap() );
150 Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
151 if( xNodeSupplier.is() )
153 Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
154 if( xNode.is() && !maTimeNodeList.empty() )
156 SlidePersistPtr pSlidePtr( shared_from_this() );
157 TimeNodePtr pNode(maTimeNodeList.front());
158 OSL_ENSURE( pNode, "pNode" );
160 pNode->setNode( rFilterBase, xNode, pSlidePtr );
165 void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
167 if ( mpBackgroundPropertiesPtr )
169 sal_Int32 nPhClr = maBackgroundColor.isUsed() ?
170 maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
172 ::oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
173 mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
174 PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
178 void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter,
179 oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel )
181 ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
182 if( pTextParagraphPropertiesPtr == 0 )
184 // no properties. return
185 return;
188 PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
190 PropertySet aPropSet( rxPropSet );
191 aPropSet.setProperties( rTextParagraphPropertyMap );
192 pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
195 void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
197 if ( mbMaster )
201 Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
202 Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
203 Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
205 if ( aXNameAccess.is() && aXNamed.is() )
207 oox::drawingml::TextListStylePtr pTextListStylePtr;
208 OUString aStyle;
209 OUString aFamily;
211 const OUString sOutline( "outline1" );
212 const OUString sTitle( "title" );
213 const OUString sStandard( "standard" );
214 const OUString sSubtitle( "subtitle" );
216 for( int i = 0; i < 4; i++ ) // todo: aggregation of bodystyle (subtitle)
218 switch( i )
220 case 0 : // title style
222 pTextListStylePtr = maTitleTextStylePtr;
223 aStyle = sTitle;
224 aFamily= aXNamed->getName();
225 break;
227 case 1 : // body style
229 pTextListStylePtr = maBodyTextStylePtr;
230 aStyle = sOutline;
231 aFamily= aXNamed->getName();
232 break;
234 case 3 : // notes style
236 pTextListStylePtr = maNotesTextStylePtr;
237 aStyle = sTitle;
238 aFamily= aXNamed->getName();
239 break;
241 case 4 : // standard style
243 pTextListStylePtr = maOtherTextStylePtr;
244 aStyle = sStandard;
245 aFamily = "graphics";
246 break;
248 case 5 : // subtitle
250 pTextListStylePtr = maBodyTextStylePtr;
251 aStyle = sSubtitle;
252 aFamily = aXNamed->getName();
253 break;
256 Reference< container::XNameAccess > xFamilies;
257 if ( aXNameAccess->hasByName( aFamily ) )
259 if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
261 if ( xFamilies->hasByName( aStyle ) )
263 Reference< style::XStyle > aXStyle;
264 if ( xFamilies->getByName( aStyle ) >>= aXStyle )
266 Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
267 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
268 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
269 if ( i == 1 /* BodyStyle */ )
271 for ( int nLevel = 1; nLevel < 5; nLevel++ )
274 sal_Char pOutline[ 9 ] = "outline1";
275 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
276 OUString sOutlineStyle( OUString::createFromAscii( pOutline ) );
277 if ( xFamilies->hasByName( sOutlineStyle ) )
279 xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
280 if( aXStyle.is() )
281 xPropSet = Reference< beans::XPropertySet >( aXStyle, UNO_QUERY_THROW );
284 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
285 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
295 catch( const Exception& )
301 void SlidePersist::hideShapesAsMasterShapes()
303 std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
304 std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
305 while( aShapesIter != rShapes.end() )
307 while( aShapesIter != rShapes.end() )
309 std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
310 std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
311 while( aChildIter != rChildren.end() ) {
312 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter++).get() );
313 if (!pPPTShape)
314 continue;
315 OSL_TRACE("hide shape with id: %s", OUStringToOString(pPPTShape->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
316 pPPTShape->setHiddenMasterShape( true );
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */