sw/source/uibase/docvw/PageBreakWin.cxx |  118 +++++++++++++-------------------
 1 file changed, 49 insertions(+), 69 deletions(-)

New commits:
commit d7dfae214384f37901b532618e4d3ef117bd0285
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Sat Dec 19 22:06:02 2020 +0300
Commit:     Justin Luth <justin_l...@sil.org>
CommitDate: Mon Dec 21 13:26:51 2020 +0100

    NFC flatten PageBreakWin and minor cleanup
    
    Cleanup:
    -everything uses the same pCnt, so do that once and share it.
    -use FindFirstBodyContent to consolidate a lot of ugliness.
    -make pNd into a reference, since it is used unconditionally.
    -had to switch to IsInTab since we only have content frames now.
    
    Change-Id: I0ce66e98ea915152ef534e7719100da7cd6ca2db
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108071
    Tested-by: Justin Luth <justin_l...@sil.org>
    Reviewed-by: Justin Luth <justin_l...@sil.org>

diff --git a/sw/source/uibase/docvw/PageBreakWin.cxx 
b/sw/source/uibase/docvw/PageBreakWin.cxx
index 6167369ba219..5b405d329200 100644
--- a/sw/source/uibase/docvw/PageBreakWin.cxx
+++ b/sw/source/uibase/docvw/PageBreakWin.cxx
@@ -225,86 +225,66 @@ IMPL_LINK(SwPageBreakWin, SelectHdl, const OString&, 
rIdent, void)
 {
     SwFrameControlPtr pThis = GetEditWin()->GetFrameControlsManager( 
).GetControl( FrameControlType::PageBreak, GetFrame() );
 
-    if (rIdent == "edit")
+    SwContentFrame *pCnt = 
const_cast<SwContentFrame*>(GetPageFrame()->FindFirstBodyContent());
+    if (pCnt && rIdent == "edit")
     {
-        const SwLayoutFrame* pBodyFrame = static_cast< const SwLayoutFrame* >( 
GetPageFrame()->Lower() );
-        while ( pBodyFrame && !pBodyFrame->IsBodyFrame() )
-            pBodyFrame = static_cast< const SwLayoutFrame* >( 
pBodyFrame->GetNext() );
-
         SwEditWin* pEditWin = GetEditWin();
 
-        if ( pBodyFrame )
+        SwWrtShell& rSh = pEditWin->GetView().GetWrtShell();
+        bool bOldLock = rSh.IsViewLocked();
+        rSh.LockView( true );
+
+        SwContentNode& rNd = pCnt->IsTextFrame()
+            ? *static_cast<SwTextFrame*>(pCnt)->GetTextNodeFirst()
+            : *static_cast<SwNoTextFrame*>(pCnt)->GetNode();
+
+        if ( pCnt->IsInTab() )
+        {
+            rSh.Push( );
+            rSh.ClearMark();
+
+            rSh.SetSelection( rNd );
+
+            SfxStringItem 
aItem(pEditWin->GetView().GetPool().GetWhich(FN_FORMAT_TABLE_DLG), "textflow");
+            pEditWin->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
+                    FN_FORMAT_TABLE_DLG,
+                    SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
+                    { &aItem });
+
+            rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
+        }
+        else
         {
-            SwWrtShell& rSh = pEditWin->GetView().GetWrtShell();
-            bool bOldLock = rSh.IsViewLocked();
-            rSh.LockView( true );
-
-            if ( pBodyFrame->Lower()->IsTabFrame() )
-            {
-                rSh.Push( );
-                rSh.ClearMark();
-
-                SwContentFrame *pCnt = const_cast< SwContentFrame* >( 
pBodyFrame->ContainsContent() );
-                SwContentNode* pNd = pCnt->IsTextFrame()
-                    ? static_cast<SwTextFrame*>(pCnt)->GetTextNodeFirst()
-                    : static_cast<SwNoTextFrame*>(pCnt)->GetNode();
-                rSh.SetSelection( *pNd );
-
-                SfxStringItem 
aItem(pEditWin->GetView().GetPool().GetWhich(FN_FORMAT_TABLE_DLG), "textflow");
-                
pEditWin->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
-                        FN_FORMAT_TABLE_DLG,
-                        SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
-                        { &aItem });
-
-                rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
-            }
-            else
-            {
-                SwContentFrame *pCnt = const_cast< SwContentFrame* >( 
pBodyFrame->ContainsContent() );
-                SwContentNode* pNd = pCnt->IsTextFrame()
-                    ? static_cast<SwTextFrame*>(pCnt)->GetTextNodeFirst()
-                    : static_cast<SwNoTextFrame*>(pCnt)->GetNode();
-
-                SwPaM aPaM( *pNd );
-                SwPaMItem aPaMItem( pEditWin->GetView().GetPool( ).GetWhich( 
FN_PARAM_PAM ), &aPaM );
-                SfxStringItem aItem( pEditWin->GetView().GetPool( ).GetWhich( 
SID_PARA_DLG ), "textflow" );
-                
pEditWin->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
-                        SID_PARA_DLG,
-                        SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
-                        { &aItem, &aPaMItem });
-            }
-            rSh.LockView( bOldLock );
-            pEditWin->GrabFocus( );
+            SwPaM aPaM( rNd );
+            SwPaMItem aPaMItem( pEditWin->GetView().GetPool( ).GetWhich( 
FN_PARAM_PAM ), &aPaM );
+            SfxStringItem aItem( pEditWin->GetView().GetPool( ).GetWhich( 
SID_PARA_DLG ), "textflow" );
+            pEditWin->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
+                    SID_PARA_DLG,
+                    SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
+                    { &aItem, &aPaMItem });
         }
+        rSh.LockView( bOldLock );
+        pEditWin->GrabFocus( );
     }
-    else if (rIdent == "delete")
+    else if (pCnt && rIdent == "delete")
     {
-        const SwLayoutFrame* pBodyFrame = static_cast< const SwLayoutFrame* >( 
GetPageFrame()->Lower() );
-        while ( pBodyFrame && !pBodyFrame->IsBodyFrame() )
-            pBodyFrame = static_cast< const SwLayoutFrame* >( 
pBodyFrame->GetNext() );
-
-        if ( pBodyFrame )
-        {
-
-            SwContentFrame *pCnt = const_cast< SwContentFrame* >( 
pBodyFrame->ContainsContent() );
-            SwContentNode* pNd = pCnt->IsTextFrame()
-                ? static_cast<SwTextFrame*>(pCnt)->GetTextNodeFirst()
-                : static_cast<SwNoTextFrame*>(pCnt)->GetNode();
+        SwContentNode& rNd = pCnt->IsTextFrame()
+            ? *static_cast<SwTextFrame*>(pCnt)->GetTextNodeFirst()
+            : *static_cast<SwNoTextFrame*>(pCnt)->GetNode();
 
-            pNd->GetDoc().GetIDocumentUndoRedo( ).StartUndo( 
SwUndoId::UI_DELETE_PAGE_BREAK, nullptr );
+        rNd.GetDoc().GetIDocumentUndoRedo( ).StartUndo( 
SwUndoId::UI_DELETE_PAGE_BREAK, nullptr );
 
-            SfxItemSet aSet(
-                GetEditWin()->GetView().GetWrtShell().GetAttrPool(),
-                svl::Items<RES_PAGEDESC, RES_BREAK>{});
-            aSet.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
-            aSet.Put( SwFormatPageDesc( nullptr ) );
+        SfxItemSet aSet(
+            GetEditWin()->GetView().GetWrtShell().GetAttrPool(),
+            svl::Items<RES_PAGEDESC, RES_BREAK>{});
+        aSet.Put( SvxFormatBreakItem( SvxBreak::NONE, RES_BREAK ) );
+        aSet.Put( SwFormatPageDesc( nullptr ) );
 
-            SwPaM aPaM( *pNd );
-            pNd->GetDoc().getIDocumentContentOperations().InsertItemSet(
-                aPaM, aSet, SetAttrMode::DEFAULT, 
GetPageFrame()->getRootFrame());
+        SwPaM aPaM( rNd );
+        rNd.GetDoc().getIDocumentContentOperations().InsertItemSet(
+            aPaM, aSet, SetAttrMode::DEFAULT, GetPageFrame()->getRootFrame());
 
-            pNd->GetDoc().GetIDocumentUndoRedo( ).EndUndo( 
SwUndoId::UI_DELETE_PAGE_BREAK, nullptr );
-        }
+        rNd.GetDoc().GetIDocumentUndoRedo( ).EndUndo( 
SwUndoId::UI_DELETE_PAGE_BREAK, nullptr );
     }
 
     // Only fade if there is more than this temporary shared pointer:
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to