LibreOffice Module oox (master) 1
layoutnodecontext.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 "layoutnodecontext.hxx"
21
26#include "rulelistcontext.hxx"
27#include <oox/token/namespaces.hxx>
28#include <oox/token/tokens.hxx>
29#include <sal/log.hxx>
30#include <utility>
31
32using namespace ::oox::core;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::xml::sax;
35
36namespace oox::drawingml {
37
38namespace {
39
40class IfContext
41 : public LayoutNodeContext
42{
43public:
44 IfContext( ContextHandler2Helper const & rParent,
45 const AttributeList& rAttribs,
46 const ConditionAtomPtr& pAtom )
47 : LayoutNodeContext( rParent, rAttribs, pAtom )
48 {}
49};
50
51class AlgorithmContext
52 : public ContextHandler2
53{
54public:
55 AlgorithmContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, const AlgAtomPtr & pNode )
56 : ContextHandler2( rParent )
57 , mnRevision( 0 )
58 , mpNode( pNode )
59 {
60 mnRevision = rAttribs.getInteger( XML_rev, 0 );
61 pNode->setType(rAttribs.getToken(XML_type, 0));
62 }
63
64 virtual ContextHandlerRef
65 onCreateContext( ::sal_Int32 aElement,
66 const AttributeList& rAttribs ) override
67 {
68 switch( aElement )
69 {
70 case DGM_TOKEN( param ):
71 {
72 sal_Int32 nType = rAttribs.getToken(XML_type, 0);
73 switch (nType)
74 {
75 case XML_ar:
76 mpNode->setAspectRatio(rAttribs.getDouble(XML_val, 0));
77 break;
78 default:
79 const sal_Int32 nValTok = rAttribs.getToken(XML_val, 0);
80 mpNode->addParam(nType, nValTok > 0 ? nValTok
81 : rAttribs.getInteger(XML_val, 0));
82 break;
83 }
84 break;
85 }
86 default:
87 break;
88 }
89
90 return this;
91 }
92
93private:
94 sal_Int32 mnRevision;
96};
97
98class ChooseContext
99 : public ContextHandler2
100{
101public:
102 ChooseContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, LayoutAtomPtr pNode )
103 : ContextHandler2( rParent )
104 , mpNode(std::move( pNode ))
105 {
106 msName = rAttribs.getStringDefaulted( XML_name );
107 }
108
109 virtual ContextHandlerRef
110 onCreateContext( ::sal_Int32 aElement,
111 const AttributeList& rAttribs ) override
112 {
113 switch( aElement )
114 {
115 case DGM_TOKEN( if ):
116 {
117 // CT_When
118 ConditionAtomPtr pNode = std::make_shared<ConditionAtom>(mpNode->getLayoutNode(), false, rAttribs.getFastAttributeList());
120 return new IfContext( *this, rAttribs, pNode );
121 }
122 case DGM_TOKEN( else ):
123 {
124 // CT_Otherwise
125 ConditionAtomPtr pNode = std::make_shared<ConditionAtom>(mpNode->getLayoutNode(), true, rAttribs.getFastAttributeList());
127 return new IfContext( *this, rAttribs, pNode );
128 }
129 default:
130 break;
131 }
132
133 return this;
134 }
135private:
136 OUString msName;
138};
139
140class ForEachContext
141 : public LayoutNodeContext
142{
143public:
144 ForEachContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, const ForEachAtomPtr& pAtom )
145 : LayoutNodeContext( rParent, rAttribs, pAtom )
146 {
147 pAtom->setRef(rAttribs.getStringDefaulted(XML_ref));
148 pAtom->iterator().loadFromXAttr( rAttribs.getFastAttributeList() );
149
150 LayoutAtomMap& rLayoutAtomMap = pAtom->getLayoutNode().getDiagram().getLayout()->getLayoutAtomMap();
151 rLayoutAtomMap[pAtom->getName()] = pAtom;
152 }
153};
154
155// CT_LayoutVariablePropertySet
156class LayoutVariablePropertySetContext
157 : public ContextHandler2
158{
159public:
160 LayoutVariablePropertySetContext( ContextHandler2Helper const & rParent, LayoutNode::VarMap & aVar )
161 : ContextHandler2( rParent )
162 , mVariables( aVar )
163 {
164 }
165
166 virtual ContextHandlerRef onCreateContext( ::sal_Int32 aElement, const AttributeList& rAttribs ) override
167 {
168 mVariables[ getBaseToken(aElement) ] = rAttribs.getStringDefaulted( XML_val );
169 return this;
170 }
171private:
173};
174
175}
176
177// CT_LayoutNode
178LayoutNodeContext::LayoutNodeContext( ContextHandler2Helper const & rParent,
179 const AttributeList& rAttribs,
180 const LayoutAtomPtr& pAtom )
181 : ContextHandler2( rParent )
182 , mpNode( pAtom )
183{
184 assert( pAtom && "Node must NOT be NULL" );
185 mpNode->setName( rAttribs.getStringDefaulted( XML_name ) );
186}
187
189{
190}
191
194 const AttributeList& rAttribs )
195{
196 switch( aElement )
197 {
198 case DGM_TOKEN( layoutNode ):
199 {
200 LayoutNodePtr pNode = std::make_shared<LayoutNode>(mpNode->getLayoutNode().getDiagram());
202
203 if (rAttribs.hasAttribute(XML_chOrder))
204 {
205 pNode->setChildOrder(rAttribs.getToken(XML_chOrder, XML_b));
206 }
207 else
208 {
209 for (LayoutAtomPtr pAtom = mpNode; pAtom; pAtom = pAtom->getParent())
210 {
211 auto pLayoutNode = dynamic_cast<LayoutNode*>(pAtom.get());
212 if (pLayoutNode)
213 {
214 pNode->setChildOrder(pLayoutNode->getChildOrder());
215 break;
216 }
217 }
218 }
219
220 pNode->setMoveWith( rAttribs.getStringDefaulted( XML_moveWith ) );
221 pNode->setStyleLabel( rAttribs.getStringDefaulted( XML_styleLbl ) );
222 return new LayoutNodeContext( *this, rAttribs, pNode );
223 }
224 case DGM_TOKEN( shape ):
225 {
226 ShapePtr pShape;
227
228 if( rAttribs.hasAttribute( XML_type ) )
229 {
230 pShape = std::make_shared<Shape>("com.sun.star.drawing.CustomShape");
231 if (!rAttribs.getBool(XML_hideGeom, false))
232 {
233 const sal_Int32 nType(rAttribs.getToken( XML_type, XML_obj ));
234 pShape->setSubType( nType );
235 pShape->getCustomShapeProperties()->setShapePresetType( nType );
236 }
237 }
238 else
239 {
240 pShape = std::make_shared<Shape>("com.sun.star.drawing.GroupShape");
241 }
242
243 pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE);
244
245 pShape->setZOrderOff(rAttribs.getInteger(XML_zOrderOff, 0));
246
247 ShapeAtomPtr pAtom = std::make_shared<ShapeAtom>(mpNode->getLayoutNode(), pShape);
249 return new ShapeContext( *this, ShapePtr(), pShape );
250 }
251 case DGM_TOKEN( extLst ):
252 return nullptr;
253 case DGM_TOKEN( alg ):
254 {
255 // CT_Algorithm
256 AlgAtomPtr pAtom = std::make_shared<AlgAtom>(mpNode->getLayoutNode());
258 return new AlgorithmContext( *this, rAttribs, pAtom );
259 }
260 case DGM_TOKEN( choose ):
261 {
262 // CT_Choose
263 LayoutAtomPtr pAtom = std::make_shared<ChooseAtom>(mpNode->getLayoutNode());
265 return new ChooseContext( *this, rAttribs, pAtom );
266 }
267 case DGM_TOKEN( forEach ):
268 {
269 // CT_ForEach
270 ForEachAtomPtr pAtom = std::make_shared<ForEachAtom>(mpNode->getLayoutNode(), rAttribs.getFastAttributeList());
272 return new ForEachContext( *this, rAttribs, pAtom );
273 }
274 case DGM_TOKEN( constrLst ):
275 // CT_Constraints
276 return new ConstraintListContext( *this, mpNode );
277 case DGM_TOKEN( presOf ):
278 {
279 // CT_PresentationOf
280 // TODO
281 IteratorAttr aIterator;
282 aIterator.loadFromXAttr(rAttribs.getFastAttributeList());
283 break;
284 }
285 case DGM_TOKEN( ruleLst ):
286 // CT_Rules
287 return new RuleListContext( *this, mpNode );
288 case DGM_TOKEN( varLst ):
289 {
290 LayoutNodePtr pNode(std::dynamic_pointer_cast<LayoutNode>(mpNode));
291 if( pNode )
292 {
293 return new LayoutVariablePropertySetContext( *this, pNode->variables() );
294 }
295 else
296 {
297 SAL_WARN("oox", "OOX: encountered a varLst in a non layoutNode context" );
298 }
299 break;
300 }
301 default:
302 break;
303 }
304
305 return this;
306}
307
308}
309
310/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Returns the boolean value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
static void connect(const LayoutAtomPtr &pParent, const LayoutAtomPtr &pChild)
LayoutNodeContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttributes, const LayoutAtomPtr &pNode)
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
void setChildOrder(sal_Int32 nOrder)
std::map< sal_Int32, OUString > VarMap
Handles one <dgm:ruleLst> element.
OUString msName
LayoutNode::VarMap & mVariables
sal_Int32 mnRevision
AlgAtomPtr mpNode
#define SAL_WARN(area, stream)
::rtl::Reference< ContextHandler > ContextHandlerRef
std::shared_ptr< ShapeAtom > ShapeAtomPtr
std::shared_ptr< ConditionAtom > ConditionAtomPtr
std::shared_ptr< Shape > ShapePtr
std::shared_ptr< AlgAtom > AlgAtomPtr
std::map< OUString, LayoutAtomPtr > LayoutAtomMap
std::shared_ptr< LayoutAtom > LayoutAtomPtr
std::shared_ptr< LayoutNode > LayoutNodePtr
const sal_Int32 PER_DEGREE
std::shared_ptr< ForEachAtom > ForEachAtomPtr
XML_type
QPRO_FUNC_TYPE nType
void loadFromXAttr(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttributes)