bump product version to 4.1.6.2
[LibreOffice.git] / oox / source / ppt / pptshapecontext.cxx
bloba42fe8d131d407f1650bf61d4f79f8a0de41a3a7
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 <com/sun/star/xml/sax/FastToken.hpp>
21 #include <com/sun/star/drawing/LineStyle.hpp>
22 #include <com/sun/star/beans/XMultiPropertySet.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/container/XNamed.hpp>
26 #include "oox/helper/attributelist.hxx"
27 #include "oox/ppt/pptshape.hxx"
28 #include "oox/ppt/pptshapecontext.hxx"
29 #include "oox/ppt/pptshapepropertiescontext.hxx"
30 #include "oox/ppt/slidepersist.hxx"
31 #include "oox/drawingml/shapestylecontext.hxx"
32 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
33 #include "oox/drawingml/lineproperties.hxx"
34 #include "oox/drawingml/drawingmltypes.hxx"
35 #include "oox/drawingml/customshapegeometry.hxx"
36 #include "oox/drawingml/textbodycontext.hxx"
37 #include "oox/drawingml/transform2dcontext.hxx"
39 using namespace oox::core;
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::drawing;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::text;
45 using namespace ::com::sun::star::xml::sax;
47 namespace oox { namespace ppt {
49 // CT_Shape
50 PPTShapeContext::PPTShapeContext( ContextHandler& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
51 : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
52 , mpSlidePersistPtr( pSlidePersistPtr )
56 oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
58 oox::drawingml::ShapePtr aShapePtr;
59 oox::drawingml::ShapePtr aChoiceShapePtr1;
60 oox::drawingml::ShapePtr aChoiceShapePtr2;
61 std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
62 while( aRevIter != rShapes.rend() )
64 if ( (*aRevIter)->getSubType() == nMasterPlaceholder )
66 if( !oSubTypeIndex.has() && aChoiceShapePtr1 == NULL )
67 aChoiceShapePtr1 = *aRevIter;
68 else if( aChoiceShapePtr2 == NULL )
69 aChoiceShapePtr2 = *aRevIter;
70 if( (*aRevIter)->getSubTypeIndex() == oSubTypeIndex )
72 aShapePtr = *aRevIter;
73 break;
76 std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
77 aShapePtr = findPlaceholder( nMasterPlaceholder, oSubTypeIndex, rChildren );
78 if ( aShapePtr.get() )
79 break;
80 ++aRevIter;
82 if( aShapePtr == NULL )
83 return aChoiceShapePtr1 ? aChoiceShapePtr1 : aChoiceShapePtr2;
84 return aShapePtr;
87 // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
88 oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder,
89 const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes )
91 oox::drawingml::ShapePtr pPlaceholder = findPlaceholder( nFirstPlaceholder, oSubTypeIndex, rShapes );
92 return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : findPlaceholder( nSecondPlaceholder, oSubTypeIndex, rShapes );
95 Reference< XFastContextHandler > PPTShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
97 Reference< XFastContextHandler > xRet;
98 if( getNamespace( aElementToken ) == NMSP_dsp )
99 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
101 switch( aElementToken )
103 // nvSpPr CT_ShapeNonVisual begin
104 // case PPT_TOKEN( drElemPr ):
105 // break;
106 case PPT_TOKEN( cNvPr ):
108 AttributeList aAttribs( xAttribs );
109 mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) );
110 mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) );
111 mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) );
112 break;
114 case PPT_TOKEN( ph ):
116 sal_Int32 nSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) );
117 mpShapePtr->setSubType( nSubType );
118 if( xAttribs->hasAttribute( XML_idx ) )
119 mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() );
120 if ( nSubType )
122 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
123 if ( pPPTShapePtr )
125 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
126 if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
128 // inheriting properties from placeholder objects by cloning shape
129 sal_Int32 nFirstPlaceholder = 0;
130 sal_Int32 nSecondPlaceholder = 0;
131 switch( nSubType )
133 case XML_ctrTitle : // slide/layout
134 nFirstPlaceholder = XML_ctrTitle;
135 nSecondPlaceholder = XML_title;
136 break;
138 case XML_subTitle : // slide/layout
139 nFirstPlaceholder = XML_subTitle;
140 nSecondPlaceholder = XML_title;
141 break;
143 case XML_obj : // slide/layout
144 nFirstPlaceholder = XML_obj;
145 nSecondPlaceholder = XML_body;
146 break;
148 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
149 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
150 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
151 case XML_hdr : // notes/notesmaster/handoutmaster
152 case XML_body : // slide/layout/master/notes/notesmaster
153 case XML_title : // slide/layout/master/
154 case XML_chart : // slide/layout
155 case XML_tbl : // slide/layout
156 case XML_clipArt : // slide/layout
157 case XML_dgm : // slide/layout
158 case XML_media : // slide/layout
159 case XML_sldImg : // notes/notesmaster
160 case XML_pic : // slide/layout
161 nFirstPlaceholder = nSubType;
162 default:
163 break;
165 if ( nFirstPlaceholder )
167 oox::drawingml::ShapePtr pPlaceholder;
168 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
170 if( pPPTShapePtr->getSubTypeIndex().has() )
171 pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
172 if ( !pPlaceholder.get() )
173 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
174 mpSlidePersistPtr->getShapes()->getChildren() );
176 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
178 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
179 if ( pMasterPersist.get() ) {
180 if( pPPTShapePtr->getSubTypeIndex().has() )
181 pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
182 // TODO: Check if this is required for non-notes pages as well...
183 if ( !pPlaceholder.get() || ( pMasterPersist->isNotesPage() && pPlaceholder->getSubType() != nFirstPlaceholder &&
184 pPlaceholder->getSubType() != nSecondPlaceholder ) )
186 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
187 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
191 if ( pPlaceholder.get() )
193 OSL_TRACE("shape %s will get shape reference %s applied", OUStringToOString(mpShapePtr->getId(), RTL_TEXTENCODING_UTF8 ).getStr(), OUStringToOString(pPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
194 mpShapePtr->applyShapeReference( *pPlaceholder.get() );
195 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
196 if ( pPPTShape )
197 pPPTShape->setReferenced( sal_True );
198 pPPTShapePtr->setPlaceholder( pPlaceholder );
205 break;
208 // nvSpPr CT_ShapeNonVisual end
210 case PPT_TOKEN( spPr ):
211 xRet = new PPTShapePropertiesContext( *this, *mpShapePtr );
212 break;
214 case PPT_TOKEN( style ):
215 xRet = new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
216 break;
218 case PPT_TOKEN( txBody ):
220 oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
221 xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True );
222 mpShapePtr->setTextBody( xTextBody );
223 xRet = new oox::drawingml::TextBodyContext( *this, *xTextBody );
224 break;
226 case PPT_TOKEN( txXfrm ):
228 xRet = new oox::drawingml::Transform2DContext( *this, xAttribs, *mpShapePtr, true );
229 break;
233 if( !xRet.is() )
234 xRet.set( this );
236 return xRet;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */