sw/source/core/fields/usrfld.cxx |    2 +-
 sw/source/ui/fldui/fldvar.cxx    |   25 ++++++++++++++++++++-----
 2 files changed, 21 insertions(+), 6 deletions(-)

New commits:
commit 8c8457526a11fd03ed63a86ecdeeb270d5551049
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Sat Apr 1 17:19:12 2023 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Sun Apr 2 11:29:05 2023 +0200

    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.
    
    Change-Id: I199575469672a9f8bada2d2edde5036766977501
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149910
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sw/source/ui/fldui/fldvar.cxx b/sw/source/ui/fldui/fldvar.cxx
index e0db9b458294..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_uInt32 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
commit ba6d84b854e1abd3e913423dbcfaf192f7ade7f2
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Sat Apr 1 16:59:07 2023 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Sun Apr 2 11:28:56 2023 +0200

    Resolves: tdf#154218 Tie user field content value string to content locale
    
    ... instead of the format's locale.
    
    Change-Id: I83aeaa1433486241626fafc1ab9b4e2b3802d3eb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149909
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/fields/usrfld.cxx b/sw/source/core/fields/usrfld.cxx
index 33a5e7096dc4..4f84b8b7bcbb 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());
         }
     }
 

Reply via email to