Kaydet (Commit) 923061d1 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/62367Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
üst a8b72c8a
...@@ -50,7 +50,7 @@ ConstraintListContext::onCreateContext( ::sal_Int32 aElement, ...@@ -50,7 +50,7 @@ ConstraintListContext::onCreateContext( ::sal_Int32 aElement,
case DGM_TOKEN( constr ): case DGM_TOKEN( constr ):
{ {
std::shared_ptr< ConstraintAtom > pNode( new ConstraintAtom(mpNode->getLayoutNode()) ); std::shared_ptr< ConstraintAtom > pNode( new ConstraintAtom(mpNode->getLayoutNode()) );
mpNode->addChild( pNode ); LayoutAtom::connect(mpNode, pNode);
Constraint& rConstraint = pNode->getConstraint(); Constraint& rConstraint = pNode->getConstraint();
rConstraint.mnFor = rAttribs.getToken( XML_for, XML_none ); rConstraint.mnFor = rAttribs.getToken( XML_for, XML_none );
......
...@@ -227,6 +227,19 @@ void AlgAtom::accept( LayoutAtomVisitor& rVisitor ) ...@@ -227,6 +227,19 @@ void AlgAtom::accept( LayoutAtomVisitor& rVisitor )
void AlgAtom::layoutShape( const ShapePtr& rShape, void AlgAtom::layoutShape( const ShapePtr& rShape,
const std::vector<Constraint>& rConstraints ) const 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) switch(mnType)
{ {
case XML_composite: case XML_composite:
...@@ -357,11 +370,10 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -357,11 +370,10 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
double fSpace = 0.3; double fSpace = 0.3;
awt::Size aChildSize = rShape->getSize(); awt::Size aChildSize = rShape->getSize();
if (nDir == XML_fromL || nDir == XML_fromR)
// Lineral vertically: no adjustment of width.
if (nDir != XML_fromT)
aChildSize.Width /= (nCount + (nCount-1)*fSpace); 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); awt::Point aCurrPos(0, 0);
if (nIncX == -1) if (nIncX == -1)
...@@ -756,6 +768,18 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode ...@@ -756,6 +768,18 @@ bool LayoutNode::setupShape( const ShapePtr& rShape, const dgm::Point* pPresNode
return true; 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 ) void ShapeAtom::accept( LayoutAtomVisitor& rVisitor )
{ {
rVisitor.visit(*this); rVisitor.visit(*this);
......
...@@ -106,17 +106,30 @@ public: ...@@ -106,17 +106,30 @@ public:
const OUString& getName() const const OUString& getName() const
{ return msName; } { return msName; }
private:
void addChild( const LayoutAtomPtr & pNode ) void addChild( const LayoutAtomPtr & pNode )
{ mpChildNodes.push_back( pNode ); } { mpChildNodes.push_back( pNode ); }
void setParent(const LayoutAtomPtr& pParent) { mpParent = pParent; }
public:
virtual const std::vector<LayoutAtomPtr>& getChildren() const virtual const std::vector<LayoutAtomPtr>& getChildren() const
{ return mpChildNodes; } { 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 // dump for debug
void dump(int level = 0); void dump(int level = 0);
protected: protected:
const LayoutNode& mrLayoutNode; const LayoutNode& mrLayoutNode;
std::vector< LayoutAtomPtr > mpChildNodes; std::vector< LayoutAtomPtr > mpChildNodes;
std::weak_ptr<LayoutAtom> mpParent;
OUString msName; OUString msName;
}; };
...@@ -238,6 +251,8 @@ public: ...@@ -238,6 +251,8 @@ public:
bool setupShape( const ShapePtr& rShape, bool setupShape( const ShapePtr& rShape,
const dgm::Point* pPresNode ) const; const dgm::Point* pPresNode ) const;
const LayoutNode* getParentLayoutNode() const;
private: private:
const Diagram& mrDgm; const Diagram& mrDgm;
VarMap mVariables; VarMap mVariables;
......
...@@ -106,14 +106,14 @@ public: ...@@ -106,14 +106,14 @@ public:
{ {
// CT_When // CT_When
ConditionAtomPtr pNode( new ConditionAtom(mpNode->getLayoutNode(), false, rAttribs.getFastAttributeList()) ); ConditionAtomPtr pNode( new ConditionAtom(mpNode->getLayoutNode(), false, rAttribs.getFastAttributeList()) );
mpNode->addChild( pNode ); LayoutAtom::connect(mpNode, pNode);
return new IfContext( *this, rAttribs, pNode ); return new IfContext( *this, rAttribs, pNode );
} }
case DGM_TOKEN( else ): case DGM_TOKEN( else ):
{ {
// CT_Otherwise // CT_Otherwise
ConditionAtomPtr pNode( new ConditionAtom(mpNode->getLayoutNode(), true, rAttribs.getFastAttributeList()) ); ConditionAtomPtr pNode( new ConditionAtom(mpNode->getLayoutNode(), true, rAttribs.getFastAttributeList()) );
mpNode->addChild( pNode ); LayoutAtom::connect(mpNode, pNode);
return new IfContext( *this, rAttribs, pNode ); return new IfContext( *this, rAttribs, pNode );
} }
default: default:
...@@ -183,7 +183,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement, ...@@ -183,7 +183,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
case DGM_TOKEN( layoutNode ): case DGM_TOKEN( layoutNode ):
{ {
LayoutNodePtr pNode( new LayoutNode(mpNode->getLayoutNode().getDiagram()) ); LayoutNodePtr pNode( new LayoutNode(mpNode->getLayoutNode().getDiagram()) );
mpNode->addChild( pNode ); LayoutAtom::connect(mpNode, pNode);
pNode->setChildOrder( rAttribs.getToken( XML_chOrder, XML_b ) ); pNode->setChildOrder( rAttribs.getToken( XML_chOrder, XML_b ) );
pNode->setMoveWith( rAttribs.getString( XML_moveWith ).get() ); pNode->setMoveWith( rAttribs.getString( XML_moveWith ).get() );
pNode->setStyleLabel( rAttribs.getString( XML_styleLbl ).get() ); pNode->setStyleLabel( rAttribs.getString( XML_styleLbl ).get() );
...@@ -211,7 +211,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement, ...@@ -211,7 +211,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE); pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE);
ShapeAtomPtr pAtom( new ShapeAtom(mpNode->getLayoutNode(), pShape) ); ShapeAtomPtr pAtom( new ShapeAtom(mpNode->getLayoutNode(), pShape) );
mpNode->addChild( pAtom ); LayoutAtom::connect(mpNode, pAtom);
return new ShapeContext( *this, ShapePtr(), pShape ); return new ShapeContext( *this, ShapePtr(), pShape );
} }
case DGM_TOKEN( extLst ): case DGM_TOKEN( extLst ):
...@@ -220,21 +220,21 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement, ...@@ -220,21 +220,21 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
{ {
// CT_Algorithm // CT_Algorithm
AlgAtomPtr pAtom( new AlgAtom(mpNode->getLayoutNode()) ); AlgAtomPtr pAtom( new AlgAtom(mpNode->getLayoutNode()) );
mpNode->addChild( pAtom ); LayoutAtom::connect(mpNode, pAtom);
return new AlgorithmContext( *this, rAttribs, pAtom ); return new AlgorithmContext( *this, rAttribs, pAtom );
} }
case DGM_TOKEN( choose ): case DGM_TOKEN( choose ):
{ {
// CT_Choose // CT_Choose
LayoutAtomPtr pAtom( new ChooseAtom(mpNode->getLayoutNode()) ); LayoutAtomPtr pAtom( new ChooseAtom(mpNode->getLayoutNode()) );
mpNode->addChild( pAtom ); LayoutAtom::connect(mpNode, pAtom);
return new ChooseContext( *this, rAttribs, pAtom ); return new ChooseContext( *this, rAttribs, pAtom );
} }
case DGM_TOKEN( forEach ): case DGM_TOKEN( forEach ):
{ {
// CT_ForEach // CT_ForEach
ForEachAtomPtr pAtom( new ForEachAtom(mpNode->getLayoutNode(), rAttribs.getFastAttributeList()) ); ForEachAtomPtr pAtom( new ForEachAtom(mpNode->getLayoutNode(), rAttribs.getFastAttributeList()) );
mpNode->addChild( pAtom ); LayoutAtom::connect(mpNode, pAtom);
return new ForEachContext( *this, rAttribs, pAtom ); return new ForEachContext( *this, rAttribs, pAtom );
} }
case DGM_TOKEN( constrLst ): case DGM_TOKEN( constrLst ):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment