/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** * The SwNode2LayImpl class does the actual work, the SwNode2Layout class is * just the public interface.
*/ class SwNode2LayImpl
{
std::unique_ptr<SwIterator<SwFrame, sw::BroadcastingModify, sw::IteratorMode::UnwrapMulti>> mpIter;
sw::BroadcastingModify* mpMod;
std::vector<SwFrame*> mvUpperFrames; // To collect the Upper
SwNodeOffset mnIndex; // The Index of the to-be-inserted Nodes bool mbMaster : 1; // true => only Master, false => only Frames without Follow bool mbInit : 1; // Did we already call First() at SwClient?
SwFrame const* FindNeighbourFrameForNode(SwNode const& rNode)
{
SwNodeIndex idx(rNode);
SwFlowFrame const* pFlow(nullptr); if (GoPreviousWithFrame(&idx, &pFlow))
{ if (::CheckNodesRange(rNode, idx.GetNode(), true))
{ while (pFlow->HasFollow())
{ // try to get the one on the current page
pFlow = pFlow->GetFollow();
} return &pFlow->GetFrame();
}
}
idx = rNode; if (GoNextWithFrame(idx.GetNodes(), &idx, &pFlow))
{ if (::CheckNodesRange(rNode, idx.GetNode(), true))
{ while (pFlow->IsFollow())
{ // try to get the one on the current page
pFlow = pFlow->GetPrecede();
} return &pFlow->GetFrame();
}
} return nullptr;
}
}
/** * The main purpose of this ctor is to find the right sw::BroadcastingModify to iterate over. * * @param bSearch true: find the next Content or TableNode which contains * Frames (to collect the pUpper). * Else we assume that rNode points already to such a * Content or TableNode. * We insert before or after it.
*/
SwNode2LayImpl::SwNode2LayImpl( const SwNode& rNode, SwNodeOffset nIdx, bool bSearch )
: mnIndex( nIdx ), mbInit( false )
{ const SwNode* pNd; if( bSearch || rNode.IsSectionNode() )
{ // Find the next Content/TableNode that contains a Frame, so that we can add // ourselves before/after it if( !bSearch && rNode.GetIndex() < mnIndex )
{
SwNodeIndex aTmp( *rNode.EndOfSectionNode(), +1 );
pNd = GoPreviousWithFrame(&aTmp, nullptr); if( pNd && rNode.GetIndex() > pNd->GetIndex() )
pNd = nullptr; // Do not go over the limits
mbMaster = false;
} else
{
SwNodeIndex aTmp( rNode, -1 );
pNd = GoNextWithFrame(rNode.GetNodes(), &aTmp, nullptr);
mbMaster = true; if( !bSearch && pNd && rNode.EndOfSectionIndex() < pNd->GetIndex() )
pNd = nullptr; // Do not go over the limits
}
} else
{
pNd = &rNode;
mbMaster = mnIndex < rNode.GetIndex();
} if( pNd )
{ if( pNd->IsContentNode() )
mpMod = const_cast<sw::BroadcastingModify*>(static_cast<sw::BroadcastingModify const *>(pNd->GetContentNode())); else
{
assert(pNd->IsTableNode());
mpMod = pNd->GetTableNode()->GetTable().GetFrameFormat();
}
mpIter.reset(new SwIterator<SwFrame, sw::BroadcastingModify, sw::IteratorMode::UnwrapMulti>(*mpMod));
} else
{
mpIter = nullptr;
mpMod = nullptr;
}
}
/** * Returns the next "useful" Frame. * * When calling this method for the first time, a First is triggered at the * actual Iterator. The result is check for suitability: Follows are not * accepted, a Master is accepted when collecting the pUpper and when * inserting before it. * When inserting after it, we find and return the last Follow starting * from the Master. * * If the Frame is located in a SectionFrame, we check to see whether the * SectionFrame is the suitable return value (instead of the Frame itself). * This is the case if the to-be-inserted Node is outside of the Section.
*/
SwFrame* SwNode2LayImpl::NextFrame()
{
SwFrame* pRet; if( !mpIter ) return nullptr; if( !mbInit )
{
pRet = mpIter->First();
mbInit = true;
} else
pRet = mpIter->Next(); while( pRet )
{
SwFlowFrame* pFlow = SwFlowFrame::CastFlowFrame( pRet );
assert(pFlow); // Follows are pretty volatile, thus we ignore them. // Even if we insert after the Frame, we start from the Master // and iterate through it until the last Follow if( !pFlow->IsFollow() )
{ if( !mbMaster )
{ while( pFlow->HasFollow() )
pFlow = pFlow->GetFollow();
pRet = &(pFlow->GetFrame());
} if( pRet->IsInSct() )
{
SwSectionFrame* pSct = pRet->FindSctFrame(); // ATTENTION: If we are in a Footnote, from a Layout point of view // it could be located in a Section with columns, although it // should be outside of it when looking at the Nodes. // Thus, when dealing with Footnotes, we need to check whether the // SectionFrame is also located within the Footnote and not outside of it. if( !pRet->IsInFootnote() || pSct->IsInFootnote() )
{
assert(pSct && pSct->GetSection());
SwSectionNode* pNd = pSct->GetSection()->GetFormat()->GetSectionNode();
assert(pNd); // If the result Frame is located within a Section Frame // whose Section does not contain the Node, we return with // the SectionFrame, else we return with the Content/TabFrame if( mbMaster )
{ if( pNd->GetIndex() >= mnIndex )
pRet = pSct;
} elseif( pNd->EndOfSectionIndex() < mnIndex )
pRet = pSct;
}
} return pRet;
}
pRet = mpIter->Next();
} return nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.