Resolves: tdf#154218 Use the proper document's SwCalc locale for formula field
... instead of the format's locale to generate the expanded value
string to be reinterpreted again. i.e. inherited by SwSetExpField
used with Set variable.
Change-Id: I0bb545282a50032f2d8d2965020a36e3c5c8914e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149911
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx
index e91ede1..87583f7 100644
--- a/sw/inc/calc.hxx
+++ b/sw/inc/calc.hxx
@@ -22,6 +22,7 @@
#include <memory>
#include <vector>
#include <i18nlangtag/lang.h>
#include <basic/sbxvar.hxx>
#include <unotools/syslocale.hxx>
#include <rtl/ustrbuf.hxx>
@@ -260,6 +261,8 @@ public:
static bool Str2Double( const OUString& rStr, sal_Int32& rPos,
double& rVal, SwDoc const *const pDoc );
static LanguageType GetDocAppScriptLang( SwDoc const & rDoc );
SW_DLLPUBLIC static bool IsValidVarName( const OUString& rStr,
OUString* pValidName = nullptr );
};
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 592f969..d6b0976 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -195,7 +195,8 @@ CalcOp* FindOperator( const OUString& rSrch )
OperatorCompare ));
}
static LanguageType GetDocAppScriptLang( SwDoc const & rDoc )
// static
LanguageType SwCalc::GetDocAppScriptLang( SwDoc const & rDoc )
{
TypedWhichId<SvxLanguageItem> nWhich =
GetWhichOfScript( RES_CHRATR_LANGUAGE,
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index 80ae487..2f816d2 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -807,6 +807,7 @@ void SwFormulaField::SetFormula(const OUString& rStr)
{
sal_Int32 nPos = 0;
double fTmpValue;
// Uses the SwCalc document locale.
if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
SwValueField::SetValue( fTmpValue );
}
@@ -824,7 +825,10 @@ void SwFormulaField::SetExpandedFormula( const OUString& rStr )
{
SwValueField::SetValue(fTmpValue);
m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(fTmpValue, nFormat);
// Will get reinterpreted by SwCalc when updating fields, so use
// the proper locale.
m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString( fTmpValue,
SwCalc::GetDocAppScriptLang( *GetDoc()));
return;
}
}