Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / diagram / diagramlayoutatoms.hxx
blob68cff05e85c8e1bd7bb9305ff45bc73ec56c435f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <map>
24 #include <memory>
25 #include <array>
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 {
35 class DiagramLayout;
36 typedef std::shared_ptr< DiagramLayout > DiagramLayoutPtr;
38 // AG_IteratorAttributes
39 struct IteratorAttr
41 IteratorAttr();
43 // not sure this belong here, but wth
44 void loadFromXAttr( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
46 sal_Int32 mnAxis;
47 sal_Int32 mnCnt;
48 bool mbHideLastTrans;
49 sal_Int32 mnPtType;
50 sal_Int32 mnSt;
51 sal_Int32 mnStep;
54 struct ConditionAttr
56 ConditionAttr();
58 // not sure this belong here, but wth
59 void loadFromXAttr( const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes );
61 sal_Int32 mnFunc;
62 sal_Int32 mnArg;
63 sal_Int32 mnOp;
64 OUString msVal;
67 struct LayoutAtomVisitor;
68 class LayoutAtom;
70 typedef std::shared_ptr< LayoutAtom > LayoutAtomPtr;
72 /** abstract Atom for the layout */
73 class LayoutAtom
75 public:
76 virtual ~LayoutAtom() { }
78 /** visitor acceptance
80 virtual void accept( LayoutAtomVisitor& ) = 0;
82 void setName( const OUString& sName )
83 { msName = sName; }
84 const OUString& getName() const
85 { return msName; }
87 virtual void addChild( const LayoutAtomPtr & pNode )
88 { mpChildNodes.push_back( pNode ); }
89 virtual const std::vector<LayoutAtomPtr>& getChildren() const
90 { return mpChildNodes; }
92 // dump for debug
93 void dump(int level = 0);
94 protected:
95 std::vector< LayoutAtomPtr > mpChildNodes;
96 OUString msName;
99 class ConstraintAtom
100 : public LayoutAtom
102 public:
103 ConstraintAtom() :
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 )
111 { mnFor = 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 )
117 { mnType = 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 )
127 { mfFactor = fVal; }
128 void setValue( const double& fVal )
129 { mfValue = fVal; }
130 void setOperator( sal_Int32 nToken )
131 { mnOperator = nToken; }
132 private:
133 sal_Int32 mnFor;
134 OUString msForName;
135 sal_Int32 mnPointType;
136 sal_Int32 mnType;
137 sal_Int32 mnRefFor;
138 OUString msRefForName;
139 sal_Int32 mnRefType;
140 sal_Int32 mnRefPointType;
141 double mfFactor;
142 double mfValue;
143 sal_Int32 mnOperator;
146 class AlgAtom
147 : public LayoutAtom
149 public:
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 )
157 { mnType = 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;
162 private:
163 sal_Int32 mnType;
164 ParamMap maMap;
167 typedef std::shared_ptr< AlgAtom > AlgAtomPtr;
169 class ForEachAtom
170 : public LayoutAtom
172 public:
173 explicit ForEachAtom(const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes);
175 IteratorAttr & iterator()
176 { return maIter; }
177 virtual void accept( LayoutAtomVisitor& ) override;
179 private:
180 IteratorAttr maIter;
183 typedef std::shared_ptr< ForEachAtom > ForEachAtomPtr;
185 class ConditionAtom
186 : public LayoutAtom
188 public:
189 explicit ConditionAtom(const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttributes);
190 virtual void accept( LayoutAtomVisitor& ) override;
191 void readElseBranch()
192 { mbElse=true; }
193 virtual void addChild( const LayoutAtomPtr & pNode ) override;
194 virtual const std::vector<LayoutAtomPtr>& getChildren() const override;
195 private:
196 bool mbElse;
197 IteratorAttr maIter;
198 ConditionAttr maCond;
199 std::vector< LayoutAtomPtr > mpElseChildNodes;
202 typedef std::shared_ptr< ConditionAtom > ConditionAtomPtr;
204 /** "choose" statements. Atoms will be tested in order. */
205 class ChooseAtom
206 : public LayoutAtom
208 public:
209 virtual void accept( LayoutAtomVisitor& ) override;
212 class LayoutNode
213 : public LayoutAtom
215 public:
216 enum {
217 VAR_animLvl = 0,
218 VAR_animOne,
219 VAR_bulletEnabled,
220 VAR_chMax,
221 VAR_chPref,
222 VAR_dir,
223 VAR_hierBranch,
224 VAR_orgChart,
225 VAR_resizeHandles
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;
233 VarMap & variables()
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
244 { return mpShape; }
246 bool setupShape( const ShapePtr& rShape,
247 const Diagram& rDgm,
248 sal_uInt32 nIdx ) const;
250 private:
251 VarMap mVariables;
252 OUString msMoveWith;
253 OUString msStyleLabel;
254 ShapePtr mpShape;
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;
275 sal_Int32 mnCurrIdx;
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;
285 public:
286 ShapeCreationVisitor(const ShapePtr& rParentShape,
287 const Diagram& rDgm) :
288 mpParentShape(rParentShape),
289 mrDgm(rDgm),
290 mnCurrIdx(0)
296 #endif
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */