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 #include <com/sun/star/container/XNamed.hpp>
23
24 #include <oox/helper/attributelist.hxx>
25 #include <oox/drawingml/shapegroupcontext.hxx>
26 #include <oox/drawingml/connectorshapecontext.hxx>
27 #include <oox/drawingml/graphicshapecontext.hxx>
28 #include <drawingml/lineproperties.hxx>
29 #include <oox/drawingml/drawingmltypes.hxx>
30 #include <drawingml/customshapegeometry.hxx>
31 #include <drawingml/shapepropertiescontext.hxx>
32 #include <drawingml/textbodycontext.hxx>
33 #include <oox/token/namespaces.hxx>
34 #include <oox/token/tokens.hxx>
35 #include <sal/log.hxx>
36
37 using namespace oox::core;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::drawing;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::text;
43 using namespace ::com::sun::star::xml::sax;
44
45 namespace oox { namespace drawingml {
46
ShapeGroupContext(FragmentHandler2 const & rParent,ShapePtr const & pMasterShapePtr,ShapePtr const & pGroupShapePtr)47 ShapeGroupContext::ShapeGroupContext( FragmentHandler2 const & rParent, ShapePtr const & pMasterShapePtr, ShapePtr const & pGroupShapePtr )
48 : FragmentHandler2( rParent )
49 , mpGroupShapePtr( pGroupShapePtr )
50 {
51 if( pMasterShapePtr )
52 mpGroupShapePtr->setWps(pMasterShapePtr->getWps());
53 if( pMasterShapePtr.get() && mpGroupShapePtr.get() )
54 pMasterShapePtr->addChild( mpGroupShapePtr );
55 }
56
~ShapeGroupContext()57 ShapeGroupContext::~ShapeGroupContext()
58 {
59 }
60
onCreateContext(sal_Int32 aElementToken,const AttributeList & rAttribs)61 ContextHandlerRef ShapeGroupContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
62 {
63 switch( getBaseToken( aElementToken ) )
64 {
65 case XML_cNvPr:
66 {
67 mpGroupShapePtr->setHidden( rAttribs.getBool( XML_hidden, false ) );
68 mpGroupShapePtr->setId( rAttribs.getString( XML_id ).get() );
69 mpGroupShapePtr->setName( rAttribs.getString( XML_name ).get() );
70 break;
71 }
72 case XML_ph:
73 mpGroupShapePtr->setSubType( rAttribs.getToken( XML_type, FastToken::DONTKNOW ) );
74 if( rAttribs.hasAttribute( XML_idx ) )
75 mpGroupShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
76 break;
77 // nvSpPr CT_ShapeNonVisual end
78
79 case XML_grpSpPr:
80 return new ShapePropertiesContext( *this, *mpGroupShapePtr );
81 case XML_nvGrpSpPr:
82 return this;
83 case XML_spPr:
84 return new ShapePropertiesContext( *this, *mpGroupShapePtr );
85 /*
86 case XML_style:
87 return new ShapeStyleContext( getParser() );
88 */
89 case XML_cxnSp: // connector shape
90 {
91 ShapePtr pShape(new Shape("com.sun.star.drawing.ConnectorShape"));
92 pShape->setLockedCanvas(mpGroupShapePtr->getLockedCanvas());
93 return new ConnectorShapeContext( *this, mpGroupShapePtr, pShape );
94 }
95 case XML_grpSp: // group shape
96 return new ShapeGroupContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GroupShape" ) );
97 case XML_sp: // shape
98 case XML_wsp:
99 // Don't set default character height for WPS shapes, Writer has its
100 // own way to set the default, and if we don't set it here, editing
101 // properly inherits it.
102 return new ShapeContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.CustomShape", getBaseToken(aElementToken) == XML_sp ) );
103 case XML_pic: // CT_Picture
104 return new GraphicShapeContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ) );
105 case XML_graphicFrame: // CT_GraphicalObjectFrame
106 return new GraphicalObjectFrameContext( *this, mpGroupShapePtr, std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ), true );
107 case XML_cNvGrpSpPr:
108 break;
109 case XML_grpSpLocks:
110 break;
111 default:
112 SAL_WARN("oox", "ShapeGroupContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
113 break;
114 }
115
116 return this;
117 }
118
119 } }
120
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
122