Resolves: tdf#151351 rework flat button rendering

Change-Id: Idf98c5bb96e5646e25b1ccd70b3774c7de479d18
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140979
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx
index 0edb9d9..f9d9408 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -976,6 +976,9 @@ void PushButton::ImplDrawPushButton(vcl::RenderContext& rRenderContext)
    if (mbPressed || mbIsActive)
        nButtonStyle |= DrawButtonFlags::Pressed;

    if (GetStyle() & WB_FLATBUTTON)
        nButtonStyle |= DrawButtonFlags::Flat;

    // TODO: move this to Window class or make it a member !!!
    ControlType aCtrlType = ControlType::Generic;
    switch(GetParent()->GetType())
@@ -1151,8 +1154,7 @@ void PushButton::ImplDrawPushButton(vcl::RenderContext& rRenderContext)
    if (GetStyle() & WB_FLATBUTTON)
    {
        tools::Rectangle aTempRect(aInRect);
        if (bRollOver)
            ImplDrawPushButtonFrame(rRenderContext, aTempRect, nButtonStyle);
        ImplDrawPushButtonFrame(rRenderContext, aTempRect, nButtonStyle);
        aInRect.AdjustLeft(2 );
        aInRect.AdjustTop(2 );
        aInRect.AdjustRight( -2 );
diff --git a/vcl/source/window/decoview.cxx b/vcl/source/window/decoview.cxx
index 62c60f4..d6bbd2d 100644
--- a/vcl/source/window/decoview.cxx
+++ b/vcl/source/window/decoview.cxx
@@ -23,11 +23,6 @@
#include <vcl/window.hxx>
#include <vcl/ctrl.hxx>

constexpr auto BUTTON_DRAW_FLATTEST = DrawButtonFlags::Flat |
                                 DrawButtonFlags::Pressed |
                                 DrawButtonFlags::Checked |
                                 DrawButtonFlags::Highlight;

namespace {

tools::Long AdjustRectToSquare( tools::Rectangle &rRect )
@@ -481,6 +476,9 @@ void ImplDrawButton( OutputDevice *const pDev, tools::Rectangle aFillRect,
    }
    else
    {
        const bool bFlat(nStyle & DrawButtonFlags::Flat);
        const bool bDepressed(nStyle & (DrawButtonFlags::Pressed | DrawButtonFlags::Checked));

        if ( nStyle & DrawButtonFlags::Default )
        {
            const Color aDefBtnColor = rStyleSettings.GetDarkShadowColor();
@@ -495,30 +493,28 @@ void ImplDrawButton( OutputDevice *const pDev, tools::Rectangle aFillRect,
            aFillRect.AdjustLeft( 1 );
        }

        bool bNoFace = false;
        Color aColor1;
        Color aColor2;
        if ( nStyle & (DrawButtonFlags::Pressed | DrawButtonFlags::Checked) )
        if (!bFlat)
        {
            aColor1 = rStyleSettings.GetDarkShadowColor();
            aColor2 = rStyleSettings.GetLightColor();
        }
        else
        {
            if ( nStyle & DrawButtonFlags::NoLightBorder )
                aColor1 = rStyleSettings.GetLightBorderColor();
            if (bDepressed)
            {
                aColor1 = rStyleSettings.GetDarkShadowColor();
                aColor2 = rStyleSettings.GetLightColor();
            }
            else
                aColor1 = rStyleSettings.GetLightColor();
            if ( (nStyle & BUTTON_DRAW_FLATTEST) == DrawButtonFlags::Flat )
                aColor2 = rStyleSettings.GetShadowColor();
            else
            {
                if ( nStyle & DrawButtonFlags::NoLightBorder )
                    aColor1 = rStyleSettings.GetLightBorderColor();
                else
                    aColor1 = rStyleSettings.GetLightColor();
                aColor2 = rStyleSettings.GetDarkShadowColor();
        }
            }

        ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 );
            ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 );

        if ( (nStyle & BUTTON_DRAW_FLATTEST) != DrawButtonFlags::Flat )
        {
            if ( nStyle & (DrawButtonFlags::Pressed | DrawButtonFlags::Checked) )
            if (bDepressed)
            {
                aColor1 = rStyleSettings.GetShadowColor();
                aColor2 = rStyleSettings.GetLightBorderColor();
@@ -533,11 +529,22 @@ void ImplDrawButton( OutputDevice *const pDev, tools::Rectangle aFillRect,
            }
            ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 );
        }
        else // flat buttons
        {
            // draw a border if the flat button is highlighted
            if (nStyle & DrawButtonFlags::Highlight)
            {
                aColor1 = rStyleSettings.GetShadowColor();
                ImplDraw2ColorFrame(pDev, aFillRect, aColor1, aColor1);
            }
            // fill in the button if it is pressed in
            bNoFace = !bDepressed;
        }

        pDev->SetLineColor();
        if ( nStyle & (DrawButtonFlags::Checked | DrawButtonFlags::DontKnow) )
            pDev->SetFillColor( rStyleSettings.GetCheckedColor() );
        else
        else if (!bNoFace)
            pDev->SetFillColor( rStyleSettings.GetFaceColor() );
        pDev->DrawRect( aFillRect );
    }