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
26 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
28 #include <oox/drawingml/shape.hxx>
29 #include "diagram.hxx"
31 namespace oox
{ namespace drawingml
{
34 typedef std::shared_ptr
< DiagramLayout
> DiagramLayoutPtr
;
36 // AG_IteratorAttributes
41 // not sure this belong here, but wth
42 void loadFromXAttr( const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
44 std::vector
<sal_Int32
> maAxis
;
56 // not sure this belong here, but wth
57 void loadFromXAttr( const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
70 sal_Int32 mnPointType
;
73 OUString msRefForName
;
75 sal_Int32 mnRefPointType
;
81 typedef std::map
<sal_Int32
, sal_Int32
> LayoutProperty
;
82 typedef std::map
<OUString
, LayoutProperty
> LayoutPropertyMap
;
84 struct LayoutAtomVisitor
;
88 typedef std::shared_ptr
< LayoutAtom
> LayoutAtomPtr
;
90 /** abstract Atom for the layout */
94 LayoutAtom(LayoutNode
& rLayoutNode
) : mrLayoutNode(rLayoutNode
) {}
95 virtual ~LayoutAtom() { }
97 LayoutNode
& getLayoutNode()
98 { return mrLayoutNode
; }
100 /** visitor acceptance
102 virtual void accept( LayoutAtomVisitor
& ) = 0;
104 void setName( const OUString
& sName
)
106 const OUString
& getName() const
110 void addChild( const LayoutAtomPtr
& pNode
)
111 { mpChildNodes
.push_back( pNode
); }
112 void setParent(const LayoutAtomPtr
& pParent
) { mpParent
= pParent
; }
115 const std::vector
<LayoutAtomPtr
>& getChildren() const
116 { return mpChildNodes
; }
118 LayoutAtomPtr
getParent() const { return mpParent
.lock(); }
120 static void connect(const LayoutAtomPtr
& pParent
, const LayoutAtomPtr
& pChild
)
122 pParent
->addChild(pChild
);
123 pChild
->setParent(pParent
);
127 void dump(int level
= 0);
130 LayoutNode
& mrLayoutNode
;
131 std::vector
< LayoutAtomPtr
> mpChildNodes
;
132 std::weak_ptr
<LayoutAtom
> mpParent
;
140 ConstraintAtom(LayoutNode
& rLayoutNode
) : LayoutAtom(rLayoutNode
) {}
141 virtual void accept( LayoutAtomVisitor
& ) override
;
142 Constraint
& getConstraint()
143 { return maConstraint
; }
144 void parseConstraint(std::vector
<Constraint
>& rConstraints
, bool bRequireForName
) const;
146 Constraint maConstraint
;
153 AlgAtom(LayoutNode
& rLayoutNode
) : LayoutAtom(rLayoutNode
), mnType(0), maMap() {}
155 typedef std::map
<sal_Int32
,sal_Int32
> ParamMap
;
157 virtual void accept( LayoutAtomVisitor
& ) override
;
159 void setType( sal_Int32 nToken
)
161 void addParam( sal_Int32 nType
, sal_Int32 nVal
)
162 { maMap
[nType
]=nVal
; }
163 sal_Int32
getVerticalShapesCount(const ShapePtr
& rShape
);
164 void layoutShape( const ShapePtr
& rShape
,
165 const std::vector
<Constraint
>& rConstraints
);
167 void setAspectRatio(double fAspectRatio
) { mfAspectRatio
= fAspectRatio
; }
169 double getAspectRatio() const { return mfAspectRatio
; }
174 /// Aspect ratio is not integer, so not part of maMap.
175 double mfAspectRatio
= 0;
177 /// Determines the connector shape type for conn algorithm
178 sal_Int32
getConnectorType();
181 typedef std::shared_ptr
< AlgAtom
> AlgAtomPtr
;
187 explicit ForEachAtom(LayoutNode
& rLayoutNode
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
189 IteratorAttr
& iterator()
191 void setRef(const OUString
& rsRef
)
193 const OUString
& getRef() const
195 virtual void accept( LayoutAtomVisitor
& ) override
;
196 LayoutAtomPtr
getRefAtom();
203 typedef std::shared_ptr
< ForEachAtom
> ForEachAtomPtr
;
209 explicit ConditionAtom(LayoutNode
& rLayoutNode
, bool isElse
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
210 virtual void accept( LayoutAtomVisitor
& ) override
;
211 bool getDecision(const dgm::Point
* pPresPoint
) const;
214 static bool compareResult(sal_Int32 nOperator
, sal_Int32 nFirst
, sal_Int32 nSecond
);
215 sal_Int32
getNodeCount(const dgm::Point
* pPresPoint
) const;
219 ConditionAttr maCond
;
222 typedef std::shared_ptr
< ConditionAtom
> ConditionAtomPtr
;
224 /** "choose" statements. Atoms will be tested in order. */
229 ChooseAtom(LayoutNode
& rLayoutNode
)
230 : LayoutAtom(rLayoutNode
)
232 virtual void accept( LayoutAtomVisitor
& ) override
;
239 typedef std::map
<sal_Int32
, OUString
> VarMap
;
241 LayoutNode(const Diagram
& rDgm
) : LayoutAtom(*this), mrDgm(rDgm
), mnChildOrder(0) {}
242 const Diagram
& getDiagram() const
244 virtual void accept( LayoutAtomVisitor
& ) override
;
246 { return mVariables
; }
247 void setMoveWith( const OUString
& sName
)
248 { msMoveWith
= sName
; }
249 void setStyleLabel( const OUString
& sLabel
)
250 { msStyleLabel
= sLabel
; }
251 void setChildOrder( sal_Int32 nOrder
)
252 { mnChildOrder
= nOrder
; }
253 void setExistingShape( const ShapePtr
& pShape
)
254 { mpExistingShape
= pShape
; }
255 const ShapePtr
& getExistingShape() const
256 { return mpExistingShape
; }
257 const std::vector
<ShapePtr
> & getNodeShapes() const
258 { return mpNodeShapes
; }
259 void addNodeShape(const ShapePtr
& pShape
)
260 { mpNodeShapes
.push_back(pShape
); }
262 bool setupShape( const ShapePtr
& rShape
,
263 const dgm::Point
* pPresNode
) const;
265 const LayoutNode
* getParentLayoutNode() const;
268 const Diagram
& mrDgm
;
271 OUString msStyleLabel
;
272 ShapePtr mpExistingShape
;
273 std::vector
<ShapePtr
> mpNodeShapes
;
274 sal_Int32 mnChildOrder
;
277 typedef std::shared_ptr
< LayoutNode
> LayoutNodePtr
;
283 ShapeAtom(LayoutNode
& rLayoutNode
, const ShapePtr
& pShape
) : LayoutAtom(rLayoutNode
), mpShapeTemplate(pShape
) {}
284 virtual void accept( LayoutAtomVisitor
& ) override
;
285 const ShapePtr
& getShapeTemplate() const
286 { return mpShapeTemplate
; }
289 ShapePtr
const mpShapeTemplate
;
292 typedef std::shared_ptr
< ShapeAtom
> ShapeAtomPtr
;
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */