[Libreoffice-commits] core.git: sc/inc sc/qa sc/source

Katarina Behrens Katarina.Behrens at cib.de
Fri Jul 24 07:33:51 PDT 2015


 sc/inc/calcconfig.hxx                  |    2 +
 sc/qa/unit/ucalc_formula.cxx           |   11 ++++----
 sc/source/core/tool/calcconfig.cxx     |   12 ++++++++-
 sc/source/core/tool/interpr1.cxx       |    7 ++++-
 sc/source/ui/optdlg/calcoptionsdlg.cxx |    2 -
 sc/source/ui/unoobj/confuno.cxx        |   43 ++++++++++++++++++---------------
 6 files changed, 50 insertions(+), 27 deletions(-)

New commits:
commit 738be269bfc795400fcb10d4eefb6c33b17bded4
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Thu Jul 23 09:52:59 2015 +0200

    tdf#92256: Handle case when string ref syntax is unknown
    
    i.e. the document doesn't have that property. Use CONV_A1_XL_A1
    pseudoconvention for interpreting INDIRECT in such case
    
    Change-Id: If9bac9053029b4b8f79d3ac7ac0759adbb25803f
    Reviewed-on: https://gerrit.libreoffice.org/17311
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/inc/calcconfig.hxx b/sc/inc/calcconfig.hxx
index d10154c..18aab21 100644
--- a/sc/inc/calcconfig.hxx
+++ b/sc/inc/calcconfig.hxx
@@ -43,6 +43,7 @@ struct SC_DLLPUBLIC ScCalcConfig
     formula::FormulaGrammar::AddressConvention meStringRefAddressSyntax;
     StringConversion meStringConversion;
     bool mbEmptyStringAsZero:1;
+    bool mbHasStringRefSyntax:1;
 
     bool mbOpenCLSubsetOnly:1;
     bool mbOpenCLAutoSelect:1;
@@ -59,6 +60,7 @@ struct SC_DLLPUBLIC ScCalcConfig
 
     void reset();
     void MergeDocumentSpecific( const ScCalcConfig& r );
+    void SetStringRefSyntax( formula::FormulaGrammar::AddressConvention eConv );
 
     bool operator== (const ScCalcConfig& r) const;
     bool operator!= (const ScCalcConfig& r) const;
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 8610c54..b7c4fd7 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -4396,9 +4396,10 @@ void Test::testFuncINDIRECT()
 
     m_pDoc->CalcAll();
     {
-        // Default is to use the current formula syntax, which is Calc A1.
+        // Default is to use compatibility mode, accept both Calc A1 and
+        // Excel A1 syntax
         const OUString* aChecks[] = {
-            &aTest, &aRefErr, &aRefErr, &aTest
+            &aTest, &aTest, &aRefErr, &aTest
         };
 
         for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
@@ -4409,7 +4410,7 @@ void Test::testFuncINDIRECT()
     }
 
     ScCalcConfig aConfig;
-    aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_OOO;
+    aConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_OOO );
     m_pDoc->SetCalcConfig(aConfig);
     m_pDoc->CalcAll();
     {
@@ -4425,7 +4426,7 @@ void Test::testFuncINDIRECT()
         }
     }
 
-    aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_XL_A1;
+    aConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_A1 );
     m_pDoc->SetCalcConfig(aConfig);
     m_pDoc->CalcAll();
     {
@@ -4441,7 +4442,7 @@ void Test::testFuncINDIRECT()
         }
     }
 
-    aConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_XL_R1C1;
+    aConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_XL_R1C1 );
     m_pDoc->SetCalcConfig(aConfig);
     m_pDoc->CalcAll();
     {
diff --git a/sc/source/core/tool/calcconfig.cxx b/sc/source/core/tool/calcconfig.cxx
index 6fd4345..cc52ad7 100644
--- a/sc/source/core/tool/calcconfig.cxx
+++ b/sc/source/core/tool/calcconfig.cxx
@@ -23,7 +23,8 @@
 ScCalcConfig::ScCalcConfig() :
     meStringRefAddressSyntax(formula::FormulaGrammar::CONV_UNSPECIFIED),
     meStringConversion(StringConversion::LOCALE),     // old LibreOffice behavior
-    mbEmptyStringAsZero(false)
+    mbEmptyStringAsZero(false),
+    mbHasStringRefSyntax(false)
 {
     setOpenCLConfigToDefault();
 
@@ -85,6 +86,13 @@ void ScCalcConfig::MergeDocumentSpecific( const ScCalcConfig& r )
     mbEmptyStringAsZero      = r.mbEmptyStringAsZero;
     // INDIRECT ref syntax is per document.
     meStringRefAddressSyntax = r.meStringRefAddressSyntax;
+    mbHasStringRefSyntax      = r.mbHasStringRefSyntax;
+}
+
+void ScCalcConfig::SetStringRefSyntax( formula::FormulaGrammar::AddressConvention eConv )
+{
+    meStringRefAddressSyntax = eConv;
+    mbHasStringRefSyntax = true;
 }
 
 bool ScCalcConfig::operator== (const ScCalcConfig& r) const
@@ -92,6 +100,7 @@ bool ScCalcConfig::operator== (const ScCalcConfig& r) const
     return meStringRefAddressSyntax == r.meStringRefAddressSyntax &&
            meStringConversion == r.meStringConversion &&
            mbEmptyStringAsZero == r.mbEmptyStringAsZero &&
+           mbHasStringRefSyntax == r.mbHasStringRefSyntax &&
            mbOpenCLSubsetOnly == r.mbOpenCLSubsetOnly &&
            mbOpenCLAutoSelect == r.mbOpenCLAutoSelect &&
            maOpenCLDevice == r.maOpenCLDevice &&
@@ -127,6 +136,7 @@ std::ostream& operator<<(std::ostream& rStream, const ScCalcConfig& rConfig)
         "StringRefAddressSyntax=" << rConfig.meStringRefAddressSyntax << ","
         "StringConversion=" << StringConversionToString(rConfig.meStringConversion) << ","
         "EmptyStringAsZero=" << (rConfig.mbEmptyStringAsZero?"Y":"N") << ","
+        "HasStringRefSyntax=" << (rConfig.mbHasStringRefSyntax?"Y":"N") << ","
         "OpenCLSubsetOnly=" << (rConfig.mbOpenCLSubsetOnly?"Y":"N") << ","
         "OpenCLAutoSelect=" << (rConfig.mbOpenCLAutoSelect?"Y":"N") << ","
         "OpenCLDevice='" << rConfig.maOpenCLDevice << "',"
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 31e98b1..ec7c41f 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -7031,13 +7031,18 @@ void ScInterpreter::ScIndirect()
             // Use the current address syntax if unspecified.
             eConv = pDok->GetAddressConvention();
 
+        // either CONV_A1_XL_A1 was explicitly configured, or nothing at all
+        // was configured
+        bool bTryXlA1 = (eConv == FormulaGrammar::CONV_A1_XL_A1 ||
+                          !maCalcConfig.mbHasStringRefSyntax);
+
         if (nParamCount == 2 && 0.0 == ::rtl::math::approxFloor( GetDouble()))
         {
             // Overwrite the config and try Excel R1C1.
             eConv = FormulaGrammar::CONV_XL_R1C1;
+            bTryXlA1 = false;
         }
 
-        bool bTryXlA1 = (eConv == FormulaGrammar::CONV_A1_XL_A1);
 
         const ScAddress::Details aDetails( bTryXlA1 ? FormulaGrammar::CONV_OOO : eConv, aPos );
         const ScAddress::Details aDetailsXlA1( FormulaGrammar::CONV_XL_A1, aPos );
diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index 6f2de0b..dc41f5f 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -226,7 +226,7 @@ IMPL_LINK(ScCalcOptionsDialog, ConversionModifiedHdl, ListBox*, pConv )
 
 IMPL_LINK(ScCalcOptionsDialog, SyntaxModifiedHdl, ListBox*, pSyntax)
 {
-    maConfig.meStringRefAddressSyntax = toAddressConvention(pSyntax->GetSelectEntryPos());
+    maConfig.SetStringRefSyntax(toAddressConvention(pSyntax->GetSelectEntryPos()));
     return 0;
 }
 
diff --git a/sc/source/ui/unoobj/confuno.cxx b/sc/source/ui/unoobj/confuno.cxx
index 5d0385e..c695f4f 100644
--- a/sc/source/ui/unoobj/confuno.cxx
+++ b/sc/source/ui/unoobj/confuno.cxx
@@ -312,10 +312,10 @@ void SAL_CALL ScDocumentConfiguration::setPropertyValue(
                     case 2: // CONV_XL_A1
                     case 3: // CONV_XL_R1C1
                     case 7: // CONV_A1_XL_A1
-                        aCalcConfig.meStringRefAddressSyntax = static_cast<formula::FormulaGrammar::AddressConvention>( nUno );
+                        aCalcConfig.SetStringRefSyntax( static_cast<formula::FormulaGrammar::AddressConvention>( nUno ) );
                         break;
                     default:
-                        aCalcConfig.meStringRefAddressSyntax = formula::FormulaGrammar::CONV_UNSPECIFIED;
+                        aCalcConfig.SetStringRefSyntax( formula::FormulaGrammar::CONV_UNSPECIFIED );
                         break;
 
                 }
@@ -461,26 +461,31 @@ uno::Any SAL_CALL ScDocumentConfiguration::getPropertyValue( const OUString& aPr
         else if ( aPropertyName == SC_UNO_SYNTAXSTRINGREF )
         {
             ScCalcConfig aCalcConfig = rDoc.GetCalcConfig();
-            formula::FormulaGrammar::AddressConvention aConv = aCalcConfig.meStringRefAddressSyntax;
 
-            switch (aConv)
+            // if it hasn't been read or explicitly changed, don't write it
+            if ( aCalcConfig.mbHasStringRefSyntax )
             {
-                case formula::FormulaGrammar::CONV_OOO:
-                case formula::FormulaGrammar::CONV_XL_A1:
-                case formula::FormulaGrammar::CONV_XL_R1C1:
-                case formula::FormulaGrammar::CONV_A1_XL_A1:
-                     aRet <<= static_cast<sal_Int16>( aConv );
-                     break;
-
-                case formula::FormulaGrammar::CONV_UNSPECIFIED:
-                case formula::FormulaGrammar::CONV_ODF:
-                case formula::FormulaGrammar::CONV_XL_OOX:
-                case formula::FormulaGrammar::CONV_LOTUS_A1:
-                case formula::FormulaGrammar::CONV_LAST:
+                formula::FormulaGrammar::AddressConvention aConv = aCalcConfig.meStringRefAddressSyntax;
+
+                switch (aConv)
                 {
-                    aRet <<= sal_Int16(9999);
-                    break;
-                }
+                    case formula::FormulaGrammar::CONV_OOO:
+                    case formula::FormulaGrammar::CONV_XL_A1:
+                    case formula::FormulaGrammar::CONV_XL_R1C1:
+                    case formula::FormulaGrammar::CONV_A1_XL_A1:
+                         aRet <<= static_cast<sal_Int16>( aConv );
+                         break;
+
+                    case formula::FormulaGrammar::CONV_UNSPECIFIED:
+                    case formula::FormulaGrammar::CONV_ODF:
+                    case formula::FormulaGrammar::CONV_XL_OOX:
+                    case formula::FormulaGrammar::CONV_LOTUS_A1:
+                    case formula::FormulaGrammar::CONV_LAST:
+                    {
+                        aRet <<= sal_Int16(9999);
+                        break;
+                    }
+                 }
              }
         }
 


More information about the Libreoffice-commits mailing list