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