include/vcl/themecolors.hxx | 6 ++++ svtools/source/config/colorcfg.cxx | 12 +++++--- vcl/osx/salframe.cxx | 4 +- vcl/osx/salnativewidgets.cxx | 12 ++++---- vcl/qt5/QtCustomStyle.cxx | 3 -- vcl/qt5/QtMenu.cxx | 6 +--- vcl/unx/gtk3/custom-theme.cxx | 3 -- vcl/unx/gtk3/salnativewidgets-gtk.cxx | 2 - vcl/win/gdi/salnativewidgets-luna.cxx | 50 +++++++++++++++++----------------- vcl/win/window/salframe.cxx | 4 +- 10 files changed, 54 insertions(+), 48 deletions(-)
New commits: commit c398498fe155790a8e6510353427ffa5224343ac Author: Sahil Gautam <sahil.gautam.ext...@allotropia.de> AuthorDate: Tue Jan 7 10:05:08 2025 +0530 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Jan 7 09:19:23 2025 +0100 tdf#164393 ThemeColors refactor part 1 - Use a single `ThemeColors::VclPluginCanUseThemeColors()` check instead of `ThemeColors::IsThemeLoaded()` and then checking if the current scheme is Automatic or not Change-Id: I96294c3b4b75b5f2cee02c72a8b0dd1a85bedec4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179853 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/vcl/themecolors.hxx b/include/vcl/themecolors.hxx index 80f56db5e0e4..67551dbdac8d 100644 --- a/include/vcl/themecolors.hxx +++ b/include/vcl/themecolors.hxx @@ -28,6 +28,12 @@ public: return rThemeName == svtools::AUTOMATIC_COLOR_SCHEME; } + static bool VclPluginCanUseThemeColors() + { + return IsThemeLoaded() + && !ThemeColors::IsAutomaticTheme(ThemeColors::GetThemeColors().GetThemeName()); + }; + void SetWindowColor(const Color& rColor) { m_aWindowColor = rColor; } void SetWindowTextColor(const Color& rColor) { m_aWindowTextColor = rColor; } void SetBaseColor(const Color& rColor) { m_aBaseColor = rColor; } diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx index 4e1266234f1f..a5e74df04386 100644 --- a/vcl/osx/salframe.cxx +++ b/vcl/osx/salframe.cxx @@ -1557,7 +1557,7 @@ SAL_WNODEPRECATED_DECLARATIONS_POP StyleSettings aStyleSettings = rSettings.GetStyleSettings(); bool bUseDarkMode(GetUseDarkMode()); - if (!ThemeColors::IsThemeLoaded()) + if (!ThemeColors::VclPluginCanUseThemeColors()) { OUString sThemeName(!bUseDarkMode ? u"sukapura_svg" : u"sukapura_dark_svg"); aStyleSettings.SetPreferredIconTheme(sThemeName, bUseDarkMode); @@ -1731,7 +1731,7 @@ SAL_WNODEPRECATED_DECLARATIONS_POP aStyleSettings.SetHideDisabledMenuItems( true ); aStyleSettings.SetPreferredContextMenuShortcuts( false ); - if (ThemeColors::IsThemeLoaded()) + if (ThemeColors::VclPluginCanUseThemeColors()) lcl_LoadColorsFromTheme(aStyleSettings); rSettings.SetStyleSettings( aStyleSettings ); diff --git a/vcl/osx/salnativewidgets.cxx b/vcl/osx/salnativewidgets.cxx index 07f26c51171a..cfbb154eef74 100644 --- a/vcl/osx/salnativewidgets.cxx +++ b/vcl/osx/salnativewidgets.cxx @@ -423,7 +423,7 @@ static void drawBox(CGContextRef context, const NSRect& rc, NSColor* pColor) static void drawEditableBackground(CGContextRef context, const NSRect& rc) { CGContextSaveGState(context); - if (ThemeColors::IsThemeLoaded()) + if (ThemeColors::VclPluginCanUseThemeColors()) CGContextSetFillColorWithColor(context, colorFromRGB(ThemeColors::GetThemeColors().GetBaseColor()).CGColor); else CGContextSetFillColorWithColor(context, [NSColor controlBackgroundColor].CGColor); @@ -443,14 +443,14 @@ bool AquaGraphicsBackendBase::performDrawNativeControl(ControlType nType, AquaSalFrame* mpFrame) { bool bOK = false; - bool bThemeLoaded(ThemeColors::IsThemeLoaded()); + bool bCanUseThemeColors(ThemeColors::VclPluginCanUseThemeColors()); AquaSalInstance* pInst = GetSalData()->mpInstance; HIRect rc = ImplGetHIRectFromRectangle(rControlRegion); switch (nType) { case ControlType::Toolbar: { - if (bThemeLoaded) + if (bCanUseThemeColors) drawBox(context, rc, colorFromRGB(ThemeColors::GetThemeColors().GetWindowColor())); else drawBox(context, rc, NSColor.windowBackgroundColor); @@ -459,7 +459,7 @@ bool AquaGraphicsBackendBase::performDrawNativeControl(ControlType nType, break; case ControlType::WindowBackground: { - if (bThemeLoaded) + if (bCanUseThemeColors) drawBox(context, rc, colorFromRGB(ThemeColors::GetThemeColors().GetWindowColor())); else drawBox(context, rc, NSColor.windowBackgroundColor); @@ -470,7 +470,7 @@ bool AquaGraphicsBackendBase::performDrawNativeControl(ControlType nType, { rc.size.width += 2; rc.size.height += 2; - if (bThemeLoaded) + if (bCanUseThemeColors) drawBox(context, rc, colorFromRGB(ThemeColors::GetThemeColors().GetBaseColor())); else drawBox(context, rc, NSColor.controlBackgroundColor); @@ -738,7 +738,7 @@ bool AquaGraphicsBackendBase::performDrawNativeControl(ControlType nType, ? static_cast<const ScrollbarValue *>(&aValue) : nullptr; if (nPart == ControlPart::DrawBackgroundVert || nPart == ControlPart::DrawBackgroundHorz) { - if (bThemeLoaded) + if (bCanUseThemeColors) drawBox(context, rc, colorFromRGB(ThemeColors::GetThemeColors().GetBaseColor())); else drawBox(context, rc, NSColor.controlBackgroundColor); diff --git a/vcl/qt5/QtCustomStyle.cxx b/vcl/qt5/QtCustomStyle.cxx index d3fdcd4c856a..ea2d4771019d 100644 --- a/vcl/qt5/QtCustomStyle.cxx +++ b/vcl/qt5/QtCustomStyle.cxx @@ -129,8 +129,7 @@ bool QtCustomStyle::IsSystemThemeChanged() void QtCustomStyle::LoadCustomStyle(bool bDarkMode) { - if (!ThemeColors::IsThemeLoaded() - || ThemeColors::IsAutomaticTheme(ThemeColors::GetThemeColors().GetThemeName())) + if (!ThemeColors::VclPluginCanUseThemeColors()) return; // don't set custom palette in case the system theme has been changed. diff --git a/vcl/qt5/QtMenu.cxx b/vcl/qt5/QtMenu.cxx index b306e35eb54a..e90248a032e3 100644 --- a/vcl/qt5/QtMenu.cxx +++ b/vcl/qt5/QtMenu.cxx @@ -484,12 +484,10 @@ void QtMenu::SetFrame(const SalFrame* pFrame) void QtMenu::DoFullMenuUpdate(Menu* pMenuBar) { - if (mpQMenuBar && ThemeColors::IsThemeLoaded() - && !ThemeColors::IsAutomaticTheme(ThemeColors::GetThemeColors().GetThemeName())) + if (mpQMenuBar && ThemeColors::VclPluginCanUseThemeColors()) mpQMenuBar->setPalette(QtCustomStyle::GetMenuBarPalette()); - if (mpQMenu && ThemeColors::IsThemeLoaded() - && !ThemeColors::IsAutomaticTheme(ThemeColors::GetThemeColors().GetThemeName())) + if (mpQMenu && ThemeColors::VclPluginCanUseThemeColors()) mpQMenu->setPalette(QtCustomStyle::GetMenuPalette()); // clear action groups since menu is rebuilt diff --git a/vcl/unx/gtk3/custom-theme.cxx b/vcl/unx/gtk3/custom-theme.cxx index a5e7cb3a1f9a..f7892bd68568 100644 --- a/vcl/unx/gtk3/custom-theme.cxx +++ b/vcl/unx/gtk3/custom-theme.cxx @@ -95,8 +95,7 @@ void ApplyCustomTheme(GdkDisplay* pGdkDisplay, GtkCssProvider** pCustomThemeProv void ApplyCustomTheme(GdkScreen* pScreen, GtkCssProvider** pCustomThemeProvider) #endif { - if (!ThemeColors::IsThemeLoaded() - || ThemeColors::IsAutomaticTheme(ThemeColors::GetThemeColors().GetThemeName())) + if (!ThemeColors::VclPluginCanUseThemeColors()) return; if ((*pCustomThemeProvider) == nullptr) diff --git a/vcl/unx/gtk3/salnativewidgets-gtk.cxx b/vcl/unx/gtk3/salnativewidgets-gtk.cxx index 0bd56c02cb9f..fb8041c74e6d 100644 --- a/vcl/unx/gtk3/salnativewidgets-gtk.cxx +++ b/vcl/unx/gtk3/salnativewidgets-gtk.cxx @@ -2670,7 +2670,7 @@ bool GtkSalGraphics::updateSettings(AllSettings& rSettings) aStyleSet.SetMinThumbSize(min_slider_length); // preferred icon style - if (!ThemeColors::IsThemeLoaded()) + if (!ThemeColors::VclPluginCanUseThemeColors()) { gchar* pIconThemeName = nullptr; gboolean bDarkIconTheme = false; diff --git a/vcl/win/gdi/salnativewidgets-luna.cxx b/vcl/win/gdi/salnativewidgets-luna.cxx index 7d1cdc0c98eb..18946824ed99 100644 --- a/vcl/win/gdi/salnativewidgets-luna.cxx +++ b/vcl/win/gdi/salnativewidgets-luna.cxx @@ -663,7 +663,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, if( nPart == ControlPart::Entire ) nType = ControlType::Editbox; - bool bThemeLoaded = ThemeColors::IsThemeLoaded(); + bool bCanUseThemeColors = ThemeColors::VclPluginCanUseThemeColors(); int iPart(0), iState(0); if( nType == ControlType::Scrollbar ) { @@ -680,7 +680,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = ABS_UPNORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, nullptr); @@ -698,7 +698,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = ABS_DOWNNORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, nullptr); @@ -716,7 +716,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = ABS_LEFTNORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, nullptr); @@ -734,7 +734,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = ABS_RIGHTNORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, nullptr); @@ -757,7 +757,7 @@ 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) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, nullptr); @@ -791,7 +791,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = SCRBS_NORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); hr = DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, nullptr); @@ -922,7 +922,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = PBS_NORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption); @@ -988,7 +988,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = EPSN_NORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption); @@ -1022,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 (bThemeLoaded || bUseDarkMode) + if (bCanUseThemeColors || bUseDarkMode) { Color aColor(Application::GetSettings().GetStyleSettings().GetDisableColor()); ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(), @@ -1038,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 (bThemeLoaded || bUseDarkMode) + if (bCanUseThemeColors || bUseDarkMode) { Color aColor(Application::GetSettings().GetStyleSettings().GetWindowColor()); ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(), @@ -1098,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 (bThemeLoaded || bUseDarkMode) + if (bCanUseThemeColors || bUseDarkMode) { Color aColor; if (iState == TILES_SELECTED) @@ -1148,7 +1148,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = bChecked ? TS_CHECKED : TS_NORMAL; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, iPart, iState, rc); if (bUseDarkMode && (bChecked || (nState & (ControlState::PRESSED) || (nState & ControlState::ROLLOVER)))) @@ -1192,7 +1192,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 (bThemeLoaded || bUseDarkMode) + if (bCanUseThemeColors || bUseDarkMode) { Color aColor(Application::GetSettings().GetStyleSettings().GetWindowColor()); ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(), @@ -1224,10 +1224,10 @@ 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 (bThemeLoaded || bUseDarkMode) + if (bCanUseThemeColors || bUseDarkMode) { Color aColor - = bThemeLoaded + = bCanUseThemeColors ? ThemeColors::GetThemeColors().GetMenuBarColor() : Application::GetSettings().GetStyleSettings().GetWindowColor(); ScopedHBRUSH hbrush(CreateSolidBrush(RGB(aColor.GetRed(), @@ -1258,12 +1258,12 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = MBI_NORMAL; - if (bThemeLoaded + if (bCanUseThemeColors || (GetSalData()->mbThemeMenuSupport && Application::GetSettings().GetStyleSettings().GetHighContrastMode() && (nState & (ControlState::SELECTED | nState & ControlState::ROLLOVER)))) { - Color aColor = bThemeLoaded + Color aColor = bCanUseThemeColors ? ThemeColors::GetThemeColors().GetMenuBarHighlightColor() : Application::GetSettings().GetStyleSettings().GetHighlightColor(); @@ -1408,7 +1408,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, aGutterRC.right = aGutterRC.left+3; } - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, MENU_POPUPBACKGROUND, iState, rc); return @@ -1423,7 +1423,7 @@ static bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc, else iState = (nState & ControlState::SELECTED) ? MPI_DISABLEDHOT : MPI_DISABLED; - if (bThemeLoaded) + if (bCanUseThemeColors) return drawThemedControl(hDC, nType, MENU_POPUPITEM, iState, rc); return ImplDrawTheme( hTheme, hDC, MENU_POPUPITEM, iState, rc, aCaption ); @@ -1896,17 +1896,17 @@ void WinSalGraphics::updateSettingsNative( AllSettings& rSettings ) Color aMenuBarTextColor = 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 - bool bThemeLoaded = ThemeColors::IsThemeLoaded(); - if( bThemeLoaded || !aStyleSettings.GetHighContrastMode() ) + bool bCanUseThemeColors = ThemeColors::VclPluginCanUseThemeColors(); + if( bCanUseThemeColors || !aStyleSettings.GetHighContrastMode() ) { const ThemeColors& rThemeColors = ThemeColors::GetThemeColors(); - aStyleSettings.SetMenuHighlightTextColor(bThemeLoaded + aStyleSettings.SetMenuHighlightTextColor(bCanUseThemeColors ? rThemeColors.GetMenuHighlightTextColor() : aStyleSettings.GetMenuTextColor()); aStyleSettings.SetMenuBarRolloverTextColor( - bThemeLoaded ? rThemeColors.GetMenuBarHighlightTextColor() : aMenuBarTextColor); + bCanUseThemeColors ? rThemeColors.GetMenuBarHighlightTextColor() : aMenuBarTextColor); aStyleSettings.SetMenuBarHighlightTextColor( - bThemeLoaded ? rThemeColors.GetMenuBarHighlightTextColor() : aMenuBarTextColor); + bCanUseThemeColors ? rThemeColors.GetMenuBarHighlightTextColor() : aMenuBarTextColor); } pSVData->maNWFData.mnMenuFormatBorderX = 2; diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx index f768f4340b2c..82bb02d85e1c 100644 --- a/vcl/win/window/salframe.cxx +++ b/vcl/win/window/salframe.cxx @@ -2758,7 +2758,7 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings ) } const bool bUseDarkMode(UseDarkMode()); - if (!ThemeColors::IsThemeLoaded()) + if (!ThemeColors::VclPluginCanUseThemeColors()) { OUString sThemeName(!bUseDarkMode ? u"colibre" : u"colibre_dark"); aStyleSettings.SetPreferredIconTheme(sThemeName, bUseDarkMode); @@ -3000,7 +3000,7 @@ void WinSalFrame::UpdateSettings( AllSettings& rSettings ) // otherwise, menu shows up as white in dark mode aStyleSettings.SetMenuColor(aStyleSettings.GetWindowColor()); - if (ThemeColors::IsThemeLoaded()) + if (ThemeColors::VclPluginCanUseThemeColors()) lcl_LoadColorsFromTheme(aStyleSettings); rSettings.SetMouseSettings( aMouseSettings ); commit 7970a121a83653474e696550f91c5e7b963674e8 Author: Sahil Gautam <sahil.gautam.ext...@allotropia.de> AuthorDate: Tue Jan 7 10:48:38 2025 +0530 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Jan 7 09:19:13 2025 +0100 tdf#164393 Format the code to make clang-format happy Change-Id: I1a07935757752c64e86e779a6f3b3c925774c6d8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179852 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/svtools/source/config/colorcfg.cxx b/svtools/source/config/colorcfg.cxx index 544e544cf398..8dfdd757b151 100644 --- a/svtools/source/config/colorcfg.cxx +++ b/svtools/source/config/colorcfg.cxx @@ -446,7 +446,8 @@ void ColorConfig::LoadThemeColorsFromRegistry() rThemeColors.SetMenuBarColor(GetColorValue(svtools::MENUBARCOLOR).nColor); rThemeColors.SetMenuBarTextColor(GetColorValue(svtools::MENUBARTEXTCOLOR).nColor); rThemeColors.SetMenuBarHighlightColor(GetColorValue(svtools::MENUBARHIGHLIGHTCOLOR).nColor); - rThemeColors.SetMenuBarHighlightTextColor(GetColorValue(svtools::MENUBARHIGHLIGHTTEXTCOLOR).nColor); + rThemeColors.SetMenuBarHighlightTextColor( + GetColorValue(svtools::MENUBARHIGHLIGHTTEXTCOLOR).nColor); rThemeColors.SetMenuColor(GetColorValue(svtools::MENUCOLOR).nColor); rThemeColors.SetMenuTextColor(GetColorValue(svtools::MENUTEXTCOLOR).nColor); rThemeColors.SetMenuHighlightColor(GetColorValue(svtools::MENUHIGHLIGHTCOLOR).nColor); @@ -459,9 +460,12 @@ void ColorConfig::LoadThemeColorsFromRegistry() // as more controls support it, we might want to have ColorConfigValue entries in ThemeColors // instead of just colors. for now that seems overkill for just one control. - rThemeColors.SetAppBackBitmapFileName(m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).sBitmapFileName); - rThemeColors.SetAppBackUseBitmap(m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).bUseBitmapBackground); - rThemeColors.SetAppBackBitmapStretched(m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).bIsBitmapStretched); + rThemeColors.SetAppBackBitmapFileName( + m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).sBitmapFileName); + rThemeColors.SetAppBackUseBitmap( + m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).bUseBitmapBackground); + rThemeColors.SetAppBackBitmapStretched( + m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).bIsBitmapStretched); ThemeColors::SetThemeLoaded(true); }