[Libreoffice-commits] core.git: sw/source

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Tue Dec 22 15:56:55 UTC 2020


 sw/source/uibase/docvw/PageBreakWin.cxx |   49 +++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

New commits:
commit 6156a419a2d3f09d91afd00f84c84ba717442f43
Author:     Justin Luth <justin.luth at collabora.com>
AuthorDate: Sat Dec 19 16:20:46 2020 +0300
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Dec 22 16:56:09 2020 +0100

    tdf#136578 sw BreakDashedLine: edit/delete PageAfter
    
    When you click on the blue dashed line indicating a page break,
    that delete should remove both that page's break-before,
    and the previous paragraph's break-after.
    Also, edit should detect if a break comes from a PageAfter.
    
    Prior to this commit, multiple things were wrong:
    -the previous paragraph wasn't checked, so PageAfter
    breaks were not deleted.
    -edit looked at the wrong para if break was PageAfter.
    -the current paragraph's PageAfter was deleted - deleting
    the NEXT page break, and not THIS one.
    
    I hope only tables are the exception to the rule.
    It doesn't seem to matter which table pNd is set with the
    NONE'd break. In theory, I could edit the real GetBreakItem
    functions to add in that code, but that seems very
    dangerous at this low of a level.
    
    Prior commit d7dfae214384f37901b532618e4d3ef117bd0285
    flattened this function and did other minor cleanup.
    
    Change-Id: I9944c25853ec206f9febb6ea9f4e34c13c770ebb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108072
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/source/uibase/docvw/PageBreakWin.cxx b/sw/source/uibase/docvw/PageBreakWin.cxx
index 5b405d329200..2bd4eaa8abc7 100644
--- a/sw/source/uibase/docvw/PageBreakWin.cxx
+++ b/sw/source/uibase/docvw/PageBreakWin.cxx
@@ -25,6 +25,7 @@
 #include <PostItMgr.hxx>
 #include <FrameControlsManager.hxx>
 #include <strings.hrc>
+#include <tabfrm.hxx>
 #include <uiitems.hxx>
 #include <view.hxx>
 #include <viewopt.hxx>
@@ -221,11 +222,37 @@ void SwPageBreakWin::PaintButton()
     m_xMenuButton->set_custom_button(m_xVirDev.get());
 }
 
+static SvxBreak lcl_GetBreakItem(const SwContentFrame* pCnt)
+{
+    SvxBreak eBreak = SvxBreak::NONE;
+    if ( pCnt )
+    {
+        if ( pCnt->IsInTab() )
+            eBreak =  pCnt->FindTabFrame()->GetBreakItem().GetBreak();
+        else
+            eBreak = pCnt->GetBreakItem().GetBreak();
+    }
+    return eBreak;
+}
+
 IMPL_LINK(SwPageBreakWin, SelectHdl, const OString&, rIdent, void)
 {
     SwFrameControlPtr pThis = GetEditWin()->GetFrameControlsManager( ).GetControl( FrameControlType::PageBreak, GetFrame() );
 
+    // Is there a PageBefore break on this page?
     SwContentFrame *pCnt = const_cast<SwContentFrame*>(GetPageFrame()->FindFirstBodyContent());
+    SvxBreak eBreak = lcl_GetBreakItem( pCnt );
+
+    // Also check the previous page - to see if there is a PageAfter break
+    SwContentFrame *pPrevCnt = nullptr;
+    SvxBreak ePrevBreak = SvxBreak::NONE;
+    const SwPageFrame* pPrevPage = static_cast<const SwPageFrame*>(GetPageFrame()->GetPrev());
+    if ( pPrevPage )
+    {
+        pPrevCnt = const_cast<SwContentFrame*>(pPrevPage->FindLastBodyContent());
+        ePrevBreak = lcl_GetBreakItem( pPrevCnt );
+    }
+
     if (pCnt && rIdent == "edit")
     {
         SwEditWin* pEditWin = GetEditWin();
@@ -234,6 +261,10 @@ IMPL_LINK(SwPageBreakWin, SelectHdl, const OString&, rIdent, void)
         bool bOldLock = rSh.IsViewLocked();
         rSh.LockView( true );
 
+        // Order of edit detection: first RES_BREAK PageAfter, then RES_BREAK PageBefore/RES_PAGEDESC
+        if ( ePrevBreak == SvxBreak::PageAfter )
+            pCnt = pPrevCnt;
+
         SwContentNode& rNd = pCnt->IsTextFrame()
             ? *static_cast<SwTextFrame*>(pCnt)->GetTextNodeFirst()
             : *static_cast<SwNoTextFrame*>(pCnt)->GetNode();
@@ -277,13 +308,29 @@ IMPL_LINK(SwPageBreakWin, SelectHdl, const OString&, rIdent, void)
         SfxItemSet aSet(
             GetEditWin()->GetView().GetWrtShell().GetAttrPool(),
             svl::Items<RES_PAGEDESC, RES_BREAK>{});
-        aSet.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
+
         aSet.Put( SwFormatPageDesc( nullptr ) );
+        // This break could be from the current paragraph, if it has a PageBefore break.
+        if ( eBreak == SvxBreak::PageBefore )
+            aSet.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
 
         SwPaM aPaM( rNd );
         rNd.GetDoc().getIDocumentContentOperations().InsertItemSet(
             aPaM, aSet, SetAttrMode::DEFAULT, GetPageFrame()->getRootFrame());
 
+        // This break could be from the previous paragraph, if it has a PageAfter break.
+        if ( ePrevBreak == SvxBreak::PageAfter )
+        {
+            SwContentNode& rPrevNd = pPrevCnt->IsTextFrame()
+                ? *static_cast<SwTextFrame*>(pPrevCnt)->GetTextNodeFirst()
+                : *static_cast<SwNoTextFrame*>(pPrevCnt)->GetNode();
+            aSet.ClearItem();
+            aSet.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
+            aPaM = SwPaM( rPrevNd );
+            rPrevNd.GetDoc().getIDocumentContentOperations().InsertItemSet(
+                aPaM, aSet, SetAttrMode::DEFAULT, pPrevCnt->getRootFrame());
+        }
+
         rNd.GetDoc().GetIDocumentUndoRedo( ).EndUndo( SwUndoId::UI_DELETE_PAGE_BREAK, nullptr );
     }
 


More information about the Libreoffice-commits mailing list