summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2020-07-05 02:20:52 +0200
committerBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2020-07-05 13:24:17 +0200
commit3b9aa11d885c91a3b040cb2b103b815c75d170bc (patch)
tree6d27ceaa5b4683214438523aacdd080f550c8893
parent25c1a9be773fd3248463bdbd64c30140ac0d2406 (diff)
GotoTOXMarkBase: SwIterator no more ...
Change-Id: I60935850596eeb7209bd84782c954919c02cb259 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98050 Tested-by: Jenkins Reviewed-by: Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org>
-rw-r--r--sw/inc/tox.hxx20
-rw-r--r--sw/source/core/crsr/crstrvl.cxx58
-rw-r--r--sw/source/core/doc/doctxm.cxx25
-rw-r--r--sw/source/core/inc/doctxm.hxx3
4 files changed, 59 insertions, 47 deletions
diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx
index 8dca84897b47..475a48830a7f 100644
--- a/sw/inc/tox.hxx
+++ b/sw/inc/tox.hxx
@@ -41,6 +41,7 @@ class SwTOXMark;
class SwTextTOXMark;
class SwDoc;
class SwRootFrame;
+class SwContentFrame;
typedef std::vector<SwTOXMark*> SwTOXMarks;
@@ -49,6 +50,18 @@ namespace sw {
SwTOXMarks& m_rMarks;
CollectTextMarksHint(SwTOXMarks& rMarks) : m_rMarks(rMarks) {}
};
+ struct FindContentFrameHint final : SfxHint {
+ SwContentFrame*& m_rpContentFrame;
+ const SwDoc& m_rDoc;
+ const SwRootFrame& m_rLayout;
+ const bool m_isReadOnlyAvailable;
+ FindContentFrameHint(SwContentFrame*& rpContentFrame, const SwDoc& rDoc, const SwRootFrame& rLayout, const bool isReadOnlyAvailable)
+ : m_rpContentFrame(rpContentFrame)
+ , m_rDoc(rDoc)
+ , m_rLayout(rLayout)
+ , m_isReadOnlyAvailable(isReadOnlyAvailable)
+ {}
+ };
}
// Entry of content index, alphabetical index or user defined index
@@ -161,6 +174,13 @@ public:
inline TOXTypes GetType() const;
void CollectTextMarks(SwTOXMarks& rMarks) const
{ const_cast<SwTOXType*>(this)->GetNotifier().Broadcast(sw::CollectTextMarksHint(rMarks)); }
+ SwContentFrame* FindContentFrame(const SwDoc& rDoc, const SwRootFrame& rLayout, const bool isReadOnlyAvailable) const
+ {
+ SwContentFrame* pContentFrame = nullptr;
+ const_cast<SwTOXType*>(this)->GetNotifier().Broadcast(sw::FindContentFrameHint(pContentFrame, rDoc, rLayout, isReadOnlyAvailable));
+ return pContentFrame;
+ }
+
private:
OUString m_aName;
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 8be87766dc66..5ee44842b56f 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -366,53 +366,19 @@ bool SwCursorShell::GotoPrevTOXBase( const OUString* pName )
/// jump to index of TOXMark
void SwCursorShell::GotoTOXMarkBase()
{
- bool bRet = false;
-
SwTOXMarks aMarks;
- sal_uInt16 nCnt = SwDoc::GetCurTOXMark( *m_pCurrentCursor->GetPoint(), aMarks );
- if( nCnt )
- {
- // Take the 1. and get the index type. Search in its dependency list
- // for the actual index
- const SwTOXType* pType = aMarks[0]->GetTOXType();
- SwIterator<SwTOXBase,SwTOXType> aIter( *pType );
-
- for( SwTOXBase* pTOX = aIter.First(); pTOX; pTOX = aIter.Next() )
- {
- auto pTOXBaseSection = dynamic_cast<const SwTOXBaseSection*>( pTOX);
- if( !pTOXBaseSection )
- continue;
- auto pSectFormat = pTOXBaseSection->GetFormat();
- if( !pSectFormat )
- continue;
- const SwSectionNode* pSectNd = pSectFormat->GetSectionNode();
- if (!pSectNd)
- continue;
- SwNodeIndex aIdx( *pSectNd, 1 );
- SwContentNode* pCNd = aIdx.GetNode().GetContentNode();
- if( !pCNd )
- pCNd = GetDoc()->GetNodes().GoNext( &aIdx );
- if( !pCNd )
- continue;
- if( pCNd->EndOfSectionIndex() >= pSectNd->EndOfSectionIndex() )
- continue;
- const SwContentFrame* pCFrame = pCNd->getLayoutFrame( GetLayout() );
- if( pCFrame && ( IsReadOnlyAvailable() || !pCFrame->IsProtected() ) )
- {
- SwCallLink aLk( *this ); // watch Cursor-Moves
- SwCursorSaveState aSaveState( *m_pCurrentCursor );
- assert(pCFrame->IsTextFrame());
- *m_pCurrentCursor->GetPoint() =
- static_cast<SwTextFrame const*>(pCFrame)
- ->MapViewToModelPos(TextFrameIndex(0));
- bRet = !m_pCurrentCursor->IsInProtectTable() &&
- !m_pCurrentCursor->IsSelOvr();
- if( bRet )
- UpdateCursor(SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE|SwCursorShell::READONLY);
- break;
- }
- }
- }
+ sal_uInt16 nCnt = SwDoc::GetCurTOXMark(*m_pCurrentCursor->GetPoint(), aMarks);
+ if(!nCnt)
+ return;
+ // Take the 1. and get the index type. Ask it for the actual index.
+ const SwTOXType* pType = aMarks[0]->GetTOXType();
+ auto pContentFrame = pType->FindContentFrame(*GetDoc(), *GetLayout(), IsReadOnlyAvailable());
+ SwCallLink aLk(*this); // watch Cursor-Moves
+ SwCursorSaveState aSaveState(*m_pCurrentCursor);
+ assert(pContentFrame->IsTextFrame());
+ *m_pCurrentCursor->GetPoint() = static_cast<SwTextFrame const*>(pContentFrame)->MapViewToModelPos(TextFrameIndex(0));
+ if(!m_pCurrentCursor->IsInProtectTable() && !m_pCurrentCursor->IsSelOvr())
+ UpdateCursor(SwCursorShell::SCROLLWIN|SwCursorShell::CHKRANGE|SwCursorShell::READONLY);
}
/// Jump to next/previous table formula
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index bea433019820..10b2be028f55 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -1172,6 +1172,31 @@ SwTextFormatColl* SwTOXBaseSection::GetTextFormatColl( sal_uInt16 nLevel )
return pColl;
}
+void SwTOXBaseSection::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
+{
+ if (auto pFindHint = dynamic_cast<const sw::FindContentFrameHint*>(&rHint))
+ {
+ if(pFindHint->m_rpContentFrame)
+ return;
+ auto pSectFormat = GetFormat();
+ if(!pSectFormat)
+ return;
+ const SwSectionNode* pSectNd = pSectFormat->GetSectionNode();
+ if(!pSectNd)
+ return;
+ SwNodeIndex aIdx(*pSectNd, 1);
+ SwContentNode* pCNd = aIdx.GetNode().GetContentNode();
+ if(!pCNd)
+ pCNd = pFindHint->m_rDoc.GetNodes().GoNext(&aIdx);
+ if(!pCNd)
+ return;
+ if(pCNd->EndOfSectionIndex() >= pSectNd->EndOfSectionIndex())
+ return;
+ pFindHint->m_rpContentFrame = pCNd->getLayoutFrame(&pFindHint->m_rLayout);
+ } else
+ SwTOXBase::SwClientNotify(rModify, rHint);
+}
+
/// Create from Marks
void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
const SwTextNode* pOwnChapterNode,
diff --git a/sw/source/core/inc/doctxm.hxx b/sw/source/core/inc/doctxm.hxx
index 53a649cdd12e..faea538caea8 100644
--- a/sw/source/core/inc/doctxm.hxx
+++ b/sw/source/core/inc/doctxm.hxx
@@ -32,7 +32,7 @@ class SwTextFormatColl;
struct SwPosition;
struct SwTOXSortTabBase;
-class SwTOXBaseSection : public SwTOXBase, public SwSection
+class SwTOXBaseSection final : public SwTOXBase, public SwSection
{
std::vector<std::unique_ptr<SwTOXSortTabBase>> m_aSortArr;
@@ -73,6 +73,7 @@ class SwTOXBaseSection : public SwTOXBase, public SwSection
// return text collection via name/ from format pool
SwTextFormatColl* GetTextFormatColl( sal_uInt16 nLevel );
+ virtual void SwClientNotify(const SwModify& rModify, const SfxHint& rHint) override;
public:
SwTOXBaseSection(SwTOXBase const& rBase, SwSectionFormat & rFormat);