cui/source/options/appearance.cxx                          |   10 ++---
 include/vcl/themecolors.hxx                                |   24 ++++++++++---
 officecfg/registry/schema/org/openoffice/Office/Common.xcs |   19 ++++++++--
 svtools/source/config/colorcfg.cxx                         |   12 +++---
 vcl/qt5/QtCustomStyle.cxx                                  |    8 ++--
 vcl/source/app/themecolors.cxx                             |   15 +++++++-
 6 files changed, 65 insertions(+), 23 deletions(-)

New commits:
commit 242b8a9540f8e019dbe82c11d989d20d3a0f0ea7
Author:     Sahil Gautam <sahil.gautam.ext...@allotropia.de>
AuthorDate: Tue Jan 7 10:43:29 2025 +0530
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jan 7 12:24:40 2025 +0100

    tdf#164393 [API CHANGE] ThemeColors refactor part 3
    
    - add functions like IsThemeEnabled(), IsThemeDisabled(), GetThemeState(),
      SetThemeState() to check/change registry (theme state) values so that
      code outside ThemeColors class remains unaffected from any API changes,
      and use enums like ENABLED and DISABLED to represent int values from
      registry.
    
    Change-Id: I6067cb5b0fa40d6c038e398229ef8ba93d26ca92
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179404
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/cui/source/options/appearance.cxx 
b/cui/source/options/appearance.cxx
index fa70705ab327..f36c6255809e 100644
--- a/cui/source/options/appearance.cxx
+++ b/cui/source/options/appearance.cxx
@@ -21,6 +21,7 @@
 #include <tools/debug.hxx>
 #include <unotools/resmgr.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/themecolors.hxx>
 #include <comphelper/dispatchcommand.hxx>
 #include <comphelper/propertyvalue.hxx>
 #include <map>
@@ -196,11 +197,10 @@ bool SvxAppearanceTabPage::FillItemSet(SfxItemSet* /* 
rSet */)
     // commit LibreOfficeTheme, enable it if the current scheme is not 
Automatic
     if (m_xSchemeList->get_value_changed_from_saved())
     {
-        bool bIsLibreOfficeThemeEnabled = m_xSchemeList->get_active_id() != 
AUTOMATIC_COLOR_SCHEME;
-        auto pChange(comphelper::ConfigurationChanges::create());
-        
officecfg::Office::Common::Appearance::LibreOfficeTheme::set(bIsLibreOfficeThemeEnabled,
-                                                                     pChange);
-        pChange->commit();
+        ThemeState eLibreOfficeThemeState = m_xSchemeList->get_active_id() != 
AUTOMATIC_COLOR_SCHEME
+                                                ? ThemeState::ENABLED
+                                                : ThemeState::DISABLED;
+        ThemeColors::SetThemeState(eLibreOfficeThemeState);
     }
 
     return true;
diff --git a/include/vcl/themecolors.hxx b/include/vcl/themecolors.hxx
index 55d6d5836489..3e23368bd351 100644
--- a/include/vcl/themecolors.hxx
+++ b/include/vcl/themecolors.hxx
@@ -11,6 +11,15 @@
 #include <vcl/dllapi.h>
 #include <svtools/colorcfg.hxx>
 
+/* ThemeState represents registry values for "LibreOfficeTheme" enumeration
+ * in officecfg/registry/schema/org/openoffice/Office/Common.xcs, which means
+ * that the associations here have a meaning. Please don't change it. */
+enum class ThemeState
+{
+    DISABLED = 0,
+    ENABLED = 1,
+};
+
 class VCL_DLLPUBLIC ThemeColors
 {
     ThemeColors() {}
@@ -28,6 +37,13 @@ public:
         return rThemeName == svtools::AUTOMATIC_COLOR_SCHEME;
     }
 
+    static ThemeState GetThemeState();
+    static void SetThemeState(ThemeState eState);
+
+    static bool IsThemeDisabled() { return GetThemeState() == 
ThemeState::DISABLED; };
+    static bool IsThemeEnabled() { return GetThemeState() == 
ThemeState::ENABLED; };
+
+    // !IsThemeCached means that the ThemeColors object doesn't have the 
colors from the registry yet.
     static bool VclPluginCanUseThemeColors()
     {
         return IsThemeCached()
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 5946b021e16a..be596df8e308 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5163,11 +5163,24 @@
       <info>
         <desc>Specifies appearance settings for the application.</desc>
       </info>
-      <prop oor:name="LibreOfficeTheme" oor:type="xs:boolean" 
oor:nillable="false">
+      <prop oor:name="LibreOfficeTheme" oor:type="xs:short" 
oor:nillable="false">
         <info>
-          <desc>Enable UI Themeing in LibreOffice.</desc>
+          <desc>Specifies LibreOfficeTheme state.</desc>
+          <label>LibreOffice Theme</label>
         </info>
-        <value>false</value>
+        <constraints>
+          <enumeration oor:value="0">
+            <info>
+              <desc>Disabled</desc>
+            </info>
+          </enumeration>
+          <enumeration oor:value="1">
+            <info>
+              <desc>Enabled</desc>
+            </info>
+          </enumeration>
+        </constraints>
+        <value>0</value>
       </prop>
       <prop oor:name="ApplicationAppearance" oor:type="xs:short" 
oor:nillable="false">
         <info>
diff --git a/svtools/source/config/colorcfg.cxx 
b/svtools/source/config/colorcfg.cxx
index 138f22025979..2ec5abf16d28 100644
--- a/svtools/source/config/colorcfg.cxx
+++ b/svtools/source/config/colorcfg.cxx
@@ -472,7 +472,7 @@ void ColorConfig::LoadThemeColorsFromRegistry()
 
 void ColorConfig::SetupTheme()
 {
-    if (!officecfg::Office::Common::Appearance::LibreOfficeTheme::get()
+    if (ThemeColors::IsThemeDisabled()
         || ThemeColors::IsAutomaticTheme(GetCurrentSchemeName()))
     {
         ThemeColors::SetThemeCached(false);
diff --git a/vcl/source/app/themecolors.cxx b/vcl/source/app/themecolors.cxx
index 0652df93e523..33f4601f89bc 100644
--- a/vcl/source/app/themecolors.cxx
+++ b/vcl/source/app/themecolors.cxx
@@ -7,8 +7,21 @@
  */
 
 #include <vcl/themecolors.hxx>
+#include <officecfg/Office/Common.hxx>
 
 ThemeColors ThemeColors::m_aThemeColors;
 bool ThemeColors::m_bIsThemeCached = false;
 
+void ThemeColors::SetThemeState(ThemeState eState)
+{
+    auto pChange(comphelper::ConfigurationChanges::create());
+    
officecfg::Office::Common::Appearance::LibreOfficeTheme::set(static_cast<int>(eState),
 pChange);
+    pChange->commit();
+}
+
+ThemeState ThemeColors::GetThemeState()
+{
+    return 
static_cast<ThemeState>(officecfg::Office::Common::Appearance::LibreOfficeTheme::get());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 6929168584be46583ae033c3b82574f743490c4c
Author:     Sahil Gautam <sahil.gautam.ext...@allotropia.de>
AuthorDate: Tue Jan 7 10:31:50 2025 +0530
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jan 7 12:24:26 2025 +0100

    tdf#164393 ThemeColors refactor part 2
    
    - rename IsThemeLoaded() to IsThemeCached() (similar for setter) because
      it's not loading but caching colors in ThemeColors::m_aThemeColors.
      ColorConfig_Impl::Load() loads themes.
    
    Change-Id: If65302bc77d50f637176beaac47b43dff949368b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179854
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/vcl/themecolors.hxx b/include/vcl/themecolors.hxx
index 67551dbdac8d..55d6d5836489 100644
--- a/include/vcl/themecolors.hxx
+++ b/include/vcl/themecolors.hxx
@@ -14,15 +14,15 @@
 class VCL_DLLPUBLIC ThemeColors
 {
     ThemeColors() {}
-    static bool m_bIsThemeLoaded;
+    static bool m_bIsThemeCached;
     static ThemeColors m_aThemeColors;
 
 public:
     static ThemeColors& GetThemeColors() { return m_aThemeColors; }
     static void SetThemeColors(const ThemeColors& rThemeColors) { 
m_aThemeColors = rThemeColors; }
 
-    static bool IsThemeLoaded() { return m_bIsThemeLoaded; }
-    static void SetThemeLoaded(bool bLoaded) { m_bIsThemeLoaded = bLoaded; }
+    static bool IsThemeCached() { return m_bIsThemeCached; }
+    static void SetThemeCached(bool bCached) { m_bIsThemeCached = bCached; }
     static bool IsAutomaticTheme(std::u16string_view rThemeName)
     {
         return rThemeName == svtools::AUTOMATIC_COLOR_SCHEME;
@@ -30,7 +30,7 @@ public:
 
     static bool VclPluginCanUseThemeColors()
     {
-        return IsThemeLoaded()
+        return IsThemeCached()
                && 
!ThemeColors::IsAutomaticTheme(ThemeColors::GetThemeColors().GetThemeName());
     };
 
diff --git a/svtools/source/config/colorcfg.cxx 
b/svtools/source/config/colorcfg.cxx
index 8dfdd757b151..138f22025979 100644
--- a/svtools/source/config/colorcfg.cxx
+++ b/svtools/source/config/colorcfg.cxx
@@ -467,7 +467,7 @@ void ColorConfig::LoadThemeColorsFromRegistry()
     rThemeColors.SetAppBackBitmapStretched(
         
m_pImpl->GetColorConfigValue(svtools::APPBACKGROUND).bIsBitmapStretched);
 
-    ThemeColors::SetThemeLoaded(true);
+    ThemeColors::SetThemeCached(true);
 }
 
 void ColorConfig::SetupTheme()
@@ -475,17 +475,17 @@ void ColorConfig::SetupTheme()
     if (!officecfg::Office::Common::Appearance::LibreOfficeTheme::get()
         || ThemeColors::IsAutomaticTheme(GetCurrentSchemeName()))
     {
-        ThemeColors::SetThemeLoaded(false);
+        ThemeColors::SetThemeCached(false);
         return;
     }
 
-    if (!ThemeColors::IsThemeLoaded())
+    if (!ThemeColors::IsThemeCached())
     {
-        // extension to registry
+        // registry to ColorConfig::m_pImpl
         m_pImpl->Load(GetCurrentSchemeName());
         m_pImpl->CommitCurrentSchemeName();
 
-        // registry to theme
+        // ColorConfig::m_pImpl to static ThemeColors::m_aThemeColors
         LoadThemeColorsFromRegistry();
     }
 }
diff --git a/vcl/qt5/QtCustomStyle.cxx b/vcl/qt5/QtCustomStyle.cxx
index ea2d4771019d..26678ea530cc 100644
--- a/vcl/qt5/QtCustomStyle.cxx
+++ b/vcl/qt5/QtCustomStyle.cxx
@@ -18,7 +18,7 @@
 void QtCustomStyle::drawPrimitive(PrimitiveElement element, const 
QStyleOption* option,
                                   QPainter* painter, const QWidget* widget) 
const
 {
-    if (!ThemeColors::IsThemeLoaded() || IsSystemThemeChanged())
+    if (!ThemeColors::IsThemeCached() || IsSystemThemeChanged())
     {
         QProxyStyle::drawPrimitive(element, option, painter, widget);
         return;
@@ -45,7 +45,7 @@ void QtCustomStyle::drawPrimitive(PrimitiveElement element, 
const QStyleOption*
 
 QPalette QtCustomStyle::customPalette()
 {
-    if (!ThemeColors::IsThemeLoaded())
+    if (!ThemeColors::IsThemeCached())
         return QApplication::palette();
 
     const ThemeColors& aThemeColors = ThemeColors::GetThemeColors();
@@ -75,7 +75,7 @@ QPalette QtCustomStyle::customPalette()
 
 QPalette QtCustomStyle::GetMenuBarPalette()
 {
-    if (!ThemeColors::IsThemeLoaded() || IsSystemThemeChanged())
+    if (!ThemeColors::IsThemeCached() || IsSystemThemeChanged())
         return QApplication::palette();
 
     QPalette aPal;
@@ -92,7 +92,7 @@ QPalette QtCustomStyle::GetMenuBarPalette()
 
 QPalette QtCustomStyle::GetMenuPalette()
 {
-    if (!ThemeColors::IsThemeLoaded() || IsSystemThemeChanged())
+    if (!ThemeColors::IsThemeCached() || IsSystemThemeChanged())
         return QApplication::palette();
 
     QPalette aPal;
diff --git a/vcl/source/app/themecolors.cxx b/vcl/source/app/themecolors.cxx
index b46fdee33e8d..0652df93e523 100644
--- a/vcl/source/app/themecolors.cxx
+++ b/vcl/source/app/themecolors.cxx
@@ -9,6 +9,6 @@
 #include <vcl/themecolors.hxx>
 
 ThemeColors ThemeColors::m_aThemeColors;
-bool ThemeColors::m_bIsThemeLoaded = false;
+bool ThemeColors::m_bIsThemeCached = false;
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to