Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / ppt / pptshapecontext.cxx
blob81e0cbb71fa8fb5b604ea417c8a05eb3436abfaa
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 "drawingml/shapestylecontext.hxx"
32 #include "drawingml/misccontexts.hxx"
33 #include "drawingml/lineproperties.hxx"
34 #include "oox/drawingml/drawingmltypes.hxx"
35 #include "drawingml/customshapegeometry.hxx"
36 #include "drawingml/textbodycontext.hxx"
37 #include "drawingml/transform2dcontext.hxx"
38 #include <oox/token/namespaces.hxx>
39 #include <oox/token/properties.hxx>
40 #include <oox/token/tokens.hxx>
42 using namespace oox::core;
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::text;
48 using namespace ::com::sun::star::xml::sax;
50 namespace oox { namespace ppt {
52 // CT_Shape
53 PPTShapeContext::PPTShapeContext( ContextHandler2Helper& rParent, const SlidePersistPtr& rSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
54 : oox::drawingml::ShapeContext( rParent, pMasterShapePtr, pShapePtr )
55 , mpSlidePersistPtr( rSlidePersistPtr )
59 ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
61 if( getNamespace( aElementToken ) == NMSP_dsp )
62 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
64 switch( aElementToken )
66 // nvSpPr CT_ShapeNonVisual begin
67 // case PPT_TOKEN( drElemPr ):
68 // break;
69 case PPT_TOKEN( cNvPr ):
71 mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
72 mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
73 mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
74 break;
76 case PPT_TOKEN( ph ):
78 sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
79 mpShapePtr->setSubType( nSubType );
80 if( rAttribs.hasAttribute( XML_idx ) )
81 mpShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
82 if ( nSubType )
84 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
85 if ( pPPTShapePtr )
87 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
88 if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
90 // inheriting properties from placeholder objects by cloning shape
91 sal_Int32 nFirstPlaceholder = 0;
92 sal_Int32 nSecondPlaceholder = 0;
93 switch( nSubType )
95 case XML_ctrTitle : // slide/layout
96 nFirstPlaceholder = XML_ctrTitle;
97 nSecondPlaceholder = XML_title;
98 break;
100 case XML_subTitle : // slide/layout
101 nFirstPlaceholder = XML_subTitle;
102 nSecondPlaceholder = XML_body;
103 break;
105 case XML_obj : // slide/layout
106 nFirstPlaceholder = XML_obj;
107 nSecondPlaceholder = XML_body;
108 break;
110 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
111 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
112 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
113 case XML_hdr : // notes/notesmaster/handoutmaster
114 case XML_body : // slide/layout/master/notes/notesmaster
115 case XML_title : // slide/layout/master/
116 case XML_chart : // slide/layout
117 case XML_tbl : // slide/layout
118 case XML_clipArt : // slide/layout
119 case XML_dgm : // slide/layout
120 case XML_media : // slide/layout
121 case XML_sldImg : // notes/notesmaster
122 case XML_pic : // slide/layout
123 nFirstPlaceholder = nSubType;
124 break;
125 default:
126 break;
128 if ( nFirstPlaceholder )
130 oox::drawingml::ShapePtr pPlaceholder;
131 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
133 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
134 pPPTShapePtr->getSubTypeIndex(), mpSlidePersistPtr->getShapes()->getChildren(), true );
136 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
138 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
139 if ( pMasterPersist.get() )
141 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
142 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
145 if ( pPlaceholder.get() )
147 SAL_INFO("oox.ppt","shape " << mpShapePtr->getId() <<
148 " will get shape reference " << pPlaceholder->getId() << " applied");
149 mpShapePtr->applyShapeReference( *pPlaceholder.get() );
150 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
151 if ( pPPTShape )
152 pPPTShape->setReferenced( true );
153 pPPTShapePtr->setPlaceholder( pPlaceholder );
160 break;
163 // nvSpPr CT_ShapeNonVisual end
165 case PPT_TOKEN( spPr ):
166 return new PPTShapePropertiesContext( *this, *mpShapePtr );
168 case PPT_TOKEN( style ):
169 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
171 case PPT_TOKEN( txBody ):
173 oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
174 xTextBody->getTextProperties().maPropertyMap.setProperty( PROP_FontIndependentLineSpacing, true );
175 mpShapePtr->setTextBody( xTextBody );
176 return new oox::drawingml::TextBodyContext( *this, *xTextBody );
178 case PPT_TOKEN( txXfrm ):
180 return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
184 return this;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */