Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / oox / source / ppt / pptshapegroupcontext.cxx
blobef8934835bedd6a2d2a5474ab166f64469561574
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 <memory>
21 #include <com/sun/star/xml/sax/FastToken.hpp>
23 #include <oox/core/xmlfilterbase.hxx>
24 #include <oox/core/fragmenthandler2.hxx>
25 #include <oox/helper/attributelist.hxx>
26 #include <oox/ppt/pptshape.hxx>
27 #include <oox/ppt/pptgraphicshapecontext.hxx>
28 #include <oox/ppt/pptshapecontext.hxx>
29 #include <oox/ppt/pptshapegroupcontext.hxx>
30 #include <oox/drawingml/graphicshapecontext.hxx>
31 #include <oox/drawingml/drawingmltypes.hxx>
32 #include <drawingml/shapepropertiescontext.hxx>
33 #include <oox/drawingml/connectorshapecontext.hxx>
34 #include <drawingml/fillproperties.hxx>
35 #include "extdrawingfragmenthandler.hxx"
36 #include <oox/token/namespaces.hxx>
37 #include <oox/token/tokens.hxx>
38 #include <utility>
40 using namespace oox::core;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::xml::sax;
44 namespace oox::ppt {
46 PPTShapeGroupContext::PPTShapeGroupContext(
47 FragmentHandler2 const & rParent,
48 oox::ppt::SlidePersistPtr pSlidePersistPtr,
49 const ShapeLocation eShapeLocation,
50 const oox::drawingml::ShapePtr& pMasterShapePtr,
51 const oox::drawingml::ShapePtr& pGroupShapePtr )
52 : ShapeGroupContext( rParent, pMasterShapePtr, pGroupShapePtr )
53 , mpSlidePersistPtr(std::move( pSlidePersistPtr ))
54 , meShapeLocation( eShapeLocation )
58 ContextHandlerRef PPTShapeGroupContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
60 if( getNamespace( aElementToken ) == NMSP_dsp )
61 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
63 switch( aElementToken )
65 case OOX_TOKEN(dml, extLst):
66 case OOX_TOKEN(dml, ext):
67 break;
68 case OOX_TOKEN(adec, decorative):
70 mpGroupShapePtr->setDecorative(rAttribs.getBool(XML_val, false));
72 break;
73 case PPT_TOKEN( cNvPr ):
75 // don't override SmartArt properties for embedded drawing's spTree
76 mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
77 if (mpGroupShapePtr->getId().isEmpty())
78 mpGroupShapePtr->setId(rAttribs.getStringDefaulted(XML_id));
79 if (mpGroupShapePtr->getName().isEmpty())
80 mpGroupShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
81 break;
83 case PPT_TOKEN( ph ):
84 mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
85 if( rAttribs.hasAttribute( XML_idx ) )
86 mpGroupShapePtr->setSubTypeIndex( rAttribs.getInteger( XML_idx, 0 ) );
87 break;
88 // nvSpPr CT_ShapeNonVisual end
90 case PPT_TOKEN( grpSpPr ):
91 return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr );
92 case PPT_TOKEN( spPr ):
93 return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr );
95 case PPT_TOKEN( style ):
96 return new ShapeStyleContext( getParser() );
98 case PPT_TOKEN( cxnSp ): // connector shape
100 auto pShape = std::make_shared<PPTShape>(meShapeLocation, u"com.sun.star.drawing.ConnectorShape"_ustr);
101 return new oox::drawingml::ConnectorShapeContext(*this, mpGroupShapePtr, pShape,
102 pShape->getConnectorShapeProperties());
104 case PPT_TOKEN( grpSp ): // group shape
105 return new PPTShapeGroupContext( *this, mpSlidePersistPtr, meShapeLocation, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.GroupShape"_ustr ) );
106 case PPT_TOKEN( sp ): // Shape
108 auto pShape = std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.CustomShape"_ustr );
109 bool bUseBgFill = rAttribs.getBool(XML_useBgFill, false);
110 pShape->getFillProperties().moUseBgFill = bUseBgFill;
111 if (bUseBgFill)
113 pShape->getFillProperties().moFillType = XML_noFill;
115 pShape->setModelId(rAttribs.getStringDefaulted( XML_modelId ));
116 return new PPTShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, pShape );
118 case PPT_TOKEN( pic ): // CT_Picture
119 return new PPTGraphicShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.GraphicObjectShape"_ustr ) );
120 case PPT_TOKEN( graphicFrame ): // CT_GraphicalObjectFrame
122 pGraphicShape = std::make_shared<PPTShape>( meShapeLocation, u"com.sun.star.drawing.OLE2Shape"_ustr );
123 return new oox::drawingml::GraphicalObjectFrameContext( *this, mpGroupShapePtr, pGraphicShape, true );
127 return this;
130 void PPTShapeGroupContext::importExtDrawings( )
132 if( !pGraphicShape )
133 return;
135 for (auto const& extDrawing : pGraphicShape->getExtDrawings())
137 OUString aFragmentPath = getFragmentPathFromRelId(extDrawing);
138 getFilter().importFragment( new ExtDrawingFragmentHandler( getFilter(), aFragmentPath,
139 mpSlidePersistPtr,
140 meShapeLocation,
141 mpGroupShapePtr,
142 pGraphicShape ) );
143 pGraphicShape->keepDiagramDrawing(getFilter(), aFragmentPath);
145 // Apply font color imported from color fragment
146 if( pGraphicShape->getFontRefColorForNodes().isUsed() )
147 applyFontRefColor(mpGroupShapePtr, pGraphicShape->getFontRefColorForNodes());
149 pGraphicShape = oox::drawingml::ShapePtr( nullptr );
152 void PPTShapeGroupContext::applyFontRefColor(const oox::drawingml::ShapePtr& pShape, const oox::drawingml::Color& rFontRefColor)
154 pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor;
155 std::vector< oox::drawingml::ShapePtr >& vChildren = pShape->getChildren();
156 for (auto const& child : vChildren)
158 applyFontRefColor(child, rFontRefColor);
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */