cid#1640468 Dereference after null check
[LibreOffice.git] / oox / source / drawingml / shapegroupcontext.cxx
blob4f78358e9c95d3c857f790a3f3eaf6af8b0b73b2
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/beans/XMultiPropertySet.hpp>
23 #include <oox/helper/attributelist.hxx>
24 #include <oox/drawingml/shapegroupcontext.hxx>
25 #include <oox/drawingml/connectorshapecontext.hxx>
26 #include <oox/drawingml/graphicshapecontext.hxx>
27 #include <oox/drawingml/drawingmltypes.hxx>
28 #include <drawingml/shapepropertiescontext.hxx>
29 #include <oox/token/namespaces.hxx>
30 #include <oox/token/tokens.hxx>
31 #include <sal/log.hxx>
32 #include <utility>
34 using namespace oox::core;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::xml::sax;
38 namespace oox::drawingml {
40 ShapeGroupContext::ShapeGroupContext( FragmentHandler2 const & rParent, ShapePtr const & pMasterShapePtr, ShapePtr pGroupShapePtr )
41 : FragmentHandler2( rParent )
42 , mpGroupShapePtr(std::move( pGroupShapePtr ))
44 if( pMasterShapePtr )
45 mpGroupShapePtr->setWps(pMasterShapePtr->getWps());
46 if( pMasterShapePtr && mpGroupShapePtr )
47 pMasterShapePtr->addChild( mpGroupShapePtr );
50 ShapeGroupContext::~ShapeGroupContext()
54 ContextHandlerRef ShapeGroupContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
56 switch( getBaseToken( aElementToken ) )
58 case XML_extLst:
59 case XML_ext:
60 break;
61 case XML_decorative:
63 mpGroupShapePtr->setDecorative(rAttribs.getBool(XML_val, false));
65 break;
66 case XML_cNvPr:
68 mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
69 mpGroupShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) );
70 mpGroupShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) );
71 break;
73 case XML_ph:
74 mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
75 if( rAttribs.hasAttribute( XML_idx ) )
76 mpGroupShapePtr->setSubTypeIndex( rAttribs.getInteger( XML_idx, 0 ) );
77 break;
78 // nvSpPr CT_ShapeNonVisual end
80 case XML_grpSpPr:
81 return new ShapePropertiesContext( *this, *mpGroupShapePtr );
82 case XML_nvGrpSpPr:
83 return this;
84 case XML_spPr:
85 return new ShapePropertiesContext( *this, *mpGroupShapePtr );
87 case XML_style:
88 return new ShapeStyleContext( getParser() );
90 case XML_cxnSp: // connector shape
92 ShapePtr pShape = std::make_shared<Shape>("com.sun.star.drawing.ConnectorShape");
93 pShape->setLockedCanvas(mpGroupShapePtr->getLockedCanvas());
94 pShape->setWordprocessingCanvas(mpGroupShapePtr->isInWordprocessingCanvas());
95 return new ConnectorShapeContext(*this, mpGroupShapePtr, pShape,
96 pShape->getConnectorShapeProperties());
98 case XML_grpSp: // group shape
99 return new ShapeGroupContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GroupShape" ) );
100 case XML_sp: // shape
101 case XML_wsp:
102 // Don't set default character height for WPS shapes, Writer has its
103 // own way to set the default, and if we don't set it here, editing
104 // properly inherits it.
105 return new ShapeContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.CustomShape", getBaseToken(aElementToken) == XML_sp ) );
106 case XML_pic: // CT_Picture
107 return new GraphicShapeContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ) );
108 case XML_graphicFrame: // CT_GraphicalObjectFrame
109 return new GraphicalObjectFrameContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ), true );
110 case XML_cNvGrpSpPr:
111 break;
112 case XML_grpSpLocks:
113 break;
114 default:
115 SAL_WARN("oox", "ShapeGroupContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
116 break;
119 return this;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */