sc/Library_sc.mk                         |    1 
 sc/source/ui/inc/ThemeColorChanger.hxx   |   31 +++++++++
 sc/source/ui/theme/ThemeColorChanger.cxx |   97 +++++++++++++++++++++++++++++++
 sc/source/ui/view/formatsh.cxx           |   13 +---
 sc/source/ui/view/tabvwsh3.cxx           |    6 -
 5 files changed, 137 insertions(+), 11 deletions(-)

New commits:
commit 59a972aecc4f7851031cac21e5ae56410dbe7120
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu May 11 17:51:49 2023 +0900
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Aug 11 09:06:41 2023 +0200

    sc: change (char, background) style colors when changing the theme
    
    This adds a Calc specific ThemeColorChanger, which changes the
    character and background colors in styles. In addition add the
    changes that make this possible - support in SvxBrushItem for
    the ComplexColor, making sure that ComplexColor is properly passed
    to other items (mainly from color picker),...
    
    Change-Id: Id2e98c42bbe195a0f75cc8951ff69f6d7eea6be0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151667
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155511
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 79c41e83ebac..b53b4efdee8e 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -540,6 +540,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools \
     sc/source/ui/StatisticsDialogs/TTestDialog \
     sc/source/ui/StatisticsDialogs/ZTestDialog \
+    sc/source/ui/theme/ThemeColorChanger \
     sc/source/ui/uitest/uiobject \
     sc/source/ui/undo/areasave \
     sc/source/ui/undo/refundo \
diff --git a/sc/source/ui/inc/ThemeColorChanger.hxx 
b/sc/source/ui/inc/ThemeColorChanger.hxx
new file mode 100644
index 000000000000..888cf34f11ba
--- /dev/null
+++ b/sc/source/ui/inc/ThemeColorChanger.hxx
@@ -0,0 +1,31 @@
+/* -*- 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/theme/ThemeColorChanger.hxx>
+#include "docsh.hxx"
+
+namespace sc
+{
+class ThemeColorChanger : public svx::IThemeColorChanger
+{
+    ScDocShell& m_rDocShell;
+
+public:
+    ThemeColorChanger(ScDocShell& rDocShell);
+    virtual ~ThemeColorChanger() override;
+
+    void apply(std::shared_ptr<model::ColorSet> const& pColorSet) override;
+};
+
+} // end sc namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/theme/ThemeColorChanger.cxx 
b/sc/source/ui/theme/ThemeColorChanger.cxx
new file mode 100644
index 000000000000..870ef5b15cb8
--- /dev/null
+++ b/sc/source/ui/theme/ThemeColorChanger.cxx
@@ -0,0 +1,97 @@
+/* -*- 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 <ThemeColorChanger.hxx>
+
+#include <sal/config.h>
+
+#include <docmodel/uno/UnoComplexColor.hxx>
+#include <docmodel/theme/Theme.hxx>
+#include <editeng/colritem.hxx>
+#include <editeng/brushitem.hxx>
+
+#include <stlpool.hxx>
+#include <stlsheet.hxx>
+#include <scitems.hxx>
+#include <document.hxx>
+
+namespace sc
+{
+ThemeColorChanger::ThemeColorChanger(ScDocShell& rDocShell)
+    : m_rDocShell(rDocShell)
+{
+}
+
+ThemeColorChanger::~ThemeColorChanger() = default;
+
+namespace
+{
+void paragraphStyleChange(ScStyleSheet* pStyle, model::ColorSet const& 
rColorSet)
+{
+    const SfxPoolItem* pItem = nullptr;
+    auto& rItemSet = pStyle->GetItemSet();
+
+    if (rItemSet.HasItem(ATTR_FONT_COLOR, &pItem))
+    {
+        auto const* pColorItem = static_cast<const SvxColorItem*>(pItem);
+        model::ComplexColor const& rComplexColor = 
pColorItem->getComplexColor();
+        if (rComplexColor.meType == model::ColorType::Scheme)
+        {
+            auto eThemeType = rComplexColor.meSchemeType;
+            if (eThemeType != model::ThemeColorType::Unknown)
+            {
+                Color aColor = rColorSet.getColor(eThemeType);
+                aColor = rComplexColor.applyTransformations(aColor);
+
+                SvxColorItem aColorItem(*pColorItem);
+                aColorItem.setColor(aColor);
+                rItemSet.Put(aColorItem);
+            }
+        }
+    }
+    if (rItemSet.HasItem(ATTR_BACKGROUND, &pItem))
+    {
+        auto const* pBrushItem = static_cast<const SvxBrushItem*>(pItem);
+        model::ComplexColor const& rComplexColor = 
pBrushItem->getComplexColor();
+        if (rComplexColor.meType == model::ColorType::Scheme)
+        {
+            auto eThemeType = rComplexColor.meSchemeType;
+            if (eThemeType != model::ThemeColorType::Unknown)
+            {
+                Color aColor = rColorSet.getColor(eThemeType);
+                aColor = rComplexColor.applyTransformations(aColor);
+
+                SvxBrushItem aNewBrushItem(*pBrushItem);
+                aNewBrushItem.SetColor(aColor);
+                rItemSet.Put(aNewBrushItem);
+            }
+        }
+    }
+}
+} // end anonymous ns
+
+void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& 
pColorSet)
+{
+    auto& rDocument = m_rDocShell.GetDocument();
+    ScStyleSheetPool* pPool = rDocument.GetStyleSheetPool();
+    ScStyleSheet* pStyle;
+
+    // Paragraph style color change
+    pStyle = static_cast<ScStyleSheet*>(pPool->First(SfxStyleFamily::Para));
+    while (pStyle)
+    {
+        paragraphStyleChange(pStyle, *pColorSet);
+        pStyle = static_cast<ScStyleSheet*>(pPool->Next());
+    }
+}
+
+} // end sw namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 913915a20dc8..a6e637536f44 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -1980,17 +1980,13 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
             // ATTR_BACKGROUND (=SID_ATTR_BRUSH) has to be set to two IDs:
             case SID_BACKGROUND_COLOR:
                 {
-                    Color aColor;
-
-                    if (!lcl_getColorFromStr(pNewAttrs, aColor))
-                    {
-                        const SvxColorItem&  rNewColorItem = pNewAttrs->Get( 
SID_BACKGROUND_COLOR );
-                        aColor = rNewColorItem.GetValue();
-                    }
+                    const SvxColorItem&  rNewColorItem = pNewAttrs->Get( 
SID_BACKGROUND_COLOR );
+                    Color aColor = rNewColorItem.GetValue();
 
                     SvxBrushItem aBrushItem(
                         pTabViewShell->GetSelectionPattern()->GetItem( 
ATTR_BACKGROUND ) );
-                    aBrushItem.SetColor( aColor );
+                    aBrushItem.SetColor(aColor);
+                    
aBrushItem.setComplexColor(rNewColorItem.getComplexColor());
 
                     pTabViewShell->ApplyAttr( aBrushItem, false );
                 }
@@ -2003,6 +1999,7 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq )
                     const SvxBrushItem& rNewBrushItem = static_cast<const 
SvxBrushItem&>(
                                             pNewAttrs->Get( 
GetPool().GetWhich(nSlot) ) );
                     aBrushItem.SetColor(rNewBrushItem.GetColor());
+                    
aBrushItem.setComplexColor(rNewBrushItem.getComplexColor());
                     pTabViewShell->ApplyAttr( aBrushItem );
                 }
                 break;
diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx
index 8e0695a29d20..03005edfb72d 100644
--- a/sc/source/ui/view/tabvwsh3.cxx
+++ b/sc/source/ui/view/tabvwsh3.cxx
@@ -62,7 +62,7 @@
 #include <svx/svdpagv.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/dialog/ThemeDialog.hxx>
-#include <svx/theme/ThemeColorChanger.hxx>
+#include <ThemeColorChanger.hxx>
 
 namespace
 {
@@ -1352,14 +1352,14 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
                 ScViewData& rViewData = GetViewData();
                 vcl::Window* pWin = rViewData.GetActiveWin();
                 auto pDialog = std::make_shared<svx::ThemeDialog>(pWin ? 
pWin->GetFrameWeld() : nullptr, pTheme.get());
-                weld::DialogController::runAsync(pDialog, [pDialog, 
pPage](sal_uInt32 nResult) {
+                weld::DialogController::runAsync(pDialog, [this, 
pDialog](sal_uInt32 nResult) {
                     if (RET_OK != nResult)
                         return;
 
                     auto pColorSet = pDialog->getCurrentColorSet();
                     if (pColorSet)
                     {
-                        svx::ThemeColorChanger aChanger(pPage);
+                        sc::ThemeColorChanger 
aChanger(*GetViewData().GetDocShell());
                         aChanger.apply(pColorSet);
                     }
                 });

Reply via email to