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/pptshape.hxx"
21 : #include "oox/core/xmlfilterbase.hxx"
22 : #include "oox/drawingml/textbody.hxx"
23 :
24 : #include <com/sun/star/container/XNamed.hpp>
25 : #include <com/sun/star/beans/XMultiPropertySet.hpp>
26 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 : #include <com/sun/star/drawing/HomogenMatrix3.hpp>
28 : #include <com/sun/star/text/XText.hpp>
29 : #include <basegfx/matrix/b2dhommatrix.hxx>
30 : #include "oox/ppt/slidepersist.hxx"
31 :
32 : using rtl::OUString;
33 : using namespace ::oox::core;
34 : using namespace ::oox::drawingml;
35 : using namespace ::com::sun::star;
36 : using namespace ::com::sun::star::awt;
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::beans;
39 : using namespace ::com::sun::star::frame;
40 : using namespace ::com::sun::star::text;
41 : using namespace ::com::sun::star::drawing;
42 :
43 : namespace oox { namespace ppt {
44 :
45 73 : PPTShape::PPTShape( const oox::ppt::ShapeLocation eShapeLocation, const sal_Char* pServiceName )
46 : : Shape( pServiceName )
47 : , meShapeLocation( eShapeLocation )
48 73 : , mbReferenced( sal_False )
49 : {
50 73 : }
51 :
52 146 : PPTShape::~PPTShape()
53 : {
54 146 : }
55 :
56 0 : static const char* lclDebugSubType( sal_Int32 nType )
57 : {
58 0 : switch (nType) {
59 : case XML_ctrTitle :
60 0 : return "ctrTitle";
61 : case XML_title :
62 0 : return "title";
63 : case XML_subTitle :
64 0 : return "subTitle";
65 : case XML_obj :
66 0 : return "obj";
67 : case XML_body :
68 0 : return "body";
69 : case XML_dt :
70 0 : return "dt";
71 : case XML_hdr :
72 0 : return "hdr";
73 : case XML_ftr :
74 0 : return "frt";
75 : case XML_sldNum :
76 0 : return "sldNum";
77 : case XML_sldImg :
78 0 : return "sldImg";
79 : }
80 :
81 0 : return "unknown - please extend lclDebugSubType";
82 : }
83 :
84 1 : oox::drawingml::TextListStylePtr PPTShape::getSubTypeTextListStyle( const SlidePersist& rSlidePersist, sal_Int32 nSubType )
85 : {
86 1 : oox::drawingml::TextListStylePtr pTextListStyle;
87 :
88 : OSL_TRACE( "subtype style: %s", lclDebugSubType( nSubType ) );
89 :
90 1 : switch( nSubType )
91 : {
92 : case XML_ctrTitle :
93 : case XML_title :
94 : case XML_subTitle :
95 0 : pTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getTitleTextStyle() : rSlidePersist.getTitleTextStyle();
96 0 : break;
97 : case XML_obj :
98 0 : pTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getBodyTextStyle() : rSlidePersist.getBodyTextStyle();
99 0 : break;
100 : case XML_body :
101 1 : if ( rSlidePersist.isNotesPage() )
102 0 : pTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getNotesTextStyle() : rSlidePersist.getNotesTextStyle();
103 : else
104 1 : pTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getBodyTextStyle() : rSlidePersist.getBodyTextStyle();
105 1 : break;
106 : }
107 :
108 1 : return pTextListStyle;
109 : }
110 :
111 43 : void PPTShape::addShape(
112 : oox::core::XmlFilterBase& rFilterBase,
113 : SlidePersist& rSlidePersist,
114 : const oox::drawingml::Theme* pTheme,
115 : const Reference< XShapes >& rxShapes,
116 : basegfx::B2DHomMatrix& aTransformation,
117 : const awt::Rectangle* pShapeRect,
118 : ::oox::drawingml::ShapeIdMap* pShapeMap )
119 : {
120 : OSL_TRACE("add shape id: %s location: %s subtype: %d service: %s", rtl::OUStringToOString(msId, RTL_TEXTENCODING_UTF8 ).getStr(), meShapeLocation == Master ? "master" : meShapeLocation == Slide ? "slide" : meShapeLocation == Layout ? "layout" : "other", mnSubType, rtl::OUStringToOString(msServiceName, RTL_TEXTENCODING_UTF8 ).getStr());
121 : // only placeholder from layout are being inserted
122 43 : if ( mnSubType && ( meShapeLocation == Master ) )
123 60 : return;
124 : try
125 : {
126 26 : rtl::OUString sServiceName( msServiceName );
127 26 : if( !sServiceName.isEmpty() )
128 : {
129 26 : oox::drawingml::TextListStylePtr aMasterTextListStyle;
130 26 : Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW );
131 26 : sal_Bool bClearText = sal_False;
132 :
133 51 : if ( sServiceName != "com.sun.star.drawing.GraphicObjectShape" &&
134 25 : sServiceName != "com.sun.star.drawing.OLE2Shape" )
135 : {
136 25 : const rtl::OUString sOutlinerShapeService( "com.sun.star.presentation.OutlinerShape" );
137 : OSL_TRACE("has master: %p", rSlidePersist.getMasterPersist().get());
138 25 : switch( mnSubType )
139 : {
140 : case XML_ctrTitle :
141 : case XML_title :
142 : {
143 5 : sServiceName = "com.sun.star.presentation.TitleTextShape";
144 5 : aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getTitleTextStyle() : rSlidePersist.getTitleTextStyle();
145 : }
146 5 : break;
147 : case XML_subTitle :
148 : {
149 2 : if ( ( meShapeLocation == Master ) || ( meShapeLocation == Layout ) )
150 2 : sServiceName = rtl::OUString();
151 : else {
152 0 : sServiceName = "com.sun.star.presentation.SubtitleShape";
153 0 : aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getTitleTextStyle() : rSlidePersist.getTitleTextStyle();
154 : }
155 : }
156 2 : break;
157 : case XML_obj :
158 : {
159 2 : sServiceName = sOutlinerShapeService;
160 2 : aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getBodyTextStyle() : rSlidePersist.getBodyTextStyle();
161 : }
162 2 : break;
163 : case XML_body :
164 : {
165 2 : if ( rSlidePersist.isNotesPage() )
166 : {
167 1 : sServiceName = "com.sun.star.presentation.NotesShape";
168 1 : aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getNotesTextStyle() : rSlidePersist.getNotesTextStyle();
169 : }
170 : else
171 : {
172 1 : sServiceName = sOutlinerShapeService;
173 1 : aMasterTextListStyle = rSlidePersist.getMasterPersist().get() ? rSlidePersist.getMasterPersist()->getBodyTextStyle() : rSlidePersist.getBodyTextStyle();
174 : }
175 : }
176 2 : break;
177 : case XML_dt :
178 1 : sServiceName = "com.sun.star.presentation.DateTimeShape";
179 1 : bClearText = sal_True;
180 1 : break;
181 : case XML_hdr :
182 0 : sServiceName = "com.sun.star.presentation.HeaderShape";
183 0 : bClearText = sal_True;
184 0 : break;
185 : case XML_ftr :
186 2 : sServiceName = "com.sun.star.presentation.FooterShape";
187 2 : bClearText = sal_True;
188 2 : break;
189 : case XML_sldNum :
190 4 : sServiceName = "com.sun.star.presentation.SlideNumberShape";
191 4 : bClearText = sal_True;
192 4 : break;
193 : case XML_sldImg :
194 1 : sServiceName = "com.sun.star.presentation.PageShape";
195 1 : break;
196 : case XML_chart :
197 0 : if ( meShapeLocation == Layout )
198 0 : sServiceName = sOutlinerShapeService;
199 : else
200 0 : sServiceName = "com.sun.star.presentation.ChartShape";
201 0 : break;
202 : case XML_tbl :
203 0 : if ( meShapeLocation == Layout )
204 0 : sServiceName = sOutlinerShapeService;
205 : else
206 0 : sServiceName = "com.sun.star.presentation.TableShape";
207 0 : break;
208 : case XML_pic :
209 0 : if ( meShapeLocation == Layout )
210 0 : sServiceName = sOutlinerShapeService;
211 : else
212 0 : sServiceName = "com.sun.star.presentation.GraphicObjectShape";
213 0 : break;
214 : case XML_media :
215 0 : if ( meShapeLocation == Layout )
216 0 : sServiceName = sOutlinerShapeService;
217 : else
218 0 : sServiceName = "com.sun.star.presentation.MediaShape";
219 0 : break;
220 : default:
221 6 : if ( mnSubType && meShapeLocation == Layout )
222 0 : sServiceName = sOutlinerShapeService;
223 6 : break;
224 25 : }
225 : }
226 :
227 : OSL_TRACE("shape service: %s", rtl::OUStringToOString(sServiceName, RTL_TEXTENCODING_UTF8 ).getStr());
228 :
229 26 : if( mnSubType && getSubTypeIndex().has() && meShapeLocation == Layout ) {
230 7 : oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex().get(), rSlidePersist.getShapes()->getChildren(), true );
231 7 : if (!pPlaceholder.get())
232 5 : pPlaceholder = PPTShape::findPlaceholder( mnSubType, rSlidePersist.getShapes()->getChildren(), true );
233 :
234 7 : if (pPlaceholder.get()) {
235 7 : if( maSize.Width == 0 || maSize.Height == 0 ) {
236 0 : awt::Size aSize = maSize;
237 0 : if( maSize.Width == 0 )
238 0 : aSize.Width = pPlaceholder->getSize().Width;
239 0 : if( maSize.Height == 0 )
240 0 : aSize.Height = pPlaceholder->getSize().Height;
241 0 : setSize( aSize );
242 0 : if ( maPosition.X == 0 || maPosition.Y == 0 ) {
243 0 : awt::Point aPosition = maPosition;
244 0 : if( maPosition.X == 0 )
245 0 : aPosition.X = pPlaceholder->getPosition().X;
246 0 : if( maPosition.Y == 0 )
247 0 : aPosition.Y = pPlaceholder->getPosition().Y;
248 0 : setPosition( aPosition );
249 : }
250 : }
251 7 : }
252 : }
253 :
254 : // use placeholder index if possible
255 26 : if( mnSubType && getSubTypeIndex().has() && rSlidePersist.getMasterPersist().get() ) {
256 5 : oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex().get(), rSlidePersist.getMasterPersist()->getShapes()->getChildren() );
257 : // TODO: Check if this is required for non-notes slides as well...
258 5 : if( rSlidePersist.isNotesPage() && pPlaceholder.get() && pPlaceholder->getSubType() != getSubType() )
259 1 : pPlaceholder.reset();
260 :
261 5 : if( pPlaceholder.get()) {
262 : OSL_TRACE("found placeholder with index: %d and type: %s", getSubTypeIndex().get(), lclDebugSubType( mnSubType ));
263 : }
264 5 : if( pPlaceholder.get() ) {
265 1 : PPTShape* pPPTPlaceholder = dynamic_cast< PPTShape* >( pPlaceholder.get() );
266 1 : TextListStylePtr pNewTextListStyle ( new TextListStyle() );
267 :
268 1 : if( pPlaceholder->getTextBody() ) {
269 :
270 1 : pNewTextListStyle->apply( pPlaceholder->getTextBody()->getTextListStyle() );
271 1 : if( pPlaceholder->getMasterTextListStyle().get() )
272 1 : pNewTextListStyle->apply( *pPlaceholder->getMasterTextListStyle() );
273 :
274 : // OSL_TRACE("placeholder body style");
275 : // pPlaceholder->getTextBody()->getTextListStyle().dump();
276 : // OSL_TRACE("master text list style");
277 : // pPlaceholder->getMasterTextListStyle()->dump();
278 :
279 1 : aMasterTextListStyle = pNewTextListStyle;
280 : // OSL_TRACE("combined master text list style");
281 : // aMasterTextListStyle->dump();
282 : }
283 1 : if( pPPTPlaceholder->mpPlaceholder.get() ) {
284 : OSL_TRACE("placeholder has parent placeholder: %s type: %s index: %d",
285 : rtl::OUStringToOString( pPPTPlaceholder->mpPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr(),
286 : lclDebugSubType( pPPTPlaceholder->mpPlaceholder->getSubType() ),
287 : pPPTPlaceholder->mpPlaceholder->getSubTypeIndex().get() );
288 : OSL_TRACE("has textbody %d", pPPTPlaceholder->mpPlaceholder->getTextBody() != NULL );
289 1 : TextListStylePtr pPlaceholderStyle = getSubTypeTextListStyle( rSlidePersist, pPPTPlaceholder->mpPlaceholder->getSubType() );
290 1 : if( pPPTPlaceholder->mpPlaceholder->getTextBody() )
291 1 : pNewTextListStyle->apply( pPPTPlaceholder->mpPlaceholder->getTextBody()->getTextListStyle() );
292 1 : if( pPlaceholderStyle.get() ) {
293 1 : pNewTextListStyle->apply( *pPlaceholderStyle );
294 : //pPlaceholderStyle->dump();
295 1 : }
296 1 : }
297 4 : } else if( !mpPlaceholder.get() ) {
298 1 : aMasterTextListStyle.reset();
299 : }
300 5 : OSL_TRACE("placeholder id: %s", pPlaceholder.get() ? rtl::OUStringToOString(pPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr() : "not found");
301 : }
302 :
303 26 : if ( !sServiceName.isEmpty() )
304 : {
305 24 : if ( !aMasterTextListStyle.get() )
306 : {
307 15 : bool isOther = !getTextBody().get() && !sServiceName.equalsAscii("com.sun.star.drawing.GroupShape");
308 15 : TextListStylePtr aSlideStyle = isOther ? rSlidePersist.getOtherTextStyle() : rSlidePersist.getDefaultTextStyle();
309 : // Combine from MasterSlide details as well.
310 15 : if( rSlidePersist.getMasterPersist().get() )
311 : {
312 10 : aMasterTextListStyle = isOther ? rSlidePersist.getMasterPersist()->getOtherTextStyle() : rSlidePersist.getMasterPersist()->getDefaultTextStyle();
313 10 : if( aSlideStyle.get() )
314 10 : aMasterTextListStyle->apply( *aSlideStyle.get() );
315 : }
316 : else
317 : {
318 5 : aMasterTextListStyle = aSlideStyle;
319 15 : }
320 : }
321 :
322 24 : if( aMasterTextListStyle.get() && getTextBody().get() ) {
323 19 : TextListStylePtr aCombinedTextListStyle (new TextListStyle());
324 :
325 19 : aCombinedTextListStyle->apply( *aMasterTextListStyle.get() );
326 :
327 19 : if( mpPlaceholder.get() && mpPlaceholder->getTextBody().get() )
328 16 : aCombinedTextListStyle->apply( mpPlaceholder->getTextBody()->getTextListStyle() );
329 19 : aCombinedTextListStyle->apply( getTextBody()->getTextListStyle() );
330 :
331 19 : setMasterTextListStyle( aCombinedTextListStyle );
332 : } else
333 5 : setMasterTextListStyle( aMasterTextListStyle );
334 :
335 24 : Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, pShapeRect, bClearText, mpPlaceholder.get() != NULL, aTransformation ) );
336 24 : if ( !rSlidePersist.isMasterPage() && rSlidePersist.getPage().is() && ( (sal_Int32)mnSubType == XML_title ) )
337 : {
338 : try
339 : {
340 1 : rtl::OUString aTitleText;
341 1 : Reference< XTextRange > xText( xShape, UNO_QUERY_THROW );
342 1 : aTitleText = xText->getString();
343 1 : if ( !aTitleText.isEmpty() && ( aTitleText.getLength() < 64 ) ) // just a magic value, but we don't want to set slide names which are too long
344 : {
345 1 : Reference< container::XNamed > xName( rSlidePersist.getPage(), UNO_QUERY_THROW );
346 1 : xName->setName( aTitleText );
347 1 : }
348 : }
349 0 : catch( uno::Exception& )
350 : {
351 :
352 : }
353 : }
354 24 : if( pShapeMap && !msId.isEmpty() )
355 : {
356 24 : (*pShapeMap)[ msId ] = shared_from_this();
357 : }
358 :
359 : // if this is a group shape, we have to add also each child shape
360 24 : Reference< XShapes > xShapes( xShape, UNO_QUERY );
361 24 : if ( xShapes.is() )
362 0 : addChildren( rFilterBase, *this, pTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap, aTransformation );
363 26 : }
364 26 : }
365 : }
366 0 : catch( const Exception& )
367 : {
368 : }
369 : }
370 :
371 18 : void PPTShape::applyShapeReference( const oox::drawingml::Shape& rReferencedShape, bool bUseText )
372 : {
373 18 : Shape::applyShapeReference( rReferencedShape, bUseText );
374 18 : }
375 :
376 40 : oox::drawingml::ShapePtr PPTShape::findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly )
377 : {
378 40 : oox::drawingml::ShapePtr aShapePtr;
379 40 : std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
380 110 : while( aRevIter != rShapes.rend() )
381 : {
382 70 : if ( (*aRevIter)->getSubType() == nMasterPlaceholder &&
383 10 : ( !bMasterOnly ||
384 20 : ( dynamic_cast< PPTShape* >( (*aRevIter).get() ) && dynamic_cast< PPTShape* >( (*aRevIter).get() )->getShapeLocation() == Master ) ) )
385 : {
386 5 : aShapePtr = *aRevIter;
387 5 : break;
388 : }
389 35 : std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
390 35 : aShapePtr = findPlaceholder( nMasterPlaceholder, rChildren, bMasterOnly );
391 35 : if ( aShapePtr.get() )
392 5 : break;
393 30 : ++aRevIter;
394 : }
395 40 : return aShapePtr;
396 : }
397 :
398 187 : oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly )
399 : {
400 187 : oox::drawingml::ShapePtr aShapePtr;
401 :
402 187 : std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
403 529 : while( aRevIter != rShapes.rend() )
404 : {
405 204 : if ( (*aRevIter)->getSubTypeIndex().has() && (*aRevIter)->getSubTypeIndex().get() == nIdx &&
406 15 : ( !bMasterOnly ||
407 18 : ( dynamic_cast< PPTShape* >( (*aRevIter).get() ) && dynamic_cast< PPTShape* >( (*aRevIter).get() )->getShapeLocation() == Master ) ) )
408 : {
409 8 : aShapePtr = *aRevIter;
410 8 : break;
411 : }
412 163 : std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
413 163 : aShapePtr = findPlaceholderByIndex( nIdx, rChildren, bMasterOnly );
414 163 : if ( aShapePtr.get() )
415 8 : break;
416 155 : ++aRevIter;
417 : }
418 187 : return aShapePtr;
419 : }
420 :
421 51 : } }
422 :
423 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|