1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 #include <osl/diagnose.h>
23 #include <svx/svdobj.hxx>
25 #include <anchoredobject.hxx>
26 #include <bodyfrm.hxx>
27 #include <swtable.hxx>
28 #include <rootfrm.hxx>
29 #include <pagefrm.hxx>
30 #include <viewimp.hxx>
31 #include <viewopt.hxx>
33 #include <frmtool.hxx>
34 #include <IDocumentFieldsAccess.hxx>
35 #include <editeng/formatbreakitem.hxx>
36 #include <editeng/keepitem.hxx>
37 #include <fmtanchr.hxx>
38 #include <fmtsrnd.hxx>
39 #include <fmtpdsc.hxx>
40 #include <editeng/ulspitem.hxx>
41 #include <tgrditem.hxx>
44 #include <editeng/pgrditem.hxx>
48 #include <notxtfrm.hxx>
51 #include <pagedesc.hxx>
54 #include <sectfrm.hxx>
55 #include <section.hxx>
56 #include <dbg_lay.hxx>
57 #include <lineinfo.hxx>
58 #include <fmtclbl.hxx>
59 #include <sortedobjs.hxx>
60 #include <layouter.hxx>
61 #include <fmtfollowtextflow.hxx>
63 #include <IDocumentSettingAccess.hxx>
64 #include <IDocumentDrawModelAccess.hxx>
67 #include <flyfrms.hxx>
69 bool SwFlowFrame::s_bMoveBwdJump
= false;
71 SwFlowFrame::SwFlowFrame( SwFrame
&rFrame
) :
74 m_pPrecede( nullptr ),
76 m_bUndersized( false ),
80 SwFlowFrame::~SwFlowFrame()
84 m_pFollow
->m_pPrecede
= nullptr;
88 m_pPrecede
->m_pFollow
= nullptr;
92 void SwFlowFrame::SetFollow(SwFlowFrame
*const pFollow
)
96 assert(this == m_pFollow
->m_pPrecede
);
97 m_pFollow
->m_pPrecede
= nullptr;
100 if (m_pFollow
!= nullptr)
102 if (m_pFollow
->m_pPrecede
) // re-chaining pFollow?
104 assert(m_pFollow
== m_pFollow
->m_pPrecede
->m_pFollow
);
105 m_pFollow
->m_pPrecede
->m_pFollow
= nullptr;
107 m_pFollow
->m_pPrecede
= this;
111 /// @return true if any follow has the JoinLocked flag
112 bool SwFlowFrame::HasLockedFollow() const
114 const SwFlowFrame
* pFrame
= GetFollow();
117 if( pFrame
->IsJoinLocked() )
119 pFrame
= pFrame
->GetFollow();
124 bool SwFlowFrame::IsKeepFwdMoveAllowed( bool bIgnoreMyOwnKeepValue
)
126 // If all the predecessors up to the first of the chain have
127 // the 'keep' attribute set, and the first of the chain's
128 // IsFwdMoveAllowed returns false, then we're not allowed to move.
129 SwFrame
*pFrame
= &m_rThis
;
130 if ( !pFrame
->IsInFootnote() ) {
131 if ( bIgnoreMyOwnKeepValue
&& pFrame
->GetIndPrev() )
132 pFrame
= pFrame
->GetIndPrev();
134 { if ( pFrame
->GetAttrSet()->GetKeep().GetValue() )
135 pFrame
= pFrame
->GetIndPrev();
140 //See IsFwdMoveAllowed()
142 if ( pFrame
&& pFrame
->GetIndPrev() )
147 void SwFlowFrame::CheckKeep()
149 // Kick off the "last" predecessor with a 'keep' attribute, because
150 // it's possible for the whole troop to move back.
151 SwFrame
*pPre
= m_rThis
.GetIndPrev();
153 if( pPre
->IsSctFrame() )
155 SwFrame
*pLast
= static_cast<SwSectionFrame
*>(pPre
)->FindLastContent();
156 if( pLast
&& pLast
->FindSctFrame() == pPre
)
163 while ( (bKeep
= pPre
->GetAttrSet()->GetKeep().GetValue()) &&
164 nullptr != ( pTmp
= pPre
->GetIndPrev() ) )
166 if( pTmp
->IsSctFrame() )
168 SwFrame
*pLast
= static_cast<SwSectionFrame
*>(pTmp
)->FindLastContent();
169 if( pLast
&& pLast
->FindSctFrame() == pTmp
)
177 pPre
->InvalidatePos();
183 * Determines if the next content frame after rThis will require the full area of the parent body
186 bool IsNextContentFullPage(const SwFrame
& rThis
)
188 const SwFrame
* pNext
= rThis
.FindNextCnt();
194 const SwSortedObjs
* pNextDrawObjs
= pNext
->GetDrawObjs();
195 if (!pNextDrawObjs
|| !pNextDrawObjs
->size())
200 for (const auto& pDrawObj
: *pNextDrawObjs
)
207 SwTwips nDrawObjHeight
= pDrawObj
->GetObjRectWithSpaces().Height();
208 const SwPageFrame
* pPageFrame
= pDrawObj
->GetPageFrame();
214 SwTwips nBodyHeight
= pPageFrame
->GetLower()->getFrameArea().Height();
215 if (nDrawObjHeight
< nBodyHeight
)
220 const SwFormatSurround
& rSurround
= pDrawObj
->GetFrameFormat().GetSurround();
221 if (rSurround
.GetSurround() != text::WrapTextMode_NONE
)
226 // At this point the height of the draw object will use all the vertical available space,
227 // and also no wrapping will be performed, so all horizontal space will be taken as well.
235 bool SwFlowFrame::IsKeep(SvxFormatKeepItem
const& rKeep
,
236 SvxFormatBreakItem
const& rBreak
,
237 bool const bCheckIfLastRowShouldKeep
) const
239 // 1. The keep attribute is ignored inside footnotes
240 // 2. For compatibility reasons, the keep attribute is
241 // ignored for frames inside table cells
242 // 3. If bBreakCheck is set to true, this function only checks
243 // if there are any break after attributes set at rAttrs
244 // or break before attributes set for the next content (or next table)
245 // 4. Keep is ignored if the next frame will require its own page.
246 bool bKeep
= bCheckIfLastRowShouldKeep
||
247 ( !m_rThis
.IsInFootnote() &&
248 ( !m_rThis
.IsInTab() || m_rThis
.IsTabFrame() ) &&
249 rKeep
.GetValue() && !IsNextContentFullPage(m_rThis
));
251 if (bKeep
&& m_rThis
.IsTextFrame())
253 auto& rTextFrame
= static_cast<SwTextFrame
&>(m_rThis
);
254 if (rTextFrame
.HasNonLastSplitFlyDrawObj())
256 // Allow split for the non-last anchors of a split fly, even if rKeep.GetValue() is
262 OSL_ENSURE( !bCheckIfLastRowShouldKeep
|| m_rThis
.IsTabFrame(),
263 "IsKeep with bCheckIfLastRowShouldKeep should only be used for tabfrms" );
265 // Ignore keep attribute if there are break situations:
268 switch (rBreak
.GetBreak())
270 case SvxBreak::ColumnAfter
:
271 case SvxBreak::ColumnBoth
:
272 case SvxBreak::PageAfter
:
273 case SvxBreak::PageBoth
:
283 if( nullptr != (pNxt
= m_rThis
.FindNextCnt()) &&
284 (!m_pFollow
|| pNxt
!= &m_pFollow
->GetFrame()))
286 // The last row of a table only keeps with the next content
287 // it they are in the same section:
288 if ( bCheckIfLastRowShouldKeep
)
290 const SwSection
* pThisSection
= nullptr;
291 const SwSection
* pNextSection
= nullptr;
292 const SwSectionFrame
* pThisSectionFrame
= m_rThis
.FindSctFrame();
293 const SwSectionFrame
* pNextSectionFrame
= pNxt
->FindSctFrame();
295 if ( pThisSectionFrame
)
296 pThisSection
= pThisSectionFrame
->GetSection();
298 if ( pNextSectionFrame
)
299 pNextSection
= pNextSectionFrame
->GetSection();
301 if ( pThisSection
!= pNextSection
)
307 SvxFormatBreakItem
const* pBreak
;
308 SwFormatPageDesc
const* pPageDesc
;
309 SwTabFrame
* pTab
= pNxt
->IsInTab() ? pNxt
->FindTabFrame() : nullptr;
310 if (pTab
&& (!m_rThis
.IsInTab() || m_rThis
.FindTabFrame() != pTab
))
312 const SwAttrSet
*const pSet
= &pTab
->GetFormat()->GetAttrSet();
313 pBreak
= &pSet
->GetBreak();
314 pPageDesc
= &pSet
->GetPageDesc();
318 pBreak
= &pNxt
->GetBreakItem();
319 pPageDesc
= &pNxt
->GetPageDescItem();
322 if (pPageDesc
->GetPageDesc())
324 else switch (pBreak
->GetBreak())
326 case SvxBreak::ColumnBefore
:
327 case SvxBreak::ColumnBoth
:
328 case SvxBreak::PageBefore
:
329 case SvxBreak::PageBoth
:
341 sal_uInt8
SwFlowFrame::BwdMoveNecessary( const SwPageFrame
*pPage
, const SwRect
&rRect
)
343 // The return value helps deciding whether we need to flow back (3),
344 // or whether we can use the good old WouldFit (0, 1), or if
345 // it's reasonable to relocate and test-format (2).
347 // Bit 1 in this case means that there are objects anchored to myself,
348 // bit 2 means that I have to evade other objects.
350 // If a SurroundObj that desires to be wrapped around overlaps with the
351 // Rect, it's required to flow (because we can't guess the relationships).
352 // However it's possible for a test formatting to happen.
353 // If the SurroundObj is a Fly and I'm a Lower, or the Fly is a Lower of
354 // mine, then it doesn't matter.
355 // If the SurroundObj is anchored in a character bound Fly, and I'm not
356 // a Lower of that character bound Fly myself, then the Fly doesn't matter.
358 // If the object is anchored with me, i can ignore it, because
359 // it's likely that it will follow me with the flow. A test formatting is
360 // not allowed in that case, however!
362 SwFlowFrame
*pTmp
= this;
364 { // If there are objects hanging either on me or on a follow, we can't
365 // do a test formatting, because paragraph bound objects wouldn't
366 // be properly considered, and character bound objects shouldn't
367 // be test formatted at all.
368 if( pTmp
->GetFrame().GetDrawObjs() )
370 pTmp
= pTmp
->GetFollow();
371 } while ( !nRet
&& pTmp
);
372 const SwSortedObjs
*pObjs
= pPage
? pPage
->GetSortedObjs() : nullptr;
376 const SwSortedObjs
&rObjs
= *pObjs
;
377 SwNodeOffset nIndex
= NODE_OFFSET_MAX
;
378 for ( size_t i
= 0; nRet
< 3 && i
< rObjs
.size(); ++i
)
381 SwAnchoredObject
* pObj
= rObjs
[i
];
382 const SwFrameFormat
& rFormat
= pObj
->GetFrameFormat();
383 const SwRect
aRect( pObj
->GetObjRect() );
384 if ( aRect
.Overlaps( rRect
) &&
385 rFormat
.GetSurround().GetSurround() != css::text::WrapTextMode_THROUGH
)
387 if( m_rThis
.IsLayoutFrame() && //Fly Lower of This?
388 Is_Lower_Of( &m_rThis
, pObj
->GetDrawObj() ) )
390 if( auto pFly
= pObj
->DynCastFlyFrame() )
392 if ( pFly
->IsAnLower( &m_rThis
) )//This Lower of Fly?
396 const SwFrame
* pAnchor
= pObj
->GetAnchorFrame();
397 if ( pAnchor
== &m_rThis
)
403 // Don't do this if the object is anchored behind me in the text
404 // flow, because then I wouldn't evade it.
405 if ( ::IsFrameInSameContext( pAnchor
, &m_rThis
) )
407 if ( rFormat
.GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_PARA
)
409 // The index of the other one can be retrieved using the anchor attribute.
410 SwNodeOffset nTmpIndex
= rFormat
.GetAnchor().GetAnchorNode()->GetIndex();
411 // Now we're going to check whether the current paragraph before
412 // the anchor of the displacing object sits in the text. If this
413 // is the case, we don't try to evade it.
414 // The index is being determined via SwFormatAnchor, because it's
415 // getting quite expensive otherwise.
416 if( NODE_OFFSET_MAX
== nIndex
)
419 if (m_rThis
.IsTextFrame())
420 pNode
= static_cast<SwTextFrame
&>(m_rThis
).GetTextNodeFirst();
421 else if (m_rThis
.IsNoTextFrame())
422 pNode
= static_cast<SwNoTextFrame
&>(m_rThis
).GetNode();
423 else if( m_rThis
.IsSctFrame() )
424 pNode
= static_cast<SwSectionFormat
*>(static_cast<SwSectionFrame
&>(m_rThis
).
425 GetFormat())->GetSectionNode();
428 assert(!m_rThis
.IsContentFrame());
429 OSL_ENSURE( m_rThis
.IsTabFrame(), "new FowFrame?" );
430 pNode
= static_cast<SwTabFrame
&>(m_rThis
).GetTable()->
431 GetTabSortBoxes()[0]->GetSttNd()->FindTableNode();
433 nIndex
= pNode
->GetIndex();
435 if (nIndex
< nTmpIndex
&&
436 (!m_rThis
.IsTextFrame() ||
437 !FrameContainsNode(static_cast<SwTextFrame
&>(m_rThis
), nTmpIndex
)))
453 /// A specialized form of Cut(), which relocates a whole chain (this and the following,
454 /// in particular). During this process, only the minimum operations and notifications are done.
455 SwLayoutFrame
*SwFlowFrame::CutTree( SwFrame
*pStart
)
457 // Cut the Start and all the neighbours; they are chained together and
458 // a handle to the first one is returned. Residuals are invalidated
461 SwLayoutFrame
*pLay
= pStart
->GetUpper();
462 if ( pLay
->IsInFootnote() )
463 pLay
= pLay
->FindFootnoteFrame();
466 // <pPrepare( PrepareHint::QuoVadis )> only for frames in footnotes
467 if( pStart
->IsInFootnote() )
469 SwFrame
* pTmp
= pStart
->GetIndPrev();
471 pTmp
->Prepare( PrepareHint::QuoVadis
);
474 // Just cut quickly and take care that we don't cause problems with the
475 // left-behinds. The pointers of the chain being cut can point who-knows where.
476 if ( pStart
== pStart
->GetUpper()->Lower() )
477 pStart
->GetUpper()->m_pLower
= nullptr;
478 if ( pStart
->GetPrev() )
480 pStart
->GetPrev()->mpNext
= nullptr;
481 pStart
->mpPrev
= nullptr;
484 if ( pLay
->IsFootnoteFrame() )
486 if ( !pLay
->Lower() && !pLay
->IsColLocked() &&
487 !static_cast<SwFootnoteFrame
*>(pLay
)->IsBackMoveLocked() )
489 // tdf#101821 don't delete it while iterating over it
490 if (!pLay
->IsDeleteForbidden())
493 SwFrame::DestroyFrame(pLay
);
495 // else: assume there is code on the stack to clean up empty
497 // (don't go into the else branch below, it produces a disconnected
498 // footnote with null upper that can be returned by
499 // SwFootnoteBossFrame::FindFootnote() causing null pointer deref
500 // in SwTextFrame::ConnectFootnote()
504 bool bUnlock
= !static_cast<SwFootnoteFrame
*>(pLay
)->IsBackMoveLocked();
505 static_cast<SwFootnoteFrame
*>(pLay
)->LockBackMove();
506 pLay
->InvalidateSize();
507 pLay
->Calc(pLay
->getRootFrame()->GetCurrShell()->GetOut());
508 SwContentFrame
*pCnt
= pLay
->ContainsContent();
509 while ( pCnt
&& pLay
->IsAnLower( pCnt
) )
511 // It's possible for the ContentFrame to be locked, and we don't want
512 // to end up in an endless page migration, so we're not even
513 // going to call Calc!
514 OSL_ENSURE( pCnt
->IsTextFrame(), "The Graphic has landed." );
515 if ( static_cast<SwTextFrame
*>(pCnt
)->IsLocked() ||
516 static_cast<SwTextFrame
*>(pCnt
)->GetFollow() == pStart
)
518 pCnt
->Calc(pCnt
->getRootFrame()->GetCurrShell()->GetOut());
519 pCnt
= pCnt
->GetNextContentFrame();
522 static_cast<SwFootnoteFrame
*>(pLay
)->UnlockBackMove();
529 /// A specialized form of Paste(), which relocates a whole chain (this and the following,
530 /// in particular). During this process, only the minimum operations and notifications are done.
531 bool SwFlowFrame::PasteTree( SwFrame
*pStart
, SwLayoutFrame
*pParent
, SwFrame
*pSibling
,
532 SwFrame
*pOldParent
)
534 // returns true if there's a LayoutFrame in the chain.
537 // The chain beginning with pStart is inserted before pSibling
538 // under the parent. We take care to invalidate as required.
540 // I'm receiving a finished chain. We need to update the pointers for
541 // the beginning of the chain, then all the uppers and finally the end.
542 // On the way there, we invalidate as required.
545 pStart
->mpPrev
= pSibling
->GetPrev();
546 if ( nullptr != pStart
->mpPrev
)
547 pStart
->GetPrev()->mpNext
= pStart
;
549 pParent
->m_pLower
= pStart
;
550 pSibling
->InvalidatePos_();
551 pSibling
->InvalidatePrt_();
555 pStart
->mpPrev
= pParent
->Lower();
556 if ( nullptr == pStart
->mpPrev
)
557 pParent
->m_pLower
= pStart
;
560 //If the pParent has more than 1 child nodes, former design will
561 //ignore them directly without any collection work. It will make some
562 //dangling pointers. This lead the crash...
563 //The new design will find the last child of pParent in loop way, and
564 //add the pStart after the last child.
565 // pParent->Lower()->pNext = pStart;
567 SwFrame
* pTemp
= pParent
->m_pLower
;
571 pTemp
= pTemp
->mpNext
;
574 pStart
->mpPrev
= pTemp
;
575 pTemp
->mpNext
= pStart
;
583 if ( pParent
->IsSctFrame() )
585 // We have no sibling because pParent is a section frame and
586 // has just been created to contain some content. The printing
587 // area of the frame behind pParent has to be invalidated, so
588 // that the correct distance between pParent and the next frame
589 // can be calculated.
590 pParent
->InvalidateNextPrtArea();
593 SwFrame
*pFloat
= pStart
;
594 SwFrame
*pLst
= nullptr;
595 SwRectFnSet
aRectFnSet(pParent
);
596 SwTwips nGrowVal
= 0;
598 { pFloat
->mpUpper
= pParent
;
599 pFloat
->InvalidateAll_();
600 pFloat
->CheckDirChange();
602 // I'm a friend of the TextFrame and thus am allowed to do many things.
603 // The CacheIdx idea seems to be a bit risky!
604 if ( pFloat
->IsTextFrame() )
606 if ( static_cast<SwTextFrame
*>(pFloat
)->GetCacheIdx() != USHRT_MAX
)
607 static_cast<SwTextFrame
*>(pFloat
)->Init(); // I'm his friend.
612 nGrowVal
+= aRectFnSet
.GetHeight(pFloat
->getFrameArea());
613 if ( pFloat
->GetNext() )
614 pFloat
= pFloat
->GetNext();
624 pLst
->mpNext
= pSibling
;
625 pSibling
->mpPrev
= pLst
;
626 if( pSibling
->IsInFootnote() )
628 if( pSibling
->IsSctFrame() )
629 pSibling
= static_cast<SwSectionFrame
*>(pSibling
)->ContainsAny();
631 pSibling
->Prepare( PrepareHint::ErgoSum
);
636 if ( pOldParent
&& pOldParent
->IsBodyFrame() ) // For variable page height while browsing
637 pOldParent
->Shrink( nGrowVal
);
638 pParent
->Grow( nGrowVal
);
641 if ( pParent
->IsFootnoteFrame() )
642 static_cast<SwFootnoteFrame
*>(pParent
)->InvalidateNxtFootnoteCnts( pParent
->FindPageFrame() );
646 void SwFlowFrame::MoveSubTree( SwLayoutFrame
* pParent
, SwFrame
* pSibling
)
648 OSL_ENSURE( pParent
, "No parent given." );
649 OSL_ENSURE( m_rThis
.GetUpper(), "Where are we coming from?" );
651 // Be economical with notifications if an action is running.
652 SwViewShell
*pSh
= m_rThis
.getRootFrame()->GetCurrShell();
653 const SwViewShellImp
*pImp
= pSh
? pSh
->Imp() : nullptr;
654 const bool bComplete
= pImp
&& pImp
->IsAction() && pImp
->GetLayAction().IsComplete();
658 SwFrame
*pPre
= m_rThis
.GetIndPrev();
662 // follow-up of i#26250
663 // invalidate printing area of previous frame, if it's in a table
664 if ( pPre
->GetUpper()->IsInTab() )
666 pPre
->InvalidatePrt_();
668 pPre
->InvalidatePage();
672 m_rThis
.GetUpper()->SetCompletePaint();
673 m_rThis
.GetUpper()->InvalidatePage();
677 SwPageFrame
*pOldPage
= m_rThis
.FindPageFrame();
679 SwLayoutFrame
*pOldParent
;
683 //JoinLock pParent for the lifetime of the Cut/Paste call to avoid
684 //SwSectionFrame::MergeNext removing the pParent we're trying to reparent
686 FlowFrameJoinLockGuard
aJoinGuard(pParent
);
687 SwFrameDeleteGuard
aDeleteGuard(pParent
);
688 pOldParent
= CutTree( &m_rThis
);
689 bInvaLay
= PasteTree( &m_rThis
, pParent
, pSibling
, pOldParent
);
692 // If, by cutting & pasting, an empty SectionFrame came into existence, it should
693 // disappear automatically.
694 SwSectionFrame
*pSct
;
696 SwFlyFrame
* pFly
= nullptr;
697 if ( pOldParent
&& !pOldParent
->Lower() &&
698 ( pOldParent
->IsInSct() &&
699 !(pSct
= pOldParent
->FindSctFrame())->ContainsContent() &&
700 !pSct
->ContainsAny( true ) ) )
702 pSct
->DelEmpty( false );
704 else if (pOldParent
&& !pOldParent
->Lower()
705 && (pOldParent
->IsInFly() && !(pFly
= pOldParent
->FindFlyFrame())->ContainsContent()
706 && !pFly
->ContainsAny()))
708 if (pFly
->IsFlySplitAllowed())
710 // Master fly is empty now that we pasted the content to the follow, mark it for
712 auto pFlyAtContent
= static_cast<SwFlyAtContentFrame
*>(pFly
);
713 pFlyAtContent
->DelEmpty();
717 // If we're in a column section, we'd rather not call Calc "from below"
718 if( !m_rThis
.IsInSct() &&
719 ( !m_rThis
.IsInTab() || ( m_rThis
.IsTabFrame() && !m_rThis
.GetUpper()->IsInTab() ) ) )
720 m_rThis
.GetUpper()->Calc(m_rThis
.getRootFrame()->GetCurrShell()->GetOut());
721 else if( m_rThis
.GetUpper()->IsSctFrame() )
723 SwSectionFrame
* pTmpSct
= static_cast<SwSectionFrame
*>(m_rThis
.GetUpper());
724 bool bOld
= pTmpSct
->IsContentLocked();
725 pTmpSct
->SetContentLock( true );
726 pTmpSct
->Calc(m_rThis
.getRootFrame()->GetCurrShell()->GetOut());
728 pTmpSct
->SetContentLock( false );
730 SwPageFrame
*pPage
= m_rThis
.FindPageFrame();
732 if ( pOldPage
!= pPage
)
734 m_rThis
.InvalidatePage( pPage
);
735 if ( m_rThis
.IsLayoutFrame() )
737 SwContentFrame
*pCnt
= static_cast<SwLayoutFrame
*>(&m_rThis
)->ContainsContent();
739 pCnt
->InvalidatePage( pPage
);
741 else if ( pSh
&& pSh
->GetDoc()->GetLineNumberInfo().IsRestartEachPage()
742 && pPage
->FindFirstBodyContent() == &m_rThis
)
744 m_rThis
.InvalidateLineNum_();
747 if ( bInvaLay
|| (pSibling
&& pSibling
->IsLayoutFrame()) )
748 m_rThis
.GetUpper()->InvalidatePage( pPage
);
751 bool SwFlowFrame::IsAnFollow( const SwFlowFrame
*pAssumed
) const
753 const SwFlowFrame
*pFoll
= this;
755 { if ( pAssumed
== pFoll
)
757 pFoll
= pFoll
->GetFollow();
762 SwTextFrame
* SwContentFrame::FindMaster() const
764 OSL_ENSURE( IsFollow(), "SwContentFrame::FindMaster(): !IsFollow" );
766 const SwContentFrame
* pPrec
= static_cast<const SwContentFrame
*>(SwFlowFrame::GetPrecede());
768 if ( pPrec
&& pPrec
->HasFollow() && pPrec
->GetFollow() == this )
770 OSL_ENSURE( pPrec
->IsTextFrame(), "NoTextFrame with follow found" );
771 return const_cast<SwTextFrame
*>(static_cast< const SwTextFrame
* >(pPrec
));
774 OSL_FAIL( "Follow is lost in Space." );
778 SwSectionFrame
* SwSectionFrame::FindMaster() const
780 OSL_ENSURE( IsFollow(), "SwSectionFrame::FindMaster(): !IsFollow" );
785 SwIterator
<SwSectionFrame
,SwFormat
> aIter( *m_pSection
->GetFormat() );
786 SwSectionFrame
* pSect
= aIter
.First();
789 if (pSect
->GetFollow() == this)
791 pSect
= aIter
.Next();
794 OSL_FAIL( "Follow is lost in Space." );
798 SwTabFrame
* SwTabFrame::FindMaster( bool bFirstMaster
) const
800 OSL_ENSURE( IsFollow(), "SwTabFrame::FindMaster(): !IsFollow" );
802 SwIterator
<SwTabFrame
,SwFormat
> aIter( *GetTable()->GetFrameFormat() );
803 SwTabFrame
* pTab
= aIter
.First();
808 // Optimization. This makes code like this obsolete:
809 // while ( pTab->IsFollow() )
810 // pTab = pTab->FindMaster();
812 if ( !pTab
->IsFollow() )
814 SwTabFrame
* pNxt
= pTab
;
817 if ( pNxt
->GetFollow() == this )
819 pNxt
= pNxt
->GetFollow();
825 if ( pTab
->GetFollow() == this )
832 OSL_FAIL( "Follow is lost in Space." );
837 * Returns the next/previous Layout leaf that's NOT below this (or even is this itself).
838 * Also, that leaf must be in the same text flow as the pAnch origin frame (Body, Footnote)
840 const SwLayoutFrame
*SwFrame::GetLeaf( MakePageType eMakePage
, bool bFwd
,
841 const SwFrame
*pAnch
) const
843 // No flow, no joy...
844 if ( !(IsInDocBody() || IsInFootnote() || IsInFly()) )
847 const SwFrame
*pLeaf
= this;
851 { pLeaf
= const_cast<SwFrame
*>(pLeaf
)->GetLeaf( eMakePage
, bFwd
);
854 (!IsLayoutFrame() || !static_cast<const SwLayoutFrame
*>(this)->IsAnLower( pLeaf
)))
856 if ( pAnch
->IsInDocBody() == pLeaf
->IsInDocBody() &&
857 pAnch
->IsInFootnote() == pLeaf
->IsInFootnote() )
862 } while ( !bFound
&& pLeaf
);
864 return static_cast<const SwLayoutFrame
*>(pLeaf
);
867 SwLayoutFrame
*SwFrame::GetLeaf( MakePageType eMakePage
, bool bFwd
)
869 if ( IsInFootnote() )
870 return bFwd
? GetNextFootnoteLeaf( eMakePage
) : GetPrevFootnoteLeaf( eMakePage
);
873 // A frame could be inside a table AND inside a section.
874 // Thus, it has to be determined, which is the first parent.
875 bool bInTab( IsInTab() );
876 bool bInSct( IsInSct() );
877 if ( bInTab
&& bInSct
)
879 const SwFrame
* pUpperFrame( GetUpper() );
880 while ( pUpperFrame
)
882 if ( pUpperFrame
->IsTabFrame() )
884 // the table is the first.
888 else if ( pUpperFrame
->IsSctFrame() )
890 // the section is the first.
895 pUpperFrame
= pUpperFrame
->GetUpper();
899 if ( bInTab
&& ( !IsTabFrame() || GetUpper()->IsCellFrame() ) ) // TABLE IN TABLE
900 return bFwd
? GetNextCellLeaf() : GetPrevCellLeaf();
903 return bFwd
? GetNextSctLeaf( eMakePage
) : GetPrevSctLeaf();
905 if (IsInFly() && FindFlyFrame()->IsFlySplitAllowed())
909 return GetNextFlyLeaf(eMakePage
);
913 return GetPrevFlyLeaf();
917 return bFwd
? GetNextLeaf( eMakePage
) : GetPrevLeaf();
922 bool HasPageBreakBefore(SwPageFrame
const& rPage
)
924 SwFrame
const* pFlow(rPage
.FindFirstBodyContent());
929 while (pFlow
->GetUpper()->IsInTab())
931 pFlow
= pFlow
->GetUpper()->FindTabFrame();
933 return pFlow
->GetPageDescItem().GetPageDesc()
934 || pFlow
->GetBreakItem().GetBreak() == SvxBreak::PageBefore
935 || pFlow
->GetBreakItem().GetBreak() == SvxBreak::PageBoth
;
940 bool SwFrame::WrongPageDesc( SwPageFrame
* pNew
)
942 // Now it's getting a bit complicated:
944 // Maybe I'm bringing a Pagedesc myself; in that case,
945 // the pagedesc of the next page needs to correspond.
946 // Otherwise, I'll have to dig a bit deeper to see where
947 // the following Pagedesc is coming from.
948 // If the following page itself tells me that it's pagedesc
949 // is wrong, I can happily exchange it.
950 // If the page however thinks that it's pagedesc is correct,
951 // this doesn't mean it's useful to me:
952 // If the first BodyContent asks for a PageDesc or a PageBreak,
953 // I'll have to insert a new page - except the desired page is
955 // If I inserted a new page, the problems only get started:
956 // because then it's likely for the next page to have been
957 // wrong and having been swapped because of that.
958 // This in turn means that I have a new (and correct) page,
959 // but the conditions to swap still apply.
960 // Way out of the situation: Try to preliminarily insert a
961 // new page once (empty pages are already inserted by InsertPage()
964 //My Pagedesc doesn't count if I'm a follow!
965 const SwPageDesc
*pDesc
= nullptr;
966 std::optional
<sal_uInt16
> oTmp
;
967 SwFlowFrame
*pFlow
= SwFlowFrame::CastFlowFrame( this );
968 if ( !pFlow
|| !pFlow
->IsFollow() )
970 const SwFormatPageDesc
&rFormatDesc
= GetPageDescItem();
971 pDesc
= rFormatDesc
.GetPageDesc();
974 if( !pDesc
->GetRightFormat() )
976 else if( !pDesc
->GetLeftFormat() )
978 else if( rFormatDesc
.GetNumOffset() )
979 oTmp
= rFormatDesc
.GetNumOffset();
983 // Does the Content bring a Pagedesc or do we need the
984 // virtual page number of the new layout leaf?
985 // PageDesc isn't allowed with Follows
986 const bool isRightPage
= oTmp
? sw::IsRightPageByNumber(*mpRoot
, *oTmp
) : pNew
->OnRightPage();
988 pDesc
= pNew
->FindPageDesc();
990 bool bFirst
= pNew
->OnFirstPage();
992 const SwFlowFrame
*pNewFlow
= pNew
->FindFirstBodyContent();
993 // Did we find ourselves?
994 if( pNewFlow
== pFlow
)
996 if ( pNewFlow
&& pNewFlow
->GetFrame().IsInTab() )
997 pNewFlow
= pNewFlow
->GetFrame().FindTabFrame();
998 const SwPageDesc
*pNewDesc
= ( pNewFlow
&& !pNewFlow
->IsFollow() )
999 ? pNewFlow
->GetFrame().GetPageDescItem().GetPageDesc()
1002 SAL_INFO( "sw.pageframe", "WrongPageDesc p: " << pNew
<< " phys: " << pNew
->GetPhyPageNum() );
1003 SAL_INFO( "sw.pageframe", "WrongPageDesc " << pNew
->GetPageDesc() << " " << pDesc
);
1004 SAL_INFO( "sw.pageframe", "WrongPageDesc right: " << isRightPage
1005 << " first: " << bFirst
<< " " << pNew
->GetFormat() << " == "
1006 << (isRightPage
? pDesc
->GetRightFormat(bFirst
) : pDesc
->GetLeftFormat(bFirst
)) << " "
1007 << (isRightPage
? pDesc
->GetLeftFormat(bFirst
) : pDesc
->GetRightFormat(bFirst
)) );
1009 return (pNew
->GetPageDesc() != pDesc
) // own desc ?
1010 || (pNew
->GetFormat() !=
1011 (isRightPage
? pDesc
->GetRightFormat(bFirst
) : pDesc
->GetLeftFormat(bFirst
)))
1012 || (pNewDesc
&& pNewDesc
== pDesc
);
1015 /// Returns the next layout leaf in which we can move the frame.
1016 SwLayoutFrame
*SwFrame::GetNextLeaf( MakePageType eMakePage
)
1018 OSL_ENSURE( !IsInFootnote(), "GetNextLeaf(), don't call me for Footnote." );
1019 OSL_ENSURE( !IsInSct(), "GetNextLeaf(), don't call me for Sections." );
1021 const bool bBody
= IsInDocBody(); // If I'm coming from the DocBody,
1022 // I want to end up in the body.
1024 // It doesn't make sense to insert pages, as we only want to search the
1027 eMakePage
= MAKEPAGE_NONE
;
1029 // For tables, we just take the big leap. A simple GetNext would
1030 // iterate through the first cells and, in turn, all other cells.
1031 SwLayoutFrame
*pLayLeaf
= nullptr;
1034 SwFrame
*const pTmp
= static_cast<SwTabFrame
*>(this)->FindLastContentOrTable();
1036 pLayLeaf
= pTmp
->GetUpper();
1039 pLayLeaf
= GetNextLayoutLeaf();
1041 SwLayoutFrame
*pOldLayLeaf
= nullptr; // Make sure that we don't have to
1042 // start searching from top when we
1043 // have a freshly created page.
1044 bool bNewPg
= false; // Only insert a new page once.
1050 // There's yet another LayoutFrame. Let's see if it's ready to host
1052 // It only needs to be of the same kind like my starting point
1053 // (DocBody or Footnote respectively)
1054 if ( pLayLeaf
->FindPageFrame()->IsFootnotePage() )
1055 { // If I ended up at the end note pages, we're done.
1059 if ( (bBody
&& !pLayLeaf
->IsInDocBody()) || pLayLeaf
->IsInTab()
1060 || pLayLeaf
->IsInSct() )
1062 // They don't want me! Try again
1063 pOldLayLeaf
= pLayLeaf
;
1064 pLayLeaf
= pLayLeaf
->GetNextLayoutLeaf();
1068 // I'm wanted, therefore I'm done. However, it may still be that,
1069 // during a page break, the page type isn't the desired one. In that
1070 // case we have to insert a page of the correct type.
1072 if( !IsFlowFrame() && ( eMakePage
== MAKEPAGE_NONE
||
1073 eMakePage
==MAKEPAGE_APPEND
|| eMakePage
==MAKEPAGE_NOSECTION
) )
1076 SwPageFrame
*pNew
= pLayLeaf
->FindPageFrame();
1077 const SwViewShell
*pSh
= getRootFrame()->GetCurrShell();
1078 // The pagedesc check does not make sense for frames in fly frames
1079 if ( pNew
!= FindPageFrame() && !bNewPg
&& !IsInFly() &&
1081 // Do not consider page descriptions in browse mode (since
1082 // MoveBwd ignored them)
1083 !(pSh
&& pSh
->GetViewOptions()->getBrowseMode() ) )
1085 if( WrongPageDesc( pNew
) )
1087 SwFootnoteContFrame
*pCont
= pNew
->FindFootnoteCont();
1090 // If the reference of the first footnote of this page
1091 // lies before the page, we'd rather not insert a new page.
1093 SwFootnoteFrame
*pFootnote
= static_cast<SwFootnoteFrame
*>(pCont
->Lower());
1094 if( pFootnote
&& pFootnote
->GetRef() )
1096 const sal_uInt16 nRefNum
= pNew
->GetPhyPageNum();
1097 if( pFootnote
->GetRef()->GetPhyPageNum() < nRefNum
)
1101 //Gotcha! The following page is wrong, therefore we need to
1103 if ( eMakePage
== MAKEPAGE_INSERT
)
1107 SwPageFrame
*pPg
= pOldLayLeaf
?
1108 pOldLayLeaf
->FindPageFrame() : nullptr;
1109 if ( pPg
&& pPg
->IsEmptyPage() )
1110 // Don't insert behind. Insert before the EmptyPage.
1111 pPg
= static_cast<SwPageFrame
*>(pPg
->GetPrev());
1113 if ( !pPg
|| pPg
== pNew
)
1114 pPg
= FindPageFrame();
1116 InsertPage( pPg
, false );
1117 pLayLeaf
= GetNextLayoutLeaf();
1118 pOldLayLeaf
= nullptr;
1129 // There's no other matching LayoutFrame, so we have to insert
1131 if ( eMakePage
== MAKEPAGE_APPEND
|| eMakePage
== MAKEPAGE_INSERT
)
1134 pOldLayLeaf
? pOldLayLeaf
->FindPageFrame() : FindPageFrame(),
1137 // And again from the start.
1138 pLayLeaf
= pOldLayLeaf
? pOldLayLeaf
: GetNextLayoutLeaf();
1147 /// Returns the previous layout leaf where we can move the frame.
1148 SwLayoutFrame
*SwFrame::GetPrevLeaf()
1150 OSL_ENSURE( !IsInFootnote(), "GetPrevLeaf(), don't call me for Footnote." );
1152 const bool bBody
= IsInDocBody(); // If I'm coming from the DocBody,
1153 // I want to end up in the body.
1154 const bool bFly
= IsInFly();
1156 SwLayoutFrame
*pLayLeaf
= GetPrevLayoutLeaf();
1157 SwLayoutFrame
*pPrevLeaf
= nullptr;
1161 if ( pLayLeaf
->IsInTab() || // Never go into tables.
1162 pLayLeaf
->IsInSct() ) // Same goes for sections!
1163 pLayLeaf
= pLayLeaf
->GetPrevLayoutLeaf();
1164 else if ( bBody
&& pLayLeaf
->IsInDocBody() )
1166 if ( pLayLeaf
->Lower() )
1168 pPrevLeaf
= pLayLeaf
;
1169 pLayLeaf
= pLayLeaf
->GetPrevLayoutLeaf();
1171 SwFlowFrame::SetMoveBwdJump( true );
1174 break; //Contents in Flys should accept any layout leaf.
1176 pLayLeaf
= pLayLeaf
->GetPrevLayoutLeaf();
1178 return pLayLeaf
? pLayLeaf
: pPrevLeaf
;
1181 bool SwFlowFrame::IsPrevObjMove() const
1183 // true: The FlowFrame must respect the a border of the predecessor, also needs
1184 // to insert a break if required.
1186 //!!!!!!!!!!!Hack!!!!!!!!!!!
1187 const SwViewShell
*pSh
= m_rThis
.getRootFrame()->GetCurrShell();
1188 if( pSh
&& pSh
->GetViewOptions()->getBrowseMode() )
1191 SwFrame
*pPre
= m_rThis
.FindPrev();
1193 if ( pPre
&& pPre
->GetDrawObjs() )
1195 OSL_ENSURE( SwFlowFrame::CastFlowFrame( pPre
), "new flowfrm?" );
1196 if( SwFlowFrame::CastFlowFrame( pPre
)->IsAnFollow( this ) )
1198 if (SwFlowFrame::CastFlowFrame(pPre
)->IsJoinLocked())
1200 SwBorderAttrAccess
baa(SwFrame::GetCache(), pPre
);
1201 SwBorderAttrs
const& rAttrs(*baa
.Get());
1202 if (SwFlowFrame::CastFlowFrame(pPre
)->IsKeep(rAttrs
.GetAttrSet().GetKeep(), pPre
->GetBreakItem()))
1203 { // pPre is currently being formatted - maybe it moved back but
1204 // its objects still have the old page's body as
1205 // mpVertPosOrientFrame and SwContentFrame::MakeAll() is calling
1206 // pNxt->Calc() in this case so allow this frame to move back
1207 return false; // too, else pPre is forced to move forward again.
1210 SwLayoutFrame
* pPreUp
= pPre
->GetUpper();
1211 // If the upper is a SectionFrame, or a column of a SectionFrame, we're
1212 // allowed to protrude out of it. However, we need to respect the
1213 // Upper of the SectionFrame.
1214 if( pPreUp
->IsInSct() )
1216 if( pPreUp
->IsSctFrame() )
1217 pPreUp
= pPreUp
->GetUpper();
1218 else if( pPreUp
->IsColBodyFrame() &&
1219 pPreUp
->GetUpper()->GetUpper()->IsSctFrame() )
1220 pPreUp
= pPreUp
->GetUpper()->GetUpper()->GetUpper();
1222 // i#26945 - re-factoring
1223 // use <GetVertPosOrientFrame()> to determine, if object has followed the
1224 // text flow to the next layout frame
1225 for (SwAnchoredObject
* pObj
: *pPre
->GetDrawObjs())
1228 // Do not consider hidden objects
1229 // i#26945 - do not consider object, which
1230 // doesn't follow the text flow.
1231 if ( pObj
->GetFrameFormat().GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId(
1232 pObj
->GetDrawObj()->GetLayer() ) &&
1233 pObj
->GetFrameFormat().GetFollowTextFlow().GetValue() )
1235 const SwLayoutFrame
* pVertPosOrientFrame
= pObj
->GetVertPosOrientFrame();
1236 if ( pVertPosOrientFrame
&&
1237 pPreUp
!= pVertPosOrientFrame
&&
1238 !pPreUp
->IsAnLower( pVertPosOrientFrame
) )
1249 |* If there's a hard page break before the Frame AND there's a
1250 |* predecessor on the same page, true is returned (we need to create a
1251 |* new PageBreak). Otherwise, returns false.
1252 |* If bAct is set to true, this function returns true if
1253 |* there's a PageBreak.
1254 |* Of course, we don't evaluate the hard page break for follows.
1255 |* The page break is in its own FrameFormat (BEFORE) or in the FrameFormat of the
1256 |* predecessor (AFTER). If there's no predecessor on the page, we don't
1257 |* need to think further.
1258 |* Also, a page break (or the need for one) is also present if
1259 |* the FrameFormat contains a PageDesc.
1260 |* The implementation works only on ContentFrames! - the definition
1261 |* of the predecessor is not clear for LayoutFrames.
1263 bool SwFlowFrame::IsPageBreak( bool bAct
) const
1265 if ( !IsFollow() && m_rThis
.IsInDocBody() &&
1266 ( !m_rThis
.IsInTab() || ( m_rThis
.IsTabFrame() && !m_rThis
.GetUpper()->IsInTab() ) ) ) // i66968
1268 const SwViewShell
*pSh
= m_rThis
.getRootFrame()->GetCurrShell();
1269 if( pSh
&& pSh
->GetViewOptions()->getBrowseMode() )
1272 // Determine predecessor
1273 const SwFrame
*pPrev
= m_rThis
.FindPrev();
1274 while ( pPrev
&& ( !pPrev
->IsInDocBody() ||
1275 ( pPrev
->IsTextFrame() && static_cast<const SwTextFrame
*>(pPrev
)->IsHiddenNow() ) ) )
1276 pPrev
= pPrev
->FindPrev();
1280 OSL_ENSURE( pPrev
->IsInDocBody(), "IsPageBreak: Not in DocBody?" );
1282 { if ( m_rThis
.FindPageFrame() == pPrev
->FindPageFrame() )
1286 { if ( m_rThis
.FindPageFrame() != pPrev
->FindPageFrame() )
1290 //for compatibility, also break at column break if no columns exist
1291 const IDocumentSettingAccess
& rIDSA
= m_rThis
.GetUpper()->GetFormat()->getIDocumentSettingAccess();
1292 const bool bTreatSingleColumnBreakAsPageBreak
= rIDSA
.get(DocumentSettingId::TREAT_SINGLE_COLUMN_BREAK_AS_PAGE_BREAK
);
1293 const SvxBreak eBreak
= m_rThis
.GetBreakItem().GetBreak();
1294 if ( eBreak
== SvxBreak::PageBefore
||
1295 eBreak
== SvxBreak::PageBoth
||
1296 ( bTreatSingleColumnBreakAsPageBreak
&& eBreak
== SvxBreak::ColumnBefore
&& !m_rThis
.FindColFrame() ))
1300 const SvxBreak
&ePrB
= pPrev
->GetBreakItem().GetBreak();
1301 if ( ePrB
== SvxBreak::PageAfter
||
1302 ePrB
== SvxBreak::PageBoth
||
1303 m_rThis
.GetPageDescItem().GetPageDesc())
1314 |* If there's a hard column break before the Frame AND there is
1315 |* a predecessor in the same column, we return true (we need to create
1316 |* a ColBreak). Otherwise, we return false.
1317 |* If bAct is set to true, we return true if there's a ColBreak.
1318 |* Of course, we don't evaluate the hard column break for follows.
1320 |* The column break is in its own FrameFormat (BEFORE) or in the FrameFormat of the
1321 |* predecessor (AFTER). If there's no predecessor in the column, we don't
1322 |* need to think further.
1323 |* The implementation works only on ContentFrames! - the definition
1324 |* of the predecessor is not clear for LayoutFrames.
1326 bool SwFlowFrame::IsColBreak( bool bAct
) const
1328 if ( !IsFollow() && (m_rThis
.IsMoveable() || bAct
) )
1330 const SwFrame
*pCol
= m_rThis
.FindColFrame();
1333 // Determine predecessor
1334 const SwFrame
*pPrev
= m_rThis
.FindPrev();
1335 while( pPrev
&& ( ( !pPrev
->IsInDocBody() && !m_rThis
.IsInFly() && !m_rThis
.FindFooterOrHeader() ) ||
1336 ( pPrev
->IsTextFrame() && static_cast<const SwTextFrame
*>(pPrev
)->IsHiddenNow() ) ) )
1337 pPrev
= pPrev
->FindPrev();
1342 { if ( pCol
== pPrev
->FindColFrame() )
1346 { if ( pCol
!= pPrev
->FindColFrame() )
1350 const SvxBreak eBreak
= m_rThis
.GetBreakItem().GetBreak();
1351 if ( eBreak
== SvxBreak::ColumnBefore
||
1352 eBreak
== SvxBreak::ColumnBoth
)
1356 const SvxBreak
&ePrB
= pPrev
->GetBreakItem().GetBreak();
1357 if ( ePrB
== SvxBreak::ColumnAfter
||
1358 ePrB
== SvxBreak::ColumnBoth
)
1367 bool SwFlowFrame::HasParaSpaceAtPages( bool bSct
) const
1369 if( m_rThis
.IsInSct() )
1371 const SwFrame
* pTmp
= m_rThis
.GetUpper();
1374 if( pTmp
->IsCellFrame() || pTmp
->IsFlyFrame() ||
1375 pTmp
->IsFooterFrame() || pTmp
->IsHeaderFrame() ||
1376 ( pTmp
->IsFootnoteFrame() && !static_cast<const SwFootnoteFrame
*>(pTmp
)->GetMaster() ) )
1378 if( pTmp
->IsPageFrame() )
1379 return !pTmp
->GetPrev() || IsPageBreak(true);
1380 if( pTmp
->IsColumnFrame() && pTmp
->GetPrev() )
1381 return IsColBreak( true );
1382 if( pTmp
->IsSctFrame() && ( !bSct
|| pTmp
->GetPrev() ) )
1384 pTmp
= pTmp
->GetUpper();
1386 OSL_FAIL( "HasParaSpaceAtPages: Where's my page?" );
1389 if( !m_rThis
.IsInDocBody() || ( m_rThis
.IsInTab() && !m_rThis
.IsTabFrame()) ||
1390 IsPageBreak( true ) || ( m_rThis
.FindColFrame() && IsColBreak( true ) ) )
1392 const SwFrame
* pTmp
= m_rThis
.FindColFrame();
1395 if( pTmp
->GetPrev() )
1400 pTmp
= pTmp
->FindPageFrame();
1401 return pTmp
&& !pTmp
->GetPrev();
1404 /** helper method to determine previous frame for calculation of the
1409 const SwFrame
* SwFlowFrame::GetPrevFrameForUpperSpaceCalc_( const SwFrame
* _pProposedPrevFrame
) const
1411 const SwFrame
* pPrevFrame
= _pProposedPrevFrame
1412 ? _pProposedPrevFrame
1413 : m_rThis
.GetPrev();
1415 // Skip hidden paragraphs and empty sections
1416 while ( pPrevFrame
&&
1417 ( ( pPrevFrame
->IsTextFrame() &&
1418 static_cast<const SwTextFrame
*>(pPrevFrame
)->IsHiddenNow() ) ||
1419 ( pPrevFrame
->IsSctFrame() &&
1420 !static_cast<const SwSectionFrame
*>(pPrevFrame
)->GetSection() ) ) )
1422 pPrevFrame
= pPrevFrame
->GetPrev();
1425 // Special case: no direct previous frame is found but frame is in footnote
1426 // Search for a previous frame in previous footnote,
1427 // if frame isn't in a section, which is also in the footnote
1428 if ( !pPrevFrame
&& m_rThis
.IsInFootnote() &&
1429 ( m_rThis
.IsSctFrame() ||
1430 !m_rThis
.IsInSct() || !m_rThis
.FindSctFrame()->IsInFootnote() ) )
1432 const SwFootnoteFrame
* pPrevFootnoteFrame
=
1433 static_cast<const SwFootnoteFrame
*>(m_rThis
.FindFootnoteFrame()->GetPrev());
1434 if ( pPrevFootnoteFrame
)
1436 pPrevFrame
= pPrevFootnoteFrame
->GetLastLower();
1438 // Skip hidden paragraphs and empty sections
1439 while ( pPrevFrame
&&
1440 ( ( pPrevFrame
->IsTextFrame() &&
1441 static_cast<const SwTextFrame
*>(pPrevFrame
)->IsHiddenNow() ) ||
1442 ( pPrevFrame
->IsSctFrame() &&
1443 !static_cast<const SwSectionFrame
*>(pPrevFrame
)->GetSection() ) ) )
1445 pPrevFrame
= pPrevFrame
->GetPrev();
1449 // Special case: found previous frame is a section
1450 // Search for the last content in the section
1451 if( pPrevFrame
&& pPrevFrame
->IsSctFrame() )
1453 const SwSectionFrame
* pPrevSectFrame
=
1454 static_cast<const SwSectionFrame
*>(pPrevFrame
);
1455 pPrevFrame
= pPrevSectFrame
->FindLastContent();
1456 // If the last content is in a table _inside_ the section,
1457 // take the table herself.
1458 // Correction: Check directly, if table is inside table, instead of indirectly
1459 // by checking, if section isn't inside a table
1460 if ( pPrevFrame
&& pPrevFrame
->IsInTab() )
1462 const SwTabFrame
* pTableFrame
= pPrevFrame
->FindTabFrame();
1463 if ( pPrevSectFrame
->IsAnLower( pTableFrame
) )
1465 pPrevFrame
= pTableFrame
;
1468 // Correction: skip hidden text frames
1469 while ( pPrevFrame
&&
1470 pPrevFrame
->IsTextFrame() &&
1471 static_cast<const SwTextFrame
*>(pPrevFrame
)->IsHiddenNow() )
1473 pPrevFrame
= pPrevFrame
->GetPrev();
1480 /// Compare styles attached to these text frames.
1481 static bool lcl_IdenticalStyles(const SwFrame
* pPrevFrame
, const SwFrame
* pFrame
)
1483 SwTextFormatColl
*pPrevFormatColl
= nullptr;
1484 if (pPrevFrame
&& pPrevFrame
->IsTextFrame())
1486 const SwTextFrame
*pTextFrame
= static_cast< const SwTextFrame
* >( pPrevFrame
);
1487 pPrevFormatColl
= dynamic_cast<SwTextFormatColl
*>(
1488 pTextFrame
->GetTextNodeForParaProps()->GetFormatColl());
1491 bool bIdenticalStyles
= false;
1492 if (pFrame
&& pFrame
->IsTextFrame())
1494 const SwTextFrame
*pTextFrame
= static_cast< const SwTextFrame
* >( pFrame
);
1495 SwTextFormatColl
*const pFormatColl
= dynamic_cast<SwTextFormatColl
*>(
1496 pTextFrame
->GetTextNodeForParaProps()->GetFormatColl());
1497 bIdenticalStyles
= pPrevFormatColl
== pFormatColl
;
1499 return bIdenticalStyles
;
1502 static bool lcl_getContextualSpacing(const SwFrame
* pPrevFrame
)
1505 SwBorderAttrAccess
aAccess(SwFrame::GetCache(), pPrevFrame
);
1506 const SwBorderAttrs
*pAttrs
= aAccess
.Get();
1508 bRet
= pAttrs
->GetULSpace().GetContext();
1514 SwTwips
SwFlowFrame::CalcUpperSpace( const SwBorderAttrs
*pAttrs
,
1516 const bool _bConsiderGrid
) const
1518 const SwFrame
* pPrevFrame
= GetPrevFrameForUpperSpaceCalc_( pPr
);
1520 std::optional
<SwBorderAttrAccess
> oAccess
;
1524 if( m_rThis
.IsSctFrame() )
1526 SwSectionFrame
* pFoll
= &static_cast<SwSectionFrame
&>(m_rThis
);
1528 pOwn
= pFoll
->ContainsAny();
1529 while( !pOwn
&& nullptr != ( pFoll
= pFoll
->GetFollow() ) );
1535 oAccess
.emplace(SwFrame::GetCache(), pOwn
);
1536 pAttrs
= oAccess
->Get();
1545 const IDocumentSettingAccess
& rIDSA
= m_rThis
.GetUpper()->GetFormat()->getIDocumentSettingAccess();
1548 const bool bUseFormerLineSpacing
= rIDSA
.get(DocumentSettingId::OLD_LINE_SPACING
);
1549 const bool bContextualSpacingThis
= pAttrs
->GetULSpace().GetContext();
1550 const bool bContextualSpacingPrev
= lcl_getContextualSpacing(pPrevFrame
);
1551 bool bIdenticalStyles
= lcl_IdenticalStyles(pPrevFrame
, &m_rThis
);
1553 const bool bContextualSpacing
= bContextualSpacingThis
1554 && bContextualSpacingPrev
1555 && bIdenticalStyles
;
1557 // tdf#125893 always ignore own top margin setting of the actual paragraph
1558 // with contextual spacing, if the previous paragraph is identical
1559 const bool bHalfContextualSpacing
= !bContextualSpacing
1560 && bContextualSpacingThis
1561 && !bContextualSpacingPrev
1562 && bIdenticalStyles
;
1564 // tdf#134463 always ignore own bottom margin setting of the previous paragraph
1565 // with contextual spacing, if the actual paragraph is identical
1566 const bool bHalfContextualSpacingPrev
= !bContextualSpacing
1567 && !bContextualSpacingThis
1568 && bContextualSpacingPrev
1569 && bIdenticalStyles
;
1571 // i#11860 - use new method to determine needed spacing
1572 // values of found previous frame and use these values.
1573 SwTwips nPrevLowerSpace
= 0;
1574 SwTwips nPrevLineSpacing
= 0;
1576 bool bPrevLineSpacingProportional
= false;
1577 GetSpacingValuesOfFrame( (*pPrevFrame
),
1578 nPrevLowerSpace
, nPrevLineSpacing
,
1579 bPrevLineSpacingProportional
,
1581 if( rIDSA
.get(DocumentSettingId::PARA_SPACE_MAX
) )
1583 // FIXME: apply bHalfContextualSpacing for better portability?
1584 nUpper
= bContextualSpacing
? 0 : nPrevLowerSpace
+ pAttrs
->GetULSpace().GetUpper();
1585 SwTwips nAdd
= nPrevLineSpacing
;
1586 // i#11859 - consideration of the line spacing
1587 // for the upper spacing of a text frame
1588 if ( bUseFormerLineSpacing
)
1590 // former consideration
1591 if ( pOwn
->IsTextFrame() )
1593 nAdd
= std::max( nAdd
, SwTwips(static_cast<SwTextFrame
*>(pOwn
)->GetLineSpace()) );
1599 // new consideration:
1600 // Only the proportional line spacing of the previous
1601 // text frame is considered for the upper spacing and
1602 // the line spacing values are add up instead of
1603 // building its maximum.
1604 if ( pOwn
->IsTextFrame() )
1608 // A proportional line spacing of the previous text frame
1609 // is added up to an own leading line spacing.
1610 // Otherwise, the maximum of the leading line spacing
1611 // of the previous text frame and the own leading line
1612 // spacing is built.
1613 if ( bPrevLineSpacingProportional
)
1615 nAdd
+= static_cast<SwTextFrame
*>(pOwn
)->GetLineSpace( true );
1619 nAdd
= std::max( nAdd
, SwTwips(static_cast<SwTextFrame
*>(pOwn
)->GetLineSpace( true )) );
1627 nUpper
= bContextualSpacing
? 0 : std::max(
1628 bHalfContextualSpacingPrev
? 0 : static_cast<tools::Long
>(nPrevLowerSpace
),
1629 bHalfContextualSpacing
? 0 : static_cast<tools::Long
>(pAttrs
->GetULSpace().GetUpper()) );
1631 // i#11859 - consideration of the line spacing
1632 // for the upper spacing of a text frame
1633 if ( bUseFormerLineSpacing
)
1635 // former consideration
1636 if ( pOwn
->IsTextFrame() )
1637 nUpper
= std::max( nUpper
, SwTwips(static_cast<SwTextFrame
*>(pOwn
)->GetLineSpace()) );
1638 if ( nPrevLineSpacing
!= 0 )
1640 nUpper
= std::max( nUpper
, nPrevLineSpacing
);
1645 // new consideration:
1646 // Only the proportional line spacing of the previous
1647 // text frame is considered for the upper spacing and
1648 // the line spacing values are add up and added to
1649 // the paragraph spacing instead of building the
1650 // maximum of the line spacings and the paragraph spacing.
1651 SwTwips nAdd
= nPrevLineSpacing
;
1652 if ( pOwn
->IsTextFrame() )
1656 // A proportional line spacing of the previous text frame
1657 // is added up to an own leading line spacing.
1658 // Otherwise, the maximum of the leading line spacing
1659 // of the previous text frame and the own leading line
1660 // spacing is built.
1661 if ( bPrevLineSpacingProportional
)
1663 nAdd
+= static_cast<SwTextFrame
*>(pOwn
)->GetLineSpace( true );
1667 nAdd
= std::max( nAdd
, SwTwips(static_cast<SwTextFrame
*>(pOwn
)->GetLineSpace( true )) );
1674 else if ( rIDSA
.get(DocumentSettingId::PARA_SPACE_MAX_AT_PAGES
) &&
1675 CastFlowFrame( pOwn
)->HasParaSpaceAtPages( m_rThis
.IsSctFrame() ) )
1677 nUpper
= pAttrs
->GetULSpace().GetUpper();
1681 // i#25029 - pass previous frame <pPrevFrame>
1682 // to method <GetTopLine(..)>, if parameter <pPr> is set.
1683 // Note: parameter <pPr> is set, if method is called from <SwTextFrame::WouldFit(..)>
1684 nUpper
+= pAttrs
->GetTopLine( m_rThis
, (pPr
? pPrevFrame
: nullptr) );
1686 // i#11860 - consider value of new parameter <_bConsiderGrid>
1687 // and use new method <GetUpperSpaceAmountConsideredForPageGrid(..)>
1689 //consider grid in square page mode
1690 if ( _bConsiderGrid
&& m_rThis
.GetUpper()->GetFormat()->GetDoc()->IsSquaredPageMode() )
1692 nUpper
+= GetUpperSpaceAmountConsideredForPageGrid_( nUpper
);
1697 /** method to determine the upper space amount, which is considered for
1701 Precondition: Position of frame is valid.
1703 SwTwips
SwFlowFrame::GetUpperSpaceAmountConsideredForPageGrid_(
1704 const SwTwips _nUpperSpaceWithoutGrid
) const
1706 SwTwips nUpperSpaceAmountConsideredForPageGrid
= 0;
1708 if ( m_rThis
.IsInDocBody() && m_rThis
.GetAttrSet()->GetParaGrid().GetValue() )
1710 const SwPageFrame
* pPageFrame
= m_rThis
.FindPageFrame();
1711 SwTextGridItem
const*const pGrid(GetGridItem(pPageFrame
));
1714 const SwFrame
* pBodyFrame
= pPageFrame
->FindBodyCont();
1717 const tools::Long nGridLineHeight
=
1718 pGrid
->GetBaseHeight() + pGrid
->GetRubyHeight();
1720 SwRectFnSet
aRectFnSet(&m_rThis
);
1721 const SwTwips nBodyPrtTop
= aRectFnSet
.GetPrtTop(*pBodyFrame
);
1722 const SwTwips nProposedPrtTop
=
1723 aRectFnSet
.YInc( aRectFnSet
.GetTop(m_rThis
.getFrameArea()),
1724 _nUpperSpaceWithoutGrid
);
1726 const SwTwips nSpaceAbovePrtTop
=
1727 aRectFnSet
.YDiff( nProposedPrtTop
, nBodyPrtTop
);
1728 const SwTwips nSpaceOfCompleteLinesAbove
=
1729 nGridLineHeight
* ( nSpaceAbovePrtTop
/ nGridLineHeight
);
1730 SwTwips nNewPrtTop
=
1731 aRectFnSet
.YInc( nBodyPrtTop
, nSpaceOfCompleteLinesAbove
);
1732 if ( aRectFnSet
.YDiff( nProposedPrtTop
, nNewPrtTop
) > 0 )
1734 nNewPrtTop
= aRectFnSet
.YInc( nNewPrtTop
, nGridLineHeight
);
1737 const SwTwips nNewUpperSpace
=
1738 aRectFnSet
.YDiff( nNewPrtTop
,
1739 aRectFnSet
.GetTop(m_rThis
.getFrameArea()) );
1741 nUpperSpaceAmountConsideredForPageGrid
=
1742 nNewUpperSpace
- _nUpperSpaceWithoutGrid
;
1744 OSL_ENSURE( nUpperSpaceAmountConsideredForPageGrid
>= 0,
1745 "<SwFlowFrame::GetUpperSpaceAmountConsideredForPageGrid(..)> - negative space considered for page grid!" );
1749 return nUpperSpaceAmountConsideredForPageGrid
;
1752 /** method to determine the upper space amount, which is considered for
1757 SwTwips
SwFlowFrame::GetUpperSpaceAmountConsideredForPrevFrame() const
1759 SwTwips nUpperSpaceAmountOfPrevFrame
= 0;
1761 const SwFrame
* pPrevFrame
= GetPrevFrameForUpperSpaceCalc_();
1764 SwTwips nPrevLowerSpace
= 0;
1765 SwTwips nPrevLineSpacing
= 0;
1767 bool bDummy
= false;
1768 GetSpacingValuesOfFrame( (*pPrevFrame
), nPrevLowerSpace
, nPrevLineSpacing
, bDummy
, lcl_IdenticalStyles(pPrevFrame
, &m_rThis
));
1769 if ( nPrevLowerSpace
> 0 || nPrevLineSpacing
> 0 )
1771 const IDocumentSettingAccess
& rIDSA
= m_rThis
.GetUpper()->GetFormat()->getIDocumentSettingAccess();
1772 if ( rIDSA
.get(DocumentSettingId::PARA_SPACE_MAX
) ||
1773 !rIDSA
.get(DocumentSettingId::OLD_LINE_SPACING
) )
1775 nUpperSpaceAmountOfPrevFrame
= nPrevLowerSpace
+ nPrevLineSpacing
;
1779 nUpperSpaceAmountOfPrevFrame
= std::max( nPrevLowerSpace
, nPrevLineSpacing
);
1784 return nUpperSpaceAmountOfPrevFrame
;
1787 /** method to determine the upper space amount, which is considered for
1788 the previous frame and the page grid, if option 'Use former object
1793 SwTwips
SwFlowFrame::GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid() const
1795 SwTwips nUpperSpaceAmountConsideredForPrevFrameAndPageGrid
= 0;
1797 if (!m_rThis
.GetUpper() || !m_rThis
.GetUpper()->GetFormat())
1799 return nUpperSpaceAmountConsideredForPrevFrameAndPageGrid
;
1802 if ( !m_rThis
.GetUpper()->GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::USE_FORMER_OBJECT_POS
) )
1804 nUpperSpaceAmountConsideredForPrevFrameAndPageGrid
=
1805 GetUpperSpaceAmountConsideredForPrevFrame() +
1806 ( m_rThis
.GetUpper()->GetFormat()->GetDoc()->IsSquaredPageMode()
1807 ? GetUpperSpaceAmountConsideredForPageGrid_( CalcUpperSpace( nullptr, nullptr, false ) )
1811 return nUpperSpaceAmountConsideredForPrevFrameAndPageGrid
;
1814 // Calculation of lower space
1816 SwTwips
SwFlowFrame::CalcLowerSpace( const SwBorderAttrs
* _pAttrs
) const
1818 SwTwips nLowerSpace
= 0;
1820 std::optional
<SwBorderAttrAccess
> oAttrAccess
;
1823 oAttrAccess
.emplace(SwFrame::GetCache(), &m_rThis
);
1824 _pAttrs
= oAttrAccess
->Get();
1827 bool bCommonBorder
= true;
1828 if ( m_rThis
.IsInSct() && m_rThis
.GetUpper()->IsColBodyFrame() )
1830 const SwSectionFrame
* pSectFrame
= m_rThis
.FindSctFrame();
1831 bCommonBorder
= pSectFrame
->GetFormat()->GetBalancedColumns().GetValue();
1833 nLowerSpace
= bCommonBorder
?
1834 _pAttrs
->GetBottomLine( m_rThis
) :
1835 _pAttrs
->CalcBottomLine();
1838 // - correct consideration of table frames
1839 // - use new method <CalcAddLowerSpaceAsLastInTableCell(..)>
1840 if ( ( ( m_rThis
.IsTabFrame() && m_rThis
.GetUpper()->IsInTab() ) ||
1841 // No lower spacing, if frame has a follow
1842 ( m_rThis
.IsInTab() && !GetFollow() ) ) &&
1843 !m_rThis
.GetIndNext() )
1845 nLowerSpace
+= CalcAddLowerSpaceAsLastInTableCell( _pAttrs
);
1848 // tdf#128195 Consider para spacing below last paragraph in header
1849 bool bHasSpacingBelowPara
= m_rThis
.GetUpper()->GetFormat()->getIDocumentSettingAccess().get(
1850 DocumentSettingId::HEADER_SPACING_BELOW_LAST_PARA
);
1851 if (bHasSpacingBelowPara
&& !m_rThis
.IsInTab() && !m_rThis
.IsInFly()
1852 && m_rThis
.FindFooterOrHeader() && !GetFollow() && !m_rThis
.GetIndNext())
1854 nLowerSpace
+= _pAttrs
->GetULSpace().GetLower() + _pAttrs
->CalcLineSpacing();
1860 /** calculation of the additional space to be considered, if flow frame
1861 is the last inside a table cell
1865 SwTwips
SwFlowFrame::CalcAddLowerSpaceAsLastInTableCell(
1866 const SwBorderAttrs
* _pAttrs
) const
1868 SwTwips nAdditionalLowerSpace
= 0;
1870 IDocumentSettingAccess
const& rIDSA(m_rThis
.GetUpper()->GetFormat()->getIDocumentSettingAccess());
1871 if (rIDSA
.get(DocumentSettingId::ADD_PARA_SPACING_TO_TABLE_CELLS
))
1873 const SwFrame
* pFrame
= &m_rThis
;
1874 if ( pFrame
->IsSctFrame() )
1876 const SwSectionFrame
* pSectFrame
= static_cast<const SwSectionFrame
*>(pFrame
);
1877 pFrame
= pSectFrame
->FindLastContent();
1878 if ( pFrame
&& pFrame
->IsInTab() )
1880 const SwTabFrame
* pTableFrame
= pFrame
->FindTabFrame();
1881 if ( pSectFrame
->IsAnLower( pTableFrame
) )
1883 pFrame
= pTableFrame
;
1888 std::optional
<SwBorderAttrAccess
> oAttrAccess
;
1889 if (pFrame
&& (!_pAttrs
|| pFrame
!= &m_rThis
))
1891 oAttrAccess
.emplace(SwFrame::GetCache(), pFrame
);
1892 _pAttrs
= oAttrAccess
->Get();
1897 nAdditionalLowerSpace
+= _pAttrs
->GetULSpace().GetLower();
1899 if (rIDSA
.get(DocumentSettingId::ADD_PARA_LINE_SPACING_TO_TABLE_CELLS
))
1901 nAdditionalLowerSpace
+= _pAttrs
->CalcLineSpacing();
1906 return nAdditionalLowerSpace
;
1909 /// Moves the Frame forward if it seems necessary regarding the current conditions and attributes.
1910 bool SwFlowFrame::CheckMoveFwd( bool& rbMakePage
, bool bKeep
, bool bIgnoreMyOwnKeepValue
)
1912 const SwFrame
* pNxt
= m_rThis
.GetIndNext();
1914 if ( bKeep
&& //!bMovedBwd &&
1915 ( !pNxt
|| ( pNxt
->IsTextFrame() && static_cast<const SwTextFrame
*>(pNxt
)->IsEmptyMaster() ) ) &&
1916 ( nullptr != (pNxt
= m_rThis
.FindNext()) ) && IsKeepFwdMoveAllowed(bIgnoreMyOwnKeepValue
) )
1918 if( pNxt
->IsSctFrame() )
1919 { // Don't get fooled by empty SectionFrames
1920 const SwFrame
* pTmp
= nullptr;
1921 while( pNxt
&& pNxt
->IsSctFrame() &&
1922 ( !static_cast<const SwSectionFrame
*>(pNxt
)->GetSection() ||
1923 nullptr == ( pTmp
= static_cast<const SwSectionFrame
*>(pNxt
)->ContainsAny() ) ) )
1925 pNxt
= pNxt
->FindNext();
1929 pNxt
= pTmp
; // the content of the next notempty sectionfrm
1931 if( pNxt
&& pNxt
->isFrameAreaPositionValid() )
1934 const SwSectionFrame
*pSct
= m_rThis
.FindSctFrame();
1935 if( pSct
&& !pSct
->isFrameAreaSizeValid() )
1937 const SwSectionFrame
* pNxtSct
= pNxt
->FindSctFrame();
1938 if( pNxtSct
&& pSct
->IsAnFollow( pNxtSct
) )
1945 //Keep together with the following frame
1946 MoveFwd( rbMakePage
, false );
1952 bool bMovedFwd
= false;
1954 if ( m_rThis
.GetIndPrev() )
1956 if ( IsPrevObjMove() ) // Should we care about objects of the Prev?
1959 if ( !MoveFwd( rbMakePage
, false ) )
1964 if ( IsPageBreak( false ) )
1966 while ( MoveFwd( rbMakePage
, true ) )
1971 else if ( IsColBreak ( false ) )
1973 const SwPageFrame
*pPage
= m_rThis
.FindPageFrame();
1974 SwFrame
*pCol
= m_rThis
.FindColFrame();
1976 { MoveFwd( rbMakePage
, false );
1977 SwFrame
*pTmp
= m_rThis
.FindColFrame();
1985 } while ( IsColBreak( false ) );
1986 if ( pPage
!= m_rThis
.FindPageFrame() )
1994 bool SwFlowFrame::ForbiddenForFootnoteCntFwd() const
1996 return m_rThis
.IsTabFrame() || m_rThis
.IsInTab();
1999 /// Return value guarantees that a new page was not created,
2000 /// although false does not NECESSARILY indicate that a new page was created.
2001 /// Either false or true(MoveFootnoteCntFwd) can be returned if no changes were made
2002 bool SwFlowFrame::MoveFwd( bool bMakePage
, bool bPageBreak
, bool bMoveAlways
)
2004 //!!!!MoveFootnoteCntFwd might need to be updated as well.
2005 SwFootnoteBossFrame
*pOldBoss
= m_rThis
.FindFootnoteBossFrame();
2006 if (m_rThis
.IsInFootnote())
2008 assert(!ForbiddenForFootnoteCntFwd()); // prevented by IsMoveable()
2009 if (!m_rThis
.IsContentFrame() || !pOldBoss
)
2011 SAL_WARN("sw.core", "Tables in footnotes are not truly supported");
2014 return static_cast<SwContentFrame
&>(m_rThis
).MoveFootnoteCntFwd( bMakePage
, pOldBoss
);
2017 if( !IsFwdMoveAllowed() && !bMoveAlways
)
2020 if( m_rThis
.IsInSct() )
2022 SwFootnoteBossFrame
* pBoss
= m_rThis
.FindFootnoteBossFrame();
2023 bNoFwd
= !pBoss
->IsInSct() || ( !pBoss
->Lower()->GetNext() &&
2024 !pBoss
->GetPrev() );
2027 // Allow the MoveFwd even if we do not have an IndPrev in these cases:
2028 if ( m_rThis
.IsInTab() &&
2029 ( !m_rThis
.IsTabFrame() ||
2030 m_rThis
.GetUpper()->IsInTab() ) &&
2031 nullptr != m_rThis
.GetNextCellLeaf() )
2038 // It's allowed to move PageBreaks if the Frame isn't the first
2043 const SwFrame
*pCol
= m_rThis
.FindColFrame();
2044 if ( !pCol
|| !pCol
->GetPrev() )
2049 // prevent -Werror=maybe-uninitialized under gcc 11.2.0
2050 #if defined __GNUC__ && !defined __clang__ && __GNUC__ == 13
2051 #pragma GCC diagnostic push
2052 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
2054 std::optional
<SwFrameDeleteGuard
> oDeleteGuard
;
2055 #if defined __GNUC__ && !defined __clang__ && __GNUC__ == 13
2056 #pragma GCC diagnostic pop
2059 oDeleteGuard
.emplace(pOldBoss
);
2061 bool bSamePage
= true;
2062 SwLayoutFrame
*pNewUpper
=
2063 m_rThis
.GetLeaf( bMakePage
? MAKEPAGE_INSERT
: MAKEPAGE_NONE
, true );
2067 PROTOCOL_ENTER( &m_rThis
, PROT::MoveFwd
, DbgAction::NONE
, nullptr );
2068 SwPageFrame
*pOldPage
= pOldBoss
->FindPageFrame();
2069 // We move ourself and all the direct successors before the
2070 // first ContentFrame below the new Upper.
2072 // If our NewUpper lies in a SectionFrame, we need to make sure
2073 // that it won't destroy itself in Calc.
2074 SwSectionFrame
* pSect
= pNewUpper
->FindSctFrame();
2077 // If we only switch column within our SectionFrame, we better don't
2078 // call Calc, as this would format the SectionFrame, which in turn would
2079 // call us again, etc.
2080 if( pSect
!= m_rThis
.FindSctFrame() )
2082 bool bUnlock
= !pSect
->IsColLocked();
2084 pNewUpper
->Calc(m_rThis
.getRootFrame()->GetCurrShell()->GetOut());
2089 // Do not calculate split cell frames.
2090 else if ( !pNewUpper
->IsCellFrame() || pNewUpper
->Lower() )
2091 pNewUpper
->Calc(m_rThis
.getRootFrame()->GetCurrShell()->GetOut());
2093 SwFootnoteBossFrame
*pNewBoss
= pNewUpper
->FindFootnoteBossFrame();
2094 bool bBossChg
= pNewBoss
!= pOldBoss
;
2095 pNewBoss
= pNewBoss
->FindFootnoteBossFrame( true );
2096 pOldBoss
= pOldBoss
->FindFootnoteBossFrame( true );
2097 SwPageFrame
* pNewPage
= pOldPage
;
2099 oDeleteGuard
.reset();
2101 // First, we move the footnotes.
2102 bool bFootnoteMoved
= false;
2105 // If pSect has just been created, the printing area of pSect has
2106 // been calculated based on the first content of its follow.
2107 // In this case we prefer to call a SimpleFormat for this new
2108 // section after we inserted the contents. Otherwise the section
2109 // frame will invalidate its lowers, if its printing area changes
2110 // in SwSectionFrame::Format, which can cause loops.
2111 const bool bForceSimpleFormat
= pSect
&& pSect
->HasFollow() &&
2112 !pSect
->ContainsAny();
2114 if ( pNewBoss
!= pOldBoss
)
2116 pNewPage
= pNewBoss
->FindPageFrame();
2117 bSamePage
= pNewPage
== pOldPage
;
2118 // Set deadline, so the footnotes don't think up
2120 SwRectFnSet
aRectFnSet(pOldBoss
);
2121 SwSaveFootnoteHeight
aHeight( pOldBoss
,
2122 aRectFnSet
.GetBottom(pOldBoss
->getFrameArea()) );
2123 SwContentFrame
* pStart
= m_rThis
.IsContentFrame() ?
2124 static_cast<SwContentFrame
*>(&m_rThis
) : static_cast<SwLayoutFrame
&>(m_rThis
).ContainsContent();
2125 OSL_ENSURE( pStart
|| ( m_rThis
.IsTabFrame() && !static_cast<SwTabFrame
&>(m_rThis
).Lower() ),
2126 "MoveFwd: Missing Content" );
2127 SwLayoutFrame
* pBody
= pStart
? ( pStart
->IsTextFrame() ?
2128 const_cast<SwBodyFrame
*>(static_cast<SwTextFrame
*>(pStart
)->FindBodyFrame()) : nullptr ) : nullptr;
2130 bFootnoteMoved
= pBody
->MoveLowerFootnotes( pStart
, pOldBoss
, pNewBoss
,
2133 // It's possible when dealing with SectionFrames that we have been moved
2134 // by pNewUpper->Calc(), for instance into the pNewUpper.
2135 // MoveSubTree or PasteTree respectively is not prepared to handle such a
2137 if( pNewUpper
!= m_rThis
.GetUpper() )
2140 SwSectionFrame
* pOldSct
= nullptr;
2141 if ( m_rThis
.GetUpper()->IsSctFrame() )
2143 pOldSct
= static_cast<SwSectionFrame
*>(m_rThis
.GetUpper());
2146 MoveSubTree( pNewUpper
, pNewUpper
->Lower() );
2149 if ( pOldSct
&& pOldSct
->GetSection() )
2151 // Prevent loops by setting the new height at
2152 // the section frame if footnotes have been moved.
2153 // Otherwise the call of SwLayNotify::~SwLayNotify() for
2154 // the (invalid) section frame will invalidate the first
2155 // lower of its follow, because it grows due to the removed
2157 // Note: If pOldSct has become empty during MoveSubTree, it
2158 // has already been scheduled for removal. No SimpleFormat
2160 pOldSct
->SimpleFormat();
2164 if ( bForceSimpleFormat
)
2166 pSect
->SimpleFormat();
2169 if ( bFootnoteMoved
&& !bSamePage
)
2171 pOldPage
->UpdateFootnoteNum();
2172 pNewPage
->UpdateFootnoteNum();
2177 m_rThis
.Prepare( PrepareHint::BossChanged
, nullptr, false );
2180 SwViewShell
*pSh
= m_rThis
.getRootFrame()->GetCurrShell();
2181 if ( pSh
&& !pSh
->Imp()->IsUpdateExpFields() )
2182 pSh
->GetDoc()->getIDocumentFieldsAccess().SetNewFieldLst(true); // Will be done by CalcLayout() later on!
2184 pNewPage
->InvalidateSpelling();
2185 pNewPage
->InvalidateSmartTags();
2186 pNewPage
->InvalidateAutoCompleteWords();
2187 pNewPage
->InvalidateWordCount();
2191 // No <CheckPageDesc(..)> in online layout
2192 const SwViewShell
*pSh
= m_rThis
.getRootFrame()->GetCurrShell();
2194 if ( !( pSh
&& pSh
->GetViewOptions()->getBrowseMode() ) )
2197 // check page description not only in situation with sections.
2199 ((!IsFollow() && m_rThis
.GetPageDescItem().GetPageDesc()) ||
2200 pOldPage
->GetPageDesc()->GetFollow() != pNewPage
->GetPageDesc() ) )
2202 SwFrame::CheckPageDescs( pNewPage
, false );
2209 /** Return value tells whether any changes have been made.
2210 * If true, the frame has moved backwards to an earlier column/section/frame/page etc.
2212 * @note This should be called by derived classes.
2213 * @note The actual moving must be implemented in the subclasses via Cut()/Paste().
2215 bool SwFlowFrame::MoveBwd( bool &rbReformat
)
2217 SwFlowFrame::SetMoveBwdJump( false );
2219 SwFootnoteFrame
* pFootnote
= m_rThis
.FindFootnoteFrame();
2220 if ( pFootnote
&& pFootnote
->IsBackMoveLocked() )
2223 // Text frames, which are directly inside
2224 // tables aren't allowed to move backward.
2225 if ( m_rThis
.IsTextFrame() && m_rThis
.IsInTab() )
2227 const SwLayoutFrame
* pUpperFrame
= m_rThis
.GetUpper();
2228 while ( pUpperFrame
)
2230 if ( pUpperFrame
->IsTabFrame() || pUpperFrame
->IsRowFrame() )
2234 // If the text frame is a follow-section-in-table, that can move
2235 // backward as well.
2236 bool bIsFollowSection
= pUpperFrame
->IsSctFrame() && static_cast<const SwSectionFrame
*>(pUpperFrame
)->GetPrecede();
2238 // If the text frame is a follow-in-table, that can move
2239 // backward as well.
2240 bool bIsFollow
= const_cast<SwLayoutFrame
*>(pUpperFrame
)->GetPrevCellLeaf();
2242 if ( ( pUpperFrame
->IsColumnFrame() && pUpperFrame
->IsInSct() ) || bIsFollowSection
|| bIsFollow
)
2246 pUpperFrame
= pUpperFrame
->GetUpper();
2250 SwFootnoteBossFrame
* pOldBoss
= m_rThis
.FindFootnoteBossFrame();
2254 SwPageFrame
* const pOldPage
= pOldBoss
->FindPageFrame();
2255 SwLayoutFrame
*pNewUpper
= nullptr;
2256 bool bCheckPageDescs
= false;
2257 bool bCheckPageDescOfNextPage
= false;
2261 // If the footnote already sits on the same page/column as the reference,
2262 // we can't flow back. The breaks don't need to be checked for footnotes.
2264 // i#37084 FindLastContent does not necessarily
2265 // have to have a result != 0
2266 SwFrame
* pRef
= nullptr;
2267 const bool bEndnote
= pFootnote
->GetAttr()->GetFootnote().IsEndNote();
2268 const IDocumentSettingAccess
& rSettings
2269 = pFootnote
->GetAttrSet()->GetDoc()->getIDocumentSettingAccess();
2270 if( bEndnote
&& pFootnote
->IsInSct() )
2272 SwSectionFrame
* pSect
= pFootnote
->FindSctFrame();
2273 if( pSect
->IsEndnAtEnd() )
2274 // Endnotes at the end of the section.
2275 pRef
= pSect
->FindLastContent( SwFindMode::LastCnt
);
2277 else if (bEndnote
&& rSettings
.get(DocumentSettingId::CONTINUOUS_ENDNOTES
))
2279 // Endnotes at the end of the document.
2280 SwPageFrame
* pPage
= m_rThis
.getRootFrame()->GetLastPage();
2281 pRef
= pPage
->FindLastBodyContent();
2284 // Endnotes on a separate page.
2285 pRef
= pFootnote
->GetRef();
2287 OSL_ENSURE( pRef
, "MoveBwd: Endnote for an empty section?" );
2290 pOldBoss
= pOldBoss
->FindFootnoteBossFrame( true );
2291 SwFootnoteBossFrame
*pRefBoss
= pRef
->FindFootnoteBossFrame( !bEndnote
);
2292 if ( pOldBoss
!= pRefBoss
&&
2295 pRefBoss
->IsBefore( pOldBoss
) )
2297 pNewUpper
= m_rThis
.GetLeaf( MAKEPAGE_FTN
, false );
2299 else if ( IsPageBreak( true ) ) // Do we have to respect a PageBreak?
2301 // If the previous page doesn't have a Frame in the body,
2302 // flowing back makes sense despite the PageBreak (otherwise,
2303 // we'd get an empty page).
2304 // Of course we need to overlook empty pages!
2305 const SwFrame
*pFlow
= &m_rThis
;
2308 pFlow
= pFlow
->FindPrev();
2310 ( pFlow
->FindPageFrame() == pOldPage
||
2311 !pFlow
->IsInDocBody() ) );
2314 tools::Long nDiff
= pOldPage
->GetPhyPageNum() - pFlow
->GetPhyPageNum();
2317 if ( static_cast<SwPageFrame
*>(pOldPage
->GetPrev())->IsEmptyPage() )
2321 pNewUpper
= m_rThis
.GetLeaf( MAKEPAGE_NONE
, false );
2323 // Now <pNewUpper> is a previous layout frame, which contains
2324 // content. But the new upper layout frame has to be the next one.
2325 // Thus, hack for issue i14206 no longer needed, but fix for issue 114442
2326 // Correct fix for i53139
2327 // Check for wrong page description before using next new upper.
2328 // i#66051 - further correction of fix for i53139
2329 // Check for correct type of new next upper layout frame
2330 // Another correction of fix for i53139
2331 // Assumption, that in all cases <pNewUpper> is a previous
2332 // layout frame, which contains content, is wrong.
2333 // Another correction of fix for i53139
2334 // Beside type check, check also, if proposed new next upper
2335 // frame is inside the same frame types.
2336 // i#73194 - and yet another correction
2337 // of fix for i53139:
2338 // Assure that the new next upper layout frame doesn't
2339 // equal the current one.
2340 // E.g.: content is on page 3, on page 2 is only a 'ghost'
2341 // section and on page 1 is normal content. Method <FindPrev(..)>
2342 // will find the last content of page 1, but <GetLeaf(..)>
2343 // returns new upper on page 2.
2344 if (pNewUpper
&& pNewUpper
->Lower())
2346 SwLayoutFrame
* pNewNextUpper
= pNewUpper
->GetLeaf( MAKEPAGE_NONE
, true );
2347 if ( pNewNextUpper
&&
2348 pNewNextUpper
!= m_rThis
.GetUpper() &&
2349 pNewNextUpper
->GetType() == pNewUpper
->GetType() &&
2350 pNewNextUpper
->IsInDocBody() == pNewUpper
->IsInDocBody() &&
2351 pNewNextUpper
->IsInFootnote() == pNewUpper
->IsInFootnote() &&
2352 pNewNextUpper
->IsInTab() == pNewUpper
->IsInTab() &&
2353 pNewNextUpper
->IsInSct() == pNewUpper
->IsInSct() &&
2354 !m_rThis
.WrongPageDesc( pNewNextUpper
->FindPageFrame() ) )
2356 pNewUpper
= pNewNextUpper
;
2357 bCheckPageDescOfNextPage
= true;
2361 bCheckPageDescs
= true;
2366 else if ( IsColBreak( true ) )
2368 // If the previous column doesn't contain a ContentFrame, flowing back
2369 // makes sense despite the ColumnBreak, as otherwise we'd get
2371 if( m_rThis
.IsInSct() )
2373 pNewUpper
= m_rThis
.GetLeaf( MAKEPAGE_NONE
, false );
2374 if( pNewUpper
&& !SwFlowFrame::IsMoveBwdJump() &&
2375 ( pNewUpper
->ContainsContent() ||
2376 ( ( !pNewUpper
->IsColBodyFrame() ||
2377 !pNewUpper
->GetUpper()->GetPrev() ) &&
2378 !pNewUpper
->FindSctFrame()->GetPrev() ) ) )
2380 pNewUpper
= nullptr;
2383 // i#69409 - check <pNewUpper>
2384 // i#71065 - check <SwFlowFrame::IsMoveBwdJump()>
2385 else if ( pNewUpper
&& !SwFlowFrame::IsMoveBwdJump() )
2387 // Now <pNewUpper> is a previous layout frame, which
2388 // contains content. But the new upper layout frame
2389 // has to be the next one.
2390 // Correct fix for i53139
2391 // Check for wrong page description before using next new upper.
2392 // i#66051 - further correction of fix for i53139
2393 // Check for correct type of new next upper layout frame
2394 // Another correction of fix for i53139
2395 // Beside type check, check also, if proposed new next upper
2396 // frame is inside the same frame types.
2397 SwLayoutFrame
* pNewNextUpper
= pNewUpper
->GetLeaf( MAKEPAGE_NOSECTION
, true );
2398 if ( pNewNextUpper
&&
2399 pNewNextUpper
->GetType() == pNewUpper
->GetType() &&
2400 pNewNextUpper
->IsInDocBody() == pNewUpper
->IsInDocBody() &&
2401 pNewNextUpper
->IsInFootnote() == pNewUpper
->IsInFootnote() &&
2402 pNewNextUpper
->IsInTab() == pNewUpper
->IsInTab() &&
2403 pNewNextUpper
->IsInSct() == pNewUpper
->IsInSct() &&
2404 !m_rThis
.WrongPageDesc( pNewNextUpper
->FindPageFrame() ) )
2406 pNewUpper
= pNewNextUpper
;
2412 const SwFrame
*pCol
= m_rThis
.FindColFrame();
2418 if ( pCol
->GetPrev() )
2419 pCol
= pCol
->GetPrev();
2423 pCol
= m_rThis
.GetLeaf( MAKEPAGE_NONE
, false );
2427 // ColumnFrames now with BodyFrame
2428 SwLayoutFrame
* pColBody
= pCol
->IsColumnFrame() ?
2429 const_cast<SwLayoutFrame
*>(static_cast<const SwLayoutFrame
*>(static_cast<const SwLayoutFrame
*>(pCol
)->Lower())) :
2430 const_cast<SwLayoutFrame
*>(static_cast<const SwLayoutFrame
*>(pCol
));
2431 if ( pColBody
->ContainsContent() )
2433 bGoOn
= false; // We have content here! we accept this
2434 // only if GetLeaf() has set the MoveBwdJump.
2435 if( SwFlowFrame::IsMoveBwdJump() )
2437 pNewUpper
= pColBody
;
2439 // Now <pNewUpper> is a previous layout frame, which
2440 // contains content. But the new upper layout frame
2441 // has to be the next one.
2442 // Correct fix for i53139
2443 // Check for wrong page description before using next new upper.
2444 // i#66051 - further correction of fix for i53139
2445 // Check for correct type of new next upper layout frame
2446 // Another correction of fix for i53139
2447 // Beside type check, check also, if proposed new next upper
2448 // frame is inside the same frame types.
2450 // Check that the proposed new next upper layout
2451 // frame isn't the current one.
2452 SwLayoutFrame
* pNewNextUpper
= pNewUpper
->GetLeaf( MAKEPAGE_NONE
, true );
2453 if ( pNewNextUpper
&&
2454 pNewNextUpper
!= m_rThis
.GetUpper() &&
2455 pNewNextUpper
->GetType() == pNewUpper
->GetType() &&
2456 pNewNextUpper
->IsInDocBody() == pNewUpper
->IsInDocBody() &&
2457 pNewNextUpper
->IsInFootnote() == pNewUpper
->IsInFootnote() &&
2458 pNewNextUpper
->IsInTab() == pNewUpper
->IsInTab() &&
2459 pNewNextUpper
->IsInSct() == pNewUpper
->IsInSct() &&
2460 !m_rThis
.WrongPageDesc( pNewNextUpper
->FindPageFrame() ) )
2462 pNewUpper
= pNewNextUpper
;
2468 if( pNewUpper
) // We already had an empty column, in other
2469 bJump
= true; // words we skipped one.
2470 pNewUpper
= pColBody
; // this empty column could be considered,
2471 // but we continue searching nevertheless.
2476 SwFlowFrame::SetMoveBwdJump( true );
2479 else // No breaks - we can flow back.
2480 pNewUpper
= m_rThis
.GetLeaf( MAKEPAGE_NONE
, false );
2482 // i#27801 - no move backward of 'master' text frame,
2483 // if - due to its object positioning - it isn't allowed to be on the new page frame
2484 // i#44049 - add another condition for not moving backward
2485 // If one of its objects has restarted the layout process, moving backward
2486 // isn't sensible either.
2487 // i#47697 - refine condition made for issue i44049
2488 // - allow move backward as long as the anchored object is only temporarily
2489 // positions considering its wrapping style.
2491 m_rThis
.IsTextFrame() && !IsFollow() )
2493 sal_uInt32
nToPageNum( 0 );
2494 const bool bMoveFwdByObjPos
= SwLayouter::FrameMovedFwdByObjPos(
2495 *(pOldPage
->GetFormat()->GetDoc()),
2496 static_cast<SwTextFrame
&>(m_rThis
),
2498 if ( bMoveFwdByObjPos
&&
2499 pNewUpper
->FindPageFrame()->GetPhyPageNum() < nToPageNum
)
2501 pNewUpper
= nullptr;
2503 // i#44049 - check, if one of its anchored objects
2504 // has restarted the layout process.
2505 else if ( m_rThis
.GetDrawObjs() )
2507 for (SwAnchoredObject
* pAnchoredObj
: *m_rThis
.GetDrawObjs())
2509 // i#47697 - refine condition - see above
2510 if ( pAnchoredObj
->RestartLayoutProcess() &&
2511 !pAnchoredObj
->IsTmpConsiderWrapInfluence() )
2513 pNewUpper
= nullptr;
2520 // With Follows, it's only allowed to flow back if there's no neighbor
2521 // in the new environment (because that would be the Master).
2522 // (6677) If however we skipped empty pages, we still have to move.
2523 if ( pNewUpper
&& IsFollow() && pNewUpper
->Lower() )
2526 // neglect empty sections in proposed new upper frame
2527 bool bProposedNewUpperContainsOnlyEmptySections( true );
2529 const SwFrame
* pLower( pNewUpper
->Lower() );
2532 if ( pLower
->IsSctFrame() &&
2533 !dynamic_cast<const SwSectionFrame
&>(*pLower
).GetSection() )
2535 pLower
= pLower
->GetNext();
2540 bProposedNewUpperContainsOnlyEmptySections
= false;
2545 if ( !bProposedNewUpperContainsOnlyEmptySections
)
2547 if ( SwFlowFrame::IsMoveBwdJump() )
2549 // Don't move after the Master, but into the next empty page.
2550 SwFrame
*pFrame
= pNewUpper
->Lower();
2551 while ( pFrame
->GetNext() )
2552 pFrame
= pFrame
->GetNext();
2553 pNewUpper
= pFrame
->GetLeaf( MAKEPAGE_INSERT
, true );
2554 if( pNewUpper
== m_rThis
.GetUpper() ) // Did we end up in the same place?
2555 pNewUpper
= nullptr; // If so, moving is not needed.
2558 pNewUpper
= nullptr;
2561 if ( pNewUpper
&& !ShouldBwdMoved( pNewUpper
, rbReformat
) )
2563 if( !pNewUpper
->Lower() )
2565 if( pNewUpper
->IsFootnoteContFrame() )
2568 SwFrame::DestroyFrame(pNewUpper
);
2572 SwSectionFrame
* pSectFrame
= pNewUpper
->FindSctFrame();
2574 if ( pSectFrame
&& !pSectFrame
->IsColLocked() &&
2575 !pSectFrame
->ContainsContent() && !pSectFrame
->ContainsAny( true ) )
2577 pSectFrame
->DelEmpty( true );
2578 SwFrame::DestroyFrame(pSectFrame
);
2579 m_rThis
.setFrameAreaPositionValid(true);
2583 pNewUpper
= nullptr;
2586 // i#21478 - don't move backward, if flow frame wants to
2587 // keep with next frame and next frame is locked.
2588 // i#38232 - If next frame is a table, do *not* check,
2590 if ( pNewUpper
&& !IsFollow() &&
2591 m_rThis
.GetAttrSet()->GetKeep().GetValue() && m_rThis
.GetIndNext() )
2593 SwFrame
* pIndNext
= m_rThis
.GetIndNext();
2595 if ( !pIndNext
->IsTabFrame() )
2597 // get first content of section, while empty sections are skipped
2598 while ( pIndNext
&& pIndNext
->IsSctFrame() )
2600 if( static_cast<SwSectionFrame
*>(pIndNext
)->GetSection() )
2602 SwFrame
* pTmp
= static_cast<SwSectionFrame
*>(pIndNext
)->ContainsAny();
2609 pIndNext
= pIndNext
->GetIndNext();
2611 OSL_ENSURE( !pIndNext
|| dynamic_cast<const SwTextFrame
*>( pIndNext
) != nullptr,
2612 "<SwFlowFrame::MovedBwd(..)> - incorrect next found." );
2613 if ( pIndNext
&& pIndNext
->IsFlowFrame() &&
2614 SwFlowFrame::CastFlowFrame(pIndNext
)->IsJoinLocked() )
2616 pNewUpper
= nullptr;
2622 // layout loop control for flowing content again and again moving
2623 // backward under the same layout condition.
2624 if ( pNewUpper
&& !IsFollow() &&
2625 pNewUpper
!= m_rThis
.GetUpper() &&
2626 SwLayouter::MoveBwdSuppressed( *(pOldPage
->GetFormat()->GetDoc()),
2627 *this, *pNewUpper
) )
2629 SwLayoutFrame
* pNextNewUpper
= pNewUpper
->GetLeaf(
2630 ( !m_rThis
.IsSctFrame() && m_rThis
.IsInSct() )
2631 ? MAKEPAGE_NOSECTION
2634 // i#73194 - make code robust
2635 OSL_ENSURE( pNextNewUpper
, "<SwFlowFrame::MoveBwd(..)> - missing next new upper" );
2636 if ( pNextNewUpper
&&
2637 ( pNextNewUpper
== m_rThis
.GetUpper() ||
2638 pNextNewUpper
->GetType() != m_rThis
.GetUpper()->GetType() ) )
2640 // tdf#107398 do not leave empty footnote container around
2641 if (!pNewUpper
->Lower() && pNewUpper
->IsFootnoteContFrame())
2644 SwFrame::DestroyFrame(pNewUpper
);
2646 pNewUpper
= nullptr;
2647 OSL_FAIL( "<SwFlowFrame::MoveBwd(..)> - layout loop control for layout action <Move Backward> applied!" );
2651 OSL_ENSURE( pNewUpper
!= m_rThis
.GetUpper(),
2652 "<SwFlowFrame::MoveBwd(..)> - moving backward to the current upper frame!?" );
2655 PROTOCOL_ENTER( &m_rThis
, PROT::MoveBack
, DbgAction::NONE
, nullptr );
2656 if ( pNewUpper
->IsFootnoteContFrame() )
2658 // I may have gotten a Container
2659 SwFootnoteFrame
*pNew
= SwFootnoteContFrame::PrependChained(&m_rThis
, false);
2660 pNew
->Paste( pNewUpper
);
2663 if( pNewUpper
->IsFootnoteFrame() && m_rThis
.IsInSct() )
2665 SwSectionFrame
* pSct
= m_rThis
.FindSctFrame();
2666 // If we're in a section of a footnote, we may need to create
2667 // a SwSectionFrame in the new upper
2668 if( pSct
->IsInFootnote() )
2670 SwFrame
* pTmp
= pNewUpper
->Lower();
2673 while( pTmp
->GetNext() )
2674 pTmp
= pTmp
->GetNext();
2675 if( !pTmp
->IsSctFrame() ||
2676 static_cast<SwSectionFrame
*>(pTmp
)->GetFollow() != pSct
)
2680 pNewUpper
= static_cast<SwSectionFrame
*>(pTmp
);
2683 pSct
= new SwSectionFrame( *pSct
, true );
2684 pSct
->Paste( pNewUpper
);
2687 pSct
->SimpleFormat();
2691 bool bUnlock
= false;
2692 bool bFollow
= false;
2693 // Lock section. Otherwise, it could get destroyed if the only Content
2694 // moves e.g. from the second into the first column.
2695 SwSectionFrame
* pSect
= pNewUpper
->FindSctFrame();
2698 bUnlock
= !pSect
->IsColLocked();
2700 bFollow
= pSect
->HasFollow();
2704 auto const pOld
= m_rThis
.GetUpper();
2705 ::std::optional
<SwFrameDeleteGuard
> g
;
2706 if (m_rThis
.GetUpper()->IsCellFrame())
2708 // note: IsFollowFlowRow() is never set for new-style tables
2709 SwTabFrame
const*const pTabFrame(m_rThis
.FindTabFrame());
2710 if ( pTabFrame
->IsFollow()
2711 && static_cast<SwTabFrame
const*>(pTabFrame
->GetPrecede())->HasFollowFlowLine()
2712 && pTabFrame
->GetFirstNonHeadlineRow() == m_rThis
.GetUpper()->GetUpper())
2714 // lock follow-flow-row (similar to sections above)
2715 g
.emplace(m_rThis
.GetUpper()->GetUpper());
2716 assert(m_rThis
.GetUpper()->GetUpper()->IsDeleteForbidden());
2719 pNewUpper
->Calc(m_rThis
.getRootFrame()->GetCurrShell()->GetOut());
2720 SAL_WARN_IF(pOld
!= m_rThis
.GetUpper(), "sw.core",
2721 "MoveBwd(): pNewUpper->Calc() moved this frame?");
2726 // optimization: format section, if its size is invalidated and if it's
2727 // the new parent of moved backward frame.
2728 bool bFormatSect( false );
2732 if( pSect
->HasFollow() != bFollow
)
2734 pSect
->InvalidateSize();
2736 if ( pSect
== pNewUpper
)
2741 m_rThis
.Paste( pNewUpper
);
2744 pSect
->Calc(m_rThis
.getRootFrame()->GetCurrShell()->GetOut());
2746 SwPageFrame
*pNewPage
= m_rThis
.FindPageFrame();
2747 if( pNewPage
!= pOldPage
)
2749 m_rThis
.Prepare( PrepareHint::BossChanged
, static_cast<const void*>(pOldPage
), false );
2750 SwViewShell
*pSh
= m_rThis
.getRootFrame()->GetCurrShell();
2751 if ( pSh
&& !pSh
->Imp()->IsUpdateExpFields() )
2752 pSh
->GetDoc()->getIDocumentFieldsAccess().SetNewFieldLst(true); // Will be done by CalcLayout() later on
2754 pNewPage
->InvalidateSpelling();
2755 pNewPage
->InvalidateSmartTags();
2756 pNewPage
->InvalidateAutoCompleteWords();
2757 pNewPage
->InvalidateWordCount();
2759 // No <CheckPageDesc(..)> in online layout
2760 if ( !( pSh
&& pSh
->GetViewOptions()->getBrowseMode() ) )
2762 if ( bCheckPageDescs
&& pNewPage
->GetNext() )
2764 SwPageFrame
* pStartPage
= bCheckPageDescOfNextPage
?
2766 static_cast<SwPageFrame
*>(pNewPage
->GetNext());
2767 SwFrame::CheckPageDescs( pStartPage
, false);
2769 else if (m_rThis
.GetPageDescItem().GetPageDesc())
2771 // First page could get empty for example by disabling
2773 SwFrame::CheckPageDescs( pNewPage
, false);
2778 return pNewUpper
!= nullptr;
2781 SwFlowFrame
*SwFlowFrame::CastFlowFrame( SwFrame
*pFrame
)
2783 if ( pFrame
->IsContentFrame() )
2784 return static_cast<SwContentFrame
*>(pFrame
);
2785 if ( pFrame
->IsTabFrame() )
2786 return static_cast<SwTabFrame
*>(pFrame
);
2787 if ( pFrame
->IsSctFrame() )
2788 return static_cast<SwSectionFrame
*>(pFrame
);
2792 const SwFlowFrame
*SwFlowFrame::CastFlowFrame( const SwFrame
*pFrame
)
2794 if ( pFrame
->IsContentFrame() )
2795 return static_cast<const SwContentFrame
*>(pFrame
);
2796 if ( pFrame
->IsTabFrame() )
2797 return static_cast<const SwTabFrame
*>(pFrame
);
2798 if ( pFrame
->IsSctFrame() )
2799 return static_cast<const SwSectionFrame
*>(pFrame
);
2803 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */