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,
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 );
......
......@@ -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);
......
......@@ -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;
......
......@@ -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 ):
......
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