From 633ad5fd673fd80db8d091c5f90927af30471b4d Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 9 Jul 2024 15:59:16 +0200 Subject: icon choice ctrl: Simplify list pos handling Instead of storing the current list position in the `SvxIconChoiceCtrlEntry` and having to take care of updating that when entries are added to or removed from the `SvxIconChoiceCtrl_Impl` in order to keep it in sync with the elements in the vector, just calculate and return the vector index in `SvxIconChoiceCtrl_Impl::GetEntryListPos` on demand. Change-Id: Iec4e700c1ccc1261fde778b1b38af4dbac5a14c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170247 Reviewed-by: Michael Weghorn Tested-by: Jenkins --- vcl/source/control/imivctl.hxx | 6 ++---- vcl/source/control/imivctl1.cxx | 29 ++++++----------------------- vcl/source/control/ivctrl.cxx | 1 - 3 files changed, 8 insertions(+), 28 deletions(-) (limited to 'vcl') diff --git a/vcl/source/control/imivctl.hxx b/vcl/source/control/imivctl.hxx index 1df0c7309e02..6bce8738e17c 100644 --- a/vcl/source/control/imivctl.hxx +++ b/vcl/source/control/imivctl.hxx @@ -52,9 +52,8 @@ class IcnGridMap_Impl; enum class IconChoiceFlags { NONE = 0x0000, AddMode = 0x0001, - EntryListPosValid = 0x0002, - ClearingSelection = 0x0004, - Arranging = 0x0008, + ClearingSelection = 0x0002, + Arranging = 0x0004, }; namespace o3tl { template<> struct typed_flags : is_typed_flags {}; @@ -181,7 +180,6 @@ class SvxIconChoiceCtrl_Impl bool bSelect ); void RepaintSelectedEntries(); - void SetListPositions(); void SetDefaultTextSize(); bool IsAutoArrange() const { diff --git a/vcl/source/control/imivctl1.cxx b/vcl/source/control/imivctl1.cxx index 6a58742996fb..d30b42b1d80e 100644 --- a/vcl/source/control/imivctl1.cxx +++ b/vcl/source/control/imivctl1.cxx @@ -171,11 +171,6 @@ void SvxIconChoiceCtrl_Impl::InsertEntry( std::unique_ptr= maEntries.size() - 1 ) - pEntry->nPos = maEntries.size() - 1; - else - nFlags &= ~IconChoiceFlags::EntryListPosValid; - maZOrderList.push_back( pEntry ); pImpCursor->Clear(); @@ -195,8 +190,6 @@ void SvxIconChoiceCtrl_Impl::RemoveEntry(size_t nPos) { pImpCursor->Clear(); maEntries.erase(maEntries.begin() + nPos); - // Recalculate list positions - nFlags &= ~IconChoiceFlags::EntryListPosValid; RecalcAllBoundingRectsSmart(); } @@ -207,19 +200,6 @@ tools::Rectangle SvxIconChoiceCtrl_Impl::GetOutputRect() const return tools::Rectangle( aOrigin, aOutputSize ); } -void SvxIconChoiceCtrl_Impl::SetListPositions() -{ - if( nFlags & IconChoiceFlags::EntryListPosValid ) - return; - - size_t nCount = maEntries.size(); - for( size_t nCur = 0; nCur < nCount; nCur++ ) - { - maEntries[ nCur ]->nPos = nCur; - } - nFlags |= IconChoiceFlags::EntryListPosValid; -} - void SvxIconChoiceCtrl_Impl::SelectEntry( SvxIconChoiceCtrlEntry* pEntry, bool bSelect, bool bAdd ) { @@ -1882,9 +1862,12 @@ SvxIconChoiceCtrlEntry* SvxIconChoiceCtrl_Impl::GetFirstSelectedEntry() const sal_Int32 SvxIconChoiceCtrl_Impl::GetEntryListPos( SvxIconChoiceCtrlEntry const * pEntry ) const { - if( !(nFlags & IconChoiceFlags::EntryListPosValid )) - const_cast(this)->SetListPositions(); - return pEntry->nPos; + auto it = std::find_if(maEntries.begin(), maEntries.end(), + [pEntry](auto& rIt) { return rIt.get() == pEntry; }); + if (it != maEntries.end()) + return std::distance(maEntries.begin(), it); + + return -1; } void SvxIconChoiceCtrl_Impl::InitSettings() diff --git a/vcl/source/control/ivctrl.cxx b/vcl/source/control/ivctrl.cxx index 8e1c03a45e25..ca8785651624 100644 --- a/vcl/source/control/ivctrl.cxx +++ b/vcl/source/control/ivctrl.cxx @@ -58,7 +58,6 @@ SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( OUString _aText, Image _aImage ) : aImage(std::move(_aImage)) , aText(std::move(_aText)) - , nPos(0) , eTextMode(SvxIconChoiceCtrlTextMode::Short) , nX(0) , nY(0) -- cgit