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