Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / ppt / pptgraphicshapecontext.cxx
blobf40e6468ba9c42729af770bbab1c830407a7e148
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/ppt/pptshape.hxx>
27 #include <oox/ppt/pptgraphicshapecontext.hxx>
28 #include <oox/ppt/pptshapepropertiescontext.hxx>
29 #include <oox/ppt/slidepersist.hxx>
30 #include <drawingml/shapestylecontext.hxx>
31 #include <drawingml/misccontexts.hxx>
32 #include <drawingml/lineproperties.hxx>
33 #include <oox/drawingml/drawingmltypes.hxx>
34 #include <drawingml/customshapegeometry.hxx>
35 #include <drawingml/textbodycontext.hxx>
36 #include <oox/helper/attributelist.hxx>
37 #include <oox/token/namespaces.hxx>
38 #include <oox/token/tokens.hxx>
40 using namespace oox::core;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::drawing;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::text;
46 using namespace ::com::sun::star::xml::sax;
48 namespace oox { namespace ppt {
50 // CT_Shape
51 PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler2Helper const & rParent, const SlidePersistPtr& rSlidePersistPtr, const oox::drawingml::ShapePtr& pMasterShapePtr, const oox::drawingml::ShapePtr& pShapePtr )
52 : oox::drawingml::GraphicShapeContext( rParent, pMasterShapePtr, pShapePtr )
53 , mpSlidePersistPtr( rSlidePersistPtr )
57 ContextHandlerRef PPTGraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
59 switch( aElementToken )
61 // nvSpPr CT_ShapeNonVisual begin
62 // case NMSP_PPT|XML_drElemPr:
63 // break;
64 case PPT_TOKEN(cNvPr):
65 mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
66 mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
67 break;
68 case PPT_TOKEN(ph):
70 sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
71 mpShapePtr->setSubType( nSubType );
72 OUString sIdx( rAttribs.getString( XML_idx ).get() );
73 bool bHasIdx = !sIdx.isEmpty();
74 sal_Int32 nIdx = sIdx.toInt32();
75 if( rAttribs.hasAttribute( XML_idx ) )
76 mpShapePtr->setSubTypeIndex( nIdx );
78 if ( nSubType || bHasIdx )
80 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
81 if ( pPPTShapePtr )
83 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
84 oox::drawingml::ShapePtr pPlaceholder;
86 if ( bHasIdx && eShapeLocation == Slide )
88 // TODO: use id to shape map
89 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
90 if ( pMasterPersist.get() && rAttribs.hasAttribute( XML_idx ) )
91 pPlaceholder = PPTShape::findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
93 if ( !pPlaceholder.get() && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
95 // inheriting properties from placeholder objects by cloning shape
97 sal_Int32 nFirstPlaceholder = 0;
98 sal_Int32 nSecondPlaceholder = 0;
99 switch( nSubType )
101 case XML_ctrTitle : // slide/layout
102 nFirstPlaceholder = XML_ctrTitle;
103 nSecondPlaceholder = XML_title;
104 break;
105 case XML_subTitle : // slide/layout
106 nFirstPlaceholder = XML_subTitle;
107 nSecondPlaceholder = XML_title;
108 break;
109 case XML_obj : // slide/layout
110 nFirstPlaceholder = XML_body;
111 break;
112 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
113 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
114 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
115 case XML_hdr : // notes/notesmaster/handoutmaster
116 case XML_body : // slide/layout/master/notes/notesmaster
117 case XML_title : // slide/layout/master/
118 case XML_chart : // slide/layout
119 case XML_tbl : // slide/layout
120 case XML_clipArt : // slide/layout
121 case XML_dgm : // slide/layout
122 case XML_media : // slide/layout
123 case XML_sldImg : // notes/notesmaster
124 case XML_pic : // slide/layout
125 nFirstPlaceholder = nSubType;
126 break;
127 default:
128 break;
130 if ( nFirstPlaceholder )
132 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 );
135 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
137 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
138 if ( pMasterPersist.get() )
139 pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
140 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
144 if ( pPlaceholder.get() )
146 bool bUseText = true;
147 switch( pPlaceholder->getSubType() )
149 case XML_title :
150 case XML_body :
151 case XML_ctrTitle :
152 case XML_subTitle :
153 case XML_dt :
154 case XML_sldNum :
155 case XML_ftr :
156 case XML_hdr :
157 case XML_obj :
158 case XML_chart :
159 case XML_tbl :
160 case XML_clipArt :
161 case XML_dgm :
162 case XML_media :
163 case XML_sldImg :
164 case XML_pic :
165 bUseText = false;
167 mpShapePtr->applyShapeReference( *pPlaceholder, bUseText );
168 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
169 if ( pPPTShape )
170 pPPTShape->setReferenced( true );
171 pPPTShapePtr->setPlaceholder( pPlaceholder );
175 break;
177 // nvSpPr CT_ShapeNonVisual end
179 case PPT_TOKEN(spPr):
180 return new PPTShapePropertiesContext( *this, *mpShapePtr );
182 case PPT_TOKEN(style):
183 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
185 case PPT_TOKEN(txBody):
187 oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
188 mpShapePtr->setTextBody( xTextBody );
189 return new oox::drawingml::TextBodyContext( *this, *xTextBody );
193 return GraphicShapeContext::onCreateContext( aElementToken, rAttribs );
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */