Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / ppt / slidepersist.cxx
blobb8fd28e8e538bf6cebdf513c9d5584781169f9f0
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 <basegfx/matrix/b2dhommatrix.hxx>
21 #include <com/sun/star/drawing/XShapes.hpp>
22 #include "oox/ppt/timenode.hxx"
23 #include "oox/ppt/pptshape.hxx"
24 #include "oox/ppt/slidepersist.hxx"
25 #include "drawingml/fillproperties.hxx"
26 #include "oox/drawingml/shapepropertymap.hxx"
27 #include "oox/helper/propertymap.hxx"
28 #include "oox/helper/propertyset.hxx"
29 #include "oox/vml/vmldrawing.hxx"
30 #include <oox/token/properties.hxx>
31 #include <oox/token/tokens.hxx>
32 #include "oox/core/xmlfilterbase.hxx"
33 #include "drawingml/textliststyle.hxx"
34 #include "drawingml/textparagraphproperties.hxx"
36 #include <osl/diagnose.h>
38 #include <com/sun/star/style/XStyle.hpp>
39 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
40 #include <com/sun/star/container/XNamed.hpp>
41 #include <com/sun/star/beans/XMultiPropertySet.hpp>
42 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
44 using namespace ::com::sun::star;
45 using namespace ::oox::core;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::drawing;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::animations;
51 namespace oox { namespace ppt {
53 SlidePersist::SlidePersist( XmlFilterBase& rFilter, bool bMaster, bool bNotes,
54 const css::uno::Reference< css::drawing::XDrawPage >& rxPage,
55 oox::drawingml::ShapePtr const & pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
56 : mpDrawingPtr( new oox::vml::Drawing( rFilter, rxPage, oox::vml::VMLDRAWING_POWERPOINT ) )
57 , mxPage( rxPage )
58 , maShapesPtr( pShapesPtr )
59 , mnLayoutValueToken( 0 )
60 , mbMaster( bMaster )
61 , mbNotes ( bNotes )
62 , maDefaultTextStylePtr( pDefaultTextStyle )
63 , maTitleTextStylePtr( new oox::drawingml::TextListStyle )
64 , maBodyTextStylePtr( new oox::drawingml::TextListStyle )
65 , maNotesTextStylePtr( new oox::drawingml::TextListStyle )
66 , maOtherTextStylePtr( new oox::drawingml::TextListStyle )
68 #if OSL_DEBUG_LEVEL > 0
69 mxDebugPage = mxPage;
70 #endif
73 #if OSL_DEBUG_LEVEL > 0
74 css::uno::WeakReference< css::drawing::XDrawPage > SlidePersist::mxDebugPage;
75 #endif
77 SlidePersist::~SlidePersist()
81 sal_Int16 SlidePersist::getLayoutFromValueToken()
83 sal_Int16 nLayout = 20; // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
84 switch( mnLayoutValueToken )
86 case XML_blank: nLayout = 20; break;
87 case XML_chart: nLayout = 2; break;
88 case XML_chartAndTx: nLayout = 7; break;
89 case XML_clipArtAndTx: nLayout = 9; break;
90 case XML_clipArtAndVertTx: nLayout = 24; break;
91 case XML_fourObj: nLayout = 18; break;
92 case XML_obj: nLayout = 11; break;
93 case XML_objAndTx: nLayout = 13; break;
94 case XML_objOverTx: nLayout = 14; break;
95 case XML_tbl: nLayout = 8; break;
96 case XML_title: nLayout = 0; break;
97 case XML_titleOnly: nLayout = 19; break;
98 case XML_twoObj:
99 case XML_twoColTx: nLayout = 3; break;
100 case XML_twoObjAndTx: nLayout = 15; break;
101 case XML_twoObjOverTx: nLayout = 16; break;
102 case XML_tx: nLayout = 1; break;
103 case XML_txAndChart: nLayout = 4; break;
104 case XML_txAndClipArt: nLayout = 6; break;
105 case XML_txAndMedia: nLayout = 6; break;
106 case XML_txAndObj: nLayout = 10; break;
107 case XML_txAndTwoObj: nLayout = 12; break;
108 case XML_txOverObj: nLayout = 17; break;
109 case XML_vertTitleAndTx: nLayout = 22; break;
110 case XML_vertTitleAndTxOverChart: nLayout = 21; break;
111 case XML_vertTx: nLayout = 23; break;
113 case XML_twoTxTwoObj:
114 case XML_twoObjAndObj:
115 case XML_objTx:
116 case XML_picTx:
117 case XML_secHead:
118 case XML_objOnly:
119 case XML_objAndTwoObj:
120 case XML_mediaAndTx:
121 case XML_dgm:
122 case XML_cust:
123 default:
124 nLayout = 20;
126 return nLayout;
129 void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
131 applyTextStyles( rFilterBase );
133 Reference< XShapes > xShapes( getPage(), UNO_QUERY );
135 std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
136 const std::vector< oox::drawingml::ShapePtr >::const_iterator aShapesEnd( rShapes.end() );
137 for (std::vector< oox::drawingml::ShapePtr >::const_iterator aShapesIter( rShapes.begin() );
138 aShapesIter != aShapesEnd ; ++aShapesIter)
140 std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter)->getChildren() );
141 const std::vector< oox::drawingml::ShapePtr >::const_iterator aChildEnd( rChildren.end() );
142 for (std::vector< oox::drawingml::ShapePtr >::const_iterator aChildIter( rChildren.begin() );
143 aChildIter != aChildEnd ; ++aChildIter)
145 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter).get() );
146 basegfx::B2DHomMatrix aTransformation;
147 if ( pPPTShape )
148 pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap() );
149 else
150 (*aChildIter)->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &getShapeMap() );
154 Reference< XAnimationNodeSupplier > xNodeSupplier( getPage(), UNO_QUERY);
155 if( xNodeSupplier.is() )
157 Reference< XAnimationNode > xNode( xNodeSupplier->getAnimationNode() );
158 if( xNode.is() && !maTimeNodeList.empty() )
160 SlidePersistPtr pSlidePtr( shared_from_this() );
161 TimeNodePtr pNode(maTimeNodeList.front());
162 OSL_ENSURE( pNode, "pNode" );
164 pNode->setNode( rFilterBase, xNode, pSlidePtr );
169 void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
171 if ( mpBackgroundPropertiesPtr )
173 sal_Int32 nPhClr = maBackgroundColor.isUsed() ?
174 maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
176 oox::drawingml::ShapePropertyIds aPropertyIds = (oox::drawingml::ShapePropertyInfo::DEFAULT).mrPropertyIds;
177 aPropertyIds[oox::drawingml::ShapeProperty::FillGradient] = PROP_FillGradientName;
178 oox::drawingml::ShapePropertyInfo aPropInfo( aPropertyIds, true, false, true, false );
179 oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper(), aPropInfo );
180 mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
181 PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
185 void setTextStyle( Reference< beans::XPropertySet >& rxPropSet, const XmlFilterBase& rFilter,
186 oox::drawingml::TextListStylePtr& pTextListStylePtr, int nLevel )
188 ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
189 if( pTextParagraphPropertiesPtr == nullptr )
191 // no properties. return
192 return;
195 PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
197 PropertySet aPropSet( rxPropSet );
198 aPropSet.setProperties( rTextParagraphPropertyMap );
199 pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
202 void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
204 if ( mbMaster )
208 Reference< style::XStyleFamiliesSupplier > aXStyleFamiliesSupplier( rFilterBase.getModel(), UNO_QUERY_THROW );
209 Reference< container::XNameAccess > aXNameAccess( aXStyleFamiliesSupplier->getStyleFamilies() );
210 Reference< container::XNamed > aXNamed( mxPage, UNO_QUERY_THROW );
212 if ( aXNameAccess.is() && aXNamed.is() )
214 oox::drawingml::TextListStylePtr pTextListStylePtr;
215 OUString aStyle;
216 OUString aFamily;
218 const OUString sOutline( "outline1" );
219 const OUString sTitle( "title" );
220 const OUString sStandard( "standard" );
221 const OUString sSubtitle( "subtitle" );
223 for( int i = 0; i < 4; i++ ) // todo: aggregation of bodystyle (subtitle)
225 switch( i )
227 case 0 : // title style
229 pTextListStylePtr = maTitleTextStylePtr;
230 aStyle = sTitle;
231 aFamily= aXNamed->getName();
232 break;
234 case 1 : // body style
236 pTextListStylePtr = maBodyTextStylePtr;
237 aStyle = sOutline;
238 aFamily= aXNamed->getName();
239 break;
241 case 3 : // notes style
243 pTextListStylePtr = maNotesTextStylePtr;
244 aStyle = sTitle;
245 aFamily= aXNamed->getName();
246 break;
248 case 4 : // standard style
250 pTextListStylePtr = maOtherTextStylePtr;
251 aStyle = sStandard;
252 aFamily = "graphics";
253 break;
255 case 5 : // subtitle
257 pTextListStylePtr = maBodyTextStylePtr;
258 aStyle = sSubtitle;
259 aFamily = aXNamed->getName();
260 break;
263 Reference< container::XNameAccess > xFamilies;
264 if ( aXNameAccess->hasByName( aFamily ) )
266 if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
268 if ( xFamilies->hasByName( aStyle ) )
270 Reference< style::XStyle > aXStyle;
271 if ( xFamilies->getByName( aStyle ) >>= aXStyle )
273 Reference< beans::XPropertySet > xPropSet( aXStyle, UNO_QUERY_THROW );
274 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, 0 );
275 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, 0 );
276 if ( i == 1 /* BodyStyle */ )
278 for ( int nLevel = 1; nLevel < 5; nLevel++ )
281 sal_Char pOutline[ 9 ] = "outline1";
282 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
283 OUString sOutlineStyle( OUString::createFromAscii( pOutline ) );
284 if ( xFamilies->hasByName( sOutlineStyle ) )
286 xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
287 if( aXStyle.is() )
288 xPropSet.set( aXStyle, UNO_QUERY_THROW );
291 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
292 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
302 catch( const Exception& )
308 void SlidePersist::hideShapesAsMasterShapes()
310 std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
311 std::vector< oox::drawingml::ShapePtr >::iterator aShapesIter( rShapes.begin() );
312 while( aShapesIter != rShapes.end() )
314 while( aShapesIter != rShapes.end() )
316 std::vector< oox::drawingml::ShapePtr >& rChildren( (*aShapesIter++)->getChildren() );
317 std::vector< oox::drawingml::ShapePtr >::iterator aChildIter( rChildren.begin() );
318 while( aChildIter != rChildren.end() ) {
319 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( (*aChildIter++).get() );
320 if (!pPPTShape)
321 continue;
322 pPPTShape->setHiddenMasterShape( true );
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */