LibreOffice Module sw (master) 1
flowfrm.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21#include <sal/log.hxx>
22#include <osl/diagnose.h>
23#include <svx/svdobj.hxx>
24
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>
32#include <frmatr.hxx>
33#include <frmtool.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>
42#include <txtftn.hxx>
43#include <fmtftn.hxx>
44#include <editeng/pgrditem.hxx>
45#include <paratr.hxx>
46#include <ftnfrm.hxx>
47#include <txtfrm.hxx>
48#include <notxtfrm.hxx>
49#include <tabfrm.hxx>
50#include <rowfrm.hxx>
51#include <pagedesc.hxx>
52#include <layact.hxx>
53#include <flyfrm.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>
62#include <calbck.hxx>
65#include <pam.hxx>
66#include <ndtxt.hxx>
67
68bool SwFlowFrame::s_bMoveBwdJump = false;
69
70SwFlowFrame::SwFlowFrame( SwFrame &rFrame ) :
71 m_rThis( rFrame ),
72 m_pFollow( nullptr ),
73 m_pPrecede( nullptr ),
74 m_bLockJoin( false ),
75 m_bUndersized( false ),
76 m_bFlyLock( false )
77{}
78
79SwFlowFrame::~SwFlowFrame()
80{
81 if (m_pFollow)
82 {
83 m_pFollow->m_pPrecede = nullptr;
84 }
85 if (m_pPrecede)
86 {
87 m_pPrecede->m_pFollow = nullptr;
88 }
89}
90
91void SwFlowFrame::SetFollow(SwFlowFrame *const pFollow)
92{
93 if (m_pFollow)
94 {
95 assert(this == m_pFollow->m_pPrecede);
96 m_pFollow->m_pPrecede = nullptr;
97 }
98 m_pFollow = pFollow;
99 if (m_pFollow != nullptr)
100 {
101 if (m_pFollow->m_pPrecede) // re-chaining pFollow?
102 {
103 assert(m_pFollow == m_pFollow->m_pPrecede->m_pFollow);
104 m_pFollow->m_pPrecede->m_pFollow = nullptr;
105 }
106 m_pFollow->m_pPrecede = this;
107 }
108}
109
111bool SwFlowFrame::HasLockedFollow() const
112{
113 const SwFlowFrame* pFrame = GetFollow();
114 while( pFrame )
115 {
116 if( pFrame->IsJoinLocked() )
117 return true;
118 pFrame = pFrame->GetFollow();
119 }
120 return false;
121}
122
123bool SwFlowFrame::IsKeepFwdMoveAllowed( bool bIgnoreMyOwnKeepValue )
124{
125 // If all the predecessors up to the first of the chain have
126 // the 'keep' attribute set, and the first of the chain's
127 // IsFwdMoveAllowed returns false, then we're not allowed to move.
128 SwFrame *pFrame = &m_rThis;
129 if ( !pFrame->IsInFootnote() ) {
130 if ( bIgnoreMyOwnKeepValue && pFrame->GetIndPrev() )
131 pFrame = pFrame->GetIndPrev();
132 do
133 { if ( pFrame->GetAttrSet()->GetKeep().GetValue() )
134 pFrame = pFrame->GetIndPrev();
135 else
136 return true;
137 } while ( pFrame );
138 }
139 //See IsFwdMoveAllowed()
140 bool bRet = false;
141 if ( pFrame && pFrame->GetIndPrev() )
142 bRet = true;
143 return bRet;
144}
145
146void SwFlowFrame::CheckKeep()
147{
148 // Kick off the "last" predecessor with a 'keep' attribute, because
149 // it's possible for the whole troop to move back.
150 SwFrame *pPre = m_rThis.GetIndPrev();
151 assert(pPre);
152 if( pPre->IsSctFrame() )
153 {
154 SwFrame *pLast = static_cast<SwSectionFrame*>(pPre)->FindLastContent();
155 if( pLast && pLast->FindSctFrame() == pPre )
156 pPre = pLast;
157 else
158 return;
159 }
160 SwFrame* pTmp;
161 bool bKeep;
162 while ( (bKeep = pPre->GetAttrSet()->GetKeep().GetValue()) &&
163 nullptr != ( pTmp = pPre->GetIndPrev() ) )
164 {
165 if( pTmp->IsSctFrame() )
166 {
167 SwFrame *pLast = static_cast<SwSectionFrame*>(pTmp)->FindLastContent();
168 if( pLast && pLast->FindSctFrame() == pTmp )
169 pTmp = pLast;
170 else
171 break;
172 }
173 pPre = pTmp;
174 }
175 if ( bKeep )
176 pPre->InvalidatePos();
177}
178
179namespace
180{
185bool IsNextContentFullPage(const SwFrame& rThis)
186{
187 const SwFrame* pNext = rThis.FindNextCnt();
188 if (!pNext)
189 {
190 return false;
191 }
192
193 const SwSortedObjs* pNextDrawObjs = pNext->GetDrawObjs();
194 if (!pNextDrawObjs || !pNextDrawObjs->size())
195 {
196 return false;
197 }
198
199 for (const auto& pDrawObj : *pNextDrawObjs)
200 {
201 if (!pDrawObj)
202 {
203 continue;
204 }
205
206 SwTwips nDrawObjHeight = pDrawObj->GetObjRectWithSpaces().Height();
207 const SwPageFrame* pPageFrame = pDrawObj->GetPageFrame();
208 if (!pPageFrame)
209 {
210 continue;
211 }
212
213 SwTwips nBodyHeight = pPageFrame->GetLower()->getFrameArea().Height();
214 if (nDrawObjHeight < nBodyHeight)
215 {
216 continue;
217 }
218
219 const SwFormatSurround& rSurround = pDrawObj->GetFrameFormat().GetSurround();
220 if (rSurround.GetSurround() != text::WrapTextMode_NONE)
221 {
222 continue;
223 }
224
225 // At this point the height of the draw object will use all the vertical available space,
226 // and also no wrapping will be performed, so all horizontal space will be taken as well.
227 return true;
228 }
229
230 return false;
231}
232}
233
234bool SwFlowFrame::IsKeep(SvxFormatKeepItem const& rKeep,
235 SvxFormatBreakItem const& rBreak,
236 bool const bCheckIfLastRowShouldKeep) const
237{
238 // 1. The keep attribute is ignored inside footnotes
239 // 2. For compatibility reasons, the keep attribute is
240 // ignored for frames inside table cells
241 // 3. If bBreakCheck is set to true, this function only checks
242 // if there are any break after attributes set at rAttrs
243 // or break before attributes set for the next content (or next table)
244 // 4. Keep is ignored if the next frame will require its own page.
245 bool bKeep = bCheckIfLastRowShouldKeep ||
246 ( !m_rThis.IsInFootnote() &&
247 ( !m_rThis.IsInTab() || m_rThis.IsTabFrame() ) &&
248 rKeep.GetValue() && !IsNextContentFullPage(m_rThis));
249
250 OSL_ENSURE( !bCheckIfLastRowShouldKeep || m_rThis.IsTabFrame(),
251 "IsKeep with bCheckIfLastRowShouldKeep should only be used for tabfrms" );
252
253 // Ignore keep attribute if there are break situations:
254 if ( bKeep )
255 {
256 switch (rBreak.GetBreak())
257 {
258 case SvxBreak::ColumnAfter:
259 case SvxBreak::ColumnBoth:
260 case SvxBreak::PageAfter:
261 case SvxBreak::PageBoth:
262 {
263 bKeep = false;
264 break;
265 }
266 default: break;
267 }
268 if ( bKeep )
269 {
270 SwFrame *pNxt;
271 if( nullptr != (pNxt = m_rThis.FindNextCnt()) &&
272 (!m_pFollow || pNxt != &m_pFollow->GetFrame()))
273 {
274 // The last row of a table only keeps with the next content
275 // it they are in the same section:
276 if ( bCheckIfLastRowShouldKeep )
277 {
278 const SwSection* pThisSection = nullptr;
279 const SwSection* pNextSection = nullptr;
280 const SwSectionFrame* pThisSectionFrame = m_rThis.FindSctFrame();
281 const SwSectionFrame* pNextSectionFrame = pNxt->FindSctFrame();
282
283 if ( pThisSectionFrame )
284 pThisSection = pThisSectionFrame->GetSection();
285
286 if ( pNextSectionFrame )
287 pNextSection = pNextSectionFrame->GetSection();
288
289 if ( pThisSection != pNextSection )
290 bKeep = false;
291 }
292
293 if ( bKeep )
294 {
295 SvxFormatBreakItem const* pBreak;
296 SwFormatPageDesc const* pPageDesc;
297 SwTabFrame* pTab = pNxt->IsInTab() ? pNxt->FindTabFrame() : nullptr;
298 if (pTab && (!m_rThis.IsInTab() || m_rThis.FindTabFrame() != pTab))
299 {
300 const SwAttrSet *const pSet = &pTab->GetFormat()->GetAttrSet();
301 pBreak = &pSet->GetBreak();
302 pPageDesc = &pSet->GetPageDesc();
303 }
304 else
305 {
306 pBreak = &pNxt->GetBreakItem();
307 pPageDesc = &pNxt->GetPageDescItem();
308 }
309
310 if (pPageDesc->GetPageDesc())
311 bKeep = false;
312 else switch (pBreak->GetBreak())
313 {
314 case SvxBreak::ColumnBefore:
315 case SvxBreak::ColumnBoth:
316 case SvxBreak::PageBefore:
317 case SvxBreak::PageBoth:
318 bKeep = false;
319 break;
320 default: break;
321 }
322 }
323 }
324 }
325 }
326 return bKeep;
327}
328
329sal_uInt8 SwFlowFrame::BwdMoveNecessary( const SwPageFrame *pPage, const SwRect &rRect )
330{
331 // The return value helps deciding whether we need to flow back (3),
332 // or whether we can use the good old WouldFit (0, 1), or if
333 // it's reasonable to relocate and test-format (2).
334
335 // Bit 1 in this case means that there are objects anchored to myself,
336 // bit 2 means that I have to evade other objects.
337
338 // If a SurroundObj that desires to be wrapped around overlaps with the
339 // Rect, it's required to flow (because we can't guess the relationships).
340 // However it's possible for a test formatting to happen.
341 // If the SurroundObj is a Fly and I'm a Lower, or the Fly is a Lower of
342 // mine, then it doesn't matter.
343 // If the SurroundObj is anchored in a character bound Fly, and I'm not
344 // a Lower of that character bound Fly myself, then the Fly doesn't matter.
345
346 // If the object is anchored with me, i can ignore it, because
347 // it's likely that it will follow me with the flow. A test formatting is
348 // not allowed in that case, however!
349 sal_uInt8 nRet = 0;
350 SwFlowFrame *pTmp = this;
351 do
352 { // If there are objects hanging either on me or on a follow, we can't
353 // do a test formatting, because paragraph bound objects wouldn't
354 // be properly considered, and character bound objects shouldn't
355 // be test formatted at all.
356 if( pTmp->GetFrame().GetDrawObjs() )
357 nRet = 1;
358 pTmp = pTmp->GetFollow();
359 } while ( !nRet && pTmp );
360 const SwSortedObjs *pObjs = pPage ? pPage->GetSortedObjs() : nullptr;
361 if (pObjs)
362 {
363
364 const SwSortedObjs &rObjs = *pObjs;
366 for ( size_t i = 0; nRet < 3 && i < rObjs.size(); ++i )
367 {
368
369 SwAnchoredObject* pObj = rObjs[i];
370 const SwFrameFormat& rFormat = pObj->GetFrameFormat();
371 const SwRect aRect( pObj->GetObjRect() );
372 if ( aRect.Overlaps( rRect ) &&
373 rFormat.GetSurround().GetSurround() != css::text::WrapTextMode_THROUGH )
374 {
375 if( m_rThis.IsLayoutFrame() && //Fly Lower of This?
376 Is_Lower_Of( &m_rThis, pObj->GetDrawObj() ) )
377 continue;
378 if( auto pFly = pObj->DynCastFlyFrame() )
379 {
380 if ( pFly->IsAnLower( &m_rThis ) )//This Lower of Fly?
381 continue;
382 }
383
384 const SwFrame* pAnchor = pObj->GetAnchorFrame();
385 if ( pAnchor == &m_rThis )
386 {
387 nRet |= 1;
388 continue;
389 }
390
391 // Don't do this if the object is anchored behind me in the text
392 // flow, because then I wouldn't evade it.
393 if ( ::IsFrameInSameContext( pAnchor, &m_rThis ) )
394 {
395 if ( rFormat.GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_PARA )
396 {
397 // The index of the other one can be retrieved using the anchor attribute.
398 SwNodeOffset nTmpIndex = rFormat.GetAnchor().GetAnchorNode()->GetIndex();
399 // Now we're going to check whether the current paragraph before
400 // the anchor of the displacing object sits in the text. If this
401 // is the case, we don't try to evade it.
402 // The index is being determined via SwFormatAnchor, because it's
403 // getting quite expensive otherwise.
404 if( NODE_OFFSET_MAX == nIndex )
405 {
406 const SwNode *pNode;
407 if (m_rThis.IsTextFrame())
408 pNode = static_cast<SwTextFrame&>(m_rThis).GetTextNodeFirst();
409 else if (m_rThis.IsNoTextFrame())
410 pNode = static_cast<SwNoTextFrame&>(m_rThis).GetNode();
411 else if( m_rThis.IsSctFrame() )
412 pNode = static_cast<SwSectionFormat*>(static_cast<SwSectionFrame&>(m_rThis).
413 GetFormat())->GetSectionNode();
414 else
415 {
416 assert(!m_rThis.IsContentFrame());
417 OSL_ENSURE( m_rThis.IsTabFrame(), "new FowFrame?" );
418 pNode = static_cast<SwTabFrame&>(m_rThis).GetTable()->
419 GetTabSortBoxes()[0]->GetSttNd()->FindTableNode();
420 }
421 nIndex = pNode->GetIndex();
422 }
423 if (nIndex < nTmpIndex &&
424 (!m_rThis.IsTextFrame() ||
425 !FrameContainsNode(static_cast<SwTextFrame&>(m_rThis), nTmpIndex)))
426 {
427 continue;
428 }
429 }
430 }
431 else
432 continue;
433
434 nRet |= 2;
435 }
436 }
437 }
438 return nRet;
439}
440
443SwLayoutFrame *SwFlowFrame::CutTree( SwFrame *pStart )
444{
445 // Cut the Start and all the neighbours; they are chained together and
446 // a handle to the first one is returned. Residuals are invalidated
447 // as appropriate.
448
449 SwLayoutFrame *pLay = pStart->GetUpper();
450 if ( pLay->IsInFootnote() )
451 pLay = pLay->FindFootnoteFrame();
452
453 // i#58846
454 // <pPrepare( PrepareHint::QuoVadis )> only for frames in footnotes
455 if( pStart->IsInFootnote() )
456 {
457 SwFrame* pTmp = pStart->GetIndPrev();
458 if( pTmp )
460 }
461
462 // Just cut quickly and take care that we don't cause problems with the
463 // left-behinds. The pointers of the chain being cut can point who-knows where.
464 if ( pStart == pStart->GetUpper()->Lower() )
465 pStart->GetUpper()->m_pLower = nullptr;
466 if ( pStart->GetPrev() )
467 {
468 pStart->GetPrev()->mpNext = nullptr;
469 pStart->mpPrev = nullptr;
470 }
471
472 if ( pLay->IsFootnoteFrame() )
473 {
474 if ( !pLay->Lower() && !pLay->IsColLocked() &&
475 !static_cast<SwFootnoteFrame*>(pLay)->IsBackMoveLocked() )
476 {
477 // tdf#101821 don't delete it while iterating over it
478 if (!pLay->IsDeleteForbidden())
479 {
480 pLay->Cut();
482 }
483 // else: assume there is code on the stack to clean up empty
484 // footnote frames
485 // (don't go into the else branch below, it produces a disconnected
486 // footnote with null upper that can be returned by
487 // SwFootnoteBossFrame::FindFootnote() causing null pointer deref
488 // in SwTextFrame::ConnectFootnote()
489 }
490 else
491 {
492 bool bUnlock = !static_cast<SwFootnoteFrame*>(pLay)->IsBackMoveLocked();
493 static_cast<SwFootnoteFrame*>(pLay)->LockBackMove();
494 pLay->InvalidateSize();
495 pLay->Calc(pLay->getRootFrame()->GetCurrShell()->GetOut());
496 SwContentFrame *pCnt = pLay->ContainsContent();
497 while ( pCnt && pLay->IsAnLower( pCnt ) )
498 {
499 // It's possible for the ContentFrame to be locked, and we don't want
500 // to end up in an endless page migration, so we're not even
501 // going to call Calc!
502 OSL_ENSURE( pCnt->IsTextFrame(), "The Graphic has landed." );
503 if ( static_cast<SwTextFrame*>(pCnt)->IsLocked() ||
504 static_cast<SwTextFrame*>(pCnt)->GetFollow() == pStart )
505 break;
506 pCnt->Calc(pCnt->getRootFrame()->GetCurrShell()->GetOut());
507 pCnt = pCnt->GetNextContentFrame();
508 }
509 if( bUnlock )
510 static_cast<SwFootnoteFrame*>(pLay)->UnlockBackMove();
511 }
512 pLay = nullptr;
513 }
514 return pLay;
515}
516
519bool SwFlowFrame::PasteTree( SwFrame *pStart, SwLayoutFrame *pParent, SwFrame *pSibling,
520 SwFrame *pOldParent )
521{
522 // returns true if there's a LayoutFrame in the chain.
523 bool bRet = false;
524
525 // The chain beginning with pStart is inserted before pSibling
526 // under the parent. We take care to invalidate as required.
527
528 // I'm receiving a finished chain. We need to update the pointers for
529 // the beginning of the chain, then all the uppers and finally the end.
530 // On the way there, we invalidate as required.
531 if ( pSibling )
532 {
533 pStart->mpPrev = pSibling->GetPrev();
534 if ( nullptr != pStart->mpPrev )
535 pStart->GetPrev()->mpNext = pStart;
536 else
537 pParent->m_pLower = pStart;
538 pSibling->InvalidatePos_();
539 pSibling->InvalidatePrt_();
540 }
541 else
542 {
543 pStart->mpPrev = pParent->Lower();
544 if ( nullptr == pStart->mpPrev )
545 pParent->m_pLower = pStart;
546 else
547 //i#100782
548 //If the pParent has more than 1 child nodes, former design will
549 //ignore them directly without any collection work. It will make some
550 //dangling pointers. This lead the crash...
551 //The new design will find the last child of pParent in loop way, and
552 //add the pStart after the last child.
553 // pParent->Lower()->pNext = pStart;
554 {
555 SwFrame* pTemp = pParent->m_pLower;
556 while (pTemp)
557 {
558 if (pTemp->mpNext)
559 pTemp = pTemp->mpNext;
560 else
561 {
562 pStart->mpPrev = pTemp;
563 pTemp->mpNext = pStart;
564 break;
565 }
566 }
567 }
568
569
570 // i#27145
571 if ( pParent->IsSctFrame() )
572 {
573 // We have no sibling because pParent is a section frame and
574 // has just been created to contain some content. The printing
575 // area of the frame behind pParent has to be invalidated, so
576 // that the correct distance between pParent and the next frame
577 // can be calculated.
578 pParent->InvalidateNextPrtArea();
579 }
580 }
581 SwFrame *pFloat = pStart;
582 SwFrame *pLst = nullptr;
583 SwRectFnSet aRectFnSet(pParent);
584 SwTwips nGrowVal = 0;
585 do
586 { pFloat->mpUpper = pParent;
587 pFloat->InvalidateAll_();
588 pFloat->CheckDirChange();
589
590 // I'm a friend of the TextFrame and thus am allowed to do many things.
591 // The CacheIdx idea seems to be a bit risky!
592 if ( pFloat->IsTextFrame() )
593 {
594 if ( static_cast<SwTextFrame*>(pFloat)->GetCacheIdx() != USHRT_MAX )
595 static_cast<SwTextFrame*>(pFloat)->Init(); // I'm his friend.
596 }
597 else
598 bRet = true;
599
600 nGrowVal += aRectFnSet.GetHeight(pFloat->getFrameArea());
601 if ( pFloat->GetNext() )
602 pFloat = pFloat->GetNext();
603 else
604 {
605 pLst = pFloat;
606 pFloat = nullptr;
607 }
608 } while ( pFloat );
609
610 if ( pSibling )
611 {
612 pLst->mpNext = pSibling;
613 pSibling->mpPrev = pLst;
614 if( pSibling->IsInFootnote() )
615 {
616 if( pSibling->IsSctFrame() )
617 pSibling = static_cast<SwSectionFrame*>(pSibling)->ContainsAny();
618 if( pSibling )
619 pSibling->Prepare( PrepareHint::ErgoSum );
620 }
621 }
622 if ( nGrowVal )
623 {
624 if ( pOldParent && pOldParent->IsBodyFrame() ) // For variable page height while browsing
625 pOldParent->Shrink( nGrowVal );
626 pParent->Grow( nGrowVal );
627 }
628
629 if ( pParent->IsFootnoteFrame() )
630 static_cast<SwFootnoteFrame*>(pParent)->InvalidateNxtFootnoteCnts( pParent->FindPageFrame() );
631 return bRet;
632}
633
634void SwFlowFrame::MoveSubTree( SwLayoutFrame* pParent, SwFrame* pSibling )
635{
636 OSL_ENSURE( pParent, "No parent given." );
637 OSL_ENSURE( m_rThis.GetUpper(), "Where are we coming from?" );
638
639 // Be economical with notifications if an action is running.
640 SwViewShell *pSh = m_rThis.getRootFrame()->GetCurrShell();
641 const SwViewShellImp *pImp = pSh ? pSh->Imp() : nullptr;
642 const bool bComplete = pImp && pImp->IsAction() && pImp->GetLayAction().IsComplete();
643
644 if ( !bComplete )
645 {
646 SwFrame *pPre = m_rThis.GetIndPrev();
647 if ( pPre )
648 {
649 pPre->SetRetouche();
650 // follow-up of i#26250
651 // invalidate printing area of previous frame, if it's in a table
652 if ( pPre->GetUpper()->IsInTab() )
653 {
654 pPre->InvalidatePrt_();
655 }
656 pPre->InvalidatePage();
657 }
658 else
659 {
660 m_rThis.GetUpper()->SetCompletePaint();
661 m_rThis.GetUpper()->InvalidatePage();
662 }
663 }
664
665 SwPageFrame *pOldPage = m_rThis.FindPageFrame();
666
667 SwLayoutFrame *pOldParent;
668 bool bInvaLay;
669
670 {
671 //JoinLock pParent for the lifetime of the Cut/Paste call to avoid
672 //SwSectionFrame::MergeNext removing the pParent we're trying to reparent
673 //into
674 FlowFrameJoinLockGuard aJoinGuard(pParent);
675 SwFrameDeleteGuard aDeleteGuard(pParent);
676 pOldParent = CutTree( &m_rThis );
677 bInvaLay = PasteTree( &m_rThis, pParent, pSibling, pOldParent );
678 }
679
680 // If, by cutting & pasting, an empty SectionFrame came into existence, it should
681 // disappear automatically.
682 SwSectionFrame *pSct;
683
684 if ( pOldParent && !pOldParent->Lower() &&
685 ( pOldParent->IsInSct() &&
686 !(pSct = pOldParent->FindSctFrame())->ContainsContent() &&
687 !pSct->ContainsAny( true ) ) )
688 {
689 pSct->DelEmpty( false );
690 }
691
692 // If we're in a column section, we'd rather not call Calc "from below"
693 if( !m_rThis.IsInSct() &&
694 ( !m_rThis.IsInTab() || ( m_rThis.IsTabFrame() && !m_rThis.GetUpper()->IsInTab() ) ) )
695 m_rThis.GetUpper()->Calc(m_rThis.getRootFrame()->GetCurrShell()->GetOut());
696 else if( m_rThis.GetUpper()->IsSctFrame() )
697 {
698 SwSectionFrame* pTmpSct = static_cast<SwSectionFrame*>(m_rThis.GetUpper());
699 bool bOld = pTmpSct->IsContentLocked();
700 pTmpSct->SetContentLock( true );
701 pTmpSct->Calc(m_rThis.getRootFrame()->GetCurrShell()->GetOut());
702 if( !bOld )
703 pTmpSct->SetContentLock( false );
704 }
705 SwPageFrame *pPage = m_rThis.FindPageFrame();
706
707 if ( pOldPage != pPage )
708 {
709 m_rThis.InvalidatePage( pPage );
710 if ( m_rThis.IsLayoutFrame() )
711 {
712 SwContentFrame *pCnt = static_cast<SwLayoutFrame*>(&m_rThis)->ContainsContent();
713 if ( pCnt )
714 pCnt->InvalidatePage( pPage );
715 }
716 else if ( pSh && pSh->GetDoc()->GetLineNumberInfo().IsRestartEachPage()
717 && pPage->FindFirstBodyContent() == &m_rThis )
718 {
719 m_rThis.InvalidateLineNum_();
720 }
721 }
722 if ( bInvaLay || (pSibling && pSibling->IsLayoutFrame()) )
723 m_rThis.GetUpper()->InvalidatePage( pPage );
724}
725
726bool SwFlowFrame::IsAnFollow( const SwFlowFrame *pAssumed ) const
727{
728 const SwFlowFrame *pFoll = this;
729 do
730 { if ( pAssumed == pFoll )
731 return true;
732 pFoll = pFoll->GetFollow();
733 } while ( pFoll );
734 return false;
735}
736
738{
739 OSL_ENSURE( IsFollow(), "SwContentFrame::FindMaster(): !IsFollow" );
740
741 const SwContentFrame* pPrec = static_cast<const SwContentFrame*>(SwFlowFrame::GetPrecede());
742
743 if ( pPrec && pPrec->HasFollow() && pPrec->GetFollow() == this )
744 {
745 OSL_ENSURE( pPrec->IsTextFrame(), "NoTextFrame with follow found" );
746 return const_cast<SwTextFrame*>(static_cast< const SwTextFrame* >(pPrec));
747 }
748
749 OSL_FAIL( "Follow is lost in Space." );
750 return nullptr;
751}
752
754{
755 OSL_ENSURE( IsFollow(), "SwSectionFrame::FindMaster(): !IsFollow" );
756
757 if (!m_pSection)
758 return nullptr;
759
761 SwSectionFrame* pSect = aIter.First();
762 while ( pSect )
763 {
764 if (pSect->GetFollow() == this)
765 return pSect;
766 pSect = aIter.Next();
767 }
768
769 OSL_FAIL( "Follow is lost in Space." );
770 return nullptr;
771}
772
773SwTabFrame* SwTabFrame::FindMaster( bool bFirstMaster ) const
774{
775 OSL_ENSURE( IsFollow(), "SwTabFrame::FindMaster(): !IsFollow" );
776
777 SwIterator<SwTabFrame,SwFormat> aIter( *GetTable()->GetFrameFormat() );
778 SwTabFrame* pTab = aIter.First();
779 while ( pTab )
780 {
781 if ( bFirstMaster )
782 {
783 // Optimization. This makes code like this obsolete:
784 // while ( pTab->IsFollow() )
785 // pTab = pTab->FindMaster();
786
787 if ( !pTab->IsFollow() )
788 {
789 SwTabFrame* pNxt = pTab;
790 while ( pNxt )
791 {
792 if ( pNxt->GetFollow() == this )
793 return pTab;
794 pNxt = pNxt->GetFollow();
795 }
796 }
797 }
798 else
799 {
800 if ( pTab->GetFollow() == this )
801 return pTab;
802 }
803
804 pTab = aIter.Next();
805 }
806
807 OSL_FAIL( "Follow is lost in Space." );
808 return nullptr;
809}
810
815const SwLayoutFrame *SwFrame::GetLeaf( MakePageType eMakePage, bool bFwd,
816 const SwFrame *pAnch ) const
817{
818 // No flow, no joy...
819 if ( !(IsInDocBody() || IsInFootnote() || IsInFly()) )
820 return nullptr;
821
822 const SwFrame *pLeaf = this;
823 bool bFound = false;
824
825 do
826 { pLeaf = const_cast<SwFrame*>(pLeaf)->GetLeaf( eMakePage, bFwd );
827
828 if ( pLeaf &&
829 (!IsLayoutFrame() || !static_cast<const SwLayoutFrame*>(this)->IsAnLower( pLeaf )))
830 {
831 if ( pAnch->IsInDocBody() == pLeaf->IsInDocBody() &&
832 pAnch->IsInFootnote() == pLeaf->IsInFootnote() )
833 {
834 bFound = true;
835 }
836 }
837 } while ( !bFound && pLeaf );
838
839 return static_cast<const SwLayoutFrame*>(pLeaf);
840}
841
843{
844 if ( IsInFootnote() )
845 return bFwd ? GetNextFootnoteLeaf( eMakePage ) : GetPrevFootnoteLeaf( eMakePage );
846
847 // i#53323
848 // A frame could be inside a table AND inside a section.
849 // Thus, it has to be determined, which is the first parent.
850 bool bInTab( IsInTab() );
851 bool bInSct( IsInSct() );
852 if ( bInTab && bInSct )
853 {
854 const SwFrame* pUpperFrame( GetUpper() );
855 while ( pUpperFrame )
856 {
857 if ( pUpperFrame->IsTabFrame() )
858 {
859 // the table is the first.
860 bInSct = false;
861 break;
862 }
863 else if ( pUpperFrame->IsSctFrame() )
864 {
865 // the section is the first.
866 bInTab = false;
867 break;
868 }
869
870 pUpperFrame = pUpperFrame->GetUpper();
871 }
872 }
873
874 if ( bInTab && ( !IsTabFrame() || GetUpper()->IsCellFrame() ) ) // TABLE IN TABLE
875 return bFwd ? GetNextCellLeaf() : GetPrevCellLeaf();
876
877 if ( bInSct )
878 return bFwd ? GetNextSctLeaf( eMakePage ) : GetPrevSctLeaf();
879
880 if (IsInFly() && FindFlyFrame()->IsFlySplitAllowed())
881 {
882 if (bFwd)
883 {
884 return GetNextFlyLeaf(eMakePage);
885 }
886 else
887 {
888 return GetPrevFlyLeaf();
889 }
890 }
891
892 return bFwd ? GetNextLeaf( eMakePage ) : GetPrevLeaf();
893}
894
896{
897 // Now it's getting a bit complicated:
898
899 // Maybe I'm bringing a Pagedesc myself; in that case,
900 // the pagedesc of the next page needs to correspond.
901 // Otherwise, I'll have to dig a bit deeper to see where
902 // the following Pagedesc is coming from.
903 // If the following page itself tells me that it's pagedesc
904 // is wrong, I can happily exchange it.
905 // If the page however thinks that it's pagedesc is correct,
906 // this doesn't mean it's useful to me:
907 // If the first BodyContent asks for a PageDesc or a PageBreak,
908 // I'll have to insert a new page - except the desired page is
909 // the correct one.
910 // If I inserted a new page, the problems only get started:
911 // because then it's likely for the next page to have been
912 // wrong and having been swapped because of that.
913 // This in turn means that I have a new (and correct) page,
914 // but the conditions to swap still apply.
915 // Way out of the situation: Try to preliminarily insert a
916 // new page once (empty pages are already inserted by InsertPage()
917 // if required)
918
919 //My Pagedesc doesn't count if I'm a follow!
920 const SwPageDesc *pDesc = nullptr;
921 std::optional<sal_uInt16> oTmp;
922 SwFlowFrame *pFlow = SwFlowFrame::CastFlowFrame( this );
923 if ( !pFlow || !pFlow->IsFollow() )
924 {
925 const SwFormatPageDesc &rFormatDesc = GetPageDescItem();
926 pDesc = rFormatDesc.GetPageDesc();
927 if( pDesc )
928 {
929 if( !pDesc->GetRightFormat() )
930 oTmp = 2;
931 else if( !pDesc->GetLeftFormat() )
932 oTmp = 1;
933 else if( rFormatDesc.GetNumOffset() )
934 oTmp = rFormatDesc.GetNumOffset();
935 }
936 }
937
938 // Does the Content bring a Pagedesc or do we need the
939 // virtual page number of the new layout leaf?
940 // PageDesc isn't allowed with Follows
941 const bool isRightPage = oTmp ? sw::IsRightPageByNumber(*mpRoot, *oTmp) : pNew->OnRightPage();
942 if ( !pDesc )
943 pDesc = pNew->FindPageDesc();
944
945 bool bFirst = pNew->OnFirstPage();
946
947 const SwFlowFrame *pNewFlow = pNew->FindFirstBodyContent();
948 // Did we find ourselves?
949 if( pNewFlow == pFlow )
950 pNewFlow = nullptr;
951 if ( pNewFlow && pNewFlow->GetFrame().IsInTab() )
952 pNewFlow = pNewFlow->GetFrame().FindTabFrame();
953 const SwPageDesc *pNewDesc= ( pNewFlow && !pNewFlow->IsFollow() )
954 ? pNewFlow->GetFrame().GetPageDescItem().GetPageDesc()
955 : nullptr;
956
957 SAL_INFO( "sw.pageframe", "WrongPageDesc p: " << pNew << " phys: " << pNew->GetPhyPageNum() );
958 SAL_INFO( "sw.pageframe", "WrongPageDesc " << pNew->GetPageDesc() << " " << pDesc );
959 SAL_INFO( "sw.pageframe", "WrongPageDesc right: " << isRightPage
960 << " first: " << bFirst << " " << pNew->GetFormat() << " == "
961 << (isRightPage ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)) << " "
962 << (isRightPage ? pDesc->GetLeftFormat(bFirst) : pDesc->GetRightFormat(bFirst)) );
963
964 return (pNew->GetPageDesc() != pDesc) // own desc ?
965 || (pNew->GetFormat() !=
966 (isRightPage ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)))
967 || (pNewDesc && pNewDesc == pDesc);
968}
969
972{
973 OSL_ENSURE( !IsInFootnote(), "GetNextLeaf(), don't call me for Footnote." );
974 OSL_ENSURE( !IsInSct(), "GetNextLeaf(), don't call me for Sections." );
975
976 const bool bBody = IsInDocBody(); // If I'm coming from the DocBody,
977 // I want to end up in the body.
978
979 // It doesn't make sense to insert pages, as we only want to search the
980 // chain.
981 if( IsInFly() )
982 eMakePage = MAKEPAGE_NONE;
983
984 // For tables, we just take the big leap. A simple GetNext would
985 // iterate through the first cells and, in turn, all other cells.
986 SwLayoutFrame *pLayLeaf = nullptr;
987 if ( IsTabFrame() )
988 {
989 SwFrame *const pTmp = static_cast<SwTabFrame*>(this)->FindLastContentOrTable();
990 if ( pTmp )
991 pLayLeaf = pTmp->GetUpper();
992 }
993 if ( !pLayLeaf )
994 pLayLeaf = GetNextLayoutLeaf();
995
996 SwLayoutFrame *pOldLayLeaf = nullptr; // Make sure that we don't have to
997 // start searching from top when we
998 // have a freshly created page.
999 bool bNewPg = false; // Only insert a new page once.
1000
1001 while ( true )
1002 {
1003 if ( pLayLeaf )
1004 {
1005 // There's yet another LayoutFrame. Let's see if it's ready to host
1006 // me as well.
1007 // It only needs to be of the same kind like my starting point
1008 // (DocBody or Footnote respectively)
1009 if ( pLayLeaf->FindPageFrame()->IsFootnotePage() )
1010 { // If I ended up at the end note pages, we're done.
1011 pLayLeaf = nullptr;
1012 continue;
1013 }
1014 if ( (bBody && !pLayLeaf->IsInDocBody()) || pLayLeaf->IsInTab()
1015 || pLayLeaf->IsInSct() )
1016 {
1017 // They don't want me! Try again
1018 pOldLayLeaf = pLayLeaf;
1019 pLayLeaf = pLayLeaf->GetNextLayoutLeaf();
1020 continue;
1021 }
1022
1023 // I'm wanted, therefore I'm done. However, it may still be that,
1024 // during a page break, the page type isn't the desired one. In that
1025 // case we have to insert a page of the correct type.
1026
1027 if( !IsFlowFrame() && ( eMakePage == MAKEPAGE_NONE ||
1028 eMakePage==MAKEPAGE_APPEND || eMakePage==MAKEPAGE_NOSECTION ) )
1029 return pLayLeaf;
1030
1031 SwPageFrame *pNew = pLayLeaf->FindPageFrame();
1032 const SwViewShell *pSh = getRootFrame()->GetCurrShell();
1033 // The pagedesc check does not make sense for frames in fly frames
1034 if ( pNew != FindPageFrame() && !bNewPg && !IsInFly() &&
1035 // i#46683
1036 // Do not consider page descriptions in browse mode (since
1037 // MoveBwd ignored them)
1038 !(pSh && pSh->GetViewOptions()->getBrowseMode() ) )
1039 {
1040 if( WrongPageDesc( pNew ) )
1041 {
1042 SwFootnoteContFrame *pCont = pNew->FindFootnoteCont();
1043 if( pCont )
1044 {
1045 // If the reference of the first footnote of this page
1046 // lies before the page, we'd rather not insert a new page.
1047
1048 SwFootnoteFrame *pFootnote = static_cast<SwFootnoteFrame*>(pCont->Lower());
1049 if( pFootnote && pFootnote->GetRef() )
1050 {
1051 const sal_uInt16 nRefNum = pNew->GetPhyPageNum();
1052 if( pFootnote->GetRef()->GetPhyPageNum() < nRefNum )
1053 break;
1054 }
1055 }
1056 //Gotcha! The following page is wrong, therefore we need to
1057 //insert a new one.
1058 if ( eMakePage == MAKEPAGE_INSERT )
1059 {
1060 bNewPg = true;
1061
1062 SwPageFrame *pPg = pOldLayLeaf ?
1063 pOldLayLeaf->FindPageFrame() : nullptr;
1064 if ( pPg && pPg->IsEmptyPage() )
1065 // Don't insert behind. Insert before the EmptyPage.
1066 pPg = static_cast<SwPageFrame*>(pPg->GetPrev());
1067
1068 if ( !pPg || pPg == pNew )
1069 pPg = FindPageFrame();
1070
1071 InsertPage( pPg, false );
1072 pLayLeaf = GetNextLayoutLeaf();
1073 pOldLayLeaf = nullptr;
1074 continue;
1075 }
1076 else
1077 pLayLeaf = nullptr;
1078 }
1079 }
1080 break;
1081 }
1082 else
1083 {
1084 // There's no other matching LayoutFrame, so we have to insert
1085 // a new page.
1086 if ( eMakePage == MAKEPAGE_APPEND || eMakePage == MAKEPAGE_INSERT )
1087 {
1088 InsertPage(
1089 pOldLayLeaf ? pOldLayLeaf->FindPageFrame() : FindPageFrame(),
1090 false );
1091
1092 // And again from the start.
1093 pLayLeaf = pOldLayLeaf ? pOldLayLeaf : GetNextLayoutLeaf();
1094 }
1095 else
1096 break;
1097 }
1098 }
1099 return pLayLeaf;
1100}
1101
1104{
1105 OSL_ENSURE( !IsInFootnote(), "GetPrevLeaf(), don't call me for Footnote." );
1106
1107 const bool bBody = IsInDocBody(); // If I'm coming from the DocBody,
1108 // I want to end up in the body.
1109 const bool bFly = IsInFly();
1110
1111 SwLayoutFrame *pLayLeaf = GetPrevLayoutLeaf();
1112 SwLayoutFrame *pPrevLeaf = nullptr;
1113
1114 while ( pLayLeaf )
1115 {
1116 if ( pLayLeaf->IsInTab() || // Never go into tables.
1117 pLayLeaf->IsInSct() ) // Same goes for sections!
1118 pLayLeaf = pLayLeaf->GetPrevLayoutLeaf();
1119 else if ( bBody && pLayLeaf->IsInDocBody() )
1120 {
1121 if ( pLayLeaf->Lower() )
1122 break;
1123 pPrevLeaf = pLayLeaf;
1124 pLayLeaf = pLayLeaf->GetPrevLayoutLeaf();
1125 if ( pLayLeaf )
1126 SwFlowFrame::SetMoveBwdJump( true );
1127 }
1128 else if ( bFly )
1129 break; //Contents in Flys should accept any layout leaf.
1130 else
1131 pLayLeaf = pLayLeaf->GetPrevLayoutLeaf();
1132 }
1133 return pLayLeaf ? pLayLeaf : pPrevLeaf;
1134}
1135
1136bool SwFlowFrame::IsPrevObjMove() const
1137{
1138 // true: The FlowFrame must respect the a border of the predecessor, also needs
1139 // to insert a break if required.
1140
1142 const SwViewShell *pSh = m_rThis.getRootFrame()->GetCurrShell();
1143 if( pSh && pSh->GetViewOptions()->getBrowseMode() )
1144 return false;
1145
1146 SwFrame *pPre = m_rThis.FindPrev();
1147
1148 if ( pPre && pPre->GetDrawObjs() )
1149 {
1150 OSL_ENSURE( SwFlowFrame::CastFlowFrame( pPre ), "new flowfrm?" );
1151 if( SwFlowFrame::CastFlowFrame( pPre )->IsAnFollow( this ) )
1152 return false;
1153 if (SwFlowFrame::CastFlowFrame(pPre)->IsJoinLocked())
1154 {
1156 SwBorderAttrs const& rAttrs(*baa.Get());
1157 if (SwFlowFrame::CastFlowFrame(pPre)->IsKeep(rAttrs.GetAttrSet().GetKeep(), pPre->GetBreakItem()))
1158 { // pPre is currently being formatted - maybe it moved back but
1159 // its objects still have the old page's body as
1160 // mpVertPosOrientFrame and SwContentFrame::MakeAll() is calling
1161 // pNxt->Calc() in this case so allow this frame to move back
1162 return false; // too, else pPre is forced to move forward again.
1163 }
1164 }
1165 SwLayoutFrame* pPreUp = pPre->GetUpper();
1166 // If the upper is a SectionFrame, or a column of a SectionFrame, we're
1167 // allowed to protrude out of it. However, we need to respect the
1168 // Upper of the SectionFrame.
1169 if( pPreUp->IsInSct() )
1170 {
1171 if( pPreUp->IsSctFrame() )
1172 pPreUp = pPreUp->GetUpper();
1173 else if( pPreUp->IsColBodyFrame() &&
1174 pPreUp->GetUpper()->GetUpper()->IsSctFrame() )
1175 pPreUp = pPreUp->GetUpper()->GetUpper()->GetUpper();
1176 }
1177 // i#26945 - re-factoring
1178 // use <GetVertPosOrientFrame()> to determine, if object has followed the
1179 // text flow to the next layout frame
1180 for (SwAnchoredObject* pObj : *pPre->GetDrawObjs())
1181 {
1182
1183 // Do not consider hidden objects
1184 // i#26945 - do not consider object, which
1185 // doesn't follow the text flow.
1187 pObj->GetDrawObj()->GetLayer() ) &&
1189 {
1190 const SwLayoutFrame* pVertPosOrientFrame = pObj->GetVertPosOrientFrame();
1191 if ( pVertPosOrientFrame &&
1192 pPreUp != pVertPosOrientFrame &&
1193 !pPreUp->IsAnLower( pVertPosOrientFrame ) )
1194 {
1195 return true;
1196 }
1197 }
1198 }
1199 }
1200 return false;
1201}
1202
1218bool SwFlowFrame::IsPageBreak( bool bAct ) const
1219{
1220 if ( !IsFollow() && m_rThis.IsInDocBody() &&
1221 ( !m_rThis.IsInTab() || ( m_rThis.IsTabFrame() && !m_rThis.GetUpper()->IsInTab() ) ) ) // i66968
1222 {
1223 const SwViewShell *pSh = m_rThis.getRootFrame()->GetCurrShell();
1224 if( pSh && pSh->GetViewOptions()->getBrowseMode() )
1225 return false;
1226
1227 // Determine predecessor
1228 const SwFrame *pPrev = m_rThis.FindPrev();
1229 while ( pPrev && ( !pPrev->IsInDocBody() ||
1230 ( pPrev->IsTextFrame() && static_cast<const SwTextFrame*>(pPrev)->IsHiddenNow() ) ) )
1231 pPrev = pPrev->FindPrev();
1232
1233 if ( pPrev )
1234 {
1235 OSL_ENSURE( pPrev->IsInDocBody(), "IsPageBreak: Not in DocBody?" );
1236 if ( bAct )
1237 { if ( m_rThis.FindPageFrame() == pPrev->FindPageFrame() )
1238 return false;
1239 }
1240 else
1241 { if ( m_rThis.FindPageFrame() != pPrev->FindPageFrame() )
1242 return false;
1243 }
1244
1245 //for compatibility, also break at column break if no columns exist
1246 const IDocumentSettingAccess& rIDSA = m_rThis.GetUpper()->GetFormat()->getIDocumentSettingAccess();
1247 const bool bTreatSingleColumnBreakAsPageBreak = rIDSA.get(DocumentSettingId::TREAT_SINGLE_COLUMN_BREAK_AS_PAGE_BREAK);
1248 const SvxBreak eBreak = m_rThis.GetBreakItem().GetBreak();
1249 if ( eBreak == SvxBreak::PageBefore ||
1250 eBreak == SvxBreak::PageBoth ||
1251 ( bTreatSingleColumnBreakAsPageBreak && eBreak == SvxBreak::ColumnBefore && !m_rThis.FindColFrame() ))
1252 return true;
1253 else
1254 {
1255 const SvxBreak &ePrB = pPrev->GetBreakItem().GetBreak();
1256 if ( ePrB == SvxBreak::PageAfter ||
1257 ePrB == SvxBreak::PageBoth ||
1258 m_rThis.GetPageDescItem().GetPageDesc())
1259 {
1260 return true;
1261 }
1262 }
1263 }
1264 }
1265 return false;
1266}
1267
1281bool SwFlowFrame::IsColBreak( bool bAct ) const
1282{
1283 if ( !IsFollow() && (m_rThis.IsMoveable() || bAct) )
1284 {
1285 const SwFrame *pCol = m_rThis.FindColFrame();
1286 if ( pCol )
1287 {
1288 // Determine predecessor
1289 const SwFrame *pPrev = m_rThis.FindPrev();
1290 while( pPrev && ( ( !pPrev->IsInDocBody() && !m_rThis.IsInFly() && !m_rThis.FindFooterOrHeader() ) ||
1291 ( pPrev->IsTextFrame() && static_cast<const SwTextFrame*>(pPrev)->IsHiddenNow() ) ) )
1292 pPrev = pPrev->FindPrev();
1293
1294 if ( pPrev )
1295 {
1296 if ( bAct )
1297 { if ( pCol == pPrev->FindColFrame() )
1298 return false;
1299 }
1300 else
1301 { if ( pCol != pPrev->FindColFrame() )
1302 return false;
1303 }
1304
1305 const SvxBreak eBreak = m_rThis.GetBreakItem().GetBreak();
1306 if ( eBreak == SvxBreak::ColumnBefore ||
1307 eBreak == SvxBreak::ColumnBoth )
1308 return true;
1309 else
1310 {
1311 const SvxBreak &ePrB = pPrev->GetBreakItem().GetBreak();
1312 if ( ePrB == SvxBreak::ColumnAfter ||
1313 ePrB == SvxBreak::ColumnBoth )
1314 return true;
1315 }
1316 }
1317 }
1318 }
1319 return false;
1320}
1321
1322bool SwFlowFrame::HasParaSpaceAtPages( bool bSct ) const
1323{
1324 if( m_rThis.IsInSct() )
1325 {
1326 const SwFrame* pTmp = m_rThis.GetUpper();
1327 while( pTmp )
1328 {
1329 if( pTmp->IsCellFrame() || pTmp->IsFlyFrame() ||
1330 pTmp->IsFooterFrame() || pTmp->IsHeaderFrame() ||
1331 ( pTmp->IsFootnoteFrame() && !static_cast<const SwFootnoteFrame*>(pTmp)->GetMaster() ) )
1332 return true;
1333 if( pTmp->IsPageFrame() )
1334 return !pTmp->GetPrev() || IsPageBreak(true);
1335 if( pTmp->IsColumnFrame() && pTmp->GetPrev() )
1336 return IsColBreak( true );
1337 if( pTmp->IsSctFrame() && ( !bSct || pTmp->GetPrev() ) )
1338 return false;
1339 pTmp = pTmp->GetUpper();
1340 }
1341 OSL_FAIL( "HasParaSpaceAtPages: Where's my page?" );
1342 return false;
1343 }
1344 if( !m_rThis.IsInDocBody() || ( m_rThis.IsInTab() && !m_rThis.IsTabFrame()) ||
1345 IsPageBreak( true ) || ( m_rThis.FindColFrame() && IsColBreak( true ) ) )
1346 return true;
1347 const SwFrame* pTmp = m_rThis.FindColFrame();
1348 if( pTmp )
1349 {
1350 if( pTmp->GetPrev() )
1351 return false;
1352 }
1353 else
1354 pTmp = &m_rThis;
1355 pTmp = pTmp->FindPageFrame();
1356 return pTmp && !pTmp->GetPrev();
1357}
1358
1364const SwFrame* SwFlowFrame::GetPrevFrameForUpperSpaceCalc_( const SwFrame* _pProposedPrevFrame ) const
1365{
1366 const SwFrame* pPrevFrame = _pProposedPrevFrame
1367 ? _pProposedPrevFrame
1368 : m_rThis.GetPrev();
1369
1370 // Skip hidden paragraphs and empty sections
1371 while ( pPrevFrame &&
1372 ( ( pPrevFrame->IsTextFrame() &&
1373 static_cast<const SwTextFrame*>(pPrevFrame)->IsHiddenNow() ) ||
1374 ( pPrevFrame->IsSctFrame() &&
1375 !static_cast<const SwSectionFrame*>(pPrevFrame)->GetSection() ) ) )
1376 {
1377 pPrevFrame = pPrevFrame->GetPrev();
1378 }
1379
1380 // Special case: no direct previous frame is found but frame is in footnote
1381 // Search for a previous frame in previous footnote,
1382 // if frame isn't in a section, which is also in the footnote
1383 if ( !pPrevFrame && m_rThis.IsInFootnote() &&
1384 ( m_rThis.IsSctFrame() ||
1385 !m_rThis.IsInSct() || !m_rThis.FindSctFrame()->IsInFootnote() ) )
1386 {
1387 const SwFootnoteFrame* pPrevFootnoteFrame =
1388 static_cast<const SwFootnoteFrame*>(m_rThis.FindFootnoteFrame()->GetPrev());
1389 if ( pPrevFootnoteFrame )
1390 {
1391 pPrevFrame = pPrevFootnoteFrame->GetLastLower();
1392
1393 // Skip hidden paragraphs and empty sections
1394 while ( pPrevFrame &&
1395 ( ( pPrevFrame->IsTextFrame() &&
1396 static_cast<const SwTextFrame*>(pPrevFrame)->IsHiddenNow() ) ||
1397 ( pPrevFrame->IsSctFrame() &&
1398 !static_cast<const SwSectionFrame*>(pPrevFrame)->GetSection() ) ) )
1399 {
1400 pPrevFrame = pPrevFrame->GetPrev();
1401 }
1402 }
1403 }
1404 // Special case: found previous frame is a section
1405 // Search for the last content in the section
1406 if( pPrevFrame && pPrevFrame->IsSctFrame() )
1407 {
1408 const SwSectionFrame* pPrevSectFrame =
1409 static_cast<const SwSectionFrame*>(pPrevFrame);
1410 pPrevFrame = pPrevSectFrame->FindLastContent();
1411 // If the last content is in a table _inside_ the section,
1412 // take the table herself.
1413 // Correction: Check directly, if table is inside table, instead of indirectly
1414 // by checking, if section isn't inside a table
1415 if ( pPrevFrame && pPrevFrame->IsInTab() )
1416 {
1417 const SwTabFrame* pTableFrame = pPrevFrame->FindTabFrame();
1418 if ( pPrevSectFrame->IsAnLower( pTableFrame ) )
1419 {
1420 pPrevFrame = pTableFrame;
1421 }
1422 }
1423 // Correction: skip hidden text frames
1424 while ( pPrevFrame &&
1425 pPrevFrame->IsTextFrame() &&
1426 static_cast<const SwTextFrame*>(pPrevFrame)->IsHiddenNow() )
1427 {
1428 pPrevFrame = pPrevFrame->GetPrev();
1429 }
1430 }
1431
1432 return pPrevFrame;
1433}
1434
1436static bool lcl_IdenticalStyles(const SwFrame* pPrevFrame, const SwFrame* pFrame)
1437{
1438 SwTextFormatColl *pPrevFormatColl = nullptr;
1439 if (pPrevFrame && pPrevFrame->IsTextFrame())
1440 {
1441 const SwTextFrame *pTextFrame = static_cast< const SwTextFrame * >( pPrevFrame );
1442 pPrevFormatColl = dynamic_cast<SwTextFormatColl*>(
1443 pTextFrame->GetTextNodeForParaProps()->GetFormatColl());
1444 }
1445
1446 bool bIdenticalStyles = false;
1447 if (pFrame && pFrame->IsTextFrame())
1448 {
1449 const SwTextFrame *pTextFrame = static_cast< const SwTextFrame * >( pFrame );
1450 SwTextFormatColl *const pFormatColl = dynamic_cast<SwTextFormatColl*>(
1451 pTextFrame->GetTextNodeForParaProps()->GetFormatColl());
1452 bIdenticalStyles = pPrevFormatColl == pFormatColl;
1453 }
1454 return bIdenticalStyles;
1455}
1456
1457static bool lcl_getContextualSpacing(const SwFrame* pPrevFrame)
1458{
1459 bool bRet;
1460 SwBorderAttrAccess aAccess(SwFrame::GetCache(), pPrevFrame);
1461 const SwBorderAttrs *pAttrs = aAccess.Get();
1462
1463 bRet = pAttrs->GetULSpace().GetContext();
1464
1465 return bRet;
1466}
1467
1468
1469SwTwips SwFlowFrame::CalcUpperSpace( const SwBorderAttrs *pAttrs,
1470 const SwFrame* pPr,
1471 const bool _bConsiderGrid ) const
1472{
1473 const SwFrame* pPrevFrame = GetPrevFrameForUpperSpaceCalc_( pPr );
1474
1475 std::optional<SwBorderAttrAccess> oAccess;
1476 SwFrame* pOwn;
1477 if( !pAttrs )
1478 {
1479 if( m_rThis.IsSctFrame() )
1480 {
1481 SwSectionFrame* pFoll = &static_cast<SwSectionFrame&>(m_rThis);
1482 do
1483 pOwn = pFoll->ContainsAny();
1484 while( !pOwn && nullptr != ( pFoll = pFoll->GetFollow() ) );
1485 if( !pOwn )
1486 return 0;
1487 }
1488 else
1489 pOwn = &m_rThis;
1490 oAccess.emplace(SwFrame::GetCache(), pOwn);
1491 pAttrs = oAccess->Get();
1492 }
1493 else
1494 {
1495 pOwn = &m_rThis;
1496 }
1497 SwTwips nUpper = 0;
1498
1499 {
1500 const IDocumentSettingAccess& rIDSA = m_rThis.GetUpper()->GetFormat()->getIDocumentSettingAccess();
1501 if( pPrevFrame )
1502 {
1503 const bool bUseFormerLineSpacing = rIDSA.get(DocumentSettingId::OLD_LINE_SPACING);
1504 const bool bContextualSpacingThis = pAttrs->GetULSpace().GetContext();
1505 const bool bContextualSpacingPrev = lcl_getContextualSpacing(pPrevFrame);
1506 bool bIdenticalStyles = lcl_IdenticalStyles(pPrevFrame, &m_rThis);
1507
1508 const bool bContextualSpacing = bContextualSpacingThis
1509 && bContextualSpacingPrev
1510 && bIdenticalStyles;
1511
1512 // tdf#125893 always ignore own top margin setting of the actual paragraph
1513 // with contextual spacing, if the previous paragraph is identical
1514 const bool bHalfContextualSpacing = !bContextualSpacing
1515 && bContextualSpacingThis
1516 && !bContextualSpacingPrev
1517 && bIdenticalStyles;
1518
1519 // tdf#134463 always ignore own bottom margin setting of the previous paragraph
1520 // with contextual spacing, if the actual paragraph is identical
1521 const bool bHalfContextualSpacingPrev = !bContextualSpacing
1522 && !bContextualSpacingThis
1523 && bContextualSpacingPrev
1524 && bIdenticalStyles;
1525
1526 // i#11860 - use new method to determine needed spacing
1527 // values of found previous frame and use these values.
1528 SwTwips nPrevLowerSpace = 0;
1529 SwTwips nPrevLineSpacing = 0;
1530 // i#102458
1531 bool bPrevLineSpacingProportional = false;
1532 GetSpacingValuesOfFrame( (*pPrevFrame),
1533 nPrevLowerSpace, nPrevLineSpacing,
1534 bPrevLineSpacingProportional,
1535 bIdenticalStyles);
1537 {
1538 // FIXME: apply bHalfContextualSpacing for better portability?
1539 nUpper = bContextualSpacing ? 0 : nPrevLowerSpace + pAttrs->GetULSpace().GetUpper();
1540 SwTwips nAdd = nPrevLineSpacing;
1541 // i#11859 - consideration of the line spacing
1542 // for the upper spacing of a text frame
1543 if ( bUseFormerLineSpacing )
1544 {
1545 // former consideration
1546 if ( pOwn->IsTextFrame() )
1547 {
1548 nAdd = std::max( nAdd, SwTwips(static_cast<SwTextFrame*>(pOwn)->GetLineSpace()) );
1549 }
1550 nUpper += nAdd;
1551 }
1552 else
1553 {
1554 // new consideration:
1555 // Only the proportional line spacing of the previous
1556 // text frame is considered for the upper spacing and
1557 // the line spacing values are add up instead of
1558 // building its maximum.
1559 if ( pOwn->IsTextFrame() )
1560 {
1561 // i#102458
1562 // Correction:
1563 // A proportional line spacing of the previous text frame
1564 // is added up to an own leading line spacing.
1565 // Otherwise, the maximum of the leading line spacing
1566 // of the previous text frame and the own leading line
1567 // spacing is built.
1568 if ( bPrevLineSpacingProportional )
1569 {
1570 nAdd += static_cast<SwTextFrame*>(pOwn)->GetLineSpace( true );
1571 }
1572 else
1573 {
1574 nAdd = std::max( nAdd, SwTwips(static_cast<SwTextFrame*>(pOwn)->GetLineSpace( true )) );
1575 }
1576 }
1577 nUpper += nAdd;
1578 }
1579 }
1580 else
1581 {
1582 nUpper = bContextualSpacing ? 0 : std::max(
1583 bHalfContextualSpacingPrev ? 0 : static_cast<tools::Long>(nPrevLowerSpace),
1584 bHalfContextualSpacing ? 0 : static_cast<tools::Long>(pAttrs->GetULSpace().GetUpper()) );
1585
1586 // i#11859 - consideration of the line spacing
1587 // for the upper spacing of a text frame
1588 if ( bUseFormerLineSpacing )
1589 {
1590 // former consideration
1591 if ( pOwn->IsTextFrame() )
1592 nUpper = std::max( nUpper, SwTwips(static_cast<SwTextFrame*>(pOwn)->GetLineSpace()) );
1593 if ( nPrevLineSpacing != 0 )
1594 {
1595 nUpper = std::max( nUpper, nPrevLineSpacing );
1596 }
1597 }
1598 else
1599 {
1600 // new consideration:
1601 // Only the proportional line spacing of the previous
1602 // text frame is considered for the upper spacing and
1603 // the line spacing values are add up and added to
1604 // the paragraph spacing instead of building the
1605 // maximum of the line spacings and the paragraph spacing.
1606 SwTwips nAdd = nPrevLineSpacing;
1607 if ( pOwn->IsTextFrame() )
1608 {
1609 // i#102458
1610 // Correction:
1611 // A proportional line spacing of the previous text frame
1612 // is added up to an own leading line spacing.
1613 // Otherwise, the maximum of the leading line spacing
1614 // of the previous text frame and the own leading line
1615 // spacing is built.
1616 if ( bPrevLineSpacingProportional )
1617 {
1618 nAdd += static_cast<SwTextFrame*>(pOwn)->GetLineSpace( true );
1619 }
1620 else
1621 {
1622 nAdd = std::max( nAdd, SwTwips(static_cast<SwTextFrame*>(pOwn)->GetLineSpace( true )) );
1623 }
1624 }
1625 nUpper += nAdd;
1626 }
1627 }
1628 }
1630 CastFlowFrame( pOwn )->HasParaSpaceAtPages( m_rThis.IsSctFrame() ) )
1631 {
1632 nUpper = pAttrs->GetULSpace().GetUpper();
1633 }
1634 }
1635
1636 // i#25029 - pass previous frame <pPrevFrame>
1637 // to method <GetTopLine(..)>, if parameter <pPr> is set.
1638 // Note: parameter <pPr> is set, if method is called from <SwTextFrame::WouldFit(..)>
1639 nUpper += pAttrs->GetTopLine( m_rThis, (pPr ? pPrevFrame : nullptr) );
1640
1641 // i#11860 - consider value of new parameter <_bConsiderGrid>
1642 // and use new method <GetUpperSpaceAmountConsideredForPageGrid(..)>
1643
1644 //consider grid in square page mode
1645 if ( _bConsiderGrid && m_rThis.GetUpper()->GetFormat()->GetDoc()->IsSquaredPageMode() )
1646 {
1647 nUpper += GetUpperSpaceAmountConsideredForPageGrid_( nUpper );
1648 }
1649 return nUpper;
1650}
1651
1658SwTwips SwFlowFrame::GetUpperSpaceAmountConsideredForPageGrid_(
1659 const SwTwips _nUpperSpaceWithoutGrid ) const
1660{
1661 SwTwips nUpperSpaceAmountConsideredForPageGrid = 0;
1662
1663 if ( m_rThis.IsInDocBody() && m_rThis.GetAttrSet()->GetParaGrid().GetValue() )
1664 {
1665 const SwPageFrame* pPageFrame = m_rThis.FindPageFrame();
1666 SwTextGridItem const*const pGrid(GetGridItem(pPageFrame));
1667 if( pGrid )
1668 {
1669 const SwFrame* pBodyFrame = pPageFrame->FindBodyCont();
1670 if ( pBodyFrame )
1671 {
1672 const tools::Long nGridLineHeight =
1673 pGrid->GetBaseHeight() + pGrid->GetRubyHeight();
1674
1675 SwRectFnSet aRectFnSet(&m_rThis);
1676 const SwTwips nBodyPrtTop = aRectFnSet.GetPrtTop(*pBodyFrame);
1677 const SwTwips nProposedPrtTop =
1678 aRectFnSet.YInc( aRectFnSet.GetTop(m_rThis.getFrameArea()),
1679 _nUpperSpaceWithoutGrid );
1680
1681 const SwTwips nSpaceAbovePrtTop =
1682 aRectFnSet.YDiff( nProposedPrtTop, nBodyPrtTop );
1683 const SwTwips nSpaceOfCompleteLinesAbove =
1684 nGridLineHeight * ( nSpaceAbovePrtTop / nGridLineHeight );
1685 SwTwips nNewPrtTop =
1686 aRectFnSet.YInc( nBodyPrtTop, nSpaceOfCompleteLinesAbove );
1687 if ( aRectFnSet.YDiff( nProposedPrtTop, nNewPrtTop ) > 0 )
1688 {
1689 nNewPrtTop = aRectFnSet.YInc( nNewPrtTop, nGridLineHeight );
1690 }
1691
1692 const SwTwips nNewUpperSpace =
1693 aRectFnSet.YDiff( nNewPrtTop,
1694 aRectFnSet.GetTop(m_rThis.getFrameArea()) );
1695
1696 nUpperSpaceAmountConsideredForPageGrid =
1697 nNewUpperSpace - _nUpperSpaceWithoutGrid;
1698
1699 OSL_ENSURE( nUpperSpaceAmountConsideredForPageGrid >= 0,
1700 "<SwFlowFrame::GetUpperSpaceAmountConsideredForPageGrid(..)> - negative space considered for page grid!" );
1701 }
1702 }
1703 }
1704 return nUpperSpaceAmountConsideredForPageGrid;
1705}
1706
1712SwTwips SwFlowFrame::GetUpperSpaceAmountConsideredForPrevFrame() const
1713{
1714 SwTwips nUpperSpaceAmountOfPrevFrame = 0;
1715
1716 const SwFrame* pPrevFrame = GetPrevFrameForUpperSpaceCalc_();
1717 if ( pPrevFrame )
1718 {
1719 SwTwips nPrevLowerSpace = 0;
1720 SwTwips nPrevLineSpacing = 0;
1721 // i#102458
1722 bool bDummy = false;
1723 GetSpacingValuesOfFrame( (*pPrevFrame), nPrevLowerSpace, nPrevLineSpacing, bDummy, lcl_IdenticalStyles(pPrevFrame, &m_rThis));
1724 if ( nPrevLowerSpace > 0 || nPrevLineSpacing > 0 )
1725 {
1726 const IDocumentSettingAccess& rIDSA = m_rThis.GetUpper()->GetFormat()->getIDocumentSettingAccess();
1729 {
1730 nUpperSpaceAmountOfPrevFrame = nPrevLowerSpace + nPrevLineSpacing;
1731 }
1732 else
1733 {
1734 nUpperSpaceAmountOfPrevFrame = std::max( nPrevLowerSpace, nPrevLineSpacing );
1735 }
1736 }
1737 }
1738
1739 return nUpperSpaceAmountOfPrevFrame;
1740}
1741
1748SwTwips SwFlowFrame::GetUpperSpaceAmountConsideredForPrevFrameAndPageGrid() const
1749{
1750 SwTwips nUpperSpaceAmountConsideredForPrevFrameAndPageGrid = 0;
1751
1752 if (!m_rThis.GetUpper() || !m_rThis.GetUpper()->GetFormat())
1753 {
1754 return nUpperSpaceAmountConsideredForPrevFrameAndPageGrid;
1755 }
1756
1757 if ( !m_rThis.GetUpper()->GetFormat()->getIDocumentSettingAccess().get(DocumentSettingId::USE_FORMER_OBJECT_POS) )
1758 {
1759 nUpperSpaceAmountConsideredForPrevFrameAndPageGrid =
1760 GetUpperSpaceAmountConsideredForPrevFrame() +
1761 ( m_rThis.GetUpper()->GetFormat()->GetDoc()->IsSquaredPageMode()
1762 ? GetUpperSpaceAmountConsideredForPageGrid_( CalcUpperSpace( nullptr, nullptr, false ) )
1763 : 0 );
1764 }
1765
1766 return nUpperSpaceAmountConsideredForPrevFrameAndPageGrid;
1767}
1768
1769// Calculation of lower space
1770
1771SwTwips SwFlowFrame::CalcLowerSpace( const SwBorderAttrs* _pAttrs ) const
1772{
1773 SwTwips nLowerSpace = 0;
1774
1775 std::optional<SwBorderAttrAccess> oAttrAccess;
1776 if ( !_pAttrs )
1777 {
1778 oAttrAccess.emplace(SwFrame::GetCache(), &m_rThis);
1779 _pAttrs = oAttrAccess->Get();
1780 }
1781
1782 bool bCommonBorder = true;
1783 if ( m_rThis.IsInSct() && m_rThis.GetUpper()->IsColBodyFrame() )
1784 {
1785 const SwSectionFrame* pSectFrame = m_rThis.FindSctFrame();
1786 bCommonBorder = pSectFrame->GetFormat()->GetBalancedColumns().GetValue();
1787 }
1788 nLowerSpace = bCommonBorder ?
1789 _pAttrs->GetBottomLine( m_rThis ) :
1790 _pAttrs->CalcBottomLine();
1791
1792 // i#26250
1793 // - correct consideration of table frames
1794 // - use new method <CalcAddLowerSpaceAsLastInTableCell(..)>
1795 if ( ( ( m_rThis.IsTabFrame() && m_rThis.GetUpper()->IsInTab() ) ||
1796 // No lower spacing, if frame has a follow
1797 ( m_rThis.IsInTab() && !GetFollow() ) ) &&
1798 !m_rThis.GetIndNext() )
1799 {
1800 nLowerSpace += CalcAddLowerSpaceAsLastInTableCell( _pAttrs );
1801 }
1802
1803 // tdf#128195 Consider para spacing below last paragraph in header
1804 bool bHasSpacingBelowPara = m_rThis.GetUpper()->GetFormat()->getIDocumentSettingAccess().get(
1806 if (bHasSpacingBelowPara && !m_rThis.IsInFly() && m_rThis.FindFooterOrHeader() && !GetFollow()
1807 && !m_rThis.GetIndNext())
1808 nLowerSpace += _pAttrs->GetULSpace().GetLower() + _pAttrs->CalcLineSpacing();
1809
1810 return nLowerSpace;
1811}
1812
1818SwTwips SwFlowFrame::CalcAddLowerSpaceAsLastInTableCell(
1819 const SwBorderAttrs* _pAttrs ) const
1820{
1821 SwTwips nAdditionalLowerSpace = 0;
1822
1823 IDocumentSettingAccess const& rIDSA(m_rThis.GetUpper()->GetFormat()->getIDocumentSettingAccess());
1825 {
1826 const SwFrame* pFrame = &m_rThis;
1827 if ( pFrame->IsSctFrame() )
1828 {
1829 const SwSectionFrame* pSectFrame = static_cast<const SwSectionFrame*>(pFrame);
1830 pFrame = pSectFrame->FindLastContent();
1831 if ( pFrame && pFrame->IsInTab() )
1832 {
1833 const SwTabFrame* pTableFrame = pFrame->FindTabFrame();
1834 if ( pSectFrame->IsAnLower( pTableFrame ) )
1835 {
1836 pFrame = pTableFrame;
1837 }
1838 }
1839 }
1840
1841 std::optional<SwBorderAttrAccess> oAttrAccess;
1842 if (pFrame && (!_pAttrs || pFrame != &m_rThis))
1843 {
1844 oAttrAccess.emplace(SwFrame::GetCache(), pFrame);
1845 _pAttrs = oAttrAccess->Get();
1846 }
1847
1848 if (_pAttrs)
1849 {
1850 nAdditionalLowerSpace += _pAttrs->GetULSpace().GetLower();
1851
1853 {
1854 nAdditionalLowerSpace += _pAttrs->CalcLineSpacing();
1855 }
1856 }
1857 }
1858
1859 return nAdditionalLowerSpace;
1860}
1861
1863bool SwFlowFrame::CheckMoveFwd( bool& rbMakePage, bool bKeep, bool bIgnoreMyOwnKeepValue )
1864{
1865 const SwFrame* pNxt = m_rThis.GetIndNext();
1866
1867 if ( bKeep &&
1868 ( !pNxt || ( pNxt->IsTextFrame() && static_cast<const SwTextFrame*>(pNxt)->IsEmptyMaster() ) ) &&
1869 ( nullptr != (pNxt = m_rThis.FindNext()) ) && IsKeepFwdMoveAllowed(bIgnoreMyOwnKeepValue) )
1870 {
1871 if( pNxt->IsSctFrame() )
1872 { // Don't get fooled by empty SectionFrames
1873 const SwFrame* pTmp = nullptr;
1874 while( pNxt && pNxt->IsSctFrame() &&
1875 ( !static_cast<const SwSectionFrame*>(pNxt)->GetSection() ||
1876 nullptr == ( pTmp = static_cast<const SwSectionFrame*>(pNxt)->ContainsAny() ) ) )
1877 {
1878 pNxt = pNxt->FindNext();
1879 pTmp = nullptr;
1880 }
1881 if( pTmp )
1882 pNxt = pTmp; // the content of the next notempty sectionfrm
1883 }
1884 if( pNxt && pNxt->isFrameAreaPositionValid() )
1885 {
1886 bool bMove = false;
1887 const SwSectionFrame *pSct = m_rThis.FindSctFrame();
1888 if( pSct && !pSct->isFrameAreaSizeValid() )
1889 {
1890 const SwSectionFrame* pNxtSct = pNxt->FindSctFrame();
1891 if( pNxtSct && pSct->IsAnFollow( pNxtSct ) )
1892 bMove = true;
1893 }
1894 else
1895 bMove = true;
1896 if( bMove )
1897 {
1898 //Keep together with the following frame
1899 MoveFwd( rbMakePage, false );
1900 return true;
1901 }
1902 }
1903 }
1904
1905 bool bMovedFwd = false;
1906
1907 if ( m_rThis.GetIndPrev() )
1908 {
1909 if ( IsPrevObjMove() ) // Should we care about objects of the Prev?
1910 {
1911 bMovedFwd = true;
1912 if ( !MoveFwd( rbMakePage, false ) )
1913 rbMakePage = false;
1914 }
1915 else
1916 {
1917 if ( IsPageBreak( false ) )
1918 {
1919 while ( MoveFwd( rbMakePage, true ) )
1920 /* do nothing */;
1921 rbMakePage = false;
1922 bMovedFwd = true;
1923 }
1924 else if ( IsColBreak ( false ) )
1925 {
1926 const SwPageFrame *pPage = m_rThis.FindPageFrame();
1927 SwFrame *pCol = m_rThis.FindColFrame();
1928 do
1929 { MoveFwd( rbMakePage, false );
1930 SwFrame *pTmp = m_rThis.FindColFrame();
1931 if( pTmp != pCol )
1932 {
1933 bMovedFwd = true;
1934 pCol = pTmp;
1935 }
1936 else
1937 break;
1938 } while ( IsColBreak( false ) );
1939 if ( pPage != m_rThis.FindPageFrame() )
1940 rbMakePage = false;
1941 }
1942 }
1943 }
1944 return bMovedFwd;
1945}
1946
1947bool SwFlowFrame::ForbiddenForFootnoteCntFwd() const
1948{
1949 return m_rThis.IsTabFrame() || m_rThis.IsInTab();
1950}
1951
1955bool SwFlowFrame::MoveFwd( bool bMakePage, bool bPageBreak, bool bMoveAlways )
1956{
1958 SwFootnoteBossFrame *pOldBoss = m_rThis.FindFootnoteBossFrame();
1959 if (m_rThis.IsInFootnote())
1960 {
1961 assert(!ForbiddenForFootnoteCntFwd()); // prevented by IsMoveable()
1962 if (!m_rThis.IsContentFrame() || !pOldBoss)
1963 {
1964 SAL_WARN("sw.core", "Tables in footnotes are not truly supported");
1965 return false;
1966 }
1967 return static_cast<SwContentFrame&>(m_rThis).MoveFootnoteCntFwd( bMakePage, pOldBoss );
1968 }
1969
1970 if( !IsFwdMoveAllowed() && !bMoveAlways )
1971 {
1972 bool bNoFwd = true;
1973 if( m_rThis.IsInSct() )
1974 {
1975 SwFootnoteBossFrame* pBoss = m_rThis.FindFootnoteBossFrame();
1976 bNoFwd = !pBoss->IsInSct() || ( !pBoss->Lower()->GetNext() &&
1977 !pBoss->GetPrev() );
1978 }
1979
1980 // Allow the MoveFwd even if we do not have an IndPrev in these cases:
1981 if ( m_rThis.IsInTab() &&
1982 ( !m_rThis.IsTabFrame() ||
1983 m_rThis.GetUpper()->IsInTab() ) &&
1984 nullptr != m_rThis.GetNextCellLeaf() )
1985 {
1986 bNoFwd = false;
1987 }
1988
1989 if( bNoFwd )
1990 {
1991 // It's allowed to move PageBreaks if the Frame isn't the first
1992 // one on the page.
1993 if ( !bPageBreak )
1994 return false;
1995
1996 const SwFrame *pCol = m_rThis.FindColFrame();
1997 if ( !pCol || !pCol->GetPrev() )
1998 return false;
1999 }
2000 }
2001
2002 std::optional<SwFrameDeleteGuard> oDeleteGuard;
2003 if (bMakePage)
2004 oDeleteGuard.emplace(pOldBoss);
2005
2006 bool bSamePage = true;
2007 SwLayoutFrame *pNewUpper =
2008 m_rThis.GetLeaf( bMakePage ? MAKEPAGE_INSERT : MAKEPAGE_NONE, true );
2009
2010 if ( pNewUpper )
2011 {
2012 PROTOCOL_ENTER( &m_rThis, PROT::MoveFwd, DbgAction::NONE, nullptr );
2013 SwPageFrame *pOldPage = pOldBoss->FindPageFrame();
2014 // We move ourself and all the direct successors before the
2015 // first ContentFrame below the new Upper.
2016
2017 // If our NewUpper lies in a SectionFrame, we need to make sure
2018 // that it won't destroy itself in Calc.
2019 SwSectionFrame* pSect = pNewUpper->FindSctFrame();
2020 if( pSect )
2021 {
2022 // If we only switch column within our SectionFrame, we better don't
2023 // call Calc, as this would format the SectionFrame, which in turn would
2024 // call us again, etc.
2025 if( pSect != m_rThis.FindSctFrame() )
2026 {
2027 bool bUnlock = !pSect->IsColLocked();
2028 pSect->ColLock();
2029 pNewUpper->Calc(m_rThis.getRootFrame()->GetCurrShell()->GetOut());
2030 if( bUnlock )
2031 pSect->ColUnlock();
2032 }
2033 }
2034 // Do not calculate split cell frames.
2035 else if ( !pNewUpper->IsCellFrame() || pNewUpper->Lower() )
2036 pNewUpper->Calc(m_rThis.getRootFrame()->GetCurrShell()->GetOut());
2037
2038 SwFootnoteBossFrame *pNewBoss = pNewUpper->FindFootnoteBossFrame();
2039 bool bBossChg = pNewBoss != pOldBoss;
2040 pNewBoss = pNewBoss->FindFootnoteBossFrame( true );
2041 pOldBoss = pOldBoss->FindFootnoteBossFrame( true );
2042 SwPageFrame* pNewPage = pOldPage;
2043
2044 oDeleteGuard.reset();
2045
2046 // First, we move the footnotes.
2047 bool bFootnoteMoved = false;
2048
2049 // i#26831
2050 // If pSect has just been created, the printing area of pSect has
2051 // been calculated based on the first content of its follow.
2052 // In this case we prefer to call a SimpleFormat for this new
2053 // section after we inserted the contents. Otherwise the section
2054 // frame will invalidate its lowers, if its printing area changes
2055 // in SwSectionFrame::Format, which can cause loops.
2056 const bool bForceSimpleFormat = pSect && pSect->HasFollow() &&
2057 !pSect->ContainsAny();
2058
2059 if ( pNewBoss != pOldBoss )
2060 {
2061 pNewPage = pNewBoss->FindPageFrame();
2062 bSamePage = pNewPage == pOldPage;
2063 // Set deadline, so the footnotes don't think up
2064 // silly things...
2065 SwRectFnSet aRectFnSet(pOldBoss);
2066 SwSaveFootnoteHeight aHeight( pOldBoss,
2067 aRectFnSet.GetBottom(pOldBoss->getFrameArea()) );
2068 SwContentFrame* pStart = m_rThis.IsContentFrame() ?
2069 static_cast<SwContentFrame*>(&m_rThis) : static_cast<SwLayoutFrame&>(m_rThis).ContainsContent();
2070 OSL_ENSURE( pStart || ( m_rThis.IsTabFrame() && !static_cast<SwTabFrame&>(m_rThis).Lower() ),
2071 "MoveFwd: Missing Content" );
2072 SwLayoutFrame* pBody = pStart ? ( pStart->IsTextFrame() ?
2073 const_cast<SwBodyFrame *>(static_cast<SwTextFrame*>(pStart)->FindBodyFrame()) : nullptr ) : nullptr;
2074 if( pBody )
2075 bFootnoteMoved = pBody->MoveLowerFootnotes( pStart, pOldBoss, pNewBoss,
2076 false);
2077 }
2078 // It's possible when dealing with SectionFrames that we have been moved
2079 // by pNewUpper->Calc(), for instance into the pNewUpper.
2080 // MoveSubTree or PasteTree respectively is not prepared to handle such a
2081 // situation.
2082 if( pNewUpper != m_rThis.GetUpper() )
2083 {
2084 // i#27145
2085 SwSectionFrame* pOldSct = nullptr;
2086 if ( m_rThis.GetUpper()->IsSctFrame() )
2087 {
2088 pOldSct = static_cast<SwSectionFrame*>(m_rThis.GetUpper());
2089 }
2090
2091 MoveSubTree( pNewUpper, pNewUpper->Lower() );
2092
2093 // i#27145
2094 if ( pOldSct && pOldSct->GetSection() )
2095 {
2096 // Prevent loops by setting the new height at
2097 // the section frame if footnotes have been moved.
2098 // Otherwise the call of SwLayNotify::~SwLayNotify() for
2099 // the (invalid) section frame will invalidate the first
2100 // lower of its follow, because it grows due to the removed
2101 // footnotes.
2102 // Note: If pOldSct has become empty during MoveSubTree, it
2103 // has already been scheduled for removal. No SimpleFormat
2104 // for these.
2105 pOldSct->SimpleFormat();
2106 }
2107
2108 // i#26831
2109 if ( bForceSimpleFormat )
2110 {
2111 pSect->SimpleFormat();
2112 }
2113
2114 if ( bFootnoteMoved && !bSamePage )
2115 {
2116 pOldPage->UpdateFootnoteNum();
2117 pNewPage->UpdateFootnoteNum();
2118 }
2119
2120 if( bBossChg )
2121 {
2122 m_rThis.Prepare( PrepareHint::BossChanged, nullptr, false );
2123 if( !bSamePage )
2124 {
2125 SwViewShell *pSh = m_rThis.getRootFrame()->GetCurrShell();
2126 if ( pSh && !pSh->Imp()->IsUpdateExpFields() )
2127 pSh->GetDoc()->getIDocumentFieldsAccess().SetNewFieldLst(true); // Will be done by CalcLayout() later on!
2128
2129 pNewPage->InvalidateSpelling();
2130 pNewPage->InvalidateSmartTags();
2131 pNewPage->InvalidateAutoCompleteWords();
2132 pNewPage->InvalidateWordCount();
2133 }
2134 }
2135 }
2136 // No <CheckPageDesc(..)> in online layout
2137 const SwViewShell *pSh = m_rThis.getRootFrame()->GetCurrShell();
2138
2139 if ( !( pSh && pSh->GetViewOptions()->getBrowseMode() ) )
2140 {
2141 // i#106452
2142 // check page description not only in situation with sections.
2143 if ( !bSamePage &&
2144 ( m_rThis.GetPageDescItem().GetPageDesc() ||
2145 pOldPage->GetPageDesc()->GetFollow() != pNewPage->GetPageDesc() ) )
2146 {
2147 SwFrame::CheckPageDescs( pNewPage, false );
2148 }
2149 }
2150 }
2151 return bSamePage;
2152}
2153
2160bool SwFlowFrame::MoveBwd( bool &rbReformat )
2161{
2162 SwFlowFrame::SetMoveBwdJump( false );
2163
2164 SwFootnoteFrame* pFootnote = m_rThis.FindFootnoteFrame();
2165 if ( pFootnote && pFootnote->IsBackMoveLocked() )
2166 return false;
2167
2168 // Text frames, which are directly inside
2169 // tables aren't allowed to move backward.
2170 if ( m_rThis.IsTextFrame() && m_rThis.IsInTab() )
2171 {
2172 const SwLayoutFrame* pUpperFrame = m_rThis.GetUpper();
2173 while ( pUpperFrame )
2174 {
2175 if ( pUpperFrame->IsTabFrame() || pUpperFrame->IsRowFrame() )
2176 {
2177 return false;
2178 }
2179 // If the text frame is a follow-section-in-table, that can move
2180 // backward as well.
2181 bool bIsFollowSection = pUpperFrame->IsSctFrame() && static_cast<const SwSectionFrame*>(pUpperFrame)->GetPrecede();
2182
2183 // If the text frame is a follow-in-table, that can move
2184 // backward as well.
2185 bool bIsFollow = const_cast<SwLayoutFrame*>(pUpperFrame)->GetPrevCellLeaf();
2186
2187 if ( ( pUpperFrame->IsColumnFrame() && pUpperFrame->IsInSct() ) || bIsFollowSection || bIsFollow )
2188 {
2189 break;
2190 }
2191 pUpperFrame = pUpperFrame->GetUpper();
2192 }
2193 }
2194
2195 SwFootnoteBossFrame * pOldBoss = m_rThis.FindFootnoteBossFrame();
2196 if (!pOldBoss)
2197 return false;
2198
2199 SwPageFrame * const pOldPage = pOldBoss->FindPageFrame();
2200 SwLayoutFrame *pNewUpper = nullptr;
2201 bool bCheckPageDescs = false;
2202 bool bCheckPageDescOfNextPage = false;
2203
2204 if ( pFootnote )
2205 {
2206 // If the footnote already sits on the same page/column as the reference,
2207 // we can't flow back. The breaks don't need to be checked for footnotes.
2208
2209 // i#37084 FindLastContent does not necessarily
2210 // have to have a result != 0
2211 SwFrame* pRef = nullptr;
2212 const bool bEndnote = pFootnote->GetAttr()->GetFootnote().IsEndNote();
2213 const IDocumentSettingAccess& rSettings
2214 = pFootnote->GetAttrSet()->GetDoc()->getIDocumentSettingAccess();
2215 if( bEndnote && pFootnote->IsInSct() )
2216 {
2217 SwSectionFrame* pSect = pFootnote->FindSctFrame();
2218 if( pSect->IsEndnAtEnd() )
2219 // Endnotes at the end of the section.
2220 pRef = pSect->FindLastContent( SwFindMode::LastCnt );
2221 }
2222 else if (bEndnote && rSettings.get(DocumentSettingId::CONTINUOUS_ENDNOTES))
2223 {
2224 // Endnotes at the end of the document.
2225 SwPageFrame* pPage = m_rThis.getRootFrame()->GetLastPage();
2226 pRef = pPage->FindLastBodyContent();
2227 }
2228 if( !pRef )
2229 // Endnotes on a separate page.
2230 pRef = pFootnote->GetRef();
2231
2232 OSL_ENSURE( pRef, "MoveBwd: Endnote for an empty section?" );
2233
2234 if( !bEndnote )
2235 pOldBoss = pOldBoss->FindFootnoteBossFrame( true );
2236 SwFootnoteBossFrame *pRefBoss = pRef->FindFootnoteBossFrame( !bEndnote );
2237 if ( pOldBoss != pRefBoss &&
2238
2239 ( !bEndnote ||
2240 pRefBoss->IsBefore( pOldBoss ) )
2241 )
2242 pNewUpper = m_rThis.GetLeaf( MAKEPAGE_FTN, false );
2243 }
2244 else if ( IsPageBreak( true ) ) // Do we have to respect a PageBreak?
2245 {
2246 // If the previous page doesn't have a Frame in the body,
2247 // flowing back makes sense despite the PageBreak (otherwise,
2248 // we'd get an empty page).
2249 // Of course we need to overlook empty pages!
2250 const SwFrame *pFlow = &m_rThis;
2251 do
2252 {
2253 pFlow = pFlow->FindPrev();
2254 } while ( pFlow &&
2255 ( pFlow->FindPageFrame() == pOldPage ||
2256 !pFlow->IsInDocBody() ) );
2257 if ( pFlow )
2258 {
2259 tools::Long nDiff = pOldPage->GetPhyPageNum() - pFlow->GetPhyPageNum();
2260 if ( nDiff > 1 )
2261 {
2262 if ( static_cast<SwPageFrame*>(pOldPage->GetPrev())->IsEmptyPage() )
2263 nDiff -= 1;
2264 if ( nDiff > 1 )
2265 {
2266 pNewUpper = m_rThis.GetLeaf( MAKEPAGE_NONE, false );
2267 // i#53139
2268 // Now <pNewUpper> is a previous layout frame, which contains
2269 // content. But the new upper layout frame has to be the next one.
2270 // Thus, hack for issue i14206 no longer needed, but fix for issue 114442
2271 // Correct fix for i53139
2272 // Check for wrong page description before using next new upper.
2273 // i#66051 - further correction of fix for i53139
2274 // Check for correct type of new next upper layout frame
2275 // Another correction of fix for i53139
2276 // Assumption, that in all cases <pNewUpper> is a previous
2277 // layout frame, which contains content, is wrong.
2278 // Another correction of fix for i53139
2279 // Beside type check, check also, if proposed new next upper
2280 // frame is inside the same frame types.
2281 // i#73194 - and yet another correction
2282 // of fix for i53139:
2283 // Assure that the new next upper layout frame doesn't
2284 // equal the current one.
2285 // E.g.: content is on page 3, on page 2 is only a 'ghost'
2286 // section and on page 1 is normal content. Method <FindPrev(..)>
2287 // will find the last content of page 1, but <GetLeaf(..)>
2288 // returns new upper on page 2.
2289 if (pNewUpper && pNewUpper->Lower())
2290 {
2291 SwLayoutFrame* pNewNextUpper = pNewUpper->GetLeaf( MAKEPAGE_NONE, true );
2292 if ( pNewNextUpper &&
2293 pNewNextUpper != m_rThis.GetUpper() &&
2294 pNewNextUpper->GetType() == pNewUpper->GetType() &&
2295 pNewNextUpper->IsInDocBody() == pNewUpper->IsInDocBody() &&
2296 pNewNextUpper->IsInFootnote() == pNewUpper->IsInFootnote() &&
2297 pNewNextUpper->IsInTab() == pNewUpper->IsInTab() &&
2298 pNewNextUpper->IsInSct() == pNewUpper->IsInSct() &&
2299 !m_rThis.WrongPageDesc( pNewNextUpper->FindPageFrame() ) )
2300 {
2301 pNewUpper = pNewNextUpper;
2302 bCheckPageDescOfNextPage = true;
2303 }
2304 }
2305
2306 bCheckPageDescs = true;
2307 }
2308 }
2309 }
2310 }
2311 else if ( IsColBreak( true ) )
2312 {
2313 // If the previous column doesn't contain a ContentFrame, flowing back
2314 // makes sense despite the ColumnBreak, as otherwise we'd get
2315 // an empty column.
2316 if( m_rThis.IsInSct() )
2317 {
2318 pNewUpper = m_rThis.GetLeaf( MAKEPAGE_NONE, false );
2319 if( pNewUpper && !SwFlowFrame::IsMoveBwdJump() &&
2320 ( pNewUpper->ContainsContent() ||
2321 ( ( !pNewUpper->IsColBodyFrame() ||
2322 !pNewUpper->GetUpper()->GetPrev() ) &&
2323 !pNewUpper->FindSctFrame()->GetPrev() ) ) )
2324 {
2325 pNewUpper = nullptr;
2326 }
2327 // i#53139
2328 // i#69409 - check <pNewUpper>
2329 // i#71065 - check <SwFlowFrame::IsMoveBwdJump()>
2330 else if ( pNewUpper && !SwFlowFrame::IsMoveBwdJump() )
2331 {
2332 // Now <pNewUpper> is a previous layout frame, which
2333 // contains content. But the new upper layout frame
2334 // has to be the next one.
2335 // Correct fix for i53139
2336 // Check for wrong page description before using next new upper.
2337 // i#66051 - further correction of fix for i53139
2338 // Check for correct type of new next upper layout frame
2339 // Another correction of fix for i53139
2340 // Beside type check, check also, if proposed new next upper
2341 // frame is inside the same frame types.
2342 SwLayoutFrame* pNewNextUpper = pNewUpper->GetLeaf( MAKEPAGE_NOSECTION, true );
2343 if ( pNewNextUpper &&
2344 pNewNextUpper->GetType() == pNewUpper->GetType() &&
2345 pNewNextUpper->IsInDocBody() == pNewUpper->IsInDocBody() &&
2346 pNewNextUpper->IsInFootnote() == pNewUpper->IsInFootnote() &&
2347 pNewNextUpper->IsInTab() == pNewUpper->IsInTab() &&
2348 pNewNextUpper->IsInSct() == pNewUpper->IsInSct() &&
2349 !m_rThis.WrongPageDesc( pNewNextUpper->FindPageFrame() ) )
2350 {
2351 pNewUpper = pNewNextUpper;
2352 }
2353 }
2354 }
2355 else
2356 {
2357 const SwFrame *pCol = m_rThis.FindColFrame();
2358 assert(pCol);
2359 bool bGoOn = true;
2360 bool bJump = false;
2361 do
2362 {
2363 if ( pCol->GetPrev() )
2364 pCol = pCol->GetPrev();
2365 else
2366 {
2367 bGoOn = false;
2368 pCol = m_rThis.GetLeaf( MAKEPAGE_NONE, false );
2369 }
2370 if ( pCol )
2371 {
2372 // ColumnFrames now with BodyFrame
2373 SwLayoutFrame* pColBody = pCol->IsColumnFrame() ?
2374 const_cast<SwLayoutFrame*>(static_cast<const SwLayoutFrame*>(static_cast<const SwLayoutFrame*>(pCol)->Lower())) :
2375 const_cast<SwLayoutFrame*>(static_cast<const SwLayoutFrame*>(pCol));
2376 if ( pColBody->ContainsContent() )
2377 {
2378 bGoOn = false; // We have content here! we accept this
2379 // only if GetLeaf() has set the MoveBwdJump.
2380 if( SwFlowFrame::IsMoveBwdJump() )
2381 {
2382 pNewUpper = pColBody;
2383 // i#53139
2384 // Now <pNewUpper> is a previous layout frame, which
2385 // contains content. But the new upper layout frame
2386 // has to be the next one.
2387 // Correct fix for i53139
2388 // Check for wrong page description before using next new upper.
2389 // i#66051 - further correction of fix for i53139
2390 // Check for correct type of new next upper layout frame
2391 // Another correction of fix for i53139
2392 // Beside type check, check also, if proposed new next upper
2393 // frame is inside the same frame types.
2394 // i#71065
2395 // Check that the proposed new next upper layout
2396 // frame isn't the current one.
2397 SwLayoutFrame* pNewNextUpper = pNewUpper->GetLeaf( MAKEPAGE_NONE, true );
2398 if ( pNewNextUpper &&
2399 pNewNextUpper != m_rThis.GetUpper() &&
2400 pNewNextUpper->GetType() == pNewUpper->GetType() &&
2401 pNewNextUpper->IsInDocBody() == pNewUpper->IsInDocBody() &&
2402 pNewNextUpper->IsInFootnote() == pNewUpper->IsInFootnote() &&
2403 pNewNextUpper->IsInTab() == pNewUpper->IsInTab() &&
2404 pNewNextUpper->IsInSct() == pNewUpper->IsInSct() &&
2405 !m_rThis.WrongPageDesc( pNewNextUpper->FindPageFrame() ) )
2406 {
2407 pNewUpper = pNewNextUpper;
2408 }
2409 }
2410 }
2411 else
2412 {
2413 if( pNewUpper ) // We already had an empty column, in other
2414 bJump = true; // words we skipped one.
2415 pNewUpper = pColBody; // this empty column could be considered,
2416 // but we continue searching nevertheless.
2417 }
2418 }
2419 } while( bGoOn );
2420 if( bJump )
2421 SwFlowFrame::SetMoveBwdJump( true );
2422 }
2423 }
2424 else // No breaks - we can flow back.
2425 pNewUpper = m_rThis.GetLeaf( MAKEPAGE_NONE, false );
2426
2427 // i#27801 - no move backward of 'master' text frame,
2428 // if - due to its object positioning - it isn't allowed to be on the new page frame
2429 // i#44049 - add another condition for not moving backward
2430 // If one of its objects has restarted the layout process, moving backward
2431 // isn't sensible either.
2432 // i#47697 - refine condition made for issue i44049
2433 // - allow move backward as long as the anchored object is only temporarily
2434 // positions considering its wrapping style.
2435 if ( pNewUpper &&
2436 m_rThis.IsTextFrame() && !IsFollow() )
2437 {
2438 sal_uInt32 nToPageNum( 0 );
2439 const bool bMoveFwdByObjPos = SwLayouter::FrameMovedFwdByObjPos(
2440 *(pOldPage->GetFormat()->GetDoc()),
2441 static_cast<SwTextFrame&>(m_rThis),
2442 nToPageNum );
2443 if ( bMoveFwdByObjPos &&
2444 pNewUpper->FindPageFrame()->GetPhyPageNum() < nToPageNum )
2445 {
2446 pNewUpper = nullptr;
2447 }
2448 // i#44049 - check, if one of its anchored objects
2449 // has restarted the layout process.
2450 else if ( m_rThis.GetDrawObjs() )
2451 {
2452 for (SwAnchoredObject* pAnchoredObj : *m_rThis.GetDrawObjs())
2453 {
2454 // i#47697 - refine condition - see above
2455 if ( pAnchoredObj->RestartLayoutProcess() &&
2456 !pAnchoredObj->IsTmpConsiderWrapInfluence() )
2457 {
2458 pNewUpper = nullptr;
2459 break;
2460 }
2461 }
2462 }
2463 }
2464
2465 // With Follows, it's only allowed to flow back if there's no neighbor
2466 // in the new environment (because that would be the Master).
2467 // (6677) If however we skipped empty pages, we still have to move.
2468 if ( pNewUpper && IsFollow() && pNewUpper->Lower() )
2469 {
2470 // i#79774
2471 // neglect empty sections in proposed new upper frame
2472 bool bProposedNewUpperContainsOnlyEmptySections( true );
2473 {
2474 const SwFrame* pLower( pNewUpper->Lower() );
2475 while ( pLower )
2476 {
2477 if ( pLower->IsSctFrame() &&
2478 !dynamic_cast<const SwSectionFrame&>(*pLower).GetSection() )
2479 {
2480 pLower = pLower->GetNext();
2481 continue;
2482 }
2483 else
2484 {
2485 bProposedNewUpperContainsOnlyEmptySections = false;
2486 break;
2487 }
2488 }
2489 }
2490 if ( !bProposedNewUpperContainsOnlyEmptySections )
2491 {
2492 if ( SwFlowFrame::IsMoveBwdJump() )
2493 {
2494 // Don't move after the Master, but into the next empty page.
2495 SwFrame *pFrame = pNewUpper->Lower();
2496 while ( pFrame->GetNext() )
2497 pFrame = pFrame->GetNext();
2498 pNewUpper = pFrame->GetLeaf( MAKEPAGE_INSERT, true );
2499 if( pNewUpper == m_rThis.GetUpper() ) // Did we end up in the same place?
2500 pNewUpper = nullptr; // If so, moving is not needed.
2501 }
2502 else
2503 pNewUpper = nullptr;
2504 }
2505 }
2506 if ( pNewUpper && !ShouldBwdMoved( pNewUpper, rbReformat ) )
2507 {
2508 if( !pNewUpper->Lower() )
2509 {
2510 if( pNewUpper->IsFootnoteContFrame() )
2511 {
2512 pNewUpper->Cut();
2513 SwFrame::DestroyFrame(pNewUpper);
2514 }
2515 else
2516 {
2517 SwSectionFrame* pSectFrame = pNewUpper->FindSctFrame();
2518
2519 if ( pSectFrame && !pSectFrame->IsColLocked() &&
2520 !pSectFrame->ContainsContent() && !pSectFrame->ContainsAny( true ) )
2521 {
2522 pSectFrame->DelEmpty( true );
2523 SwFrame::DestroyFrame(pSectFrame);
2524 m_rThis.setFrameAreaPositionValid(true);
2525 }
2526 }
2527 }
2528 pNewUpper = nullptr;
2529 }
2530
2531 // i#21478 - don't move backward, if flow frame wants to
2532 // keep with next frame and next frame is locked.
2533 // i#38232 - If next frame is a table, do *not* check,
2534 // if it's locked.
2535 if ( pNewUpper && !IsFollow() &&
2536 m_rThis.GetAttrSet()->GetKeep().GetValue() && m_rThis.GetIndNext() )
2537 {
2538 SwFrame* pIndNext = m_rThis.GetIndNext();
2539 // i#38232
2540 if ( !pIndNext->IsTabFrame() )
2541 {
2542 // get first content of section, while empty sections are skipped
2543 while ( pIndNext && pIndNext->IsSctFrame() )
2544 {
2545 if( static_cast<SwSectionFrame*>(pIndNext)->GetSection() )
2546 {
2547 SwFrame* pTmp = static_cast<SwSectionFrame*>(pIndNext)->ContainsAny();
2548 if ( pTmp )
2549 {
2550 pIndNext = pTmp;
2551 break;
2552 }
2553 }
2554 pIndNext = pIndNext->GetIndNext();
2555 }
2556 OSL_ENSURE( !pIndNext || dynamic_cast<const SwTextFrame*>( pIndNext) != nullptr,
2557 "<SwFlowFrame::MovedBwd(..)> - incorrect next found." );
2558 if ( pIndNext && pIndNext->IsFlowFrame() &&
2559 SwFlowFrame::CastFlowFrame(pIndNext)->IsJoinLocked() )
2560 {
2561 pNewUpper = nullptr;
2562 }
2563 }
2564 }
2565
2566 // i#65250
2567 // layout loop control for flowing content again and again moving
2568 // backward under the same layout condition.
2569 if ( pNewUpper && !IsFollow() &&
2570 pNewUpper != m_rThis.GetUpper() &&
2572 *this, *pNewUpper ) )
2573 {
2574 SwLayoutFrame* pNextNewUpper = pNewUpper->GetLeaf(
2575 ( !m_rThis.IsSctFrame() && m_rThis.IsInSct() )
2577 : MAKEPAGE_NONE,
2578 true );
2579 // i#73194 - make code robust
2580 OSL_ENSURE( pNextNewUpper, "<SwFlowFrame::MoveBwd(..)> - missing next new upper" );
2581 if ( pNextNewUpper &&
2582 ( pNextNewUpper == m_rThis.GetUpper() ||
2583 pNextNewUpper->GetType() != m_rThis.GetUpper()->GetType() ) )
2584 {
2585 // tdf#107398 do not leave empty footnote container around
2586 if (!pNewUpper->Lower() && pNewUpper->IsFootnoteContFrame())
2587 {
2588 pNewUpper->Cut();
2589 SwFrame::DestroyFrame(pNewUpper);
2590 }
2591 pNewUpper = nullptr;
2592 OSL_FAIL( "<SwFlowFrame::MoveBwd(..)> - layout loop control for layout action <Move Backward> applied!" );
2593 }
2594 }
2595
2596 OSL_ENSURE( pNewUpper != m_rThis.GetUpper(),
2597 "<SwFlowFrame::MoveBwd(..)> - moving backward to the current upper frame!?" );
2598 if ( pNewUpper )
2599 {
2600 PROTOCOL_ENTER( &m_rThis, PROT::MoveBack, DbgAction::NONE, nullptr );
2601 if ( pNewUpper->IsFootnoteContFrame() )
2602 {
2603 // I may have gotten a Container
2605 pNew->Paste( pNewUpper );
2606 pNewUpper = pNew;
2607 }
2608 if( pNewUpper->IsFootnoteFrame() && m_rThis.IsInSct() )
2609 {
2610 SwSectionFrame* pSct = m_rThis.FindSctFrame();
2611 // If we're in a section of a footnote, we may need to create
2612 // a SwSectionFrame in the new upper
2613 if( pSct->IsInFootnote() )
2614 {
2615 SwFrame* pTmp = pNewUpper->Lower();
2616 if( pTmp )
2617 {
2618 while( pTmp->GetNext() )
2619 pTmp = pTmp->GetNext();
2620 if( !pTmp->IsSctFrame() ||
2621 static_cast<SwSectionFrame*>(pTmp)->GetFollow() != pSct )
2622 pTmp = nullptr;
2623 }
2624 if( pTmp )
2625 pNewUpper = static_cast<SwSectionFrame*>(pTmp);
2626 else
2627 {
2628 pSct = new SwSectionFrame( *pSct, true );
2629 pSct->Paste( pNewUpper );
2630 pSct->Init();
2631 pNewUpper = pSct;
2632 pSct->SimpleFormat();
2633 }
2634 }
2635 }
2636 bool bUnlock = false;
2637 bool bFollow = false;
2638 // Lock section. Otherwise, it could get destroyed if the only Content
2639 // moves e.g. from the second into the first column.
2640 SwSectionFrame* pSect = pNewUpper->FindSctFrame();
2641 if( pSect )
2642 {
2643 bUnlock = !pSect->IsColLocked();
2644 pSect->ColLock();
2645 bFollow = pSect->HasFollow();
2646 }
2647
2648 {
2649 auto const pOld = m_rThis.GetUpper();
2650 ::std::optional<SwFrameDeleteGuard> g;
2651 if (m_rThis.GetUpper()->IsCellFrame())
2652 {
2653 // note: IsFollowFlowRow() is never set for new-style tables
2654 SwTabFrame const*const pTabFrame(m_rThis.FindTabFrame());
2655 if ( pTabFrame->IsFollow()
2656 && static_cast<SwTabFrame const*>(pTabFrame->GetPrecede())->HasFollowFlowLine()
2657 && pTabFrame->GetFirstNonHeadlineRow() == m_rThis.GetUpper()->GetUpper())
2658 {
2659 // lock follow-flow-row (similar to sections above)
2660 g.emplace(m_rThis.GetUpper()->GetUpper());
2661 assert(m_rThis.GetUpper()->GetUpper()->IsDeleteForbidden());
2662 }
2663 }
2664 pNewUpper->Calc(m_rThis.getRootFrame()->GetCurrShell()->GetOut());
2665 SAL_WARN_IF(pOld != m_rThis.GetUpper(), "sw.core",
2666 "MoveBwd(): pNewUpper->Calc() moved this frame?");
2667 }
2668
2669 m_rThis.Cut();
2670
2671 // optimization: format section, if its size is invalidated and if it's
2672 // the new parent of moved backward frame.
2673 bool bFormatSect( false );
2674 if( bUnlock )
2675 {
2676 pSect->ColUnlock();
2677 if( pSect->HasFollow() != bFollow )
2678 {
2679 pSect->InvalidateSize();
2680 // - optimization
2681 if ( pSect == pNewUpper )
2682 bFormatSect = true;
2683 }
2684 }
2685
2686 m_rThis.Paste( pNewUpper );
2687 // - optimization
2688 if ( bFormatSect )
2689 pSect->Calc(m_rThis.getRootFrame()->GetCurrShell()->GetOut());
2690
2691 SwPageFrame *pNewPage = m_rThis.FindPageFrame();
2692 if( pNewPage != pOldPage )
2693 {
2694 m_rThis.Prepare( PrepareHint::BossChanged, static_cast<const void*>(pOldPage), false );
2695 SwViewShell *pSh = m_rThis.getRootFrame()->GetCurrShell();
2696 if ( pSh && !pSh->Imp()->IsUpdateExpFields() )
2697 pSh->GetDoc()->getIDocumentFieldsAccess().SetNewFieldLst(true); // Will be done by CalcLayout() later on
2698
2699 pNewPage->InvalidateSpelling();
2700 pNewPage->InvalidateSmartTags();
2701 pNewPage->InvalidateAutoCompleteWords();
2702 pNewPage->InvalidateWordCount();
2703
2704 // No <CheckPageDesc(..)> in online layout
2705 if ( !( pSh && pSh->GetViewOptions()->getBrowseMode() ) )
2706 {
2707 if ( bCheckPageDescs && pNewPage->GetNext() )
2708 {
2709 SwPageFrame* pStartPage = bCheckPageDescOfNextPage ?
2710 pNewPage :
2711 static_cast<SwPageFrame*>(pNewPage->GetNext());
2712 SwFrame::CheckPageDescs( pStartPage, false);
2713 }
2714 else if (m_rThis.GetPageDescItem().GetPageDesc())
2715 {
2716 // First page could get empty for example by disabling
2717 // a section
2718 SwFrame::CheckPageDescs( pNewPage, false);
2719 }
2720 }
2721 }
2722 }
2723 return pNewUpper != nullptr;
2724}
2725
2726SwFlowFrame *SwFlowFrame::CastFlowFrame( SwFrame *pFrame )
2727{
2728 if ( pFrame->IsContentFrame() )
2729 return static_cast<SwContentFrame*>(pFrame);
2730 if ( pFrame->IsTabFrame() )
2731 return static_cast<SwTabFrame*>(pFrame);
2732 if ( pFrame->IsSctFrame() )
2733 return static_cast<SwSectionFrame*>(pFrame);
2734 return nullptr;
2735}
2736
2737const SwFlowFrame *SwFlowFrame::CastFlowFrame( const SwFrame *pFrame )
2738{
2739 if ( pFrame->IsContentFrame() )
2740 return static_cast<const SwContentFrame*>(pFrame);
2741 if ( pFrame->IsTabFrame() )
2742 return static_cast<const SwTabFrame*>(pFrame);
2743 if ( pFrame->IsSctFrame() )
2744 return static_cast<const SwSectionFrame*>(pFrame);
2745 return nullptr;
2746}
2747
2748/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ TREAT_SINGLE_COLUMN_BREAK_AS_PAGE_BREAK
@ ADD_PARA_LINE_SPACING_TO_TABLE_CELLS
virtual bool IsVisibleLayerId(SdrLayerID _nLayerId) const =0
method to determine, if a layer ID belongs to the visible ones.
virtual void SetNewFieldLst(bool bFlag)=0
Provides access to settings of a document.
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
virtual SdrLayerID GetLayer() const
bool GetValue() const
SvxBreak GetBreak() const
sal_uInt16 GetUpper() const
sal_uInt16 GetLower() const
bool GetContext() const
wrapper class for the positioning of Writer fly frames and drawing objects
const SwFrame * GetAnchorFrame() const
const SwLayoutFrame * GetVertPosOrientFrame() const
virtual SwFrameFormat & GetFrameFormat()=0
virtual const SwFlyFrame * DynCastFlyFrame() const
const SdrObject * GetDrawObj() const
virtual SwRect GetObjRect() const =0
const SvxFormatBreakItem & GetBreak(bool=true) const
Definition: frmatr.hxx:74
const SwDoc * GetDoc() const
Definition: swatrset.hxx:204
const SwFormatPageDesc & GetPageDesc(bool=true) const
Definition: fmtpdsc.hxx:75
const SvxFormatKeepItem & GetKeep(bool=true) const
Definition: frmatr.hxx:68
Container of body content (i.e.
Definition: bodyfrm.hxx:29
SwBorderAttrs * Get()
Definition: frmtool.cxx:2704
const SvxULSpaceItem & GetULSpace() const
Definition: frmtool.hxx:398
sal_uInt16 GetTopLine(const SwFrame &_rFrame, const SwFrame *_pPrevFrame=nullptr) const
Definition: frmtool.hxx:487
sal_uInt16 GetBottomLine(const SwFrame &_rFrame) const
Definition: frmtool.hxx:496
sal_uInt16 CalcBottomLine() const
Definition: frmtool.hxx:518
sal_uInt16 CalcLineSpacing() const
Definition: frmtool.hxx:548
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
const SwContentFrame * GetFollow() const
Definition: cntfrm.hxx:136
SwContentFrame * GetNextContentFrame() const
Definition: cntfrm.hxx:120
SwTextFrame * FindMaster() const
Definition: flowfrm.cxx:737
SwFormatColl * GetFormatColl() const
Definition: node.hxx:497
const SwLineNumberInfo & GetLineNumberInfo() const
Definition: lineinfo.cxx:49
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:365
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:184
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:163
SwLayoutFrame * FindBodyCont()
Searches the first ContentFrame in BodyText below the page.
Definition: findfrm.cxx:48
SwFootnoteContFrame * FindFootnoteCont()
Definition: ftnfrm.cxx:1036
static SwFootnoteFrame * PrependChained(SwFrame *pThis, bool bDefaultFormat)
Definition: ftnfrm.hxx:74
Represents one footnote or endnote in the layout.
Definition: ftnfrm.hxx:82
void InvalidateNxtFootnoteCnts(SwPageFrame const *pPage)
Definition: ftnfrm.cxx:496
const SwFootnoteFrame * GetMaster() const
Definition: ftnfrm.hxx:121
virtual void Paste(SwFrame *pParent, SwFrame *pSibling=nullptr) override
Definition: ftnfrm.cxx:592
const SwTextFootnote * GetAttr() const
Definition: ftnfrm.hxx:124
const SwContentFrame * GetRef() const
Definition: ftnfrm.cxx:2907
bool IsBackMoveLocked() const
Definition: ftnfrm.hxx:135
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:67
SwNode * GetAnchorNode() const
Definition: atrfrm.cxx:1606
bool IsEndNote() const
Definition: fmtftn.hxx:73
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:36
SwPageDesc * GetPageDesc()
Definition: fmtpdsc.hxx:61
const ::std::optional< sal_uInt16 > & GetNumOffset() const
Definition: fmtpdsc.hxx:64
css::text::WrapTextMode GetSurround() const
Definition: fmtsrnd.hxx:51
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:139
const SwFormatFollowTextFlow & GetFollowTextFlow(bool=true) const
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:88
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:136
const SwFormatSurround & GetSurround(bool=true) const
Definition: fmtsrnd.hxx:66
const SwFormatNoBalancedColumns & GetBalancedColumns(bool=true) const
Definition: fmtclbl.hxx:42
const SwRect & getFrameArea() const
Definition: frame.hxx:179
bool isFrameAreaPositionValid() const
Definition: frame.hxx:166
bool isFrameAreaSizeValid() const
Definition: frame.hxx:167
Style of a layout element.
Definition: frmfmt.hxx:62
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool OnRightPage() const
Definition: frame.hxx:739
bool IsRowFrame() const
Definition: frame.hxx:1228
SwTwips Grow(SwTwips, bool bTst=false, bool bInfo=false)
Definition: wsfrm.cxx:1515
bool IsCellFrame() const
Definition: frame.hxx:1232
SwLayoutFrame * GetPrevLeaf()
Returns the previous layout leaf where we can move the frame.
Definition: flowfrm.cxx:1103
SwFrame * mpPrev
Definition: frame.hxx:339
bool IsFootnoteContFrame() const
Definition: frame.hxx:1204
bool IsTextFrame() const
Definition: frame.hxx:1240
virtual bool Prepare(const PrepareHint ePrep=PrepareHint::Clear, const void *pVoid=nullptr, bool bNotify=true)
Definition: wsfrm.cxx:608
SwFrame * GetIndPrev() const
Definition: frame.hxx:730
void CheckDirChange()
checks the layout direction and invalidates the lower frames recursively, if necessary.
Definition: ssfrm.cxx:195
bool IsInDocBody() const
Definition: frame.hxx:949
SwTwips Shrink(SwTwips, bool bTst=false, bool bInfo=false)
Definition: wsfrm.cxx:1559
SwFlyFrame * FindFlyFrame()
Definition: frame.hxx:1117
SwSectionFrame * FindSctFrame()
Definition: frame.hxx:1121
SwTabFrame * FindTabFrame()
Definition: frame.hxx:1105
SwFrame * FindNext()
Definition: frame.hxx:1147
SwFrame * GetNext()
Definition: frame.hxx:682
SwLayoutFrame * GetNextSctLeaf(MakePageType eMakePage)
Returns the next layout sheet where the frame can be moved in.
Definition: sectfrm.cxx:1580
bool IsPageFrame() const
Definition: frame.hxx:1184
bool IsColLocked() const
Definition: frame.hxx:892
bool IsColumnFrame() const
Definition: frame.hxx:1188
friend class SwFlowFrame
Definition: frame.hxx:317
bool IsTabFrame() const
Definition: frame.hxx:1224
SwLayoutFrame * GetNextFlyLeaf(MakePageType eMakePage)
Definition: flycnt.cxx:1550
void InvalidatePos_()
Definition: frame.hxx:793
SwFrameType GetType() const
Definition: frame.hxx:521
bool IsInFootnote() const
Definition: frame.hxx:955
bool IsHeaderFrame() const
Definition: frame.hxx:1196
SwPageFrame * InsertPage(SwPageFrame *pSibling, bool bFootnote)
Definition: pagechg.cxx:1366
virtual void Calc(vcl::RenderContext *pRenderContext) const
Definition: trvlfrm.cxx:1799
const SwSortedObjs * GetDrawObjs() const
Definition: frame.hxx:568
bool IsInTab() const
Definition: frame.hxx:961
SwLayoutFrame * GetPrevFlyLeaf()
Definition: flycnt.cxx:1637
SwFrame * FindPrev()
Definition: frame.hxx:1161
static SwCache & GetCache()
Definition: frame.hxx:523
SwLayoutFrame * mpUpper
Definition: frame.hxx:337
SwFrame * GetLower()
Definition: findfrm.cxx:196
bool IsInFly() const
Definition: frame.hxx:967
static void CheckPageDescs(SwPageFrame *pStart, bool bNotifyFields=true, SwPageFrame **ppPrev=nullptr)
Check all pages (starting from the given one) if they use the appropriate frame format.
Definition: pagechg.cxx:1066
virtual bool IsDeleteForbidden() const
Definition: frame.hxx:893
const SwAttrSet * GetAttrSet() const
WARNING: this may not return correct RES_PAGEDESC/RES_BREAK items for SwTextFrame,...
Definition: findfrm.cxx:762
void InvalidateNextPrtArea()
method to invalidate printing area of next frame #i11859#
Definition: findfrm.cxx:1367
bool OnFirstPage() const
Definition: trvlfrm.cxx:1779
bool IsFlowFrame() const
Definition: frame.hxx:1248
bool WrongPageDesc(SwPageFrame *pNew)
Definition: flowfrm.cxx:895
SwLayoutFrame * GetNextCellLeaf()
Definition: findfrm.cxx:1611
bool IsFooterFrame() const
Definition: frame.hxx:1200
void InvalidatePos()
Definition: frame.hxx:1049
SwLayoutFrame * GetPrevFootnoteLeaf(MakePageType eMakeFootnote)
Get the preceding layout leaf in that the frame can be moved.
Definition: ftnfrm.cxx:749
bool IsFootnoteFrame() const
Definition: frame.hxx:1208
SwLayoutFrame * GetUpper()
Definition: frame.hxx:684
const SwLayoutFrame * GetNextLayoutLeaf() const
Definition: frame.hxx:1026
SwLayoutFrame * GetLeaf(MakePageType eMakePage, bool bFwd)
Definition: flowfrm.cxx:842
SwFrame * mpNext
Definition: frame.hxx:338
void InvalidatePage(const SwPageFrame *pPage=nullptr) const
Invalidates the page in which the Frame is currently placed.
Definition: wsfrm.cxx:618
SwLayoutFrame * GetNextFootnoteLeaf(MakePageType eMakePage)
Return the next layout leaf in that the frame can be moved.
Definition: ftnfrm.cxx:667
SwRootFrame * mpRoot
Definition: frame.hxx:336
SwLayoutFrame * GetNextLeaf(MakePageType eMakePage)
Returns the next layout leaf in which we can move the frame.
Definition: flowfrm.cxx:971
SwRootFrame * getRootFrame()
Definition: frame.hxx:685
virtual const SvxFormatBreakItem & GetBreakItem() const
Definition: findfrm.cxx:742
bool IsFlyFrame() const
Definition: frame.hxx:1216
bool IsContentFrame() const
Definition: frame.hxx:1236
void InvalidatePrt_()
Definition: frame.hxx:785
SwFrame * GetPrev()
Definition: frame.hxx:683
SwFrame * FindColFrame()
Definition: findfrm.cxx:615
bool IsSctFrame() const
Definition: frame.hxx:1220
void InvalidateSize()
Definition: frame.hxx:1035
SwContentFrame * FindNextCnt(const bool _bInSameFootnote=false)
Definition: findfrm.cxx:217
const SwLayoutFrame * GetPrevLayoutLeaf() const
Definition: frame.hxx:1030
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
SwFootnoteFrame * FindFootnoteFrame()
Definition: frame.hxx:1113
virtual const SwFormatPageDesc & GetPageDescItem() const
Definition: findfrm.cxx:747
SwFrame * GetIndNext()
Definition: frame.hxx:733
SwFootnoteBossFrame * FindFootnoteBossFrame(bool bFootnotes=false)
Definition: findfrm.cxx:491
sal_uInt16 GetPhyPageNum() const
Definition: trvlfrm.cxx:1706
void InvalidateAll_()
Definition: frame.hxx:809
static void DestroyFrame(SwFrame *const pFrame)
this is the only way to delete a SwFrame instance
Definition: ssfrm.cxx:390
void SetRetouche() const
Definition: frame.hxx:1009
bool IsLayoutFrame() const
Definition: frame.hxx:1176
SwLayoutFrame * GetPrevSctLeaf()
Returns the preceding layout sheet where the frame can be moved into.
Definition: sectfrm.cxx:1933
bool IsBodyFrame() const
Definition: frame.hxx:1212
bool IsColBodyFrame() const
These SwFrame inlines are here, so that frame.hxx does not need to include layfrm....
Definition: layfrm.hxx:210
SwLayoutFrame * GetPrevCellLeaf()
Definition: findfrm.cxx:1621
bool IsInSct() const
Definition: frame.hxx:973
TElementType * Next()
Definition: calbck.hxx:380
TElementType * First()
Definition: calbck.hxx:372
bool IsComplete() const
Definition: layact.hxx:171
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
Definition: layfrm.hxx:36
bool IsAnLower(const SwFrame *) const
Definition: findfrm.cxx:233
virtual const SwFrameFormat * GetFormat() const
Definition: ssfrm.cxx:401
const SwFrame * ContainsAny(const bool _bInvestigateFootnoteForSections=false) const
Method <ContainsAny()> doesn't investigate content of footnotes by default.
Definition: findfrm.cxx:131
bool IsBefore(const SwLayoutFrame *_pCheckRefLayFrame) const
method to check relative position of layout frame to a given layout frame.
Definition: findfrm.cxx:260
const SwFrame * GetLastLower() const
Definition: findfrm.cxx:1917
const SwContentFrame * ContainsContent() const
Checks if the frame contains one or more ContentFrame's anywhere in his subsidiary structure; if so t...
Definition: findfrm.cxx:72
SwFrame * m_pLower
Definition: layfrm.hxx:53
bool MoveLowerFootnotes(SwContentFrame *pStart, SwFootnoteBossFrame *pOldBoss, SwFootnoteBossFrame *pNewBoss, const bool bFootnoteNums)
Moving the Footnotes of all Lowers - starting from StartContent.
Definition: ftnfrm.cxx:2661
const SwFrame * Lower() const
Definition: layfrm.hxx:101
virtual void Cut() override
Definition: wsfrm.cxx:1446
static bool FrameMovedFwdByObjPos(const SwDoc &_rDoc, const SwTextFrame &_rTextFrame, sal_uInt32 &_ornToPageNum)
Definition: layouter.cxx:342
static bool MoveBwdSuppressed(const SwDoc &p_rDoc, const SwFlowFrame &p_rFlowFrame, const SwLayoutFrame &p_rNewUpperFrame)
Definition: layouter.cxx:437
bool IsRestartEachPage() const
Definition: lineinfo.hxx:89
const SwContentNode * GetNode() const
Definition: notxtfrm.hxx:77
Base class of the Writer document model elements.
Definition: node.hxx:98
SwNodeOffset GetIndex() const
Definition: node.hxx:312
SwFrameFormat * GetRightFormat(bool const bFirst=false)
Layout uses the following methods to obtain a format in order to be able to create a page.
Definition: pagedesc.cxx:389
const SwPageDesc * GetFollow() const
Definition: pagedesc.hxx:267
SwFrameFormat * GetLeftFormat(bool const bFirst=false)
Definition: pagedesc.cxx:382
A page of the document layout.
Definition: pagefrm.hxx:59
SwContentFrame * FindLastBodyContent()
Searches the last ContentFrame in BodyText below the page.
Definition: findfrm.cxx:57
void InvalidateWordCount() const
Definition: pagefrm.hxx:400
void InvalidateAutoCompleteWords() const
Definition: pagefrm.hxx:396
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:205
const SwSortedObjs * GetSortedObjs() const
Definition: pagefrm.hxx:133
void InvalidateSmartTags() const
Definition: pagefrm.hxx:392
bool IsEmptyPage() const
Definition: pagefrm.hxx:158
SwContentFrame * FindFirstBodyContent()
Definition: pagefrm.hxx:353
void InvalidateSpelling() const
Definition: pagefrm.hxx:387
SwPageDesc * FindPageDesc()
Definition: pagechg.cxx:755
bool IsFootnotePage() const
Foot note interface.
Definition: pagefrm.hxx:200
void UpdateFootnoteNum()
Definition: ftnfrm.cxx:2431
SwPageDesc * GetPageDesc()
Definition: pagefrm.hxx:144
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Height(tools::Long nNew)
Definition: swrect.hxx:193
SwViewShell * GetCurrShell() const
Definition: rootfrm.hxx:210
const SwPageFrame * GetLastPage() const
Definition: rootfrm.hxx:366
SwSection * GetSection()
Definition: sectfrm.hxx:97
bool IsEndnAtEnd() const
Definition: sectfrm.hxx:161
void DelEmpty(bool bRemove)
Definition: sectfrm.cxx:192
bool IsContentLocked() const
Definition: sectfrm.hxx:165
SwSection * m_pSection
Definition: sectfrm.hxx:52
SwContentFrame * FindLastContent(SwFindMode nMode=SwFindMode::None)
Definition: sectfrm.cxx:918
void ColUnlock()
Definition: sectfrm.hxx:100
void SimpleFormat()
Definition: sectfrm.cxx:1173
void SetContentLock(bool bNew)
Definition: sectfrm.hxx:164
virtual void Paste(SwFrame *pParent, SwFrame *pSibling=nullptr) override
Definition: sectfrm.cxx:347
SwSectionFrame * FindMaster() const
Definition: flowfrm.cxx:753
void ColLock()
Definition: sectfrm.hxx:99
const SwSectionFrame * GetFollow() const
Definition: sectfrm.hxx:173
SwSectionFormat * GetFormat()
Definition: section.hxx:339
class for collecting anchored objects
Definition: sortedobjs.hxx:49
size_t size() const
Definition: sortedobjs.cxx:43
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:49
SwTabFrame * FindMaster(bool bFirstMaster=false) const
Definition: flowfrm.cxx:773
const SwTabFrame * GetFollow() const
Definition: tabfrm.hxx:252
const SwTable * GetTable() const
Definition: tabfrm.hxx:160
bool HasFollowFlowLine() const
Definition: tabfrm.hxx:176
const SwFormatFootnote & GetFootnote() const
Definition: txatbase.hxx:208
Represents the style of a paragraph.
Definition: fmtcol.hxx:61
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:166
bool IsEmptyMaster() const
If there's a Follow and we don't contain text ourselves.
Definition: txtfrm.hxx:456
bool IsHiddenNow() const
Hidden.
Definition: txtfrm.cxx:1360
SwTextNode const * GetTextNodeForParaProps() const
Definition: txtfrm.cxx:1303
bool getBrowseMode() const
Definition: viewopt.hxx:638
bool IsUpdateExpFields()
Definition: viewimp.cxx:194
bool IsAction() const
SS for the Lay-/IdleAction and relatives.
Definition: viewimp.hxx:196
SwLayAction & GetLayAction()
Definition: viewimp.hxx:198
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:347
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:434
SwViewShellImp * Imp()
Definition: viewsh.hxx:190
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
void Init()
@ MoveFwd
@ MoveBack
#define PROTOCOL_ENTER(pFrame, nFunc, nAct, pPar)
Definition: dbg_lay.hxx:92
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
static bool lcl_getContextualSpacing(const SwFrame *pPrevFrame)
Definition: flowfrm.cxx:1457
static bool lcl_IdenticalStyles(const SwFrame *pPrevFrame, const SwFrame *pFrame)
Compare styles attached to these text frames.
Definition: flowfrm.cxx:1436
MakePageType
Definition: frame.hxx:113
@ MAKEPAGE_INSERT
Definition: frame.hxx:116
@ MAKEPAGE_FTN
Definition: frame.hxx:117
@ MAKEPAGE_NONE
Definition: frame.hxx:114
@ MAKEPAGE_NOSECTION
Definition: frame.hxx:118
@ MAKEPAGE_APPEND
Definition: frame.hxx:115
bool Is_Lower_Of(const SwFrame *pCurrFrame, const SdrObject *pObj)
Definition: frmtool.cxx:3622
void GetSpacingValuesOfFrame(const SwFrame &rFrame, SwTwips &onLowerSpacing, SwTwips &onLineSpacing, bool &obIsLineSpacingProportional, bool bIdenticalStyles)
method to determine the spacing values of a frame
Definition: frmtool.cxx:3961
bool IsFrameInSameContext(const SwFrame *pInnerFrame, const SwFrame *pFrame)
Definition: frmtool.cxx:3668
sal_Int32 nIndex
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
int i
bool IsRightPageByNumber(SwRootFrame const &rLayout, sal_uInt16 nPageNum)
Definition: frmtool.cxx:3133
bool FrameContainsNode(SwContentFrame const &rFrame, SwNodeOffset nNodeIndex)
Definition: txtfrm.cxx:290
long Long
constexpr SwNodeOffset NODE_OFFSET_MAX(SAL_MAX_INT32)
SwTextGridItem const * GetGridItem(SwPageFrame const *const)
Definition: pagechg.cxx:2650
SvxBreak
tools::Long SwTwips
Definition: swtypes.hxx:51
unsigned char sal_uInt8