diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-11-26 14:05:56 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-11-26 21:11:48 +0100 |
commit | c8afb4000f178badaf63c2f38fd3fbc12ec832f3 (patch) | |
tree | 65bb8d7e673e80635bd3adc27c608ad8a90336b6 | |
parent | b1e73fd49661e07e6085310f3f6ecc6ade2a3762 (diff) |
tdf#129037 add a way to select multiple entries of a ListBox together
Change-Id: I362a9e9e644e15f0dd3aeb691973a0979d17eeb0
Reviewed-on: https://gerrit.libreoffice.org/83771
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/vcl/lstbox.hxx | 1 | ||||
-rw-r--r-- | toolkit/source/awt/vclxwindows.cxx | 7 | ||||
-rw-r--r-- | vcl/source/control/listbox.cxx | 30 |
3 files changed, 37 insertions, 1 deletions
diff --git a/include/vcl/lstbox.hxx b/include/vcl/lstbox.hxx index 4ff5cf071790..9c519b6919dc 100644 --- a/include/vcl/lstbox.hxx +++ b/include/vcl/lstbox.hxx @@ -164,6 +164,7 @@ public: void SelectEntry( const OUString& rStr, bool bSelect = true ); void SelectEntryPos( sal_Int32 nPos, bool bSelect = true ); + void SelectEntriesPos( const std::vector<sal_Int32>& rPositions, bool bSelect = true ); sal_Int32 GetSelectedEntryCount() const; OUString GetSelectedEntry( sal_Int32 nSelIndex = 0 ) const; diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx index 5645bf099288..50071403d6e5 100644 --- a/toolkit/source/awt/vclxwindows.cxx +++ b/toolkit/source/awt/vclxwindows.cxx @@ -1716,19 +1716,24 @@ void VCLXListBox::selectItemsPos( const css::uno::Sequence<sal_Int16>& aPosition VclPtr< ListBox > pBox = GetAs< ListBox >(); if ( pBox ) { + std::vector<sal_Int32> aPositionVec; + aPositionVec.reserve(aPositions.getLength()); + bool bChanged = false; for ( auto n = aPositions.getLength(); n; ) { const auto nPos = aPositions.getConstArray()[--n]; if ( pBox->IsEntryPosSelected( nPos ) != bool(bSelect) ) { - pBox->SelectEntryPos( nPos, bSelect ); + aPositionVec.push_back(nPos); bChanged = true; } } if ( bChanged ) { + pBox->SelectEntriesPos(aPositionVec, bSelect); + // VCL doesn't call select handler after API call. // ImplCallItemListeners(); diff --git a/vcl/source/control/listbox.cxx b/vcl/source/control/listbox.cxx index 2de9f387011a..a93a9e52dde4 100644 --- a/vcl/source/control/listbox.cxx +++ b/vcl/source/control/listbox.cxx @@ -1071,6 +1071,36 @@ void ListBox::SelectEntryPos( sal_Int32 nPos, bool bSelect ) } } +void ListBox::SelectEntriesPos( const std::vector<sal_Int32>& rPositions, bool bSelect ) +{ + if (!mpImplLB) + return; + + bool bCallListeners = false; + + const sal_Int32 nCurrentPos = mpImplLB->GetCurrentPos(); + const auto nEntryCount = mpImplLB->GetEntryList()->GetEntryCount(); + const auto nMRUCount = mpImplLB->GetEntryList()->GetMRUCount(); + + for (auto nPos : rPositions) + { + if (0 <= nPos && nPos < nEntryCount) + { + mpImplLB->SelectEntry(nPos + nMRUCount, bSelect); + if (nCurrentPos != nPos && bSelect) + bCallListeners = true; + } + } + + //Only when bSelect == true, send both Selection & Focus events + if (bCallListeners) + { + CallEventListeners(VclEventId::ListboxSelect); + if (HasFocus()) + CallEventListeners(VclEventId::ListboxFocus); + } +} + void ListBox::SetEntryData( sal_Int32 nPos, void* pNewData ) { mpImplLB->SetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount(), pNewData ); |