summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-01-30 22:59:11 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-01-31 09:03:39 +0100
commit8cccfc82a3038bc28864ae9e94418a141b4aa545 (patch)
treea858d048048114601d8fd67147fbbc87e0b0644e /svx
parent4253acd5300c526b062fc5b5f109e93e6e9d08df (diff)
Revert "store last five MRU currencies in the currency drop-down"
This reverts commit dc6b93011cc5435f367666e43e354c6ab97bbc90. Change-Id: Ia56cb2e906303d6d59061df3e21954306bee2298 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162754 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx168
1 files changed, 42 insertions, 126 deletions
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 9a3669aac56a..192bf6c6fdd5 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -112,10 +112,6 @@
#define COMBO_WIDTH_IN_CHARS 18
-#define MAX_MRU_CURRENCIES 5
-
-#define INVALID_CURRENCY sal_uInt16(-2)
-
// namespaces
using namespace ::editeng;
using namespace ::com::sun::star;
@@ -3915,13 +3911,15 @@ namespace
, m_rSelectedFormat(rSelectedFormat)
, m_eSelectedLanguage(eSelectedLanguage)
{
+ std::vector< OUString > aList;
+ std::vector< sal_uInt16 > aCurrencyList;
const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
sal_uInt16 nLen = rCurrencyTable.size();
SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM );
m_eFormatLanguage = aFormatter.GetLanguage();
- const SvxCurrencyToolBoxControl::SvxCurrencyVect_t &rCurrencies = pControl->GetCurrencySymbols( );
+ SvxCurrencyToolBoxControl::GetCurrencySymbols( aList, true, aCurrencyList );
sal_uInt16 nPos = 0, nCount = 0;
sal_Int32 nSelectedPos = -1;
@@ -3931,11 +3929,9 @@ namespace
OUString sLongestString;
m_xCurrencyLb->freeze();
- for( const SvxCurrencyToolBoxControl::SvxCurrencyData& curr : rCurrencies )
+ for( const auto& rItem : aList )
{
- const OUString& rItem = curr.m_label;
- sal_uInt16 rCurrencyIndex = rCurrencies[ nCount ].m_currencyIdx;
-
+ sal_uInt16& rCurrencyIndex = aCurrencyList[ nCount ];
if ( rCurrencyIndex < nLen )
{
m_xCurrencyLb->append_text(rItem);
@@ -4012,8 +4008,6 @@ namespace
m_xControl->execute(nSelected + 1);
- m_xCurrencyLb->scroll_to_row(0);
-
m_xControl->EndPopupMode();
return true;
@@ -4037,26 +4031,6 @@ void SvxCurrencyToolBoxControl::initialize( const css::uno::Sequence< css::uno::
pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWN | pToolBox->GetItemBits(nId));
}
-const SvxCurrencyToolBoxControl::SvxCurrencyVect_t &SvxCurrencyToolBoxControl::GetCurrencySymbols( ) {
- inner_GetCurrencySymbols( true, m_currencies, m_mru_currencies );
- return m_currencies;
-}
-
-void SvxCurrencyToolBoxControl::addMruCurrency(sal_Int16 currencyPosition) {
- if (currencyPosition == 1)
- return;
-
- const SvxCurrencyData& curr = m_currencies[currencyPosition];
- auto currencyIter = std::find( m_mru_currencies.begin(), m_mru_currencies.end(), curr );
-
- if ( currencyIter != m_mru_currencies.end() )
- m_mru_currencies.erase( currencyIter );
-
- m_mru_currencies.insert( m_mru_currencies.begin(), curr );
- if (m_mru_currencies.size() > MAX_MRU_CURRENCIES)
- m_mru_currencies.resize( MAX_MRU_CURRENCIES );
-}
-
std::unique_ptr<WeldToolbarPopup> SvxCurrencyToolBoxControl::weldPopupWindow()
{
return std::make_unique<SvxCurrencyList_Impl>(this, m_pToolbar, m_aFormatString, m_eLanguage);
@@ -4089,12 +4063,11 @@ void SvxCurrencyToolBoxControl::execute( sal_Int16 nSelectModifier )
nFormatKey = rxNumberFormats->queryKey( m_aFormatString, aLocale, false );
if ( nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND )
nFormatKey = rxNumberFormats->addNew( m_aFormatString, aLocale );
- addMruCurrency(nSelectModifier);
- }
- catch( const uno::Exception& )
- {
- nFormatKey = m_nFormatKey;
- }
+ }
+ catch( const uno::Exception& )
+ {
+ nFormatKey = m_nFormatKey;
+ }
}
else
nFormatKey = m_nFormatKey;
@@ -4136,134 +4109,77 @@ Reference< css::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessib
}
//static
-sal_uInt16 const SvxCurrencyToolBoxControl::SvxCurrencyData::InvalidCurrency = INVALID_CURRENCY;
-
-SvxCurrencyToolBoxControl::SvxCurrencyData::SvxCurrencyData(
- sal_uInt16 currencyIdx,
- bool onlyIsoCode
-) :
- m_currencyIdx(currencyIdx),
- m_onlyIsoCode(onlyIsoCode)
-{}
-
-bool SvxCurrencyToolBoxControl::SvxCurrencyData::operator == (const SvxCurrencyData& other) const
-{
- return
- (m_currencyIdx == other.m_currencyIdx) &&
- (m_onlyIsoCode == other.m_onlyIsoCode);
-}
-
-//static
void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList, bool bFlag,
std::vector<sal_uInt16>& rCurrencyList )
{
- SvxCurrencyVect_t currencies, mru_currencies;
-
- inner_GetCurrencySymbols(bFlag, currencies, mru_currencies);
-
- rList.resize(currencies.size());
- rCurrencyList.resize(currencies.size());
-
- for (size_t j = 0; j < currencies.size(); j++) {
- rList[j] = std::move(currencies[j].m_label);
- rCurrencyList[j] = currencies[j].m_currencyIdx;
- }
-}
+ rCurrencyList.clear();
-//static
-void SvxCurrencyToolBoxControl::inner_GetCurrencySymbols(
- bool bFlag,
- SvxCurrencyVect_t &pCurrencies,
- SvxCurrencyVect_t &p_mru_currencies)
-{
const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
sal_uInt16 nCount = rCurrencyTable.size();
- // reserving space for mru currencies on top of vector after -1 element
- pCurrencies.resize( p_mru_currencies.size() + 1);
- std::fill( pCurrencies.begin() + 1, pCurrencies.end(), SvxCurrencyData() );
-
- // lambda for vector insertion: mru currencies are on top
- auto addCurrency = [&pCurrencies, &p_mru_currencies]
- (SvxCurrencyData& curr, size_t position = SIZE_MAX)
- {
- auto mruIter = std::find(p_mru_currencies.begin(), p_mru_currencies.end(), curr);
-
- if (mruIter == p_mru_currencies.end()) {
- if (position == SIZE_MAX)
- pCurrencies.push_back( std::move(curr) );
- else
- pCurrencies.insert( pCurrencies.begin() + position, std::move(curr) );
- }
- else {
- size_t index = mruIter - p_mru_currencies.begin();
- pCurrencies[index] = std::move(curr);
- }
- };
+ sal_uInt16 nStart = 1;
- SvxCurrencyData aCurr( sal_uInt16(-1) );
- aCurr.m_label = ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol() ) + " ";
- aCurr.m_label += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
+ OUString aString( ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol() ) + " " );
+ aString += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
rCurrencyTable[0].GetLanguage() ) );
- pCurrencies[0] = aCurr;
- if( bFlag ) {
- aCurr.m_currencyIdx = 0;
- addCurrency( aCurr );
- }
+ rList.push_back( aString );
+ rCurrencyList.push_back( sal_uInt16(-1) ); // nAuto
- sal_uInt16 nStart = pCurrencies.size();
+ if( bFlag )
+ {
+ rList.push_back( aString );
+ rCurrencyList.push_back( 0 );
+ ++nStart;
+ }
CollatorWrapper aCollator( ::comphelper::getProcessComponentContext() );
aCollator.loadDefaultCollator( Application::GetSettings().GetLanguageTag().getLocale(), 0 );
static constexpr OUString aTwoSpace(u" "_ustr);
- // appending "long symbol" list
for( sal_uInt16 i = 1; i < nCount; ++i )
{
- SvxCurrencyData curr( i );
- curr.m_label = ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() );
- curr.m_label += aTwoSpace;
- curr.m_label += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol() );
- curr.m_label += aTwoSpace;
- curr.m_label += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
+ OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) );
+ aStr += aTwoSpace;
+ aStr += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol() );
+ aStr += aTwoSpace;
+ aStr += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
rCurrencyTable[i].GetLanguage() ) );
- SvxCurrencyVect_t::size_type j = nStart;
- for( ; j < pCurrencies.size(); ++j )
- if ( aCollator.compareString( curr.m_label, pCurrencies[j].m_label ) < 0 )
+ std::vector<OUString>::size_type j = nStart;
+ for( ; j < rList.size(); ++j )
+ if ( aCollator.compareString( aStr, rList[j] ) < 0 )
break; // insert before first greater than
- addCurrency( curr, j );
+ rList.insert( rList.begin() + j, aStr );
+ rCurrencyList.insert( rCurrencyList.begin() + j, i );
}
// Append ISO codes to symbol list.
// XXX If this is to be changed, various other places would had to be
// adapted that assume this order!
- size_t nCont = pCurrencies.size();
+ std::vector<OUString>::size_type nCont = rList.size();
for ( sal_uInt16 i = 1; i < nCount; ++i )
{
bool bInsert = true;
- SvxCurrencyData curr( i, true );
- curr.m_label = ApplyLreOrRleEmbedding(rCurrencyTable[i].GetBankSymbol());
+ OUString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() ) );
- size_t j = nCont;
- for ( ; j < pCurrencies.size() && bInsert; ++j )
+ std::vector<OUString>::size_type j = nCont;
+ for ( ; j < rList.size() && bInsert; ++j )
{
- if( pCurrencies[j].m_label == curr.m_label )
+ if( rList[j] == aStr )
bInsert = false;
- else if ( aCollator.compareString( curr.m_label, pCurrencies[j].m_label ) < 0 )
+ else if ( aCollator.compareString( aStr, rList[j] ) < 0 )
break; // insert before first greater than
}
if ( bInsert )
- addCurrency( curr, j );
+ {
+ rList.insert( rList.begin() + j, aStr );
+ rCurrencyList.insert( rCurrencyList.begin() + j, i );
+ }
}
-
- for ( int j = p_mru_currencies.size() - 1; j > 0; j-- )
- if ( pCurrencies[j].m_currencyIdx == SvxCurrencyData::InvalidCurrency )
- pCurrencies.erase( pCurrencies.begin() + j );
}
ListBoxColorWrapper::ListBoxColorWrapper(ColorListBox* pControl)