fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / graphicshapecontext.cxx
blob2b46302296c87fa50b49aea059e2f621ed8c8409
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( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr )
56 : ShapeContext( rParent, pMasterShapePtr, pShapePtr )
60 Reference< XFastContextHandler > GraphicShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
62 Reference< XFastContextHandler > xRet;
64 switch( getBaseToken( aElementToken ) )
66 // CT_ShapeProperties
67 case XML_xfrm:
68 xRet.set( new Transform2DContext( *this, xAttribs, *mpShapePtr ) );
69 break;
70 case XML_blipFill:
71 xRet.set( new BlipFillContext( *this, xAttribs, mpShapePtr->getGraphicProperties().maBlipProps ) );
72 break;
73 case XML_wavAudioFile:
75 getEmbeddedWAVAudioFile( getRelations(), xAttribs, mpShapePtr->getGraphicProperties().maAudio );
76 if( !mpShapePtr->getGraphicProperties().maAudio.msEmbed.isEmpty() )
78 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
79 Reference< XInputStream > xInStrm( getFilter().openInputStream( mpShapePtr->getGraphicProperties().maAudio.msEmbed ), UNO_SET_THROW );
80 Reference< XTempFile > xTempFile( TempFile::create(xContext) );
81 Reference< XOutputStream > xOutStrm( xTempFile->getOutputStream(), UNO_SET_THROW );
82 BinaryXOutputStream aOutStrm( xOutStrm, false );
83 BinaryXInputStream aInStrm( xInStrm, false );
84 aInStrm.copyToStream( aOutStrm );
86 xTempFile->setRemoveFile( false );
87 mpShapePtr->getGraphicProperties().maAudio.msEmbed = xTempFile->getUri();
90 break;
93 if ((getNamespace( aElementToken ) == NMSP_vml) && mpShapePtr)
95 mpShapePtr->setServiceName("com.sun.star.drawing.CustomShape");
96 CustomShapePropertiesPtr pCstmShpProps
97 (mpShapePtr->getCustomShapeProperties());
99 pCstmShpProps->setShapePresetType( getBaseToken( aElementToken ) );
102 if( !xRet.is() )
103 xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) );
105 return xRet;
108 // ============================================================================
109 // CT_GraphicalObjectFrameContext
111 GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) :
112 ShapeContext( rParent, pMasterShapePtr, pShapePtr ),
113 mbEmbedShapesInChart( bEmbedShapesInChart )
117 Reference< XFastContextHandler > GraphicalObjectFrameContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
119 Reference< XFastContextHandler > xRet;
121 switch( getBaseToken( aElementToken ) )
123 // CT_ShapeProperties
124 case XML_nvGraphicFramePr: // CT_GraphicalObjectFrameNonVisual
125 break;
126 case XML_xfrm: // CT_Transform2D
127 xRet.set( new Transform2DContext( *this, xAttribs, *mpShapePtr ) );
128 break;
129 case XML_graphic: // CT_GraphicalObject
130 xRet.set( this );
131 break;
133 case XML_graphicData : // CT_GraphicalObjectData
135 OUString sUri( xAttribs->getOptionalValue( XML_uri ) );
136 if ( sUri == "http://schemas.openxmlformats.org/presentationml/2006/ole" )
137 xRet.set( new OleObjectGraphicDataContext( *this, mpShapePtr ) );
138 else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/diagram" )
139 xRet.set( new DiagramGraphicDataContext( *this, mpShapePtr ) );
140 else if ( sUri == "http://schemas.openxmlformats.org/drawingml/2006/chart" )
141 xRet.set( new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart ) );
142 else if ( sUri.compareToAscii( "http://schemas.openxmlformats.org/drawingml/2006/table" ) == 0 )
143 xRet.set( new table::TableContext( *this, mpShapePtr ) );
144 else
146 OSL_TRACE( "OOX: Ignore graphicsData of %s", OUSTRING_TO_CSTR( sUri ) );
147 return xRet;
150 break;
152 if( !xRet.is() )
153 xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) );
155 return xRet;
158 // ============================================================================
160 OleObjectGraphicDataContext::OleObjectGraphicDataContext( ContextHandler& rParent, ShapePtr xShape ) :
161 ShapeContext( rParent, ShapePtr(), xShape ),
162 mrOleObjectInfo( xShape->setOleObjectType() )
166 OleObjectGraphicDataContext::~OleObjectGraphicDataContext()
168 /* Register the OLE shape at the VML drawing, this prevents that the
169 related VML shape converts the OLE object by itself. */
170 if( !mrOleObjectInfo.maShapeId.isEmpty() )
171 if( ::oox::vml::Drawing* pVmlDrawing = getFilter().getVmlDrawing() )
172 pVmlDrawing->registerOleObject( mrOleObjectInfo );
175 Reference< XFastContextHandler > OleObjectGraphicDataContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
177 Reference< XFastContextHandler > xRet;
178 AttributeList aAttribs( xAttribs );
180 switch( nElement )
182 case PPT_TOKEN( oleObj ):
184 mrOleObjectInfo.maShapeId = aAttribs.getXString( XML_spid, OUString() );
185 const Relation* pRelation = getRelations().getRelationFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) );
186 OSL_ENSURE( pRelation, "OleObjectGraphicDataContext::createFastChildContext - missing relation for OLE object" );
187 if( pRelation )
189 mrOleObjectInfo.mbLinked = pRelation->mbExternal;
190 if( pRelation->mbExternal )
192 mrOleObjectInfo.maTargetLink = getFilter().getAbsoluteUrl( pRelation->maTarget );
194 else
196 OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
197 if( !aFragmentPath.isEmpty() )
198 getFilter().importBinaryData( mrOleObjectInfo.maEmbeddedData, aFragmentPath );
201 mrOleObjectInfo.maName = aAttribs.getXString( XML_name, OUString() );
202 mrOleObjectInfo.maProgId = aAttribs.getXString( XML_progId, OUString() );
203 mrOleObjectInfo.mbShowAsIcon = aAttribs.getBool( XML_showAsIcon, false );
204 xRet.set( this );
206 break;
208 case PPT_TOKEN( embed ):
209 OSL_ENSURE( !mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
210 break;
212 case PPT_TOKEN( link ):
213 OSL_ENSURE( mrOleObjectInfo.mbLinked, "OleObjectGraphicDataContext::createFastChildContext - unexpected child element" );
214 mrOleObjectInfo.mbAutoUpdate = aAttribs.getBool( XML_updateAutomatic, false );
215 break;
216 case PPT_TOKEN( pic ):
217 xRet.set( new GraphicShapeContext( *this, mpMasterShapePtr, mpShapePtr ) );
218 break;
220 return xRet;
223 // ============================================================================
225 DiagramGraphicDataContext::DiagramGraphicDataContext( ContextHandler& rParent, ShapePtr pShapePtr )
226 : ShapeContext( rParent, ShapePtr(), pShapePtr )
228 pShapePtr->setDiagramType();
231 DiagramGraphicDataContext::~DiagramGraphicDataContext()
235 Reference< XFastContextHandler > DiagramGraphicDataContext::createFastChildContext( ::sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs )
236 throw (SAXException, RuntimeException)
238 Reference< XFastContextHandler > xRet;
240 switch( aElementToken )
242 case DGM_TOKEN( relIds ):
244 msDm = xAttribs->getOptionalValue( R_TOKEN( dm ) );
245 msLo = xAttribs->getOptionalValue( R_TOKEN( lo ) );
246 msQs = xAttribs->getOptionalValue( R_TOKEN( qs ) );
247 msCs = xAttribs->getOptionalValue( R_TOKEN( cs ) );
248 loadDiagram(mpShapePtr,
249 getFilter(),
250 getFragmentPathFromRelId( msDm ),
251 getFragmentPathFromRelId( msLo ),
252 getFragmentPathFromRelId( msQs ),
253 getFragmentPathFromRelId( msCs ));
254 OSL_TRACE("diagram added shape %s of type %s, size (%d,%d,%d,%d)",
255 OUSTRING_TO_CSTR( mpShapePtr->getName() ),
256 OUSTRING_TO_CSTR( mpShapePtr->getServiceName() ),
257 mpShapePtr->getPosition().X,
258 mpShapePtr->getPosition().Y,
259 mpShapePtr->getSize().Width,
260 mpShapePtr->getSize().Height);
261 break;
263 default:
264 break;
267 if( !xRet.is() )
268 xRet.set( ShapeContext::createFastChildContext( aElementToken, xAttribs ) );
270 return xRet;
273 // ============================================================================
275 ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) :
276 ShapeContext( rParent, ShapePtr(), rxShape ),
277 mrChartShapeInfo( rxShape->setChartType( bEmbedShapes ) )
281 Reference< XFastContextHandler > ChartGraphicDataContext::createFastChildContext( ::sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
282 throw (SAXException, RuntimeException)
284 if( nElement == C_TOKEN( chart ) )
286 AttributeList aAttribs( rxAttribs );
287 mrChartShapeInfo.maFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) );
289 return 0;
292 // ============================================================================
294 } // namespace drawingml
295 } // namespace oox
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */