include/sfx2/objsh.hxx                         |    3 
 include/svx/PaletteManager.hxx                 |   29 ----
 include/svx/theme/ThemeColorPaletteManager.hxx |   67 +++++++++++
 sd/source/ui/docshell/docshell.cxx             |   14 --
 sd/source/ui/inc/DrawDocShell.hxx              |    2 
 sfx2/source/doc/objcont.cxx                    |    2 
 svx/Library_svxcore.mk                         |    1 
 svx/source/tbxctrls/PaletteManager.cxx         |  151 ++-----------------------
 svx/source/theme/ThemeColorPaletteManager.cxx  |  130 +++++++++++++++++++++
 sw/inc/docsh.hxx                               |    2 
 sw/source/uibase/app/docst.cxx                 |    4 
 11 files changed, 231 insertions(+), 174 deletions(-)

New commits:
commit f46d6a53f83d3942c83edee9189162e37fb99937
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat Jun 3 10:44:51 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Jun 6 08:13:19 2023 +0200

    svx: extract theme color generation into ThemeColorPaletteManager
    
    The generation of theme colors generation code is moved to the
    ThemeColorPaletteManager class, so it can be reused.
    
    Also change the GetThemeColors return type from std::vector<Color>
    to std::shared_ptr<theme::ColorSet> as we can now safely do that
    and simplifies things.
    
    Change-Id: I4a54bff889a1f97cb1e30467188dc69e07e8c518
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152588
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 6c4c040d2ebc4371a706c762e7e6707875c43535)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152607
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index ef1a0a33e1dc..38ae4166cf0e 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -46,6 +46,7 @@
 #include <sfx2/AccessibilityIssue.hxx>
 
 namespace weld {class Button; }
+namespace model {class ColorSet; }
 class SbxValue;
 class SbxArray;
 class BasicManager;
@@ -558,7 +559,7 @@ public:
     StarBASIC*                  GetBasic() const;
 
     virtual std::set<Color>     GetDocColors();
-    virtual std::vector<Color> GetThemeColors();
+    virtual std::shared_ptr<model::ColorSet> GetThemeColors();
 
     // Accessibility Check
     virtual sfx::AccessibilityIssueCollection runAccessibilityCheck();
diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx
index 37d22b92ec64..5a5000bc0076 100644
--- a/include/svx/PaletteManager.hxx
+++ b/include/svx/PaletteManager.hxx
@@ -16,13 +16,13 @@
  *   except in compliance with the License. You may obtain a copy of
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
-#ifndef INCLUDED_SVX_PALETTEMANAGER_HXX
-#define INCLUDED_SVX_PALETTEMANAGER_HXX
+#pragma once
 
 #include <svx/Palette.hxx>
 #include <rtl/ustring.hxx>
 #include <svx/xtable.hxx>
 #include <svtools/colrdlg.hxx>
+#include <svx/theme/ThemeColorPaletteManager.hxx>
 
 #include <deque>
 #include <vector>
@@ -31,26 +31,7 @@
 namespace com::sun::star::uno { class XComponentContext; }
 namespace svx { class ToolboxButtonColorUpdaterBase; }
 namespace weld { class Window; }
-
-enum class ThemePaletteColorType
-{
-    Black,
-    White,
-    Low,
-    High,
-    Normal
-};
-
-struct ThemePaletteData
-{
-    ThemePaletteColorType meType = ThemePaletteColorType::Normal;
-    Color maColor;
-};
-
-struct ThemePaletteCollection
-{
-    std::array<ThemePaletteData, 12> maData;
-};
+namespace model { class ColorSet; }
 
 class SVXCORE_DLLPUBLIC PaletteManager
 {
@@ -69,7 +50,7 @@ class SVXCORE_DLLPUBLIC PaletteManager
     ColorSelectFunction maColorSelectFunction;
 
     std::unique_ptr<SvColorDialog> m_pColorDlg;
-    std::optional<ThemePaletteCollection> moThemePaletteCollection;
+    std::optional<svx::ThemePaletteCollection> moThemePaletteCollection;
 
     PaletteManager(const PaletteManager* pClone);
 public:
@@ -106,6 +87,4 @@ public:
     static void DispatchColorCommand(const OUString& aCommand, const 
NamedColor& rColor);
 };
 
-#endif // INCLUDED_SVX_PALETTEMANAGER_HXX
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/theme/ThemeColorPaletteManager.hxx 
b/include/svx/theme/ThemeColorPaletteManager.hxx
new file mode 100644
index 000000000000..14fbda39248b
--- /dev/null
+++ b/include/svx/theme/ThemeColorPaletteManager.hxx
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#pragma once
+
+#include <svx/svxdllapi.h>
+#include <rtl/ustring.hxx>
+#include <array>
+#include <memory>
+#include <tools/color.hxx>
+#include <docmodel/theme/ThemeColorType.hxx>
+
+namespace model
+{
+class ColorSet;
+}
+
+namespace svx
+{
+struct SVXCORE_DLLPUBLIC ThemePaletteEffect
+{
+    Color maColor;
+    OUString maColorName;
+    sal_Int16 mnLumOff = 0;
+    sal_Int16 mnLumMod = 10'000;
+
+    sal_Int16 getPercentage()
+    {
+        if (mnLumOff > 0)
+            return mnLumOff / 100;
+        else
+            return (-10'000 + mnLumMod) / 100;
+    }
+};
+
+struct SVXCORE_DLLPUBLIC ThemePaletteColorData
+{
+    Color maBaseColor;
+    model::ThemeColorType meThemeColorType;
+    std::array<ThemePaletteEffect, 6> maEffects;
+
+    sal_Int16 getLumMod(sal_uInt16 nEffect) const { return 
maEffects[nEffect].mnLumMod; }
+    sal_Int16 getLumOff(sal_uInt16 nEffect) const { return 
maEffects[nEffect].mnLumOff; }
+};
+
+struct SVXCORE_DLLPUBLIC ThemePaletteCollection
+{
+    std::array<ThemePaletteColorData, 12> maColors;
+};
+
+class SVXCORE_DLLPUBLIC ThemeColorPaletteManager final
+{
+    std::shared_ptr<model::ColorSet> m_pColorSet;
+
+public:
+    ThemeColorPaletteManager(std::shared_ptr<model::ColorSet> const& 
pColorSet);
+    ThemePaletteCollection generate();
+};
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/docshell/docshell.cxx 
b/sd/source/ui/docshell/docshell.cxx
index 14c63bb87766..0cbee1370964 100644
--- a/sd/source/ui/docshell/docshell.cxx
+++ b/sd/source/ui/docshell/docshell.cxx
@@ -488,27 +488,21 @@ void DrawDocShell::ClearUndoBuffer()
         pUndoManager->Clear();
 }
 
-std::vector<Color> DrawDocShell::GetThemeColors()
+std::shared_ptr<model::ColorSet> DrawDocShell::GetThemeColors()
 {
     auto pViewShell = dynamic_cast<sd::DrawViewShell*>(GetViewShell());
     if (!pViewShell)
-    {
         return {};
-    }
 
     SdPage* pPage = pViewShell->getCurrentPage();
-    model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme().get();
+    auto pTheme = pPage->getSdrPageProperties().GetTheme();
     if (!pPage->IsMasterPage())
-    {
-        pTheme = 
pPage->TRG_GetMasterPage().getSdrPageProperties().GetTheme().get();
-    }
+        pTheme = pPage->TRG_GetMasterPage().getSdrPageProperties().GetTheme();
 
     if (!pTheme)
-    {
         return {};
-    }
 
-    return pTheme->GetColors();
+    return pTheme->getColorSet();
 }
 
 } // end of namespace sd
diff --git a/sd/source/ui/inc/DrawDocShell.hxx 
b/sd/source/ui/inc/DrawDocShell.hxx
index 86917fcb7402..5c742befd855 100644
--- a/sd/source/ui/inc/DrawDocShell.hxx
+++ b/sd/source/ui/inc/DrawDocShell.hxx
@@ -201,7 +201,7 @@ public:
 
     void                    ClearUndoBuffer();
 
-    std::vector<Color> GetThemeColors() override;
+    std::shared_ptr<model::ColorSet> GetThemeColors() override;
 
 private:
     static void setEditMode(DrawViewShell* pDrawViewShell, bool isMasterPage);
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
index caf222c61d2d..177451b116b6 100644
--- a/sfx2/source/doc/objcont.cxx
+++ b/sfx2/source/doc/objcont.cxx
@@ -321,7 +321,7 @@ std::set<Color> SfxObjectShell::GetDocColors()
     return empty;
 }
 
-std::vector<Color> SfxObjectShell::GetThemeColors() { return 
std::vector<Color>(); }
+std::shared_ptr<model::ColorSet> SfxObjectShell::GetThemeColors() { return {}; 
}
 
 sfx::AccessibilityIssueCollection SfxObjectShell::runAccessibilityCheck()
 {
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 5a7e48a47018..b2386326301d 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -430,6 +430,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
     svx/source/table/tableundo \
     svx/source/table/viewcontactoftableobj \
     svx/source/theme/ThemeColorChanger \
+    svx/source/theme/ThemeColorPaletteManager \
     svx/source/tbxctrls/extrusioncontrols \
     svx/source/tbxctrls/fontworkgallery \
     svx/source/tbxctrls/linectrl \
diff --git a/svx/source/tbxctrls/PaletteManager.cxx 
b/svx/source/tbxctrls/PaletteManager.cxx
index a3d7726bb3ba..3fb713f50a6e 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -29,6 +29,7 @@
 #include <svx/strings.hrc>
 #include <svx/svxids.hrc>
 #include <svx/dialmgr.hxx>
+
 #include <tbxcolorupdate.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/settings.hxx>
@@ -52,29 +53,6 @@
 #include <stack>
 #include <set>
 
-namespace
-{
-constexpr const std::array<sal_Int16, 6> g_aPercentBlack = {      0,    50,    
35,    25,    15,     5 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsBlack = { 10'000, 5'000, 
6'500, 7'500, 8'500, 9'500 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsBlack = {      0, 5'000, 
3'500, 2'500, 1'500, 0'500 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercentLow = {      0,    90,    
75,    50,    25,    10 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsLow = { 10'000, 1'000, 
2'500, 5'000, 7'500, 9'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsLow = {      0, 9'000, 
7'500, 5'000, 2'500, 1'000 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercent = {      0,    80,    60,  
  40,   -25,   -50 };
-constexpr const std::array<sal_Int16, 6> g_aLumMods = { 10'000, 2'000, 4'000, 
6'000, 7'500, 5'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffs = {      0, 8'000, 6'000, 
4'000,     0,     0 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercentHigh = {      0,   -10,   
-25,   -50,   -75,   -90 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsHigh = { 10'000, 9'000, 
7'500, 5'000, 2'500, 1'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsHigh = {      0,     0,     
0,     0,     0,     0 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercentWhite = {      0,    -5,   
-15,   -25,   -35,   -50 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsWhite = { 10'000, 9'500, 
8'500, 7'500, 6'500, 5'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsWhite = {      0,     0,    
 0,     0,     0,     0 };
-}
-
 PaletteManager::PaletteManager() :
     
mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()),
     mnNumOfPalettes(3),
@@ -198,31 +176,11 @@ bool PaletteManager::GetLumModOff(sal_uInt16 nThemeIndex, 
sal_uInt16 nEffect, sa
     if (!moThemePaletteCollection)
         return false;
 
-    auto const& aThemeColorData = 
moThemePaletteCollection->maData[nThemeIndex];
+    auto const& aThemeColorData = 
moThemePaletteCollection->maColors[nThemeIndex];
+
+    rLumMod = aThemeColorData.getLumMod(nEffect);
+    rLumOff = aThemeColorData.getLumOff(nEffect);
 
-    switch (aThemeColorData.meType)
-    {
-        case ThemePaletteColorType::Black:
-            rLumMod = g_aLumModsBlack[nEffect];
-            rLumOff = g_aLumOffsBlack[nEffect];
-            break;
-        case ThemePaletteColorType::White:
-            rLumMod = g_aLumModsWhite[nEffect];
-            rLumOff = g_aLumOffsWhite[nEffect];
-            break;
-        case ThemePaletteColorType::Low:
-            rLumMod = g_aLumModsLow[nEffect];
-            rLumOff = g_aLumOffsLow[nEffect];
-            break;
-        case ThemePaletteColorType::High:
-            rLumMod = g_aLumModsHigh[nEffect];
-            rLumOff = g_aLumOffsHigh[nEffect];
-            break;
-        case ThemePaletteColorType::Normal:
-            rLumMod = g_aLumMods[nEffect];
-            rLumOff = g_aLumOffs[nEffect];
-            break;
-    }
     return true;
 }
 
@@ -247,95 +205,22 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet 
&rColorSet)
         SfxObjectShell* pObjectShell = SfxObjectShell::Current();
         if (pObjectShell)
         {
-            std::vector<Color> aColors = pObjectShell->GetThemeColors();
-            mnColorCount = aColors.size();
+            auto pColorSet = pObjectShell->GetThemeColors();
+            mnColorCount = 12;
             rColorSet.Clear();
-            if (aColors.size() >= 12)
-            {
-                const std::array<OUString, 12> aColorNames = {
-                    SvxResId(RID_SVXSTR_THEME_COLOR1),  
SvxResId(RID_SVXSTR_THEME_COLOR2),
-                    SvxResId(RID_SVXSTR_THEME_COLOR3),  
SvxResId(RID_SVXSTR_THEME_COLOR4),
-                    SvxResId(RID_SVXSTR_THEME_COLOR5),  
SvxResId(RID_SVXSTR_THEME_COLOR6),
-                    SvxResId(RID_SVXSTR_THEME_COLOR7),  
SvxResId(RID_SVXSTR_THEME_COLOR8),
-                    SvxResId(RID_SVXSTR_THEME_COLOR9),  
SvxResId(RID_SVXSTR_THEME_COLOR10),
-                    SvxResId(RID_SVXSTR_THEME_COLOR11), 
SvxResId(RID_SVXSTR_THEME_COLOR12),
-                };
-
-                sal_uInt16 nItemId = 0;
-
-                moThemePaletteCollection = ThemePaletteCollection();
-                for (size_t nColor = 0; nColor < aColorNames.size(); ++nColor)
-                {
-                    Color aColor = aColors[nColor];
-                    basegfx::BColor aBColor = 
basegfx::utils::rgb2hsl(aColor.getBColor());
-                    double aLuminanceValue = aBColor.getBlue() * 255.0;
-                    moThemePaletteCollection->maData[nColor].maColor = aColor;
-
-                    if (aLuminanceValue < 0.5)
-                        moThemePaletteCollection->maData[nColor].meType = 
ThemePaletteColorType::Black;
-                    else if (aLuminanceValue > 254.5)
-                        moThemePaletteCollection->maData[nColor].meType = 
ThemePaletteColorType::White;
-                    else if (aLuminanceValue < 50.5)
-                        moThemePaletteCollection->maData[nColor].meType = 
ThemePaletteColorType::Low;
-                    else if (aLuminanceValue > 203.5)
-                        moThemePaletteCollection->maData[nColor].meType = 
ThemePaletteColorType::High;
-                    else
-                        moThemePaletteCollection->maData[nColor].meType = 
ThemePaletteColorType::Normal;
-                }
+            sal_uInt16 nItemId = 0;
 
-                // Each row is one effect type (no effect + each type).
-                for (size_t nEffect : {0, 1, 2, 3, 4, 5})
+            svx::ThemeColorPaletteManager aThemeColorManager(pColorSet);
+            moThemePaletteCollection = aThemeColorManager.generate();
+
+            // Each row is one effect type (no effect + each type).
+            for (size_t nEffect : {0, 1, 2, 3, 4, 5})
+            {
+                // Each column is one color type.
+                for (auto const& rColorData : 
moThemePaletteCollection->maColors)
                 {
-                    // Each column is one color type.
-                    for (size_t nColor = 0; nColor < aColorNames.size(); 
++nColor)
-                    {
-                        auto const& aThemeColorData = 
moThemePaletteCollection->maData[nColor];
-                        Color aColor = aThemeColorData.maColor;
-                        sal_Int16 nColorTemplateValue = 0;
-                        switch (aThemeColorData.meType)
-                        {
-                            case ThemePaletteColorType::Black:
-                                nColorTemplateValue = g_aPercentBlack[nEffect];
-                                break;
-                            case ThemePaletteColorType::White:
-                                nColorTemplateValue = g_aPercentWhite[nEffect];
-                                break;
-                            case ThemePaletteColorType::Low:
-                                nColorTemplateValue = g_aPercentLow[nEffect];
-                                break;
-                            case ThemePaletteColorType::High:
-                                nColorTemplateValue = g_aPercentHigh[nEffect];
-                                break;
-                            case ThemePaletteColorType::Normal:
-                                nColorTemplateValue = g_aPercent[nEffect];
-                                break;
-                        }
-
-                        sal_Int16 nLumMod = 10'000;
-                        sal_Int16 nLumOff = 0;
-                        GetLumModOff(nColor, nEffect, nLumMod, nLumOff);
-                        aColor.ApplyLumModOff(nLumMod, nLumOff);
-
-                        OUString aColorName;
-                        if (nColorTemplateValue > 0)
-                        {
-                            OUString aTemplate = 
SvxResId(RID_SVXSTR_THEME_EFFECT_LIGHTER);
-                            aColorName = aTemplate.replaceAll("$THEME_NAME", 
aColorNames[nColor]);
-                            aColorName = aColorName.replaceAll("$PERCENTAGE", 
OUString::number(std::abs(nColorTemplateValue)));
-
-                        }
-                        else if (nColorTemplateValue < 0)
-                        {
-                            OUString aTemplate = 
SvxResId(RID_SVXSTR_THEME_EFFECT_DARKER);
-                            aColorName = aTemplate.replaceAll("$THEME_NAME", 
aColorNames[nColor]);
-                            aColorName = aColorName.replaceAll("$PERCENTAGE", 
OUString::number(std::abs(nColorTemplateValue)));
-                        }
-                        else
-                        {
-                            aColorName = aColorNames[nColor];
-                        }
-                        rColorSet.InsertItem(nItemId++, aColor, aColorName);
-                    }
+                    auto const& rEffect = rColorData.maEffects[nEffect];
+                    rColorSet.InsertItem(nItemId++, rEffect.maColor, 
rEffect.maColorName);
                 }
             }
         }
diff --git a/svx/source/theme/ThemeColorPaletteManager.cxx 
b/svx/source/theme/ThemeColorPaletteManager.cxx
new file mode 100644
index 000000000000..82ebb38fb69a
--- /dev/null
+++ b/svx/source/theme/ThemeColorPaletteManager.cxx
@@ -0,0 +1,130 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <svx/theme/ThemeColorPaletteManager.hxx>
+
+#include <basegfx/color/bcolortools.hxx>
+#include <tools/color.hxx>
+#include <unotools/resmgr.hxx>
+#include <svx/dialmgr.hxx>
+#include <svx/strings.hrc>
+#include <docmodel/theme/ColorSet.hxx>
+
+#include <array>
+
+namespace
+{
+constexpr const std::array<const std::array<sal_Int16, 6>, 5> g_aLumMods = {
+    std::array<sal_Int16, 6>{ 10'000, 5'000, 6'500, 7'500, 8'500, 9'500 },
+    std::array<sal_Int16, 6>{ 10'000, 1'000, 2'500, 5'000, 7'500, 9'000 },
+    std::array<sal_Int16, 6>{ 10'000, 2'000, 4'000, 6'000, 7'500, 5'000 },
+    std::array<sal_Int16, 6>{ 10'000, 9'000, 7'500, 5'000, 2'500, 1'000 },
+    std::array<sal_Int16, 6>{ 10'000, 9'500, 8'500, 7'500, 6'500, 5'000 },
+};
+
+constexpr const std::array<const std::array<sal_Int16, 6>, 5> g_aLumOffs = {
+    std::array<sal_Int16, 6>{ 0, 5'000, 3'500, 2'500, 1'500, 0'500 },
+    std::array<sal_Int16, 6>{ 0, 9'000, 7'500, 5'000, 2'500, 1'000 },
+    std::array<sal_Int16, 6>{ 0, 8'000, 6'000, 4'000, 0, 0 },
+    std::array<sal_Int16, 6>{ 0, 0, 0, 0, 0, 0 },
+    std::array<sal_Int16, 6>{ 0, 0, 0, 0, 0, 0 },
+};
+
+} // end anonymous namespace
+
+namespace svx
+{
+ThemeColorPaletteManager::ThemeColorPaletteManager(
+    std::shared_ptr<model::ColorSet> const& pColorSet)
+    : m_pColorSet(pColorSet)
+{
+}
+
+svx::ThemePaletteCollection ThemeColorPaletteManager::generate()
+{
+    svx::ThemePaletteCollection aThemePaletteCollection;
+
+    const std::array<OUString, 12> aColorNames = {
+        SvxResId(RID_SVXSTR_THEME_COLOR1),  SvxResId(RID_SVXSTR_THEME_COLOR2),
+        SvxResId(RID_SVXSTR_THEME_COLOR3),  SvxResId(RID_SVXSTR_THEME_COLOR4),
+        SvxResId(RID_SVXSTR_THEME_COLOR5),  SvxResId(RID_SVXSTR_THEME_COLOR6),
+        SvxResId(RID_SVXSTR_THEME_COLOR7),  SvxResId(RID_SVXSTR_THEME_COLOR8),
+        SvxResId(RID_SVXSTR_THEME_COLOR9),  SvxResId(RID_SVXSTR_THEME_COLOR10),
+        SvxResId(RID_SVXSTR_THEME_COLOR11), SvxResId(RID_SVXSTR_THEME_COLOR12),
+    };
+
+    for (size_t nColor = 0; nColor < aColorNames.size(); ++nColor)
+    {
+        auto eThemeType = model::convertToThemeColorType(nColor);
+        if (eThemeType == model::ThemeColorType::Unknown)
+            continue;
+
+        auto& aThemeColorData = aThemePaletteCollection.maColors[nColor];
+        aThemeColorData.meThemeColorType = eThemeType;
+
+        Color aThemeColor = m_pColorSet->getColor(eThemeType);
+        aThemeColorData.maBaseColor = aThemeColor;
+
+        basegfx::BColor aHSLColor = 
basegfx::utils::rgb2hsl(aThemeColor.getBColor());
+        double aLuminanceValue = aHSLColor.getBlue() * 255.0;
+
+        for (size_t nEffect : { 0, 1, 2, 3, 4, 5 })
+        {
+            auto& rEffect = aThemeColorData.maEffects[nEffect];
+            size_t nIndex = 0;
+
+            if (aLuminanceValue < 0.5)
+                nIndex = 0; // Black
+            else if (aLuminanceValue > 254.5)
+                nIndex = 4; // White
+            else if (aLuminanceValue < 50.5)
+                nIndex = 1; // Low
+            else if (aLuminanceValue > 203.5)
+                nIndex = 3; // High
+            else
+                nIndex = 2; // Middle
+
+            rEffect.mnLumOff = g_aLumOffs[nIndex][nEffect];
+            rEffect.mnLumMod = g_aLumMods[nIndex][nEffect];
+
+            rEffect.maColor = aThemeColor;
+            rEffect.maColor.ApplyLumModOff(rEffect.mnLumMod, rEffect.mnLumOff);
+
+            OUString aColorName;
+            sal_Int16 nPercent = rEffect.getPercentage();
+
+            OUString aTemplate;
+            if (nPercent > 0)
+            {
+                aTemplate = SvxResId(RID_SVXSTR_THEME_EFFECT_LIGHTER);
+            }
+            else if (nPercent < 0)
+            {
+                aTemplate = SvxResId(RID_SVXSTR_THEME_EFFECT_DARKER);
+            }
+
+            if (!aTemplate.isEmpty())
+            {
+                aColorName = aTemplate.replaceAll("$THEME_NAME", 
aColorNames[nColor]);
+                aColorName
+                    = aColorName.replaceAll("$PERCENTAGE", 
OUString::number(std::abs(nPercent)));
+            }
+            else
+            {
+                aColorName = aColorNames[nColor];
+            }
+            rEffect.maColorName = aColorName;
+        }
+    }
+    return aThemePaletteCollection;
+}
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index 74fa2225ae93..a48dcad8276b 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -254,7 +254,7 @@ public:
 
     virtual std::set<Color> GetDocColors() override;
 
-    virtual std::vector<Color> GetThemeColors() override;
+    virtual std::shared_ptr<model::ColorSet> GetThemeColors() override;
 
     sfx::AccessibilityIssueCollection runAccessibilityCheck() override;
 
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 1afcd2ba9de1..6fe201784e76 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -1580,7 +1580,7 @@ std::set<Color> SwDocShell::GetDocColors()
     return m_xDoc->GetDocColors();
 }
 
-std::vector<Color> SwDocShell::GetThemeColors()
+std::shared_ptr<model::ColorSet> SwDocShell::GetThemeColors()
 {
     SdrPage* pPage = 
m_xDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     if (!pPage)
@@ -1588,7 +1588,7 @@ std::vector<Color> SwDocShell::GetThemeColors()
     auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
     if (!pTheme)
         return {};
-    return pTheme->GetColors();
+    return pTheme->getColorSet();
 }
 
 void  SwDocShell::LoadStyles( SfxObjectShell& rSource )

Reply via email to