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>
29 #include "diagram.hxx"
31 namespace oox::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
);
66 /// Constraints allow you to specify an ideal (or starting point) size for each shape.
70 OUString msRefForName
;
74 sal_Int32 mnPointType
;
78 sal_Int32 mnRefPointType
;
82 /// Rules allow you to specify what to do when constraints can't be fully satisfied.
88 typedef std::map
<sal_Int32
, sal_Int32
> LayoutProperty
;
89 typedef std::map
<OUString
, LayoutProperty
> LayoutPropertyMap
;
91 struct LayoutAtomVisitor
;
95 typedef std::shared_ptr
< LayoutAtom
> LayoutAtomPtr
;
97 /** abstract Atom for the layout */
101 LayoutAtom(LayoutNode
& rLayoutNode
) : mrLayoutNode(rLayoutNode
) {}
102 virtual ~LayoutAtom() { }
104 LayoutNode
& getLayoutNode()
105 { return mrLayoutNode
; }
107 /** visitor acceptance
109 virtual void accept( LayoutAtomVisitor
& ) = 0;
111 void setName( const OUString
& sName
)
113 const OUString
& getName() const
117 void addChild( const LayoutAtomPtr
& pNode
)
118 { mpChildNodes
.push_back( pNode
); }
119 void setParent(const LayoutAtomPtr
& pParent
) { mpParent
= pParent
; }
122 const std::vector
<LayoutAtomPtr
>& getChildren() const
123 { return mpChildNodes
; }
125 LayoutAtomPtr
getParent() const { return mpParent
.lock(); }
127 static void connect(const LayoutAtomPtr
& pParent
, const LayoutAtomPtr
& pChild
)
129 pParent
->addChild(pChild
);
130 pChild
->setParent(pParent
);
134 void dump(int level
= 0);
137 LayoutNode
& mrLayoutNode
;
138 std::vector
< LayoutAtomPtr
> mpChildNodes
;
139 std::weak_ptr
<LayoutAtom
> mpParent
;
147 ConstraintAtom(LayoutNode
& rLayoutNode
) : LayoutAtom(rLayoutNode
) {}
148 virtual void accept( LayoutAtomVisitor
& ) override
;
149 Constraint
& getConstraint()
150 { return maConstraint
; }
151 void parseConstraint(std::vector
<Constraint
>& rConstraints
, bool bRequireForName
) const;
153 Constraint maConstraint
;
156 /// Represents one <dgm:rule> element.
161 RuleAtom(LayoutNode
& rLayoutNode
) : LayoutAtom(rLayoutNode
) {}
162 virtual void accept( LayoutAtomVisitor
& ) override
;
165 void parseRule(std::vector
<Rule
>& rRules
) const;
174 AlgAtom(LayoutNode
& rLayoutNode
) : LayoutAtom(rLayoutNode
), mnType(0), maMap() {}
176 typedef std::map
<sal_Int32
,sal_Int32
> ParamMap
;
178 virtual void accept( LayoutAtomVisitor
& ) override
;
180 void setType( sal_Int32 nToken
)
182 const ParamMap
& getMap() const { return maMap
; }
183 void addParam( sal_Int32 nType
, sal_Int32 nVal
)
184 { maMap
[nType
]=nVal
; }
185 sal_Int32
getVerticalShapesCount(const ShapePtr
& rShape
);
186 void layoutShape( const ShapePtr
& rShape
,
187 const std::vector
<Constraint
>& rConstraints
,
188 const std::vector
<Rule
>& rRules
);
190 void setAspectRatio(double fAspectRatio
) { mfAspectRatio
= fAspectRatio
; }
192 double getAspectRatio() const { return mfAspectRatio
; }
197 /// Aspect ratio is not integer, so not part of maMap.
198 double mfAspectRatio
= 0;
200 /// Determines the connector shape type for conn algorithm
201 sal_Int32
getConnectorType();
204 typedef std::shared_ptr
< AlgAtom
> AlgAtomPtr
;
206 /// Finds optimal grid to layout children that have fixed aspect ratio.
210 static void layoutShapeChildren(const AlgAtom
& rAlg
, const ShapePtr
& rShape
,
211 const std::vector
<Constraint
>& rConstraints
);
215 * Lays out child layout nodes along a vertical path and works with the trapezoid shape to create a
221 static void layoutShapeChildren(const ShapePtr
& rShape
);
225 * Specifies the size and position for all child layout nodes.
230 static void layoutShapeChildren(AlgAtom
& rAlg
, const ShapePtr
& rShape
,
231 const std::vector
<Constraint
>& rConstraints
);
235 * Apply rConstraint to the rProperties shared layout state.
237 * Note that the order in which constraints are applied matters, given that constraints can refer to
238 * each other, and in case A depends on B and A is applied before B, the effect of A won't be
239 * updated when B is applied.
241 static void applyConstraintToLayout(const Constraint
& rConstraint
,
242 LayoutPropertyMap
& rProperties
);
245 * Decides if a certain reference type (e.g. "right") can be inferred from the available properties
246 * in rMap (e.g. left and width). Returns true if rValue is written to.
248 static bool inferFromLayoutProperty(const LayoutProperty
& rMap
, sal_Int32 nRefType
,
256 explicit ForEachAtom(LayoutNode
& rLayoutNode
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
258 IteratorAttr
& iterator()
260 void setRef(const OUString
& rsRef
)
262 const OUString
& getRef() const
264 virtual void accept( LayoutAtomVisitor
& ) override
;
265 LayoutAtomPtr
getRefAtom();
272 typedef std::shared_ptr
< ForEachAtom
> ForEachAtomPtr
;
278 explicit ConditionAtom(LayoutNode
& rLayoutNode
, bool isElse
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttributes
);
279 virtual void accept( LayoutAtomVisitor
& ) override
;
280 bool getDecision(const svx::diagram::Point
* pPresPoint
) const;
283 static bool compareResult(sal_Int32 nOperator
, sal_Int32 nFirst
, sal_Int32 nSecond
);
284 sal_Int32
getNodeCount(const svx::diagram::Point
* pPresPoint
) const;
288 ConditionAttr maCond
;
291 typedef std::shared_ptr
< ConditionAtom
> ConditionAtomPtr
;
293 /** "choose" statements. Atoms will be tested in order. */
298 ChooseAtom(LayoutNode
& rLayoutNode
)
299 : LayoutAtom(rLayoutNode
)
301 virtual void accept( LayoutAtomVisitor
& ) override
;
308 typedef std::map
<sal_Int32
, OUString
> VarMap
;
310 LayoutNode(Diagram
& rDgm
)
316 Diagram
& getDiagram() { return mrDgm
; }
317 virtual void accept( LayoutAtomVisitor
& ) override
;
319 { return mVariables
; }
320 void setMoveWith( const OUString
& sName
)
321 { msMoveWith
= sName
; }
322 void setStyleLabel( const OUString
& sLabel
)
323 { msStyleLabel
= sLabel
; }
324 void setChildOrder( sal_Int32 nOrder
)
325 { mnChildOrder
= nOrder
; }
326 sal_Int32
getChildOrder() const { return mnChildOrder
; }
327 void setExistingShape( const ShapePtr
& pShape
)
328 { mpExistingShape
= pShape
; }
329 const ShapePtr
& getExistingShape() const
330 { return mpExistingShape
; }
331 const std::vector
<ShapePtr
> & getNodeShapes() const
332 { return mpNodeShapes
; }
333 void addNodeShape(const ShapePtr
& pShape
)
334 { mpNodeShapes
.push_back(pShape
); }
336 bool setupShape( const ShapePtr
& rShape
,
337 const svx::diagram::Point
* pPresNode
,
338 sal_Int32 nCurrIdx
) const;
340 const LayoutNode
* getParentLayoutNode() const;
346 OUString msStyleLabel
;
347 ShapePtr mpExistingShape
;
348 std::vector
<ShapePtr
> mpNodeShapes
;
349 sal_Int32 mnChildOrder
;
352 typedef std::shared_ptr
< LayoutNode
> LayoutNodePtr
;
358 ShapeAtom(LayoutNode
& rLayoutNode
, ShapePtr pShape
) : LayoutAtom(rLayoutNode
), mpShapeTemplate(std::move(pShape
)) {}
359 virtual void accept( LayoutAtomVisitor
& ) override
;
360 const ShapePtr
& getShapeTemplate() const
361 { return mpShapeTemplate
; }
364 ShapePtr mpShapeTemplate
;
367 typedef std::shared_ptr
< ShapeAtom
> ShapeAtomPtr
;
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */