include/svx/tbcontrl.hxx         |   65 ---------------
 svx/source/tbxctrls/tbcontrl.cxx |  168 +++++++++------------------------------
 2 files changed, 42 insertions(+), 191 deletions(-)

New commits:
commit 8cccfc82a3038bc28864ae9e94418a141b4aa545
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jan 30 22:59:11 2024 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Jan 31 09:03:39 2024 +0100

    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 <qui...@gmail.com>

diff --git a/include/svx/tbcontrl.hxx b/include/svx/tbcontrl.hxx
index 11d41ee4ddde..9fffced835cb 100644
--- a/include/svx/tbcontrl.hxx
+++ b/include/svx/tbcontrl.hxx
@@ -249,73 +249,11 @@ public:
 /** Popup controller for currency combo widget **/
 class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) SvxCurrencyToolBoxControl final : 
public svt::PopupWindowController
 {
-public:
-    /**
-    * Struct containing currency data<p>
-    * an instance corresponds to a line in the combo
-    **/
-    struct SvxCurrencyData {
-        /** position of the currency in 
SvxCurrencyToolBoxControl::CurrencySymbols vector **/
-        sal_uInt16 m_currencyIdx;
-
-        /**
-        * False if the instance corresponds to a line of the combo that shows 
only the ISO code<p>
-        * True otherwise
-        **/
-        bool m_onlyIsoCode;
-        OUString m_label;
-
-        /** Constant for invalid currency **/
-        static const sal_uInt16 InvalidCurrency;
-
-        /**
-        * Constructor
-        *
-        * @param currencyIdx Position of the currency in 
SvxCurrencyToolBoxControl::CurrencySymbols vector
-        * @param onlyIsoCode False if the instance corresponds to a line of 
the combo that shows
-        * only the ISO code<p> True otherwise
-        **/
-        SvxCurrencyData(
-            sal_uInt16 currencyIdx = InvalidCurrency,
-            bool onlyIsoCode = false
-        );
-
-        /** Needed by std::find **/
-        bool operator == (const SvxCurrencyData& other) const;
-    };
-
-    /** vector of combo box currencies **/
-    typedef std::vector<SvxCurrencyData> SvxCurrencyVect_t;
-
 private:
     OUString     m_aFormatString;
     LanguageType m_eLanguage;
     sal_uInt32   m_nFormatKey;
 
-    /** Currencies in the combo **/
-    SvxCurrencyVect_t  m_currencies;
-
-
-    /** Most recently used currencies **/
-    SvxCurrencyVect_t  m_mru_currencies;
-
-    /** Adds a currency to the most recently used list **/
-    void addMruCurrency(sal_Int16 currencyPosition);
-
-    /**
-    * Inner static method that polialtes the currency list and the most 
recently used
-    * currency list.<p>
-    * The method is static for backward compatibility: it is used by the two
-    * homonymous public methods, one of which is static while the other is 
instance
-    *
-    * @param bFlag used by SvxNumberFormatShell::GetCurrencySymbols
-    * @param p_mru_currencies output: most recently used currencies
-    * @param pCurrencies output: most recently used currencies
-    * @see SvxNumberFormatShell::GetCurrencySymbols
-    **/
-    static void inner_GetCurrencySymbols( bool bFlag, SvxCurrencyVect_t 
&p_mru_currencies,
-                                    SvxCurrencyVect_t &pCurrencies);
-
 public:
     /**
     * Static method used by SvxNumberFormatShell::GetCurrencySymbols<p>
@@ -328,9 +266,6 @@ public:
     static void GetCurrencySymbols( std::vector<OUString>& rList, bool bFlag,
                                     std::vector<sal_uInt16>& rCurrencyList );
 
-    /** Instance method used by SvxCurrencyList_Impl constructor **/
-    const SvxCurrencyVect_t& GetCurrencySymbols();
-
     explicit SvxCurrencyToolBoxControl( const 
css::uno::Reference<css::uno::XComponentContext>& rContext );
     virtual ~SvxCurrencyToolBoxControl() override;
 
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;
@@ -4135,135 +4108,78 @@ Reference< css::accessibility::XAccessible > 
SvxFontNameBox_Impl::CreateAccessib
     return InterimItemWindow::CreateAccessible();
 }
 
-//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)

Reply via email to