cui/source/options/appearance.cxx                          |   10 +++---
 include/vcl/themecolors.hxx                                |   16 ++++++++++
 officecfg/registry/schema/org/openoffice/Office/Common.xcs |   19 ++++++++++---
 svtools/source/config/colorcfg.cxx                         |    2 -
 vcl/source/app/themecolors.cxx                             |   13 ++++++++
 5 files changed, 51 insertions(+), 9 deletions(-)

New commits:
commit 1655e4297355684570abfc0af0bd94045f8d400f
Author:     Sahil Gautam <[email protected]>
AuthorDate: Tue Jan 7 10:43:29 2025 +0530
Commit:     Sahil Gautam <[email protected]>
CommitDate: Mon Jan 26 09:35:06 2026 +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 <[email protected]>
    (cherry picked from commit 242b8a9540f8e019dbe82c11d989d20d3a0f0ea7)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198076
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Sahil Gautam <[email protected]>

diff --git a/cui/source/options/appearance.cxx 
b/cui/source/options/appearance.cxx
index 718603f8549a..a0acbc488b53 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>
@@ -190,11 +191,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 95e4bd2c1878..41fcf02e20b3 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5177,11 +5177,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 febac2f0aaea..7df881439615 100644
--- a/svtools/source/config/colorcfg.cxx
+++ b/svtools/source/config/colorcfg.cxx
@@ -480,7 +480,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: */

Reply via email to