[Libreoffice-commits] core.git: include/svl sc/source svl/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Sat Apr 18 01:08:54 UTC 2020


 include/svl/zforlist.hxx         |    3 +
 sc/source/core/tool/interpr1.cxx |   55 ----------------------------
 svl/source/numbers/zforlist.cxx  |   74 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 54 deletions(-)

New commits:
commit dbda099d198a2236bafea2209cb5e3fc58ee8741
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Fri Apr 17 21:20:41 2020 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Sat Apr 18 03:08:03 2020 +0200

    Move implementation of CELL("format";...) to SvNumberFormatter, tdf#132106 prep
    
    In preparation of further detailed handling.
    
    Change-Id: I9e4d916de031b742d0af1025b945b7608fed8266
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92462
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx
index 70371d59a1bd..664ddbc25de7 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -616,6 +616,9 @@ public:
                                      sal_uInt16& nPrecision, sal_uInt16& nLeadingCnt,
                                      LanguageType eLnge = LANGUAGE_DONTKNOW );
 
+    /// Get return string for Calc CELL() function, "G", "D1", ...
+    OUString GetCalcCellReturn( sal_uInt32 nFormat ) const;
+
     /// Check if format code string may be deleted by user
     bool IsUserDefined( const OUString& sStr, LanguageType eLnge = LANGUAGE_DONTKNOW );
 
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 8f54c25d258b..03a8f46731a6 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -2202,60 +2202,7 @@ namespace {
 
 void getFormatString(SvNumberFormatter* pFormatter, sal_uLong nFormat, OUString& rFmtStr)
 {
-    bool        bAppendPrec = true;
-    sal_uInt16  nPrec, nLeading;
-    bool        bThousand, bIsRed;
-    pFormatter->GetFormatSpecialInfo( nFormat, bThousand, bIsRed, nPrec, nLeading );
-
-    switch( pFormatter->GetType( nFormat ) )
-    {
-        case SvNumFormatType::NUMBER:
-            if(bThousand) rFmtStr = ","; else rFmtStr = "F";
-            break;
-        case SvNumFormatType::CURRENCY:
-            rFmtStr = "C";
-            break;
-        case SvNumFormatType::SCIENTIFIC:
-            rFmtStr = "S";
-            break;
-        case SvNumFormatType::PERCENT:
-            rFmtStr = "P";
-            break;
-        default:
-        {
-            bAppendPrec = false;
-            switch( pFormatter->GetIndexTableOffset( nFormat ) )
-            {
-                case NF_DATE_SYSTEM_SHORT:
-                case NF_DATE_SYS_DMMMYY:
-                case NF_DATE_SYS_DDMMYY:
-                case NF_DATE_SYS_DDMMYYYY:
-                case NF_DATE_SYS_DMMMYYYY:
-                case NF_DATE_DIN_DMMMYYYY:
-                case NF_DATE_SYS_DMMMMYYYY:
-                case NF_DATE_DIN_DMMMMYYYY: rFmtStr = "D1"; break;
-                case NF_DATE_SYS_DDMMM:     rFmtStr = "D2"; break;
-                case NF_DATE_SYS_MMYY:      rFmtStr = "D3"; break;
-                case NF_DATETIME_SYSTEM_SHORT_HHMM:
-                case NF_DATETIME_SYS_DDMMYYYY_HHMM:
-                case NF_DATETIME_SYS_DDMMYYYY_HHMMSS:
-                                            rFmtStr = "D4"; break;
-                case NF_DATE_DIN_MMDD:      rFmtStr = "D5"; break;
-                case NF_TIME_HHMMSSAMPM:    rFmtStr = "D6"; break;
-                case NF_TIME_HHMMAMPM:      rFmtStr = "D7"; break;
-                case NF_TIME_HHMMSS:        rFmtStr = "D8"; break;
-                case NF_TIME_HHMM:          rFmtStr = "D9"; break;
-                default:                    rFmtStr = "G";
-            }
-        }
-    }
-    if( bAppendPrec )
-        rFmtStr += OUString::number(nPrec);
-    const SvNumberformat* pFormat = pFormatter->GetEntry( nFormat );
-    if( lcl_FormatHasNegColor( pFormat ) )
-        rFmtStr += "-";
-    if( lcl_FormatHasOpenPar( pFormat ) )
-        rFmtStr += "()";
+    rFmtStr = pFormatter->GetCalcCellReturn( nFormat);
 }
 
 }
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 21886b25d04e..4edf0692a41e 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -2179,6 +2179,80 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin
     return nCheckPos;
 }
 
+OUString SvNumberFormatter::GetCalcCellReturn( sal_uInt32 nFormat ) const
+{
+    ::osl::MutexGuard aGuard( GetInstanceMutex() );
+    const SvNumberformat* pFormat = GetFormatEntry( nFormat );
+    if (!pFormat)
+        return "G";
+
+    OUString    aStr;
+    bool        bAppendPrec = true;
+    sal_uInt16  nPrec, nLeading;
+    bool        bThousand, bIsRed;
+    pFormat->GetFormatSpecialInfo( bThousand, bIsRed, nPrec, nLeading );
+
+    switch (pFormat->GetMaskedType())
+    {
+        case SvNumFormatType::NUMBER:
+            if (bThousand)
+                aStr = ",";
+            else
+                aStr = "F";
+        break;
+        case SvNumFormatType::CURRENCY:
+            aStr = "C";
+        break;
+        case SvNumFormatType::SCIENTIFIC:
+            aStr = "S";
+        break;
+        case SvNumFormatType::PERCENT:
+            aStr = "P";
+        break;
+        default:
+            {
+                bAppendPrec = false;
+                switch (GetIndexTableOffset( nFormat ))
+                {
+                    case NF_DATE_SYSTEM_SHORT:
+                    case NF_DATE_SYS_DMMMYY:
+                    case NF_DATE_SYS_DDMMYY:
+                    case NF_DATE_SYS_DDMMYYYY:
+                    case NF_DATE_SYS_DMMMYYYY:
+                    case NF_DATE_DIN_DMMMYYYY:
+                    case NF_DATE_SYS_DMMMMYYYY:
+                    case NF_DATE_DIN_DMMMMYYYY: aStr = "D1"; break;
+                    case NF_DATE_SYS_DDMMM:     aStr = "D2"; break;
+                    case NF_DATE_SYS_MMYY:      aStr = "D3"; break;
+                    case NF_DATETIME_SYSTEM_SHORT_HHMM:
+                    case NF_DATETIME_SYS_DDMMYYYY_HHMM:
+                    case NF_DATETIME_SYS_DDMMYYYY_HHMMSS:
+                                                aStr = "D4"; break;
+                    case NF_DATE_DIN_MMDD:      aStr = "D5"; break;
+                    case NF_TIME_HHMMSSAMPM:    aStr = "D6"; break;
+                    case NF_TIME_HHMMAMPM:      aStr = "D7"; break;
+                    case NF_TIME_HHMMSS:        aStr = "D8"; break;
+                    case NF_TIME_HHMM:          aStr = "D9"; break;
+                    default:                    aStr = "G";
+                }
+            }
+    }
+
+    if (bAppendPrec)
+        aStr += OUString::number(nPrec);
+
+    if (pFormat->GetColor( 1 ))
+        aStr += "-";    // negative color
+
+    /* FIXME: this probably should not match on literal strings and only be
+     * performed on number or currency formats, but it is what Calc originally
+     * implemented. */
+    if (pFormat->GetFormatstring().indexOf('(') != -1)
+        aStr += "()";
+
+    return aStr;
+}
+
 sal_Int32 SvNumberFormatter::ImpGetFormatCodeIndex(
             css::uno::Sequence< css::i18n::NumberFormatCode >& rSeq,
             const NfIndexTableOffset nTabOff )


More information about the Libreoffice-commits mailing list