Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / ppt / slidepersist.cxx
blob247831677dfda8bb61affb706587e95efe1a555f
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() const
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 for (auto const& shape : rShapes)
138 std::vector< oox::drawingml::ShapePtr >& rChildren( shape->getChildren() );
139 for (auto const& child : rChildren)
141 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() );
142 basegfx::B2DHomMatrix aTransformation;
143 if ( pPPTShape )
144 pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap() );
145 else
146 child->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &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 Reference<XAnimationNode> xDummy;
161 pNode->setNode(rFilterBase, xNode, pSlidePtr, xDummy);
166 void SlidePersist::createBackground( const XmlFilterBase& rFilterBase )
168 if ( mpBackgroundPropertiesPtr )
170 ::Color nPhClr = maBackgroundColor.isUsed() ?
171 maBackgroundColor.getColor( rFilterBase.getGraphicHelper() ) : API_RGB_TRANSPARENT;
173 oox::drawingml::ShapePropertyIds aPropertyIds = oox::drawingml::ShapePropertyInfo::DEFAULT.mrPropertyIds;
174 aPropertyIds[oox::drawingml::ShapeProperty::FillGradient] = PROP_FillGradientName;
175 oox::drawingml::ShapePropertyInfo aPropInfo( aPropertyIds, true, false, true, false, false );
176 oox::drawingml::ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper(), aPropInfo );
177 mpBackgroundPropertiesPtr->pushToPropMap( aPropMap, rFilterBase.getGraphicHelper(), 0, nPhClr );
178 PropertySet( mxPage ).setProperty( PROP_Background, aPropMap.makePropertySet() );
182 static void setTextStyle( Reference< beans::XPropertySet > const & rxPropSet, const XmlFilterBase& rFilter,
183 oox::drawingml::TextListStylePtr const & pTextListStylePtr, int nLevel )
185 ::oox::drawingml::TextParagraphPropertiesPtr pTextParagraphPropertiesPtr( pTextListStylePtr->getListStyle()[ nLevel ] );
186 if( pTextParagraphPropertiesPtr == nullptr )
188 // no properties. return
189 return;
192 PropertyMap& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr->getTextParagraphPropertyMap() );
194 PropertySet aPropSet( rxPropSet );
195 aPropSet.setProperties( rTextParagraphPropertyMap );
196 pTextParagraphPropertiesPtr->getTextCharacterProperties().pushToPropSet( aPropSet, rFilter );
199 void SlidePersist::applyTextStyles( const XmlFilterBase& rFilterBase )
201 if ( mbMaster )
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 );
209 if ( aXNameAccess.is() )
211 oox::drawingml::TextListStylePtr pTextListStylePtr;
212 OUString aStyle;
213 OUString aFamily;
215 const OUString sOutline( "outline1" );
216 const OUString sTitle( "title" );
217 const OUString sStandard( "standard" );
218 const OUString sSubtitle( "subtitle" );
220 for( int i = 0; i < 4; i++ ) // todo: aggregation of bodystyle (subtitle)
222 switch( i )
224 case 0 : // title style
226 pTextListStylePtr = maTitleTextStylePtr;
227 aStyle = sTitle;
228 aFamily= aXNamed->getName();
229 break;
231 case 1 : // body style
233 pTextListStylePtr = maBodyTextStylePtr;
234 aStyle = sOutline;
235 aFamily= aXNamed->getName();
236 break;
238 case 3 : // notes style
240 pTextListStylePtr = maNotesTextStylePtr;
241 aStyle = sTitle;
242 aFamily= aXNamed->getName();
243 break;
245 case 4 : // standard style
247 pTextListStylePtr = maOtherTextStylePtr;
248 aStyle = sStandard;
249 aFamily = "graphics";
250 break;
252 case 5 : // subtitle
254 pTextListStylePtr = maBodyTextStylePtr;
255 aStyle = sSubtitle;
256 aFamily = aXNamed->getName();
257 break;
260 Reference< container::XNameAccess > xFamilies;
261 if ( aXNameAccess->hasByName( aFamily ) )
263 if( aXNameAccess->getByName( aFamily ) >>= xFamilies )
265 if ( xFamilies->hasByName( aStyle ) )
267 Reference< style::XStyle > aXStyle;
268 if ( xFamilies->getByName( aStyle ) >>= aXStyle )
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 */ )
275 for ( int nLevel = 1; nLevel < 5; nLevel++ )
278 sal_Char pOutline[ 9 ] = "outline1";
279 pOutline[ 7 ] = static_cast< sal_Char >( '0' + nLevel );
280 OUString sOutlineStyle( OUString::createFromAscii( pOutline ) );
281 if ( xFamilies->hasByName( sOutlineStyle ) )
283 xFamilies->getByName( sOutlineStyle ) >>= aXStyle;
284 if( aXStyle.is() )
285 xPropSet.set( aXStyle, UNO_QUERY_THROW );
288 setTextStyle( xPropSet, rFilterBase, maDefaultTextStylePtr, nLevel );
289 setTextStyle( xPropSet, rFilterBase, pTextListStylePtr, nLevel );
299 catch( const Exception& )
305 void SlidePersist::hideShapesAsMasterShapes()
307 std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
308 for (auto const& shape : rShapes)
310 std::vector< oox::drawingml::ShapePtr >& rChildren( shape->getChildren() );
311 for (auto const& child : rChildren)
313 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() );
314 if (!pPPTShape)
315 continue;
316 pPPTShape->setHiddenMasterShape( true );
321 Reference<XAnimationNode> SlidePersist::getAnimationNode(const OUString& sId) const
323 const auto& pIter = maAnimNodesMap.find(sId);
324 if (pIter != maAnimNodesMap.end())
325 return pIter->second;
327 Reference<XAnimationNode> aResult;
328 return aResult;
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */