LibreOffice Module oox (master)  1
shapegroupcontext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <com/sun/star/xml/sax/FastToken.hpp>
21 #include <com/sun/star/beans/XMultiPropertySet.hpp>
22 
29 #include <oox/token/namespaces.hxx>
30 #include <oox/token/tokens.hxx>
31 #include <sal/log.hxx>
32 
33 using namespace oox::core;
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::drawing;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::xml::sax;
39 
40 namespace oox::drawingml {
41 
42 ShapeGroupContext::ShapeGroupContext( FragmentHandler2 const & rParent, ShapePtr const & pMasterShapePtr, ShapePtr const & pGroupShapePtr )
43 : FragmentHandler2( rParent )
44 , mpGroupShapePtr( pGroupShapePtr )
45 {
46  if( pMasterShapePtr )
47  mpGroupShapePtr->setWps(pMasterShapePtr->getWps());
48  if( pMasterShapePtr && mpGroupShapePtr )
49  pMasterShapePtr->addChild( mpGroupShapePtr );
50 }
51 
53 {
54 }
55 
56 ContextHandlerRef ShapeGroupContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
57 {
58  switch( getBaseToken( aElementToken ) )
59  {
60  case XML_cNvPr:
61  {
62  mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
63  mpGroupShapePtr->setId( rAttribs.getString( XML_id ).get() );
64  mpGroupShapePtr->setName( rAttribs.getString( XML_name ).get() );
65  break;
66  }
67  case XML_ph:
68  mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
69  if( rAttribs.hasAttribute( XML_idx ) )
70  mpGroupShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
71  break;
72  // nvSpPr CT_ShapeNonVisual end
73 
74  case XML_grpSpPr:
75  return new ShapePropertiesContext( *this, *mpGroupShapePtr );
76  case XML_nvGrpSpPr:
77  return this;
78  case XML_spPr:
79  return new ShapePropertiesContext( *this, *mpGroupShapePtr );
80 /*
81  case XML_style:
82  return new ShapeStyleContext( getParser() );
83 */
84  case XML_cxnSp: // connector shape
85  {
86  ShapePtr pShape = std::make_shared<Shape>("com.sun.star.drawing.ConnectorShape");
87  pShape->setLockedCanvas(mpGroupShapePtr->getLockedCanvas());
88  return new ConnectorShapeContext( *this, mpGroupShapePtr, pShape );
89  }
90  case XML_grpSp: // group shape
91  return new ShapeGroupContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GroupShape" ) );
92  case XML_sp: // shape
93  case XML_wsp:
94  // Don't set default character height for WPS shapes, Writer has its
95  // own way to set the default, and if we don't set it here, editing
96  // properly inherits it.
97  return new ShapeContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.CustomShape", getBaseToken(aElementToken) == XML_sp ) );
98  case XML_pic: // CT_Picture
99  return new GraphicShapeContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ) );
100  case XML_graphicFrame: // CT_GraphicalObjectFrame
101  return new GraphicalObjectFrameContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ), true );
102  case XML_cNvGrpSpPr:
103  break;
104  case XML_grpSpLocks:
105  break;
106  default:
107  SAL_WARN("oox", "ShapeGroupContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
108  break;
109  }
110 
111  return this;
112 }
113 
114 }
115 
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptValue< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
const Type & get() const
Definition: helper.hxx:185
ShapeGroupContext(::oox::core::FragmentHandler2 const &rParent, ShapePtr const &pMasterShapePtr, ShapePtr const &pGroupShapePtr)
Provides access to attribute values of an element.
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
#define SAL_WARN(area, stream)
std::shared_ptr< Shape > ShapePtr
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.