sw/qa/extras/uiwriter/uiwriter4.cxx | 62 ++++++++++++++++++++++++++++++++++++ sw/source/uibase/uiview/view0.cxx | 18 ++++++++++ sw/source/uibase/uiview/viewmdi.cxx | 3 + 3 files changed, 83 insertions(+)
New commits: commit ef562a3be1d9a283966ad2289fa3a24a7014c774 Author: Andreas Heinisch <[email protected]> AuthorDate: Thu Jan 15 18:08:26 2026 +0100 Commit: Andreas Heinisch <[email protected]> CommitDate: Fri Jan 30 02:05:02 2026 +0100 tdf#98446 - Switch to single-page view mode when hiding whitespace Switch to single-page view mode when hiding whitespace while in multi-page or book view since hiding whitespace is only possible in single-view page mode. Change-Id: Ib3a4281aa0ff1d47a8821aef765003de9ed99173 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197381 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <[email protected]> diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx b/sw/qa/extras/uiwriter/uiwriter4.cxx index 914586cade41..a4c3b4a62bbc 100644 --- a/sw/qa/extras/uiwriter/uiwriter4.cxx +++ b/sw/qa/extras/uiwriter/uiwriter4.cxx @@ -113,6 +113,68 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf96515) CPPUNIT_ASSERT_EQUAL(1, getPages()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf98446_switch_to_single_page_on_hide_whitespace) +{ + createSwDoc(); + + SwDocShell* pDocShell = getSwDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + SwView* pView = pDocShell->GetView(); + + // Enable hide whitespace view mode + SwViewOption aViewOptions(*pWrtShell->GetViewOptions()); + aViewOptions.SetHideWhitespaceMode(true); + pWrtShell->ApplyViewOptions(aViewOptions); + CPPUNIT_ASSERT(pWrtShell->GetViewOptions()->IsWhitespaceHidden()); + + // --- Case 1: Multiple pages per row ------------------------------------- + + // Switch to multiple pages per row + dispatchCommand(mxComponent, u".uno:MultiplePagesPerRow"_ustr, {}); + // Without the fix in place, this test would have failed with + // - Expected: Switching back to single-page layout when hiding whitespace + // - Actual : Layout remained in multi-column mode + CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsWhitespaceHidden()); + + // Re-apply hide whitespace in multi-column mode + pWrtShell->ApplyViewOptions(aViewOptions); + + // Without the fix in place, this test would have failed with + // - Expected: Switching back to single-page layout when hiding whitespace + // - Actual : Layout remained in multi-column mode + CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsViewLayoutBookMode()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell->GetViewOptions()->GetViewLayoutColumns()); + + // --- Case 2: Book mode -------------------------------------------------- + dispatchCommand(mxComponent, u".uno:BookView"_ustr, {}); + // Without the fix in place, this test would have failed with + // - Expected: Switching back to single-page layout when hiding whitespace + // - Actual : Layout remained in book mode + CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsWhitespaceHidden()); + + // Re-apply hide whitespace in multi-column mode + pWrtShell->ApplyViewOptions(aViewOptions); + // Without the fix in place, this test would have failed with + // - Expected: Switching back to single-page layout when hiding whitespace + // - Actual : Layout remained in book mode + CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsViewLayoutBookMode()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell->GetViewOptions()->GetViewLayoutColumns()); + + // --- Case 3: Manual layout changes -------------------------------------- + + // Without the fix in place, this test would have failed with + // - Expected: Multi-column layout disables whitespace hiding + // - Actual : Whitespace remained hidden in multi-column mode + pView->SetViewLayout(/*nColumns=*/0, /*bBookMode=*/false); + CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsWhitespaceHidden()); + + // Without the fix in place, this test would have failed with + // - Expected: Multi-column layout disables whitespace hiding + // - Actual : Whitespace remained hidden in multi-column mode + pView->SetViewLayout(/*nColumns=*/2, /*bBookMode=*/true); + CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsWhitespaceHidden()); +} + static OUString lcl_translitTest(SwDoc& rDoc, const SwPaM& rPaM, TransliterationFlags const nType) { utl::TransliterationWrapper aTrans(::comphelper::getProcessComponentContext(), nType); diff --git a/sw/source/uibase/uiview/view0.cxx b/sw/source/uibase/uiview/view0.cxx index 5eea15c5ef86..9e25d5dd4f3f 100644 --- a/sw/source/uibase/uiview/view0.cxx +++ b/sw/source/uibase/uiview/view0.cxx @@ -526,6 +526,13 @@ void SwView::ExecViewOptions(SfxRequest &rReq) bFlag = !pOpt->IsHideWhitespaceMode(); pOpt->SetHideWhitespaceMode(bFlag); + + // tdf#98446 - switch to single-page view when selecting hide whitespaces option + if (bFlag && !pOpt->CanHideWhitespace()) + { + pOpt->SetViewLayoutBookMode(false); + pOpt->SetViewLayoutColumns(1); + } break; case FN_VIEW_SHOW_WHITESPACE: @@ -533,6 +540,13 @@ void SwView::ExecViewOptions(SfxRequest &rReq) bFlag = pOpt->IsHideWhitespaceMode(); pOpt->SetHideWhitespaceMode(!bFlag); + + // tdf#98446 - switch to single-page view when deselecting show whitespaces option + if (!bFlag && !pOpt->CanHideWhitespace()) + { + pOpt->SetViewLayoutBookMode(false); + pOpt->SetViewLayoutColumns(1); + } break; case FN_VIEW_SMOOTH_SCROLL: @@ -812,11 +826,15 @@ void SwView::ExecViewOptions(SfxRequest &rReq) case FN_MULTIPLE_PAGES_PER_ROW: pOpt->SetViewLayoutBookMode( false ); pOpt->SetViewLayoutColumns( 0 ); + // tdf#98446 - hiding whitespace is only possible in single-page view + pOpt->SetHideWhitespaceMode(false); break; case FN_BOOKVIEW: pOpt->SetViewLayoutColumns( 2 ); pOpt->SetViewLayoutBookMode( true ); + // tdf#98446 - hiding whitespace is only possible in single-page view + pOpt->SetHideWhitespaceMode(false); break; case SID_CLICK_CHANGE_ROTATION: if( STATE_TOGGLE == eState ) diff --git a/sw/source/uibase/uiview/viewmdi.cxx b/sw/source/uibase/uiview/viewmdi.cxx index 842a09602249..b402e3fab021 100644 --- a/sw/source/uibase/uiview/viewmdi.cxx +++ b/sw/source/uibase/uiview/viewmdi.cxx @@ -253,6 +253,9 @@ void SwView::SetViewLayout( sal_uInt16 nColumns, bool bBookMode, bool bViewOnly SwViewOption aOpt( *pOpt ); aOpt.SetViewLayoutColumns( nColumns ); aOpt.SetViewLayoutBookMode( bBookMode ); + // tdf#98446 - hiding whitespace is only possible in single-page view + if (!aOpt.CanHideWhitespace()) + aOpt.SetHideWhitespaceMode(false); m_pWrtShell->ApplyViewOptions( aOpt ); }
