diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-08-10 10:15:33 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-08-29 13:13:16 +0200 |
commit | f075c30ed6b7820a7723cf18049c2ec2384c5dab (patch) | |
tree | 0b5454b01026652177e466a1cac2d9b96879cbea | |
parent | 978a54b99d7e2df9c0df61cdc3d4153a005618b0 (diff) |
Refactor duplicated code in SwFrame::InsertPage
Change-Id: Iff9a78cf2f5e6ded4d1b03a8303529aa324ddad9
-rw-r--r-- | sw/source/core/inc/rootfrm.hxx | 8 | ||||
-rw-r--r-- | sw/source/core/layout/pagechg.cxx | 75 |
2 files changed, 45 insertions, 38 deletions
diff --git a/sw/source/core/inc/rootfrm.hxx b/sw/source/core/inc/rootfrm.hxx index 66dc0ecf0601..078a8380b29d 100644 --- a/sw/source/core/inc/rootfrm.hxx +++ b/sw/source/core/inc/rootfrm.hxx @@ -58,6 +58,12 @@ namespace o3tl template<> struct typed_flags<SwInvalidateFlags> : is_typed_flags<SwInvalidateFlags, 0x7f> {}; }; +enum class SwRemoveResult +{ + Next, + Prev +}; + /// The root element of a Writer document layout. class SwRootFrame: public SwLayoutFrame { @@ -385,6 +391,8 @@ public: bool IsLayoutFreezed() const { return mbLayoutFreezed; } void FreezeLayout( bool freeze ) { mbLayoutFreezed = freeze; } + + void RemovePage( SwPageFrame **pDel, SwRemoveResult eResult ); }; inline long SwRootFrame::GetBrowseWidth() const diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx index 6375f8cb0386..b679cc6d2cf3 100644 --- a/sw/source/core/layout/pagechg.cxx +++ b/sw/source/core/layout/pagechg.cxx @@ -1158,6 +1158,27 @@ namespace const SwFrame* pBodyContent = pBody ? pBody->Lower() : nullptr; return pBodyContent && pBodyContent->IsDeleteForbidden(); } + + bool doInsertPage( SwRootFrame *pRoot, SwPageFrame **pRefSibling, + SwFrameFormat *pFormat, SwPageDesc *pDesc, + bool bFootnote, SwPageFrame **pRefPage ) + { + SwPageFrame *pPage = new SwPageFrame(pFormat, pRoot, pDesc); + SwPageFrame *pSibling = *pRefSibling; + if ( pRefPage ) + *pRefPage = pPage; + pPage->Paste( pRoot, pSibling ); + pPage->PreparePage( bFootnote ); + // If the sibling has no body text, destroy it as long as it is no footnote page. + if ( pSibling && !pSibling->IsFootnotePage() && + !pSibling->FindFirstBodyContent() && + (!pRefPage || !isDeleteForbidden(pSibling)) ) + { + pRoot->RemovePage( pRefSibling, SwRemoveResult::Next ) ; + return false; + } + return true; + } } SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote ) @@ -1197,44 +1218,16 @@ SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote ) // If there is no FrameFormat for this page, create an empty page. if( bWishedOdd != bNextOdd ) { - SwFrameFormat *const pEmptyFormat = pDoc->GetEmptyPageFormat(); - SwPageDesc *pTmpDesc = pPrevPage->GetPageDesc(); - SwPageFrame *pPage = new SwPageFrame(pEmptyFormat, pRoot, pTmpDesc); - pPage->Paste( pRoot, pSibling ); - pPage->PreparePage( bFootnote ); - // If the sibling has no body text, destroy it as long as it is no footnote page. - if ( pSibling && !pSibling->IsFootnotePage() && - !pSibling->FindFirstBodyContent() ) - { - SwPageFrame *pDel = pSibling; - pSibling = static_cast<SwPageFrame*>(pSibling->GetNext()); - if ( !pDoc->GetFootnoteIdxs().empty() ) - pRoot->RemoveFootnotes( pDel, true ); - pDel->Cut(); - SwFrame::DestroyFrame(pDel); - } - else + if( doInsertPage( pRoot, &pSibling, pDoc->GetEmptyPageFormat(), + pPrevPage->GetPageDesc(), bFootnote, nullptr ) ) bCheckPages = true; } SwFrameFormat *const pFormat( (bWishedOdd) ? pDesc->GetRightFormat(bWishedFirst) : pDesc->GetLeftFormat(bWishedFirst) ); assert(pFormat); - SwPageFrame *pPage = new SwPageFrame( pFormat, pRoot, pDesc ); - pPage->Paste( pRoot, pSibling ); - pPage->PreparePage( bFootnote ); - // If the sibling has no body text, destroy it as long as it is no footnote page. - if ( pSibling && !pSibling->IsFootnotePage() && - !pSibling->FindFirstBodyContent() && !isDeleteForbidden(pSibling) ) - { - SwPageFrame *pDel = pSibling; - pSibling = static_cast<SwPageFrame*>(pSibling->GetNext()); - if ( !pDoc->GetFootnoteIdxs().empty() ) - pRoot->RemoveFootnotes( pDel, true ); - pDel->Cut(); - SwFrame::DestroyFrame(pDel); - } - else + SwPageFrame *pPage = nullptr; + if( doInsertPage( pRoot, &pSibling, pFormat, pDesc, bFootnote, &pPage ) ) bCheckPages = true; if ( pSibling ) @@ -1304,6 +1297,17 @@ SwTwips SwRootFrame::ShrinkFrame( SwTwips nDist, bool bTst, bool ) return nDist; } +void SwRootFrame::RemovePage( SwPageFrame **pDelRef, SwRemoveResult eResult ) +{ + SwPageFrame *pDel = *pDelRef; + (*pDelRef) = static_cast<SwPageFrame*>( + eResult == SwRemoveResult::Next ? pDel->GetNext() : pDel->GetPrev() ); + if ( !GetFormat()->GetDoc()->GetFootnoteIdxs().empty() ) + RemoveFootnotes( pDel, true ); + pDel->Cut(); + SwFrame::DestroyFrame( pDel ); +} + /// remove pages that are not needed at all void SwRootFrame::RemoveSuperfluous() { @@ -1375,12 +1379,7 @@ void SwRootFrame::RemoveSuperfluous() if ( pPage ) { - SwPageFrame *pEmpty = pPage; - pPage = static_cast<SwPageFrame*>(pPage->GetPrev()); - if ( !GetFormat()->GetDoc()->GetFootnoteIdxs().empty() ) - RemoveFootnotes( pEmpty, true ); - pEmpty->Cut(); - SwFrame::DestroyFrame(pEmpty); + RemovePage( &pPage, SwRemoveResult::Prev ); nDocPos = pPage ? pPage->Frame().Top() : 0; } } while ( pPage ); |