formula/source/core/api/FormulaCompiler.cxx |    3 +--
 sc/source/core/tool/compiler.cxx            |   24 +++++++++++++++++++++---
 2 files changed, 22 insertions(+), 5 deletions(-)

New commits:
commit 86ed0105a4d70d481e3358ae1c6855766ef44d23
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Wed Aug 3 22:54:46 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Thu Aug 4 02:50:59 2022 +0200

    Resolves: tdf#150253 Add English names for GRAM_API AddIn functions
    
    ... so not only the com.sun.star.sheet.addin.* programmatic names
    are recognized for XCell::setFormula() non-localized API calls.
    
    Change-Id: I1f1f3f45001360445b25765312782f04ee079ee9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137769
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/formula/source/core/api/FormulaCompiler.cxx 
b/formula/source/core/api/FormulaCompiler.cxx
index 1aa8d9f65855..a13a7a1734e8 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -961,8 +961,7 @@ void FormulaCompiler::InitSymbolsAPI() const
     static OpCodeMapData aMap;
     osl::MutexGuard aGuard(&aMap.maMtx);
     if (!aMap.mxSymbolMap)
-        // XFunctionAccess API always used PODF grammar, keep it.
-        loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH_API, 
FormulaGrammar::GRAM_PODF, aMap.mxSymbolMap, SeparatorType::RESOURCE_BASE);
+        loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH_API, 
FormulaGrammar::GRAM_API, aMap.mxSymbolMap, SeparatorType::RESOURCE_BASE);
     mxSymbolsAPI = aMap.mxSymbolMap;
 }
 
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 0de38ad001b2..2b1d70280926 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -110,6 +110,9 @@ void ScCompiler::fillFromAddInMap( const 
NonConstOpCodeMapPtr& xMap,FormulaGramm
     size_t nSymbolOffset;
     switch( _eGrammar )
     {
+        // XFunctionAccess and XCell::setFormula()/getFormula() API always used
+        // PODF grammar symbols, keep it.
+        case FormulaGrammar::GRAM_API:
         case FormulaGrammar::GRAM_PODF:
             nSymbolOffset = offsetof( AddInMap, pUpper);
             break;
@@ -121,9 +124,8 @@ void ScCompiler::fillFromAddInMap( const 
NonConstOpCodeMapPtr& xMap,FormulaGramm
             nSymbolOffset = offsetof( AddInMap, pEnglish);
             break;
     }
-    const AddInMap* pMap = g_aAddInMap;
-    const AddInMap* const pStop = pMap + GetAddInMapCount();
-    for ( ; pMap < pStop; ++pMap)
+    const AddInMap* const pStop = g_aAddInMap + GetAddInMapCount();
+    for (const AddInMap* pMap = g_aAddInMap; pMap < pStop; ++pMap)
     {
         char const * const * ppSymbol =
             reinterpret_cast< char const * const * >(
@@ -131,6 +133,22 @@ void ScCompiler::fillFromAddInMap( const 
NonConstOpCodeMapPtr& xMap,FormulaGramm
         xMap->putExternal( OUString::createFromAscii( *ppSymbol),
                 OUString::createFromAscii( pMap->pOriginal));
     }
+    if (_eGrammar == FormulaGrammar::GRAM_API)
+    {
+        // Add English names additionally to programmatic names, so they
+        // can be used in XCell::setFormula() non-localized API calls.
+        // Note the reverse map will still deliver programmatic names for
+        // XCell::getFormula().
+        nSymbolOffset = offsetof( AddInMap, pEnglish);
+        for (const AddInMap* pMap = g_aAddInMap; pMap < pStop; ++pMap)
+        {
+            char const * const * ppSymbol =
+                reinterpret_cast< char const * const * >(
+                        reinterpret_cast< char const * >(pMap) + 
nSymbolOffset);
+            xMap->putExternal( OUString::createFromAscii( *ppSymbol),
+                    OUString::createFromAscii( pMap->pOriginal));
+        }
+    }
 }
 
 void ScCompiler::fillFromAddInCollectionUpperName( const NonConstOpCodeMapPtr& 
xMap ) const

Reply via email to