sw/source/core/doc/notxtfrm.cxx                 |    3 --
 sw/source/core/layout/layact.cxx                |    3 --
 sw/source/core/layout/paintfrm.cxx              |   31 ++++++------------------
 sw/source/core/text/EnhancedPDFExportHelper.cxx |    3 --
 sw/source/core/text/frmpaint.cxx                |    3 --
 sw/source/core/text/inftxt.cxx                  |   25 ++++++-------------
 sw/source/core/text/porrst.cxx                  |    3 --
 sw/source/core/text/portxt.cxx                  |    3 --
 sw/source/core/txtnode/fntcache.cxx             |   11 ++------
 sw/source/core/view/pagepreviewlayout.cxx       |    6 +---
 sw/source/core/view/viewpg.cxx                  |    6 ----
 sw/source/core/view/viewsh.cxx                  |    4 ---
 sw/source/core/view/vprint.cxx                  |    3 --
 sw/source/filter/ww8/ww8par3.cxx                |    3 --
 sw/source/ui/chrdlg/drpcps.cxx                  |    3 --
 sw/source/ui/frmdlg/column.cxx                  |    3 --
 sw/source/ui/table/autoformatpreview.cxx        |    7 ++---
 sw/source/uibase/docvw/AnnotationWin2.cxx       |    9 ++----
 sw/source/uibase/docvw/SidebarTxtControl.cxx    |    4 ---
 sw/source/uibase/frmdlg/colex.cxx               |    3 --
 sw/source/uibase/sidebar/QuickFindPanel.cxx     |    3 --
 sw/source/uibase/uiview/srcview.cxx             |    4 ---
 sw/source/uibase/utlui/unotools.cxx             |    3 --
 sw/source/writerfilter/dmapper/SdtHelper.cxx    |    4 ---
 24 files changed, 45 insertions(+), 105 deletions(-)

New commits:
commit 20d4eda7ab8ddb09cda0b47d86694bf239273059
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Aug 16 23:36:14 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Aug 17 10:00:14 2025 +0200

    Use OutputDevice::ScopedPush in sw
    
    Change-Id: Id5e8eb02c9fbcb0e7afaf72cb160a32190abbdb7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189802
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx
index 9d0175f14608..1d7a9623a3f1 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -206,12 +206,11 @@ static void lcl_ClearArea( const SwFrame &rFrame,
     }
     else
     {
-        rOut.Push( vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+        auto popIt = rOut.ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
         rOut.SetFillColor( 
rFrame.getRootFrame()->GetCurrShell()->Imp()->GetRetoucheColor());
         rOut.SetLineColor();
         for( const auto &rRegion : aRegion )
             rOut.DrawRect( rRegion.SVRect() );
-        rOut.Pop();
     }
 }
 
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 8fb5d154ac12..de8e0055e592 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -2368,11 +2368,10 @@ void SwLayIdle::ShowIdle( Color eColor )
         tools::Rectangle aRect( 0, 0, 5, 5 );
         aRect = pWin->PixelToLogic( aRect );
         // Depending on if idle layout is in progress or not, draw a "red 
square" or a "green square".
-        pWin->GetOutDev()->Push( 
vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+        auto popIt = pWin->GetOutDev()->ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
         pWin->GetOutDev()->SetFillColor( eColor );
         pWin->GetOutDev()->SetLineColor();
         pWin->GetOutDev()->DrawRect( aRect );
-        pWin->GetOutDev()->Pop();
     }
 }
 #define SHOW_IDLE( Color ) ShowIdle( Color )
diff --git a/sw/source/core/layout/paintfrm.cxx 
b/sw/source/core/layout/paintfrm.cxx
index f1d8a7984a86..da13badc60e8 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -870,7 +870,7 @@ void SwLineRects::PaintLines( OutputDevice *pOut, 
SwPaintProperties const &prope
     // #i16816# tagged pdf support
     SwTaggedPDFHelper aTaggedPDFHelper( nullptr, nullptr, nullptr, *pOut );
 
-    pOut->Push( vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+    auto popIt = pOut->ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
     pOut->SetFillColor();
     pOut->SetLineColor();
     ConnectEdges( pOut, properties );
@@ -976,8 +976,6 @@ void SwLineRects::PaintLines( OutputDevice *pOut, 
SwPaintProperties const &prope
         }
     }
     m_nLastCount = nMinCount;
-    pOut->Pop();
-
 }
 
 void SwSubsRects::PaintSubsidiary( OutputDevice *pOut,
@@ -1044,7 +1042,7 @@ void SwSubsRects::PaintSubsidiary( OutputDevice *pOut,
     if (m_aLineRects.empty())
         return;
 
-    pOut->Push( vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+    auto popIt = pOut->ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
     pOut->SetLineColor();
 
     // Reset draw mode in high contrast mode in order to get fill color
@@ -1083,8 +1081,6 @@ void SwSubsRects::PaintSubsidiary( OutputDevice *pOut,
     }
 
     pOut->SetDrawMode( nOldDrawMode );
-
-    pOut->Pop();
 }
 
 // Various functions that are use in this file.
@@ -1899,7 +1895,7 @@ void DrawGraphic(
             // area, from which the background brush is determined.
             aGrf.Pos() = rOrg.Pos();
             // setup clipping at output device
-            rOutDev.Push( vcl::PushFlags::CLIPREGION );
+            auto popIt = rOutDev.ScopedPush(vcl::PushFlags::CLIPREGION);
             rOutDev.IntersectClipRegion( rOut.SVRect() );
             // use new method <GraphicObject::DrawTiled(::)>
             {
@@ -1936,8 +1932,6 @@ void DrawGraphic(
                                         Size( aPaintOffset.X(), 
aPaintOffset.Y() ),
                                         std::max( 128, static_cast<int>( 
sqrt(sqrt( Abitmap)) + .5 ) ) );
             }
-            // reset clipping at output device
-            rOutDev.Pop();
             // set <bDraw> and <bRetouche> to false, indicating that background
             // graphic and background are already drawn.
             bDraw = bRetouche = false;
@@ -1956,7 +1950,7 @@ void DrawGraphic(
     bool bGrfBackgrdAlreadyDrawn = false;
     if ( bRetouche )
     {
-        rOutDev.Push( vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+        auto popIt = rOutDev.ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
         rOutDev.SetLineColor();
 
         // check, if an existing background graphic (not filling the complete
@@ -2107,7 +2101,6 @@ void DrawGraphic(
                 }
             }
         }
-        rOutDev.Pop();
     }
 
     if( bDraw && aGrf.Overlaps( rOut ) )
@@ -4363,7 +4356,7 @@ void SwFlyFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
             //receives the original Rect but PaintSwFrameBackground only the 
limited
             //one.
 
-            rRenderContext.Push( 
vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+            auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
             rRenderContext.SetLineColor();
 
             pPage = FindPageFrame();
@@ -4387,7 +4380,7 @@ void SwFlyFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
                 }
                 if ( bContour )
                 {
-                    rRenderContext.Push();
+                    auto popIt2 = rRenderContext.ScopedPush();
                     // #i80822#
                     // apply clip region under the same conditions, which are
                     // used in <SwNoTextFrame::PaintSwFrame(..)> to set the 
clip region
@@ -4404,8 +4397,6 @@ void SwFlyFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
                     {
                         PaintSwFrameBackground( aRegion[i], pPage, rAttrs, 
false, true );
                     }
-
-                    rRenderContext.Pop();
                 }
                 else
                 {
@@ -4418,8 +4409,6 @@ void SwFlyFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
 
             // paint border before painting background
             PaintSwFrameShadowAndBorder(rRect, pPage, rAttrs);
-
-            rRenderContext.Pop();
         }
     }
 
@@ -4603,7 +4592,7 @@ void SwTextFrame::PaintParagraphStylesHighlighting() const
         aFont.SetFamily(FontFamily::FAMILY_MODERN);
         aFont.SetColor(COL_BLACK);
 
-        pRenderContext->Push(vcl::PushFlags::ALL);
+        auto popIt = pRenderContext->ScopedPush(vcl::PushFlags::ALL);
 
         pRenderContext->SetFillColor(nStyleColor);
         pRenderContext->SetLineColor(nStyleColor);
@@ -4625,8 +4614,6 @@ void SwTextFrame::PaintParagraphStylesHighlighting() const
         pRenderContext->SetTextFillColor(nStyleColor);
         pRenderContext->DrawText(aRect, OUString::number(nStyleNumber),
                                  DrawTextFlags::Center | 
DrawTextFlags::VCenter);
-
-        pRenderContext->Pop();
     }
 }
 
@@ -6713,7 +6700,7 @@ void SwFrame::PaintBaBo( const SwRect& rRect, const 
SwPageFrame *pPage,
     // #i16816# tagged pdf support
     SwTaggedPDFHelper aTaggedPDFHelper( nullptr, nullptr, nullptr, *pOut );
 
-    pOut->Push( vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+    auto popIt = pOut->ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
     pOut->SetLineColor();
 
     SwBorderAttrAccess aAccess( SwFrame::GetCache(), this );
@@ -6745,8 +6732,6 @@ void SwFrame::PaintBaBo( const SwRect& rRect, const 
SwPageFrame *pPage,
 
         PaintSwFrameShadowAndBorder(aRect, pPage, rAttrs);
     }
-
-    pOut->Pop();
 }
 
 static bool lcl_compareFillAttributes(const 
drawinglayer::attribute::SdrAllFillAttributesHelperPtr& pA, const 
drawinglayer::attribute::SdrAllFillAttributesHelperPtr& pB)
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx 
b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index 62052080d479..193b33afa2ae 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -2321,7 +2321,7 @@ void 
SwEnhancedPDFExportHelper::EnhancedPDFExport(LanguageType const eLanguageDe
 
     // Prepare the output device:
 
-    mrOut.Push( vcl::PushFlags::MAPMODE );
+    auto popIt = mrOut.ScopedPush(vcl::PushFlags::MAPMODE);
     MapMode aMapMode( mrOut.GetMapMode() );
     aMapMode.SetMapUnit( MapUnit::MapTwip );
     mrOut.SetMapMode( aMapMode );
@@ -3068,7 +3068,6 @@ void 
SwEnhancedPDFExportHelper::EnhancedPDFExport(LanguageType const eLanguageDe
     // Restore view, cursor, and outdev:
     mrSh.LockView( bOldLockView );
     mrSh.SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent);
-    mrOut.Pop();
 }
 
 void SwEnhancedPDFExportHelper::ExportAuthorityEntryLinks()
diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx
index 9c4fbd392213..5e6f0b4a369e 100644
--- a/sw/source/core/text/frmpaint.cxx
+++ b/sw/source/core/text/frmpaint.cxx
@@ -297,7 +297,7 @@ void SwExtraPainter::PaintRedline( SwTwips nY, tools::Long 
nMax, sal_Int16 nWord
             m_aClip.ChgClip( m_aRect, m_pTextFrame );
         }
     }
-    m_pSh->GetOut()->Push(vcl::PushFlags::LINECOLOR);
+    auto popIt = m_pSh->GetOut()->ScopedPush(vcl::PushFlags::LINECOLOR);
     m_pSh->GetOut()->SetLineColor(nWordSpacing ? COL_LIGHTRED : 
SwModule::get()->GetRedlineMarkColor());
 
     if ( nWordSpacing )
@@ -310,7 +310,6 @@ void SwExtraPainter::PaintRedline( SwTwips nY, tools::Long 
nMax, sal_Int16 nWord
     }
     else
         m_pSh->GetOut()->DrawLine( aStart, aEnd );
-    m_pSh->GetOut()->Pop();
 }
 
 void SwTextFrame::PaintExtraData( const SwRect &rRect ) const
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 72fa1b3bb345..3e3174311d81 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -1121,13 +1121,12 @@ void SwTextPaintInfo::DrawLineBreak( const 
SwLinePortion &rPor ) const
         if (eClear != SwLineBreakClear::NONE)
         {
             // Paint indicator if this clear is left/right/all.
-            m_pOut->Push(vcl::PushFlags::LINECOLOR);
+            auto popIt = m_pOut->ScopedPush(vcl::PushFlags::LINECOLOR);
             
m_pOut->SetLineColor(SwViewOption::GetCurrentViewOptions().GetNonPrintingCharacterColor());
             if (eClear != SwLineBreakClear::RIGHT)
                 m_pOut->DrawLine(aRect.BottomLeft(), aRect.TopLeft());
             if (eClear != SwLineBreakClear::LEFT)
                 m_pOut->DrawLine(aRect.BottomRight(), aRect.TopRight());
-            m_pOut->Pop();
         }
     }
 
@@ -1224,18 +1223,17 @@ void SwTextPaintInfo::DrawCheckBox(const 
SwFieldFormCheckboxPortion &rPor, bool
             !GetOpt().IsPagePreview())
     {
         OutputDevice* pOut = const_cast<OutputDevice*>(GetOut());
-        pOut->Push( vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR );
+        auto popIt = pOut->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
         if( m_pFnt->GetHighlightColor() != COL_TRANSPARENT )
             pOut->SetFillColor(m_pFnt->GetHighlightColor());
         else
             pOut->SetFillColor(GetOpt().GetFieldShadingsColor());
         pOut->SetLineColor();
         pOut->DrawRect( aIntersect.SVRect() );
-        pOut->Pop();
     }
     const int delta = 25;
     tools::Rectangle r(aIntersect.Left()+delta, aIntersect.Top()+delta, 
aIntersect.Right()-delta, aIntersect.Bottom()-delta);
-    m_pOut->Push( vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR );
+    auto popIt = m_pOut->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
     m_pOut->SetLineColor( Color(0, 0, 0));
     m_pOut->SetFillColor();
     m_pOut->DrawRect( r );
@@ -1244,7 +1242,6 @@ void SwTextPaintInfo::DrawCheckBox(const 
SwFieldFormCheckboxPortion &rPor, bool
         m_pOut->DrawLine(r.TopLeft(), r.BottomRight());
         m_pOut->DrawLine(r.TopRight(), r.BottomLeft());
     }
-    m_pOut->Pop();
 }
 
 void SwTextPaintInfo::DrawBackground( const SwLinePortion &rPor, const Color 
*pColor ) const
@@ -1258,7 +1255,7 @@ void SwTextPaintInfo::DrawBackground( const SwLinePortion 
&rPor, const Color *pC
         return;
 
     OutputDevice* pOut = const_cast<OutputDevice*>(GetOut());
-    pOut->Push( vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR );
+    auto popIt = pOut->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
 
     if ( pColor )
         pOut->SetFillColor( *pColor );
@@ -1268,7 +1265,6 @@ void SwTextPaintInfo::DrawBackground( const SwLinePortion 
&rPor, const Color *pC
     pOut->SetLineColor();
 
     DrawRect( aIntersect, true );
-    pOut->Pop();
 }
 
 void SwTextPaintInfo::DrawBackBrush( const SwLinePortion &rPor ) const
@@ -1293,11 +1289,10 @@ void SwTextPaintInfo::DrawBackBrush( const 
SwLinePortion &rPor ) const
                     !GetOpt().IsPagePreview())
             {
                 OutputDevice* pOutDev = const_cast<OutputDevice*>(GetOut());
-                pOutDev->Push( vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR );
+                auto popIt = pOutDev->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
                 pOutDev->SetFillColor( GetOpt().GetFieldShadingsColor() );
                 pOutDev->SetLineColor( );
                 pOutDev->DrawRect( aIntersect.SVRect() );
-                pOutDev->Pop();
             }
         }
     }
@@ -1326,7 +1321,7 @@ void SwTextPaintInfo::DrawBackBrush( const SwLinePortion 
&rPor ) const
         aFillColor = *m_pFnt->GetBackColor();
     }
 
-    pTmpOut->Push( vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR );
+    auto popIt = pTmpOut->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
 
     if (aFillColor == COL_TRANSPARENT)
         pTmpOut->SetFillColor();
@@ -1335,8 +1330,6 @@ void SwTextPaintInfo::DrawBackBrush( const SwLinePortion 
&rPor ) const
     pTmpOut->SetLineColor();
 
     DrawRect( aIntersect, false );
-
-    pTmpOut->Pop();
 }
 
 void SwTextPaintInfo::DrawBorder( const SwLinePortion &rPor ) const
@@ -1498,8 +1491,8 @@ void SwTextPaintInfo::DrawCSDFHighlighting(const 
SwLinePortion &rPor) const
     if (sCSNumberOrDF)
     {
         OutputDevice* pTmpOut = const_cast<OutputDevice*>(GetOut());
-        pTmpOut->Push(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR
-                      | vcl::PushFlags::TEXTLAYOUTMODE | vcl::PushFlags::FONT);
+        auto popIt = pTmpOut->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR
+                                          | vcl::PushFlags::TEXTLAYOUTMODE | 
vcl::PushFlags::FONT);
 
         // draw a filled rectangle at the formatted CS or DF text
         pTmpOut->SetFillColor(aFillColor.value());
@@ -1522,8 +1515,6 @@ void SwTextPaintInfo::DrawCSDFHighlighting(const 
SwLinePortion &rPor) const
 
         pTmpOut->SetTextFillColor(aFillColor.value());
         pTmpOut->DrawText(aSVRect, sCSNumberOrDF.value(), DrawTextFlags::NONE);
-
-        pTmpOut->Pop();
     }
 }
 
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index 53fc1e3eff71..e7054c6a6d27 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -654,14 +654,13 @@ void SwHiddenTextPortion::Paint( const SwTextPaintInfo & 
rInf) const
 {
 #ifdef DBG_UTIL
     OutputDevice* pOut = const_cast<OutputDevice*>(rInf.GetOut());
-    pOut->Push(vcl::PushFlags::FILLCOLOR);
+    auto popIt = pOut->ScopedPush(vcl::PushFlags::FILLCOLOR);
     pOut->SetFillColor( rInf.GetOpt().GetFieldShadingsColor() );
     Point aPos( rInf.GetPos() );
     aPos.AdjustY( -150 );
     aPos.AdjustX( -25 );
     SwRect aRect( aPos, Size( 100, 200 ) );
     pOut->DrawRect( aRect.SVRect() );
-    pOut->Pop();
 #else
     (void)rInf;
 #endif
diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx
index 1feb0a9b86e5..a95ec986ef7b 100644
--- a/sw/source/core/text/portxt.cxx
+++ b/sw/source/core/text/portxt.cxx
@@ -1011,11 +1011,10 @@ void SwTextInputFieldPortion::Paint( const 
SwTextPaintInfo &rInf ) const
             && !rInf.GetOpt().IsPagePreview())
         {
             OutputDevice* pOut = const_cast<OutputDevice*>(rInf.GetOut());
-            pOut->Push(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
+            auto popIt = pOut->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
             pOut->SetFillColor(rInf.GetOpt().GetFieldShadingsColor());
             pOut->SetLineColor();
             pOut->DrawRect(aIntersect.SVRect());
-            pOut->Pop();
         }
     }
 }
diff --git a/sw/source/core/txtnode/fntcache.cxx 
b/sw/source/core/txtnode/fntcache.cxx
index 558e95355351..bb6221532490 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -650,10 +650,8 @@ static void lcl_DrawLineForWrongListData(
     }
 
     SwForbidden::iterator pIter = rForbidden.begin();
