summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-10-21 14:43:13 +0200
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2024-10-22 20:21:08 +0200
commit42c7e6848f61438f747c9509f17bef2dca29d937 (patch)
treebf35b5b2286013e0e084067c1883244e5714bd94 /vcl
parentc0d114ab2460a925acf256c27d88aadffc61a571 (diff)
tdf#152534 Win 11 Dark: Draw toolbar button bg + frame manually
When using the dark theme on Windows 11, the background color for toolbar buttons is light blue as with the light theme, which results in insufficient contrast. According to the comments in tdf#152534, this is is a in the Windows dark theme which can also be seen in other apps or has been worked around there, like in Notepad++ [1]. Work around the issue by not letting the theme draw the background (using Win API function `DrawThemeBackground`) when on Windows 11 and using dark theme, but manually draw the background and a frame instead for now. For the background color, use a color that's a bit lighter than the background color for non-highlighted items. [1] https://github.com/notepad-plus-plus/notepad-plus-plus/commit/5d086f93a80d275fcc5e4047ae49c614680a7e5b Change-Id: Ie35937fde2e8c7078c4979a2ef60c28fc4679574 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175334 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins (cherry picked from commit 620b293808f6111556c31674437917e70b106e9e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175396 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/win/gdi/salnativewidgets-luna.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/vcl/win/gdi/salnativewidgets-luna.cxx b/vcl/win/gdi/salnativewidgets-luna.cxx
index 318009acadae..4daad8eadc9b 100644
--- a/vcl/win/gdi/salnativewidgets-luna.cxx
+++ b/vcl/win/gdi/salnativewidgets-luna.cxx
@@ -39,6 +39,7 @@
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
+#include <salinst.hxx>
#include <toolbarvalue.hxx>
#include <menubarvalue.hxx>
@@ -909,6 +910,28 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc,
iState = bChecked ? TS_HOTCHECKED : TS_HOT;
else
iState = bChecked ? TS_CHECKED : TS_NORMAL;
+
+ if (bUseDarkMode && GetSalInstance()->getOSVersion().startsWith(u"Windows 11")
+ && (bChecked
+ || (nState & (ControlState::PRESSED) || (nState & ControlState::ROLLOVER))))
+ {
+ // tdf#152534 workaround bug with Windows 11 Dark theme using
+ // light blue as highlight color which gives insufficient
+ // contrast for hovered-over or pressed/checked toolbar buttons:
+ // manually draw background (using color a bit lighter than background
+ // for non-highlighted items) and draw a frame around it
+ ScopedHBRUSH aBgColorBrush(CreateSolidBrush(RGB(38, 38, 38)));
+ FillRect(hDC, &rc, aBgColorBrush.get());
+ const Color aFrameColor = Application::GetSettings().GetStyleSettings().GetDisableColor();
+ ScopedHBRUSH aFrameBrush(CreateSolidBrush(
+ RGB(aFrameColor.GetRed(), aFrameColor.GetGreen(), aFrameColor.GetBlue())));
+ FrameRect(hDC, &rc, aFrameBrush.get());
+
+ DrawThemeText(hTheme, hDC, iPart, iState, o3tl::toW(aCaption.getStr()), -1,
+ DT_CENTER | DT_VCENTER | DT_SINGLELINE, 0, &rc);
+ return true;
+ }
+
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
else if( nPart == ControlPart::ThumbHorz || nPart == ControlPart::ThumbVert )