summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-10-25 17:42:36 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-10-25 20:00:28 +0200
commit923061d17d4b5b8bf0d4a8111b270c99a7c649a9 (patch)
tree045ab60cd5d9c0bc198f6736902519c724137a3c
parenta8b72c8a54ab6ce68764a4c5b97b7af0e30ce566 (diff)
oox smartart: work towards accessing parent constraints
The "Vertical Box List" preset in PowerPoint contains two linear layouts, the inner one nested in the outer one. All the constraints are stated on the parent layout. This commit doesn't actually read those constraints yet, but adds infrastructure to look up parents of layout nodes and also to get the constraints of a layout node. No functional changes intended. Change-Id: If844d17a90f8f180a9d21245249a2744bea32b31 Reviewed-on: https://gerrit.libreoffice.org/62367 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins
-rw-r--r--oox/source/drawingml/diagram/constraintlistcontext.cxx2
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.cxx32
-rw-r--r--oox/source/drawingml/diagram/diagramlayoutatoms.hxx15
-rw-r--r--oox/source/drawingml/diagram/layoutnodecontext.cxx14
4 files changed, 51 insertions, 12 deletions
diff --git a/oox/source/drawingml/diagram/constraintlistcontext.cxx b/oox/source/drawingml/diagram/constraintlistcontext.cxx
index 99e3f3d10e72..cc71c89b226a 100644
--- a/oox/source/drawingml/diagram/constraintlistcontext.cxx
+++ b/oox/source/drawingml/diagram/constraintlistcontext.cxx
@@ -50,7 +50,7 @@ ConstraintListContext::onCreateContext( ::sal_Int32 aElement,
case DGM_TOKEN( constr ):
{
std::shared_ptr< ConstraintAtom > pNode( new ConstraintAtom(mpNode->getLayoutNode()) );
- mpNode->addChild( pNode );
+ LayoutAtom::connect(mpNode, pNode);
Constraint& rConstraint = pNode->getConstraint();
rConstraint.mnFor = rAttribs.getToken( XML_for, XML_none );
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 7ef0e456ce0f..eeaa0812383d 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -227,6 +227,19 @@ void AlgAtom::accept( LayoutAtomVisitor& rVisitor )
void AlgAtom::layoutShape( const ShapePtr& rShape,
const std::vector<Constraint>& rConstraints ) const
{
+ // Algorithm result may depend on the parent constraints as well.
+ std::vector<Constraint> aParentConstraints;
+ const LayoutNode* pParent = getLayoutNode().getParentLayoutNode();
+ if (pParent)
+ {
+ for (const auto& pChild : pParent->getChildren())
+ {
+ auto pConstraintAtom = dynamic_cast<ConstraintAtom*>(pChild.get());
+ if (pConstraintAtom)
+ pConstraintAtom->parseConstraint(aParentConstraints);
+ }
+ }
+
switch(mnType)
{
case XML_composite:
@@ -357,11 +370,10 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
double fSpace = 0.3;
awt::Size aChildSize = rShape->getSize();
-
- // Lineral vertically: no adjustment of width.
- if (nDir != XML_fromT)
+ if (nDir == XML_fromL || nDir == XML_fromR)
aChildSize.Width /= (nCount + (nCount-1)*fSpace);
- aChildSize.Height /= (nCount + (nCount-1)*fSpace);
+ else if (nDir == XML_fromT || nDir == XML_fromB)
+ aChildSize.Height /= (nCount + (nCount-1)*fSpace);
awt::Point aCurrPos(0, 0);
if (nIncX == -1)
@@ -756,6 +768,18 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
return true;
}
+const LayoutNode* LayoutNode::getParentLayoutNode() const
+{
+ for (LayoutAtomPtr pAtom = getParent(); pAtom; pAtom = pAtom->getParent())
+ {
+ auto pLayoutNode = dynamic_cast<LayoutNode*>(pAtom.get());
+ if (pLayoutNode)
+ return pLayoutNode;
+ }
+
+ return nullptr;
+}
+
void ShapeAtom::accept( LayoutAtomVisitor& rVisitor )
{
rVisitor.visit(*this);
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
index 606e8794becc..50ff8a300ac5 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
@@ -106,17 +106,30 @@ public:
const OUString& getName() const
{ return msName; }
+private:
void addChild( const LayoutAtomPtr & pNode )
{ mpChildNodes.push_back( pNode ); }
+ void setParent(const LayoutAtomPtr& pParent) { mpParent = pParent; }
+
+public:
virtual const std::vector<LayoutAtomPtr>& getChildren() const
{ return mpChildNodes; }
+ LayoutAtomPtr getParent() const { return mpParent.lock(); }
+
+ static void connect(const LayoutAtomPtr& pParent, const LayoutAtomPtr& pChild)
+ {
+ pParent->addChild(pChild);
+ pChild->setParent(pParent);
+ }
+
// dump for debug
void dump(int level = 0);
protected:
const LayoutNode& mrLayoutNode;
std::vector< LayoutAtomPtr > mpChildNodes;
+ std::weak_ptr<LayoutAtom> mpParent;
OUString msName;
};
@@ -238,6 +251,8 @@ public:
bool setupShape( const ShapePtr& rShape,
const dgm::Point* pPresNode ) const;
+ const LayoutNode* getParentLayoutNode() const;
+
private:
const Diagram& mrDgm;
VarMap mVariables;
diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx
index 682348172f87..d81cbdf74ae0 100644
--- a/oox/source/drawingml/diagram/layoutnodecontext.cxx
+++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx
@@ -106,14 +106,14 @@ public:
{
// CT_When
ConditionAtomPtr pNode( new ConditionAtom(mpNode->getLayoutNode(), false, rAttribs.getFastAttributeList()) );
- mpNode->addChild( pNode );
+ LayoutAtom::connect(mpNode, pNode);
return new IfContext( *this, rAttribs, pNode );
}
case DGM_TOKEN( else ):
{
// CT_Otherwise
ConditionAtomPtr pNode( new ConditionAtom(mpNode->getLayoutNode(), true, rAttribs.getFastAttributeList()) );
- mpNode->addChild( pNode );
+ LayoutAtom::connect(mpNode, pNode);
return new IfContext( *this, rAttribs, pNode );
}
default:
@@ -183,7 +183,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
case DGM_TOKEN( layoutNode ):
{
LayoutNodePtr pNode( new LayoutNode(mpNode->getLayoutNode().getDiagram()) );
- mpNode->addChild( pNode );
+ LayoutAtom::connect(mpNode, pNode);
pNode->setChildOrder( rAttribs.getToken( XML_chOrder, XML_b ) );
pNode->setMoveWith( rAttribs.getString( XML_moveWith ).get() );
pNode->setStyleLabel( rAttribs.getString( XML_styleLbl ).get() );
@@ -211,7 +211,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE);
ShapeAtomPtr pAtom( new ShapeAtom(mpNode->getLayoutNode(), pShape) );
- mpNode->addChild( pAtom );
+ LayoutAtom::connect(mpNode, pAtom);
return new ShapeContext( *this, ShapePtr(), pShape );
}
case DGM_TOKEN( extLst ):
@@ -220,21 +220,21 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
{
// CT_Algorithm
AlgAtomPtr pAtom( new AlgAtom(mpNode->getLayoutNode()) );
- mpNode->addChild( pAtom );
+ LayoutAtom::connect(mpNode, pAtom);
return new AlgorithmContext( *this, rAttribs, pAtom );
}
case DGM_TOKEN( choose ):
{
// CT_Choose
LayoutAtomPtr pAtom( new ChooseAtom(mpNode->getLayoutNode()) );
- mpNode->addChild( pAtom );
+ LayoutAtom::connect(mpNode, pAtom);
return new ChooseContext( *this, rAttribs, pAtom );
}
case DGM_TOKEN( forEach ):
{
// CT_ForEach
ForEachAtomPtr pAtom( new ForEachAtom(mpNode->getLayoutNode(), rAttribs.getFastAttributeList()) );
- mpNode->addChild( pAtom );
+ LayoutAtom::connect(mpNode, pAtom);
return new ForEachContext( *this, rAttribs, pAtom );
}
case DGM_TOKEN( constrLst ):