1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DIAGRAMLAYOUTATOMS_HXX
21 #define INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DIAGRAMLAYOUTATOMS_HXX
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
30 #include "oox/drawingml/shape.hxx"
31 #include "diagram.hxx"
33 namespace oox
{ namespace drawingml
{
36 typedef std::shared_ptr
< DiagramLayout
> DiagramLayoutPtr
;
38 // AG_IteratorAttributes
43 // not sure this belong here, but wth
44 void loadFromXAttr( const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
58 // not sure this belong here, but wth
59 void loadFromXAttr( const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
67 struct LayoutAtomVisitor
;
70 typedef std::shared_ptr
< LayoutAtom
> LayoutAtomPtr
;
72 /** abstract Atom for the layout */
76 virtual ~LayoutAtom() { }
78 /** visitor acceptance
80 virtual void accept( LayoutAtomVisitor
& ) = 0;
82 void setName( const OUString
& sName
)
84 const OUString
& getName() const
87 virtual void addChild( const LayoutAtomPtr
& pNode
)
88 { mpChildNodes
.push_back( pNode
); }
89 virtual const std::vector
<LayoutAtomPtr
>& getChildren() const
90 { return mpChildNodes
; }
93 void dump(int level
= 0);
95 std::vector
< LayoutAtomPtr
> mpChildNodes
;
104 mnFor(-1), msForName(), mnPointType(-1), mnType(-1), mnRefFor(-1), msRefForName(),
105 mnRefType(-1), mnRefPointType(-1), mfFactor(1.0), mfValue(0.0), mnOperator(0)
108 virtual void accept( LayoutAtomVisitor
& ) override
;
110 void setFor( sal_Int32 nToken
)
112 void setForName( const OUString
& sName
)
113 { msForName
= sName
; }
114 void setPointType( sal_Int32 nToken
)
115 { mnPointType
= nToken
; }
116 void setType( sal_Int32 nToken
)
118 void setRefFor( sal_Int32 nToken
)
119 { mnRefFor
= nToken
; }
120 void setRefForName( const OUString
& sName
)
121 { msRefForName
= sName
; }
122 void setRefType( sal_Int32 nToken
)
123 { mnRefType
= nToken
; }
124 void setRefPointType( sal_Int32 nToken
)
125 { mnRefPointType
= nToken
; }
126 void setFactor( const double& fVal
)
128 void setValue( const double& fVal
)
130 void setOperator( sal_Int32 nToken
)
131 { mnOperator
= nToken
; }
135 sal_Int32 mnPointType
;
138 OUString msRefForName
;
140 sal_Int32 mnRefPointType
;
143 sal_Int32 mnOperator
;
150 AlgAtom() : mnType(0), maMap() {}
152 typedef std::map
<sal_Int32
,sal_Int32
> ParamMap
;
154 virtual void accept( LayoutAtomVisitor
& ) override
;
156 void setType( sal_Int32 nToken
)
158 void addParam( sal_Int32 nType
, sal_Int32 nVal
)
159 { maMap
[nType
]=nVal
; }
160 void layoutShape( const ShapePtr
& rShape
,
161 const OUString
& rName
) const;
167 typedef std::shared_ptr
< AlgAtom
> AlgAtomPtr
;
173 explicit ForEachAtom(const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
175 IteratorAttr
& iterator()
177 virtual void accept( LayoutAtomVisitor
& ) override
;
183 typedef std::shared_ptr
< ForEachAtom
> ForEachAtomPtr
;
189 explicit ConditionAtom(const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
190 virtual void accept( LayoutAtomVisitor
& ) override
;
191 void readElseBranch()
193 virtual void addChild( const LayoutAtomPtr
& pNode
) override
;
194 virtual const std::vector
<LayoutAtomPtr
>& getChildren() const override
;
198 ConditionAttr maCond
;
199 std::vector
< LayoutAtomPtr
> mpElseChildNodes
;
202 typedef std::shared_ptr
< ConditionAtom
> ConditionAtomPtr
;
204 /** "choose" statements. Atoms will be tested in order. */
209 virtual void accept( LayoutAtomVisitor
& ) override
;
227 // we know that the array is of fixed size
228 // the use of Any allow having empty values
229 typedef std::array
<css::uno::Any
, 9> VarMap
;
231 LayoutNode() : mnChildOrder(0) {}
232 virtual void accept( LayoutAtomVisitor
& ) override
;
234 { return mVariables
; }
235 void setMoveWith( const OUString
& sName
)
236 { msMoveWith
= sName
; }
237 void setStyleLabel( const OUString
& sLabel
)
238 { msStyleLabel
= sLabel
; }
239 void setChildOrder( sal_Int32 nOrder
)
240 { mnChildOrder
= nOrder
; }
241 void setShape( const ShapePtr
& pShape
)
242 { mpShape
= pShape
; }
243 const ShapePtr
& getShape() const
246 bool setupShape( const ShapePtr
& rShape
,
248 sal_uInt32 nIdx
) const;
253 OUString msStyleLabel
;
255 sal_Int32 mnChildOrder
;
258 typedef std::shared_ptr
< LayoutNode
> LayoutNodePtr
;
260 struct LayoutAtomVisitor
262 virtual ~LayoutAtomVisitor() {}
263 virtual void visit(ConstraintAtom
& rAtom
) = 0;
264 virtual void visit(AlgAtom
& rAtom
) = 0;
265 virtual void visit(ForEachAtom
& rAtom
) = 0;
266 virtual void visit(ConditionAtom
& rAtom
) = 0;
267 virtual void visit(ChooseAtom
& rAtom
) = 0;
268 virtual void visit(LayoutNode
& rAtom
) = 0;
271 class ShapeCreationVisitor
: public LayoutAtomVisitor
273 ShapePtr mpParentShape
;
274 const Diagram
& mrDgm
;
277 void defaultVisit(LayoutAtom
& rAtom
);
278 virtual void visit(ConstraintAtom
& rAtom
) override
;
279 virtual void visit(AlgAtom
& rAtom
) override
;
280 virtual void visit(ForEachAtom
& rAtom
) override
;
281 virtual void visit(ConditionAtom
& rAtom
) override
;
282 virtual void visit(ChooseAtom
& rAtom
) override
;
283 virtual void visit(LayoutNode
& rAtom
) override
;
286 ShapeCreationVisitor(const ShapePtr
& rParentShape
,
287 const Diagram
& rDgm
) :
288 mpParentShape(rParentShape
),
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */