vcl/win/gdi/salnativewidgets-luna.cxx |  291 ++++++++++++++++++++++++++++++++--
 vcl/win/window/salframe.cxx           |   86 +++++++++-
 2 files changed, 359 insertions(+), 18 deletions(-)

New commits:
commit 608deaf49c585e8b34e9d53e4e3f175fbfdf3201
Author:     Sahil Gautam <[email protected]>
AuthorDate: Sun Nov 24 01:45:01 2024 +0530
Commit:     Sahil Gautam <[email protected]>
CommitDate: Tue Nov 26 10:03:15 2024 +0100

    Libreoffice Theme Part 4: Windows Color Customization
    
    I couldn't find any way of putting the colors from the theme back
    into the system using the win32 api. Taking inspiration from Caolan's
    dark mode patch (commit: a3f400886768bf95fbd8e6b236e11d7aac393b96,
    related: tdf#118320 enable some windows dark theme support, 2022-03-17),
    I was able to make it work.
    
    I am working on vcl welding for windows, for which I am learning win32.
    In the coming weeks/months the themeing approach for windows
    is expected evolve because of that. There are some "rough edges" still...
    something to be addressed later in different tickets.
    
    Change-Id: I4b4cb3804b9b7a9d15e75a1b2511cdedda2b5b12
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170840
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-by: Sahil Gautam <[email protected]>

diff --git a/vcl/win/gdi/salnativewidgets-luna.cxx 
b/vcl/win/gdi/salnativewidgets-luna.cxx
index 53f835fbdd8a..02248127ed09 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 <vcl/themecolors.hxx>
 #include <salinst.hxx>
 #include <toolbarvalue.hxx>
 #include <menubarvalue.hxx>
@@ -434,6 +435,211 @@ bool UseDarkMode()
     return bRet;
 }
 
+static bool drawThemedControl(HDC hDC, ControlType nType, int iPart, int 
iState, RECT rc)
+{
+    if (nType == ControlType::Scrollbar)
+    {
+        if (iPart == SBP_ARROWBTN)
+        {
+            const Color& rBackColor = 
ThemeColors::GetThemeColors().GetWindowColor();
+            const Color& rArrowFillColor = 
ThemeColors::GetThemeColors().GetBaseColor();
+
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(rBackColor.GetRed(),
+                                                     rBackColor.GetGreen(),
+                                                     rBackColor.GetBlue())));
+            FillRect(hDC, &rc, hbrush.get());
+
+            bool bDrawArrow = false;
+            POINT aArrowPoints[3];
+
+            if (iState == ABS_UPHOT || iState == ABS_UPPRESSED)
+            {
+                aArrowPoints[0] = { rc.left + (rc.right - rc.left) / 4, 
rc.bottom - (rc.bottom - rc.top) / 4 };
+                aArrowPoints[1] = { rc.right - (rc.right - rc.left) / 4, 
rc.bottom - (rc.bottom - rc.top) / 4 };
+                aArrowPoints[2] = { rc.left + (rc.right - rc.left) / 2, rc.top 
+ (rc.bottom - rc.top) / 4 };
+                bDrawArrow = true;
+            }
+            else if (iState == ABS_DOWNHOT || iState == ABS_DOWNPRESSED)
+            {
+                aArrowPoints[0] = { rc.left + (rc.right - rc.left) / 4, rc.top 
+ (rc.bottom - rc.top) / 4 };
+                aArrowPoints[1] = { rc.right - (rc.right - rc.left) / 4, 
rc.top + (rc.bottom - rc.top) / 4 };
+                aArrowPoints[2] = { rc.left + (rc.right - rc.left) / 2, 
rc.bottom - (rc.bottom - rc.top) / 4 };
+                bDrawArrow = true;
+            }
+            else if (iState == ABS_RIGHTHOT || iState == ABS_RIGHTPRESSED)
+            {
+                aArrowPoints[0] = { rc.left + (rc.right - rc.left) / 4, rc.top 
+ (rc.bottom - rc.top) / 4 };
+                aArrowPoints[1] = { rc.right - (rc.right - rc.left) / 4, 
rc.top + (rc.bottom - rc.top) / 2 };
+                aArrowPoints[2] = { rc.left + (rc.right - rc.left) / 4, 
rc.bottom - (rc.bottom - rc.top) / 4 };
+                bDrawArrow = true;
+            }
+            else if (iState == ABS_LEFTHOT || iState == ABS_LEFTPRESSED)
+            {
+                aArrowPoints[0] = { rc.right - (rc.right - rc.left) / 4, 
rc.top + (rc.bottom - rc.top) / 4 };
+                aArrowPoints[1] = { rc.right - (rc.right - rc.left) / 4, 
rc.bottom - (rc.bottom - rc.top) / 4 };
+                aArrowPoints[2] = { rc.left + (rc.right - rc.left) / 4, rc.top 
+ (rc.bottom - rc.top) / 2 };
+                bDrawArrow = true;
+            }
+
+            if (bDrawArrow)
+            {
+                ScopedHPEN hpen(CreatePen(PS_SOLID, 1, RGB(0, 0, 0)));
+                ScopedHBRUSH 
hbrushArrow(CreateSolidBrush(RGB(rArrowFillColor.GetRed(),
+                                                              
rArrowFillColor.GetGreen(),
+                                                              
rArrowFillColor.GetBlue())));
+                SelectObject(hDC, hpen.get());
+                SelectObject(hDC, hbrushArrow.get());
+                Polygon(hDC, aArrowPoints, ARRAYSIZE(aArrowPoints));
+            }
+            return true;
+        }
+        else if (iPart == SBP_THUMBBTNHORZ || iPart == SBP_THUMBBTNVERT)
+        {
+            Color aScrollBarThumbColor = 
ThemeColors::GetThemeColors().GetBaseColor();
+            const Color& rBackgroundColor = 
ThemeColors::GetThemeColors().GetWindowColor();
+
+            if (iState == SCRBS_PRESSED)
+                aScrollBarThumbColor.IncreaseLuminance(60);
+            else if (iState = SCRBS_HOT)
+                aScrollBarThumbColor.IncreaseLuminance(30);
+
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(rBackgroundColor.GetRed(),
+                                                     
rBackgroundColor.GetGreen(),
+                                                     
rBackgroundColor.GetBlue())));
+            FillRect(hDC, &rc, hbrush.get());
+
+            RECT thumb = rc;
+            if (iPart == SBP_THUMBBTNHORZ)
+            {
+                thumb.top += 3;
+                thumb.bottom -= 3;
+            }
+            else
+            {
+                thumb.left += 3;
+                thumb.right -= 3;
+            }
+
+            hbrush = 
ScopedHBRUSH(CreateSolidBrush(RGB(aScrollBarThumbColor.GetRed(),
+                                                       
aScrollBarThumbColor.GetGreen(),
+                                                       
aScrollBarThumbColor.GetBlue())));
+            FillRect(hDC, &thumb, hbrush.get());
+            return true;
+        }
+        else if (iPart == SBP_UPPERTRACKHORZ || iPart == SBP_LOWERTRACKHORZ
+                || iPart == SBP_UPPERTRACKVERT || iPart == SBP_LOWERTRACKVERT)
+        {
+            const Color& rWindowColor = 
ThemeColors::GetThemeColors().GetWindowColor();
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(rWindowColor.GetRed(),
+                                                     rWindowColor.GetGreen(),
+                                                     rWindowColor.GetBlue())));
+            FillRect(hDC, &rc, hbrush.get());
+            FrameRect(hDC, &rc, hbrush.get());
+            return true;
+        }
+    }
+    else if (nType == ControlType::Pushbutton)
+    {
+        if (iPart == BP_PUSHBUTTON)
+        {
+            Color aButtonColor = 
ThemeColors::GetThemeColors().GetButtonColor();
+            const Color& rButtonRectColor = 
ThemeColors::GetThemeColors().GetDisabledColor();
+
+            if (iState == PBS_PRESSED)
+                aButtonColor.Merge(rButtonRectColor, 230);
+            else if (iState == PBS_DISABLED)
+                aButtonColor = 
ThemeColors::GetThemeColors().GetDisabledColor();
+            else if (iState == PBS_HOT)
+                aButtonColor.Merge(rButtonRectColor, 170);
+            else if (iState == PBS_DEFAULTED)
+                aButtonColor.Merge(rButtonRectColor, 150);
+
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aButtonColor.GetRed(),
+                                                     aButtonColor.GetGreen(),
+                                                     aButtonColor.GetBlue())));
+            FillRect(hDC, &rc, hbrush.get());
+
+            hbrush = 
ScopedHBRUSH(CreateSolidBrush(RGB(rButtonRectColor.GetRed(),
+                                                       
rButtonRectColor.GetGreen(),
+                                                       
rButtonRectColor.GetBlue())));
+            FrameRect(hDC, &rc, hbrush.get());
+            return true;
+        }
+    }
+    else if (nType == ControlType::Editbox)
+    {
+        if (iPart == EP_EDITBORDER_NOSCROLL)
+        {
+            const Color& rColor = 
ThemeColors::GetThemeColors().GetSeparatorColor();
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(rColor.GetRed(),
+                                                     rColor.GetGreen(),
+                                                     rColor.GetBlue())));
+            FrameRect(hDC, &rc, hbrush.get());
+            return true;
+        }
+    }
+    else if (nType == ControlType::Toolbar)
+    {
+        if (iPart == TP_BUTTON)
+        {
+            Color aButtonColor = 
ThemeColors::GetThemeColors().GetAccentColor();
+            const Color& rWindowColor = 
ThemeColors::GetThemeColors().GetWindowColor();
+            Color aFrameOutline = aButtonColor;
+
+            if (iState == TS_PRESSED)
+                aButtonColor.Merge(rWindowColor, 100);
+            else if (iState == TS_HOTCHECKED || iState == TS_HOT)
+                aButtonColor.Merge(rWindowColor, 60);
+            else if (iState == TS_CHECKED || iState == TS_NORMAL)
+                aButtonColor.Merge(rWindowColor, 100);
+
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aButtonColor.GetRed(),
+                                                     aButtonColor.GetGreen(),
+                                                     aButtonColor.GetBlue())));
+            FillRect(hDC, &rc, hbrush.get());
+
+            hbrush = ScopedHBRUSH(CreateSolidBrush(RGB(aFrameOutline.GetRed(),
+                                                       
aFrameOutline.GetGreen(),
+                                                       
aFrameOutline.GetBlue())));
+            FrameRect(hDC, &rc, hbrush.get());
+            return true;
+        }
+    }
+    else if (nType == ControlType::MenuPopup)
+    {
+        if (iPart == MENU_POPUPBACKGROUND)
+        {
+            Color aColor(ThemeColors::GetThemeColors().GetMenuColor());
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(),
+                                                     aColor.GetGreen(),
+                                                     aColor.GetBlue())));
+            FillRect(hDC, &rc, hbrush.get());
+
+            aColor = ThemeColors::GetThemeColors().GetMenuBorderColor();
+            hbrush = ScopedHBRUSH(CreateSolidBrush( RGB(aColor.GetRed(),
+                                                        aColor.GetGreen(),
+                                                        aColor.GetBlue())));
+            FrameRect(hDC, &rc, hbrush.get());
+            return true;
+        }
+        else if (iPart == MENU_POPUPITEM)
+        {
+            Color aBackgroundColor;
+            if (iState == MPI_HOT || iState == MPI_NORMAL)
+                aBackgroundColor = 
ThemeColors::GetThemeColors().GetMenuHighlightColor();
+            else if (iState == MPI_DISABLEDHOT || MPI_DISABLED)
+                aBackgroundColor = 
ThemeColors::GetThemeColors().GetDisabledColor();
+
+            ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aBackgroundColor.GetRed(),
+                                                     
aBackgroundColor.GetGreen(),
+                                                     
aBackgroundColor.GetBlue())));
+            FillRect(hDC, &rc, hbrush.get());
+            return true;
+        }
+    }
+    return false;
+}
+
 static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc,
                             ControlType nType,
                             ControlPart nPart,
@@ -457,6 +663,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
         if( nPart == ControlPart::Entire )
             nType = ControlType::Editbox;
 
+    bool bThemeLoaded = ThemeColors::IsThemeLoaded();
     int iPart(0), iState(0);
     if( nType == ControlType::Scrollbar )
     {
@@ -472,6 +679,10 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
                 iState = ABS_UPHOT;
             else
                 iState = ABS_UPNORMAL;
+
+            if (bThemeLoaded)
+                return drawThemedControl(hDC, nType, iPart, iState, rc);
+
             hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 
nullptr);
             return (hr == S_OK);
         }
@@ -486,6 +697,10 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
                 iState = ABS_DOWNHOT;
             else
                 iState = ABS_DOWNNORMAL;
+
+            if (bThemeLoaded)
+                return drawThemedControl(hDC, nType, iPart, iState, rc);
+
             hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 
nullptr);
             return (hr == S_OK);
         }
@@ -500,6 +715,10 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
                 iState = ABS_LEFTHOT;
             else
                 iState = ABS_LEFTNORMAL;
+
+            if (bThemeLoaded)
+                return drawThemedControl(hDC, nType, iPart, iState, rc);
+
             hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 
nullptr);
             return (hr == S_OK);
         }
@@ -514,6 +733,10 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
                 iState = ABS_RIGHTHOT;
             else
                 iState = ABS_RIGHTNORMAL;
+
+            if (bThemeLoaded)
+                return drawThemedControl(hDC, nType, iPart, iState, rc);
+
             hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 
nullptr);
             return (hr == S_OK);
         }
@@ -534,6 +757,9 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
             GetThemePartSize(hTheme, hDC, iPart, iState, nullptr, TS_TRUE, 
&sz);
             GetThemePartSize(hTheme, hDC, iPart, iState, nullptr, TS_DRAW, 
&sz);
 
+            if (bThemeLoaded)
+                return drawThemedControl(hDC, nType, iPart, iState, rc);
+
             hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 
nullptr);
             // paint gripper on thumb if enough space
             if( ( (nPart == ControlPart::ThumbVert) && (rc.bottom-rc.top > 12) 
) ||
@@ -564,6 +790,10 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
                 iState = SCRBS_HOT;
             else
                 iState = SCRBS_NORMAL;
+
+            if (bThemeLoaded)
+                return drawThemedControl(hDC, nType, iPart, iState, rc);
+
             hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 
nullptr);
             return (hr == S_OK);
         }
@@ -692,6 +922,9 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
         else
             iState = PBS_NORMAL;
 
+        if (bThemeLoaded)
+            return drawThemedControl(hDC, nType, iPart, iState, rc);
+
         return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
     }
 
@@ -755,6 +988,9 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
         else
             iState = EPSN_NORMAL;
 
+        if (bThemeLoaded)
+            return drawThemedControl(hDC, nType, iPart, iState, rc);
+
         return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
     }
 
