sw/qa/extras/uiwriter/uiwriter.cxx | 47 +++++++++++++++++++++++++++++++++++++ sw/source/core/layout/calcmove.cxx | 30 ++++++++++++++++++++++- sw/source/core/layout/wsfrm.cxx | 15 +++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-)
New commits: commit 5ae9e8440a7d861b0903b1a220e1deb5b467d306 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Dec 16 15:41:38 2015 +0100 tdf#96536 sw Hide Whitespace: shrink oversized page frames on para delete The body frame did get a request to shrink, but because it had fixed size, nothing happened. Trigger a recalc that does the right thing wrt. hidden whitespace. (cherry picked from commit 72f0067258fd7738217abd43452abe282e05c11b) Conflicts: sw/qa/extras/uiwriter/uiwriter.cxx sw/source/core/layout/calcmove.cxx Change-Id: I446978da8b33372c2ab30200b45b1bcec1dea7a0 diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 75a56d6..ca57c28 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -106,6 +106,7 @@ public: void testTdf89954(); void testTdf89720(); void testTdf96515(); + void testTdf96536(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -149,6 +150,7 @@ public: CPPUNIT_TEST(testTdf89954); CPPUNIT_TEST(testTdf89720); CPPUNIT_TEST(testTdf96515); + CPPUNIT_TEST(testTdf96536); CPPUNIT_TEST_SUITE_END(); @@ -1172,6 +1174,29 @@ void SwUiWriterTest::testTdf96515() CPPUNIT_ASSERT_EQUAL(1, getPages()); } +void SwUiWriterTest::testTdf96536() +{ + // Enable hide whitespace mode. + SwDoc* pDoc = createDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwViewOption aViewOptions(*pWrtShell->GetViewOptions()); + aViewOptions.SetHideWhitespaceMode(true); + pWrtShell->ApplyViewOptions(aViewOptions); + + // Insert a new paragraph at the end of the document, and then delete it. + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XParagraphAppend> xParagraphAppend(xTextDocument->getText(), uno::UNO_QUERY); + xParagraphAppend->finishParagraph(uno::Sequence<beans::PropertyValue>()); + calcLayout(); + uno::Reference<lang::XComponent> xParagraph(getParagraph(2), uno::UNO_QUERY); + xParagraph->dispose(); + calcLayout(); + + // This was 552, page did not shrink after deleting the second paragraph. + // 276 is 12pt font size + default line spacing (15%). + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(276), parseDump("/root/infos/bounds", "height").toInt32()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index 6c7f5d7..75024af 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -1521,7 +1521,8 @@ void SwContentFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/) const long nPrtBottom = (GetUpper()->*fnRect->fnGetPrtBottom)(); long nBottomDist = (Frm().*fnRect->fnBottomDist)( nPrtBottom ); - if (getRootFrm()->GetCurrShell()->GetViewOptions()->IsWhitespaceHidden()) + SwViewShell* pShell = getRootFrm()->GetCurrShell(); + if (pShell && pShell->GetViewOptions()->IsWhitespaceHidden()) { // When whitespace is hidden, the page frame has two heights: the // nominal (defined by the frame format), and the actual (which is diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx index 9eed78e..205f704 100644 --- a/sw/source/core/layout/wsfrm.cxx +++ b/sw/source/core/layout/wsfrm.cxx @@ -2358,6 +2358,21 @@ SwTwips SwLayoutFrm::ShrinkFrm( SwTwips nDist, bool bTst, bool bInfo ) const SwViewShell *pSh = getRootFrm()->GetCurrShell(); const bool bBrowse = pSh && pSh->GetViewOptions()->getBrowseMode(); const sal_uInt16 nTmpType = bBrowse ? 0x2084: 0x2004; //Row+Cell, Browse by Body. + + if (pSh && pSh->GetViewOptions()->IsWhitespaceHidden()) + { + if (IsBodyFrm()) + { + // Whitespace is hidden and this body frame will not shrink, as it + // has a fix size. + // Invalidate the page frame size, so in case the reason for the + // shrink was that there is more whitespace on this page, the size + // without whitespace will be recalculated correctly. + SwPageFrm* pPageFrame = FindPageFrm(); + pPageFrame->InvalidateSize(); + } + } + if( !(GetType() & nTmpType) && HasFixSize() ) return 0; commit 64726957da2d64d4ad7d6718842ea1d6974696dc Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Dec 16 09:49:18 2015 +0100 tdf#96515 sw Hide Whitespace: avoid creating unneeded page frames (cherry picked from commit 2c23d4ee1e1370b20560e47db7efaeaac1d94b26) Conflicts: sw/qa/extras/uiwriter/uiwriter.cxx sw/source/core/layout/calcmove.cxx Change-Id: I9b273543ccf2eaa87116c6e1475860e9e872c445 diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 9d0d1b1..75a56d6 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -11,6 +11,7 @@ #include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <com/sun/star/i18n/TextConversionOption.hpp> #include <com/sun/star/frame/DispatchHelper.hpp> +#include <com/sun/star/text/XParagraphAppend.hpp> #include <swmodeltestbase.hxx> #include <ndtxt.hxx> #include <wrtsh.hxx> @@ -104,6 +105,7 @@ public: void testDde(); void testTdf89954(); void testTdf89720(); + void testTdf96515(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -146,6 +148,7 @@ public: CPPUNIT_TEST(testDde); CPPUNIT_TEST(testTdf89954); CPPUNIT_TEST(testTdf89720); + CPPUNIT_TEST(testTdf96515); CPPUNIT_TEST_SUITE_END(); @@ -1150,6 +1153,25 @@ void SwUiWriterTest::testTdf89720() #endif } +void SwUiWriterTest::testTdf96515() +{ + // Enable hide whitespace mode. + SwDoc* pDoc = createDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwViewOption aViewOptions(*pWrtShell->GetViewOptions()); + aViewOptions.SetHideWhitespaceMode(true); + pWrtShell->ApplyViewOptions(aViewOptions); + + // Insert a new paragraph at the end of the document. + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XParagraphAppend> xParagraphAppend(xTextDocument->getText(), uno::UNO_QUERY); + xParagraphAppend->finishParagraph(uno::Sequence<beans::PropertyValue>()); + calcLayout(); + + // This was 2, a new page was created for the new paragraph. + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index 0820e38..6c7f5d7 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -1519,7 +1519,34 @@ void SwContentFrm::MakeAll(vcl::RenderContext* /*pRenderContext*/) // Bottom(). This might happen with undersized TextFrms on the lower edge of a // multi-column section const long nPrtBottom = (GetUpper()->*fnRect->fnGetPrtBottom)(); - const long nBottomDist = (Frm().*fnRect->fnBottomDist)( nPrtBottom ); + long nBottomDist = (Frm().*fnRect->fnBottomDist)( nPrtBottom ); + + if (getRootFrm()->GetCurrShell()->GetViewOptions()->IsWhitespaceHidden()) + { + // When whitespace is hidden, the page frame has two heights: the + // nominal (defined by the frame format), and the actual (which is + // at most the nominal height, but can be smaller in case there is + // no content for the whole page). + // The layout size is the actual one, but we want to move the + // content frame to a new page only in case it doesn't fit the + // nominal size. + if (nBottomDist < 0) + { + // Content frame doesn't fit the actual size, check if it fits the nominal one. + SwPageFrm* pPageFrame = FindPageFrm(); + const SwFrameFormat* pPageFormat = static_cast<const SwFrameFormat*>(pPageFrame->GetRegisteredIn()); + const Size& rPageSize = pPageFormat->GetFrmSize().GetSize(); + long nWhitespace = rPageSize.getHeight() - pPageFrame->Frm().Height(); + if (nWhitespace > -nBottomDist) + { + // It does: don't move it and invalidate our page frame so + // that it gets a larger height. + nBottomDist = 0; + pPageFrame->InvalidateSize(); + } + } + } + if( nBottomDist >= 0 ) { if ( bKeep && bMoveable ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits