20#include <bookmark.hxx>
40using namespace ::boost;
48 const int BEFORE_NODE = 0;
49 const int BEFORE_SAME_NODE = 1;
50 const int SAME_POSITION = 2;
51 const int BEHIND_SAME_NODE = 3;
52 const int BEHIND_NODE = 4;
57 int nReturn = BEFORE_NODE;
61 if( nCntIdx < nContent )
62 nReturn = BEFORE_SAME_NODE;
63 else if( nCntIdx == nContent )
64 nReturn = SAME_POSITION;
66 nReturn = BEHIND_SAME_NODE;
68 else if( nIndex > nNode )
69 nReturn = BEHIND_NODE;
81 SAL_INFO(
"sw.core",
"Index: " << m_nIdx <<
"\tOther: " << m_bOther <<
"\tContent: " << m_nContent);
94 const sal_Int32 m_nOffset;
95 OffsetUpdater(
SwContentNode const * pNewContentNode, sal_Int32 nOffset)
96 : m_pNewContentNode(pNewContentNode), m_nOffset(nOffset) {};
97 void operator()(
SwPosition& rPos, sal_Int32 nContent)
const
99 rPos.
Assign(*m_pNewContentNode, nContent + m_nOffset);
106 const sal_Int32 m_nCorrLen;
108 : m_pNewContentNode(pNewContentNode), m_nLen(nLen), m_nCorrLen(nCorrLen) {};
109 void operator()(
SwPosition& rPos, sal_Int32 nContent)
const
111 if( nContent < m_nCorrLen )
113 nContent =
std::min( nContent,
static_cast<sal_Int32
>(m_nLen) );
117 nContent -= m_nCorrLen;
119 rPos.
Assign( *m_pNewContentNode, nContent );
124 std::vector<MarkEntry> m_aBkmkEntries;
125 std::vector<MarkEntry> m_aRedlineEntries;
126 std::vector<MarkEntry> m_aFlyEntries;
127 std::vector<PaMEntry> m_aUnoCursorEntries;
128 std::vector<PaMEntry> m_aShellCursorEntries;
129 typedef std::function<void (
SwPosition& rPos, sal_Int32 nContent)> updater_t;
130 virtual void Clear()
override
132 m_aBkmkEntries.clear();
133 m_aRedlineEntries.clear();
134 m_aFlyEntries.clear();
135 m_aUnoCursorEntries.clear();
136 m_aShellCursorEntries.clear();
138 virtual bool Empty()
override
140 return m_aBkmkEntries.empty() && m_aRedlineEntries.empty() && m_aFlyEntries.empty() && m_aUnoCursorEntries.empty() && m_aShellCursorEntries.empty();
142 virtual void Save(
SwDoc& rDoc,
SwNodeOffset nNode, sal_Int32 nContent,
bool bSaveFlySplit=
false)
override
144 SaveBkmks(rDoc, nNode, nContent);
145 SaveRedlines(rDoc, nNode, nContent);
146 SaveFlys(rDoc, nNode, nContent, bSaveFlySplit);
147 SaveUnoCursors(rDoc, nNode, nContent);
148 SaveShellCursors(rDoc, nNode, nContent);
153 updater_t aUpdater = OffsetUpdater(pCNd, nOffset);
154 if (eMode & RestoreMode::NonFlys)
156 RestoreBkmks(rDoc, aUpdater);
157 RestoreRedlines(rDoc, aUpdater);
158 RestoreUnoCursors(aUpdater);
159 RestoreShellCursors(aUpdater);
161 if (eMode & RestoreMode::Flys)
163 RestoreFlys(rDoc, aUpdater, bAuto, bAtStart);
166 virtual void Restore(
SwNode& rNd, sal_Int32 nLen, sal_Int32 nCorrLen,
RestoreMode eMode = RestoreMode::All)
override
170 updater_t aUpdater = LimitUpdater(pCNd, nLen, nCorrLen);
171 if (eMode & RestoreMode::NonFlys)
173 RestoreBkmks(rDoc, aUpdater);
174 RestoreRedlines(rDoc, aUpdater);
175 RestoreUnoCursors(aUpdater);
176 RestoreShellCursors(aUpdater);
178 if (eMode & RestoreMode::Flys)
180 RestoreFlys(rDoc, aUpdater,
false,
false);
186 void RestoreBkmks(
SwDoc& rDoc, updater_t
const & rUpdater);
188 void RestoreRedlines(
SwDoc& rDoc, updater_t
const & rUpdater);
189 void SaveFlys(
SwDoc& rDoc,
SwNodeOffset nNode, sal_Int32 nContent,
bool bSaveFlySplit);
190 void RestoreFlys(
SwDoc& rDoc, updater_t
const & rUpdater,
bool bAuto,
bool bAtStart);
192 void RestoreUnoCursors(updater_t
const & rUpdater);
194 void RestoreShellCursors(updater_t
const & rUpdater);
197 static void SetRightMarkPos(MarkBase* pMark,
bool bOther,
const SwPosition*
const pPos)
198 { bOther ? pMark->SetOtherMarkPos(*pPos) : pMark->SetMarkPos(*pPos); };
200 void lcl_ChkPaM( std::vector<PaMEntry>& rPaMEntries,
const SwNodeOffset nNode,
const sal_Int32 nContent,
SwPaM& rPaM,
const bool bGetPoint,
bool bSetMark)
206 rPaMEntries.push_back(aEntry);
209 void lcl_ChkPaMBoth( std::vector<PaMEntry>& rPaMEntries,
const SwNodeOffset nNode,
const sal_Int32 nContent,
SwPaM& rPaM)
211 lcl_ChkPaM(rPaMEntries, nNode, nContent, rPaM,
true,
true);
212 lcl_ChkPaM(rPaMEntries, nNode, nContent, rPaM,
false,
false);
214 void lcl_ChkUnoCrsrPaMBoth(std::vector<PaMEntry>& rPaMEntries,
const SwNodeOffset nNode,
const sal_Int32 nContent,
SwPaM& rPaM)
216 lcl_ChkPaM(rPaMEntries, nNode, nContent, rPaM,
true,
false);
217 lcl_ChkPaM(rPaMEntries, nNode, nContent, rPaM,
false,
true);
221 static void DumpEntries(std::vector<MarkEntry>* pEntries)
223 for (MarkEntry& aEntry : *pEntries)
229void ContentIdxStoreImpl::SaveBkmks(
SwDoc& rDoc,
SwNodeOffset nNode, sal_Int32 nContent)
238 const ::sw::mark::IMark* pBkmk = *ppBkmk;
239 bool bMarkPosEqual =
false;
240 if(pBkmk->GetMarkPos().GetNodeIndex() == nNode
241 && pBkmk->GetMarkPos().GetContentIndex() <= nContent)
243 if(pBkmk->GetMarkPos().GetContentIndex() < nContent)
245 const MarkEntry aEntry = {
static_cast<tools::Long>(ppBkmk - pMarkAccess->
getAllMarksBegin()),
false, pBkmk->GetMarkPos().GetContentIndex() };
246 m_aBkmkEntries.push_back(aEntry);
249 bMarkPosEqual =
true;
251 if(pBkmk->IsExpanded()
252 && pBkmk->GetOtherMarkPos().GetNodeIndex() == nNode
253 && pBkmk->GetOtherMarkPos().GetContentIndex() <= nContent)
257 const MarkEntry aEntry = {
static_cast<tools::Long>(ppBkmk - pMarkAccess->
getAllMarksBegin()),
false, pBkmk->GetMarkPos().GetContentIndex() };
258 m_aBkmkEntries.push_back(aEntry);
260 const MarkEntry aEntry = {
static_cast<tools::Long>(ppBkmk - pMarkAccess->
getAllMarksBegin()),
true, pBkmk->GetOtherMarkPos().GetContentIndex() };
261 m_aBkmkEntries.push_back(aEntry);
266void ContentIdxStoreImpl::RestoreBkmks(
SwDoc& rDoc, updater_t
const & rUpdater)
269 for (
const MarkEntry& aEntry : m_aBkmkEntries)
273 SwPosition aNewPos(GetRightMarkPos(pMark, aEntry.m_bOther));
274 rUpdater(aNewPos, aEntry.m_nContent);
275 SetRightMarkPos(pMark, aEntry.m_bOther, &aNewPos);
278 if (!m_aBkmkEntries.empty())
285void ContentIdxStoreImpl::SaveRedlines(
SwDoc& rDoc,
SwNodeOffset nNode, sal_Int32 nContent)
291 int nPointPos = lcl_RelativePosition( *pRdl->GetPoint(), nNode, nContent );
292 int nMarkPos = pRdl->HasMark() ? lcl_RelativePosition( *pRdl->GetMark(), nNode, nContent ) :
297 if( nPointPos == BEFORE_SAME_NODE ||
298 ( nPointPos == SAME_POSITION && nMarkPos < SAME_POSITION ) )
300 const MarkEntry aEntry = { nIdx,
false, pRdl->GetPoint()->GetContentIndex() };
301 m_aRedlineEntries.push_back(aEntry);
303 if( pRdl->HasMark() && ( nMarkPos == BEFORE_SAME_NODE ||
304 ( nMarkPos == SAME_POSITION && nPointPos < SAME_POSITION ) ) )
306 const MarkEntry aEntry = { nIdx,
true, pRdl->GetMark()->GetContentIndex() };
307 m_aRedlineEntries.push_back(aEntry);
313void ContentIdxStoreImpl::RestoreRedlines(
SwDoc& rDoc, updater_t
const & rUpdater)
316 for (
const MarkEntry& aEntry : m_aRedlineEntries)
319 ? rRedlTable[ aEntry.m_nIdx ]->GetMark()
320 : rRedlTable[ aEntry.m_nIdx ]->GetPoint();
321 rUpdater(*pPos, aEntry.m_nContent);
325void ContentIdxStoreImpl::SaveFlys(
SwDoc& rDoc,
SwNodeOffset nNode, sal_Int32 nContent,
bool bSaveFlySplit)
339 MarkEntry aSave = { 0,
false, 0 };
346 if ( pAnchorNode && ( nNode == pAnchorNode->
GetIndex() ) &&
347 ( RndStdIds::FLY_AT_PARA == rAnchor.
GetAnchorId() ||
348 RndStdIds::FLY_AT_CHAR == rAnchor.
GetAnchorId() ) )
351 aSave.m_bOther =
false;
353 if ( RndStdIds::FLY_AT_CHAR == rAnchor.
GetAnchorId() )
355 if( nContent <= aSave.m_nContent )
358 aSave.m_bOther =
true;
364 m_aFlyEntries.push_back(aSave);
371void ContentIdxStoreImpl::RestoreFlys(
SwDoc& rDoc, updater_t
const & rUpdater,
bool bAuto,
bool bAtStart)
374 for (
const MarkEntry& aEntry : m_aFlyEntries)
382 if(bAtStart && RndStdIds::FLY_AT_PARA == rFlyAnchor.
GetAnchorId())
386 rUpdater(aNewPos, aEntry.m_nContent);
387 if ( RndStdIds::FLY_AT_CHAR != rFlyAnchor.
GetAnchorId() )
389 aNewPos.nContent.Assign(
nullptr, 0 );
391 aNew.SetAnchor( &aNewPos );
404void ContentIdxStoreImpl::SaveUnoCursors(
SwDoc& rDoc,
SwNodeOffset nNode, sal_Int32 nContent)
409 auto pUnoCursor(pWeakUnoCursor.lock());
414 lcl_ChkUnoCrsrPaMBoth(m_aUnoCursorEntries, nNode, nContent, rPaM);
417 if( pUnoTableCursor )
421 lcl_ChkUnoCrsrPaMBoth(m_aUnoCursorEntries, nNode, nContent, rPaM);
427void ContentIdxStoreImpl::RestoreUnoCursors(updater_t
const & rUpdater)
429 for (
const PaMEntry& aEntry : m_aUnoCursorEntries)
431 rUpdater(aEntry.m_pPaM->GetBound(!aEntry.m_isMark), aEntry.m_nContent);
435void ContentIdxStoreImpl::SaveShellCursors(
SwDoc& rDoc,
SwNodeOffset nNode, sal_Int32 nContent)
442 if(
auto pCursorShell =
dynamic_cast<SwCursorShell *
>(&rCurShell) )
444 SwPaM *_pStackCursor = pCursorShell->GetStackCursor();
448 lcl_ChkPaMBoth( m_aShellCursorEntries, nNode, nContent, *_pStackCursor);
451 _pStackCursor = _pStackCursor->
GetNext();
452 if (_pStackCursor == pCursorShell->GetStackCursor())
458 lcl_ChkPaMBoth( m_aShellCursorEntries, nNode, nContent, rPaM);
464void ContentIdxStoreImpl::RestoreShellCursors(updater_t
const & rUpdater)
466 for (
const PaMEntry& aEntry : m_aShellCursorEntries)
468 rUpdater(aEntry.m_pPaM->GetBound(aEntry.m_isMark), aEntry.m_nContent);
475 return std::make_shared<ContentIdxStoreImpl>();
virtual const SwRootFrame * GetCurrentLayout() const =0
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
std::vector<::sw::mark::MarkBase * >::const_iterator const & get() const
Provides access to the marks of a document.
virtual const_iterator_t getAllMarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of marks.
virtual void assureSortedMarkContainers() const =0
virtual const_iterator_t getAllMarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence of marks.
virtual const SwRedlineTable & GetRedlineTable() const =0
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
std::vector< std::weak_ptr< SwUnoCursor > > mvUnoCursorTable
void cleanupUnoCursorTable() const
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
SwEditShell const * GetEditShell() const
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
IDocumentMarkAccess * getIDocumentMarkAccess()
const sw::FrameFormats< sw::SpzFrameFormat * > * GetSpzFrameFormats() const
Base class of the Writer layout elements.
const SwSortedObjs * GetDrawObjs() const
Base class of the Writer document model elements.
SwNodeOffset GetIndex() const
SwContentNode * GetContentNode()
PaM is Point and Mark: a selection of the document model.
SwPosition & GetBound(bool bOne=true)
Represents the visualization of a paragraph.
sw::MergedPara * GetMergedPara()
ring_container GetRingContainer()
Takes care of storing relevant attributes of an SwTextNode before split, then restore them on the new...
virtual void Save(SwDoc &rDoc, SwNodeOffset nNode, sal_Int32 nContent, bool bSaveFlySplit=false)=0
static std::shared_ptr< ContentIdxStore > Create()
virtual void Restore(SwDoc &rDoc, SwNodeOffset nNode, sal_Int32 nOffset=0, bool bAuto=false, bool bAtStart=false, RestoreMode=RestoreMode::All)=0
virtual const SwPosition & GetOtherMarkPos() const =0
virtual const SwPosition & GetMarkPos() const =0
constexpr TypedWhichId< SwFlyFrameFormat > RES_FLYFRMFMT(162)
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(165)
#define SAL_INFO(area, stream)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Marks a position in the document model.
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
SwNodeOffset GetNodeIndex() const
sal_Int32 GetContentIndex() const