diff options
author | Henry Castro <hcastro@collabora.com> | 2017-07-10 17:33:38 -0400 |
---|---|---|
committer | pranavk <pranavk@collabora.co.uk> | 2018-01-18 16:08:29 +0100 |
commit | d8be925640a142315bcf73c25f85fb8eefeba79a (patch) | |
tree | 43b84160fe9165c32565b56f48594bf8cc665b6b /sw | |
parent | 2425c5cc08b150c9b1b9a6f542b2f5b46a695b40 (diff) |
sw lok: enable Page Header/Footer
Reviewed-on: https://gerrit.libreoffice.org/39782
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Henry Castro <hcastro@collabora.com>
(cherry picked from commit 3ba914c229adfed5c917d1ee23d35b9184b092c4)
Change-Id: I5e0d080c53079069a086f06c2a314b6372bf6391
Reviewed-on: https://gerrit.libreoffice.org/47830
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 75 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 36 |
2 files changed, 109 insertions, 2 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 91cc2140716b..804f77073803 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -34,6 +34,7 @@ #include <sfx2/dispatch.hxx> #include <sfx2/viewfrm.hxx> #include <sfx2/lokhelper.hxx> +#include <sfx2/dispatch.hxx> #include <redline.hxx> #include <IDocumentRedlineAccess.hxx> @@ -89,6 +90,8 @@ public: void testDisableUndoRepair(); void testAllTrackedChanges(); void testDocumentRepair(); + void testPageHeader(); + void testPageFooter(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -136,7 +139,8 @@ public: CPPUNIT_TEST(testDisableUndoRepair); CPPUNIT_TEST(testAllTrackedChanges); CPPUNIT_TEST(testDocumentRepair); - + CPPUNIT_TEST(testPageHeader); + CPPUNIT_TEST(testPageFooter); CPPUNIT_TEST_SUITE_END(); private: @@ -1921,6 +1925,75 @@ void SwTiledRenderingTest::testDocumentRepair() comphelper::LibreOfficeKit::setActive(false); } +namespace { +void checkPageHeaderOrFooter(const SfxViewShell* pViewShell, sal_uInt16 nWhich, bool bValue) +{ + const SfxPoolItem* pState = nullptr; + pViewShell->GetDispatcher()->QueryState(nWhich, pState); + CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem * >(pState)); + CPPUNIT_ASSERT_EQUAL(bValue, dynamic_cast< const SfxBoolItem * >(pState)->GetValue()); +}; + +} + +void SwTiledRenderingTest::testPageHeader() +{ + comphelper::LibreOfficeKit::setActive(); + + createDoc("dummy.fodt"); + SfxViewShell* pViewShell = SfxViewShell::Current(); + // Check Page Header State + checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEHEADER, false); + // Insert Page Header + { + SfxBoolItem aItem(FN_PARAM_1, true); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEHEADER, SfxCallMode::SYNCHRON, {&aItem}); + } + // Check Page Header State + checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEHEADER, true); + + // Remove Page Header + { + SfxBoolItem aItem(FN_PARAM_1, false); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEHEADER, SfxCallMode::SYNCHRON, {&aItem}); + } + // Check Page Header State + checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEHEADER, false); + + mxComponent->dispose(); + mxComponent.clear(); + comphelper::LibreOfficeKit::setActive(false); +} + +void SwTiledRenderingTest::testPageFooter() +{ + comphelper::LibreOfficeKit::setActive(); + + createDoc("dummy.fodt"); + SfxViewShell* pViewShell = SfxViewShell::Current(); + // Check Page Footer State + checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEFOOTER, false); + // Insert Page Footer + { + SfxBoolItem aItem(FN_PARAM_1, true); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEFOOTER, SfxCallMode::SYNCHRON, {&aItem}); + } + // Check Page Footer State + checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEFOOTER, true); + + // Remove Page Footer + { + SfxBoolItem aItem(FN_PARAM_1, false); + pViewShell->GetDispatcher()->ExecuteList(FN_INSERT_PAGEFOOTER, SfxCallMode::SYNCHRON, {&aItem}); + } + // Check Footer State + checkPageHeaderOrFooter(pViewShell, FN_INSERT_PAGEFOOTER, false); + + mxComponent->dispose(); + mxComponent.clear(); + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 824e6dc1d650..08da7496a15c 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -22,6 +22,7 @@ #include <hintids.hxx> #include <cmdid.h> #include <helpid.h> +#include <comphelper/lok.hxx> #include <i18nutil/unicode.hxx> #include <i18nlangtag/languagetag.hxx> @@ -97,6 +98,10 @@ #include <IDocumentStatistics.hxx> #include <sfx2/sfxdlg.hxx> #include <unotools/lingucfg.hxx> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/util/XChangesBatch.hpp> #include <com/sun/star/uno/Any.hxx> #include <editeng/unolingu.hxx> #include <unotools/syslocaleoptions.hxx> @@ -119,6 +124,9 @@ #include <memory> using namespace ::com::sun::star; +using namespace com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace com::sun::star::style; using namespace svx::sidebar; static void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> pCoreSet, bool bSel, bool bSelectionPut, SfxRequest *pReq); @@ -1356,7 +1364,7 @@ void SwTextShell::Execute(SfxRequest &rReq) bool bOn = true; if( SfxItemState::SET == pArgs->GetItemState(FN_PARAM_1, false, &pItem)) bOn = static_cast<const SfxBoolItem*>(pItem)->GetValue(); - rWrtSh.ChangeHeaderOrFooter(sStyleName, FN_INSERT_PAGEHEADER == nSlot, bOn, !rReq.IsAPI()); + rWrtSh.ChangeHeaderOrFooter(sStyleName, FN_INSERT_PAGEHEADER == nSlot, bOn, !comphelper::LibreOfficeKit::isActive() && !rReq.IsAPI()); rReq.Done(); } break; @@ -1694,6 +1702,32 @@ void SwTextShell::GetState( SfxItemSet &rSet ) case FN_INSERT_PAGEHEADER: case FN_INSERT_PAGEFOOTER: + if (comphelper::LibreOfficeKit::isActive()) + { + bool bState = false; + bool bIsPhysical = false; + uno::Reference< XStyleFamiliesSupplier > xSupplier(GetView().GetDocShell()->GetBaseModel(), uno::UNO_QUERY); + if (xSupplier.is()) + { + uno::Reference< XNameContainer > xContainer; + uno::Reference< XNameAccess > xFamilies = xSupplier->getStyleFamilies(); + if (xFamilies->getByName("PageStyles") >>= xContainer) + { + uno::Sequence< OUString > aSeqNames = xContainer->getElementNames(); + for (sal_Int32 itNames = 0; itNames < aSeqNames.getLength(); itNames++) + { + uno::Reference< XPropertySet > xPropSet(xContainer->getByName(aSeqNames[itNames]), uno::UNO_QUERY); + if (xPropSet.is() && (xPropSet->getPropertyValue("IsPhysical") >>= bIsPhysical) && bIsPhysical) + { + if ((xPropSet->getPropertyValue(nWhich == FN_INSERT_PAGEHEADER ? OUString("HeaderIsOn") : OUString("FooterIsOn")) >>= bState) && bState) + break; + } + } + } + } + rSet.Put(SfxBoolItem(nWhich, bState)); + } + else { rSet.Put( SfxObjectShellItem( nWhich, GetView().GetDocShell() )); } |