From 2cac2ee38445c19c9281f54c2b961bbc9149cc00 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sat, 27 Jan 2024 00:33:56 +0900 Subject: sc: put used currencies on top of the currency pop-up list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list of currencies is fairly long and there is no easy way to search the list, so to make it easier to concurrently fint the desired currency, put the currencies that are used in the document on top of the list. This adds a DocumentModelAccessor class, which is used to access parts of the document model from other modules throught the SfxObjectShell. Change-Id: I81a180b674ae69b373b0422f363678e8bab37194 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162638 Tested-by: Jenkins CollaboraOffice Reviewed-by: Miklos Vajna (cherry picked from commit 79da840fac78f11c156801c43d8b79d6d4f32869) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162755 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- svx/source/items/numfmtsh.cxx | 5 +++- svx/source/tbxctrls/tbcontrl.cxx | 59 +++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 14 deletions(-) (limited to 'svx') diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx index 8605817491ba..4f0825a88bca 100644 --- a/svx/source/items/numfmtsh.cxx +++ b/svx/source/items/numfmtsh.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -1397,7 +1398,9 @@ void SvxNumberFormatShell::GetCurrencySymbols(std::vector& rList, sal_ bool bFlag = (pTmpCurrencyEntry == nullptr); - SvxCurrencyToolBoxControl::GetCurrencySymbols(rList, bFlag, aCurCurrencyList); + std::vector aDocumentCurrencyIDs; + SvxCurrencyToolBoxControl::GetCurrencySymbols(rList, bFlag, aCurCurrencyList, + aDocumentCurrencyIDs); if (pPos == nullptr) return; diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 192bf6c6fdd5..d3f89aad706c 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -92,16 +92,19 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -3919,7 +3922,13 @@ namespace SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM ); m_eFormatLanguage = aFormatter.GetLanguage(); - SvxCurrencyToolBoxControl::GetCurrencySymbols( aList, true, aCurrencyList ); + std::vector aCurrencyIDs; + + SfxObjectShell* pDocShell = SfxObjectShell::Current(); + if (auto pModelAccessor = pDocShell->GetDocumentModelAccessor()) + aCurrencyIDs = pModelAccessor->getDocumentCurrencies(); + + SvxCurrencyToolBoxControl::GetCurrencySymbols(aList, true, aCurrencyList, aCurrencyIDs); sal_uInt16 nPos = 0, nCount = 0; sal_Int32 nSelectedPos = -1; @@ -4109,8 +4118,9 @@ Reference< css::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessib } //static -void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector& rList, bool bFlag, - std::vector& rCurrencyList ) +void SvxCurrencyToolBoxControl::GetCurrencySymbols(std::vector& rList, bool bFlag, + std::vector& rCurrencyList, + std::vector const& rDocumentCurrencyIDs) { rCurrencyList.clear(); @@ -4120,8 +4130,7 @@ void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector& rList sal_uInt16 nStart = 1; OUString aString( ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol() ) + " " ); - aString += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString( - rCurrencyTable[0].GetLanguage() ) ); + aString += ApplyLreOrRleEmbedding(SvtLanguageTable::GetLanguageString(rCurrencyTable[0].GetLanguage())); rList.push_back( aString ); rCurrencyList.push_back( sal_uInt16(-1) ); // nAuto @@ -4140,17 +4149,40 @@ void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector& rList for( sal_uInt16 i = 1; i < nCount; ++i ) { - OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) ); + auto& rCurrencyEntry = rCurrencyTable[i]; + + OUString aStr( ApplyLreOrRleEmbedding(rCurrencyEntry.GetBankSymbol())); aStr += aTwoSpace; - aStr += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol() ); + aStr += ApplyLreOrRleEmbedding(rCurrencyEntry.GetSymbol()); aStr += aTwoSpace; - aStr += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString( - rCurrencyTable[i].GetLanguage() ) ); + aStr += ApplyLreOrRleEmbedding(SvtLanguageTable::GetLanguageString(rCurrencyEntry.GetLanguage())); std::vector::size_type j = nStart; - for( ; j < rList.size(); ++j ) - if ( aCollator.compareString( aStr, rList[j] ) < 0 ) - break; // insert before first greater than + + // Search if the currency is present in the document + auto iter = std::find_if(rDocumentCurrencyIDs.begin(), rDocumentCurrencyIDs.end(), [rCurrencyEntry](sfx::CurrencyID const& rCurrency) + { + const NfCurrencyEntry* pEntry = SvNumberFormatter::GetCurrencyEntry(o3tl::temporary(bool()), rCurrency.aSymbol, rCurrency.aExtension, rCurrency.eLanguage); + + if (pEntry) + return rCurrencyEntry.GetLanguage() == pEntry->GetLanguage() && rCurrencyEntry.GetSymbol() == pEntry->GetSymbol(); + + return false; + }); + + // If currency is in document, insert it on top + if (iter != rDocumentCurrencyIDs.end()) + { + nStart++; + } + else + { + for( ; j < rList.size(); ++j ) + { + if ( aCollator.compareString( aStr, rList[j] ) < 0 ) + break; // insert before first greater than + } + } rList.insert( rList.begin() + j, aStr ); rCurrencyList.insert( rCurrencyList.begin() + j, i ); @@ -4164,7 +4196,8 @@ void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector& rList for ( sal_uInt16 i = 1; i < nCount; ++i ) { bool bInsert = true; - OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) ); + auto& rCurrencyEntry = rCurrencyTable[i]; + OUString aStr( ApplyLreOrRleEmbedding(rCurrencyEntry.GetBankSymbol())); std::vector::size_type j = nCont; for ( ; j < rList.size() && bInsert; ++j ) -- cgit