include/sfx2/sfxsids.hrc | 1 include/sfx2/viewfrm.hxx | 2 sfx2/CppunitTest_sfx2_view.mk | 45 ++++++++++++++++++ sfx2/Module_sfx2.mk | 1 sfx2/qa/cppunit/data/reload-page.odg |binary sfx2/qa/cppunit/view.cxx | 87 +++++++++++++++++++++++++++++++++++ sfx2/source/doc/objserv.cxx | 18 ++++++- sfx2/source/view/viewfrm.cxx | 16 ++++++ 8 files changed, 168 insertions(+), 2 deletions(-)
New commits: commit 8a07588cb648e26a3fc06643b0210fc75201afb8 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Aug 19 15:22:20 2020 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Aug 19 21:47:13 2020 +0200 sd signature line: preserve current page after signing Once the user adds a visible signature to a PDF file, we reload the document, so what you see on the screen matches what's in the file (and you can add a next signature). Make sure that in case the signature is not on the first page, the current page state is preserved. Change-Id: Ia1780ce5602ee350855b6dec8340a65e63bf2d4e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100999 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index 91c69e467654..88d708e4cb98 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -311,6 +311,7 @@ class SvxSearchItem; #define SID_POSTDATA (SID_SFX_START + 1536) #define SID_DONELINK (SID_SFX_START + 646) #define SID_REFERER (SID_SFX_START + 654) +#define SID_PAGE_NUMBER (SID_SFX_START + 655) #define SID_MODIFIER (SID_SFX_START + 669) #define SID_SETOPTIONS (SID_SFX_START + 670) #define SID_SOURCEVIEW (SID_SFX_START + 675) diff --git a/include/sfx2/viewfrm.hxx b/include/sfx2/viewfrm.hxx index e3a3ddaffb2e..07d1360c57c7 100644 --- a/include/sfx2/viewfrm.hxx +++ b/include/sfx2/viewfrm.hxx @@ -170,7 +170,7 @@ public: SAL_DLLPRIVATE void ReleaseObjectShell_Impl(); SAL_DLLPRIVATE void GetState_Impl( SfxItemSet &rSet ); - SAL_DLLPRIVATE void ExecReload_Impl( SfxRequest &rReq ); + void ExecReload_Impl(SfxRequest& rReq); SAL_DLLPRIVATE void StateReload_Impl( SfxItemSet &rSet ); SAL_DLLPRIVATE void ExecView_Impl( SfxRequest &rReq ); SAL_DLLPRIVATE void StateView_Impl( SfxItemSet &rSet ); diff --git a/sfx2/CppunitTest_sfx2_view.mk b/sfx2/CppunitTest_sfx2_view.mk new file mode 100644 index 000000000000..e39346c1075a --- /dev/null +++ b/sfx2/CppunitTest_sfx2_view.mk @@ -0,0 +1,45 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sfx2_view)) + +$(eval $(call gb_CppunitTest_use_externals,sfx2_view,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sfx2_view, \ + sfx2/qa/cppunit/view \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sfx2_view, \ + comphelper \ + cppu \ + sal \ + test \ + unotest \ + sfx \ + svl \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,sfx2_view)) + +$(eval $(call gb_CppunitTest_use_ure,sfx2_view)) +$(eval $(call gb_CppunitTest_use_vcl,sfx2_view)) + +$(eval $(call gb_CppunitTest_use_rdb,sfx2_view,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sfx2_view,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sfx2_view)) + +# vim: set noet sw=4 ts=4: diff --git a/sfx2/Module_sfx2.mk b/sfx2/Module_sfx2.mk index d084ac929c0f..d64b871c2a7f 100644 --- a/sfx2/Module_sfx2.mk +++ b/sfx2/Module_sfx2.mk @@ -36,6 +36,7 @@ $(eval $(call gb_Module_add_check_targets,sfx2,\ CppunitTest_sfx2_misc \ CppunitTest_sfx2_controlleritem \ CppunitTest_sfx2_classification \ + CppunitTest_sfx2_view \ )) $(eval $(call gb_Module_add_subsequentcheck_targets,sfx2,\ diff --git a/sfx2/qa/cppunit/data/reload-page.odg b/sfx2/qa/cppunit/data/reload-page.odg new file mode 100644 index 000000000000..0e9cf08649a0 Binary files /dev/null and b/sfx2/qa/cppunit/data/reload-page.odg differ diff --git a/sfx2/qa/cppunit/view.cxx b/sfx2/qa/cppunit/view.cxx new file mode 100644 index 000000000000..e5ce404c21e9 --- /dev/null +++ b/sfx2/qa/cppunit/view.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/drawing/XDrawView.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <sfx2/app.hxx> +#include <sfx2/sfxsids.hrc> +#include <sfx2/viewfrm.hxx> +#include <svl/itemset.hxx> +#include <svl/intitem.hxx> +#include <sfx2/request.hxx> +#include <sfx2/bindings.hxx> + +using namespace com::sun::star; + +char const DATA_DIRECTORY[] = "/sfx2/qa/cppunit/data/"; + +/// Covers sfx2/source/view/ fixes. +class Sfx2ViewTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference<lang::XComponent> mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference<lang::XComponent>& getComponent() { return mxComponent; } +}; + +void Sfx2ViewTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Sfx2ViewTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +CPPUNIT_TEST_FIXTURE(Sfx2ViewTest, testReloadPage) +{ + // Load a document, which has 2 pages. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "reload-page.odg"; + getComponent() = loadFromDesktop(aURL); + + // Reload, and request to start on page 2. + SfxViewFrame* pFrame = SfxViewFrame::Current(); + SfxAllItemSet aSet(SfxGetpApp()->GetPool()); + aSet.Put(SfxInt32Item(SID_PAGE_NUMBER, 1)); + SfxRequest aReq(SID_RELOAD, SfxCallMode::SLOT, aSet); + pFrame->ExecReload_Impl(aReq); + uno::Reference<frame::XModel> xModel = SfxObjectShell::Current()->GetBaseModel(); + getComponent() = xModel; + + // Check the current page after reload. + uno::Reference<drawing::XDrawView> xController(xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xPage(xController->getCurrentPage(), uno::UNO_QUERY); + sal_Int32 nPage{}; + xPage->getPropertyValue("Number") >>= nPage; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 1 + // i.e. the document was opened on page 1, not page 2, SID_PAGE_NUMBER was ignored. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), nPage); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 349cac3ac4d0..8ab9ea898e9a 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -35,6 +35,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/servicehelper.hxx> #include <com/sun/star/security/CertificateValidity.hpp> +#include <com/sun/star/drawing/XDrawView.hpp> #include <com/sun/star/security/DocumentSignatureInformation.hpp> #include <com/sun/star/security/DocumentDigitalSignatures.hpp> @@ -47,6 +48,7 @@ #include <svtools/sfxecode.hxx> #include <svtools/ehdl.hxx> #include <sal/log.hxx> +#include <sfx2/app.hxx> #include <comphelper/string.hxx> #include <basic/sbxcore.hxx> @@ -468,7 +470,21 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) SfxViewFrame* pFrame = GetFrame(); if (pFrame) { - pFrame->GetDispatcher()->Execute(SID_RELOAD); + // Store current page before reload. + SfxAllItemSet aSet(SfxGetpApp()->GetPool()); + uno::Reference<drawing::XDrawView> xController( + GetBaseModel()->getCurrentController(), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xPage(xController->getCurrentPage(), + uno::UNO_QUERY); + sal_Int32 nPage{}; + xPage->getPropertyValue("Number") >>= nPage; + if (nPage > 0) + { + // nPage is 1-based. + aSet.Put(SfxInt32Item(SID_PAGE_NUMBER, nPage - 1)); + } + SfxRequest aReq(SID_RELOAD, SfxCallMode::SLOT, aSet); + pFrame->ExecReload_Impl(aReq); } } else diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index d5041c7c7e2c..b0f1e40fbb82 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -66,6 +66,8 @@ #include <com/sun/star/document/XViewDataSupplier.hpp> #include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/task/InteractionHandler.hpp> +#include <com/sun/star/drawing/XDrawView.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> @@ -853,6 +855,20 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) aViewFrames.clear(); } + const SfxInt32Item* pPageNumber = rReq.GetArg<SfxInt32Item>(SID_PAGE_NUMBER); + if (pPageNumber && pPageNumber->GetValue() >= 0) + { + // Restore current page after reload. + uno::Reference<drawing::XDrawView> xController( + xNewObj->GetModel()->getCurrentController(), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPagesSupplier> xSupplier(xNewObj->GetModel(), + uno::UNO_QUERY); + uno::Reference<drawing::XDrawPages> xDrawPages = xSupplier->getDrawPages(); + uno::Reference<drawing::XDrawPage> xDrawPage( + xDrawPages->getByIndex(pPageNumber->GetValue()), uno::UNO_QUERY); + xController->setCurrentPage(xDrawPage); + } + // Propagate document closure. SfxGetpApp()->NotifyEvent( SfxEventHint( SfxEventHintId::CloseDoc, GlobalEventConfig::GetEventName( GlobalEventId::CLOSEDOC ), xOldObj ) ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits