diff options
author | Eike Rathke <erack@redhat.com> | 2023-01-09 23:18:35 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2023-01-10 00:02:40 +0000 |
commit | b5cca905c6f3e090dae6e649381664925474a04a (patch) | |
tree | 5ca633c7b3f2c41a6895ed9a5f576a21aa22debc /sc | |
parent | d24fc94281458b57368ff4fef1fe1182dadbea72 (diff) |
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
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/addincol.cxx | 56 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 9 |
2 files changed, 49 insertions, 16 deletions
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx index bf7d8652de1b..99f8061df3d2 100644 --- a/sc/source/core/tool/addincol.cxx +++ b/sc/source/core/tool/addincol.cxx @@ -739,10 +739,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 ); @@ -785,7 +794,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++) { @@ -946,20 +954,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 f3861e4ddbbe..d37823695fd5 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(), @@ -5529,6 +5528,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; |