include/vcl/outdev.hxx          |   34 ++++++++
 include/vcl/window.hxx          |   16 ----
 sc/source/ui/view/hdrcont.cxx   |   56 +++++++-------
 vcl/source/control/imivctl1.cxx |    8 +-
 vcl/source/outdev/rect.cxx      |  156 +++++++++++++++++++++++++++++++++++++++
 vcl/source/treelist/headbar.cxx |   12 ++-
 vcl/source/window/brdwin.cxx    |    6 -
 vcl/source/window/menu.cxx      |    4 -
 vcl/source/window/paint.cxx     |  157 +---------------------------------------
 vcl/source/window/toolbox.cxx   |    7 +
 vcl/source/window/window.cxx    |  108 ---------------------------
 11 files changed, 245 insertions(+), 319 deletions(-)

New commits:
commit 506e68b3ff052c14481bdc069ed48a4c82a33631
Author:     Dan Williams <[email protected]>
AuthorDate: Tue Jan 6 16:19:39 2026 -0600
Commit:     Dan Williams <[email protected]>
CommitDate: Wed Feb 25 16:39:53 2026 +0100

    vcl: move DrawSelectionBackground into OutputDevice
    
    dfb70a8f6367 "Add DrawSelectionBackground that is outside of vcl::Window"
    implied that eventually all use of Window::DrawSelectionBackground()
    should go away in favor of RenderTools' version, but there were a couple
    instances left.
    
    There's no real point to having a completely separate namespace/class
    for DrawSelectionBackground() and since it just uses all the RenderContext
    stuff internally, and since OutputDevice == RenderContext, just make
    it a class method of OutputDevice.
    
    But given the original commit that started all this, we can't use
    any vcl::Window inside OutputDevice, so we need to pass a couple
    Window color properties into DrawSelectionBackground() to make
    things work like they did before.
    
    Change-Id: Iad61591f38c1c2e22e5611af255f03db83369af6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196642
    Tested-by: Jenkins
    Reviewed-by: Dan Williams <[email protected]>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 454292b36f6e..1e8fb5b7a1a6 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -628,6 +628,40 @@ public:
      */
     void                        DrawGridOfCrosses( const tools::Rectangle& 
rGridArea, const Size& rGridDistance, const tools::Rectangle& rDrawingArea );
 
+    /** Draw background for selected or checked items in toolboxes etc.
+
+     @param rRect                      The area to draw the selection 
background for
+     @param aWinBackgroundColor        Background color of the window that 
owns this output device
+     @param nHighlight                 Drawing modifier to change transparency 
based on item state
+     @param bChecked                   If true and nHighlight is > 0, darkens 
the drawn selection color
+     @param bDrawBorder                If true, draw the exterior border of 
the selection
+     @param bDrawExtBorderOnly         If true, only draw the exterior border 
of the selection
+     @param pWinControlForegroundColor If the window that owns this output 
device is a
+                                       control background (eg, 
IsControlBackground() returns
+                                       true) this value should be the window's 
control
+                                       foreground color
+     @param nCornerRadius              If > 0, round the corners of the drawn 
background
+                                       by the given amount
+     @param pPaintColor                If not null, use the given color as the 
selection
+                                       background color; otherwise use the 
system style highlight
+                                       color.
+
+     @returns The color to use when drawing text over the selection 
background. Only valid
+              when pWinControlForegroundColor is given.
+
+     @since LibreOffice 26.8
+    */
+    Color                       DrawSelectionBackground(
+                                    const tools::Rectangle& rRect,
+                                    Color aWinBackgroundColor,
+                                    sal_uInt16 nHighlight,
+                                    bool bChecked,
+                                    bool bDrawBorder = false,
+                                    bool bDrawExtBorderOnly = false,
+                                    Color const * pWinControlForeground = 
nullptr,
+                                    tools::Long nCornerRadius = 0,
+                                    Color const * pPaintColor = nullptr);
+
     ///@}
 
     /** @name Invert functions
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 1451d1554eb6..7a2bee572052 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -416,19 +416,6 @@ namespace o3tl {
 
 namespace vcl {
 
-class RenderTools
-{
-public:
-    // transparent background for selected or checked items in toolboxes etc.
-    // + selection Color with a text color complementing the selection 
background
-    // + rounded edge
-    static void DrawSelectionBackground(vcl::RenderContext& rRenderContext, 
vcl::Window const & rWindow,
-                                        const tools::Rectangle& rRect, 
sal_uInt16 nHighlight,
-                                        bool bChecked, bool bDrawBorder, bool 
bDrawExtBorderOnly,
-                                        Color* pSelectionTextColor = nullptr, 
tools::Long nCornerRadius = 0,
-                                        Color const * pPaintColor = nullptr);
-};
-
 class VCL_DLLPUBLIC Window : public virtual VclReferenceBase
 {
     friend class ::vcl::Cursor;
@@ -1058,9 +1045,6 @@ public:
     virtual void                        ShowFocus(const tools::Rectangle& 
rRect);
     void                                HideFocus();
 
-    // transparent background for selected or checked items in toolboxes etc.
-    void                                DrawSelectionBackground( const 
tools::Rectangle& rRect, sal_uInt16 highlight, bool bChecked, bool bDrawBorder 
);
-
     void                                ShowTracking( const tools::Rectangle& 
rRect,
                                                       ShowTrackFlags nFlags = 
ShowTrackFlags::Small );
     void                                HideTracking();
diff --git a/sc/source/ui/view/hdrcont.cxx b/sc/source/ui/view/hdrcont.cxx
index e9d9f398fbd3..47506cfa2a8d 100644
--- a/sc/source/ui/view/hdrcont.cxx
+++ b/sc/source/ui/view/hdrcont.cxx
@@ -231,12 +231,12 @@ tools::Long ScHeaderControl::GetScrPos( SCCOLROW nEntryNo 
) const
     return nScrPos;
 }
 
-void ScHeaderControl::Paint( vcl::RenderContext& /*rRenderContext*/, const 
tools::Rectangle& rRect )
+void ScHeaderControl::Paint( vcl::RenderContext& rRenderContext, const 
tools::Rectangle& rRect )
 {
     // It is important for VCL to have few calls, that is why the outer lines 
are
     // grouped together
 
-    const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+    const StyleSettings& rStyleSettings = 
rRenderContext.GetSettings().GetStyleSettings();
     bool bHighContrast = rStyleSettings.GetHighContrastMode();
     bool bDark = rStyleSettings.GetFaceColor().IsDark();
     // Use the same distinction for bDark as in Window::DrawSelectionBackground
@@ -253,9 +253,9 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
         aBoldFont.SetColor( aSelTextColor );
 
     if (bAutoFilterSet)
-        SetTextColor(aAFilterTextColor);
+        rRenderContext.SetTextColor(aAFilterTextColor);
     else
-        SetTextColor((bBoldSet && !bHighContrast) ? aSelTextColor : 
aTextColor);
+        rRenderContext.SetTextColor((bBoldSet && !bHighContrast) ? 
aSelTextColor : aTextColor);
 
     ScModule* mod = ScModule::get();
     Color aSelLineColor = 
mod->GetColorConfig().GetColorValue(svtools::CALCCELLFOCUS).nColor;
@@ -330,7 +330,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
     //  background is different for entry area and behind the entries
 
     tools::Rectangle aFillRect;
-    GetOutDev()->SetLineColor();
+    rRenderContext.SetLineColor();
 
     if ( nLineEnd * nLayoutSign >= nInitScrPos * nLayoutSign )
     {
@@ -353,23 +353,23 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
             aFaceColor.IncreaseLuminance(20);
         else
             aFaceColor.DecreaseLuminance(20);
-        GetOutDev()->SetFillColor(aFaceColor);
+        rRenderContext.SetFillColor(aFaceColor);
         if ( bVertical )
             aFillRect = tools::Rectangle( 0, nInitScrPos, nBarSize-1, nLineEnd 
);
         else
             aFillRect = tools::Rectangle( nInitScrPos, 0, nLineEnd, nBarSize-1 
);
-        GetOutDev()->DrawRect( aFillRect );
+        rRenderContext.DrawRect( aFillRect );
     }
 
     if ( nLineEnd * nLayoutSign < nPEnd * nLayoutSign )
     {
         Color aAppBackgroundColor = 
mod->GetColorConfig().GetColorValue(svtools::APPBACKGROUND).nColor;
-        GetOutDev()->SetFillColor(aAppBackgroundColor);
+        rRenderContext.SetFillColor(aAppBackgroundColor);
         if ( bVertical )
             aFillRect = tools::Rectangle( 0, nLineEnd+nLayoutSign, nBarSize-1, 
nPEnd );
         else
             aFillRect = tools::Rectangle( nLineEnd+nLayoutSign, 0, nPEnd, 
nBarSize-1 );
-        GetOutDev()->DrawRect( aFillRect );
+        rRenderContext.DrawRect( aFillRect );
     }
 
     if ( nLineEnd * nLayoutSign >= nPStart * nLayoutSign )
@@ -386,15 +386,15 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                 if ( bDark )
                 {
                     //  solid grey background for dark face color is drawn 
before lines
-                    GetOutDev()->SetLineColor();
-                    GetOutDev()->SetFillColor( COL_LIGHTGRAY );
-                    GetOutDev()->DrawRect( aFillRect );
+                    rRenderContext.SetLineColor();
+                    rRenderContext.SetFillColor( COL_LIGHTGRAY );
+                    rRenderContext.DrawRect( aFillRect );
                 }
             }
             else
             {
                 // background for selection
-                GetOutDev()->SetLineColor();
+                rRenderContext.SetLineColor();
                 Color aColor = 
mod->GetColorConfig().GetColorValue(svtools::CALCCELLFOCUS).nColor;
 // merging the highlightcolor (which is used if accent does not exist) with 
the background
 // fails in many cases such as Breeze Dark (highlight is too close to 
background) and
@@ -402,21 +402,21 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
 #ifdef MACOSX
                 aColor.Merge( rStyleSettings.GetFaceColor(), 80 );
 #endif
-                GetOutDev()->SetFillColor( aColor );
-                GetOutDev()->DrawRect( aFillRect );
+                rRenderContext.SetFillColor( aColor );
+                rRenderContext.DrawRect( aFillRect );
             }
         }
 
-        GetOutDev()->SetLineColor( rStyleSettings.GetShadowColor() );
+        rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
         if (bVertical)
         {
-            GetOutDev()->DrawLine( Point( 0, nPStart ), Point( 0, nLineEnd ) 
); //left
-            GetOutDev()->DrawLine( Point( nBarSize-1, nPStart ), Point( 
nBarSize-1, nLineEnd ) ); //right
+            rRenderContext.DrawLine( Point( 0, nPStart ), Point( 0, nLineEnd ) 
); //left
+            rRenderContext.DrawLine( Point( nBarSize-1, nPStart ), Point( 
nBarSize-1, nLineEnd ) ); //right
         }
         else
         {
-            GetOutDev()->DrawLine( Point( nPStart, nBarSize-1 ), Point( 
nLineEnd, nBarSize-1 ) ); //bottom
-            GetOutDev()->DrawLine( Point( nPStart, 0 ), Point( nLineEnd, 0 ) 
); //top
+            rRenderContext.DrawLine( Point( nPStart, nBarSize-1 ), Point( 
nLineEnd, nBarSize-1 ) ); //bottom
+            rRenderContext.DrawLine( Point( nPStart, 0 ), Point( nLineEnd, 0 ) 
); //top
         }
     }
 
@@ -483,10 +483,10 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
         {
             case HeaderPaintPass::SelectionBottom:
                 // same as non-selected for high contrast
-                GetOutDev()->SetLineColor( bHighContrast ? 
rStyleSettings.GetShadowColor() : aSelLineColor );
+                rRenderContext.SetLineColor( bHighContrast ? 
rStyleSettings.GetShadowColor() : aSelLineColor );
                 break;
             case HeaderPaintPass::Bottom:
-                GetOutDev()->SetLineColor( rStyleSettings.GetShadowColor() );
+                rRenderContext.SetLineColor( rStyleSettings.GetShadowColor() );
                 break;
             case HeaderPaintPass::Text:
                 // DrawSelectionBackground is used only for high contrast on 
light background
@@ -505,9 +505,9 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                         aTransRect = tools::Rectangle( 0, nTransStart, 
nBarSize-1, nTransEnd );
                     else
                         aTransRect = tools::Rectangle( nTransStart, 0, 
nTransEnd, nBarSize-1 );
-                    SetBackground( rStyleSettings.GetFaceColor() );
-                    DrawSelectionBackground( aTransRect, 0, true, false );
-                    SetBackground();
+                    rRenderContext.SetBackground( 
rStyleSettings.GetFaceColor() );
+                    rRenderContext.DrawSelectionBackground(aTransRect, 
GetBackgroundColor(), 0, true);
+                    rRenderContext.SetBackground();
                 }
                 break;
         }
@@ -563,10 +563,10 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                                     if ( GetEntrySize(nEntryNo+1)==0 )
                                     {
                                         if (bVertical)
-                                            GetOutDev()->DrawLine( 
Point(aScrPos.X(),aEndPos.Y()-nLayoutSign),
+                                            rRenderContext.DrawLine( 
Point(aScrPos.X(),aEndPos.Y()-nLayoutSign),
                                                       
Point(aEndPos.X(),aEndPos.Y()-nLayoutSign) );
                                         else
-                                            GetOutDev()->DrawLine( 
Point(aEndPos.X()-nLayoutSign,aScrPos.Y()),
+                                            rRenderContext.DrawLine( 
Point(aEndPos.X()-nLayoutSign,aScrPos.Y()),
                                                       
Point(aEndPos.X()-nLayoutSign,aEndPos.Y()) );
                                     }
                             }
@@ -634,7 +634,7 @@ void ScHeaderControl::Paint( vcl::RenderContext& 
/*rRenderContext*/, const tools
                                 else
                                     aRect = tools::Rectangle(aScrPos.X(), 
aScrPos.Y(), aEndPos.X(),
                                                              aEndPos.Y());
-                                GetOutDev()->DrawText(aRect, aString, 
nDrawTextStyle);
+                                rRenderContext.DrawText(aRect, aString, 
nDrawTextStyle);
                             }
                             break;
                     }
diff --git a/vcl/source/control/imivctl1.cxx b/vcl/source/control/imivctl1.cxx
index f9fcfaa28929..9eeabe2ad8b1 100644
--- a/vcl/source/control/imivctl1.cxx
+++ b/vcl/source/control/imivctl1.cxx
@@ -1085,10 +1085,10 @@ void 
SvxIconChoiceCtrl_Impl::PaintEntry(SvxIconChoiceCtrlEntry* pEntry, const Po
 
     if (!bNativeOK)
     {
-        if (bSelected)
-            vcl::RenderTools::DrawSelectionBackground(
-                rRenderContext, *pView, aFocusRect, pView->HasFocus() ? 1 : 2, 
false, false, false);
-        else
+        if (bSelected) {
+            rRenderContext.DrawSelectionBackground(aFocusRect, 
pView->GetBackgroundColor(),
+                                                    pView->HasFocus() ? 1 : 2, 
false);
+        } else
             PaintEmphasis(aTextRect, rRenderContext);
 
         if (pEntry->IsFocused())
diff --git a/vcl/source/outdev/rect.cxx b/vcl/source/outdev/rect.cxx
index 15ca8e40e9f3..0461a8a548c1 100644
--- a/vcl/source/outdev/rect.cxx
+++ b/vcl/source/outdev/rect.cxx
@@ -542,4 +542,160 @@ void AdjustTwoRect( SalTwoRect& rTwoRect, const 
tools::Rectangle& rValidSrcRect
     }
 }
 
+Color OutputDevice::DrawSelectionBackground(const tools::Rectangle& rRect,
+                                            Color aWinBackgroundColor,
+                                            sal_uInt16 nHighlight,
+                                            bool bChecked,
+                                            bool bDrawBorder,
+                                            bool bDrawExtBorderOnly,
+                                            Color const * 
pWinControlForeground,
+                                            tools::Long nCornerRadius,
+                                            Color const * pPaintColor)
+{
+    if (rRect.IsEmpty())
+        return COL_TRANSPARENT;
+
+    bool bRoundEdges = nCornerRadius > 0;
+
+    const StyleSettings& rStyles = GetSettings().GetStyleSettings();
+
+    // colors used for item highlighting
+    Color aSelectionBorderColor(pPaintColor ? *pPaintColor : 
rStyles.GetHighlightColor());
+    Color aSelectionFillColor(aSelectionBorderColor);
+
+    bool bDark = rStyles.GetFaceColor().IsDark();
+    bool bBright = ( rStyles.GetFaceColor() == COL_WHITE );
+
+    int c1 = aSelectionBorderColor.GetLuminance();
+    int c2 = aWinBackgroundColor.GetLuminance();
+
+    if (!bDark && !bBright && std::abs(c2 - c1) < (pPaintColor ? 40 : 75))
+    {
+        // contrast too low
+        sal_uInt16 h, s, b;
+        aSelectionFillColor.RGBtoHSB( h, s, b );
+        if( b > 50 )    b -= 40;
+        else            b += 40;
+        aSelectionFillColor = Color::HSBtoRGB( h, s, b );
+        aSelectionBorderColor = aSelectionFillColor;
+    }
+
+    if (bRoundEdges)
+    {
+        if (aSelectionBorderColor.IsDark())
+            aSelectionBorderColor.IncreaseLuminance(128);
+        else
+            aSelectionBorderColor.DecreaseLuminance(128);
+    }
+
+    tools::Rectangle aRect(rRect);
+    if (bDrawExtBorderOnly)
+    {
+        aRect.AdjustLeft( -1 );
+        aRect.AdjustTop( -1 );
+        aRect.AdjustRight(1 );
+        aRect.AdjustBottom(1 );
+    }
+    auto popIt = ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
+
+    if (bDrawBorder)
+        SetLineColor(bDark ? COL_WHITE : (bBright ? COL_BLACK : 
aSelectionBorderColor));
+    else
+        SetLineColor();
+
+    sal_uInt16 nPercent = 0;
+    if (!nHighlight)
+    {
+        if (bDark)
+            aSelectionFillColor = COL_BLACK;
+        else
+            nPercent = 80;  // just checked (light)
+    }
+    else
+    {
+        if (bChecked && nHighlight == 2)
+        {
+            if (bDark)
+                aSelectionFillColor = COL_LIGHTGRAY;
+            else if (bBright)
+            {
+                aSelectionFillColor = COL_BLACK;
+                SetLineColor(COL_BLACK);
+                nPercent = 0;
+            }
+            else
+                nPercent = bRoundEdges ? 40 : 20; // selected, pressed or 
checked ( very dark )
+        }
+        else if (bChecked || nHighlight == 1)
+        {
+            if (bDark)
+                aSelectionFillColor = COL_GRAY;
+            else if (bBright)
+            {
+                aSelectionFillColor = COL_BLACK;
+                SetLineColor(COL_BLACK);
+                nPercent = 0;
+            }
+            else
+                nPercent = bRoundEdges ? 60 : 35; // selected, pressed or 
checked ( very dark )
+        }
+        else
+        {
+            if (bDark)
+                aSelectionFillColor = COL_LIGHTGRAY;
+            else if (bBright)
+            {
+                aSelectionFillColor = COL_BLACK;
+                SetLineColor(COL_BLACK);
+                if (nHighlight == 3)
+                    nPercent = 80;
+                else
+                    nPercent = 0;
+            }
+            else
+                nPercent = 70; // selected ( dark )
+        }
+    }
+
+    Color aSelectionTextColor;
+
+    if (bDark && bDrawExtBorderOnly)
+    {
+        SetFillColor();
+        aSelectionTextColor = rStyles.GetHighlightTextColor();
+    }
+    else
+    {
+        SetFillColor(aSelectionFillColor);
+
+        Color aTextColor = pWinControlForeground ? *pWinControlForeground : 
rStyles.GetButtonTextColor();
+        Color aHLTextColor = rStyles.GetHighlightTextColor();
+        int nTextDiff = std::abs(aSelectionFillColor.GetLuminance() - 
aTextColor.GetLuminance());
+        int nHLDiff = std::abs(aSelectionFillColor.GetLuminance() - 
aHLTextColor.GetLuminance());
+        aSelectionTextColor = (nHLDiff >= nTextDiff) ? aHLTextColor : 
aTextColor;
+    }
+
+    if (bDark)
+    {
+        DrawRect(aRect);
+    }
+    else
+    {
+        if (bRoundEdges)
+        {
+            tools::Polygon aPoly(aRect, nCornerRadius, nCornerRadius);
+            tools::PolyPolygon aPolyPoly(aPoly);
+            DrawTransparent(aPolyPoly, nPercent);
+        }
+        else
+        {
+            tools::Polygon aPoly(aRect);
+            tools::PolyPolygon aPolyPoly(aPoly);
+            DrawTransparent(aPolyPoly, nPercent);
+        }
+    }
+
+    return aSelectionTextColor;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/treelist/headbar.cxx b/vcl/source/treelist/headbar.cxx
index eed3867e55f6..9bb3c001da41 100644
--- a/vcl/source/treelist/headbar.cxx
+++ b/vcl/source/treelist/headbar.cxx
@@ -341,10 +341,14 @@ void HeaderBar::ImplDrawItem(vcl::RenderContext& 
rRenderContext, sal_uInt16 nPos
 
         // draw ButtonStyle
         // avoid 3D borders
-        if (bHigh)
-            vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, 
aRect, 1, true, false, false, &aSelectionTextColor);
-        else if (!mbButtonStyle || (nBits & HeaderBarItemBits::FLAT))
-            vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, 
aRect, 0, true, false, false, &aSelectionTextColor);
+        Color const *aWinControlForeground = IsControlBackground() ? 
&GetControlForeground() : nullptr;
+        if (bHigh) {
+            aSelectionTextColor = 
rRenderContext.DrawSelectionBackground(aRect, GetBackgroundColor(),
+                                                    1, true, false, false, 
aWinControlForeground);
+        } else if (!mbButtonStyle || (nBits & HeaderBarItemBits::FLAT)) {
+            aSelectionTextColor = 
rRenderContext.DrawSelectionBackground(aRect, GetBackgroundColor(),
+                                                    0, true, false, false, 
aWinControlForeground);
+        }
     }
 
     // do not draw if there is no space
diff --git a/vcl/source/window/brdwin.cxx b/vcl/source/window/brdwin.cxx
index e13ba5feb04c..a72ad8ea925b 100644
--- a/vcl/source/window/brdwin.cxx
+++ b/vcl/source/window/brdwin.cxx
@@ -92,9 +92,9 @@ static void ImplDrawBrdWinSymbolButton( vcl::RenderContext& 
rRenderContext,
             rRenderContext.SetFillColor( 
rRenderContext.GetSettings().GetStyleSettings().GetWindowColor() );
             rRenderContext.SetLineColor();
             rRenderContext.DrawRect( rRect );
-            vcl::RenderTools::DrawSelectionBackground(rRenderContext, *pWin, 
rRect, 2,
-                                                      bool(nState & 
DrawButtonFlags::Pressed),
-                                                      true, false );
+            rRenderContext.DrawSelectionBackground(rRect, 
pWin->GetBackgroundColor(), 2,
+                                                   bool(nState & 
DrawButtonFlags::Pressed),
+                                                   true);
         }
         aTempRect = rRect;
         aTempRect.AdjustLeft( 3 );
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 8a30f278f6a2..9302da36c5fc 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -1652,6 +1652,7 @@ Size Menu::ImplCalcSize( vcl::Window* pWin )
 static void ImplPaintCheckBackground(vcl::RenderContext & rRenderContext, 
vcl::Window const & rWindow, const tools::Rectangle& i_rRect, bool i_bHighlight)
 {
     bool bNativeOk = false;
+
     if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, 
ControlPart::Button))
     {
         ImplControlValue    aControlValue;
@@ -1670,7 +1671,8 @@ static void ImplPaintCheckBackground(vcl::RenderContext & 
rRenderContext, vcl::W
     {
         const StyleSettings& rSettings = 
rRenderContext.GetSettings().GetStyleSettings();
         Color aColor( i_bHighlight ? rSettings.GetMenuHighlightTextColor() : 
rSettings.GetHighlightColor() );
-        RenderTools::DrawSelectionBackground(rRenderContext, rWindow, i_rRect, 
0, i_bHighlight, true, false, nullptr, 2, &aColor);
+        rRenderContext.DrawSelectionBackground(i_rRect, 
rWindow.GetBackgroundColor(), 0,
+                                               i_bHighlight, true, false, 
nullptr, 2, &aColor);
     }
 }
 
diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx
index 676b6af3902a..beabf7e16a81 100644
--- a/vcl/source/window/paint.cxx
+++ b/vcl/source/window/paint.cxx
@@ -325,156 +325,6 @@ void PaintHelper::DoPaint(const vcl::Region* pRegion)
 namespace vcl
 {
 
-void RenderTools::DrawSelectionBackground(vcl::RenderContext& rRenderContext, 
vcl::Window const & rWindow,
-                                          const tools::Rectangle& rRect, 
sal_uInt16 nHighlight,
-                                          bool bChecked, bool bDrawBorder, 
bool bDrawExtBorderOnly,
-                                          Color* pSelectionTextColor, 
tools::Long nCornerRadius, Color const * pPaintColor)
-{
-    if (rRect.IsEmpty())
-        return;
-
-    bool bRoundEdges = nCornerRadius > 0;
-
-    const StyleSettings& rStyles = 
rRenderContext.GetSettings().GetStyleSettings();
-
-    // colors used for item highlighting
-    Color aSelectionBorderColor(pPaintColor ? *pPaintColor : 
rStyles.GetHighlightColor());
-    Color aSelectionFillColor(aSelectionBorderColor);
-
-    bool bDark = rStyles.GetFaceColor().IsDark();
-    bool bBright = ( rStyles.GetFaceColor() == COL_WHITE );
-
-    int c1 = aSelectionBorderColor.GetLuminance();
-    int c2 = rWindow.GetBackgroundColor().GetLuminance();
-
-    if (!bDark && !bBright && std::abs(c2 - c1) < (pPaintColor ? 40 : 75))
-    {
-        // contrast too low
-        sal_uInt16 h, s, b;
-        aSelectionFillColor.RGBtoHSB( h, s, b );
-        if( b > 50 )    b -= 40;
-        else            b += 40;
-        aSelectionFillColor = Color::HSBtoRGB( h, s, b );
-        aSelectionBorderColor = aSelectionFillColor;
-    }
-
-    if (bRoundEdges)
-    {
-        if (aSelectionBorderColor.IsDark())
-            aSelectionBorderColor.IncreaseLuminance(128);
-        else
-            aSelectionBorderColor.DecreaseLuminance(128);
-    }
-
-    tools::Rectangle aRect(rRect);
-    if (bDrawExtBorderOnly)
-    {
-        aRect.AdjustLeft( -1 );
-        aRect.AdjustTop( -1 );
-        aRect.AdjustRight(1 );
-        aRect.AdjustBottom(1 );
-    }
-    auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
-
-    if (bDrawBorder)
-        rRenderContext.SetLineColor(bDark ? COL_WHITE : (bBright ? COL_BLACK : 
aSelectionBorderColor));
-    else
-        rRenderContext.SetLineColor();
-
-    sal_uInt16 nPercent = 0;
-    if (!nHighlight)
-    {
-        if (bDark)
-            aSelectionFillColor = COL_BLACK;
-        else
-            nPercent = 80;  // just checked (light)
-    }
-    else
-    {
-        if (bChecked && nHighlight == 2)
-        {
-            if (bDark)
-                aSelectionFillColor = COL_LIGHTGRAY;
-            else if (bBright)
-            {
-                aSelectionFillColor = COL_BLACK;
-                rRenderContext.SetLineColor(COL_BLACK);
-                nPercent = 0;
-            }
-            else
-                nPercent = bRoundEdges ? 40 : 20; // selected, pressed or 
checked ( very dark )
-        }
-        else if (bChecked || nHighlight == 1)
-        {
-            if (bDark)
-                aSelectionFillColor = COL_GRAY;
-            else if (bBright)
-            {
-                aSelectionFillColor = COL_BLACK;
-                rRenderContext.SetLineColor(COL_BLACK);
-                nPercent = 0;
-            }
-            else
-                nPercent = bRoundEdges ? 60 : 35; // selected, pressed or 
checked ( very dark )
-        }
-        else
-        {
-            if (bDark)
-                aSelectionFillColor = COL_LIGHTGRAY;
-            else if (bBright)
-            {
-                aSelectionFillColor = COL_BLACK;
-                rRenderContext.SetLineColor(COL_BLACK);
-                if (nHighlight == 3)
-                    nPercent = 80;
-                else
-                    nPercent = 0;
-            }
-            else
-                nPercent = 70; // selected ( dark )
-        }
-    }
-
-    if (bDark && bDrawExtBorderOnly)
-    {
-        rRenderContext.SetFillColor();
-        if (pSelectionTextColor)
-            *pSelectionTextColor = rStyles.GetHighlightTextColor();
-    }
-    else
-    {
-        rRenderContext.SetFillColor(aSelectionFillColor);
-        if (pSelectionTextColor)
-        {
-            Color aTextColor = rWindow.IsControlBackground() ? 
rWindow.GetControlForeground() : rStyles.GetButtonTextColor();
-            Color aHLTextColor = rStyles.GetHighlightTextColor();
-            int nTextDiff = std::abs(aSelectionFillColor.GetLuminance() - 
aTextColor.GetLuminance());
-            int nHLDiff = std::abs(aSelectionFillColor.GetLuminance() - 
aHLTextColor.GetLuminance());
-            *pSelectionTextColor = (nHLDiff >= nTextDiff) ? aHLTextColor : 
aTextColor;
-        }
-    }
-
-    if (bDark)
-    {
-        rRenderContext.DrawRect(aRect);
-    }
-    else
-    {
-        if (bRoundEdges)
-        {
-            tools::Polygon aPoly(aRect, nCornerRadius, nCornerRadius);
-            tools::PolyPolygon aPolyPoly(aPoly);
-            rRenderContext.DrawTransparent(aPolyPoly, nPercent);
-        }
-        else
-        {
-            tools::Polygon aPoly(aRect);
-            tools::PolyPolygon aPolyPoly(aPoly);
-            rRenderContext.DrawTransparent(aPolyPoly, nPercent);
-        }
-    }
-}
-
 void Window::PushPaintHelper(PaintHelper *pHelper, vcl::RenderContext& 
rRenderContext)
 {
     pHelper->SetPop();
@@ -572,8 +422,11 @@ PaintHelper::~PaintHelper()
     }
 
     // #98943# draw toolbox selection
-    if( !m_aSelectionRect.IsEmpty() )
-        m_pWindow->DrawSelectionBackground( m_aSelectionRect, 3, false, true );
+    if( !m_aSelectionRect.IsEmpty() ) {
+        m_pWindow->GetOutDev()->DrawSelectionBackground( m_aSelectionRect,
+                                                         
m_pWindow->GetBackgroundColor(),
+                                                         3, false, true);
+    }
 }
 
 namespace vcl {
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index 2d1caa8cbaa8..519599eaec5d 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -2521,9 +2521,10 @@ void ToolBox::ImplDrawButton(vcl::RenderContext& 
rRenderContext, const tools::Re
                                               rRect, nState, aControlValue, 
OUString() );
     }
 
-    if (!bNativeOk)
-        vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, 
rRect, bIsWindow ? 3 : highlight,
-                                                  bChecked, true, bIsWindow, 
nullptr, 2);
+    if (!bNativeOk) {
+        rRenderContext.DrawSelectionBackground(rRect, GetBackgroundColor(), 
bIsWindow ? 3 : highlight,
+                                               bChecked, true, bIsWindow, 
nullptr, 2);
+    }
 }
 
 void ToolBox::ImplDrawItem(vcl::RenderContext& rRenderContext, 
ImplToolItems::size_type nPos, sal_uInt16 nHighlight)
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 9fddc0b91daa..cfc2674d1e21 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -3483,114 +3483,6 @@ void Window::RecordLayoutData( vcl::ControlLayoutData* 
pLayout, const tools::Rec
     GetOutDev()->mpOutDevData->mpRecordLayout = nullptr;
 }
 
-void Window::DrawSelectionBackground( const tools::Rectangle& rRect,
-                                      sal_uInt16 highlight,
-                                      bool bChecked,
-                                      bool bDrawBorder
-                                      )
-{
-    if( rRect.IsEmpty() )
-        return;
-
-    const StyleSettings& rStyles = GetSettings().GetStyleSettings();
-
-    // colors used for item highlighting
-    Color aSelectionBorderCol( rStyles.GetHighlightColor() );
-    Color aSelectionFillCol( aSelectionBorderCol );
-
-    bool bDark = rStyles.GetFaceColor().IsDark();
-    bool bBright = ( rStyles.GetFaceColor() == COL_WHITE );
-
-    int c1 = aSelectionBorderCol.GetLuminance();
-    int c2 = GetBackgroundColor().GetLuminance();
-
-    if( !bDark && !bBright && abs( c2-c1 ) < 75 )
-    {
-        // contrast too low
-        sal_uInt16 h,s,b;
-        aSelectionFillCol.RGBtoHSB( h, s, b );
-        if( b > 50 )    b -= 40;
-        else            b += 40;
-        aSelectionFillCol = Color::HSBtoRGB( h, s, b );
-        aSelectionBorderCol = aSelectionFillCol;
-    }
-
-    tools::Rectangle aRect( rRect );
-    auto popIt = GetOutDev()->ScopedPush(vcl::PushFlags::FILLCOLOR | 
vcl::PushFlags::LINECOLOR);
-
-    if( bDrawBorder )
-        GetOutDev()->SetLineColor( bDark ? COL_WHITE : ( bBright ? COL_BLACK : 
aSelectionBorderCol ) );
-    else
-        GetOutDev()->SetLineColor();
-
-    sal_uInt16 nPercent = 0;
-    if( !highlight )
-    {
-        if( bDark )
-            aSelectionFillCol = COL_BLACK;
-        else
-            nPercent = 80;  // just checked (light)
-    }
-    else
-    {
-        if( bChecked && highlight == 2 )
-        {
-            if( bDark )
-                aSelectionFillCol = COL_LIGHTGRAY;
-            else if ( bBright )
-            {
-                aSelectionFillCol = COL_BLACK;
-                GetOutDev()->SetLineColor( COL_BLACK );
-                nPercent = 0;
-            }
-            else
-                nPercent = 20;          // selected, pressed or checked ( very 
dark )
-        }
-        else if( bChecked || highlight == 1 )
-        {
-            if( bDark )
-                aSelectionFillCol = COL_GRAY;
-            else if ( bBright )
-            {
-                aSelectionFillCol = COL_BLACK;
-                GetOutDev()->SetLineColor( COL_BLACK );
-                nPercent = 0;
-            }
-            else
-                nPercent = 35;          // selected, pressed or checked ( very 
dark )
-        }
-        else
-        {
-            if( bDark )
-                aSelectionFillCol = COL_LIGHTGRAY;
-            else if ( bBright )
-            {
-                aSelectionFillCol = COL_BLACK;
-                GetOutDev()->SetLineColor( COL_BLACK );
-                if( highlight == 3 )
-                    nPercent = 80;
-                else
-                    nPercent = 0;
-            }
-            else
-                nPercent = 70;          // selected ( dark )
-        }
-    }
-
-    GetOutDev()->SetFillColor( aSelectionFillCol );
-
-    if( bDark )
-    {
-        GetOutDev()->DrawRect( aRect );
-    }
-    else
-    {
-        tools::Polygon aPoly( aRect );
-        tools::PolyPolygon aPolyPoly( aPoly );
-        GetOutDev()->DrawTransparent( aPolyPoly, nPercent );
-    }
-}
-
 bool Window::IsScrollable() const
 {
     // check for scrollbars

Reply via email to