GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / ppt / pptshapecontext.cxx
blobf5a1e903a1af5d60d77ab99621721658c4eb2c0e
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( ContextHandler2Helper& 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 == 0 )
67 aChoiceShapePtr1 = *aRevIter;
68 else if( aChoiceShapePtr2 == 0 )
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 == 0 )
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 ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
97 if( getNamespace( aElementToken ) == NMSP_dsp )
98 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
100 switch( aElementToken )
102 // nvSpPr CT_ShapeNonVisual begin
103 // case PPT_TOKEN( drElemPr ):
104 // break;
105 case PPT_TOKEN( cNvPr ):
107 mpShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
108 mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
109 mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
110 break;
112 case PPT_TOKEN( ph ):
114 sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
115 mpShapePtr->setSubType( nSubType );
116 if( rAttribs.hasAttribute( XML_idx ) )
117 mpShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
118 if ( nSubType )
120 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
121 if ( pPPTShapePtr )
123 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
124 if ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) )
126 // inheriting properties from placeholder objects by cloning shape
127 sal_Int32 nFirstPlaceholder = 0;
128 sal_Int32 nSecondPlaceholder = 0;
129 switch( nSubType )
131 case XML_ctrTitle : // slide/layout
132 nFirstPlaceholder = XML_ctrTitle;
133 nSecondPlaceholder = XML_title;
134 break;
136 case XML_subTitle : // slide/layout
137 nFirstPlaceholder = XML_subTitle;
138 nSecondPlaceholder = XML_title;
139 break;
141 case XML_obj : // slide/layout
142 nFirstPlaceholder = XML_obj;
143 nSecondPlaceholder = XML_body;
144 break;
146 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
147 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
148 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
149 case XML_hdr : // notes/notesmaster/handoutmaster
150 case XML_body : // slide/layout/master/notes/notesmaster
151 case XML_title : // slide/layout/master/
152 case XML_chart : // slide/layout
153 case XML_tbl : // slide/layout
154 case XML_clipArt : // slide/layout
155 case XML_dgm : // slide/layout
156 case XML_media : // slide/layout
157 case XML_sldImg : // notes/notesmaster
158 case XML_pic : // slide/layout
159 nFirstPlaceholder = nSubType;
160 default:
161 break;
163 if ( nFirstPlaceholder )
165 oox::drawingml::ShapePtr pPlaceholder;
166 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
168 if( pPPTShapePtr->getSubTypeIndex().has() )
169 pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), mpSlidePersistPtr->getShapes()->getChildren() );
170 if ( !pPlaceholder.get() )
171 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pPPTShapePtr->getSubTypeIndex(),
172 mpSlidePersistPtr->getShapes()->getChildren() );
174 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
176 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
177 if ( pMasterPersist.get() ) {
178 if( pPPTShapePtr->getSubTypeIndex().has() )
179 pPlaceholder = PPTShape::findPlaceholderByIndex( pPPTShapePtr->getSubTypeIndex().get(), pMasterPersist->getShapes()->getChildren() );
180 // TODO: Check if this is required for non-notes pages as well...
181 if ( !pPlaceholder.get() || ( pMasterPersist->isNotesPage() && pPlaceholder->getSubType() != nFirstPlaceholder &&
182 pPlaceholder->getSubType() != nSecondPlaceholder ) )
184 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
185 pPPTShapePtr->getSubTypeIndex(), pMasterPersist->getShapes()->getChildren() );
189 if ( pPlaceholder.get() )
191 OSL_TRACE("shape %s will get shape reference %s applied", OUStringToOString(mpShapePtr->getId(), RTL_TEXTENCODING_UTF8 ).getStr(), OUStringToOString(pPlaceholder->getId(), RTL_TEXTENCODING_UTF8 ).getStr());
192 mpShapePtr->applyShapeReference( *pPlaceholder.get() );
193 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
194 if ( pPPTShape )
195 pPPTShape->setReferenced( sal_True );
196 pPPTShapePtr->setPlaceholder( pPlaceholder );
203 break;
206 // nvSpPr CT_ShapeNonVisual end
208 case PPT_TOKEN( spPr ):
209 return new PPTShapePropertiesContext( *this, *mpShapePtr );
211 case PPT_TOKEN( style ):
212 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
214 case PPT_TOKEN( txBody ):
216 oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody( mpShapePtr->getTextBody() ) );
217 xTextBody->getTextProperties().maPropertyMap[ PROP_FontIndependentLineSpacing ] <<= static_cast< sal_Bool >( sal_True );
218 mpShapePtr->setTextBody( xTextBody );
219 return new oox::drawingml::TextBodyContext( *this, *xTextBody );
221 case PPT_TOKEN( txXfrm ):
223 return new oox::drawingml::Transform2DContext( *this, rAttribs, *mpShapePtr, true );
227 return this;
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */