sw/inc/calc.hxx | 3 +++ sw/source/core/bastyp/calc.cxx | 3 ++- sw/source/core/fields/fldbas.cxx | 6 +++++- sw/source/core/fields/usrfld.cxx | 2 +- sw/source/ui/fldui/fldvar.cxx | 25 ++++++++++++++++++++----- 5 files changed, 31 insertions(+), 8 deletions(-)
New commits: commit 1093fc294ea5a823da4ebcfdafbef3327f9c82bf Author: Eike Rathke <[email protected]> AuthorDate: Sun Apr 2 11:51:43 2023 +0200 Commit: Michael Stahl <[email protected]> CommitDate: Wed Apr 5 11:24:33 2023 +0200 Resolves: tdf#154218 Use proper locale for user field and set variable This is a combination of 3 commits. Resolves: tdf#154218 Tie user field content value string to content locale ... instead of the format's locale. xChange-Id: I83aeaa1433486241626fafc1ab9b4e2b3802d3eb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149909 Reviewed-by: Eike Rathke <[email protected]> Tested-by: Jenkins (cherry picked from commit ba6d84b854e1abd3e913423dbcfaf192f7ade7f2) Related: tdf#154218 Actually use the top format selected Choosing a format of Additional Formats replaces the listbox content with the format's category so the assumption that Text would be the first entry does not hold. For such format still Text was assumed and the input used as literal string, which defeated the actual value formatting capabilities and a possible formula interpretation for SwUserFieldType. xChange-Id: I199575469672a9f8bada2d2edde5036766977501 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149910 Reviewed-by: Eike Rathke <[email protected]> Tested-by: Jenkins (cherry picked from commit 8c8457526a11fd03ed63a86ecdeeb270d5551049) Conflicts: sw/source/ui/fldui/fldvar.cxx 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. xChange-Id: I0bb545282a50032f2d8d2965020a36e3c5c8914e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149911 Reviewed-by: Eike Rathke <[email protected]> Tested-by: Jenkins (cherry picked from commit 82ed010cd39351adcd4015e2bdd1591aa869cf18) Change-Id: I83aeaa1433486241626fafc1ab9b4e2b3802d3eb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149936 Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx index e91ede14e6a5..87583f752ff4 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 592f969bde0b..d6b09766fb40 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 59e54e291dbb..82dd70668387 100644 --- a/sw/source/core/fields/fldbas.cxx +++ b/sw/source/core/fields/fldbas.cxx @@ -778,6 +778,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 ); } @@ -795,7 +796,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; } } diff --git a/sw/source/core/fields/usrfld.cxx b/sw/source/core/fields/usrfld.cxx index 0067d3b6d7c4..9e490efd03c2 100644 --- a/sw/source/core/fields/usrfld.cxx +++ b/sw/source/core/fields/usrfld.cxx @@ -307,7 +307,7 @@ void SwUserFieldType::SetContent( const OUString& rStr, sal_uInt32 nFormat ) SetValue(fValue); LanguageTag aContentLanguage(GetFieldTypeLanguage()); m_aContentLang = aContentLanguage.getBcp47(); - m_aContent = DoubleToString(fValue, nFormat); + m_aContent = DoubleToString(fValue, aContentLanguage.getLanguageType()); } } diff --git a/sw/source/ui/fldui/fldvar.cxx b/sw/source/ui/fldui/fldvar.cxx index 5116ae438780..bf2456ee8c41 100644 --- a/sw/source/ui/fldui/fldvar.cxx +++ b/sw/source/ui/fldui/fldvar.cxx @@ -1006,8 +1006,15 @@ IMPL_LINK(SwFieldVarPage, TBClickHdl, weld::Button&, rBox, void) { if (nNumFormatPos != -1) { - sal_uLong nNumberFormat = nNumFormatPos == 0 ? 0 : m_xNumFormatLB->GetFormat(); - if (nNumberFormat) + // The first listbox entry is Text and second is + // Formula and both are SAL_MAX_UINT32 :-/ but only if + // not another yet unlisted of Additional Formats was + // selected that may claim the top position :-/ + sal_uInt32 nNumberFormat = m_xNumFormatLB->GetFormat(); + const bool bText = (nNumFormatPos == 0 && nNumberFormat == SAL_MAX_UINT32); + if (bText) + nNumberFormat = 0; + if (nNumberFormat && nNumberFormat != SAL_MAX_UINT32) { // Switch language to office-language because Kalkulator expects // String in office format and it should be fed into dialog like // that @@ -1015,7 +1022,7 @@ IMPL_LINK(SwFieldVarPage, TBClickHdl, weld::Button&, rBox, void) } static_cast<SwUserFieldType*>(pType)->SetContent(m_xValueED->get_text(), nNumberFormat); static_cast<SwUserFieldType*>(pType)->SetType( - nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR ); + bText ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR ); } } else @@ -1049,8 +1056,16 @@ IMPL_LINK(SwFieldVarPage, TBClickHdl, weld::Button&, rBox, void) if (nNumFormatPos != -1) { - aType.SetType(nNumFormatPos == 0 ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR); - aType.SetContent( sValue, nNumFormatPos == 0 ? 0 : m_xNumFormatLB->GetFormat() ); + // The first listbox entry is Text and second is + // Formula and both are SAL_MAX_UINT32 :-/ but only if + // not another yet unlisted of Additional Formats was + // selected that may claim the top position :-/ + sal_uInt32 nNumberFormat = m_xNumFormatLB->GetFormat(); + const bool bText = (nNumFormatPos == 0 && nNumberFormat == SAL_MAX_UINT32); + if (bText) + nNumberFormat = 0; + aType.SetType(bText ? nsSwGetSetExpType::GSE_STRING : nsSwGetSetExpType::GSE_EXPR); + aType.SetContent( sValue, nNumberFormat ); m_xSelectionLB->append_text(sName); m_xSelectionLB->select_text(sName); GetFieldMgr().InsertFieldType( aType ); // Userfld new
