Resolves: tdf#152948 Do not use GetExcelName() to obtain English function name

As the function name says, it's the Excel compatibility name and
not the Calc UI visible name and thus does not have the _ADD or
_EXCEL2003 suffixes. Theoretically the names may even be
completely different.

Change-Id: I5f52dee77009123ebc3762defe08c937a3a59a18
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145246
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
(cherry picked from commit b5cca905c6f3e090dae6e649381664925474a04a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145226
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index 3100a09..ef2ae2f 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -738,10 +738,19 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&

    // Even if GetUseEnglishFunctionName() would return true, do not set the
    // locale to en-US to get English function names as that also would mix in
    // English descriptions and parameter names. English function names are now
    // handled below.
    // English descriptions and parameter names. Also, setting a locale will
    // reinitialize the Add-In completely, so switching back and forth isn't a
    // good idea either.
    xAddIn->setLocale( Application::GetSettings().GetUILanguageTag().getLocale());

    // Instead, in a second run with 'en-US' obtain English names.
    struct FuncNameData
    {
        OUString            aFuncU;
        ScUnoAddInFuncData* pData;
    };
    std::vector<FuncNameData> aFuncNameData;

    OUString aServiceName( xName->getServiceName() );
    ScUnoAddInHelpIdGenerator aHelpIdGenerator( aServiceName );

@@ -784,7 +793,6 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
    if ( !pEnglishHashMap )
        pEnglishHashMap.reset( new ScAddInHashMap );

    const LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US);
    const uno::Reference<reflection::XIdlMethod>* pArray = aMethods.getConstArray();
    for (tools::Long nFuncPos=0; nFuncPos<nNewCount; nFuncPos++)
    {
@@ -945,20 +953,42 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
                                pData->GetUpperLocal(),
                                pData );

                    OUString aEnglishName;
                    if (!pData->GetExcelName( aEnglishLanguageTag, aEnglishName, false /*bFallbackToAny*/))
                        SAL_WARN("sc.core", "no English name for " << aLocalName << " " << aFuncName);
                    else
                    {
                        pEnglishHashMap->emplace(
                                ScCompiler::GetCharClassEnglish()->uppercase(aEnglishName),
                                pData );
                    }
                    pData->SetEnglishName(aEnglishName);    // takes care of handling empty
                    aFuncNameData.push_back({aFuncU, pData});
                }
            }
        }
    }

    const LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US);
    xAddIn->setLocale( aEnglishLanguageTag.getLocale());
    for (const auto& rFunc : aFuncNameData)
    {
        OUString aEnglishName;
        try
        {
            aEnglishName = xAddIn->getDisplayFunctionName( rFunc.aFuncU );
        }
        catch(uno::Exception&)
        {
        }
        if (aEnglishName.isEmpty()
                && rFunc.pData->GetExcelName( aEnglishLanguageTag, aEnglishName, false /*bFallbackToAny*/))
        {
            // Check our known suffixes and append if not present. Note this
            // depends on localization (that should not add such suffix, but..)
            // and is really only a last resort.
            if (rFunc.pData->GetLocalName().endsWith("_ADD") && !aEnglishName.endsWith("_ADD"))
                aEnglishName += "_ADD";
            else if (rFunc.pData->GetLocalName().endsWith("_EXCEL2003") && !aEnglishName.endsWith("_EXCEL2003"))
                aEnglishName += "_EXCEL2003";
            SAL_WARN("sc.core", "obtaining English name for " << rFunc.pData->GetLocalName() << " "
                    << rFunc.pData->GetOriginalName() << " as ExcelName '" << aEnglishName << "'");
        }
        SAL_WARN_IF(aEnglishName.isEmpty(), "sc.core", "no English name for "
                << rFunc.pData->GetLocalName() << " " << rFunc.pData->GetOriginalName());
        rFunc.pData->SetEnglishName(aEnglishName);  // takes care of handling empty
        pEnglishHashMap->emplace( rFunc.pData->GetUpperEnglish(), rFunc.pData);
    }
}

static void lcl_UpdateFunctionList( const ScFunctionList& rFunctionList, const ScUnoAddInFuncData& rFuncData,
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 7be5a36..1180c55 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -167,7 +167,6 @@ void ScCompiler::fillFromAddInCollectionUpperName( const NonConstOpCodeMapPtr& x

void ScCompiler::fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr& xMap ) const
{
    const LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US);
    ScUnoAddInCollection* pColl = ScGlobal::GetAddInCollection();
    tools::Long nCount = pColl->GetFuncCount();
    for (tools::Long i=0; i < nCount; ++i)
@@ -175,8 +174,8 @@ void ScCompiler::fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr&
        const ScUnoAddInFuncData* pFuncData = pColl->GetFuncData(i);
        if (pFuncData)
        {
            OUString aName;
            if (pFuncData->GetExcelName( aEnglishLanguageTag, aName))
            const OUString aName( pFuncData->GetUpperEnglish());
            if (!aName.isEmpty())
                xMap->putExternalSoftly( aName, pFuncData->GetOriginalName());
            else
                xMap->putExternalSoftly( pFuncData->GetUpperName(),
@@ -5537,6 +5536,10 @@ void ScCompiler::fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry
        {
            if ( _bIsEnglish )
            {
                // This is used with OOXML import, so GetExcelName() is really
                // wanted here until we'll have a parameter to differentiate
                // from the general css::sheet::XFormulaOpCodeMapper case and
                // use pFuncData->GetUpperEnglish().
                OUString aName;
                if (pFuncData->GetExcelName( aEnglishLanguageTag, aName))
                    aEntry.Name = aName;