GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / drawingml / graphicshapecontext.cxx
blob4cf3366e1808a2d7d8124d98e26da0209bdf404c
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/io/TempFile.hpp>
21 #include "oox/drawingml/graphicshapecontext.hxx"
22 #include <osl/diagnose.h>
24 #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
25 #include "oox/drawingml/customshapeproperties.hxx"
26 #include "oox/drawingml/diagram/diagram.hxx"
27 #include "oox/drawingml/table/tablecontext.hxx"
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "oox/helper/attributelist.hxx"
30 #include "oox/helper/graphichelper.hxx"
31 #include "oox/helper/propertyset.hxx"
32 #include "oox/vml/vmldrawing.hxx"
33 #include "oox/vml/vmlshape.hxx"
34 #include "oox/vml/vmlshapecontainer.hxx"
35 #include "oox/drawingml/fillproperties.hxx"
36 #include "oox/drawingml/transform2dcontext.hxx"
37 #include "oox/helper/binaryinputstream.hxx"
38 #include "oox/helper/binaryoutputstream.hxx"
39 #include <comphelper/processfactory.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::io;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::xml::sax;
47 using namespace ::oox::core;
49 namespace oox {
50 namespace drawingml {
52 // ============================================================================
53 // CT_Picture
55 GraphicShapeContext::GraphicShapeContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
56 : ShapeContext( rParent, pMasterShapePtr, pShapePtr )
60 ContextHandlerRef GraphicShapeContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
62 switch( getBaseToken( aElementToken ) )
64 // CT_ShapeProperties
65 case XML_xfrm:
66 return new Transform2DContext( *this, rAttribs, *mpShapePtr );
67 case XML_blipFill:
68 return new BlipFillContext( *this, rAttribs, mpShapePtr->getGraphicProperties().maBlipProps );
69 case XML_wavAudioFile:
71 getEmbeddedWAVAudioFile( getRelations(), rAttribs.getFastAttributeList(), mpShapePtr->getGraphicProperties().maAudio );
72 if( !mpShapePtr->getGraphicProperties().maAudio.msEmbed.isEmpty() )
74 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
75 Reference< XInputStream > xInStrm( getFilter().openInputStream( mpShapePtr->getGraphicProperties().maAudio.msEmbed ), UNO_SET_THROW );
76 Reference< XTempFile > xTempFile( TempFile::create(xContext) );
77 Reference< XOutputStream > xOutStrm( xTempFile->getOutputStream(), UNO_SET_THROW );
78 BinaryXOutputStream aOutStrm( xOutStrm, false );
79 BinaryXInputStream aInStrm( xInStrm, false );
80 aInStrm.copyToStream( aOutStrm );
82 xTempFile->setRemoveFile( false );
83 mpShapePtr->getGraphicProperties().maAudio.msEmbed = xTempFile->getUri();
86 break;
89 if ((getNamespace( aElementToken ) == NMSP_vml) && mpShapePtr)
91 mpShapePtr->setServiceName("com.sun.star.drawing.CustomShape");
92 CustomShapePropertiesPtr pCstmShpProps
93 (mpShapePtr->getCustomShapeProperties());
95 pCstmShpProps->setShapePresetType( getBaseToken( aElementToken ) );
98 return ShapeContext::onCreateContext( aElementToken, rAttribs );
101 // ============================================================================
102 // CT_GraphicalObjectFrameContext
104 GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler2Helper& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) :
105 ShapeContext( rParent, pMasterShapePtr, pShapePtr ),
106 mbEmbedShapesInChart( bEmbedShapesInChart )
110 ContextHandlerRef GraphicalObjectFrameContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
112 switch( getBaseToken( aElementToken ) )
114 // CT_ShapeProperties
115 case XML_nvGraphicFramePr: // CT_GraphicalObjectFrameNonVisual
116 break;
117 case XML_xfrm: // CT_Transform2D
118 return new Transform2DContext( *this, rAttribs, *mpShapePtr );
119 case XML_graphic: // CT_GraphicalObject
120 return this;
122 case XML_graphicData : // CT_GraphicalObjectData
124 OUString sUri( rAttribs.getString( XML_uri ).get() );
125 if ( sUri == "http://schemas.openxmlformats.org/presentationml/2006/ole" )
126 return new OleObjectGraphicDataContext( *this, mpShapePtr );
127 else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/diagram" )
128 return new DiagramGraphicDataContext( *this, mpShapePtr );
129 else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/chart" )
130 return new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart );
131 else if ( sUri.equalsAscii( "http://schemas.openxmlformats.org/drawingml/2006/table" ) )
132 return new table::TableContext( *this, mpShapePtr );
133 else
135 OSL_TRACE( "OOX: Ignore graphicsData of %s", OUSTRING_TO_CSTR( sUri ) );
136 return 0;
139 break;
142 return ShapeContext::onCreateContext( aElementToken, rAttribs );
145 // ============================================================================
147 OleObjectGraphicDataContext::OleObjectGraphicDataContext( ContextHandler2Helper& rParent, ShapePtr xShape ) :
148 ShapeContext( rParent, ShapePtr(), xShape ),
149 mrOleObjectInfo( xShape->setOleObjectType() )
153 OleObjectGraphicDataContext::~OleObjectGraphicDataContext()
155 /* Register the OLE shape at the VML drawing, this prevents that the
156 related VML shape converts the OLE object by itself. */
157 if( !mrOleObjectInfo.maShapeId.isEmpty() )
158 if( ::oox::vml::Drawing* pVmlDrawing = getFilter().getVmlDrawing() )
159 pVmlDrawing->registerOleObject( mrOleObjectInfo );
162 ContextHandlerRef OleObjectGraphicDataContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
164 switch( nElement )
166 case PPT_TOKEN( oleObj ):
168 mrOleObjectInfo.maShapeId = rAttribs.getXString( XML_spid, OUString() );
169 const Relation* pRelation = getRelations().getRelationFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
170 OSL_ENSURE( pRelation, "OleObjectGraphicDataContext::createFastChildContext - missing relation for OLE object" );
171 if( pRelation )
173 mrOleObjectInfo.mbLinked = pRelation->mbExternal;
174 if( pRelation->mbExternal )
176 mrOleObjectInfo.maTargetLink = getFilter().getAbsoluteUrl( pRelation->maTarget );
178 else
180 OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
181 if( !aFragmentPath.isEmpty() )
182 getFilter().importBinaryData( mrOleObjectInfo.maEmbeddedData, aFragmentPath );
185 mrOleObjectInfo.maName = rAttribs.getXString( XML_name, OUString() );
186 mrOleObjectInfo.maProgId = rAttribs.getXString( XML_progId, OUString() );
187 mrOleObjectInfo.mbShowAsIcon = rAttribs.getBool( XML_showAsIcon, false );
188 return this;
190 break;
192 case PPT_TOKEN( embed ):
193 OSL_ENSURE( !mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
194 break;
196 case PPT_TOKEN( link ):
197 OSL_ENSURE( mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
198 mrOleObjectInfo.mbAutoUpdate = rAttribs.getBool( XML_updateAutomatic, false );
199 break;
200 case PPT_TOKEN( pic ):
201 return new GraphicShapeContext( *this, mpMasterShapePtr, mpShapePtr );
202 break;
204 return 0;
207 // ============================================================================
209 DiagramGraphicDataContext::DiagramGraphicDataContext( ContextHandler2Helper& rParent, ShapePtr pShapePtr )
210 : ShapeContext( rParent, ShapePtr(), pShapePtr )
212 pShapePtr->setDiagramType();
215 DiagramGraphicDataContext::~DiagramGraphicDataContext()
219 ContextHandlerRef DiagramGraphicDataContext::onCreateContext( ::sal_Int32 aElementToken, const AttributeList& rAttribs )
221 switch( aElementToken )
223 case DGM_TOKEN( relIds ):
225 msDm = rAttribs.getString( R_TOKEN( dm ) ).get();
226 msLo = rAttribs.getString( R_TOKEN( lo ) ).get();
227 msQs = rAttribs.getString( R_TOKEN( qs ) ).get();
228 msCs = rAttribs.getString( R_TOKEN( cs ) ).get();
229 loadDiagram(mpShapePtr,
230 getFilter(),
231 getFragmentPathFromRelId( msDm ),
232 getFragmentPathFromRelId( msLo ),
233 getFragmentPathFromRelId( msQs ),
234 getFragmentPathFromRelId( msCs ));
235 SAL_INFO("oox.drawingml", OSL_THIS_FUNC
236 << "diagram added shape " << mpShapePtr->getName()
237 << " of type " << mpShapePtr->getServiceName()
238 << ", size (" << mpShapePtr->getPosition().X
239 << "," << mpShapePtr->getPosition().Y
240 << "," << mpShapePtr->getSize().Width
241 << "," << mpShapePtr->getSize().Height
242 <<")");
243 break;
245 default:
246 break;
249 return ShapeContext::onCreateContext( aElementToken, rAttribs );
252 // ============================================================================
254 ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler2Helper& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) :
255 ShapeContext( rParent, ShapePtr(), rxShape ),
256 mrChartShapeInfo( rxShape->setChartType( bEmbedShapes ) )
260 ContextHandlerRef ChartGraphicDataContext::onCreateContext( ::sal_Int32 nElement, const AttributeList& rAttribs )
262 if( nElement == C_TOKEN( chart ) )
264 mrChartShapeInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
266 return 0;
269 // ============================================================================
271 } // namespace drawingml
272 } // namespace oox
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */