Bump version to 24.04.3.4
[LibreOffice.git] / oox / source / ppt / pptshapegroupcontext.cxx
blob49a5f5ce4ba66a80d153a09f9288fc779a137d7f
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::uno;
43 using namespace ::com::sun::star::drawing;
44 using namespace ::com::sun::star::text;
45 using namespace ::com::sun::star::xml::sax;
47 namespace oox::ppt {
49 PPTShapeGroupContext::PPTShapeGroupContext(
50 FragmentHandler2 const & rParent,
51 oox::ppt::SlidePersistPtr pSlidePersistPtr,
52 const ShapeLocation eShapeLocation,
53 const oox::drawingml::ShapePtr& pMasterShapePtr,
54 const oox::drawingml::ShapePtr& pGroupShapePtr )
55 : ShapeGroupContext( rParent, pMasterShapePtr, pGroupShapePtr )
56 , mpSlidePersistPtr(std::move( pSlidePersistPtr ))
57 , meShapeLocation( eShapeLocation )
61 ContextHandlerRef PPTShapeGroupContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
63 if( getNamespace( aElementToken ) == NMSP_dsp )
64 aElementToken = NMSP_ppt | getBaseToken( aElementToken );
66 switch( aElementToken )
68 case OOX_TOKEN(dml, extLst):
69 case OOX_TOKEN(dml, ext):
70 break;
71 case OOX_TOKEN(adec, decorative):
73 mpGroupShapePtr->setDecorative(rAttribs.getBool(XML_val, false));
75 break;
76 case PPT_TOKEN( cNvPr ):
78 // don't override SmartArt properties for embedded drawing's spTree
79 mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
80 if (mpGroupShapePtr->getId().isEmpty())
81 mpGroupShapePtr->setId(rAttribs.getStringDefaulted(XML_id));
82 if (mpGroupShapePtr->getName().isEmpty())
83 mpGroupShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
84 break;
86 case PPT_TOKEN( ph ):
87 mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
88 if( rAttribs.hasAttribute( XML_idx ) )
89 mpGroupShapePtr->setSubTypeIndex( rAttribs.getInteger( XML_idx, 0 ) );
90 break;
91 // nvSpPr CT_ShapeNonVisual end
93 case PPT_TOKEN( grpSpPr ):
94 return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr );
95 case PPT_TOKEN( spPr ):
96 return new oox::drawingml::ShapePropertiesContext( *this, *mpGroupShapePtr );
98 case PPT_TOKEN( style ):
99 return new ShapeStyleContext( getParser() );
101 case PPT_TOKEN( cxnSp ): // connector shape
103 auto pShape = std::make_shared<PPTShape>(meShapeLocation, "com.sun.star.drawing.ConnectorShape");
104 return new oox::drawingml::ConnectorShapeContext(*this, mpGroupShapePtr, pShape,
105 pShape->getConnectorShapeProperties());
107 case PPT_TOKEN( grpSp ): // group shape
108 return new PPTShapeGroupContext( *this, mpSlidePersistPtr, meShapeLocation, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GroupShape" ) );
109 case PPT_TOKEN( sp ): // Shape
111 auto pShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.CustomShape" );
112 bool bUseBgFill = rAttribs.getBool(XML_useBgFill, false);
113 if (bUseBgFill)
115 pShape->getFillProperties().moFillType = XML_noFill;
116 pShape->getFillProperties().moUseBgFill = true;
118 pShape->setModelId(rAttribs.getStringDefaulted( XML_modelId ));
119 return new PPTShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, pShape );
121 case PPT_TOKEN( pic ): // CT_Picture
122 return new PPTGraphicShapeContext( *this, mpSlidePersistPtr, mpGroupShapePtr, std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.GraphicObjectShape" ) );
123 case PPT_TOKEN( graphicFrame ): // CT_GraphicalObjectFrame
125 pGraphicShape = std::make_shared<PPTShape>( meShapeLocation, "com.sun.star.drawing.OLE2Shape" );
126 return new oox::drawingml::GraphicalObjectFrameContext( *this, mpGroupShapePtr, pGraphicShape, true );
130 return this;
133 void PPTShapeGroupContext::importExtDrawings( )
135 if( !pGraphicShape )
136 return;
138 for (auto const& extDrawing : pGraphicShape->getExtDrawings())
140 OUString aFragmentPath = getFragmentPathFromRelId(extDrawing);
141 getFilter().importFragment( new ExtDrawingFragmentHandler( getFilter(), aFragmentPath,
142 mpSlidePersistPtr,
143 meShapeLocation,
144 mpGroupShapePtr,
145 pGraphicShape ) );
146 pGraphicShape->keepDiagramDrawing(getFilter(), aFragmentPath);
148 // Apply font color imported from color fragment
149 if( pGraphicShape->getFontRefColorForNodes().isUsed() )
150 applyFontRefColor(mpGroupShapePtr, pGraphicShape->getFontRefColorForNodes());
152 pGraphicShape = oox::drawingml::ShapePtr( nullptr );
155 void PPTShapeGroupContext::applyFontRefColor(const oox::drawingml::ShapePtr& pShape, const oox::drawingml::Color& rFontRefColor)
157 pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor;
158 std::vector< oox::drawingml::ShapePtr >& vChildren = pShape->getChildren();
159 for (auto const& child : vChildren)
161 applyFontRefColor(child, rFontRefColor);
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */