1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/propertyset.hxx"
26 #include "oox/vml/vmldrawing.hxx"
27 #include "oox/core/xmlfilterbase.hxx"
29 #include <com/sun/star/style/XStyle.hpp>
30 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
31 #include <com/sun/star/container/XNamed.hpp>
32 #include <com/sun/star/beans/XMultiPropertySet.hpp>
33 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
35 using namespace ::com::sun::star
;
36 using namespace ::oox::core
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::drawing
;
39 using namespace ::com::sun::star::container
;
40 using namespace ::com::sun::star::animations
;
42 namespace oox
{ namespace ppt
{
44 SlidePersist::SlidePersist( XmlFilterBase
& rFilter
, sal_Bool bMaster
, sal_Bool bNotes
,
45 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XDrawPage
>& rxPage
,
46 oox::drawingml::ShapePtr pShapesPtr
, const drawingml::TextListStylePtr
& pDefaultTextStyle
)
47 : mpDrawingPtr( new oox::vml::Drawing( rFilter
, rxPage
, oox::vml::VMLDRAWING_POWERPOINT
) )
49 , maShapesPtr( pShapesPtr
)
50 , mnLayoutValueToken( 0 )
53 , maDefaultTextStylePtr( pDefaultTextStyle
)
54 , maTitleTextStylePtr( new oox::drawingml::TextListStyle
)
55 , maBodyTextStylePtr( new oox::drawingml::TextListStyle
)
56 , maNotesTextStylePtr( new oox::drawingml::TextListStyle
)
57 , maOtherTextStylePtr( new oox::drawingml::TextListStyle
)
59 #if OSL_DEBUG_LEVEL > 0
64 #if OSL_DEBUG_LEVEL > 0
65 ::com::sun::star::uno::WeakReference
< ::com::sun::star::drawing::XDrawPage
> SlidePersist::mxDebugPage
;
68 SlidePersist::~SlidePersist()
72 sal_Int16
SlidePersist::getLayoutFromValueToken()
74 sal_Int16 nLayout
= 20; // 20 == blanc (so many magic numbers :-( the description at com.sun.star.presentation.DrawPage.Layout does not help)
75 switch( mnLayoutValueToken
)
77 case XML_blank
: nLayout
= 20; break;
78 case XML_chart
: nLayout
= 2; break;
79 case XML_chartAndTx
: nLayout
= 7; break;
80 case XML_clipArtAndTx
: nLayout
= 9; break;
81 case XML_clipArtAndVertTx
: nLayout
= 24; break;
82 case XML_fourObj
: nLayout
= 18; break;
83 case XML_obj
: nLayout
= 11; break;
84 case XML_objAndTx
: nLayout
= 13; break;
85 case XML_objOverTx
: nLayout
= 14; break;
86 case XML_tbl
: nLayout
= 8; break;
87 case XML_title
: nLayout
= 0; break;
88 case XML_titleOnly
: nLayout
= 19; break;
90 case XML_twoColTx
: nLayout
= 3; break;
91 case XML_twoObjAndTx
: nLayout
= 15; break;
92 case XML_twoObjOverTx
: nLayout
= 16; break;
93 case XML_tx
: nLayout
= 1; break;
94 case XML_txAndChart
: nLayout
= 4; break;
95 case XML_txAndClipArt
: nLayout
= 6; break;
96 case XML_txAndMedia
: nLayout
= 6; break;
97 case XML_txAndObj
: nLayout
= 10; break;
98 case XML_txAndTwoObj
: nLayout
= 12; break;
99 case XML_txOverObj
: nLayout
= 17; break;
100 case XML_vertTitleAndTx
: nLayout
= 22; break;
101 case XML_vertTitleAndTxOverChart
: nLayout
= 21; break;
102 case XML_vertTx
: nLayout
= 23; break;
104 case XML_twoTxTwoObj
:
105 case XML_twoObjAndObj
:
110 case XML_objAndTwoObj
:
120 void SlidePersist::createXShapes( XmlFilterBase
& rFilterBase
)
122 applyTextStyles( rFilterBase
);
124 Reference
< XShapes
> xShapes( getPage(), UNO_QUERY
);
126 std::vector
< oox::drawingml::ShapePtr
>& rShapes( maShapesPtr
->getChildren() );
127 const std::vector
< oox::drawingml::ShapePtr
>::const_iterator
aShapesEnd( rShapes
.end() );
128 for (std::vector
< oox::drawingml::ShapePtr
>::const_iterator
aShapesIter( rShapes
.begin() );
129 aShapesIter
!= aShapesEnd
; ++aShapesIter
)
131 std::vector
< oox::drawingml::ShapePtr
>& rChildren( (*aShapesIter
)->getChildren() );
132 const std::vector
< oox::drawingml::ShapePtr
>::const_iterator
aChildEnd( rChildren
.end() );
133 for (std::vector
< oox::drawingml::ShapePtr
>::const_iterator
aChildIter( rChildren
.begin() );
134 aChildIter
!= aChildEnd
; ++aChildIter
)
136 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( (*aChildIter
).get() );
137 basegfx::B2DHomMatrix aTransformation
;
139 pPPTShape
->addShape( rFilterBase
, *this, getTheme().get(), xShapes
, aTransformation
, 0, &getShapeMap() );
141 (*aChildIter
)->addShape( rFilterBase
, getTheme().get(), xShapes
, aTransformation
, maShapesPtr
->getFillProperties(), 0, &getShapeMap() );
145 Reference
< XAnimationNodeSupplier
> xNodeSupplier( getPage(), UNO_QUERY
);
146 if( xNodeSupplier
.is() )
148 Reference
< XAnimationNode
> xNode( xNodeSupplier
->getAnimationNode() );
149 if( xNode
.is() && !maTimeNodeList
.empty() )
151 SlidePersistPtr
pSlidePtr( shared_from_this() );
152 TimeNodePtr
pNode(maTimeNodeList
.front());
153 OSL_ENSURE( pNode
, "pNode" );
155 pNode
->setNode( rFilterBase
, xNode
, pSlidePtr
);
160 void SlidePersist::createBackground( const XmlFilterBase
& rFilterBase
)
162 if ( mpBackgroundPropertiesPtr
)
164 sal_Int32 nPhClr
= maBackgroundColor
.isUsed() ?
165 maBackgroundColor
.getColor( rFilterBase
.getGraphicHelper() ) : API_RGB_TRANSPARENT
;
167 ::oox::drawingml::ShapePropertyMap
aPropMap( rFilterBase
.getModelObjectHelper() );
168 mpBackgroundPropertiesPtr
->pushToPropMap( aPropMap
, rFilterBase
.getGraphicHelper(), 0, nPhClr
);
169 PropertySet( mxPage
).setProperty( PROP_Background
, aPropMap
.makePropertySet() );
173 void setTextStyle( Reference
< beans::XPropertySet
>& rxPropSet
, const XmlFilterBase
& rFilter
,
174 oox::drawingml::TextListStylePtr
& pTextListStylePtr
, int nLevel
)
176 ::oox::drawingml::TextParagraphPropertiesPtr
pTextParagraphPropertiesPtr( pTextListStylePtr
->getListStyle()[ nLevel
] );
177 if( pTextParagraphPropertiesPtr
== 0 )
179 // no properties. return
183 PropertyMap
& rTextParagraphPropertyMap( pTextParagraphPropertiesPtr
->getTextParagraphPropertyMap() );
185 PropertySet
aPropSet( rxPropSet
);
186 aPropSet
.setProperties( rTextParagraphPropertyMap
);
187 pTextParagraphPropertiesPtr
->getTextCharacterProperties().pushToPropSet( aPropSet
, rFilter
);
190 void SlidePersist::applyTextStyles( const XmlFilterBase
& rFilterBase
)
196 Reference
< style::XStyleFamiliesSupplier
> aXStyleFamiliesSupplier( rFilterBase
.getModel(), UNO_QUERY_THROW
);
197 Reference
< container::XNameAccess
> aXNameAccess( aXStyleFamiliesSupplier
->getStyleFamilies() );
198 Reference
< container::XNamed
> aXNamed( mxPage
, UNO_QUERY_THROW
);
200 if ( aXNameAccess
.is() && aXNamed
.is() )
202 oox::drawingml::TextListStylePtr pTextListStylePtr
;
206 const OUString
sOutline( "outline1" );
207 const OUString
sTitle( "title" );
208 const OUString
sStandard( "standard" );
209 const OUString
sSubtitle( "subtitle" );
211 for( int i
= 0; i
< 4; i
++ ) // todo: aggregation of bodystyle (subtitle)
215 case 0 : // title style
217 pTextListStylePtr
= maTitleTextStylePtr
;
219 aFamily
= aXNamed
->getName();
222 case 1 : // body style
224 pTextListStylePtr
= maBodyTextStylePtr
;
226 aFamily
= aXNamed
->getName();
229 case 3 : // notes style
231 pTextListStylePtr
= maNotesTextStylePtr
;
233 aFamily
= aXNamed
->getName();
236 case 4 : // standard style
238 pTextListStylePtr
= maOtherTextStylePtr
;
240 aFamily
= "graphics";
245 pTextListStylePtr
= maBodyTextStylePtr
;
247 aFamily
= aXNamed
->getName();
251 Reference
< container::XNameAccess
> xFamilies
;
252 if ( aXNameAccess
->hasByName( aFamily
) )
254 if( aXNameAccess
->getByName( aFamily
) >>= xFamilies
)
256 if ( xFamilies
->hasByName( aStyle
) )
258 Reference
< style::XStyle
> aXStyle
;
259 if ( xFamilies
->getByName( aStyle
) >>= aXStyle
)
261 Reference
< beans::XPropertySet
> xPropSet( aXStyle
, UNO_QUERY_THROW
);
262 setTextStyle( xPropSet
, rFilterBase
, maDefaultTextStylePtr
, 0 );
263 setTextStyle( xPropSet
, rFilterBase
, pTextListStylePtr
, 0 );
264 if ( i
== 1 /* BodyStyle */ )
266 for ( int nLevel
= 1; nLevel
< 5; nLevel
++ )
269 sal_Char pOutline
[ 9 ] = "outline1";
270 pOutline
[ 7 ] = static_cast< sal_Char
>( '0' + nLevel
);
271 OUString
sOutlineStyle( OUString::createFromAscii( pOutline
) );
272 if ( xFamilies
->hasByName( sOutlineStyle
) )
274 xFamilies
->getByName( sOutlineStyle
) >>= aXStyle
;
276 xPropSet
= Reference
< beans::XPropertySet
>( aXStyle
, UNO_QUERY_THROW
);
279 setTextStyle( xPropSet
, rFilterBase
, maDefaultTextStylePtr
, nLevel
);
280 setTextStyle( xPropSet
, rFilterBase
, pTextListStylePtr
, nLevel
);
290 catch( const Exception
& )
296 void SlidePersist::hideShapesAsMasterShapes()
298 std::vector
< oox::drawingml::ShapePtr
>& rShapes( maShapesPtr
->getChildren() );
299 std::vector
< oox::drawingml::ShapePtr
>::iterator
aShapesIter( rShapes
.begin() );
300 while( aShapesIter
!= rShapes
.end() )
302 while( aShapesIter
!= rShapes
.end() )
304 std::vector
< oox::drawingml::ShapePtr
>& rChildren( (*aShapesIter
++)->getChildren() );
305 std::vector
< oox::drawingml::ShapePtr
>::iterator
aChildIter( rChildren
.begin() );
306 while( aChildIter
!= rChildren
.end() ) {
307 PPTShape
* pPPTShape
= dynamic_cast< PPTShape
* >( (*aChildIter
++).get() );
308 OSL_TRACE("hide shape with id: %s", OUStringToOString(pPPTShape
->getId(), RTL_TEXTENCODING_UTF8
).getStr());
309 pPPTShape
->setHiddenMasterShape( true );
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */