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 <boost/shared_ptr.hpp>
27 #include <boost/array.hpp>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
32 #include "oox/drawingml/shape.hxx"
33 #include "diagram.hxx"
35 namespace oox
{ namespace drawingml
{
38 typedef boost::shared_ptr
< DiagramLayout
> DiagramLayoutPtr
;
40 // AG_IteratorAttributes
45 // not sure this belong here, but wth
46 void loadFromXAttr( const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>& xAttributes
);
60 // not sure this belong here, but wth
61 void loadFromXAttr( const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>& xAttributes
);
69 struct LayoutAtomVisitor
;
72 typedef boost::shared_ptr
< LayoutAtom
> LayoutAtomPtr
;
74 /** abstract Atom for the layout */
78 virtual ~LayoutAtom() { }
80 /** visitor acceptance
82 virtual void accept( LayoutAtomVisitor
& ) = 0;
84 void setName( const OUString
& sName
)
86 const OUString
& getName() const
89 virtual void addChild( const LayoutAtomPtr
& pNode
)
90 { mpChildNodes
.push_back( pNode
); }
91 virtual const std::vector
<LayoutAtomPtr
>& getChildren() const
92 { return mpChildNodes
; }
95 void dump(int level
= 0);
97 std::vector
< LayoutAtomPtr
> mpChildNodes
;
106 mnFor(-1), msForName(), mnPointType(-1), mnType(-1), mnRefFor(-1), msRefForName(),
107 mnRefType(-1), mnRefPointType(-1), mfFactor(1.0), mfValue(0.0), mnOperator(0)
110 virtual ~ConstraintAtom() { }
112 virtual void accept( LayoutAtomVisitor
& ) SAL_OVERRIDE
;
114 void setFor( sal_Int32 nToken
)
116 void setForName( const OUString
& sName
)
117 { msForName
= sName
; }
118 void setPointType( sal_Int32 nToken
)
119 { mnPointType
= nToken
; }
120 void setType( sal_Int32 nToken
)
122 void setRefFor( sal_Int32 nToken
)
123 { mnRefFor
= nToken
; }
124 void setRefForName( const OUString
& sName
)
125 { msRefForName
= sName
; }
126 void setRefType( sal_Int32 nToken
)
127 { mnRefType
= nToken
; }
128 void setRefPointType( sal_Int32 nToken
)
129 { mnRefPointType
= nToken
; }
130 void setFactor( const double& fVal
)
132 void setValue( const double& fVal
)
134 void setOperator( sal_Int32 nToken
)
135 { mnOperator
= nToken
; }
139 sal_Int32 mnPointType
;
142 OUString msRefForName
;
144 sal_Int32 mnRefPointType
;
147 sal_Int32 mnOperator
;
150 typedef boost::shared_ptr
< ConstraintAtom
> ConstraintAtomPtr
;
156 AlgAtom() : mnType(0), maMap() {}
158 virtual ~AlgAtom() { }
160 typedef std::map
<sal_Int32
,sal_Int32
> ParamMap
;
162 virtual void accept( LayoutAtomVisitor
& ) SAL_OVERRIDE
;
164 void setType( sal_Int32 nToken
)
166 void addParam( sal_Int32 nType
, sal_Int32 nVal
)
167 { maMap
[nType
]=nVal
; }
168 void layoutShape( const ShapePtr
& rShape
,
170 const OUString
& rName
) const;
176 typedef boost::shared_ptr
< AlgAtom
> AlgAtomPtr
;
182 explicit ForEachAtom(const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>& xAttributes
);
184 virtual ~ForEachAtom() { }
186 IteratorAttr
& iterator()
188 virtual void accept( LayoutAtomVisitor
& ) SAL_OVERRIDE
;
194 typedef boost::shared_ptr
< ForEachAtom
> ForEachAtomPtr
;
200 explicit ConditionAtom(const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>& xAttributes
);
201 virtual ~ConditionAtom()
204 virtual void accept( LayoutAtomVisitor
& ) SAL_OVERRIDE
;
205 IteratorAttr
& iterator()
207 ConditionAttr
& cond()
209 void readElseBranch()
211 virtual void addChild( const LayoutAtomPtr
& pNode
) SAL_OVERRIDE
;
212 virtual const std::vector
<LayoutAtomPtr
>& getChildren() const SAL_OVERRIDE
;
216 ConditionAttr maCond
;
217 std::vector
< LayoutAtomPtr
> mpElseChildNodes
;
220 typedef boost::shared_ptr
< ConditionAtom
> ConditionAtomPtr
;
222 /** "choose" statements. Atoms will be tested in order. */
227 virtual ~ChooseAtom()
229 virtual void accept( LayoutAtomVisitor
& ) SAL_OVERRIDE
;
247 // we know that the array is of fixed size
248 // the use of Any allow having empty values
249 typedef boost::array
< ::com::sun::star::uno::Any
, 9 > VarMap
;
251 LayoutNode() : mnChildOrder(0) {}
252 virtual ~LayoutNode() { }
253 virtual void accept( LayoutAtomVisitor
& ) SAL_OVERRIDE
;
255 { return mVariables
; }
256 void setMoveWith( const OUString
& sName
)
257 { msMoveWith
= sName
; }
258 void setStyleLabel( const OUString
& sLabel
)
259 { msStyleLabel
= sLabel
; }
260 void setChildOrder( sal_Int32 nOrder
)
261 { mnChildOrder
= nOrder
; }
262 void setShape( const ShapePtr
& pShape
)
263 { mpShape
= pShape
; }
264 const ShapePtr
& getShape() const
267 bool setupShape( const ShapePtr
& rShape
,
269 sal_uInt32 nIdx
) const;
274 OUString msStyleLabel
;
276 sal_Int32 mnChildOrder
;
279 typedef boost::shared_ptr
< LayoutNode
> LayoutNodePtr
;
281 struct LayoutAtomVisitor
283 virtual ~LayoutAtomVisitor() {}
284 virtual void visit(ConstraintAtom
& rAtom
) = 0;
285 virtual void visit(AlgAtom
& rAtom
) = 0;
286 virtual void visit(ForEachAtom
& rAtom
) = 0;
287 virtual void visit(ConditionAtom
& rAtom
) = 0;
288 virtual void visit(ChooseAtom
& rAtom
) = 0;
289 virtual void visit(LayoutNode
& rAtom
) = 0;
292 class ShapeCreationVisitor
: public LayoutAtomVisitor
294 ShapePtr mpParentShape
;
295 const Diagram
& mrDgm
;
298 void defaultVisit(LayoutAtom
& rAtom
);
299 virtual void visit(ConstraintAtom
& rAtom
) SAL_OVERRIDE
;
300 virtual void visit(AlgAtom
& rAtom
) SAL_OVERRIDE
;
301 virtual void visit(ForEachAtom
& rAtom
) SAL_OVERRIDE
;
302 virtual void visit(ConditionAtom
& rAtom
) SAL_OVERRIDE
;
303 virtual void visit(ChooseAtom
& rAtom
) SAL_OVERRIDE
;
304 virtual void visit(LayoutNode
& rAtom
) SAL_OVERRIDE
;
307 ShapeCreationVisitor(const ShapePtr
& rParentShape
,
308 const Diagram
& rDgm
) :
309 mpParentShape(rParentShape
),
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */