sw/source/core/inc/flyfrm.hxx                                      |    2 
 sw/source/core/inc/flyfrms.hxx                                     |    7 -
 sw/source/core/inc/frame.hxx                                       |    1 
 sw/source/core/inc/txtfrm.hxx                                      |    4 
 sw/source/core/layout/anchoredobject.cxx                           |   19 +++
 sw/source/core/layout/flowfrm.cxx                                  |    4 
 sw/source/core/layout/fly.cxx                                      |   13 +-
 sw/source/core/layout/flycnt.cxx                                   |   59 
++++++----
 sw/source/core/layout/flylay.cxx                                   |    4 
 sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx |   18 +++
 sw/source/core/text/frmform.cxx                                    |   12 ++
 sw/source/core/text/itratr.cxx                                     |   32 +++++
 sw/source/core/text/itrform2.cxx                                   |   20 +++
 13 files changed, 168 insertions(+), 27 deletions(-)

New commits:
commit 57fb11a8b8a1510625bc9261ccf35ac36de59a34
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Feb 7 13:43:12 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 28 09:08:58 2023 +0100

    sw: fix anchoring in SwFrame::GetNextFlyLeaf()
    
    The core of this change is in SwFrame::GetNextFlyLeaf(), which used to
    assume that there is a next frame after the fly's anchor, but it's
    perfectly valid to not have such a frame. Instead if a fly is split,
    then also split its anchor, so effectively only the last follow of such
    anchor hosts content, all the others are empty and only serve as an
    anchor of a non-last member of a split fly frame chain.
    
    Once this anchoring is changed, adjustments are needed at other places,
    so a sample split fly frame (2 paragraphs, 1st para on first page, 2nd
    para on second page) is still layout out correctly:
    
    - SwAnchoredObject::FindAnchorCharFrame(): return the right follow text
      frame for follow flys. This is needed because flys have to be anchored
      to masters, and then this function can find the frame that's used for
      positioning.
    
    - SwFlyFrame::Format(): get the rectangle of the correct body frame,
      otherwise we would get the bottom of the 1st body frame instead of the
      2nd body frame for the follow fly, leading to a negative height of the
      follow fly frame.
    
    - SwToContentAnchoredObjectPosition::CalcPosition(): position against
      the right follow text frame, similar to
      SwAnchoredObject::FindAnchorCharFrame().
    
    - SwTextFrame::AdjustFollow_(): don't join a master with its follow if
      there is a split fly frame anchored in the master. The assumption is
      that first the fly has to be moved away, then we can do such a join.
    
    - Introduce a SwTextFrame::GetSplitFlyDrawObjs() to avoid copy&paste in
      SwTextFrame::AdjustFollow_() & SwTextFormatter::FormatLine().
    
    With this, a sample split fly frame is split to two pages with correct
    anchors if SW_FORCE_FLY_SPLIT=1 is set. The anchor frame has duplicated
    text on the 1st and 2nd page still, though.
    
    Towards an initial working layout for multi-page fly frames.
    
    (cherry picked from commit ddfb800e60d98340c99c8013f6df3f2060687dd0)
    
    Change-Id: Ie99b13c2e318ec63f69c8a47bbc604771509e24a

diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index 3fd73ea2c6ec..cb22ebc439f8 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -50,6 +50,7 @@ enum class ExpandMode;
 class SwTextAttr;
 class SwWrtShell;
 class SwNode;
+class SwFlyAtContentFrame;
 
 #define NON_PRINTING_CHARACTER_COLOR Color(0x26, 0x8b, 0xd2)
 
@@ -783,6 +784,9 @@ public:
     OUString GetCurWord(SwPosition const&) const;
     sal_uInt16 GetScalingOfSelectedText(TextFrameIndex nStt, TextFrameIndex 
nEnd);
 
+    /// Like GetDrawObjs(), but limit to fly frames which are allowed to split.
+    std::vector<SwFlyAtContentFrame*> GetSplitFlyDrawObjs();
+
     virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override;
 };
 
diff --git a/sw/source/core/layout/anchoredobject.cxx 
b/sw/source/core/layout/anchoredobject.cxx
index 130a5d8c7553..4272437f9e25 100644
--- a/sw/source/core/layout/anchoredobject.cxx
+++ b/sw/source/core/layout/anchoredobject.cxx
@@ -31,6 +31,7 @@
 #include <pagefrm.hxx>
 #include <layouter.hxx>
 #include <osl/diagnose.h>
+#include <flyfrms.hxx>
 
 using namespace ::com::sun::star;
 
@@ -716,6 +717,24 @@ SwTextFrame* SwAnchoredObject::FindAnchorCharFrame()
             TextFrameIndex const 
nOffset(pFrame->MapModelToViewPos(*rAnch.GetContentAnchor()));
             pAnchorCharFrame = &pFrame->GetFrameAtOfst(nOffset);
         }
+        else if (SwFlyFrame* pFlyFrame = DynCastFlyFrame())
+        {
+            // See if this fly is split. If so, then the anchor is also split. 
All anchors are
+            // empty, except the last follow.
+            if (pFlyFrame->IsFlySplitAllowed())
+            {
+                auto pFlyAtContentFrame = 
static_cast<SwFlyAtContentFrame*>(pFlyFrame);
+                if (pFlyAtContentFrame->GetPrecede())
+                {
+                    SwTextFrame* 
pFrame(static_cast<SwTextFrame*>(AnchorFrame()));
+                    const SwTextFrame* pFollow = pFrame->GetFollow();
+                    if (pFollow)
+                    {
+                        pAnchorCharFrame = const_cast<SwTextFrame*>(pFollow);
+                    }
+                }
+            }
+        }
     }
 
     return pAnchorCharFrame;
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index e256a0b9e0ac..91c0f0549680 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -1318,6 +1318,12 @@ void SwFlyFrame::Format( vcl::RenderContext* 
/*pRenderContext*/, const SwBorderA
                 nRemaining = MINFLY;
 
             const SwFrame* pAnchor = GetAnchorFrame();
+            if (SwFrame* pAnchorChar = FindAnchorCharFrame())
+            {
+                // If we find a follow of the anchor that is effectively the 
anchor of this fly,
+                // then use that as the anchor for sizing purposes.
+                pAnchor = pAnchorChar;
+            }
             const SwFrame* pAnchorUpper = pAnchor ? pAnchor->GetUpper() : 
nullptr;
             if (pAnchorUpper && IsFlySplitAllowed())
             {
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index 2fcd1723d0fc..474d21bd7f97 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -1566,24 +1566,18 @@ SwLayoutFrame *SwFrame::GetNextFlyLeaf( MakePageType 
eMakePage )
     {
         SwFlyAtContentFrame* pNew = nullptr;
         SwFrame* pFlyAnchor = const_cast<SwFrame*>(pFly->GetAnchorFrame());
-        if (pFlyAnchor)
+        if (pFlyAnchor && pFlyAnchor->IsTextFrame())
         {
-            SwFrame* pTmp = pFlyAnchor->GetNext();
-            if (pTmp)
-            {
-                SwFlowFrame* pNxt = nullptr;
-                if (pTmp->IsContentFrame())
-                {
-                    pNxt = static_cast<SwContentFrame*>(pTmp);
-                }
-                if (pNxt)
-                {
-                    pNxt->MoveSubTree(pLayLeaf);
-
-                    pNew = new SwFlyAtContentFrame( *pFly );
-                    pNxt->GetFrame().AppendFly( pNew );
-                }
-            }
+            // Split the anchor at char 0: all the content goes to the follow 
of the anchor.
+            auto pFlyAnchorTextFrame = static_cast<SwTextFrame*>(pFlyAnchor);
+            pFlyAnchorTextFrame->SplitFrame(TextFrameIndex(0));
+            auto pNext = static_cast<SwTextFrame*>(pFlyAnchor->GetNext());
+            pNext->MoveSubTree(pLayLeaf);
+
+            // Now create the follow of the fly and anchor it in the just 
created follow of the
+            // anchor.
+            pNew = new SwFlyAtContentFrame(*pFly);
+            pFlyAnchorTextFrame->AppendFly(pNew);
         }
         pLayLeaf = pNew;
     }
diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx 
b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
index 700b737b1689..7a9dd8546a3a 100644
--- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
@@ -41,6 +41,7 @@
 #include <fmtwrapinfluenceonobjpos.hxx>
 #include <sortedobjs.hxx>
 #include <textboxhelper.hxx>
+#include <flyfrms.hxx>
 
 using namespace ::com::sun::star;
 
@@ -225,6 +226,23 @@ void SwToContentAnchoredObjectPosition::CalcPosition()
                 
rAnchorTextFrame.MapModelToViewPos(*rAnch.GetContentAnchor())));
             mpToCharOrientFrame = pOrientFrame;
         }
+        else if (SwFlyFrame* pFlyFrame = GetAnchoredObj().DynCastFlyFrame())
+        {
+            // See if this fly is split. If so, then the anchor is also split. 
All anchors are
+            // empty, except the last follow.
+            if (pFlyFrame->IsFlySplitAllowed())
+            {
+                auto pFlyAtContentFrame = 
static_cast<SwFlyAtContentFrame*>(pFlyFrame);
+                if (pFlyAtContentFrame->GetPrecede())
+                {
+                    const SwTextFrame* pFollow = rAnchorTextFrame.GetFollow();
+                    if (pFollow)
+                    {
+                        pOrientFrame = pFollow;
+                    }
+                }
+            }
+        }
     }
     aRectFnSet.Refresh(pOrientFrame);
 
diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx
index 19dcb6e3ed5f..31becc976597 100644
--- a/sw/source/core/text/frmform.cxx
+++ b/sw/source/core/text/frmform.cxx
@@ -49,6 +49,7 @@
 #include <editeng/tstpitem.hxx>
 #include <redline.hxx>
 #include <comphelper/lok.hxx>
+#include <flyfrms.hxx>
 
 // Tolerance in formatting and text output
 #define SLOPPY_TWIPS    5
@@ -579,6 +580,17 @@ void SwTextFrame::AdjustFollow_( SwTextFormatter &rLine,
             }
             if (GetFollow()->IsDeleteForbidden())
                 return;
+
+            for (const auto& pFlyFrame : GetSplitFlyDrawObjs())
+            {
+                // If a fly frame is anchored to us that has a follow, then 
don't join the anchor.
+                // First those fly frames have to be joined.
+                if (pFlyFrame->GetFollow())
+                {
+                    return;
+                }
+            }
+
             JoinFrame();
         }
 
diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx
index d78a687a23d1..41431bf4b715 100644
--- a/sw/source/core/text/itratr.cxx
+++ b/sw/source/core/text/itratr.cxx
@@ -57,6 +57,10 @@
 #include <editeng/lrspitem.hxx>
 #include <calbck.hxx>
 #include <frameformats.hxx>
+#include <sortedobjs.hxx>
+#include <anchoredobject.hxx>
+#include <flyfrm.hxx>
+#include <flyfrms.hxx>
 
 using namespace ::com::sun::star::i18n;
 using namespace ::com::sun::star;
@@ -1448,6 +1452,34 @@ sal_uInt16 SwTextFrame::GetScalingOfSelectedText(
     return o3tl::narrowing<sal_uInt16>( nWidth ? ((100 * 
aIter.GetFnt()->GetTextSize_( aDrawInf ).Height()) / nWidth ) : 0 );
 }
 
+std::vector<SwFlyAtContentFrame*> SwTextFrame::GetSplitFlyDrawObjs()
+{
+    std::vector<SwFlyAtContentFrame*> aObjs;
+    SwSortedObjs* pSortedObjs = GetDrawObjs();
+    if (!pSortedObjs)
+    {
+        return aObjs;
+    }
+
+    for (const auto& pSortedObj : *pSortedObjs)
+    {
+        SwFlyFrame* pFlyFrame = pSortedObj->DynCastFlyFrame();
+        if (!pFlyFrame)
+        {
+            continue;
+        }
+
+        if (!pFlyFrame->IsFlySplitAllowed())
+        {
+            continue;
+        }
+
+        aObjs.push_back(static_cast<SwFlyAtContentFrame*>(pFlyFrame));
+    }
+
+    return aObjs;
+}
+
 SwTwips SwTextNode::GetWidthOfLeadingTabs() const
 {
     SwTwips nRet = 0;
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 48ad43bde8ef..e65468d62d4c 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1936,36 +1936,19 @@ TextFrameIndex 
SwTextFormatter::FormatLine(TextFrameIndex const nStartPos)
             if (m_pFrame)
             {
                 // Don't oversize the line in case of split flys, so we don't 
try to move the anchor
-                // of a precede fly forward.
+                // of a precede fly forward, next to its follow.
                 bool bHasNonLastFlySplitAnchored = false;
-                SwSortedObjs* pSortedObjs = m_pFrame->GetDrawObjs();
-                if (pSortedObjs)
+                for (const auto& pFlyFrame : m_pFrame->GetSplitFlyDrawObjs())
                 {
-                    for (const auto& pSortedObj : *pSortedObjs)
+                    if (pFlyFrame->GetFollow())
                     {
-                        SwFlyFrame* pFlyFrame = pSortedObj->DynCastFlyFrame();
-                        if (!pFlyFrame)
-                        {
-                            continue;
-                        }
-
-                        if (!pFlyFrame->IsFlySplitAllowed())
-                        {
-                            continue;
-                        }
-
-                        auto pFlyAtContentFrame = 
static_cast<SwFlyAtContentFrame*>(pFlyFrame);
-                        if (pFlyAtContentFrame->GetFollow())
-                        {
-                            bHasNonLastFlySplitAnchored = true;
-                            break;
-                        }
+                        bHasNonLastFlySplitAnchored = true;
+                        break;
                     }
                 }
-
                 if (bHasNonLastFlySplitAnchored)
                 {
-                    m_pCurr->SetRealHeight( GetFrameRstHeight() );
+                    m_pCurr->SetRealHeight(GetFrameRstHeight());
                 }
             }
 
commit 24a8679b1737193ab17be0b987bb03aee511a596
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Feb 7 08:23:50 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 28 09:08:58 2023 +0100

    sw: handle split flys in SwTextFormatter::FormatLine()
    
    One workaround in SwFrame::GetNextFlyLeaf() is to assume that there is
    always a next frame after the fly's anchor when we split the fly. An
    alternative to this is to split the fly's anchor as well, so we always
    have a next such frame.
    
    When this happens, we hit various problems, the first is that once we
    have 2 flys after the split, we try to move the first fly to page 2 as
    well.
    
    The reason for this appears to be that SwTextFormatter::FormatLine()
    sets the height of the line in the fly's anchor to 1 twip larger than
    the available space. Disable this tweak when the only reason that text
    frame is on the page to serve as an anchor. We definitely don't want to
    move it to the next page, arguing it's too large.
    
    Towards an initial layout for multi-page fly frames.
    
    (cherry picked from commit 6275bd9db475cb984ac153d06ed1ddadfa2fadb7)
    
    Change-Id: Ia7b7a93ff78af640366fb49e30e910e5f4e0e0a2

diff --git a/sw/source/core/inc/flyfrms.hxx b/sw/source/core/inc/flyfrms.hxx
index 39f9c1dbf2f5..608e04ff8f11 100644
--- a/sw/source/core/inc/flyfrms.hxx
+++ b/sw/source/core/inc/flyfrms.hxx
@@ -179,6 +179,7 @@ public:
 
     SwFlyAtContentFrame( SwFlyFrameFormat*, SwFrame*, SwFrame *pAnchor, bool 
bFollow = false );
     SwFlyAtContentFrame(SwFlyAtContentFrame& rPrecede);
+    ~SwFlyAtContentFrame();
 
     void SetAbsPos( const Point &rNew );
 
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index 2d4c9a373796..2fcd1723d0fc 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -90,6 +90,10 @@ 
SwFlyAtContentFrame::SwFlyAtContentFrame(SwFlyAtContentFrame& rPrecede)
     rPrecede.SetFollow(this);
 }
 
+SwFlyAtContentFrame::~SwFlyAtContentFrame()
+{
+}
+
 // #i28701#
 
 void SwFlyAtContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& 
rHint)
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 91f73ed87825..48ad43bde8ef 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1932,6 +1932,43 @@ TextFrameIndex 
SwTextFormatter::FormatLine(TextFrameIndex const nStartPos)
             m_pCurr->SetLen(TextFrameIndex(0));
             m_pCurr->Height( GetFrameRstHeight() + 1, false );
             m_pCurr->SetRealHeight( GetFrameRstHeight() + 1 );
+
+            if (m_pFrame)
+            {
+                // Don't oversize the line in case of split flys, so we don't 
try to move the anchor
+                // of a precede fly forward.
+                bool bHasNonLastFlySplitAnchored = false;
+                SwSortedObjs* pSortedObjs = m_pFrame->GetDrawObjs();
+                if (pSortedObjs)
+                {
+                    for (const auto& pSortedObj : *pSortedObjs)
+                    {
+                        SwFlyFrame* pFlyFrame = pSortedObj->DynCastFlyFrame();
+                        if (!pFlyFrame)
+                        {
+                            continue;
+                        }
+
+                        if (!pFlyFrame->IsFlySplitAllowed())
+                        {
+                            continue;
+                        }
+
+                        auto pFlyAtContentFrame = 
static_cast<SwFlyAtContentFrame*>(pFlyFrame);
+                        if (pFlyAtContentFrame->GetFollow())
+                        {
+                            bHasNonLastFlySplitAnchored = true;
+                            break;
+                        }
+                    }
+                }
+
+                if (bHasNonLastFlySplitAnchored)
+                {
+                    m_pCurr->SetRealHeight( GetFrameRstHeight() );
+                }
+            }
+
             m_pCurr->Width(0);
             m_pCurr->Truncate();
             return nStartPos;
commit ba5234cde0e8319efcb3ce5ac21e7f5b8b9060d4
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Feb 6 08:21:02 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 28 09:08:58 2023 +0100

    sw: implement SwFrame::GetPrevFlyLeaf()
    
    This is much easier than the "next" case, since here we can nullptr when
    there is no previous leaf instead of creating one.
    
    With this, if the MoveBwd() call in SwContentFrame::MakeAll() is
    disabled, some simple fly frame can be split across 2 pages if it's
    positioned in a way that the rectangle of the fly would not fit into the
    body frame without changing the position, in SW_FORCE_FLY_SPLIT=1 mode.
    
    Towards an initial layout for multi-page fly frames.
    
    (cherry picked from commit 27fbab13557a75b5402c11a1697541edc124116a)
    
    Change-Id: I3b6ba85ad66117b5595a113d688e2fcb97bcf745

diff --git a/sw/source/core/inc/flyfrms.hxx b/sw/source/core/inc/flyfrms.hxx
index 61a40d8a8f8c..39f9c1dbf2f5 100644
--- a/sw/source/core/inc/flyfrms.hxx
+++ b/sw/source/core/inc/flyfrms.hxx
@@ -195,6 +195,8 @@ public:
     virtual bool IsFormatPossible() const override;
     const SwFlyAtContentFrame* GetFollow() const;
     SwFlyAtContentFrame* GetFollow();
+    const SwFlyAtContentFrame* GetPrecede() const;
+    SwFlyAtContentFrame* GetPrecede();
 };
 
 // Flys that are bound to a character in Content
diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx
index 8102a7e26e56..e610de6eab70 100644
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@ -549,6 +549,7 @@ public:
     SwLayoutFrame *GetPrevLeaf   ();
     SwLayoutFrame *GetPrevFootnoteLeaf( MakePageType eMakeFootnote );
     SwLayoutFrame *GetPrevSctLeaf();
+    SwLayoutFrame *GetPrevFlyLeaf();
     SwLayoutFrame *GetPrevCellLeaf();
     const SwLayoutFrame *GetLeaf ( MakePageType eMakePage, bool bFwd,
                                  const SwFrame *pAnch ) const;
diff --git a/sw/source/core/layout/flowfrm.cxx 
b/sw/source/core/layout/flowfrm.cxx
index 9939dceafa1b..e53d32b9fa20 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -883,6 +883,10 @@ SwLayoutFrame *SwFrame::GetLeaf( MakePageType eMakePage, 
bool bFwd )
         {
             return GetNextFlyLeaf(eMakePage);
         }
+        else
+        {
+            return GetPrevFlyLeaf();
+        }
     }
 
     return bFwd ? GetNextLeaf( eMakePage ) : GetPrevLeaf();
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index 427ac5b9c37b..2d4c9a373796 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -1586,4 +1586,25 @@ SwLayoutFrame *SwFrame::GetNextFlyLeaf( MakePageType 
eMakePage )
     return pLayLeaf;
 }
 
+const SwFlyAtContentFrame* SwFlyAtContentFrame::GetPrecede() const
+{
+    return static_cast<const SwFlyAtContentFrame*>(SwFlowFrame::GetPrecede());
+}
+
+SwFlyAtContentFrame* SwFlyAtContentFrame::GetPrecede()
+{
+    return static_cast<SwFlyAtContentFrame*>(SwFlowFrame::GetPrecede());
+}
+
+SwLayoutFrame* SwFrame::GetPrevFlyLeaf()
+{
+    auto pFly = dynamic_cast<SwFlyAtContentFrame*>(FindFlyFrame());
+    if (!pFly->IsFlySplitAllowed())
+    {
+        return nullptr;
+    }
+
+    return pFly->GetPrecede();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 34cbc037304107d3cbc2a480a63cd32dcde0ad41
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Feb 3 08:17:57 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 28 09:08:58 2023 +0100

    sw: avoid unwanted initial content in split/follow fly frames
    
    If the fly on the first gets split, SwFrame::GetNextFlyLeaf() will
    create a follow fly frame. Don't fill this one with content, we'll
    instead want to move some of the content of the master here. (Which is
    not yet working.)
    
    InsertCnt() is called *really* early, so we can't check if this frame
    has a master -- just pass a bool around instead.
    
    This fixes the unwanted first paragraph in the follow fly frame at
    least. (The one that fits the master already.)
    
    Towards an initial layout for multi-page fly frames.
    
    (cherry picked from commit 8855813f8147f430348a32703b89dfb7b0793fee)
    
    Change-Id: If364fdaf7595fbc5addbc6b3b3b0092e958c5380

diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx
index 1931054b0ce0..cc6d969401bf 100644
--- a/sw/source/core/inc/flyfrm.hxx
+++ b/sw/source/core/inc/flyfrm.hxx
@@ -147,7 +147,7 @@ protected:
 
     Size CalcRel( const SwFormatFrameSize &rSz ) const;
 
-    SwFlyFrame( SwFlyFrameFormat*, SwFrame*, SwFrame *pAnchor );
+    SwFlyFrame( SwFlyFrameFormat*, SwFrame*, SwFrame *pAnchor, bool bFollow = 
false );
 
     virtual void DestroyImpl() override;
     virtual ~SwFlyFrame() override;
diff --git a/sw/source/core/inc/flyfrms.hxx b/sw/source/core/inc/flyfrms.hxx
index 01ac3872dcd6..61a40d8a8f8c 100644
--- a/sw/source/core/inc/flyfrms.hxx
+++ b/sw/source/core/inc/flyfrms.hxx
@@ -71,7 +71,7 @@ protected:
     friend class SwFlyNotify;
     virtual void NotifyBackground( SwPageFrame *pPage,
                                    const SwRect& rRect, PrepareHint eHint) 
override;
-    SwFlyFreeFrame( SwFlyFrameFormat*, SwFrame*, SwFrame *pAnchor );
+    SwFlyFreeFrame( SwFlyFrameFormat*, SwFrame*, SwFrame *pAnchor, bool 
bFollow = false );
 
     virtual void DestroyImpl() override;
     virtual ~SwFlyFreeFrame() override;
@@ -177,7 +177,7 @@ class SwFlyAtContentFrame final: public SwFlyFreeFrame, 
public SwFlowFrame
 public:
     // #i28701#
 
-    SwFlyAtContentFrame( SwFlyFrameFormat*, SwFrame*, SwFrame *pAnchor );
+    SwFlyAtContentFrame( SwFlyFrameFormat*, SwFrame*, SwFrame *pAnchor, bool 
bFollow = false );
     SwFlyAtContentFrame(SwFlyAtContentFrame& rPrecede);
 
     void SetAbsPos( const Point &rNew );
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 91188af711c9..e256a0b9e0ac 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -81,7 +81,7 @@ using namespace ::com::sun::star;
 
 static SwTwips lcl_CalcAutoWidth( const SwLayoutFrame& rFrame );
 
-SwFlyFrame::SwFlyFrame( SwFlyFrameFormat *pFormat, SwFrame* pSib, SwFrame 
*pAnch ) :
+SwFlyFrame::SwFlyFrame( SwFlyFrameFormat *pFormat, SwFrame* pSib, SwFrame 
*pAnch, bool bFollow ) :
     SwLayoutFrame( pFormat, pSib ),
      // #i26791#
     m_pPrevLink( nullptr ),
@@ -171,7 +171,10 @@ SwFlyFrame::SwFlyFrame( SwFlyFrameFormat *pFormat, 
SwFrame* pSib, SwFrame *pAnch
 
     Chain( pAnch );
 
-    InsertCnt();
+    if (!bFollow)
+    {
+        InsertCnt();
+    }
 
     // Put it somewhere outside so that out document is not formatted 
unnecessarily often
     SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index c2fd6bc28666..427ac5b9c37b 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -74,8 +74,8 @@ SwTwips lcl_GetTopForObjPos(const SwContentFrame* pCnt, const 
bool bVert, const
 
 }
 
-SwFlyAtContentFrame::SwFlyAtContentFrame( SwFlyFrameFormat *pFormat, SwFrame* 
pSib, SwFrame *pAnch ) :
-    SwFlyFreeFrame( pFormat, pSib, pAnch ),
+SwFlyAtContentFrame::SwFlyAtContentFrame( SwFlyFrameFormat *pFormat, SwFrame* 
pSib, SwFrame *pAnch, bool bFollow ) :
+    SwFlyFreeFrame( pFormat, pSib, pAnch, bFollow ),
     SwFlowFrame(static_cast<SwFrame&>(*this))
 {
     m_bAtCnt = true;
@@ -84,7 +84,7 @@ SwFlyAtContentFrame::SwFlyAtContentFrame( SwFlyFrameFormat 
*pFormat, SwFrame* pS
 
 SwFlyAtContentFrame::SwFlyAtContentFrame(SwFlyAtContentFrame& rPrecede)
     : SwFlyAtContentFrame(rPrecede.GetFormat(), 
const_cast<SwFrame*>(rPrecede.GetAnchorFrame()),
-                          const_cast<SwFrame*>(rPrecede.GetAnchorFrame()))
+                          const_cast<SwFrame*>(rPrecede.GetAnchorFrame()), 
/*bFollow=*/true)
 {
     SetFollow(rPrecede.GetFollow());
     rPrecede.SetFollow(this);
diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx
index 05770eeed33a..b1bfe32aab10 100644
--- a/sw/source/core/layout/flylay.cxx
+++ b/sw/source/core/layout/flylay.cxx
@@ -52,8 +52,8 @@
 
 using namespace ::com::sun::star;
 
-SwFlyFreeFrame::SwFlyFreeFrame( SwFlyFrameFormat *pFormat, SwFrame* pSib, 
SwFrame *pAnch )
-:   SwFlyFrame( pFormat, pSib, pAnch ),
+SwFlyFreeFrame::SwFlyFreeFrame( SwFlyFrameFormat *pFormat, SwFrame* pSib, 
SwFrame *pAnch, bool bFollow )
+:   SwFlyFrame( pFormat, pSib, pAnch, bFollow ),
     // #i34753#
     mbNoMakePos( false ),
     // #i37068#

Reply via email to