-    if (rInf.GetOut().GetConnectMetaFile())
-        rInf.GetOut().Push();
-    else
-        rInf.GetOut().Push(vcl::PushFlags::LINECOLOR);
+    auto popIt = rInf.GetOut().ScopedPush(
+        rInf.GetOut().GetConnectMetaFile() ? vcl::PushFlags::ALL : 
vcl::PushFlags::LINECOLOR);
 
     // iterate over all ranges stored in the respective SwWrongList
     do
@@ -742,8 +740,6 @@ static void lcl_DrawLineForWrongListData(
         nWrLen = rInf.GetIdx() + rInf.GetLen() - nStart;
     }
     while (nWrLen && pWList->Check( nStart, nWrLen ));
-
-    rInf.GetOut().Pop();
 }
 
 static void GetTextArray(const SwDrawTextInfo& rExtraInf, const OutputDevice& 
rDevice,
@@ -1606,7 +1602,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
                               aKashidaArray, nIdx, nLen, 
rInf.GetLayoutContext());
                 if (bBullet)
                 {
-                    rInf.GetOut().Push();
+                    auto popIt = rInf.GetOut().ScopedPush();
                     Color aPreviousColor = pTmpFont->GetColor();
 
                     FontLineStyle aPreviousUnderline = 
pTmpFont->GetUnderline();
@@ -1646,7 +1642,6 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
                     pTmpFont->SetUnderline(aPreviousUnderline);
                     pTmpFont->SetOverline(aPreviousOverline);
                     pTmpFont->SetStrikeout(aPreviousStrikeout);
-                    rInf.GetOut().Pop();
                 }
             }
         }
diff --git a/sw/source/core/view/pagepreviewlayout.cxx 
b/sw/source/core/view/pagepreviewlayout.cxx
index 184d60c30650..1b0445f7489f 100644
--- a/sw/source/core/view/pagepreviewlayout.cxx
+++ b/sw/source/core/view/pagepreviewlayout.cxx
@@ -1215,7 +1215,8 @@ void 
SwPagePreviewLayout::PaintSelectMarkAtPage(vcl::RenderContext& rRenderConte
     OutputDevice* pOutputDev = &rRenderContext;
     MapMode aMapMode( pOutputDev->GetMapMode() );
     // save fill and line color and mapping mode of output device
-    pOutputDev->Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::MAPMODE);
+    auto popIt = pOutputDev->ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR
+                                        | vcl::PushFlags::MAPMODE);
 
     // determine selection mark color
     Color aSelPgLineColor(117, 114, 106);
@@ -1249,9 +1250,6 @@ void 
SwPagePreviewLayout::PaintSelectMarkAtPage(vcl::RenderContext& rRenderConte
                        aPxPageRect.Right()-1, aPxPageRect.Bottom()-1 );
     aRect = pOutputDev->PixelToLogic( aRect );
     pOutputDev->DrawRect( aRect );
-
-    // reset fill and line color and mapping mode of output device
-    pOutputDev->Pop();
 }
 
 /** paint to mark new selected page
diff --git a/sw/source/core/view/viewpg.cxx b/sw/source/core/view/viewpg.cxx
index 02ebd1a69e12..fd9b0969d88c 100644
--- a/sw/source/core/view/viewpg.cxx
+++ b/sw/source/core/view/viewpg.cxx
@@ -75,7 +75,7 @@ void SwViewShell::PrintProspect(
 
     // save settings of OutputDevice (should be done always since the
     // output device is now provided by a call from outside the Writer)
-    pPrinter->Push();
+    auto popIt = pPrinter->ScopedPush();
 
     std::pair< sal_Int32, sal_Int32 > rPagesToPrint =
             rPrintData.GetRenderData().GetPagePairsForProspectPrinting()[ 
nRenderer ];
@@ -207,10 +207,6 @@ void SwViewShell::PrintProspect(
     //!! applying/modifying view options and formatting the document should 
now only be done in getRendererCount!
 
     pFntCache->Flush();
-
-    // restore settings of OutputDevice (should be done always now since the
-    // output device is now provided by a call from outside the Writer)
-    pPrinter->Pop();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 9985cc0e5f0b..01c142016089 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -1810,7 +1810,7 @@ void SwViewShell::PaintDesktop_(const SwRegionRects 
&rRegion)
         return;
 
     // OD 2004-04-23 #116347#
-    GetOut()->Push( vcl::PushFlags::FILLCOLOR|vcl::PushFlags::LINECOLOR );
+    auto popIt = GetOut()->ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
     GetOut()->SetLineColor();
 
     for ( auto &rRgn : rRegion )
@@ -1854,8 +1854,6 @@ void SwViewShell::PaintDesktop_(const SwRegionRects 
&rRegion)
 
         DLPostPaint2(false);
     }
-
-    GetOut()->Pop();
 }
 
 bool SwViewShell::DrawAppBackgroundBitmap(vcl::RenderContext* rRenderContext, 
const SwRect& rRect)
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
index a1c14fb3c65d..45b51169fb99 100644
--- a/sw/source/core/view/vprint.cxx
+++ b/sw/source/core/view/vprint.cxx
@@ -587,11 +587,10 @@ void SwViewShell::PrtOle2( SwDoc *pDoc, const 
SwViewOption *pOpt, const SwPrintD
         // document because the thumbnail creation will not trigger a complete
         // formatting of the document.
 
-        rRenderContext.Push( vcl::PushFlags::CLIPREGION );
+        auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::CLIPREGION);
         rRenderContext.IntersectClipRegion( aSwRect.SVRect() );
         pSh->GetLayout()->PaintSwFrame( rRenderContext, aSwRect );
 
-        rRenderContext.Pop();
         // first the CurrShell object needs to be destroyed!
     }
 }
diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index a1bd16a06aa9..766b308fd8f9 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -2388,13 +2388,12 @@ awt::Size 
SwWW8ImplReader::MiserableDropDownFormHack(const OUString &rString,
     OSL_ENSURE(pOut, "Impossible");
     if (pOut)
     {
-        pOut->Push( vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE );
+        auto popIt = pOut->ScopedPush(vcl::PushFlags::FONT | 
vcl::PushFlags::MAPMODE);
         pOut->SetMapMode( MapMode( MapUnit::Map100thMM ));
         pOut->SetFont( aFont );
         aRet.Width  = pOut->GetTextWidth(rString);
         aRet.Width += 500; //plus size of button, total hack territory
         aRet.Height = pOut->GetTextHeight();
-        pOut->Pop();
     }
     return aRet;
 }
diff --git a/sw/source/ui/chrdlg/drpcps.cxx b/sw/source/ui/chrdlg/drpcps.cxx
index 5e45810006e6..5ed6e0e86d4d 100644
--- a/sw/source/ui/chrdlg/drpcps.cxx
+++ b/sw/source/ui/chrdlg/drpcps.cxx
@@ -115,12 +115,11 @@ static void calcFontHeightAnyAscent(vcl::RenderContext& 
rWin, vcl::Font const &
 {
     if ( !_nHeight )
     {
-        rWin.Push(vcl::PushFlags::FONT);
+        auto popIt = rWin.ScopedPush(vcl::PushFlags::FONT);
         rWin.SetFont(_rFont);
         FontMetric aMetric(rWin.GetFontMetric());
         _nHeight = aMetric.GetLineHeight();
         _nAscent = aMetric.GetAscent();
-        rWin.Pop();
     }
 }
 
diff --git a/sw/source/ui/frmdlg/column.cxx b/sw/source/ui/frmdlg/column.cxx
index 2dad1a1df3fc..d56aab406615 100644
--- a/sw/source/ui/frmdlg/column.cxx
+++ b/sw/source/ui/frmdlg/column.cxx
@@ -1318,7 +1318,7 @@ void ColumnValueSet::UserDraw(const UserDrawEvent& rUDEvt)
     tools::Long nRectHeight = aRect.GetHeight();
 
     Point aBLPos = aRect.TopLeft();
-    pDev->Push(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
+    auto popIt = pDev->ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
     pDev->SetFillColor(rStyleSettings.GetFieldColor());
     pDev->SetLineColor(rStyleSettings.GetFieldTextColor());
 
@@ -1368,7 +1368,6 @@ void ColumnValueSet::UserDraw(const UserDrawEvent& rUDEvt)
             pDev->DrawLine(aStart, aEnd);
         }
     }
-    pDev->Pop();
 }
 
 void ColumnValueSet::StyleUpdated()
diff --git a/sw/source/ui/table/autoformatpreview.cxx 
b/sw/source/ui/table/autoformatpreview.cxx
index fe41318798a5..92f149536c1e 100644
--- a/sw/source/ui/table/autoformatpreview.cxx
+++ b/sw/source/ui/table/autoformatpreview.cxx
@@ -327,7 +327,8 @@ void AutoFormatPreview::DrawBackground(vcl::RenderContext& 
rRenderContext)
             SvxBrushItem aBrushItem(
                 maCurrentData.GetBoxFormat(GetFormatIndex(nCol, 
nRow)).GetProps().GetBackground());
 
-            rRenderContext.Push(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
+            auto popIt
+                = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
             rRenderContext.SetLineColor();
             if (aBrushItem.GetColor() == COL_TRANSPARENT)
                 rRenderContext.SetFillColor();
@@ -339,7 +340,6 @@ void AutoFormatPreview::DrawBackground(vcl::RenderContext& 
rRenderContext)
                                  
basegfx::fround<tools::Long>(aCellRange.getMinY()),
                                  
basegfx::fround<tools::Long>(aCellRange.getMaxX()),
                                  
basegfx::fround<tools::Long>(aCellRange.getMaxY())));
-            rRenderContext.Pop();
         }
     }
 }
@@ -439,7 +439,7 @@ void AutoFormatPreview::NotifyChange(const 
SwTableAutoFormat& rNewData)
 
 void AutoFormatPreview::Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle&)
 {
-    rRenderContext.Push(vcl::PushFlags::ALL);
+    auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::ALL);
 
     const Color& rWinColor
         = 
SwModule::get()->GetColorConfig().GetColorValue(::svtools::DOCCOLOR).nColor;
@@ -470,7 +470,6 @@ void AutoFormatPreview::Paint(vcl::RenderContext& 
rRenderContext, const tools::R
     PaintCells(rRenderContext);
 
     rRenderContext.SetDrawMode(nOldDrawMode);
-    rRenderContext.Pop();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index 11e1cb6f2d28..431cdbbe2e5f 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -195,10 +195,9 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, 
const Point& rPt)
         Point aPos(rPt + PixelToLogic(Point(x, y)));
         Size aSize(PixelToLogic(Size(width, height)));
 
-        pDev->Push(vcl::PushFlags::CLIPREGION);
+        auto popIt1 = pDev->ScopedPush(vcl::PushFlags::CLIPREGION);
         pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
         pDev->DrawText(aPos, mxMetadataAuthor->get_label());
-        pDev->Pop();
     }
 
     if (mxMetadataDate->get_visible())
@@ -208,10 +207,9 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, 
const Point& rPt)
         Point aPos(rPt + PixelToLogic(Point(x, y)));
         Size aSize(PixelToLogic(Size(width, height)));
 
-        pDev->Push(vcl::PushFlags::CLIPREGION);
+        auto popIt1 = pDev->ScopedPush(vcl::PushFlags::CLIPREGION);
         pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
         pDev->DrawText(aPos, mxMetadataDate->get_label());
-        pDev->Pop();
     }
 
     if (mxMetadataResolved->get_visible())
@@ -221,10 +219,9 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, 
const Point& rPt)
         Point aPos(rPt + PixelToLogic(Point(x, y)));
         Size aSize(PixelToLogic(Size(width, height)));
 
-        pDev->Push(vcl::PushFlags::CLIPREGION);
+        auto popIt1 = pDev->ScopedPush(vcl::PushFlags::CLIPREGION);
         pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
         pDev->DrawText(aPos, mxMetadataResolved->get_label());
-        pDev->Pop();
     }
 
     mxSidebarTextControl->DrawForPage(pDev, rPt);
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx 
b/sw/source/uibase/docvw/SidebarTxtControl.cxx
index acb72005eaba..652b8f7427e8 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.cxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx
@@ -239,7 +239,7 @@ void SidebarTextControl::DrawForPage(OutputDevice* pDev, 
const Point& rPt)
     if ( mrSidebarWin.GetLayoutStatus()!=SwPostItHelper::DELETED )
         return;
 
-    pDev->Push(vcl::PushFlags::LINECOLOR);
+    auto popIt = pDev->ScopedPush(vcl::PushFlags::LINECOLOR);
 
     pDev->SetLineColor(mrSidebarWin.GetChangeColor());
     Point aBottomRight(rPt);
@@ -253,8 +253,6 @@ void SidebarTextControl::DrawForPage(OutputDevice* pDev, 
const Point& rPt)
     aBottomLeft.Move(Size(0, aSize.Height()));
 
     pDev->DrawLine(aTopRight, aBottomLeft);
-
-    pDev->Pop();
 }
 
 void SidebarTextControl::Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& rRect)
diff --git a/sw/source/uibase/frmdlg/colex.cxx 
b/sw/source/uibase/frmdlg/colex.cxx
index 6ddde5ecaabc..26b08f1faf08 100644
--- a/sw/source/uibase/frmdlg/colex.cxx
+++ b/sw/source/uibase/frmdlg/colex.cxx
@@ -313,7 +313,7 @@ SwColumnOnlyExample::SwColumnOnlyExample()
 
 void SwColumnOnlyExample::Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& /*rRect*/)
 {
-    rRenderContext.Push(vcl::PushFlags::MAPMODE);
+    auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE);
     rRenderContext.Erase();
 
     Fraction aScale(m_aWinSize.Height(), m_aFrameSize.Height());
@@ -401,7 +401,6 @@ void SwColumnOnlyExample::Paint(vcl::RenderContext& 
rRenderContext, const tools:
             }
         }
     }
-    rRenderContext.Pop();
 }
 
 void  SwColumnOnlyExample::SetColumns(const SwFormatCol& rCol)
diff --git a/sw/source/uibase/sidebar/QuickFindPanel.cxx 
b/sw/source/uibase/sidebar/QuickFindPanel.cxx
index a5e633254ab0..77a8b24c190c 100644
--- a/sw/source/uibase/sidebar/QuickFindPanel.cxx
+++ b/sw/source/uibase/sidebar/QuickFindPanel.cxx
@@ -331,7 +331,7 @@ IMPL_LINK(QuickFindPanel, SearchFindsListRender, 
weld::TreeView::render_args, aP
         tools::Long aTextWidth = rRenderContext.GetTextWidth(aEntry);
         tools::Long aTextHeight = rRenderContext.GetTextHeight();
 
-        rRenderContext.Push();
+        auto popIt = rRenderContext.ScopedPush();
         svtools::ColorConfig aColorConfig;
         
rRenderContext.SetLineColor(aColorConfig.GetColorValue(svtools::BUTTONTEXTCOLOR).nColor);
         rRenderContext.DrawLine(
@@ -343,7 +343,6 @@ IMPL_LINK(QuickFindPanel, SearchFindsListRender, 
weld::TreeView::render_args, aP
         rRenderContext.DrawLine(
             Point(aRect.Center().AdjustX(aTextWidth / 2) + 5, 
aRect.Center().getY()),
             aRect.RightCenter());
-        rRenderContext.Pop();
     }
 }
 
diff --git a/sw/source/uibase/uiview/srcview.cxx 
b/sw/source/uibase/uiview/srcview.cxx
index f6988e1c63ba..3767f12ad641 100644
--- a/sw/source/uibase/uiview/srcview.cxx
+++ b/sw/source/uibase/uiview/srcview.cxx
@@ -668,7 +668,7 @@ sal_Int32 SwSrcView::PrintSource(
     //! But since HTML source code is expected to be just a small number of 
pages
     //! even this poor algorithm should be enough...
 
-    pOutDev->Push();
+    auto popIt = pOutDev->ScopedPush();
 
     TextEngine* pTextEngine = m_aEditWin->GetTextEngine();
     pOutDev->SetMapMode(MapMode(MapUnit::Map100thMM));
@@ -727,8 +727,6 @@ sal_Int32 SwSrcView::PrintSource(
         aPos.AdjustY(nParaSpace );
     }
 
-    pOutDev->Pop();
-
     OSL_ENSURE( bCalcNumPagesOnly || nPage <= nCurPage, "page number out of 
range" );
     return nCurPage;
 }
diff --git a/sw/source/uibase/utlui/unotools.cxx 
b/sw/source/uibase/utlui/unotools.cxx
index 09bacb12c50b..9c01c5e6994c 100644
--- a/sw/source/uibase/utlui/unotools.cxx
+++ b/sw/source/uibase/utlui/unotools.cxx
@@ -156,7 +156,7 @@ void SwOneExampleFrame::Paint(vcl::RenderContext& 
rRenderContext, const tools::R
 
         double fZoom = 100.0 / nZoom;
 
-        m_xVirDev->Push(vcl::PushFlags::ALL);
+        auto popIt = m_xVirDev->ScopedPush(vcl::PushFlags::ALL);
         m_xVirDev->SetMapMode(MapMode(MapUnit::MapTwip));
         SwDoc *pDoc = m_xCursor->GetDoc();
         SwDocShell* pShell = pDoc->GetDocShell();
@@ -164,7 +164,6 @@ void SwOneExampleFrame::Paint(vcl::RenderContext& 
rRenderContext, const tools::R
         pShell->SetVisArea(tools::Rectangle(Point(), Size(aRect.GetWidth() * 
fZoom,
                                                           aRect.GetHeight() * 
fZoom)));
         pShell->DoDraw(m_xVirDev.get(), aRect.TopLeft(), aRect.GetSize(), 
JobSetup(), ASPECT_CONTENT, true);
-        m_xVirDev->Pop();
     }
 
     rRenderContext.DrawOutDev(Point(), aSize, Point(), aSize, *m_xVirDev);
diff --git a/sw/source/writerfilter/dmapper/SdtHelper.cxx 
b/sw/source/writerfilter/dmapper/SdtHelper.cxx
index 74292c0a8a8e..ce9730c80b8c 100644
--- a/sw/source/writerfilter/dmapper/SdtHelper.cxx
+++ b/sw/source/writerfilter/dmapper/SdtHelper.cxx
@@ -55,7 +55,7 @@ static awt::Size lcl_getOptimalWidth(const 
StyleSheetTablePtr& pStyleSheet,
 
     MapMode aMap(MapUnit::Map100thMM);
     OutputDevice* pOut = Application::GetDefaultDevice();
-    pOut->Push(vcl::PushFlags::FONT | vcl::PushFlags::MAPMODE);
+    auto popIt = pOut->ScopedPush(vcl::PushFlags::FONT | 
vcl::PushFlags::MAPMODE);
 
     PropertyMapPtr pDefaultCharProps = pStyleSheet->GetDefaultCharProps();
     vcl::Font aFont(pOut->GetFont());
@@ -73,8 +73,6 @@ static awt::Size lcl_getOptimalWidth(const 
StyleSheetTablePtr& pStyleSheet,
     pOut->SetMapMode(aMap);
     sal_Int32 nWidth = pOut->GetTextWidth(aLongest);
 
-    pOut->Pop();
-
     // Border: see PDFWriterImpl::drawFieldBorder(), border size is font 
height / 4,
     // so additional width / height needed is height / 2.
     sal_Int32 nBorder = nHeight / 2;

Reply via email to