From 252ce90e39648c47bcfdb39547d0ac82bacdbae6 Mon Sep 17 00:00:00 2001 From: Henry Castro Date: Tue, 9 Jan 2018 22:17:23 -0400 Subject: sw lokit: add page syles to header & footer Change-Id: I3c0b0603d1e03f1cc19af4324dd2b909320d9d4a Reviewed-on: https://gerrit.libreoffice.org/47687 Tested-by: Jenkins Reviewed-by: Henry Castro --- sw/qa/extras/tiledrendering/tiledrendering.cxx | 27 ++++++++++++++----- sw/source/uibase/shells/textsh1.cxx | 37 ++++++++++++++++++++------ 2 files changed, 49 insertions(+), 15 deletions(-) (limited to 'sw') diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 3dd1335e50f9..3a9c1c6f9985 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1944,11 +1945,19 @@ namespace { void checkPageHeaderOrFooter(const SfxViewShell* pViewShell, sal_uInt16 nWhich, bool bValue) { + uno::Sequence aSeq; const SfxPoolItem* pState = nullptr; pViewShell->GetDispatcher()->QueryState(nWhich, pState); - const SfxBoolItem* pBoolItem = dynamic_cast(pState); - CPPUNIT_ASSERT(pBoolItem); - CPPUNIT_ASSERT_EQUAL(bValue, pBoolItem->GetValue()); + const SfxStringListItem* pListItem = dynamic_cast(pState); + CPPUNIT_ASSERT(pListItem); + pListItem->GetStringList(aSeq); + if (bValue) + { + CPPUNIT_ASSERT_EQUAL(1, aSeq.getLength()); + CPPUNIT_ASSERT_EQUAL(OUString("Default Style"), aSeq[0]); + } + else + CPPUNIT_ASSERT_EQUAL(0, aSeq.getLength()); }; } @@ -1963,16 +1972,18 @@ void SwTiledRenderingTest::testPageHeader() checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEHEADER, false); // Insert Page Header { + SfxStringItem aStyle(FN_INSERT_PAGEHEADER, "Default Style"); SfxBoolItem aItem(FN_PARAM_1, true); - pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEHEADER, SfxCallMode::SYNCHRON, {&aItem}); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEHEADER, SfxCallMode::API | SfxCallMode::SYNCHRON, {&aStyle, &aItem}); } // Check Page Header State checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEHEADER, true); // Remove Page Header { + SfxStringItem aStyle(FN_INSERT_PAGEHEADER, "Default Style"); SfxBoolItem aItem(FN_PARAM_1, false); - pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEHEADER, SfxCallMode::SYNCHRON, {&aItem}); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEHEADER, SfxCallMode::API | SfxCallMode::SYNCHRON, {&aStyle, &aItem}); } // Check Page Header State checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEHEADER, false); @@ -1992,16 +2003,18 @@ void SwTiledRenderingTest::testPageFooter() checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEFOOTER, false); // Insert Page Footer { + SfxStringItem aPageStyle(FN_INSERT_PAGEFOOTER, "Default Style"); SfxBoolItem aItem(FN_PARAM_1, true); - pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEFOOTER, SfxCallMode::SYNCHRON, {&aItem}); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEFOOTER, SfxCallMode::API | SfxCallMode::SYNCHRON, {&aPageStyle, &aItem}); } // Check Page Footer State checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEFOOTER, true); // Remove Page Footer { + SfxStringItem aPageStyle(FN_INSERT_PAGEFOOTER, "Default Style"); SfxBoolItem aItem(FN_PARAM_1, false); - pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEFOOTER, SfxCallMode::SYNCHRON, {&aItem}); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEFOOTER, SfxCallMode::API | SfxCallMode::SYNCHRON, {&aPageStyle, &aItem}); } // Check Footer State checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEFOOTER, false); diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 6c64bdac4d77..561ba1de9cea 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -1303,7 +1303,7 @@ void SwTextShell::Execute(SfxRequest &rReq) bool bOn = true; if( SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1, false, &pItem)) bOn = static_cast(pItem)->GetValue(); - rWrtSh.ChangeHeaderOrFooter(sStyleName, FN_INSERT_PAGEHEADER == nSlot, bOn, !comphelper::LibreOfficeKit::isActive() && !rReq.IsAPI()); + rWrtSh.ChangeHeaderOrFooter(sStyleName, FN_INSERT_PAGEHEADER == nSlot, bOn, !rReq.IsAPI()); rReq.Done(); } break; @@ -1650,7 +1650,15 @@ void SwTextShell::GetState( SfxItemSet &rSet ) if (comphelper::LibreOfficeKit::isActive()) { bool bState = false; + bool bAllState = true; bool bIsPhysical = false; + + OUString aStyleName; + std::vector aList; + const OUString sPhysical("IsPhysical"); + const OUString sDisplay("DisplayName"); + const OUString sHeaderOn(nWhich == FN_INSERT_PAGEHEADER ? OUString("HeaderIsOn") : OUString("FooterIsOn")); + uno::Reference< XStyleFamiliesSupplier > xSupplier(GetView().GetDocShell()->GetBaseModel(), uno::UNO_QUERY); if (xSupplier.is()) { @@ -1659,18 +1667,31 @@ void SwTextShell::GetState( SfxItemSet &rSet ) if (xFamilies->getByName("PageStyles") >>= xContainer) { uno::Sequence< OUString > aSeqNames = xContainer->getElementNames(); - for (sal_Int32 itNames = 0; itNames < aSeqNames.getLength(); itNames++) + for (sal_Int32 itName = 0; itName < aSeqNames.getLength(); itName++) { - uno::Reference< XPropertySet > xPropSet(xContainer->getByName(aSeqNames[itNames]), uno::UNO_QUERY); - if (xPropSet.is() && (xPropSet->getPropertyValue("IsPhysical") >>= bIsPhysical) && bIsPhysical) + aStyleName = aSeqNames[itName]; + uno::Reference xPropSet(xContainer->getByName(aStyleName), uno::UNO_QUERY); + if (xPropSet.is() && (xPropSet->getPropertyValue(sPhysical) >>= bIsPhysical) && bIsPhysical) { - if ((xPropSet->getPropertyValue(nWhich == FN_INSERT_PAGEHEADER ? OUString("HeaderIsOn") : OUString("FooterIsOn")) >>= bState) && bState) - break; + xPropSet->getPropertyValue(sDisplay) >>= aStyleName; + if ((xPropSet->getPropertyValue(sHeaderOn)>>= bState) && bState) + aList.push_back(aStyleName); + else + bState = false; + + // Check if all entries have the same state + bAllState &= bState; } - } + else + bIsPhysical = false; + } } } - rSet.Put(SfxBoolItem(nWhich, bState)); + + if (bAllState && aList.size() > 1) + aList.push_back("_ALL_"); + + rSet.Put(SfxStringListItem(nWhich, &aList)); } else { -- cgit