@@ -786,7 +1022,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
     {
         // tabpane in tabcontrols gets drawn in "darkmode" as if it was a
         // a "light" theme, so bodge this by drawing a frame directly
-        if (bUseDarkMode)
+        if (bThemeLoaded || bUseDarkMode)
         {
             Color 
aColor(Application::GetSettings().GetStyleSettings().GetDisableColor());
             ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(),
@@ -802,7 +1038,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
     if( nType == ControlType::TabBody )
     {
         // tabbody in main window gets drawn in white in "darkmode", so bodge 
this here
-        if (bUseDarkMode)
+        if (bThemeLoaded || bUseDarkMode)
         {
             Color 
aColor(Application::GetSettings().GetStyleSettings().GetWindowColor());
             ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(),
@@ -862,7 +1098,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
 
         // tabitem in tabcontrols gets drawn in "darkmode" as if it was a
         // a "light" theme, so bodge this by drawing with a button instead
-        if (bUseDarkMode)
+        if (bThemeLoaded || bUseDarkMode)
         {
             Color aColor;
             if (iState == TILES_SELECTED)
@@ -912,6 +1148,9 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
             else
                 iState = bChecked ? TS_CHECKED : TS_NORMAL;
 
+            if (bThemeLoaded)
+                return drawThemedControl(hDC, nType, iPart, iState, rc);
+
             if (bUseDarkMode && (bChecked || (nState & (ControlState::PRESSED) 
|| (nState & ControlState::ROLLOVER))))
             {
                 const WinOSVersionInfo aVersion = 
WinSalInstance::getWinOSVersionInfo();
@@ -954,7 +1193,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, 
RECT rc,
             }
 
             // toolbar in main window gets drawn in white in "darkmode", so 
bodge this here
-            if (bUseDarkMode)
+            if (bThemeLoaded || bUseDarkMode)
             {
                 Color 
aColor(Application::GetSettings().GetStyleSettings().GetWindowColor());
                 ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(),
@@ -986,9 +1225,12 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME 
hTheme, RECT rc,
                 rc.bottom += pValue->maTopDockingAreaHeight;    // extend 
potential gradient to cover docking area as well
 
                 // menubar in main window gets drawn in white in "darkmode", 
so bodge this here
-                if (bUseDarkMode)
+                if (bThemeLoaded || bUseDarkMode)
                 {
-                    Color 
aColor(Application::GetSettings().GetStyleSettings().GetWindowColor());
+                    Color aColor
+                        = bThemeLoaded
+                              ? ThemeColors::GetThemeColors().GetMenuBarColor()
+                              : 
Application::GetSettings().GetStyleSettings().GetWindowColor();
                     ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(),
                                                              aColor.GetGreen(),
                                                              
aColor.GetBlue())));
@@ -1017,13 +1259,18 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME 
hTheme, RECT rc,
                 else
                     iState = MBI_NORMAL;
 
-                if(GetSalData()->mbThemeMenuSupport && 
Application::GetSettings().GetStyleSettings().GetHighContrastMode()
-                    && ( nState & (ControlState::SELECTED | nState & 
ControlState::ROLLOVER )))
+                if (bThemeLoaded
+                    || (GetSalData()->mbThemeMenuSupport
+                        && 
Application::GetSettings().GetStyleSettings().GetHighContrastMode()
+                        && (nState & (ControlState::SELECTED | nState & 
ControlState::ROLLOVER))))
                 {
-                    Color 
aColor(Application::GetSettings().GetStyleSettings().GetHighlightColor());
+                    Color aColor = bThemeLoaded
+                              ? 
ThemeColors::GetThemeColors().GetMenuBarHighlightColor()
+                              : 
Application::GetSettings().GetStyleSettings().GetHighlightColor();
+
                     ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(),
-                        aColor.GetGreen(),
-                        aColor.GetBlue())));
+                                                             aColor.GetGreen(),
+                                                             
aColor.GetBlue())));
                     FillRect(hDC, &rc, hbrush.get());
                     return true;
                 }
@@ -1161,6 +1408,10 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME 
hTheme, RECT rc,
                     aGutterRC.left += aValue.getNumericVal();
                     aGutterRC.right = aGutterRC.left+3;
                 }
+
+                if (bThemeLoaded)
+                    return drawThemedControl(hDC, nType, MENU_POPUPBACKGROUND, 
iState, rc);
+
                 return
                 ImplDrawTheme( hTheme, hDC, MENU_POPUPBACKGROUND, 0, rc, 
aCaption ) &&
                 ImplDrawTheme( hTheme, hDC, MENU_POPUPGUTTER, 0, aGutterRC, 
aCaption )
@@ -1172,6 +1423,10 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME 
hTheme, RECT rc,
                     iState = (nState & ControlState::SELECTED) ? MPI_HOT : 
MPI_NORMAL;
                 else
                     iState = (nState & ControlState::SELECTED) ? 
MPI_DISABLEDHOT : MPI_DISABLED;
+
+                if (bThemeLoaded)
+                    return drawThemedControl(hDC, nType, MENU_POPUPITEM, 
iState, rc);
+
                 return ImplDrawTheme( hTheme, hDC, MENU_POPUPITEM, iState, rc, 
aCaption );
             }
             else if( nPart == ControlPart::MenuItemCheckMark || nPart == 
ControlPart::MenuItemRadioMark )
@@ -1642,11 +1897,17 @@ void WinSalGraphics::updateSettingsNative( AllSettings& 
rSettings )
     Color aMenuBarTextColor = 
aStyleSettings.GetPersonaMenuBarTextColor().value_or( 
aStyleSettings.GetMenuTextColor() );
     // in aero menuitem highlight text is drawn in the same color as normal
     // high contrast highlight color is not related to persona and not apply 
blur or transparency
-    if( !aStyleSettings.GetHighContrastMode() )
+    bool bThemeLoaded = ThemeColors::IsThemeLoaded();
+    if( bThemeLoaded || !aStyleSettings.GetHighContrastMode() )
     {
-        aStyleSettings.SetMenuHighlightTextColor( 
aStyleSettings.GetMenuTextColor() );
-        aStyleSettings.SetMenuBarRolloverTextColor( aMenuBarTextColor );
-        aStyleSettings.SetMenuBarHighlightTextColor( aMenuBarTextColor );
+        const ThemeColors& rThemeColors = ThemeColors::GetThemeColors();
+        aStyleSettings.SetMenuHighlightTextColor(bThemeLoaded
+                                                     ? 
rThemeColors.GetMenuHighlightTextColor()
+                                                     : 
aStyleSettings.GetMenuTextColor());
+        aStyleSettings.SetMenuBarRolloverTextColor(
+            bThemeLoaded ? rThemeColors.GetMenuBarHighlightTextColor() : 
aMenuBarTextColor);
+        aStyleSettings.SetMenuBarHighlightTextColor(
+            bThemeLoaded ? rThemeColors.GetMenuBarHighlightTextColor() : 
aMenuBarTextColor);
     }
 
     pSVData->maNWFData.mnMenuFormatBorderX = 2;
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index 09018fdf8c6b..dbbffe73b27b 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -23,6 +23,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/awt/Rectangle.hpp>
 #include <com/sun/star/uno/DeploymentException.hpp>
+#include <IconThemeSelector.hxx>
 
 #include <officecfg/Office/Common.hxx>
 
@@ -51,6 +52,7 @@
 #include <vcl/sysdata.hxx>
 #include <vcl/timer.hxx>
 #include <vcl/settings.hxx>
+#include <vcl/themecolors.hxx>
 #include <vcl/keycodes.hxx>
 #include <vcl/window.hxx>
 #include <vcl/wrkwin.hxx>
@@ -2610,6 +2612,72 @@ static tools::Long ImplW2I( const wchar_t* pStr )
     return n;
 }
 
