summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2018-10-19 14:49:12 +0200
committerMichael Stahl <Michael.Stahl@cib.de>2018-11-10 19:47:00 +0100
commit47bc166b3c31d9a370e1f4aad8acef62f3ed0e5d (patch)
tree1ff05a7c33f71fb8da7d41b6d8cfdddf9781649d
parent291ad692be1a9b956cfd909f52a30f100b786aa0 (diff)
sw_redlinehide_3: add second SwNodeNum tree to SwList
... so it can be used when redlines are hidden in the layout. Change-Id: I6cb2bca2fb8ba3913bbf6633996341b52639fe41
-rw-r--r--sw/inc/list.hxx1
-rw-r--r--sw/source/core/doc/list.cxx53
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx40
3 files changed, 64 insertions, 30 deletions
diff --git a/sw/inc/list.hxx b/sw/inc/list.hxx
index 1c5bfc7d4478..1cfdad5e0716 100644
--- a/sw/inc/list.hxx
+++ b/sw/inc/list.hxx
@@ -44,6 +44,7 @@ class SwList
void SetDefaultListStyleName(OUString const&);
void InsertListItem( SwNodeNum& rNodeNum,
+ bool isHiddenRedlines,
const int nLevel );
static void RemoveListItem( SwNodeNum& rNodeNum );
diff --git a/sw/source/core/doc/list.cxx b/sw/source/core/doc/list.cxx
index a3c4e90dcc49..c449c58e97b0 100644
--- a/sw/source/core/doc/list.cxx
+++ b/sw/source/core/doc/list.cxx
@@ -39,7 +39,7 @@ class SwListImpl
const OUString& GetDefaultListStyleName() const { return msDefaultListStyleName;}
- void InsertListItem( SwNodeNum& rNodeNum,
+ void InsertListItem( SwNodeNum& rNodeNum, bool isHiddenRedlines,
const int nLevel );
static void RemoveListItem( SwNodeNum& rNodeNum );
@@ -57,7 +57,24 @@ class SwListImpl
OUString msDefaultListStyleName;
// list trees for certain document ranges
- typedef std::pair<std::unique_ptr<SwNodeNum>, std::unique_ptr<SwPaM>> tListTreeForRange;
+ struct tListTreeForRange
+ {
+ /// tree always corresponds to document model
+ std::unique_ptr<SwNodeNum> pRoot;
+ /// Tree that is missing those nodes that are merged or hidden
+ /// by delete redlines; this is only used if there is a layout
+ /// that has IsHideRedlines() enabled.
+ /// A second tree is needed because not only are the numbers in
+ /// the nodes different, the structure of the tree may be different
+ /// as well, if a high-level node is hidden its children go under
+ /// the previous node on the same level.
+ /// The nodes of pRootRLHidden are a subset of the nodes of pRoot.
+ std::unique_ptr<SwNodeNum> pRootRLHidden;
+ /// top-level SwNodes section
+ std::unique_ptr<SwPaM> pSection;
+ tListTreeForRange(SwNodeNum *const p1, SwNodeNum *const p2, SwPaM *const p3)
+ : pRoot(p1), pRootRLHidden(p2), pSection(p3) {}
+ };
typedef std::vector<tListTreeForRange> tListTrees;
tListTrees maListTrees;
@@ -81,8 +98,9 @@ SwListImpl::SwListImpl( const OUString& sListId,
SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
+ SwNodeNum* pNumberTreeRootNodeRL = new SwNodeNum( &rDefaultListStyle );
SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
- maListTrees.emplace_back(pNumberTreeRootNode, pPam);
+ maListTrees.emplace_back(pNumberTreeRootNode, pNumberTreeRootNodeRL, pPam);
pNode = pNode->EndOfSectionNode();
if (pNode != &rNodes.GetEndOfContent())
@@ -102,12 +120,12 @@ SwListImpl::~SwListImpl() COVERITY_NOEXCEPT_FALSE
aNumberTreeIter != maListTrees.end();
++aNumberTreeIter )
{
- SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
+ SwNodeNum::HandleNumberTreeRootNodeDelete(*((*aNumberTreeIter).pRoot));
+ SwNodeNum::HandleNumberTreeRootNodeDelete(*((*aNumberTreeIter).pRootRLHidden));
}
}
-
-void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
+void SwListImpl::InsertListItem( SwNodeNum& rNodeNum, bool const isHiddenRedlines,
const int nLevel )
{
const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
@@ -118,15 +136,17 @@ void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
aNumberTreeIter != maListTrees.end();
++aNumberTreeIter )
{
- const SwPosition* pStart = (*aNumberTreeIter).second->Start();
- const SwPosition* pEnd = (*aNumberTreeIter).second->End();
+ const SwPosition* pStart = (*aNumberTreeIter).pSection->Start();
+ const SwPosition* pEnd = (*aNumberTreeIter).pSection->End();
const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
if ( pRangeNodes == pNodesOfNodeNum &&
*pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
{
- (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
-
+ auto const& pRoot(isHiddenRedlines
+ ? (*aNumberTreeIter).pRootRLHidden
+ : (*aNumberTreeIter).pRoot);
+ pRoot->AddChild(&rNodeNum, nLevel);
break;
}
}
@@ -144,7 +164,8 @@ void SwListImpl::InvalidateListTree()
aNumberTreeIter != maListTrees.end();
++aNumberTreeIter )
{
- (*aNumberTreeIter).first->InvalidateTree();
+ (*aNumberTreeIter).pRoot->InvalidateTree();
+ (*aNumberTreeIter).pRootRLHidden->InvalidateTree();
}
}
@@ -155,7 +176,8 @@ void SwListImpl::ValidateListTree()
aNumberTreeIter != maListTrees.end();
++aNumberTreeIter )
{
- (*aNumberTreeIter).first->NotifyInvalidChildren();
+ (*aNumberTreeIter).pRoot->NotifyInvalidChildren();
+ (*aNumberTreeIter).pRootRLHidden->NotifyInvalidChildren();
}
}
@@ -202,7 +224,8 @@ void SwListImpl::NotifyItemsOnListLevel( const int nLevel )
aNumberTreeIter != maListTrees.end();
++aNumberTreeIter )
{
- (*aNumberTreeIter).first->NotifyNodesOnListLevel( nLevel );
+ (*aNumberTreeIter).pRoot->NotifyNodesOnListLevel( nLevel );
+ (*aNumberTreeIter).pRootRLHidden->NotifyNodesOnListLevel( nLevel );
}
}
@@ -232,10 +255,10 @@ void SwList::SetDefaultListStyleName(OUString const& rNew)
mpListImpl->msDefaultListStyleName = rNew;
}
-void SwList::InsertListItem( SwNodeNum& rNodeNum,
+void SwList::InsertListItem( SwNodeNum& rNodeNum, bool const isHiddenRedlines,
const int nLevel )
{
- mpListImpl->InsertListItem( rNodeNum, nLevel );
+ mpListImpl->InsertListItem( rNodeNum, isHiddenRedlines, nLevel );
}
void SwList::RemoveListItem( SwNodeNum& rNodeNum )
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 830f6630b744..9638231a2ed9 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -4223,33 +4223,43 @@ bool SwTextNode::IsCountedInList() const
return aIsCountedInListItem.GetValue();
}
-void SwTextNode::AddToList()
+static SwList * FindList(SwTextNode *const pNode)
{
- if ( IsInList() )
- {
- OSL_FAIL( "<SwTextNode::AddToList()> - the text node is already added to a list. Serious defect" );
- return;
- }
-
- const OUString sListId = GetListId();
+ const OUString sListId = pNode->GetListId();
if (!sListId.isEmpty())
{
- SwList* pList = GetDoc()->getIDocumentListsAccess().getListByName( sListId );
+ auto & rIDLA(pNode->GetDoc()->getIDocumentListsAccess());
+ SwList* pList = rIDLA.getListByName( sListId );
if ( pList == nullptr )
{
// Create corresponding list.
- SwNumRule* pNumRule = GetNumRule();
+ SwNumRule* pNumRule = pNode->GetNumRule();
if ( pNumRule )
{
- pList = GetDoc()->getIDocumentListsAccess().createList( sListId, GetNumRule()->GetName() );
+ pList = rIDLA.createList(sListId, pNode->GetNumRule()->GetName());
}
}
OSL_ENSURE( pList != nullptr,
"<SwTextNode::AddToList()> - no list for given list id. Serious defect" );
- if ( pList )
- {
- pList->InsertListItem( *CreateNum(), GetAttrListLevel() );
- }
+ return pList;
+ }
+ return nullptr;
+}
+
+void SwTextNode::AddToList()
+{
+ if ( IsInList() )
+ {
+ OSL_FAIL( "<SwTextNode::AddToList()> - the text node is already added to a list. Serious defect" );
+ return;
+ }
+
+ SwList *const pList(FindList(this));
+ if (pList)
+ {
+ assert(!mpNodeNum);
+ mpNodeNum = new SwNodeNum(this);
+ pList->InsertListItem(*mpNodeNum, false, GetAttrListLevel());
}
}