sc/inc/cellvalues.hxx | 3 +++ sc/inc/formularesult.hxx | 3 ++- sc/source/core/data/cellvalues.cxx | 7 +++++++ sc/source/core/data/column4.cxx | 22 ++++++++++++++++++---- sc/source/core/tool/formularesult.cxx | 4 ++-- 5 files changed, 32 insertions(+), 7 deletions(-)
New commits: commit 40a59e3e58de1c3f60ae52d09fbc386399f8f122 Author: Eike Rathke <er...@redhat.com> AuthorDate: Wed Dec 7 21:22:41 2022 +0100 Commit: Eike Rathke <er...@redhat.com> CommitDate: Wed Dec 7 23:41:51 2022 +0000 Resolves: tdf#120190 Handle multiline string in Formula to Value conversion ... as usual as EditTextObject. Change-Id: Iddb52593851dcf371318f29318902ae8d4b483d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143801 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins diff --git a/sc/inc/cellvalues.hxx b/sc/inc/cellvalues.hxx index 0043d65270e6..352a152ec891 100644 --- a/sc/inc/cellvalues.hxx +++ b/sc/inc/cellvalues.hxx @@ -15,6 +15,7 @@ class ScColumn; class ScFormulaCell; +class EditTextObject; namespace svl { @@ -69,6 +70,8 @@ public: void reset(size_t nSize); void setValue(size_t nRow, double fVal); void setValue(size_t nRow, const svl::SharedString& rStr); + /// Takes ownership of pEditText. + void setValue(size_t nRow, std::unique_ptr<EditTextObject> pEditText); void swap(CellValues& r); diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx index ff036a78bcb3..581d9a4bba3d 100644 --- a/sc/inc/formularesult.hxx +++ b/sc/inc/formularesult.hxx @@ -35,12 +35,13 @@ struct FormulaResultValue double mfValue; svl::SharedString maString; + bool mbMultiLine = false; Type meType; FormulaError mnError; FormulaResultValue(); FormulaResultValue( double fValue ); - FormulaResultValue( svl::SharedString aStr ); + FormulaResultValue( svl::SharedString aStr, bool bMultiLine ); FormulaResultValue( FormulaError nErr ); }; diff --git a/sc/source/core/data/cellvalues.cxx b/sc/source/core/data/cellvalues.cxx index 290dc0d091a9..d23d7a9eccca 100644 --- a/sc/source/core/data/cellvalues.cxx +++ b/sc/source/core/data/cellvalues.cxx @@ -11,6 +11,7 @@ #include <cellvalues.hxx> #include <column.hxx> #include <formulacell.hxx> +#include <editeng/editobj.hxx> #include <cassert> @@ -147,6 +148,12 @@ void CellValues::setValue( size_t nRow, const svl::SharedString& rStr ) mpImpl->miAttrPos = mpImpl->maCellTextAttrs.set(mpImpl->miAttrPos, nRow, sc::CellTextAttr()); } +void CellValues::setValue( size_t nRow, std::unique_ptr<EditTextObject> pEditText ) +{ + mpImpl->miCellPos = mpImpl->maCells.set(mpImpl->miCellPos, nRow, pEditText.release()); + mpImpl->miAttrPos = mpImpl->maCellTextAttrs.set(mpImpl->miAttrPos, nRow, sc::CellTextAttr()); +} + void CellValues::swap( CellValues& r ) { std::swap(mpImpl, r.mpImpl); diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index ce982e920f8c..83123dffd88b 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -30,6 +30,7 @@ #include <compiler.hxx> #include <recursionhelper.hxx> #include <docsh.hxx> +#include <editutil.hxx> #include <SparklineGroup.hxx> @@ -478,13 +479,15 @@ namespace { class ConvertFormulaToValueHandler { sc::CellValues maResValues; + ScDocument& mrDoc; bool mbModified; public: - ConvertFormulaToValueHandler(ScSheetLimits const & rSheetLimits) : + ConvertFormulaToValueHandler(ScDocument& rDoc) : + mrDoc(rDoc), mbModified(false) { - maResValues.reset(rSheetLimits.GetMaxRowCount()); + maResValues.reset(mrDoc.GetSheetLimits().GetMaxRowCount()); } void operator() ( size_t nRow, const ScFormulaCell* pCell ) @@ -496,7 +499,18 @@ public: maResValues.setValue(nRow, aRes.mfValue); break; case sc::FormulaResultValue::String: - maResValues.setValue(nRow, aRes.maString); + if (aRes.mbMultiLine) + { + ScFieldEditEngine& rEngine = mrDoc.GetEditEngine(); + rEngine.SetTextCurrentDefaults(aRes.maString.getString()); + std::unique_ptr<EditTextObject> pObj(rEngine.CreateTextObject()); + pObj->NormalizeString(mrDoc.GetSharedStringPool()); + maResValues.setValue(nRow, std::move(pObj)); + } + else + { + maResValues.setValue(nRow, aRes.maString); + } break; case sc::FormulaResultValue::Error: case sc::FormulaResultValue::Invalid: @@ -528,7 +542,7 @@ void ScColumn::ConvertFormulaToValue( sc::SharedFormulaUtil::splitFormulaCellGroups(GetDoc(), maCells, aBounds); // Parse all formulas within the range and store their results into temporary storage. - ConvertFormulaToValueHandler aFunc(GetDoc().GetSheetLimits()); + ConvertFormulaToValueHandler aFunc(GetDoc()); sc::ParseFormula(maCells.begin(), maCells, nRow1, nRow2, aFunc); if (!aFunc.isModified()) // No formula cells encountered. diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx index 31b13af8fea8..b421354550a3 100644 --- a/sc/source/core/tool/formularesult.cxx +++ b/sc/source/core/tool/formularesult.cxx @@ -18,7 +18,7 @@ namespace sc { FormulaResultValue::FormulaResultValue() : mfValue(0.0), meType(Invalid), mnError(FormulaError::NONE) {} FormulaResultValue::FormulaResultValue( double fValue ) : mfValue(fValue), meType(Value), mnError(FormulaError::NONE) {} -FormulaResultValue::FormulaResultValue( svl::SharedString aStr ) : mfValue(0.0), maString(std::move(aStr)), meType(String), mnError(FormulaError::NONE) {} +FormulaResultValue::FormulaResultValue( svl::SharedString aStr, bool bMultiLine ) : mfValue(0.0), maString(std::move(aStr)), mbMultiLine(bMultiLine), meType(String), mnError(FormulaError::NONE) {} FormulaResultValue::FormulaResultValue( FormulaError nErr ) : mfValue(0.0), meType(Error), mnError(nErr) {} } @@ -428,7 +428,7 @@ sc::FormulaResultValue ScFormulaResult::GetResult() const return sc::FormulaResultValue(); if (isString(sv)) - return sc::FormulaResultValue(GetString()); + return sc::FormulaResultValue(GetString(), IsMultiline()); // Invalid return sc::FormulaResultValue();