sd/source/console/PresenterToolBar.cxx | 43 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 24 deletions(-)
New commits: commit fc78db91c21468cb5cedb70707e7bfc618edc38f Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri May 16 01:21:52 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri May 16 20:16:41 2025 +0200 tdf#160094 sd presenter: Use unordered_map for mapping ... the size explicitly, instead of having a vector and the assumption that the elemnt at index i in `aPartSizes` provides the size for the element at the same index in `maElementContainer`. This also makes it unnecessary to use the "reversed index" for the RTL case and will allow further deduplication in an upcoming commit. Change-Id: I6d00ea116fc7ee144f1ec90ed54da7004800eb4c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185382 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/sd/source/console/PresenterToolBar.cxx b/sd/source/console/PresenterToolBar.cxx index 92b838d83d9d..4444bf1a7fc2 100644 --- a/sd/source/console/PresenterToolBar.cxx +++ b/sd/source/console/PresenterToolBar.cxx @@ -663,10 +663,9 @@ void PresenterToolBar::Layout ( mbIsLayoutPending = false; const awt::Rectangle aWindowBox (mxWindow->getPosSize()); - ::std::vector<geometry::RealSize2D> aPartSizes (maElementContainer.size()); + std::unordered_map<SharedElementContainerPart, geometry::RealSize2D> aPartSizes; geometry::RealSize2D aTotalSize (0,0); bool bIsHorizontal (true); - sal_Int32 nIndex (0); double nTotalHorizontalGap (0); sal_Int32 nGapCount (0); for (const auto& rxPart : maElementContainer) @@ -674,7 +673,7 @@ void PresenterToolBar::Layout ( geometry::RealSize2D aSize (CalculatePartSize(rxCanvas, rxPart, bIsHorizontal)); // Remember the size of each part for later. - aPartSizes[nIndex] = aSize; + aPartSizes[rxPart] = aSize; // Add gaps between elements. if (rxPart->size()>1 && bIsHorizontal) @@ -689,7 +688,6 @@ void PresenterToolBar::Layout ( aTotalSize.Width += aSize.Width; // Height is the maximum height of all parts. aTotalSize.Height = ::std::max(aTotalSize.Height, aSize.Height); - ++nIndex; } // Add gaps between parts. if (maElementContainer.size() > 1) @@ -730,38 +728,35 @@ void PresenterToolBar::Layout ( /* push front or back ? ... */ /// check whether RTL interface or not if(!AllSettings::GetLayoutRTL()){ - nIndex = 0; for (const auto& rxPart : maElementContainer) { geometry::RealRectangle2D aBoundingBox( nX, nY, - nX+aPartSizes[nIndex].Width, nY+aTotalSize.Height); + nX + aPartSizes[rxPart].Width, nY + aTotalSize.Height); // Add space for gaps between elements. if (rxPart->size() > 1 && bIsHorizontal) aBoundingBox.X2 += (rxPart->size() - 1) * nGapWidth; - LayoutPart(rxCanvas, rxPart, aBoundingBox, aPartSizes[nIndex], bIsHorizontal); + LayoutPart(rxCanvas, rxPart, aBoundingBox, aPartSizes[rxPart], bIsHorizontal); bIsHorizontal = !bIsHorizontal; nX += aBoundingBox.X2 - aBoundingBox.X1 + nGapWidth; - ++nIndex; } } else { ElementContainer::reverse_iterator iPart; - nIndex = aPartSizes.size() - 1; - for (iPart = maElementContainer.rbegin(); iPart != maElementContainer.rend(); ++iPart, --nIndex) + for (iPart = maElementContainer.rbegin(); iPart != maElementContainer.rend(); ++iPart) { geometry::RealRectangle2D aBoundingBox( nX, nY, - nX+aPartSizes[nIndex].Width, nY+aTotalSize.Height); + nX + aPartSizes[*iPart].Width, nY + aTotalSize.Height); // Add space for gaps between elements. if ((*iPart)->size() > 1) if (bIsHorizontal) aBoundingBox.X2 += ((*iPart)->size()-1) * nGapWidth; - LayoutPart(rxCanvas, *iPart, aBoundingBox, aPartSizes[nIndex], bIsHorizontal); + LayoutPart(rxCanvas, *iPart, aBoundingBox, aPartSizes[*iPart], bIsHorizontal); bIsHorizontal = !bIsHorizontal; nX += aBoundingBox.X2 - aBoundingBox.X1 + nGapWidth; } commit 140fb3b98b4f8e1331634213a0825fbe92ccda15 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri May 16 09:05:05 2025 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Fri May 16 20:16:33 2025 +0200 tdf#160094 sd presenter: Don't use invalid iterator for RTL Use reverse iterators instead of manually iterating backwards and using an invalid iterator of `std::vector::begin() - 1` that triggered /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/debug/safe_iterator.h:1103: In function: _Self gnu_debug::operator-(const _Self &, difference_type) Error: attempt to retreat a dereferenceable (start-of-sequence) iterator 1 steps, which falls outside its valid range. Objects involved in the operation: iterator @ 0x7ffe4f131df8 { type = gnu_cxx::normal_iterator<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>, std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > >*, std::vector<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>, std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > >, std::allocator<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>, std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > > > > > (mutable iterator); state = dereferenceable (start-of-sequence); references sequence with type 'std::debug::vector<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>, std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > >, std::allocator<std::shared_ptr<std::debug::vector<rtl::Reference<sdext::presenter::PresenterToolBar::Element>, std::allocator<rtl::Reference<sdext::presenter::PresenterToolBar::Element> > > > > >' @ 0x55ee4e1a92a8 } when starting Impress with SAL_RTL_ENABLED=1 and then starting a slideshow with Presenter Console enabled. for an `--enable-dbgutil` Linux build. Replace the hard-coded `nIndex=2` with `nIndex = aPartSizes.size() - 1` (there are 3 vector elements) and rename `iBegin` to `iFirst` (as it no longer is the begin iterator, but points to the first element in the vector, i.e. the element at index 0, not the first one when reverse-iterating). Change-Id: Ibfc3b776391dae8b986964ef8f8d3c256f12d553 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185381 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/sd/source/console/PresenterToolBar.cxx b/sd/source/console/PresenterToolBar.cxx index 77030d2254dc..92b838d83d9d 100644 --- a/sd/source/console/PresenterToolBar.cxx +++ b/sd/source/console/PresenterToolBar.cxx @@ -748,9 +748,9 @@ void PresenterToolBar::Layout ( } } else { - ElementContainer::iterator iPart; - ElementContainer::iterator iBegin (maElementContainer.begin()); - for (iPart=maElementContainer.end()-1, nIndex=2; iPart!=iBegin-1; --iPart, --nIndex) + ElementContainer::reverse_iterator iPart; + nIndex = aPartSizes.size() - 1; + for (iPart = maElementContainer.rbegin(); iPart != maElementContainer.rend(); ++iPart, --nIndex) { geometry::RealRectangle2D aBoundingBox( nX, nY, @@ -862,10 +862,10 @@ void PresenterToolBar::LayoutPart ( } } else { - ElementContainerPart::const_iterator iElement; - ElementContainerPart::const_iterator iBegin (rpPart->begin()); + ElementContainerPart::const_reverse_iterator iElement; + ElementContainerPart::const_reverse_iterator iFirst = rpPart->rend() - 1; - for (iElement=rpPart->end()-1; iElement!=iBegin-1; --iElement) + for (iElement= rpPart->rbegin(); iElement!= rpPart->rend(); ++iElement) { if (iElement->get() == nullptr) continue; @@ -886,11 +886,11 @@ void PresenterToolBar::LayoutPart ( else { // reverse presentation time with current time - if (iElement==iBegin){ - iElement=iBegin+2; + if (iElement == iFirst){ + iElement = iFirst - 2; } - else if (iElement==iBegin+2){ - iElement=iBegin; + else if (iElement == iFirst - 2){ + iElement = iFirst; } const awt::Size aNewElementSize ((*iElement)->GetBoundingSize(rxCanvas)); if ((*iElement)->IsFilling()) @@ -904,10 +904,10 @@ void PresenterToolBar::LayoutPart ( nY += aNewElementSize.Height + nGap; // return the index as it was before the reversing - if (iElement==iBegin) - iElement=iBegin+2; - else if (iElement==iBegin+2) - iElement=iBegin; + if (iElement == iFirst) + iElement = iFirst - 2; + else if (iElement == iFirst - 2) + iElement = iFirst; } } }