GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / ppt / pptgraphicshapecontext.cxx
blob730ce23967bf47b88ac82d77ed4fc3e3482fb4c5
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 "oox/drawingml/shapestylecontext.hxx"
31 #include "oox/token/namespaces.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/token/tokens.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 PPTGraphicShapeContext::PPTGraphicShapeContext( ContextHandler2Helper& rParent, const SlidePersistPtr pSlidePersistPtr, oox::drawingml::ShapePtr pMasterShapePtr, oox::drawingml::ShapePtr pShapePtr )
51 : oox::drawingml::GraphicShapeContext( rParent, pMasterShapePtr, pShapePtr )
52 , mpSlidePersistPtr( pSlidePersistPtr )
56 // if nFirstPlaceholder can't be found, it will be searched for nSecondPlaceholder
57 static oox::drawingml::ShapePtr findPlaceholder( sal_Int32 nFirstPlaceholder, sal_Int32 nSecondPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes )
59 oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, rShapes );
60 return !nSecondPlaceholder || pPlaceholder.get() ? pPlaceholder : PPTShape::findPlaceholder( nSecondPlaceholder, rShapes );
63 ContextHandlerRef PPTGraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
65 switch( aElementToken )
67 // nvSpPr CT_ShapeNonVisual begin
68 // case NMSP_PPT|XML_drElemPr:
69 // break;
70 case PPT_TOKEN(cNvPr):
71 mpShapePtr->setId( rAttribs.getString( XML_id ).get() );
72 mpShapePtr->setName( rAttribs.getString( XML_name ).get() );
73 break;
74 case PPT_TOKEN(ph):
76 sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
77 mpShapePtr->setSubType( nSubType );
78 OUString sIdx( rAttribs.getString( XML_idx ).get() );
79 sal_Bool bHasIdx = !sIdx.isEmpty();
80 sal_Int32 nIdx = sIdx.toInt32();
81 if( rAttribs.hasAttribute( XML_idx ) )
82 mpShapePtr->setSubTypeIndex( nIdx );
84 if ( nSubType || bHasIdx )
86 PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
87 if ( pPPTShapePtr )
89 oox::ppt::ShapeLocation eShapeLocation = pPPTShapePtr->getShapeLocation();
90 oox::drawingml::ShapePtr pPlaceholder;
92 if ( bHasIdx && eShapeLocation == Slide )
94 // TODO: use id to shape map
95 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
96 if ( pMasterPersist.get() && rAttribs.hasAttribute( XML_idx ) )
97 pPlaceholder = PPTShape::findPlaceholderByIndex( nIdx, pMasterPersist->getShapes()->getChildren() );
99 if ( !pPlaceholder.get() && ( ( eShapeLocation == Slide ) || ( eShapeLocation == Layout ) ) )
101 // inheriting properties from placeholder objects by cloning shape
103 sal_Int32 nFirstPlaceholder = 0;
104 sal_Int32 nSecondPlaceholder = 0;
105 switch( nSubType )
107 case XML_ctrTitle : // slide/layout
108 nFirstPlaceholder = XML_ctrTitle;
109 nSecondPlaceholder = XML_title;
110 break;
111 case XML_subTitle : // slide/layout
112 nFirstPlaceholder = XML_subTitle;
113 nSecondPlaceholder = XML_title;
114 break;
115 case XML_obj : // slide/layout
116 nFirstPlaceholder = XML_body;
117 break;
118 case XML_dt : // slide/layout/master/notes/notesmaster/handoutmaster
119 case XML_sldNum : // slide/layout/master/notes/notesmaster/handoutmaster
120 case XML_ftr : // slide/layout/master/notes/notesmaster/handoutmaster
121 case XML_hdr : // notes/notesmaster/handoutmaster
122 case XML_body : // slide/layout/master/notes/notesmaster
123 case XML_title : // slide/layout/master/
124 case XML_chart : // slide/layout
125 case XML_tbl : // slide/layout
126 case XML_clipArt : // slide/layout
127 case XML_dgm : // slide/layout
128 case XML_media : // slide/layout
129 case XML_sldImg : // notes/notesmaster
130 case XML_pic : // slide/layout
131 nFirstPlaceholder = nSubType;
132 default:
133 break;
135 if ( nFirstPlaceholder )
137 if ( eShapeLocation == Layout ) // for layout objects the referenced object can be found within the same shape tree
138 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, mpSlidePersistPtr->getShapes()->getChildren() );
139 else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
141 SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
142 if ( pMasterPersist.get() )
143 pPlaceholder = findPlaceholder( nFirstPlaceholder, nSecondPlaceholder, pMasterPersist->getShapes()->getChildren() );
147 if ( pPlaceholder.get() )
149 bool bUseText = true;
150 switch( pPlaceholder->getSubType() )
152 case XML_title :
153 case XML_body :
154 case XML_ctrTitle :
155 case XML_subTitle :
156 case XML_dt :
157 case XML_sldNum :
158 case XML_ftr :
159 case XML_hdr :
160 case XML_obj :
161 case XML_chart :
162 case XML_tbl :
163 case XML_clipArt :
164 case XML_dgm :
165 case XML_media :
166 case XML_sldImg :
167 case XML_pic :
168 bUseText = false;
170 mpShapePtr->applyShapeReference( *pPlaceholder.get(), bUseText );
171 PPTShape* pPPTShape = dynamic_cast< PPTShape* >( pPlaceholder.get() );
172 if ( pPPTShape )
173 pPPTShape->setReferenced( sal_True );
174 pPPTShapePtr->setPlaceholder( pPlaceholder );
178 break;
180 // nvSpPr CT_ShapeNonVisual end
182 case PPT_TOKEN(spPr):
183 return new PPTShapePropertiesContext( *this, *mpShapePtr );
185 case PPT_TOKEN(style):
186 return new oox::drawingml::ShapeStyleContext( *this, *mpShapePtr );
188 case PPT_TOKEN(txBody):
190 oox::drawingml::TextBodyPtr xTextBody( new oox::drawingml::TextBody );
191 mpShapePtr->setTextBody( xTextBody );
192 return new oox::drawingml::TextBodyContext( *this, *xTextBody );
196 return GraphicShapeContext::onCreateContext( aElementToken, rAttribs );
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */