sc/qa/unit/bugfix-test.cxx | 21 ++++++++++++++++ sc/qa/unit/data/ods/tdf108188_pagestyle.ods |binary sc/source/core/data/stlsheet.cxx | 35 +++++++++++++++++++--------- sfx2/source/dialog/StyleList.cxx | 15 ------------ 4 files changed, 45 insertions(+), 26 deletions(-)
New commits: commit 10c07e001da992cff4078c1cb1f49fdb16673ac3 Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Sun May 8 14:31:00 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed May 11 09:56:12 2022 +0200 tdf#108188, tdf#131190 - Verify that the page style is actually used Change-Id: I007d26c6fcaf60d2a2378cc00e630da447f95a8a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134022 Tested-by: Andreas Heinisch <andreas.heini...@yahoo.de> Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> (cherry picked from commit ad79900cd62c487bda9d2515892d62b3b08a5dfa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134067 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/unit/bugfix-test.cxx b/sc/qa/unit/bugfix-test.cxx index 7fd56122216e..d2a4f71f3087 100644 --- a/sc/qa/unit/bugfix-test.cxx +++ b/sc/qa/unit/bugfix-test.cxx @@ -29,6 +29,7 @@ #include <svx/svdpage.hxx> #include <svx/svdomeas.hxx> #include <userdat.hxx> +#include <stlpool.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -63,6 +64,7 @@ public: void testTdf129789(); void testTdf130725(); void testTdf104502_hiddenColsCountedInPageCount(); + void testTdf108188_pagestyle(); CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testTdf137576_Measureline); @@ -87,6 +89,7 @@ public: CPPUNIT_TEST(testTdf129789); CPPUNIT_TEST(testTdf130725); CPPUNIT_TEST(testTdf104502_hiddenColsCountedInPageCount); + CPPUNIT_TEST(testTdf108188_pagestyle); CPPUNIT_TEST_SUITE_END(); private: @@ -748,6 +751,24 @@ void ScFiltersTest::testTdf104502_hiddenColsCountedInPageCount() xShell->DoClose(); } +void ScFiltersTest::testTdf108188_pagestyle() +{ + ScDocShellRef xDocSh = loadDoc(u"tdf108188_pagestyle.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh); + + // Check if the user defined page style is present + const OUString aTestPageStyle = "TestPageStyle"; + ScDocument& rDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT_EQUAL(aTestPageStyle, rDoc.GetPageStyle(0)); + + // Without the accompanying fix in place, the page styles are always used + ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); + CPPUNIT_ASSERT(pStylePool->Find(aTestPageStyle, SfxStyleFamily::Page)->IsUsed()); + CPPUNIT_ASSERT(!pStylePool->Find("Default", SfxStyleFamily::Page)->IsUsed()); + + xDocSh->DoClose(); +} + ScFiltersTest::ScFiltersTest() : ScBootstrapFixture( "sc/qa/unit/data" ) diff --git a/sc/qa/unit/data/ods/tdf108188_pagestyle.ods b/sc/qa/unit/data/ods/tdf108188_pagestyle.ods new file mode 100644 index 000000000000..d0ecf9f88453 Binary files /dev/null and b/sc/qa/unit/data/ods/tdf108188_pagestyle.ods differ diff --git a/sc/source/core/data/stlsheet.cxx b/sc/source/core/data/stlsheet.cxx index 5712bf883c78..ae113cc82e91 100644 --- a/sc/source/core/data/stlsheet.cxx +++ b/sc/source/core/data/stlsheet.cxx @@ -250,19 +250,32 @@ SfxItemSet& ScStyleSheet::GetItemSet() bool ScStyleSheet::IsUsed() const { - if ( GetFamily() == SfxStyleFamily::Para ) + switch (GetFamily()) { - // Always query the document to let it decide if a rescan is necessary, - // and store the state. - ScDocument* pDoc = static_cast<ScStyleSheetPool*>(m_pPool)->GetDocument(); - if ( pDoc && pDoc->IsStyleSheetUsed( *this ) ) - eUsage = Usage::USED; - else - eUsage = Usage::NOTUSED; - return eUsage == Usage::USED; + case SfxStyleFamily::Para: + { + // Always query the document to let it decide if a rescan is necessary, + // and store the state. + ScDocument* pDoc = static_cast<ScStyleSheetPool*>(m_pPool)->GetDocument(); + if ( pDoc && pDoc->IsStyleSheetUsed( *this ) ) + eUsage = Usage::USED; + else + eUsage = Usage::NOTUSED; + return eUsage == Usage::USED; + } + case SfxStyleFamily::Page: + { + // tdf#108188 - verify that the page style is actually used + ScDocument* pDoc = static_cast<ScStyleSheetPool*>(m_pPool)->GetDocument(); + if (pDoc && pDoc->IsPageStyleInUse(GetName(), nullptr)) + eUsage = Usage::USED; + else + eUsage = Usage::NOTUSED; + return eUsage == Usage::USED; + } + default: + return true; } - else - return true; } void ScStyleSheet::Notify( SfxBroadcaster&, const SfxHint& rHint ) diff --git a/sfx2/source/dialog/StyleList.cxx b/sfx2/source/dialog/StyleList.cxx index 5b86a1033c49..f8bcf6ee1799 100644 --- a/sfx2/source/dialog/StyleList.cxx +++ b/sfx2/source/dialog/StyleList.cxx @@ -1335,21 +1335,6 @@ IMPL_LINK_NOARG(StyleList, EnableDelete, void*, void) { bEnableDelete = true; } - else if (pStyle->GetFamily() == SfxStyleFamily::Page) - { - // Hack to allow Calc page styles to be deleted, - // remove when IsUsed is fixed for Calc page styles. - SfxViewFrame* pFrame = m_pCurObjShell->GetFrame(); - if (pFrame) - { - uno::Reference<frame::XFrame> xFrame = pFrame->GetFrame().GetFrameInterface(); - if (vcl::CommandInfoProvider::GetModuleIdentifier(xFrame) - == "com.sun.star.sheet.SpreadsheetDocument") - { - bEnableDelete = true; - } - } - } } } m_pParentDialog->EnableDel(bEnableDelete, this);