+static void lcl_LoadColorsFromTheme(StyleSettings& rStyleSet)
+{
+    const ThemeColors& rThemeColors = ThemeColors::GetThemeColors();
+
+    rStyleSet.SetWindowColor(rThemeColors.GetWindowColor());
+    rStyleSet.BatchSetBackgrounds(rThemeColors.GetWindowColor());
+
+    rStyleSet.SetActiveTabColor(rThemeColors.GetWindowColor());
+    rStyleSet.SetInactiveTabColor(rThemeColors.GetBaseColor());
+    rStyleSet.SetDisableColor(rThemeColors.GetDisabledColor()); // tab outline
+
+    // Highlight related colors
+    rStyleSet.SetAccentColor(rThemeColors.GetAccentColor());
+    rStyleSet.SetHighlightColor(rThemeColors.GetAccentColor());
+
+    rStyleSet.SetListBoxWindowHighlightColor(rThemeColors.GetAccentColor());
+    rStyleSet.SetListBoxWindowTextColor(rThemeColors.GetWindowTextColor());
+    rStyleSet.SetListBoxWindowBackgroundColor(rThemeColors.GetBaseColor());
+    
rStyleSet.SetListBoxWindowHighlightTextColor(rThemeColors.GetMenuHighlightTextColor());
+    rStyleSet.SetWindowTextColor(rThemeColors.GetWindowTextColor()); // 
Treeview Lists
+
+    rStyleSet.SetRadioCheckTextColor(rThemeColors.GetWindowTextColor());
+    rStyleSet.SetLabelTextColor(rThemeColors.GetWindowTextColor());
+    rStyleSet.SetFieldTextColor(rThemeColors.GetWindowTextColor());
+    rStyleSet.SetTabTextColor(rThemeColors.GetWindowTextColor());
+    rStyleSet.SetFieldColor(rThemeColors.GetBaseColor());
+    rStyleSet.SetMenuBarTextColor(rThemeColors.GetMenuBarTextColor());
+    rStyleSet.SetMenuTextColor(rThemeColors.GetMenuTextColor());
+
+    
rStyleSet.SetDefaultActionButtonTextColor(rThemeColors.GetButtonTextColor());
+    rStyleSet.SetActionButtonTextColor(rThemeColors.GetButtonTextColor());
+    rStyleSet.SetShadowColor(rThemeColors.GetShadeColor());
+
+    rStyleSet.SetDefaultButtonTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetDefaultButtonRolloverTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetDefaultButtonPressedRolloverTextColor(rThemeColors.GetButtonTextColor());
+
+    rStyleSet.SetFlatButtonTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetFlatButtonPressedRolloverTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetFlatButtonRolloverTextColor(rThemeColors.GetButtonTextColor());
+
+    rStyleSet.SetButtonRolloverTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetDefaultActionButtonRolloverTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetDefaultActionButtonPressedRolloverTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetActionButtonRolloverTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetActionButtonPressedRolloverTextColor(rThemeColors.GetButtonTextColor());
+    rStyleSet.SetFieldRolloverTextColor(rThemeColors.GetButtonTextColor());
+
+    rStyleSet.SetButtonRolloverTextColor(rThemeColors.GetButtonTextColor());
+    
rStyleSet.SetButtonPressedRolloverTextColor(rThemeColors.GetButtonTextColor());
+    rStyleSet.SetHelpColor(rThemeColors.GetWindowColor());
+    rStyleSet.SetHelpTextColor(rThemeColors.GetWindowTextColor());
+
+    // rStyleSet.SetHighlightTextColor(aThemeColors.GetActiveTextColor());
+    // rStyleSet.SetActiveColor(aThemeColors.GetActiveColor());
+    rStyleSet.SetActiveTextColor(rThemeColors.GetWindowTextColor());
+
+    // rStyleSet.SetLinkColor(aThemeColors.GetAccentColor());
+    // Color aVisitedLinkColor = aThemeColors.GetActiveColor();
+    // aVisitedLinkColor.Merge(aThemeColors.GetWindowColor(), 100);
+    // rStyleSet.SetVisitedLinkColor(aVisitedLinkColor);
+    // rStyleSet.SetToolTextColor(Color(255, 0, 0));
+
+    
rStyleSet.SetTabRolloverTextColor(rThemeColors.GetMenuBarHighlightTextColor());
+}
+
 void WinSalFrame::UpdateSettings( AllSettings& rSettings )
 {
     MouseSettings aMouseSettings = rSettings.GetMouseSettings();
@@ -2690,9 +2758,16 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings 
)
     }
 
     const bool bUseDarkMode(UseDarkMode());
-
-    OUString sThemeName(!bUseDarkMode ? u"colibre" : u"colibre_dark");
-    aStyleSettings.SetPreferredIconTheme(sThemeName, bUseDarkMode);
+    if (!ThemeColors::IsThemeLoaded())
+    {
+        OUString sThemeName(!bUseDarkMode ? u"colibre" : u"colibre_dark");
+        aStyleSettings.SetPreferredIconTheme(sThemeName, bUseDarkMode);
+    }
+    else
+    {
+        
aStyleSettings.SetPreferredIconTheme(vcl::IconThemeSelector::GetIconThemeForDesktopEnvironment(
+            Application::GetDesktopEnvironment(), 
ThemeColors::GetThemeColors().GetWindowColor().IsDark()));
+    }
 
     if (bUseDarkMode)
     {
@@ -2930,6 +3005,11 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings 
)
         }
     }
 
+    // otherwise, menu shows up as white in dark mode
+    aStyleSettings.SetMenuColor(aStyleSettings.GetWindowColor());
+    if (ThemeColors::IsThemeLoaded())
+        lcl_LoadColorsFromTheme(aStyleSettings);
+
     rSettings.SetMouseSettings( aMouseSettings );
     rSettings.SetStyleSettings( aStyleSettings );
 

Reply via email to