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 <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/inc/cellvalues.hxx b/sc/inc/cellvalues.hxx
index 0043d65..352a152 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 ff036a7..581d9a4 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 290dc0d..d23d7a9 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 ce982e9..83123df 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 31b13af..b421354 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();