sc/qa/extras/macros-test.cxx | 40 +++++++++++++++++++++++++++++++ sc/qa/extras/testdocuments/tdf104902.ods |binary sc/source/ui/view/viewfunc.cxx | 17 ++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-)
New commits: commit 7f220aeae695e06c5e5dfed6ccf1d8b8f8a13e6e Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Thu Dec 30 19:57:10 2021 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Feb 15 21:28:51 2022 +0100 tdf#104902 - Handle embedded newline in Calc's .uno:EnterString Change-Id: I6377aebb06b6e6873ce61984a887d9e16eecd361 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127766 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> (cherry picked from commit 44d237c375b7ef9a5a61a2f752bd19b57649ffbd) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129932 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index cf732e2dd294..559dd903e4eb 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -51,6 +51,7 @@ public: void testTdf114427(); void testTdf107885(); void testRowColumn(); + void testTdf104902(); void testTdf142033(); void testTdf131562(); void testPasswordProtectedUnicodeString(); @@ -82,6 +83,7 @@ public: CPPUNIT_TEST(testTdf114427); CPPUNIT_TEST(testTdf107885); CPPUNIT_TEST(testRowColumn); + CPPUNIT_TEST(testTdf104902); CPPUNIT_TEST(testTdf142033); CPPUNIT_TEST(testTdf131562); CPPUNIT_TEST(testPasswordProtectedUnicodeString); @@ -552,6 +554,44 @@ void ScMacrosTest::testMacroButtonFormControlXlsxExport() assertXPath(pWorkbookDoc, "//x:workbook/definedNames", 0); } +void ScMacrosTest::testTdf104902() +{ + OUString aFileName; + createFileURL(u"tdf104902.ods", aFileName); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.display_bug?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // Export to ODS + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell); + ScDocument& rDoc = pDocSh->GetDocument(); + + CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), rDoc.GetString(ScAddress(0, 0, 0))); + + // Without the fix in place, this test would have failed with + // - Expected: string with + // newlines + // - Actual : string withnewlines + CPPUNIT_ASSERT_EQUAL(OUString(u"string with" + OUStringChar(u'\xA') + u"newlines"), rDoc.GetString(ScAddress(0, 1, 0))); + + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + void ScMacrosTest::testTdf142033() { OUString aFileName; diff --git a/sc/qa/extras/testdocuments/tdf104902.ods b/sc/qa/extras/testdocuments/tdf104902.ods new file mode 100644 index 000000000000..8524522fdcd3 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf104902.ods differ diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index ecaa0a2cdf8a..95020795aceb 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -77,6 +77,7 @@ #include <comphelper/lok.hxx> #include <conditio.hxx> #include <columnspanset.hxx> +#include <stringutil.hxx> #include <memory> @@ -578,10 +579,24 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, } else { + ScFieldEditEngine& rEngine = rDoc.GetEditEngine(); for (const auto& rTab : rMark) { bool bNumFmtSet = false; - rFunc.SetNormalString( bNumFmtSet, ScAddress( nCol, nRow, rTab ), rString, false ); + const ScAddress aScAddress(nCol, nRow, rTab); + + // tdf#104902 - handle embedded newline + if (ScStringUtil::isMultiline(rString)) + { + rEngine.SetTextCurrentDefaults(rString); + rDoc.SetEditText(aScAddress, rEngine.CreateTextObject()); + pDocSh->AdjustRowHeight(nRow, nRow, rTab); + } + else + { + rFunc.SetNormalString(bNumFmtSet, aScAddress, rString, false); + } + if (bNumFmtSet) { /* FIXME: if set on any sheet results in changed only on