Use correct object
[LibreOffice.git] / oox / source / ppt / pptshapecontext.cxx
blob6caed1728d01e47d1e0fadaba341de3b87b35aa3
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 <sal/log.hxx>
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/ppt/pptshape.hxx>
24 #include <oox/ppt/pptshapecontext.hxx>
25 #include <oox/ppt/pptshapepropertiescontext.hxx>
26 #include <oox/ppt/slidepersist.hxx>
27 #include <drawingml/shapestylecontext.hxx>
28 #include <oox/drawingml/drawingmltypes.hxx>
29 #include <drawingml/textbodycontext.hxx>
30 #include <drawingml/transform2dcontext.hxx>
31 #include <oox/token/namespaces.hxx>
32 #include <oox/token/properties.hxx>
33 #include <oox/token/tokens.hxx>
34 #include <utility>
36 using namespace oox::core;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
40 namespace oox::ppt {
42 // CT_Shape
43 PPTShapeContext::PPTShapeContext( ContextHandler2Helper const & rParent, SlidePersistPtr pSlidePersistPtr, const oox::drawingml::ShapePtr& pMasterShapePtr, const oox::drawingml::ShapePtr& pShapePtr )
44 : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
45 , mpSlidePersistPtr(std::move( pSlidePersistPtr ))
49 ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
51 if( getNamespace( aElementToken ) == NMSP_dsp )
52 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
54 switch( aElementToken )
56 // nvSpPr CT_ShapeNonVisual begin
57 // case PPT_TOKEN( drElemPr ):
58 // break;
59 case PPT_TOKEN( cNvPr ):
61 mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
62 mpShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) );
63 mpShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
64 break;
66 case PPT_TOKEN( ph ):
68 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
69 std::optional< sal_Int32 > oSubType( rAttribs.getToken( XML_type) );
70 sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
71 oox::drawingml::ShapePtr pTmpPlaceholder;
73 mpShapePtr->setSubType( nSubType );
75 if( rAttribs.hasAttribute( XML_idx ) )
77 sal_Int32 nSubTypeIndex = rAttribs.getInteger( XML_idx, 0 );
78 mpShapePtr->setSubTypeIndex( nSubTypeIndex );
80 if(!oSubType.has_value() && pMasterPersist)
82 pTmpPlaceholder = PPTShape::findPlaceholderByIndex( nSubTypeIndex, pMasterPersist->getShapes()->getChildren() );
84 if(pTmpPlaceholder)
85 nSubType = pTmpPlaceholder->getSubType(); // When we don't have type attribute on slide but have on slidelayout we have to use it instead of default type
89 if ( nSubType )
91 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
92 if ( pPPTShapePtr )
94 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
95 if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
97 // inheriting properties from placeholder objects by cloning shape
98 sal_Int32 nFirstPlaceholder = 0;
99 sal_Int32 nSecondPlaceholder = 0;
100 switch( nSubType )
102 case XML_ctrTitle : // slide/layout
103 nFirstPlaceholder = XML_ctrTitle;
104 nSecondPlaceholder = XML_title;
105 break;
107 case XML_subTitle : // slide/layout
108 nFirstPlaceholder = XML_subTitle;
109 nSecondPlaceholder = XML_body;
110 break;
112 case XML_obj : // slide/layout
113 nFirstPlaceholder = XML_obj;
114 nSecondPlaceholder = XML_body;
115 break;
117 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
118 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
119 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
120 case XML_hdr : // notes/notesmaster/handoutmaster
121 case XML_body : // slide/layout/master/notes/notesmaster
122 case XML_title : // slide/layout/master/
123 case XML_chart : // slide/layout
124 case XML_tbl : // slide/layout
125 case XML_clipArt : // slide/layout
126 case XML_dgm : // slide/layout
127 case XML_media : // slide/layout
128 case XML_sldImg : // notes/notesmaster
129 case XML_pic : // slide/layout
130 nFirstPlaceholder = nSubType;
131 break;
132 default:
133 break;
135 if ( nFirstPlaceholder )
137 oox::drawingml::ShapePtr pPlaceholder;
138 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
140 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
141 pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren(), true );
143 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
145 if ( pMasterPersist )
147 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
148 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
151 if ( pPlaceholder )
153 SAL_INFO("oox.ppt","shape " << mpShapePtr->getId() <<
154 " will get shape reference " << pPlaceholder->getId() << " applied");
155 mpShapePtr->applyShapeReference( *pPlaceholder );
156 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
157 if ( pPPTShape )
158 pPPTShape->setReferenced( true );
159 pPPTShapePtr->setPlaceholder( pPlaceholder );
166 break;
169 // nvSpPr CT_ShapeNonVisual end
171 case PPT_TOKEN( spPr ):
172 return new PPTShapePropertiesContext( *this, *mpShapePtr );
174 case PPT_TOKEN( style ):
175 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
177 case PPT_TOKEN( txBody ):
179 oox::drawingml::TextBodyPtr xTextBody = std::make_shared<oox::drawingml::TextBody>( mpShapePtr->getTextBody() );
180 xTextBody->getTextProperties().maPropertyMap.setProperty( PROP_FontIndependentLineSpacing, true );
181 mpShapePtr->setTextBody( xTextBody );
182 return new oox::drawingml::TextBodyContext( *this, mpShapePtr );
184 case PPT_TOKEN( txXfrm ):
186 return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
190 return ShapeContext::onCreateContext(aElementToken, rAttribs);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */