sw/CppunitTest_sw_uibase_shells.mk | 1 sw/qa/uibase/shells/textfld.cxx | 60 ++++++++++++++++++++++++++++++++++++ sw/sdi/swriter.sdi | 2 - sw/source/uibase/shells/textfld.cxx | 10 ++++++ 4 files changed, 72 insertions(+), 1 deletion(-)
New commits: commit 13594ec9080912f59a0700fed603022138c5f806 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jan 18 08:20:24 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jan 19 15:48:28 2023 +0000 sw, .uno:InsertField: add a new Wrapper parameter This is similar to ceea8f3924f26d5f10adc41b9ea587c77c2fda74 (sw: .uno:TextFormField: add new Wrapper parameter, 2023-01-16), but that was for fieldmarks & footnotes, while this is for refmarks & footnotes. Also start a new test file as the one for the entire directory starts to grow too long. (cherry picked from commit e9d5ccd5a0822969412dbddf0191e28703e72e82) Change-Id: Ib7c0e03d6686a8a52a5691a4e2dbf97dcc2facba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145713 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/CppunitTest_sw_uibase_shells.mk b/sw/CppunitTest_sw_uibase_shells.mk index a3d880458663..c4a1cee37a74 100644 --- a/sw/CppunitTest_sw_uibase_shells.mk +++ b/sw/CppunitTest_sw_uibase_shells.mk @@ -14,6 +14,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sw_uibase_shells)) $(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_uibase_shells)) $(eval $(call gb_CppunitTest_add_exception_objects,sw_uibase_shells, \ + sw/qa/uibase/shells/textfld \ sw/qa/uibase/shells/shells \ )) diff --git a/sw/qa/uibase/shells/textfld.cxx b/sw/qa/uibase/shells/textfld.cxx new file mode 100644 index 000000000000..7799063a016c --- /dev/null +++ b/sw/qa/uibase/shells/textfld.cxx @@ -0,0 +1,60 @@ +/* -*- 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 <swmodeltestbase.hxx> + +#include <comphelper/propertyvalue.hxx> + +#include <wrtsh.hxx> +#include <docsh.hxx> +#include <ftnidx.hxx> +#include <txtftn.hxx> + +namespace +{ +/// Covers sw/source/uibase/shells/textfld.cxx fixes. +class Test : public SwModelTestBase +{ +public: + Test() + : SwModelTestBase("/sw/qa/uibase/shells/data/") + { + } +}; +} + +CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkFootnote) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting a refmark inside a footnote: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", uno::Any(OUString("myref"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("content"))), + comphelper::makePropertyValue("Wrapper", uno::Any(OUString("Footnote"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + + // Then make sure that the note body contains the refmark: + SwFootnoteIdxs& rNotes = pDoc->GetFootnoteIdxs(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. no note was inserted. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rNotes.size()); + SwTextFootnote* pNote = rNotes[0]; + const SwFormatFootnote& rFormatNote = pNote->GetFootnote(); + CPPUNIT_ASSERT(!rFormatNote.IsEndNote()); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT_EQUAL(OUString("content"), rFormatNote.GetFootnoteText(*pWrtShell->GetLayout())); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index 64da3512ef94..ea549387516c 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -2911,7 +2911,7 @@ SfxVoidItem InsertEnvelope FN_ENVELOP ] SfxVoidItem InsertField FN_INSERT_FIELD -(SfxUInt16Item Type FN_PARAM_FIELD_TYPE,SfxUInt16Item SubType FN_PARAM_FIELD_SUBTYPE,SfxStringItem Name FN_INSERT_FIELD,SfxStringItem Content FN_PARAM_FIELD_CONTENT,SfxUInt32Item Format FN_PARAM_FIELD_FORMAT,SfxStringItem Separator FN_PARAM_3, SfxStringItem TypeName FN_PARAM_4) +(SfxUInt16Item Type FN_PARAM_FIELD_TYPE,SfxUInt16Item SubType FN_PARAM_FIELD_SUBTYPE,SfxStringItem Name FN_INSERT_FIELD,SfxStringItem Content FN_PARAM_FIELD_CONTENT,SfxUInt32Item Format FN_PARAM_FIELD_FORMAT,SfxStringItem Separator FN_PARAM_3, SfxStringItem TypeName FN_PARAM_4, SfxStringItem Wrapper FN_PARAM_5) [ AutoUpdate = FALSE, FastCall = FALSE, diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index bce713647c62..a68b17124d2b 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -290,6 +290,16 @@ void SwTextShell::ExecField(SfxRequest &rReq) if(!sTmp.isEmpty()) cSeparator = sTmp[0]; } + if (pArgs->GetItemState(FN_PARAM_5, false, &pItem) == SfxItemState::SET) + { + const OUString& rWrapper = static_cast<const SfxStringItem *>(pItem)->GetValue(); + if (rWrapper == "Footnote") + { + // Wrap the field in the requested container instead of inserting it + // directly at the cursor position. + GetShellPtr()->InsertFootnote(OUString()); + } + } SwInsertField_Data aData(nType, nSubType, aPar1, aPar2, nFormat, GetShellPtr(), cSeparator ); bRes = aFieldMgr.InsertField( aData ); }