sc/source/ui/view/viewdata.cxx | 2 - sw/CppunitTest_sw_uibase_shells.mk | 1 sw/qa/uibase/shells/textfld.cxx | 61 ++++++++++++++++++++++++++++++++++++ sw/sdi/swriter.sdi | 2 - sw/source/uibase/shells/textfld.cxx | 10 +++++ 5 files changed, 74 insertions(+), 2 deletions(-)
New commits: commit 1f8c02353d653a6d4a72d918aaf6be5f367137c9 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Jan 13 08:56:29 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jan 18 09:56:33 2023 +0000 sc: fix crash in ScViewData::GetCurXForTab() Crashreport signature: program/libsclo.so ScViewData::GetCurXForTab(short) const sc/source/ui/view/viewdata.cxx:1431 program/libsclo.so ScViewFunc::OnLOKInsertDeleteColumn(short, long) sc/source/ui/view/viewfunc.cxx:1552 program/libsclo.so ScDocFunc::InsertCells(ScRange const&, ScMarkData const*, InsCellCmd, bool, bool, bool) source/ui/docshell/docfunc.cxx:2256 program/libsclo.so ScViewFunc::InsertCells(InsCellCmd, bool, bool) sc/source/ui/view/viewfunc.cxx:1658 Seeing that e.g. ScViewData::WriteUserDataSequence() already checks if the pointer in maTabData is a nullptr, do the same here. Change-Id: I0ebdba8c8a5bedd3c3c57c36bdf0632e2fee45c9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145697 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 0ef96d96c7ae..ae68a5dfc725 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -1429,7 +1429,7 @@ SCROW ScViewData::GetPosY( ScVSplitPos eWhich, SCTAB nForTab ) const SCCOL ScViewData::GetCurXForTab( SCTAB nTabIndex ) const { - if (!ValidTab(nTabIndex) || (nTabIndex >= static_cast<SCTAB>(maTabData.size()))) + if (!ValidTab(nTabIndex) || (nTabIndex >= static_cast<SCTAB>(maTabData.size())) || !maTabData[nTabIndex]) return -1; return maTabData[nTabIndex]->nCurX; commit e9d5ccd5a0822969412dbddf0191e28703e72e82 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jan 18 08:20:24 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jan 18 09:56:23 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. Change-Id: Ib7c0e03d6686a8a52a5691a4e2dbf97dcc2facba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145698 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/CppunitTest_sw_uibase_shells.mk b/sw/CppunitTest_sw_uibase_shells.mk index 14e961f4725d..932769a421e6 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..ef4da3aa65b1 --- /dev/null +++ b/sw/qa/uibase/shells/textfld.cxx @@ -0,0 +1,61 @@ +/* -*- 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: + 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: + SwDoc* pDoc = getSwDoc(); + 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 = getSwDocShell()->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 b974614b1e01..49f181d9b377 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -2943,7 +2943,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 97f94174e987..6c4fa4297c46 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -299,6 +299,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 ); }