summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-07-09 15:59:16 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2024-07-10 09:26:26 +0200
commit633ad5fd673fd80db8d091c5f90927af30471b4d (patch)
tree53e8d1208eed00bd7c673ca192ae1139788da7fe /vcl
parent46d55cf7960ecea3bc8af29f7a05159e5979c3ac (diff)
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 <m.weghorn@posteo.de> Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/imivctl.hxx6
-rw-r--r--vcl/source/control/imivctl1.cxx29
-rw-r--r--vcl/source/control/ivctrl.cxx1
3 files changed, 8 insertions, 28 deletions
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<IconChoiceFlags> : is_typed_flags<IconChoiceFlags, 0x007f> {};
@@ -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<SvxIconChoiceCtrlEntry
maEntries.push_back( std::move(pEntry1) );
}
- if( (nFlags & IconChoiceFlags::EntryListPosValid) && nPos >= 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<SvxIconChoiceCtrl_Impl*>(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)