sc/source/ui/view/gridwin.cxx | 79 +++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 31 deletions(-)
New commits: commit 49d502e8017b2f8f0de153f0f3003b5f25d683b1 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Fri Jan 19 11:43:36 2024 +0000 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri Jan 19 14:51:33 2024 +0100 use a ScopeGuard to restore the original map mode in all these cases the original map mode was always restored so there is no change for these examples. Change-Id: Iec24b2cd269b9408dac6404e054b3bb989ec7744 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162306 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 58d35876ad30..7ab9d66ea71b 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -6625,10 +6625,16 @@ void ScGridWindow::DeleteSelectionOverlay() void ScGridWindow::UpdateSelectionOverlay() { - MapMode aDrawMode = GetDrawMapMode(); - MapMode aOldMode = GetMapMode(); - if ( aOldMode != aDrawMode ) - SetMapMode( aDrawMode ); + const MapMode aDrawMode = GetDrawMapMode(); + const MapMode aOldMode = GetMapMode(); + comphelper::ScopeGuard aMapModeGuard( + [&aOldMode, &aDrawMode, this] { + if (aOldMode != aDrawMode) + SetMapMode(aOldMode); + } + ); + if (aOldMode != aDrawMode) + SetMapMode(aDrawMode); DeleteSelectionOverlay(); std::vector<tools::Rectangle> aRects; @@ -6865,10 +6871,16 @@ void ScGridWindow::UpdateDragRectOverlay() bool bInPrintTwips = comphelper::LibreOfficeKit::isCompatFlagSet( comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs); - MapMode aDrawMode = GetDrawMapMode(); - MapMode aOldMode = GetMapMode(); - if ( aOldMode != aDrawMode ) - SetMapMode( aDrawMode ); + const MapMode aDrawMode = GetDrawMapMode(); + const MapMode aOldMode = GetMapMode(); + comphelper::ScopeGuard aMapModeGuard( + [&aOldMode, &aDrawMode, this] { + if (aOldMode != aDrawMode) + SetMapMode(aOldMode); + } + ); + if (aOldMode != aDrawMode) + SetMapMode(aDrawMode); DeleteDragRectOverlay(); @@ -7021,9 +7033,6 @@ void ScGridWindow::UpdateDragRectOverlay() pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, aRectsString); } } - - if ( aOldMode != aDrawMode ) - SetMapMode( aOldMode ); } void ScGridWindow::DeleteHeaderOverlay() @@ -7033,10 +7042,16 @@ void ScGridWindow::DeleteHeaderOverlay() void ScGridWindow::UpdateHeaderOverlay() { - MapMode aDrawMode = GetDrawMapMode(); - MapMode aOldMode = GetMapMode(); - if ( aOldMode != aDrawMode ) - SetMapMode( aDrawMode ); + const MapMode aDrawMode = GetDrawMapMode(); + const MapMode aOldMode = GetMapMode(); + comphelper::ScopeGuard aMapModeGuard( + [&aOldMode, &aDrawMode, this] { + if (aOldMode != aDrawMode) + SetMapMode(aOldMode); + } + ); + if (aOldMode != aDrawMode) + SetMapMode(aDrawMode); DeleteHeaderOverlay(); @@ -7067,9 +7082,6 @@ void ScGridWindow::UpdateHeaderOverlay() mpOOHeader->append(std::move(pOverlay)); } } - - if ( aOldMode != aDrawMode ) - SetMapMode( aOldMode ); } void ScGridWindow::DeleteShrinkOverlay() @@ -7079,10 +7091,16 @@ void ScGridWindow::DeleteShrinkOverlay() void ScGridWindow::UpdateShrinkOverlay() { - MapMode aDrawMode = GetDrawMapMode(); - MapMode aOldMode = GetMapMode(); - if ( aOldMode != aDrawMode ) - SetMapMode( aDrawMode ); + const MapMode aDrawMode = GetDrawMapMode(); + const MapMode aOldMode = GetMapMode(); + comphelper::ScopeGuard aMapModeGuard( + [&aOldMode, &aDrawMode, this] { + if (aOldMode != aDrawMode) + SetMapMode(aOldMode); + } + ); + if (aOldMode != aDrawMode) + SetMapMode(aDrawMode); DeleteShrinkOverlay(); @@ -7134,9 +7152,6 @@ void ScGridWindow::UpdateShrinkOverlay() mpOOShrink->append(std::move(pOverlay)); } } - - if ( aOldMode != aDrawMode ) - SetMapMode( aOldMode ); } void ScGridWindow::DeleteSparklineGroupOverlay() @@ -7146,9 +7161,14 @@ void ScGridWindow::DeleteSparklineGroupOverlay() void ScGridWindow::UpdateSparklineGroupOverlay() { - MapMode aDrawMode = GetDrawMapMode(); - - MapMode aOldMode = GetMapMode(); + const MapMode aDrawMode = GetDrawMapMode(); + const MapMode aOldMode = GetMapMode(); + comphelper::ScopeGuard aMapModeGuard( + [&aOldMode, &aDrawMode, this] { + if (aOldMode != aDrawMode) + SetMapMode(aOldMode); + } + ); if (aOldMode != aDrawMode) SetMapMode(aDrawMode); @@ -7197,9 +7217,6 @@ void ScGridWindow::UpdateSparklineGroupOverlay() } } } - - if (aOldMode != aDrawMode) - SetMapMode(aOldMode); } // #i70788# central method to get the OverlayManager safely