summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-05-30 02:23:02 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-05-31 09:25:33 +0200
commitc60ad7e0fbf3cc86af167f5e98b38c25620ada7e (patch)
tree396185b09f35dad1adf7fd3f42d344a12c0e8e3f /sw/source
parent5da4acd4818741c3b68be211bd7a21e4c080ed4d (diff)
tdf#160958: merge hidden section's follows; move first-on-page section back
Change-Id: I6bd6707089dcea58d5df4bef63aa769769d97ea9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168235 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/layout/sectfrm.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 23b427c1507b..c92af1303fae 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -833,6 +833,42 @@ void SwSectionFrame::MakeAll(vcl::RenderContext* pRenderContext)
setFramePrintAreaValid(true);
return;
}
+
+ if (!GetPrev() && !IsFollow() && IsInDocBody() && IsHiddenNow())
+ {
+ // This may be the first frame on a page, and it may had moved to that page because its
+ // content required that (a page break in the first paragraph, or a tall first line, or
+ // "do not break paragraph" setting, or the like). Try to move back, to allow following
+ // frames to move back, if possible. Sections cannot move back; workaround by a call to
+ // GetPrevSctLeaf(), which may return a candidate upper frame on a previous page, or it
+ // may create a new master for this at the end of the previous page. Cut and paste this
+ // appropriately; then drop the temporary, if needed.
+ if (SwLayoutFrame* moveBackPos = GetPrevSctLeaf())
+ {
+ SwLayoutFrame* newUpper = moveBackPos;
+ SwFrame* newSibling = nullptr;
+ const bool temporaryMasterCreated = IsFollow();
+ if (temporaryMasterCreated)
+ {
+ assert(moveBackPos == &GetPrecede()->GetFrame());
+ newUpper = moveBackPos->GetUpper();
+ newSibling = moveBackPos->GetNext(); // actually, will be also nullptr
+ }
+ if (newUpper != GetUpper())
+ {
+ // Can't use MoveSubTree, because the move needs to fire events to re-layout
+ Cut();
+ Paste(newUpper, newSibling);
+ }
+ if (temporaryMasterCreated)
+ {
+ moveBackPos->Cut();
+ DestroyFrame(moveBackPos);
+ }
+ assert(!IsFollow());
+ }
+ }
+
LockJoin(); // I don't let myself to be destroyed on the way
while( GetNext() && GetNext() == GetFollow() )
@@ -843,6 +879,17 @@ void SwSectionFrame::MakeAll(vcl::RenderContext* pRenderContext)
break;
}
+ if (GetFollow() && IsHiddenNow())
+ {
+ // Merge all the follows of this hidden section
+ while (auto* follow = GetFollow())
+ {
+ MergeNext(follow);
+ if (GetFollow() == follow) // failed to merge
+ break; // avoid endless loop
+ }
+ }
+
// OD 2004-03-15 #116561# - In online layout join the follows, if section
// can grow.
const SwViewShell *pSh = getRootFrame()->GetCurrShell();
@@ -2677,6 +2724,11 @@ void SwSectionFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint)
{
InvalidateAll();
InvalidateObjs(false);
+ {
+ // Set it to a huge positive value, to make sure a recalculation fires
+ SwFrameAreaDefinition::FrameAreaWriteAccess area(*this);
+ SwRectFnSet(this).SetHeight(area, std::numeric_limits<tools::Long>::max());
+ }
for (SwFrame* pLowerFrame = Lower(); pLowerFrame; pLowerFrame = pLowerFrame->GetNext())
{