basctl/source/dlged/dlged.cxx                       |    4 ---
 canvas/source/vcl/canvashelper_texturefill.cxx      |    3 --
 canvas/source/vcl/spritecanvashelper.cxx            |    4 ---
 cui/source/tabpages/grfpage.cxx                     |    4 ---
 cui/source/tabpages/numfmt.cxx                      |    3 --
 dbaccess/source/ui/browser/dataview.cxx             |    3 --
 dbaccess/source/ui/tabledesign/TEditControl.cxx     |    3 --
 desktop/source/deployment/gui/dp_gui_extlistbox.cxx |    3 --
 desktop/source/lib/init.cxx                         |    3 --
 forms/source/richtext/richtextimplcontrol.cxx       |    7 +----
 reportdesign/source/ui/report/StartMarker.cxx       |   26 +++++++++-----------
 toolkit/source/controls/table/gridtablerenderer.cxx |   20 +++------------
 toolkit/source/hatchwindow/ipwin.cxx                |    3 --
 13 files changed, 29 insertions(+), 57 deletions(-)

New commits:
commit b68633e21cc73bbffee06859a1c495fc4e25140a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Aug 16 23:42:37 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Aug 17 09:44:41 2025 +0200

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

diff --git a/basctl/source/dlged/dlged.cxx b/basctl/source/dlged/dlged.cxx
index b60ca6627542..1f72b3ae4e07 100644
--- a/basctl/source/dlged/dlged.cxx
+++ b/basctl/source/dlged/dlged.cxx
@@ -1071,7 +1071,7 @@ namespace Print
 static void lcl_PrintHeader( Printer* pPrinter, const OUString& rTitle ) // 
not working yet
 {
 
-    pPrinter->Push();
+    auto popIt = pPrinter->ScopedPush();
 
     Size const aSz = pPrinter->GetOutputSize();
 
@@ -1102,8 +1102,6 @@ static void lcl_PrintHeader( Printer* pPrinter, const 
OUString& rTitle ) // not
 
     nY = Print::nTopMargin - Print::nBorder;
     pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
-
-    pPrinter->Pop();
 }
 
 
diff --git a/canvas/source/vcl/canvashelper_texturefill.cxx 
b/canvas/source/vcl/canvashelper_texturefill.cxx
index aa94de3f1d0f..7c468ba4b4b3 100644
--- a/canvas/source/vcl/canvashelper_texturefill.cxx
+++ b/canvas/source/vcl/canvashelper_texturefill.cxx
@@ -1039,7 +1039,7 @@ namespace vclcanvas
                             if( mp2ndOutDevProvider )
                             {
                                 OutputDevice& r2ndOutDev( 
mp2ndOutDevProvider->getOutDev() );
-                                r2ndOutDev.Push( vcl::PushFlags::CLIPREGION );
+                                auto popIt = 
r2ndOutDev.ScopedPush(vcl::PushFlags::CLIPREGION);
 
                                 r2ndOutDev.IntersectClipRegion( 
aPolyClipRegion );
                                 textureFill( r2ndOutDev,
@@ -1051,7 +1051,6 @@ namespace vclcanvas
                                              nTilesY,
                                              aSz,
                                              aGrfAttr );
-                                r2ndOutDev.Pop();
                             }
                         }
                     }
diff --git a/canvas/source/vcl/spritecanvashelper.cxx 
b/canvas/source/vcl/spritecanvashelper.cxx
index c8bef05d721f..7daff2655c48 100644
--- a/canvas/source/vcl/spritecanvashelper.cxx
+++ b/canvas/source/vcl/spritecanvashelper.cxx
@@ -406,13 +406,11 @@ namespace vclcanvas
             // repaint uncovered areas from sprite. Need to actually
             // clip here, since we're only repainting _parts_ of the
             // sprite
-            rOutDev.Push( vcl::PushFlags::CLIPREGION );
+            auto popIt = rOutDev.ScopedPush(vcl::PushFlags::CLIPREGION);
 
             for( const auto& rArea : aUnscrollableAreas )
                 opaqueUpdateSpriteArea( aFirst->second.getSprite(),
                                         rOutDev, rArea );
-
-            rOutDev.Pop();
         }
 
         // repaint uncovered areas from backbuffer - take the
diff --git a/cui/source/tabpages/grfpage.cxx b/cui/source/tabpages/grfpage.cxx
index 3895080969ae..e5e18fdad9b7 100644
--- a/cui/source/tabpages/grfpage.cxx
+++ b/cui/source/tabpages/grfpage.cxx
@@ -752,7 +752,7 @@ void SvxCropExample::SetDrawingArea(weld::DrawingArea* 
pDrawingArea)
 
 void SvxCropExample::Paint(vcl::RenderContext& rRenderContext, const 
::tools::Rectangle&)
 {
-    rRenderContext.Push(vcl::PushFlags::MAPMODE);
+    auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE);
     rRenderContext.SetMapMode(m_aMapMode);
 
     // Win BG
@@ -803,8 +803,6 @@ void SvxCropExample::Paint(vcl::RenderContext& 
rRenderContext, const ::tools::Re
             rRenderContext.DrawPolyLine(rSnippet);
         },
         2.0 * fLogicDashLength);
-
-    rRenderContext.Pop();
 }
 
 void SvxCropExample::Resize()
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index e62f8ee53b7d..836f72440d05 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -141,7 +141,7 @@ void SvxNumberPreview::NotifyChange( const OUString& 
rPrevStr,
 
 void SvxNumberPreview::Paint(vcl::RenderContext& rRenderContext, const 
::tools::Rectangle&)
 {
-    rRenderContext.Push(vcl::PushFlags::ALL);
+    auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::ALL);
 
     svtools::ColorConfig aColorConfig;
     Color aBgColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
@@ -184,7 +184,6 @@ void SvxNumberPreview::Paint(vcl::RenderContext& 
rRenderContext, const ::tools::
 
     Point aPosText(nX, (aSzWnd.Height() - GetTextHeight()) / 2);
     rRenderContext.DrawText(aPosText, aTmpStr);
-    rRenderContext.Pop();
 }
 
 // class SvxNumberFormatTabPage ------------------------------------------
diff --git a/dbaccess/source/ui/browser/dataview.cxx 
b/dbaccess/source/ui/browser/dataview.cxx
index 11f9a91df015..a06d58029e53 100644
--- a/dbaccess/source/ui/browser/dataview.cxx
+++ b/dbaccess/source/ui/browser/dataview.cxx
@@ -68,11 +68,10 @@ namespace dbaui
     {
         // draw the background
         {
-            rRenderContext.Push(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
+            auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
             rRenderContext.SetLineColor();
             
rRenderContext.SetFillColor(GetSettings().GetStyleSettings().GetFaceColor());
             rRenderContext.DrawRect(_rRect);
-            rRenderContext.Pop();
         }
 
         // let the base class do anything it needs
diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx 
b/dbaccess/source/ui/tabledesign/TEditControl.cxx
index 8ab86caeea15..00ef43be9f6d 100644
--- a/dbaccess/source/ui/tabledesign/TEditControl.cxx
+++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx
@@ -300,10 +300,9 @@ void OTableEditorCtrl::PaintCell(OutputDevice& rDev, const 
tools::Rectangle& rRe
 {
     const OUString aText( GetCellText( m_nCurrentPos, nColumnId ));
 
-    rDev.Push( vcl::PushFlags::CLIPREGION );
+    auto popIt = rDev.ScopedPush(vcl::PushFlags::CLIPREGION);
     rDev.SetClipRegion(vcl::Region(rRect));
     rDev.DrawText( rRect, aText, DrawTextFlags::Left | DrawTextFlags::VCenter 
);
-    rDev.Pop();
 }
 
 CellController* OTableEditorCtrl::GetController(sal_Int32 nRow, sal_uInt16 
nColumnId)
diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx 
b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
index 28131001fc5b..3faf1bb9593a 100644
--- a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
+++ b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
@@ -507,7 +507,7 @@ void ExtensionBox_Impl::DrawRow(vcl::RenderContext& 
rRenderContext, const tools:
     {
         aPos = rRect.TopLeft() + Point( ICON_OFFSET + nMaxTitleWidth + 
(2*SPACE_BETWEEN), TOP_OFFSET );
 
-        rRenderContext.Push(vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR | 
vcl::PushFlags::TEXTFILLCOLOR);
+        auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::FONT | 
vcl::PushFlags::TEXTCOLOR | vcl::PushFlags::TEXTFILLCOLOR);
         rRenderContext.SetTextColor(rStyleSettings.GetLinkColor());
         rRenderContext.SetTextFillColor(rStyleSettings.GetFieldColor());
         vcl::Font aFont = rRenderContext.GetFont();
@@ -516,7 +516,6 @@ void ExtensionBox_Impl::DrawRow(vcl::RenderContext& 
rRenderContext, const tools:
         rRenderContext.SetFont(aFont);
         rRenderContext.DrawText(aPos, rEntry->m_sPublisher);
         rEntry->m_aLinkRect = tools::Rectangle(aPos, Size(nLinkWidth, 
aTextHeight));
-        rRenderContext.Pop();
     }
 
     // Draw status icons
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ff66953c032e..981ac0c73525 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -4314,11 +4314,10 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
         // Draw a small red rectangle in the top left corner so that it's easy 
to see where a new tile begins.
         tools::Rectangle aRect(0, 0, 5, 5);
         aRect = pDevice->PixelToLogic(aRect);
-        pDevice->Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
+        auto popIt = pDevice->ScopedPush(PushFlags::FILLCOLOR | 
PushFlags::LINECOLOR);
         pDevice->SetFillColor(COL_LIGHTRED);
         pDevice->SetLineColor();
         pDevice->DrawRect(aRect);
-        pDevice->Pop();
     }
 
 #ifdef _WIN32
diff --git a/forms/source/richtext/richtextimplcontrol.cxx 
b/forms/source/richtext/richtextimplcontrol.cxx
index 83a810cab780..43e250ae9f37 100644
--- a/forms/source/richtext/richtextimplcontrol.cxx
+++ b/forms/source/richtext/richtextimplcontrol.cxx
@@ -436,10 +436,9 @@ namespace frm
             tools::Long nFontWidth = 
m_pEngine->GetStandardFont(0).GetFontSize().Width();
             if ( !nFontWidth )
             {
-                m_pViewport->GetOutDev()->Push( vcl::PushFlags::FONT );
+                auto popIt = 
m_pViewport->GetOutDev()->ScopedPush(vcl::PushFlags::FONT);
                 m_pViewport->SetFont( m_pEngine->GetStandardFont(0) );
                 nFontWidth = m_pViewport->GetTextWidth( u"x"_ustr );
-                m_pViewport->GetOutDev()->Pop();
             }
             // ... is the scroll size for the horizontal scrollbar
             m_pHScroll->SetLineSize( 5 * nFontWidth );
@@ -551,7 +550,7 @@ namespace frm
     {
         // need to normalize the map mode of the device - every paint 
operation on any device needs
         // to use the same map mode
-        _pDev->Push( vcl::PushFlags::MAPMODE | vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR );
+        auto popIt = _pDev->ScopedPush(vcl::PushFlags::MAPMODE | 
vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
 
         // enforce our "normalize map mode" on the device
         MapMode aRefMapMode( m_pEngine->GetRefDevice()->GetMapMode() );
@@ -602,8 +601,6 @@ namespace frm
 
         // actually draw the content
         m_pEngine->DrawText_ToRectangle(*_pDev, aPlayground, Point(), true);
-
-        _pDev->Pop();
     }
 
 
diff --git a/reportdesign/source/ui/report/StartMarker.cxx 
b/reportdesign/source/ui/report/StartMarker.cxx
index 170ef063eac1..8e9d4fc56ca9 100644
--- a/reportdesign/source/ui/report/StartMarker.cxx
+++ b/reportdesign/source/ui/report/StartMarker.cxx
@@ -96,7 +96,7 @@ sal_Int32 OStartMarker::getMinHeight() const
 
 void OStartMarker::Paint(vcl::RenderContext& rRenderContext, const 
tools::Rectangle& /*rRect*/)
 {
-    rRenderContext.Push(vcl::PushFlags::TEXTCOLOR);
+    auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::TEXTCOLOR);
 
     Size aSize(GetOutputSizePixel());
     const tools::Long nCornerWidth = tools::Long(CORNER_SPACE * 
double(GetMapMode().GetScaleX()));
@@ -134,20 +134,20 @@ void OStartMarker::Paint(vcl::RenderContext& 
rRenderContext, const tools::Rectan
         rRenderContext.DrawGradient(PixelToLogic(aPoly) ,aGradient);
     }
 
-    rRenderContext.Push(vcl::PushFlags::MAPMODE);
-    rRenderContext.SetMapMode();
-
-    rRenderContext.DrawImage(m_aImageRect.TopLeft(), m_aImageRect.GetSize(), 
m_aImage);
+    {
+        auto popIt2 = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE);
+        rRenderContext.SetMapMode();
 
-    const Color aColor(m_nColor);
-    Color aTextColor = GetTextColor();
-    if (aColor.GetLuminance() < 128)
-        aTextColor = COL_WHITE;
-    rRenderContext.SetTextColor(aTextColor);
+        rRenderContext.DrawImage(m_aImageRect.TopLeft(), 
m_aImageRect.GetSize(), m_aImage);
 
-    rRenderContext.DrawText(m_aTextRect, m_aText, DrawTextFlags::MultiLine | 
DrawTextFlags::WordBreakHyphenation);
+        const Color aColor(m_nColor);
+        Color aTextColor = GetTextColor();
+        if (aColor.GetLuminance() < 128)
+            aTextColor = COL_WHITE;
+        rRenderContext.SetTextColor(aTextColor);
 
-    rRenderContext.Pop();
+        rRenderContext.DrawText(m_aTextRect, m_aText, DrawTextFlags::MultiLine 
| DrawTextFlags::WordBreakHyphenation);
+    }
 
     if (m_bMarked)
     {
@@ -159,8 +159,6 @@ void OStartMarker::Paint(vcl::RenderContext& 
rRenderContext, const tools::Rectan
         rRenderContext.DrawPolyLine( 
tools::Polygon(rRenderContext.PixelToLogic(aRect)),
                                     LineInfo(LineStyle::Solid, 2));
     }
-
-    rRenderContext.Pop();
 }
 
 void OStartMarker::MouseButtonUp( const MouseEvent& rMEvt )
diff --git a/toolkit/source/controls/table/gridtablerenderer.cxx 
b/toolkit/source/controls/table/gridtablerenderer.cxx
index 35af29c17bff..c36d1727c4cf 100644
--- a/toolkit/source/controls/table/gridtablerenderer.cxx
+++ b/toolkit/source/controls/table/gridtablerenderer.cxx
@@ -218,7 +218,7 @@ namespace svt::table
     {
         OSL_PRECOND(_bIsColHeaderArea || _bIsRowHeaderArea, 
"GridTableRenderer::PaintHeaderArea: invalid area flags!");
 
-        rRenderContext.Push(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
+        auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
 
         Color const background = 
lcl_getEffectiveColor(m_pImpl->rModel.getHeaderBackgroundColor(),
                                                        _rStyle, 
&StyleSettings::GetDialogColor);
@@ -233,8 +233,6 @@ namespace svt::table
         rRenderContext.SetLineColor(lineColor);
         rRenderContext.DrawLine(_rArea.BottomLeft(), _rArea.BottomRight());
         rRenderContext.DrawLine(_rArea.BottomRight(), _rArea.TopRight());
-
-        rRenderContext.Pop();
     }
 
 
@@ -243,7 +241,7 @@ namespace svt::table
         vcl::RenderContext& rRenderContext,
         const tools::Rectangle& _rArea, const StyleSettings& _rStyle)
     {
-        rRenderContext.Push(vcl::PushFlags::LINECOLOR);
+        auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR);
 
         OUString sHeaderText;
         PColumnModel const pColumn = m_pImpl->rModel.getColumnModel( _nCol );
@@ -293,8 +291,6 @@ namespace svt::table
                                             aIndicatorBitmap);
             }
         }
-
-        rRenderContext.Pop();
     }
 
 
@@ -304,7 +300,7 @@ namespace svt::table
         // remember the row for subsequent calls to the other ->ITableRenderer 
methods
         m_pImpl->nCurrentRow = _nRow;
 
-        rRenderContext.Push(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
+        auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
 
         Color backgroundColor = _rStyle.GetFieldColor();
 
@@ -354,15 +350,13 @@ namespace svt::table
         rRenderContext.SetLineColor();
         rRenderContext.SetFillColor(backgroundColor);
         rRenderContext.DrawRect(_rRowArea);
-
-        rRenderContext.Pop();
     }
 
 
     void GridTableRenderer::PaintRowHeader(vcl::RenderContext& rRenderContext,
                                            const tools::Rectangle& _rArea, 
const StyleSettings& _rStyle)
     {
-        rRenderContext.Push( vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::TEXTCOLOR );
+        auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::TEXTCOLOR);
 
         std::optional<Color> const aLineColor( m_pImpl->rModel.getLineColor() 
);
         Color const lineColor = !aLineColor ? _rStyle.GetSeparatorColor() : 
*aLineColor;
@@ -384,8 +378,6 @@ namespace svt::table
                 // TODO: is using the horizontal alignment of the 0'th column 
a good idea here? This is pretty ... arbitrary ..
             rRenderContext.DrawText(aTextRect, rowTitle, nDrawTextFlags);
         }
-
-        rRenderContext.Pop();
     }
 
 
@@ -414,7 +406,7 @@ namespace svt::table
     void GridTableRenderer::PaintCell(ColPos const i_column, bool _bSelected, 
bool i_hasControlFocus,
                                       vcl::RenderContext& rRenderContext, 
const tools::Rectangle& _rArea, const StyleSettings& _rStyle)
     {
-        rRenderContext.Push(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
+        auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | 
vcl::PushFlags::FILLCOLOR);
 
         tools::Rectangle const aContentArea(lcl_getContentArea(*m_pImpl, 
_rArea));
         CellRenderContext const aCellRenderContext(rRenderContext, 
aContentArea, _rStyle, i_column, _bSelected, i_hasControlFocus);
@@ -437,8 +429,6 @@ namespace svt::table
             rRenderContext.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() 
);
             rRenderContext.DrawLine( _rArea.BottomRight(), _rArea.TopRight() );
         }
-
-        rRenderContext.Pop();
     }
 
 
diff --git a/toolkit/source/hatchwindow/ipwin.cxx 
b/toolkit/source/hatchwindow/ipwin.cxx
index 32ab1a7418b7..5e8c933b1952 100644
--- a/toolkit/source/hatchwindow/ipwin.cxx
+++ b/toolkit/source/hatchwindow/ipwin.cxx
@@ -119,7 +119,7 @@ std::array<tools::Rectangle,4> 
SvResizeHelper::FillMoveRectsPixel() const
 *************************************************************************/
 void SvResizeHelper::Draw(vcl::RenderContext& rRenderContext)
 {
-    rRenderContext.Push();
+    auto popIt = rRenderContext.ScopedPush();
     rRenderContext.SetMapMode( MapMode() );
 
     rRenderContext.SetFillColor( COL_LIGHTGRAY );
@@ -134,7 +134,6 @@ void SvResizeHelper::Draw(vcl::RenderContext& 
rRenderContext)
     std::array<tools::Rectangle,8> aRects = FillHandleRectsPixel();
     for (i = 0; i < 8; i++)
         rRenderContext.DrawRect( aRects[ i ] );
-    rRenderContext.Pop();
 }
 
 /*************************************************************************

Reply via email to