diff options
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/inc/frmtool.hxx | 8 | ||||
-rw-r--r-- | sw/source/core/layout/flowfrm.cxx | 18 | ||||
-rw-r--r-- | sw/source/core/layout/frmtool.cxx | 25 | ||||
-rw-r--r-- | sw/source/core/layout/laycache.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/layout/newfrm.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/layout/pagechg.cxx | 28 | ||||
-rw-r--r-- | sw/source/core/layout/trvlfrm.cxx | 38 |
7 files changed, 75 insertions, 62 deletions
diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx index a32a5a0b9c62..c8447d8dd0f1 100644 --- a/sw/source/core/inc/frmtool.hxx +++ b/sw/source/core/inc/frmtool.hxx @@ -150,8 +150,14 @@ extern bool bSetCompletePaintOnInvalidate; SwTwips CalcRowRstHeight( SwLayoutFrame *pRow ); long CalcHeightWithFlys( const SwFrame *pFrame ); +namespace sw { + +bool IsRightPageByNumber(SwRootFrame const& rLayout, sal_uInt16 nPageNum); + +} // namespace sw + SwPageFrame *InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper, - bool bOdd, bool bFirst, bool bInsertEmpty, bool bFootnote, + bool isRightPage, bool bFirst, bool bInsertEmpty, bool bFootnote, SwFrame *pSibling ); // connect Flys with page diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx index f35bf168ec4f..1b8997cd6c2b 100644 --- a/sw/source/core/layout/flowfrm.cxx +++ b/sw/source/core/layout/flowfrm.cxx @@ -848,7 +848,7 @@ bool SwFrame::WrongPageDesc( SwPageFrame* pNew ) //My Pagedesc doesn't count if I'm a follow! const SwPageDesc *pDesc = nullptr; - int nTmp = 0; + boost::optional<sal_uInt16> oTmp; SwFlowFrame *pFlow = SwFlowFrame::CastFlowFrame( this ); if ( !pFlow || !pFlow->IsFollow() ) { @@ -857,18 +857,18 @@ bool SwFrame::WrongPageDesc( SwPageFrame* pNew ) if( pDesc ) { if( !pDesc->GetRightFormat() ) - nTmp = 2; + oTmp = 2; else if( !pDesc->GetLeftFormat() ) - nTmp = 1; + oTmp = 1; else if( rFormatDesc.GetNumOffset() ) - nTmp = rFormatDesc.GetNumOffset().get(); + oTmp = rFormatDesc.GetNumOffset(); } } // Does the Content bring a Pagedesc or do we need the // virtual page number of the new layout leaf? // PageDesc isn't allowed with Follows - const bool bOdd = nTmp ? (nTmp % 2) !=0 : pNew->OnRightPage(); + const bool isRightPage = oTmp ? sw::IsRightPageByNumber(*mpRoot, *oTmp) : pNew->OnRightPage(); if ( !pDesc ) pDesc = pNew->FindPageDesc(); @@ -886,14 +886,14 @@ bool SwFrame::WrongPageDesc( SwPageFrame* pNew ) SAL_INFO( "sw.pageframe", "WrongPageDesc p: " << pNew << " phys: " << pNew->GetPhyPageNum() ); SAL_INFO( "sw.pageframe", "WrongPageDesc " << pNew->GetPageDesc() << " " << pDesc ); - SAL_INFO( "sw.pageframe", "WrongPageDesc odd: " << bOdd + SAL_INFO( "sw.pageframe", "WrongPageDesc right: " << isRightPage << " first: " << bFirst << " " << pNew->GetFormat() << " == " - << (bOdd ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)) << " " - << (bOdd ? pDesc->GetLeftFormat(bFirst) : pDesc->GetRightFormat(bFirst)) ); + << (isRightPage ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst)) << " " + << (isRightPage ? pDesc->GetLeftFormat(bFirst) : pDesc->GetRightFormat(bFirst)) ); return (pNew->GetPageDesc() != pDesc) // own desc ? || (pNew->GetFormat() != - (bOdd ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst))) + (isRightPage ? pDesc->GetRightFormat(bFirst) : pDesc->GetLeftFormat(bFirst))) || (pNewDesc && pNewDesc == pDesc); } diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx index 132e3345c0ca..0cad5caca44a 100644 --- a/sw/source/core/layout/frmtool.cxx +++ b/sw/source/core/layout/frmtool.cxx @@ -2884,10 +2884,27 @@ void RestoreContent( SwFrame *pSav, SwLayoutFrame *pParent, SwFrame *pSibling ) pParent->Grow( nGrowVal ); } +namespace sw { + +bool IsRightPageByNumber(SwRootFrame const& rLayout, sal_uInt16 const nPageNum) +{ + assert(rLayout.GetLower()); + // unfortunately can only get SwPageDesc, not SwFormatPageDesc here... + auto const nFirstVirtPageNum(rLayout.GetLower()->GetVirtPageNum()); + bool const isFirstPageOfLayoutOdd(nFirstVirtPageNum % 2 == 1); + return ((nPageNum % 2) == 1) == isFirstPageOfLayoutOdd; +} + +} // namespace sw + SwPageFrame * InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper, - bool bOdd, bool bFirst, bool bInsertEmpty, bool bFootnote, + bool const isRightPage, bool const bFirst, bool bInsertEmpty, + bool const bFootnote, SwFrame *pSibling ) { + assert(pUpper); + assert(pUpper->IsRootFrame()); + assert(!pSibling || static_cast<SwLayoutFrame const*>(pUpper)->Lower() != pSibling); // currently no insert before 1st page SwPageFrame *pRet; SwDoc *pDoc = static_cast<SwLayoutFrame*>(pUpper)->GetFormat()->GetDoc(); if (bFirst) @@ -2896,7 +2913,7 @@ SwPageFrame * InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper, { // We need to fallback to left or right page format, decide it now. // FIXME: is this still needed? - if (bOdd) + if (isRightPage) { rDesc.GetFirstMaster().SetFormatAttr( rDesc.GetMaster().GetHeader() ); rDesc.GetFirstMaster().SetFormatAttr( rDesc.GetMaster().GetFooter() ); @@ -2911,11 +2928,11 @@ SwPageFrame * InsertNewPage( SwPageDesc &rDesc, SwFrame *pUpper, } } } - SwFrameFormat *pFormat(bOdd ? rDesc.GetRightFormat(bFirst) : rDesc.GetLeftFormat(bFirst)); + SwFrameFormat *pFormat(isRightPage ? rDesc.GetRightFormat(bFirst) : rDesc.GetLeftFormat(bFirst)); // If there is no FrameFormat for this page, add an empty page if ( !pFormat ) { - pFormat = bOdd ? rDesc.GetLeftFormat() : rDesc.GetRightFormat(); + pFormat = isRightPage ? rDesc.GetLeftFormat() : rDesc.GetRightFormat(); OSL_ENSURE( pFormat, "Descriptor without any format?!" ); bInsertEmpty = !bInsertEmpty; } diff --git a/sw/source/core/layout/laycache.cxx b/sw/source/core/layout/laycache.cxx index f78f0a4e9a47..ff1ad6a53eb7 100644 --- a/sw/source/core/layout/laycache.cxx +++ b/sw/source/core/layout/laycache.cxx @@ -670,17 +670,19 @@ bool SwLayHelper::CheckInsertPage() if ( oPgNum ) static_cast<SwRootFrame*>(mrpPage->GetUpper())->SetVirtPageNum(true); } - bool bNextPageOdd = !mrpPage->OnRightPage(); + bool bNextPageRight = !mrpPage->OnRightPage(); bool bInsertEmpty = false; - if( oPgNum && bNextPageOdd != ( ( oPgNum.get() % 2 ) != 0 ) ) + assert(mrpPage->GetUpper()->GetLower()); + if (oPgNum && bNextPageRight != IsRightPageByNumber( + *static_cast<SwRootFrame*>(mrpPage->GetUpper()), *oPgNum)) { - bNextPageOdd = !bNextPageOdd; + bNextPageRight = !bNextPageRight; bInsertEmpty = true; } // If the page style is changing, we'll have a first page. bool bNextPageFirst = pDesc != mrpPage->GetPageDesc(); ::InsertNewPage( const_cast<SwPageDesc&>(*pDesc), mrpPage->GetUpper(), - bNextPageOdd, bNextPageFirst, bInsertEmpty, false, mrpPage->GetNext() ); + bNextPageRight, bNextPageFirst, bInsertEmpty, false, mrpPage->GetNext()); if ( bEnd ) { OSL_ENSURE( mrpPage->GetNext(), "No new page?" ); diff --git a/sw/source/core/layout/newfrm.cxx b/sw/source/core/layout/newfrm.cxx index e4ae9a45c53e..1d1f4597fcf2 100644 --- a/sw/source/core/layout/newfrm.cxx +++ b/sw/source/core/layout/newfrm.cxx @@ -489,15 +489,9 @@ void SwRootFrame::Init( SwFrameFormat* pFormat ) if ( !pDesc ) pDesc = &pDoc->GetPageDesc( 0 ); - const bool bOdd = !oPgNum || 0 != ( oPgNum.get() % 2 ); - const bool bFirst = true; - // Even page numbers are supposed to be printed as left pages. So if a - // page number has been explicitly set for this first page, then we must - // insert a blank page before it to make it a left page. - const bool bInsertEmpty = !bOdd; - // Create a page and put it in the layout - SwPageFrame *pPage = ::InsertNewPage( *pDesc, this, bOdd, bFirst, bInsertEmpty, false, nullptr ); + // The first page is always a right-page and always a first-page + SwPageFrame *pPage = ::InsertNewPage(*pDesc, this, true, true, false, false, nullptr); // Find the first page in the Bodytext section. SwLayoutFrame *pLay = pPage->FindBodyCont(); diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx index a2b70fb68e81..a684b1602a1a 100644 --- a/sw/source/core/layout/pagechg.cxx +++ b/sw/source/core/layout/pagechg.cxx @@ -991,7 +991,7 @@ void SwPageFrame::PrepareRegisterChg() } //FIXME: provide missing documentation -/** Check all pages (starting from the given one) if they use the right frame format. +/** Check all pages (starting from the given one) if they use the appropriate frame format. * * If "wrong" pages are found, try to fix this as simple as possible. * @@ -1291,8 +1291,8 @@ SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote ) SwPageDesc *pDesc = nullptr; // insert right (odd) or left (even) page? - bool bNextOdd = !pPrevPage->OnRightPage(); - bool bWishedOdd = bNextOdd; + bool bNextRightPage = !pPrevPage->OnRightPage(); + bool bWishedRightPage = bNextRightPage; // Which PageDesc is relevant? // For ContentFrame take the one from format if provided, @@ -1304,7 +1304,7 @@ SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote ) if ( rDesc.GetNumOffset() ) { ::boost::optional<sal_uInt16> oNumOffset = rDesc.GetNumOffset(); - bWishedOdd = oNumOffset && (oNumOffset.get() % 2) != 0; + bWishedRightPage = sw::IsRightPageByNumber(*pRoot, *oNumOffset); // use the opportunity to set the flag at root pRoot->SetVirtPageNum( true ); } @@ -1313,20 +1313,20 @@ SwPageFrame *SwFrame::InsertPage( SwPageFrame *pPrevPage, bool bFootnote ) pDesc = pPrevPage->GetPageDesc()->GetFollow(); assert(pDesc && "Missing PageDesc"); - if( !(bWishedOdd ? pDesc->GetRightFormat() : pDesc->GetLeftFormat()) ) - bWishedOdd = !bWishedOdd; + if( !(bWishedRightPage ? pDesc->GetRightFormat() : pDesc->GetLeftFormat()) ) + bWishedRightPage = !bWishedRightPage; bool const bWishedFirst = pDesc != pPrevPage->GetPageDesc(); SwDoc *pDoc = pPrevPage->GetFormat()->GetDoc(); bool bCheckPages = false; // If there is no FrameFormat for this page, create an empty page. - if( bWishedOdd != bNextOdd ) + if (bWishedRightPage != bNextRightPage) { if( doInsertPage( pRoot, &pSibling, pDoc->GetEmptyPageFormat(), pPrevPage->GetPageDesc(), bFootnote, nullptr ) ) bCheckPages = true; } - SwFrameFormat *const pFormat( bWishedOdd + SwFrameFormat *const pFormat( bWishedRightPage ? pDesc->GetRightFormat(bWishedFirst) : pDesc->GetLeftFormat(bWishedFirst) ); assert(pFormat); @@ -1560,17 +1560,17 @@ void SwRootFrame::AssertFlyPages() // and let the ::Notify mechanism newly evaluate // m_bEmptyPage (see SwPageFrame::UpdateAttr_). Code is taken and // adapted from ::InsertPage (used below), this needs previous page - bool bWishedOdd(!pPrevPage->OnRightPage()); + bool bWishedRightPage(!pPrevPage->OnRightPage()); SwPageDesc* pDesc(pPrevPage->GetPageDesc()->GetFollow()); assert(pDesc && "Missing PageDesc"); - if(!(bWishedOdd ? pDesc->GetRightFormat() : pDesc->GetLeftFormat())) + if (!(bWishedRightPage ? pDesc->GetRightFormat() : pDesc->GetLeftFormat())) { - bWishedOdd = !bWishedOdd; + bWishedRightPage = !bWishedRightPage; } bool const bWishedFirst(pDesc != pPrevPage->GetPageDesc()); - SwFrameFormat* pFormat(bWishedOdd ? pDesc->GetRightFormat(bWishedFirst) : pDesc->GetLeftFormat(bWishedFirst)); + SwFrameFormat* pFormat(bWishedRightPage ? pDesc->GetRightFormat(bWishedFirst) : pDesc->GetLeftFormat(bWishedFirst)); // set SwFrameFormat, this will trigger SwPageFrame::UpdateAttr_ and re-evaluate // m_bEmptyPage, too @@ -1614,9 +1614,9 @@ void SwRootFrame::AssertFlyPages() if ( pPage ) { SwPageDesc *pTmpDesc = pPage->FindPageDesc(); - bool bOdd = pPage->OnRightPage(); + bool isRightPage = pPage->OnRightPage(); if ( pPage->GetFormat() != - (bOdd ? pTmpDesc->GetRightFormat() : pTmpDesc->GetLeftFormat()) ) + (isRightPage ? pTmpDesc->GetRightFormat() : pTmpDesc->GetLeftFormat()) ) RemoveFootnotes( pPage, false, true ); } } diff --git a/sw/source/core/layout/trvlfrm.cxx b/sw/source/core/layout/trvlfrm.cxx index 850196487a22..8cb591d05026 100644 --- a/sw/source/core/layout/trvlfrm.cxx +++ b/sw/source/core/layout/trvlfrm.cxx @@ -1692,16 +1692,18 @@ sal_uInt16 SwFrame::GetPhyPageNum() const return pPage ? pPage->GetPhyPageNum() : 0; } -/** Decides if the page want to be a rightpage or not. +/** Decides if the page want to be a right page or not. * * If the first content of the page has a page descriptor, we take the follow * of the page descriptor of the last not empty page. If this descriptor allows - * only right(left) pages and the page isn't an empty page then it want to be + * only right(left) pages and the page isn't an empty page then it wants to be * such right(left) page. If the descriptor allows right and left pages, we * look for a number offset in the first content. If there is one, odd number - * results right pages, even number results left pages. + * results right pages (or left pages if document starts with even number), + * even number results left pages (or right pages if document starts with even + * number). * If there is no number offset, we take the physical page number instead, - * but a previous empty page don't count. + * but a previous empty page doesn't count. */ bool SwFrame::WannaRightPage() const { @@ -1738,23 +1740,23 @@ bool SwFrame::WannaRightPage() const } } OSL_ENSURE( pDesc, "No pagedescriptor" ); - bool bOdd; + bool isRightPage; if( oPgNum ) - bOdd = (oPgNum.get() % 2) != 0; + isRightPage = sw::IsRightPageByNumber(*mpRoot, *oPgNum); else { - bOdd = pPage->OnRightPage(); + isRightPage = pPage->OnRightPage(); if( pPage->GetPrev() && static_cast<const SwPageFrame*>(pPage->GetPrev())->IsEmptyPage() ) - bOdd = !bOdd; + isRightPage = !isRightPage; } if( !pPage->IsEmptyPage() ) { if( !pDesc->GetRightFormat() ) - bOdd = false; + isRightPage = false; else if( !pDesc->GetLeftFormat() ) - bOdd = true; + isRightPage = true; } - return bOdd; + return isRightPage; } bool SwFrame::OnFirstPage() const @@ -1767,17 +1769,9 @@ bool SwFrame::OnFirstPage() const const SwPageFrame* pPrevFrame = dynamic_cast<const SwPageFrame*>(pPage->GetPrev()); if (pPrevFrame) { - if (pPrevFrame->IsEmptyPage() && pPrevFrame->GetPhyPageNum()==1) - { - // This was the first page of the document, but its page number - // was set to an even number, so a blank page was automatically - // inserted before it to make this be a "left" page. - // We still use the first page format of the page style here. - bRet = true; - } else { - const SwPageDesc* pDesc = pPage->GetPageDesc(); - bRet = pPrevFrame->GetPageDesc() != pDesc; - } + // first page of layout may be empty page, but only if it starts with "Left Page" style + const SwPageDesc* pDesc = pPage->GetPageDesc(); + bRet = pPrevFrame->GetPageDesc() != pDesc; } else bRet = true; |